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 "MHillasCalc.h"
|
---|
77 | #include "MImgCleanStd.h"
|
---|
78 | #include "MWriteRootFile.h"
|
---|
79 |
|
---|
80 | #include "MSimMMCS.h"
|
---|
81 | #include "MSimAbsorption.h"
|
---|
82 | #include "MSimAtmosphere.h"
|
---|
83 | #include "MSimReflector.h"
|
---|
84 | #include "MSimPointingPos.h"
|
---|
85 | #include "MSimPSF.h"
|
---|
86 | #include "MSimGeomCam.h"
|
---|
87 | #include "MSimSignalCam.h"
|
---|
88 | #include "MSimAPD.h"
|
---|
89 | #include "MSimExcessNoise.h"
|
---|
90 | #include "MSimCamera.h"
|
---|
91 | #include "MSimTrigger.h"
|
---|
92 | #include "MSimReadout.h"
|
---|
93 | #include "MSimRandomPhotons.h"
|
---|
94 | #include "MSimBundlePhotons.h"
|
---|
95 | #include "MSimCalibrationSignal.h"
|
---|
96 |
|
---|
97 | // Histograms
|
---|
98 | #include "MBinning.h"
|
---|
99 |
|
---|
100 | #include "MHn.h"
|
---|
101 | #include "MHCamera.h"
|
---|
102 | #include "MHCamEvent.h"
|
---|
103 | #include "MHPhotonEvent.h"
|
---|
104 |
|
---|
105 | // Container
|
---|
106 | #include "MRawRunHeader.h"
|
---|
107 | #include "MParameters.h"
|
---|
108 | #include "MReflector.h"
|
---|
109 | #include "MParEnv.h"
|
---|
110 | #include "MPulseShape.h"
|
---|
111 | #include "MGeomCam.h"
|
---|
112 |
|
---|
113 | #include "MPedestalCam.h"
|
---|
114 | #include "MPedestalPix.h"
|
---|
115 |
|
---|
116 | ClassImp(MJSimulation);
|
---|
117 |
|
---|
118 | using namespace std;
|
---|
119 |
|
---|
120 | // --------------------------------------------------------------------------
|
---|
121 | //
|
---|
122 | // Default constructor.
|
---|
123 | //
|
---|
124 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
125 | //
|
---|
126 | MJSimulation::MJSimulation(const char *name, const char *title)
|
---|
127 | : fForceMode(kFALSE), fCamera(kTRUE) ,fForceTrigger(kFALSE)
|
---|
128 | {
|
---|
129 | fName = name ? name : "MJSimulation";
|
---|
130 | fTitle = title ? title : "Standard analysis and reconstruction";
|
---|
131 | }
|
---|
132 |
|
---|
133 | Bool_t MJSimulation::CheckEnvLocal()
|
---|
134 | {
|
---|
135 | fForceMode = GetEnv("ForceMode", fForceMode);
|
---|
136 | fForceTrigger = GetEnv("ForceTrigger", fForceTrigger);
|
---|
137 | fCamera = GetEnv("Camera", fCamera);
|
---|
138 |
|
---|
139 | return kTRUE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | Bool_t MJSimulation::WriteResult(const MParList &plist)
|
---|
143 | {
|
---|
144 | if (fPathOut.IsNull())
|
---|
145 | {
|
---|
146 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
---|
147 | return kTRUE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | TObjArray cont;
|
---|
151 | cont.Add(const_cast<TEnv*>(GetEnv()));
|
---|
152 | //cont.Add(const_cast<MSequence*>(&fSequence));
|
---|
153 |
|
---|
154 | cont.Add(plist.FindObject("MPulseShape"));
|
---|
155 | cont.Add(plist.FindObject("Reflector"));
|
---|
156 | cont.Add(plist.FindObject("MGeomCam"));
|
---|
157 | cont.Add(plist.FindObject("GeomCones"));
|
---|
158 |
|
---|
159 | if (fDisplay)
|
---|
160 | {
|
---|
161 | // TString title = "-- Reflector: ";
|
---|
162 | // title += fSequence.GetSequence();
|
---|
163 | // title += " --";
|
---|
164 | // fDisplay->SetTitle(title, kFALSE);
|
---|
165 | fDisplay->SetTitle("Ceres", kFALSE);
|
---|
166 |
|
---|
167 | cont.Add(fDisplay);
|
---|
168 | }
|
---|
169 |
|
---|
170 | // const TString oname = Form("reflector%08d.root", fSequence.GetSequence());
|
---|
171 | const TString oname = "ceres.root";
|
---|
172 | return WriteContainer(cont, oname, "RECREATE");
|
---|
173 | }
|
---|
174 |
|
---|
175 | void MJSimulation::SetupHist(MHn &hist) const
|
---|
176 | {
|
---|
177 | hist.AddHist("MCorsikaEvtHeader.fTotalEnergy");
|
---|
178 | hist.InitName("Energy");
|
---|
179 | hist.InitTitle("Energy;E [GeV]");
|
---|
180 | hist.SetLog(kTRUE, kTRUE, kFALSE);
|
---|
181 |
|
---|
182 | hist.AddHist("MPhotonEvent.GetNumExternal");
|
---|
183 | hist.InitName("Size");
|
---|
184 | hist.InitTitle("Size;S [#]");
|
---|
185 | hist.SetLog(kTRUE, kTRUE, kFALSE);
|
---|
186 |
|
---|
187 | hist.AddHist("-MCorsikaEvtHeader.fX/100","-MCorsikaEvtHeader.fY/100");
|
---|
188 | hist.SetDrawOption("colz");
|
---|
189 | hist.InitName("Impact;Impact;Impact");
|
---|
190 | hist.InitTitle("Impact;West <--> East [m];South <--> North [m]");
|
---|
191 | hist.SetAutoRange();
|
---|
192 |
|
---|
193 | hist.AddHist("MCorsikaEvtHeader.fFirstInteractionHeight/100000");
|
---|
194 | hist.InitName("Height");
|
---|
195 | hist.InitTitle("FirstInteractionHeight;h [km]");
|
---|
196 |
|
---|
197 | hist.AddHist("(MCorsikaEvtHeader.fAz+MCorsikaRunHeader.fMagneticFieldAz)*TMath::RadToDeg()", "MCorsikaEvtHeader.fZd*TMath::RadToDeg()");
|
---|
198 | hist.InitName("SkyOrigin;Az;Zd");
|
---|
199 | hist.InitTitle("Sky Origin;Az [deg];Zd [deg]");
|
---|
200 | hist.SetDrawOption("colz");
|
---|
201 | hist.SetAutoRange();
|
---|
202 |
|
---|
203 | TString sin2 = "sin(MCorsikaEvtHeader.fZd)*sin(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
|
---|
204 | TString cos2 = "cos(MCorsikaEvtHeader.fZd)*cos(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
|
---|
205 | TString cos = "cos(MCorsikaEvtHeader.fAz-MCorsikaRunHeader.fAzMin*TMath::DegToRad())";
|
---|
206 |
|
---|
207 | TString form = "acos("+sin2+"*"+cos+"+"+cos2+")*TMath::RadToDeg()";
|
---|
208 |
|
---|
209 | hist.AddHist(form);
|
---|
210 | hist.InitName("ViewCone");
|
---|
211 | hist.InitTitle("Incident Angle;\\alpha [\\deg]");
|
---|
212 | }
|
---|
213 |
|
---|
214 | void MJSimulation::SetupCommonFileStructure(MWriteRootFile &write) const
|
---|
215 | {
|
---|
216 | // Common run headers
|
---|
217 | write.AddContainer("MCorsikaRunHeader", "RunHeaders", kFALSE);
|
---|
218 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
219 | write.AddContainer("MGeomCam", "RunHeaders");
|
---|
220 | write.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
221 |
|
---|
222 | // Common events
|
---|
223 | write.AddContainer("MCorsikaEvtHeader", "Events", kFALSE);
|
---|
224 | write.AddContainer("MRawEvtHeader", "Events");
|
---|
225 | write.AddContainer("MMcEvt", "Events");
|
---|
226 | }
|
---|
227 |
|
---|
228 | Bool_t MJSimulation::Process(const MArgs &args)
|
---|
229 | {
|
---|
230 | /*
|
---|
231 | if (!fSequence.IsValid())
|
---|
232 | {
|
---|
233 | *fLog << err << "ERROR - Sequence invalid!" << endl;
|
---|
234 | return kFALSE;
|
---|
235 | }
|
---|
236 | */
|
---|
237 |
|
---|
238 | //if (!HasWritePermission(GetPathOut()))
|
---|
239 | // return kFALSE;
|
---|
240 |
|
---|
241 | *fLog << inf;
|
---|
242 | fLog->Separator(GetDescriptor());
|
---|
243 |
|
---|
244 | if (!CheckEnv())
|
---|
245 | return kFALSE;
|
---|
246 |
|
---|
247 | *fLog << warn << "FIXME: Monte Carlo simulation: Sequences not supported yet.";
|
---|
248 | //*fLog << fSequence.GetFileName() << endl;
|
---|
249 | *fLog << endl;
|
---|
250 |
|
---|
251 | // --------------------------------------------------------------------------------
|
---|
252 |
|
---|
253 | //MDirIter iter;
|
---|
254 | //if (fSequence.GetRuns(iter, MSequence::kCalibrated)<=0)
|
---|
255 | // return kFALSE;
|
---|
256 |
|
---|
257 | // Setup Parlist
|
---|
258 | MParList plist;
|
---|
259 | plist.AddToList(this); // take care of fDisplay!
|
---|
260 |
|
---|
261 | // setup TaskList
|
---|
262 | MTaskList tasks;
|
---|
263 | plist.AddToList(&tasks);
|
---|
264 |
|
---|
265 | // --------------------------------------------------------------------------------
|
---|
266 |
|
---|
267 | // FIXME: Allow empty GeomCones!
|
---|
268 | MParEnv env0("Reflector");
|
---|
269 | MParEnv env1("GeomCones");
|
---|
270 | MParEnv env2("MGeomCam");
|
---|
271 | env0.SetClassName("MReflector");
|
---|
272 | env1.SetClassName("MGeomCam");
|
---|
273 | env2.SetClassName("MGeomCam");
|
---|
274 | plist.AddToList(&env0);
|
---|
275 | plist.AddToList(&env1);
|
---|
276 | plist.AddToList(&env2);
|
---|
277 |
|
---|
278 | plist.FindCreateObj("MPedPhotCam", "MPedPhotFromExtractorRndm");
|
---|
279 |
|
---|
280 | MPulseShape shape;
|
---|
281 | plist.AddToList(&shape);
|
---|
282 |
|
---|
283 | // *** FIXME *** FIXME *** FIXME ***
|
---|
284 | plist.FindCreateObj("MMcRunHeader");
|
---|
285 |
|
---|
286 | MRawRunHeader header;
|
---|
287 | header.SetValidMagicNumber();
|
---|
288 | //header.InitFadcType(3);
|
---|
289 |
|
---|
290 | header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTData);
|
---|
291 | if (args.GetNumArguments()==1)
|
---|
292 | {
|
---|
293 | if (!args.GetArgumentStr(0).CompareTo("pedestal", TString::kIgnoreCase))
|
---|
294 | {
|
---|
295 | header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPedestal);
|
---|
296 | header.SetSourceInfo("Pedestal");
|
---|
297 | }
|
---|
298 | if (!args.GetArgumentStr(0).CompareTo("calibration", TString::kIgnoreCase))
|
---|
299 | {
|
---|
300 | header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTCalibration);
|
---|
301 | header.SetSourceInfo("Calibration");
|
---|
302 | }
|
---|
303 | if (!args.GetArgumentStr(0).CompareTo("pointrun", TString::kIgnoreCase))
|
---|
304 | header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPointRun);
|
---|
305 | }
|
---|
306 |
|
---|
307 | // FIXME: Move to MSimPointingPos, MSimCalibrationSignal
|
---|
308 | // Can we use this as input for MSimPointingPos?
|
---|
309 | header.SetObservation("On", "MonteCarlo");
|
---|
310 | plist.AddToList(&header);
|
---|
311 | // ++++++++ FIXME FIXME FIXME +++++++++++++
|
---|
312 |
|
---|
313 | /*
|
---|
314 | MPedestalCam pedcam;
|
---|
315 | pedcam.Init(geomcam.GetNumPixels());
|
---|
316 | for (UInt_t i=0; i<geomcam.GetNumPixels(); i++)
|
---|
317 | pedcam[i].Set(128./header.GetScale(), 22.5/header.GetScale());
|
---|
318 | plist.AddToList(&pedcam);
|
---|
319 | */
|
---|
320 |
|
---|
321 | // -------------------------------------------------------------------
|
---|
322 |
|
---|
323 | MCorsikaRead read;
|
---|
324 | read.SetForceMode(fForceMode);
|
---|
325 |
|
---|
326 | for (int i=0; i<args.GetNumArguments();i ++)
|
---|
327 | read.AddFile(args.GetArgumentStr(i));
|
---|
328 |
|
---|
329 | MSimMMCS simmmcs;
|
---|
330 |
|
---|
331 | MSimAtmosphere simatm;
|
---|
332 | MSimAbsorption absapd("PhotonDetectionEfficiency");
|
---|
333 | MSimAbsorption absmir("MirrorReflectivity");
|
---|
334 | MSimAbsorption cones("ConesAngularAcceptance");
|
---|
335 | cones.SetUseTheta();
|
---|
336 |
|
---|
337 | MSimPointingPos pointing;
|
---|
338 |
|
---|
339 | MSimReflector reflect;
|
---|
340 | reflect.SetNameGeomCam("GeomCones");
|
---|
341 | // MSimStarField stars;
|
---|
342 |
|
---|
343 | MContinue cont1("MPhotonEvent.GetNumPhotons<1", "ContEmpty1");
|
---|
344 | MContinue cont2("MPhotonEvent.GetNumPhotons<1", "ContEmpty2");
|
---|
345 |
|
---|
346 | // -------------------------------------------------------------------
|
---|
347 |
|
---|
348 | MBinning binse( 100, 1, 100000, "BinningEnergy", "log");
|
---|
349 | MBinning binss( 100, 1, 10000000, "BinningSize", "log");
|
---|
350 | MBinning binsi( 100, -500, 500, "BinningImpact");
|
---|
351 | MBinning binsh( 150, 0, 50, "BinningHeight");
|
---|
352 | MBinning binsaz(720, -360, 360, "BinningAz");
|
---|
353 | MBinning binszd( 70, 0, 70, "BinningZd");
|
---|
354 | MBinning binsvc( 45, 0, 9, "BinningViewCone");
|
---|
355 | MBinning binsew(150, 0, 50, "BinningEvtWidth");
|
---|
356 | MBinning binsd("BinningDistC");
|
---|
357 | MBinning binsd0("BinningDist");
|
---|
358 | MBinning binstr("BinningTrigPos");
|
---|
359 |
|
---|
360 | plist.AddToList(&binse);
|
---|
361 | plist.AddToList(&binss);
|
---|
362 | plist.AddToList(&binsi);
|
---|
363 | plist.AddToList(&binsh);
|
---|
364 | plist.AddToList(&binszd);
|
---|
365 | plist.AddToList(&binsaz);
|
---|
366 | plist.AddToList(&binsvc);
|
---|
367 | plist.AddToList(&binsew);
|
---|
368 | plist.AddToList(&binstr);
|
---|
369 | plist.AddToList(&binsd);
|
---|
370 | plist.AddToList(&binsd0);
|
---|
371 |
|
---|
372 | MHn mhn1, mhn2, mhn3;
|
---|
373 | SetupHist(mhn1);
|
---|
374 | SetupHist(mhn2);
|
---|
375 | SetupHist(mhn3);
|
---|
376 |
|
---|
377 | MH3 mhtp("TriggerPos.fVal-IntendedPulsePos.fVal-MPulseShape.GetPulseWidth");
|
---|
378 | mhtp.SetName("TrigPos");
|
---|
379 | mhtp.SetTitle("Trigger position w.r.t. the first photon hitting a detector");
|
---|
380 |
|
---|
381 | MH3 mhew("MPhotonStatistics.fLength");
|
---|
382 | mhew.SetName("EvtWidth");
|
---|
383 | mhew.SetTitle("Time between first and last photon hitting a detector");
|
---|
384 |
|
---|
385 | MH3 mhed("MPhotonStatistics.fTimeMedDev");
|
---|
386 | mhed.SetName("EvtMedDev;EvtWidth");
|
---|
387 |
|
---|
388 | MFillH fillh1(&mhn1, "", "FillCorsika");
|
---|
389 | MFillH fillh2(&mhn2, "", "FillH2");
|
---|
390 | MFillH fillh3(&mhn3, "", "FillH3");
|
---|
391 | MFillH filltp(&mhtp, "", "FillTriggerPos");
|
---|
392 | MFillH fillew(&mhew, "", "FillEvtWidth");
|
---|
393 | MFillH filled(&mhed, "", "FillMedDev");
|
---|
394 | fillh1.SetNameTab("Corsika", "Distribution as simulated by Corsika");
|
---|
395 | fillh2.SetNameTab("Detectable", "Distribution of events hit the detector");
|
---|
396 | fillh3.SetNameTab("Triggered", "Distribution of triggered events");
|
---|
397 | filltp.SetNameTab("TrigPos", "TriggerPosition w.r.t the first photon");
|
---|
398 | fillew.SetNameTab("EvtWidth", "Time between first and last photon hitting a detector");
|
---|
399 | filled.SetNameTab("MedDev", "Time between first and last photon hitting a detector");
|
---|
400 |
|
---|
401 | MHPhotonEvent planeG(1); // Get from MaxImpact
|
---|
402 | MHPhotonEvent plane0(2); // Get from MReflector
|
---|
403 | MHPhotonEvent plane1(2);
|
---|
404 | MHPhotonEvent plane2(2);
|
---|
405 | MHPhotonEvent plane3(2);
|
---|
406 | MHPhotonEvent plane4(2);
|
---|
407 | MHPhotonEvent planeF1(3); // Get from MGeomCam
|
---|
408 | MHPhotonEvent planeF2(header.IsPointRun()?4:3); // Get from MGeomCam
|
---|
409 |
|
---|
410 | //MHPSF psf;
|
---|
411 |
|
---|
412 | MFillH fillG(&planeG, "MPhotonEvent", "FillGround");
|
---|
413 | MFillH fill0(&plane0, "MirrorPlane0", "FillReflector");
|
---|
414 | //MFillH fill1(&plane1, "MirrorPlane1", "FillCamShadow");
|
---|
415 | MFillH fill2(&plane2, "MirrorPlane2", "FillCandidates");
|
---|
416 | MFillH fill3(&plane3, "MirrorPlane3", "FillReflected");
|
---|
417 | MFillH fill4(&plane4, "MirrorPlane4", "FillFocal");
|
---|
418 | MFillH fillF1(&planeF1, "MPhotonEvent", "FillCamera");
|
---|
419 | MFillH fillF2(&planeF2, "MPhotonEvent", "FillCones");
|
---|
420 | //MFillH fillP(&psf, "MPhotonEvent", "FillPSF");
|
---|
421 |
|
---|
422 | fillG.SetNameTab("Ground", "Photon distribution at ground");
|
---|
423 | fill0.SetNameTab("Reflector", "Photon distribution at reflector plane w/o camera shadow");
|
---|
424 | //fill1.SetNameTab("CamShadow", "Photon distribution at reflector plane w/ camera shadow");
|
---|
425 | fill2.SetNameTab("Candidates", "'Can hit' photon distribution at reflector plane w/ camera shadow");
|
---|
426 | fill3.SetNameTab("Reflected", "Photon distribution after reflector projected to reflector plane");
|
---|
427 | fill4.SetNameTab("Focal", "Photon distribution at focal plane");
|
---|
428 | fillF1.SetNameTab("Camera", "Photon distribution which hit the detector");
|
---|
429 | fillF2.SetNameTab("Cones", "Photon distribution after cones");
|
---|
430 | //fillP.SetNameTab("PSF", "Photon distribution after cones for all mirrors");
|
---|
431 |
|
---|
432 | // -------------------------------------------------------------------
|
---|
433 |
|
---|
434 | // FIXME: Pedestal and Calibration runs should get P and C
|
---|
435 | const TString rule1(Form("s/cer([0-9]+)/%s\\/00$1_R_MonteCarlo.root/", Esc(fPathOut).Data()));
|
---|
436 | const TString rule2(Form("s/cer([0-9]+)/%s\\/00$1_I_MonteCarlo.root/", Esc(fPathOut).Data()));
|
---|
437 | const TString rule3(Form("s/cer([0-9]+)/%s\\/00$1_D_MonteCarlo.root/", Esc(fPathOut).Data()));
|
---|
438 |
|
---|
439 | MWriteRootFile write3a( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
|
---|
440 | MWriteRootFile write3b( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
|
---|
441 | MWriteRootFile write2a( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
|
---|
442 | MWriteRootFile write2b( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
|
---|
443 | MWriteRootFile write1a( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
|
---|
444 | MWriteRootFile write1b( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
|
---|
445 |
|
---|
446 | write1a.SetName("WriteRefData");
|
---|
447 | write1b.SetName("WriteRefMC");
|
---|
448 | write2a.SetName("WriteSigData");
|
---|
449 | write2b.SetName("WriteSigMC");
|
---|
450 | write3a.SetName("WriteCamData");
|
---|
451 | write3b.SetName("WriteCamMC");
|
---|
452 |
|
---|
453 | SetupCommonFileStructure(write1a);
|
---|
454 | SetupCommonFileStructure(write2a);
|
---|
455 | SetupCommonFileStructure(write3a);
|
---|
456 |
|
---|
457 | // R: Dedicated file structureedicated events
|
---|
458 | write1a.AddContainer("MPhotonEvent", "Events");
|
---|
459 |
|
---|
460 | // I: Dedicated file structureedicated events
|
---|
461 | write2a.AddContainer("MPedPhotFromExtractorRndm", "RunHeaders"); // FIXME: Needed for the signal files to be display in MARS
|
---|
462 | write2a.AddContainer("MSignalCam", "Events");
|
---|
463 |
|
---|
464 | // D: Dedicated file structureedicated events
|
---|
465 | write3a.AddContainer("ElectronicNoise", "RunHeaders");
|
---|
466 | write3a.AddContainer("MRawEvtData", "Events");
|
---|
467 |
|
---|
468 | // Basic MC data
|
---|
469 | write1b.AddContainer("MMcEvtBasic", "OriginalMC");
|
---|
470 | write2b.AddContainer("MMcEvtBasic", "OriginalMC");
|
---|
471 | write3b.AddContainer("MMcEvtBasic", "OriginalMC");
|
---|
472 |
|
---|
473 | // -------------------------------------------------------------------
|
---|
474 |
|
---|
475 | MGeomApply apply;
|
---|
476 |
|
---|
477 | MSimPSF simpsf;
|
---|
478 |
|
---|
479 | MSimGeomCam simgeom;
|
---|
480 | simgeom.SetNameGeomCam("GeomCones");
|
---|
481 |
|
---|
482 | MSimCalibrationSignal simcal;
|
---|
483 | simcal.SetNameGeomCam("GeomCones");
|
---|
484 |
|
---|
485 | // Dark Current: 4MHz = 0.004 GHz
|
---|
486 | // Light of night sky at La Palma: ~ 0.2 ph / cm^2 / sr / ns
|
---|
487 | // 5deg camera: 6e-3 sr
|
---|
488 | // NSB = 0.2*6e-3
|
---|
489 |
|
---|
490 | MSimRandomPhotons simnsb;
|
---|
491 | // simnsb.SetFreq(0.005, 0.004); // 5MHz/cm^2, 4MHz
|
---|
492 | simnsb.SetFreq(0, 0.04); // 40MHz fixed for each APD
|
---|
493 | simnsb.SetNameGeomCam("GeomCones");
|
---|
494 |
|
---|
495 | // FIXME: How do we handle star-light? We need the rate but we also
|
---|
496 | // need to process it through the mirror!
|
---|
497 |
|
---|
498 | MSimAPD simapd;
|
---|
499 | simapd.SetFreq(0.04); // Must be identical to MSimRanodmPhotons!!
|
---|
500 | simapd.SetNameGeomCam("GeomCones");
|
---|
501 |
|
---|
502 | MSimExcessNoise simexcnoise;
|
---|
503 | MSimBundlePhotons simsum;
|
---|
504 | MSimSignalCam simsignal;
|
---|
505 | MSimCamera simcam;
|
---|
506 | MSimTrigger simtrig;
|
---|
507 | MSimReadout simdaq;
|
---|
508 |
|
---|
509 | MContinue conttrig("TriggerPos.fVal<0", "ContTrigger");
|
---|
510 |
|
---|
511 | MParameterD pulpos("IntendedPulsePos");
|
---|
512 | // pulpos.SetVal(40); // [ns]
|
---|
513 | plist.AddToList(&pulpos);
|
---|
514 |
|
---|
515 | MParameterD trigger("TriggerPos");
|
---|
516 | trigger.SetVal(0);
|
---|
517 | plist.AddToList(&trigger);
|
---|
518 |
|
---|
519 | // -------------------------------------------------------------------
|
---|
520 |
|
---|
521 | // Remove isolated pixels
|
---|
522 | MImgCleanStd clean(0, 0);
|
---|
523 | clean.SetCleanLvl0(0); // The level above which isolated pixels are kept
|
---|
524 | clean.SetCleanRings(0);
|
---|
525 | clean.SetMethod(MImgCleanStd::kAbsolute);
|
---|
526 |
|
---|
527 | //clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
|
---|
528 |
|
---|
529 | MHillasCalc hcalc;
|
---|
530 | hcalc.Disable(MHillasCalc::kCalcConc);
|
---|
531 |
|
---|
532 | MHCamEvent evt0a(/*10*/0, "Signal", "Average signal;;S [ph]");
|
---|
533 | MHCamEvent evt0c(/*10*/0, "MaxSignal", "Maximum signal;;S [ph]");
|
---|
534 | MHCamEvent evt0d(/*11*/8, "ArrTm", "Time after first photon;;T [ns]");
|
---|
535 | evt0a.SetErrorSpread(kFALSE);
|
---|
536 | evt0c.SetCollectMax();
|
---|
537 |
|
---|
538 | MFillH fillx0a(&evt0a, "MSignalCam", "FillAvgSignal");
|
---|
539 | MFillH fillx0c(&evt0c, "MSignalCam", "FillMaxSignal");
|
---|
540 | MFillH fillx0d(&evt0d, "MSignalCam", "FillArrTm");
|
---|
541 | MFillH fillx1("MHHillas", "MHillas", "FillHillas");
|
---|
542 | //MFillH fillx2("MHHillasExt", "", "FillHillasExt");
|
---|
543 | MFillH fillx3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
|
---|
544 | MFillH fillth("MHThreshold", "", "FillThreshold");
|
---|
545 | MFillH fillca("MHCollectionArea", "", "FillTrigArea");
|
---|
546 | //MFillH fillx4("MHImagePar", "MImagePar", "FillImagePar");
|
---|
547 | //MFillH fillx5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
|
---|
548 |
|
---|
549 | fillth.SetNameTab("Threshold");
|
---|
550 | fillca.SetNameTab("TrigArea");
|
---|
551 |
|
---|
552 | // -------------------------------------------------------------------
|
---|
553 |
|
---|
554 | if (header.IsDataRun())
|
---|
555 | {
|
---|
556 | tasks.AddToList(&read);
|
---|
557 | tasks.AddToList(&pointing);
|
---|
558 | tasks.AddToList(&simmmcs);
|
---|
559 | if (!fPathOut.IsNull() && !HasNullOut())
|
---|
560 | {
|
---|
561 | tasks.AddToList(&write1b);
|
---|
562 | tasks.AddToList(&write2b);
|
---|
563 | if (fCamera)
|
---|
564 | tasks.AddToList(&write3b);
|
---|
565 | }
|
---|
566 | // if (header.IsPointRun())
|
---|
567 | // tasks.AddToList(&stars);
|
---|
568 | if (1)
|
---|
569 | tasks.AddToList(&simatm); // Here because before fillh1
|
---|
570 | tasks.AddToList(&fillh1);
|
---|
571 | tasks.AddToList(&fillG);
|
---|
572 | if (!header.IsPointRun())
|
---|
573 | {
|
---|
574 | tasks.AddToList(&absapd);
|
---|
575 | tasks.AddToList(&absmir);
|
---|
576 | if (0)
|
---|
577 | tasks.AddToList(&simatm); // FASTER?
|
---|
578 | }
|
---|
579 | tasks.AddToList(&reflect);
|
---|
580 | if (!header.IsPointRun())
|
---|
581 | {
|
---|
582 | tasks.AddToList(&fill0);
|
---|
583 | //tasks.AddToList(&fill1);
|
---|
584 | tasks.AddToList(&fill2);
|
---|
585 | tasks.AddToList(&fill3);
|
---|
586 | tasks.AddToList(&fill4);
|
---|
587 | tasks.AddToList(&fillF1);
|
---|
588 | }
|
---|
589 | tasks.AddToList(&cones);
|
---|
590 | tasks.AddToList(&fillF2);
|
---|
591 | //if (header.IsPointRun())
|
---|
592 | // tasks.AddToList(&fillP);
|
---|
593 | tasks.AddToList(&cont1);
|
---|
594 | if (!header.IsPointRun())
|
---|
595 | tasks.AddToList(&fillh2);
|
---|
596 | }
|
---|
597 | // -------------------------------
|
---|
598 | tasks.AddToList(&apply);
|
---|
599 | if (header.IsDataRun())
|
---|
600 | {
|
---|
601 | tasks.AddToList(&simpsf);
|
---|
602 | tasks.AddToList(&simgeom);
|
---|
603 | tasks.AddToList(&cont2);
|
---|
604 | }
|
---|
605 | if (fCamera)
|
---|
606 | {
|
---|
607 | if (header.IsPedestalRun() || header.IsCalibrationRun())
|
---|
608 | tasks.AddToList(&simcal);
|
---|
609 | tasks.AddToList(&simnsb);
|
---|
610 | tasks.AddToList(&simapd);
|
---|
611 | tasks.AddToList(&simexcnoise);
|
---|
612 | }
|
---|
613 | tasks.AddToList(&simsum);
|
---|
614 | if (fCamera)
|
---|
615 | {
|
---|
616 | tasks.AddToList(&simcam);
|
---|
617 | if (header.IsDataRun() || fForceTrigger)
|
---|
618 | tasks.AddToList(&simtrig);
|
---|
619 | tasks.AddToList(&conttrig);
|
---|
620 | tasks.AddToList(&simdaq);
|
---|
621 | }
|
---|
622 | tasks.AddToList(&simsignal); // What do we do if signal<0?
|
---|
623 | if (!fPathOut.IsNull() && !HasNullOut())
|
---|
624 | {
|
---|
625 | tasks.AddToList(&write1a);
|
---|
626 | if (!header.IsPedestalRun())
|
---|
627 | tasks.AddToList(&write2a);
|
---|
628 | if (fCamera)
|
---|
629 | tasks.AddToList(&write3a);
|
---|
630 | }
|
---|
631 | // -------------------------------
|
---|
632 | if (fCamera)
|
---|
633 | {
|
---|
634 | // FIXME: MHCollectionArea Trigger Area!
|
---|
635 | if (header.IsDataRun())
|
---|
636 | tasks.AddToList(&fillh3);
|
---|
637 | tasks.AddToList(&filltp);
|
---|
638 | }
|
---|
639 | if (header.IsDataRun())
|
---|
640 | {
|
---|
641 | tasks.AddToList(&fillew);
|
---|
642 | tasks.AddToList(&filled);
|
---|
643 | }
|
---|
644 | if (!header.IsPedestalRun())
|
---|
645 | {
|
---|
646 | tasks.AddToList(&fillx0a);
|
---|
647 | tasks.AddToList(&fillx0c);
|
---|
648 | if (!header.IsCalibrationRun())
|
---|
649 | tasks.AddToList(&clean);
|
---|
650 | tasks.AddToList(&hcalc);
|
---|
651 | tasks.AddToList(&fillx0d);
|
---|
652 | tasks.AddToList(&fillx1);
|
---|
653 | //tasks.AddToList(&fillx2);
|
---|
654 | tasks.AddToList(&fillx3);
|
---|
655 | tasks.AddToList(&fillth);
|
---|
656 | tasks.AddToList(&fillca);
|
---|
657 | //tasks.AddToList(&fillx4);
|
---|
658 | //tasks.AddToList(&fillx5);
|
---|
659 | }
|
---|
660 | //-------------------------------------------
|
---|
661 |
|
---|
662 | tasks.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
|
---|
663 |
|
---|
664 | // Create and setup the eventloop
|
---|
665 | MEvtLoop evtloop(fName);
|
---|
666 | evtloop.SetParList(&plist);
|
---|
667 | evtloop.SetDisplay(fDisplay);
|
---|
668 | evtloop.SetLogStream(&gLog);
|
---|
669 | if (!SetupEnv(evtloop))
|
---|
670 | return kFALSE;
|
---|
671 |
|
---|
672 | // FIXME: If pedestal file given use the values from this file
|
---|
673 | //-------------------------------------------
|
---|
674 |
|
---|
675 | MGeomCam *cam = static_cast<MGeomCam*>(env2.GetCont());
|
---|
676 |
|
---|
677 | if (binstr.IsDefault())
|
---|
678 | binstr.SetEdgesLin(150, -shape.GetPulseWidth(),
|
---|
679 | header.GetFreqSampling()/1000.*header.GetNumSamples()+shape.GetPulseWidth());
|
---|
680 |
|
---|
681 | if (binsd.IsDefault() && cam)
|
---|
682 | binsd.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
|
---|
683 |
|
---|
684 | if (binsd0.IsDefault() && cam)
|
---|
685 | binsd0.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
|
---|
686 |
|
---|
687 |
|
---|
688 | header.Print();
|
---|
689 |
|
---|
690 | // FIXME: Display acceptance curves!
|
---|
691 |
|
---|
692 | if (fDisplay)
|
---|
693 | {
|
---|
694 | TCanvas &c = fDisplay->AddTab("Info");
|
---|
695 | c.Divide(2,2);
|
---|
696 |
|
---|
697 | c.cd(1);
|
---|
698 | gPad->SetBorderMode(0);
|
---|
699 | gPad->SetFrameBorderMode(0);
|
---|
700 | gPad->SetGridx();
|
---|
701 | gPad->SetGridy();
|
---|
702 | gROOT->SetSelectedPad(0);
|
---|
703 | shape.DrawClone()->SetBit(kCanDelete);
|
---|
704 |
|
---|
705 | if (env0.GetCont() && (header.IsDataRun() || header.IsPointRun()))
|
---|
706 | {
|
---|
707 | c.cd(3);
|
---|
708 | gPad->SetBorderMode(0);
|
---|
709 | gPad->SetFrameBorderMode(0);
|
---|
710 | gPad->SetGridx();
|
---|
711 | gPad->SetGridy();
|
---|
712 | gROOT->SetSelectedPad(0);
|
---|
713 | static_cast<MReflector*>(env0.GetCont())->DrawClone("line")->SetBit(kCanDelete);
|
---|
714 |
|
---|
715 | }
|
---|
716 |
|
---|
717 | if (fCamera)
|
---|
718 | {
|
---|
719 | if (env1.GetCont())
|
---|
720 | {
|
---|
721 | c.cd(2);
|
---|
722 | gPad->SetBorderMode(0);
|
---|
723 | gPad->SetFrameBorderMode(0);
|
---|
724 | gPad->SetGridx();
|
---|
725 | gPad->SetGridy();
|
---|
726 | gROOT->SetSelectedPad(0);
|
---|
727 | MHCamera *c = new MHCamera(static_cast<MGeomCam&>(*env1.GetCont()));
|
---|
728 | c->SetStats(kFALSE);
|
---|
729 | c->SetBit(MHCamera::kNoLegend);
|
---|
730 | c->SetBit(kCanDelete);
|
---|
731 | c->Draw();
|
---|
732 |
|
---|
733 | }
|
---|
734 |
|
---|
735 | if (cam)
|
---|
736 | {
|
---|
737 | c.cd(4);
|
---|
738 | gPad->SetBorderMode(0);
|
---|
739 | gPad->SetFrameBorderMode(0);
|
---|
740 | gPad->SetGridx();
|
---|
741 | gPad->SetGridy();
|
---|
742 | gROOT->SetSelectedPad(0);
|
---|
743 | MHCamera *c = new MHCamera(*cam);
|
---|
744 | c->SetStats(kFALSE);
|
---|
745 | c->SetBit(MHCamera::kNoLegend);
|
---|
746 | c->SetBit(kCanDelete);
|
---|
747 | c->Draw();
|
---|
748 | }
|
---|
749 | }
|
---|
750 | }
|
---|
751 |
|
---|
752 | //-------------------------------------------
|
---|
753 |
|
---|
754 | // Execute first analysis
|
---|
755 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
756 | {
|
---|
757 | gLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
758 | return kFALSE;
|
---|
759 | }
|
---|
760 |
|
---|
761 | //-------------------------------------------
|
---|
762 | // FIXME: Display Spline in tab
|
---|
763 | // FIXME: Display Reflector in tab
|
---|
764 | // FIXME: Display Routing(?) in tab
|
---|
765 | // FIXME: Display Camera(s) in tab
|
---|
766 | //-------------------------------------------
|
---|
767 |
|
---|
768 | if (!WriteResult(plist))
|
---|
769 | return kFALSE;
|
---|
770 |
|
---|
771 | *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
|
---|
772 |
|
---|
773 | return kTRUE;
|
---|
774 | }
|
---|