| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Abelardo Moralejo 1/2004 <mailto:moralejo@pd.infn.it>
|
|---|
| 20 | ! Eva Domingo 1/2005 <mailto:domingo@ifae.es>
|
|---|
| 21 | !
|
|---|
| 22 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 23 | !
|
|---|
| 24 | !
|
|---|
| 25 | \* ======================================================================== */
|
|---|
| 26 |
|
|---|
| 27 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 28 | //
|
|---|
| 29 | // STARMC - STandard Analysis and Reconstruction (MC example)
|
|---|
| 30 | //
|
|---|
| 31 | // This macro is a version of the standard converter to convert raw data
|
|---|
| 32 | // into image parameters, made to show how to run analysis on MC files.
|
|---|
| 33 | //
|
|---|
| 34 | // (1/2005):: Spline extractor added and additional containers written out
|
|---|
| 35 | //
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 |
|
|---|
| 38 | #include "MImgCleanStd.h"
|
|---|
| 39 |
|
|---|
| 40 | void makeHillasMC()
|
|---|
| 41 | {
|
|---|
| 42 | //
|
|---|
| 43 | // This is a demonstration program which calculates the image
|
|---|
| 44 | // parameters from Magic Monte Carlo files (output of camera).
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | TString* CalibrationFilename;
|
|---|
| 48 | TString* AnalysisFilename;
|
|---|
| 49 | TString* OutFilename1;
|
|---|
| 50 | TString* OutFilename2;
|
|---|
| 51 |
|
|---|
| 52 | // ------------- USER CHANGE -----------------
|
|---|
| 53 | // Comment line starting "CalibrationFileName" to disable calibration.
|
|---|
| 54 | // In that case the units of the MHillas.fSize parameter will be ADC counts
|
|---|
| 55 | // (rather, equivalent ADC counts in inner pixels, since we correct for the
|
|---|
| 56 | // possible differences in gain of outer pixels)
|
|---|
| 57 |
|
|---|
| 58 | // File to be used in the calibration (must be a camera file without added noise)
|
|---|
| 59 | CalibrationFilename = new TString("/discpepe/root_0.73mirror/wuerzburg/gammas_nonoise/Gamma_zbin0_0_7_1000to1009_w0.root");
|
|---|
| 60 | // File to be analyzed
|
|---|
| 61 | AnalysisFilename = new TString("/discpepe/root_0.73mirror/wuerzburg/gammas/Gamma_zbin*.root");
|
|---|
| 62 |
|
|---|
| 63 | // Change output file names as desired.
|
|---|
| 64 | // If you want only one output (not dividing the events in Train and Test samples),
|
|---|
| 65 | // comment the initialization of OutFilename2.
|
|---|
| 66 | OutFilename1 = new TString("/mnt/users/domingo/MAGIC/Disp05/All_gammas_0.73mirror_zbin0to12_cleaned_4035_Spline.root");
|
|---|
| 67 | // OutFilename1 = new TString("star_train.root"); // Output file name 1 (test)
|
|---|
| 68 | // OutFilename2 = new TString("star_test.root"); // Output file name 2 (train)
|
|---|
| 69 |
|
|---|
| 70 | // Fraction of events (taken at random) which one wants to process from the
|
|---|
| 71 | // file to be analyzed (useful to make smaller files if starting sample is too large).
|
|---|
| 72 | Float_t accepted_fraction = 1.;
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | // ------------- USER CHANGE -----------------
|
|---|
| 76 | // Cleaning levels
|
|---|
| 77 | Float_t CleanLev[2] = {4.0, 3.5}; // Tail cuts for image analysis
|
|---|
| 78 |
|
|---|
| 79 | // Signal extractor
|
|---|
| 80 | // (default=Spline, other extraction methods can be used)
|
|---|
| 81 | const Int_t wsize=2;
|
|---|
| 82 | MExtractor* sigextract = new MExtractTimeAndChargeSpline();
|
|---|
| 83 | ((MExtractTimeAndChargeSpline*)sigextract)->SetTimeType(MExtractTimeAndChargeSpline::kHalfMaximum);
|
|---|
| 84 | ((MExtractTimeAndChargeSpline*)sigextract)->SetChargeType(MExtractTimeAndChargeSpline::kIntegral);
|
|---|
| 85 | ((MExtractTimeAndChargeSpline*)sigextract)->SetRiseTime((Float_t)wsize*0.25);
|
|---|
| 86 | ((MExtractTimeAndChargeSpline*)sigextract)->SetFallTime((Float_t)wsize*0.75);
|
|---|
| 87 | // Define FADC slices to be integrated in high and low gain:
|
|---|
| 88 | sigextract->SetRange(1, 11, 2, 12);
|
|---|
| 89 | // Defines when to switch to low gain
|
|---|
| 90 | sigextract->SetSaturationLimit(240);
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | // -------------------------------------------
|
|---|
| 94 | //
|
|---|
| 95 | // Create a empty Parameter List and an empty Task List
|
|---|
| 96 | // The tasklist is identified in the eventloop by its name
|
|---|
| 97 | //
|
|---|
| 98 | MParList plist;
|
|---|
| 99 | MTaskList tlist;
|
|---|
| 100 | plist.AddToList(&tlist);
|
|---|
| 101 |
|
|---|
| 102 | // MGeomCamMagic geomcam;
|
|---|
| 103 |
|
|---|
| 104 | // MSrcPosCam src;
|
|---|
| 105 | // WOBBLE MODE!!
|
|---|
| 106 | // src.SetX(120.); // units: mm
|
|---|
| 107 | // src.SetXY(0.,0.4/geomcam.GetConvMm2Deg());
|
|---|
| 108 | // src.SetXY(0.,0.);
|
|---|
| 109 | // src.SetReadyToSave();
|
|---|
| 110 |
|
|---|
| 111 | MBadPixelsCam badpix;
|
|---|
| 112 |
|
|---|
| 113 | // plist.AddToList(&geomcam);
|
|---|
| 114 | // plist.AddToList(&src);
|
|---|
| 115 | plist.AddToList(&badpix);
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | // Now setup the tasks and tasklist:
|
|---|
| 119 | // ---------------------------------
|
|---|
| 120 | //
|
|---|
| 121 | MReadMarsFile read("Events");
|
|---|
| 122 | if (CalibrationFilename)
|
|---|
| 123 | read.AddFile(CalibrationFilename->Data());
|
|---|
| 124 | read.DisableAutoScheme();
|
|---|
| 125 |
|
|---|
| 126 | MGeomApply geom;
|
|---|
| 127 | // Reads in geometry from MC file and sets the right sizes for
|
|---|
| 128 | // several parameter containers.
|
|---|
| 129 |
|
|---|
| 130 | MMcPedestalCopy pcopy;
|
|---|
| 131 | // Copies pedestal data from the MC file run fadc header to the MPedestalCam container.
|
|---|
| 132 |
|
|---|
| 133 | MPointingPosCalc pointcalc;
|
|---|
| 134 | // Creates MPointingPos object and fill it with the telescope orientation
|
|---|
| 135 | // information taken from MMcEvt.
|
|---|
| 136 |
|
|---|
| 137 | MMcCalibrationUpdate mccalibupdate;
|
|---|
| 138 |
|
|---|
| 139 | MCalibrateData calib;
|
|---|
| 140 | // Transforms signals from ADC counts into photons. In the first
|
|---|
| 141 | // loop it applies a "dummy" calibration supplied by MMcCalibrationUpdate, just
|
|---|
| 142 | // to equalize inner and outer pixels. At the end of the first loop, in the
|
|---|
| 143 | // PostProcess of MMcCalibrationCalc (see below) the true calibration constants
|
|---|
| 144 | // are calculated.
|
|---|
| 145 | calib.SetCalibrationMode(MCalibrateData::kFfactor);
|
|---|
| 146 |
|
|---|
| 147 | // MBlindPixelCalc blind;
|
|---|
| 148 | // blind.SetUseInterpolation();
|
|---|
| 149 |
|
|---|
| 150 | MMcCalibrationCalc mccalibcalc;
|
|---|
| 151 | // Calculates calibration constants to convert from ADC counts to photons.
|
|---|
| 152 |
|
|---|
| 153 | MImgCleanStd clean(CleanLev[0], CleanLev[1]);
|
|---|
| 154 | // Applies tail cuts to image. Since the calibration is performed on
|
|---|
| 155 | // noiseless camera files, the precise values of the cleaning levels
|
|---|
| 156 | // are unimportant for the calibration file processing (in any case,
|
|---|
| 157 | // only pixels without any C-photon will be rejected).
|
|---|
| 158 | clean.SetCleanRings(1);
|
|---|
| 159 | // clean.SetRemoveSingle(kFALSE);
|
|---|
| 160 | // clean.SetMethod(MImgCleanStd::kDemocratic);
|
|---|
| 161 |
|
|---|
| 162 | MHillasCalc hcalc;
|
|---|
| 163 | // Calculates Hillas parameters.
|
|---|
| 164 |
|
|---|
| 165 | tlist.AddToList(&read);
|
|---|
| 166 | tlist.AddToList(&geom);
|
|---|
| 167 | tlist.AddToList(&pcopy);
|
|---|
| 168 | tlist.AddToList(&pointcalc);
|
|---|
| 169 | tlist.AddToList(sigextract);
|
|---|
| 170 | tlist.AddToList(&mccalibupdate);
|
|---|
| 171 | tlist.AddToList(&calib);
|
|---|
| 172 | tlist.AddToList(&clean);
|
|---|
| 173 | // tlist.AddToList(&blind);
|
|---|
| 174 | tlist.AddToList(&hcalc);
|
|---|
| 175 | tlist.AddToList(&mccalibcalc);
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 | //
|
|---|
| 179 | // Open output files:
|
|---|
| 180 | //
|
|---|
| 181 |
|
|---|
| 182 | MWriteRootFile write1(OutFilename1->Data()); // Writes output1
|
|---|
| 183 | write1.AddContainer("MRawRunHeader", "RunHeaders");
|
|---|
| 184 | write1.AddContainer("MMcRunHeader", "RunHeaders");
|
|---|
| 185 | write1.AddContainer("MSrcPosCam", "RunHeaders");
|
|---|
| 186 | write1.AddContainer("MGeomCam", "RunHeaders");
|
|---|
| 187 | write1.AddContainer("MMcConfigRunHeader", "RunHeaders");
|
|---|
| 188 | write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
|
|---|
| 189 | write1.AddContainer("MMcFadcHeader", "RunHeaders");
|
|---|
| 190 | write1.AddContainer("MMcTrigHeader", "RunHeaders");
|
|---|
| 191 |
|
|---|
| 192 | write1.AddContainer("MRawEvtHeader", "Events");
|
|---|
| 193 | write1.AddContainer("MMcEvt", "Events");
|
|---|
| 194 | write1.AddContainer("MHillas", "Events");
|
|---|
| 195 | write1.AddContainer("MHillasExt", "Events");
|
|---|
| 196 | write1.AddContainer("MHillasSrc", "Events");
|
|---|
| 197 | write1.AddContainer("MImagePar", "Events");
|
|---|
| 198 | write1.AddContainer("MNewImagePar", "Events");
|
|---|
| 199 | write1.AddContainer("MConcentration", "Events");
|
|---|
| 200 | write1.AddContainer("MIslands", "Events");
|
|---|
| 201 | write1.AddContainer("MTopology", "Events");
|
|---|
| 202 | write1.AddContainer("MPointingPos", "Events");
|
|---|
| 203 | //write1.AddContainer("MArrivalTimeCam", "Events");
|
|---|
| 204 | //write1.AddContainer("MCerPhotEvt", "Events");
|
|---|
| 205 |
|
|---|
| 206 | if (OutFilename2)
|
|---|
| 207 | {
|
|---|
| 208 | MWriteRootFile write2(OutFilename2->Data()); // Writes output2
|
|---|
| 209 | write2.AddContainer("MRawRunHeader", "RunHeaders");
|
|---|
| 210 | write2.AddContainer("MMcRunHeader", "RunHeaders");
|
|---|
| 211 | write2.AddContainer("MSrcPosCam", "RunHeaders");
|
|---|
| 212 | write2.AddContainer("MGeomCam", "RunHeaders");
|
|---|
| 213 | write2.AddContainer("MMcConfigRunHeader", "RunHeaders");
|
|---|
| 214 | write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
|
|---|
| 215 | write2.AddContainer("MMcFadcHeader", "RunHeaders");
|
|---|
| 216 | write2.AddContainer("MMcTrigHeader", "RunHeaders");
|
|---|
| 217 |
|
|---|
| 218 | write2.AddContainer("MRawEvtHeader", "Events");
|
|---|
| 219 | write2.AddContainer("MMcEvt", "Events");
|
|---|
| 220 | write2.AddContainer("MHillas", "Events");
|
|---|
| 221 | write2.AddContainer("MHillasExt", "Events");
|
|---|
| 222 | write2.AddContainer("MHillasSrc", "Events");
|
|---|
| 223 | write2.AddContainer("MImagePar", "Events");
|
|---|
| 224 | write2.AddContainer("MNewImagePar", "Events");
|
|---|
| 225 | write2.AddContainer("MConcentration", "Events");
|
|---|
| 226 | write2.AddContainer("MIslands", "Events");
|
|---|
| 227 | write2.AddContainer("MTopology", "Events");
|
|---|
| 228 | write2.AddContainer("MPointingPos", "Events");
|
|---|
| 229 | //write2.AddContainer("MArrivalTimeCam", "Events");
|
|---|
| 230 | //write2.AddContainer("MCerPhotEvt", "Events");
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 | // Divide output in train and test samples, using the event number
|
|---|
| 234 | // (odd/even) to achieve otherwise unbiased event samples:
|
|---|
| 235 | MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
|
|---|
| 236 | MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
|
|---|
| 237 |
|
|---|
| 238 | write1.SetFilter(&filter1);
|
|---|
| 239 | write2.SetFilter(&filter2);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 | //
|
|---|
| 244 | // FIRST LOOP: Calibration loop (with no noise file)
|
|---|
| 245 | //
|
|---|
| 246 | MProgressBar bar;
|
|---|
| 247 | bar.SetWindowName("Calibrating...");
|
|---|
| 248 |
|
|---|
| 249 | MEvtLoop evtloop;
|
|---|
| 250 | evtloop.SetProgressBar(&bar);
|
|---|
| 251 | evtloop.SetParList(&plist);
|
|---|
| 252 |
|
|---|
| 253 | if (CalibrationFilename)
|
|---|
| 254 | {
|
|---|
| 255 | if (!evtloop.Eventloop())
|
|---|
| 256 | return;
|
|---|
| 257 | mccalibcalc.GetHistADC2PhotEl()->Write();
|
|---|
| 258 | mccalibcalc.GetHistPhot2PhotEl()->Write();
|
|---|
| 259 | // Writes out the histograms used for calibration.
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 | //
|
|---|
| 264 | // SECOND LOOP: Analysis loop (process file with noise)
|
|---|
| 265 | //
|
|---|
| 266 | bar.SetWindowName("Analyzing...");
|
|---|
| 267 |
|
|---|
| 268 | MIslands isl;
|
|---|
| 269 | MArrivalTimeCam timecam;
|
|---|
| 270 | MTopology topology;
|
|---|
| 271 | plist.AddToList(&isl);
|
|---|
| 272 | plist.AddToList(&timecam);
|
|---|
| 273 | plist.AddToList(&topology);
|
|---|
| 274 |
|
|---|
| 275 | MArrivalTimeCalc2 timecalc;
|
|---|
| 276 | // Calculates the arrival time as the mean time of the fWindowSize
|
|---|
| 277 | // time slices which have the highest integral content.
|
|---|
| 278 | // MArrivalTimeCalc timecalc;
|
|---|
| 279 | // Calculates the arrival times of photons. Returns the absolute
|
|---|
| 280 | // maximum of the spline that interpolates the FADC slices.
|
|---|
| 281 |
|
|---|
| 282 | MIslandsCalc islcalc;
|
|---|
| 283 | islcalc.SetOutputName("MIslands");
|
|---|
| 284 | islcalc.SetAlgorithm(1);
|
|---|
| 285 | // MIslandsClean islclean(40);
|
|---|
| 286 | // islclean.SetInputName("MIslands");
|
|---|
| 287 | // islclean.SetMethod(1);
|
|---|
| 288 |
|
|---|
| 289 | MTopologyCalc topcalc;
|
|---|
| 290 |
|
|---|
| 291 | // Change the read task by another one which reads the file we want to analyze:
|
|---|
| 292 | MReadMarsFile read2("Events");
|
|---|
| 293 | read2.AddFile(AnalysisFilename->Data());
|
|---|
| 294 | read2.DisableAutoScheme();
|
|---|
| 295 | tlist.AddToListBefore(&read2, &read);
|
|---|
| 296 | tlist.RemoveFromList(&read);
|
|---|
| 297 |
|
|---|
| 298 | // Add new tasks (Islands and Topology calculations)
|
|---|
| 299 | tlist.AddToListBefore(&timecalc,&mccalibupdate);
|
|---|
| 300 | tlist.AddToListBefore(&islcalc,&hcalc);
|
|---|
| 301 | // tlist.AddToListBefore(&islclean,&hcalc);
|
|---|
| 302 | tlist.AddToListBefore(&topcalc,&hcalc);
|
|---|
| 303 |
|
|---|
| 304 | // Analyze only the desired fraction of events, skip the rest:
|
|---|
| 305 | MFEventSelector eventselector;
|
|---|
| 306 | Float_t rejected_fraction = 1. - accepted_fraction;
|
|---|
| 307 | eventselector.SetSelectionRatio(rejected_fraction);
|
|---|
| 308 | MContinue skip(&eventselector);
|
|---|
| 309 | tlist.AddToListBefore(&skip, sigextract);
|
|---|
| 310 |
|
|---|
| 311 | // Remove calibration task from list.
|
|---|
| 312 | tlist.RemoveFromList(&mccalibcalc);
|
|---|
| 313 |
|
|---|
| 314 | // Add tasks to write output:
|
|---|
| 315 | if (OutFilename2)
|
|---|
| 316 | {
|
|---|
| 317 | tlist.AddToList(&filter1);
|
|---|
| 318 | tlist.AddToList(&filter2);
|
|---|
| 319 | tlist.AddToList(&write2);
|
|---|
| 320 | }
|
|---|
| 321 | tlist.AddToList(&write1);
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 | if (!evtloop.Eventloop())
|
|---|
| 325 | return;
|
|---|
| 326 |
|
|---|
| 327 | tlist.PrintStatistics();
|
|---|
| 328 | }
|
|---|