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

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