source: branches/AddingGoogleTestEnvironment/mjobs/MJSimulation.cc@ 19923

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