source: trunk/MagicSoft/Mars/mmovie/MMovieWrite.cc@ 9312

Last change on this file since 9312 was 9303, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 25.1 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 4/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2007
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMovieWrite
28//
29// The intention of this class is to encode movies prepard by the
30// MMoviePrepare task.
31//
32// For writing the movies the images are converted to ppm and piped through
33// ppm2y4m to mpeg2enc. The output format is a mpeg2 movie and should
34// be within the specifications of mpeg2 for DVD. Its size is 720x480,
35// which is a good compromise between resolution and file size. The frame
36// rate is fixed to 24fps.
37//
38// By changing the setup you can control the output:
39//
40// NumEvents: To make sure the file size doesn't get too large
41// (300 evts are roughly 80MB with the default seetings) you can set
42// a maximum number of events. If this number of events has been encoded
43// the eventloop is stopped.
44//
45// TargetLength: The length (in seconds) each even will be encoded to.
46// For example with the default Target Length of 5s and the fixed frame
47// rate of 24fps each event will be encoded into 24f/s*5s +1f = 121frames
48// equally distributed between the beginning of the first and the end of
49// the last frame.
50//
51// Threshold: The default threshold is 2. At 2 times median pedestal rms
52// of the pixles with area index 0 (for MAGIC: inner pixels) the color
53// palette will change from yellow to red and isolated pixels between
54// the median rms and 2 times the median of the rms will be removed from
55// the image. To switch off this behaviour you can set a threshold
56// below one.
57//
58// Filename: The output filename of the movie. If it doesn't end with ".mpg"
59// the suffix is added.
60//
61// The interpolation of the frames is done using a TSpline3. If the spline
62// would extrapolate due to the shift by the relative time calibration the
63// contents is set to zero. Unsuitable pixels are interpolated frame by
64// frame using the surrounding suitable pixels.
65//
66// A few words about file size: MPEG is a motion compensation compression,
67// which means that if a region of a past frame is shown again at the same
68// place or somewhere else this region is referenced instead of encoded again.
69// This means that in our case (almost all frames are identical!) the
70// increase of file size is far from linear with the number of encoded events!
71//
72//
73// Input:
74// MGeomCam
75// MRawRunHeader
76// MRawEvtHeader
77// MSignalCam
78// MBadPixelsCam
79// MMovieData
80// [MMcEvt]
81//
82/////////////////////////////////////////////////////////////////////////////
83#include "MMovieWrite.h"
84
85#include <errno.h>
86
87#include <TF1.h>
88#include <TStyle.h>
89#include <TColor.h>
90#include <TCanvas.h>
91#include <TSystem.h>
92#include <TASImage.h>
93#include <TStopwatch.h>
94
95#include "MString.h"
96
97#include "MParList.h"
98#include "MTaskList.h"
99
100#include "MGeomCam.h"
101#include "MGeomPix.h"
102
103#include "MMcEvt.hxx"
104
105#include "MH.h"
106#include "MHCamera.h"
107#include "MMovieData.h"
108#include "MSignalCam.h"
109#include "MRawEvtHeader.h"
110#include "MRawRunHeader.h"
111#include "MBadPixelsCam.h"
112#include "MBadPixelsPix.h"
113#include "MCalibrateData.h"
114
115#include "MLog.h"
116#include "MLogManip.h"
117
118ClassImp(MMovieWrite);
119
120using namespace std;
121
122// --------------------------------------------------------------------------
123//
124// Default constructor.
125//
126MMovieWrite::MMovieWrite(const char *name, const char *title)
127 : fPipe(0), fTargetLength(5), fThreshold(2), fNumEvents(25000), fFilename("movie.mpg")
128{
129 fName = name ? name : "MMovieWrite";
130 fTitle = title ? title : "Task to encode a movie";
131}
132
133// --------------------------------------------------------------------------
134//
135// Close pipe if still open
136//
137MMovieWrite::~MMovieWrite()
138{
139 if (fPipe)
140 gSystem->ClosePipe(fPipe);
141}
142
143// --------------------------------------------------------------------------
144//
145// Check the pipe for errors. In case of error print an error message.
146// return kFALSE in case of error, kTRUE in case of success.
147//
148Bool_t MMovieWrite::CheckPipe()
149{
150 if (!ferror(fPipe))
151 return kTRUE;
152
153 *fLog << err << "Error in pipe: " << strerror(errno) << endl;
154 return kFALSE;
155}
156
157// --------------------------------------------------------------------------
158//
159// Open pipe for encoding the movie
160//
161Bool_t MMovieWrite::OpenPipe()
162{
163 // name = "ppmtoy4m -B -S 420mpeg2 -v 0 | yuvplay";
164 // name = Form("ppmtoy4m -B -S 420jpeg -v 0 -F %d:%d | yuv2lav -v 0 -o output%03d.avi", TMath::Nint() TMath::Nint(fTargetLength*1000))
165 // name = "ppmtoy4m -B -F 3:1 -S 420jpeg -v 0 | yuv2lav -v 0 -o output.avi";
166
167 TString name;
168 name = "ppmtoy4m -B -F 24:1 -S 420jpeg -v 0 | ";
169 name += "mpeg2enc -v 0 -F 2 -I 0 -M 2 -o ";
170 name += fFilename;
171 if (!fFilename.EndsWith(".mpg"))
172 name += ".mpg";
173
174 const Int_t n = TMath::Nint(fTargetLength*24)+1;
175
176 name += " -f 9 -E 40 -r 0 -K kvcd ";
177 name += MString::Format("-g %d -G %d", n, n);
178
179 // For higher resolution add "--no-constraints"
180
181 fPipe = gSystem->OpenPipe(name, "w");
182 if (!fPipe)
183 {
184 *fLog << err;
185 *fLog << "Pipe: " << name << endl;
186 *fLog << "Couldn't open pipe... aborting." << endl;
187 CheckPipe();
188 return kFALSE;
189 }
190
191 *fLog << inf << "Setup pipe to ppmtoy4m and mpeg2enc to encode " << fFilename << "." << endl;
192
193 return kTRUE;
194
195 // 1: 37M name += "-f 9 -E 40 -H -4 1 -2 1 --dualprime-mpeg2";
196 // 2: 42M name += "-f 9";
197 // 3: 37M name += "-f 9 -E 40 -4 1 -2 1 --dualprime-mpeg2";
198 // 4: 37M name += "-f 9 -E 40 -4 1 -2 1";
199 // 5: 37M name += "-f 9 -E 40 -4 4 -2 4"; // 640x400 3 frames/slice
200 // 6: 11M name += "-f 3 -E 40 -b 750"; // 640x400 3 frames/slice
201
202 // 7: 28M name += "-f 9 -E 40 -G 50"; // 640x400 3 frames/slice
203 // 8: 24M name += "-f 9 -E 40 -G 500"; // 640x400 3 frames/slice
204
205 // 9: 17M name += "-f 9 -E 40 -G 2400"; // 640x400 24 frames/slice
206 // 10: 19M name += "-f 9 -E 40 -G 1120"; // 720x480 3 frames/slice
207 // 20: 33M name += "-f 9 -E 40 -g 28 -G 28"; // 720x480 3 frames/slice
208 // 57M name += "-f 9 -E 40 -g 28 -G 28 -q 4"; // 720x480 3 frames/slice
209
210 // 30M name += "-f 9 -E 40 -g 84 -G 84 -r 0"; // 720x480 3 frames/slice
211 // 31M name += "-f 9 -E 40 -g 56 -G 56 -r 0"; // 720x480 3 frames/slice
212 // 34M name += "-f 9 -E 40 -g 28 -G 28 -r 0"; // 720x480 3 frames/slice
213 // 24: 24M name += "-f 9 -E 40 -g 28 -G 28 -r 0 -K kvcd"; // 720x480 3 frames/slice
214 // 25: 24M name += "-f 9 -E -40 -g 28 -G 28 -r 0 -K kvcd"; // 720x480 3 frames/slice
215 // 26: 26M name += "-f 9 -E 0 -g 28 -G 28 -r 0 -K kvcd"; // 720x480 3 frames/slice
216 // 34M name += "-f 9 -E 40 -g 28 -G 28 -r 2"; // 720x480 3 frames/slice
217 // 33M name += "-f 9 -E 40 -g 28 -G 28 -r 32"; // 720x480 3 frames/slice
218
219 // name += "-f 9 -E 40 -g 121 -G 121 -r 0 -K kvcd"; // 720x480 5s 24 frames/slice
220
221 // 11: 56M name += "-f 9 -E 40 -g 217 -G 217"; // 720x480 24 frames/slice
222 // 18: 59M name += "-f 9 -E 40 -G 250"; // 720x480 24 frames/slice
223 // 62M name += "-f 9 -E 40 -G 184"; // 720x480 24 frames/slice
224
225 // 12: --- name += "-f 9 -E 40 -G 500 -q 31"; // 720x480 3frames/slice
226 // 13: 49M name += "-f 9 -E 40 -G 500 -q 4"; // 720x480 3frames/slice
227 // 14: 21M name += "-f 9 -E 40 -G 500 -q 4 -b 1500"; // 720x480 3frames/slice
228
229 // 15: 57M name += "-f 9 -E 40 -G 500 --no-constraints"; // 1280 864 3frames/slice
230
231 // 16: >80 name += "-f 9 -E 40 -G 217 --no-constraints -b 3000"; // 1280 864 24frames/slice
232 // 17: >50 name += "-f 9 -E 40 -G 682 -b 3000 --no-constraints"; // 1280 864 24frames/slice
233}
234
235// --------------------------------------------------------------------------
236//
237// Search for:
238// - MGeomCam
239// - MRawRunHeader
240// - MRawEvtHeader
241// - MSignalCam
242// - MBadPixelsCam
243// - MMovieData
244//
245// Open a pipe to write the images to. Can be either a player or
246// an encoder.
247//
248Int_t MMovieWrite::PreProcess(MParList *plist)
249{
250 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
251 if (!fCam)
252 {
253 *fLog << err << "MGeomCam not found ... aborting." << endl;
254 return kFALSE;
255 }
256 fRun = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
257 if (!fRun)
258 {
259 *fLog << err << "MRawRunHeader not found ... aborting." << endl;
260 return kFALSE;
261 }
262 fHead = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
263 if (!fHead)
264 {
265 *fLog << err << "MRawEvtHeader not found ... aborting." << endl;
266 return kFALSE;
267 }
268 fSig = (MSignalCam*)plist->FindObject("MSignalCam");
269 if (!fSig)
270 {
271 *fLog << err << "MSignalCam not found ... aborting." << endl;
272 return kFALSE;
273 }
274 fBad = (MBadPixelsCam*)plist->FindObject("MBadPixelsCam");
275 if (!fBad)
276 {
277 *fLog << err << "MBadPixelsCam not found ... aborting." << endl;
278 return kFALSE;
279 }
280 fIn = (MMovieData*)plist->FindObject("MMovieData");
281 if (!fIn)
282 {
283 *fLog << err << "MMovieData not found... aborting." << endl;
284 return kFALSE;
285 }
286
287 fMC = (MMcEvt*)plist->FindObject("MMcEvt");
288
289 return OpenPipe();
290}
291
292TStopwatch clockT, clock1, clock2, clock3;
293
294// --------------------------------------------------------------------------
295//
296// Close pipe if still open
297//
298Int_t MMovieWrite::PostProcess()
299{
300 if (fPipe)
301 {
302 gSystem->ClosePipe(fPipe);
303 fPipe=0;
304 }
305
306 *fLog << all << endl;
307 *fLog << "Snap: " << flush;
308 clock1.Print();
309 *fLog << "Writ: " << flush;
310 clock2.Print();
311 *fLog << "Prep: " << flush;
312 clock3.Print();
313 *fLog << "Totl: " << flush;
314 clockT.Print();
315 *fLog << endl;
316
317 return kTRUE;
318}
319
320// --------------------------------------------------------------------------
321//
322// Produce a 99 color palette made such, that everything below one
323// pedestal rms is white, everything up to two pedestal rms is yellow
324// and everything above gets colors.
325//
326Int_t MMovieWrite::SetPalette(Double_t rms, const TH1 &h) const
327{
328 const Double_t min = h.GetMinimum();
329 const Double_t max = h.GetMaximum();
330
331 const Double_t f = (fThreshold*rms-min)/(max-min);
332 const Double_t w = 1-f;
333
334 // --- Produce the nice colored palette ---
335
336 // min th*rms max
337 double s[6] = {0.0, f/2, f, f+w/4, f+3*w/5, 1.0 };
338
339 double r[6] = {1.0, 1.0, 1.0, 0.85, 0.1, 0.0 };
340 double g[6] = {1.0, 1.0, 1.0, 0.0, 0.1, 0.0 };
341 double b[6] = {0.9, 0.55, 0.4, 0.0, 0.7, 0.1 };
342
343 TArrayI col(99);
344
345#if ROOT_VERSION_CODE < ROOT_VERSION(5,18,00)
346 const Int_t rc = gStyle->CreateGradientColorTable(6, s, r, g, b, col.GetSize());
347#else
348 const Int_t rc = TColor::CreateGradientColorTable(6, s, r, g, b, col.GetSize());
349#endif
350
351 // --- Overwrite the 'underflow' bin with white ---
352
353 for (int i=0; i<col.GetSize(); i++)
354 col[i] = gStyle->GetColorPalette(i);
355
356 col[0] = TColor::GetColor(0xff, 0xff, 0xff);
357
358 // --- Set Plette ---
359
360 gStyle->SetPalette(col.GetSize(), col.GetArray());
361
362 return rc;
363}
364
365// --------------------------------------------------------------------------
366//
367// The created colors are not overwritten and must be deleted manually
368// because having more than 32768 color in a palette will crash
369// gPad->PaintBox
370//
371void MMovieWrite::DeletePalette(Int_t colidx) const
372{
373 for (int i=0; i<99; i++)
374 {
375 TColor *col = gROOT->GetColor(colidx+i);
376 if (col)
377 delete col;
378 }
379}
380
381/*
382// --------------------------------------------------------------------------
383//
384// Do a snapshot from the pad via TASImage::FromPad and write the
385// image to the pipe.
386// return kFALSE in case of error, kTRUE in case of success.
387//
388Bool_t MMovieWrite::WriteImage(TVirtualPad &pad)
389{
390 clock1.Start(kFALSE);
391 TASImage img;
392 img.FromPad(&pad);
393 clock1.Stop();
394
395 clock2.Start(kFALSE);
396 const Bool_t rc = WriteImage(img);
397 clock2.Stop();
398
399 return rc;
400}
401
402#include <TVirtualPS.h>
403Bool_t MMovieWrite::WriteImage(TVirtualPad &pad)
404{
405 TVirtualPS *psave = gVirtualPS;
406
407 clock1.Start(kFALSE);
408 TImage dump("", 114);
409 dump.SetBit(BIT(11));
410 pad.Paint();
411 TASImage *itmp = (TASImage*)dump.GetStream();
412 clock1.Stop();
413
414 clock2.Start(kFALSE);
415 const Bool_t rc = WriteImage(*itmp);
416 clock2.Stop();
417
418 gVirtualPS = psave;
419
420 return rc;
421}
422*/
423
424// --------------------------------------------------------------------------
425//
426// Update the part of the idst image with the contents of the pad.
427//
428// It is a lot faster not to rerender the parts of the image which don't
429// change anyhow, because rerendering the camera is by far the slowest.
430//
431void MMovieWrite::UpdateImage(TASImage &idst, TVirtualPad &pad)
432{
433 // Get image from pad
434 TASImage isrc;
435 isrc.FromPad(&pad);
436
437 // Get position and width of destination- and source-image
438 const UInt_t wsrc = isrc.GetWidth(); // width of image
439 const UInt_t hsrc = isrc.GetHeight(); // height of image
440
441 const UInt_t usrc = pad.UtoPixel(1)*4; // width of pad (argb)
442 //const UInt_t vsrc = pad.VtoPixel(0); // height of pad
443
444 const UInt_t xsrc = pad.UtoAbsPixel(0); // offset of pad in canvas
445 const UInt_t ysrc = pad.VtoAbsPixel(1); // offset of pad in canvas
446
447 const UInt_t wdst = idst.GetWidth();
448 //const UInt_t hdst = idst.GetHeight();
449
450 // Update destination image with source image
451 const UInt_t size = wsrc*hsrc;
452
453 UInt_t *psrc = isrc.GetArgbArray();
454 UInt_t *pdst = idst.GetArgbArray();
455
456 UInt_t *src = psrc + ysrc*wsrc+xsrc;
457 UInt_t *dst = pdst + ysrc*wdst+xsrc;
458
459 while (src<psrc+size)
460 {
461 memcpy(dst, src, usrc);
462
463 src += wsrc;
464 dst += wdst;
465 }
466}
467
468// --------------------------------------------------------------------------
469//
470// Write the image as ppm (raw/P6) to the pipe.
471// return kFALSE in case of error, kTRUE in case of success.
472//
473Bool_t MMovieWrite::WriteImage(TASImage &img)
474{
475 // Write image header
476 fprintf(fPipe, "P6 %d %d 255\n", img.GetWidth(), img.GetHeight());
477 if (!CheckPipe())
478 return kFALSE;
479
480 // Write image data (remove alpha channel from argb data)
481 UInt_t *argb = img.GetArgbArray();
482 for (UInt_t *ptr=argb; ptr<argb+img.GetWidth()*img.GetHeight(); ptr++)
483 fwrite(ptr, 1, 3, fPipe);
484
485 return CheckPipe();
486}
487
488// --------------------------------------------------------------------------
489//
490// Update TASImage with changing parts of the image and write image to pipe.
491// return kFALSE in case of error, kTRUE in case of success.
492//
493Bool_t MMovieWrite::WriteImage(TASImage &img, TVirtualPad &pad)
494{
495 clock1.Start(kFALSE);
496 UpdateImage(img, pad);
497 clock1.Stop();
498
499 clock2.Start(kFALSE);
500 const Bool_t rc = WriteImage(img);
501 clock2.Stop();
502
503 return rc;
504}
505
506// --------------------------------------------------------------------------
507//
508// Do a simple interpolation of the surrounding suitable pixels for all
509// unsuitable pixels.
510//
511void MMovieWrite::TreatBadPixels(TH1 &h) const
512{
513 const UShort_t entries = fCam->GetNumPixels();
514
515 //
516 // Loop over all pixels
517 //
518 for (UShort_t i=0; i<entries; i++)
519 {
520 //
521 // Check whether pixel with idx i is blind
522 //
523 if (!(*fBad)[i].IsUnsuitable())
524 continue;
525
526 const MGeomPix &gpix = (*fCam)[i];
527
528 Int_t num = 0;
529 Double_t sum = 0;
530
531 //
532 // Loop over all its neighbors
533 //
534 Int_t n = gpix.GetNumNeighbors();
535 while (n--)
536 {
537 const UShort_t nidx = gpix.GetNeighbor(n);
538
539 //
540 // Do not use blind neighbors
541 //
542 if ((*fBad)[nidx].IsUnsuitable())
543 continue;
544
545 sum += h.GetBinContent(nidx+1);
546 num++;
547 }
548
549 h.SetBinContent(i+1, sum/num);
550 }
551}
552
553// --------------------------------------------------------------------------
554//
555// Do a simple interpolation of the surrounding suitable pixels for all
556// unsuitable pixels.
557//
558void MMovieWrite::Clean(TH1 &h, Double_t rms) const
559{
560 if (fThreshold<1)
561 return;
562
563 const UShort_t entries = fCam->GetNumPixels();
564
565 //
566 // Loop over all pixels
567 //
568 for (UShort_t i=0; i<entries; i++)
569 {
570 Double_t val = h.GetBinContent(i+1);
571 if (val<rms || val>fThreshold*rms)
572 continue;
573
574 const MGeomPix &gpix = (*fCam)[i];
575
576 //
577 // Loop over all its neighbors
578 //
579 Int_t n = gpix.GetNumNeighbors();
580 while (n)
581 {
582 const UShort_t nidx = gpix.GetNeighbor(n-1);
583 if (h.GetBinContent(nidx+1)>=rms)
584 break;
585 n--;
586 }
587
588 if (n==0)
589 h.SetBinContent(i+1, 0);
590 }
591}
592
593// --------------------------------------------------------------------------
594//
595Bool_t MMovieWrite::Process(TH1 &h, TVirtualPad &c)
596{
597 // ---------------- Setup ------------------
598
599 const Float_t freq = fRun->GetFreqSampling()/1000.; // [GHz] Sampling frequency
600 const UInt_t slices = fIn->GetNumSlices();
601 const Float_t len = slices/freq; // [ns] length of data stream in data-time
602 //const Float_t len = (slices-2)/freq; // [ns] length of data stream in data-time
603
604 const Double_t rms = fIn->GetMedianPedestalRms();
605 const Double_t max = fIn->GetMax(); // scale the lover limit such
606 const Double_t dif = (max-rms)*99/98; // that everything below rms is
607 const Double_t min = max-dif; // displayed as white
608
609 // If the maximum is equal or less the
610 // pedestal rms something must be wrong
611 if (dif<=0)
612 return kFALSE;
613
614 h.SetMinimum(min);
615 h.SetMaximum(max);
616
617 // -----------------------------------------
618
619 // Produce starting image from canvas
620 TASImage img;
621 img.FromPad(&c);
622
623 // Set new adapted palette for further rendering
624 const Int_t colidx = SetPalette(rms, h);
625
626 // Get the pad containing the camera with the movie
627 TVirtualPad &pad = *c.GetPad(1)->GetPad(1);
628
629 // Calculate number of frames
630 const Int_t numframes = TMath::Nint(fTargetLength*24);
631
632 // Get number of pixels in camera
633 const Int_t npix = fCam->GetNumPixels();
634
635 // Loop over all frames+1 (upper edge)
636 for (Int_t i=0; i<=numframes; i++)
637 {
638 // Calculate corresponding time
639 const Float_t t = len*i/numframes;// + 0.5/freq; // Process from slice beg+0.5 to end-1.5
640
641 // Calculate histogram contents by spline interpolation
642 for (UShort_t p=0; p<npix; p++)
643 {
644 const Double_t y = (*fBad)[p].IsUnsuitable() ? 0 : fIn->CheckedEval(p, t);
645 h.SetBinContent(p+1, y);
646 }
647
648 // Interpolate unsuitable pixels
649 TreatBadPixels(h);
650
651 // Clean single pixels
652 Clean(h, rms);
653
654 // Set new name to be displayed
655 h.SetName(MString::Format("%d: %.2f/%.1fns", i+1, t*freq, t));
656
657 // Update existing image with new data and encode into pipe
658 if (!WriteImage(img, pad))
659 return kFALSE;
660 }
661
662 DeletePalette(colidx);
663
664 cout << setw(3) << GetNumExecutions() << ": " << MString::Format("%6.2f", (float)numframes/(slices-2)) << " f/sl " << slices << " " << numframes+1 << endl;
665
666 return kTRUE;
667}
668
669// --------------------------------------------------------------------------
670//
671Int_t MMovieWrite::Process()
672{
673 clockT.Start(kFALSE);
674
675 clock3.Start(kFALSE);
676
677 // ---------------- Prepare display ------------------
678
679 Bool_t batch = gROOT->IsBatch();
680 gROOT->SetBatch();
681
682 TCanvas c;
683 //c.Iconify();
684 c.SetBorderMode(0);
685 c.SetFrameBorderMode(0);
686 c.SetFillColor(kWhite);
687 //c.SetCanvasSize(640, 400);
688 c.SetCanvasSize(720, 480);
689 //c.SetCanvasSize(960, 640);
690 //c.SetCanvasSize(1024, 688);
691 //c.SetCanvasSize(1152, 768);
692 //c.SetCanvasSize(1280, 864);
693
694 MH::SetPalette("pretty");
695
696 c.cd();
697 TPad p1("Pad2", "", 0.7, 0.66, 0.99, 0.99);
698 p1.SetNumber(2);
699 p1.SetBorderMode(0);
700 p1.SetFrameBorderMode(0);
701 p1.SetFillColor(kWhite);
702 p1.Draw();
703 p1.cd();
704
705 MHCamera hsig(*fCam, "Signal", "Calibrated Signal");
706 hsig.SetYTitle("S [phe]");
707 hsig.SetCamContent(*fSig, 99);
708 hsig.SetMinimum(0);
709 //hsig.SetContour(99);
710 hsig.Draw("nopal");
711
712 c.cd();
713 TPad p2("Pad3", "", 0.7, 0.33, 0.99, 0.65);
714 p2.SetNumber(3);
715 p2.SetBorderMode(0);
716 p2.SetFrameBorderMode(0);
717 p2.SetFillColor(kWhite);
718 p2.Draw();
719 p2.cd();
720
721 MHCamera htime(*fCam, "ArrivalTime", "Calibrated Arrival Time");
722 htime.SetYTitle("T [au]");
723 htime.SetCamContent(*fSig, 8);
724 htime.Draw("nopal");
725
726 c.cd();
727 TPad p3("Pad4", "", 0.7, 0.00, 0.99, 0.32);
728 p3.SetNumber(4);
729 p3.SetBorderMode(0);
730 p3.SetFrameBorderMode(0);
731 p3.SetFillColor(kWhite);
732 p3.Draw();
733 p3.cd();
734/*
735 TH1F htpro("TimeProj", "", slices, 0, len);
736 for (UInt_t i=0; i<htime.GetNumPixels(); i++)
737 if(htime.IsUsed(i))
738 htpro.Fill((htime.GetBinContent(i+1)-first)/freq, hsig.GetBinContent(i+1));
739 htpro.SetMinimum(0);
740 htpro.SetMaximum(100);
741 htpro.SetLineColor(kBlue);
742 htpro.Draw();
743
744 TF1 fgaus("f1", "gaus");
745 const Double_t m = (htpro.GetMaximumBin()-0.5)*len/slices;
746 fgaus.SetParameter(0, htpro.GetMaximum());
747 fgaus.SetParameter(1, m);
748 fgaus.SetParameter(2, 1.0);
749 fgaus.SetParLimits(1, m-3, m+3);
750 fgaus.SetParLimits(2, 0, 3);
751 fgaus.SetLineWidth(1);
752 fgaus.SetLineColor(kMagenta);
753 htpro.Fit(&fgaus, "NI", "", m-3, m+3);
754 fgaus.Draw("same");
755
756 g.SetMarkerStyle(kFullDotMedium);
757 g.Draw("PL");
758 //g.SetMinimum(0);
759 //g.SetMaximum(100);
760 //g.Draw("APL");
761
762 p3.Update();
763 p3.cd(1);
764 gPad->Update();
765 */
766 c.cd();
767 TPad p0("MainPad", "", 0.01, 0.01, 0.69, 0.99);
768 p0.SetNumber(1);
769 p0.SetBorderMode(0);
770 p0.SetFrameBorderMode(0);
771 p0.SetFillColor(kWhite);
772 p0.Draw();
773 p0.cd();
774 /*
775 cout << "Max=" << hsig.GetMaximum() << "/" << fIn->GetMax() << " ";
776 cout << hsig.GetMaximum()/fIn->GetMax() << endl;
777 Float_t rms0 = fPed->GetAveragedRmsPerArea(*fCam, 0, fBad)[0];
778 Float_t rms1 = fPed->GetAveragedRmsPerArea(*fCam, 1, fBad)[0];
779 cout << "RMS="<<rms0<<"/"<<rms1<<endl;
780
781 rms0 = GetMedianPedestalRms();
782
783 cout << "MED=" << rms0 << endl;
784 */
785
786 TString s = MString::Format("%d: Evt #", GetNumExecutions()+1);
787 s += fHead->GetDAQEvtNumber();
788 s += " of ";
789 s += "Run #";
790 s += fRun->GetRunNumber();
791 if (fMC)
792 s = fMC->GetDescription(s);
793
794 MHCamera h(*fCam);
795 h.SetTitle(s);
796 h.SetAllUsed();
797 h.SetYTitle("V [au]");
798 h.SetContour(99);
799
800 h.Draw("nopal");
801
802 // ---------------- Show data ------------------
803 gStyle->SetOptStat(1000000001);
804/*
805 p0.Modified();
806 p1.Modified();
807 p2.Modified();
808
809 p0.GetPad(1)->Modified();
810 p1.GetPad(1)->Modified();
811 p2.GetPad(1)->Modified();
812
813 c.Update();
814 */
815
816 // ---------------- Show data ------------------
817
818 clock3.Stop();
819
820 // Switch off automatical adding to directory (SetName would do)
821 const Bool_t add = TH1::AddDirectoryStatus();
822 TH1::AddDirectory(kFALSE);
823
824 const Bool_t rc = Process(h, c);
825
826 // restore previous state
827 TH1::AddDirectory(add);
828
829 clockT.Stop();
830
831 gROOT->SetBatch(batch);
832
833 if (!rc)
834 return kERROR;
835
836 return fNumEvents<=0 || GetNumExecutions()<fNumEvents;
837}
838
839// --------------------------------------------------------------------------
840//
841// Check for corresponding entries in resource file and setup
842//
843// Example:
844// MMovieWrite.TargetLength: 5 <seconds>
845// MMovieWrite.NumEvents: 500
846// MMovieWrite.Threshold: 2 <rms>
847// MMovieWrite.FileName: movie.mpg
848//
849Int_t MMovieWrite::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
850{
851 Bool_t rc = kFALSE;
852 if (IsEnvDefined(env, prefix, "NumEvents", print))
853 {
854 fNumEvents = GetEnvValue(env, prefix, "NumEvents", (Int_t)fNumEvents);
855 rc = kTRUE;
856 }
857 if (IsEnvDefined(env, prefix, "TargetLength", print))
858 {
859 fTargetLength = GetEnvValue(env, prefix, "TargetLength", fTargetLength);
860 rc = kTRUE;
861 }
862 if (IsEnvDefined(env, prefix, "Threshold", print))
863 {
864 fThreshold = GetEnvValue(env, prefix, "Threshold", fThreshold);
865 rc = kTRUE;
866 }
867 if (IsEnvDefined(env, prefix, "FileName", print))
868 {
869 fFilename = GetEnvValue(env, prefix, "FileName", fFilename);
870 rc = kTRUE;
871 }
872 return rc;
873}
Note: See TracBrowser for help on using the repository browser.