| 1 | #include "MLogManip.h"
|
|---|
| 2 |
|
|---|
| 3 | /*****************************************************************
|
|---|
| 4 |
|
|---|
| 5 | CALLISTO -- CALibrate LIght Signals and Time Offsets
|
|---|
| 6 |
|
|---|
| 7 | datafile:
|
|---|
| 8 | A data file written by the fadctrl, e.g.
|
|---|
| 9 | 20170727_006.fits.fz or
|
|---|
| 10 | 00000015.003_D_MonteCarlo019_Events.fits.fz
|
|---|
| 11 |
|
|---|
| 12 | drsfile:
|
|---|
| 13 | Usually the third of the three .drs.fits files from a
|
|---|
| 14 | DRS calibration sequence, e.g. 20170727_004.drs.fits
|
|---|
| 15 |
|
|---|
| 16 | drstime:
|
|---|
| 17 | An input file with the constants for the DRS timing calibration
|
|---|
| 18 | [Not used right now, keep it 0]
|
|---|
| 19 |
|
|---|
| 20 | delays:
|
|---|
| 21 | A file with the delays of the individual channels
|
|---|
| 22 | [Not available right now, keep it 0]
|
|---|
| 23 |
|
|---|
| 24 | outpath:
|
|---|
| 25 | The path to which the output files are written
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | To run the macro from the command line (assuming you are in a directory
|
|---|
| 29 | Mars/build where you have built your Mars environment) you can do
|
|---|
| 30 |
|
|---|
| 31 | root ../hawc/callisto.C\(\"20191002_018.fits.fz\",\"20191002_013.drs.fits\"\)
|
|---|
| 32 |
|
|---|
| 33 | or from within root
|
|---|
| 34 |
|
|---|
| 35 | [0] .x ../hawc/callisto.C("20191002_018.fits.fz", "20191002_013.drs.fits")
|
|---|
| 36 |
|
|---|
| 37 | ******************************************************************/
|
|---|
| 38 | int callisto(const char *datafile, const char *drsfile,
|
|---|
| 39 | const char *outpath=".")
|
|---|
| 40 | {
|
|---|
| 41 | // ======================================================
|
|---|
| 42 |
|
|---|
| 43 | const char *drstime = 0;
|
|---|
| 44 | const char *delays = 0;
|
|---|
| 45 |
|
|---|
| 46 | // ======================================================
|
|---|
| 47 |
|
|---|
| 48 | // true: Display correctly mapped pixels in the camera displays
|
|---|
| 49 | // but the value-vs-index plot is in software/spiral indices
|
|---|
| 50 | // false: Display pixels in hardware/linear indices,
|
|---|
| 51 | // but the order is the camera display is distorted.
|
|---|
| 52 | // false is assumed automatically for files with the ISMC flag set.
|
|---|
| 53 | bool usemap = true;
|
|---|
| 54 |
|
|---|
| 55 | // mapping file (found in Mars/hawc)
|
|---|
| 56 | const char *mmap = usemap ? "/home/hawc/FACT++-src/famous/resources/hawcseye/HAWCsEyemap181214.txt": NULL;
|
|---|
| 57 |
|
|---|
| 58 | //const char *pulse_template = "template-pulse.root";
|
|---|
| 59 |
|
|---|
| 60 | // Define a list of defect pixels here (software index)
|
|---|
| 61 | // They get interpolated from their neighbors
|
|---|
| 62 | // (if there are at least three valid neighbors)
|
|---|
| 63 | // The bahaviour can be altered in the corresponding task
|
|---|
| 64 | // (MBadPixelsTreat)
|
|---|
| 65 | MBadPixelsCam badpixels;
|
|---|
| 66 | badpixels.InitSize(64);
|
|---|
| 67 | badpixels[61].SetUnsuitable(MBadPixelsPix::kUnsuitable);
|
|---|
| 68 | badpixels[62].SetUnsuitable(MBadPixelsPix::kUnsuitable);
|
|---|
| 69 | badpixels[63].SetUnsuitable(MBadPixelsPix::kUnsuitable);
|
|---|
| 70 |
|
|---|
| 71 | // Range in which the pulse extraction searches for the
|
|---|
| 72 | // pulse (in samples).
|
|---|
| 73 | const int first_slice = 250;
|
|---|
| 74 | const int last_slice = 330;
|
|---|
| 75 |
|
|---|
| 76 | // Calibration constant (for the moment a single constant to
|
|---|
| 77 | // convert the extracted charge to photo-electrons)
|
|---|
| 78 | //double scale = 1./22.553;//0.2;
|
|---|
| 79 | double scale = 1./17.557;
|
|---|
| 80 |
|
|---|
| 81 | // ------------------------------------------------------
|
|---|
| 82 |
|
|---|
| 83 | Long_t max = 0; // All
|
|---|
| 84 |
|
|---|
| 85 | // ======================================================
|
|---|
| 86 |
|
|---|
| 87 | // Check if the requested mapping file is available
|
|---|
| 88 | if (mmap && gSystem->AccessPathName(mmap, kFileExists))
|
|---|
| 89 | {
|
|---|
| 90 | gLog << err << "ERROR - Cannot access mapping file '" << mmap << "'" << endl;
|
|---|
| 91 | return 11;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | // -------------------------------------------------------
|
|---|
| 95 |
|
|---|
| 96 | // Check if the requested DRS time calibration constants are available
|
|---|
| 97 | MDrsCalibrationTime timecam;
|
|---|
| 98 | if (drstime && !timecam.ReadFits(drstime))
|
|---|
| 99 | {
|
|---|
| 100 | gLog << err << "ERROR - Could not get MDrsCalibrationTime from " << drstime << endl;
|
|---|
| 101 | return 21;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | if (delays)
|
|---|
| 105 | {
|
|---|
| 106 | TGraph g(delays);
|
|---|
| 107 | if (g.GetN()!=1440)
|
|---|
| 108 | {
|
|---|
| 109 | gLog << err << "Error reading file " << delays << endl;
|
|---|
| 110 | return 22;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | timecam.SetDelays(g);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // ------------------------------------------------------
|
|---|
| 117 |
|
|---|
| 118 | // Check and read the channel delays
|
|---|
| 119 | if (drstime && delays)
|
|---|
| 120 | {
|
|---|
| 121 | TGraph g(delays);
|
|---|
| 122 | if (g.GetN()!=1440)
|
|---|
| 123 | {
|
|---|
| 124 | gLog << err << "Error reading file " << delays << endl;
|
|---|
| 125 | return 41;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | timecam.SetDelays(g);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | // -------------------------------------------------------
|
|---|
| 132 |
|
|---|
| 133 | // Check and read the DRS calibration constants
|
|---|
| 134 | MDrsCalibration drscalib300;
|
|---|
| 135 | if (drsfile && !drscalib300.ReadFits(drsfile))
|
|---|
| 136 | return 31;
|
|---|
| 137 |
|
|---|
| 138 | // ======================================================
|
|---|
| 139 |
|
|---|
| 140 | gLog.Separator("Callisto");
|
|---|
| 141 | gLog << all;
|
|---|
| 142 | gLog << "Data file: " << datafile << '\n';
|
|---|
| 143 | if (drsfile)
|
|---|
| 144 | gLog << "DRS Calib: " << drsfile << '\n';
|
|---|
| 145 | if (drstime)
|
|---|
| 146 | gLog << "DRS Time: " << drstime << '\n';
|
|---|
| 147 | if (delays)
|
|---|
| 148 | gLog << "Delays: " << delays << '\n';
|
|---|
| 149 | gLog << "Outpath: " << outpath << '\n';
|
|---|
| 150 | gLog << endl;
|
|---|
| 151 |
|
|---|
| 152 | // ------------------------------------------------------
|
|---|
| 153 |
|
|---|
| 154 | gStyle->SetOptFit(kTRUE);
|
|---|
| 155 |
|
|---|
| 156 | // ===================================================================
|
|---|
| 157 |
|
|---|
| 158 | gLog << endl;
|
|---|
| 159 | gLog.Separator("Calibrating data");
|
|---|
| 160 |
|
|---|
| 161 | // Instantiate the list of tasks
|
|---|
| 162 | MTaskList tlist5;
|
|---|
| 163 |
|
|---|
| 164 | // Instantiate the list of data containers
|
|---|
| 165 | MParList plist5;
|
|---|
| 166 | plist5.AddToList(&tlist5);
|
|---|
| 167 | plist5.AddToList(&badpixels);
|
|---|
| 168 | if (drsfile)
|
|---|
| 169 | plist5.AddToList(&drscalib300);
|
|---|
| 170 | if (drstime)
|
|---|
| 171 | plist5.AddToList(&timecam);
|
|---|
| 172 |
|
|---|
| 173 | // Instantiate the camera geometry
|
|---|
| 174 | MGeomCamFAMOUS geom;
|
|---|
| 175 | plist5.AddToList(&geom);
|
|---|
| 176 |
|
|---|
| 177 | // Instantiate the status display
|
|---|
| 178 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 179 |
|
|---|
| 180 | // Instantiate the event loop
|
|---|
| 181 | MEvtLoop loop5("CalibratingData");
|
|---|
| 182 | loop5.SetDisplay(d);
|
|---|
| 183 | loop5.SetParList(&plist5);
|
|---|
| 184 |
|
|---|
| 185 | // ------------------ Setup the tasks ---------------
|
|---|
| 186 |
|
|---|
| 187 | MDirIter files(datafile);
|
|---|
| 188 |
|
|---|
| 189 | // Instantiate the reading task
|
|---|
| 190 | // You can use
|
|---|
| 191 | // read5.AddFiles("*.fits.fz")
|
|---|
| 192 | // for example to read more than one file at once
|
|---|
| 193 | MRawFitsRead read5;
|
|---|
| 194 | read5.AddFiles(files);
|
|---|
| 195 | if (mmap)
|
|---|
| 196 | read5.LoadMap(mmap);
|
|---|
| 197 |
|
|---|
| 198 | // Instantiate the histogram to be filled with the rates
|
|---|
| 199 | MH3 hrate("MRawRunHeader.GetFileID", "int(MRawEvtHeader.GetTriggerID)&0xff00");
|
|---|
| 200 | hrate.SetWeight("1./TMath::Max(MRawRunHeader.GetRunLength,1.)");
|
|---|
| 201 | hrate.SetName("Rate");
|
|---|
| 202 | hrate.SetTitle("Event rate [Hz];File Id;Trigger Type;");
|
|---|
| 203 | hrate.InitLabels(MH3::kLabelsXY);
|
|---|
| 204 | hrate.DefineLabelY( 0, "Data"); // What if TriggerID==0 already???
|
|---|
| 205 | hrate.DefineLabelY(0x100, "Cal");
|
|---|
| 206 | hrate.DefineLabelY(0x400, "Ped");
|
|---|
| 207 | // hrate.DefaultLabelY("ERROR");
|
|---|
| 208 |
|
|---|
| 209 | // Instantiate the task to fill therate histogram
|
|---|
| 210 | MFillH fill5a(&hrate);
|
|---|
| 211 |
|
|---|
| 212 | // Instantiate the task to ensure proper sizing of all containers
|
|---|
| 213 | MGeomApply apply5;
|
|---|
| 214 |
|
|---|
| 215 | // Instantiate the task to apply the drs calibration constants
|
|---|
| 216 | MDrsCalibApply drsapply5;
|
|---|
| 217 | drsapply5.SetMaxNumPrevEvents(0); // Switched off step-correction -> crashes due to the requirement of N*9 ch
|
|---|
| 218 |
|
|---|
| 219 | // Instantiate the filter to select only physics events
|
|---|
| 220 | MFDataPhrase filterdat("(int(MRawEvtHeader.GetTriggerID)&0xff00)==0", "SelectDat");
|
|---|
| 221 |
|
|---|
| 222 | // ---
|
|---|
| 223 | /*
|
|---|
| 224 | MExtractTimeAndChargeSpline extractor5dat;
|
|---|
| 225 | extractor5dat.SetRange(first_slice, last_slice);
|
|---|
| 226 | extractor5dat.SetRiseTimeHiGain(rise_time_dat);
|
|---|
| 227 | extractor5dat.SetFallTimeHiGain(fall_time_dat);
|
|---|
| 228 | extractor5dat.SetHeightTm(heighttm);
|
|---|
| 229 | extractor5dat.SetChargeType(type);
|
|---|
| 230 | extractor5dat.SetSaturationLimit(600000);
|
|---|
| 231 | extractor5dat.SetNoiseCalculation(kFALSE);
|
|---|
| 232 | */
|
|---|
| 233 |
|
|---|
| 234 | // Instantiate the digital filter (weighted sliding average) to clean the data
|
|---|
| 235 | // Note that the weights are not adapted yet to HAWC's Eye
|
|---|
| 236 | // A better filter might be worth to think about
|
|---|
| 237 | MFilterData filterdata1;
|
|---|
| 238 |
|
|---|
| 239 | // Instatiate task to extract the maximum of the pulse (correspondins to
|
|---|
| 240 | // a weighted integral) and the position of the leading edge between
|
|---|
| 241 | // first_slice and last_slice as charge and arrival time
|
|---|
| 242 | MExtractFACT extractor5dat("ExtractPulse");
|
|---|
| 243 | extractor5dat.SetRange(first_slice, last_slice);
|
|---|
| 244 | extractor5dat.SetNoiseCalculation(kFALSE);
|
|---|
| 245 |
|
|---|
| 246 | // Instantiate task which applies the calibration constants
|
|---|
| 247 | MCalibrateFact conv5;
|
|---|
| 248 | conv5.SetScale(scale);
|
|---|
| 249 | //conv5.SetCalibConst(calib);
|
|---|
| 250 |
|
|---|
| 251 | // Instantiate task which applies the DRS time calibration
|
|---|
| 252 | MCalibrateDrsTimes calctm5;
|
|---|
| 253 | calctm5.SetNameUncalibrated("UncalibratedTimes");
|
|---|
| 254 |
|
|---|
| 255 | // Instantiate task to interpolate bad pixels
|
|---|
| 256 | MBadPixelsTreat treat5;
|
|---|
| 257 | treat5.SetProcessPedestalRun(kFALSE);
|
|---|
| 258 | treat5.SetProcessPedestalEvt(kFALSE);
|
|---|
| 259 |
|
|---|
| 260 | // Instantiate histograms to display charges
|
|---|
| 261 | MHCamEvent evt5b(0, "ExtSig", "Extracted signal;;S [mV#cdot sl]");
|
|---|
| 262 | MHCamEvent evt5c(0, "CalSig", "Calibrated and interpolated signal;;S [~phe]");
|
|---|
| 263 | MHCamEvent evt5d(4, "ExtSigTm", "Extracted time;;T [sl]");
|
|---|
| 264 | MHCamEvent evt5e(6, "CalSigTm", "Calibrated and interpolated time;;T [ns]");
|
|---|
| 265 |
|
|---|
| 266 | // Instantiate task to fill those histograms
|
|---|
| 267 | MFillH fill5b(&evt5b, "MExtractedSignalCam", "FillExtSig");
|
|---|
| 268 | MFillH fill5c(&evt5c, "MSignalCam", "FillCalSig");
|
|---|
| 269 | MFillH fill5d(&evt5d, "MArrivalTimeCam", "FillExtTm");
|
|---|
| 270 | MFillH fill5e(&evt5e, "MSignalCam", "FillCalTm");
|
|---|
| 271 |
|
|---|
| 272 | // Setup those histograms to fit a gaussian to the distribution
|
|---|
| 273 | fill5c.SetDrawOption("gaus");
|
|---|
| 274 | fill5d.SetDrawOption("gaus");
|
|---|
| 275 | fill5e.SetDrawOption("gaus");
|
|---|
| 276 |
|
|---|
| 277 | // Instantiate the task to apply the software trigger
|
|---|
| 278 | MSoftwareTriggerCalc swtrig;
|
|---|
| 279 |
|
|---|
| 280 | // This is an alternative if more than one file should be read in a single loop
|
|---|
| 281 | // In this case the output file name of each file is created with this rule
|
|---|
| 282 | // from the input file name. Note that the filename of the output file
|
|---|
| 283 | // with the status display must then be explicitly given.
|
|---|
| 284 | //
|
|---|
| 285 | //const TString fname(Form("s/([0-9]+_[0-9]+)[.]fits([.][fg]z)?$/%s\\/$1_C.root/",
|
|---|
| 286 | // MJob::Esc(outpath).Data()));
|
|---|
| 287 | //MWriteRootFile write5(2, fname, "RECREATE", "Calibrated Data");
|
|---|
| 288 |
|
|---|
| 289 | /*
|
|---|
| 290 | // Convert the name of the input file to the name of the output file
|
|---|
| 291 | TString fname = gSystem->ConcatFileName(outpath, gSystem->BaseName(datafile));
|
|---|
| 292 | fname.ReplaceAll(".fits.gz", ".root");
|
|---|
| 293 | fname.ReplaceAll(".fits.fz", ".root");
|
|---|
| 294 | fname.ReplaceAll(".fits", ".root");
|
|---|
| 295 | fname.ReplaceAll("_D_", "_C_");
|
|---|
| 296 |
|
|---|
| 297 | gSystem->ExpandPathName(fname);
|
|---|
| 298 | */
|
|---|
| 299 |
|
|---|
| 300 | const TString rule(Form("s/([0-9]+)([._])([0-9]+)(_[DPC])?([_].*)?([.]fits([.]fz)?)$/%s\\/$1$2$3_Y$5.root/",
|
|---|
| 301 | MJob:: Esc(outpath).Data()));
|
|---|
| 302 |
|
|---|
| 303 | // Instantitate the writing task and setup the writing
|
|---|
| 304 | MWriteRootFile write5(2, rule, "RECREATE", "Calibrated Data");
|
|---|
| 305 | write5.AddContainer("MSignalCam", "Events");
|
|---|
| 306 | write5.AddContainer("MRawEvtHeader", "Events");
|
|---|
| 307 | write5.AddContainer("MSoftwareTrigger","Events");
|
|---|
| 308 | write5.AddContainer("MRawRunHeader", "RunHeaders");
|
|---|
| 309 | write5.AddContainer("MGeomCam", "RunHeaders");
|
|---|
| 310 |
|
|---|
| 311 | write5.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
|
|---|
| 312 | write5.AddContainer("MCorsikaRunHeader", "RunHeaders", kFALSE);
|
|---|
| 313 | write5.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
|
|---|
| 314 | write5.AddContainer("MCorsikaEvtHeader", "Events", kFALSE);
|
|---|
| 315 | write5.AddContainer("MMcEvt", "Events", kFALSE);
|
|---|
| 316 | write5.AddContainer("IncidentAngle", "Events", kFALSE);
|
|---|
| 317 | write5.AddContainer("MPointingPos", "Events", kFALSE);
|
|---|
| 318 | write5.AddContainer("MSimSourcePos", "Events", kFALSE);
|
|---|
| 319 | write5.AddContainer("MTime", "Events", kFALSE);
|
|---|
| 320 | write5.AddContainer("MRawBoardsFACT", "Events", kFALSE);
|
|---|
| 321 | write5.AddContainer("MSrcPosCam", "Events", kFALSE);
|
|---|
| 322 |
|
|---|
| 323 | // ------------------ Setup histograms and fill tasks ----------------
|
|---|
| 324 |
|
|---|
| 325 | // Instantitate the task list and setp the list
|
|---|
| 326 | MTaskList tlist5dat;
|
|---|
| 327 | tlist5dat.AddToList(&fill5b);
|
|---|
| 328 | tlist5dat.AddToList(&fill5c);
|
|---|
| 329 | tlist5dat.AddToList(&fill5d);
|
|---|
| 330 | tlist5dat.AddToList(&fill5e);
|
|---|
| 331 | tlist5dat.SetFilter(&filterdat);
|
|---|
| 332 |
|
|---|
| 333 | tlist5.AddToList(&read5);
|
|---|
| 334 | tlist5.AddToList(&apply5);
|
|---|
| 335 | tlist5.AddToList(&drsapply5);
|
|---|
| 336 | tlist5.AddToList(&fill5a);
|
|---|
| 337 | tlist5.AddToList(&swtrig);
|
|---|
| 338 | tlist5.AddToList(&filterdata1);
|
|---|
| 339 | tlist5.AddToList(&extractor5dat);
|
|---|
| 340 | tlist5.AddToList(&calctm5);
|
|---|
| 341 | tlist5.AddToList(&conv5);
|
|---|
| 342 | tlist5.AddToList(&treat5);
|
|---|
| 343 | tlist5.AddToList(&filterdat);
|
|---|
| 344 | tlist5.AddToList(&tlist5dat);
|
|---|
| 345 | tlist5.AddToList(&write5);
|
|---|
| 346 |
|
|---|
| 347 | // run the eventloop
|
|---|
| 348 | if (!loop5.Eventloop(max))
|
|---|
| 349 | return 18;
|
|---|
| 350 |
|
|---|
| 351 | // Check if the display was closed (deleted) by the user
|
|---|
| 352 | if (!loop5.GetDisplay())
|
|---|
| 353 | return 19;
|
|---|
| 354 |
|
|---|
| 355 | // ============================================================
|
|---|
| 356 |
|
|---|
| 357 | TString fname = write5.GetFileName();
|
|---|
| 358 | fname.ReplaceAll(".root", "-display.root");
|
|---|
| 359 |
|
|---|
| 360 | // Write the status display to the file
|
|---|
| 361 | TString title = "-- Calibrated signal [";
|
|---|
| 362 | title += datafile;
|
|---|
| 363 | title += "] --";
|
|---|
| 364 | d->SetTitle(title, kFALSE);
|
|---|
| 365 |
|
|---|
| 366 | d->SaveAsRoot(fname);
|
|---|
| 367 |
|
|---|
| 368 | return 0;
|
|---|
| 369 | }
|
|---|