1 | /*********************************/
|
---|
2 | /* Compute the hillas parameters */
|
---|
3 | /*********************************/
|
---|
4 |
|
---|
5 | #include "TString.h"
|
---|
6 | #include "TArrayS.h"
|
---|
7 |
|
---|
8 | #include "MParList.h"
|
---|
9 | #include "MTaskList.h"
|
---|
10 | #include "MPedestalCam.h"
|
---|
11 | #include "MBadPixelsCam.h"
|
---|
12 | #include "MBadPixelsTreat.h"
|
---|
13 | #include "MReadMarsFile.h"
|
---|
14 | #include "MGeomApply.h"
|
---|
15 | #include "MPedCalcPedRun.h"
|
---|
16 | #include "MEvtLoop.h"
|
---|
17 | #include "MGeomCamMagic.h"
|
---|
18 | #include "MExtractedSignalCam.h"
|
---|
19 | #include "MCalibrationChargeCam.h"
|
---|
20 | #include "MCalibrationQECam.h"
|
---|
21 | #include "MCalibrationQEPix.h"
|
---|
22 | #include "MHCalibrationChargeCam.h"
|
---|
23 | #include "MHCalibrationRelTimeCam.h"
|
---|
24 | #include "MExtractor.h"
|
---|
25 | #include "MExtractFixedWindow.h"
|
---|
26 | #include "MExtractSlidingWindow.h"
|
---|
27 | #include "MExtractSignal.h"
|
---|
28 | #include "MCalibrationChargeCalc.h"
|
---|
29 | #include "MFCosmics.h"
|
---|
30 | #include "MContinue.h"
|
---|
31 | #include "MLog.h"
|
---|
32 | #include "MCerPhotEvt.h"
|
---|
33 | #include "MPedPhotCam.h"
|
---|
34 | #include "MCalibrate.h"
|
---|
35 | #include "MPedPhotCalc.h"
|
---|
36 | #include "MHillas.h"
|
---|
37 | #include "MNewImagePar.h"
|
---|
38 | #include "MRawRunHeader.h"
|
---|
39 | #include "MSrcPosCam.h"
|
---|
40 | #include "MBlindPixelCalc.h"
|
---|
41 | #include "MImgCleanStd.h"
|
---|
42 | #include "MHillasSrcCalc.h"
|
---|
43 | #include "MHillasCalc.h"
|
---|
44 | #include "MArrivalTimeCam.h"
|
---|
45 | #include "MArrivalTimeCalc2.h"
|
---|
46 | #include "MIslands.h"
|
---|
47 | #include "MIslandCalc.h"
|
---|
48 | #include "MIslandClean.h"
|
---|
49 | #include "MWriteRootFile.h"
|
---|
50 | #include "MArgs.h"
|
---|
51 | #include "MRunIter.h"
|
---|
52 | #include "MJPedestal.h"
|
---|
53 | #include "MJCalibration.h"
|
---|
54 | #include "MHillasDisplay.h"
|
---|
55 | #include "MF.h"
|
---|
56 | #include "MContinue.h"
|
---|
57 |
|
---|
58 | #include "TApplication.h"
|
---|
59 |
|
---|
60 | #include <iostream>
|
---|
61 | #include <fstream>
|
---|
62 | #include <stdlib.h>
|
---|
63 |
|
---|
64 | using namespace std;
|
---|
65 |
|
---|
66 | Bool_t readDatacards(TString& filename);
|
---|
67 | void calib();
|
---|
68 |
|
---|
69 | // initial and final time slices to be used in signal extraction
|
---|
70 | const Byte_t hifirst = 1;
|
---|
71 | const Byte_t hilast = 14;
|
---|
72 | const Byte_t lofirst = 3;
|
---|
73 | const Byte_t lolast = 14;
|
---|
74 |
|
---|
75 | // declaration of variables read from datacards
|
---|
76 | TString outname;
|
---|
77 | TString idirname;
|
---|
78 | TString filter;
|
---|
79 | TString psfilename("makehillas.ps");
|
---|
80 | MRunIter caliter;
|
---|
81 | MRunIter pediter;
|
---|
82 | MRunIter datiter;
|
---|
83 | UInt_t display = 0;
|
---|
84 | ULong_t nmaxevents= 999999999;
|
---|
85 | Short_t calflag = 1;
|
---|
86 | Float_t lcore = 3.0;
|
---|
87 | Float_t ltail = 1.5;
|
---|
88 | Int_t islflag = 0;
|
---|
89 | Float_t lnew = 40;
|
---|
90 | Int_t kmethod = 1;
|
---|
91 | Int_t kalgorithm = 1;
|
---|
92 | Int_t nfiles = 0;
|
---|
93 |
|
---|
94 | const TString defaultcard="makehillas.datacard";
|
---|
95 | /*************************************************************/
|
---|
96 | static void Usage()
|
---|
97 | {
|
---|
98 | gLog <<endl;
|
---|
99 | gLog << "Usage is:" << endl;
|
---|
100 | gLog << " calib [-h] [-?] <datacards>" << endl << endl;
|
---|
101 | gLog << " <datacards>: datacards file name (dafault input.datacards)" << endl;
|
---|
102 | gLog << " -?/-h: This help" << endl << endl;
|
---|
103 | }
|
---|
104 | /*************************************************************/
|
---|
105 | int main(int argc, char **argv)
|
---|
106 | {
|
---|
107 | // create a TApplication to be able to
|
---|
108 | TApplication app("Application",0,0);
|
---|
109 |
|
---|
110 | // evaluate arguments
|
---|
111 | MArgs arg(argc, argv);
|
---|
112 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
113 | {
|
---|
114 | Usage();
|
---|
115 | return -1;
|
---|
116 | }
|
---|
117 |
|
---|
118 | TString datacard = arg.GetArgumentStr(0);
|
---|
119 | if(!datacard.Length())
|
---|
120 | datacard = defaultcard;
|
---|
121 |
|
---|
122 | if(!readDatacards(datacard))
|
---|
123 | {
|
---|
124 | cout << "Error reading datacards. Stoping" << endl;
|
---|
125 | return -1;
|
---|
126 | }
|
---|
127 |
|
---|
128 | calib();
|
---|
129 | }
|
---|
130 |
|
---|
131 | /*************************************************************/
|
---|
132 | void calib()
|
---|
133 | {
|
---|
134 | // Set the general tasks/containers
|
---|
135 | MExtractFixedWindow extractor;
|
---|
136 | extractor.SetRange(hifirst,hilast,lofirst,lolast);
|
---|
137 |
|
---|
138 | // MExtractSlidingWindow extractor;
|
---|
139 | // extractor.SetRange(hifirst,hilast,lofirst,lolast);
|
---|
140 | // extractor.SetWindowSize(2,2);
|
---|
141 |
|
---|
142 | MGeomCamMagic geomcam;
|
---|
143 | MGeomApply geomapl;
|
---|
144 |
|
---|
145 | /************************************/
|
---|
146 | /* FIRST LOOP: PEDESTAL COMPUTATION */
|
---|
147 | /************************************/
|
---|
148 |
|
---|
149 | // If you want to exclude pixels from the beginning, read
|
---|
150 | // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
|
---|
151 | //badcam.AsciiRead("badpixels.dat");
|
---|
152 |
|
---|
153 | MJPedestal pedloop;
|
---|
154 | pedloop.SetInput(&pediter);
|
---|
155 | pedloop.SetExtractor(&extractor);
|
---|
156 | // pedloop.SetBadPixels(badcam);
|
---|
157 |
|
---|
158 | if (!pedloop.Process())
|
---|
159 | return;
|
---|
160 |
|
---|
161 | /*****************************/
|
---|
162 | /* SECOND LOOP: CALIBRATION */
|
---|
163 | /*****************************/
|
---|
164 |
|
---|
165 | MJCalibration calloop;
|
---|
166 |
|
---|
167 | calloop.SetExtractor(&extractor);
|
---|
168 | calloop.SetInput(&caliter);
|
---|
169 | calloop.SetBadPixels(pedloop.GetBadPixels());
|
---|
170 | if(calflag==2)
|
---|
171 | calloop.SetUseBlindPixel();
|
---|
172 |
|
---|
173 | if(calflag>0)
|
---|
174 | if (!calloop.Process(pedloop.GetPedestalCam()))
|
---|
175 | return;
|
---|
176 |
|
---|
177 | Float_t meanCharge[577];
|
---|
178 | Float_t meanSigma[577];
|
---|
179 | Float_t meanFADC2Phe[577];
|
---|
180 | Float_t meanFADCtoPh[577];
|
---|
181 | Float_t prob[577];
|
---|
182 | ofstream fout;
|
---|
183 |
|
---|
184 | fout.open(outname);
|
---|
185 |
|
---|
186 | for (Int_t i=0; i<577; i++)
|
---|
187 | {
|
---|
188 | meanCharge[i] = 0;
|
---|
189 | MCalibrationChargePix calpix = (MCalibrationChargePix&)(calloop.GetCalibrationCam())[i];
|
---|
190 | MCalibrationQEPix qepix = ( MCalibrationQEPix&)(calloop.GetQECam())[i];
|
---|
191 | meanCharge[i] = calpix.GetMean();
|
---|
192 | meanSigma[i] = calpix.GetSigma();
|
---|
193 | meanFADC2Phe[i]=calpix.GetMeanConvFADC2Phe();
|
---|
194 | meanFADCtoPh[i]=calpix.GetMeanConvFADC2Phe()/qepix.GetQECascadesFFactor(0);
|
---|
195 | prob[i]=calpix.GetProb();
|
---|
196 | fout << i << '\t' << meanCharge[i] << '\t' << meanSigma[i]<< '\t' << meanFADC2Phe[i]<< '\t' <<meanFADCtoPh[i]<< '\t' <<prob[i]<< '\t' <<(Int_t)calpix.IsHiGainSaturation()<<endl;
|
---|
197 | }
|
---|
198 |
|
---|
199 | fout.close();
|
---|
200 |
|
---|
201 | return;
|
---|
202 |
|
---|
203 | }
|
---|
204 | //-------------------------------------------------------------------------------
|
---|
205 |
|
---|
206 | Bool_t readDatacards(TString& filename)
|
---|
207 | {
|
---|
208 | ifstream ifun(filename.Data());
|
---|
209 | if(!ifun)
|
---|
210 | {
|
---|
211 | cout << "File " << filename << " not found" << endl;
|
---|
212 | return kFALSE;
|
---|
213 | }
|
---|
214 |
|
---|
215 | TString word;
|
---|
216 |
|
---|
217 | while(ifun >> word)
|
---|
218 | {
|
---|
219 | // skip comments
|
---|
220 | if(word[0]=='/' && word[1]=='/')
|
---|
221 | {
|
---|
222 | while(ifun.get()!='\n'); // skip line
|
---|
223 | continue;
|
---|
224 | }
|
---|
225 |
|
---|
226 | // input file directory
|
---|
227 | if(strcmp(word.Data(),"IDIR")==0)
|
---|
228 | {
|
---|
229 | if(idirname.Length())
|
---|
230 | cout << "readDataCards Warning: overriding input directory file name" << endl;
|
---|
231 | ifun >> idirname;
|
---|
232 | }
|
---|
233 |
|
---|
234 | // pedestal runs
|
---|
235 | if(strcmp(word.Data(),"PRUNS")==0)
|
---|
236 | {
|
---|
237 | if(pediter.GetNumRuns())
|
---|
238 | cout << "readDataCards Warning: adding pedestal runs to the existing list" << endl;
|
---|
239 | ifun >> word;
|
---|
240 | pediter.AddRuns(word.Data(),idirname.Data());
|
---|
241 | }
|
---|
242 |
|
---|
243 | // calibration runs
|
---|
244 | if(strcmp(word.Data(),"CRUNS")==0)
|
---|
245 | {
|
---|
246 | if(caliter.GetNumRuns())
|
---|
247 | cout << "readDataCards Warning: adding calibration runs to the existing list" << endl;
|
---|
248 | ifun >> word;
|
---|
249 | caliter.AddRuns(word.Data(),idirname.Data());
|
---|
250 | }
|
---|
251 |
|
---|
252 | // output file name
|
---|
253 | if(strcmp(word.Data(),"OUTFILE")==0)
|
---|
254 | {
|
---|
255 | if(outname.Length())
|
---|
256 | cout << "readDataCards Warning: overriding output file name" << endl;
|
---|
257 | ifun >> outname;
|
---|
258 | }
|
---|
259 |
|
---|
260 | // calibration flag
|
---|
261 | if(strcmp(word.Data(),"CALFLAG")==0)
|
---|
262 | ifun >> calflag;
|
---|
263 |
|
---|
264 |
|
---|
265 | }
|
---|
266 |
|
---|
267 | pediter.Reset();
|
---|
268 | caliter.Reset();
|
---|
269 | datiter.Reset();
|
---|
270 | TString pfile;
|
---|
271 |
|
---|
272 | // Dump read values
|
---|
273 | cout << "************************************************" << endl;
|
---|
274 | cout << "* Datacards read from file " << filename << endl;
|
---|
275 | cout << "************************************************" << endl;
|
---|
276 | cout << "Pedestal file (s): " << endl;
|
---|
277 | while(!(pfile=pediter.Next()).IsNull())
|
---|
278 | cout << pfile << endl;
|
---|
279 | cout << "Calibration file (s): " << endl;
|
---|
280 | while(!(pfile=caliter.Next()).IsNull())
|
---|
281 | cout << pfile << endl;
|
---|
282 | cout << "Output file name: " << outname << endl;
|
---|
283 | cout << "Calibration: ";
|
---|
284 | if(calflag==0)
|
---|
285 | cout << "Pixel area proportional intercalibration" << endl;
|
---|
286 | else if(calflag==-1)
|
---|
287 | cout << "No calibration whatsoever" << endl;
|
---|
288 | else if(calflag==1)
|
---|
289 | cout << "Default calibration" << endl;
|
---|
290 | else if(calflag==11)
|
---|
291 | cout << "Default calibration + bad pixels interpolation" << endl;
|
---|
292 |
|
---|
293 | if(!pediter.GetNumEntries())
|
---|
294 | {
|
---|
295 | cout << "No pedestal file name specified" << endl;
|
---|
296 | return kFALSE;
|
---|
297 | }
|
---|
298 | if(!caliter.GetNumEntries() && calflag>0)
|
---|
299 | {
|
---|
300 | cout << "No calibration file name specified" << endl;
|
---|
301 | return kFALSE;
|
---|
302 | }
|
---|
303 | if(!outname.Length())
|
---|
304 | {
|
---|
305 | cout << "No output file name specified" << endl;
|
---|
306 | return kFALSE;
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 | return kTRUE;
|
---|
311 | }
|
---|
312 |
|
---|