| 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, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Author(s): Markus Gaug, 4/2004 <mailto:markus@ifae.es>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MJPedestal
|
|---|
| 29 | //
|
|---|
| 30 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | #include "MJPedestal.h"
|
|---|
| 32 |
|
|---|
| 33 | #include <TF1.h>
|
|---|
| 34 | #include <TEnv.h>
|
|---|
| 35 | #include <TFile.h>
|
|---|
| 36 | #include <TLine.h>
|
|---|
| 37 | #include <TLatex.h>
|
|---|
| 38 | #include <TString.h>
|
|---|
| 39 | #include <TCanvas.h>
|
|---|
| 40 | #include <TSystem.h>
|
|---|
| 41 | #include <TLegend.h>
|
|---|
| 42 |
|
|---|
| 43 | #include "MLog.h"
|
|---|
| 44 | #include "MLogManip.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MTaskEnv.h"
|
|---|
| 47 | #include "MSequence.h"
|
|---|
| 48 | #include "MRunIter.h"
|
|---|
| 49 | #include "MParList.h"
|
|---|
| 50 | #include "MTaskList.h"
|
|---|
| 51 | #include "MEvtLoop.h"
|
|---|
| 52 | #include "MExtractor.h"
|
|---|
| 53 |
|
|---|
| 54 | #include "MStatusDisplay.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MGeomCam.h"
|
|---|
| 57 | #include "MHCamera.h"
|
|---|
| 58 | #include "MPedestalCam.h"
|
|---|
| 59 | #include "MBadPixelsCam.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MReadMarsFile.h"
|
|---|
| 62 | #include "MRawFileRead.h"
|
|---|
| 63 | #include "MGeomApply.h"
|
|---|
| 64 | #include "MBadPixelsMerge.h"
|
|---|
| 65 | #include "MPedCalcPedRun.h"
|
|---|
| 66 | #include "MPedCalcFromLoGain.h"
|
|---|
| 67 |
|
|---|
| 68 | ClassImp(MJPedestal);
|
|---|
| 69 |
|
|---|
| 70 | using namespace std;
|
|---|
| 71 |
|
|---|
| 72 | const Double_t MJPedestal::fgPedestalMin = 4.;
|
|---|
| 73 | const Double_t MJPedestal::fgPedestalMax = 16.;
|
|---|
| 74 | const Double_t MJPedestal::fgPedRmsMin = 0.;
|
|---|
| 75 | const Double_t MJPedestal::fgPedRmsMax = 20.;
|
|---|
| 76 |
|
|---|
| 77 | const Float_t MJPedestal::fgRefPedClosedLids = 9.635;
|
|---|
| 78 | const Float_t MJPedestal::fgRefPedExtraGalactic = 9.93;
|
|---|
| 79 | const Float_t MJPedestal::fgRefPedGalactic = 10.03;
|
|---|
| 80 | const Float_t MJPedestal::fgRefPedRmsClosedLidsInner = 1.7;
|
|---|
| 81 | const Float_t MJPedestal::fgRefPedRmsExtraGalacticInner = 5.6;
|
|---|
| 82 | const Float_t MJPedestal::fgRefPedRmsGalacticInner = 6.92;
|
|---|
| 83 | const Float_t MJPedestal::fgRefPedRmsClosedLidsOuter = 1.7;
|
|---|
| 84 | const Float_t MJPedestal::fgRefPedRmsExtraGalacticOuter = 3.35;
|
|---|
| 85 | const Float_t MJPedestal::fgRefPedRmsGalacticOuter = 4.2;
|
|---|
| 86 |
|
|---|
| 87 | // --------------------------------------------------------------------------
|
|---|
| 88 | //
|
|---|
| 89 | // Default constructor.
|
|---|
| 90 | //
|
|---|
| 91 | // Sets:
|
|---|
| 92 | // - fRuns to 0,
|
|---|
| 93 | // - fExtractor to NULL,
|
|---|
| 94 | // - fDataCheck to kFALSE,
|
|---|
| 95 | // - fExtractType to kUsePedRun
|
|---|
| 96 | // - fStorage to Normal Storage
|
|---|
| 97 | //
|
|---|
| 98 | MJPedestal::MJPedestal(const char *name, const char *title)
|
|---|
| 99 | : fRuns(0), fExtractor(NULL), fDisplayType(kNormalDisplay),
|
|---|
| 100 | fDataCheck(kFALSE)
|
|---|
| 101 | {
|
|---|
| 102 | fName = name ? name : "MJPedestal";
|
|---|
| 103 | fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
|
|---|
| 104 |
|
|---|
| 105 | SetNormalStorage();
|
|---|
| 106 | SetUsePedRun();
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | const char* MJPedestal::GetOutputFile() const
|
|---|
| 110 | {
|
|---|
| 111 | if (fSequence.IsValid())
|
|---|
| 112 | return Form("%s/pedest%06d.root", (const char*)fPathOut, fSequence.GetSequence());
|
|---|
| 113 |
|
|---|
| 114 | if (!fRuns)
|
|---|
| 115 | return "";
|
|---|
| 116 |
|
|---|
| 117 | return Form("%s/%s-F0.root", (const char*)fPathOut, (const char*)fRuns->GetRunsAsFileName());
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | //---------------------------------------------------------------------------------
|
|---|
| 121 | //
|
|---|
| 122 | // Try to read an existing MPedestalCam from a previously created output file.
|
|---|
| 123 | // If found, also an MBadPixelsCam and the corresponding display is read.
|
|---|
| 124 | //
|
|---|
| 125 | // In case of Storage type "kNoStorage" or if the file is not found or the
|
|---|
| 126 | // MPedestalCam cannot be read, return kFALSE, otherwise kTRUE.
|
|---|
| 127 | //
|
|---|
| 128 | Bool_t MJPedestal::ReadPedestalCam()
|
|---|
| 129 | {
|
|---|
| 130 | if (IsNoStorage())
|
|---|
| 131 | return kFALSE;
|
|---|
| 132 |
|
|---|
| 133 | const TString fname = GetOutputFile();
|
|---|
| 134 |
|
|---|
| 135 | if (gSystem->AccessPathName(fname, kFileExists))
|
|---|
| 136 | {
|
|---|
| 137 | *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
|
|---|
| 138 | return kFALSE;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | *fLog << inf << "Reading from file: " << fname << endl;
|
|---|
| 142 |
|
|---|
| 143 | TFile file(fname, "READ");
|
|---|
| 144 | if (fPedestalCam.Read()<=0)
|
|---|
| 145 | {
|
|---|
| 146 | *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
|
|---|
| 147 | return kFALSE;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | if (file.FindKey("MBadPixelsCam"))
|
|---|
| 151 | {
|
|---|
| 152 | MBadPixelsCam bad;
|
|---|
| 153 | if (bad.Read()<=0)
|
|---|
| 154 | {
|
|---|
| 155 | *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
|
|---|
| 156 | return kFALSE;
|
|---|
| 157 | }
|
|---|
| 158 | fBadPixels.Merge(bad);
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
|
|---|
| 162 | fDisplay->Read();
|
|---|
| 163 |
|
|---|
| 164 | return kTRUE;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | MExtractor *MJPedestal::ReadCalibration() const
|
|---|
| 168 | {
|
|---|
| 169 | const TString fname = Form("%s/calib%06d.root", fPathIn.Data(), fSequence.GetSequence());
|
|---|
| 170 |
|
|---|
| 171 | *fLog << inf << "Reading from file: " << fname << endl;
|
|---|
| 172 |
|
|---|
| 173 | TFile file(fname, "READ");
|
|---|
| 174 | if (!file.IsOpen())
|
|---|
| 175 | {
|
|---|
| 176 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
|
|---|
| 177 | return NULL;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | TObject *o = file.Get("ExtractSignal");
|
|---|
| 181 | if (o && !o->InheritsFrom(MExtractor::Class()))
|
|---|
| 182 | {
|
|---|
| 183 | *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
|---|
| 184 | return NULL;
|
|---|
| 185 | }
|
|---|
| 186 | return o ? (MExtractor*)o->Clone() : NULL;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | //---------------------------------------------------------------------------------
|
|---|
| 190 | //
|
|---|
| 191 | // Display the results.
|
|---|
| 192 | // If Display type "kDataCheck" was chosen, also the reference lines are displayed.
|
|---|
| 193 | //
|
|---|
| 194 | void MJPedestal::DisplayResult(MParList &plist)
|
|---|
| 195 | {
|
|---|
| 196 | if (!fDisplay)
|
|---|
| 197 | return;
|
|---|
| 198 |
|
|---|
| 199 | //
|
|---|
| 200 | // Update display
|
|---|
| 201 | //
|
|---|
| 202 | TString title = fDisplay->GetTitle();
|
|---|
| 203 | title += "-- Pedestal ";
|
|---|
| 204 | if (fSequence.IsValid())
|
|---|
| 205 | title += fSequence.GetName();
|
|---|
| 206 | else
|
|---|
| 207 | if (fRuns) // FIXME: What to do if an environmentfile was used?
|
|---|
| 208 | title += fRuns->GetRunsAsString();
|
|---|
| 209 | title += " --";
|
|---|
| 210 | fDisplay->SetTitle(title);
|
|---|
| 211 |
|
|---|
| 212 | //
|
|---|
| 213 | // Get container from list
|
|---|
| 214 | //
|
|---|
| 215 | MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
|
|---|
| 216 |
|
|---|
| 217 | //
|
|---|
| 218 | // Create container to display
|
|---|
| 219 | //
|
|---|
| 220 | MHCamera disp0(geomcam, "MPedestalCam;ped", "Mean Pedestal");
|
|---|
| 221 | MHCamera disp1(geomcam, "MPedestalCam;RMS", "Pedestal RMS");
|
|---|
| 222 |
|
|---|
| 223 | disp0.SetCamContent(fPedestalCam, 0);
|
|---|
| 224 | disp0.SetCamError (fPedestalCam, 1);
|
|---|
| 225 |
|
|---|
| 226 | disp1.SetCamContent(fPedestalCam, 2);
|
|---|
| 227 | disp1.SetCamError (fPedestalCam, 3);
|
|---|
| 228 |
|
|---|
| 229 | disp0.SetYTitle("Pedestal [counts/slice]");
|
|---|
| 230 | disp1.SetYTitle("RMS [counts/slice]");
|
|---|
| 231 |
|
|---|
| 232 | //
|
|---|
| 233 | // Display data
|
|---|
| 234 | //
|
|---|
| 235 | TCanvas &c3 = fDisplay->AddTab("Pedestals");
|
|---|
| 236 | c3.Divide(2,3);
|
|---|
| 237 |
|
|---|
| 238 | if (fDisplayType != kDataCheckDisplay)
|
|---|
| 239 | {
|
|---|
| 240 | disp0.CamDraw(c3, 1, 2, 1);
|
|---|
| 241 | disp1.CamDraw(c3, 2, 2, 6);
|
|---|
| 242 | return;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | c3.cd(1);
|
|---|
| 246 | gPad->SetBorderMode(0);
|
|---|
| 247 | gPad->SetTicks();
|
|---|
| 248 | MHCamera *obj1=(MHCamera*)disp0.DrawCopy("hist");
|
|---|
| 249 | //
|
|---|
| 250 | // for the datacheck, fix the ranges!!
|
|---|
| 251 | //
|
|---|
| 252 | obj1->SetMinimum(fgPedestalMin);
|
|---|
| 253 | obj1->SetMaximum(fgPedestalMax);
|
|---|
| 254 |
|
|---|
| 255 | //
|
|---|
| 256 | // Set the datacheck sizes:
|
|---|
| 257 | //
|
|---|
| 258 | FixDataCheckHist((TH1D*)obj1);
|
|---|
| 259 | //
|
|---|
| 260 | // set reference lines
|
|---|
| 261 | //
|
|---|
| 262 | DisplayReferenceLines(obj1,0);
|
|---|
| 263 |
|
|---|
| 264 | //
|
|---|
| 265 | // end reference lines
|
|---|
| 266 | //
|
|---|
| 267 | c3.cd(3);
|
|---|
| 268 | gPad->SetBorderMode(0);
|
|---|
| 269 | obj1->SetPrettyPalette();
|
|---|
| 270 | obj1->Draw();
|
|---|
| 271 |
|
|---|
| 272 | c3.cd(5);
|
|---|
| 273 | gPad->SetBorderMode(0);
|
|---|
| 274 | gPad->SetTicks();
|
|---|
| 275 | TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName());
|
|---|
| 276 | obj2->Draw();
|
|---|
| 277 | obj2->SetBit(kCanDelete);
|
|---|
| 278 | obj2->Fit("gaus","Q");
|
|---|
| 279 | obj2->GetFunction("gaus")->SetLineColor(kYellow);
|
|---|
| 280 | //
|
|---|
| 281 | // Set the datacheck sizes:
|
|---|
| 282 | //
|
|---|
| 283 | FixDataCheckHist(obj2);
|
|---|
| 284 | obj2->SetStats(1);
|
|---|
| 285 |
|
|---|
| 286 | c3.cd(2);
|
|---|
| 287 | gPad->SetBorderMode(0);
|
|---|
| 288 | gPad->SetTicks();
|
|---|
| 289 | MHCamera *obj3=(MHCamera*)disp1.DrawCopy("hist");
|
|---|
| 290 | //
|
|---|
| 291 | // for the datacheck, fix the ranges!!
|
|---|
| 292 | //
|
|---|
| 293 | obj3->SetMinimum(fgPedRmsMin);
|
|---|
| 294 | obj3->SetMaximum(fgPedRmsMax);
|
|---|
| 295 | //
|
|---|
| 296 | // Set the datacheck sizes:
|
|---|
| 297 | //
|
|---|
| 298 | FixDataCheckHist((TH1D*)obj3);
|
|---|
| 299 | //
|
|---|
| 300 | // set reference lines
|
|---|
| 301 | //
|
|---|
| 302 | DisplayReferenceLines(obj1,1);
|
|---|
| 303 |
|
|---|
| 304 | c3.cd(4);
|
|---|
| 305 | gPad->SetBorderMode(0);
|
|---|
| 306 | obj3->SetPrettyPalette();
|
|---|
| 307 | obj3->Draw();
|
|---|
| 308 |
|
|---|
| 309 | c3.cd(6);
|
|---|
| 310 | gPad->SetBorderMode(0);
|
|---|
| 311 |
|
|---|
| 312 | if (geomcam.InheritsFrom("MGeomCamMagic"))
|
|---|
| 313 | {
|
|---|
| 314 | TArrayI inner(1);
|
|---|
| 315 | inner[0] = 0;
|
|---|
| 316 |
|
|---|
| 317 | TArrayI outer(1);
|
|---|
| 318 | outer[0] = 1;
|
|---|
| 319 |
|
|---|
| 320 | TArrayI s0(6);
|
|---|
| 321 | s0[0] = 6;
|
|---|
| 322 | s0[1] = 1;
|
|---|
| 323 | s0[2] = 2;
|
|---|
| 324 | s0[3] = 3;
|
|---|
| 325 | s0[4] = 4;
|
|---|
| 326 | s0[5] = 5;
|
|---|
| 327 |
|
|---|
| 328 | TArrayI s1(3);
|
|---|
| 329 | s1[0] = 6;
|
|---|
| 330 | s1[1] = 1;
|
|---|
| 331 | s1[2] = 2;
|
|---|
| 332 |
|
|---|
| 333 | TArrayI s2(3);
|
|---|
| 334 | s2[0] = 3;
|
|---|
| 335 | s2[1] = 4;
|
|---|
| 336 | s2[2] = 5;
|
|---|
| 337 |
|
|---|
| 338 | TVirtualPad *pad = gPad;
|
|---|
| 339 | pad->Divide(2,1);
|
|---|
| 340 |
|
|---|
| 341 | TH1D *inout[2];
|
|---|
| 342 | inout[0] = disp1.ProjectionS(s0, inner, "Inner");
|
|---|
| 343 | inout[1] = disp1.ProjectionS(s0, outer, "Outer");
|
|---|
| 344 | FixDataCheckHist(inout[0]);
|
|---|
| 345 | FixDataCheckHist(inout[1]);
|
|---|
| 346 |
|
|---|
| 347 | inout[0]->SetTitle(Form("%s %s",disp1.GetTitle(),"Inner"));
|
|---|
| 348 | inout[1]->SetTitle(Form("%s %s",disp1.GetTitle(),"Outer"));
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 | for (int i=0; i<2; i++)
|
|---|
| 352 | {
|
|---|
| 353 | pad->cd(i+1);
|
|---|
| 354 | gPad->SetBorderMode(0);
|
|---|
| 355 | gPad->SetTicks();
|
|---|
| 356 |
|
|---|
| 357 | inout[i]->SetDirectory(NULL);
|
|---|
| 358 | inout[i]->SetLineColor(kRed+i);
|
|---|
| 359 | inout[i]->SetBit(kCanDelete);
|
|---|
| 360 | inout[i]->Draw();
|
|---|
| 361 | inout[i]->Fit("gaus", "Q");
|
|---|
| 362 |
|
|---|
| 363 | TLegend *leg2 = new TLegend(0.6,0.2,0.9,0.55);
|
|---|
| 364 | leg2->SetHeader(inout[i]->GetName());
|
|---|
| 365 | leg2->AddEntry(inout[i], inout[i]->GetName(), "l");
|
|---|
| 366 |
|
|---|
| 367 | //
|
|---|
| 368 | // Display the outliers as dead and noisy pixels
|
|---|
| 369 | //
|
|---|
| 370 | DisplayOutliers(inout[i]);
|
|---|
| 371 |
|
|---|
| 372 | //
|
|---|
| 373 | // Display the two half of the camera separately
|
|---|
| 374 | //
|
|---|
| 375 | TH1D *half[2];
|
|---|
| 376 | half[0] = disp1.ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
|
|---|
| 377 | half[1] = disp1.ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
|
|---|
| 378 |
|
|---|
| 379 | for (int j=0; j<2; j++)
|
|---|
| 380 | {
|
|---|
| 381 | half[j]->SetLineColor(kRed+i+2*j+1);
|
|---|
| 382 | half[j]->SetDirectory(NULL);
|
|---|
| 383 | half[j]->SetBit(kCanDelete);
|
|---|
| 384 | half[j]->Draw("same");
|
|---|
| 385 | leg2->AddEntry(half[j], half[j]->GetName(), "l");
|
|---|
| 386 | }
|
|---|
| 387 | leg2->Draw();
|
|---|
| 388 | }
|
|---|
| 389 | }
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | void MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
|
|---|
| 393 | {
|
|---|
| 394 | Double_t x = cam->GetNbinsX();
|
|---|
| 395 |
|
|---|
| 396 | const MGeomCam *geom = cam->GetGeometry();
|
|---|
| 397 |
|
|---|
| 398 | if (geom->InheritsFrom("MGeomCamMagic"))
|
|---|
| 399 | x = what ? 397 : cam->GetNbinsX();
|
|---|
| 400 |
|
|---|
| 401 | TLine line;
|
|---|
| 402 | line.SetLineStyle(kDashed);
|
|---|
| 403 | line.SetLineWidth(3);
|
|---|
| 404 |
|
|---|
| 405 | line.SetLineColor(kBlue);
|
|---|
| 406 | TLine *l1 = line.DrawLine(0, what ? fgRefPedRmsGalacticInner : fgRefPedGalactic,
|
|---|
| 407 | x, what ? fgRefPedRmsGalacticInner : fgRefPedGalactic);
|
|---|
| 408 |
|
|---|
| 409 | line.SetLineColor(kYellow);
|
|---|
| 410 | TLine *l2 = line.DrawLine(0, what ? fgRefPedRmsExtraGalacticInner : fgRefPedExtraGalactic,
|
|---|
| 411 | x, what ? fgRefPedRmsExtraGalacticInner : fgRefPedExtraGalactic);
|
|---|
| 412 |
|
|---|
| 413 | line.SetLineColor(kMagenta);
|
|---|
| 414 | TLine *l3 = line.DrawLine(0, what ? fgRefPedRmsClosedLidsInner : fgRefPedClosedLids,
|
|---|
| 415 | x, what ? fgRefPedRmsClosedLidsInner : fgRefPedClosedLids);
|
|---|
| 416 |
|
|---|
| 417 | if (geom->InheritsFrom("MGeomCamMagic"))
|
|---|
| 418 | if (what)
|
|---|
| 419 | {
|
|---|
| 420 | const Double_t x2 = cam->GetNbinsX();
|
|---|
| 421 |
|
|---|
| 422 | line.SetLineColor(kBlue);
|
|---|
| 423 | line.DrawLine(398, fgRefPedRmsGalacticOuter,
|
|---|
| 424 | x2, fgRefPedRmsGalacticOuter);
|
|---|
| 425 |
|
|---|
| 426 | line.SetLineColor(kYellow);
|
|---|
| 427 | line.DrawLine(398, fgRefPedRmsExtraGalacticOuter,
|
|---|
| 428 | x2, fgRefPedRmsExtraGalacticOuter);
|
|---|
| 429 |
|
|---|
| 430 | line.SetLineColor(kMagenta);
|
|---|
| 431 | line.DrawLine(398, fgRefPedRmsClosedLidsOuter,
|
|---|
| 432 | x2, fgRefPedRmsClosedLidsOuter);
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 | TLegend *leg = new TLegend(0.4,0.75,0.7,0.99);
|
|---|
| 437 | leg->SetBit(kCanDelete);
|
|---|
| 438 | leg->AddEntry(l1, "Galactic Source","l");
|
|---|
| 439 | leg->AddEntry(l2, "Extra-Galactic Source","l");
|
|---|
| 440 | leg->AddEntry(l3, "Closed Lids","l");
|
|---|
| 441 | leg->Draw();
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | void MJPedestal::DisplayOutliers(TH1D *hist) const
|
|---|
| 445 | {
|
|---|
| 446 | const Float_t mean = hist->GetFunction("gaus")->GetParameter(1);
|
|---|
| 447 | const Float_t lolim = mean - 3.5*hist->GetFunction("gaus")->GetParameter(2);
|
|---|
| 448 | const Float_t uplim = mean + 3.5*hist->GetFunction("gaus")->GetParameter(2);
|
|---|
| 449 | const Stat_t dead = hist->Integral(0,hist->FindBin(lolim)-1);
|
|---|
| 450 | const Stat_t noisy = hist->Integral(hist->FindBin(uplim)+1,hist->GetNbinsX()+1);
|
|---|
| 451 |
|
|---|
| 452 | TLatex deadtex;
|
|---|
| 453 | deadtex.SetTextSize(0.06);
|
|---|
| 454 | deadtex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.1,Form("%3i dead pixels",(Int_t)dead));
|
|---|
| 455 |
|
|---|
| 456 | TLatex noisytex;
|
|---|
| 457 | noisytex.SetTextSize(0.06);
|
|---|
| 458 | noisytex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.2,Form("%3i noisy pixels",(Int_t)noisy));
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | void MJPedestal::FixDataCheckHist(TH1D *hist) const
|
|---|
| 462 | {
|
|---|
| 463 | hist->SetDirectory(NULL);
|
|---|
| 464 | hist->SetStats(0);
|
|---|
| 465 |
|
|---|
| 466 | //
|
|---|
| 467 | // set the labels bigger
|
|---|
| 468 | //
|
|---|
| 469 | TAxis *xaxe = hist->GetXaxis();
|
|---|
| 470 | TAxis *yaxe = hist->GetYaxis();
|
|---|
| 471 |
|
|---|
| 472 | xaxe->CenterTitle();
|
|---|
| 473 | yaxe->CenterTitle();
|
|---|
| 474 | xaxe->SetTitleSize(0.06);
|
|---|
| 475 | yaxe->SetTitleSize(0.06);
|
|---|
| 476 | xaxe->SetTitleOffset(0.8);
|
|---|
| 477 | yaxe->SetTitleOffset(0.5);
|
|---|
| 478 | xaxe->SetLabelSize(0.05);
|
|---|
| 479 | yaxe->SetLabelSize(0.05);
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | /*
|
|---|
| 483 | Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const
|
|---|
| 484 | {
|
|---|
| 485 | if (fOutputPath.IsNull())
|
|---|
| 486 | return kTRUE;
|
|---|
| 487 |
|
|---|
| 488 | const TString oname(GetOutputFile());
|
|---|
| 489 |
|
|---|
| 490 | *fLog << inf << "Writing to file: " << oname << endl;
|
|---|
| 491 |
|
|---|
| 492 | TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJPedestal", 9);
|
|---|
| 493 | if (!file.IsOpen())
|
|---|
| 494 | {
|
|---|
| 495 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
|
|---|
| 496 | return kFALSE;
|
|---|
| 497 | }
|
|---|
| 498 |
|
|---|
| 499 | if (evtloop.Write(fName)<=0)
|
|---|
| 500 | {
|
|---|
| 501 | *fLog << err << "Unable to write MEvtloop to " << oname << endl;
|
|---|
| 502 | return kFALSE;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | return kTRUE;
|
|---|
| 506 | }
|
|---|
| 507 | */
|
|---|
| 508 |
|
|---|
| 509 | // --------------------------------------------------------------------------
|
|---|
| 510 | //
|
|---|
| 511 | // The following resource options are available:
|
|---|
| 512 | //
|
|---|
| 513 | // Do a datacheck run (read raw-data and enable display)
|
|---|
| 514 | // Prefix.DataCheck: Yes, No <default>
|
|---|
| 515 | //
|
|---|
| 516 | // Show data check display
|
|---|
| 517 | // Prefix.DataCheckDisplay: Yes, No <default>
|
|---|
| 518 | //
|
|---|
| 519 | // Use cosmic data instead of pedestal data (DatRuns)
|
|---|
| 520 | // Prefix.UseData: Yes, No <default>
|
|---|
| 521 | //
|
|---|
| 522 | // Write an output file with pedestals and status-display
|
|---|
| 523 | // Prefix.DisableOutput: Yes, No <default>
|
|---|
| 524 | //
|
|---|
| 525 | Bool_t MJPedestal::CheckEnvLocal()
|
|---|
| 526 | {
|
|---|
| 527 | SetDataCheck(GetEnv("DataCheck", fDataCheck));
|
|---|
| 528 |
|
|---|
| 529 | if (HasEnv("DataCheckDisplay"))
|
|---|
| 530 | fDisplayType = GetEnv("DataCheckDisplay", kFALSE) ? kDataCheckDisplay : kNormalDisplay;
|
|---|
| 531 |
|
|---|
| 532 | if (HasEnv("UseData"))
|
|---|
| 533 | fExtractType = GetEnv("UseData",kFALSE) ? kUseData : kUsePedRun;
|
|---|
| 534 |
|
|---|
| 535 | if (HasEnv("UseExtractor"))
|
|---|
| 536 | if (GetEnv("UseExtractor",kFALSE))
|
|---|
| 537 | fExtractType = kUseExtractor;
|
|---|
| 538 |
|
|---|
| 539 | SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
|
|---|
| 540 |
|
|---|
| 541 | return kTRUE;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | //---------------------------------------------------------------------------------
|
|---|
| 545 | //
|
|---|
| 546 | // Try to write the created MPedestalCam in the output file.
|
|---|
| 547 | // If possible, also an MBadPixelsCam and the corresponding display is written.
|
|---|
| 548 | //
|
|---|
| 549 | // In case of Storage type "kNoStorage" or if any of the containers
|
|---|
| 550 | // cannot be written, return kFALSE, otherwise kTRUE.
|
|---|
| 551 | //
|
|---|
| 552 | Bool_t MJPedestal::WriteResult()
|
|---|
| 553 | {
|
|---|
| 554 | if (IsNoStorage())
|
|---|
| 555 | return kTRUE;
|
|---|
| 556 |
|
|---|
| 557 | if (fPathOut.IsNull())
|
|---|
| 558 | return kTRUE;
|
|---|
| 559 |
|
|---|
| 560 | const TString oname(GetOutputFile());
|
|---|
| 561 |
|
|---|
| 562 | *fLog << inf << "Writing to file: " << oname << endl;
|
|---|
| 563 |
|
|---|
| 564 | TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
|
|---|
| 565 | if (!file.IsOpen())
|
|---|
| 566 | {
|
|---|
| 567 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
|
|---|
| 568 | return kFALSE;
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | if (fDisplay && fDisplay->Write()<=0)
|
|---|
| 572 | {
|
|---|
| 573 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
|---|
| 574 | return kFALSE;
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | if (fPedestalCam.Write()<=0)
|
|---|
| 578 | {
|
|---|
| 579 | *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
|
|---|
| 580 | return kFALSE;
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | if (fBadPixels.Write()<=0)
|
|---|
| 584 | {
|
|---|
| 585 | *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
|
|---|
| 586 | return kFALSE;
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | return kTRUE;
|
|---|
| 590 | }
|
|---|
| 591 |
|
|---|
| 592 | Bool_t MJPedestal::Process()
|
|---|
| 593 | {
|
|---|
| 594 | if (!ReadPedestalCam())
|
|---|
| 595 | return ProcessFile();
|
|---|
| 596 |
|
|---|
| 597 | return kTRUE;
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | Bool_t MJPedestal::ProcessFile()
|
|---|
| 601 | {
|
|---|
| 602 | if (!fSequence.IsValid())
|
|---|
| 603 | {
|
|---|
| 604 | if (!fRuns)
|
|---|
| 605 | {
|
|---|
| 606 | *fLog << err << "Neither AddRuns nor SetSequence nor SetEnv was called... abort." << endl;
|
|---|
| 607 | return kFALSE;
|
|---|
| 608 | }
|
|---|
| 609 | if (fRuns && fRuns->GetNumRuns() != fRuns->GetNumEntries())
|
|---|
| 610 | {
|
|---|
| 611 | *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
|
|---|
| 612 | return kFALSE;
|
|---|
| 613 | }
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | //if (!CheckEnv())
|
|---|
| 617 | // return kFALSE;
|
|---|
| 618 |
|
|---|
| 619 | CheckEnv();
|
|---|
| 620 |
|
|---|
| 621 | // --------------------------------------------------------------------------------
|
|---|
| 622 |
|
|---|
| 623 | const TString type = IsUseData() ? "data" : "pedestal";
|
|---|
| 624 |
|
|---|
| 625 | *fLog << inf;
|
|---|
| 626 | fLog->Separator(GetDescriptor());
|
|---|
| 627 | *fLog << "Calculate MPedestalCam from " << type << "-runs ";
|
|---|
| 628 | if (fSequence.IsValid())
|
|---|
| 629 | *fLog << fSequence.GetName() << endl;
|
|---|
| 630 | else
|
|---|
| 631 | if (fRuns)
|
|---|
| 632 | *fLog << fRuns->GetRunsAsString() << endl;
|
|---|
| 633 | else
|
|---|
| 634 | *fLog << "in Resource File." << endl;
|
|---|
| 635 | *fLog << endl;
|
|---|
| 636 |
|
|---|
| 637 | // --------------------------------------------------------------------------------
|
|---|
| 638 |
|
|---|
| 639 | MParList plist;
|
|---|
| 640 | MTaskList tlist;
|
|---|
| 641 | plist.AddToList(&tlist);
|
|---|
| 642 | plist.AddToList(this); // take care of fDisplay!
|
|---|
| 643 |
|
|---|
| 644 | MReadMarsFile read("Events");
|
|---|
| 645 | MRawFileRead rawread(NULL);
|
|---|
| 646 |
|
|---|
| 647 | MDirIter iter;
|
|---|
| 648 | if (fSequence.IsValid())
|
|---|
| 649 | {
|
|---|
| 650 | const Int_t n0 = IsUseData() ? fSequence.SetupDatRuns(iter, fPathData, "D", fDataCheck) : fSequence.SetupPedRuns(iter, fPathData, "P", fDataCheck);
|
|---|
| 651 | const Int_t n1 = IsUseData() ? fSequence.GetNumDatRuns() : fSequence.GetNumPedRuns();
|
|---|
| 652 | if (n0==0)
|
|---|
| 653 | {
|
|---|
| 654 | *fLog << err << "ERROR - No " << type << " input files of sequence found in " << (fPathData.IsNull()?"<defaul>":fPathData.Data()) << endl;
|
|---|
| 655 | return kFALSE;
|
|---|
| 656 | }
|
|---|
| 657 | if (n0!=n1)
|
|---|
| 658 | {
|
|---|
| 659 | *fLog << err << "ERROR - Number of " << type << " files found (" << n0 << ") in " << (fPathData.IsNull()?"<defaul>":fPathData.Data()) << " doesn't match number of files in sequence (" << n1 << ")" << endl;
|
|---|
| 660 | return kFALSE;
|
|---|
| 661 | }
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | if (fDataCheck)
|
|---|
| 665 | {
|
|---|
| 666 | if (fRuns || fSequence.IsValid())
|
|---|
| 667 | rawread.AddFiles(fSequence.IsValid() ? iter : *fRuns);
|
|---|
| 668 | tlist.AddToList(&rawread);
|
|---|
| 669 | }
|
|---|
| 670 | else
|
|---|
| 671 | {
|
|---|
| 672 | read.DisableAutoScheme();
|
|---|
| 673 | if (fRuns || fSequence.IsValid())
|
|---|
| 674 | read.AddFiles(fSequence.IsValid() ? iter : *fRuns);
|
|---|
| 675 | tlist.AddToList(&read);
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | // Setup Tasklist
|
|---|
| 679 | plist.AddToList(&fPedestalCam);
|
|---|
| 680 | plist.AddToList(&fBadPixels);
|
|---|
| 681 |
|
|---|
| 682 | MGeomApply geomapl;
|
|---|
| 683 | MBadPixelsMerge merge(&fBadPixels);
|
|---|
| 684 |
|
|---|
| 685 | MPedCalcPedRun pedcalc;
|
|---|
| 686 | MPedCalcFromLoGain pedlogain;
|
|---|
| 687 |
|
|---|
| 688 | if (!fPathIn.IsNull())
|
|---|
| 689 | {
|
|---|
| 690 | fExtractor = ReadCalibration();
|
|---|
| 691 | if (!fExtractor)
|
|---|
| 692 | return kFALSE;
|
|---|
| 693 |
|
|---|
| 694 | *fLog << all;
|
|---|
| 695 | *fLog << underline << "Signal Extractor found in calibration file" << endl;
|
|---|
| 696 | fExtractor->Print();
|
|---|
| 697 | *fLog << endl;
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | MTaskEnv taskenv("ExtractPedestal");
|
|---|
| 701 | switch (fExtractType)
|
|---|
| 702 | {
|
|---|
| 703 | case kUseData:
|
|---|
| 704 | taskenv.SetDefault(&pedlogain);
|
|---|
| 705 | if (!fExtractor)
|
|---|
| 706 | break;
|
|---|
| 707 | pedlogain.SetExtractWindow(15, (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
|
|---|
| 708 | pedlogain.SetPedestalUpdate(kFALSE);
|
|---|
| 709 | break;
|
|---|
| 710 |
|
|---|
| 711 | case kUsePedRun:
|
|---|
| 712 | taskenv.SetDefault(&pedcalc);
|
|---|
| 713 | if (!fExtractor)
|
|---|
| 714 | break;
|
|---|
| 715 | pedcalc.SetWindowSize((Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
|
|---|
| 716 | pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
|
|---|
| 717 | break;
|
|---|
| 718 |
|
|---|
| 719 | case kUseExtractor:
|
|---|
| 720 | if (!fExtractor)
|
|---|
| 721 | {
|
|---|
| 722 | *fLog << err << GetDescriptor();
|
|---|
| 723 | *fLog << "Extraction Type kUseExtractor is chosen, but no extractor has been handed over" << endl;
|
|---|
| 724 | return kFALSE;
|
|---|
| 725 | }
|
|---|
| 726 | taskenv.SetDefault(fExtractor);
|
|---|
| 727 | if (fExtractor->IsNoiseCalculation())
|
|---|
| 728 | break;
|
|---|
| 729 |
|
|---|
| 730 | *fLog << warn << GetDescriptor();
|
|---|
| 731 | *fLog <<"Extraction type is kUseExtractor, but extractor has kNoiseCalculation not set... set." << endl;
|
|---|
| 732 | fExtractor->SetNoiseCalculation();
|
|---|
| 733 | return kFALSE;
|
|---|
| 734 | }
|
|---|
| 735 |
|
|---|
| 736 | if (!fPathIn.IsNull())
|
|---|
| 737 | {
|
|---|
| 738 | delete fExtractor;
|
|---|
| 739 | fExtractor = 0;
|
|---|
| 740 | }
|
|---|
| 741 |
|
|---|
| 742 | tlist.AddToList(&geomapl);
|
|---|
| 743 | tlist.AddToList(&merge);
|
|---|
| 744 | tlist.AddToList(&taskenv);
|
|---|
| 745 |
|
|---|
| 746 | //
|
|---|
| 747 | // Execute the eventloop
|
|---|
| 748 | //
|
|---|
| 749 | MEvtLoop evtloop(fName);
|
|---|
| 750 | evtloop.SetParList(&plist);
|
|---|
| 751 | evtloop.SetDisplay(fDisplay);
|
|---|
| 752 | evtloop.SetLogStream(fLog);
|
|---|
| 753 | if (!SetupEnv(evtloop))
|
|---|
| 754 | return kFALSE;
|
|---|
| 755 |
|
|---|
| 756 | // if (!WriteEventloop(evtloop))
|
|---|
| 757 | // return kFALSE;
|
|---|
| 758 |
|
|---|
| 759 | // Execute first analysis
|
|---|
| 760 | if (!evtloop.Eventloop(fMaxEvents))
|
|---|
| 761 | {
|
|---|
| 762 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
|---|
| 763 | return kFALSE;
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | tlist.PrintStatistics();
|
|---|
| 767 |
|
|---|
| 768 | DisplayResult(plist);
|
|---|
| 769 |
|
|---|
| 770 | if (!WriteResult())
|
|---|
| 771 | return kFALSE;
|
|---|
| 772 |
|
|---|
| 773 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
|---|
| 774 | *fLog << endl << endl;
|
|---|
| 775 |
|
|---|
| 776 | return kTRUE;
|
|---|
| 777 | }
|
|---|