| 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 | ! Markus Gaug ,04/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 |
|
|---|
| 67 | ClassImp(MJPedestal);
|
|---|
| 68 |
|
|---|
| 69 | using namespace std;
|
|---|
| 70 |
|
|---|
| 71 | const Double_t MJPedestal::fgPedestalMin = 4.;
|
|---|
| 72 | const Double_t MJPedestal::fgPedestalMax = 16.;
|
|---|
| 73 | const Double_t MJPedestal::fgPedRmsMin = 0.;
|
|---|
| 74 | const Double_t MJPedestal::fgPedRmsMax = 20.;
|
|---|
| 75 |
|
|---|
| 76 | const Float_t MJPedestal::fgRefPedClosedLids = 9.635;
|
|---|
| 77 | const Float_t MJPedestal::fgRefPedExtraGalactic = 9.93;
|
|---|
| 78 | const Float_t MJPedestal::fgRefPedGalactic = 10.03;
|
|---|
| 79 | const Float_t MJPedestal::fgRefPedRmsClosedLidsInner = 1.7;
|
|---|
| 80 | const Float_t MJPedestal::fgRefPedRmsExtraGalacticInner = 5.6;
|
|---|
| 81 | const Float_t MJPedestal::fgRefPedRmsGalacticInner = 6.92;
|
|---|
| 82 | const Float_t MJPedestal::fgRefPedRmsClosedLidsOuter = 1.7;
|
|---|
| 83 | const Float_t MJPedestal::fgRefPedRmsExtraGalacticOuter = 3.35;
|
|---|
| 84 | const Float_t MJPedestal::fgRefPedRmsGalacticOuter = 4.2;
|
|---|
| 85 | // --------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // Default constructor.
|
|---|
| 88 | //
|
|---|
| 89 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
|---|
| 90 | //
|
|---|
| 91 | MJPedestal::MJPedestal(const char *name, const char *title)
|
|---|
| 92 | : fRuns(0), fExtractor(NULL), fDisplayType(kNormalDisplay),
|
|---|
| 93 | fDataCheck(kFALSE), fUseData(kFALSE)
|
|---|
| 94 | {
|
|---|
| 95 | fName = name ? name : "MJPedestal";
|
|---|
| 96 | fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | const char* MJPedestal::GetOutputFile() const
|
|---|
| 100 | {
|
|---|
| 101 | if (fSequence.IsValid())
|
|---|
| 102 | return Form("%s/pedest%06d.root", (const char*)fPathOut, fSequence.GetSequence());
|
|---|
| 103 |
|
|---|
| 104 | if (!fRuns)
|
|---|
| 105 | return "";
|
|---|
| 106 |
|
|---|
| 107 | return Form("%s/%s-F0.root", (const char*)fPathOut, (const char*)fRuns->GetRunsAsFileName());
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | Bool_t MJPedestal::ReadPedestalCam()
|
|---|
| 111 | {
|
|---|
| 112 | const TString fname = GetOutputFile();
|
|---|
| 113 |
|
|---|
| 114 | if (gSystem->AccessPathName(fname, kFileExists))
|
|---|
| 115 | {
|
|---|
| 116 | *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
|
|---|
| 117 | return kFALSE;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | *fLog << inf << "Reading from file: " << fname << endl;
|
|---|
| 121 |
|
|---|
| 122 | TFile file(fname, "READ");
|
|---|
| 123 | if (fPedestalCam.Read()<=0)
|
|---|
| 124 | {
|
|---|
| 125 | *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
|
|---|
| 126 | return kFALSE;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | if (file.FindKey("MBadPixelsCam"))
|
|---|
| 130 | {
|
|---|
| 131 | MBadPixelsCam bad;
|
|---|
| 132 | if (bad.Read()<=0)
|
|---|
| 133 | {
|
|---|
| 134 | *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
|
|---|
| 135 | return kFALSE;
|
|---|
| 136 | }
|
|---|
| 137 | fBadPixels.Merge(bad);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
|
|---|
| 141 | fDisplay->Read();
|
|---|
| 142 |
|
|---|
| 143 | return kTRUE;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | void MJPedestal::DisplayResult(MParList &plist)
|
|---|
| 147 | {
|
|---|
| 148 | if (!fDisplay)
|
|---|
| 149 | return;
|
|---|
| 150 |
|
|---|
| 151 | //
|
|---|
| 152 | // Update display
|
|---|
| 153 | //
|
|---|
| 154 | TString title = fDisplay->GetTitle();
|
|---|
| 155 | title += "-- Pedestal ";
|
|---|
| 156 | if (fSequence.IsValid())
|
|---|
| 157 | title += fSequence.GetName();
|
|---|
| 158 | else
|
|---|
| 159 | if (fRuns) // FIXME: What to do if an environmentfile was used?
|
|---|
| 160 | title += fRuns->GetRunsAsString();
|
|---|
| 161 | title += " --";
|
|---|
| 162 | fDisplay->SetTitle(title);
|
|---|
| 163 |
|
|---|
| 164 | //
|
|---|
| 165 | // Get container from list
|
|---|
| 166 | //
|
|---|
| 167 | MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
|
|---|
| 168 |
|
|---|
| 169 | //
|
|---|
| 170 | // Create container to display
|
|---|
| 171 | //
|
|---|
| 172 | MHCamera disp0(geomcam, "MPedestalCam;ped", "Mean Pedestal");
|
|---|
| 173 | MHCamera disp1(geomcam, "MPedestalCam;RMS", "Pedestal RMS");
|
|---|
| 174 |
|
|---|
| 175 | disp0.SetCamContent(fPedestalCam, 0);
|
|---|
| 176 | disp0.SetCamError (fPedestalCam, 1);
|
|---|
| 177 |
|
|---|
| 178 | disp1.SetCamContent(fPedestalCam, 2);
|
|---|
| 179 | disp1.SetCamError (fPedestalCam, 3);
|
|---|
| 180 |
|
|---|
| 181 | disp0.SetYTitle("Pedestal [counts/slice]");
|
|---|
| 182 | disp1.SetYTitle("RMS [counts/slice]");
|
|---|
| 183 |
|
|---|
| 184 | //
|
|---|
| 185 | // Display data
|
|---|
| 186 | //
|
|---|
| 187 | TCanvas &c3 = fDisplay->AddTab("Pedestals");
|
|---|
| 188 | c3.Divide(2,3);
|
|---|
| 189 |
|
|---|
| 190 | if (fDisplayType != kDataCheckDisplay)
|
|---|
| 191 | {
|
|---|
| 192 | disp0.CamDraw(c3, 1, 2, 1);
|
|---|
| 193 | disp1.CamDraw(c3, 2, 2, 6);
|
|---|
| 194 | return;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | c3.cd(1);
|
|---|
| 198 | gPad->SetBorderMode(0);
|
|---|
| 199 | gPad->SetTicks();
|
|---|
| 200 | MHCamera *obj1=(MHCamera*)disp0.DrawCopy("hist");
|
|---|
| 201 | //
|
|---|
| 202 | // for the datacheck, fix the ranges!!
|
|---|
| 203 | //
|
|---|
| 204 | obj1->SetMinimum(fgPedestalMin);
|
|---|
| 205 | obj1->SetMaximum(fgPedestalMax);
|
|---|
| 206 |
|
|---|
| 207 | //
|
|---|
| 208 | // Set the datacheck sizes:
|
|---|
| 209 | //
|
|---|
| 210 | FixDataCheckHist((TH1D*)obj1);
|
|---|
| 211 | //
|
|---|
| 212 | // set reference lines
|
|---|
| 213 | //
|
|---|
| 214 | DisplayReferenceLines(obj1,0);
|
|---|
| 215 |
|
|---|
| 216 | //
|
|---|
| 217 | // end reference lines
|
|---|
| 218 | //
|
|---|
| 219 | c3.cd(3);
|
|---|
| 220 | gPad->SetBorderMode(0);
|
|---|
| 221 | obj1->SetPrettyPalette();
|
|---|
| 222 | obj1->Draw();
|
|---|
| 223 |
|
|---|
| 224 | c3.cd(5);
|
|---|
| 225 | gPad->SetBorderMode(0);
|
|---|
| 226 | gPad->SetTicks();
|
|---|
| 227 | TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName());
|
|---|
| 228 | obj2->Draw();
|
|---|
| 229 | obj2->SetBit(kCanDelete);
|
|---|
| 230 | obj2->Fit("gaus","Q");
|
|---|
| 231 | obj2->GetFunction("gaus")->SetLineColor(kYellow);
|
|---|
| 232 | //
|
|---|
| 233 | // Set the datacheck sizes:
|
|---|
| 234 | //
|
|---|
| 235 | FixDataCheckHist(obj2);
|
|---|
| 236 | obj2->SetStats(1);
|
|---|
| 237 |
|
|---|
| 238 | c3.cd(2);
|
|---|
| 239 | gPad->SetBorderMode(0);
|
|---|
| 240 | gPad->SetTicks();
|
|---|
| 241 | MHCamera *obj3=(MHCamera*)disp1.DrawCopy("hist");
|
|---|
| 242 | //
|
|---|
| 243 | // for the datacheck, fix the ranges!!
|
|---|
| 244 | //
|
|---|
| 245 | obj3->SetMinimum(fgPedRmsMin);
|
|---|
| 246 | obj3->SetMaximum(fgPedRmsMax);
|
|---|
| 247 | //
|
|---|
| 248 | // Set the datacheck sizes:
|
|---|
| 249 | //
|
|---|
| 250 | FixDataCheckHist((TH1D*)obj3);
|
|---|
| 251 | //
|
|---|
| 252 | // set reference lines
|
|---|
| 253 | //
|
|---|
| 254 | DisplayReferenceLines(obj1,1);
|
|---|
| 255 |
|
|---|
| 256 | c3.cd(4);
|
|---|
| 257 | gPad->SetBorderMode(0);
|
|---|
| 258 | obj3->SetPrettyPalette();
|
|---|
| 259 | obj3->Draw();
|
|---|
| 260 |
|
|---|
| 261 | c3.cd(6);
|
|---|
| 262 | gPad->SetBorderMode(0);
|
|---|
| 263 |
|
|---|
| 264 | if (geomcam.InheritsFrom("MGeomCamMagic"))
|
|---|
| 265 | {
|
|---|
| 266 | TArrayI inner(1);
|
|---|
| 267 | inner[0] = 0;
|
|---|
| 268 |
|
|---|
| 269 | TArrayI outer(1);
|
|---|
| 270 | outer[0] = 1;
|
|---|
| 271 |
|
|---|
| 272 | TArrayI s0(6);
|
|---|
| 273 | s0[0] = 6;
|
|---|
| 274 | s0[1] = 1;
|
|---|
| 275 | s0[2] = 2;
|
|---|
| 276 | s0[3] = 3;
|
|---|
| 277 | s0[4] = 4;
|
|---|
| 278 | s0[5] = 5;
|
|---|
| 279 |
|
|---|
| 280 | TArrayI s1(3);
|
|---|
| 281 | s1[0] = 6;
|
|---|
| 282 | s1[1] = 1;
|
|---|
| 283 | s1[2] = 2;
|
|---|
| 284 |
|
|---|
| 285 | TArrayI s2(3);
|
|---|
| 286 | s2[0] = 3;
|
|---|
| 287 | s2[1] = 4;
|
|---|
| 288 | s2[2] = 5;
|
|---|
| 289 |
|
|---|
| 290 | TVirtualPad *pad = gPad;
|
|---|
| 291 | pad->Divide(2,1);
|
|---|
| 292 |
|
|---|
| 293 | TH1D *inout[2];
|
|---|
| 294 | inout[0] = disp1.ProjectionS(s0, inner, "Inner");
|
|---|
| 295 | inout[1] = disp1.ProjectionS(s0, outer, "Outer");
|
|---|
| 296 | FixDataCheckHist(inout[0]);
|
|---|
| 297 | FixDataCheckHist(inout[1]);
|
|---|
| 298 |
|
|---|
| 299 | inout[0]->SetTitle(Form("%s %s",disp1.GetTitle(),"Inner"));
|
|---|
| 300 | inout[1]->SetTitle(Form("%s %s",disp1.GetTitle(),"Outer"));
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 | for (int i=0; i<2; i++)
|
|---|
| 304 | {
|
|---|
| 305 | pad->cd(i+1);
|
|---|
| 306 | gPad->SetBorderMode(0);
|
|---|
| 307 | gPad->SetTicks();
|
|---|
| 308 |
|
|---|
| 309 | inout[i]->SetDirectory(NULL);
|
|---|
| 310 | inout[i]->SetLineColor(kRed+i);
|
|---|
| 311 | inout[i]->SetBit(kCanDelete);
|
|---|
| 312 | inout[i]->Draw();
|
|---|
| 313 | inout[i]->Fit("gaus", "Q");
|
|---|
| 314 |
|
|---|
| 315 | TLegend *leg2 = new TLegend(0.6,0.2,0.9,0.55);
|
|---|
| 316 | leg2->SetHeader(inout[i]->GetName());
|
|---|
| 317 | leg2->AddEntry(inout[i], inout[i]->GetName(), "l");
|
|---|
| 318 |
|
|---|
| 319 | //
|
|---|
| 320 | // Display the outliers as dead and noisy pixels
|
|---|
| 321 | //
|
|---|
| 322 | DisplayOutliers(inout[i]);
|
|---|
| 323 |
|
|---|
| 324 | //
|
|---|
| 325 | // Display the two half of the camera separately
|
|---|
| 326 | //
|
|---|
| 327 | TH1D *half[2];
|
|---|
| 328 | half[0] = disp1.ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
|
|---|
| 329 | half[1] = disp1.ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
|
|---|
| 330 |
|
|---|
| 331 | for (int j=0; j<2; j++)
|
|---|
| 332 | {
|
|---|
| 333 | half[j]->SetLineColor(kRed+i+2*j+1);
|
|---|
| 334 | half[j]->SetDirectory(NULL);
|
|---|
| 335 | half[j]->SetBit(kCanDelete);
|
|---|
| 336 | half[j]->Draw("same");
|
|---|
| 337 | leg2->AddEntry(half[j], half[j]->GetName(), "l");
|
|---|
| 338 | }
|
|---|
| 339 | leg2->Draw();
|
|---|
| 340 | }
|
|---|
| 341 | }
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | void MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
|
|---|
| 345 | {
|
|---|
| 346 |
|
|---|
| 347 | Double_t x = cam->GetNbinsX();
|
|---|
| 348 |
|
|---|
| 349 | const MGeomCam *geom = cam->GetGeometry();
|
|---|
| 350 |
|
|---|
| 351 | if (geom->InheritsFrom("MGeomCamMagic"))
|
|---|
| 352 | x = what ? 397 : cam->GetNbinsX();
|
|---|
| 353 |
|
|---|
| 354 | TLine line;
|
|---|
| 355 | line.SetLineStyle(kDashed);
|
|---|
| 356 | line.SetLineWidth(3);
|
|---|
| 357 |
|
|---|
| 358 | line.SetLineColor(kBlue);
|
|---|
| 359 | TLine *l1 = line.DrawLine(0, what ? fgRefPedRmsGalacticInner : fgRefPedGalactic,
|
|---|
| 360 | x, what ? fgRefPedRmsGalacticInner : fgRefPedGalactic);
|
|---|
| 361 |
|
|---|
| 362 | line.SetLineColor(kYellow);
|
|---|
| 363 | TLine *l2 = line.DrawLine(0, what ? fgRefPedRmsExtraGalacticInner : fgRefPedExtraGalactic,
|
|---|
| 364 | x, what ? fgRefPedRmsExtraGalacticInner : fgRefPedExtraGalactic);
|
|---|
| 365 |
|
|---|
| 366 | line.SetLineColor(kMagenta);
|
|---|
| 367 | TLine *l3 = line.DrawLine(0, what ? fgRefPedRmsClosedLidsInner : fgRefPedClosedLids,
|
|---|
| 368 | x, what ? fgRefPedRmsClosedLidsInner : fgRefPedClosedLids);
|
|---|
| 369 |
|
|---|
| 370 | if (geom->InheritsFrom("MGeomCamMagic"))
|
|---|
| 371 | if (what)
|
|---|
| 372 | {
|
|---|
| 373 | const Double_t x2 = cam->GetNbinsX();
|
|---|
| 374 |
|
|---|
| 375 | line.SetLineColor(kBlue);
|
|---|
| 376 | line.DrawLine(398, fgRefPedRmsGalacticOuter,
|
|---|
| 377 | x2, fgRefPedRmsGalacticOuter);
|
|---|
| 378 |
|
|---|
| 379 | line.SetLineColor(kYellow);
|
|---|
| 380 | line.DrawLine(398, fgRefPedRmsExtraGalacticOuter,
|
|---|
| 381 | x2, fgRefPedRmsExtraGalacticOuter);
|
|---|
| 382 |
|
|---|
| 383 | line.SetLineColor(kMagenta);
|
|---|
| 384 | line.DrawLine(398, fgRefPedRmsClosedLidsOuter,
|
|---|
| 385 | x2, fgRefPedRmsClosedLidsOuter);
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 | TLegend *leg = new TLegend(0.4,0.75,0.7,0.99);
|
|---|
| 390 | leg->SetBit(kCanDelete);
|
|---|
| 391 | leg->AddEntry(l1, "Galactic Source","l");
|
|---|
| 392 | leg->AddEntry(l2, "Extra-Galactic Source","l");
|
|---|
| 393 | leg->AddEntry(l3, "Closed Lids","l");
|
|---|
| 394 | leg->Draw();
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | void MJPedestal::DisplayOutliers(TH1D *hist) const
|
|---|
| 398 | {
|
|---|
| 399 | const Float_t mean = hist->GetFunction("gaus")->GetParameter(1);
|
|---|
| 400 | const Float_t lolim = mean - 3.5*hist->GetFunction("gaus")->GetParameter(2);
|
|---|
| 401 | const Float_t uplim = mean + 3.5*hist->GetFunction("gaus")->GetParameter(2);
|
|---|
| 402 | const Stat_t dead = hist->Integral(0,hist->FindBin(lolim)-1);
|
|---|
| 403 | const Stat_t noisy = hist->Integral(hist->FindBin(uplim)+1,hist->GetNbinsX()+1);
|
|---|
| 404 |
|
|---|
| 405 | TLatex deadtex;
|
|---|
| 406 | deadtex.SetTextSize(0.06);
|
|---|
| 407 | deadtex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.1,Form("%3i dead pixels",(Int_t)dead));
|
|---|
| 408 |
|
|---|
| 409 | TLatex noisytex;
|
|---|
| 410 | noisytex.SetTextSize(0.06);
|
|---|
| 411 | noisytex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.2,Form("%3i noisy pixels",(Int_t)noisy));
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | void MJPedestal::FixDataCheckHist(TH1D *hist) const
|
|---|
| 415 | {
|
|---|
| 416 |
|
|---|
| 417 | hist->SetDirectory(NULL);
|
|---|
| 418 | hist->SetStats(0);
|
|---|
| 419 |
|
|---|
| 420 | //
|
|---|
| 421 | // set the labels bigger
|
|---|
| 422 | //
|
|---|
| 423 | TAxis *xaxe = hist->GetXaxis();
|
|---|
| 424 | TAxis *yaxe = hist->GetYaxis();
|
|---|
| 425 |
|
|---|
| 426 | xaxe->CenterTitle();
|
|---|
| 427 | yaxe->CenterTitle();
|
|---|
| 428 | xaxe->SetTitleSize(0.06);
|
|---|
| 429 | yaxe->SetTitleSize(0.06);
|
|---|
| 430 | xaxe->SetTitleOffset(0.8);
|
|---|
| 431 | yaxe->SetTitleOffset(0.5);
|
|---|
| 432 | xaxe->SetLabelSize(0.05);
|
|---|
| 433 | yaxe->SetLabelSize(0.05);
|
|---|
| 434 |
|
|---|
| 435 | }
|
|---|
| 436 | /*
|
|---|
| 437 | Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const
|
|---|
| 438 | {
|
|---|
| 439 | if (fOutputPath.IsNull())
|
|---|
| 440 | return kTRUE;
|
|---|
| 441 |
|
|---|
| 442 | const TString oname(GetOutputFile());
|
|---|
| 443 |
|
|---|
| 444 | *fLog << inf << "Writing to file: " << oname << endl;
|
|---|
| 445 |
|
|---|
| 446 | TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJPedestal", 9);
|
|---|
| 447 | if (!file.IsOpen())
|
|---|
| 448 | {
|
|---|
| 449 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
|
|---|
| 450 | return kFALSE;
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | if (evtloop.Write(fName)<=0)
|
|---|
| 454 | {
|
|---|
| 455 | *fLog << err << "Unable to write MEvtloop to " << oname << endl;
|
|---|
| 456 | return kFALSE;
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | return kTRUE;
|
|---|
| 460 | }
|
|---|
| 461 | */
|
|---|
| 462 |
|
|---|
| 463 | // --------------------------------------------------------------------------
|
|---|
| 464 | //
|
|---|
| 465 | // The following resource options are available:
|
|---|
| 466 | // Prefix.DataCheckDisplay: Yes, No
|
|---|
| 467 | // Prefix.DataCheck: Yes, No
|
|---|
| 468 | // Prefix.UseData: Yes, No
|
|---|
| 469 | //
|
|---|
| 470 | Bool_t MJPedestal::CheckEnvLocal()
|
|---|
| 471 | {
|
|---|
| 472 | if (HasEnv("DataCheckDisplay"))
|
|---|
| 473 | fDisplayType = GetEnv("DataCheckDisplay", kFALSE) ? kDataCheckDisplay : kNormalDisplay;
|
|---|
| 474 |
|
|---|
| 475 | SetDataCheck(GetEnv("DataCheck", fDataCheck));
|
|---|
| 476 | SetUseData(GetEnv("UseData", fUseData));
|
|---|
| 477 |
|
|---|
| 478 | return kTRUE;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | Bool_t MJPedestal::WriteResult()
|
|---|
| 482 | {
|
|---|
| 483 | if (fPathOut.IsNull())
|
|---|
| 484 | return kTRUE;
|
|---|
| 485 |
|
|---|
| 486 | const TString oname(GetOutputFile());
|
|---|
| 487 |
|
|---|
| 488 | *fLog << inf << "Writing to file: " << oname << endl;
|
|---|
| 489 |
|
|---|
| 490 | TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
|
|---|
| 491 | if (!file.IsOpen())
|
|---|
| 492 | {
|
|---|
| 493 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
|
|---|
| 494 | return kFALSE;
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | if (fDisplay && fDisplay->Write()<=0)
|
|---|
| 498 | {
|
|---|
| 499 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
|---|
| 500 | return kFALSE;
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | if (fPedestalCam.Write()<=0)
|
|---|
| 504 | {
|
|---|
| 505 | *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
|
|---|
| 506 | return kFALSE;
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | if (fBadPixels.Write()<=0)
|
|---|
| 510 | {
|
|---|
| 511 | *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
|
|---|
| 512 | return kFALSE;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | return kTRUE;
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | Bool_t MJPedestal::Process()
|
|---|
| 519 | {
|
|---|
| 520 | if (!ReadPedestalCam())
|
|---|
| 521 | return ProcessFile();
|
|---|
| 522 |
|
|---|
| 523 | return kTRUE;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | Bool_t MJPedestal::ProcessFile()
|
|---|
| 527 | {
|
|---|
| 528 | if (!fSequence.IsValid())
|
|---|
| 529 | {
|
|---|
| 530 | if (!fRuns)
|
|---|
| 531 | {
|
|---|
| 532 | *fLog << err << "Neither AddRuns nor SetSequence nor SetEnv was called... abort." << endl;
|
|---|
| 533 | return kFALSE;
|
|---|
| 534 | }
|
|---|
| 535 | if (fRuns && fRuns->GetNumRuns() != fRuns->GetNumEntries())
|
|---|
| 536 | {
|
|---|
| 537 | *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
|
|---|
| 538 | return kFALSE;
|
|---|
| 539 | }
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | //if (!CheckEnv())
|
|---|
| 543 | // return kFALSE;
|
|---|
| 544 |
|
|---|
| 545 | CheckEnv();
|
|---|
| 546 |
|
|---|
| 547 | // --------------------------------------------------------------------------------
|
|---|
| 548 |
|
|---|
| 549 | const TString type = fUseData ? "data" : "pedestal";
|
|---|
| 550 |
|
|---|
| 551 | *fLog << inf;
|
|---|
| 552 | fLog->Separator(GetDescriptor());
|
|---|
| 553 | *fLog << "Calculate MPedestalCam from " << type << "-runs ";
|
|---|
| 554 | if (fSequence.IsValid())
|
|---|
| 555 | *fLog << fSequence.GetName() << endl;
|
|---|
| 556 | else
|
|---|
| 557 | if (fRuns)
|
|---|
| 558 | *fLog << fRuns->GetRunsAsString() << endl;
|
|---|
| 559 | else
|
|---|
| 560 | *fLog << "in Resource File." << endl;
|
|---|
| 561 | *fLog << endl;
|
|---|
| 562 |
|
|---|
| 563 | // --------------------------------------------------------------------------------
|
|---|
| 564 |
|
|---|
| 565 | MParList plist;
|
|---|
| 566 | MTaskList tlist;
|
|---|
| 567 | plist.AddToList(&tlist);
|
|---|
| 568 | plist.AddToList(this); // take care of fDisplay!
|
|---|
| 569 |
|
|---|
| 570 | MReadMarsFile read("Events");
|
|---|
| 571 | MRawFileRead rawread(NULL);
|
|---|
| 572 |
|
|---|
| 573 | MDirIter iter;
|
|---|
| 574 | if (fSequence.IsValid())
|
|---|
| 575 | {
|
|---|
| 576 | const Int_t n0 = fUseData ? fSequence.SetupDatRuns(iter, fPathData) : fSequence.SetupPedRuns(iter, fPathData);
|
|---|
| 577 | const Int_t n1 = fUseData ? fSequence.GetNumDatRuns() : fSequence.GetNumPedRuns();
|
|---|
| 578 | if (n0==0)
|
|---|
| 579 | {
|
|---|
| 580 | *fLog << err << "ERROR - No " << type << " input files of sequence found in " << fPathData << endl;
|
|---|
| 581 | return kFALSE;
|
|---|
| 582 | }
|
|---|
| 583 | if (n0!=n1)
|
|---|
| 584 | {
|
|---|
| 585 | *fLog << err << "ERROR - Number of " << type << " files found (" << n0 << ") in " << fPathData << " doesn't match number of files in sequence (" << n1 << ")" << endl;
|
|---|
| 586 | return kFALSE;
|
|---|
| 587 | }
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | if (fDataCheck)
|
|---|
| 591 | {
|
|---|
| 592 | if (fRuns || fSequence.IsValid())
|
|---|
| 593 | rawread.AddFiles(fSequence.IsValid() ? iter : *fRuns);
|
|---|
| 594 | tlist.AddToList(&rawread);
|
|---|
| 595 | }
|
|---|
| 596 | else
|
|---|
| 597 | {
|
|---|
| 598 | read.DisableAutoScheme();
|
|---|
| 599 | if (fRuns || fSequence.IsValid())
|
|---|
| 600 | read.AddFiles(fSequence.IsValid() ? iter : *fRuns);
|
|---|
| 601 | tlist.AddToList(&read);
|
|---|
| 602 | }
|
|---|
| 603 |
|
|---|
| 604 | // Setup Tasklist
|
|---|
| 605 | plist.AddToList(&fPedestalCam);
|
|---|
| 606 | plist.AddToList(&fBadPixels);
|
|---|
| 607 |
|
|---|
| 608 | MGeomApply geomapl;
|
|---|
| 609 | MBadPixelsMerge merge(&fBadPixels);
|
|---|
| 610 |
|
|---|
| 611 | MPedCalcPedRun pedcalc;
|
|---|
| 612 |
|
|---|
| 613 | MTaskEnv taskenv("ExtractPedestal");
|
|---|
| 614 | taskenv.SetDefault(&pedcalc);
|
|---|
| 615 |
|
|---|
| 616 | if (fExtractor)
|
|---|
| 617 | {
|
|---|
| 618 | pedcalc.SetWindowSize((Int_t)fExtractor->GetNumHiGainSamples());
|
|---|
| 619 | pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
|
|---|
| 620 | }
|
|---|
| 621 | /*
|
|---|
| 622 | else
|
|---|
| 623 | {
|
|---|
| 624 | *fLog << warn << GetDescriptor();
|
|---|
| 625 | *fLog << ": No extractor has been chosen, take default number of FADC samples " << endl;
|
|---|
| 626 | }
|
|---|
| 627 | */
|
|---|
| 628 |
|
|---|
| 629 | tlist.AddToList(&geomapl);
|
|---|
| 630 | tlist.AddToList(&merge);
|
|---|
| 631 | tlist.AddToList(&taskenv);
|
|---|
| 632 |
|
|---|
| 633 | //
|
|---|
| 634 | // Execute the eventloop
|
|---|
| 635 | //
|
|---|
| 636 | MEvtLoop evtloop(fName);
|
|---|
| 637 | evtloop.SetParList(&plist);
|
|---|
| 638 | evtloop.SetDisplay(fDisplay);
|
|---|
| 639 | evtloop.SetLogStream(fLog);
|
|---|
| 640 | if (!SetupEnv(evtloop))
|
|---|
| 641 | return kFALSE;
|
|---|
| 642 |
|
|---|
| 643 | // if (!WriteEventloop(evtloop))
|
|---|
| 644 | // return kFALSE;
|
|---|
| 645 |
|
|---|
| 646 | // Execute first analysis
|
|---|
| 647 | if (!evtloop.Eventloop(fMaxEvents))
|
|---|
| 648 | {
|
|---|
| 649 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
|---|
| 650 | return kFALSE;
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | tlist.PrintStatistics();
|
|---|
| 654 |
|
|---|
| 655 | DisplayResult(plist);
|
|---|
| 656 |
|
|---|
| 657 | if (!WriteResult())
|
|---|
| 658 | return kFALSE;
|
|---|
| 659 |
|
|---|
| 660 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
|---|
| 661 | *fLog << endl << endl;
|
|---|
| 662 |
|
|---|
| 663 | return kTRUE;
|
|---|
| 664 | }
|
|---|