source: trunk/MagicSoft/Mars/mjobs/MJSimulation.cc@ 9461

Last change on this file since 9461 was 9461, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 28.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 1/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 "MSpline3.h"
111#include "MParSpline.h"
112#include "MGeomCam.h"
113
114#include "MPedestalCam.h"
115#include "MPedestalPix.h"
116
117ClassImp(MJSimulation);
118
119using namespace std;
120
121// --------------------------------------------------------------------------
122//
123// Default constructor.
124//
125// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
126//
127MJSimulation::MJSimulation(const char *name, const char *title)
128 : fForceMode(kFALSE), fCamera(kTRUE), fForceTrigger(kFALSE),
129 fOperationMode(kModeData)
130{
131 fName = name ? name : "MJSimulation";
132 fTitle = title ? title : "Standard analysis and reconstruction";
133}
134
135Bool_t MJSimulation::CheckEnvLocal()
136{
137 fForceMode = GetEnv("ForceMode", fForceMode);
138 fForceTrigger = GetEnv("ForceTrigger", fForceTrigger);
139 fCamera = GetEnv("Camera", fCamera);
140
141 return kTRUE;
142}
143/*
144TString MJSimulation::GetOutFile(const MSequence &seq) const
145{
146 return seq.IsValid() ? Form("ceres%08d.root", seq.GetSequence()) : "ceres.root";
147}
148*/
149
150Bool_t MJSimulation::WriteResult(const MParList &plist, const MSequence &seq)
151{
152 if (fPathOut.IsNull())
153 {
154 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
155 return kTRUE;
156 }
157
158 TObjArray cont;
159 cont.Add(const_cast<TEnv*>(GetEnv()));
160 if (seq.IsValid())
161 cont.Add(const_cast<MSequence*>(&seq));
162
163 cont.Add(plist.FindObject("PulseShape"));
164 cont.Add(plist.FindObject("Reflector"));
165 cont.Add(plist.FindObject("MGeomCam"));
166 cont.Add(plist.FindObject("GeomCones"));
167
168 if (fDisplay)
169 {
170 TString title = "-- Ceres";
171 if (seq.IsValid())
172 {
173 title += ": ";
174 title += seq.GetSequence();
175 }
176 title += " --";
177 fDisplay->SetTitle("Ceres", kFALSE);
178
179 cont.Add(fDisplay);
180 }
181
182 const TString name = seq.IsValid() ? Form("ceres%08d.root", seq.GetSequence()) : "ceres.root";
183 return WriteContainer(cont, name, "RECREATE");
184}
185
186void MJSimulation::SetupHist(MHn &hist) const
187{
188 hist.AddHist("MCorsikaEvtHeader.fTotalEnergy");
189 hist.InitName("Energy");
190 hist.InitTitle("Energy;E [GeV]");
191 hist.SetLog(kTRUE, kTRUE, kFALSE);
192
193 hist.AddHist("MPhotonEvent.GetNumExternal");
194 hist.InitName("Size");
195 hist.InitTitle("Size;S [#]");
196 hist.SetLog(kTRUE, kTRUE, kFALSE);
197
198 /*
199 hist.AddHist("-MCorsikaEvtHeader.fX/100","-MCorsikaEvtHeader.fY/100");
200 hist.SetDrawOption("colz");
201 hist.InitName("Impact;Impact;Impact");
202 hist.InitTitle("Impact;West <--> East [m];South <--> North [m]");
203 hist.SetAutoRange();
204 */
205
206 hist.AddHist("MCorsikaEvtHeader.GetImpact/100");
207 hist.InitName("Impact");
208 hist.InitTitle("Impact;Impact [m]");
209 hist.SetAutoRange();
210
211 hist.AddHist("MCorsikaEvtHeader.fFirstInteractionHeight/100000");
212 hist.InitName("Height");
213 hist.InitTitle("FirstInteractionHeight;h [km]");
214
215 hist.AddHist("(MCorsikaEvtHeader.fAz+MCorsikaRunHeader.fMagneticFieldAz)*TMath::RadToDeg()", "MCorsikaEvtHeader.fZd*TMath::RadToDeg()");
216 hist.InitName("SkyOrigin;Az;Zd");
217 hist.InitTitle("Sky Origin;Az [\\deg];Zd [\\deg]");
218 hist.SetDrawOption("colz");
219 hist.SetAutoRange();
220
221 TString sin2 = "sin(MCorsikaEvtHeader.fZd)*sin(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
222 TString cos2 = "cos(MCorsikaEvtHeader.fZd)*cos(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
223 TString cos = "cos(MCorsikaEvtHeader.fAz-MCorsikaRunHeader.fAzMin*TMath::DegToRad())";
224
225 TString form = "acos("+sin2+"*"+cos+"+"+cos2+")*TMath::RadToDeg()";
226
227 hist.AddHist(form);
228 hist.InitName("ViewCone");
229 hist.InitTitle("Incident Angle;\\alpha [\\deg]");
230}
231
232void MJSimulation::SetupCommonFileStructure(MWriteRootFile &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}
246
247Bool_t MJSimulation::Process(const MArgs &args, const MSequence &seq)
248{
249 /*
250 if (!fSequence.IsValid())
251 {
252 *fLog << err << "ERROR - Sequence invalid!" << endl;
253 return kFALSE;
254 }
255 */
256
257// if (!HasWritePermission(CombinePath(fPathOut, GetOutFile(seq))))
258// return kFALSE;
259
260 *fLog << inf;
261 fLog->Separator(GetDescriptor());
262
263 if (!CheckEnv())
264 return kFALSE;
265
266 if (seq.IsValid())
267 *fLog << fSequence.GetFileName() << endl;
268 else
269 *fLog << args.GetNumArguments() << "-files" << endl;
270 *fLog << endl;
271
272 MDirIter iter;
273 if (seq.IsValid() && seq.GetRuns(iter, MSequence::kCorsika)<=0)
274 {
275 *fLog << err << "ERROR - Sequence valid but without files." << endl;
276 return kFALSE;
277 }
278
279 // --------------------------------------------------------------------------------
280
281 // Setup Parlist
282 MParList plist;
283 plist.AddToList(this); // take care of fDisplay!
284
285 // setup TaskList
286 MTaskList tasks;
287 plist.AddToList(&tasks);
288
289 // --------------------------------------------------------------------------------
290
291 // FIXME: Allow empty GeomCones!
292 MParEnv env0("Reflector");
293 MParEnv env1("GeomCones");
294 MParEnv env2("MGeomCam");
295 env0.SetClassName("MReflector");
296 env1.SetClassName("MGeomCam");
297 env2.SetClassName("MGeomCam");
298 plist.AddToList(&env0);
299 plist.AddToList(&env1);
300 plist.AddToList(&env2);
301
302 plist.FindCreateObj("MPedPhotCam", "MPedPhotFromExtractorRndm");
303
304 MParSpline shape("PulseShape");
305 plist.AddToList(&shape);
306
307 // *** FIXME *** FIXME *** FIXME ***
308 plist.FindCreateObj("MMcRunHeader");
309
310 MRawRunHeader header;
311 header.SetValidMagicNumber();
312 //header.InitFadcType(3);
313
314 switch (fOperationMode)
315 {
316 case kModeData:
317 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTData);
318 break;
319
320 case kModePed:
321 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPedestal);
322 header.SetSourceInfo("Pedestal");
323 break;
324
325 case kModeCal:
326 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTCalibration);
327 header.SetSourceInfo("Calibration");
328 break;
329
330 case kModePointRun:
331 header.SetRunType(MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPointRun);
332 break;
333 }
334
335 // FIXME: Move to MSimPointingPos, MSimCalibrationSignal
336 // Can we use this as input for MSimPointingPos?
337 header.SetObservation("On", "MonteCarlo");
338 plist.AddToList(&header);
339 // ++++++++ FIXME FIXME FIXME +++++++++++++
340
341 /*
342 MPedestalCam pedcam;
343 pedcam.Init(geomcam.GetNumPixels());
344 for (UInt_t i=0; i<geomcam.GetNumPixels(); i++)
345 pedcam[i].Set(128./header.GetScale(), 22.5/header.GetScale());
346 plist.AddToList(&pedcam);
347 */
348
349 // -------------------------------------------------------------------
350
351 MCorsikaRead read;
352 read.SetForceMode(fForceMode);
353
354 if (!seq.IsValid())
355 {
356 for (int i=0; i<args.GetNumArguments(); i++)
357 read.AddFile(args.GetArgumentStr(i));
358 }
359 else
360 read.AddFiles(iter);
361
362 MContinue precut("", "PreCut");
363 precut.IsInverted();
364 precut.SetAllowEmpty();
365
366 MSimMMCS simmmcs;
367
368 MParSpline splinepde("PhotonDetectionEfficiency");
369 MParSpline splinemirror("MirrorReflectivity");
370 MParSpline splinecones("ConesAngularAcceptance");
371 plist.AddToList(&splinepde);
372 plist.AddToList(&splinemirror);
373 plist.AddToList(&splinecones);
374
375 MSimAtmosphere simatm;
376 MSimAbsorption absapd("SimPhotonDetectionEfficiency");
377 MSimAbsorption absmir("SimMirrorReflectivity");
378 MSimAbsorption cones("SimConesAngularAcceptance");
379 absapd.SetParName("PhotonDetectionEfficiency");
380 absmir.SetParName("MirrorReflectivity");
381 cones.SetParName("ConesAngularAcceptance");
382 cones.SetUseTheta();
383
384 MSimPointingPos pointing;
385
386 MSimReflector reflect;
387 reflect.SetNameGeomCam("GeomCones");
388// MSimStarField stars;
389
390 MContinue cont1("MPhotonEvent.GetNumPhotons<1", "ContEmpty1");
391 MContinue cont2("MPhotonEvent.GetNumPhotons<1", "ContEmpty2");
392 MContinue cont3("MPhotonEvent.GetNumPhotons<2", "ContEmpty3");
393
394 // -------------------------------------------------------------------
395
396 MBinning binse( 120, 1, 1000000, "BinningEnergy", "log");
397 MBinning binsth( 60, 0.9, 900000, "BinningThreshold", "log");
398 MBinning binsee( 36, 0.9, 900000, "BinningEnergyEst", "log");
399 MBinning binss( 100, 1, 10000000, "BinningSize", "log");
400// MBinning binsi( 100, -500, 500, "BinningImpact");
401 MBinning binsi( 32, 0, 800, "BinningImpact");
402 MBinning binsh( 150, 0, 50, "BinningHeight");
403 MBinning binsaz(720, -360, 360, "BinningAz");
404 MBinning binszd( 70, 0, 70, "BinningZd");
405 MBinning binsvc( 35, 0, 7, "BinningViewCone");
406 MBinning binsel(150, 0, 50, "BinningTotLength");
407 MBinning binsew(150, 0, 15, "BinningMedLength");
408 MBinning binsd("BinningDistC");
409 MBinning binsd0("BinningDist");
410 MBinning binstr("BinningTrigPos");
411
412 plist.AddToList(&binsee);
413 plist.AddToList(&binse);
414 plist.AddToList(&binsth);
415 plist.AddToList(&binss);
416 plist.AddToList(&binsi);
417 plist.AddToList(&binsh);
418 plist.AddToList(&binszd);
419 plist.AddToList(&binsaz);
420 plist.AddToList(&binsvc);
421 plist.AddToList(&binsel);
422 plist.AddToList(&binsew);
423 plist.AddToList(&binstr);
424 plist.AddToList(&binsd);
425 plist.AddToList(&binsd0);
426
427 MHn mhn1, mhn2, mhn3, mhn4;
428 SetupHist(mhn1);
429 SetupHist(mhn2);
430 SetupHist(mhn3);
431 SetupHist(mhn4);
432
433 MH3 mhtp("TriggerPos.fVal-IntendedPulsePos.fVal-PulseShape.GetWidth");
434 mhtp.SetName("TrigPos");
435 mhtp.SetTitle("Trigger position w.r.t. the first photon hitting a detector");
436
437 MH3 mhew("MPhotonStatistics.fLength");
438 mhew.SetName("TotLength");
439 mhew.SetTitle("Time between first and last photon hitting a detector;L [ns]");
440
441 MH3 mhed("MPhotonStatistics.fTimeMedDev");
442 mhed.SetName("MedLength");
443 mhed.SetTitle("Median deviation (1\\sigma);L [ns]");
444
445 MFillH fillh1(&mhn1, "", "FillCorsika");
446 MFillH fillh2(&mhn2, "", "FillH2");
447 MFillH fillh3(&mhn3, "", "FillH3");
448 MFillH fillh4(&mhn4, "", "FillH4");
449 MFillH filltp(&mhtp, "", "FillTriggerPos");
450 MFillH fillew(&mhew, "", "FillEvtWidth");
451 MFillH filled(&mhed, "", "FillMedDev");
452 fillh1.SetNameTab("Corsika", "Distribution as simulated by Corsika");
453 fillh2.SetNameTab("Detectable", "Distribution of events hit the detector");
454 fillh3.SetNameTab("Triggered", "Distribution of triggered events");
455 fillh4.SetNameTab("Cleaned", "Distribution after cleaning and cuts");
456 filltp.SetNameTab("TrigPos", "TriggerPosition w.r.t the first photon");
457 fillew.SetNameTab("EvtWidth", "Time between first and last photon hitting a detector");
458 filled.SetNameTab("MedDev", "Time between first and last photon hitting a detector");
459
460 MHPhotonEvent planeG(1, "HPhotonEventGround"); // Get from MaxImpact
461 MHPhotonEvent plane0(2, "HMirrorPlane0"); // Get from MReflector
462 //MHPhotonEvent plane1(2, "HMirrorPlane1");
463 MHPhotonEvent plane2(2, "HMirrorPlane2");
464 MHPhotonEvent plane3(2, "HMirrorPlane3");
465 MHPhotonEvent plane4(2, "HMirrorPlane4");
466 MHPhotonEvent planeF1(3, "HPhotonEventCamera"); // Get from MGeomCam
467 MHPhotonEvent planeF2(header.IsPointRun()?4:3, "HPhotonEventCones"); // Get from MGeomCam
468
469 plist.AddToList(&planeG);
470 plist.AddToList(&plane0);
471 plist.AddToList(&plane2);
472 plist.AddToList(&plane3);
473 plist.AddToList(&plane4);
474 plist.AddToList(&planeF1);
475 plist.AddToList(&planeF2);;
476
477 //MHPSF psf;
478
479 MFillH fillG(&planeG, "MPhotonEvent", "FillGround");
480 MFillH fill0(&plane0, "MirrorPlane0", "FillReflector");
481 //MFillH fill1(&plane1, "MirrorPlane1", "FillCamShadow");
482 MFillH fill2(&plane2, "MirrorPlane2", "FillCandidates");
483 MFillH fill3(&plane3, "MirrorPlane3", "FillReflected");
484 MFillH fill4(&plane4, "MirrorPlane4", "FillFocal");
485 MFillH fillF1(&planeF1, "MPhotonEvent", "FillCamera");
486 MFillH fillF2(&planeF2, "MPhotonEvent", "FillCones");
487 //MFillH fillP(&psf, "MPhotonEvent", "FillPSF");
488
489 fillG.SetNameTab("Ground", "Photon distribution at ground");
490 fill0.SetNameTab("Reflector", "Photon distribution at reflector plane w/o camera shadow");
491 //fill1.SetNameTab("CamShadow", "Photon distribution at reflector plane w/ camera shadow");
492 fill2.SetNameTab("Candidates", "'Can hit' photon distribution at reflector plane w/ camera shadow");
493 fill3.SetNameTab("Reflected", "Photon distribution after reflector projected to reflector plane");
494 fill4.SetNameTab("Focal", "Photon distribution at focal plane");
495 fillF1.SetNameTab("Camera", "Photon distribution which hit the detector");
496 fillF2.SetNameTab("Cones", "Photon distribution after cones");
497 //fillP.SetNameTab("PSF", "Photon distribution after cones for all mirrors");
498
499 // -------------------------------------------------------------------
500
501 const char *fmt = Form("s/cer([0-9]+)/%%s\\/00$1_%c_MonteCarlo.root/", header.GetRunTypeChar());
502
503 // FIXME: Pedestal and Calibration runs should get P and C
504 const TString rule1(Form("s/cer([0-9]+)/%s\\/00$1_R_MonteCarlo.root/", Esc(fPathOut).Data()));
505 const TString rule2(Form("s/cer([0-9]+)/%s\\/00$1_Y_MonteCarlo.root/", Esc(fPathOut).Data()));
506 const TString rule3(Form(fmt, Esc(fPathOut).Data()));
507
508 MWriteRootFile write3a( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
509 MWriteRootFile write3b( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
510 MWriteRootFile write2a( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
511 MWriteRootFile write2b( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
512 MWriteRootFile write1a( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
513 MWriteRootFile write1b( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
514
515 write1a.SetName("WriteRefData");
516 write1b.SetName("WriteRefMC");
517 write2a.SetName("WriteSigData");
518 write2b.SetName("WriteSigMC");
519 write3a.SetName("WriteCamData");
520 write3b.SetName("WriteCamMC");
521
522 SetupCommonFileStructure(write1a);
523 SetupCommonFileStructure(write2a);
524 SetupCommonFileStructure(write3a);
525
526 // R: Dedicated file structureedicated events
527 write1a.AddContainer("MPhotonEvent", "Events");
528
529 // I: Dedicated file structureedicated events
530 write2a.AddContainer("MPedPhotFromExtractorRndm", "RunHeaders"); // FIXME: Needed for the signal files to be display in MARS
531 write2a.AddContainer("MSignalCam", "Events");
532
533 // D: Dedicated file structureedicated events
534 write3a.AddContainer("ElectronicNoise", "RunHeaders");
535 write3a.AddContainer("MRawEvtData", "Events");
536
537 // Basic MC data
538 write1b.AddContainer("MMcEvtBasic", "OriginalMC");
539 write2b.AddContainer("MMcEvtBasic", "OriginalMC");
540 write3b.AddContainer("MMcEvtBasic", "OriginalMC");
541
542 // -------------------------------------------------------------------
543
544 MGeomApply apply;
545
546 MSimPSF simpsf;
547
548 MSimGeomCam simgeom;
549 simgeom.SetNameGeomCam("GeomCones");
550
551 MSimCalibrationSignal simcal;
552 simcal.SetNameGeomCam("GeomCones");
553
554 // FIXME: Simulate photons before cones and QE!
555
556 MSimRandomPhotons simnsb;
557 simnsb.SetFreq(5.8, 0.004); // ph/m^2/nm/sr/ns NSB, 4MHz dark count rate
558 simnsb.SetNameGeomCam("GeomCones");
559
560 // FIXME: How do we handle star-light? We need the rate but we also
561 // need to process it through the mirror!
562
563 MSimAPD simapd;
564 simapd.SetNameGeomCam("GeomCones");
565
566 MSimExcessNoise simexcnoise;
567 MSimBundlePhotons simsum;
568 MSimSignalCam simsignal;
569 MSimCamera simcam;
570 MSimTrigger simtrig;
571 MSimReadout simdaq;
572
573 MContinue conttrig("TriggerPos.fVal<0", "ContTrigger");
574
575 MParameterD pulpos("IntendedPulsePos");
576 // FIXME: Set a default which could be 1/3 of the digitization window
577 // pulpos.SetVal(40); // [ns]
578 plist.AddToList(&pulpos);
579
580 MParameterD trigger("TriggerPos");
581 trigger.SetVal(0);
582 plist.AddToList(&trigger);
583
584 // -------------------------------------------------------------------
585
586 // Remove isolated pixels
587 MImgCleanStd clean(0, 0);
588 clean.SetCleanLvl0(0); // The level above which isolated pixels are kept
589 clean.SetCleanRings(0);
590 clean.SetMethod(MImgCleanStd::kAbsolute);
591
592 //clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
593
594 MHillasCalc hcalc;
595 hcalc.Disable(MHillasCalc::kCalcConc);
596
597 MHCamEvent evt0a(/*10*/3, "Signal", "Average signal (absolute);;S [ph]");
598 MHCamEvent evt0c(/*10*/3, "MaxSignal", "Maximum signal (absolute);;S [ph]");
599 MHCamEvent evt0d(/*11*/8, "ArrTm", "Time after first photon;;T [ns]");
600 evt0a.SetErrorSpread(kFALSE);
601 evt0c.SetCollectMax();
602
603 MContinue cut("", "Cut");
604
605 MFillH fillx0a(&evt0a, "MSignalCam", "FillAvgSignal");
606 MFillH fillx0c(&evt0c, "MSignalCam", "FillMaxSignal");
607 MFillH fillx0d(&evt0d, "MSignalCam", "FillArrTm");
608 MFillH fillx1("MHHillas", "MHillas", "FillHillas");
609 MFillH fillx3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
610 MFillH fillx4("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
611 MFillH fillth("MHThreshold", "", "FillThreshold");
612 MFillH fillca("MHCollectionArea", "", "FillTrigArea");
613
614 fillth.SetNameTab("Threshold");
615 fillca.SetNameTab("TrigArea");
616
617 // -------------------------------------------------------------------
618
619 if (header.IsDataRun())
620 {
621 tasks.AddToList(&read);
622 tasks.AddToList(&precut);
623 tasks.AddToList(&pointing);
624 tasks.AddToList(&simmmcs);
625 if (!fPathOut.IsNull() && !HasNullOut())
626 {
627 tasks.AddToList(&write1b);
628 tasks.AddToList(&write2b);
629 if (fCamera)
630 tasks.AddToList(&write3b);
631 }
632 // if (header.IsPointRun())
633 // tasks.AddToList(&stars);
634 if (1)
635 tasks.AddToList(&simatm); // Here because before fillh1
636 tasks.AddToList(&fillh1);
637 tasks.AddToList(&fillG);
638 if (!header.IsPointRun())
639 {
640 tasks.AddToList(&absapd);
641 tasks.AddToList(&absmir);
642 if (0)
643 tasks.AddToList(&simatm); // FASTER?
644 }
645 tasks.AddToList(&reflect);
646 if (!header.IsPointRun())
647 {
648 tasks.AddToList(&fill0);
649 //tasks.AddToList(&fill1);
650 tasks.AddToList(&fill2);
651 tasks.AddToList(&fill3);
652 tasks.AddToList(&fill4);
653 tasks.AddToList(&fillF1);
654 }
655 tasks.AddToList(&cones);
656 //if (header.IsPointRun())
657 // tasks.AddToList(&fillP);
658 tasks.AddToList(&cont1);
659 }
660 // -------------------------------
661 tasks.AddToList(&apply);
662 if (header.IsDataRun())
663 {
664 tasks.AddToList(&simpsf);
665 tasks.AddToList(&simgeom);
666 tasks.AddToList(&cont2);
667 if (!header.IsPointRun())
668 {
669 tasks.AddToList(&fillF2);
670 tasks.AddToList(&fillh2);
671 }
672 tasks.AddToList(&cont3);
673 }
674 if (fCamera)
675 {
676 if (header.IsPedestalRun() || header.IsCalibrationRun())
677 tasks.AddToList(&simcal);
678 tasks.AddToList(&simnsb);
679 tasks.AddToList(&simapd);
680 tasks.AddToList(&simexcnoise);
681 }
682 tasks.AddToList(&simsum);
683 if (fCamera)
684 {
685 tasks.AddToList(&simcam);
686 if (header.IsDataRun() || fForceTrigger)
687 tasks.AddToList(&simtrig);
688 tasks.AddToList(&conttrig);
689 tasks.AddToList(&simdaq);
690 }
691 tasks.AddToList(&simsignal); // What do we do if signal<0?
692 if (!fPathOut.IsNull() && !HasNullOut())
693 {
694 tasks.AddToList(&write1a);
695 if (!header.IsPedestalRun())
696 tasks.AddToList(&write2a);
697 if (fCamera)
698 tasks.AddToList(&write3a);
699 }
700 // -------------------------------
701 if (fCamera)
702 {
703 // FIXME: MHCollectionArea Trigger Area!
704 if (header.IsDataRun())
705 tasks.AddToList(&fillh3);
706 tasks.AddToList(&filltp);
707 }
708 if (header.IsDataRun())
709 {
710 tasks.AddToList(&fillew);
711 tasks.AddToList(&filled);
712 }
713 if (!header.IsPedestalRun())
714 {
715 tasks.AddToList(&fillx0a);
716 tasks.AddToList(&fillx0c);
717 if (!header.IsCalibrationRun())
718 tasks.AddToList(&clean);
719 tasks.AddToList(&hcalc);
720 tasks.AddToList(&cut);
721 tasks.AddToList(&fillx0d);
722 tasks.AddToList(&fillx1);
723 //tasks.AddToList(&fillx2);
724 tasks.AddToList(&fillx3);
725 tasks.AddToList(&fillx4);
726 //tasks.AddToList(&fillx5);
727 }
728 if (header.IsDataRun())
729 {
730 tasks.AddToList(&fillh4);
731 tasks.AddToList(&fillth);
732 tasks.AddToList(&fillca);
733 }
734 //-------------------------------------------
735
736 tasks.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
737
738 // Create and setup the eventloop
739 MEvtLoop evtloop(fName);
740 evtloop.SetParList(&plist);
741 evtloop.SetDisplay(fDisplay);
742 evtloop.SetLogStream(&gLog);
743 if (!SetupEnv(evtloop))
744 return kFALSE;
745
746 // FIXME: If pedestal file given use the values from this file
747 //-------------------------------------------
748
749 MGeomCam *cam = static_cast<MGeomCam*>(env2.GetCont());
750
751 if (binstr.IsDefault())
752 binstr.SetEdgesLin(150, -shape.GetWidth(),
753 header.GetFreqSampling()/1000.*header.GetNumSamples()+shape.GetWidth());
754
755 if (binsd.IsDefault() && cam)
756 binsd.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
757
758 if (binsd0.IsDefault() && cam)
759 binsd0.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
760
761
762 header.Print();
763
764 // FIXME: Display acceptance curves!
765
766 if (fDisplay)
767 {
768 TCanvas &c = fDisplay->AddTab("Info");
769 c.Divide(2,2);
770
771 c.cd(1);
772 gPad->SetBorderMode(0);
773 gPad->SetFrameBorderMode(0);
774 gPad->SetGridx();
775 gPad->SetGridy();
776 gROOT->SetSelectedPad(0);
777 shape.DrawClone()->SetBit(kCanDelete);
778
779 if (env0.GetCont() && (header.IsDataRun() || header.IsPointRun()))
780 {
781 c.cd(3);
782 gPad->SetBorderMode(0);
783 gPad->SetFrameBorderMode(0);
784 gPad->SetGridx();
785 gPad->SetGridy();
786 gROOT->SetSelectedPad(0);
787 static_cast<MReflector*>(env0.GetCont())->DrawClone("line")->SetBit(kCanDelete);
788 }
789
790 if (fCamera)
791 {
792 if (env1.GetCont())
793 {
794 c.cd(2);
795 gPad->SetBorderMode(0);
796 gPad->SetFrameBorderMode(0);
797 gPad->SetGridx();
798 gPad->SetGridy();
799 gROOT->SetSelectedPad(0);
800 MHCamera *c = new MHCamera(static_cast<MGeomCam&>(*env1.GetCont()));
801 c->SetStats(kFALSE);
802 c->SetBit(MHCamera::kNoLegend);
803 c->SetBit(kCanDelete);
804 c->Draw();
805 }
806
807 if (cam)
808 {
809 c.cd(4);
810 gPad->SetBorderMode(0);
811 gPad->SetFrameBorderMode(0);
812 gPad->SetGridx();
813 gPad->SetGridy();
814 gROOT->SetSelectedPad(0);
815 MHCamera *c = new MHCamera(*cam);
816 c->SetStats(kFALSE);
817 c->SetBit(MHCamera::kNoLegend);
818 c->SetBit(kCanDelete);
819 c->Draw();
820 }
821 }
822
823 TCanvas &d = fDisplay->AddTab("Info2");
824 d.Divide(2,2);
825
826 d.cd(1);
827 gPad->SetBorderMode(0);
828 gPad->SetFrameBorderMode(0);
829 gPad->SetGridx();
830 gPad->SetGridy();
831 gROOT->SetSelectedPad(0);
832 splinepde.DrawClone()->SetBit(kCanDelete);
833
834 d.cd(2);
835 gPad->SetBorderMode(0);
836 gPad->SetFrameBorderMode(0);
837 gPad->SetGridx();
838 gPad->SetGridy();
839 gROOT->SetSelectedPad(0);
840 splinemirror.DrawClone()->SetBit(kCanDelete);
841
842 d.cd(3);
843 gPad->SetBorderMode(0);
844 gPad->SetFrameBorderMode(0);
845 gPad->SetGridx();
846 gPad->SetGridy();
847 gROOT->SetSelectedPad(0);
848 splinecones.DrawClone()->SetBit(kCanDelete);
849
850 d.cd(4);
851 gPad->SetBorderMode(0);
852 gPad->SetFrameBorderMode(0);
853 gPad->SetGridx();
854 gPad->SetGridy();
855 gROOT->SetSelectedPad(0);
856 MParSpline *all = (MParSpline*)splinepde.DrawClone();
857 //all->SetTitle("Combined acceptance");
858 all->SetBit(kCanDelete);
859 all->Multiply(*splinemirror.GetSpline());
860 }
861
862 //-------------------------------------------
863
864 // Execute first analysis
865 if (!evtloop.Eventloop(fMaxEvents))
866 {
867 gLog << err << GetDescriptor() << ": Failed." << endl;
868 return kFALSE;
869 }
870
871 //-------------------------------------------
872 // FIXME: Display Spline in tab
873 // FIXME: Display Reflector in tab
874 // FIXME: Display Routing(?) in tab
875 // FIXME: Display Camera(s) in tab
876 //-------------------------------------------
877
878 if (!WriteResult(plist, seq))
879 return kFALSE;
880
881 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
882
883 return kTRUE;
884}
Note: See TracBrowser for help on using the repository browser.