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

Last change on this file since 9362 was 9362, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 25.7 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_I_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 // FIXME: Simulate photons before QE!
499
500 MSimRandomPhotons simnsb;
501// simnsb.SetFreq(0.005, 0.004); // 5MHz/cm^2, 4MHz
502 simnsb.SetFreq(0, 0.04); // 40MHz fixed for each APD
503 simnsb.SetNameGeomCam("GeomCones");
504
505 // FIXME: How do we handle star-light? We need the rate but we also
506 // need to process it through the mirror!
507
508 MSimAPD simapd;
509 simapd.SetFreq(0.04); // Must be identical to MSimRanodmPhotons!!
510 simapd.SetNameGeomCam("GeomCones");
511
512 MSimExcessNoise simexcnoise;
513 MSimBundlePhotons simsum;
514 MSimSignalCam simsignal;
515 MSimCamera simcam;
516 MSimTrigger simtrig;
517 MSimReadout simdaq;
518
519 MContinue conttrig("TriggerPos.fVal<0", "ContTrigger");
520
521 MParameterD pulpos("IntendedPulsePos");
522// pulpos.SetVal(40); // [ns]
523 plist.AddToList(&pulpos);
524
525 MParameterD trigger("TriggerPos");
526 trigger.SetVal(0);
527 plist.AddToList(&trigger);
528
529 // -------------------------------------------------------------------
530
531 // Remove isolated pixels
532 MImgCleanStd clean(0, 0);
533 clean.SetCleanLvl0(0); // The level above which isolated pixels are kept
534 clean.SetCleanRings(0);
535 clean.SetMethod(MImgCleanStd::kAbsolute);
536
537 //clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
538
539 MHillasCalc hcalc;
540 hcalc.Disable(MHillasCalc::kCalcConc);
541
542 MHCamEvent evt0a(/*10*/3, "Signal", "Average signal (absolute);;S [ph]");
543 MHCamEvent evt0c(/*10*/3, "MaxSignal", "Maximum signal (absolute);;S [ph]");
544 MHCamEvent evt0d(/*11*/8, "ArrTm", "Time after first photon;;T [ns]");
545 evt0a.SetErrorSpread(kFALSE);
546 evt0c.SetCollectMax();
547
548 MFillH fillx0a(&evt0a, "MSignalCam", "FillAvgSignal");
549 MFillH fillx0c(&evt0c, "MSignalCam", "FillMaxSignal");
550 MFillH fillx0d(&evt0d, "MSignalCam", "FillArrTm");
551 MFillH fillx1("MHHillas", "MHillas", "FillHillas");
552 //MFillH fillx2("MHHillasExt", "", "FillHillasExt");
553 MFillH fillx3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
554 MFillH fillth("MHThreshold", "", "FillThreshold");
555 MFillH fillca("MHCollectionArea", "", "FillTrigArea");
556 //MFillH fillx4("MHImagePar", "MImagePar", "FillImagePar");
557 //MFillH fillx5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
558
559 fillth.SetNameTab("Threshold");
560 fillca.SetNameTab("TrigArea");
561
562 // -------------------------------------------------------------------
563
564 if (header.IsDataRun())
565 {
566 tasks.AddToList(&read);
567 tasks.AddToList(&pointing);
568 tasks.AddToList(&simmmcs);
569 if (!fPathOut.IsNull() && !HasNullOut())
570 {
571 tasks.AddToList(&write1b);
572 tasks.AddToList(&write2b);
573 if (fCamera)
574 tasks.AddToList(&write3b);
575 }
576 // if (header.IsPointRun())
577 // tasks.AddToList(&stars);
578 if (1)
579 tasks.AddToList(&simatm); // Here because before fillh1
580 tasks.AddToList(&fillh1);
581 tasks.AddToList(&fillG);
582 if (!header.IsPointRun())
583 {
584 tasks.AddToList(&absapd);
585 tasks.AddToList(&absmir);
586 if (0)
587 tasks.AddToList(&simatm); // FASTER?
588 }
589 tasks.AddToList(&reflect);
590 if (!header.IsPointRun())
591 {
592 tasks.AddToList(&fill0);
593 //tasks.AddToList(&fill1);
594 tasks.AddToList(&fill2);
595 tasks.AddToList(&fill3);
596 tasks.AddToList(&fill4);
597 tasks.AddToList(&fillF1);
598 }
599 tasks.AddToList(&cones);
600 tasks.AddToList(&fillF2);
601 //if (header.IsPointRun())
602 // tasks.AddToList(&fillP);
603 tasks.AddToList(&cont1);
604 if (!header.IsPointRun())
605 tasks.AddToList(&fillh2);
606 }
607 // -------------------------------
608 tasks.AddToList(&apply);
609 if (header.IsDataRun())
610 {
611 tasks.AddToList(&simpsf);
612 tasks.AddToList(&simgeom);
613 tasks.AddToList(&cont2);
614 }
615 if (fCamera)
616 {
617 if (header.IsPedestalRun() || header.IsCalibrationRun())
618 tasks.AddToList(&simcal);
619 tasks.AddToList(&simnsb);
620 tasks.AddToList(&simapd);
621 tasks.AddToList(&simexcnoise);
622 }
623 tasks.AddToList(&simsum);
624 if (fCamera)
625 {
626 tasks.AddToList(&simcam);
627 if (header.IsDataRun() || fForceTrigger)
628 tasks.AddToList(&simtrig);
629 tasks.AddToList(&conttrig);
630 tasks.AddToList(&simdaq);
631 }
632 tasks.AddToList(&simsignal); // What do we do if signal<0?
633 if (!fPathOut.IsNull() && !HasNullOut())
634 {
635 tasks.AddToList(&write1a);
636 if (!header.IsPedestalRun())
637 tasks.AddToList(&write2a);
638 if (fCamera)
639 tasks.AddToList(&write3a);
640 }
641 // -------------------------------
642 if (fCamera)
643 {
644 // FIXME: MHCollectionArea Trigger Area!
645 if (header.IsDataRun())
646 tasks.AddToList(&fillh3);
647 tasks.AddToList(&filltp);
648 }
649 if (header.IsDataRun())
650 {
651 tasks.AddToList(&fillew);
652 tasks.AddToList(&filled);
653 }
654 if (!header.IsPedestalRun())
655 {
656 tasks.AddToList(&fillx0a);
657 tasks.AddToList(&fillx0c);
658 if (!header.IsCalibrationRun())
659 tasks.AddToList(&clean);
660 tasks.AddToList(&hcalc);
661 tasks.AddToList(&fillx0d);
662 tasks.AddToList(&fillx1);
663 //tasks.AddToList(&fillx2);
664 tasks.AddToList(&fillx3);
665 //tasks.AddToList(&fillx4);
666 //tasks.AddToList(&fillx5);
667 }
668 if (header.IsDataRun())
669 {
670 tasks.AddToList(&fillth);
671 tasks.AddToList(&fillca);
672 }
673 //-------------------------------------------
674
675 tasks.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
676
677 // Create and setup the eventloop
678 MEvtLoop evtloop(fName);
679 evtloop.SetParList(&plist);
680 evtloop.SetDisplay(fDisplay);
681 evtloop.SetLogStream(&gLog);
682 if (!SetupEnv(evtloop))
683 return kFALSE;
684
685 // FIXME: If pedestal file given use the values from this file
686 //-------------------------------------------
687
688 MGeomCam *cam = static_cast<MGeomCam*>(env2.GetCont());
689
690 if (binstr.IsDefault())
691 binstr.SetEdgesLin(150, -shape.GetPulseWidth(),
692 header.GetFreqSampling()/1000.*header.GetNumSamples()+shape.GetPulseWidth());
693
694 if (binsd.IsDefault() && cam)
695 binsd.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
696
697 if (binsd0.IsDefault() && cam)
698 binsd0.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
699
700
701 header.Print();
702
703 // FIXME: Display acceptance curves!
704
705 if (fDisplay)
706 {
707 TCanvas &c = fDisplay->AddTab("Info");
708 c.Divide(2,2);
709
710 c.cd(1);
711 gPad->SetBorderMode(0);
712 gPad->SetFrameBorderMode(0);
713 gPad->SetGridx();
714 gPad->SetGridy();
715 gROOT->SetSelectedPad(0);
716 shape.DrawClone()->SetBit(kCanDelete);
717
718 if (env0.GetCont() && (header.IsDataRun() || header.IsPointRun()))
719 {
720 c.cd(3);
721 gPad->SetBorderMode(0);
722 gPad->SetFrameBorderMode(0);
723 gPad->SetGridx();
724 gPad->SetGridy();
725 gROOT->SetSelectedPad(0);
726 static_cast<MReflector*>(env0.GetCont())->DrawClone("line")->SetBit(kCanDelete);
727
728 }
729
730 if (fCamera)
731 {
732 if (env1.GetCont())
733 {
734 c.cd(2);
735 gPad->SetBorderMode(0);
736 gPad->SetFrameBorderMode(0);
737 gPad->SetGridx();
738 gPad->SetGridy();
739 gROOT->SetSelectedPad(0);
740 MHCamera *c = new MHCamera(static_cast<MGeomCam&>(*env1.GetCont()));
741 c->SetStats(kFALSE);
742 c->SetBit(MHCamera::kNoLegend);
743 c->SetBit(kCanDelete);
744 c->Draw();
745
746 }
747
748 if (cam)
749 {
750 c.cd(4);
751 gPad->SetBorderMode(0);
752 gPad->SetFrameBorderMode(0);
753 gPad->SetGridx();
754 gPad->SetGridy();
755 gROOT->SetSelectedPad(0);
756 MHCamera *c = new MHCamera(*cam);
757 c->SetStats(kFALSE);
758 c->SetBit(MHCamera::kNoLegend);
759 c->SetBit(kCanDelete);
760 c->Draw();
761 }
762 }
763 }
764
765 //-------------------------------------------
766
767 // Execute first analysis
768 if (!evtloop.Eventloop(fMaxEvents))
769 {
770 gLog << err << GetDescriptor() << ": Failed." << endl;
771 return kFALSE;
772 }
773
774 //-------------------------------------------
775 // FIXME: Display Spline in tab
776 // FIXME: Display Reflector in tab
777 // FIXME: Display Routing(?) in tab
778 // FIXME: Display Camera(s) in tab
779 //-------------------------------------------
780
781 if (!WriteResult(plist))
782 return kFALSE;
783
784 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
785
786 return kTRUE;
787}
Note: See TracBrowser for help on using the repository browser.