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

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