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

Last change on this file since 16621 was 15277, checked in by lyard, 12 years ago
added fits files header key support
File size: 35.0 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 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 if (fWriteFitsFile)
553 rule3.ReplaceAll("$1.root/", "$1.fits/");
554
555 MWriteFitsFile write3af( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
556 MWriteRootFile write3ar( 2, rule3, fOverwrite?"RECREATE":"NEW", "Camera file");
557
558 MTask &write3a = fWriteFitsFile ? static_cast<MTask&>(write3af) : static_cast<MTask&>(write3ar);
559
560 write3af.SetHeaderKey("DUMMY0", 3, "First dummy");
561 write3af.SetHeaderKey("DUMMY1", 3.14159265358979323846, "Second dummy");
562 write3af.SetHeaderKey("DUMMY2", true, "Third dummy");
563 write3af.SetHeaderKey("DUMMY3", "one value", "Fourth dummy");
564
565 write3af.VetoColumn("MParameterD.fVal");
566 write3af.VetoColumn("MCorsikaEvtHeader.fEvtNumber");
567 write3af.VetoColumn("MCorsikaEvtHeader.fNumReuse");
568 write3af.VetoColumn("MCorsikaEvtHeader.fTotalEnergy");
569 write3af.VetoColumn("MCorsikaEvtHeader.fStartAltitude");
570 write3af.VetoColumn("MCorsikaEvtHeader.fFirstTargetNum");
571 write3af.VetoColumn("MCorsikaEvtHeader.fFirstInteractionHeight");
572 write3af.VetoColumn("MCorsikaEvtHeader.fMomentumX");
573 write3af.VetoColumn("MCorsikaEvtHeader.fMomentumY");
574 write3af.VetoColumn("MCorsikaEvtHeader.fMomentumZ");
575 write3af.VetoColumn("MCorsikaEvtHeader.fAz");
576 write3af.VetoColumn("MCorsikaEvtHeader.fWeightedNumPhotons");
577 write3af.VetoColumn("MCorsikaEvtHeader.fZd");
578 write3af.VetoColumn("MCorsikaEvtHeader.fAd");
579 write3af.VetoColumn("MCorsikaEvtHeader.fX");
580 write3af.VetoColumn("MCorsikaEvtHeader.fY");
581 write3af.VetoColumn("MCorsikaEvtHeader.fWeightNumPhotons");
582 write3af.VetoColumn("MMcEvt.fEvtNumber");
583 write3af.VetoColumn("MMcEvt.fThick0");
584 write3af.VetoColumn("MMcEvt.fFirstTarget");
585 write3af.VetoColumn("MMcEvt.fZFirstInteraction");
586 write3af.VetoColumn("MMcEvt.fCoreD");
587 write3af.VetoColumn("MMcEvt.fCoreX");
588 write3af.VetoColumn("MMcEvt.fCoreY");
589 write3af.VetoColumn("MMcEvt.fTimeFirst");
590 write3af.VetoColumn("MMcEvt.fTimeLast");
591 write3af.VetoColumn("MMcEvt.fLongiNmax");
592 write3af.VetoColumn("MMcEvt.fLongit0");
593 write3af.VetoColumn("MMcEvt.fLongitmax");
594 write3af.VetoColumn("MMcEvt.fLongia");
595 write3af.VetoColumn("MMcEvt.fLongib");
596 write3af.VetoColumn("MMcEvt.fLongic");
597 write3af.VetoColumn("MMcEvt.fLongichi2");
598 write3af.VetoColumn("MMcEvt.fPhotIni");
599 write3af.VetoColumn("MMcEvt.fPassPhotAtm");
600 write3af.VetoColumn("MMcEvt.fPassPhotRef");
601 write3af.VetoColumn("MMcEvt.fPassPhotCone");
602 write3af.VetoColumn("MMcEvt.fPhotElfromShower");
603 write3af.VetoColumn("MMcEvt.fPhotElinCamera");
604 write3af.VetoColumn("MMcEvt.fElecCphFraction");
605 write3af.VetoColumn("MMcEvt.fMuonCphFraction");
606 write3af.VetoColumn("MMcEvt.fOtherCphFraction");
607 write3af.VetoColumn("MMcEvt.fFadcTimeJitter");
608 write3af.VetoColumn("MMcEvt.fEventReuse");
609
610 write3af.VetoColumn("MRawEvtData.fHiGainPixId");
611 write3af.VetoColumn("MRawEvtData.fLoGainPixId");
612 write3af.VetoColumn("MRawEvtData.fLoGainFadcSamples");
613 write3af.VetoColumn("MRawEvtData.fABFlags");
614 write3af.VetoColumn("MRawEvtData.fStartCells");
615 write3af.VetoColumn("MRawEvtData.fNumBytesPerSample");
616 write3af.VetoColumn("MRawEvtData.fIsSigned");
617 write3af.VetoColumn("MRawEvtHeader.fDAQEvtNumber"); //EventNum ?
618 write3af.VetoColumn("MRawEvtHeader.fNumTrigLvl1");
619 write3af.VetoColumn("MRawEvtHeader.fNumTrigLvl2");
620 write3af.VetoColumn("MRawEvtHeader.fTrigPattern");
621 write3af.VetoColumn("MRawEvtHeader.fNumLoGainOn");
622
623 write3af.SetBytesPerSample("Data", 2);
624
625 write1a.SetName("WriteRefData");
626 write1b.SetName("WriteRefMC");
627 write2a.SetName("WriteSigData");
628 write2b.SetName("WriteSigMC");
629 write3a.SetName("WriteCamData");
630 write3b.SetName("WriteCamMC");
631 write4a.SetName("WriteImgData");
632 write4b.SetName("WriteImgMC");
633
634 SetupCommonFileStructure(write1a);
635 SetupCommonFileStructure(write2a);
636 SetupCommonFileStructure(write3ar);
637 SetupCommonFileStructure(write3af);
638 SetupCommonFileStructure(write4a);
639
640 // R: Dedicated file structure
641 write1a.AddContainer("MPhotonEvent", "Events");
642
643 // Y: Dedicated file structure
644 write2a.AddContainer("MPedPhotFromExtractorRndm", "RunHeaders"); // FIXME: Needed for the signal files to be display in MARS
645 write2a.AddContainer("MSignalCam", "Events");
646
647 // D: Dedicated file structure
648 write3af.AddContainer("ElectronicNoise", "RunHeaders");
649 write3af.AddContainer("IntendedPulsePos", "RunHeaders");
650 write3af.AddContainer("MRawEvtData", "Events");
651
652 write3ar.AddContainer("ElectronicNoise", "RunHeaders");
653 write3ar.AddContainer("IntendedPulsePos", "RunHeaders");
654 write3ar.AddContainer("MRawEvtData", "Events");
655 // It doesn't make much sene to write this information
656 // to the file because the units are internal units not
657 // related to the output samples
658 // if (header.IsDataRun() || fForceTrigger)
659 // write3a.AddContainer("TriggerPos", "Events");
660
661 // I: Dedicated file structure
662 write4a.AddContainer("MHillas", "Events");
663 write4a.AddContainer("MHillasSrc", "Events");
664 write4a.AddContainer("MImagePar", "Events");
665 write4a.AddContainer("MNewImagePar", "Events");
666
667 // Basic MC data
668 write1b.AddContainer("MMcEvtBasic", "OriginalMC");
669 write2b.AddContainer("MMcEvtBasic", "OriginalMC");
670 write3b.AddContainer("MMcEvtBasic", "OriginalMC");
671 write4b.AddContainer("MMcEvtBasic", "OriginalMC");
672
673 // -------------------------------------------------------------------
674
675 MGeomApply apply;
676
677 MSimPSF simpsf;
678
679 MSimGeomCam simgeom;
680 simgeom.SetNameGeomCam("GeomCones");
681
682 MSimCalibrationSignal simcal;
683 simcal.SetNameGeomCam("GeomCones");
684
685 // Sky Quality Meter: 21.82M = 2.02e-4cd/m^2
686 // 1cd = 12.566 lm / 4pi sr
687
688 // FIXME: Simulate photons before cones and QE!
689
690 MSimRandomPhotons simnsb;
691 simnsb.SetFreq(5.8, 0.004); // ph/m^2/nm/sr/ns NSB, 4MHz dark count rate
692 simnsb.SetNameGeomCam("GeomCones");
693
694 // FIXME: How do we handle star-light? We need the rate but we also
695 // need to process it through the mirror!
696
697 MSimAPD simapd;
698 simapd.SetNameGeomCam("GeomCones");
699
700 MSimExcessNoise simexcnoise;
701 MSimBundlePhotons simsum;
702 MSimSignalCam simsignal;
703 MSimCamera simcam;
704 MSimTrigger simtrig;
705 MSimReadout simdaq;
706
707 MContinue conttrig("TriggerPos.fVal<0", "ContTrigger");
708
709 MParameterD pulpos("IntendedPulsePos");
710 // FIXME: Set a default which could be 1/3 of the digitization window
711 // pulpos.SetVal(40); // [ns]
712 plist.AddToList(&pulpos);
713
714 MParameterD trigger("TriggerPos");
715 trigger.SetVal(0);
716 plist.AddToList(&trigger);
717
718 // -------------------------------------------------------------------
719
720 // Remove isolated pixels
721 MImgCleanStd clean(0, 0);
722 //clean.SetCleanLvl0(0); // The level above which isolated pixels are kept
723 clean.SetCleanRings(0);
724 clean.SetMethod(MImgCleanStd::kAbsolute);
725
726 //clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
727
728 MHillasCalc hcalc;
729 hcalc.Disable(MHillasCalc::kCalcConc);
730
731 MHCamEvent evt0a(/*10*/3, "Signal", "Average signal (absolute);;S [ph]");
732 MHCamEvent evt0c(/*10*/3, "MaxSignal", "Maximum signal (absolute);;S [ph]");
733 MHCamEvent evt0d(/*11*/8, "ArrTm", "Time after first photon;;T [ns]");
734 evt0a.SetErrorSpread(kFALSE);
735 evt0c.SetCollectMax();
736
737 MContinue cut("", "Cut");
738
739 MFillH fillx0a(&evt0a, "MSignalCam", "FillAvgSignal");
740 MFillH fillx0c(&evt0c, "MSignalCam", "FillMaxSignal");
741 MFillH fillx0d(&evt0d, "MSignalCam", "FillArrTm");
742 MFillH fillx1("MHHillas", "MHillas", "FillHillas");
743 MFillH fillx3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
744 MFillH fillx4("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
745 MFillH fillth("MHThreshold", "", "FillThreshold");
746 MFillH fillca("MHCollectionArea", "", "FillTrigArea");
747
748 fillth.SetNameTab("Threshold");
749 fillca.SetNameTab("TrigArea");
750
751 // -------------------------------------------------------------------
752
753 if (header.IsDataRun())
754 {
755 tasks.AddToList(&read);
756 tasks.AddToList(&precut);
757 tasks.AddToList(&pointing);
758 tasks.AddToList(&simmmcs);
759 if (!fPathOut.IsNull() && !HasNullOut())
760 {
761 //tasks.AddToList(&write1b);
762 tasks.AddToList(&write2b);
763 if (fCamera)
764 tasks.AddToList(&write3b);
765 if (header.IsDataRun())
766 tasks.AddToList(&write4b);
767 }
768 // if (header.IsPointRun())
769 // tasks.AddToList(&stars);
770 if (1)
771 tasks.AddToList(&simatm); // Here because before fillh1
772 tasks.AddToList(&calcangle);
773 tasks.AddToList(&fillh1);
774 tasks.AddToList(&fillG);
775 if (!header.IsPointRun())
776 {
777 tasks.AddToList(&absapd);
778 tasks.AddToList(&absmir);
779 if (0)
780 tasks.AddToList(&simatm); // FASTER?
781 }
782 tasks.AddToList(&reflect);
783 if (!header.IsPointRun())
784 {
785 tasks.AddToList(&fill0);
786 //tasks.AddToList(&fill1);
787 tasks.AddToList(&fill2);
788 tasks.AddToList(&fill3);
789 tasks.AddToList(&fill4);
790 tasks.AddToList(&fillF1);
791 }
792 tasks.AddToList(&cones);
793 tasks.AddToList(&cones2);
794 //if (header.IsPointRun())
795 // tasks.AddToList(&fillP);
796 tasks.AddToList(&cont1);
797 }
798 // -------------------------------
799 tasks.AddToList(&apply);
800 if (header.IsDataRun())
801 {
802 tasks.AddToList(&simpsf);
803 tasks.AddToList(&simgeom);
804 tasks.AddToList(&cont2);
805 if (!header.IsPointRun())
806 {
807 tasks.AddToList(&fillF2);
808 tasks.AddToList(&fillh2);
809 }
810 tasks.AddToList(&cont3);
811 }
812 if (fCamera)
813 {
814 if (header.IsPedestalRun() || header.IsCalibrationRun())
815 tasks.AddToList(&simcal);
816 tasks.AddToList(&simnsb);
817 tasks.AddToList(&simapd);
818 tasks.AddToList(&simexcnoise);
819 }
820 tasks.AddToList(&simsum);
821 if (fCamera)
822 {
823 tasks.AddToList(&simcam);
824 if (header.IsDataRun() || fForceTrigger)
825 tasks.AddToList(&simtrig);
826 tasks.AddToList(&conttrig);
827 tasks.AddToList(&simdaq);
828 }
829 tasks.AddToList(&simsignal); // What do we do if signal<0?
830 if (!fPathOut.IsNull() && !HasNullOut())
831 {
832 //tasks.AddToList(&write1a);
833 if (!header.IsPedestalRun())
834 tasks.AddToList(&write2a);
835 if (fCamera)
836 tasks.AddToList(&write3a);
837 }
838 // -------------------------------
839 if (fCamera)
840 {
841 // FIXME: MHCollectionArea Trigger Area!
842 if (header.IsDataRun())
843 tasks.AddToList(&fillh3);
844 tasks.AddToList(&filltp);
845 }
846 if (header.IsDataRun())
847 {
848 tasks.AddToList(&fillew);
849 tasks.AddToList(&filled);
850 }
851 if (!header.IsPedestalRun())
852 {
853 tasks.AddToList(&fillx0a);
854 tasks.AddToList(&fillx0c);
855 }
856 if (header.IsDataRun())
857 {
858 tasks.AddToList(&clean);
859 tasks.AddToList(&hcalc);
860 tasks.AddToList(&cut);
861 tasks.AddToList(&fillx0d);
862 tasks.AddToList(&fillx1);
863 //tasks.AddToList(&fillx2);
864 tasks.AddToList(&fillx3);
865 tasks.AddToList(&fillx4);
866 if (!HasNullOut())
867 tasks.AddToList(&write4a);
868 //tasks.AddToList(&fillx5);
869
870 tasks.AddToList(&fillh4);
871 tasks.AddToList(&fillth);
872 tasks.AddToList(&fillca);
873 }
874 //-------------------------------------------
875
876 tasks.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
877
878 // Create and setup the eventloop
879 MEvtLoop evtloop(fName);
880 evtloop.SetParList(&plist);
881 evtloop.SetDisplay(fDisplay);
882 evtloop.SetLogStream(&gLog);
883 if (!SetupEnv(evtloop))
884 return kFALSE;
885
886 // FIXME: If pedestal file given use the values from this file
887 //-------------------------------------------
888
889 MGeomCam *cam = static_cast<MGeomCam*>(env2.GetCont());
890
891 if (binstr.IsDefault())
892 binstr.SetEdgesLin(150, -shape.GetWidth(),
893 header.GetFreqSampling()/1000.*header.GetNumSamples()+shape.GetWidth());
894
895 if (binsd.IsDefault() && cam)
896 binsd.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
897
898 if (binsd0.IsDefault() && cam)
899 binsd0.SetEdgesLin(100, 0, cam->GetMaxRadius()*cam->GetConvMm2Deg());
900
901
902 header.Print();
903
904 // FIXME: Display acceptance curves!
905
906 if (fDisplay)
907 {
908 TCanvas &c = fDisplay->AddTab("Info");
909 c.Divide(2,2);
910
911 c.cd(1);
912 gPad->SetBorderMode(0);
913 gPad->SetFrameBorderMode(0);
914 gPad->SetGridx();
915 gPad->SetGridy();
916 gROOT->SetSelectedPad(0);
917 shape.DrawClone()->SetBit(kCanDelete);
918
919 if (env0.GetCont() && (header.IsDataRun() || header.IsPointRun()))
920 {
921 c.cd(3);
922 gPad->SetBorderMode(0);
923 gPad->SetFrameBorderMode(0);
924 gPad->SetGridx();
925 gPad->SetGridy();
926 gROOT->SetSelectedPad(0);
927 static_cast<MReflector*>(env0.GetCont())->DrawClone("line")->SetBit(kCanDelete);
928 }
929
930 if (fCamera)
931 {
932 if (env1.GetCont())
933 {
934 c.cd(2);
935 gPad->SetBorderMode(0);
936 gPad->SetFrameBorderMode(0);
937 gPad->SetGridx();
938 gPad->SetGridy();
939 gROOT->SetSelectedPad(0);
940 MHCamera *c = new MHCamera(static_cast<MGeomCam&>(*env1.GetCont()));
941 c->SetStats(kFALSE);
942 c->SetBit(MHCamera::kNoLegend);
943 c->SetBit(kCanDelete);
944 c->Draw();
945 }
946
947 if (cam)
948 {
949 c.cd(4);
950 gPad->SetBorderMode(0);
951 gPad->SetFrameBorderMode(0);
952 gPad->SetGridx();
953 gPad->SetGridy();
954 gROOT->SetSelectedPad(0);
955 MHCamera *c = new MHCamera(*cam);
956 c->SetStats(kFALSE);
957 c->SetBit(MHCamera::kNoLegend);
958 c->SetBit(kCanDelete);
959 c->Draw();
960 }
961 }
962
963 TCanvas &d = fDisplay->AddTab("Info2");
964 d.Divide(2,3);
965
966 d.cd(1);
967 gPad->SetBorderMode(0);
968 gPad->SetFrameBorderMode(0);
969 gPad->SetGridx();
970 gPad->SetGridy();
971 gROOT->SetSelectedPad(0);
972 splinepde.DrawClone()->SetBit(kCanDelete);
973
974 d.cd(3);
975 gPad->SetBorderMode(0);
976 gPad->SetFrameBorderMode(0);
977 gPad->SetGridx();
978 gPad->SetGridy();
979 gROOT->SetSelectedPad(0);
980 splinecones2.DrawClone()->SetBit(kCanDelete);
981
982 d.cd(5);
983 gPad->SetBorderMode(0);
984 gPad->SetFrameBorderMode(0);
985 gPad->SetGridx();
986 gPad->SetGridy();
987 gROOT->SetSelectedPad(0);
988 splinemirror.DrawClone()->SetBit(kCanDelete);
989
990 d.cd(2);
991 gPad->SetBorderMode(0);
992 gPad->SetFrameBorderMode(0);
993 gPad->SetGridx();
994 gPad->SetGridy();
995 gROOT->SetSelectedPad(0);
996 splinecones.DrawClone()->SetBit(kCanDelete);
997 //splinecones2.DrawClone("same")->SetBit(kCanDelete);
998
999 d.cd(6);
1000 gPad->SetBorderMode(0);
1001 gPad->SetFrameBorderMode(0);
1002 gPad->SetGridx();
1003 gPad->SetGridy();
1004 gROOT->SetSelectedPad(0);
1005 MParSpline *all = (MParSpline*)splinepde.DrawClone();
1006 //all->SetTitle("Combined acceptance");
1007 all->SetBit(kCanDelete);
1008 if (splinemirror.GetSpline())
1009 all->Multiply(*splinemirror.GetSpline());
1010 if (splinecones2.GetSpline())
1011 all->Multiply(*splinecones2.GetSpline());
1012 }
1013
1014 //-------------------------------------------
1015
1016 // Execute first analysis
1017 if (!evtloop.Eventloop(fMaxEvents))
1018 {
1019 gLog << err << GetDescriptor() << ": Failed." << endl;
1020 return kFALSE;
1021 }
1022
1023 //-------------------------------------------
1024 // FIXME: Display Spline in tab
1025 // FIXME: Display Reflector in tab
1026 // FIXME: Display Routing(?) in tab
1027 // FIXME: Display Camera(s) in tab
1028 //-------------------------------------------
1029
1030 if (!WriteResult(plist, seq, header.GetRunNumber()))
1031 return kFALSE;
1032
1033 *fLog << all << GetDescriptor() << ": Done." << endl << endl << endl;;
1034
1035 return kTRUE;
1036}
Note: See TracBrowser for help on using the repository browser.