source: trunk/MagicSoft/Mars/mjobs/MJStar.cc@ 9352

Last change on this file since 9352 was 9343, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 19.4 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, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJStar
28//
29// Resource file entries are case sensitive!
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MJStar.h"
33
34#include <TEnv.h>
35#include <TFile.h>
36
37// Core
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MDirIter.h"
42#include "MParList.h"
43#include "MTaskList.h"
44#include "MEvtLoop.h"
45
46#include "MStatusDisplay.h"
47
48// Histograms
49#include "MHSectorVsTime.h"
50#include "MHEffectiveOnTime.h"
51#include "MHCamEvent.h"
52#include "MBinning.h"
53
54///NEEWWWW
55#include "MH3.h"
56
57// Tasks
58#include "MReadReports.h"
59#include "MReadMarsFile.h"
60#include "MContinue.h"
61#include "MGeomApply.h"
62#include "MEventRateCalc.h"
63#include "MImgCleanStd.h"
64#include "MSrcPosCalc.h"
65#include "MSrcPosCorrect.h"
66#include "MHillasCalc.h"
67#include "MMuonSearchParCalc.h"
68#include "MMuonCalibParCalc.h"
69#include "MFillH.h"
70#include "MWriteRootFile.h"
71
72// Filter
73#include "MFDataPhrase.h"
74#include "MFTriggerPattern.h"
75#include "MFilterList.h"
76#include "MFDataMember.h"
77#include "MFDeltaT.h"
78#include "MFSoftwareTrigger.h"
79
80// Parameter container
81#include "MMuonSetup.h"
82#include "MObservatory.h"
83//#include "MTriggerPattern.h"
84#include "MPointingPosCalc.h"
85
86ClassImp(MJStar);
87
88using namespace std;
89
90// --------------------------------------------------------------------------
91//
92// Default constructor.
93//
94// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
95//
96MJStar::MJStar(const char *name, const char *title) : fMuonAnalysis(kTRUE)
97{
98 fName = name ? name : "MJStar";
99 fTitle = title ? title : "Standard analysis and reconstruction";
100}
101
102Bool_t MJStar::CheckEnvLocal()
103{
104 DisableMuonAnalysis(!GetEnv("MuonAnalysis", fMuonAnalysis));
105 return kTRUE;
106}
107
108Bool_t MJStar::WriteResult()
109{
110 if (fPathOut.IsNull())
111 {
112 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
113 return kTRUE;
114 }
115
116 TObjArray cont;
117 cont.Add(const_cast<TEnv*>(GetEnv()));
118 cont.Add(const_cast<MSequence*>(&fSequence));
119
120 if (fDisplay)
121 {
122 TString title = "-- Star: ";
123 title += fSequence.GetSequence();
124 title += " --";
125 fDisplay->SetTitle(title, kFALSE);
126
127 cont.Add(fDisplay);
128 }
129
130 const TString oname = Form("star%08d.root", fSequence.GetSequence());
131 return WriteContainer(cont, oname, "RECREATE");
132}
133
134Bool_t MJStar::Process()
135{
136 if (!fSequence.IsValid())
137 {
138 *fLog << err << "ERROR - Sequence invalid!" << endl;
139 return kFALSE;
140 }
141
142 // --------------------------------------------------------------------------------
143
144 *fLog << inf;
145 fLog->Separator(GetDescriptor());
146 *fLog << "Calculate image parameters of sequence ";
147 *fLog << fSequence.GetFileName() << endl;
148 *fLog << endl;
149
150 if (!CheckEnv())
151 return kFALSE;
152
153 // --------------------------------------------------------------------------------
154
155 MDirIter iter;
156 if (fSequence.GetRuns(iter, MSequence::kCalibrated)<=0)
157 return kFALSE;
158
159 // Setup Parlist
160 MParList plist;
161 plist.AddToList(this); // take care of fDisplay!
162
163 MObservatory obs;
164 plist.AddToList(&obs);
165
166 MMuonSetup muonsetup;
167 plist.AddToList(&muonsetup);
168
169 // Setup binnings for muon analysis
170 MBinning bins1("BinningRadius");
171 MBinning bins2("BinningArcWidth");
172 MBinning bins3("BinningRingBroadening");
173 MBinning bins4("BinningSizeVsArcRadius");
174 MBinning bins5("BinningMuonWidth");
175 MBinning bins6("BinningArcPhi");
176 plist.AddToList(&bins1);
177 plist.AddToList(&bins2);
178 plist.AddToList(&bins3);
179 plist.AddToList(&bins4);
180 plist.AddToList(&bins5);
181 plist.AddToList(&bins6);
182
183
184 // Setup Tasklist
185 MTaskList tlist;
186 plist.AddToList(&tlist);
187
188 MReadReports readreal;
189 readreal.AddTree("Events", "MTime.", MReadReports::kMaster);
190 readreal.AddTree("Drive", MReadReports::kRequired);
191 readreal.AddTree("Starguider", MReadReports::kRequired);
192 readreal.AddTree("Camera", MReadReports::kRequired);
193 readreal.AddTree("Currents");
194 readreal.AddTree("CC");
195 readreal.AddTree("Rec");
196 readreal.AddTree("Trigger");
197 readreal.AddTree("Pyrometer");
198 readreal.AddFiles(iter);
199
200 MReadMarsFile readmc("Events");
201 readmc.DisableAutoScheme();
202 readmc.AddFiles(iter);
203
204 // ------------------ Setup general tasks ----------------
205
206 MFDeltaT fdeltat;
207 MContinue cont(&fdeltat, "FilterDeltaT", "Filter events with wrong timing");
208 cont.SetInverted();
209
210 MGeomApply apply; // Only necessary to craete geometry
211 MEventRateCalc rate;
212 rate.SetNumEvents(1200);
213
214 MFSoftwareTrigger swtrig;
215 MContinue contsw(&swtrig, "FilterSwTrigger", "Software trigger");
216 contsw.SetInverted();
217
218 MImgCleanStd clean;
219 clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
220
221 MSrcPosCalc poscalc;
222 MHillasCalc hcalc;
223 hcalc.Disable(MHillasCalc::kCalcConc);
224
225 // ------------------ Setup histograms and fill tasks ----------------
226 MHCamEvent evt0a(0, "Cleaned", "Average signal after Cleaning;;S [phe]");
227 MHCamEvent evt0c(0, "Sparkless", "Average signal after Cleaning and Spark cuts;;S [phe]");
228 MHCamEvent evt0d(0, "Sparks", "Average signal after Cleaning for Spark cuts;;S [phe]");
229 MHCamEvent evt0b(0, "UsedPix", "Fraction of Events in which Pixels are used;;Fraction");
230 evt0a.SetErrorSpread(kFALSE);
231 evt0b.SetErrorSpread(kFALSE);
232 evt0c.SetErrorSpread(kFALSE);
233 evt0d.SetErrorSpread(kFALSE);
234 evt0b.SetThreshold(0);
235
236 MFillH fillvs("MHRate", "MTime", "FillEventRate");
237 MFillH fillp1("MHPointing", "MTimeDrive", "FillDrive");
238 MFillH fillp2("MHPointing", "MTimeStarguider", "FillStarguider");
239 fillp1.SetBit(MFillH::kDoNotDisplay);
240 fillp1.SetBit(MFillH::kCanSkip);
241 fillp2.SetBit(MFillH::kCanSkip);
242
243 // Needed in parameter list for ReadEnv
244 MHEffectiveOnTime hontime;
245 plist.AddToList(&hontime);
246
247 MFillH fill0a(&evt0a, "MSignalCam", "FillSignalCam");
248 MFillH fill0b(&evt0b, "MSignalCam", "FillCntUsedPixels");
249 MFillH fill0c(&evt0c, "MSignalCam", "FillSignalCamSparkless");
250 MFillH fill0d(&evt0d, "MSignalCam", "FillSignalCamSparks");
251 MFillH fill1("MHHillas", "MHillas", "FillHillas");
252 MFillH fill2("MHHillasExt", "", "FillHillasExt");
253 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
254 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
255 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
256 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
257
258 //fillvs.SetNameTab("Rate");
259 fill9.SetNameTab("EffOnTime");
260 fill0c.SetNameTab("Sparkless");
261 fill0d.SetNameTab("Sparks");
262
263 // FIXME: This should be replaced by a cut working for all triggers!
264 MTriggerPattern par; // An empty trigger pattern for older files
265 plist.AddToList(&par); // without MTriggerPattern stored in the file
266
267 // For the effective on-time calculation we don't want SUM-only events
268 MFTriggerPattern fsum;
269 fsum.SetDefault(kTRUE);
270 fsum.DenyAll();
271 fsum.RequireTriggerLvl1();
272 fsum.AllowTriggerLvl2();
273 fsum.AllowSumTrigger();
274 fill9.SetFilter(&fsum);
275
276 // Plot the trigger pattern rates vs. run-number
277 MH3 hrate("MRawRunHeader.GetFileID", "MTriggerPattern.GetUnprescaled");
278 if (fSequence.IsMonteCarlo())
279 hrate.SetWeight("100./MMcRunHeader.fNumSimulatedShowers");
280 else
281 hrate.SetWeight("1./TMath::Max(MRawRunHeader.GetRunLength,1)");
282 hrate.SetName("Rate");
283 hrate.SetTitle("Event rate after cleaning [Hz];File Id;Trigger Type;");
284 hrate.InitLabels(MH3::kLabelsX);
285 hrate.DefaultLabelY("ERROR");
286 hrate.DefineLabelY( 0, "0"); // 0: No pattern
287 hrate.DefineLabelY( 1, "Trig"); // 1: Lvl1
288 hrate.DefineLabelY( 4, "Trig"); // 4: Lvl2
289 hrate.DefineLabelY( 5, "Trig"); // Lvl2+Lvl1
290 hrate.DefineLabelY(32, "Sum"); // 32: Sum
291 hrate.DefineLabelY(33, "Trig"); // Sum+Lvl1
292 hrate.DefineLabelY(36, "Trig"); // Sum+Lvl2
293 hrate.DefineLabelY(37, "Trig"); // Sum+Lvl1+Lvl2
294
295 MFillH frate(&hrate, "", "FillRate");
296 frate.SetDrawOption("box");
297
298 // ------------------ Setup write task ----------------
299
300 // Effective on-time need its own not to be skipped by (eg) image cleaning
301 // Muons needs its own to have a unique SetReadyToSave
302 const TString rule(Form("s/(([0-9]+_)?(M[12]_)?[0-9.]+)_Y_(.*[.]root)$/%s\\/$1_I_$4/", Esc(fPathOut).Data()));
303 MWriteRootFile write( 2, rule, fOverwrite?"RECREATE":"NEW", "Image parameters");
304 MWriteRootFile writet(2, rule, fOverwrite?"RECREATE":"NEW", "Image parameters"); // EffectiveOnTime
305 MWriteRootFile writem(2, rule, fOverwrite?"RECREATE":"NEW", "Image parameters"); // Muons
306 writem.SetName("WriteMuons");
307
308 // Data
309 write.AddContainer("MHillas", "Events");
310 write.AddContainer("MHillasExt", "Events");
311 write.AddContainer("MHillasSrc", "Events");
312 write.AddContainer("MImagePar", "Events");
313 write.AddContainer("MNewImagePar", "Events");
314 write.AddContainer("MRawEvtHeader", "Events");
315 write.AddContainer("MPointingPos", "Events");
316 write.AddContainer("MTriggerPattern", "Events");
317
318 // Run Header
319 write.AddContainer("MRawRunHeader", "RunHeaders");
320// write.AddContainer("MBadPixelsCam", "RunHeaders");
321 write.AddContainer("MGeomCam", "RunHeaders");
322 write.AddContainer("MObservatory", "RunHeaders");
323
324 // Muon Setup
325 write.AddContainer("BinningRadius", "RunHeaders");
326 write.AddContainer("BinningArcWidth", "RunHeaders");
327 write.AddContainer("BinningRingBroadening", "RunHeaders");
328 write.AddContainer("BinningSizeVsArcRadius", "RunHeaders");
329 write.AddContainer("MMuonSetup", "RunHeaders");
330
331 if (fSequence.IsMonteCarlo())
332 {
333 // Monte Carlo Data
334 write.AddContainer("MMcEvt", "Events");
335 write.AddContainer("MMcTrig", "Events", kFALSE);
336 write.AddContainer("MSrcPosCam", "Events");
337 // Monte Carlo Run Headers
338 write.AddContainer("MMcRunHeader", "RunHeaders");
339 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
340 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
341 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
342 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
343 }
344 else
345 {
346 // Event time
347 write.AddContainer("MTime", "Events");
348
349 // Slow-control trees with time information
350 write.AddTree("Drive");
351 write.AddTree("Starguider", kFALSE);
352 write.AddTree("Pyrometer", kFALSE);
353 writet.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
354 writet.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
355 }
356
357 // What to write in muon tree
358 writem.AddContainer("MMuonSearchPar", "Muons");
359 writem.AddContainer("MMuonCalibPar", "Muons");
360 writem.AddContainer("MHillas", "Muons");
361 writem.AddContainer("MHillasExt", "Muons");
362 writem.AddContainer("MHillasSrc", "Muons");
363 writem.AddContainer("MImagePar", "Muons");
364 writem.AddContainer("MNewImagePar", "Muons");
365 writem.AddContainer("MRawEvtHeader", "Muons");
366 writem.AddContainer("MPointingPos", "Muons");
367 if (fSequence.IsMonteCarlo())
368 {
369 // Monte Carlo Data
370 writem.AddContainer("MMcEvt", "Muons");
371 writem.AddContainer("MMcTrig", "Muons", kFALSE);
372 }
373
374 if (fSequence.IsMonteCarlo())
375 if (fMuonAnalysis)
376 writem.AddCopySource("OriginalMC");
377 else
378 write.AddCopySource("OriginalMC");
379
380 MTaskList tlist2("Events");
381 tlist2.AddToList(&apply);
382 if (!fSequence.IsMonteCarlo())
383 tlist2.AddToList(&cont);
384 tlist2.AddToList(&contsw);
385 if (!fSequence.IsMonteCarlo())
386 {
387 // Calibration events don't enter star at all.
388 tlist2.AddToList(&rate);
389 tlist2.AddToList(&fillvs);
390 tlist2.AddToList(&fsum);
391 tlist2.AddToList(&fill9);
392 tlist2.AddToList(&writet);
393 }
394
395 // Spark cut:
396 // This cut is a little bit different from the default cut in the
397 // ganymed.rc, because the cut in ganymed.rc also suppresses a
398 // little background, while the cut here only shows sparks
399 MFDataPhrase fsparks("log10(MNewImagePar.fConcCOG)<-0.45*(log10(MHillas.fSize)-2.5)-0.24", "SparkCut");
400 //fill0b.SetFilter(&fsparks);
401 fill0c.SetFilter(&fsparks);
402
403 // Inverted spark cut (need not to be a member of the task list
404 // because it fsparks is
405 MFilterList fnsparks(&fsparks);
406 fill0d.SetFilter(&fnsparks);
407
408 tlist2.AddToList(&clean);
409 tlist2.AddToList(&poscalc);
410
411 MFillH fillsp("MHSrcPosCam", "MSrcPosCam", "FillSrcPosCam");
412 fillsp.SetNameTab("Src");
413 if (fSequence.IsMonteCarlo())
414 tlist2.AddToList(&fillsp);
415
416
417 tlist2.AddToList(&hcalc);
418 tlist2.AddToList(&fsparks);
419 tlist2.AddToList(&fill0a);
420 tlist2.AddToList(&fill0c);
421 tlist2.AddToList(&fill0d);
422 tlist2.AddToList(&fill0b);
423 tlist2.AddToList(&frate);
424 tlist2.AddToList(&fill1);
425 tlist2.AddToList(&fill2);
426 tlist2.AddToList(&fill3);
427 tlist2.AddToList(&fill4);
428 tlist2.AddToList(&fill5);
429
430 // ----------------------- Muon Analysis ----------------------
431 // Filter to start muon analysis
432 MFDataPhrase fmuon1("MHillas.fSize>150 && MNewImagePar.fConcCOG<0.1", "MuonPreCut");
433 // Filter to calculate further muon parameters
434 MFDataPhrase fmuon2("(MMuonSearchPar.fRadius>180) && (MMuonSearchPar.fRadius<400) &&"
435 "(MMuonSearchPar.fDeviation<45)", "MuonSearchCut");
436 // Filter to fill the MHMuonPar
437 MFDataPhrase fmuon3("(MMuonCalibPar.fArcPhi>190) && (MMuonSearchPar.fDeviation<35) &&"
438 "(MMuonCalibPar.fArcWidth<0.20) && (MMuonCalibPar.fArcWidth>0.04) &&"
439 "MMuonCalibPar.fRelTimeSigma<1.5",
440 "MuonFinalCut");
441 // Filter to write Muons to Muon tree
442 MFDataMember fmuon4("MMuonCalibPar.fArcPhi", '>', -0.5, "MuonWriteCut");
443 writem.SetFilter(&fmuon4);
444
445 MMuonSearchParCalc muscalc;
446 muscalc.SetFilter(&fmuon1);
447
448 MMuonCalibParCalc mcalc;
449 mcalc.SetFilter(&fmuon2);
450
451 MFillH fillmuon("MHSingleMuon", "", "FillMuon");
452 MFillH fillmpar("MHMuonPar", "", "FillMuonPar");
453 fillmuon.SetFilter(&fmuon2);
454 fillmpar.SetFilter(&fmuon3);
455 fillmuon.SetBit(MFillH::kDoNotDisplay);
456
457 if (fMuonAnalysis)
458 {
459 tlist2.AddToList(&fmuon1);
460 tlist2.AddToList(&muscalc);
461 tlist2.AddToList(&fmuon2);
462 tlist2.AddToList(&fillmuon);
463 tlist2.AddToList(&mcalc);
464 tlist2.AddToList(&fmuon3);
465 tlist2.AddToList(&fillmpar);
466 tlist2.AddToList(&fmuon4);
467 tlist2.AddToList(&writem);
468 }
469
470 // ------------------------------------------------------------
471
472 // Initialize histogram
473 MHSectorVsTime histdc, histrms;
474 histdc.SetNameTime("MTimeCamera");
475 histdc.SetTitle("Average DC currents of all pixels vs time;;<I> [nA]");
476 histdc.SetMinimum(0);
477 histdc.SetMaximum(10);
478 histrms.SetNameTime("MTimeCamera");
479 histrms.SetTitle("Average pedestal rms of all pixels vs time;;<\\sigma_{p}> [phe]");
480 histrms.SetType(5);
481 histrms.SetMinimum(0);
482 histrms.SetMaximum(10);
483
484 /*
485 // Define area index [0=inner, 1=outer]
486 // TArrayI inner(1); inner[0] = 0; histdc.SetAreaIndex(inner);
487 */
488
489 // Task to fill the histogram
490 MFillH filldc(&histdc, "MCameraDC", "FillDC");
491 MFillH fillrms(&histrms, "MPedPhotFromExtractorRndm", "FillPedRms");
492 //MFillH filltst("MHTest", "MTime", "FillTest");
493 filldc.SetNameTab("Currents");
494 fillrms.SetNameTab("MeanRms");
495 //filltst.SetNameTab("Test");
496
497 MFillH fillw1("MHWeather", "MTimeCC", "FillWeather");
498 MFillH fillw2("MHWeather", "MTimePyrometer", "FillPyrometer");
499 fillw2.SetBit(MFillH::kDoNotDisplay);
500 fillw2.SetBit(MFillH::kCanSkip);
501
502 // instantiate camera histogram containers
503 MHCamEvent evtdt(0, "Thresholds", "Average Discriminator Thresholds;;DT [au]");
504 plist.AddToList(&evtdt);
505
506 // instantiate fill tasks
507 MFillH filldt1("Thresholds", "MCameraTH", "FillDT-CC");
508 MFillH filldt2("Thresholds", "MCameraTH", "FillDT-Rec");
509 filldt1.SetNameTab("DT");
510 filldt2.SetBit(MFillH::kDoNotDisplay);
511 filldt2.SetBit(MFillH::kCanSkip);
512
513 MHSectorVsTime histipr;
514
515 histipr.SetNameTime("MTimeTrigger");
516 histipr.SetTitle("Mean of all IPR;;<IPR> [Hz]");
517 histipr.SetMinimum(0);
518 //histipr.SetUseMedian();
519
520 // Task to fill the histogram
521 MFillH fillipr(&histipr, "MTriggerIPR", "FillIPR");
522 fillipr.SetNameTab("IPR");
523
524 MPointingPosCalc pcalc;
525
526 // ------------------------------------------------------------
527
528 tlist.AddToList(fSequence.IsMonteCarlo() ? (MTask*)&readmc : (MTask*)&readreal);
529 tlist.AddToList(&pcalc, fSequence.IsMonteCarlo() ? "Events" : "Drive");
530 //tlist.AddToList(&filltst, "Events");
531 tlist.AddToList(&tlist2, "Events");
532 if (!fSequence.IsMonteCarlo())
533 {
534 // initiate task list
535 tlist.AddToList(&fillw1, "CC");
536 tlist.AddToList(&fillw2, "Pyrometer");
537 tlist.AddToList(&fillp1, "Drive");
538 tlist.AddToList(&fillp2, "Starguider");
539 tlist.AddToList(&fillrms, "Camera");
540 tlist.AddToList(&filldc, "Camera");
541 tlist.AddToList(&fillipr, "Trigger");
542 tlist.AddToList(&filldt1, "CC"); // Old files: Receiver information in CC-Tree (Mars<=2.0)
543 tlist.AddToList(&filldt2, "Rec"); // New files: Receiver information in Rec-Tree (Mars >2.0)
544 }
545 if (!HasNullOut())
546 tlist.AddToList(&write);
547
548 // Create and setup the eventloop
549 MEvtLoop evtloop(fName);
550 evtloop.SetParList(&plist);
551 evtloop.SetDisplay(fDisplay);
552 evtloop.SetLogStream(fLog);
553 if (!SetupEnv(evtloop))
554 return kFALSE;
555
556 // Execute first analysis
557 if (!evtloop.Eventloop(fMaxEvents))
558 {
559 *fLog << err << GetDescriptor() << ": Failed." << endl;
560 return kFALSE;
561 }
562
563 if (!WriteResult())
564 return kFALSE;
565
566 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
567
568 return kTRUE;
569}
Note: See TracBrowser for help on using the repository browser.