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