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

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