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

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