Changeset 7409 for trunk/MagicSoft/Mars/mfilter
- Timestamp:
- 11/18/05 17:15:30 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/mfilter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc
r2206 r7409 18 18 ! Author(s): Antonio Stamerra 02/2003 <mailto:antonio.stamerra@pi.infn.it> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 320 ! Copyright: MAGIC Software Development, 2000-2005 21 21 ! 22 22 ! … … 65 65 // -------------------------------------------------------------------------- 66 66 // 67 // Default Constructor 68 // 69 MFEnergySlope::MFEnergySlope(const char *name, const char *title): 70 fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.) 71 { 72 fName = name ? name : "MFEnergySlope"; 73 fTitle = title ? title : "Filter to select energy with given slope"; 74 } 75 76 // -------------------------------------------------------------------------- 77 // 67 78 // Constructor 68 79 // 69 MFEnergySlope::MFEnergySlope(const char *name, const char *title): 70 fNumSelectedEvts(0), fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.) 71 { 72 // fContName = cname; 73 fName = name ? name : "MFEnergySlope"; 74 fTitle = title ? title : "Filter to select energy with given slope"; 80 MFEnergySlope::MFEnergySlope(Float_t slope, const char *name, const char *title): 81 fNewSlope(TMath::Abs(slope)), fMcMinEnergy(-1.), fMcMaxEnergy(-1.) 82 { 83 fName = name ? name : "MFEnergySlope"; 84 fTitle = title ? title : "Filter to select energy with given slope"; 75 85 } 76 86 … … 84 94 Int_t MFEnergySlope::PreProcess(MParList *pList) 85 95 { 86 96 if (fNewSlope<0) 97 { 98 *fLog << err << "New slope still undefined... aborting." << endl; 99 return kFALSE; 100 } 101 102 fEvt = (MMcEvt*)pList->FindObject("MMcEvt"); 103 if (!fEvt) 104 { 105 *fLog << err << "MMcEvt not found... aborting." << endl; 106 return kFALSE; 107 } 108 109 return kTRUE; 110 } 111 112 // -------------------------------------------------------------------------- 113 // 114 // Preprocess 115 // 116 // MC slope and min/max energy are read 117 // Normalization factor is computed 118 // 119 Bool_t MFEnergySlope::ReInit(MParList *pList) 120 { 87 121 MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader"); 88 89 122 if (!runheader) 90 { 91 *fLog << err << dbginf << fName << " [MMcCorsikaRunHeader] not found... aborting." << endl; 92 return kFALSE; 93 } 123 { 124 *fLog << err << "MMcCorsikaRunHeader not found... aborting." << endl; 125 return kFALSE; 126 } 127 94 128 // 95 // Read info from the MC sample (it must be generated with 129 // Read info from the MC sample (it must be generated with 96 130 // reflector ver.0.6 and camera ver. 0.6) 97 131 // 98 fMcSlope = runheader->GetSlopeSpec(); 132 fMcSlope = runheader->GetSlopeSpec(); 99 133 if (fMcMinEnergy<0) 100 fMcMinEnergy = runheader->GetELowLim();134 fMcMinEnergy = runheader->GetELowLim(); 101 135 if (fMcMinEnergy<0) 102 fMcMaxEnergy = runheader->GetEUppLim(); 103 104 *fLog << inf; 105 *fLog << "MFEnergySlope::PreProcess: fetched MC info:" << endl; 106 *fLog << " E Slope: " << fMcSlope << endl; 107 *fLog << " E Min: " << fMcMinEnergy << endl; 108 *fLog << " E Max: " << fMcMaxEnergy << endl; 109 *fLog << " New E Slope: " << fNewSlope << endl; 110 136 fMcMaxEnergy = runheader->GetEUppLim(); 137 111 138 // Slope is used with positive values in the code 112 139 if (fNewSlope < 0) 113 fNewSlope *= -1;140 fNewSlope *= -1; 114 141 if (fMcSlope < 0) 115 fMcSlope *= -1; 116 117 118 // Set normalization on energy 119 fN0 = pow(fNewSlope>fMcSlope?fMcMinEnergy:fMcMaxEnergy,fNewSlope-fMcSlope); 120 121 *fLog << "Normalization factor:" <<fN0 << endl; 122 123 //--- 124 fEvt = (MMcEvt*)pList->FindObject("MMcEvt"); 125 if (!fEvt) 126 { 127 *fLog << err << dbginf << fName << " [MMcEvt] not found... aborting." << endl; 128 return kFALSE; 129 } 142 fMcSlope *= -1; 143 144 // Calculate normalization factor 145 fN0 = TMath::Power(fNewSlope>fMcSlope ? fMcMinEnergy : fMcMaxEnergy, fNewSlope-fMcSlope); 146 147 // Print some infos 148 *fLog << inf; 149 *fLog << "Fetched MC info:" << endl; 150 *fLog << " Change E Slope " << fMcSlope << " (" << fMcMinEnergy << " < E < "; 151 *fLog << fMcMaxEnergy << ") to " << fNewSlope << endl; 152 *fLog << " Norm factor: " << fN0 << endl; 130 153 131 154 return kTRUE; … … 144 167 Int_t MFEnergySlope::Process() 145 168 { 146 fResult = kTRUE; 147 148 // Energy slopes are the same: skip it 149 if (fNewSlope == fMcSlope) 169 fResult = kTRUE; 170 171 // Energy slopes are the same: skip it 172 if (fNewSlope == fMcSlope) 173 return kTRUE; 174 175 // The value of the normalized spectrum is compared with a 176 // random value in [0,1]; 177 // if the latter is higher the event is accepted 178 const Float_t energy = fEvt->GetEnergy(); 179 180 /* 181 // 182 // If energy bounds different from MC ones are selected, then 183 // events outside these bounds are rejected, as their slope has 184 // not been changed. 185 // 186 if (energy > fMcMaxEnergy || energy < fMcMinEnergy) 187 { 188 fResult = kFALSE; 189 return kTRUE; 190 } 191 */ 192 193 const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope); 194 const Float_t Nrnd = gRandom->Uniform(); 195 196 fResult = Nexp > Nrnd; 197 198 //if (fResult) 199 // fNumSelectedEvts++; 200 150 201 return kTRUE; 151 152 // The value of the normalized spectrum is compared with a 153 // random value in [0,1]; 154 // if the latter is higher the event is accepted 155 const Float_t energy = fEvt->GetEnergy(); 156 157 /* 158 // 159 // If energy bounds different from MC ones are selected, then 160 // events outside these bounds are rejected, as their slope has 161 // not been changed. 162 // 163 if (energy > fMcMaxEnergy || energy < fMcMinEnergy) 164 { 165 fResult = kFALSE; 166 return kTRUE; 167 } 168 */ 169 170 const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope); 171 const Float_t Nrnd = gRandom->Uniform(); 172 173 fResult = Nexp > Nrnd; 174 175 if (!fResult) 176 return kTRUE; 177 178 fNumSelectedEvts++; 179 return kTRUE; 180 } 181 202 } 203 204 205 // -------------------------------------------------------------------------- 206 // 207 // MFEnergySlope.NewSlope: -2.8 208 // 209 Int_t MFEnergySlope::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 210 { 211 Bool_t rc = kFALSE; 212 if (IsEnvDefined(env, prefix, "NewSlope", print)) 213 { 214 rc = kTRUE; 215 SetNewSlope(GetEnvValue(env, prefix, "NewSlope", fNewSlope)); 216 } 217 return rc; 218 } -
trunk/MagicSoft/Mars/mfilter/MFEnergySlope.h
r2206 r7409 1 1 #ifndef MARS_MFEnergySlope 2 2 #define MARS_MFEnergySlope 3 /////////////////////////////////////////////////////////////////////////////4 // //5 // MFEnergySlope //6 // //7 /////////////////////////////////////////////////////////////////////////////8 3 9 4 #ifndef MARS_MFilter … … 11 6 #endif 12 7 8 class MMcEvt; 13 9 class MParList; 14 class MMcEvt;15 10 class MMcCorsikaRunHeader; 16 11 … … 18 13 { 19 14 private: 20 Int_t fNumSelectedEvts; // counter for number of selected events15 //Int_t fNumSelectedEvts; // counter for number of selected events 21 16 22 MMcEvt *fEvt; // Events used to determin energy slope17 MMcEvt *fEvt; //! Events used to determin energy slope 23 18 24 Bool_t fResult; // Result returned by IsExpressionTrue25 19 Float_t fNewSlope; // New slope set by user 20 Float_t fMcSlope; //! Original energy slope from MC data 26 21 27 Float_t fMcSlope; // Original energy slope from MC data 28 Float_t fMcMinEnergy; // Starting energy of MC data 29 Float_t fMcMaxEnergy; // Ending energy of MC data 22 Float_t fMcMinEnergy; //! Starting energy of MC data 23 Float_t fMcMaxEnergy; //! Ending energy of MC data 30 24 31 Float_t fN0; // Normalization factor25 Float_t fN0; //! Normalization factor 32 26 33 Int_t PreProcess(MParList *pList); 34 Int_t Process(); 27 Bool_t fResult; //! Result returned by IsExpressionTrue 28 29 // MTask 30 Int_t PreProcess(MParList *pList); 31 Bool_t ReInit(MParList *pList); 32 Int_t Process(); 33 34 // MFilter 35 Bool_t IsExpressionTrue() const { return fResult; } 35 36 36 37 public: 37 38 MFEnergySlope(const char *name=NULL, const char *title=NULL); 39 MFEnergySlope(Float_t slope, const char *name=NULL, const char *title=NULL); 38 40 39 Bool_t IsExpressionTrue() const { return fResult; } 41 // Setter 42 void SetNewSlope(Float_t f) { fNewSlope = TMath::Abs(f); } 43 void SetMcSlope(Float_t f) { fMcSlope = TMath::Abs(f); } 40 44 41 // Slope is used with positive values in the code 42 void SetNewSlope(Float_t f) {fNewSlope = TMath::Abs(f);} 43 void SetMcSlope(Float_t f) {fMcSlope = TMath::Abs(f);} 45 void SetMcMinEnergy(Float_t f) { fMcMinEnergy = f; } 46 void SetMcMaxEnergy(Float_t f) { fMcMaxEnergy = f; } 44 47 45 void SetMcMinEnergy(Float_t f) {fMcMinEnergy = f;}46 void SetMcMaxEnergy(Float_t f) {fMcMaxEnergy = f;}48 // MParContainer 49 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 47 50 48 51 ClassDef(MFEnergySlope, 0) // A Filter to select events with a given energy slope
Note:
See TracChangeset
for help on using the changeset viewer.