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

Last change on this file since 4555 was 4555, checked in by aliu, 20 years ago
*** empty log message ***
File size: 15.7 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 "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 "MHCalibrationChargeCam.h"
21#include "MHCalibrationRelTimeCam.h"
22#include "MExtractor.h"
23#include "MExtractFixedWindow.h"
24#include "MExtractSlidingWindow.h"
25#include "MExtractSignal.h"
26#include "MCalibrationChargeCalc.h"
27#include "MFCosmics.h"
28#include "MContinue.h"
29#include "MLog.h"
30#include "MCerPhotEvt.h"
31#include "MPedPhotCam.h"
32#include "MCalibrate.h"
33#include "MPedPhotCalc.h"
34#include "MHillas.h"
35#include "MNewImagePar.h"
36#include "MRawRunHeader.h"
37#include "MSrcPosCam.h"
38#include "MImgCleanStd.h"
39#include "MHillasSrcCalc.h"
40#include "MHillasCalc.h"
41#include "MArrivalTimeCam.h"
42#include "MArrivalTimeCalc2.h"
43#include "MIslands.h"
44#include "MIslandCalc.h"
45#include "MIslandClean.h"
46#include "MWriteRootFile.h"
47#include "MArgs.h"
48#include "MRunIter.h"
49#include "MJPedestal.h"
50#include "MJCalibration.h"
51#include "MHillasDisplay.h"
52#include "MF.h"
53#include "MContinue.h"
54
55#include "TApplication.h"
56
57#include <iostream>
58#include <fstream>
59#include <stdlib.h>
60
61using namespace std;
62
63Bool_t readDatacards(TString& filename);
64void makeHillas();
65
66// initial and final time slices to be used in signal extraction
67const Byte_t hifirst = 1;
68const Byte_t hilast = 14;
69const Byte_t lofirst = 3;
70const Byte_t lolast = 14;
71
72// declaration of variables read from datacards
73TString outname;
74const TString outpath = "./";
75TString idirname;
76TString filter;
77TString psfilename("makehillas.ps");
78MRunIter pedcaliter;
79MRunIter caliter;
80MRunIter pediter;
81MRunIter datiter;
82UInt_t display = 0;
83ULong_t nmaxevents= 999999999;
84Short_t calflag = 1;
85Bool_t caltimeflag = kFALSE;
86Short_t cleanflag = 1;
87UShort_t lrings = 1;
88Float_t lcore = 3.0;
89Float_t ltail = 1.5;
90Int_t islflag = 0;
91Float_t lnew = 40;
92Int_t kmethod = 1;
93Int_t kalgorithm = 1;
94Int_t nfiles = 0;
95
96const TString defaultcard="makehillas.datacard";
97/*************************************************************/
98static void Usage()
99{
100 gLog <<endl;
101 gLog << "Usage is:" << endl;
102 gLog << " makeHillas [-h] [-?] <datacards>" << endl << endl;
103 gLog << " <datacards>: datacards file name (dafault input.datacards)" << endl;
104 gLog << " -?/-h: This help" << endl << endl;
105}
106/*************************************************************/
107int main(int argc, char **argv)
108{
109 // create a TApplication to be able to
110 TApplication app("Application",0,0);
111
112 // evaluate arguments
113 MArgs arg(argc, argv);
114 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
115 {
116 Usage();
117 return -1;
118 }
119
120 TString datacard = arg.GetArgumentStr(0);
121 if(!datacard.Length())
122 datacard = defaultcard;
123
124 if(!readDatacards(datacard))
125 {
126 cout << "Error reading datacards. Stoping" << endl;
127 return -1;
128 }
129
130 makeHillas();
131}
132
133/*************************************************************/
134void makeHillas()
135{
136 // Set the general tasks/containers
137 MExtractFixedWindow extractor;
138 extractor.SetRange(hifirst,hilast,lofirst,lolast);
139
140 //MExtractSlidingWindow extractor;
141 //extractor.SetRange(hifirst,hilast,lofirst,lolast);
142 //extractor.SetWindowSize(4,4);
143
144 MGeomCamMagic geomcam;
145 MGeomApply geomapl;
146
147 /************************************/
148 /* FIRST LOOP: PEDESTAL COMPUTATION */
149 /************************************/
150
151 // If you want to exclude pixels from the beginning, read
152 // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
153 //badcam.AsciiRead("badpixels.dat");
154
155 MJPedestal pedcalloop;
156 pedcalloop.SetInput(&pediter);
157 pedcalloop.SetExtractor(&extractor);
158 // pedloop.SetBadPixels(badcam);
159 //pedcalloop.SetOutputPath(outpath.Data());
160
161
162 if (!pedcalloop.Process())
163 return;
164
165 /*****************************/
166 /* SECOND LOOP: CALIBRATION */
167 /*****************************/
168
169 MJCalibration calloop;
170
171 calloop.SetRelTimeCalibration(caltimeflag);
172 calloop.SetExtractor(&extractor);
173 calloop.SetInput(&caliter);
174 calloop.SetBadPixels(pedcalloop.GetBadPixels());
175 if(calflag==2)
176 calloop.SetUseBlindPixel();
177 if(calflag>0)
178 if (!calloop.Process(pedcalloop.GetPedestalCam()))
179 return;
180
181
182 /************************************************************************/
183 /* THIRD LOOP: PEDESTAL CALIBRATION INTO PHOTONS */
184 /************************************************************************/
185 // First Compute the pedestals
186 MJPedestal pedloop;
187 pedloop.SetInput(&pediter);
188
189 if (!pedloop.Process())
190 return;
191
192 MParList plist3;
193 MTaskList tlist3;
194 plist3.AddToList(&tlist3);
195
196 // containers
197 MCerPhotEvt nphot;
198 MPedPhotCam nphotrms;
199 MExtractedSignalCam sigcam;
200
201 plist3.AddToList(&geomcam);
202 plist3.AddToList(&pedloop.GetPedestalCam());
203 plist3.AddToList(&calloop.GetCalibrationCam());
204 plist3.AddToList(&calloop.GetQECam());
205 plist3.AddToList(&calloop.GetRelTimeCam());
206 plist3.AddToList(&calloop.GetBadPixels());
207 plist3.AddToList(&sigcam);
208 plist3.AddToList(&nphot);
209 plist3.AddToList(&nphotrms);
210
211
212 MCalibrate::CalibrationMode_t calMode=MCalibrate::kDefault;
213 if(calflag==0)
214 calMode=MCalibrate::kNone;
215 if(calflag==-1)
216 calMode=MCalibrate::kDummy;
217
218 //tasks
219 MReadMarsFile read3("Events");
220 static_cast<MRead&>(read3).AddFiles(pediter);
221 read3.DisableAutoScheme();
222
223 MCalibrate photcalc(calMode);
224 MPedPhotCalc photrmscalc;
225
226 tlist3.AddToList(&read3);
227 tlist3.AddToList(&geomapl);
228 tlist3.AddToList(&extractor);
229 tlist3.AddToList(&photcalc);
230 tlist3.AddToList(&photrmscalc);
231
232 // Create and setup the eventloop
233 MEvtLoop evtloop3;
234 evtloop3.SetParList(&plist3);
235 if (!evtloop3.Eventloop())
236 return;
237
238 tlist3.PrintStatistics();
239
240 /************************************************************************/
241 /* FOURTH LOOP: DATA CALIBRATION INTO PHOTONS */
242 /************************************************************************/
243
244 MParList plist4;
245 MTaskList tlist4;
246 plist4.AddToList(&tlist4);
247
248 // containers
249 MHillas hillas;
250 MNewImagePar newimagepar;
251 MSrcPosCam source;
252 MRawRunHeader runhead;
253
254 MArrivalTimeCam timecam;
255
256
257 // islands
258 MIslands isl;
259 MIslands isl2;
260 MIslands isl3;
261
262 isl.SetName("MIslands");
263 isl2.SetName("MIslands2");
264 isl3.SetName("MIslands3");
265
266 plist4.AddToList(&timecam);
267 plist4.AddToList(&isl);
268
269 if (islflag == 2)
270 plist4.AddToList(&isl2);
271 if (islflag == 3)
272 plist4.AddToList(&isl3);
273
274 plist4.AddToList(&geomcam);
275 plist4.AddToList(&pedloop.GetPedestalCam());
276 plist4.AddToList(&calloop.GetCalibrationCam());
277 plist4.AddToList(&calloop.GetQECam());
278 plist4.AddToList(&calloop.GetRelTimeCam());
279 plist4.AddToList(&calloop.GetBadPixels());
280 plist4.AddToList(&nphot);
281 plist4.AddToList(&nphotrms);
282 plist4.AddToList(&source);
283 plist4.AddToList(&hillas);
284 plist4.AddToList(&newimagepar);
285 plist4.AddToList(&runhead);
286
287 // cuts
288 MF cut(filter);
289
290 //tasks
291 MReadMarsFile read4("Events");
292 static_cast<MRead&>(read4).AddFiles(datiter);
293 read4.DisableAutoScheme();
294
295 MImgCleanStd clean(lcore,ltail);
296 clean.SetCleanRings(lrings);
297 MImgCleanStd::CleaningMethod_t cleanMeth= MImgCleanStd::kStandard;
298 if(cleanflag==2)
299 cleanMeth=MImgCleanStd::kDemocratic;
300 clean.SetMethod(cleanMeth);
301
302 MArrivalTimeCalc2 timecalc;
303 MIslandCalc island;
304 island.SetOutputName("MIslands");
305 island.SetAlgorithm(kalgorithm);
306
307 MBadPixelsTreat interpolatebadpixels;
308 interpolatebadpixels.SetUseInterpolation();
309 interpolatebadpixels.SetSloppyTreatment();
310
311 MIslandClean islclean(lnew);
312 islclean.SetInputName("MIslands");
313 islclean.SetMethod(kmethod);
314
315 MIslandCalc island2;
316 island2.SetOutputName("MIslands2");
317 island2.SetAlgorithm(kalgorithm);
318
319 MIslandCalc island3;
320 island3.SetOutputName("MIslands3");
321
322
323 MHillasCalc hcalc;
324 MHillasSrcCalc csrc1;
325
326 MContinue applycut(&cut);
327 applycut.SetInverted(kTRUE);
328 MWriteRootFile write(outname,"RECREATE");
329
330 MHillasDisplay* disphillas=NULL;
331
332 write.AddContainer("MHillas" , "Parameters");
333 write.AddContainer("MHillasSrc" , "Parameters");
334 write.AddContainer("MHillasExt" , "Parameters");
335 write.AddContainer("MNewImagePar" , "Parameters");
336 write.AddContainer("MRawEvtHeader" , "Parameters");
337 write.AddContainer("MRawRunHeader" , "Parameters");
338 write.AddContainer("MTime" , "Parameters");
339 write.AddContainer("MConcentration" , "Parameters");
340 write.AddContainer("MSrcPosCam" , "Parameters");
341 write.AddContainer("MIslands" , "Parameters");
342
343 if (islflag == 2)
344 write.AddContainer("MIslands2" , "Parameters");
345 if (islflag == 3)
346 write.AddContainer("MIslands3" , "Parameters");
347
348
349 if(display)
350 {
351 disphillas = new MHillasDisplay(&nphot,&geomcam);
352 disphillas->SetIslandsName("MIslands");
353 if (islflag == 2)
354 disphillas->SetIslandsName("MIslands2");
355 if (islflag == 3)
356 disphillas->SetIslandsName("MIslands3");
357 }
358
359 tlist4.AddToList(&read4);
360 tlist4.AddToList(&geomapl);
361 tlist4.AddToList(&extractor);
362 tlist4.AddToList(&photcalc);
363 if(calflag==11 || calflag==21)
364 tlist4.AddToList(&interpolatebadpixels);
365 tlist4.AddToList(&clean);
366 tlist4.AddToList(&timecalc);
367 tlist4.AddToList(&island);
368
369 if (islflag == 2)
370 {
371 tlist4.AddToList(&islclean);
372 tlist4.AddToList(&island2);
373 }
374
375 if (islflag == 3)
376 {
377 tlist4.AddToList(&islclean);
378 tlist4.AddToList(&island3);
379 }
380
381 tlist4.AddToList(&hcalc);
382 tlist4.AddToList(&csrc1);
383 if(filter.Length())
384 tlist4.AddToList(&applycut);
385 tlist4.AddToList(&write);
386 if(display)
387 {
388 disphillas->SetPSFile();
389 disphillas->SetPSFileName(psfilename);
390 if(display==2)
391 disphillas->SetPause(kFALSE);
392 tlist4.AddToList(disphillas);
393 }
394
395 // Create and setup the eventloop
396 MEvtLoop datloop;
397 datloop.SetParList(&plist4);
398
399 cout << "*************************************************************" << endl;
400 cout << "*** COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS) ***" << endl;
401 cout << "*************************************************************" << endl;
402
403 if (!datloop.Eventloop(nmaxevents))
404 return;
405
406 tlist4.PrintStatistics();
407
408}
409//-------------------------------------------------------------------------------
410
411Bool_t readDatacards(TString& filename)
412{
413 ifstream ifun(filename.Data());
414 if(!ifun)
415 {
416 cout << "File " << filename << " not found" << endl;
417 return kFALSE;
418 }
419
420 TString word;
421
422 while(ifun >> word)
423 {
424 // skip comments
425 if(word[0]=='/' && word[1]=='/')
426 {
427 while(ifun.get()!='\n'); // skip line
428 continue;
429 }
430
431 // number of events
432 if(strcmp(word.Data(),"NEVENTS")==0)
433 ifun >> nmaxevents;
434
435
436 // input file directory
437 if(strcmp(word.Data(),"IDIR")==0)
438 {
439 if(idirname.Length())
440 cout << "readDataCards Warning: overriding input directory file name" << endl;
441 ifun >> idirname;
442 }
443
444 // pedestal runs
445 if(strcmp(word.Data(),"PRUNS")==0)
446 {
447 if(pediter.GetNumRuns())
448 cout << "readDataCards Warning: adding pedestal runs to the existing list" << endl;
449 ifun >> word;
450 pediter.AddRuns(word.Data(),idirname.Data());
451 }
452
453 // pedestal runs for calibration
454 if(strcmp(word.Data(),"PCRUNS")==0)
455 {
456 if(pedcaliter.GetNumRuns())
457 cout << "readDataCards Warning: adding pedestal runs for calibration to the existing list" << endl;
458 ifun >> word;
459 pedcaliter.AddRuns(word.Data(),idirname.Data());
460 }
461
462 // calibration runs
463 if(strcmp(word.Data(),"CRUNS")==0)
464 {
465 if(caliter.GetNumRuns())
466 cout << "readDataCards Warning: adding calibration runs to the existing list" << endl;
467 ifun >> word;
468 caliter.AddRuns(word.Data(),idirname.Data());
469 }
470
471 // data runs
472 if(strcmp(word.Data(),"DRUNS")==0)
473 {
474 if(datiter.GetNumRuns())
475 cout << "readDataCards Warning: adding data runs to the existing list" << endl;
476 ifun >> word;
477 datiter.AddRuns(word.Data(),idirname.Data());
478 }
479
480 // output file name
481 if(strcmp(word.Data(),"OUTFILE")==0)
482 {
483 if(outname.Length())
484 cout << "readDataCards Warning: overriding output file name" << endl;
485 ifun >> outname;
486 }
487
488 // exclusion cut
489 if(strcmp(word.Data(),"FILTER")==0)
490 {
491 if(filter.Length())
492 cout << "readDataCards Warning: overriding existing cut" << endl;
493
494 char ch;
495 while((ch=ifun.get())!='\n')
496 filter.Append(ch);
497 }
498
499 // display flag
500 if(strcmp(word.Data(),"DISPLAY")==0)
501 ifun >> display;
502
503 // ps file name
504 if(strcmp(word.Data(),"PSFILENAME")==0)
505 ifun >> psfilename;
506
507 // calibration flag
508 if(strcmp(word.Data(),"CALFLAG")==0)
509 ifun >> calflag;
510
511 // calibration flag
512 if(strcmp(word.Data(),"CALTIME")==0)
513 ifun >> caltimeflag;
514
515 // cleaning level
516 if(strcmp(word.Data(),"CLEANLEVEL")==0)
517 {
518 ifun >> lcore;
519 ifun >> ltail;
520 if(ifun.get()!='\n'){
521 ifun.unget();
522 ifun >> lrings;
523 if(ifun.get()!='\n'){
524 ifun.unget();
525 ifun >> cleanflag;
526 }
527 }
528 }
529
530 if(strcmp(word.Data(),"ISLFLAG")==0)
531 {
532 ifun >> islflag;
533
534 // if (islflag == 1 || islflag == 2)
535 ifun >> kalgorithm;
536 }
537
538 // island cleaning
539 if (islflag == 2){
540 if(strcmp(word.Data(),"ISLANDCLEAN")==0)
541 {
542 ifun >> kmethod;
543 ifun >> lnew;
544 }
545 }
546 }
547
548 pediter.Reset();
549 caliter.Reset();
550 datiter.Reset();
551 TString pfile;
552
553 // Dump read values
554 cout << "************************************************" << endl;
555 cout << "* Datacards read from file " << filename << endl;
556 cout << "************************************************" << endl;
557 cout << "Pedestal file (s): " << endl;
558 while(!(pfile=pediter.Next()).IsNull())
559 cout << pfile << endl;
560 cout << "Calibration file (s): " << endl;
561 while(!(pfile=caliter.Next()).IsNull())
562 cout << pfile << endl;
563 cout << "Data file (s): " << endl;
564 while(!(pfile=datiter.Next()).IsNull())
565 cout << pfile << endl;
566 cout << "Maximum number of events: " << nmaxevents << endl;
567 if(filter.Length())
568 cout << "Applying rejection cut: " << filter << endl;
569 cout << "Output file name: " << outname << endl;
570 if(display)
571 cout << "Generating PS file: " << psfilename << endl;
572 cout << "Calibration: ";
573 if(calflag==0)
574 cout << "Pixel area proportional intercalibration" << endl;
575 else if(calflag==-1)
576 cout << "No calibration whatsoever" << endl;
577 else if(calflag==1)
578 cout << "Default calibration" << endl;
579 else if(calflag==11)
580 cout << "Default calibration + bad pixels interpolation" << endl;
581 cout << "Cleaning level: ("<<lcore<<","<<ltail<<") - " << lrings << "ring" << endl;
582 cout << "Cleaning methode: "<< cleanflag << endl;
583 if (islflag == 1 || islflag == 2)
584 cout << "Island calcultation..." << "using algorithm #" << kalgorithm <<endl;
585 if (islflag == 2)
586 {
587 cout << "Island Cleaning: "<< kmethod <<" method "<< lnew << " new threshold" << endl;
588 }
589 cout << "***********" << endl << endl;
590
591 if(!pediter.GetNumEntries())
592 {
593 cout << "No pedestal file name specified" << endl;
594 return kFALSE;
595 }
596 if(!caliter.GetNumEntries() && calflag>0)
597 {
598 cout << "No calibration file name specified" << endl;
599 return kFALSE;
600 }
601 if(!datiter.GetNumEntries())
602 {
603 cout << "No data file name specified" << endl;
604 return kFALSE;
605 }
606 if(!outname.Length())
607 {
608 cout << "No output file name specified" << endl;
609 return kFALSE;
610 }
611
612
613 return kTRUE;
614}
615
Note: See TracBrowser for help on using the repository browser.