source: trunk/Mars/mjobs/MJSimulation.cc@ 17737

Last change on this file since 17737 was 17737, checked in by tbretz, 11 years ago
Unified the two SetupCommonFileStructure.
File size: 34.7 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/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJSimulation
28//
29//
30// Force reading a corsika file even if the footer (RUNE-section) is missing
31// by setting fForceMode to kTRUE or from the resource file by
32//
33// ForceMode: Yes
34//
35//
36// To switch off the simulation of the camera electronics, use:
37//
38// Camera: Off
39//
40// Note, that the border of the camera and the propertied of the cones
41// are still simulated (simply because it is fast). Furthermore, this
42// switches off the trigger for the output, i.e. all data which deposits
43// at least one photon in at least one pixel is written to the output file.
44//
45//
46// In case of a pedestal or calibration run the artificial trigger can
47// be "switched off" and the cosmics trrigger "switched on" by setting
48// fForceTrigger to kTRUE or from the resource file by
49//
50// ForceTrigger: Yes
51//
52//
53/////////////////////////////////////////////////////////////////////////////
54#include "MJSimulation.h"
55
56#include <TEnv.h>
57#include <TCanvas.h>
58
59// Core
60#include "MLog.h"
61#include "MLogManip.h"
62
63#include "MArgs.h"
64#include "MDirIter.h"
65#include "MParList.h"
66#include "MTaskList.h"
67#include "MEvtLoop.h"
68
69#include "MStatusDisplay.h"
70
71// Tasks
72#include "MCorsikaRead.h"
73#include "MContinue.h"
74#include "MFillH.h"
75#include "MGeomApply.h"
76#include "MParameterCalc.h"
77#include "MHillasCalc.h"
78#include "MImgCleanStd.h"
79#include "MWriteRootFile.h"
80#include "MWriteFitsFile.h"
81
82#include "MSimMMCS.h"
83#include "MSimAbsorption.h"
84#include "MSimAtmosphere.h"
85#include "MSimReflector.h"
86#include "MSimPointingPos.h"
87#include "MSimPSF.h"
88#include "MSimGeomCam.h"
89#include "MSimSignalCam.h"
90#include "MSimAPD.h"
91#include "MSimExcessNoise.h"
92#include "MSimCamera.h"
93#include "MSimTrigger.h"
94#include "MSimReadout.h"
95#include "MSimRandomPhotons.h"
96#include "MSimBundlePhotons.h"
97#include "MSimCalibrationSignal.h"
98
99// Histograms
100#include "MBinning.h"
101
102#include "MHn.h"
103#include "MHCamera.h"
104#include "MHCamEvent.h"
105#include "MHPhotonEvent.h"
106
107// Container
108#include "MRawRunHeader.h"
109#include "MParameters.h"
110#include "MReflector.h"
111#include "MParEnv.h"
112#include "MSpline3.h"
113#include "MParSpline.h"
114#include "MGeomCam.h"
115
116#include "MPedestalCam.h"
117#include "MPedestalPix.h"
118
119ClassImp(MJSimulation);
120
121using namespace std;
122
123// --------------------------------------------------------------------------
124//
125// Default constructor.
126//
127// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
128//
129MJSimulation::MJSimulation(const char *name, const char *title)
130 : fForceMode(kFALSE), fCamera(kTRUE), fForceTrigger(kFALSE),
131 fWriteFitsFile(kFALSE), fOperationMode(kModeData), fRunNumber(-1)
132{
133 fName = name ? name : "MJSimulation";
134 fTitle = title ? title : "Standard analysis and reconstruction";
135}
136
137Bool_t MJSimulation::CheckEnvLocal()
138{
139 fForceMode = GetEnv("ForceMode", fForceMode);
140 fForceTrigger = GetEnv("ForceTrigger", fForceTrigger);
141 fCamera = GetEnv("Camera", fCamera);
142
143 return kTRUE;
144}
145/*
146TString MJSimulation::GetOutFile(const MSequence &seq) const
147{
148 return seq.IsValid() ? Form("ceres%08d.root", seq.GetSequence()) : "ceres.root";
149}
150*/
151
152Bool_t MJSimulation::WriteResult(const MParList &plist, const MSequence &seq, Int_t num)
153{
154 if (fPathOut.IsNull())
155 {
156 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
157 return kTRUE;
158 }
159
160 TObjArray cont;
161 cont.Add(const_cast<TEnv*>(GetEnv()));
162 if (seq.IsValid())
163 cont.Add(const_cast<MSequence*>(&seq));
164
165 cont.Add(plist.FindObject("PulseShape"));
166 cont.Add(plist.FindObject("Reflector"));
167 cont.Add(plist.FindObject("MGeomCam"));
168 cont.Add(plist.FindObject("GeomCones"));
169
170 TNamed cmdline("CommandLine", fCommandLine.Data());
171 cont.Add(&cmdline);
172
173 if (fDisplay)
174 {
175 TString title = "-- Ceres";
176 if (seq.IsValid())
177 {
178 title += ": ";
179 title += seq.GetSequence();
180 }
181 title += " --";
182 fDisplay->SetTitle("Ceres", kFALSE);
183
184 cont.Add(fDisplay);
185 }
186
187 const TString name = Form("ceres%08d.root", num);
188 return WriteContainer(cont, name, "RECREATE");
189}
190
191void MJSimulation::SetupHist(MHn &hist) const
192{
193 hist.AddHist("MCorsikaEvtHeader.fTotalEnergy");
194 hist.InitName("Energy");
195 hist.InitTitle("Energy;E [GeV]");
196 hist.SetLog(kTRUE, kTRUE, kFALSE);
197
198 hist.AddHist("MPhotonEvent.GetNumExternal");
199 hist.InitName("Size");
200 hist.InitTitle("Size;S [#]");
201 hist.SetLog(kTRUE, kTRUE, kFALSE);
202
203 /*
204 hist.AddHist("-MCorsikaEvtHeader.fX/100","-MCorsikaEvtHeader.fY/100");
205 hist.SetDrawOption("colz");
206 hist.InitName("Impact;Impact;Impact");
207 hist.InitTitle("Impact;West <--> East [m];South <--> North [m]");
208 hist.SetAutoRange();
209 */
210
211 hist.AddHist("MCorsikaEvtHeader.GetImpact/100");
212 hist.InitName("Impact");
213 hist.InitTitle("Impact;Impact [m]");
214 hist.SetAutoRange();
215
216 hist.AddHist("MCorsikaEvtHeader.fFirstInteractionHeight/100000");
217 hist.InitName("Height");
218 hist.InitTitle("FirstInteractionHeight;h [km]");
219
220 hist.AddHist("(MCorsikaEvtHeader.fAz+MCorsikaRunHeader.fMagneticFieldAz)*TMath::RadToDeg()", "MCorsikaEvtHeader.fZd*TMath::RadToDeg()");
221 hist.InitName("SkyOrigin;Az;Zd");
222 hist.InitTitle("Sky Origin;Az [\\circ];Zd [\\circ]");
223 hist.SetDrawOption("colz");
224 hist.SetAutoRange();
225
226 hist.AddHist("IncidentAngle.fVal");
227 hist.InitName("ViewCone");
228 hist.InitTitle("Incident Angle;\\alpha [\\circ]");
229}
230
231template<class T>
232void MJSimulation::SetupCommonFileStructure(T &write) const
233{
234 // Common run headers
235 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
236 write.AddContainer("MCorsikaRunHeader", "RunHeaders", kFALSE);
237 write.AddContainer("MRawRunHeader", "RunHeaders");
238 write.AddContainer("MGeomCam", "RunHeaders");
239 write.AddContainer("MMcRunHeader", "RunHeaders");
240
241 // Common events
242 write.AddContainer("MCorsikaEvtHeader", "Events", kFALSE);
243 write.AddContainer("MRawEvtHeader", "Events");
244 write.AddContainer("MMcEvt", "Events");
245 write.AddContainer("IncidentAngle", "Events", kFALSE);
246 write.AddContainer("MPointingPos", "Events", kFALSE);
247}
248
249void MJSimulation::SetupHeaderKeys(MWriteFitsFile &write,MRawRunHeader &header) const
250{
251 const MTime now(-1);
252 write.SetHeaderKey("ISMC",true,"Bool if File is Montecarlo File");
253 write.SetHeaderKey("TELESCOP", "FACT", "");
254 write.SetHeaderKey("PACKAGE", "MARS Cheobs", "");
255 write.SetHeaderKey("VERSION", "1.0", "");
256 write.SetHeaderKey("CREATOR", "Ceres", "");
257 write.SetHeaderKey("EXTREL", 1., "");
258 write.SetHeaderKey("COMPILED", __DATE__" " __TIME__, "");
259 write.SetHeaderKey("REVISION", "0", "");
260 write.SetHeaderKey("ORIGIN", "FACT", "");
261 write.SetHeaderKey("DATE", now.GetStringFmt("%Y-%m-%dT%H:%M:%S").Data(), "");
262 write.SetHeaderKey("NIGHT", now.GetNightAsInt(), "");
263 write.SetHeaderKey("TIMESYS", "UTC", "");
264 write.SetHeaderKey("TIMEUNIT", "d", "");
265 write.SetHeaderKey("MJDREF", 40587, "");
266 //write.SetHeaderKey("BLDVER", 1, "");
267 write.SetHeaderKey("RUNID", header.GetRunNumber(), "");
268 write.SetHeaderKey("NBOARD", 40, "");
269 write.SetHeaderKey("NPIX", header.GetNumPixel(), "");
270 write.SetHeaderKey("NROI", header.GetNumSamplesHiGain(), "");
271 write.SetHeaderKey("NROITM", 0, "");
272 write.SetHeaderKey("TMSHIFT", 0, "");
273 write.SetHeaderKey("CAMERA", "MGeomCamFACT", "");
274 write.SetHeaderKey("DAQ", "DRS4", "");
275
276 // FTemme: ADCRANGE and ADC have to be calculated, using the values for
277 // the fadctype.
278// write.SetHeaderKey("ADCRANGE", 2000, "Dynamic range in mV");
279// write.SetHeaderKey("ADC", 12, "Resolution in bits");
280
281 switch(header.GetRunType())
282 {
283 case MRawRunHeader::kRTData|MRawRunHeader::kRTMonteCarlo:
284 write.SetHeaderKey("RUNTYPE", "data", "");
285 break;
286 case MRawRunHeader::kRTPedestal|MRawRunHeader::kRTMonteCarlo:
287 write.SetHeaderKey("RUNTYPE", "pedestal", "");
288 break;
289 case MRawRunHeader::kRTCalibration|MRawRunHeader::kRTMonteCarlo:
290 write.SetHeaderKey("RUNTYPE", "calibration", "");
291 break;
292 }
293// write.SetHeaderKey("ID", 777, "Board 0: Board ID");
294// write.SetHeaderKey("FMVER", 532, "Board 0: Firmware Version");
295// write.SetHeaderKey("DNA", "0", "");
296// write.SetHeaderKey("BOARD", 0, "");
297// write.SetHeaderKey("PRESC", 40, "");
298// write.SetHeaderKey("PHASE", 0, "");
299// write.SetHeaderKey("DAC0", 26500, "");
300// write.SetHeaderKey("DAC1", 0, "");
301// write.SetHeaderKey("DAC2", 0, "");
302// write.SetHeaderKey("DAC3", 0, "");
303// write.SetHeaderKey("DAC4", 28800, "");
304// write.SetHeaderKey("DAC5", 28800, "");
305// write.SetHeaderKey("DAC6", 28800, "");
306// write.SetHeaderKey("DAC7", 28800, "");
307 write.SetHeaderKey("REFCLK", header.GetFreqSampling(), "");
308 write.SetHeaderKey("DRSCALIB", false, "");
309// write.SetHeaderKey("TSTARTI", 0, "");
310// write.SetHeaderKey("TSTARTF", 0., "");
311// write.SetHeaderKey("TSTOPI", 0, "");
312// write.SetHeaderKey("TSTOPF", 0., "");
313// write.SetHeaderKey("DATE-OBS", "1970-01-01T00:00:00", "");
314// write.SetHeaderKey("DATE-END", "1970-01-01T00:00:00", "");
315// write.SetHeaderKey("NTRG", 0, "");
316// write.SetHeaderKey("NTRGPED", 0, "");
317// write.SetHeaderKey("NTRGLPE", 0, "");
318// write.SetHeaderKey("NTRGTIM", 0, "");
319// write.SetHeaderKey("NTRGLPI", 0, "");
320// write.SetHeaderKey("NTRGEXT1", 0, "");
321// write.SetHeaderKey("NTRGEXT2", 0, "");
322// write.SetHeaderKey("NTRGMISC", 0, "");
323}
324
325void MJSimulation::SetupVetoColumns(MWriteFitsFile &write) const
326{
327 write.VetoColumn("MParameterD.fVal");
328 write.VetoColumn("MRawEvtData.fLoGainPixId");
329 write.VetoColumn("MRawEvtData.fLoGainFadcSamples");
330 write.VetoColumn("MRawEvtData.fABFlags");
331 write.VetoColumn("MRawEvtHeader.fNumTrigLvl2");
332 //write.VetoColumn("MRawEvtHeader.fTrigPattern");
333 write.VetoColumn("MRawEvtHeader.fNumLoGainOn");
334}
335
336Bool_t MJSimulation::Process(const MArgs &args, const MSequence &seq)
337{
338 *fLog << inf;
339 fLog->Separator(GetDescriptor());
340
341 if (!CheckEnv())
342 return kFALSE;
343
344 if (seq.IsValid())
345 *fLog << fSequence.GetFileName() << endl;
346 else
347 *fLog << "Input: " << args.GetNumArguments() << "-files" << endl;
348 *fLog << endl;
349
350 MDirIter iter;
351 if (seq.IsValid() && seq.GetRuns(iter, MSequence::kCorsika)<=0)
352 {
353 *fLog << err << "ERROR - Sequence valid but without files." << endl;
354 return kFALSE;
355 }
356
357 // --------------------------------------------------------------------------------
358 // Setup Parlist
359 MParList plist;
360 plist.AddToList(this); // take care of fDisplay!
361 // setup TaskList
362 MTaskList tasks;
363 plist.AddToList(&tasks);
364 // --------------------------------------------------------------------------------
365
366 // FIXME: Allow empty GeomCones!
367 MParEnv env0("Reflector");
368 MParEnv env1("GeomCones");
369 MParEnv env2("MGeomCam");
370 env0.SetClassName("MReflector");
371 env1.SetClassName("MGeomCam");
372 env2.SetClassName("MGeomCam");
373 plist.AddToList(&env0);
374 plist.AddToList(&env1);
375 plist.AddToList(&env2);
376
377 plist.FindCreateObj("MPedPhotCam", "MPedPhotFromExtractorRndm");
378
379 MParSpline shape("PulseShape");
380 plist.AddToList(&shape);
381
382 // *** FIXME *** FIXME *** FIXME ***
383 plist.FindCreateObj("MMcRunHeader");
384
385 MRawRunHeader header;
386 header.SetValidMagicNumber();
387 //header.InitFadcType(3);
388
389 switch (fOperationMode)
390 {
391 case kModeData:
392 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTData);
393 header.SetRunInfo(0, fRunNumber<0 ? 3 : fRunNumber);
394 break;
395
396 case kModePed:
397 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPedestal);
398 header.SetSourceInfo("Pedestal");
399 header.SetRunInfo(0, fRunNumber<0 ? 1 : fRunNumber);
400 break;
401
402 case kModeCal:
403 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTCalibration);
404 header.SetSourceInfo("Calibration");
405 header.SetRunInfo(0, fRunNumber<0 ? 2 : fRunNumber);
406 break;
407
408 case kModePointRun:
409 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPointRun);
410 header.SetRunInfo(0, fRunNumber<0 ? 0 : fRunNumber);
411 break;
412 }
413
414 // FIXME: Move to MSimPointingPos, MSimCalibrationSignal
415 // Can we use this as input for MSimPointingPos?
416 header.SetObservation("On", "MonteCarlo");
417 plist.AddToList(&header);
418
419 MCorsikaRead read;
420 read.SetForceMode(fForceMode);
421
422 if (!seq.IsValid())
423 {
424 for (int i=0; i<args.GetNumArguments(); i++)
425 read.AddFile(args.GetArgumentStr(i));
426 }
427 else
428 read.AddFiles(iter);
429
430 MContinue precut("", "PreCut");
431 precut.IsInverted();
432 precut.SetAllowEmpty();
433
434 MSimMMCS simmmcs;
435
436 MParSpline splinepde("PhotonDetectionEfficiency");
437 MParSpline splinemirror("MirrorReflectivity");
438 MParSpline splinecones("ConesAngularAcceptance");
439 MParSpline splinecones2("ConesTransmission");
440 plist.AddToList(&splinepde);
441 plist.AddToList(&splinemirror);
442 plist.AddToList(&splinecones);
443 plist.AddToList(&splinecones2);
444
445 const TString sin2 = "sin(MCorsikaEvtHeader.fZd)*sin(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
446 const TString cos2 = "cos(MCorsikaEvtHeader.fZd)*cos(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
447 const TString cos = "cos(MCorsikaEvtHeader.fAz-MCorsikaRunHeader.fAzMin*TMath::DegToRad())";
448
449 const TString form = "acos("+sin2+"*"+cos+"+"+cos2+")*TMath::RadToDeg()";
450
451 MParameterCalc calcangle(form, "CalcIncidentAngle");
452 calcangle.SetNameParameter("IncidentAngle");
453
454 MSimAtmosphere simatm;
455 MSimAbsorption absapd("SimPhotonDetectionEfficiency");
456 MSimAbsorption absmir("SimMirrorReflectivity");
457 MSimAbsorption cones("SimConesAngularAcceptance");
458 MSimAbsorption cones2("SimConesTransmission");
459 absapd.SetParName("PhotonDetectionEfficiency");
460 absmir.SetParName("MirrorReflectivity");
461 cones.SetParName("ConesAngularAcceptance");
462 cones.SetUseTheta();
463 cones2.SetParName("ConesTransmission");
464
465 MSimPointingPos pointing;
466
467 MSimReflector reflect;
468 reflect.SetNameGeomCam("GeomCones");
469 reflect.SetNameReflector("Reflector");
470// MSimStarField stars;
471
472 MContinue cont1("MPhotonEvent.GetNumPhotons<1", "ContEmpty1");
473 MContinue cont2("MPhotonEvent.GetNumPhotons<1", "ContEmpty2");
474 MContinue cont3("MPhotonEvent.GetNumPhotons<2", "ContEmpty3");
475 cont1.SetAllowEmpty();
476 cont2.SetAllowEmpty();
477 cont3.SetAllowEmpty();
478
479 // -------------------------------------------------------------------
480
481 MBinning binse( 120, 1, 1000000, "BinningEnergy", "log");
482 MBinning binsth( 60, 0.9, 900000, "BinningThreshold", "log");
483 MBinning binsee( 36, 0.9, 900000, "BinningEnergyEst", "log");
484 MBinning binss( 100, 1, 10000000, "BinningSize", "log");
485// MBinning binsi( 100, -500, 500, "BinningImpact");
486 MBinning binsi( 32, 0, 800, "BinningImpact");
487 MBinning binsh( 150, 0, 50, "BinningHeight");
488 MBinning binsaz(720, -360, 360, "BinningAz");
489 MBinning binszd( 70, 0, 70, "BinningZd");
490 MBinning binsvc( 35, 0, 7, "BinningViewCone");
491 MBinning binsel(150, 0, 50, "BinningTotLength");
492 MBinning binsew(150, 0, 15, "BinningMedLength");
493 MBinning binsd("BinningDistC");
494 MBinning binsd0("BinningDist");
495 MBinning binstr("BinningTrigPos");
496
497 plist.AddToList(&binsee);
498 plist.AddToList(&binse);
499 plist.AddToList(&binsth);
500 plist.AddToList(&binss);
501 plist.AddToList(&binsi);
502 plist.AddToList(&binsh);
503 plist.AddToList(&binszd);
504 plist.AddToList(&binsaz);
505 plist.AddToList(&binsvc);
506 plist.AddToList(&binsel);
507 plist.AddToList(&binsew);
508 plist.AddToList(&binstr);
509 plist.AddToList(&binsd);
510 plist.AddToList(&binsd0);
511
512 MHn mhn1, mhn2, mhn3, mhn4;
513 SetupHist(mhn1);
514 SetupHist(mhn2);
515 SetupHist(mhn3);
516 SetupHist(mhn4);
517
518 MH3 mhtp("TriggerPos.fVal-IntendedPulsePos.fVal-PulseShape.GetWidth");
519 mhtp.SetName("TrigPos");
520 mhtp.SetTitle("Trigger position w.r.t. the first photon hitting a detector");
521
522 MH3 mhew("MPhotonStatistics.fLength");
523 mhew.SetName("TotLength");
524 mhew.SetTitle("Time between first and last photon hitting a detector;L [ns]");
525
526 MH3 mhed("MPhotonStatistics.fTimeMedDev");
527 mhed.SetName("MedLength");
528 mhed.SetTitle("Median deviation (1\\sigma);L [ns]");
529
530 MFillH fillh1(&mhn1, "", "FillCorsika");
531 MFillH fillh2(&mhn2, "", "FillH2");
532 MFillH fillh3(&mhn3, "", "FillH3");
533 MFillH fillh4(&mhn4, "", "FillH4");
534 MFillH filltp(&mhtp, "", "FillTriggerPos");
535 MFillH fillew(&mhew, "", "FillEvtWidth");
536 MFillH filled(&mhed, "", "FillMedDev");
537 fillh1.SetNameTab("Corsika", "Distribution as simulated by Corsika");
538 fillh2.SetNameTab("Detectable", "Distribution of events hit the detector");
539 fillh3.SetNameTab("Triggered", "Distribution of triggered events");
540 fillh4.SetNameTab("Cleaned", "Distribution after cleaning and cuts");
541 filltp.SetNameTab("TrigPos", "TriggerPosition w.r.t the first photon");
542 fillew.SetNameTab("EvtWidth", "Time between first and last photon hitting a detector");
543 filled.SetNameTab("MedDev", "Median deviation of arrival time of photons hitting a detector");
544
545 MHPhotonEvent planeG(1, "HPhotonEventGround"); // Get from MaxImpact
546 MHPhotonEvent plane0(2, "HMirrorPlane0"); // Get from MReflector
547 //MHPhotonEvent plane1(2, "HMirrorPlane1");
548 MHPhotonEvent plane2(2, "HMirrorPlane2");
549 MHPhotonEvent plane3(2, "HMirrorPlane3");
550 MHPhotonEvent plane4(2, "HMirrorPlane4");
551 MHPhotonEvent planeF1(6, "HPhotonEventCamera"); // Get from MGeomCam
552 MHPhotonEvent planeF2(header.IsPointRun()?4:6, "HPhotonEventCones"); // Get from MGeomCam
553
554 plist.AddToList(&planeG);
555 plist.AddToList(&plane0);
556 plist.AddToList(&plane2);
557 plist.AddToList(&plane3);
558 plist.AddToList(&plane4);
559 plist.AddToList(&planeF1);
560 plist.AddToList(&planeF2);;
561
562 //MHPSF psf;
563
564 MFillH fillG(&planeG, "MPhotonEvent", "FillGround");
565 MFillH fill0(&plane0, "MirrorPlane0", "FillReflector");
566 //MFillH fill1(&plane1, "MirrorPlane1", "FillCamShadow");
567 MFillH fill2(&plane2, "MirrorPlane2", "FillCandidates");
568 MFillH fill3(&plane3, "MirrorPlane3", "FillReflected");
569 MFillH fill4(&plane4, "MirrorPlane4", "FillFocal");
570 MFillH fillF1(&planeF1, "MPhotonEvent", "FillCamera");
571 MFillH fillF2(&planeF2, "MPhotonEvent", "FillCones");
572 //MFillH fillP(&psf, "MPhotonEvent", "FillPSF");
573
574 fillG.SetNameTab("Ground", "Photon distribution at ground");
575 fill0.SetNameTab("Reflector", "Photon distribution at reflector plane w/o camera shadow");
576 //fill1.SetNameTab("CamShadow", "Photon distribution at reflector plane w/ camera shadow");
577 fill2.SetNameTab("Candidates", "*Can hit* photon distribution at reflector plane w/ camera shadow");
578 fill3.SetNameTab("Reflected", "Photon distribution after reflector projected to reflector plane");
579 fill4.SetNameTab("Focal", "Photon distribution at focal plane");
580 fillF1.SetNameTab("Camera", "Photon distribution which hit the detector");
581 fillF2.SetNameTab("Cones", "Photon distribution after cones");
582 //fillP.SetNameTab("PSF", "Photon distribution after cones for all mirrors");
583
584 // -------------------------------------------------------------------
585
586 const char *fmt = Form("s/cer([0-9]+)([0-9][0-9][0-9])/%s\\/%08d.$2_%%c_MonteCarlo$1.root/", Esc(fPathOut).Data(), header.GetRunNumber());
587
588 const TString rule1(Form(fmt, 'R'));
589 const TString rule2(Form(fmt, 'Y'));
590 const TString rule4(Form(fmt, 'I'));
591 TString rule3(Form(fmt, header.GetRunTypeChar()));
592
593 MWriteRootFile write4a( 2, rule4, fOverwrite?"RECREATE":"NEW", "Star file");
594 MWriteRootFile write4b( 2, rule4, fOverwrite?"RECREATE":"NEW", "Star file");
595 MWriteRootFile write3b( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
596 MWriteRootFile write2a( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
597 MWriteRootFile write2b( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
598 MWriteRootFile write1a( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
599 MWriteRootFile write1b( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
600
601 if (fWriteFitsFile)
602 rule3.ReplaceAll("$1.root/", "$1.fits/");
603
604 MWriteFitsFile write3af( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
605 MWriteRootFile write3ar( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
606
607 MTask &write3a = fWriteFitsFile ? static_cast<MTask&>(write3af) : static_cast<MTask&>(write3ar);
608
609 //SetupHeaderKeys(write3af,header);
610 SetupVetoColumns(write3af);
611
612 write3af.SetBytesPerSample("Data", 2);
613
614 write1a.SetName("WriteRefData");
615 write1b.SetName("WriteRefMC");
616 write2a.SetName("WriteSigData");
617 write2b.SetName("WriteSigMC");
618 write3a.SetName("WriteCamData");
619 write3b.SetName("WriteCamMC");
620 write4a.SetName("WriteImgData");
621 write4b.SetName("WriteImgMC");
622
623 SetupCommonFileStructure(write1a);
624 SetupCommonFileStructure(write2a);
625 SetupCommonFileStructure(write3ar);
626 SetupCommonFileStructure(write3af);
627 SetupCommonFileStructure(write4a);
628
629 // R: Dedicated file structure
630 write1a.AddContainer("MPhotonEvent", "Events");
631
632 // Y: Dedicated file structure
633 write2a.AddContainer("MPedPhotFromExtractorRndm", "RunHeaders"); // FIXME: Needed for the signal files to be display in MARS
634 write2a.AddContainer("MSignalCam", "Events");
635
636 // D: Dedicated file structure
637 write3af.AddContainer("ElectronicNoise", "RunHeaders");
638 write3af.AddContainer("IntendedPulsePos", "RunHeaders");
639 write3af.AddContainer("MRawEvtData", "Events");
640 write3af.AddContainer("MTruePhotonsPerPixelCont", "Events");
641
642 if (fOperationMode == kModeData){
643 write3af.AddContainer("MMcEvtBasic", "Events");
644 }
645
646 write3af.AddContainer("MPhotonEvent","Events");
647
648 write3ar.AddContainer("ElectronicNoise", "RunHeaders");
649 write3ar.AddContainer("IntendedPulsePos", "RunHeaders");
650 write3ar.AddContainer("MRawEvtData", "Events");
651 // It doesn't make much sene to write this information
652 // to the file because the units are internal units not
653 // related to the output samples
654 // if (header.IsDataRun() || fForceTrigger)
655 // write3a.AddContainer("TriggerPos", "Events");
656
657 // I: Dedicated file structure
658 write4a.AddContainer("MHillas", "Events");
659 write4a.AddContainer("MHillasSrc", "Events");
660 write4a.AddContainer("MImagePar", "Events");
661 write4a.AddContainer("MNewImagePar", "Events");
662
663 // Basic MC data
664 write1b.AddContainer("MMcEvtBasic", "OriginalMC");
665 write2b.AddContainer("MMcEvtBasic", "OriginalMC");
666 write3b.AddContainer("MMcEvtBasic", "OriginalMC");
667 write4b.AddContainer("MMcEvtBasic", "OriginalMC");
668
669 // -------------------------------------------------------------------
670
671 MGeomApply apply;
672
673 MSimPSF simpsf;
674
675 MSimGeomCam simgeom;
676 simgeom.SetNameGeomCam("GeomCones");
677
678 MSimCalibrationSignal simcal;
679 simcal.SetNameGeomCam("GeomCones");
680
681 // Sky Quality Meter: 21.82M = 2.02e-4cd/m^2
682 // 1cd = 12.566 lm / 4pi sr
683
684 // FIXME: Simulate photons before cones and QE!
685
686 MSimRandomPhotons simnsb;
687 simnsb.SetFreq(5.8, 0.004); // ph/m^2/nm/sr/ns NSB, 4MHz dark count rate
688 simnsb.SetNameGeomCam("GeomCones");
689
690 // FIXME: How do we handle star-light? We need the rate but we also
691 // need to process it through the mirror!
692
693 MSimAPD simapd;
694 simapd.SetNameGeomCam("GeomCones");
695
696 MSimExcessNoise simexcnoise;
697 MSimBundlePhotons simsum;
698 MSimSignalCam simsignal;
699 MSimCamera simcam;
700 MSimTrigger simtrig;
701 MSimReadout simdaq;
702
703 MContinue conttrig("TriggerPos.fVal<0", "ContTrigger");
704
705 MParameterD pulpos("IntendedPulsePos");
706 // FIXME: Set a default which could be 1/3 of the digitization window
707 // pulpos.SetVal(40); // [ns]
708 plist.AddToList(&pulpos);
709
710 MParameterD trigger("TriggerPos");
711 trigger.SetVal(0);
712 plist.AddToList(&trigger);
713
714 // -------------------------------------------------------------------
715
716 // Remove isolated pixels
717 MImgCleanStd clean(0, 0);
718 //clean.SetCleanLvl0(0); // The level above which isolated pixels are kept
719 clean.SetCleanRings(0);
720 clean.SetMethod(MImgCleanStd::kAbsolute);
721
722 //clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
723
724 MHillasCalc hcalc;
725 hcalc.Disable(MHillasCalc::kCalcConc);
726
727 MHCamEvent evt0a(/*10*/3, "Signal", "Average signal (absolute);;S [ph]");
728 MHCamEvent evt0c(/*10*/3, "MaxSignal", "Maximum signal (absolute);;S [ph]");
729 MHCamEvent evt0d(/*11*/8, "ArrTm", "Time after first photon;;T [ns]");
730 evt0a.SetErrorSpread(kFALSE);
731 evt0c.SetCollectMax();
732
733 MContinue cut("", "Cut");
734
735 MFillH fillx0a(&evt0a, "MSignalCam", "FillAvgSignal");
736 MFillH fillx0c(&evt0c, "MSignalCam", "FillMaxSignal");
737 MFillH fillx0d(&evt0d, "MSignalCam", "FillArrTm");
738 MFillH fillx1("MHHillas", "MHillas", "FillHillas");
739 MFillH fillx3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
740 MFillH fillx4("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
741 MFillH fillth("MHThreshold", "", "FillThreshold");
742 MFillH fillca("MHCollectionArea", "", "FillTrigArea");
743
744 fillth.SetNameTab("Threshold");
745 fillca.SetNameTab("TrigArea");
746
747 // -------------------------------------------------------------------
748
749 if (header.IsDataRun())
750 {
751 tasks.AddToList(&read);
752 tasks.AddToList(&precut);
753 tasks.AddToList(&pointing);
754 tasks.AddToList(&simmmcs);
755 if (!fPathOut.IsNull() && !HasNullOut())
756 {
757 //tasks.AddToList(&write1b);
758 tasks.AddToList(&write2b);
759 if (fCamera)
760 tasks.AddToList(&write3b);
761 if (header.IsDataRun())
762 tasks.AddToList(&write4b);
763 }
764 // if (header.IsPointRun())
765 // tasks.AddToList(&stars);
766 if (1)
767 tasks.AddToList(&simatm); // Here because before fillh1
768 tasks.AddToList(&calcangle);
769 tasks.AddToList(&fillh1);
770 tasks.AddToList(&fillG);
771 if (!header.IsPointRun())
772 {
773 tasks.AddToList(&absapd);
774 tasks.AddToList(&absmir);
775 if (0)
776 tasks.AddToList(&simatm); // FASTER?
777 }
778 tasks.AddToList(&reflect);
779 if (!header.IsPointRun())
780 {
781 tasks.AddToList(&fill0);
782 //tasks.AddToList(&fill1);
783 tasks.AddToList(&fill2);
784 tasks.AddToList(&fill3);
785 tasks.AddToList(&fill4);
786 tasks.AddToList(&fillF1);
787 }
788 tasks.AddToList(&cones);
789 tasks.AddToList(&cones2);
790 //if (header.IsPointRun())
791 // tasks.AddToList(&fillP);
792 tasks.AddToList(&cont1);
793 }
794 // -------------------------------
795 tasks.AddToList(&apply);
796 if (header.IsDataRun())
797 {
798 tasks.AddToList(&simpsf);
799 tasks.AddToList(&simgeom);
800 tasks.AddToList(&cont2);
801 if (!header.IsPointRun())
802 {
803 tasks.AddToList(&fillF2);
804 tasks.AddToList(&fillh2);
805 }
806 tasks.AddToList(&cont3);
807 }
808 if (fCamera)
809 {
810 if (header.IsPedestalRun() || header.IsCalibrationRun())
811 tasks.AddToList(&simcal);
812 tasks.AddToList(&simnsb);
813 tasks.AddToList(&simapd);
814 tasks.AddToList(&simexcnoise);
815 }
816 tasks.AddToList(&simsum);
817 if (fCamera)
818 {
819 tasks.AddToList(&simcam);
820 if (header.IsDataRun() || fForceTrigger)
821 tasks.AddToList(&simtrig);
822 tasks.AddToList(&conttrig);
823 tasks.AddToList(&simdaq);
824 }
825 tasks.AddToList(&simsignal); // What do we do if signal<0?
826 if (!fPathOut.IsNull() && !HasNullOut())
827 {
828 //tasks.AddToList(&write1a);
829 if (!header.IsPedestalRun())
830 tasks.AddToList(&write2a);
831 if (fCamera)
832 tasks.AddToList(&write3a);
833 }
834 // -------------------------------
835 if (fCamera)
836 {
837 // FIXME: MHCollectionArea Trigger Area!
838 if (header.IsDataRun())
839 tasks.AddToList(&fillh3);
840 tasks.AddToList(&filltp);
841 }
842 if (header.IsDataRun())
843 {
844 tasks.AddToList(&fillew);
845 tasks.AddToList(&filled);
846 }
847 if (!header.IsPedestalRun())
848 {
849 tasks.AddToList(&fillx0a);
850 tasks.AddToList(&fillx0c);
851 }
852 if (header.IsDataRun())
853 {
854 tasks.AddToList(&clean);
855 tasks.AddToList(&hcalc);
856 tasks.AddToList(&cut);
857 tasks.AddToList(&fillx0d);
858 tasks.AddToList(&fillx1);
859 //tasks.AddToList(&fillx2);
860 tasks.AddToList(&fillx3);
861 tasks.AddToList(&fillx4);
862 if (!HasNullOut())
863 tasks.AddToList(&write4a);
864 //tasks.AddToList(&fillx5);
865
866 tasks.AddToList(&fillh4);
867 tasks.AddToList(&fillth);
868 tasks.AddToList(&fillca);
869 }
870 //-------------------------------------------
871
872 tasks.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
873
874 // Create and setup the eventloop
875 MEvtLoop evtloop(fName);
876 evtloop.SetParList(&plist);
877 evtloop.SetDisplay(fDisplay);
878 evtloop.SetLogStream(&gLog);
879 if (!SetupEnv(evtloop))
880 return kFALSE;
881
882 // FIXME: If pedestal file given use the values from this file
883 //-------------------------------------------
884
885 MGeomCam *cam = static_cast<MGeomCam*>(env2.GetCont());
886
887 if (binstr.IsDefault())
888 binstr.SetEdgesLin(150, -shape.GetWidth(),
889 header.GetFreqSampling()/1000.*header.GetNumSamples()+shape.GetWidth());
890
891 if (binsd.IsDefault() && cam)
892 binsd.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
893
894 if (binsd0.IsDefault() && cam)
895 binsd0.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
896
897
898 header.Print();
899
900 // FIXME: Display acceptance curves!
901
902 if (fDisplay)
903 {
904 TCanvas &c = fDisplay->AddTab("Info");
905 c.Divide(2,2);
906
907 c.cd(1);
908 gPad->SetBorderMode(0);
909 gPad->SetFrameBorderMode(0);
910 gPad->SetGridx();
911 gPad->SetGridy();
912 gROOT->SetSelectedPad(0);
913 shape.DrawClone()->SetBit(kCanDelete);
914
915 if (env0.GetCont() && (header.IsDataRun() || header.IsPointRun()))
916 {
917 c.cd(3);
918 gPad->SetBorderMode(0);
919 gPad->SetFrameBorderMode(0);
920 gPad->SetGridx();
921 gPad->SetGridy();
922 gROOT->SetSelectedPad(0);
923 static_cast<MReflector*>(env0.GetCont())->DrawClone("line")->SetBit(kCanDelete);
924 }
925
926 if (fCamera)
927 {
928 if (env1.GetCont())
929 {
930 c.cd(2);
931 gPad->SetBorderMode(0);
932 gPad->SetFrameBorderMode(0);
933 gPad->SetGridx();
934 gPad->SetGridy();
935 gROOT->SetSelectedPad(0);
936 MHCamera *c = new MHCamera(static_cast<MGeomCam&>(*env1.GetCont()));
937 c->SetStats(kFALSE);
938 c->SetBit(MHCamera::kNoLegend);
939 c->SetBit(kCanDelete);
940 c->Draw();
941 }
942
943 if (cam)
944 {
945 c.cd(4);
946 gPad->SetBorderMode(0);
947 gPad->SetFrameBorderMode(0);
948 gPad->SetGridx();
949 gPad->SetGridy();
950 gROOT->SetSelectedPad(0);
951 MHCamera *c = new MHCamera(*cam);
952 c->SetStats(kFALSE);
953 c->SetBit(MHCamera::kNoLegend);
954 c->SetBit(kCanDelete);
955 c->Draw();
956 }
957 }
958
959 TCanvas &d = fDisplay->AddTab("Info2");
960 d.Divide(2,3);
961
962 d.cd(1);
963 gPad->SetBorderMode(0);
964 gPad->SetFrameBorderMode(0);
965 gPad->SetGridx();
966 gPad->SetGridy();
967 gROOT->SetSelectedPad(0);
968 splinepde.DrawClone()->SetBit(kCanDelete);
969
970 d.cd(3);
971 gPad->SetBorderMode(0);
972 gPad->SetFrameBorderMode(0);
973 gPad->SetGridx();
974 gPad->SetGridy();
975 gROOT->SetSelectedPad(0);
976 splinecones2.DrawClone()->SetBit(kCanDelete);
977
978 d.cd(5);
979 gPad->SetBorderMode(0);
980 gPad->SetFrameBorderMode(0);
981 gPad->SetGridx();
982 gPad->SetGridy();
983 gROOT->SetSelectedPad(0);
984 splinemirror.DrawClone()->SetBit(kCanDelete);
985
986 d.cd(2);
987 gPad->SetBorderMode(0);
988 gPad->SetFrameBorderMode(0);
989 gPad->SetGridx();
990 gPad->SetGridy();
991 gROOT->SetSelectedPad(0);
992 splinecones.DrawClone()->SetBit(kCanDelete);
993 //splinecones2.DrawClone("same")->SetBit(kCanDelete);
994
995 d.cd(6);
996 gPad->SetBorderMode(0);
997 gPad->SetFrameBorderMode(0);
998 gPad->SetGridx();
999 gPad->SetGridy();
1000 gROOT->SetSelectedPad(0);
1001 MParSpline *all = (MParSpline*)splinepde.DrawClone();
1002 //all->SetTitle("Combined acceptance");
1003 all->SetBit(kCanDelete);
1004 if (splinemirror.GetSpline())
1005 all->Multiply(*splinemirror.GetSpline());
1006 if (splinecones2.GetSpline())
1007 all->Multiply(*splinecones2.GetSpline());
1008 }
1009
1010 //-------------------------------------------
1011
1012 // Execute first analysis
1013 if (!evtloop.Eventloop(fMaxEvents))
1014 {
1015 gLog << err << GetDescriptor() << ": Failed." << endl;
1016 return kFALSE;
1017 }
1018
1019 //-------------------------------------------
1020 // FIXME: Display Spline in tab
1021 // FIXME: Display Reflector in tab
1022 // FIXME: Display Routing(?) in tab
1023 // FIXME: Display Camera(s) in tab
1024 //-------------------------------------------
1025
1026 if (!WriteResult(plist, seq, header.GetRunNumber()))
1027 return kFALSE;
1028
1029 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
1030
1031 return kTRUE;
1032}
Note: See TracBrowser for help on using the repository browser.