Changeset 14476
- Timestamp:
- 10/15/12 14:27:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/PulseTemplates/pulse.C
r14472 r14476 10 10 Pulse::Pulse() 11 11 { 12 InitMembers(); 13 } 14 15 Pulse::Pulse(TString name) 16 { 17 InitMembers(); 18 mName = name; 19 } 20 21 Pulse::Pulse(TString name, TH1* histo) 22 { 23 InitMembers(); 24 mName = name; 25 mHisto = histo; 26 Fit(mName, mOptions, mType); 27 } 28 29 Pulse::Pulse(TString name, TH1* histo, int type) 30 { 31 InitMembers(); 32 mName = name; 33 mHisto = histo; 34 mType = type; 35 Fit(mName, mOptions, mType); 36 } 37 38 Pulse::Pulse(TString name, TH1* histo, TString options) 39 { 40 InitMembers(); 41 mName = name; 42 mHisto = histo; 43 mOptions += options; 44 Fit(mName, mOptions, mType); 45 } 46 47 Pulse::Pulse(TString name, TH1* histo, TString options, int type) 48 { 49 InitMembers(); 50 mName = name; 51 mHisto = histo; 52 mOptions += options; 53 mType = type; 54 Fit(mName, mOptions, mType); 55 } 56 57 58 Pulse::~Pulse() 59 { 60 delete mModel; 61 } 62 63 void 64 Pulse::InitMembers() 65 { 66 mName = "pulse"; 12 67 mHisto = NULL; 13 mOptions = ""; 68 mModel = NULL; 69 mOptions = "S"; 14 70 mBsl = 0; 15 71 mHeight = 0; 16 m Start= 0;17 m Rising= 0;18 mTau Rising= 0;19 mTau Falling= 0;72 mT0 = 0; 73 mT1 = 0; 74 mTau1 = 0; 75 mTau2 = 0; 20 76 mIntegral = 0; 21 77 mAmplitude = 0; 22 78 mPhE = 0; 23 } 24 25 Pulse::Pulse(TH1* histo) 26 { 27 mHisto = histo; 28 mOptions = ""; 29 mBsl = 0; 30 mHeight = 0; 31 mStart = 0; 32 mRising = 0; 33 mTauRising = 0; 34 mTauFalling = 0; 35 mIntegral = 0; 36 mAmplitude = 0; 37 mPhE = 0; 38 } 39 40 Pulse::Pulse(TH1* histo, TString options) 41 { 42 mHisto = histo; 43 mOptions = options; 44 mBsl = 0; 45 mHeight = 0; 46 mStart = 0; 47 mRising = 0; 48 mTauRising = 0; 49 mTauFalling = 0; 50 mIntegral = 0; 51 mAmplitude = 0; 52 mPhE = 0; 53 } 54 55 Pulse::~Pulse() 56 { 57 79 mType = 0; 80 mFitProb = 0; 81 mFitNCalls = 0; 82 mFitNdf = 0; 83 mChi2 = 0; 58 84 } 59 85 … … 61 87 Pulse::Fit( 62 88 TString fitName, 63 TString fitOptions 89 TString fitOptions, 90 int type 64 91 ) 65 92 { … … 70 97 fitName, 71 98 fitOptions, 99 type, 72 100 fitMin, 73 101 fitMax 74 );102 ); 75 103 } 76 104 77 105 void 78 106 Pulse::Fit( 107 TString fitName, 108 TString fitOptions, 109 int type, 110 int fitMin, 111 int fitMax 112 ) 113 { 114 fitOptions += "R"; 115 if (type == 0) 116 FitSectionWise( 117 "Model0", 118 fitOptions, 119 fitMin, 120 fitMax 121 ); 122 else if (type == 1) 123 FitContious( 124 "Model1", 125 fitOptions, 126 fitMin, 127 fitMax 128 ); 129 else{ 130 cout << "not a correct type number --> fitting skipped!" << endl; 131 return; 132 } 133 134 CalculateParameters(); 135 return; 136 } 137 138 void 139 Pulse::FitSectionWise( 79 140 TString fitName, 80 141 TString fitOptions, … … 83 144 ) 84 145 { 85 TF1 fit(fitName, shapeFunc, fitMin, fitMax, 6 ); 146 mFitMin = fitMin; 147 mFitMax = fitMax; 148 mModel = new TF1(fitName, shapeFunc, fitMin, fitMax, 6 ); 86 149 87 150 // ====================================================================== … … 92 155 int first_bin = mHisto->GetXaxis()->GetFirst(); 93 156 94 for (int i = 0; i < 10; i++){157 for (int i = 0; i < 30; i++){ 95 158 bsl += mHisto->GetBinContent(first_bin+0); 96 159 } 97 bsl = bsl/ 10;160 bsl = bsl/30; 98 161 99 162 double stop = mHisto->GetMaximumBin(); //pos of max 100 163 double height = mHisto->GetBinContent(stop); 101 164 double start = stop-10; //pos 10 slices before maximum 102 double rising = (stop - start)/tau;103 165 // ====================================================================== 104 166 … … 107 169 108 170 109 fit.SetParameters(para); 110 fit.SetParNames("BSL", "Height", "Start", "Rising", "Tau1", "TauFalling"); 111 fit.SetLineColor(kRed); 112 mHisto->Fit(&fit, fitOptions); 113 114 mBsl = fit.GetParameter(0); 115 mHeight = fit.GetParameter(1); 116 mStart = fit.GetParameter(2); 117 mRising = fit.GetParameter(3); 118 mTauRising = fit.GetParameter(4); 119 mTauFalling = fit.GetParameter(5); 120 } 121 122 void 123 Pulse::Fit2( 124 TString fitName, 125 TString fitOptions 126 ) 127 { 128 int fitMin = mHisto->GetXaxis()->GetFirst(); 129 int fitMax = mHisto->GetXaxis()->GetLast(); 130 131 Fit2( 132 fitName, 133 fitOptions, 134 fitMin, 135 fitMax 136 ); 137 } 138 139 void 140 Pulse::Fit2( 171 mModel->SetParameters(para); 172 mModel->SetParNames("BSL", "A0", "t0", "t1", "Tau1", "Tau2"); 173 mModel->SetLineColor(kRed); 174 175 mFitResultPtr = mHisto->Fit(mModel, fitOptions); 176 177 mBsl = mModel->GetParameter(0); 178 mHeight = mModel->GetParameter(1); 179 mT0 = mModel->GetParameter(2); 180 mT1 = mModel->GetParameter(3); 181 mTau1 = mModel->GetParameter(4); 182 mTau2 = mModel->GetParameter(5); 183 } 184 185 void 186 Pulse::FitContious( 141 187 TString fitName, 142 188 TString fitOptions, … … 145 191 ) 146 192 { 147 TF1 fit(fitName, shapeFunc2, fitMin, fitMax, 5 ); 193 mFitMin = fitMin; 194 mFitMax = fitMax; 195 mModel = new TF1(fitName, shapeFunc2, fitMin, fitMax, 5 ); 148 196 149 197 // ====================================================================== … … 154 202 int first_bin = mHisto->GetXaxis()->GetFirst(); 155 203 156 for (int i = 0; i < 10; i++){204 for (int i = 0; i < 30; i++){ 157 205 bsl += mHisto->GetBinContent(first_bin+0); 158 206 } 159 bsl = bsl/ 10;207 bsl = bsl/30; 160 208 161 209 double stop = mHisto->GetMaximumBin(); //pos of max … … 166 214 167 215 double para[] = {bsl, amplitude, start, tau, tau}; 168 fit.SetParameters(para); 169 fit.SetParNames("BSL", "Amplitude", "Start", "Tau1", "TauFalling"); 170 fit.SetLineColor(kBlue); 171 mHisto->Fit(&fit, fitOptions); 172 173 mBsl = fit.GetParameter(0); 174 mAmplitude = fit.GetParameter(1); 175 mStart = fit.GetParameter(2); 176 mTauRising = fit.GetParameter(3); 177 mTauFalling = fit.GetParameter(4); 216 mModel->SetParameters(para); 217 mModel->SetParNames("BSL", "A0", "t0", "Tau1", "Tau2"); 218 mModel->SetLineColor(kBlue); 219 220 mFitResultPtr = mHisto->Fit(mModel, fitOptions); 221 222 mBsl = mModel->GetParameter(0); 223 mHeight = mModel->GetParameter(1); 224 mT0 = mModel->GetParameter(2); 225 mTau1 = mModel->GetParameter(3); 226 mTau2 = mModel->GetParameter(4); 178 227 } 179 228 180 229 double Pulse::GetBsl(){ return mBsl;} 181 230 double Pulse::GetHeight(){ return mHeight;} 182 double Pulse::GetAvalancheStart(){ return m Start;}183 double Pulse::GetAvalancheEnd(){ return m Rising;}184 double Pulse::GetTimeConstRising(){ return mTau Rising;}185 double Pulse::GetTimeConstFalling(){ return mTau Falling;}231 double Pulse::GetAvalancheStart(){ return mT0;} 232 double Pulse::GetAvalancheEnd(){ return mT1;} 233 double Pulse::GetTimeConstRising(){ return mTau1;} 234 double Pulse::GetTimeConstFalling(){ return mTau2;} 186 235 double Pulse::GetIntegral(){ return mIntegral;} 187 236 double Pulse::GetAmplitude(){ return mAmplitude;} 188 237 int Pulse::GetPE(){ return mPhE;} 189 238 239 void 240 Pulse::CalculateParameters() 241 { 242 mIntegral = mModel->Integral(mFitMin, mFitMax); 243 mAmplitude = mModel->GetMaximum() - mBsl; 244 mFitProb = mFitResultPtr->Prob(); 245 mFitNCalls = mFitResultPtr->NCalls(); 246 mFitNdf = mFitResultPtr->Ndf(); 247 mChi2 = mFitResultPtr->Chi2(); 248 } 249 250 190 251 //double 191 252 int Heaviside(double val) 192 253 { 193 if( val < 0) return 0;194 254 if( val >= 0) return 1; 255 else return 0; 195 256 } 196 257 … … 214 275 // helper variables 215 276 // double max = start + rising * tau1; 216 double e1 = height *(1 - Exp(-(t[0]-start)/tau1 ) );277 double e1 = (1 - Exp(-(t[0]-start)/tau1 ) ); 217 278 // double e2 = (-1) * height * (1 - Exp(-(x[0]-max)/tau2 ) ); 218 double e2 = (-1) * height *(1 - Exp(-(t[0]-stop)/tau2 ) );279 double e2 = (-1) * (1 - Exp(-(t[0]-stop)/tau2 ) ); 219 280 // calculate return value 281 returnval += Heaviside(t[0]-start)*e1; 282 returnval += Heaviside(t[0]-stop)*e2; 283 returnval *= height; 220 284 returnval += bsl; 221 222 if (t[0] > start) 223 returnval += e1; 224 if (t[0] > stop) 225 returnval += e2; 285 // if (t[0] > start) 286 // returnval += e1; 287 // if (t[0] > stop) 288 // returnval += e2; 226 289 227 290 return returnval; 228 } 291 292 293 } 294 295 229 296 230 297 /* … … 282 349 return returnval; 283 350 } 284
Note:
See TracChangeset
for help on using the changeset viewer.