source: tags/Mars-V0.10.3/mjobs/MJStar.cc

Last change on this file was 8111, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 15.0 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-2004
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#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MDirIter.h"
41#include "MParList.h"
42#include "MTaskList.h"
43#include "MEvtLoop.h"
44
45#include "MStatusDisplay.h"
46
47#include "MHSectorVsTime.h"
48#include "MHCamEvent.h"
49#include "MBinning.h"
50
51#include "MReadReports.h"
52#include "MReadMarsFile.h"
53#include "MF.h"
54#include "MFDataMember.h"
55#include "MFDeltaT.h"
56#include "MFSoftwareTrigger.h"
57#include "MContinue.h"
58#include "MGeomApply.h"
59#include "MEventRateCalc.h"
60#include "MImgCleanStd.h"
61#include "MSrcPosCalc.h"
62#include "MSrcPosCorrect.h"
63#include "MHillasCalc.h"
64#include "MMuonSearchParCalc.h"
65#include "MMuonCalibParCalc.h"
66#include "MFillH.h"
67#include "MWriteRootFile.h"
68
69#include "MMuonSetup.h"
70#include "MObservatory.h"
71#include "MPointingPosCalc.h"
72
73ClassImp(MJStar);
74
75using namespace std;
76
77// --------------------------------------------------------------------------
78//
79// Default constructor.
80//
81// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
82//
83MJStar::MJStar(const char *name, const char *title) : fMuonAnalysis(kTRUE)
84{
85 fName = name ? name : "MJStar";
86 fTitle = title ? title : "Standard analysis and reconstruction";
87}
88
89Bool_t MJStar::CheckEnvLocal()
90{
91 DisableMuonAnalysis(!GetEnv("MuonAnalysis", fMuonAnalysis));
92 return kTRUE;
93}
94
95Bool_t MJStar::WriteResult()
96{
97 if (fPathOut.IsNull())
98 {
99 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
100 return kTRUE;
101 }
102
103 const TString oname = Form("%s/star%08d.root", (const char*)fPathOut, fSequence.GetSequence());
104
105 *fLog << inf << "Writing to file: " << oname << endl;
106
107 TFile file(oname, "RECREATE");
108
109 *fLog << inf << " - MStatusDisplay..." << flush;
110 if (fDisplay && fDisplay->Write()<=0)
111 {
112 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
113 return kFALSE;
114 }
115 *fLog << inf << "ok." << endl;
116
117 return kTRUE;
118}
119
120Bool_t MJStar::Process(Bool_t ismc)
121{
122 if (!fSequence.IsValid())
123 {
124 *fLog << err << "ERROR - Sequence invalid!" << endl;
125 return kFALSE;
126 }
127
128 //if (!CheckEnv())
129 // return kFALSE;
130
131 CheckEnv();
132
133 // --------------------------------------------------------------------------------
134
135 *fLog << inf;
136 fLog->Separator(GetDescriptor());
137 *fLog << "Calculate image parameters of sequence ";
138 *fLog << fSequence.GetName() << endl;
139 *fLog << endl;
140
141 // --------------------------------------------------------------------------------
142
143 MDirIter iter;
144 const Int_t n0 = fSequence.SetupDatRuns(iter, MSequence::kCalibrated, fPathData);
145 const Int_t n1 = fSequence.GetNumDatRuns();
146 if (n0==0)
147 {
148 *fLog << err << "ERROR - No input files of sequence found!" << endl;
149 return kFALSE;
150 }
151 if (n0!=n1)
152 {
153 *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
154 if (fLog->GetDebugLevel()>4)
155 {
156 *fLog << dbg << "Files which are searched:" << endl;
157 iter.Print();
158 }
159 return kFALSE;
160 }
161
162 // Setup Parlist
163 MParList plist;
164 plist.AddToList(this); // take care of fDisplay!
165
166 MObservatory obs;
167 plist.AddToList(&obs);
168
169 MMuonSetup muonsetup;
170 plist.AddToList(&muonsetup);
171
172 // Setup binnings for muon analysis
173 MBinning bins1("BinningRadius");
174 MBinning bins2("BinningArcWidth");
175 MBinning bins3("BinningRingBroadening");
176 MBinning bins4("BinningSizeVsArcRadius");
177 MBinning bins5("BinningMuonWidth");
178 MBinning bins6("BinningArcPhi");
179 plist.AddToList(&bins1);
180 plist.AddToList(&bins2);
181 plist.AddToList(&bins3);
182 plist.AddToList(&bins4);
183 plist.AddToList(&bins5);
184 plist.AddToList(&bins6);
185
186
187 // Setup Tasklist
188 MTaskList tlist;
189 plist.AddToList(&tlist);
190
191 MReadReports readreal;
192 readreal.AddTree("Events", "MTime.", MReadReports::kMaster);
193 readreal.AddTree("Drive", MReadReports::kRequired);
194 readreal.AddTree("Starguider", MReadReports::kRequired);
195 readreal.AddTree("Currents", MReadReports::kRequired);
196 readreal.AddTree("CC");
197 readreal.AddFiles(iter);
198
199 MReadMarsFile readmc("Events");
200 readmc.DisableAutoScheme();
201 readmc.AddFiles(iter);
202
203 // ------------------ Setup general tasks ----------------
204
205 MFDeltaT fdeltat;
206 MContinue cont(&fdeltat, "FilterDeltaT", "Filter events with wrong timing");
207 cont.SetInverted();
208
209 MGeomApply apply; // Only necessary to craete geometry
210 MEventRateCalc rate;
211 rate.SetNumEvents(1200);
212
213 MFSoftwareTrigger swtrig;
214 MContinue contsw(&swtrig, "FilterSwTrigger", "Software trigger");
215 contsw.SetInverted();
216
217 MImgCleanStd clean;
218 clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
219
220 MSrcPosCalc poscalc;
221 MHillasCalc hcalc;
222 hcalc.Disable(MHillasCalc::kCalcConc);
223
224 // ------------------ Setup histograms and fill tasks ----------------
225 MHCamEvent evt0a(0, "Cleaned", "Signal after Cleaning;;S [\\gamma]");
226 MHCamEvent evt0b(0, "UsedPix", "Fraction of Events in which Pixels are used;;Fraction");
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 MFillH fill0a(&evt0a, "MSignalCam", "FillSignalCam");
237 MFillH fill0b(&evt0b, "MSignalCam", "FillCntUsedPixels");
238 MFillH fill1("MHHillas", "MHillas", "FillHillas");
239 MFillH fill2("MHHillasExt", "", "FillHillasExt");
240 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
241 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
242 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
243 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
244
245 //fillvs.SetNameTab("Rate");
246 fill9.SetNameTab("EffOnTime");
247
248 // ------------------ Setup write task ----------------
249
250 // Effective on-time need its own not to be skipped by (eg) image cleaning
251 // Muons needs its own to have a unique SetReadyToSave
252 const TString rule(Form("%s{s/_Y_/_I_}", fPathOut.Data()));
253 MWriteRootFile write( 2, rule, fOverwrite?"RECREATE":"NEW");
254 MWriteRootFile writet(2, rule, fOverwrite?"RECREATE":"NEW"); // EffectiveOnTime
255 MWriteRootFile writem(2, rule, fOverwrite?"RECREATE":"NEW"); // Muons
256 writem.SetName("WriteMuons");
257
258 // Data
259 write.AddContainer("MHillas", "Events");
260 write.AddContainer("MHillasExt", "Events");
261 write.AddContainer("MHillasSrc", "Events");
262 write.AddContainer("MImagePar", "Events");
263 write.AddContainer("MNewImagePar", "Events");
264 write.AddContainer("MRawEvtHeader", "Events");
265 write.AddContainer("MPointingPos", "Events");
266
267 // Run Header
268 write.AddContainer("MRawRunHeader", "RunHeaders");
269 write.AddContainer("MBadPixelsCam", "RunHeaders");
270 write.AddContainer("MGeomCam", "RunHeaders");
271 write.AddContainer("MObservatory", "RunHeaders");
272
273 // Muon Setup
274 write.AddContainer("BinningRadius", "RunHeaders");
275 write.AddContainer("BinningArcWidth", "RunHeaders");
276 write.AddContainer("BinningRingBroadening", "RunHeaders");
277 write.AddContainer("BinningSizeVsArcRadius", "RunHeaders");
278 write.AddContainer("MMuonSetup", "RunHeaders");
279
280 if (ismc)
281 {
282 // Monte Carlo Data
283 write.AddContainer("MMcEvt", "Events");
284 write.AddContainer("MMcTrig", "Events");
285 // Monte Carlo Run Headers
286 write.AddContainer("MMcRunHeader", "RunHeaders");
287 write.AddContainer("MMcTrigHeader", "RunHeaders");
288 write.AddContainer("MMcFadcHeader", "RunHeaders");
289 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
290 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
291 }
292 else
293 {
294 write.AddContainer("MTime", "Events");
295 // Drive
296 write.AddContainer("MReportDrive", "Drive");
297 write.AddContainer("MTimeDrive", "Drive");
298 // Starguider
299 write.AddContainer("MReportStarguider", "Starguider", kFALSE);
300 write.AddContainer("MTimeStarguider", "Starguider", kFALSE);
301 // Effective On Time
302 writet.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
303 writet.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
304 }
305
306 // What to write in muon tree
307 writem.AddContainer("MMuonSearchPar", "Muons");
308 writem.AddContainer("MMuonCalibPar", "Muons");
309 writem.AddContainer("MHillas", "Muons");
310 writem.AddContainer("MHillasExt", "Muons");
311 writem.AddContainer("MHillasSrc", "Muons");
312 writem.AddContainer("MImagePar", "Muons");
313 writem.AddContainer("MNewImagePar", "Muons");
314 writem.AddContainer("MRawEvtHeader", "Muons");
315 writem.AddContainer("MPointingPos", "Muons");
316 if (ismc)
317 {
318 // Monte Carlo Data
319 writem.AddContainer("MMcEvt", "Muons");
320 writem.AddContainer("MMcTrig", "Muons");
321 }
322
323 if (ismc)
324 if (fMuonAnalysis)
325 writem.AddCopySource("OriginalMC");
326 else
327 write.AddCopySource("OriginalMC");
328
329 MTaskList tlist2("Events");
330 tlist2.AddToList(&apply);
331 if (!ismc)
332 tlist2.AddToList(&cont);
333 tlist2.AddToList(&contsw);
334 if (!ismc)
335 {
336 // Calibration events don't enter star at all.
337 tlist2.AddToList(&rate);
338 tlist2.AddToList(&fillvs);
339 tlist2.AddToList(&fill9);
340 tlist2.AddToList(&writet);
341 }
342 tlist2.AddToList(&clean);
343 tlist2.AddToList(&fill0a);
344 tlist2.AddToList(&fill0b);
345 tlist2.AddToList(&poscalc);
346 tlist2.AddToList(&hcalc);
347 tlist2.AddToList(&fill1);
348 tlist2.AddToList(&fill2);
349 tlist2.AddToList(&fill3);
350 tlist2.AddToList(&fill4);
351 tlist2.AddToList(&fill5);
352
353 // ----------------------- Muon Analysis ----------------------
354 // Filter to start muon analysis
355 MF fmuon1("MHillas.fSize>150", "MuonPreCut");
356 // Filter to calculate further muon parameters
357 MF fmuon2("(MMuonSearchPar.fRadius>180) && (MMuonSearchPar.fRadius<400) &&"
358 "(MMuonSearchPar.fDeviation<45)", "MuonSearchCut");
359 // Filter to fill the MHMuonPar
360 MF fmuon3("(MMuonCalibPar.fArcPhi>190) && (MMuonSearchPar.fDeviation<35) &&"
361 "(MMuonCalibPar.fArcWidth<0.20) && (MMuonCalibPar.fArcWidth>0.04)",
362 "MuonFinalCut");
363 // Filter to write Muons to Muon tree
364 MFDataMember fmuon4("MMuonCalibPar.fArcPhi", '>', -0.5, "MuonWriteCut");
365 writem.SetFilter(&fmuon4);
366
367 MMuonSearchParCalc muscalc;
368 muscalc.SetFilter(&fmuon1);
369
370 MMuonCalibParCalc mcalc;
371 mcalc.SetFilter(&fmuon2);
372
373 MFillH fillmuon("MHSingleMuon", "", "FillMuon");
374 MFillH fillmpar("MHMuonPar", "", "FillMuonPar");
375 fillmuon.SetFilter(&fmuon2);
376 fillmpar.SetFilter(&fmuon3);
377 fillmuon.SetBit(MFillH::kDoNotDisplay);
378
379 if (fMuonAnalysis)
380 {
381 tlist2.AddToList(&fmuon1);
382 tlist2.AddToList(&muscalc);
383 tlist2.AddToList(&fmuon2);
384 tlist2.AddToList(&fillmuon);
385 tlist2.AddToList(&mcalc);
386 tlist2.AddToList(&fmuon3);
387 tlist2.AddToList(&fillmpar);
388 tlist2.AddToList(&fmuon4);
389 tlist2.AddToList(&writem);
390 }
391
392 // ------------------------------------------------------------
393
394 // Initialize histogram
395 MHSectorVsTime histdc, histrms;
396 histdc.SetNameTime("MTimeCurrents");
397 histdc.SetTitle("Mean of all DC Currents;;<I> [nA]");
398 histdc.SetMinimum(0);
399 histdc.SetMaximum(10);
400 histrms.SetNameTime("MTimeCurrents");
401 histrms.SetTitle("Mean pedestal rms of all pixels;;<\\sigma_{p}> [phe]");
402 histrms.SetType(5);
403 histrms.SetMinimum(0);
404 histrms.SetMaximum(10);
405
406 /*
407 // Define area index [0=inner, 1=outer]
408 // TArrayI inner(1); inner[0] = 0; histdc.SetAreaIndex(inner);
409 */
410
411 // Task to fill the histogram
412 MFillH filldc(&histdc, "MCameraDC", "FillDC");
413 MFillH fillrms(&histrms, "MPedPhotFromExtractorRndm", "FillPedRms");
414 //MFillH filltst("MHTest", "MTime", "FillTest");
415 filldc.SetNameTab("Currents");
416 fillrms.SetNameTab("MeanRms");
417 //filltst.SetNameTab("Test");
418
419 MFillH fillw("MHWeather", "MTimeCC", "FillWeather");
420
421 MPointingPosCalc pcalc;
422
423 // ------------------------------------------------------------
424
425 tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
426 tlist.AddToList(&pcalc, ismc ? "Events" : "Drive");
427 //tlist.AddToList(&filltst, "Events");
428 tlist.AddToList(&tlist2, "Events");
429 if (!ismc)
430 {
431 tlist.AddToList(&fillw, "CC");
432 tlist.AddToList(&fillp1, "Drive");
433 tlist.AddToList(&fillp2, "Starguider");
434 tlist.AddToList(&filldc, "Currents");
435 tlist.AddToList(&fillrms, "Currents");
436 }
437 tlist.AddToList(&write);
438
439 // Create and setup the eventloop
440 MEvtLoop evtloop(fName);
441 evtloop.SetParList(&plist);
442 evtloop.SetDisplay(fDisplay);
443 evtloop.SetLogStream(fLog);
444 if (!SetupEnv(evtloop))
445 return kFALSE;
446
447 // Execute first analysis
448 if (!evtloop.Eventloop(fMaxEvents))
449 {
450 *fLog << err << GetDescriptor() << ": Failed." << endl;
451 return kFALSE;
452 }
453
454 if (!WriteResult())
455 return kFALSE;
456
457 *fLog << all << GetDescriptor() << ": Done." << endl;
458 *fLog << endl << endl;
459
460 return kTRUE;
461}
Note: See TracBrowser for help on using the repository browser.