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

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