Changeset 6491 for trunk/MagicSoft/Mars/mmontecarlo
- Timestamp:
- 02/15/05 17:20:40 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mmontecarlo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc
r5340 r6491 17 17 ! 18 18 ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de> 19 ! Author(s): Harald Kornmayer 1/2001 19 ! Author(s): Harald Kornmayer 1/2001 20 ! Author(s): Abelardo Moralejo 2/2005 <mailto:moralejo@pd.infn.it> 20 21 ! 21 22 ! Copyright: MAGIC Software Development, 2000-2002 … … 26 27 ////////////////////////////////////////////////////////////////////////////// 27 28 // 28 // MHMcCollectionAreaCalc 29 // 30 // Remark: The initialization is mainly done in the ReInit function. 31 // Please make sure, that you don't use MReadTree when processing 32 // a file. Use a 'ReInit'-calling task like MReadMarsFile 29 // MMcCollectionAreaCalc 33 30 // 34 31 ////////////////////////////////////////////////////////////////////////////// … … 42 39 43 40 #include "MMcEvt.hxx" 44 #include "MMcTrig.hxx" 41 #include "MMcEvtBasic.h" 42 45 43 #include "MMcRunHeader.hxx" 46 44 #include "MMcCorsikaRunHeader.h" … … 52 50 using namespace std; 53 51 54 MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input, 55 const char *name, const char *title) 52 //////////////////////////////////////////////////////////////////////////////// 53 // 54 // Constructor 55 // 56 MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input, const char *name, 57 const char *title): 58 fBinsTheta(0), fBinsEnergy(0), fSpectrum(0) 56 59 { 57 60 fName = name ? name : "MMcCollectionAreaCalc"; 58 61 fTitle = title ? title : "Task to calculate the collection area"; 59 60 fObjName = input ? input : "MMcTrig";61 AddToBranchList(Form("%s.fNumFirstLevel", input));62 63 AddToBranchList("MMcEvt.fEnergy");64 AddToBranchList("MMcEvt.fImpact");65 66 fCorsikaVersion = 0;67 fAllEvtsTriggered = kFALSE;68 fTotalNumSimulatedShowers = 0;69 fThetaMin = -1.;70 fThetaMax = -1.;71 72 62 } 73 63 64 //////////////////////////////////////////////////////////////////////////////// 65 // 66 // PreProcess. 67 // Create MHMcCollectionArea object if necessary. 68 // Search in parameter list for MBinning objects with binning in theta and E. 69 // These contain the coarse binning to be used in the analysis. Then search 70 // for other necessary input containers: 71 // if MMcEvt is found, it means we are in the loop over the Events tree, 72 // and so we must fill the histogram MHMcCollectionArea::fHistSel (using 73 // MHMcCollectionArea::FillSel). If MMcEvt is not found, it means that we are in 74 // the loop over the "OriginalMC" tree, containing all the original Corsika events 75 // produced, and hence we must fill the histogram fHistAll through 76 // MHMcCollectionArea::FillAll. 77 // 74 78 Int_t MMcCollectionAreaCalc::PreProcess (MParList *pList) 75 79 { 76 // connect the raw data with this task80 fCollArea = (MHMcCollectionArea*)pList->FindCreateObj("MHMcCollectionArea"); 77 81 78 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt"); 79 if (!fMcEvt) 82 // Look for the binnings of the histograms if they have not been already 83 // found in a previous loop. 84 85 if (!fBinsTheta) 80 86 { 81 *fLog << err << "MMcEvt not found... abort." << endl; 82 return kFALSE; 87 fBinsTheta = (MBinning*) pList->FindObject("binsTheta"); 88 if (!fBinsTheta) 89 { 90 *fLog << err << "Coarse Theta binning not found... Aborting." 91 << endl; 92 return kFALSE; 93 } 94 } 95 96 if (!fBinsEnergy) 97 { 98 fBinsEnergy = (MBinning*) pList->FindObject("binsEnergy"); 99 if (!fBinsEnergy) 100 { 101 *fLog << err << "Coarse Energy binning not found... Aborting." 102 << endl; 103 return kFALSE; 104 } 105 } 106 107 fCollArea->SetCoarseBinnings(*fBinsEnergy, *fBinsTheta); 108 109 110 // Look for the input containers 111 112 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt"); 113 if (fMcEvt) 114 { 115 *fLog << inf << "MMcEvt found... I will fill MHMcCollectionArea.fHistSel..." << endl; 116 return kTRUE; 117 } 118 119 *fLog << inf << "MMcEvt not found... looking for MMcEvtBasic..." << endl; 120 121 122 fMcEvtBasic = (MMcEvtBasic*) pList->FindObject("MMcEvtBasic"); 123 124 if (fMcEvtBasic) 125 { 126 *fLog << inf << "MMcEvtBasic found... I will fill MHMcCollectionArea.fHistAll..." << endl; 127 return kTRUE; 128 } 129 130 *fLog << err << "MMcEvtBasic not found. Aborting..." << endl; 131 132 return kFALSE; 133 } 134 135 //////////////////////////////////////////////////////////////////////////////// 136 // 137 // Process. Depending on whether fMcEvt or fMcEvtBasic are available, fill 138 // MHMcCollectionArea::fHistAll, else, if fMcEvt is available, fill 139 // MHMcCollectionArea::fHistSel 140 // 141 Int_t MMcCollectionAreaCalc::Process() 142 { 143 Double_t energy = fMcEvt? fMcEvt->GetEnergy() : fMcEvtBasic->GetEnergy(); 144 Double_t impact = fMcEvt? fMcEvt->GetImpact()/100. : fMcEvtBasic->GetImpact()/100.; // in m 145 Double_t theta = fMcEvt? fMcEvt->GetTelescopeTheta()*TMath::RadToDeg() : 146 fMcEvtBasic->GetTelescopeTheta()*TMath::RadToDeg(); // in deg 147 148 if (fMcEvt) 149 fCollArea->FillSel(energy, impact, theta); 150 else 151 fCollArea->FillAll(energy, impact, theta); 152 153 return kTRUE; 154 } 155 156 /////////////////////////////////////////////////////////////////////////////// 157 // 158 // Postprocess. If both fHistAll and fHistSel are already filled, calculate 159 // effective areas. Else it means we still have to run one more loop. 160 // 161 Int_t MMcCollectionAreaCalc::PostProcess() 162 { 163 if ( ((TH2D*)fCollArea->GetHistAll())->GetEntries() > 0 && 164 ((TH2D*)fCollArea->GetHistSel())->GetEntries() > 0) 165 { 166 *fLog << inf << "Calculation Collection Area..." << endl; 167 fCollArea->Calc(fSpectrum); 83 168 } 84 169 85 170 return kTRUE; 86 171 } 87 88 Bool_t MMcCollectionAreaCalc::ReInit(MParList *plist)89 {90 fCollArea=0;91 92 MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");93 if (!runheader)94 {95 *fLog << err << "Error - MMcRunHeader not found... abort." << endl;96 return kFALSE;97 }98 99 fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();100 *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;101 102 103 if ( (fThetaMin >= 0 && fThetaMin != runheader->GetShowerThetaMin()) ||104 (fThetaMax >= 0 && fThetaMax != runheader->GetShowerThetaMax()) )105 {106 *fLog << warn << "Warning - Read files have different Theta ranges (";107 *fLog << "(" << fThetaMin << ", " << fThetaMax << ") vs (" <<108 runheader->GetShowerThetaMin() << ", " <<109 runheader->GetShowerThetaMax() << ")..." << endl;110 }111 fThetaMin = runheader->GetShowerThetaMin();112 fThetaMax = runheader->GetShowerThetaMax();113 114 115 if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())116 *fLog << warn << "Warning - Read files have different Corsika versions..." << endl;117 fCorsikaVersion = runheader->GetCorsikaVersion();118 119 120 fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();121 *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;122 123 124 fCollArea = (MHMcCollectionArea*)plist->FindCreateObj("MHMcCollectionArea");125 if (!fCollArea)126 return kFALSE;127 128 if (!fAllEvtsTriggered)129 {130 fMcTrig = (MMcTrig*)plist->FindObject(fObjName);131 if (!fMcTrig)132 {133 *fLog << err << fObjName << " [MMcTrig] not found... anort." << endl;134 return kFALSE;135 }136 return kTRUE;137 }138 139 MMcCorsikaRunHeader *corrunheader = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");140 if (!corrunheader)141 {142 *fLog << err << "MMcCorsikaRunHeader not found... abort." << endl;143 return kFALSE;144 }145 146 //147 // Calculate approximately the original number of events in each148 // energy bin:149 //150 151 const Float_t emin = corrunheader->GetELowLim();152 const Float_t emax = corrunheader->GetEUppLim();153 const Float_t expo = 1 + corrunheader->GetSlopeSpec();154 const Float_t k = runheader->GetNumSimulatedShowers() /155 (pow(emax,expo) - pow(emin,expo)) ;156 157 TH2 &hall = *fCollArea->GetHistAll();158 159 const Int_t nbinx = hall.GetNbinsX();160 161 TAxis &axe = *hall.GetXaxis();162 for (Int_t i = 1; i <= nbinx; i++)163 {164 const Float_t e1 = axe.GetBinLowEdge(i);165 const Float_t e2 = axe.GetBinLowEdge(i+1);166 167 if (e1 < emin || e2 > emax)168 continue;169 170 const Float_t events = k * (pow(e2, expo) - pow(e1, expo));171 //172 // We fill the i-th energy bin, with the total number of events173 // Second argument of Fill would be impact parameter of each174 // event, but we don't really need it for the collection area,175 // so we just put a dummy value (1.)176 //177 178 const Float_t energy = (e1+e2)/2.;179 hall.Fill(energy, 1., events);180 }181 182 return kTRUE;183 }184 185 Int_t MMcCollectionAreaCalc::Process()186 {187 const Double_t energy = fMcEvt->GetEnergy();188 const Double_t impact = fMcEvt->GetImpact()/100.;189 190 //191 // This happens for camera files created with Camera 0.5192 //193 if (TMath::IsNaN(impact))194 {195 *fLog << err << dbginf << "ERROR - Impact=NaN (Not a number)... abort." << endl;196 return kERROR;197 }198 199 if (!fAllEvtsTriggered)200 {201 fCollArea->FillAll(energy, impact);202 203 if (fMcTrig->GetFirstLevel() <= 0)204 return kTRUE;205 }206 207 fCollArea->FillSel(energy, impact);208 209 return kTRUE;210 }211 212 Int_t MMcCollectionAreaCalc::PostProcess()213 {214 if (!fCollArea)215 return kTRUE;216 217 //218 // do the calculation of the effectiv area219 //220 *fLog << inf << "Calculation Collection Area..." << endl;221 222 if (!fAllEvtsTriggered)223 fCollArea->CalcEfficiency();224 else225 {226 *fLog << inf << "Total number of showers: " << fTotalNumSimulatedShowers << endl;227 fCollArea->CalcEfficiency2();228 }229 230 return kTRUE;231 }232 -
trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.h
r5340 r6491 7 7 8 8 #include <TH2.h> 9 #include <TF1.h> 9 10 10 11 class MParList; 11 12 class MMcEvt; 13 class MMcEvtBasic; 12 14 class MMcTrig; 13 15 class MHMcCollectionArea; 16 class MBinning; 14 17 15 18 class MMcCollectionAreaCalc : public MTask 16 19 { 17 20 private: 18 const MMcEvt *fMcEvt; 19 const MMcTrig *fMcTrig; 21 const MMcEvt *fMcEvt; 22 const MMcEvtBasic *fMcEvtBasic; 23 const MMcTrig *fMcTrig; 24 25 MBinning *fBinsTheta; 26 MBinning *fBinsEnergy; 27 // Coarse zenith angle and energy bins used in the analysis 28 29 TF1 *fSpectrum; 30 // Tentative energy spectrum. This modifies slightly the calculation 31 // of the effective area (see MHMcCollectionArea::Calc) 32 20 33 21 34 MHMcCollectionArea *fCollArea; … … 23 36 TString fObjName; 24 37 25 UInt_t fTotalNumSimulatedShowers; 26 UInt_t fCorsikaVersion; 27 Bool_t fAllEvtsTriggered; 28 Float_t fThetaMin; 29 Float_t fThetaMax; 30 31 Bool_t ReInit(MParList *plist); 32 33 Int_t PreProcess(MParList *pList); 34 Int_t Process(); 35 Int_t PostProcess(); 38 Int_t PreProcess(MParList *pList); 39 Int_t Process(); 40 Int_t PostProcess(); 36 41 37 42 public: 38 MMcCollectionAreaCalc(const char *input=NULL, 39 const char *name=NULL, const char *title=NULL); 43 MMcCollectionAreaCalc(const char *input = NULL, 44 const char *name = NULL, const char *title = NULL); 45 46 void SetSpectrum(TF1 *f) { fSpectrum = f; } 40 47 41 48 ClassDef(MMcCollectionAreaCalc, 0) // Task to calculate the collection area histogram
Note:
See TracChangeset
for help on using the changeset viewer.