Changeset 12690 for fact/tools/rootmacros/gainfit2.C
- Timestamp:
- 12/02/11 18:43:49 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/gainfit2.C
r12640 r12690 31 31 float amplMean; 32 32 } proj; 33 vector<proj> proj_of_pixel; 33 vector<proj> channel; 34 35 36 //----------------------------------------------------------------------------- 37 // Decleration of Histograms 38 //----------------------------------------------------------------------------- 39 40 //Amplification Distribution 41 TH1F *hAmplDistribution = NULL; 42 TH1F *hAmplDistribution2 = NULL; 43 TH1F *hAmplVsChannel = NULL; 44 45 //Lists of Histograms taht are to be saved 46 TObjArray hList; 47 TObjArray hListPeakSpektra; 48 34 49 35 50 //----------------------------------------------------------------------------- … … 37 52 //----------------------------------------------------------------------------- 38 53 54 void BookHistos(); 55 void SaveHistograms(const char * ); 56 //Double_t spek_fit(Double_t *x, Double_t *par) 57 39 58 40 59 //----------------------------------------------------------------------------- … … 44 63 45 64 int gainfit2( 46 const char * InputRootFileName = "../analysis/fpeak/20111109_006_fpeak.root", 47 const char * OutTextFileName = "../analysis/fpeak/20111109_006_gainfit.txt", 48 //TODO: Output into txt-file 65 const char * InputRootFileName = "../analysis/fpeak/20111109_006/20111109_006_fpeak.root", 66 const char * InputBaselineFileName = "../analysis/fpeak/20111109_006/20111109_006_fbsl.root", 67 const char * OutTextFileName = "../analysis/fpeak/20111109_006_gainfit_test.txt", 68 const char * RootOutFileName = "../analysis/fpeak/20111109_006_gainfit_test.root", 49 69 bool showHistos = false, 50 70 bool debug = false) … … 55 75 //----------------------------------------------------------------------------- 56 76 77 //Open Rootfiles Files 78 TFile * baseline = TFile::Open( InputBaselineFileName ); 79 TFile * file = TFile::Open( InputRootFileName ); 80 81 57 82 TH1D *hPixelProjection = NULL; 58 TFile * file = TFile::Open( InputRootFileName ); 83 //Baseline 84 TH2F * hbaseline = (TH2F*)baseline->Get("histo_mean"); 85 //Amplitude spectrum 59 86 TH2F *h = (TH2F*)file->Get("hAmplSpek_cfd"); 60 87 88 BookHistos(); 61 89 62 90 Double_t par[9]; … … 65 93 TF1 *g3 = new TF1("g3","gaus",25,35); 66 94 TF1 *g4 = new TF1("g4","gaus"); 67 TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",5,35); 68 TH1F *hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (1+2)", 500, 0 , 20 ); 69 TH1F *hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 ); 70 TH1F *hAmplDistribution3 = new TH1F("hAmplDistribution3","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 ); 71 72 TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 800,800); 73 //TCanvas *cGainDist = new TCanvas("cGainDist", "cGainDist", 0,501, 1000,500); 95 TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,32); 96 97 98 TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 1200,400); 74 99 cGainFit->Clear(); 75 cGainFit->Divide( 2, 2);76 77 //----------------------------------------------------------------------------- 78 // Loop over all Pixels and fit Distribution of singles, doubles and tripples 79 //----------------------------------------------------------------------------- 100 cGainFit->Divide(3, 2); 101 102 TCanvas *cGraphs = new TCanvas("cGraphs", "Horst", 0,401, 1200,400); 103 cGraphs->Clear(); 104 cGraphs->Divide(1, 2); 80 105 81 106 cGainFit->cd(1); … … 85 110 h->SetAxisRange(0, 100, "Y"); 86 111 h->Draw("COLZ"); 87 proj_of_pixel.resize(h->GetNbinsX());112 channel.resize(h->GetNbinsX()); 88 113 NumberOfPixels = h->GetNbinsX(); 114 115 cGainFit->cd(2); 116 hbaseline->SetTitle("Baselinedistribution of all Pixels"); 117 hbaseline->SetAxisRange(-5, 5, "X"); 118 //hbaseline->SetAxisRange(0, 100, "Y"); 119 hbaseline->Fit("gaus"); 120 hbaseline->Draw(); 121 122 //----------------------------------------------------------------------------- 123 // Graphs 124 //----------------------------------------------------------------------------- 125 126 Double_t simple_gain[NumberOfPixels]; 127 Double_t gain[NumberOfPixels]; 128 Double_t pixelvec[NumberOfPixels]; 129 for (UInt_t i=0; i<NumberOfPixels; i++){ 130 pixelvec[i]=i; 131 simple_gain[i]=0; 132 gain[i]=0; 133 } 134 135 TGraph *gr1 = new TGraph(NumberOfPixels,pixelvec,simple_gain); 136 TGraph *gr2 = new TGraph(NumberOfPixels,pixelvec,gain); 137 138 gr1->SetMarkerStyle(5); 139 gr2->SetMarkerStyle(2); 140 gr1->SetMarkerColor(kRed); 141 gr2->SetMarkerColor(kBlack); 142 gr1->SetMarkerSize(0.5); 143 gr2->SetMarkerSize(0.5); 144 TMultiGraph *mg = new TMultiGraph(); 145 mg->Add(gr1); 146 mg->Add(gr2); 147 148 149 150 151 //----------------------------------------------------------------------------- 152 // Loop over all Pixels and fit Distribution of singles, doubles and tripples 153 //----------------------------------------------------------------------------- 154 89 155 cout << "Number of Pixels: " << NumberOfPixels << endl; 90 91 156 // Begin of Loop 92 157 for (UInt_t pixel = 0; pixel < NumberOfPixels; pixel++){ 158 159 //Title 160 TString pixelnumber; 161 pixelnumber += "hPixelProj"; 162 pixelnumber += "_"; 163 pixelnumber += pixel + 1 ; 93 164 94 165 cout << "-----------------------------------------------------------" << endl; … … 96 167 cout << "-----------------------------------------------------------" << endl; 97 168 98 hPixelProjection = h->ProjectionY( "# ", pixel+1, pixel+1); //Projectipon of each Pixel out of Ampl.Spectrum169 hPixelProjection = h->ProjectionY( pixelnumber , pixel+1, pixel+1); //Projectipon of each Pixel out of Ampl.Spectrum 99 170 hPixelProjection->SetTitle("Amplitude Spectrum of one Pixels"); 100 171 hPixelProjection->SetAxisRange(0, 40, "X"); … … 105 176 106 177 total->SetLineColor(2); 107 cGainFit->cd( 2);178 cGainFit->cd(3); 108 179 gPad->SetLogy(1); 109 180 hPixelProjection->SetYTitle("Counts"); … … 126 197 //----------------------------------------------------------------------------- 127 198 128 // total->GetParameters( proj_of_pixel[ pixel ].fitParameters);129 proj_of_pixel[ pixel ].PID = pixel+1;130 131 132 // proj_of_pixel[ pixel ].tripple_peakSigm = total->GetParameter(8);133 // proj_of_pixel[ pixel ].ampl = total->GetParameter(1) - total->GetParameter(4);199 // total->GetParameters(channel[ pixel ].fitParameters); 200 channel[ pixel ].PID = pixel+1; 201 202 203 // channel[ pixel ].tripple_peakSigm = total->GetParameter(8); 204 // channel[ pixel ].ampl = total->GetParameter(1) - total->GetParameter(4); 134 205 135 206 //----------------------------------------------------------------------------- 136 207 // Draw Histograms 137 208 //----------------------------------------------------------------------------- 138 139 cGainFit->cd(3);140 gPad->SetLogy(1);141 g4->SetLineColor(2);142 hAmplDistribution->SetXTitle("Amplification [mV]");143 hAmplDistribution->SetYTitle("Counts");144 hAmplDistribution->SetAxisRange(7.5, 12.5, "X");145 proj_of_pixel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);146 hAmplDistribution->Fill( proj_of_pixel[ pixel ].amplSD ) ;147 hAmplDistribution->Fit(g4);148 209 149 210 cGainFit->cd(4); 150 211 gPad->SetLogy(1); 151 212 g4->SetLineColor(2); 152 hAmplDistribution2->SetXTitle("Amplification [mV]"); 153 hAmplDistribution2->SetYTitle("Counts"); 154 hAmplDistribution2->SetAxisRange(7.5, 12.5, "X"); 155 proj_of_pixel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4); 156 hAmplDistribution2->Fill(proj_of_pixel[ pixel ].amplDT) ; 213 channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1); 214 hAmplDistribution->Fill( channel[ pixel ].amplSD ) ; 215 hAmplDistribution->Fit(g4); 216 217 cGainFit->cd(5); 218 gPad->SetLogy(1); 219 g4->SetLineColor(2); 220 channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4); 221 hAmplDistribution2->Fill(channel[ pixel ].amplDT) ; 157 222 hAmplDistribution2->Fit(g4); 158 223 224 cGainFit->cd(6); 225 hAmplVsChannel->SetBinContent(pixel, channel[ pixel ].amplSD); 226 227 gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplSD); 228 gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplDT); 229 230 159 231 if( showHistos ){ 160 cGainFit->cd(3); 232 if (pixel%40==0){ 233 cGainFit->cd(4); 161 234 hAmplDistribution->Draw(); 162 cGainFit->cd( 4);235 cGainFit->cd(5); 163 236 hAmplDistribution2->Draw(); 237 } 238 239 cGainFit->cd(6); 240 hAmplVsChannel->Draw(); 241 if (pixel%60==0){ 242 cGraphs->cd(2); 243 mg->Draw("APL"); 244 cGraphs->cd(1); 245 gr1->Draw("APL"); 246 } 247 164 248 cGainFit->Modified(); 165 249 cGainFit->Update(); 250 cGraphs->Modified(); 251 cGraphs->Update(); 166 252 } 167 253 if(debug){ … … 180 266 //----------------------------------------------------------------------------- 181 267 182 cGainFit->cd( 2);268 cGainFit->cd(3); 183 269 hPixelProjection->Draw(); 184 270 hPixelProjection->Fit(total,"R+"); 185 271 186 cGainFit->cd( 3);272 cGainFit->cd(4); 187 273 hAmplDistribution->Draw(); 188 274 189 cGainFit->cd( 4);275 cGainFit->cd(5); 190 276 hAmplDistribution2->Draw(); 277 278 cGainFit->cd(6); 279 hAmplVsChannel->Draw(); 191 280 192 281 cGainFit->Modified(); 193 282 cGainFit->Update(); 283 284 cGraphs->cd(2); 285 mg->Draw("APL"); 286 cGraphs->cd(1); 287 gr1->Draw("APL"); 288 cGraphs->Modified(); 289 cGraphs->Update(); 194 290 195 291 //----------------------------------------------------------------------------- … … 220 316 out << "# PixelID : gain between Single and Double Peak : gain between Double and Tripple Peak " << endl; 221 317 out << "# gain is derived from the parameters of a three gaussian fit function " << endl; 222 for ( int pixel=0; pixel<1440; pixel++){223 out << proj_of_pixel[ pixel ].PID << ";\t" ;224 out << proj_of_pixel[ pixel ].amplSD << ";\t" ;225 out << proj_of_pixel[ pixel ].amplDT << ";\t" ;318 for (UInt_t pixel=0; pixel<NumberOfPixels; pixel++){ 319 out << channel[ pixel ].PID << ";\t" ; 320 out << channel[ pixel ].amplSD << ";\t" ; 321 out << channel[ pixel ].amplDT << ";\t" ; 226 322 out << filename << endl; 227 323 228 324 } 229 325 out.close(); 230 326 SaveHistograms( RootOutFileName ); 231 327 return( 0 ); 232 328 } 329 330 //----------------------------------------------------------------------------- 331 // End of Main 332 //----------------------------------------------------------------------------- 333 334 335 336 337 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 338 //+ + 339 //+ Function definitions + 340 //+ + 341 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 342 343 344 345 //----------------------------------------------------------------------------- 346 // Function: Book Histograms 347 //----------------------------------------------------------------------------- 348 349 void BookHistos(){ 350 351 //Amplification Distribution - Single2Double 352 hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (1+2)", 500, 0 , 20 ); 353 hAmplDistribution->SetXTitle("Amplification [mV]"); 354 hAmplDistribution->SetYTitle("Counts"); 355 hAmplDistribution->SetAxisRange(7.5, 12.5, "X"); 356 hList.Add( hAmplDistribution ); 357 358 //Amplification Distribution2 - Double2Tripple 359 hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 ); 360 hAmplDistribution2->SetXTitle("Amplification [mV]"); 361 hAmplDistribution2->SetYTitle("Counts"); 362 hAmplDistribution2->SetAxisRange(7.5, 12.5, "X"); 363 hList.Add( hAmplDistribution2 ); 364 365 //Amplification vs Channels 366 hAmplVsChannel = new TH1F("hAmplVsChannel","Amplifications (SD) of each Channel", 1440, -0.5 , 1439.5 ); 367 hAmplVsChannel->SetYTitle("Amplification [mV]"); 368 hAmplVsChannel->SetXTitle("Channels"); 369 hAmplVsChannel->SetLineColor(2); 370 hList.Add( hAmplVsChannel ); 371 } 372 373 //----------------------------------------------------------------------------- 374 // Save Histograms 375 //----------------------------------------------------------------------------- 376 377 void SaveHistograms( const char * loc_fname){ 378 // create the histogram file (replace if already existing) 379 TFile tf( loc_fname, "RECREATE"); 380 381 hList.Write(); // write the major histograms into the top level directory 382 tf.mkdir("PeakSpektra"); tf.cd("PeakSpektra"); // go to new subdirectory 383 hListPeakSpektra.Write(); // write histos into subdirectory 384 385 tf.Close(); // close the file 386 } 387 388 //----------------------------------------------------------------------------- 389 // MulitOrder MultiGauß Function 390 //----------------------------------------------------------------------------- 391 392 /* 393 Double_t spek_fit(Double_t *x, Double_t *par, Uint_t *maxorder) 394 { 395 Double_t exp = 0; 396 397 //Double_t arg2 = 0; 398 //if (par[2] != 0) arg = (v[0] - par[1])/par[2]; 399 //if (par[5] != 0) arg2 = (v[0] - par[4])/par[5]; 400 401 //Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg) + par[3]*TMath::Exp(-0.5*arg2*arg2); 402 403 for(int order = 0; order < maxorder; order++){ 404 peak[order]=par[0]*par[4]/(order+1)*((x[0]-(order+1)*par[1])*(x[0]-(order+1)*par[1]))/(par[2]*par[2]); 405 exp = exp + peak[order]; 406 } 407 408 Double_t fitval = TMath::Exp(-0.5*exp); 409 return fitval; 410 } 411 */ 412
Note:
See TracChangeset
for help on using the changeset viewer.