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

Last change on this file since 4531 was 4531, checked in by rico, 20 years ago
makeHillas.cc
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
310 MIslandClean islclean(lnew);
311 islclean.SetInputName("MIslands");
312 islclean.SetMethod(kmethod);
313
314 MIslandCalc island2;
315 island2.SetOutputName("MIslands2");
316 island2.SetAlgorithm(kalgorithm);
317
318 MIslandCalc island3;
319 island3.SetOutputName("MIslands3");
320
321
322 MHillasCalc hcalc;
323 MHillasSrcCalc csrc1;
324
325 MContinue applycut(&cut);
326 applycut.SetInverted(kTRUE);
327 MWriteRootFile write(outname,"RECREATE");
328
329 MHillasDisplay* disphillas=NULL;
330
331 write.AddContainer("MHillas" , "Parameters");
332 write.AddContainer("MHillasSrc" , "Parameters");
333 write.AddContainer("MHillasExt" , "Parameters");
334 write.AddContainer("MNewImagePar" , "Parameters");
335 write.AddContainer("MRawEvtHeader" , "Parameters");
336 write.AddContainer("MRawRunHeader" , "Parameters");
337 write.AddContainer("MTime" , "Parameters");
338 write.AddContainer("MConcentration" , "Parameters");
339 write.AddContainer("MSrcPosCam" , "Parameters");
340 write.AddContainer("MIslands" , "Parameters");
341
342 if (islflag == 2)
343 write.AddContainer("MIslands2" , "Parameters");
344 if (islflag == 3)
345 write.AddContainer("MIslands3" , "Parameters");
346
347
348 if(display)
349 {
350 disphillas = new MHillasDisplay(&nphot,&geomcam);
351 disphillas->SetIslandsName("MIslands");
352 if (islflag == 2)
353 disphillas->SetIslandsName("MIslands2");
354 if (islflag == 3)
355 disphillas->SetIslandsName("MIslands3");
356 }
357
358 tlist4.AddToList(&read4);
359 tlist4.AddToList(&geomapl);
360 tlist4.AddToList(&extractor);
361 tlist4.AddToList(&photcalc);
362 if(calflag==11 || calflag==21)
363 tlist4.AddToList(&interpolatebadpixels);
364 tlist4.AddToList(&clean);
365 tlist4.AddToList(&timecalc);
366 tlist4.AddToList(&island);
367
368 if (islflag == 2)
369 {
370 tlist4.AddToList(&islclean);
371 tlist4.AddToList(&island2);
372 }
373
374 if (islflag == 3)
375 {
376 tlist4.AddToList(&islclean);
377 tlist4.AddToList(&island3);
378 }
379
380 tlist4.AddToList(&hcalc);
381 tlist4.AddToList(&csrc1);
382 if(filter.Length())
383 tlist4.AddToList(&applycut);
384 tlist4.AddToList(&write);
385 if(display)
386 {
387 disphillas->SetPSFile();
388 disphillas->SetPSFileName(psfilename);
389 if(display==2)
390 disphillas->SetPause(kFALSE);
391 tlist4.AddToList(disphillas);
392 }
393
394 // Create and setup the eventloop
395 MEvtLoop datloop;
396 datloop.SetParList(&plist4);
397
398 cout << "*************************************************************" << endl;
399 cout << "*** COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS) ***" << endl;
400 cout << "*************************************************************" << endl;
401
402 if (!datloop.Eventloop(nmaxevents))
403 return;
404
405 tlist4.PrintStatistics();
406
407}
408//-------------------------------------------------------------------------------
409
410Bool_t readDatacards(TString& filename)
411{
412 ifstream ifun(filename.Data());
413 if(!ifun)
414 {
415 cout << "File " << filename << " not found" << endl;
416 return kFALSE;
417 }
418
419 TString word;
420
421 while(ifun >> word)
422 {
423 // skip comments
424 if(word[0]=='/' && word[1]=='/')
425 {
426 while(ifun.get()!='\n'); // skip line
427 continue;
428 }
429
430 // number of events
431 if(strcmp(word.Data(),"NEVENTS")==0)
432 ifun >> nmaxevents;
433
434
435 // input file directory
436 if(strcmp(word.Data(),"IDIR")==0)
437 {
438 if(idirname.Length())
439 cout << "readDataCards Warning: overriding input directory file name" << endl;
440 ifun >> idirname;
441 }
442
443 // pedestal runs
444 if(strcmp(word.Data(),"PRUNS")==0)
445 {
446 if(pediter.GetNumRuns())
447 cout << "readDataCards Warning: adding pedestal runs to the existing list" << endl;
448 ifun >> word;
449 pediter.AddRuns(word.Data(),idirname.Data());
450 }
451
452 // pedestal runs for calibration
453 if(strcmp(word.Data(),"PCRUNS")==0)
454 {
455 if(pedcaliter.GetNumRuns())
456 cout << "readDataCards Warning: adding pedestal runs for calibration to the existing list" << endl;
457 ifun >> word;
458 pedcaliter.AddRuns(word.Data(),idirname.Data());
459 }
460
461 // calibration runs
462 if(strcmp(word.Data(),"CRUNS")==0)
463 {
464 if(caliter.GetNumRuns())
465 cout << "readDataCards Warning: adding calibration runs to the existing list" << endl;
466 ifun >> word;
467 caliter.AddRuns(word.Data(),idirname.Data());
468 }
469
470 // data runs
471 if(strcmp(word.Data(),"DRUNS")==0)
472 {
473 if(datiter.GetNumRuns())
474 cout << "readDataCards Warning: adding data runs to the existing list" << endl;
475 ifun >> word;
476 datiter.AddRuns(word.Data(),idirname.Data());
477 }
478
479 // output file name
480 if(strcmp(word.Data(),"OUTFILE")==0)
481 {
482 if(outname.Length())
483 cout << "readDataCards Warning: overriding output file name" << endl;
484 ifun >> outname;
485 }
486
487 // exclusion cut
488 if(strcmp(word.Data(),"FILTER")==0)
489 {
490 if(filter.Length())
491 cout << "readDataCards Warning: overriding existing cut" << endl;
492
493 char ch;
494 while((ch=ifun.get())!='\n')
495 filter.Append(ch);
496 }
497
498 // display flag
499 if(strcmp(word.Data(),"DISPLAY")==0)
500 ifun >> display;
501
502 // ps file name
503 if(strcmp(word.Data(),"PSFILENAME")==0)
504 ifun >> psfilename;
505
506 // calibration flag
507 if(strcmp(word.Data(),"CALFLAG")==0)
508 ifun >> calflag;
509
510 // calibration flag
511 if(strcmp(word.Data(),"CALTIME")==0)
512 ifun >> caltimeflag;
513
514 // cleaning level
515 if(strcmp(word.Data(),"CLEANLEVEL")==0)
516 {
517 ifun >> lcore;
518 ifun >> ltail;
519 if(ifun.get()!='\n'){
520 ifun.unget();
521 ifun >> lrings;
522 if(ifun.get()!='\n'){
523 ifun.unget();
524 ifun >> cleanflag;
525 }
526 }
527 }
528
529 if(strcmp(word.Data(),"ISLFLAG")==0)
530 {
531 ifun >> islflag;
532
533 // if (islflag == 1 || islflag == 2)
534 ifun >> kalgorithm;
535 }
536
537 // island cleaning
538 if (islflag == 2){
539 if(strcmp(word.Data(),"ISLANDCLEAN")==0)
540 {
541 ifun >> kmethod;
542 ifun >> lnew;
543 }
544 }
545 }
546
547 pediter.Reset();
548 caliter.Reset();
549 datiter.Reset();
550 TString pfile;
551
552 // Dump read values
553 cout << "************************************************" << endl;
554 cout << "* Datacards read from file " << filename << endl;
555 cout << "************************************************" << endl;
556 cout << "Pedestal file (s): " << endl;
557 while(!(pfile=pediter.Next()).IsNull())
558 cout << pfile << endl;
559 cout << "Calibration file (s): " << endl;
560 while(!(pfile=caliter.Next()).IsNull())
561 cout << pfile << endl;
562 cout << "Data file (s): " << endl;
563 while(!(pfile=datiter.Next()).IsNull())
564 cout << pfile << endl;
565 cout << "Maximum number of events: " << nmaxevents << endl;
566 if(filter.Length())
567 cout << "Applying rejection cut: " << filter << endl;
568 cout << "Output file name: " << outname << endl;
569 if(display)
570 cout << "Generating PS file: " << psfilename << endl;
571 cout << "Calibration: ";
572 if(calflag==0)
573 cout << "Pixel area proportional intercalibration" << endl;
574 else if(calflag==-1)
575 cout << "No calibration whatsoever" << endl;
576 else if(calflag==1)
577 cout << "Default calibration" << endl;
578 else if(calflag==11)
579 cout << "Default calibration + bad pixels interpolation" << endl;
580 cout << "Cleaning level: ("<<lcore<<","<<ltail<<") - " << lrings << "ring" << endl;
581 cout << "Cleaning methode: "<< cleanflag << endl;
582 if (islflag == 1 || islflag == 2)
583 cout << "Island calcultation..." << "using algorithm #" << kalgorithm <<endl;
584 if (islflag == 2)
585 {
586 cout << "Island Cleaning: "<< kmethod <<" method "<< lnew << " new threshold" << endl;
587 }
588 cout << "***********" << endl << endl;
589
590 if(!pediter.GetNumEntries())
591 {
592 cout << "No pedestal file name specified" << endl;
593 return kFALSE;
594 }
595 if(!caliter.GetNumEntries() && calflag>0)
596 {
597 cout << "No calibration file name specified" << endl;
598 return kFALSE;
599 }
600 if(!datiter.GetNumEntries())
601 {
602 cout << "No data file name specified" << endl;
603 return kFALSE;
604 }
605 if(!outname.Length())
606 {
607 cout << "No output file name specified" << endl;
608 return kFALSE;
609 }
610
611
612 return kTRUE;
613}
614
Note: See TracBrowser for help on using the repository browser.