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

Last change on this file since 9428 was 9374, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 19.6 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 MBinning binsd("BinningDist");
177 plist.AddToList(&bins1);
178 plist.AddToList(&bins2);
179 plist.AddToList(&bins3);
180 plist.AddToList(&bins4);
181 plist.AddToList(&bins5);
182 plist.AddToList(&bins6);
183 plist.AddToList(&binsd);
184
185
186 // Setup Tasklist
187 MTaskList tlist;
188 plist.AddToList(&tlist);
189
190 MReadReports readreal;
191 readreal.AddTree("Events", "MTime.", MReadReports::kMaster);
192 readreal.AddTree("Drive", MReadReports::kRequired);
193 readreal.AddTree("Starguider", MReadReports::kRequired);
194 readreal.AddTree("Camera", MReadReports::kRequired);
195 readreal.AddTree("Currents");
196 readreal.AddTree("CC");
197 readreal.AddTree("Rec");
198 readreal.AddTree("Trigger");
199 readreal.AddTree("Pyrometer");
200 readreal.AddFiles(iter);
201
202 MReadMarsFile readmc("Events");
203 readmc.DisableAutoScheme();
204 readmc.AddFiles(iter);
205
206 // ------------------ Setup general tasks ----------------
207
208 MFDeltaT fdeltat;
209 MContinue cont(&fdeltat, "FilterDeltaT", "Filter events with wrong timing");
210 cont.SetInverted();
211
212 MGeomApply apply; // Only necessary to craete geometry
213 MEventRateCalc rate;
214 rate.SetNumEvents(1200);
215
216 MFSoftwareTrigger swtrig;
217 MContinue contsw(&swtrig, "FilterSwTrigger", "Software trigger");
218 contsw.SetInverted();
219
220 MImgCleanStd clean;
221 clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
222
223 MSrcPosCalc poscalc;
224 MHillasCalc hcalc;
225 hcalc.Disable(MHillasCalc::kCalcConc);
226
227 // ------------------ Setup histograms and fill tasks ----------------
228 MHCamEvent evt0a(0, "Cleaned", "Average signal after Cleaning;;S [phe]");
229 MHCamEvent evt0c(0, "Sparkless", "Average signal after Cleaning and Spark cuts;;S [phe]");
230 MHCamEvent evt0d(0, "Sparks", "Average signal after Cleaning for Spark cuts;;S [phe]");
231 MHCamEvent evt0b(0, "UsedPix", "Fraction of Events in which Pixels are used;;Fraction");
232 evt0a.SetErrorSpread(kFALSE);
233 evt0b.SetErrorSpread(kFALSE);
234 evt0c.SetErrorSpread(kFALSE);
235 evt0d.SetErrorSpread(kFALSE);
236 evt0b.SetThreshold(0);
237
238 MFillH fillvs("MHRate", "MTime", "FillEventRate");
239 MFillH fillp1("MHPointing", "MTimeDrive", "FillDrive");
240 MFillH fillp2("MHPointing", "MTimeStarguider", "FillStarguider");
241 fillp1.SetBit(MFillH::kDoNotDisplay);
242 fillp1.SetBit(MFillH::kCanSkip);
243 fillp2.SetBit(MFillH::kCanSkip);
244
245 // Needed in parameter list for ReadEnv
246 MHEffectiveOnTime hontime;
247 plist.AddToList(&hontime);
248
249 MFillH fill0a(&evt0a, "MSignalCam", "FillSignalCam");
250 MFillH fill0b(&evt0b, "MSignalCam", "FillCntUsedPixels");
251 MFillH fill0c(&evt0c, "MSignalCam", "FillSignalCamSparkless");
252 MFillH fill0d(&evt0d, "MSignalCam", "FillSignalCamSparks");
253 MFillH fill1("MHHillas", "MHillas", "FillHillas");
254 MFillH fill2("MHHillasExt", "", "FillHillasExt");
255 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
256 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
257 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
258 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
259
260 //fillvs.SetNameTab("Rate");
261 fill9.SetNameTab("EffOnTime");
262 fill0c.SetNameTab("Sparkless");
263 fill0d.SetNameTab("Sparks");
264
265 // FIXME: This should be replaced by a cut working for all triggers!
266 MTriggerPattern par; // An empty trigger pattern for older files
267 plist.AddToList(&par); // without MTriggerPattern stored in the file
268
269 // For the effective on-time calculation we don't want SUM-only events
270 MFTriggerPattern fsum;
271 fsum.SetDefault(kTRUE);
272 fsum.DenyAll();
273 fsum.RequireTriggerLvl1();
274 fsum.AllowTriggerLvl2();
275 fsum.AllowSumTrigger();
276 fill9.SetFilter(&fsum);
277
278 // Plot the trigger pattern rates vs. run-number
279 MH3 hrate("MRawRunHeader.GetFileID", "MTriggerPattern.GetUnprescaled");
280 if (fSequence.IsMonteCarlo())
281 hrate.SetWeight("100./MMcRunHeader.fNumSimulatedShowers");
282 else
283 hrate.SetWeight("1./TMath::Max(MRawRunHeader.GetRunLength,1)");
284 hrate.SetName("Rate");
285 hrate.SetTitle("Event rate after cleaning [Hz];File Id;Trigger Type;");
286 hrate.InitLabels(MH3::kLabelsX);
287 hrate.DefaultLabelY("ERROR");
288 hrate.DefineLabelY( 0, "0"); // 0: No pattern
289 hrate.DefineLabelY( 1, "Trig"); // 1: Lvl1
290 hrate.DefineLabelY( 4, "Trig"); // 4: Lvl2
291 hrate.DefineLabelY( 5, "Trig"); // Lvl2+Lvl1
292 hrate.DefineLabelY(32, "Sum"); // 32: Sum
293 hrate.DefineLabelY(33, "Trig"); // Sum+Lvl1
294 hrate.DefineLabelY(36, "Trig"); // Sum+Lvl2
295 hrate.DefineLabelY(37, "Trig"); // Sum+Lvl1+Lvl2
296
297 MFillH frate(&hrate, "", "FillRate");
298 frate.SetDrawOption("box");
299
300 // ------------------ Setup write task ----------------
301
302 // Effective on-time need its own not to be skipped by (eg) image cleaning
303 // Muons needs its own to have a unique SetReadyToSave
304 const TString rule(Form("s/(([0-9]+_)?(M[12]_)?[0-9.]+)_Y_(.*[.]root)$/%s\\/$1_I_$4/", Esc(fPathOut).Data()));
305 MWriteRootFile write( 2, rule, fOverwrite?"RECREATE":"NEW", "Image parameters");
306 MWriteRootFile writet(2, rule, fOverwrite?"RECREATE":"NEW", "Image parameters"); // EffectiveOnTime
307 MWriteRootFile writem(2, rule, fOverwrite?"RECREATE":"NEW", "Image parameters"); // Muons
308 writem.SetName("WriteMuons");
309
310 // Data
311 write.AddContainer("MHillas", "Events");
312 write.AddContainer("MHillasExt", "Events");
313 write.AddContainer("MHillasSrc", "Events");
314 write.AddContainer("MImagePar", "Events");
315 write.AddContainer("MNewImagePar", "Events");
316 write.AddContainer("MRawEvtHeader", "Events");
317 write.AddContainer("MPointingPos", "Events");
318 write.AddContainer("MTriggerPattern", "Events");
319
320 // Run Header
321 write.AddContainer("MRawRunHeader", "RunHeaders");
322// write.AddContainer("MBadPixelsCam", "RunHeaders");
323 write.AddContainer("MGeomCam", "RunHeaders");
324 write.AddContainer("MObservatory", "RunHeaders");
325
326 // Muon Setup
327 write.AddContainer("BinningRadius", "RunHeaders");
328 write.AddContainer("BinningArcWidth", "RunHeaders");
329 write.AddContainer("BinningRingBroadening", "RunHeaders");
330 write.AddContainer("BinningSizeVsArcRadius", "RunHeaders");
331 write.AddContainer("MMuonSetup", "RunHeaders");
332
333 if (fSequence.IsMonteCarlo())
334 {
335 // Monte Carlo Data
336 write.AddContainer("MMcEvt", "Events");
337 write.AddContainer("MMcTrig", "Events", kFALSE);
338 write.AddContainer("MSrcPosCam", "Events");
339 // Monte Carlo Run Headers
340 write.AddContainer("MMcRunHeader", "RunHeaders");
341 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
342 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
343 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
344 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
345 }
346 else
347 {
348 // Event time
349 write.AddContainer("MTime", "Events");
350
351 // Slow-control trees with time information
352 write.AddTree("Drive");
353 write.AddTree("Starguider", kFALSE);
354 write.AddTree("Pyrometer", kFALSE);
355 writet.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
356 writet.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
357 }
358
359 // What to write in muon tree
360 writem.AddContainer("MMuonSearchPar", "Muons");
361 writem.AddContainer("MMuonCalibPar", "Muons");
362 writem.AddContainer("MHillas", "Muons");
363 writem.AddContainer("MHillasExt", "Muons");
364 writem.AddContainer("MHillasSrc", "Muons");
365 writem.AddContainer("MImagePar", "Muons");
366 writem.AddContainer("MNewImagePar", "Muons");
367 writem.AddContainer("MRawEvtHeader", "Muons");
368 writem.AddContainer("MPointingPos", "Muons");
369 if (fSequence.IsMonteCarlo())
370 {
371 // Monte Carlo Data
372 writem.AddContainer("MMcEvt", "Muons");
373 writem.AddContainer("MMcTrig", "Muons", kFALSE);
374 }
375
376 if (fSequence.IsMonteCarlo())
377 {
378 if (fMuonAnalysis)
379 writem.AddCopySource("OriginalMC");
380 else
381 write.AddCopySource("OriginalMC");
382 }
383
384 MTaskList tlist2("Events");
385 tlist2.AddToList(&apply);
386 if (!fSequence.IsMonteCarlo())
387 tlist2.AddToList(&cont);
388 tlist2.AddToList(&contsw);
389 if (!fSequence.IsMonteCarlo())
390 {
391 // Calibration events don't enter star at all.
392 tlist2.AddToList(&rate);
393 tlist2.AddToList(&fillvs);
394 tlist2.AddToList(&fsum);
395 tlist2.AddToList(&fill9);
396 tlist2.AddToList(&writet);
397 }
398
399 // Spark cut:
400 // This cut is a little bit different from the default cut in the
401 // ganymed.rc, because the cut in ganymed.rc also suppresses a
402 // little background, while the cut here only shows sparks
403 MFDataPhrase fsparks("log10(MNewImagePar.fConcCOG)<-0.45*(log10(MHillas.fSize)-2.5)-0.24", "SparkCut");
404 //fill0b.SetFilter(&fsparks);
405 fill0c.SetFilter(&fsparks);
406
407 // Inverted spark cut (need not to be a member of the task list
408 // because it fsparks is
409 MFilterList fnsparks(&fsparks);
410 fill0d.SetFilter(&fnsparks);
411
412 tlist2.AddToList(&clean);
413 tlist2.AddToList(&poscalc);
414
415 MFillH fillsp("MHSrcPosCam", "MSrcPosCam", "FillSrcPosCam");
416 fillsp.SetNameTab("Src");
417 if (fSequence.IsMonteCarlo())
418 tlist2.AddToList(&fillsp);
419
420
421 tlist2.AddToList(&hcalc);
422 tlist2.AddToList(&fsparks);
423 tlist2.AddToList(&fill0a);
424 tlist2.AddToList(&fill0c);
425 tlist2.AddToList(&fill0d);
426 tlist2.AddToList(&fill0b);
427 tlist2.AddToList(&frate);
428 tlist2.AddToList(&fill1);
429 tlist2.AddToList(&fill2);
430 tlist2.AddToList(&fill3);
431 tlist2.AddToList(&fill4);
432 tlist2.AddToList(&fill5);
433
434 // ----------------------- Muon Analysis ----------------------
435 // Filter to start muon analysis
436 MFDataPhrase fmuon1("MHillas.fSize>150 && MNewImagePar.fConcCOG<0.1", "MuonPreCut");
437 // Filter to calculate further muon parameters
438 MFDataPhrase fmuon2("(MMuonSearchPar.fRadius*MGeomCam.fConvMm2Deg>0.6) && (MMuonSearchPar.fRadius*MGeomCam.fConvMm2Deg<1.35) &&"
439 "(MMuonSearchPar.fDeviation*MGeomCam.fConvMm2Deg<0.152)", "MuonSearchCut");
440 // Filter to fill the MHMuonPar
441 MFDataPhrase fmuon3("(MMuonCalibPar.fArcPhi>190) && (MMuonSearchPar.fDeviation*MGeomCam.fConvMm2Deg<0.118) &&"
442 "(MMuonCalibPar.fArcWidth<0.20) && (MMuonCalibPar.fArcWidth>0.04) &&"
443 "MMuonCalibPar.fRelTimeSigma<1.5",
444 "MuonFinalCut");
445 // Filter to write Muons to Muon tree
446 MFDataMember fmuon4("MMuonCalibPar.fArcPhi", '>', -0.5, "MuonWriteCut");
447 writem.SetFilter(&fmuon4);
448
449 MMuonSearchParCalc muscalc;
450 muscalc.SetFilter(&fmuon1);
451
452 MMuonCalibParCalc mcalc;
453 mcalc.SetFilter(&fmuon2);
454
455 MFillH fillmuon("MHSingleMuon", "", "FillMuon");
456 MFillH fillmpar("MHMuonPar", "", "FillMuonPar");
457 fillmuon.SetFilter(&fmuon2);
458 fillmpar.SetFilter(&fmuon3);
459 fillmuon.SetBit(MFillH::kDoNotDisplay);
460
461 if (fMuonAnalysis)
462 {
463 tlist2.AddToList(&fmuon1);
464 tlist2.AddToList(&muscalc);
465 tlist2.AddToList(&fmuon2);
466 tlist2.AddToList(&fillmuon);
467 tlist2.AddToList(&mcalc);
468 tlist2.AddToList(&fmuon3);
469 tlist2.AddToList(&fillmpar);
470 tlist2.AddToList(&fmuon4);
471 tlist2.AddToList(&writem);
472 }
473
474 // ------------------------------------------------------------
475
476 // Initialize histogram
477 MHSectorVsTime histdc, histrms;
478 histdc.SetNameTime("MTimeCamera");
479 histdc.SetTitle("Average DC currents of all pixels vs time;;<I> [nA]");
480 histdc.SetMinimum(0);
481 histdc.SetMaximum(10);
482 histrms.SetNameTime("MTimeCamera");
483 histrms.SetTitle("Average pedestal rms of all pixels vs time;;<\\sigma_{p}> [phe]");
484 histrms.SetType(5);
485 histrms.SetMinimum(0);
486 histrms.SetMaximum(10);
487
488 /*
489 // Define area index [0=inner, 1=outer]
490 // TArrayI inner(1); inner[0] = 0; histdc.SetAreaIndex(inner);
491 */
492
493 // Task to fill the histogram
494 MFillH filldc(&histdc, "MCameraDC", "FillDC");
495 MFillH fillrms(&histrms, "MPedPhotFromExtractorRndm", "FillPedRms");
496 //MFillH filltst("MHTest", "MTime", "FillTest");
497 filldc.SetNameTab("Currents");
498 fillrms.SetNameTab("MeanRms");
499 //filltst.SetNameTab("Test");
500
501 MFillH fillw1("MHWeather", "MTimeCC", "FillWeather");
502 MFillH fillw2("MHWeather", "MTimePyrometer", "FillPyrometer");
503 fillw2.SetBit(MFillH::kDoNotDisplay);
504 fillw2.SetBit(MFillH::kCanSkip);
505
506 // instantiate camera histogram containers
507 MHCamEvent evtdt(0, "Thresholds", "Average Discriminator Thresholds;;DT [au]");
508 plist.AddToList(&evtdt);
509
510 // instantiate fill tasks
511 MFillH filldt1("Thresholds", "MCameraTH", "FillDT-CC");
512 MFillH filldt2("Thresholds", "MCameraTH", "FillDT-Rec");
513 filldt1.SetNameTab("DT");
514 filldt2.SetBit(MFillH::kDoNotDisplay);
515 filldt2.SetBit(MFillH::kCanSkip);
516
517 MHSectorVsTime histipr;
518
519 histipr.SetNameTime("MTimeTrigger");
520 histipr.SetTitle("Mean of all IPR;;<IPR> [Hz]");
521 histipr.SetMinimum(0);
522 //histipr.SetUseMedian();
523
524 // Task to fill the histogram
525 MFillH fillipr(&histipr, "MTriggerIPR", "FillIPR");
526 fillipr.SetNameTab("IPR");
527
528 MPointingPosCalc pcalc;
529
530 // ------------------------------------------------------------
531
532 tlist.AddToList(fSequence.IsMonteCarlo() ? (MTask*)&readmc : (MTask*)&readreal);
533 tlist.AddToList(&pcalc, fSequence.IsMonteCarlo() ? "Events" : "Drive");
534 //tlist.AddToList(&filltst, "Events");
535 tlist.AddToList(&tlist2, "Events");
536 if (!fSequence.IsMonteCarlo())
537 {
538 // initiate task list
539 tlist.AddToList(&fillw1, "CC");
540 tlist.AddToList(&fillw2, "Pyrometer");
541 tlist.AddToList(&fillp1, "Drive");
542 tlist.AddToList(&fillp2, "Starguider");
543 tlist.AddToList(&fillrms, "Camera");
544 tlist.AddToList(&filldc, "Camera");
545 tlist.AddToList(&fillipr, "Trigger");
546 tlist.AddToList(&filldt1, "CC"); // Old files: Receiver information in CC-Tree (Mars<=2.0)
547 tlist.AddToList(&filldt2, "Rec"); // New files: Receiver information in Rec-Tree (Mars >2.0)
548 }
549 if (!HasNullOut())
550 tlist.AddToList(&write);
551
552 // Create and setup the eventloop
553 MEvtLoop evtloop(fName);
554 evtloop.SetParList(&plist);
555 evtloop.SetDisplay(fDisplay);
556 evtloop.SetLogStream(fLog);
557 if (!SetupEnv(evtloop))
558 return kFALSE;
559
560 // Execute first analysis
561 if (!evtloop.Eventloop(fMaxEvents))
562 {
563 *fLog << err << GetDescriptor() << ": Failed." << endl;
564 return kFALSE;
565 }
566
567 if (!WriteResult())
568 return kFALSE;
569
570 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
571
572 return kTRUE;
573}
Note: See TracBrowser for help on using the repository browser.