Changeset 12713
- Timestamp:
- 12/09/11 18:32:03 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/gainfit2.C
r12712 r12713 1 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 //+ Root Macro: GainFit2 for FACT + 3 //+---------------------------------------------------------------------------+ 4 //+ by: jens.buss@tu-dortmund.de + 5 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 // 7 // - analyse gain of pixels from Dark-Count-Photon-Spektrum (pedestal on) 8 // - read a root-file produced by "fpeak.C" and get Amplitudespektrum 9 // of all pixel 10 // - read a root-file produced by "fbsl.C" and get baseline 11 // - calculate pixelgain from multi-gaussian-fit 12 // over each pixels amplitudespektrum 13 // - draw distribution of gains 14 // - draw gain vs. pixel 15 // - find Pixels with deviating gainvalue (e.g. dead , crazy Pixels) 16 // and write their number to log-file (e.g. date_run_gainfit.txt) 17 // - save histograms into root-file (e.g. date_run_gainfit.root) 18 // 19 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 20 1 21 #include <TFile.h> 2 22 #include <TH2F.h> … … 29 49 Double_t amplSD; 30 50 Double_t amplDT; 31 Double_t amplMean;51 Double_t cross; 32 52 Double_t ampl_fspek_fit; 53 Double_t ampl_fspek_fit2; 54 Double_t bsl; 33 55 bool crazy; 34 56 } proj; … … 42 64 dist_t distribution; 43 65 66 //Verbosity for Histograms 67 TString verbos[3]={"Q","", ""}; 44 68 //----------------------------------------------------------------------------- 45 69 // Decleration of Histograms … … 49 73 TH1F *hAmplDistribution = NULL; 50 74 TH1F *hAmplDistribution2 = NULL; 51 TH1F *h PixelGainFit= NULL;75 TH1F *hGainFitBsl = NULL; 52 76 53 77 //Lists of Histograms that have to be saved 54 78 TObjArray hList; 55 79 TObjArray hListPeakSpektra; 80 TObjArray hListCrazy; 56 81 57 82 //----------------------------------------------------------------------------- … … 63 88 void BookHistos(); 64 89 void SaveHistograms(const char * ); 65 bool SearchAnormal(UInt_t, Double_t );90 bool SearchAnormal(UInt_t, Double_t, int verbosityLevel ); 66 91 67 92 //----------------------------------------------------------------------------- … … 73 98 const char * InputRootFileName = "../analysis/fpeak/20111109_006/20111109_006_fpeak.root", 74 99 const char * InputBaselineFileName = "../analysis/fpeak/20111109_006/20111109_006_fbsl.root", 75 const char * OutTextFileName = "../analysis/fpeak/20111109_006 _gainfit_test.txt",76 const char * RootOutFileName = "../analysis/fpeak/20111109_006 _gainfit_test.root",100 const char * OutTextFileName = "../analysis/fpeak/20111109_006/20111109_006_gainfit.txt", 101 const char * RootOutFileName = "../analysis/fpeak/20111109_006/20111109_006_gainfit.root", 77 102 bool showHistos = false, 78 bool debug = false) 103 bool debug = false, 104 int verbosityLevel = 3) 79 105 { 80 106 … … 106 132 TF1 *g3 = new TF1("g3","gaus",25,35); 107 133 TF1 *g4 = new TF1("g4","gaus"); 108 TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,32);134 //TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,60); 109 135 TF1 *fspek_fit = new TF1("fspek_fit", spek_fit, 5, 60, 5); 110 TF1 *fspek_fit2 = new TF1("fspek_fit2", spek_fit2, 5, 60, 5);136 TF1 *fspek_fit2 = new TF1("fspek_fit2", spek_fit2, 5, 60, 4); 111 137 112 138 //Create Canvases … … 128 154 129 155 130 cGainFit->cd( 2);156 cGainFit->cd(3); 131 157 hbaseline->SetTitle("Baselinedistribution of all Pixels"); 132 hbaseline->SetAxisRange(-5, 5, "X");133 //hbaseline->SetAxisRange(0, 100, "Y");134 hbaseline-> Fit("gaus");158 Double_t Xrange = hbaseline->GetMean(1); 159 hbaseline->SetAxisRange(Xrange-1.5, Xrange + 1.5, "X"); 160 hbaseline->SetAxisRange(0, (hbaseline->GetBinContent(hbaseline->GetMaximumBin())+300), "Y"); 135 161 hbaseline->Draw(); 136 162 … … 154 180 gr2->SetMarkerStyle(2); 155 181 gr1->SetMarkerColor(kRed); 156 gr2->SetMarkerColor(kBl ack);182 gr2->SetMarkerColor(kBlue); 157 183 gr1->SetMarkerSize(0.5); 158 184 gr2->SetMarkerSize(0.5); 185 gr1->SetTitle("G-APD Amplification vs. Channel (with Baseline Parameter)"); 186 gr2->SetTitle("G-APD Amplification vs. Channel (without Baseline Parameter)"); 159 187 TMultiGraph *mg = new TMultiGraph(); 160 188 mg->Add(gr1); … … 165 193 //----------------------------------------------------------------------------- 166 194 167 cout << "Number of Pixels: " << NumberOfPixels << endl;195 if (verbosityLevel > 1) cout << "Number of Pixels: " << NumberOfPixels << endl; 168 196 // Begin of Loop 169 197 for (UInt_t pixel = 0; pixel < NumberOfPixels; pixel++){ 170 198 171 //Title 199 channel[ pixel ].PID = pixel+0; 200 201 //Title 172 202 TString histotitle; 173 203 histotitle += "hPixelPro_"; 174 histotitle += pixel + 1 ; 175 204 histotitle += pixel+0 ; 205 206 if (verbosityLevel > 1){ 176 207 cout << "-----------------------------------------------------------" << endl; 177 cout << " PID: " << pixel+ 1<< endl;208 cout << " PID: " << pixel+0 << endl; 178 209 cout << "-----------------------------------------------------------" << endl; 210 } 179 211 //Amplitude Spectrum of a Pixel 180 212 hPixelAmplSpek[ pixel ] = new TH1D; 181 hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+ 1, pixel+1); //Projectipon of each Pixel out of Ampl.Spectrum182 hPixelAmplSpek[ pixel ]->SetAxisRange(0, 40, "X");213 hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+0, pixel+0); //Projectipon of each Pixel out of Ampl.Spectrum 214 hPixelAmplSpek[ pixel ]->SetAxisRange(0, 60, "X"); 183 215 184 216 histotitle = "Amplitude Spectrum of Pixel #"; 185 histotitle += pixel + 1;217 histotitle += pixel+0 ; 186 218 187 219 hPixelAmplSpek[ pixel ]->SetTitle(histotitle); … … 194 226 //----------------------------------------------------------------------------- 195 227 196 total->SetLineColor(2);197 fspek_fit->SetLineColor( 3);228 //total->SetLineColor(2); 229 fspek_fit->SetLineColor(kRed); 198 230 fspek_fit2->SetLineColor(kBlue); 199 231 fspek_fit2->SetLineStyle(2); 200 232 201 cGainFit->cd( 3);233 cGainFit->cd(4); 202 234 gPad->SetLogy(1); 203 235 204 hPixelAmplSpek[ pixel ]->Fit(g1, "R");205 hPixelAmplSpek[ pixel ]->Fit(g2, "R+");206 hPixelAmplSpek[ pixel ]->Fit(g3, "R+");236 hPixelAmplSpek[ pixel ]->Fit(g1,verbos[verbosityLevel-1]+"R"); 237 hPixelAmplSpek[ pixel ]->Fit(g2,verbos[verbosityLevel-1]+"0R+"); 238 hPixelAmplSpek[ pixel ]->Fit(g3,verbos[verbosityLevel-1]+"0R+"); 207 239 g1->GetParameters(&par[0]); 208 240 g2->GetParameters(&par[3]); 209 241 g3->GetParameters(&par[6]); 210 242 243 //total->SetParameters(par); 244 245 //hPixelAmplSpek[ pixel ]->Fit(total,verbos[verbosityLevel-1]+"R+"); 246 //channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1); 247 //channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4); 248 //channel[ pixel ].amplMean = fspek_fit->GetParameter(1); 249 250 par[4] = -1; 211 251 fspek_fit->SetParameters(par); 252 cout << "spek_fit" << endl; 253 hPixelAmplSpek[ pixel ]->Fit(fspek_fit,verbos[verbosityLevel-1]+"R+"); 254 channel[ pixel ].ampl_fspek_fit = fspek_fit->GetParameter(1); 255 channel[ pixel ].bsl = fspek_fit->GetParameter(4); 256 cout << "Baseline:" << channel[ pixel ].bsl << endl; 257 212 258 fspek_fit2->SetParameters(par); 213 total->SetParameters(par); 214 hPixelAmplSpek[ pixel ]->Fit(total,"R+"); 215 hPixelAmplSpek[ pixel ]->Fit(fspek_fit,"R+"); 216 hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,"R+"); 217 259 cout << "fspek_fit2" << endl; 260 hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,verbos[verbosityLevel-1]+"R+"); 261 channel[ pixel ].ampl_fspek_fit2 = fspek_fit2->GetParameter(1); 262 218 263 if( showHistos ){ 219 264 hPixelAmplSpek[ pixel ]->Draw(); … … 222 267 223 268 224 //----------------------------------------------------------------------------- 225 // Save Parameters into vetor 226 //----------------------------------------------------------------------------- 227 228 // total->GetParameters(channel[ pixel ].fitParameters); 229 channel[ pixel ].PID = pixel+1; 230 channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1); 231 channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4); 232 channel[ pixel ].amplMean = fspek_fit->GetParameter(1); 233 channel[ pixel ].ampl_fspek_fit = fspek_fit->GetParameter(1); 234 235 // channel[ pixel ].tripple_peakSigm = total->GetParameter(8); 236 // channel[ pixel ].ampl = total->GetParameter(1) - total->GetParameter(4); 269 270 237 271 238 272 //----------------------------------------------------------------------------- … … 240 274 //----------------------------------------------------------------------------- 241 275 242 cGainFit->cd( 4);276 cGainFit->cd(2); 243 277 gPad->SetLogy(1); 244 278 g4->SetLineColor(2); 245 hAmplDistribution->Fill( channel[ pixel ].ampl SD) ;246 hAmplDistribution->Fit(g4 );279 hAmplDistribution->Fill( channel[ pixel ].ampl_fspek_fit ) ; 280 hAmplDistribution->Fit(g4, verbos[verbosityLevel-1]); 247 281 distribution.sigma = g4->GetParameter(2); 248 282 distribution.mean = g4->GetParameter(1); … … 251 285 cGainFit->cd(5); 252 286 gPad->SetLogy(1); 253 g4->SetLineColor( 2);254 hAmplDistribution2->Fill(channel[ pixel ].ampl Mean) ;255 hAmplDistribution2->Fit(g4 );256 257 cGainFit->cd( 6);258 h PixelGainFit->SetBinContent(pixel, channel[ pixel ].amplSD);259 287 g4->SetLineColor(kBlue); 288 hAmplDistribution2->Fill(channel[ pixel ].ampl_fspek_fit2) ; 289 hAmplDistribution2->Fit(g4, verbos[verbosityLevel-1]); 290 291 cGainFit->cd(3); 292 hGainFitBsl->Fill(channel[ pixel ].bsl); 293 hGainFitBsl->Draw("same"); 260 294 if( showHistos ){ 261 295 if (pixel%40==0){ 262 cGainFit->cd( 4);296 cGainFit->cd(2); 263 297 hAmplDistribution->Draw(); 264 298 cGainFit->cd(5); … … 267 301 268 302 cGainFit->cd(6); 269 h PixelGainFit->Draw();303 hGainFitBsl->Draw(); 270 304 } 271 305 … … 274 308 //----------------------------------------------------------------------------- 275 309 276 gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl SD);277 gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl Mean);310 gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl_fspek_fit); 311 gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl_fspek_fit2); 278 312 279 313 280 314 if( showHistos ){ 281 315 if (pixel%60==0){ 316 cGraphs->cd(1); 317 gr2->Draw("APL"); 282 318 cGraphs->cd(2); 283 gr2->Draw("APL");284 cGraphs->cd(1);285 319 gr1->Draw("APL"); 286 320 } … … 311 345 312 346 313 // ( cGainFit->cd( 3);347 // ( cGainFit->cd(4); 314 348 // hPixelAmplSpek[ NumberOfPixels ]->Draw(); 315 349 316 cGainFit->cd( 4);350 cGainFit->cd(2); 317 351 hAmplDistribution->Draw(); 318 352 … … 321 355 322 356 cGainFit->cd(6); 323 hPixelGainFit->Draw(); 357 hGainFitBsl->Draw(); 358 hbaseline->Draw("same"); 324 359 325 360 cGainFit->Modified(); 326 361 cGainFit->Update(); 327 362 363 cGraphs->cd(1); 364 gr2->Draw("APL"); 328 365 cGraphs->cd(2); 329 gr2->Draw("APL");330 cGraphs->cd(1);331 366 gr1->Draw("APL"); 332 367 cGraphs->Modified(); … … 351 386 ++it; 352 387 } 353 cout << filename << endl;388 if (verbosityLevel > 0) cout << filename << endl; 354 389 355 390 ofstream out; … … 362 397 for (UInt_t pixel=0; pixel<NumberOfPixels; pixel++){ 363 398 out << channel[ pixel ].PID << ";\t" ; 364 out << channel[ pixel ].amplSD << ";\t" ; 365 out << channel[ pixel ].amplDT << ";\t" ; 366 out << channel[ pixel ].ampl_fspek_fit << "\t" ; 367 368 channel[ pixel ].crazy = SearchAnormal(pixel, 4); //check if pixel had a strange gain 399 out << channel[ pixel ].ampl_fspek_fit << ";\t" ; 400 // out << channel[ pixel ].amplDT << ";\t" ; 401 out << channel[ pixel ].ampl_fspek_fit2 << "\t" ; 402 403 //check if pixel gain is compareable to gain of the others and save result to logfile 404 channel[ pixel ].crazy = SearchAnormal(pixel, 4, verbosityLevel); 405 if (channel[ pixel ].crazy) hListCrazy.Add(hPixelAmplSpek[ pixel ]); 369 406 out << channel[ pixel ].crazy << "\t" ; 370 407 … … 399 436 400 437 //Amplification Distribution - Single2Double 401 hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification ( 1+2)", 500, 0 , 20 );438 hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (with Baseline Parameter)", 500, 0 , 20 ); 402 439 hAmplDistribution->SetXTitle("Amplification [mV]"); 403 440 hAmplDistribution->SetYTitle("Counts"); … … 406 443 407 444 //Amplification Distribution2 - Double2Tripple 408 hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification( 2+3)", 500, 0 , 20 );445 hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(without Baseline Parameter)", 500, 0 , 20 ); 409 446 hAmplDistribution2->SetXTitle("Amplification [mV]"); 410 447 hAmplDistribution2->SetYTitle("Counts"); … … 412 449 hList.Add( hAmplDistribution2 ); 413 450 414 // Amplificationvs Channels415 h PixelGainFit = new TH1F("hPixelGainFit","Amplifications (SD) of each Channel", 1440, -0.5 , 1439.5);416 h PixelGainFit->SetYTitle("Amplification [mV]");417 h PixelGainFit->SetXTitle("Channels");418 h PixelGainFit->SetLineColor(2);419 hList.Add( h PixelGainFit);451 //cross vs Channels 452 hGainFitBsl = new TH1F("hGainFitBsl","BaselineDistribution from plot", 400,-99.5,100.5); 453 hGainFitBsl->SetYTitle("Counts"); 454 hGainFitBsl->SetXTitle("Voltage [mV]"); 455 hGainFitBsl->SetLineColor(2); 456 hList.Add( hGainFitBsl ); 420 457 421 458 } … … 432 469 tf.mkdir("PeakSpektra"); tf.cd("PeakSpektra"); // go to new subdirectory 433 470 hListPeakSpektra.Write(); // write histos into subdirectory 434 471 tf.mkdir("CrazyPixels"); tf.cd("CrazyPixels"); // go to new subdirectory 472 hListCrazy.Write(); // write histos into subdirector 435 473 tf.Close(); // close the file 436 474 } 437 475 438 476 //----------------------------------------------------------------------------- 439 // MulitOrder MultiGauß Function477 // Fit-Function: Sum of several Gauß-Function with falling Maximum Amplitude 440 478 //----------------------------------------------------------------------------- 441 479 442 480 Double_t spek_fit(Double_t *x, Double_t *par){ 481 Double_t arg = 0; 482 Double_t arg2 = 0; 483 Double_t arg3 = 0; 484 Double_t arg4 = 0; 485 Double_t cross = 0; 486 if (par[0] != 0) cross = par[3]/par[0]; 487 if (par[2] != 0) arg = (x[0] - par[1]-par[4])/par[2]; 488 if (par[2] != 0) arg2 = (x[0] - 2*par[1]-par[4])/par[2]; 489 if (par[2] != 0) arg3 = (x[0] - 3*par[1]-par[4])/par[2]; 490 if (par[2] != 0) arg4 = (x[0] - 4*par[1]-par[4])/par[2]; 491 Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg); 492 Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2); 493 Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3); 494 Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4); 495 return peak1 + peak2 + peak3 + peak4; 496 } 497 498 //----------------------------------------------------------------------------- 499 // Fit-Function: Sum of several Gauß-Function with overlying potential decay 500 //----------------------------------------------------------------------------- 501 502 Double_t spek_fit2(Double_t *x, Double_t *par){ 443 503 444 504 Double_t arg = 0; … … 447 507 Double_t arg4 = 0; 448 508 Double_t cross = 1; 449 if (par[0] != 0) cross = par[ 4]/par[0];509 if (par[0] != 0) cross = par[3]/par[0]; 450 510 if (par[2] != 0) arg = (x[0] - par[1])/par[2]; 451 511 if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2]; 452 512 if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2]; 453 513 if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2]; 454 cross = par[4]/par[0];455 514 Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg); 456 515 Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2); 457 516 Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3); 458 517 Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4); 459 //Double_t decayoverlay = TMath::Exp(-x[0]);460 518 return peak1 + peak2 + peak3 + peak4; 461 519 } 462 520 463 Double_t spek_fit2(Double_t *x, Double_t *par){ 464 465 Double_t arg = 0; 466 Double_t arg2 = 0; 467 Double_t arg3 = 0; 468 Double_t arg4 = 0; 469 Double_t cross = 1; 470 if (par[0] != 0) cross = par[4]/par[0]; 471 if (par[2] != 0) arg = (x[0] - par[1])/par[2]; 472 if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2]; 473 if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2]; 474 if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2]; 475 cross = par[4]/par[0]; 476 Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg); 477 Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2); 478 Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3); 479 Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4); 480 Double_t decayoverlay = TMath::Exp(-x[0]*TMath::Log(1.0001)); 481 return peak1 + peak2 + peak3 + peak4 + decayoverlay; 482 } 483 484 bool SearchAnormal(UInt_t pixel, Double_t distance){ //// MACHT ALLES KEINEN SINN WENN MAN KEINE BETRÄGE BETRACHTET 521 //----------------------------------------------------------------------------- 522 // Function: Search for Pixel that do not have a compareable gain to the Other 523 //----------------------------------------------------------------------------- 524 525 bool SearchAnormal(UInt_t pixel, Double_t distance, int verbosityLevel){ 485 526 Double_t check = channel[ pixel ].ampl_fspek_fit; 486 527 check = TMath::Sqrt(check*check); … … 489 530 } 490 531 else{ 491 cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl;532 if (verbosityLevel > 2) cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl; 492 533 return true; 493 534 } 494 535 } 495 536 496 /*497 498 499 500 501 502 503 */504 505 506 /*507 Double_t spek_fit(Double_t *x, Double_t *par, Uint_t *maxorder)508 {509 Double_t exp = 0;510 511 //Double_t arg2 = 0;512 //if (par[2] != 0) arg = (v[0] - par[1])/par[2];513 //if (par[5] != 0) arg2 = (v[0] - par[4])/par[5];514 515 //Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg) + par[3]*TMath::Exp(-0.5*arg2*arg2);516 517 for(int order = 0; order < maxorder; order++){518 peak[order]=par[0]*par[4]/(order+1)*((x[0]-(order+1)*par[1])*(x[0]-(order+1)*par[1]))/(par[2]*par[2]);519 exp = exp + peak[order];520 }521 522 Double_t fitval = TMath::Exp(-0.5*exp);523 return fitval;524 }525 */
Note:
See TracChangeset
for help on using the changeset viewer.