source: trunk/MagicSoft/Mars/mtemp/mifae/programs/makeHillas.cc@ 4099

Last change on this file since 4099 was 4056, checked in by rico, 21 years ago
*** empty log message ***
File size: 12.3 KB
Line 
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 "MReadMarsFile.h"
13#include "MGeomApply.h"
14#include "MPedCalcPedRun.h"
15#include "MEvtLoop.h"
16#include "MGeomCamMagic.h"
17#include "MExtractedSignalCam.h"
18#include "MCalibrationChargeCam.h"
19#include "MHCalibrationChargeCam.h"
20#include "MHCalibrationRelTimeCam.h"
21#include "MExtractor.h"
22#include "MExtractFixedWindow.h"
23#include "MExtractSignal.h"
24#include "MCalibrationChargeCalc.h"
25#include "MFCosmics.h"
26#include "MContinue.h"
27#include "MFillH.h"
28#include "MLog.h"
29#include "MCerPhotEvt.h"
30#include "MPedPhotCam.h"
31#include "MCalibrate.h"
32#include "MPedPhotCalc.h"
33#include "MHillas.h"
34#include "MRawRunHeader.h"
35#include "MSrcPosCam.h"
36#include "MBlindPixelCalc.h"
37#include "MImgCleanStd.h"
38#include "MHillasSrcCalc.h"
39#include "MHillasCalc.h"
40#include "MArrivalTimeCam.h"
41#include "MArrivalTimeCalc2.h"
42#include "MIslands.h"
43#include "MIslandCalc.h"
44#include "MIslandClean.h"
45#include "MWriteRootFile.h"
46#include "MProgressBar.h"
47#include "MArgs.h"
48#include "MRunIter.h"
49#include "MJPedestal.h"
50#include "MJCalibration.h"
51
52#include <iostream>
53#include <fstream>
54#include <stdlib.h>
55
56using namespace std;
57
58Bool_t readDatacards(TString& filename);
59void makeHillas();
60
61// initial and final time slices to be used in signal extraction
62const Byte_t hifirst = 0;
63const Byte_t hilast = 13;
64const Byte_t lofirst = 3;
65const Byte_t lolast = 12;
66
67// declaration of variables read from datacards
68TString outname;
69TString idirname;
70MRunIter caliter;
71MRunIter pediter;
72MRunIter datiter;
73ULong_t nmaxevents=999999999;
74Short_t calflag=1;
75Float_t lcore = 3.0;
76Float_t ltail = 1.5;
77Int_t islflag = 0;
78Float_t lnew = 40;
79Int_t kmethod = 1;
80Int_t nfiles = 0;
81
82const TString defaultcard="input.datacard";
83/*************************************************************/
84static void Usage()
85{
86 gLog <<endl;
87 gLog << "Usage is:" << endl;
88 gLog << " makeHillas [-h] [-?] <datacards>" << endl << endl;
89 gLog << " <datacards>: datacards file name (dafault input.datacards)" << endl;
90 gLog << " -?/-h: This help" << endl << endl;
91}
92/*************************************************************/
93int main(int argc, char **argv)
94{
95 // evaluate arguments
96 MArgs arg(argc, argv);
97 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
98 {
99 Usage();
100 return -1;
101 }
102
103 TString datacard = arg.GetArgumentStr(0);
104 if(!datacard.Length())
105 datacard = defaultcard;
106
107 if(!readDatacards(datacard))
108 {
109 cout << "Error reading datacards. Stoping" << endl;
110 return -1;
111 }
112 makeHillas();
113}
114
115/*************************************************************/
116void makeHillas()
117{
118 // Set the general tasks/containers
119 MExtractFixedWindow extractor;
120 extractor.SetRange(hifirst,hilast,lofirst,lolast);
121
122 MCalibrationQECam qecam;
123 MBadPixelsCam badcam;
124 MGeomCamMagic geomcam;
125 MGeomApply geomapl;
126
127 /************************************/
128 /* FIRST LOOP: PEDESTAL COMPUTATION */
129 /************************************/
130
131 // If you want to exclude pixels from the beginning, read
132 // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
133 //badcam.AsciiRead("badpixels.dat");
134
135 MJPedestal pedloop;
136 pedloop.SetInput(&pediter);
137 pedloop.SetExtractor(&extractor);
138 pedloop.SetBadPixels(badcam);
139
140 if (!pedloop.Process())
141 return;
142
143 /*****************************/
144 /* SECOND LOOP: CALIBRATION */
145 /*****************************/
146
147 MJCalibration calloop;
148
149 calloop.SetExtractor(&extractor);
150 calloop.SetInput(&caliter);
151 calloop.SetQECam(qecam);
152 calloop.SetBadPixels(pedloop.GetBadPixels());
153 if (!calloop.Process(pedloop.GetPedestalCam()))
154 return;
155
156 /************************************************************************/
157 /* THIRD LOOP: PEDESTAL CALIBRATION INTO PHOTONS */
158 /************************************************************************/
159 MParList plist3;
160 MTaskList tlist3;
161 plist3.AddToList(&tlist3);
162
163 // containers
164 MCerPhotEvt nphot;
165 MPedPhotCam nphotrms;
166 MExtractedSignalCam sigcam;
167
168 plist3.AddToList(&geomcam);
169 plist3.AddToList(&pedloop.GetPedestalCam());
170 plist3.AddToList(&calloop.GetCalibrationCam());
171 plist3.AddToList(&badcam);
172 plist3.AddToList(&sigcam);
173 plist3.AddToList(&nphot);
174 plist3.AddToList(&nphotrms);
175
176
177 MCalibrate::CalibrationMode_t calMode=MCalibrate::kDefault;
178 if(calflag==0)
179 calMode=MCalibrate::kNone;
180 if(calflag==-1)
181 calMode=MCalibrate::kDummy;
182
183 //tasks
184 MReadMarsFile read3("Events");
185 static_cast<MRead&>(read3).AddFiles(pediter);
186 read3.DisableAutoScheme();
187
188 // MExtractSignal extsig;
189 // extsig.SetRange(hifirst,hilast,lofirst,lolast);
190 MCalibrate photcalc(calMode);
191 MPedPhotCalc photrmscalc;
192
193 tlist3.AddToList(&read3);
194 tlist3.AddToList(&geomapl);
195 tlist3.AddToList(&extractor);
196 tlist3.AddToList(&photcalc);
197 tlist3.AddToList(&photrmscalc);
198
199 // Create and setup the eventloop
200 MEvtLoop evtloop3;
201 evtloop3.SetParList(&plist3);
202 if (!evtloop3.Eventloop())
203 return;
204
205 tlist3.PrintStatistics();
206
207 /************************************************************************/
208 /* FOURTH LOOP: DATA CALIBRATION INTO PHOTONS */
209 /************************************************************************/
210
211 MParList plist4;
212 MTaskList tlist4;
213 plist4.AddToList(&tlist4);
214
215 // containers
216 MHillas hillas;
217 MSrcPosCam source;
218 MRawRunHeader runhead;
219
220 MArrivalTimeCam timecam;
221
222 MIslands isl;
223 isl.SetName("MIslands1");
224
225 MIslands isl2;
226 isl2.SetName("MIslands2");
227
228 if (islflag == 1 || islflag == 2)
229 {
230 plist4.AddToList(&timecam);
231 plist4.AddToList(&isl);
232 }
233
234 if (islflag == 2)
235 {
236 plist4.AddToList(&isl2);
237 }
238
239 plist4.AddToList(&geomcam);
240 plist4.AddToList(&pedloop.GetPedestalCam());
241 plist4.AddToList(&calloop.GetCalibrationCam());
242 // plist4.AddToList(&badcam);
243 plist4.AddToList(&nphot);
244 plist4.AddToList(&nphotrms);
245 plist4.AddToList(&source);
246 plist4.AddToList(&hillas);
247 plist4.AddToList(&runhead);
248
249 //tasks
250 MReadMarsFile read4("Events");
251 static_cast<MRead&>(read4).AddFiles(datiter);
252 read4.DisableAutoScheme();
253
254 // set bad pixels
255 MBlindPixelCalc blind;
256 MBlindPixelCalc blind2;
257 const Short_t x[16] = {330,395,329,396,389,
258 323,388,322,384,385,
259 386,387,321,320,319,
260 394};
261 const TArrayS bp(16,(Short_t*)x);
262 blind.SetPixelIndices(bp);
263 blind2.SetPixelIndices(bp);
264
265 MImgCleanStd clean(lcore,ltail);
266
267 MArrivalTimeCalc2 timecalc;
268
269 MIslandCalc island;
270 island.SetOutputName("MIslands1");
271
272 MIslandClean islclean(lnew);
273 islclean.SetInputName("MIslands1");
274 islclean.SetMethod(kmethod);
275
276 MIslandCalc island2;
277 island2.SetOutputName("MIslands2");
278
279
280 MHillasCalc hcalc;
281 MHillasSrcCalc csrc1;
282
283 MWriteRootFile write(outname,"RECREATE");
284
285 write.AddContainer("MHillas" , "Parameters");
286 write.AddContainer("MHillasSrc" , "Parameters");
287 write.AddContainer("MHillasExt" , "Parameters");
288 write.AddContainer("MNewImagePar" , "Parameters");
289 write.AddContainer("MRawEvtHeader" , "Parameters");
290 write.AddContainer("MRawRunHeader" , "Parameters");
291 write.AddContainer("MConcentration" , "Parameters");
292 write.AddContainer("MSrcPosCam" , "Parameters");
293
294 if (islflag == 1 || islflag == 2)
295 write.AddContainer("MIslands1" , "Parameters");
296 if (islflag == 2)
297 write.AddContainer("MIslands2" , "Parameters");
298
299 tlist4.AddToList(&read4);
300 tlist4.AddToList(&geomapl);
301 tlist4.AddToList(&extractor);
302 tlist4.AddToList(&photcalc);
303 //tlist4.AddToList(&blind);
304 tlist4.AddToList(&clean);
305
306 if (islflag == 1 || islflag == 2)
307 {
308 tlist4.AddToList(&timecalc);
309 tlist4.AddToList(&island);
310 }
311
312 if (islflag == 2)
313 {
314 tlist4.AddToList(&islclean);
315 tlist4.AddToList(&island2);
316 }
317
318 //tlist4.AddToList(&blind2);
319 tlist4.AddToList(&hcalc);
320 // tlist4.AddToList(&srcposcalc);
321 tlist4.AddToList(&csrc1);
322 tlist4.AddToList(&write);
323
324 // Create and setup the eventloop
325 MEvtLoop datloop;
326 datloop.SetParList(&plist4);
327
328 cout << "*************************************************************" << endl;
329 cout << "*** COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS) ***" << endl;
330 cout << "*************************************************************" << endl;
331
332 if (!datloop.Eventloop(nmaxevents))
333 return;
334
335 tlist4.PrintStatistics();
336}
337//-------------------------------------------------------------------------------
338
339Bool_t readDatacards(TString& filename)
340{
341 ifstream ifun(filename.Data());
342 if(!ifun)
343 {
344 cout << "File " << filename << " not found" << endl;
345 return kFALSE;
346 }
347
348 TString word;
349
350 while(ifun >> word)
351 {
352 // skip comments
353 if(word[0]=='/' && word[1]=='/')
354 {
355 while(ifun.get()!='\n'); // skip line
356 continue;
357 }
358
359 // number of events
360 if(strcmp(word.Data(),"NEVENTS")==0)
361 ifun >> nmaxevents;
362
363
364 // input file directory
365 if(strcmp(word.Data(),"IDIR")==0)
366 {
367 if(idirname.Length())
368 cout << "readDataCards Warning: overriding input directory file name" << endl;
369 ifun >> idirname;
370 }
371
372 // pedestal runs
373 if(strcmp(word.Data(),"PRUNS")==0)
374 {
375 if(pediter.GetNumRuns())
376 cout << "readDataCards Warning: adding pedestal runs to the existing list" << endl;
377 ifun >> word;
378 pediter.AddRuns(word.Data(),idirname.Data());
379 }
380
381 // calibration runs
382 if(strcmp(word.Data(),"CRUNS")==0)
383 {
384 if(caliter.GetNumRuns())
385 cout << "readDataCards Warning: adding calibration runs to the existing list" << endl;
386 ifun >> word;
387 caliter.AddRuns(word.Data(),idirname.Data());
388 }
389
390 // data runs
391 if(strcmp(word.Data(),"DRUNS")==0)
392 {
393 if(datiter.GetNumRuns())
394 cout << "readDataCards Warning: adding data runs to the existing list" << endl;
395 ifun >> word;
396 datiter.AddRuns(word.Data(),idirname.Data());
397 }
398
399 // output file name
400 if(strcmp(word.Data(),"OUTFILE")==0)
401 {
402 if(outname.Length())
403 cout << "readDataCards Warning: overriding output file name" << endl;
404 ifun >> outname;
405 }
406
407 // calibration flag
408 if(strcmp(word.Data(),"CALFLAG")==0)
409 ifun >> calflag;
410
411 // cleaning level
412 if(strcmp(word.Data(),"CLEANLEVEL")==0)
413 {
414 ifun >> lcore;
415 ifun >> ltail;
416 }
417
418 if(strcmp(word.Data(),"ISLFLAG")==0)
419 {
420 ifun >> islflag;
421 }
422
423 // island cleaning
424 if (islflag == 2){
425 if(strcmp(word.Data(),"ISLANDCLEAN")==0)
426 {
427 ifun >> kmethod;
428 ifun >> lnew;
429 }
430 }
431 }
432
433 pediter.Reset();
434 caliter.Reset();
435 datiter.Reset();
436 TString pfile;
437
438 // Dump read values
439 cout << "************************************************" << endl;
440 cout << "* Datacards read from file " << filename << endl;
441 cout << "************************************************" << endl;
442 cout << "Pedestal file (s): " << endl;
443 while(!(pfile=pediter.Next()).IsNull())
444 cout << pfile << endl;
445 cout << "Calibration file (s): " << endl;
446 while(!(pfile=caliter.Next()).IsNull())
447 cout << pfile << endl;
448 cout << "Data file (s): " << endl;
449 while(!(pfile=datiter.Next()).IsNull())
450 cout << pfile << endl;
451 cout << "Maximum number of events: " << nmaxevents << endl;
452 cout << "Output file name: " << outname << endl;
453 cout << "Calibration flag: " << calflag << endl;
454 cout << "Cleaning level: ("<<lcore<<","<<ltail<<")" << endl;
455 if (islflag == 1 || islflag == 2)
456 cout << "Island calcultation..." << endl;
457 if (islflag == 2)
458 {
459 cout << "Island Cleaning: "<< kmethod <<" method "<< lnew << " new threshold" << endl;
460 }
461 cout << "***********" << endl << endl;
462
463 if(!pediter.GetNumEntries())
464 {
465 cout << "No pedestal file name specified" << endl;
466 return kFALSE;
467 }
468 if(!caliter.GetNumEntries())
469 {
470 cout << "No calibration file name specified" << endl;
471 return kFALSE;
472 }
473 if(!datiter.GetNumEntries())
474 {
475 cout << "No data file name specified" << endl;
476 return kFALSE;
477 }
478 if(!outname.Length())
479 {
480 cout << "No output file name specified" << endl;
481 return kFALSE;
482 }
483
484
485 return kTRUE;
486}
Note: See TracBrowser for help on using the repository browser.