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

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