| 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 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MJStar
|
|---|
| 28 | //
|
|---|
| 29 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 | #include "MJStar.h"
|
|---|
| 31 |
|
|---|
| 32 | #include <TEnv.h>
|
|---|
| 33 | #include <TFile.h>
|
|---|
| 34 |
|
|---|
| 35 | #include "MLog.h"
|
|---|
| 36 | #include "MLogManip.h"
|
|---|
| 37 |
|
|---|
| 38 | #include "MDirIter.h"
|
|---|
| 39 | #include "MParList.h"
|
|---|
| 40 | #include "MTaskList.h"
|
|---|
| 41 | #include "MEvtLoop.h"
|
|---|
| 42 |
|
|---|
| 43 | #include "MStatusDisplay.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "MH3.h"
|
|---|
| 46 | #include "MHVsTime.h"
|
|---|
| 47 | #include "MHCamEvent.h"
|
|---|
| 48 | #include "MBinning.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MReadReports.h"
|
|---|
| 51 | #include "MReadMarsFile.h"
|
|---|
| 52 | #include "MFDeltaT.h"
|
|---|
| 53 | #include "MContinue.h"
|
|---|
| 54 | #include "MGeomApply.h"
|
|---|
| 55 | #include "MEventRateCalc.h"
|
|---|
| 56 | #include "MImgCleanStd.h"
|
|---|
| 57 | #include "MHillasCalc.h"
|
|---|
| 58 | #include "MFillH.h"
|
|---|
| 59 | #include "MWriteRootFile.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MPointingPosCalc.h"
|
|---|
| 62 | //#include "MSrcPosFromModel.h"
|
|---|
| 63 |
|
|---|
| 64 | ClassImp(MJStar);
|
|---|
| 65 |
|
|---|
| 66 | using namespace std;
|
|---|
| 67 |
|
|---|
| 68 | // --------------------------------------------------------------------------
|
|---|
| 69 | //
|
|---|
| 70 | // Default constructor.
|
|---|
| 71 | //
|
|---|
| 72 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
|---|
| 73 | //
|
|---|
| 74 | MJStar::MJStar(const char *name, const char *title)
|
|---|
| 75 | {
|
|---|
| 76 | fName = name ? name : "MJStar";
|
|---|
| 77 | fTitle = title ? title : "Standard analysis and reconstruction";
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | Bool_t MJStar::WriteResult()
|
|---|
| 81 | {
|
|---|
| 82 | if (fPathOut.IsNull())
|
|---|
| 83 | {
|
|---|
| 84 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
|---|
| 85 | return kTRUE;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | const TString oname = Form("%s/star%06d.root", (const char*)fPathOut, fSequence.GetSequence());
|
|---|
| 89 |
|
|---|
| 90 | *fLog << inf << "Writing to file: " << oname << endl;
|
|---|
| 91 |
|
|---|
| 92 | TFile file(oname, "RECREATE");
|
|---|
| 93 |
|
|---|
| 94 | *fLog << inf << " - MStatusDisplay..." << flush;
|
|---|
| 95 | if (fDisplay && fDisplay->Write()<=0)
|
|---|
| 96 | {
|
|---|
| 97 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
|---|
| 98 | return kFALSE;
|
|---|
| 99 | }
|
|---|
| 100 | *fLog << inf << "ok." << endl;
|
|---|
| 101 |
|
|---|
| 102 | return kTRUE;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | Bool_t MJStar::ProcessFile(Bool_t ismc)
|
|---|
| 106 | {
|
|---|
| 107 | if (!fSequence.IsValid())
|
|---|
| 108 | {
|
|---|
| 109 | *fLog << err << "ERROR - Sequence invalid!" << endl;
|
|---|
| 110 | return kFALSE;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | //if (!CheckEnv())
|
|---|
| 114 | // return kFALSE;
|
|---|
| 115 |
|
|---|
| 116 | CheckEnv();
|
|---|
| 117 |
|
|---|
| 118 | // --------------------------------------------------------------------------------
|
|---|
| 119 |
|
|---|
| 120 | *fLog << inf;
|
|---|
| 121 | fLog->Separator(GetDescriptor());
|
|---|
| 122 | *fLog << "Calculate image parameters from sequence ";
|
|---|
| 123 | *fLog << fSequence.GetName() << endl;
|
|---|
| 124 | *fLog << endl;
|
|---|
| 125 |
|
|---|
| 126 | // --------------------------------------------------------------------------------
|
|---|
| 127 |
|
|---|
| 128 | MDirIter iter;
|
|---|
| 129 | const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData);
|
|---|
| 130 | const Int_t n1 = fSequence.GetNumDatRuns();
|
|---|
| 131 | if (n0==0)
|
|---|
| 132 | {
|
|---|
| 133 | *fLog << err << "ERROR - No input files of sequence found!" << endl;
|
|---|
| 134 | return kFALSE;
|
|---|
| 135 | }
|
|---|
| 136 | if (n0!=n1)
|
|---|
| 137 | {
|
|---|
| 138 | *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
|
|---|
| 139 | return kFALSE;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | // Setup Parlist
|
|---|
| 143 | MParList plist;
|
|---|
| 144 | plist.AddToList(this); // take care of fDisplay!
|
|---|
| 145 |
|
|---|
| 146 | // Setup Tasklist
|
|---|
| 147 | MTaskList tlist;
|
|---|
| 148 | plist.AddToList(&tlist);
|
|---|
| 149 |
|
|---|
| 150 | MReadReports readreal;
|
|---|
| 151 | readreal.AddTree("Events", "MTime.", kTRUE);
|
|---|
| 152 | readreal.AddTree("Drive");
|
|---|
| 153 | //read.AddTree("Trigger");
|
|---|
| 154 | //read.AddTree("Camera");
|
|---|
| 155 | //read.AddTree("CC");
|
|---|
| 156 | //read.AddTree("Currents");
|
|---|
| 157 | readreal.AddFiles(iter);
|
|---|
| 158 |
|
|---|
| 159 | MReadMarsFile readmc("Events");
|
|---|
| 160 | readmc.DisableAutoScheme();
|
|---|
| 161 | readmc.AddFiles(iter);
|
|---|
| 162 |
|
|---|
| 163 | // ------------------ Setup general tasks ----------------
|
|---|
| 164 |
|
|---|
| 165 | MFDeltaT fdeltat;
|
|---|
| 166 | MContinue cont(&fdeltat, "FilterDeltaT", "Filter events with wrong timing");
|
|---|
| 167 | cont.SetInverted();
|
|---|
| 168 |
|
|---|
| 169 | MGeomApply apply; // Only necessary to craete geometry
|
|---|
| 170 | MEventRateCalc rate;
|
|---|
| 171 | /*
|
|---|
| 172 | MEventRateCalc rate10000;
|
|---|
| 173 | rate10000.SetNameEventRate("MEventRate10000");
|
|---|
| 174 | rate10000.SetNumEvents(10000);
|
|---|
| 175 | */
|
|---|
| 176 | //MBadPixelsMerge merge(&badpix);
|
|---|
| 177 | MImgCleanStd clean;
|
|---|
| 178 | MHillasCalc hcalc;
|
|---|
| 179 |
|
|---|
| 180 | // ------------------ Setup histograms and fill tasks ----------------
|
|---|
| 181 | MHCamEvent evt0("Cleaned");
|
|---|
| 182 | evt0.SetType(0);
|
|---|
| 183 |
|
|---|
| 184 | MH3 h1("MEventRate.fRate");
|
|---|
| 185 | h1.SetName("MHEventRate");
|
|---|
| 186 | h1.SetLogy();
|
|---|
| 187 | /*
|
|---|
| 188 | MH3 h12("MEventRate10000.fRate");
|
|---|
| 189 | h12.SetName("MHEventRate");
|
|---|
| 190 | h12.SetLogy();
|
|---|
| 191 | */
|
|---|
| 192 | MBinning b1("BinningMHEventRate");
|
|---|
| 193 | b1.SetEdges(150, 0, 1500);
|
|---|
| 194 | plist.AddToList(&b1);
|
|---|
| 195 |
|
|---|
| 196 | MFillH fill0(&evt0, "MCerPhotEvt", "FillCerPhotEvt");
|
|---|
| 197 | MFillH fill1("MHHillas", "MHillas", "FillHillas");
|
|---|
| 198 | MFillH fill2("MHHillasExt", "", "FillHillasExt");
|
|---|
| 199 | MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
|
|---|
| 200 | MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
|
|---|
| 201 | MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
|
|---|
| 202 | //MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
|
|---|
| 203 | //MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
|
|---|
| 204 | MFillH fill8(&h1, "", "FillEventRate");
|
|---|
| 205 | MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
|
|---|
| 206 | //MFillH fillb(&h12, "", "FillEvtRate2");
|
|---|
| 207 | //MFillH fill9("MHCerPhot");
|
|---|
| 208 |
|
|---|
| 209 | fill8.SetNameTab("EvtRate");
|
|---|
| 210 | fill9.SetNameTab("EffOnTime");
|
|---|
| 211 |
|
|---|
| 212 | // ------------------ Setup write task ----------------
|
|---|
| 213 |
|
|---|
| 214 | MWriteRootFile write(2, Form("%s{s/_Y_/_I_}", fPathOut.Data()), fOverwrite);
|
|---|
| 215 | // Data
|
|---|
| 216 | write.AddContainer("MHillas", "Events");
|
|---|
| 217 | write.AddContainer("MHillasExt", "Events");
|
|---|
| 218 | write.AddContainer("MHillasSrc", "Events");
|
|---|
| 219 | write.AddContainer("MImagePar", "Events");
|
|---|
| 220 | write.AddContainer("MNewImagePar", "Events");
|
|---|
| 221 | //write.AddContainer("MNewImagePar2", "Events");
|
|---|
| 222 | //write.AddContainer("MImageParTime", "Events");
|
|---|
| 223 | write.AddContainer("MRawEvtHeader", "Events");
|
|---|
| 224 | if (ismc)
|
|---|
| 225 | {
|
|---|
| 226 | write.AddContainer("MPointingPos", "Events");
|
|---|
| 227 | // Monte Carlo
|
|---|
| 228 | write.AddContainer("MMcEvt", "Events");
|
|---|
| 229 | write.AddContainer("MMcTrig", "Events");
|
|---|
| 230 | // Monte Carlo Headers
|
|---|
| 231 | write.AddContainer("MMcTrigHeader", "RunHeaders");
|
|---|
| 232 | write.AddContainer("MMcConfigRunHeader", "RunHeaders");
|
|---|
| 233 | write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
|
|---|
| 234 | }
|
|---|
| 235 | else
|
|---|
| 236 | {
|
|---|
| 237 | write.AddContainer("MTime", "Events");
|
|---|
| 238 | // Run Header
|
|---|
| 239 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
|---|
| 240 | write.AddContainer("MBadPixelsCam", "RunHeaders");
|
|---|
| 241 | write.AddContainer("MGeomCam", "RunHeaders");
|
|---|
| 242 | //write.AddContainer("MObservatory", "RunHeaders");
|
|---|
| 243 | // Drive
|
|---|
| 244 | //write.AddContainer("MSrcPosCam", "Drive");
|
|---|
| 245 | write.AddContainer("MPointingPos", "Drive");
|
|---|
| 246 | write.AddContainer("MReportDrive", "Drive");
|
|---|
| 247 | write.AddContainer("MTimeDrive", "Drive");
|
|---|
| 248 | // Effective On Time
|
|---|
| 249 | write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
|
|---|
| 250 | write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | MTaskList tlist2;
|
|---|
| 254 | tlist2.AddToList(&apply);
|
|---|
| 255 | if (!ismc)
|
|---|
| 256 | {
|
|---|
| 257 | tlist2.AddToList(&cont);
|
|---|
| 258 | tlist2.AddToList(&rate);
|
|---|
| 259 | //tlist2.AddToList(&rate10000);
|
|---|
| 260 | tlist2.AddToList(&fill8);
|
|---|
| 261 | tlist2.AddToList(&fill9);
|
|---|
| 262 | }
|
|---|
| 263 | //tlist2.AddToList(&fillb);
|
|---|
| 264 | tlist2.AddToList(&clean);
|
|---|
| 265 | tlist2.AddToList(&fill0);
|
|---|
| 266 | tlist2.AddToList(&hcalc);
|
|---|
| 267 | tlist2.AddToList(&fill1);
|
|---|
| 268 | tlist2.AddToList(&fill2);
|
|---|
| 269 | tlist2.AddToList(&fill3);
|
|---|
| 270 | tlist2.AddToList(&fill4);
|
|---|
| 271 | tlist2.AddToList(&fill5);
|
|---|
| 272 | //tlist2.AddToList(&fill6);
|
|---|
| 273 | //tlist2.AddToList(&fill7);
|
|---|
| 274 | //tlist2.AddToList(&fill9);
|
|---|
| 275 |
|
|---|
| 276 | MPointingPosCalc pcalc;
|
|---|
| 277 | //MSrcPosFromModel srcpos;
|
|---|
| 278 |
|
|---|
| 279 | MTaskList tlist3;
|
|---|
| 280 | tlist3.AddToList(&pcalc);
|
|---|
| 281 | //tlist3.AddToList(&srcpos);
|
|---|
| 282 |
|
|---|
| 283 | tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
|
|---|
| 284 | tlist.AddToList(&tlist3, "Drive");
|
|---|
| 285 | tlist.AddToList(&tlist2, "Events");
|
|---|
| 286 | tlist.AddToList(&write);
|
|---|
| 287 |
|
|---|
| 288 | // Create and setup the eventloop
|
|---|
| 289 | MEvtLoop evtloop(fName);
|
|---|
| 290 | evtloop.SetParList(&plist);
|
|---|
| 291 | evtloop.SetDisplay(fDisplay);
|
|---|
| 292 | evtloop.SetLogStream(fLog);
|
|---|
| 293 | if (!SetupEnv(evtloop))
|
|---|
| 294 | return kFALSE;
|
|---|
| 295 |
|
|---|
| 296 | // Execute first analysis
|
|---|
| 297 | if (!evtloop.Eventloop(fMaxEvents))
|
|---|
| 298 | {
|
|---|
| 299 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
|---|
| 300 | return kFALSE;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | tlist.PrintStatistics();
|
|---|
| 304 |
|
|---|
| 305 | if (!WriteResult())
|
|---|
| 306 | return kFALSE;
|
|---|
| 307 |
|
|---|
| 308 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
|---|
| 309 | *fLog << endl << endl;
|
|---|
| 310 |
|
|---|
| 311 | return kTRUE;
|
|---|
| 312 | }
|
|---|