5 #define ZMUMUVALIDATIONEXAMPLE_C
10 #include "TLorentzVector.h"
16 , std::string
const & s_outFileName
18 ) : m_fileNames( s_fileNames )
19 , m_outfilename( s_outFileName )
20 ,
m_file( s_outFileName.c_str(),
"RECREATE" )
21 , m_eventChain( s_treeName.c_str() )
22 , m_truthChain(
"TruthParams" )
52 std::cout <<
"Input Files:" << std::endl;
54 std::list<std::string>::const_iterator theEnd =
m_fileNames.end();
55 for( std::list<std::string>::const_iterator itr =
m_fileNames.begin()
60 std::cout <<
" "<< *itr << std::endl;
118 const int fnQoverPtBins = 100;
120 const double eta_bound = 2.5;
121 const double phi_bound =
M_PI;
122 const double p_bound = 0.5;
123 const double pt_bound = 15;
125 const double z_bound = 0.4;
126 const double d_bound = 0.15;
128 h_DELTA =
new TH1F(
"h_DELTA",
";#delta [GeV]",200,-50,50);
130 h_pt =
new TH1F(
"Pt",
"p_{T} of both #mu; p_{T} [GeV]", 100, 0., 100.);
131 h_pt_pos =
new TH1F(
"Pt_Pos",
"p_{T} of #mu^{+}; p_{T} [GeV]", 100, 0., 100.);
132 h_pt_neg =
new TH1F(
"Pt_Neg",
"p_{T} of #mu^{-}; p_{T} [GeV]", 100, 0., 100.);
134 h_z0 =
new TH1F(
"h_z0",
"z_{0}: longitudinal impact param.; z_{0} [mm]", 100, -150., 150.);
135 h_z0_pos =
new TH1F(
"h_z0_Pos",
"z_{0} of #mu^{+};z_{0} [mm]",100, -150., 150.);
136 h_z0_neg =
new TH1F(
"h_z0_Neg",
"z_{0} of #mu^{-};z_{0} [mm]",100, -150., 150.);
137 h_d0 =
new TH1F(
"h_d0",
"d_{0}: transvers. impact param.; d_{0} [mm]", 100, -0.08, 0.08);
138 h_d0_pos =
new TH1F(
"h_d0_Pos",
"d_{0} of #mu^{+};d_{0} [mm]",100, -0.08, 0.08);
139 h_d0_neg =
new TH1F(
"h_d0_Neg",
"d_{0} of #mu^{-};d_{0} [mm]",100, -0.08, 0.08);
141 h_mass =
new TH1F(
"ZMass",
";Mass [GeV]",100,70,110);
156 entries =
new TH2F(
"entries",
"Entries per #eta-#phi bin;#eta;#phi;entries", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
158 z0delta_vs_etaphi =
new TH3F(
"Delta_z0_VsEtaPhi",
";#eta;#phi;#delta_{z_{0}} [mm]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 50,-z_bound,z_bound);
160 z0deltacorrections_vs_etaphi =
new TH2D(
"z0CorrectionVsEtaPhi",
";#eta;#phi;#delta_{z_{0}} [mm]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
162 z0deltacorrections_vs_etaphi_err =
new TH2D(
"z0CorrectionVsEtaPhi_Err",
";#eta;#phi;#delta_{z_{0}}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
165 z0delta =
new TH1D(
"Delta_z0",
";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
167 z0delta_pos =
new TH1D(
"Delta_z0_Pos",
";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
169 z0delta_neg =
new TH1D(
"Delta_z0_Neg",
";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
171 z0delta_etaphi =
new TH1D(
"Delta_z0_etaphi",
";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
173 z0delta_etaphi_pos =
new TH1D(
"Delta_z0_etaphi_Pos",
";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
175 z0delta_etaphi_neg =
new TH1D(
"Delta_z0_etaphi_Neg",
";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
179 d0delta_vs_etaphi =
new TH3F(
"Delta_d0_VsEtaPhi",
";#eta;#phi;#delta_{d_{0}} [mm]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 50,-d_bound, d_bound);
181 d0deltacorrections_vs_etaphi =
new TH2D(
"d0CorrectionVsEtaPhi",
";#eta;#phi;#delta_{d_{0}} [mm]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
183 d0deltacorrections_vs_etaphi_err =
new TH2D(
"d0CorrectionVsEtaPhi_Err",
";#eta;#phi;#delta_{d_{0}}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
185 d0delta =
new TH1D(
"Delta_d0",
";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
187 d0delta_pos =
new TH1D(
"Delta_d0_Pos",
";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
189 d0delta_neg =
new TH1D(
"Delta_d0_Neg",
";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
191 d0delta_etaphi =
new TH1D(
"Delta_d0_etaphi",
";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
193 d0delta_etaphi_pos =
new TH1D(
"Delta_d0_etaphi_Pos",
";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
195 d0delta_etaphi_neg =
new TH1D(
"Delta_d0_etaphi_Neg",
";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
198 delta_vs_etaphi =
new TH3F(
"DeltaPVsEtaPhi",
";#eta;#phi;#delta_{r}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 100,-p_bound,p_bound);
200 deltacorrections_vs_etaphi =
new TH2D(
"PCorrectionVsEtaPhi",
";#eta;#phi;#delta_{r}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
202 deltacorrections_vs_etaphi_err =
new TH2D(
"PCorrectionVsEtaPhi_Err",
";#eta;#phi;#delta_{r}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
205 lambda_vs_etaphi =
new TH3F(
"LambdaVsEtaPhi",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 100,-pt_bound,pt_bound);
207 lambdacorrections_vs_etaphi =
new TH2D(
"LambdaCorrectionVsEtaPhi",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
208 lambdacorrections_vs_etaphi_err =
new TH2D(
"LambdaCorrectionVsEtaPhi_Err",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
209 lambdacorrections_vs_etaphi_RMS =
new TH2D(
"LambdaCorrectionVsEtaPhi_RMS",
";#eta;#phi;RMS #delta_{sagitta} [GeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
212 lambda_vs_eta =
new TH2F(
"LambdaVsEta",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
213 lambda_vs_eta_pos =
new TH2F(
"LambdaVsEta_Pos",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
214 lambda_vs_eta_neg =
new TH2F(
"LambdaVsEta_Neg",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
216 lambdacorrections_vs_eta =
new TH1D(
"LambdaCorrectionVsEta",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound);
218 lambda =
new TH1D(
"Lambda",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
219 lambda_pos =
new TH1D(
"Lambda_Pos",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
220 lambda_neg =
new TH1D(
"Lambda_Neg",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
222 lambda_eta =
new TH1D(
"Lambda_eta",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
223 lambda_eta_pos =
new TH1D(
"Lambda_eta_Pos",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
224 lambda_eta_neg =
new TH1D(
"Lambda_eta_Neg",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
226 lambda_etaphi =
new TH1D(
"Lambda_etaphi",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
227 lambda_etaphi_pos =
new TH1D(
"Lambda_etaphi_Pos",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
228 lambda_etaphi_neg =
new TH1D(
"Lambda_etaphi_Neg",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
232 h_pt_truth =
new TH1D(
"Pt_Truth",
";p_{T} [GeV]",500,0,500);
233 h_pt_pos_truth =
new TH1D(
"Pt_Pos_Truth",
";p_{T} [GeV]",500,0,500);
234 h_pt_neg_truth =
new TH1D(
"Pt_Neg_Truth",
";p_{T} [GeV]",500,0,500);
236 delta_vs_etaphi_truth =
new TH3F(
"DeltaPVsEtaPhi_Truth",
";#eta;#phi;#delta_{r}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 100,-p_bound,p_bound);
237 deltacorrections_vs_etaphi_truth =
new TH2D(
"PCorrectionVsEtaPhi_Truth",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
238 deltacorrections_vs_etaphi_truth_err =
new TH2D(
"PCorrectionVsEtaPhi_Truth_Err",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
240 lambda_vs_etaphi_truth =
new TH3F(
"LambdaVsEtaPhi_Truth",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 100,-pt_bound,pt_bound);
241 lambdacorrections_vs_etaphi_truth =
new TH2D(
"LambdaCorrectionVsEtaPhi_Truth",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
242 lambdacorrections_vs_etaphi_truth_err =
new TH2D(
"LambdaCorrectionVsEtaPhi_Truth_Err",
";#eta;#phi;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
244 lambda_vs_eta_truth =
new TH2F(
"LambdaVsEta_Truth",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
247 truth_mom_bias_vs_eta =
new TH2F(
"TruthMomentumBiasVsEta",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
250 truth_mass_bias_vs_eta =
new TH2F(
"TruthMassBiasVsEta",
";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
253 lambda_truth =
new TH1D(
"Lambda_Truth",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
254 lambda_truth_pos =
new TH1D(
"Lambda_Truth_Pos",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
255 lambda_truth_neg =
new TH1D(
"Lambda_Truth_Neg",
";#delta_{sagitta} [TeV^{-1}]", 100,-pt_bound,pt_bound);
257 delta_phi_truth =
new TH1D(
"DeltaPhi_Truth",
";#phi_{Truth} - #phi_{Rec}", 100,-0.01,0.01);
259 delta_eta_truth =
new TH1D(
"DeltaEta_Truth",
";#eta_{Truth} - #eta_{Rec}", 100,-0.01,0.01);
261 delta_M2_vs_zpt_truth =
new TH2D(
"delta_M2_vs_zpt_truth",
";Z p_{T} [GeV]; #Delta (M^2)", 100,0,100, 100, -1.0, 1.0 );
262 delta_M2_vs_zpt =
new TH2D(
"delta_M2_vs_zpt",
";Z p_{T} [GeV]; #Delta (M^2)", 100,0,100, 100, -1.0, 1.0 );
264 delta_M2_vs_etaphi_pos =
new TProfile2D(
"delta_M2_vs_etaphi_pos",
";#eta;#phi; #Delta (M^2)", 20,-2.5,2.5, 20, -3.14, 3.14 );
265 delta_M2_vs_etaphi_neg =
new TProfile2D(
"delta_M2_vs_etaphi_neg",
";#eta;#phi; #Delta (M^2)", 20,-2.5,2.5, 20, -3.14, 3.14 );
270 h_QoverPt =
new TH2F(
"h_QoverPt",
"q/p_{T} whole ID", 2*fnPhiBins, -phi_bound, phi_bound, fnQoverPtBins, -1/pt_bound, 1/pt_bound);
271 h_QoverPt->GetXaxis()->SetTitle(
"#phi [rad]");
272 h_QoverPt->GetYaxis()->SetTitle(
"q/p_{T} [GeV^{-1}]");
274 h_QoverPt3D =
new TH3F(
"h_QoverPt3D",
"q/p_{T} whole ID",
275 fnEtaBins, -eta_bound, eta_bound,
276 2*fnPhiBins, -phi_bound, phi_bound,
277 fnQoverPtBins, -1/pt_bound, 1/pt_bound);
280 h_QoverPt3D->GetZaxis()->SetTitle(
"q/p_{T} [GeV^{-1}]");
289 std::cout <<
" TrkValidation::loop()" << std::endl;
299 if (
m_PrintLevel >= 1) cout <<
" ** ZmumuValidationExample::loop ** start loop on events ... " << endl;
302 if (
m_PrintLevel >= 1) cout<<
" ** ZmumuValidationExample::loop ** Fitting histograms" << endl;
332 std::cout <<
" Looping over " << maxItr <<
" events"<< std::endl;
334 for(
unsigned int eventItr = 0
339 if( eventItr % 10000 == 0 )
341 std::cout <<
" Processing event " << eventItr <<
" of " << maxItr << std::endl;
360 const double muon_mass = 105.658;
363 TLorentzVector* vec_pos =
new TLorentzVector();
364 TLorentzVector* vec_neg =
new TLorentzVector();
367 double corrected_z0_pos;
368 double corrected_z0_neg;
369 double corrected_d0_pos;
370 double corrected_d0_neg;
375 entries->Fill(vec_pos->Eta(),vec_pos->Phi(),1);
376 entries->Fill(vec_neg->Eta(),vec_neg->Phi(),1);
423 TLorentzVector* vec_truth_pos =
new TLorentzVector();
424 TLorentzVector* vec_truth_neg =
new TLorentzVector();
429 double z_mass = 91187.6;
430 double mass = ((*vec_pos) + (*vec_neg)).M();
431 double mass_truth = ((*vec_truth_pos) + (*vec_truth_neg)).M();
433 double delta_M2 = (
mass*
mass - z_mass*z_mass)/(z_mass*z_mass);
434 double delta_M2_truth = (
mass*
mass - mass_truth*mass_truth)/(mass_truth*mass_truth);
435 double delta_M2_truth_bias = (mass_truth*mass_truth - z_mass*z_mass)/(z_mass*z_mass);
443 double d_bias_truth_pos = +1/vec_truth_pos->Pt()*(1 - vec_truth_pos->P()/vec_pos->P())*1000000.0;
444 double d_bias_truth_neg = -1/vec_truth_neg->Pt()*(1 - vec_truth_neg->P()/vec_neg->P())*1000000.0;
450 double d_mass_bias_truth_pos = +1*delta_M2_truth_bias/vec_truth_pos->Pt()*1000000.0;
451 double d_mass_bias_truth_neg = -1*delta_M2_truth_bias/vec_truth_neg->Pt()*1000000.0;
457 double d_lambda_truth_pos = +1*delta_M2_truth/vec_truth_pos->Pt()*1000000.0;
458 double d_lambda_truth_neg = -1*delta_M2_truth/vec_truth_neg->Pt()*1000000.0;
473 double delta_truth_pos = (vec_truth_pos->P() - vec_pos->P())/vec_truth_pos->P();
474 double delta_truth_neg = (vec_truth_neg->P() - vec_neg->P())/vec_truth_neg->P();
487 double zpt_truth = ((*vec_truth_pos) + (*vec_truth_neg)).
Pt();
489 h_DELTA->Fill(delta_M2/(vec_pos->Pt() - vec_neg->Pt())*1000000);
498 delete vec_truth_pos;
499 delete vec_truth_neg;
547 h_pt->Fill(vec_pos->Pt()/1000.0);
548 h_pt->Fill(vec_neg->Pt()/1000.0);
549 h_pt_pos->Fill(vec_pos->Pt()/1000.0);
550 h_pt_neg->Fill(vec_neg->Pt()/1000.0);
552 h_mass->Fill(((*vec_pos)+(*vec_neg)).M()/1000.0);
575 double temp_pt_pos = muon_pos->Pt();
576 double temp_pt_neg = muon_neg->Pt();
579 double correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_pos->Eta(), muon_pos->Phi()));
582 double pt_true = muon_pos->Pt();
585 muon_pos->SetXYZM(muon_pos->Px()/(1+
correction*pt_true/1000000.0),
586 muon_pos->Py()/(1+
correction*pt_true/1000000.0),
587 muon_pos->Pz()/(1+
correction*pt_true/1000000.0),
590 cout <<
" ** correctMomentum ** mu+ (eta,phi) (" << muon_pos->Eta() <<
", " << muon_pos->Phi() <<
") "
591 <<
" bin = " << h_corrections->FindBin(muon_pos->Eta(), muon_pos->Phi())
598 muon_pos->SetXYZM(muon_pos->Px()*(1-
correction),
605 correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_neg->Eta(), muon_neg->Phi()));
608 double pt_true = muon_neg->Pt();
611 muon_neg->SetXYZM(muon_neg->Px()/(1-
correction*pt_true/1000000.0),
612 muon_neg->Py()/(1-
correction*pt_true/1000000.0),
613 muon_neg->Pz()/(1-
correction*pt_true/1000000.0),
616 cout <<
" ** correctMomentum ** mu- (eta,phi) (" << muon_neg->Eta() <<
", " << muon_neg->Phi() <<
") "
617 <<
" bin = " << h_corrections->FindBin(muon_neg->Eta(), muon_neg->Phi())
624 muon_neg->SetXYZM(muon_neg->Px()*(1-
correction),
631 cout <<
" ** correctMomentum ** mu+ Pt: " << temp_pt_pos <<
" --> " << muon_pos->Pt() <<
" Delta = " << 100*(muon_pos->Pt()-temp_pt_pos)/temp_pt_pos <<
" %"<< endl
632 <<
" mu- Pt: " << temp_pt_neg <<
" --> " << muon_neg->Pt() <<
" Delta = " << 100*(muon_neg->Pt()-temp_pt_neg)/temp_pt_neg <<
" %"<< endl;
643 double z_mass = 91187.6 +
m_shift;
644 double mass = ((*v_pos) + (*v_neg)).M();
645 double delta_M2 = (
mass*
mass - z_mass*z_mass)/(z_mass*z_mass);
649 hist->Fill(v_pos->Eta(), v_pos->Phi(), +1*
m_factor*delta_M2/v_pos->Pt()*1000000.0);
650 hist->Fill(v_neg->Eta(), v_neg->Phi(), -1*
m_factor*delta_M2/v_neg->Pt()*1000000.0);
653 hist->Fill(v_pos->Eta(), v_pos->Phi(), +1*delta_M2/2);
654 hist->Fill(v_neg->Eta(), v_neg->Phi(), +1*delta_M2/2);
662 double z_mass = 91187.6 +
m_shift;
663 double mass = ((*v_pos) + (*v_neg)).M();
664 double delta_M2 = (
mass*
mass - z_mass*z_mass)/(z_mass*z_mass);
671 hist->Fill(v_pos->Eta(), +1*delta_M2/2);
672 hist->Fill(v_neg->Eta(), +1*delta_M2/2);
679 double z_mass = 91187.6 +
m_shift;
680 double mass = ((*v_pos) + (*v_neg)).M();
681 double delta_M2 = (
mass*
mass - z_mass*z_mass)/(z_mass*z_mass);
688 hist->Fill(+1*delta_M2/2);
689 hist->Fill(+1*delta_M2/2);
696 h_QoverPt->Fill((*v_pos).Phi(), 1000/(*v_pos).Pt());
697 h_QoverPt->Fill((*v_neg).Phi(), -1000/(*v_neg).Pt());
699 h_QoverPt3D->Fill((*v_pos).Eta(), (*v_pos).Phi(), 1000/(*v_pos).Pt());
700 h_QoverPt3D->Fill((*v_neg).Eta(), (*v_neg).Phi(), -1000/(*v_neg).Pt());
706 double correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_pos->Eta(), muon_pos->Phi()));
711 correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_neg->Eta(), muon_neg->Phi()));
719 double deltazd0 = -(zd0_muon_p - zd0_muon_n);
720 hist->Fill(v_pos->Eta(),v_pos->Phi(), deltazd0);
721 hist->Fill(v_neg->Eta(),v_neg->Phi(), -1.*deltazd0);
726 double deltazd0 = (zd0_muon_p - zd0_muon_n);
727 if (
pn == +1)
hist->Fill(deltazd0);
728 if (
pn == -1)
hist->Fill(-1.*deltazd0);
730 hist->Fill(-1.*deltazd0);
731 hist->Fill(deltazd0);
744 if (
m_isMC && iteration == 1) {
781 m_file.mkdir(Form(
"Iteration%i",iteration));
782 m_file.cd(Form(
"Iteration%i",iteration));
864 cout<<
"ProfileZwithIterativeGaussFit(): No histogram supplied!"<<endl;
871 int num_bins_x =
hist->GetXaxis()->GetNbins();
872 int num_bins_y =
hist->GetYaxis()->GetNbins();
874 double num_not_converged = 0;
877 double max_sigma = 0;
878 double min_sigma = 0;
885 for (
int i = 1;
i < num_bins_x+(num_bins==1);
i+=num_bins) {
887 for (
int j = 1; j < num_bins_y+(num_bins==1); j+=num_bins) {
890 int index_y = j/num_bins;
892 current_proj =
hist->ProjectionZ(Form(
"%s_GaussProjection_%i_%i",
hist->GetName(),
index, index_y),
i,
i+num_bins-1,j,j+num_bins-1);
893 current_proj->SetTitle(Form(
"%s - Bin %i x %i",
hist->GetName(),
index,index_y));
895 double current_mu,current_err_mu, current_sigma, current_err_sigma;
897 if(current_proj->GetEntries() < minEntries) {
898 if (
m_PrintLevel >= 1) cout <<
" ** profileZwithIterativeGaussFit ** fitting " <<
hist->GetName() <<
" bin (" <<
index <<
", " << index_y <<
") "
899 <<
" Not enough entries " << current_proj->GetEntries() <<
" < " << minEntries << endl;
904 current_err_sigma = 1;
906 if (fDebug) std::cout<<
"WARNING: Only "<<current_proj->GetEntries()<<
" entries in bin "<<
index<<
","<<index_y<<
" in histogram " <<
hist->GetName()<< std::endl;
910 if (
m_PrintLevel >= 1) cout <<
" ** profileZwithIterativeGaussFit ** fitting " <<
hist->GetName() <<
" bin (" <<
index <<
", " << index_y <<
") " << endl;
912 IterativeGaussFit(current_proj, current_mu, current_err_mu, current_sigma, current_err_sigma);
914 if (current_sigma > max_sigma || max_sigma == 0) max_sigma = current_sigma;
915 if (current_sigma < min_sigma || min_sigma == 0) min_sigma = current_sigma;
916 if (current_mu > max_mu || max_mu == 0) max_mu = current_mu;
917 if (current_mu < min_mu || min_mu == 0) min_mu = current_mu;
921 float x_coord = (
hist->GetXaxis()->GetBinLowEdge(
i) +
hist->GetXaxis()->GetBinUpEdge(
i+num_bins-1))/2;
922 float y_coord = (
hist->GetYaxis()->GetBinLowEdge(j) +
hist->GetYaxis()->GetBinUpEdge(j+num_bins-1))/2;
924 if (sigma_graph) sigma_graph->Fill(x_coord,y_coord,current_sigma);
925 if (mu_graph) mu_graph->Fill(x_coord,y_coord,current_mu);
928 if (sigma_err_graph) sigma_err_graph->Fill(x_coord,y_coord,current_err_sigma);
929 if (mu_err_graph) mu_err_graph->Fill(x_coord,y_coord,current_err_mu);
937 mu_graph->GetXaxis()->SetTitle(
hist->GetXaxis()->GetTitle());
938 mu_graph->GetYaxis()->SetTitle(
hist->GetYaxis()->GetTitle());
939 mu_graph->GetYaxis()->SetTitleOffset(1);
940 mu_graph->GetZaxis()->SetTitle(
hist->GetZaxis()->GetTitle());
941 mu_graph->GetZaxis()->SetTitleOffset(1.2);
942 mu_graph->SetTitle(
"" );
948 sigma_graph->GetXaxis()->SetTitle(
hist->GetXaxis()->GetTitle());
949 sigma_graph->GetYaxis()->SetTitle(
hist->GetYaxis()->GetTitle());
950 sigma_graph->GetYaxis()->SetTitleOffset(1);
951 sigma_graph->GetZaxis()->SetTitle(
hist->GetZaxis()->GetTitle());
952 sigma_graph->GetZaxis()->SetTitleOffset(1.2);
953 sigma_graph->SetTitle(
"" );
959 mu_err_graph->GetXaxis()->SetTitle(
hist->GetXaxis()->GetTitle());
960 mu_err_graph->GetYaxis()->SetTitle(
hist->GetYaxis()->GetTitle());
961 mu_err_graph->GetYaxis()->SetTitleOffset(1);
962 mu_err_graph->GetZaxis()->SetTitle(Form(
"Error of fit #mu: %s",
hist->GetZaxis()->GetTitle()));
963 mu_err_graph->GetZaxis()->SetTitleOffset(1.2);
964 mu_err_graph->SetTitle(
hist->GetTitle());
969 if (sigma_err_graph) {
970 sigma_err_graph->GetXaxis()->SetTitle(
hist->GetXaxis()->GetTitle());
971 sigma_err_graph->GetYaxis()->SetTitle(
hist->GetYaxis()->GetTitle());
972 sigma_err_graph->GetYaxis()->SetTitleOffset(1);
973 sigma_err_graph->GetZaxis()->SetTitle(Form(
"Error of fit #sigma: %s",
hist->GetZaxis()->GetTitle()));
974 sigma_err_graph->GetZaxis()->SetTitleOffset(1.2);
975 sigma_err_graph->SetTitle(
hist->GetTitle());
981 if (num_not_converged || num_skipped) std::cout<<
"Fit Results for histogram: "<<
hist->GetName()<<std::endl;
982 if (num_not_converged) std::cout<<
"Non Convergent Bin Fraction: "<<num_not_converged<<
" / " <<num_bins_x*num_bins_y - num_skipped<<std::endl;
983 if (num_skipped) std::cout<<
"Number skipped bins: "<<num_skipped<<
" / " <<num_bins_x*num_bins_y<<std::endl;
993 std::cout <<
"Error in ProfileYwithIterativeGaussFit(): Histogram not found" <<std::endl;
998 std::cout <<
"Error in ProfileYwithIterativeGaussFit(): Invalid number of bins to integrate over." <<std::endl;
1002 const int minEntries = 50;
1003 const int fDebug = 0;
1005 int num_bins_x =
hist->GetXaxis()->GetNbins();
1007 if (mu_graph) mu_graph->Rebin(num_bins);
1008 if (sigma_graph) sigma_graph->Rebin(num_bins);
1010 double* errs_mu =
new double[num_bins_x/num_bins + 2];
1011 double* errs_sigma =
new double[num_bins_x/num_bins + 2];
1014 errs_mu[num_bins_x/num_bins + 1] = 0;
1017 errs_sigma[num_bins_x/num_bins + 1] = 0;
1019 double min_sigma = 0;
1020 double max_sigma = 0;
1024 int num_skipped = 0;
1028 for (
int i = 1;
i < (num_bins_x + (num_bins == 1));
i+=num_bins) {
1031 if (num_bins == 1)
index--;
1033 current_proj =
hist->ProjectionY(Form(
"%s_projection_%i",
hist->GetName(),
index),
i,
i+num_bins-1);
1035 double mu, mu_err,
sigma, sigma_err;
1037 if(current_proj->GetEntries() < minEntries) {
1043 if ( fDebug ) std::cout<<
"WARNING: Not enough entries in bin "<<
index<<std::endl;
1048 if (
sigma > max_sigma || max_sigma == 0) max_sigma =
sigma;
1049 if (
sigma < min_sigma || min_sigma == 0) min_sigma =
sigma;
1050 if (
mu > max_mu || max_mu == 0) max_mu =
mu;
1051 if (
mu < min_mu || min_mu == 0) min_mu =
mu;
1055 double value_x = (
hist->GetXaxis()->GetBinLowEdge(
i) +
hist->GetXaxis()->GetBinUpEdge(
i+num_bins-1))/2;
1062 if (sigma_graph) sigma_graph->Fill(value_x,
sigma);
1063 if (mu_graph) mu_graph->Fill(value_x,
mu);
1065 errs_mu[
index + 1] = mu_err;
1066 errs_sigma[
index + 1] = sigma_err;
1068 delete current_proj;
1072 sigma_graph->SetError(errs_sigma);
1075 sigma_graph->GetYaxis()->SetTitleOffset(1.5);
1076 sigma_graph->GetYaxis()->SetTitle(
hist->GetYaxis()->GetTitle());
1077 sigma_graph->GetXaxis()->SetTitle(
hist->GetXaxis()->GetTitle());
1078 sigma_graph->SetTitle(
"");
1082 mu_graph->SetError(errs_mu);
1085 mu_graph->GetYaxis()->SetTitleOffset(1.5);
1086 mu_graph->GetYaxis()->SetTitle(
hist->GetYaxis()->GetTitle());
1087 mu_graph->GetXaxis()->SetTitle(
hist->GetXaxis()->GetTitle());
1088 mu_graph->SetTitle(
"");
1091 if (fDebug && num_skipped) std::cout<<
" Number of skipped bins: "<<num_skipped<<std::endl;
1102 const int iteration_limit = 20;
1103 const float percent_limit = 0.01;
1104 const float fit_range_multiplier = 1.5;
1105 const int fDebug = 0;
1110 double current_sigma;
1111 double mu_percent_diff;
1112 double sigma_percent_diff;
1115 if (fDebug) std::cout<<
"Error in Anp::IterativeGaussFit(): Histogram to be fit is missing" <<std::endl;
1121 TF1* fit_func =
new TF1(
"fit_func",
"gaus");
1123 int bad_fit =
hist->Fit(fit_func,
"QN");
1125 if (fDebug && bad_fit) std::cout <<
"BAD INITIAL FIT: "<<
hist->GetTitle() << std::endl;
1127 last_mu = fit_func->GetParameter(1);
1128 last_sigma = fit_func->GetParameter(2);
1130 if (bad_fit) last_mu =
hist->GetMean();
1133 if (fabs(last_mu -
hist->GetMean()) > 5*
hist->GetBinWidth(1)) last_mu =
hist->GetMean();
1135 fit_func->SetRange(last_mu-fit_range_multiplier*last_sigma,last_mu+fit_range_multiplier*last_sigma);
1139 while ( iteration < iteration_limit ) {
1143 double FitRangeLower = last_mu-fit_range_multiplier*last_sigma;
1144 double FitRangeUpper = last_mu+fit_range_multiplier*last_sigma;
1147 if ((FitRangeUpper-FitRangeLower)/
hist->GetBinWidth(1) < 4) {
1148 FitRangeLower -=
hist->GetBinWidth(1);
1149 FitRangeUpper +=
hist->GetBinWidth(1);
1152 fit_func->SetRange(FitRangeLower, FitRangeUpper);
1153 if (
m_PrintLevel >= 3) cout <<
" ** IterativeGaussFit ** fit iter # " << iteration
1154 <<
" new fit range: " << FitRangeLower <<
" --> " << FitRangeUpper << endl;
1158 bad_fit =
hist->Fit(fit_func,
"RQN");
1160 if (fDebug && bad_fit) std::cout<<
" ** BAD FIT ** : bin "<<
hist->GetTitle() <<
" iteration "<<iteration<<std::endl;
1162 current_mu = fit_func->GetParameter(1);
1163 current_sigma = fit_func->GetParameter(2);
1167 float average_mu = (last_mu+current_mu)/2;
1168 float average_sigma = (last_sigma+current_sigma)/2;
1170 if (average_mu == 0) {
1171 if ( fDebug ) std::cout<<
" Average mu = 0 in bin "<<
hist->GetTitle() <<std::endl;
1172 average_mu = current_mu;
1175 if (average_sigma == 0) {
1176 if ( fDebug ) std::cout<<
"Average sigma = 0; Fit Problem in "<<
hist->GetTitle() <<
". "<<last_sigma<<
" "<<current_sigma<<std::endl;
1177 average_sigma = current_sigma;
1180 mu_percent_diff = fabs((last_mu-current_mu)/average_mu);
1181 sigma_percent_diff = fabs((last_sigma-current_sigma)/average_sigma);
1183 if ( mu_percent_diff < percent_limit && sigma_percent_diff < percent_limit )
break;
1185 if (iteration != iteration_limit) {
1186 last_mu = current_mu;
1187 last_sigma = current_sigma;
1190 if (fabs(last_mu -
hist->GetMean()) > 5*
hist->GetBinWidth(1)) {
1191 if (
m_PrintLevel >= 3) cout <<
" ** IterativeGaussFit ** fit iter # " << iteration
1192 <<
" ** WARNING ** last_mu looks bad: " << last_mu
1193 <<
" this iter mu: " << fit_func->GetParameter(1)
1194 <<
" proposed mu: " <<
hist->GetMean()
1196 last_mu =
hist->GetMean();
1200 if (iteration == iteration_limit) {
1201 if (fDebug ) std::cout<<
"WARNING: Fit did not converge to < "<<percent_limit*100<<
"% in "<<
hist->GetTitle() <<
" in "<<iteration_limit<<
" iterations. Percent Diffs: "<<mu_percent_diff*100<<
"% (Mu),"<<
" "<<sigma_percent_diff*100<<
"% (Sigma)"<<std::endl;
1206 mu_err = fit_func->GetParError(1);
1207 sigma = current_sigma;
1208 sigma_err = fit_func->GetParError(2);
1210 hist->GetListOfFunctions()->Add(fit_func);
1213 cout <<
" ** IterativeGaussFit ** fit result: histo name " <<
hist->GetName() <<
" title: " <<
hist->GetTitle() << endl
1214 <<
" mu = " <<
mu <<
" +- " << mu_err << endl
1215 <<
" sigma = " <<
sigma <<
" +- " << sigma_err
1224 cout <<
" ** IterativeGaussFit ** Please type RETURN to continue:\n>";
1225 getline(cin,
input);
1340 double RangeUpper =
hist->GetBinContent(
hist->GetMaximumBin());
1341 double RangeLower =
hist->GetBinContent(
hist->GetMinimumBin());
1343 double NewRangeUpper = RangeUpper;
1344 double NewRangeLower = -RangeUpper;
1346 if (RangeUpper < - RangeLower) {
1347 NewRangeUpper = -RangeLower;
1348 NewRangeLower = RangeLower;
1351 NewRangeUpper *= 1.01;
1352 NewRangeLower *= 1.01;
1355 cout <<
" ** SymmetrizeHisto ** old range: " << RangeLower <<
" --> " << RangeUpper << endl;
1356 cout <<
" new range: " << NewRangeLower <<
" --> " << NewRangeUpper << endl;
1359 hist->SetMaximum(NewRangeUpper);
1360 hist->SetMinimum(NewRangeLower);
1368 if (
m_PrintLevel>=3) cout <<
" ** HistogramConditioning ** START ** hist = " <<
hist->GetName() << endl;
1370 double MinEntriesMPB = 15;
1371 Int_t NGroupBins = 2;
1375 Int_t MostPopulatedBin = (
hist->GetMaximumBin());
1376 double EntriesMPB =
hist->GetBinContent(MostPopulatedBin);
1377 if (EntriesMPB < MinEntriesMPB) {
1379 if ((EntriesMPB +
hist->GetBinContent(MostPopulatedBin+1) +
hist->GetBinContent(MostPopulatedBin-1)) > MinEntriesMPB) {
1387 Bool_t DivisorFound =
false;
1388 while (!DivisorFound) {
1389 if (
hist->GetNbinsX() % NGroupBins == 0) {
1390 DivisorFound =
true;
1393 DivisorFound =
false;
1397 Int_t NBinsWas =
hist->GetNbinsX();
1399 if (
m_PrintLevel>=1) cout <<
" ** HistogramConditioning ** histogram had to be rebinned by: " << NGroupBins
1400 <<
" NBins was: " << NBinsWas <<
" and now is: " <<
hist->GetNbinsX() << endl;