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

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