Changeset 12712 for fact/tools/rootmacros/gainfit2.C
- Timestamp:
- 12/08/11 00:28:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/gainfit2.C
r12690 r12712 27 27 UInt_t PID; 28 28 vector<float> fitParameters[9]; 29 float amplSD; 30 float amplDT; 31 float amplMean; 29 Double_t amplSD; 30 Double_t amplDT; 31 Double_t amplMean; 32 Double_t ampl_fspek_fit; 33 bool crazy; 32 34 } proj; 33 35 vector<proj> channel; 34 36 37 typedef struct{ 38 Double_t constant; 39 Double_t mean; 40 Double_t sigma; 41 } dist_t; 42 dist_t distribution; 35 43 36 44 //----------------------------------------------------------------------------- … … 41 49 TH1F *hAmplDistribution = NULL; 42 50 TH1F *hAmplDistribution2 = NULL; 43 TH1F *h AmplVsChannel= NULL;44 45 //Lists of Histograms t aht are to be saved51 TH1F *hPixelGainFit = NULL; 52 53 //Lists of Histograms that have to be saved 46 54 TObjArray hList; 47 55 TObjArray hListPeakSpektra; 48 56 49 50 57 //----------------------------------------------------------------------------- 51 58 // Functions 52 59 //----------------------------------------------------------------------------- 60 Double_t spek_fit(Double_t *, Double_t *); 61 Double_t spek_fit2(Double_t *, Double_t *); 53 62 54 63 void BookHistos(); 55 64 void SaveHistograms(const char * ); 56 //Double_t spek_fit(Double_t *x, Double_t *par) 57 65 bool SearchAnormal(UInt_t, Double_t ); 58 66 59 67 //----------------------------------------------------------------------------- … … 79 87 TFile * file = TFile::Open( InputRootFileName ); 80 88 81 82 TH1D *hPixelProjection = NULL;83 89 //Baseline 84 90 TH2F * hbaseline = (TH2F*)baseline->Get("histo_mean"); 85 91 //Amplitude spectrum 86 TH2F *h = (TH2F*)file->Get("hAmplSpek_cfd"); 87 92 TH2F *hAmplSpek = (TH2F*)file->Get("hAmplSpek_cfd"); 93 NumberOfPixels = hAmplSpek->GetNbinsX(); 94 channel.resize(hAmplSpek->GetNbinsX()); 95 96 //Amplitude Spectrum of a Pixel 97 TH1D* hPixelAmplSpek[1440]; ///++++ TODO: Warning hardcoded pixelnumber, change that +++ 98 99 //Book Histograms 88 100 BookHistos(); 89 101 102 //Define Fit Functions 90 103 Double_t par[9]; 91 104 TF1 *g1 = new TF1("g1","gaus",5,15); … … 94 107 TF1 *g4 = new TF1("g4","gaus"); 95 108 TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,32); 96 97 109 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); 111 112 //Create Canvases 98 113 TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 1200,400); 99 114 cGainFit->Clear(); 100 115 cGainFit->Divide(3, 2); 101 116 102 TCanvas *cGraphs = new TCanvas("cGraphs", " Horst", 0,401, 1200,400);117 TCanvas *cGraphs = new TCanvas("cGraphs", "gain vs. channel", 0,401, 1200,400); 103 118 cGraphs->Clear(); 104 119 cGraphs->Divide(1, 2); 105 120 121 //Draw imported Histograms 106 122 cGainFit->cd(1); 107 123 gStyle->SetPalette(1,0); 108 124 gROOT->SetStyle("Plain"); 109 h->SetTitle("Amplitude Spectrum of all Pixels"); 110 h->SetAxisRange(0, 100, "Y"); 111 h->Draw("COLZ"); 112 channel.resize(h->GetNbinsX()); 113 NumberOfPixels = h->GetNbinsX(); 125 hAmplSpek->SetTitle("Amplitude Spectrum of all Pixels"); 126 hAmplSpek->SetAxisRange(0, 100, "Y"); 127 hAmplSpek->Draw("COLZ"); 128 114 129 115 130 cGainFit->cd(2); … … 146 161 mg->Add(gr2); 147 162 148 149 150 151 163 //----------------------------------------------------------------------------- 152 164 // Loop over all Pixels and fit Distribution of singles, doubles and tripples … … 158 170 159 171 //Title 160 TString pixelnumber; 161 pixelnumber += "hPixelProj"; 162 pixelnumber += "_"; 163 pixelnumber += pixel + 1 ; 172 TString histotitle; 173 histotitle += "hPixelPro_"; 174 histotitle += pixel + 1 ; 164 175 165 176 cout << "-----------------------------------------------------------" << endl; 166 177 cout << " PID: " << pixel+1 << endl; 167 178 cout << "-----------------------------------------------------------" << endl; 168 169 hPixelProjection = h->ProjectionY( pixelnumber , pixel+1, pixel+1); //Projectipon of each Pixel out of Ampl.Spectrum 170 hPixelProjection->SetTitle("Amplitude Spectrum of one Pixels"); 171 hPixelProjection->SetAxisRange(0, 40, "X"); 179 //Amplitude Spectrum of a Pixel 180 hPixelAmplSpek[ pixel ] = new TH1D; 181 hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+1, pixel+1); //Projectipon of each Pixel out of Ampl.Spectrum 182 hPixelAmplSpek[ pixel ]->SetAxisRange(0, 40, "X"); 183 184 histotitle = "Amplitude Spectrum of Pixel #"; 185 histotitle += pixel + 1 ; 186 187 hPixelAmplSpek[ pixel ]->SetTitle(histotitle); 188 hPixelAmplSpek[ pixel ]->SetYTitle("Counts [a.u.]"); 189 hListPeakSpektra.Add(hPixelAmplSpek[ pixel ]); 190 172 191 173 192 //----------------------------------------------------------------------------- … … 176 195 177 196 total->SetLineColor(2); 197 fspek_fit->SetLineColor(3); 198 fspek_fit2->SetLineColor(kBlue); 199 fspek_fit2->SetLineStyle(2); 200 178 201 cGainFit->cd(3); 179 202 gPad->SetLogy(1); 180 hPixelProjection->SetYTitle("Counts"); 181 hPixel Projection->Fit(g1,"R");182 hPixel Projection->Fit(g2,"R+");183 hPixel Projection->Fit(g3,"R+");203 204 hPixelAmplSpek[ pixel ]->Fit(g1,"R"); 205 hPixelAmplSpek[ pixel ]->Fit(g2,"R+"); 206 hPixelAmplSpek[ pixel ]->Fit(g3,"R+"); 184 207 g1->GetParameters(&par[0]); 185 208 g2->GetParameters(&par[3]); 186 209 g3->GetParameters(&par[6]); 210 211 fspek_fit->SetParameters(par); 212 fspek_fit2->SetParameters(par); 187 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 188 218 if( showHistos ){ 189 hPixelProjection->Draw(); 190 hPixelProjection->Fit(total,"R+"); 219 hPixelAmplSpek[ pixel ]->Draw(); 191 220 } 192 221 193 //TODO: Logarithmic Scale 222 194 223 195 224 //----------------------------------------------------------------------------- … … 199 228 // total->GetParameters(channel[ pixel ].fitParameters); 200 229 channel[ pixel ].PID = pixel+1; 201 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); 202 234 203 235 // channel[ pixel ].tripple_peakSigm = total->GetParameter(8); … … 211 243 gPad->SetLogy(1); 212 244 g4->SetLineColor(2); 213 channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);214 245 hAmplDistribution->Fill( channel[ pixel ].amplSD ) ; 215 246 hAmplDistribution->Fit(g4); 247 distribution.sigma = g4->GetParameter(2); 248 distribution.mean = g4->GetParameter(1); 249 distribution.constant = g4->GetParameter(0); 216 250 217 251 cGainFit->cd(5); 218 252 gPad->SetLogy(1); 219 253 g4->SetLineColor(2); 220 channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4); 221 hAmplDistribution2->Fill(channel[ pixel ].amplDT) ; 254 hAmplDistribution2->Fill(channel[ pixel ].amplMean) ; 222 255 hAmplDistribution2->Fit(g4); 223 256 224 257 cGainFit->cd(6); 225 hAmplVsChannel->SetBinContent(pixel, channel[ pixel ].amplSD); 258 hPixelGainFit->SetBinContent(pixel, channel[ pixel ].amplSD); 259 260 if( showHistos ){ 261 if (pixel%40==0){ 262 cGainFit->cd(4); 263 hAmplDistribution->Draw(); 264 cGainFit->cd(5); 265 hAmplDistribution2->Draw(); 266 } 267 268 cGainFit->cd(6); 269 hPixelGainFit->Draw(); 270 } 271 272 //----------------------------------------------------------------------------- 273 // Draw Graphs of Distributions 274 //----------------------------------------------------------------------------- 226 275 227 276 gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplSD); 228 gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl DT);277 gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplMean); 229 278 230 279 231 280 if( showHistos ){ 232 if (pixel%40==0){233 cGainFit->cd(4);234 hAmplDistribution->Draw();235 cGainFit->cd(5);236 hAmplDistribution2->Draw();237 }238 239 cGainFit->cd(6);240 hAmplVsChannel->Draw();241 281 if (pixel%60==0){ 242 282 cGraphs->cd(2); 243 mg->Draw("APL");283 gr2->Draw("APL"); 244 284 cGraphs->cd(1); 245 285 gr1->Draw("APL"); … … 251 291 cGraphs->Update(); 252 292 } 293 294 //----------------------------------------------------------------------------- 295 // Debug Modus 296 //----------------------------------------------------------------------------- 253 297 if(debug){ 254 298 … … 266 310 //----------------------------------------------------------------------------- 267 311 268 cGainFit->cd(3); 269 hPixelProjection->Draw();270 hPixelProjection->Fit(total,"R+");312 313 // ( cGainFit->cd(3); 314 // hPixelAmplSpek[ NumberOfPixels ]->Draw(); 271 315 272 316 cGainFit->cd(4); … … 277 321 278 322 cGainFit->cd(6); 279 h AmplVsChannel->Draw();323 hPixelGainFit->Draw(); 280 324 281 325 cGainFit->Modified(); … … 283 327 284 328 cGraphs->cd(2); 285 mg->Draw("APL");329 gr2->Draw("APL"); 286 330 cGraphs->cd(1); 287 331 gr1->Draw("APL"); … … 320 364 out << channel[ pixel ].amplSD << ";\t" ; 321 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 369 out << channel[ pixel ].crazy << "\t" ; 370 322 371 out << filename << endl; 323 372 … … 364 413 365 414 //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 ); 415 hPixelGainFit = new TH1F("hPixelGainFit","Amplifications (SD) of each Channel", 1440, -0.5 , 1439.5 ); 416 hPixelGainFit->SetYTitle("Amplification [mV]"); 417 hPixelGainFit->SetXTitle("Channels"); 418 hPixelGainFit->SetLineColor(2); 419 hList.Add( hPixelGainFit ); 420 371 421 } 372 422 … … 389 439 // MulitOrder MultiGauß Function 390 440 //----------------------------------------------------------------------------- 441 442 Double_t spek_fit(Double_t *x, Double_t *par){ 443 444 Double_t arg = 0; 445 Double_t arg2 = 0; 446 Double_t arg3 = 0; 447 Double_t arg4 = 0; 448 Double_t cross = 1; 449 if (par[0] != 0) cross = par[4]/par[0]; 450 if (par[2] != 0) arg = (x[0] - par[1])/par[2]; 451 if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2]; 452 if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2]; 453 if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2]; 454 cross = par[4]/par[0]; 455 Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg); 456 Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2); 457 Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3); 458 Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4); 459 //Double_t decayoverlay = TMath::Exp(-x[0]); 460 return peak1 + peak2 + peak3 + peak4; 461 } 462 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 485 Double_t check = channel[ pixel ].ampl_fspek_fit; 486 check = TMath::Sqrt(check*check); 487 if (check < (distance * distribution.sigma + distribution.mean)){ 488 return false; 489 } 490 else{ 491 cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl; 492 return true; 493 } 494 } 495 496 /* 497 498 499 500 501 502 503 */ 504 391 505 392 506 /* … … 410 524 } 411 525 */ 412
Note:
See TracChangeset
for help on using the changeset viewer.