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

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