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

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