ATLAS Offline Software
ZmumuValidationExample.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #define ZMUMUVALIDATIONEXAMPLE_C
6 
7 #include <iostream>
8 #include <list>
9 #include "TMath.h"
10 #include "TLorentzVector.h"
11 #include "TF1.h"
12 
13 #include "ZmumuValidationExample.h"
14 
15 ZmumuValidationExample::ZmumuValidationExample( std::list<std::string> const & s_fileNames, string s_treeName
16  , std::string const & s_outFileName
17  , bool isMC
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" )
23  , m_PrintLevel(0)
24  , m_EtaBins(1)
25  , m_PhiBins(1)
26  , m_isMC(isMC)
27  , n_iteration(0)
28 
29 {
30  loadChains();
32  // bookHistograms();
33 
34  m_factor = 0.5; //factor to assign lambda corrections - nominal is 0.5
35  m_shift = 0; //shift in Z mass in MeV - nominal is 0
37 }
38 
39 
41 {
42  m_file.Close();
43 
44 }
45 
46 
48 // load TChains using the user inputed list of strings
51 {
52  std::cout << "Input Files:" << std::endl;
53 
54  std::list<std::string>::const_iterator theEnd = m_fileNames.end();
55  for( std::list<std::string>::const_iterator itr = m_fileNames.begin()
56  ; itr != theEnd
57  ; ++itr
58  )
59  {
60  std::cout <<" "<< *itr << std::endl;
61 
62  m_eventChain.Add( itr->c_str() );
63  if (m_isMC) m_truthChain.Add( itr->c_str() );
64  }
65 
66  return;
67 }
68 
69 
71 // sets the branch address for each leaf to be used
74 {
76  // set branch addresses for event tree
78  m_eventChain.SetBranchAddress( "Positive_Px", &m_px_pos, &b_px_pos);
79  m_eventChain.SetBranchAddress( "Positive_Py", &m_py_pos, &b_py_pos);
80  m_eventChain.SetBranchAddress( "Positive_Pz", &m_pz_pos, &b_pz_pos);
81 
82  m_eventChain.SetBranchAddress( "Negative_Px", &m_px_neg, &b_px_neg);
83  m_eventChain.SetBranchAddress( "Negative_Py", &m_py_neg, &b_py_neg);
84  m_eventChain.SetBranchAddress( "Negative_Pz", &m_pz_neg, &b_pz_neg);
85 
86  m_eventChain.SetBranchAddress( "Positive_z0", &m_z0_pos, &b_z0_pos);
87  m_eventChain.SetBranchAddress( "Positive_d0", &m_d0_pos, &b_d0_pos);
88 
89  m_eventChain.SetBranchAddress( "Negative_z0", &m_z0_neg, &b_z0_neg);
90  m_eventChain.SetBranchAddress( "Negative_d0", &m_d0_neg, &b_d0_neg);
91 
92  if (m_isMC) {
93 
94  m_truthChain.SetBranchAddress("Positive_Px", &m_truth_px_pos, &b_truth_px_pos);
95  m_truthChain.SetBranchAddress("Positive_Py", &m_truth_py_pos, &b_truth_py_pos);
96  m_truthChain.SetBranchAddress("Positive_Pz", &m_truth_pz_pos, &b_truth_pz_pos);
97 
98  m_truthChain.SetBranchAddress("Negative_Px", &m_truth_px_neg, &b_truth_px_neg);
99  m_truthChain.SetBranchAddress("Negative_Py", &m_truth_py_neg, &b_truth_py_neg);
100  m_truthChain.SetBranchAddress("Negative_Pz", &m_truth_pz_neg, &b_truth_pz_neg);
101  }
102 
103  return;
104 }
105 
106 
108 // initializes histograms
111 {
113  // initialize histograms here
115 
116  const int fnEtaBins = m_EtaBins;
117  const int fnPhiBins = m_PhiBins;
118  const int fnQoverPtBins = 100;
119 
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;
124 
125  const double z_bound = 0.4; //mm
126  const double d_bound = 0.15; //mm
127 
128  h_DELTA = new TH1F("h_DELTA",";#delta [GeV]",200,-50,50);
129 
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.);
133 
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);
140 
141  h_mass = new TH1F("ZMass",";Mass [GeV]",100,70,110);
142 
143 // pcorrected_mass = new TH1F("PCorrectedZMass",";Mass [GeV]",100,70,110);
144 // lambdacorrected_mass = new TH1F("LambdaCorrectedZMass",";Mass [GeV]",100,70,110);
145 
146 // pcorrected_mass_vs_etaphi = new TH3F("ZMassVsEtaPhi_P",";#eta;#phi;Mass [GeV]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 100,70,110);
147 // lambdacorrected_mass_vs_etaphi = new TH3F("ZMassVsEtaPhi_Lambda",";#eta;#phi;Mass [GeV]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound, 100,70,110);
148 
149 // etaphi_pos = new TH2F("MuonEtaPhi_Positive",";#eta;#phi", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
150 // etaphi_neg = new TH2F("MuonEtaPhi_Negative",";#eta;#phi", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
151 
152 // prof_pt_vs_etaphi = new TProfile2D("AvgPtVsEtaPhi",";#eta;#phi;<p_{T}>", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
153 
154  //z0 histograms ----------------------------
155 
156  entries = new TH2F("entries","Entries per #eta-#phi bin;#eta;#phi;entries", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
157 
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);
159 
160  z0deltacorrections_vs_etaphi = new TH2D("z0CorrectionVsEtaPhi",";#eta;#phi;#delta_{z_{0}} [mm]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
161 
162  z0deltacorrections_vs_etaphi_err = new TH2D("z0CorrectionVsEtaPhi_Err",";#eta;#phi;#delta_{z_{0}}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
163 
164 
165  z0delta = new TH1D("Delta_z0", ";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
166 
167  z0delta_pos = new TH1D("Delta_z0_Pos",";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
168 
169  z0delta_neg = new TH1D("Delta_z0_Neg",";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
170 
171  z0delta_etaphi = new TH1D("Delta_z0_etaphi",";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
172 
173  z0delta_etaphi_pos = new TH1D("Delta_z0_etaphi_Pos",";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
174 
175  z0delta_etaphi_neg = new TH1D("Delta_z0_etaphi_Neg",";#delta_{z_{0}} [mm]", 100,-z_bound,z_bound);
176 
177  //d0 Histograms------------------------------------------------------------------
178 
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);
180 
181  d0deltacorrections_vs_etaphi = new TH2D("d0CorrectionVsEtaPhi",";#eta;#phi;#delta_{d_{0}} [mm]", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
182 
183  d0deltacorrections_vs_etaphi_err = new TH2D("d0CorrectionVsEtaPhi_Err",";#eta;#phi;#delta_{d_{0}}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
184 
185  d0delta = new TH1D("Delta_d0", ";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
186 
187  d0delta_pos = new TH1D("Delta_d0_Pos",";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
188 
189  d0delta_neg = new TH1D("Delta_d0_Neg",";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
190 
191  d0delta_etaphi = new TH1D("Delta_d0_etaphi",";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
192 
193  d0delta_etaphi_pos = new TH1D("Delta_d0_etaphi_Pos",";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
194 
195  d0delta_etaphi_neg = new TH1D("Delta_d0_etaphi_Neg",";#delta_{d_{0}} [mm]", 100,-d_bound,d_bound);
196 
197  //delta - charge symmetric -----------------
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);
199 
200  deltacorrections_vs_etaphi = new TH2D("PCorrectionVsEtaPhi",";#eta;#phi;#delta_{r}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
201 
202  deltacorrections_vs_etaphi_err = new TH2D("PCorrectionVsEtaPhi_Err",";#eta;#phi;#delta_{r}", fnEtaBins,-eta_bound,eta_bound, fnPhiBins,-phi_bound,phi_bound);
203 
204  //lambda * pT - charge anti-symmetric -----------------
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);
206 
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);
210 
211  //lambda * pT - charge anti-symmetric -----------------
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);
215 
216  lambdacorrections_vs_eta = new TH1D("LambdaCorrectionVsEta",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound);
217 
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);
221 
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);
225 
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);
229 
230  if (m_isMC) {
231 
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);
235 
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);
239 
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);
243 
244  lambda_vs_eta_truth = new TH2F("LambdaVsEta_Truth",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
245  lambdacorrections_vs_eta_truth = new TH1D("LambdaCorrectionVsEta_Truth",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound);
246 
247  truth_mom_bias_vs_eta = new TH2F("TruthMomentumBiasVsEta",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
248  truth_mom_biascorrections_vs_eta = new TH1D("TruthMomentumBiasCorrectionVsEta",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound);
249 
250  truth_mass_bias_vs_eta = new TH2F("TruthMassBiasVsEta",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound, 100,-pt_bound,pt_bound);
251  truth_mass_biascorrections_vs_eta = new TH1D("TruthMassBiasCorrectionVsEta",";#eta;#delta_{sagitta} [TeV^{-1}]", fnEtaBins,-eta_bound,eta_bound);
252 
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);
256 
257  delta_phi_truth = new TH1D("DeltaPhi_Truth",";#phi_{Truth} - #phi_{Rec}", 100,-0.01,0.01);
258 
259  delta_eta_truth = new TH1D("DeltaEta_Truth",";#eta_{Truth} - #eta_{Rec}", 100,-0.01,0.01);
260 
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 );
263 
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 );
266 
267  }
268 
269  // Histograms of q/pt
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}]");
273 
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);
278  h_QoverPt3D->GetXaxis()->SetTitle("#eta");
279  h_QoverPt3D->GetYaxis()->SetTitle("#phi [rad]");
280  h_QoverPt3D->GetZaxis()->SetTitle("q/p_{T} [GeV^{-1}]");
281 }
282 
283 
285 // called by user to loop over TChains
288 {
289  std::cout << " TrkValidation::loop()" << std::endl;
290  n_iteration++;
291 
292  //clear histograms to be fit
293  this->ResetHistograms();
294 
295  unsigned int const nEvents = m_eventChain.GetEntries();
296  unsigned int const maxItr = ( maxEvents > 0 && maxEvents < nEvents ) ? maxEvents : nEvents;
297 
298  //loop through events and fill histograms
299  if (m_PrintLevel >= 1) cout << " ** ZmumuValidationExample::loop ** start loop on events ... " << endl;
300  loopThroughEvents( maxItr );
301 
302  if (m_PrintLevel >= 1) cout<< " ** ZmumuValidationExample::loop ** Fitting histograms" << endl;
303 
304  //Fit corrections and add to previous corrections
308 
311 
312  if (m_isMC && n_iteration == 1) {
315 
319  }
320 
322 
323  return;
324 }
325 
326 
328 // loops over each event and calls fillHistograms() if there are tracks
330 void ZmumuValidationExample::loopThroughEvents( unsigned int maxItr )
331 {
332  std::cout << " Looping over " << maxItr << " events"<< std::endl;
333 
334  for( unsigned int eventItr = 0
335  ; eventItr != maxItr
336  ; ++eventItr
337  )
338  {
339  if( eventItr % 10000 == 0 )
340  {
341  std::cout << " Processing event " << eventItr << " of " << maxItr << std::endl;
342  }
343 
344  if( !m_eventChain.LoadTree(eventItr) || (m_isMC && !m_truthChain.LoadTree(eventItr)) )
345  continue;
346 
347  if( !m_eventChain.GetEntry(eventItr) || (m_isMC && !m_truthChain.GetEntry(eventItr)) )
348  continue;
349 
350  fillHistograms();
351  }
352 
353  return;
354 }
355 
358 {
359 
360  const double muon_mass = 105.658; //MeV
361 
362  //create lorentz vectors for both muons
363  TLorentzVector* vec_pos = new TLorentzVector();
364  TLorentzVector* vec_neg = new TLorentzVector();
365 
366  //corrected z0 for both muons
367  double corrected_z0_pos;
368  double corrected_z0_neg;
369  double corrected_d0_pos;
370  double corrected_d0_neg;
371 
372  vec_pos->SetXYZM(m_px_pos, m_py_pos, m_pz_pos, muon_mass);
373  vec_neg->SetXYZM(m_px_neg, m_py_neg, m_pz_neg, muon_mass);
374 
375  entries->Fill(vec_pos->Eta(),vec_pos->Phi(),1);
376  entries->Fill(vec_neg->Eta(),vec_neg->Phi(),1);
377 
378  fillHistogram( lambda, vec_pos, vec_neg, 1);
379  fillHistogram( lambda_pos, vec_pos, vec_neg, 1, +1);
380  fillHistogram( lambda_neg, vec_pos, vec_neg, 1, -1);
381 
382  //z0 etaphi
383  if ( m_d0_neg != 0 && m_d0_pos != 0){
384  // setting original z0values
385  corrected_z0_pos = m_z0_pos;
386  corrected_z0_neg = m_z0_neg;
387  // filling test histograms before correction
388  fillZd0Histogram( z0delta, corrected_z0_pos, corrected_z0_neg, 0);
389  fillZd0Histogram( z0delta_pos, corrected_z0_pos, corrected_z0_neg, 1);
390  fillZd0Histogram( z0delta_neg, corrected_z0_pos, corrected_z0_neg, -1);
391  // adding correction to z0_pos/neg or d0_pos/neg
392  correctZd0(z0deltacorrections_vs_etaphi, vec_pos, vec_neg, corrected_z0_pos, corrected_z0_neg);
393  // filling the main histogram to fit in the next step
394  fillZd0EtaPhiHistogram(z0delta_vs_etaphi, vec_pos, vec_neg, corrected_z0_pos, corrected_z0_neg);
395  // filling test histograms after correction
396  fillZd0Histogram( z0delta_etaphi, corrected_z0_pos, corrected_z0_neg, 0);
397  fillZd0Histogram( z0delta_etaphi_pos, corrected_z0_pos, corrected_z0_neg, 1);
398  fillZd0Histogram( z0delta_etaphi_neg, corrected_z0_pos, corrected_z0_neg, -1);
399  }
400 
401  //d0 etaphi
402  if ( m_d0_neg != 0 && m_d0_pos != 0){
403  // setting original d0values
404  corrected_d0_pos = m_d0_pos;
405  corrected_d0_neg = m_d0_neg;
406  // filling test histograms before correction
407  fillZd0Histogram( d0delta, corrected_d0_pos, corrected_d0_neg, 0);
408  fillZd0Histogram( d0delta_pos, corrected_d0_pos, corrected_d0_neg, 1);
409  fillZd0Histogram( d0delta_neg, corrected_d0_pos, corrected_d0_neg, -1);
410  // adding correction to z0_pos/neg or d0_pos/neg
411  correctZd0(d0deltacorrections_vs_etaphi, vec_pos, vec_neg, corrected_d0_pos, corrected_d0_neg);
412  // filling the main histogram to fit in the next step
413  fillZd0EtaPhiHistogram(d0delta_vs_etaphi, vec_pos, vec_neg, corrected_d0_pos, corrected_d0_neg);
414  // filling test histograms after correction
415  fillZd0Histogram( d0delta_etaphi, corrected_d0_pos, corrected_d0_neg, 0);
416  fillZd0Histogram( d0delta_etaphi_pos, corrected_d0_pos, corrected_d0_neg, 1);
417  fillZd0Histogram( d0delta_etaphi_neg, corrected_d0_pos, corrected_d0_neg, -1);
418  }
419 
420  //fill truth histograms on first iteration without correcting momentum
421  if (m_isMC && n_iteration == 1) {
422 
423  TLorentzVector* vec_truth_pos = new TLorentzVector();
424  TLorentzVector* vec_truth_neg = new TLorentzVector();
425 
426  vec_truth_pos->SetXYZM(m_truth_px_pos, m_truth_py_pos, m_truth_pz_pos, muon_mass);
427  vec_truth_neg->SetXYZM(m_truth_px_neg, m_truth_py_neg, m_truth_pz_neg, muon_mass);
428 
429  double z_mass = 91187.6; //MeV
430  double mass = ((*vec_pos) + (*vec_neg)).M();
431  double mass_truth = ((*vec_truth_pos) + (*vec_truth_neg)).M();
432 
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);
436 
437  h_pt_truth->Fill(vec_truth_pos->Pt()/1000.0);
438  h_pt_truth->Fill(vec_truth_neg->Pt()/1000.0);
439  h_pt_pos_truth->Fill(vec_truth_pos->Pt()/1000.0);
440  h_pt_neg_truth->Fill(vec_truth_neg->Pt()/1000.0);
441 
442  //truth momentum bias
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;
445 
446  truth_mom_bias_vs_eta->Fill(vec_truth_pos->Eta(), d_bias_truth_pos);
447  truth_mom_bias_vs_eta->Fill(vec_truth_neg->Eta(), d_bias_truth_neg);
448 
449  //Z mass/method bias
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;
452 
453  truth_mass_bias_vs_eta->Fill(vec_truth_pos->Eta(), d_mass_bias_truth_pos);
454  truth_mass_bias_vs_eta->Fill(vec_truth_neg->Eta(), d_mass_bias_truth_neg);
455 
456  //lambda corrections
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;
459 
460  lambda_vs_etaphi_truth->Fill(vec_truth_pos->Eta(), vec_truth_pos->Phi(), d_lambda_truth_pos);
461  lambda_vs_etaphi_truth->Fill(vec_truth_neg->Eta(), vec_truth_neg->Phi(), d_lambda_truth_neg);
462 
463  lambda_vs_eta_truth->Fill(vec_truth_pos->Eta(), d_lambda_truth_pos);
464  lambda_vs_eta_truth->Fill(vec_truth_neg->Eta(), d_lambda_truth_neg);
465 
466  lambda_truth->Fill( d_lambda_truth_pos );
467  lambda_truth->Fill( d_lambda_truth_neg );
468 
469  lambda_truth_pos->Fill( d_lambda_truth_pos );
470  lambda_truth_neg->Fill( d_lambda_truth_neg );
471 
472  //delta corrections
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();
475 
476  delta_vs_etaphi_truth->Fill(vec_truth_pos->Eta(), vec_truth_pos->Phi(), delta_truth_pos);
477  delta_vs_etaphi_truth->Fill(vec_truth_neg->Eta(), vec_truth_neg->Phi(), delta_truth_neg);
478 
479  //check eta/phi biases
480  delta_phi_truth->Fill(vec_truth_pos->Phi() - vec_pos->Phi());
481  delta_phi_truth->Fill(vec_truth_neg->Phi() - vec_neg->Phi());
482 
483  delta_eta_truth->Fill(vec_truth_pos->Eta() - vec_pos->Eta());
484  delta_eta_truth->Fill(vec_truth_neg->Eta() - vec_neg->Eta());
485 
486  //other checks
487  double zpt_truth = ((*vec_truth_pos) + (*vec_truth_neg)).Pt();
488 
489  h_DELTA->Fill(delta_M2/(vec_pos->Pt() - vec_neg->Pt())*1000000);
490  //h_DELTA->Fill(delta_M2/(vec_truth_pos->Pt() - vec_truth_neg->Pt())*1000000);
491 
492  delta_M2_vs_zpt_truth->Fill(zpt_truth/1000.0,delta_M2_truth);
493  delta_M2_vs_zpt->Fill(zpt_truth/1000.0,delta_M2);
494 
495  delta_M2_vs_etaphi_pos->Fill(vec_pos->Eta(), vec_pos->Phi(), delta_M2);
496  delta_M2_vs_etaphi_neg->Fill(vec_neg->Eta(), vec_neg->Phi(), delta_M2);
497 
498  delete vec_truth_pos;
499  delete vec_truth_neg;
500 
501  } // end if of MC and truth info
502 
503  //-----------------------------------------------------------------
504  //apply lambda momentum corrections in eta/phi
505  correctMomentum( lambdacorrections_vs_etaphi, vec_pos, vec_neg, 1);
506 
507  fillHistogram( lambda_etaphi, vec_pos, vec_neg, 1);
508  fillHistogram( lambda_etaphi_pos, vec_pos, vec_neg, 1, +1);
509  fillHistogram( lambda_etaphi_neg, vec_pos, vec_neg, 1, -1);
510 
511  //fill histograms
512  fillEtaPhiHistogram( lambda_vs_etaphi, vec_pos, vec_neg, 1);
513 
514  // fill q/pt histograms
515  fillQoverPtHistograms (vec_pos, vec_neg);
516 
517  //-----------------------------------------------------------------
518 
519  //reset muon vectors and use original values
520  vec_pos->SetXYZM(m_px_pos, m_py_pos, m_pz_pos, muon_mass);
521  vec_neg->SetXYZM(m_px_neg, m_py_neg, m_pz_neg, muon_mass);
522 
523  //apply delta momentum corrections in eta/phi
524  correctMomentum( deltacorrections_vs_etaphi, vec_pos, vec_neg, 0);
525  //fill histograms
526  fillEtaPhiHistogram( delta_vs_etaphi, vec_pos, vec_neg, 0);
527 
528  //-----------------------------------------------------------------
529 
530  //reset muon vectors and use original values
531  vec_pos->SetXYZM(m_px_pos, m_py_pos, m_pz_pos, muon_mass);
532  vec_neg->SetXYZM(m_px_neg, m_py_neg, m_pz_neg, muon_mass);
533 
534  //apply lambda momentum corrections in eta
535  correctMomentum( lambdacorrections_vs_eta, vec_pos, vec_neg, 1);
536 
537  fillHistogram( lambda_eta, vec_pos, vec_neg, 1);
538  fillHistogram( lambda_eta_pos, vec_pos, vec_neg, 1, +1);
539  fillHistogram( lambda_eta_neg, vec_pos, vec_neg, 1, -1);
540 
541  //fill histograms
542  fillEtaHistogram( lambda_vs_eta, vec_pos, vec_neg, 1);
543  fillEtaHistogram( lambda_vs_eta_pos, vec_pos, vec_neg, 1, +1);
544  fillEtaHistogram( lambda_vs_eta_neg, vec_pos, vec_neg, 1, -1);
545 
546  //check corrected pt/mass distributions at each iteration
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);
551 
552  h_mass->Fill(((*vec_pos)+(*vec_neg)).M()/1000.0);
553 
554  //check z0 distributions
555  h_z0->Fill(m_z0_pos);
556  h_z0->Fill(m_z0_neg);
557  h_z0_pos->Fill(m_z0_pos);
558  h_z0_neg->Fill(m_z0_neg);
559  //check d0 distributions
560  h_d0->Fill(m_d0_pos);
561  h_d0->Fill(m_d0_neg);
562  h_d0_pos->Fill(m_d0_pos);
563  h_d0_neg->Fill(m_d0_neg);
564  //-----------------------------------------------------------------
565 
566  delete vec_pos;
567  delete vec_neg;
568 
569  return;
570 }
571 
572 //--------------------------------------------------------------------------------------------------
573 void ZmumuValidationExample::correctMomentum( TH1* h_corrections, TLorentzVector* muon_pos, TLorentzVector* muon_neg, int use_lambda)
574 {
575  double temp_pt_pos = muon_pos->Pt();
576  double temp_pt_neg = muon_neg->Pt();
577 
578  // positive muon
579  double correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_pos->Eta(), muon_pos->Phi()));
580  if (use_lambda) {
581 
582  double pt_true = muon_pos->Pt();
583  //double pt_true = muon_pos->Pt()/(1+(+1)*correction*muon_pos->Pt()/1000000.0);
584 
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),
588  muon_pos->M());
589  if (m_PrintLevel >= 3) {
590  cout << " ** correctMomentum ** mu+ (eta,phi) (" << muon_pos->Eta() << ", " << muon_pos->Phi() << ") "
591  << " bin = " << h_corrections->FindBin(muon_pos->Eta(), muon_pos->Phi())
592  << " correction = " << correction
593  << endl;
594  }
595  }
596  else {
597  // mainly for delta corrections
598  muon_pos->SetXYZM(muon_pos->Px()*(1-correction),
599  muon_pos->Py()*(1-correction),
600  muon_pos->Pz()*(1-correction),
601  muon_pos->M());
602  }
603 
604  // negative muon
605  correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_neg->Eta(), muon_neg->Phi()));
606  if (use_lambda) {
607 
608  double pt_true = muon_neg->Pt();
609  //double pt_true = muon_neg->Pt()/(1+(+1)*correction*muon_neg->Pt()/1000000.0);
610 
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),
614  muon_neg->M());
615  if (m_PrintLevel >= 3) {
616  cout << " ** correctMomentum ** mu- (eta,phi) (" << muon_neg->Eta() << ", " << muon_neg->Phi() << ") "
617  << " bin = " << h_corrections->FindBin(muon_neg->Eta(), muon_neg->Phi())
618  << " correction = " << correction
619  << endl;
620  }
621  }
622  else {
623  // mainly for delta corrections
624  muon_neg->SetXYZM(muon_neg->Px()*(1-correction),
625  muon_neg->Py()*(1-correction),
626  muon_neg->Pz()*(1-correction),
627  muon_neg->M());
628  }
629 
630  if (m_PrintLevel >= 3) {
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;
633  }
634 
635 
636  return;
637 }
638 
639 
640 //-------------------------------------------------------------------------------
641 void ZmumuValidationExample::fillEtaPhiHistogram(TH3* hist, TLorentzVector* v_pos, TLorentzVector* v_neg, int use_lambda)
642 {
643  double z_mass = 91187.6 + m_shift; //MeV
644  double mass = ((*v_pos) + (*v_neg)).M();
645  double delta_M2 = (mass*mass - z_mass*z_mass)/(z_mass*z_mass);
646 
647  if (use_lambda) {
648  // to estimate the correction factor from: pt -> pt /(1+q pt delta_sagitta): q DeltaM2/pt
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);
651 
652  } else {
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);
655  }
656 }
657 
658 
659 //-------------------------------------------------------------------------------
660 void ZmumuValidationExample::fillEtaHistogram(TH2* hist, TLorentzVector* v_pos, TLorentzVector* v_neg, int use_lambda, int charge)
661 {
662  double z_mass = 91187.6 + m_shift; //MeV
663  double mass = ((*v_pos) + (*v_neg)).M();
664  double delta_M2 = (mass*mass - z_mass*z_mass)/(z_mass*z_mass);
665 
666  if (use_lambda) {
667  if (charge == 0 || charge == +1) hist->Fill(v_pos->Eta(), +1*m_factor*delta_M2/v_pos->Pt()*1000000.0 );
668  if (charge == 0 || charge == -1) hist->Fill(v_neg->Eta(), -1*m_factor*delta_M2/v_neg->Pt()*1000000.0 );
669 
670  } else {
671  hist->Fill(v_pos->Eta(), +1*delta_M2/2);
672  hist->Fill(v_neg->Eta(), +1*delta_M2/2);
673  }
674 }
675 
676 //-----------------------------------------------------------------------------------------------
677 void ZmumuValidationExample::fillHistogram(TH1* hist, TLorentzVector* v_pos, TLorentzVector* v_neg, int fill_lambda, int charge)
678 {
679  double z_mass = 91187.6 + m_shift; //MeV
680  double mass = ((*v_pos) + (*v_neg)).M();
681  double delta_M2 = (mass*mass - z_mass*z_mass)/(z_mass*z_mass);
682 
683  if (fill_lambda) {
684  if (charge == 0 || charge == +1) hist->Fill( +1*m_factor*delta_M2/v_pos->Pt()*1000000.0 );
685  if (charge == 0 || charge == -1) hist->Fill( -1*m_factor*delta_M2/v_neg->Pt()*1000000.0 );
686 
687  } else {
688  hist->Fill(+1*delta_M2/2);
689  hist->Fill(+1*delta_M2/2);
690  }
691 }
692 
693 //-----------------------------------------------------------------------------------------------
694 void ZmumuValidationExample::fillQoverPtHistograms(TLorentzVector* v_pos, TLorentzVector* v_neg)
695 {
696  h_QoverPt->Fill((*v_pos).Phi(), 1000/(*v_pos).Pt()); // 1000 is for MeV to GeV
697  h_QoverPt->Fill((*v_neg).Phi(), -1000/(*v_neg).Pt());
698 
699  h_QoverPt3D->Fill((*v_pos).Eta(), (*v_pos).Phi(), 1000/(*v_pos).Pt()); // 1000 is for MeV to GeV
700  h_QoverPt3D->Fill((*v_neg).Eta(), (*v_neg).Phi(), -1000/(*v_neg).Pt());
701  return;
702 }
703 // impact parameter biases methods------------------------------------------------------------------
704 void ZmumuValidationExample::correctZd0( TH1* h_corrections, TLorentzVector* muon_pos, TLorentzVector* muon_neg, double& zd0_muon_p, double& zd0_muon_n)
705 {
706  double correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_pos->Eta(), muon_pos->Phi()));
707 // std::cout << "Pos Cor" << correction << std::endl;
708 
709  zd0_muon_p = zd0_muon_p + correction ;
710 
711  correction = h_corrections->GetBinContent(h_corrections->FindBin(muon_neg->Eta(), muon_neg->Phi()));
712  zd0_muon_n = zd0_muon_n + correction ;
713 // std::cout << "Neg Cor" << correction << std::endl;
714 
715 }
716 
717 void ZmumuValidationExample::fillZd0EtaPhiHistogram(TH3* hist, TLorentzVector* v_pos, TLorentzVector* v_neg, double zd0_muon_p, double zd0_muon_n)
718 {
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);
722 }
723 
724 void ZmumuValidationExample::fillZd0Histogram(TH1* hist, double zd0_muon_p, double zd0_muon_n, int pn)
725 {
726  double deltazd0 = (zd0_muon_p - zd0_muon_n);
727  if (pn == +1) hist->Fill(deltazd0);
728  if (pn == -1) hist->Fill(-1.*deltazd0);
729  if (pn == 0) {
730  hist->Fill(-1.*deltazd0);
731  hist->Fill(deltazd0);
732  }
733 }
734 // impact parameter biases methods------------------------------------------------------------------
735 
737 // saves root objects to a TFile
740 {
741 
742  m_file.cd();
743 
744  if (m_isMC && iteration == 1) {
745 
746  h_pt_truth->Write();
747  h_pt_pos_truth->Write();
748  h_pt_neg_truth->Write();
749 
752 
755 
757  lambda_vs_eta_truth->Write();
758 
760  truth_mom_bias_vs_eta->Write();
761 
763  truth_mass_bias_vs_eta->Write();
764 
765  lambda_truth->Write();
766  lambda_truth_pos->Write();
767  lambda_truth_neg->Write();
768 
769  delta_phi_truth->Write();
770  delta_eta_truth->Write();
771 
772  delta_M2_vs_zpt_truth->Write();
773  delta_M2_vs_zpt->Write();
774 
775  delta_M2_vs_etaphi_pos->Write();
776  delta_M2_vs_etaphi_neg->Write();
777 
778  }
779 
780  if (iteration > 0) {
781  m_file.mkdir(Form("Iteration%i",iteration));
782  m_file.cd(Form("Iteration%i",iteration));
783  }
784 
785  h_pt->Write();
786  h_pt_pos->Write();
787  h_pt_neg->Write();
788  h_mass->Write();
789 
790  h_z0->Write();
791  h_z0_pos->Write();
792  h_z0_neg->Write();
793  h_d0->Write();
794  h_d0_pos->Write();
795  h_d0_neg->Write();
796 
797  deltacorrections_vs_etaphi->Write();
799 
800  entries->Write();
801 
805  lambdacorrections_vs_eta->Write();
806 
807  lambda_vs_eta->Write();
808  lambda_vs_etaphi->Write();
809 
810  lambda_vs_eta_pos->Write();
811  lambda_vs_eta_neg->Write();
812 
813  lambda->Write();
814  lambda_pos->Write();
815  lambda_neg->Write();
816 
817  lambda_eta->Write();
818  lambda_eta_pos->Write();
819  lambda_eta_neg->Write();
820 
821  lambda_etaphi->Write();
822  lambda_etaphi_pos->Write();
823  lambda_etaphi_neg->Write();
824 
825  z0delta_vs_etaphi->Write();
828 
829  z0delta->Write();
830  z0delta_pos->Write();
831  z0delta_neg->Write();
832 
833 
834  z0delta_etaphi->Write();
835  z0delta_etaphi_pos->Write();
836  z0delta_etaphi_neg->Write();
837 
838  d0delta_vs_etaphi->Write();
841 
842  d0delta->Write();
843  d0delta_pos->Write();
844  d0delta_neg->Write();
845 
846  d0delta_etaphi->Write();
847  d0delta_etaphi_pos->Write();
848  d0delta_etaphi_neg->Write();
849 
850  //cout<< "MEAN: " <<h_DELTA->GetMean()<<endl;
851  h_DELTA->Write();
852 
853  //
854  h_QoverPt->Write();
855  h_QoverPt3D->Write();
856  // delta_vs_etaphi->Write();
857 }
858 
859 
860 //-------------------------------------------------------------
861 void ZmumuValidationExample::profileZwithIterativeGaussFit(TH3* hist, TH2* mu_graph, TH2* sigma_graph, int num_bins, TH2* mu_err_graph, TH2* sigma_err_graph)
862 {
863  if (!hist) {
864  cout<< "ProfileZwithIterativeGaussFit(): No histogram supplied!"<<endl;
865  return;
866  }
867 
868  int minEntries = 50;
869  int fDebug = 0;
870 
871  int num_bins_x = hist->GetXaxis()->GetNbins();
872  int num_bins_y = hist->GetYaxis()->GetNbins();
873 
874  double num_not_converged = 0;
875  int num_skipped = 0;
876 
877  double max_sigma = 0;
878  double min_sigma = 0;
879 
880  double max_mu = 0;
881  double min_mu = 0;
882 
883  TH1D* current_proj;
884 
885  for (int i = 1; i < num_bins_x+(num_bins==1); i+=num_bins) {
886 
887  for (int j = 1; j < num_bins_y+(num_bins==1); j+=num_bins) {
888 
889  int index = i/num_bins;
890  int index_y = j/num_bins;
891 
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));
894 
895  double current_mu,current_err_mu, current_sigma, current_err_sigma;
896 
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;
900  //current_mu = -999;
901  current_mu = 0;
902  current_sigma = 0;
903  current_err_mu = 1;
904  current_err_sigma = 1;
905 
906  if (fDebug) std::cout<<"WARNING: Only "<<current_proj->GetEntries()<<" entries in bin "<<index<<","<<index_y<< " in histogram " <<hist->GetName()<< std::endl;
907  num_skipped++;
908 
909  } else {
910  if (m_PrintLevel >= 1) cout << " ** profileZwithIterativeGaussFit ** fitting " << hist->GetName() << " bin (" << index << ", " << index_y << ") " << endl;
911 
912  IterativeGaussFit(current_proj, current_mu, current_err_mu, current_sigma, current_err_sigma);
913 
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;
918 
919  }//end if entries < minEntries
920 
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;
923 
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);
926 
927  //should probably be replace bin content, not fill?
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);
930 
931  delete current_proj;
932 
933  } //end loop on j (y)
934  } //end loop on i (x)
935 
936  if (mu_graph) {
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( "" );
943  //mu_graph->SetMaximum(max_mu + 0.1* (max_mu-min_mu));
944  //mu_graph->SetMinimum(min_mu - 0.1* (max_mu-min_mu));
945  }
946 
947  if (sigma_graph) {
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( "" );
954  //sigma_graph->SetMaximum(max_sigma + 0.1* (max_sigma-min_sigma));
955  //sigma_graph->SetMinimum(min_sigma - 0.1* (max_sigma-min_sigma));
956  }
957 
958  if (mu_err_graph) {
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());
965  //mu_err_graph->SetMaximum(max_mu + 0.1* (max_mu-min_mu));
966  //mu_err_graph->SetMinimum(min_mu - 0.1* (max_mu-min_mu));
967  }
968 
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());
976  //sigma_err_graph->SetMaximum(max_mu + 0.1* (max_mu-min_mu));
977  //sigma_err_graph->SetMinimum(min_mu - 0.1* (max_mu-min_mu));
978  }
979 
980 
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;
984 
985  return;
986 }
987 
988 //-----------------------------------------------------------------------------
989 void ZmumuValidationExample::profileYwithIterativeGaussFit(TH2* hist, TH1* mu_graph, TH1* sigma_graph, int num_bins)
990 {
991 
992  if (!hist) {
993  std::cout << "Error in ProfileYwithIterativeGaussFit(): Histogram not found" <<std::endl;
994  return;
995  }
996 
997  if (num_bins < 1 ) {
998  std::cout << "Error in ProfileYwithIterativeGaussFit(): Invalid number of bins to integrate over." <<std::endl;
999  return;
1000  }
1001 
1002  const int minEntries = 50;
1003  const int fDebug = 0;
1004 
1005  int num_bins_x = hist->GetXaxis()->GetNbins();
1006 
1007  if (mu_graph) mu_graph->Rebin(num_bins);
1008  if (sigma_graph) sigma_graph->Rebin(num_bins);
1009 
1010  double* errs_mu = new double[num_bins_x/num_bins + 2]; // +2 for overflow!!
1011  double* errs_sigma = new double[num_bins_x/num_bins + 2];
1012 
1013  errs_mu[0] = 0;
1014  errs_mu[num_bins_x/num_bins + 1] = 0;
1015 
1016  errs_sigma[0] = 0;
1017  errs_sigma[num_bins_x/num_bins + 1] = 0;
1018 
1019  double min_sigma = 0;
1020  double max_sigma = 0;
1021  double min_mu = 0;
1022  double max_mu = 0;
1023 
1024  int num_skipped = 0;
1025 
1026  TH1D* current_proj;
1027 
1028  for (int i = 1; i < (num_bins_x + (num_bins == 1)); i+=num_bins) {
1029 
1030  int index = i/num_bins;
1031  if (num_bins == 1) index--;
1032 
1033  current_proj = hist->ProjectionY(Form("%s_projection_%i",hist->GetName(),index),i,i+num_bins-1);
1034 
1035  double mu, mu_err, sigma, sigma_err;
1036 
1037  if(current_proj->GetEntries() < minEntries) {
1038  mu = 0;
1039  mu_err = 0;
1040  sigma = 0;
1041  sigma_err = 0;
1042  num_skipped++;
1043  if ( fDebug ) std::cout<<"WARNING: Not enough entries in bin "<<index<<std::endl;
1044  } else {
1045 
1046  IterativeGaussFit(current_proj, mu, mu_err, sigma, sigma_err);
1047 
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;
1052 
1053  }
1054 
1055  double value_x = (hist->GetXaxis()->GetBinLowEdge(i) + hist->GetXaxis()->GetBinUpEdge(i+num_bins-1))/2;
1056 
1057  //Important!! Use Fill to increment the graph with each iteration, or SetBinContent to replace contents...
1058 
1059  //if (sigma_graph) sigma_graph->SetBinContent(i, sigma);
1060  //if (mu_graph) mu_graph->SetBinContent(i, mu);
1061 
1062  if (sigma_graph) sigma_graph->Fill(value_x, sigma);
1063  if (mu_graph) mu_graph->Fill(value_x, mu);
1064 
1065  errs_mu[index + 1] = mu_err;
1066  errs_sigma[index + 1] = sigma_err;
1067 
1068  delete current_proj;
1069  }
1070 
1071  if (sigma_graph) {
1072  sigma_graph->SetError(errs_sigma);
1073  //sigma_graph->SetMaximum(max_sigma+0.15*(max_sigma - min_sigma));
1074  //sigma_graph->SetMinimum(min_sigma-0.15*(max_sigma - min_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("");
1079  }
1080 
1081  if (mu_graph) {
1082  mu_graph->SetError(errs_mu);
1083  //mu_graph->SetMaximum(max_mu+0.15*(max_mu - min_mu));
1084  //mu_graph->SetMinimum(min_mu-0.15*(max_mu - min_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("");
1089  }
1090 
1091  if (fDebug && num_skipped) std::cout<<" Number of skipped bins: "<<num_skipped<<std::endl;
1092 
1093  return;
1094 
1095 }
1096 
1097 //-----------------------------------------------------------------------------
1098 int ZmumuValidationExample::IterativeGaussFit(TH1* hist, double &mu, double &mu_err, double &sigma, double &sigma_err)
1099 {
1100 
1101  //constants for fitting algorithm
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;
1106 
1107  double last_mu;
1108  double last_sigma;
1109  double current_mu;
1110  double current_sigma;
1111  double mu_percent_diff;
1112  double sigma_percent_diff;
1113 
1114  if (!hist) {
1115  if (fDebug) std::cout<< "Error in Anp::IterativeGaussFit(): Histogram to be fit is missing" <<std::endl;
1116  return 1;
1117  }
1118 
1119  this->HistogramConditioning(hist);
1120 
1121  TF1* fit_func = new TF1("fit_func","gaus");
1122 
1123  int bad_fit = hist->Fit(fit_func,"QN");
1124 
1125  if (fDebug && bad_fit) std::cout <<"BAD INITIAL FIT: "<< hist->GetTitle() << std::endl;
1126 
1127  last_mu = fit_func->GetParameter(1);
1128  last_sigma = fit_func->GetParameter(2);
1129 
1130  if (bad_fit) last_mu = hist->GetMean();
1131 
1132  // check as well that the last_mu is reasonable
1133  if (fabs(last_mu - hist->GetMean()) > 5*hist->GetBinWidth(1)) last_mu = hist->GetMean();
1134 
1135  fit_func->SetRange(last_mu-fit_range_multiplier*last_sigma,last_mu+fit_range_multiplier*last_sigma);
1136 
1137  int iteration = 0;
1138 
1139  while ( iteration < iteration_limit ) {
1140 
1141  iteration++;
1142 
1143  double FitRangeLower = last_mu-fit_range_multiplier*last_sigma;
1144  double FitRangeUpper = last_mu+fit_range_multiplier*last_sigma;
1145 
1146  // if range is to narrow --> broaden it
1147  if ((FitRangeUpper-FitRangeLower)/hist->GetBinWidth(1) < 4) {
1148  FitRangeLower -= hist->GetBinWidth(1);
1149  FitRangeUpper += hist->GetBinWidth(1);
1150  }
1151 
1152  fit_func->SetRange(FitRangeLower, FitRangeUpper);
1153  if (m_PrintLevel >= 3) cout << " ** IterativeGaussFit ** fit iter # " << iteration
1154  << " new fit range: " << FitRangeLower << " --> " << FitRangeUpper << endl;
1155 
1156 
1157 
1158  bad_fit = hist->Fit(fit_func, "RQN");
1159 
1160  if (fDebug && bad_fit) std::cout<<" ** BAD FIT ** : bin "<< hist->GetTitle() <<" iteration "<<iteration<<std::endl;
1161 
1162  current_mu = fit_func->GetParameter(1);
1163  current_sigma = fit_func->GetParameter(2);
1164 
1165  //std::cout<<"Iteration: "<<iteration<<" Current: "<<current_mu<<" "<<current_sigma<<" Last: "<<last_mu<<" "<<last_sigma<<std::endl;
1166 
1167  float average_mu = (last_mu+current_mu)/2;
1168  float average_sigma = (last_sigma+current_sigma)/2;
1169 
1170  if (average_mu == 0) {
1171  if ( fDebug ) std::cout<<" Average mu = 0 in bin "<< hist->GetTitle() <<std::endl;
1172  average_mu = current_mu;
1173  }
1174 
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;
1178  }
1179 
1180  mu_percent_diff = fabs((last_mu-current_mu)/average_mu);
1181  sigma_percent_diff = fabs((last_sigma-current_sigma)/average_sigma);
1182 
1183  if ( mu_percent_diff < percent_limit && sigma_percent_diff < percent_limit ) break;
1184 
1185  if (iteration != iteration_limit) { //necessary?
1186  last_mu = current_mu;
1187  last_sigma = current_sigma;
1188  }
1189  // check as well that the last_mu is reasonable
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()
1195  << endl;
1196  last_mu = hist->GetMean();
1197  }
1198  }
1199 
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;
1202  //possibly return a value other than 0 to indicate not converged?
1203  }
1204 
1205  mu = current_mu;
1206  mu_err = fit_func->GetParError(1);
1207  sigma = current_sigma;
1208  sigma_err = fit_func->GetParError(2);
1209 
1210  hist->GetListOfFunctions()->Add(fit_func);
1211 
1212  if (m_PrintLevel >= 1 ) {
1213  cout << " ** IterativeGaussFit ** fit result: histo name " << hist->GetName() << " title: " << hist->GetTitle() << endl
1214  << " mu = " << mu << " +- " << mu_err << endl
1215  << " sigma = " << sigma << " +- " << sigma_err
1216  << endl;
1217  if (TempCanvasIterGaussFit == NULL) {
1218  TempCanvasIterGaussFit = new TCanvas ("TempCanvasIterGaussFit","Iter Gauss fit", 400, 400);
1219  }
1220  hist->DrawCopy();
1221  TempCanvasIterGaussFit->Update();
1222  hist->Print();
1223  string input = "";
1224  cout << " ** IterativeGaussFit ** Please type RETURN to continue:\n>";
1225  getline(cin, input);
1226  }
1227 
1228  return 0;
1229 }
1230 
1231 //-----------------------------------------------------------------------------
1232 void ZmumuValidationExample::SetPrintLevel (int newprintlevel)
1233 {
1234  m_PrintLevel = newprintlevel;
1235  if (m_PrintLevel < 0) m_PrintLevel = 0;
1236  return;
1237 }
1238 
1239 //-----------------------------------------------------------------------------
1241 {
1242  m_EtaBins = newbins;
1243  if (m_EtaBins < 1) m_EtaBins = 1;
1244  if (m_EtaBins > 100) m_EtaBins = 100;
1245  return;
1246 }
1247 
1248 //-----------------------------------------------------------------------------
1250 {
1251  m_PhiBins = newbins;
1252  if (m_PhiBins < 1) m_PhiBins = 1;
1253  if (m_PhiBins > 100) m_PhiBins = 100;
1254  return;
1255 }
1256 
1257 //-----------------------------------------------------------------------------
1259 {
1261 
1262  lambdacorrections_vs_etaphi->DrawCopy("colz");
1263 
1264  return;
1265 }
1266 
1267 //-----------------------------------------------------------------------------
1269 {
1270  delta_vs_etaphi->Reset();
1271 
1272  //
1273  entries->Reset();
1274  z0delta_vs_etaphi->Reset();
1275 
1276  z0delta->Reset();
1277  z0delta_pos->Reset();
1278  z0delta_neg->Reset();
1279  z0delta_etaphi->Reset();
1280  z0delta_etaphi_pos->Reset();
1281  z0delta_etaphi_neg->Reset();
1282 
1283  d0delta_vs_etaphi->Reset();
1284 
1285  d0delta->Reset();
1286  d0delta_pos->Reset();
1287  d0delta_neg->Reset();
1288  d0delta_etaphi->Reset();
1289  d0delta_etaphi_pos->Reset();
1290  d0delta_etaphi_neg->Reset();
1291  //
1292 
1293  h_DELTA->Reset();
1294  h_pt->Reset();
1295  h_pt_pos->Reset();
1296  h_pt_neg->Reset();
1297  h_mass->Reset();
1298 
1299  delta_vs_etaphi->Reset();
1300 
1301  deltacorrections_vs_etaphi->Reset();
1303 
1304  lambda_vs_etaphi->Reset();
1305  lambdacorrections_vs_etaphi->Reset();
1307 
1308  lambda_vs_eta->Reset();
1309  lambda_vs_eta_pos->Reset();
1310  lambda_vs_eta_neg->Reset();
1311 
1312  lambdacorrections_vs_eta->Reset();
1313 
1314  lambda->Reset();
1315  lambda_pos->Reset();
1316  lambda_neg->Reset();
1317 
1318  lambda_eta->Reset();
1319  lambda_eta_pos->Reset();
1320  lambda_eta_neg->Reset();
1321 
1322  lambda_etaphi->Reset();
1323  lambda_etaphi_pos->Reset();
1324  lambda_etaphi_neg->Reset();
1325 
1326  // impact param histos
1327  h_z0->Reset();
1328  h_z0_pos->Reset();
1329  h_z0_neg->Reset();
1330  h_d0->Reset();
1331  h_d0_pos->Reset();
1332  h_d0_neg->Reset();
1333 
1334  return;
1335 }
1336 
1337 //-----------------------------------------------------------------------------
1339 {
1340  double RangeUpper = hist->GetBinContent(hist->GetMaximumBin());
1341  double RangeLower = hist->GetBinContent(hist->GetMinimumBin());
1342 
1343  double NewRangeUpper = RangeUpper;
1344  double NewRangeLower = -RangeUpper;
1345 
1346  if (RangeUpper < - RangeLower) {
1347  NewRangeUpper = -RangeLower;
1348  NewRangeLower = RangeLower;
1349  }
1350 
1351  NewRangeUpper *= 1.01; // increase a bit the scale just to make sure everything fits in
1352  NewRangeLower *= 1.01;
1353 
1354  if (m_PrintLevel >= 3) {
1355  cout << " ** SymmetrizeHisto ** old range: " << RangeLower << " --> " << RangeUpper << endl;
1356  cout << " new range: " << NewRangeLower << " --> " << NewRangeUpper << endl;
1357  }
1358 
1359  hist->SetMaximum(NewRangeUpper);
1360  hist->SetMinimum(NewRangeLower);
1361 
1362  return;
1363 }
1364 
1365 //-----------------------------------------------------------------------------
1367 {
1368  if (m_PrintLevel>=3) cout << " ** HistogramConditioning ** START ** hist = " << hist->GetName() << endl;
1369 
1370  double MinEntriesMPB = 15;
1371  Int_t NGroupBins = 2;
1372 
1373  // goal:
1374  // make sure that the most populated bin has a minimum number of entries
1375  Int_t MostPopulatedBin = (hist->GetMaximumBin());
1376  double EntriesMPB = hist->GetBinContent(MostPopulatedBin);
1377  if (EntriesMPB < MinEntriesMPB) {
1378  // check the entries of the neighbour channels
1379  if ((EntriesMPB + hist->GetBinContent(MostPopulatedBin+1) + hist->GetBinContent(MostPopulatedBin-1)) > MinEntriesMPB) {
1380  NGroupBins = 2;
1381  }
1382  else {
1383  NGroupBins = 3;
1384  }
1385 
1386  // now find the first divisor (factor of ) the original number of bins
1387  Bool_t DivisorFound = false;
1388  while (!DivisorFound) {
1389  if ( hist->GetNbinsX() % NGroupBins == 0) {
1390  DivisorFound = true;
1391  }
1392  else {
1393  DivisorFound = false;
1394  NGroupBins++;
1395  }
1396  }
1397  Int_t NBinsWas = hist->GetNbinsX();
1398  hist = hist->Rebin(NGroupBins);
1399  if (m_PrintLevel>=1) cout << " ** HistogramConditioning ** histogram had to be rebinned by: " << NGroupBins
1400  << " NBins was: " << NBinsWas << " and now is: " << hist->GetNbinsX() << endl;
1401 
1402  }
1403 
1404 
1405  return;
1406 }
ZmumuValidationExample::lambda_pos
TH1 * lambda_pos
Definition: ZmumuValidationExample.h:147
ZmumuValidationExample::profileZwithIterativeGaussFit
void profileZwithIterativeGaussFit(TH3 *hist, TH2 *mu_graph, TH2 *sigma_graph, int num_bins, TH2 *mu_err_graph=0, TH2 *sigma_err_graph=0)
Definition: ZmumuValidationExample.cxx:861
ZmumuValidationExample::delta_vs_etaphi_truth
TH3 * delta_vs_etaphi_truth
Definition: ZmumuValidationExample.h:189
ZmumuValidationExample::m_shift
double m_shift
Definition: ZmumuValidationExample.h:42
ZmumuValidationExample::lambdacorrections_vs_eta
TH1 * lambdacorrections_vs_eta
Definition: ZmumuValidationExample.h:144
ZmumuValidationExample::deltacorrections_vs_etaphi
TH2 * deltacorrections_vs_etaphi
Definition: ZmumuValidationExample.h:129
ZmumuValidationExample.h
ZmumuValidationExample::z0delta
TH1 * z0delta
Definition: ZmumuValidationExample.h:166
ZmumuValidationExample::m_eventChain
TChain m_eventChain
Definition: ZmumuValidationExample.h:31
ZmumuValidationExample::ZmumuValidationExample
ZmumuValidationExample(std::list< std::string > const &s_fileNames, string s_treeName="DefaultParams", std::string const &s_outFileName="ZmumuValidationExampleOutput.root", bool isMC=false)
Definition: ZmumuValidationExample.cxx:15
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
ZmumuValidationExample::DrawMap
void DrawMap()
Definition: ZmumuValidationExample.cxx:1258
ZmumuValidationExample::m_EtaBins
int m_EtaBins
Definition: ZmumuValidationExample.h:36
ZmumuValidationExample::lambda_etaphi
TH1 * lambda_etaphi
Definition: ZmumuValidationExample.h:150
ZmumuValidationExample::b_d0_pos
TBranch * b_d0_pos
Definition: ZmumuValidationExample.h:82
ZmumuValidationExample::h_pt_neg
TH1 * h_pt_neg
Definition: ZmumuValidationExample.h:101
ZmumuValidationExample::lambda_truth_neg
TH1 * lambda_truth_neg
Definition: ZmumuValidationExample.h:208
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
ZmumuValidationExample::fillEtaPhiHistogram
void fillEtaPhiHistogram(TH3 *hist, TLorentzVector *v_pos, TLorentzVector *v_neg, int use_lambda)
Definition: ZmumuValidationExample.cxx:641
ZmumuValidationExample::h_DELTA
TH1 * h_DELTA
Definition: ZmumuValidationExample.h:97
ZmumuValidationExample::z0delta_etaphi
TH1 * z0delta_etaphi
Definition: ZmumuValidationExample.h:170
ZmumuValidationExample::b_truth_pz_pos
TBranch * b_truth_pz_pos
Definition: ZmumuValidationExample.h:87
index
Definition: index.py:1
ZmumuValidationExample::lambda_vs_etaphi
TH3 * lambda_vs_etaphi
Definition: ZmumuValidationExample.h:134
ZmumuValidationExample::m_d0_pos
double m_d0_pos
Definition: ZmumuValidationExample.h:58
ZmumuValidationExample::delta_M2_vs_zpt_truth
TH2 * delta_M2_vs_zpt_truth
Definition: ZmumuValidationExample.h:214
ZmumuValidationExample::lambdacorrections_vs_etaphi_truth_err
TH2 * lambdacorrections_vs_etaphi_truth_err
Definition: ZmumuValidationExample.h:195
ZmumuValidationExample::d0deltacorrections_vs_etaphi
TH2 * d0deltacorrections_vs_etaphi
Definition: ZmumuValidationExample.h:177
plotmaker.hist
hist
Definition: plotmaker.py:148
ZmumuValidationExample::d0delta_vs_etaphi
TH3 * d0delta_vs_etaphi
Definition: ZmumuValidationExample.h:175
ZmumuValidationExample::correctMomentum
void correctMomentum(TH1 *h_corrections, TLorentzVector *muon_pos, TLorentzVector *muon_neg, int use_lambda)
Definition: ZmumuValidationExample.cxx:573
ZmumuValidationExample::m_py_neg
double m_py_neg
Definition: ZmumuValidationExample.h:53
ZmumuValidationExample::h_z0_neg
TH1 * h_z0_neg
Definition: ZmumuValidationExample.h:109
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ZmumuValidationExample::lambdacorrections_vs_etaphi_err
TH2 * lambdacorrections_vs_etaphi_err
Definition: ZmumuValidationExample.h:137
ZmumuValidationExample::lambda_eta
TH1 * lambda_eta
Definition: ZmumuValidationExample.h:154
ZmumuValidationExample::fillHistograms
void fillHistograms()
Definition: ZmumuValidationExample.cxx:357
ZmumuValidationExample::TempCanvasIterGaussFit
TCanvas * TempCanvasIterGaussFit
Definition: ZmumuValidationExample.h:227
ZmumuValidationExample::h_pt_pos
TH1 * h_pt_pos
Definition: ZmumuValidationExample.h:100
ZmumuValidationExample::b_z0_neg
TBranch * b_z0_neg
Definition: ZmumuValidationExample.h:81
ZmumuValidationExample::delta_M2_vs_etaphi_pos
TProfile2D * delta_M2_vs_etaphi_pos
Definition: ZmumuValidationExample.h:217
ZmumuValidationExample::m_fileNames
const std::list< std::string > m_fileNames
Definition: ZmumuValidationExample.h:26
ZmumuValidationExample::z0delta_neg
TH1 * z0delta_neg
Definition: ZmumuValidationExample.h:168
ZmumuValidationExample::b_truth_px_pos
TBranch * b_truth_px_pos
Definition: ZmumuValidationExample.h:85
ZmumuValidationExample::lambda_vs_etaphi_truth
TH3 * lambda_vs_etaphi_truth
Definition: ZmumuValidationExample.h:193
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
ZmumuValidationExample::b_truth_py_pos
TBranch * b_truth_py_pos
Definition: ZmumuValidationExample.h:86
ZmumuValidationExample::m_px_pos
double m_px_pos
Definition: ZmumuValidationExample.h:48
ZmumuValidationExample::~ZmumuValidationExample
~ZmumuValidationExample()
Definition: ZmumuValidationExample.cxx:40
ZmumuValidationExample::fillQoverPtHistograms
void fillQoverPtHistograms(TLorentzVector *v_pos, TLorentzVector *v_neg)
Definition: ZmumuValidationExample.cxx:694
python.SCT_ByteStreamErrorsTestAlgConfig.maxEvents
maxEvents
Definition: SCT_ByteStreamErrorsTestAlgConfig.py:43
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
ZmumuValidationExample::m_truth_py_neg
double m_truth_py_neg
Definition: ZmumuValidationExample.h:66
ZmumuValidationExample::loadChains
void loadChains()
Definition: ZmumuValidationExample.cxx:50
python.ZdcRecConfig.pn
pn
Definition: ZdcRecConfig.py:506
ZmumuValidationExample::delta_M2_vs_etaphi_neg
TProfile2D * delta_M2_vs_etaphi_neg
Definition: ZmumuValidationExample.h:218
ZmumuValidationExample::lambda_vs_eta_pos
TH2 * lambda_vs_eta_pos
Definition: ZmumuValidationExample.h:141
tools.zlumi_mc_cf.correction
def correction(mu, runmode, campaign, run=None)
Definition: zlumi_mc_cf.py:4
ZmumuValidationExample::lambda_truth_pos
TH1 * lambda_truth_pos
Definition: ZmumuValidationExample.h:207
ZmumuValidationExample::h_QoverPt3D
TH3 * h_QoverPt3D
Definition: ZmumuValidationExample.h:222
ZmumuValidationExample::m_PhiBins
int m_PhiBins
Definition: ZmumuValidationExample.h:37
ZmumuValidationExample::b_truth_pz_neg
TBranch * b_truth_pz_neg
Definition: ZmumuValidationExample.h:91
ZmumuValidationExample::SetEtaBins
void SetEtaBins(int newbins=20)
Definition: ZmumuValidationExample.cxx:1240
ZmumuValidationExample::IterativeGaussFit
int IterativeGaussFit(TH1 *hist, double &mu, double &mu_err, double &sigma, double &sigma_err)
Definition: ZmumuValidationExample.cxx:1098
ZmumuValidationExample::b_truth_py_neg
TBranch * b_truth_py_neg
Definition: ZmumuValidationExample.h:90
ZmumuValidationExample::loopThroughEvents
void loopThroughEvents(unsigned int maxItr)
Definition: ZmumuValidationExample.cxx:330
ZmumuValidationExample::d0delta_etaphi_neg
TH1 * d0delta_etaphi_neg
Definition: ZmumuValidationExample.h:186
ZmumuValidationExample::h_pt_truth
TH1 * h_pt_truth
Definition: ZmumuValidationExample.h:103
ZmumuValidationExample::lambda
TH1 * lambda
Definition: ZmumuValidationExample.h:146
ZmumuValidationExample::h_d0_neg
TH1 * h_d0_neg
Definition: ZmumuValidationExample.h:112
lumiFormat.i
int i
Definition: lumiFormat.py:85
ZmumuValidationExample::d0delta_etaphi_pos
TH1 * d0delta_etaphi_pos
Definition: ZmumuValidationExample.h:185
ZmumuValidationExample::m_truth_pz_neg
double m_truth_pz_neg
Definition: ZmumuValidationExample.h:67
ZmumuValidationExample::d0delta_neg
TH1 * d0delta_neg
Definition: ZmumuValidationExample.h:182
ZmumuValidationExample::b_pz_neg
TBranch * b_pz_neg
Definition: ZmumuValidationExample.h:78
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
ZmumuValidationExample::entries
TH2 * entries
Definition: ZmumuValidationExample.h:159
ZmumuValidationExample::truth_mass_bias_vs_eta
TH2 * truth_mass_bias_vs_eta
Definition: ZmumuValidationExample.h:203
ZmumuValidationExample::m_PrintLevel
int m_PrintLevel
Definition: ZmumuValidationExample.h:35
ZmumuValidationExample::lambda_neg
TH1 * lambda_neg
Definition: ZmumuValidationExample.h:148
ZmumuValidationExample::h_pt
TH1 * h_pt
Definition: ZmumuValidationExample.h:99
ZmumuValidationExample::d0delta_etaphi
TH1 * d0delta_etaphi
Definition: ZmumuValidationExample.h:184
ZmumuValidationExample::delta_phi_truth
TH1 * delta_phi_truth
Definition: ZmumuValidationExample.h:210
nEvents
int nEvents
Definition: fbtTestBasics.cxx:79
ZmumuValidationExample::b_pz_pos
TBranch * b_pz_pos
Definition: ZmumuValidationExample.h:74
ZmumuValidationExample::setBranchAddresses
void setBranchAddresses()
Definition: ZmumuValidationExample.cxx:73
ZmumuValidationExample::lambda_vs_eta_neg
TH2 * lambda_vs_eta_neg
Definition: ZmumuValidationExample.h:142
ZmumuValidationExample::h_d0_pos
TH1 * h_d0_pos
Definition: ZmumuValidationExample.h:111
ZmumuValidationExample::h_mass
TH1 * h_mass
Definition: ZmumuValidationExample.h:114
ZmumuValidationExample::lambdacorrections_vs_eta_truth
TH1 * lambdacorrections_vs_eta_truth
Definition: ZmumuValidationExample.h:198
ZmumuValidationExample::lambda_vs_eta_truth
TH2 * lambda_vs_eta_truth
Definition: ZmumuValidationExample.h:197
ZmumuValidationExample::delta_vs_etaphi
TH3 * delta_vs_etaphi
Definition: ZmumuValidationExample.h:127
ZmumuValidationExample::lambda_etaphi_pos
TH1 * lambda_etaphi_pos
Definition: ZmumuValidationExample.h:151
ZmumuValidationExample::fillZd0EtaPhiHistogram
void fillZd0EtaPhiHistogram(TH3 *hist, TLorentzVector *v_pos, TLorentzVector *v_neg, double z0_muon_p, double z0_muon_n)
Definition: ZmumuValidationExample.cxx:717
ZmumuValidationExample::m_px_neg
double m_px_neg
Definition: ZmumuValidationExample.h:52
ZmumuValidationExample::d0delta_pos
TH1 * d0delta_pos
Definition: ZmumuValidationExample.h:181
ZmumuValidationExample::d0delta
TH1 * d0delta
Definition: ZmumuValidationExample.h:180
ZmumuValidationExample::truth_mom_bias_vs_eta
TH2 * truth_mom_bias_vs_eta
Definition: ZmumuValidationExample.h:200
ZmumuValidationExample::SymmetrizeHisto
void SymmetrizeHisto(TH2 *hist)
Definition: ZmumuValidationExample.cxx:1338
ZmumuValidationExample::h_QoverPt
TH2 * h_QoverPt
Definition: ZmumuValidationExample.h:221
ZmumuValidationExample::m_truth_px_pos
double m_truth_px_pos
Definition: ZmumuValidationExample.h:61
ZmumuValidationExample::truth_mom_biascorrections_vs_eta
TH1 * truth_mom_biascorrections_vs_eta
Definition: ZmumuValidationExample.h:201
ZmumuValidationExample::z0delta_vs_etaphi
TH3 * z0delta_vs_etaphi
Definition: ZmumuValidationExample.h:161
ZmumuValidationExample::m_z0_pos
double m_z0_pos
Definition: ZmumuValidationExample.h:56
charge
double charge(const T &p)
Definition: AtlasPID.h:538
ZmumuValidationExample::z0deltacorrections_vs_etaphi
TH2 * z0deltacorrections_vs_etaphi
Definition: ZmumuValidationExample.h:163
ZmumuValidationExample::lambda_eta_neg
TH1 * lambda_eta_neg
Definition: ZmumuValidationExample.h:156
ZmumuValidationExample::delta_M2_vs_zpt
TH2 * delta_M2_vs_zpt
Definition: ZmumuValidationExample.h:215
ZmumuValidationExample::z0delta_etaphi_pos
TH1 * z0delta_etaphi_pos
Definition: ZmumuValidationExample.h:171
ZmumuValidationExample::m_truth_px_neg
double m_truth_px_neg
Definition: ZmumuValidationExample.h:65
ZmumuValidationExample::SetPrintLevel
void SetPrintLevel(int newprintlevel=0)
Definition: ZmumuValidationExample.cxx:1232
ZmumuValidationExample::fillEtaHistogram
void fillEtaHistogram(TH2 *hist, TLorentzVector *v_pos, TLorentzVector *v_neg, int use_lambda, int charge=0)
Definition: ZmumuValidationExample.cxx:660
ZmumuValidationExample::deltacorrections_vs_etaphi_truth
TH2 * deltacorrections_vs_etaphi_truth
Definition: ZmumuValidationExample.h:190
ZmumuValidationExample::z0delta_pos
TH1 * z0delta_pos
Definition: ZmumuValidationExample.h:167
ZmumuValidationExample::b_z0_pos
TBranch * b_z0_pos
Definition: ZmumuValidationExample.h:80
ZmumuValidationExample::HistogramConditioning
void HistogramConditioning(TH1 *hist)
Definition: ZmumuValidationExample.cxx:1366
ZmumuValidationExample::lambda_etaphi_neg
TH1 * lambda_etaphi_neg
Definition: ZmumuValidationExample.h:152
ZmumuValidationExample::h_z0_pos
TH1 * h_z0_pos
Definition: ZmumuValidationExample.h:108
ZmumuValidationExample::m_pz_pos
double m_pz_pos
Definition: ZmumuValidationExample.h:50
ZmumuValidationExample::fillHistogram
void fillHistogram(TH1 *hist, TLorentzVector *v_pos, TLorentzVector *v_neg, int fill_lambda, int charge=0)
Definition: ZmumuValidationExample.cxx:677
ZmumuValidationExample::writeToFile
void writeToFile(int iteration)
Definition: ZmumuValidationExample.cxx:739
ZmumuValidationExample::loop
void loop(unsigned maxEvents=0)
Definition: ZmumuValidationExample.cxx:287
DeMoScan.index
string index
Definition: DeMoScan.py:364
ZmumuValidationExample::m_factor
double m_factor
Definition: ZmumuValidationExample.h:43
ZmumuValidationExample::m_truth_pz_pos
double m_truth_pz_pos
Definition: ZmumuValidationExample.h:63
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
ZmumuValidationExample::ResetHistograms
void ResetHistograms()
Definition: ZmumuValidationExample.cxx:1268
ZmumuValidationExample::h_pt_pos_truth
TH1 * h_pt_pos_truth
Definition: ZmumuValidationExample.h:104
ZmumuValidationExample::bookHistograms
void bookHistograms()
Definition: ZmumuValidationExample.cxx:110
ZmumuValidationExample::m_truthChain
TChain m_truthChain
Definition: ZmumuValidationExample.h:32
ZmumuValidationExample::lambdacorrections_vs_etaphi
TH2 * lambdacorrections_vs_etaphi
Definition: ZmumuValidationExample.h:136
ZmumuValidationExample::b_py_neg
TBranch * b_py_neg
Definition: ZmumuValidationExample.h:77
ZmumuValidationExample::m_z0_neg
double m_z0_neg
Definition: ZmumuValidationExample.h:57
ZmumuValidationExample::SetPhiBins
void SetPhiBins(int newbins=20)
Definition: ZmumuValidationExample.cxx:1249
ZmumuValidationExample::lambda_vs_eta
TH2 * lambda_vs_eta
Definition: ZmumuValidationExample.h:140
ZmumuValidationExample::n_iteration
int n_iteration
Definition: ZmumuValidationExample.h:41
ZmumuValidationExample::z0deltacorrections_vs_etaphi_err
TH2 * z0deltacorrections_vs_etaphi_err
Definition: ZmumuValidationExample.h:164
ZmumuValidationExample::h_pt_neg_truth
TH1 * h_pt_neg_truth
Definition: ZmumuValidationExample.h:105
ZmumuValidationExample::b_px_pos
TBranch * b_px_pos
Definition: ZmumuValidationExample.h:72
ZmumuValidationExample::m_d0_neg
double m_d0_neg
Definition: ZmumuValidationExample.h:59
EventInfoRead.isMC
isMC
Definition: EventInfoRead.py:11
ZmumuValidationExample::m_file
TFile m_file
Definition: ZmumuValidationExample.h:29
ZmumuValidationExample::truth_mass_biascorrections_vs_eta
TH1 * truth_mass_biascorrections_vs_eta
Definition: ZmumuValidationExample.h:204
ZmumuValidationExample::m_py_pos
double m_py_pos
Definition: ZmumuValidationExample.h:49
ZmumuValidationExample::lambda_eta_pos
TH1 * lambda_eta_pos
Definition: ZmumuValidationExample.h:155
ZmumuValidationExample::correctZd0
void correctZd0(TH1 *h_corrections, TLorentzVector *muon_pos, TLorentzVector *muon_neg, double &zd0_muon_p, double &zd0_muon_n)
Definition: ZmumuValidationExample.cxx:704
ZmumuValidationExample::lambda_truth
TH1 * lambda_truth
Definition: ZmumuValidationExample.h:206
ZmumuValidationExample::h_d0
TH1 * h_d0
Definition: ZmumuValidationExample.h:110
ZmumuValidationExample::lambdacorrections_vs_etaphi_truth
TH2 * lambdacorrections_vs_etaphi_truth
Definition: ZmumuValidationExample.h:194
ZmumuValidationExample::b_py_pos
TBranch * b_py_pos
Definition: ZmumuValidationExample.h:73
ZmumuValidationExample::h_z0
TH1 * h_z0
Definition: ZmumuValidationExample.h:107
ZmumuValidationExample::fillZd0Histogram
void fillZd0Histogram(TH1 *hist, double z0_muon_p, double z0_muon_n, int pn)
Definition: ZmumuValidationExample.cxx:724
ZmumuValidationExample::z0delta_etaphi_neg
TH1 * z0delta_etaphi_neg
Definition: ZmumuValidationExample.h:172
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
ZmumuValidationExample::lambdacorrections_vs_etaphi_RMS
TH2 * lambdacorrections_vs_etaphi_RMS
Definition: ZmumuValidationExample.h:138
ZmumuValidationExample::m_isMC
bool m_isMC
Definition: ZmumuValidationExample.h:40
ZmumuValidationExample::delta_eta_truth
TH1 * delta_eta_truth
Definition: ZmumuValidationExample.h:212
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
ZmumuValidationExample::m_pz_neg
double m_pz_neg
Definition: ZmumuValidationExample.h:54
ZmumuValidationExample::b_px_neg
TBranch * b_px_neg
Definition: ZmumuValidationExample.h:76
ZmumuValidationExample::m_truth_py_pos
double m_truth_py_pos
Definition: ZmumuValidationExample.h:62
ZmumuValidationExample::profileYwithIterativeGaussFit
void profileYwithIterativeGaussFit(TH2 *hist, TH1 *mu_graph=0, TH1 *sigma_graph=0, int num_bins=1)
Definition: ZmumuValidationExample.cxx:989
ZmumuValidationExample::deltacorrections_vs_etaphi_truth_err
TH2 * deltacorrections_vs_etaphi_truth_err
Definition: ZmumuValidationExample.h:191
ZmumuValidationExample::b_truth_px_neg
TBranch * b_truth_px_neg
Definition: ZmumuValidationExample.h:89
ZmumuValidationExample::deltacorrections_vs_etaphi_err
TH2 * deltacorrections_vs_etaphi_err
Definition: ZmumuValidationExample.h:131
ZmumuValidationExample::d0deltacorrections_vs_etaphi_err
TH2 * d0deltacorrections_vs_etaphi_err
Definition: ZmumuValidationExample.h:178
ZmumuValidationExample::b_d0_neg
TBranch * b_d0_neg
Definition: ZmumuValidationExample.h:83