| 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/2005 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2007 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | //  MJCut | 
|---|
| 28 | // | 
|---|
| 29 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 30 | #include "MJCut.h" | 
|---|
| 31 |  | 
|---|
| 32 | // Root | 
|---|
| 33 | #include <TEnv.h> | 
|---|
| 34 | #include <TFile.h> | 
|---|
| 35 |  | 
|---|
| 36 | // Environment | 
|---|
| 37 | #include "MLog.h" | 
|---|
| 38 | #include "MLogManip.h" | 
|---|
| 39 |  | 
|---|
| 40 | // Eventloop | 
|---|
| 41 | #include "MParList.h" | 
|---|
| 42 | #include "MTaskList.h" | 
|---|
| 43 | #include "MEvtLoop.h" | 
|---|
| 44 |  | 
|---|
| 45 | // Display | 
|---|
| 46 | #include "MStatusDisplay.h" | 
|---|
| 47 |  | 
|---|
| 48 | // Tasks | 
|---|
| 49 | #include "MReadReports.h" | 
|---|
| 50 | #include "MReadMarsFile.h" | 
|---|
| 51 | #include "MPrint.h" | 
|---|
| 52 | #include "MContinue.h" | 
|---|
| 53 | #include "MTaskEnv.h" | 
|---|
| 54 | #include "MPointingDevCalc.h" | 
|---|
| 55 | #include "MParameterCalc.h" | 
|---|
| 56 | #include "MSrcPosRndm.h" | 
|---|
| 57 | #include "MSrcPosCalc.h" | 
|---|
| 58 | #include "MSrcPosCorrect.h" | 
|---|
| 59 | #include "MHillasCalc.h" | 
|---|
| 60 | #include "MFillH.h" | 
|---|
| 61 | #include "MWriteRootFile.h" | 
|---|
| 62 |  | 
|---|
| 63 | // Filter | 
|---|
| 64 | //#include "MFDataMember.h" | 
|---|
| 65 |  | 
|---|
| 66 | // Fit signal environment | 
|---|
| 67 | #include "../mhflux/MAlphaFitter.h" | 
|---|
| 68 | #include "../mhflux/MHAlpha.h" | 
|---|
| 69 |  | 
|---|
| 70 | // Containers | 
|---|
| 71 | #include "MH3.h" | 
|---|
| 72 | #include "MBinning.h" | 
|---|
| 73 | #include "MDataSet.h" | 
|---|
| 74 | #include "MParameters.h" | 
|---|
| 75 | #include "MPointingPos.h" | 
|---|
| 76 | #include "MObservatory.h" | 
|---|
| 77 | #include "MHSrcPosCam.h" | 
|---|
| 78 |  | 
|---|
| 79 | ClassImp(MJCut); | 
|---|
| 80 |  | 
|---|
| 81 | using namespace std; | 
|---|
| 82 |  | 
|---|
| 83 | // -------------------------------------------------------------------------- | 
|---|
| 84 | // | 
|---|
| 85 | // Default constructor.  Set defaults for fStoreSummary, fStoreresult, | 
|---|
| 86 | // fWriteOnly, fFullDisplay to kFALSE and initialize | 
|---|
| 87 | // /*fEstimateEnergy and*/ fCalcHadronness with NULL. | 
|---|
| 88 | // | 
|---|
| 89 | MJCut::MJCut(const char *name, const char *title) | 
|---|
| 90 | : fStoreSummary(kFALSE), fStoreResult(kTRUE), fWriteOnly(kFALSE), | 
|---|
| 91 | fFullDisplay(kTRUE), fRndmSrcPos(kFALSE), fNumOffSourcePos(3), | 
|---|
| 92 | fNameHist("MHThetaSq"), | 
|---|
| 93 | fCalcHadronness(0), fCalcDisp(0), fEstimateEnergy(0) | 
|---|
| 94 | { | 
|---|
| 95 | fName  = name  ? name  : "MJCut"; | 
|---|
| 96 | fTitle = title ? title : "Standard program to perform g/h-separation cuts"; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | // -------------------------------------------------------------------------- | 
|---|
| 100 | // | 
|---|
| 101 | // Destructor. Delete fEstimateEnergy and fCalcHadronness if != NULL | 
|---|
| 102 | // | 
|---|
| 103 | MJCut::~MJCut() | 
|---|
| 104 | { | 
|---|
| 105 | if (fEstimateEnergy) | 
|---|
| 106 | delete fEstimateEnergy; | 
|---|
| 107 | if (fCalcHadronness) | 
|---|
| 108 | delete fCalcHadronness; | 
|---|
| 109 | if (fCalcDisp) | 
|---|
| 110 | delete fCalcDisp; | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | // -------------------------------------------------------------------------- | 
|---|
| 114 | // | 
|---|
| 115 | // Set the name of the summary file (events after cut0) | 
|---|
| 116 | // If you give a name the storage of this file is enabled implicitly. | 
|---|
| 117 | // If you give no filename the storage is neither enabled nor disabled, | 
|---|
| 118 | // but the storage file name is reset. | 
|---|
| 119 | // If no filename is set the default filename is used. | 
|---|
| 120 | // You can explicitly enable or disable the storage using EnableStoreOf*() | 
|---|
| 121 | // The default argument is no filename. | 
|---|
| 122 | // | 
|---|
| 123 | void MJCut::SetNameSummaryFile(const char *name) | 
|---|
| 124 | { | 
|---|
| 125 | fNameSummary=name; | 
|---|
| 126 | if (!fNameSummary.IsNull()) | 
|---|
| 127 | EnableStorageOfSummary(); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | // -------------------------------------------------------------------------- | 
|---|
| 131 | // | 
|---|
| 132 | // Set the name of the summary file (events after cut3) | 
|---|
| 133 | // If you give a name the storage of this file is enabled implicitly. | 
|---|
| 134 | // If you give no filename the storage is neither enabled nor disabled, | 
|---|
| 135 | // but the storage file name is reset. | 
|---|
| 136 | // If no filename is set the default filename is used. | 
|---|
| 137 | // You can explicitly enable or disable the storage using EnableStoreOf*() | 
|---|
| 138 | // The default argument is no filename. | 
|---|
| 139 | // | 
|---|
| 140 | void MJCut::SetNameResultFile(const char *name) | 
|---|
| 141 | { | 
|---|
| 142 | fNameResult=name; | 
|---|
| 143 | if (!fNameResult.IsNull()) | 
|---|
| 144 | EnableStorageOfResult(); | 
|---|
| 145 | } | 
|---|
| 146 |  | 
|---|
| 147 | // -------------------------------------------------------------------------- | 
|---|
| 148 | // | 
|---|
| 149 | // Setup a task estimating the energy. The given task is cloned. | 
|---|
| 150 | // | 
|---|
| 151 | /* | 
|---|
| 152 | void MJCut::SetEnergyEstimator(const MTask *task) | 
|---|
| 153 | { | 
|---|
| 154 | if (fEstimateEnergy) | 
|---|
| 155 | delete fEstimateEnergy; | 
|---|
| 156 | fEstimateEnergy = task ? (MTask*)task->Clone() : 0; | 
|---|
| 157 | } | 
|---|
| 158 | */ | 
|---|
| 159 |  | 
|---|
| 160 | // -------------------------------------------------------------------------- | 
|---|
| 161 | // | 
|---|
| 162 | // Setup a task calculating the hadronness. The given task is cloned. | 
|---|
| 163 | // | 
|---|
| 164 | void MJCut::SetHadronnessCalculator(const MTask *task) | 
|---|
| 165 | { | 
|---|
| 166 | if (fCalcHadronness) | 
|---|
| 167 | delete fCalcHadronness; | 
|---|
| 168 | fCalcHadronness = task ? (MTask*)task->Clone() : 0; | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | // -------------------------------------------------------------------------- | 
|---|
| 172 | // | 
|---|
| 173 | // Setup a task calculating disp. The given task is cloned. | 
|---|
| 174 | // | 
|---|
| 175 | void MJCut::SetDispCalculator(const MTask *task) | 
|---|
| 176 | { | 
|---|
| 177 | if (fCalcDisp) | 
|---|
| 178 | delete fCalcDisp; | 
|---|
| 179 | fCalcDisp = task ? (MTask*)task->Clone() : 0; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | // -------------------------------------------------------------------------- | 
|---|
| 183 | // | 
|---|
| 184 | // Setup a task estimating the eneryg. The given task is cloned. | 
|---|
| 185 | // | 
|---|
| 186 | void MJCut::SetEnergyEstimator(const MTask *task) | 
|---|
| 187 | { | 
|---|
| 188 | if (fEstimateEnergy) | 
|---|
| 189 | delete fEstimateEnergy; | 
|---|
| 190 | fEstimateEnergy = task ? (MTask*)task->Clone() : 0; | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | // -------------------------------------------------------------------------- | 
|---|
| 194 | // | 
|---|
| 195 | // return fOutputPath+"/ganymed%08d.root", num | 
|---|
| 196 | // | 
|---|
| 197 | TString MJCut::GetOutputFile(UInt_t num) const | 
|---|
| 198 | { | 
|---|
| 199 | TString p(fPathOut); | 
|---|
| 200 | p += "/"; | 
|---|
| 201 | p += fNameOutput.IsNull() ? Form("ganymed%08d.root", num) : fNameOutput.Data(); | 
|---|
| 202 | gSystem->ExpandPathName(p); | 
|---|
| 203 | return p; | 
|---|
| 204 | } | 
|---|
| 205 |  | 
|---|
| 206 | /* | 
|---|
| 207 | Bool_t MJCut::ReadTasks(const char *fname, MTask* &env1, MTask* &env2) const | 
|---|
| 208 | { | 
|---|
| 209 | //    const TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence()); | 
|---|
| 210 |  | 
|---|
| 211 | *fLog << inf << "Reading from file: " << fname << endl; | 
|---|
| 212 |  | 
|---|
| 213 | TFile file(fname, "READ"); | 
|---|
| 214 | if (!file.IsOpen()) | 
|---|
| 215 | { | 
|---|
| 216 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl; | 
|---|
| 217 | return kFALSE; | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | TObject *o = file.Get("EstimateEnergy"); | 
|---|
| 221 | if (o && !o->InheritsFrom(MTask::Class())) | 
|---|
| 222 | { | 
|---|
| 223 | *fLog << err << dbginf << "ERROR - EstimateEnergy read from " << fname << " doesn't inherit from MTask!" << endl; | 
|---|
| 224 | return kFALSE; | 
|---|
| 225 | } | 
|---|
| 226 | env1 = o ? (MTask*)o->Clone() : FNULL; | 
|---|
| 227 |  | 
|---|
| 228 | o = file.Get("CalcHadronness"); | 
|---|
| 229 | if (o && !o->InheritsFrom(MTask::Class())) | 
|---|
| 230 | { | 
|---|
| 231 | *fLog << err << dbginf << "ERROR - CalcHadronness read from " << fname << " doesn't inherit from MTask!" << endl; | 
|---|
| 232 | return kFALSE; | 
|---|
| 233 | } | 
|---|
| 234 | env2 = o ? (MTask*)o->Clone() : NULL; | 
|---|
| 235 |  | 
|---|
| 236 | return kTRUE; | 
|---|
| 237 | } | 
|---|
| 238 | */ | 
|---|
| 239 |  | 
|---|
| 240 | // -------------------------------------------------------------------------- | 
|---|
| 241 | // | 
|---|
| 242 | // Write the tasks in cont to the file corresponding to analysis number num, | 
|---|
| 243 | // see GetOutputFile() | 
|---|
| 244 | // | 
|---|
| 245 | Bool_t MJCut::WriteTasks(UInt_t num, TObjArray &cont) const | 
|---|
| 246 | { | 
|---|
| 247 | if (fPathOut.IsNull()) | 
|---|
| 248 | { | 
|---|
| 249 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl; | 
|---|
| 250 | return kTRUE; | 
|---|
| 251 | } | 
|---|
| 252 |  | 
|---|
| 253 | const TString oname(GetOutputFile(num)); | 
|---|
| 254 |  | 
|---|
| 255 | *fLog << inf << "Writing to file: " << oname << endl; | 
|---|
| 256 |  | 
|---|
| 257 | TFile *file = 0; | 
|---|
| 258 | if (fNameResult.IsNull() && fStoreResult) | 
|---|
| 259 | { | 
|---|
| 260 | file = (TFile*)gROOT->GetListOfFiles()->FindObject(oname); | 
|---|
| 261 | if (file) | 
|---|
| 262 | file->cd(); | 
|---|
| 263 | } | 
|---|
| 264 | else | 
|---|
| 265 | file = TFile::Open(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCut", 9); | 
|---|
| 266 |  | 
|---|
| 267 | if (!file) | 
|---|
| 268 | { | 
|---|
| 269 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl; | 
|---|
| 270 | return kFALSE; | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | const Bool_t rc = WriteContainer(cont); | 
|---|
| 274 |  | 
|---|
| 275 | if (!(fNameResult.IsNull() && fStoreResult)) | 
|---|
| 276 | delete file; | 
|---|
| 277 |  | 
|---|
| 278 | return rc; | 
|---|
| 279 | } | 
|---|
| 280 |  | 
|---|
| 281 | // -------------------------------------------------------------------------- | 
|---|
| 282 | // | 
|---|
| 283 | // Write the result plots and other results to the file corresponding to | 
|---|
| 284 | // analysis number num, see GetOutputFile() | 
|---|
| 285 | // | 
|---|
| 286 | Bool_t MJCut::WriteResult(const MParList &plist, const MDataSet &set) const | 
|---|
| 287 | { | 
|---|
| 288 | TObjArray arr; | 
|---|
| 289 |  | 
|---|
| 290 | // Save all MBinnings | 
|---|
| 291 | TIter Next(plist); | 
|---|
| 292 | TObject *o=0; | 
|---|
| 293 | while ((o=Next())) | 
|---|
| 294 | if (o->InheritsFrom(MBinning::Class())) | 
|---|
| 295 | arr.Add(o); | 
|---|
| 296 |  | 
|---|
| 297 | // Save also the result, not only the setup | 
|---|
| 298 | const MHAlpha *halpha = (MHAlpha*)plist.FindObject("Hist", "MHAlpha"); | 
|---|
| 299 | if (halpha) | 
|---|
| 300 | arr.Add((TObject*)(&halpha->GetAlphaFitter())); | 
|---|
| 301 |  | 
|---|
| 302 | // Save also the dataset | 
|---|
| 303 | arr.Add(const_cast<MDataSet*>(&set)); | 
|---|
| 304 |  | 
|---|
| 305 | const Int_t num = set.GetNumAnalysis(); | 
|---|
| 306 | const TString fname(fNameOutput.IsNull() ? Form("ganymed%08d.root", num) : fNameOutput.Data()); | 
|---|
| 307 |  | 
|---|
| 308 | // If requested, write to already open output file | 
|---|
| 309 | if (fNameResult.IsNull() && fStoreResult) | 
|---|
| 310 | { | 
|---|
| 311 | TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fname); | 
|---|
| 312 | if (file) | 
|---|
| 313 | { | 
|---|
| 314 | file->cd(); | 
|---|
| 315 | return WriteContainer(arr); | 
|---|
| 316 | } | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | if (fDisplay) | 
|---|
| 320 | arr.Add(fDisplay); | 
|---|
| 321 |  | 
|---|
| 322 | arr.Add(const_cast<TEnv*>(GetEnv())); | 
|---|
| 323 |  | 
|---|
| 324 | return WriteContainer(arr, fname, "UPDATE"); | 
|---|
| 325 | } | 
|---|
| 326 |  | 
|---|
| 327 | // -------------------------------------------------------------------------- | 
|---|
| 328 | // | 
|---|
| 329 | // MJCut allows to setup several option by a resource file: | 
|---|
| 330 | //   MJCut.WriteSummary: yes, no | 
|---|
| 331 | //   MJCut.SummaryFile:  filename | 
|---|
| 332 | //   MJCut.WriteResult:  yes, no | 
|---|
| 333 | //   MJCut.ResultFile:   filename | 
|---|
| 334 | //   MJCut.HistName:     MHAlpha | 
|---|
| 335 | // | 
|---|
| 336 | Bool_t MJCut::CheckEnvLocal() | 
|---|
| 337 | { | 
|---|
| 338 | const TString f0(GetEnv("SummaryFile", "")); | 
|---|
| 339 | const TString f1(GetEnv("ResultFile",  "")); | 
|---|
| 340 | if (!f0.IsNull()) | 
|---|
| 341 | SetNameSummaryFile(f0); | 
|---|
| 342 | if (!f1.IsNull()) | 
|---|
| 343 | SetNameResultFile(f1); | 
|---|
| 344 |  | 
|---|
| 345 | EnableStorageOfSummary(GetEnv("SummaryFile", fStoreSummary)); | 
|---|
| 346 | EnableStorageOfResult(GetEnv("ResultFile", fStoreResult)); | 
|---|
| 347 | EnableFullDisplay(GetEnv("FullDisplay", fFullDisplay)); | 
|---|
| 348 | EnableRandomSrcPos(GetEnv("RandomSourcePosition", fRndmSrcPos)); | 
|---|
| 349 |  | 
|---|
| 350 | fNumOffSourcePos = GetEnv("NumOffSourcePositions", (Int_t)fNumOffSourcePos); | 
|---|
| 351 | //EnableSubstraction(GetEnv("HistogramSubstraction", fSubstraction)); | 
|---|
| 352 |  | 
|---|
| 353 | SetNameHist(GetEnv("NameHist", fNameHist)); | 
|---|
| 354 | SetNameHistFS(GetEnv("NameHistFS", fNameHistFS)); | 
|---|
| 355 |  | 
|---|
| 356 | return kTRUE; | 
|---|
| 357 | } | 
|---|
| 358 |  | 
|---|
| 359 | // -------------------------------------------------------------------------- | 
|---|
| 360 | // | 
|---|
| 361 | // Setup write to write: | 
|---|
| 362 | //     container         tree       optional? | 
|---|
| 363 | //  --------------     ----------  ----------- | 
|---|
| 364 | //   "MHillas"      to  "Events" | 
|---|
| 365 | //   "MHillasSrc"   to  "Events" | 
|---|
| 366 | //   "Hadronness"   to  "Events"       yes | 
|---|
| 367 | //   "MEnergyEst"   to  "Events"       yes | 
|---|
| 368 | //   "DataType"     to  "Events" | 
|---|
| 369 | // | 
|---|
| 370 | void MJCut::SetupWriter(MWriteRootFile *write, const char *name) const | 
|---|
| 371 | { | 
|---|
| 372 | if (!write) | 
|---|
| 373 | return; | 
|---|
| 374 |  | 
|---|
| 375 | write->SetName(name); | 
|---|
| 376 | write->AddContainer("MHillas",        "Events"); | 
|---|
| 377 | write->AddContainer("MHillasSrc",     "Events"); | 
|---|
| 378 | write->AddContainer("MHillasExt",     "Events"); | 
|---|
| 379 | write->AddContainer("MPointingPos",   "Events"); | 
|---|
| 380 | write->AddContainer("MHillasSrcAnti", "Events", kFALSE); | 
|---|
| 381 | write->AddContainer("MImagePar",      "Events", kFALSE); | 
|---|
| 382 | write->AddContainer("MNewImagePar",   "Events", kFALSE); | 
|---|
| 383 | write->AddContainer("MNewImagePar2",  "Events", kFALSE); | 
|---|
| 384 | write->AddContainer("Hadronness",     "Events", kFALSE); | 
|---|
| 385 | write->AddContainer("MSrcPosCam",     "Events", kFALSE); | 
|---|
| 386 | write->AddContainer("MSrcPosAnti",    "Events", kFALSE); | 
|---|
| 387 | write->AddContainer("ThetaSquared",   "Events", kFALSE); | 
|---|
| 388 | write->AddContainer("OpticalAxis",    "Events", kFALSE); | 
|---|
| 389 | write->AddContainer("Disp",           "Events", kFALSE); | 
|---|
| 390 | write->AddContainer("Ghostbuster",    "Events", kFALSE); | 
|---|
| 391 | write->AddContainer("MEnergyEst",     "Events", kFALSE); | 
|---|
| 392 | write->AddContainer("MTime",          "Events", kFALSE); | 
|---|
| 393 | write->AddContainer("MMcEvt",         "Events", kFALSE); | 
|---|
| 394 | write->AddContainer("DataType",       "Events"); | 
|---|
| 395 | write->AddContainer("RunNumber",      "Events"); | 
|---|
| 396 | write->AddContainer("EvtNumber",      "Events"); | 
|---|
| 397 | //    write->AddContainer("MMuonSearchPar", "Events", kFALSE); | 
|---|
| 398 | //    write->AddContainer("MMuonCalibPar",  "Events", kFALSE); | 
|---|
| 399 | } | 
|---|
| 400 |  | 
|---|
| 401 | // -------------------------------------------------------------------------- | 
|---|
| 402 | // | 
|---|
| 403 | // Create a new instance of an object with name name of class | 
|---|
| 404 | // type fNameHist in parlist. It must derive from MHAlpha. | 
|---|
| 405 | // Call ForceUsingSize for it and return its pointer. | 
|---|
| 406 | // If something fails NULL is returned. | 
|---|
| 407 | // | 
|---|
| 408 | MHAlpha *MJCut::CreateNewHist(MParList &plist, const char *name) const | 
|---|
| 409 | { | 
|---|
| 410 | TClass *cls = gROOT->GetClass(fNameHist); | 
|---|
| 411 | if (!cls) | 
|---|
| 412 | { | 
|---|
| 413 | *fLog << err << "Class " << fNameHist << " not found in dictionary... abort." << endl; | 
|---|
| 414 | return NULL; | 
|---|
| 415 | } | 
|---|
| 416 | if (!cls->InheritsFrom(MHAlpha::Class())) | 
|---|
| 417 | { | 
|---|
| 418 | *fLog << err << "Class " << fNameHist << " doesn't inherit from MHAlpha... abort." << endl; | 
|---|
| 419 | return NULL; | 
|---|
| 420 | } | 
|---|
| 421 |  | 
|---|
| 422 | const TString objname(Form("Hist%s", name)); | 
|---|
| 423 | MHAlpha *h = (MHAlpha*)plist.FindCreateObj(fNameHist, objname); | 
|---|
| 424 | if (!h) | 
|---|
| 425 | return NULL; | 
|---|
| 426 |  | 
|---|
| 427 | h->ForceUsingSize(); | 
|---|
| 428 |  | 
|---|
| 429 | return h; | 
|---|
| 430 | } | 
|---|
| 431 |  | 
|---|
| 432 | // -------------------------------------------------------------------------- | 
|---|
| 433 | // | 
|---|
| 434 | // Create a new instance of an object with name name of class | 
|---|
| 435 | // type fNameHistFS in parlist. It must derive from MHFalseSource | 
|---|
| 436 | // If something fails NULL is returned. | 
|---|
| 437 | // | 
|---|
| 438 | MH *MJCut::CreateNewHistFS(MParList &plist, const char *name) const | 
|---|
| 439 | { | 
|---|
| 440 | const TString cname(fNameHistFS.IsNull()?"MHFalseSource":fNameHistFS.Data()); | 
|---|
| 441 |  | 
|---|
| 442 | TClass *cls = gROOT->GetClass(cname); | 
|---|
| 443 | if (!cls) | 
|---|
| 444 | { | 
|---|
| 445 | *fLog << err << "Class " << cname << " not found in dictionary... abort." << endl; | 
|---|
| 446 | return NULL; | 
|---|
| 447 | } | 
|---|
| 448 | if (!cls->InheritsFrom("MHFalseSource")) | 
|---|
| 449 | { | 
|---|
| 450 | *fLog << err << "Class " << cname << " doesn't inherit from MHFalseSource... abort." << endl; | 
|---|
| 451 | return NULL; | 
|---|
| 452 | } | 
|---|
| 453 |  | 
|---|
| 454 | const TString objname(Form("FS%s", name)); | 
|---|
| 455 | return (MH*)plist.FindCreateObj(cname, objname); | 
|---|
| 456 | } | 
|---|
| 457 |  | 
|---|
| 458 | Bool_t MJCut::FillSrcPosCam(const MDataSet &set, MPointingPos &source, MHSrcPosCam &hsrcpos) | 
|---|
| 459 | { | 
|---|
| 460 | *fLog << inf; | 
|---|
| 461 | fLog->Separator(GetDescriptor()); | 
|---|
| 462 | *fLog << "Filling MHSrcPosCam " << set.GetName() << endl; | 
|---|
| 463 | *fLog << endl; | 
|---|
| 464 |  | 
|---|
| 465 | // -------------------------------------------------------------------------------- | 
|---|
| 466 |  | 
|---|
| 467 | // Setup Parlist | 
|---|
| 468 | MParList plist; | 
|---|
| 469 | plist.AddToList(this); // take care of fDisplay! | 
|---|
| 470 |  | 
|---|
| 471 | // Setup Tasklist | 
|---|
| 472 | MTaskList tlist; | 
|---|
| 473 | plist.AddToList(&tlist); | 
|---|
| 474 |  | 
|---|
| 475 | // La Palma Magic1, Possible source position | 
|---|
| 476 | MObservatory obs; | 
|---|
| 477 | plist.AddToList(&obs); | 
|---|
| 478 | plist.AddToList(&source); | 
|---|
| 479 |  | 
|---|
| 480 | // Initialize default binnings | 
|---|
| 481 | // MBinning bins1(18,  0,     90,    "BinningSrcPosCam", "lin"); | 
|---|
| 482 | // plist.AddToList(&bins1); | 
|---|
| 483 |  | 
|---|
| 484 | // ------------- Loop Off Data -------------------- | 
|---|
| 485 | MReadReports read; | 
|---|
| 486 |  | 
|---|
| 487 | read.EnableAutoScheme(); | 
|---|
| 488 | read.AddToBranchList("MTimeEffectiveOnTime.*"); | 
|---|
| 489 | read.AddToBranchList("MEffectiveOnTime.*"); | 
|---|
| 490 |  | 
|---|
| 491 | read.AddTree("Events", "MTime.", MReadReports::kMaster); | 
|---|
| 492 | read.AddTree("Drive",            MReadReports::kRequired); | 
|---|
| 493 | read.AddTree("Starguider",       MReadReports::kRequired); | 
|---|
| 494 | read.AddTree("EffectiveOnTime"); | 
|---|
| 495 |  | 
|---|
| 496 | if (!set.AddFilesOn(read)) | 
|---|
| 497 | return kFALSE; | 
|---|
| 498 |  | 
|---|
| 499 | MFillH fill(&hsrcpos, "MSrcPosCam", "FillSrcPosCam"); | 
|---|
| 500 | fill.SetNameTab("SrcPos"); | 
|---|
| 501 |  | 
|---|
| 502 | // How to get source position from off- and on-data? | 
|---|
| 503 | MSrcPosCorrect scor; | 
|---|
| 504 | MSrcPosCalc    scalc; | 
|---|
| 505 | scalc.SetMode(MSrcPosCalc::kDefault); | 
|---|
| 506 |  | 
|---|
| 507 | MPointingDevCalc devcalc; | 
|---|
| 508 |  | 
|---|
| 509 | tlist.AddToList(&read); | 
|---|
| 510 | tlist.AddToList(&devcalc, "Starguider"); | 
|---|
| 511 | tlist.AddToList(&scalc,   "Events"); | 
|---|
| 512 | tlist.AddToList(&scor,    "Events"); | 
|---|
| 513 | tlist.AddToList(&fill,    "Events"); | 
|---|
| 514 |  | 
|---|
| 515 | // by setting it here it is distributed to all consecutive tasks | 
|---|
| 516 | tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime); | 
|---|
| 517 |  | 
|---|
| 518 | // Create and setup the eventloop | 
|---|
| 519 | MEvtLoop evtloop(fName); | 
|---|
| 520 | evtloop.SetParList(&plist); | 
|---|
| 521 | evtloop.SetDisplay(fDisplay); | 
|---|
| 522 | evtloop.SetLogStream(fLog); | 
|---|
| 523 | if (!SetupEnv(evtloop)) | 
|---|
| 524 | return kFALSE; | 
|---|
| 525 |  | 
|---|
| 526 | // Execute first analysis | 
|---|
| 527 | if (!evtloop.Eventloop(fMaxEvents)) | 
|---|
| 528 | { | 
|---|
| 529 | *fLog << err << GetDescriptor() << ": Processing of on-sequences to fill SrcPosCam failed." << endl; | 
|---|
| 530 | return kFALSE; | 
|---|
| 531 | } | 
|---|
| 532 |  | 
|---|
| 533 | if (!evtloop.GetDisplay()) | 
|---|
| 534 | { | 
|---|
| 535 | *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl; | 
|---|
| 536 | return kFALSE; | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 | *fLog << all << GetDescriptor() << ": Done." << endl; | 
|---|
| 540 | *fLog << endl << endl; | 
|---|
| 541 |  | 
|---|
| 542 | return kTRUE; | 
|---|
| 543 | } | 
|---|
| 544 |  | 
|---|
| 545 | Int_t MJCut::Process(const MDataSet &set) | 
|---|
| 546 | { | 
|---|
| 547 | if (!set.IsValid()) | 
|---|
| 548 | { | 
|---|
| 549 | *fLog << err << "ERROR - DataSet invalid!" << endl; | 
|---|
| 550 | return kFALSE; | 
|---|
| 551 | } | 
|---|
| 552 |  | 
|---|
| 553 | CheckEnv(); | 
|---|
| 554 |  | 
|---|
| 555 | // -------------------------------------------------------------------------------- | 
|---|
| 556 |  | 
|---|
| 557 | if (!set.IsWobbleMode() && fNumOffSourcePos!=1) | 
|---|
| 558 | { | 
|---|
| 559 | *fLog << inf << "No wobble mode but NumOffSoucePos!=1 (" << fNumOffSourcePos << ")... reset to 1." << endl; | 
|---|
| 560 | fNumOffSourcePos = 1; | 
|---|
| 561 | } | 
|---|
| 562 |  | 
|---|
| 563 | // Possible source position (eg. Wobble Mode) | 
|---|
| 564 | MPointingPos source("MSourcePos"); | 
|---|
| 565 | if (set.HasSource()) | 
|---|
| 566 | { | 
|---|
| 567 | if (!set.GetSourcePos(source)) | 
|---|
| 568 | return -1; | 
|---|
| 569 | *fLog << all; | 
|---|
| 570 | source.Print("RaDec"); | 
|---|
| 571 | } | 
|---|
| 572 | else | 
|---|
| 573 | *fLog << all << "No source position applied..." << endl; | 
|---|
| 574 |  | 
|---|
| 575 | MParList plist; | 
|---|
| 576 |  | 
|---|
| 577 | MHSrcPosCam hsrcpos(set.IsWobbleMode()); | 
|---|
| 578 | if (!set.IsWobbleMode() && source.IsInitialized() && fRndmSrcPos) | 
|---|
| 579 | { | 
|---|
| 580 | if (!FillSrcPosCam(set, source, hsrcpos)) | 
|---|
| 581 | return -2; | 
|---|
| 582 | plist.AddToList(&hsrcpos); | 
|---|
| 583 | } | 
|---|
| 584 |  | 
|---|
| 585 | // -------------------------------------------------------------------------------- | 
|---|
| 586 |  | 
|---|
| 587 | *fLog << inf; | 
|---|
| 588 | fLog->Separator(GetDescriptor()); | 
|---|
| 589 | *fLog << "Perform cuts for data set " << set.GetName() << endl; | 
|---|
| 590 | *fLog << endl; | 
|---|
| 591 |  | 
|---|
| 592 | // -------------------------------------------------------------------------------- | 
|---|
| 593 |  | 
|---|
| 594 | // Setup Parlist | 
|---|
| 595 | plist.AddToList(this); // take care of fDisplay! | 
|---|
| 596 |  | 
|---|
| 597 | MParameterI par("DataType"); | 
|---|
| 598 | plist.AddToList(&par); | 
|---|
| 599 |  | 
|---|
| 600 | // Setup Tasklist | 
|---|
| 601 | MTaskList tlist; | 
|---|
| 602 | plist.AddToList(&tlist); | 
|---|
| 603 |  | 
|---|
| 604 | // La Palma Magic1 | 
|---|
| 605 | MObservatory obs; | 
|---|
| 606 | plist.AddToList(&obs); | 
|---|
| 607 |  | 
|---|
| 608 | if (source.IsInitialized()) | 
|---|
| 609 | plist.AddToList(&source); | 
|---|
| 610 |  | 
|---|
| 611 | // Initialize default binnings | 
|---|
| 612 | MBinning bins1( 18,  0,     90,    "BinningAlpha",  "lin"); | 
|---|
| 613 | MBinning bins2( 15, 10,     1e6 ,  "BinningSize",   "log"); | 
|---|
| 614 | MBinning bins3( 67, -0.005, 0.665, "BinningTheta",  "asin"); | 
|---|
| 615 | //MBinning binsT(150,  0,     150,   "BinningDeltaT", "lin"); | 
|---|
| 616 | MBinning bins4("BinningFalseSource"); | 
|---|
| 617 | MBinning bins5("BinningWidth"); | 
|---|
| 618 | MBinning bins6("BinningLength"); | 
|---|
| 619 | MBinning bins7("BinningDist"); | 
|---|
| 620 | MBinning bins8("BinningSlope"); | 
|---|
| 621 | MBinning bins9("BinningM3Long"); | 
|---|
| 622 | MBinning bins0("BinningM3Trans"); | 
|---|
| 623 | MBinning binsa("BinningAsym"); | 
|---|
| 624 | MBinning binsb("BinningConc1"); | 
|---|
| 625 | plist.AddToList(&bins1); | 
|---|
| 626 | plist.AddToList(&bins2); | 
|---|
| 627 | plist.AddToList(&bins3); | 
|---|
| 628 | plist.AddToList(&bins4); | 
|---|
| 629 | plist.AddToList(&bins5); | 
|---|
| 630 | plist.AddToList(&bins6); | 
|---|
| 631 | plist.AddToList(&bins7); | 
|---|
| 632 | plist.AddToList(&bins8); | 
|---|
| 633 | plist.AddToList(&bins9); | 
|---|
| 634 | plist.AddToList(&bins0); | 
|---|
| 635 | plist.AddToList(&binsa); | 
|---|
| 636 | plist.AddToList(&binsb); | 
|---|
| 637 | //plist.AddToList(&binsT); | 
|---|
| 638 |  | 
|---|
| 639 | // -------------------------------------------------------------------------------- | 
|---|
| 640 |  | 
|---|
| 641 | MParameterD scale; | 
|---|
| 642 | scale.SetVal(1./fNumOffSourcePos); | 
|---|
| 643 |  | 
|---|
| 644 | // Setup fitter and histograms | 
|---|
| 645 | MAlphaFitter fit; | 
|---|
| 646 | plist.AddToList(&fit); | 
|---|
| 647 | if (set.IsWobbleMode()) | 
|---|
| 648 | fit.SetScaleUser(1./fNumOffSourcePos); // includes fit.SetScaleMode(MAlphaFitter::kUserScale); | 
|---|
| 649 |  | 
|---|
| 650 | MHAlpha *halphaoff = CreateNewHist(plist, "Off"); | 
|---|
| 651 | MFillH falpha(halphaoff, "", "FillHist"); | 
|---|
| 652 | MH *hfsoff = CreateNewHistFS(plist, "Off"); | 
|---|
| 653 | MFillH ffs(hfsoff, "MHillas", "FillFS"); | 
|---|
| 654 |  | 
|---|
| 655 | // FIXME: If fPathIn read cuts and energy estimator from file! | 
|---|
| 656 | MContinue contq("", "CutQ"); | 
|---|
| 657 | MContinue cont0("", "Cut0"); | 
|---|
| 658 | MContinue cont1("", "Cut1"); | 
|---|
| 659 | MContinue cont2("", "Cut2"); | 
|---|
| 660 | MContinue cont3("", "Cut3"); | 
|---|
| 661 | contq.SetAllowEmpty(); | 
|---|
| 662 | cont0.SetAllowEmpty(); | 
|---|
| 663 | cont1.SetAllowEmpty(); | 
|---|
| 664 | cont2.SetAllowEmpty(); | 
|---|
| 665 | cont3.SetAllowEmpty(); | 
|---|
| 666 |  | 
|---|
| 667 | // ------------- Loop Off Data -------------------- | 
|---|
| 668 | MReadReports readoffdata; | 
|---|
| 669 | readoffdata.AddTree("Events", "MTime.", MReadReports::kMaster); | 
|---|
| 670 | readoffdata.AddTree("Drive",            MReadReports::kRequired); | 
|---|
| 671 | readoffdata.AddTree("Starguider",       MReadReports::kRequired); | 
|---|
| 672 | readoffdata.AddTree("EffectiveOnTime"); | 
|---|
| 673 |  | 
|---|
| 674 | MReadMarsFile readoffmc("Events"); | 
|---|
| 675 | readoffmc.DisableAutoScheme(); | 
|---|
| 676 |  | 
|---|
| 677 | MRead &readoff = set.IsMonteCarlo() ? (MRead&)readoffmc : (MRead&)readoffdata; | 
|---|
| 678 | const Bool_t setrc = set.IsWobbleMode() ? set.AddFilesOn(readoff) : set.AddFilesOff(readoff); | 
|---|
| 679 | if (!setrc && set.HasOffSequences()) | 
|---|
| 680 | { | 
|---|
| 681 | *fLog << err << "MDataSet::AddFiles" << (set.IsWobbleMode()?"On":"Off") << " failed." << endl; | 
|---|
| 682 | return kFALSE; | 
|---|
| 683 | } | 
|---|
| 684 |  | 
|---|
| 685 | const TString path(Form("%s/", fPathOut.Data())); | 
|---|
| 686 | TString fname0(path); | 
|---|
| 687 | TString fname1(path); | 
|---|
| 688 | fname0 += fNameSummary.IsNull() ?  (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary; | 
|---|
| 689 | fname1 += fNameResult.IsNull()  ?  (TString) Form("ganymed%08d.root",         set.GetNumAnalysis()) : fNameResult; | 
|---|
| 690 |  | 
|---|
| 691 | MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0; | 
|---|
| 692 | MWriteRootFile *write1 = CanStoreResult()  ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0; | 
|---|
| 693 | SetupWriter(write0, "WriteAfterCut0"); | 
|---|
| 694 | SetupWriter(write1, "WriteAfterCut3"); | 
|---|
| 695 |  | 
|---|
| 696 | MTaskEnv taskenv2("CalcHadronness"); | 
|---|
| 697 | taskenv2.SetDefault(fCalcHadronness); | 
|---|
| 698 |  | 
|---|
| 699 | MTaskEnv taskenv3("CalcDisp"); | 
|---|
| 700 | taskenv3.SetDefault(fCalcDisp); | 
|---|
| 701 |  | 
|---|
| 702 | MTaskEnv taskenv4("EstimateEnergy"); | 
|---|
| 703 | taskenv4.SetDefault(fEstimateEnergy); | 
|---|
| 704 |  | 
|---|
| 705 | MParameterCalc setevtnum("MRawEvtHeader.fDAQEvtNumber", "SetEvtNumber"); | 
|---|
| 706 | setevtnum.SetNameParameter("EvtNumber"); | 
|---|
| 707 |  | 
|---|
| 708 | MParameterCalc setrunnum("MRawRunHeader.fRunNumber", "SetRunNumber"); | 
|---|
| 709 | setrunnum.SetNameParameter("RunNumber"); | 
|---|
| 710 |  | 
|---|
| 711 | MFillH fill1a("MHHillasOffPre  [MHHillas]",      "MHillas",      "FillHillasPre"); | 
|---|
| 712 | MFillH fill2a("MHHillasOffPost [MHHillas]",      "MHillas",      "FillHillasPost"); | 
|---|
| 713 | MFillH fill3a("MHVsSizeOffPost [MHVsSize]",      "MHillasSrc",   "FillVsSizePost"); | 
|---|
| 714 | MFillH fill4a("MHHilExtOffPost [MHHillasExt]",   "MHillasSrc",   "FillHilExtPost"); | 
|---|
| 715 | MFillH fill5a("MHHilSrcOffPost [MHHillasSrc]",   "MHillasSrc",   "FillHilSrcPost"); | 
|---|
| 716 | MFillH fill6a("MHImgParOffPost [MHImagePar]",    "MImagePar",    "FillImgParPost"); | 
|---|
| 717 | MFillH fill7a("MHNewParOffPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost"); | 
|---|
| 718 | //MFillH fill9a("MHEffOffTime    [MHEffectiveOnTime]", "MTime",        "FillEffOnTime"); | 
|---|
| 719 | fill1a.SetNameTab("PreCut"); | 
|---|
| 720 | fill2a.SetNameTab("PostCut"); | 
|---|
| 721 | fill3a.SetNameTab("VsSize"); | 
|---|
| 722 | fill4a.SetNameTab("HilExt"); | 
|---|
| 723 | fill5a.SetNameTab("HilSrc"); | 
|---|
| 724 | fill6a.SetNameTab("ImgPar"); | 
|---|
| 725 | fill7a.SetNameTab("NewPar"); | 
|---|
| 726 | //fill9a.SetNameTab("EffOffT"); | 
|---|
| 727 |  | 
|---|
| 728 | //MFDataMember fbin("Bin.fVal", '>', 0); | 
|---|
| 729 | //fill9a.SetFilter(&fbin); | 
|---|
| 730 |  | 
|---|
| 731 | MPrint print2("MEffectiveOnTime"); | 
|---|
| 732 | print2.EnableSkip(); | 
|---|
| 733 |  | 
|---|
| 734 | MTaskList tlist2; | 
|---|
| 735 | if (set.IsWobbleMode()) | 
|---|
| 736 | { | 
|---|
| 737 | tlist2.SetNumPasses(fNumOffSourcePos); | 
|---|
| 738 | fill2a.SetWeight(&scale); | 
|---|
| 739 | fill3a.SetWeight(&scale); | 
|---|
| 740 | fill4a.SetWeight(&scale); | 
|---|
| 741 | fill5a.SetWeight(&scale); | 
|---|
| 742 | fill6a.SetWeight(&scale); | 
|---|
| 743 | fill7a.SetWeight(&scale); | 
|---|
| 744 | } | 
|---|
| 745 |  | 
|---|
| 746 | // How to get source position from off- and on-data? | 
|---|
| 747 | MSrcPosCalc scalc; | 
|---|
| 748 | scalc.SetMode(set.IsWobbleMode()?MSrcPosCalc::kWobble:MSrcPosCalc::kOffData); /********************/ | 
|---|
| 749 | scalc.SetCallback(&tlist2); | 
|---|
| 750 |  | 
|---|
| 751 | MSrcPosCorrect scor; | 
|---|
| 752 |  | 
|---|
| 753 | MHillasCalc hcalc; | 
|---|
| 754 | MHillasCalc hcalc2("MHillasCalcAnti"); | 
|---|
| 755 | hcalc.SetFlags(MHillasCalc::kCalcHillasSrc); | 
|---|
| 756 | hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc); | 
|---|
| 757 | hcalc2.SetNameHillasSrc("MHillasSrcAnti"); | 
|---|
| 758 | hcalc2.SetNameSrcPosCam("MSrcPosAnti"); | 
|---|
| 759 |  | 
|---|
| 760 | MSrcPosRndm srcrndm; | 
|---|
| 761 |  | 
|---|
| 762 | MH3 hvs("MPointingPos.fZd"); | 
|---|
| 763 | hvs.SetName("ThetaOff;Theta"); | 
|---|
| 764 | hvs.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]"); | 
|---|
| 765 |  | 
|---|
| 766 | MFillH fillvs(&hvs, "", "FillOnTime"); | 
|---|
| 767 | if (!set.IsMonteCarlo()) | 
|---|
| 768 | fillvs.SetWeight("MEffectiveOnTime"); | 
|---|
| 769 | fillvs.SetNameTab("OnTime"); | 
|---|
| 770 |  | 
|---|
| 771 | // It is not really necessary to re-calculate the image parameters | 
|---|
| 772 | // for the the on-source for MCs, but it is done for symmetry reasons | 
|---|
| 773 | if (set.IsMonteCarlo()) | 
|---|
| 774 | tlist2.AddToList(&fillvs); | 
|---|
| 775 |  | 
|---|
| 776 | tlist2.AddToList(&scalc); | 
|---|
| 777 | tlist2.AddToList(&scor); | 
|---|
| 778 | tlist2.AddToList(&srcrndm); | 
|---|
| 779 | tlist2.AddToList(&hcalc); | 
|---|
| 780 | if (set.IsWobbleMode()) | 
|---|
| 781 | tlist2.AddToList(&hcalc2); | 
|---|
| 782 | //tlist2.AddToList(&taskenv1); | 
|---|
| 783 | tlist2.AddToList(&cont0); | 
|---|
| 784 | tlist2.AddToList(&taskenv2); | 
|---|
| 785 | tlist2.AddToList(&taskenv3); | 
|---|
| 786 | tlist2.AddToList(&setrunnum); | 
|---|
| 787 | tlist2.AddToList(&setevtnum); | 
|---|
| 788 | if (write0) | 
|---|
| 789 | tlist2.AddToList(write0); | 
|---|
| 790 | tlist2.AddToList(&cont1); | 
|---|
| 791 | if (!fWriteOnly && (!set.IsWobbleMode() || !fNameHistFS.IsNull())) | 
|---|
| 792 | tlist2.AddToList(&ffs); | 
|---|
| 793 | tlist2.AddToList(&cont2); | 
|---|
| 794 | if (!fWriteOnly) | 
|---|
| 795 | { | 
|---|
| 796 | tlist2.AddToList(&fill2a); | 
|---|
| 797 | if (fFullDisplay) | 
|---|
| 798 | { | 
|---|
| 799 | tlist2.AddToList(&fill3a); | 
|---|
| 800 | tlist2.AddToList(&fill4a); | 
|---|
| 801 | tlist2.AddToList(&fill5a); | 
|---|
| 802 | tlist2.AddToList(&fill6a); | 
|---|
| 803 | tlist2.AddToList(&fill7a); | 
|---|
| 804 | } | 
|---|
| 805 | } | 
|---|
| 806 | if (!fWriteOnly) | 
|---|
| 807 | { | 
|---|
| 808 | tlist2.AddToList(&falpha); | 
|---|
| 809 | /* if (!fIsMonteCarlo) | 
|---|
| 810 | { | 
|---|
| 811 | tlist2.AddToList(&fbin); | 
|---|
| 812 | tlist2.AddToList(&fill9a); | 
|---|
| 813 | } */ | 
|---|
| 814 | } | 
|---|
| 815 | tlist2.AddToList(&cont3); | 
|---|
| 816 | tlist2.AddToList(&taskenv4); | 
|---|
| 817 |  | 
|---|
| 818 | if (write1) | 
|---|
| 819 | tlist2.AddToList(write1); | 
|---|
| 820 |  | 
|---|
| 821 | MPointingDevCalc devcalc; | 
|---|
| 822 |  | 
|---|
| 823 | tlist.AddToList(&readoff); | 
|---|
| 824 | if (!set.IsMonteCarlo()) | 
|---|
| 825 | tlist.AddToList(&fillvs, "EffectiveOnTime"); | 
|---|
| 826 | if (gLog.GetDebugLevel()>4) | 
|---|
| 827 | tlist.AddToList(&print2, "EffectiveOnTime"); | 
|---|
| 828 | tlist.AddToList(&devcalc, "Starguider"); | 
|---|
| 829 | tlist.AddToList(&contq,   "Events"); | 
|---|
| 830 | if (!fWriteOnly) | 
|---|
| 831 | tlist.AddToList(&fill1a, "Events"); | 
|---|
| 832 | tlist.AddToList(&tlist2,  "Events"); | 
|---|
| 833 |  | 
|---|
| 834 | // by setting it here it is distributed to all consecutive tasks | 
|---|
| 835 | tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime); | 
|---|
| 836 |  | 
|---|
| 837 | par.SetVal(0); | 
|---|
| 838 |  | 
|---|
| 839 | // Create and setup the eventloop | 
|---|
| 840 | MEvtLoop evtloop(fName); | 
|---|
| 841 | evtloop.SetParList(&plist); | 
|---|
| 842 | evtloop.SetDisplay(fDisplay); | 
|---|
| 843 | evtloop.SetLogStream(fLog); | 
|---|
| 844 | if (!SetupEnv(evtloop)) | 
|---|
| 845 | return kFALSE; | 
|---|
| 846 |  | 
|---|
| 847 | TObjArray cont; | 
|---|
| 848 | cont.Add(&contq); | 
|---|
| 849 | cont.Add(&cont0); | 
|---|
| 850 | cont.Add(&cont1); | 
|---|
| 851 | cont.Add(&cont2); | 
|---|
| 852 | cont.Add(&cont3); | 
|---|
| 853 | //if (taskenv1.GetTask()) | 
|---|
| 854 | //    cont.Add(taskenv1.GetTask()); | 
|---|
| 855 | if (taskenv2.GetTask()) | 
|---|
| 856 | cont.Add(taskenv2.GetTask()); | 
|---|
| 857 | if (taskenv3.GetTask()) | 
|---|
| 858 | cont.Add(taskenv3.GetTask()); | 
|---|
| 859 |  | 
|---|
| 860 | if (!WriteTasks(set.GetNumAnalysis(), cont)) | 
|---|
| 861 | return kFALSE; | 
|---|
| 862 |  | 
|---|
| 863 | if (set.HasOffSequences() || set.IsWobbleMode()) | 
|---|
| 864 | { | 
|---|
| 865 | // Execute first analysis | 
|---|
| 866 | if (!evtloop.Eventloop(fMaxEvents)) | 
|---|
| 867 | { | 
|---|
| 868 | *fLog << err << GetDescriptor() << ": Processing of off-sequences failed." << endl; | 
|---|
| 869 | return -3; | 
|---|
| 870 | } | 
|---|
| 871 |  | 
|---|
| 872 | if (!evtloop.GetDisplay()) | 
|---|
| 873 | { | 
|---|
| 874 | *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl; | 
|---|
| 875 | return kFALSE; | 
|---|
| 876 | } | 
|---|
| 877 |  | 
|---|
| 878 | //plist.FindObject("MTimeEffectiveOnTime")->Clear(); | 
|---|
| 879 | } | 
|---|
| 880 | else | 
|---|
| 881 | { | 
|---|
| 882 | // This is the simplest way to remove the two object from the parlist | 
|---|
| 883 | delete halphaoff; | 
|---|
| 884 | delete hfsoff; | 
|---|
| 885 | } | 
|---|
| 886 |  | 
|---|
| 887 | // ------------- Loop On Data -------------------- | 
|---|
| 888 | MReadReports readondata; | 
|---|
| 889 | readondata.AddTree("Events", "MTime.", MReadReports::kMaster); | 
|---|
| 890 | readondata.AddTree("Drive",            MReadReports::kRequired); | 
|---|
| 891 | readondata.AddTree("Starguider",       MReadReports::kRequired); | 
|---|
| 892 | readondata.AddTree("EffectiveOnTime"); | 
|---|
| 893 |  | 
|---|
| 894 | MReadMarsFile readonmc("Events"); | 
|---|
| 895 | readonmc.DisableAutoScheme(); | 
|---|
| 896 |  | 
|---|
| 897 | MRead &readon = set.IsMonteCarlo() ? (MRead&)readonmc : (MRead&)readondata; | 
|---|
| 898 | if (!set.AddFilesOn(readon)) | 
|---|
| 899 | return kFALSE; | 
|---|
| 900 |  | 
|---|
| 901 | scalc.SetMode(MSrcPosCalc::kDefault); | 
|---|
| 902 | scalc.SetNumRandomOffPositions(fNumOffSourcePos); | 
|---|
| 903 |  | 
|---|
| 904 | MFillH fill1b("MHHillasOnPre  [MHHillas]",      "MHillas",      "FillHillasPre"); | 
|---|
| 905 | MFillH fill2b("MHHillasOnPost [MHHillas]",      "MHillas",      "FillHillasPost"); | 
|---|
| 906 | MFillH fill3b("MHVsSizeOnPost [MHVsSize]",      "MHillasSrc",   "FillVsSizePost"); | 
|---|
| 907 | MFillH fill4b("MHHilExtOnPost [MHHillasExt]",   "MHillasSrc",   "FillHilExtPost"); | 
|---|
| 908 | MFillH fill5b("MHHilSrcOnPost [MHHillasSrc]",   "MHillasSrc",   "FillHilSrcPost"); | 
|---|
| 909 | MFillH fill6b("MHImgParOnPost [MHImagePar]",    "MImagePar",    "FillImgParPost"); | 
|---|
| 910 | MFillH fill7b("MHNewParOnPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost"); | 
|---|
| 911 | //MFillH fill9b("MHEffOnTime    [MHEffectiveOnTime]", "MTime",        "FillEffOnTime"); | 
|---|
| 912 | fill1b.SetNameTab("PreCut"); | 
|---|
| 913 | fill2b.SetNameTab("PostCut"); | 
|---|
| 914 | fill3b.SetNameTab("VsSize"); | 
|---|
| 915 | fill4b.SetNameTab("HilExt"); | 
|---|
| 916 | fill5b.SetNameTab("HilSrc"); | 
|---|
| 917 | fill6b.SetNameTab("ImgPar"); | 
|---|
| 918 | fill7b.SetNameTab("NewPar"); | 
|---|
| 919 | //fill9b.SetNameTab("EffOnT"); | 
|---|
| 920 | fill1b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 921 | fill2b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 922 | fill3b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 923 | fill4b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 924 | fill5b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 925 | fill6b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 926 | fill7b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 927 | //fill9b.SetFilter(&fbin); | 
|---|
| 928 |  | 
|---|
| 929 | /* | 
|---|
| 930 | MHVsTime hvs("MEffectiveOnTime.fVal"); | 
|---|
| 931 | hvs.SetTitle("Effective On-Time vs. Time;;T_{on}"); | 
|---|
| 932 | MFillH fillvs(&hvs, "MTimeEffectiveOnTime", "FillOnTime"); | 
|---|
| 933 | fillvs.SetNameTab("OnTime"); | 
|---|
| 934 | */ | 
|---|
| 935 |  | 
|---|
| 936 | /* | 
|---|
| 937 | MParameterD weight; | 
|---|
| 938 | weight.SetVal(-1); | 
|---|
| 939 | fill2a.SetWeight(&weight); | 
|---|
| 940 | fill3a.SetWeight(&weight); | 
|---|
| 941 | fill4a.SetWeight(&weight); | 
|---|
| 942 | fill5a.SetWeight(&weight); | 
|---|
| 943 | fill6a.SetWeight(&weight); | 
|---|
| 944 | fill7a.SetWeight(&weight); | 
|---|
| 945 | if (fSubstraction) | 
|---|
| 946 | { | 
|---|
| 947 | fill2a.SetNameTab("PostCut-"); | 
|---|
| 948 | fill3a.SetNameTab("VsSize-"); | 
|---|
| 949 | fill4a.SetNameTab("HilExt-"); | 
|---|
| 950 | fill5a.SetNameTab("HilSrc-"); | 
|---|
| 951 | fill6a.SetNameTab("ImgPar-"); | 
|---|
| 952 | fill7a.SetNameTab("NewPar-"); | 
|---|
| 953 | } | 
|---|
| 954 | */ | 
|---|
| 955 | MHAlpha *halphaon=CreateNewHist(plist); | 
|---|
| 956 | MFillH falpha2(halphaon, "", "FillHist"); | 
|---|
| 957 | MH *hfs=CreateNewHistFS(plist); | 
|---|
| 958 | MFillH ffs2(hfs, "MHillas", "FillFS"); | 
|---|
| 959 | MFillH fillphi("MHPhi", "", "FillPhi"); | 
|---|
| 960 | fillphi.SetDrawOption("anticut"); | 
|---|
| 961 |  | 
|---|
| 962 | tlist2.SetNumPasses(); | 
|---|
| 963 |  | 
|---|
| 964 | tlist.Replace(&readon); | 
|---|
| 965 | if (fRndmSrcPos && !set.IsWobbleMode()) | 
|---|
| 966 | tlist2.RemoveFromList(&srcrndm); | 
|---|
| 967 |  | 
|---|
| 968 | MFillH fillsrc(&hsrcpos, "MSrcPosCam", "FillSrcPosCam"); | 
|---|
| 969 | fillsrc.SetNameTab("SrcPos"); | 
|---|
| 970 |  | 
|---|
| 971 | if (set.IsWobbleMode() && !set.IsMonteCarlo()) | 
|---|
| 972 | tlist2.AddToListBefore(&fillsrc, &hcalc); | 
|---|
| 973 |  | 
|---|
| 974 | MH3 hvs2("MPointingPos.fZd"); | 
|---|
| 975 | hvs2.SetName("Theta"); | 
|---|
| 976 | hvs2.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]"); | 
|---|
| 977 |  | 
|---|
| 978 | MFillH fillvs2(&hvs2, "", "FillOnTime"); | 
|---|
| 979 | if (!set.IsMonteCarlo()) | 
|---|
| 980 | fillvs2.SetWeight("MEffectiveOnTime"); | 
|---|
| 981 | fillvs2.SetNameTab("OnTime"); | 
|---|
| 982 | fillvs2.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":""); | 
|---|
| 983 |  | 
|---|
| 984 | if (!fWriteOnly) | 
|---|
| 985 | { | 
|---|
| 986 | tlist.Replace(&fill1b); | 
|---|
| 987 | /*        if (fIsWobble) | 
|---|
| 988 | { | 
|---|
| 989 | tlist2.AddToListAfter(&fill2b, &fill2a); | 
|---|
| 990 | tlist2.AddToListAfter(&fill3b, &fill3a); | 
|---|
| 991 | } | 
|---|
| 992 | else | 
|---|
| 993 | */ | 
|---|
| 994 | tlist2.Replace(&fill2b); | 
|---|
| 995 | if (fFullDisplay) | 
|---|
| 996 | { | 
|---|
| 997 | tlist2.Replace(&fill3b); | 
|---|
| 998 | tlist2.Replace(&fill4b); | 
|---|
| 999 | tlist2.Replace(&fill5b); | 
|---|
| 1000 | tlist2.Replace(&fill6b); | 
|---|
| 1001 | tlist2.Replace(&fill7b); | 
|---|
| 1002 | } | 
|---|
| 1003 | tlist2.Replace(&falpha2); | 
|---|
| 1004 | //if (!fIsMonteCarlo) | 
|---|
| 1005 | //    tlist2.Replace(&fill9b); | 
|---|
| 1006 | if (!set.IsWobbleMode() || !fNameHist.IsNull()) | 
|---|
| 1007 | tlist2.Replace(&ffs2); | 
|---|
| 1008 | if (set.IsWobbleMode()) | 
|---|
| 1009 | { | 
|---|
| 1010 | tlist2.AddToListAfter(&fillphi, &falpha2); | 
|---|
| 1011 | if (!fNameHist.IsNull()) | 
|---|
| 1012 | tlist2.RemoveFromList(&ffs); | 
|---|
| 1013 | } | 
|---|
| 1014 |  | 
|---|
| 1015 | if (!set.IsMonteCarlo()) | 
|---|
| 1016 | tlist.Replace(&fillvs2); | 
|---|
| 1017 | else | 
|---|
| 1018 | tlist2.Replace(&fillvs2); | 
|---|
| 1019 | } | 
|---|
| 1020 |  | 
|---|
| 1021 | // by setting it here it is distributed to all consecutive tasks | 
|---|
| 1022 | tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime); | 
|---|
| 1023 |  | 
|---|
| 1024 | par.SetVal(1); | 
|---|
| 1025 |  | 
|---|
| 1026 | // Execute first analysis | 
|---|
| 1027 | if (!evtloop.Eventloop(fMaxEvents)) | 
|---|
| 1028 | { | 
|---|
| 1029 | *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl; | 
|---|
| 1030 | return -4; | 
|---|
| 1031 | } | 
|---|
| 1032 |  | 
|---|
| 1033 | if (write0) | 
|---|
| 1034 | delete write0; | 
|---|
| 1035 | if (write1) | 
|---|
| 1036 | delete write1; | 
|---|
| 1037 |  | 
|---|
| 1038 | // FIXME: Perform fit and plot energy dependant alpha plots | 
|---|
| 1039 | // and fit result to new tabs! | 
|---|
| 1040 | if (!WriteResult(plist, set)) | 
|---|
| 1041 | return kFALSE; | 
|---|
| 1042 |  | 
|---|
| 1043 | *fLog << all << GetDescriptor() << ": Done." << endl; | 
|---|
| 1044 | *fLog << endl << endl; | 
|---|
| 1045 |  | 
|---|
| 1046 | return kTRUE; | 
|---|
| 1047 | } | 
|---|