source: trunk/Mars/hawc/star.C@ 19820

Last change on this file since 19820 was 19776, checked in by tbretz, 6 years ago
Improved some comments and removed some obsolete code lines.
File size: 8.5 KB
Line 
1#include "MLogManip.h"
2
3/*****************************************************************
4
5 STAR -- STandard Analysis and Reconstruction
6
7 datafile:
8 A calibarted root file which came out of callist, e.g.
9 20170727_006_Y.root or
10 00000015.003_Y_MonteCarlo003_Events.root
11
12 lvl1, lvl2:
13 Lower (1) and higher (2) cleaning level
14
15 outpath:
16 The path to which the output files are written
17
18
19 To run the macro from the command line (assuming you are in a directory
20 Mars/build where you have built your Mars environment) ou can do
21
22 root ../hawc/star.C\(\"00000015.003_Y_MonteCarlo003_Events.root\"\)
23
24 or from within root
25
26 [0] .x ../hawc/star.C("00000015.003_Y_MonteCarlo003_Events.root")
27
28******************************************************************/
29int star(const char *datafile, const char *outpath=".")
30{
31 // The delta t [ns/deg] for the image cleaning
32 double deltat = 17.5;
33
34 // --------------------------------------------------------
35
36 // Define the binning for the plots
37 MBinning binse( 40, 10 , 1e4, "BinningSize", "log");
38 MBinning bins1( 36, -90, 90, "BinningAlpha");
39 MBinning bins3( 67, -0.005, 0.665, "BinningTheta", "asin");
40 MBinning bins4( 40, 0, 8, "BinningDist");
41 MBinning bins5( 30, 0, 6, "BinningWidth");
42 MBinning bins6( 30, 0, 6, "BinningLength");
43 MBinning bins7( 31, -6, 6, "BinningM3Long");
44 MBinning bins8( 31, -6, 6, "BinningM3Trans");
45 MBinning bins9( 31, -6, 6, "BinningAsym");
46 MBinning binsA( 100, 0, 10, "BinningArea");
47 MBinning binsT( 30, 0, 6, "BinningTimeSpread");
48
49
50 // ------------------------------------------------------
51
52 gLog.Separator("Star");
53 gLog << all << "Calculate image parameters of sequence ";
54 gLog << datafile << endl;
55 gLog << endl;
56
57 // ------------------------------------------------------
58
59 gLog << "Outpath: " << outpath << endl;
60
61 // TString fname = gSystem->ConcatFileName(outpath, gSystem->BaseName(datafile));
62 // fname.ReplaceAll("_C_", "_I_");
63 // gSystem->ExpandPathName(fname);
64
65 gLog.Separator();
66
67 // ---------------------------------------------------------
68
69 // Allocate/open the status display
70 MStatusDisplay *d = new MStatusDisplay;
71
72 // Instantiate the list of tasks
73 MTaskList tlist;
74
75 // Instantiate the list of parameter containers
76 MParList plist2;
77 plist2.AddToList(&tlist);
78
79 // Fill it with the binnings
80 plist2.AddToList(&binse);
81 plist2.AddToList(&bins1);
82 plist2.AddToList(&bins3);
83 plist2.AddToList(&bins4);
84 plist2.AddToList(&bins5);
85 plist2.AddToList(&bins6);
86 plist2.AddToList(&bins7);
87 plist2.AddToList(&bins8);
88 plist2.AddToList(&bins9);
89 plist2.AddToList(&binsA);
90 plist2.AddToList(&binsT);
91
92 // Instatiate the event loop
93 MEvtLoop loop;
94 loop.SetDisplay(d);
95 loop.SetParList(&plist2);
96
97 MDirIter files(datafile);
98
99 // Instantiate the reading task
100 // You can use
101 // read.AddFiles("*_C.root")
102 // for example to read more than one file at once
103 MReadMarsFile read("Events");
104 read.DisableAutoScheme();
105 read.AddFiles(files);
106
107 // Instantiate the task which takes care of the size of all containers
108 MGeomApply apply;
109
110 // Instantiate the image cleaning
111
112 // This is the most simple image cleaning possible, standard
113 // tail cut based on absolute amplitudes
114 // MImgCleanStd clean(lvl1, lvl2);
115 // clean.SetMethod(MImgCleanStd::kAbsolute);
116 // clean.SetPostCleanType(3);
117
118 // Instantiate the image cleaning as described in the TRAC
119 MImgCleanTime clean;
120 clean.SetMinCount(0);
121 clean.SetMinSize(25);
122 clean.SetDeltaT(2.5);
123
124 // Instantiate the calculation of the image parameters
125 MHillasCalc hcalc;
126 hcalc.Disable(MHillasCalc::kCalcConc);
127
128 // Instantiate a plot for the rate after cleaning
129 MH3 hrate("MRawRunHeader.GetFileID"/*, "MRawEvtHeader.GetTriggerID"*/);
130 hrate.SetWeight("1./TMath::Max(MRawRunHeader.GetRunLength,1.)");
131 hrate.SetName("Rate");
132 hrate.SetTitle("Event rate after cleaning;File Id;Event Rate [Hz];");
133 hrate.InitLabels(MH3::kLabelsX);
134 hrate.GetHist().SetMinimum(0);
135
136 // Instantiate the task to fill the rate plot
137 MFillH fillR(&hrate, "", "FillRate");
138
139 // Instantiate the camera displays to be filled
140 MHCamEvent evtC1(0, "Cleaned", "Average signal after Cleaning;;S [phe]");
141 MHCamEvent evtC2(0, "UsedPix", "Fraction of Events in which Pixels are used;;Fraction");
142 MHCamEvent evtC3(8, "PulsePos", "Pulse Position of signal after cleaning;;T [ns]");
143 evtC1.SetErrorSpread(kFALSE);
144 evtC2.SetErrorSpread(kFALSE);
145 evtC2.SetThreshold(0);
146
147 // Instantiate tasks to fill the camera displays
148 MFillH fillC1(&evtC1, "MSignalCam", "FillSignalCam");
149 MFillH fillC2(&evtC2, "MSignalCam", "FillCntUsedPixels");
150 MFillH fillC3(&evtC3, "MSignalCam", "FillPulsePos");
151
152 // Instantiate tasks to fill image parameter histograms
153 MFillH fillD1("MHHillas", "MHillas", "FillHillas");
154 MFillH fillD2("MHHillasExt", "", "FillHillasExt");
155 MFillH fillD3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
156 MFillH fillD4("MHImagePar", "MImagePar", "FillImagePar");
157 MFillH fillD5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
158 MFillH fillD6("MHVsSize", "MHillasSrc", "FillVsSize");
159
160 // Instantiate an example for a user defined plot
161 MH3 halpha("MHillasSrc.fDist*MGeomCam.fConvMm2Deg", "fabs(MHillasSrc.fAlpha)");
162 halpha.SetName("AvsD;Dist;Alpha");
163
164 // Instantiate a task to fill that plot
165 MFillH filla(&halpha);
166 filla.SetNameTab("AvsD");
167 filla.SetDrawOption("colz");
168
169 // This is an alternative if more than one file should be read in a single loop
170 // In this case the output file name of each file is created with this rule
171 // from the input file name. Note that the filename of the output file
172 // with the status display must then be explicitly given.
173 //
174 //const TString fname(Form("s/([0-9]+_[0-9]+)[.]_C.root$/%s\\/$1_I.root/",
175 // MJob::Esc(outpath).Data()));
176 //MWriteRootFile write5(2, fname, "RECREATE", "Image parameters");
177
178 const TString rule(Form("s/([0-9]+)([._])([0-9]+)(_Y)?([_].*)?[.]root$/%s\\/$1$2$3_I$5.root/",
179 MJob:: Esc(outpath).Data()));
180
181 // Instantiate writing the file
182 MWriteRootFile write(2, rule, "RECREATE", "Image parameters");
183 write.AddContainer("MTime", "Events");
184 write.AddContainer("MHillas", "Events");
185 write.AddContainer("MHillasExt", "Events");
186 write.AddContainer("MHillasSrc", "Events");
187 write.AddContainer("MImagePar", "Events");
188 write.AddContainer("MNewImagePar", "Events");
189 write.AddContainer("MRawEvtHeader", "Events");
190 write.AddContainer("MSoftwareTrigger","Events");
191 write.AddContainer("MRawRunHeader", "RunHeaders");
192 write.AddContainer("MGeomCam", "RunHeaders");
193
194 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
195 write.AddContainer("MCorsikaRunHeader", "RunHeaders", kFALSE);
196 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
197 write.AddContainer("MCorsikaEvtHeader", "Events", kFALSE);
198 write.AddContainer("MMcEvt", "Events", kFALSE);
199 write.AddContainer("IncidentAngle", "Events", kFALSE);
200 write.AddContainer("MPointingPos", "Events", kFALSE);
201 write.AddContainer("MTime", "Events", kFALSE);
202 write.AddContainer("MSrcPosCam", "Events", kFALSE);
203
204 // Setup the task list
205 tlist.AddToList(&read);
206 tlist.AddToList(&apply);
207 tlist.AddToList(&clean);
208 tlist.AddToList(&hcalc);
209 tlist.AddToList(&fillC1);
210 tlist.AddToList(&fillC2);
211 tlist.AddToList(&fillC3);
212 tlist.AddToList(&fillR);
213 tlist.AddToList(&fillD1);
214 tlist.AddToList(&fillD2);
215 tlist.AddToList(&fillD3);
216 tlist.AddToList(&fillD4);
217 tlist.AddToList(&fillD5);
218 tlist.AddToList(&fillD6);
219 tlist.AddToList(&filla);
220 tlist.AddToList(&write);
221
222 // Run the eventloop
223 if (!loop.Eventloop())
224 return 3;
225
226 // Check if the display was closed (deleted) by the user
227 if (!loop.GetDisplay())
228 return 4;
229
230 // ============================================================
231
232 TString fname = write.GetFileName();
233 fname.ReplaceAll(".root", "-display.root");
234
235 // Write the status display to the file
236 TString title = "-- Image parameters [";
237 title += datafile;
238 title += "] --";
239 d->SetTitle(title, kFALSE);
240
241 d->SaveAsRoot(fname);
242
243 return 0;
244}
Note: See TracBrowser for help on using the repository browser.