source: trunk/Mars/mjobs/MJSimulation.cc@ 14910

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