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

Last change on this file since 9450 was 9441, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 28.1 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 MSimMMCS simmmcs;
363
364 MParSpline splinepde("PhotonDetectionEfficiency");
365 MParSpline splinemirror("MirrorReflectivity");
366 MParSpline splinecones("ConesAngularAcceptance");
367 plist.AddToList(&splinepde);
368 plist.AddToList(&splinemirror);
369 plist.AddToList(&splinecones);
370
371 MSimAtmosphere simatm;
372 MSimAbsorption absapd("SimPhotonDetectionEfficiency");
373 MSimAbsorption absmir("SimMirrorReflectivity");
374 MSimAbsorption cones("SimConesAngularAcceptance");
375 absapd.SetParName("PhotonDetectionEfficiency");
376 absmir.SetParName("MirrorReflectivity");
377 cones.SetParName("ConesAngularAcceptance");
378 cones.SetUseTheta();
379
380 MSimPointingPos pointing;
381
382 MSimReflector reflect;
383 reflect.SetNameGeomCam("GeomCones");
384// MSimStarField stars;
385
386 MContinue cont1("MPhotonEvent.GetNumPhotons<1", "ContEmpty1");
387 MContinue cont2("MPhotonEvent.GetNumPhotons<1", "ContEmpty2");
388 MContinue cont3("MPhotonEvent.GetNumPhotons<2", "ContEmpty3");
389
390 // -------------------------------------------------------------------
391
392 MBinning binse( 120, 1, 1000000, "BinningEnergy", "log");
393 MBinning binsth( 60, 0.9, 900000, "BinningThreshold", "log");
394 MBinning binsee( 36, 0.9, 900000, "BinningEnergyEst", "log");
395 MBinning binss( 100, 1, 10000000, "BinningSize", "log");
396// MBinning binsi( 100, -500, 500, "BinningImpact");
397 MBinning binsi( 32, 0, 800, "BinningImpact");
398 MBinning binsh( 150, 0, 50, "BinningHeight");
399 MBinning binsaz(720, -360, 360, "BinningAz");
400 MBinning binszd( 70, 0, 70, "BinningZd");
401 MBinning binsvc( 35, 0, 7, "BinningViewCone");
402 MBinning binsel(150, 0, 50, "BinningTotLength");
403 MBinning binsew(150, 0, 15, "BinningMedLength");
404 MBinning binsd("BinningDistC");
405 MBinning binsd0("BinningDist");
406 MBinning binstr("BinningTrigPos");
407
408 plist.AddToList(&binsee);
409 plist.AddToList(&binse);
410 plist.AddToList(&binsth);
411 plist.AddToList(&binss);
412 plist.AddToList(&binsi);
413 plist.AddToList(&binsh);
414 plist.AddToList(&binszd);
415 plist.AddToList(&binsaz);
416 plist.AddToList(&binsvc);
417 plist.AddToList(&binsel);
418 plist.AddToList(&binsew);
419 plist.AddToList(&binstr);
420 plist.AddToList(&binsd);
421 plist.AddToList(&binsd0);
422
423 MHn mhn1, mhn2, mhn3, mhn4;
424 SetupHist(mhn1);
425 SetupHist(mhn2);
426 SetupHist(mhn3);
427 SetupHist(mhn4);
428
429 MH3 mhtp("TriggerPos.fVal-IntendedPulsePos.fVal-PulseShape.GetWidth");
430 mhtp.SetName("TrigPos");
431 mhtp.SetTitle("Trigger position w.r.t. the first photon hitting a detector");
432
433 MH3 mhew("MPhotonStatistics.fLength");
434 mhew.SetName("TotLength");
435 mhew.SetTitle("Time between first and last photon hitting a detector;L [ns]");
436
437 MH3 mhed("MPhotonStatistics.fTimeMedDev");
438 mhed.SetName("MedLength");
439 mhed.SetTitle("Median deviation (1\\sigma);L [ns]");
440
441 MFillH fillh1(&mhn1, "", "FillCorsika");
442 MFillH fillh2(&mhn2, "", "FillH2");
443 MFillH fillh3(&mhn3, "", "FillH3");
444 MFillH fillh4(&mhn4, "", "FillH4");
445 MFillH filltp(&mhtp, "", "FillTriggerPos");
446 MFillH fillew(&mhew, "", "FillEvtWidth");
447 MFillH filled(&mhed, "", "FillMedDev");
448 fillh1.SetNameTab("Corsika", "Distribution as simulated by Corsika");
449 fillh2.SetNameTab("Detectable", "Distribution of events hit the detector");
450 fillh3.SetNameTab("Triggered", "Distribution of triggered events");
451 fillh4.SetNameTab("Cleaned", "Distribution after cleaning and cuts");
452 filltp.SetNameTab("TrigPos", "TriggerPosition w.r.t the first photon");
453 fillew.SetNameTab("EvtWidth", "Time between first and last photon hitting a detector");
454 filled.SetNameTab("MedDev", "Time between first and last photon hitting a detector");
455
456 MHPhotonEvent planeG(1, "HPhotonEventGround"); // Get from MaxImpact
457 MHPhotonEvent plane0(2, "HMirrorPlane0"); // Get from MReflector
458 //MHPhotonEvent plane1(2, "HMirrorPlane1");
459 MHPhotonEvent plane2(2, "HMirrorPlane2");
460 MHPhotonEvent plane3(2, "HMirrorPlane3");
461 MHPhotonEvent plane4(2, "HMirrorPlane4");
462 MHPhotonEvent planeF1(3, "HPhotonEventCamera"); // Get from MGeomCam
463 MHPhotonEvent planeF2(header.IsPointRun()?4:3, "HPhotonEventCones"); // Get from MGeomCam
464
465 plist.AddToList(&planeG);
466 plist.AddToList(&plane0);
467 plist.AddToList(&plane2);
468 plist.AddToList(&plane3);
469 plist.AddToList(&plane4);
470 plist.AddToList(&planeF1);
471 plist.AddToList(&planeF2);;
472
473 //MHPSF psf;
474
475 MFillH fillG(&planeG, "MPhotonEvent", "FillGround");
476 MFillH fill0(&plane0, "MirrorPlane0", "FillReflector");
477 //MFillH fill1(&plane1, "MirrorPlane1", "FillCamShadow");
478 MFillH fill2(&plane2, "MirrorPlane2", "FillCandidates");
479 MFillH fill3(&plane3, "MirrorPlane3", "FillReflected");
480 MFillH fill4(&plane4, "MirrorPlane4", "FillFocal");
481 MFillH fillF1(&planeF1, "MPhotonEvent", "FillCamera");
482 MFillH fillF2(&planeF2, "MPhotonEvent", "FillCones");
483 //MFillH fillP(&psf, "MPhotonEvent", "FillPSF");
484
485 fillG.SetNameTab("Ground", "Photon distribution at ground");
486 fill0.SetNameTab("Reflector", "Photon distribution at reflector plane w/o camera shadow");
487 //fill1.SetNameTab("CamShadow", "Photon distribution at reflector plane w/ camera shadow");
488 fill2.SetNameTab("Candidates", "'Can hit' photon distribution at reflector plane w/ camera shadow");
489 fill3.SetNameTab("Reflected", "Photon distribution after reflector projected to reflector plane");
490 fill4.SetNameTab("Focal", "Photon distribution at focal plane");
491 fillF1.SetNameTab("Camera", "Photon distribution which hit the detector");
492 fillF2.SetNameTab("Cones", "Photon distribution after cones");
493 //fillP.SetNameTab("PSF", "Photon distribution after cones for all mirrors");
494
495 // -------------------------------------------------------------------
496
497 // FIXME: Pedestal and Calibration runs should get P and C
498 const TString rule1(Form("s/cer([0-9]+)/%s\\/00$1_R_MonteCarlo.root/", Esc(fPathOut).Data()));
499 const TString rule2(Form("s/cer([0-9]+)/%s\\/00$1_Y_MonteCarlo.root/", Esc(fPathOut).Data()));
500 const TString rule3(Form("s/cer([0-9]+)/%s\\/00$1_D_MonteCarlo.root/", Esc(fPathOut).Data()));
501
502 MWriteRootFile write3a( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
503 MWriteRootFile write3b( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
504 MWriteRootFile write2a( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
505 MWriteRootFile write2b( 2, rule2, fOverwrite?"RECREATE":"NEW", "Signal file");
506 MWriteRootFile write1a( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
507 MWriteRootFile write1b( 2, rule1, fOverwrite?"RECREATE":"NEW", "Reflector file");
508
509 write1a.SetName("WriteRefData");
510 write1b.SetName("WriteRefMC");
511 write2a.SetName("WriteSigData");
512 write2b.SetName("WriteSigMC");
513 write3a.SetName("WriteCamData");
514 write3b.SetName("WriteCamMC");
515
516 SetupCommonFileStructure(write1a);
517 SetupCommonFileStructure(write2a);
518 SetupCommonFileStructure(write3a);
519
520 // R: Dedicated file structureedicated events
521 write1a.AddContainer("MPhotonEvent", "Events");
522
523 // I: Dedicated file structureedicated events
524 write2a.AddContainer("MPedPhotFromExtractorRndm", "RunHeaders"); // FIXME: Needed for the signal files to be display in MARS
525 write2a.AddContainer("MSignalCam", "Events");
526
527 // D: Dedicated file structureedicated events
528 write3a.AddContainer("ElectronicNoise", "RunHeaders");
529 write3a.AddContainer("MRawEvtData", "Events");
530
531 // Basic MC data
532 write1b.AddContainer("MMcEvtBasic", "OriginalMC");
533 write2b.AddContainer("MMcEvtBasic", "OriginalMC");
534 write3b.AddContainer("MMcEvtBasic", "OriginalMC");
535
536 // -------------------------------------------------------------------
537
538 MGeomApply apply;
539
540 MSimPSF simpsf;
541
542 MSimGeomCam simgeom;
543 simgeom.SetNameGeomCam("GeomCones");
544
545 MSimCalibrationSignal simcal;
546 simcal.SetNameGeomCam("GeomCones");
547
548 // FIXME: Simulate photons before cones and QE!
549
550 MSimRandomPhotons simnsb;
551 simnsb.SetFreq(5.8, 0.004); // ph/m^2/nm/sr/ns NSB, 4MHz dark count rate
552 simnsb.SetNameGeomCam("GeomCones");
553
554 // FIXME: How do we handle star-light? We need the rate but we also
555 // need to process it through the mirror!
556
557 MSimAPD simapd;
558 simapd.SetNameGeomCam("GeomCones");
559
560 MSimExcessNoise simexcnoise;
561 MSimBundlePhotons simsum;
562 MSimSignalCam simsignal;
563 MSimCamera simcam;
564 MSimTrigger simtrig;
565 MSimReadout simdaq;
566
567 MContinue conttrig("TriggerPos.fVal<0", "ContTrigger");
568
569 MParameterD pulpos("IntendedPulsePos");
570 // FIXME: Set a default which could be 1/3 of the digitization window
571 // pulpos.SetVal(40); // [ns]
572 plist.AddToList(&pulpos);
573
574 MParameterD trigger("TriggerPos");
575 trigger.SetVal(0);
576 plist.AddToList(&trigger);
577
578 // -------------------------------------------------------------------
579
580 // Remove isolated pixels
581 MImgCleanStd clean(0, 0);
582 clean.SetCleanLvl0(0); // The level above which isolated pixels are kept
583 clean.SetCleanRings(0);
584 clean.SetMethod(MImgCleanStd::kAbsolute);
585
586 //clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
587
588 MHillasCalc hcalc;
589 hcalc.Disable(MHillasCalc::kCalcConc);
590
591 MHCamEvent evt0a(/*10*/3, "Signal", "Average signal (absolute);;S [ph]");
592 MHCamEvent evt0c(/*10*/3, "MaxSignal", "Maximum signal (absolute);;S [ph]");
593 MHCamEvent evt0d(/*11*/8, "ArrTm", "Time after first photon;;T [ns]");
594 evt0a.SetErrorSpread(kFALSE);
595 evt0c.SetCollectMax();
596
597 MContinue cut("", "Cut");
598
599 MFillH fillx0a(&evt0a, "MSignalCam", "FillAvgSignal");
600 MFillH fillx0c(&evt0c, "MSignalCam", "FillMaxSignal");
601 MFillH fillx0d(&evt0d, "MSignalCam", "FillArrTm");
602 MFillH fillx1("MHHillas", "MHillas", "FillHillas");
603 MFillH fillx3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
604 MFillH fillx4("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
605 MFillH fillth("MHThreshold", "", "FillThreshold");
606 MFillH fillca("MHCollectionArea", "", "FillTrigArea");
607
608 fillth.SetNameTab("Threshold");
609 fillca.SetNameTab("TrigArea");
610
611 // -------------------------------------------------------------------
612
613 if (header.IsDataRun())
614 {
615 tasks.AddToList(&read);
616 tasks.AddToList(&pointing);
617 tasks.AddToList(&simmmcs);
618 if (!fPathOut.IsNull() && !HasNullOut())
619 {
620 tasks.AddToList(&write1b);
621 tasks.AddToList(&write2b);
622 if (fCamera)
623 tasks.AddToList(&write3b);
624 }
625 // if (header.IsPointRun())
626 // tasks.AddToList(&stars);
627 if (1)
628 tasks.AddToList(&simatm); // Here because before fillh1
629 tasks.AddToList(&fillh1);
630 tasks.AddToList(&fillG);
631 if (!header.IsPointRun())
632 {
633 tasks.AddToList(&absapd);
634 tasks.AddToList(&absmir);
635 if (0)
636 tasks.AddToList(&simatm); // FASTER?
637 }
638 tasks.AddToList(&reflect);
639 if (!header.IsPointRun())
640 {
641 tasks.AddToList(&fill0);
642 //tasks.AddToList(&fill1);
643 tasks.AddToList(&fill2);
644 tasks.AddToList(&fill3);
645 tasks.AddToList(&fill4);
646 tasks.AddToList(&fillF1);
647 }
648 tasks.AddToList(&cones);
649 //if (header.IsPointRun())
650 // tasks.AddToList(&fillP);
651 tasks.AddToList(&cont1);
652 }
653 // -------------------------------
654 tasks.AddToList(&apply);
655 if (header.IsDataRun())
656 {
657 tasks.AddToList(&simpsf);
658 tasks.AddToList(&simgeom);
659 tasks.AddToList(&cont2);
660 if (!header.IsPointRun())
661 {
662 tasks.AddToList(&fillF2);
663 tasks.AddToList(&fillh2);
664 }
665 tasks.AddToList(&cont3);
666 }
667 if (fCamera)
668 {
669 if (header.IsPedestalRun() || header.IsCalibrationRun())
670 tasks.AddToList(&simcal);
671 tasks.AddToList(&simnsb);
672 tasks.AddToList(&simapd);
673 tasks.AddToList(&simexcnoise);
674 }
675 tasks.AddToList(&simsum);
676 if (fCamera)
677 {
678 tasks.AddToList(&simcam);
679 if (header.IsDataRun() || fForceTrigger)
680 tasks.AddToList(&simtrig);
681 tasks.AddToList(&conttrig);
682 tasks.AddToList(&simdaq);
683 }
684 tasks.AddToList(&simsignal); // What do we do if signal<0?
685 if (!fPathOut.IsNull() && !HasNullOut())
686 {
687 tasks.AddToList(&write1a);
688 if (!header.IsPedestalRun())
689 tasks.AddToList(&write2a);
690 if (fCamera)
691 tasks.AddToList(&write3a);
692 }
693 // -------------------------------
694 if (fCamera)
695 {
696 // FIXME: MHCollectionArea Trigger Area!
697 if (header.IsDataRun())
698 tasks.AddToList(&fillh3);
699 tasks.AddToList(&filltp);
700 }
701 if (header.IsDataRun())
702 {
703 tasks.AddToList(&fillew);
704 tasks.AddToList(&filled);
705 }
706 if (!header.IsPedestalRun())
707 {
708 tasks.AddToList(&fillx0a);
709 tasks.AddToList(&fillx0c);
710 if (!header.IsCalibrationRun())
711 tasks.AddToList(&clean);
712 tasks.AddToList(&hcalc);
713 tasks.AddToList(&cut);
714 tasks.AddToList(&fillx0d);
715 tasks.AddToList(&fillx1);
716 //tasks.AddToList(&fillx2);
717 tasks.AddToList(&fillx3);
718 tasks.AddToList(&fillx4);
719 //tasks.AddToList(&fillx5);
720 }
721 if (header.IsDataRun())
722 {
723 tasks.AddToList(&fillh4);
724 tasks.AddToList(&fillth);
725 tasks.AddToList(&fillca);
726 }
727 //-------------------------------------------
728
729 tasks.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
730
731 // Create and setup the eventloop
732 MEvtLoop evtloop(fName);
733 evtloop.SetParList(&plist);
734 evtloop.SetDisplay(fDisplay);
735 evtloop.SetLogStream(&gLog);
736 if (!SetupEnv(evtloop))
737 return kFALSE;
738
739 // FIXME: If pedestal file given use the values from this file
740 //-------------------------------------------
741
742 MGeomCam *cam = static_cast<MGeomCam*>(env2.GetCont());
743
744 if (binstr.IsDefault())
745 binstr.SetEdgesLin(150, -shape.GetWidth(),
746 header.GetFreqSampling()/1000.*header.GetNumSamples()+shape.GetWidth());
747
748 if (binsd.IsDefault() && cam)
749 binsd.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
750
751 if (binsd0.IsDefault() && cam)
752 binsd0.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
753
754
755 header.Print();
756
757 // FIXME: Display acceptance curves!
758
759 if (fDisplay)
760 {
761 TCanvas &c = fDisplay->AddTab("Info");
762 c.Divide(2,2);
763
764 c.cd(1);
765 gPad->SetBorderMode(0);
766 gPad->SetFrameBorderMode(0);
767 gPad->SetGridx();
768 gPad->SetGridy();
769 gROOT->SetSelectedPad(0);
770 shape.DrawClone()->SetBit(kCanDelete);
771
772 if (env0.GetCont() && (header.IsDataRun() || header.IsPointRun()))
773 {
774 c.cd(3);
775 gPad->SetBorderMode(0);
776 gPad->SetFrameBorderMode(0);
777 gPad->SetGridx();
778 gPad->SetGridy();
779 gROOT->SetSelectedPad(0);
780 static_cast<MReflector*>(env0.GetCont())->DrawClone("line")->SetBit(kCanDelete);
781 }
782
783 if (fCamera)
784 {
785 if (env1.GetCont())
786 {
787 c.cd(2);
788 gPad->SetBorderMode(0);
789 gPad->SetFrameBorderMode(0);
790 gPad->SetGridx();
791 gPad->SetGridy();
792 gROOT->SetSelectedPad(0);
793 MHCamera *c = new MHCamera(static_cast<MGeomCam&>(*env1.GetCont()));
794 c->SetStats(kFALSE);
795 c->SetBit(MHCamera::kNoLegend);
796 c->SetBit(kCanDelete);
797 c->Draw();
798 }
799
800 if (cam)
801 {
802 c.cd(4);
803 gPad->SetBorderMode(0);
804 gPad->SetFrameBorderMode(0);
805 gPad->SetGridx();
806 gPad->SetGridy();
807 gROOT->SetSelectedPad(0);
808 MHCamera *c = new MHCamera(*cam);
809 c->SetStats(kFALSE);
810 c->SetBit(MHCamera::kNoLegend);
811 c->SetBit(kCanDelete);
812 c->Draw();
813 }
814 }
815
816 TCanvas &d = fDisplay->AddTab("Info2");
817 d.Divide(2,2);
818
819 d.cd(1);
820 gPad->SetBorderMode(0);
821 gPad->SetFrameBorderMode(0);
822 gPad->SetGridx();
823 gPad->SetGridy();
824 gROOT->SetSelectedPad(0);
825 splinepde.DrawClone()->SetBit(kCanDelete);
826
827 d.cd(2);
828 gPad->SetBorderMode(0);
829 gPad->SetFrameBorderMode(0);
830 gPad->SetGridx();
831 gPad->SetGridy();
832 gROOT->SetSelectedPad(0);
833 splinemirror.DrawClone()->SetBit(kCanDelete);
834
835 d.cd(3);
836 gPad->SetBorderMode(0);
837 gPad->SetFrameBorderMode(0);
838 gPad->SetGridx();
839 gPad->SetGridy();
840 gROOT->SetSelectedPad(0);
841 splinecones.DrawClone()->SetBit(kCanDelete);
842
843 d.cd(4);
844 gPad->SetBorderMode(0);
845 gPad->SetFrameBorderMode(0);
846 gPad->SetGridx();
847 gPad->SetGridy();
848 gROOT->SetSelectedPad(0);
849 MParSpline *all = (MParSpline*)splinepde.DrawClone();
850 //all->SetTitle("Combined acceptance");
851 all->SetBit(kCanDelete);
852 all->Multiply(*splinemirror.GetSpline());
853 }
854
855 //-------------------------------------------
856
857 // Execute first analysis
858 if (!evtloop.Eventloop(fMaxEvents))
859 {
860 gLog << err << GetDescriptor() << ": Failed." << endl;
861 return kFALSE;
862 }
863
864 //-------------------------------------------
865 // FIXME: Display Spline in tab
866 // FIXME: Display Reflector in tab
867 // FIXME: Display Routing(?) in tab
868 // FIXME: Display Camera(s) in tab
869 //-------------------------------------------
870
871 if (!WriteResult(plist, seq))
872 return kFALSE;
873
874 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
875
876 return kTRUE;
877}
Note: See TracBrowser for help on using the repository browser.