ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/UNL/macros/MyHbbAnalyzer.C
(Generate patch)

Comparing UserCode/UNL/macros/MyHbbAnalyzer.C (file contents):
Revision 1.4 by malbouis, Wed Sep 7 17:15:06 2011 UTC vs.
Revision 1.6 by malbouis, Fri Oct 21 14:39:57 2011 UTC

# Line 9 | Line 9
9   void MyHbbAnalyzer::Loop()
10   {
11   //   In a ROOT session, you can do:
12 < //      Root > .L MyHbbAnalyzer.C
12 > //      Root > .L MyHbbAnalyzer.C+
13   //      Root > MyHbbAnalyzer t
14   //      Root > t.GetEntry(12); // Fill t data members with entry number 12
15   //      Root > t.Show();       // Show values of entry 12
# Line 37 | Line 37 | void MyHbbAnalyzer::Loop()
37  
38     Long64_t nbytes = 0, nb = 0;
39  
40   ////////
41   // open output text file
42   ////////
43   ofstream myfile;
44   myfile.open ("sync10K.txt");
40    
41     ////////
42     // get samples weight:
# Line 55 | Line 50 | void MyHbbAnalyzer::Loop()
50     // initialize variables for significance
51     ////////
52    
58   // CSV vars:
59   // variables for significance:
60   // variables for significance:
61   double cut_CSV = 0, cut2_CSV = 0;
62   double cut_interval_CSV = 0.025;
63   int const max_cut_iter_CSV = 200;
64  
65   int evt_count_CSV_zh[max_cut_iter_CSV][2];
66   //initializeArr(evt_count_CSV_zh, max_cut_iter_CSV);
67   int evt_count_CSV_zz[max_cut_iter_CSV][2];
68   //initializeArr(evt_count_CSV_zz, max_cut_iter_CSV);
69   int evt_count_CSV_z[max_cut_iter_CSV][2];
70   //initializeArr(evt_count_CSV_z, max_cut_iter_CSV);
71   // 2D significance:
72   int evt_count_CSV2D_zh[max_cut_iter_CSV][max_cut_iter_CSV];
73   //initializeArr2D(evt_count_CSV2D_zh, max_cut_iter_CSV);
74   int evt_count_CSV2D_zz[max_cut_iter_CSV][max_cut_iter_CSV];
75   //initializeArr2D(evt_count_CSV2D_zz, max_cut_iter_CSV);
76   int evt_count_CSV2D_z[max_cut_iter_CSV][max_cut_iter_CSV];
77   //initializeArr2D(evt_count_CSV2D_z, max_cut_iter_CSV);
78  
79   for (int i = 0; i != max_cut_iter_CSV; i++){
80    for (int j = 0; j != max_cut_iter_CSV; j++){
81      evt_count_CSV2D_zh[i][j] = 0;
82      evt_count_CSV2D_zz[i][j] = 0;
83      evt_count_CSV2D_z[i][j] = 0;
84      if (j < 2){
85        evt_count_CSV_zh[i][j] = 0;
86        evt_count_CSV_zz[i][j] = 0;
87        evt_count_CSV_z[i][j] = 0;
88      }// j < 2
89    }// cuts
90  }// cuts
91
53     ////////
54     // cut and count variables
55     ////////
# Line 101 | Line 62 | void MyHbbAnalyzer::Loop()
62     int allEvts_z = 0;
63     int preSelection_z = 0;
64     int pT_jj_z = 0, pT_Z_z = 0, CSV1_z = 0, CSV2_z = 0, DPhi_ZH_z = 0, N_aj_z = 0, M_jj_z = 0;
65 <  
65 >
66     ////////
67     // loop on entries
68     ////////
69     pct = 0;
70     total_entries = fChain->GetEntries();
71  
72 <   //nentries = 1000;
72 >   //nentries = 10000;
73     for (Long64_t jentry=0; jentry<nentries;jentry++) {
74        Long64_t ientry = LoadTree(jentry);
75        if (ientry < 0) break;
# Line 123 | Line 84 | void MyHbbAnalyzer::Loop()
84        if (isZZ()) weight = ZZ_weight;
85        if (isDY()) weight = DY_weight;
86  
126      //cout << "sample ZH: " << isZH() << " DY: " << isDY() << " ZZ: " << isZZ() << endl;
127      //cout << "weight = " << weight << endl;
128
87        // count events:
88        if (isZH()) allEvts++;
89        if (isZZ()) allEvts_zz++;
90        if (isDY()) allEvts_z++;
91        basicMuonDistributions("allEvts", weight);
92        basicJetDistributions("allEvts", weight);
93 <      
93 >
94 >
95        // pre-selection cuts:
96        if (!preSelect()) continue;
97        if (isZH()) preSelection++;
# Line 140 | Line 99 | void MyHbbAnalyzer::Loop()
99        if (isDY()) preSelection_z++;
100        basicMuonDistributions("preSel", weight);
101        basicJetDistributions("preSel", weight);
143      myfile << "passed pre-selection:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << "\n";
102        
103        // pt_jj cut:
104        if (!Select_pTjj()) continue;
# Line 149 | Line 107 | void MyHbbAnalyzer::Loop()
107        if (isDY()) pT_jj_z++;
108        basicMuonDistributions("pT_jj", weight);
109        basicJetDistributions("pT_jj", weight);
152      myfile << "passed pT(jj):" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
153      
110  
111        // pT_Z cut:
112        if (!Select_pTZ()) continue;
# Line 159 | Line 115 | void MyHbbAnalyzer::Loop()
115        if (isDY()) pT_Z_z++;
116        basicMuonDistributions("pT_Z", weight);
117        basicJetDistributions("pT_Z", weight);
162      myfile << "passed pTZ:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
163      
164      ////////
165      // look at CSV1 optimization:
166      // fill arrays with discriminators after cuts
167      ////////
168      int Jet1Idx, Jet2Idx;
169      jetIndices(Jet1Idx, Jet2Idx, bDisc_CSV);
170      
171      for(int icut = 0; icut != max_cut_iter_CSV; icut++){
172        cut_CSV = icut*cut_interval_CSV;
173        if (bDisc_CSV[Jet1Idx] > cut_CSV){
174          if (isZH()) evt_count_CSV_zh[icut][0] = evt_count_CSV_zh[icut][0] + 1;
175          if (isZZ()) evt_count_CSV_zz[icut][0] = evt_count_CSV_zz[icut][0] + 1;
176          if (isDY()) evt_count_CSV_z[icut][0] = evt_count_CSV_z[icut][0] + 1;
177        }
178      }// cuts
118        
119        // CSV1 cut:
120        if (!Select_CSV1()) continue;
# Line 184 | Line 123 | void MyHbbAnalyzer::Loop()
123        if (isDY()) CSV1_z++;
124        basicMuonDistributions("CSV1", weight);
125        basicJetDistributions("CSV1", weight);
187      myfile << "passed CSV1:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
188      
189      ////////
190      // look at CSV2 optimization, AFTER CSV1 cut!
191      // fill arrays with discriminators after cuts
192      ////////
193      
194      for(int icut = 0; icut != max_cut_iter_CSV; icut++){
195        cut_CSV = icut*cut_interval_CSV;
196        if (bDisc_CSV[Jet2Idx] > cut_CSV){
197          if (isZH()) evt_count_CSV_zh[icut][1] = evt_count_CSV_zh[icut][1] + 1;
198          if (isZZ()) evt_count_CSV_zz[icut][1] = evt_count_CSV_zz[icut][1] + 1;
199          if (isDY()) evt_count_CSV_z[icut][1] = evt_count_CSV_z[icut][1] + 1;
200        }
201      }// cuts
126        
203
127        // CSV2 cut:
128        if (!Select_CSV2()) continue;
129        if (isZH()) CSV2++;
# Line 208 | Line 131 | void MyHbbAnalyzer::Loop()
131        if (isDY()) CSV2_z++;
132        basicMuonDistributions("CSV2", weight);
133        basicJetDistributions("CSV2", weight);
211      myfile << "passed CSV2:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
134        
135        // DPhi cut:
136        if (!Select_DPhi()) continue;
# Line 217 | Line 139 | void MyHbbAnalyzer::Loop()
139        if (isDY()) DPhi_ZH_z++;
140        basicMuonDistributions("DPhi", weight);
141        basicJetDistributions("DPhi", weight);
142 <      myfile << "passed DPhi:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
221 <      
222 <
142 >            
143        // Naj cut:
144        if (!Select_Naj()) continue;
145        if (isZH()) N_aj++;
# Line 227 | Line 147 | void MyHbbAnalyzer::Loop()
147        if (isDY()) N_aj_z++;
148        basicMuonDistributions("Naj", weight);
149        basicJetDistributions("Naj", weight);
150 <      myfile << "passed Naj:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
231 <      
232 <
150 >    
151        // Mjj cut:
152        if (!Select_Mjj()) continue;
153        if (isZH()) M_jj++;
# Line 237 | Line 155 | void MyHbbAnalyzer::Loop()
155        if (isDY()) M_jj_z++;
156        basicMuonDistributions("Mjj", weight);
157        basicJetDistributions("Mjj", weight);
240      myfile << "passed Mjj:" << runNumber << ":" << evtNumber << ":" << lumiBlock << ":" << jetPt[0] << ":" << jetEta[0] << ":" << muonPt[0] << ":" << muonEta[0] << ":" << computePtjj() << ":" << computePtZ() << ":" << computeDPhi() << endl;
158        
242
159     }// loop on entries
160  
245   //////
246   // write significance histos
247   ////////
248   int nbins = max_cut_iter_CSV;
249   double binMax = (max_cut_iter_CSV*cut_interval_CSV)+cut_interval_CSV;
250   double binMin = cut_interval_CSV;
251  
252   // fill cut histos:
253   for (int i = 0; i!=max_cut_iter_CSV; i++){
254     for (int ijet = 0; ijet != 2; ijet++){
255       string zh_csv_histo = Form("ZH_CSV_jet%i", ijet);
256       fillhisto(zh_csv_histo, i*cut_interval_CSV, ZH_weight*evt_count_CSV_zh[i][ijet], "", nbins, binMin, binMax);
257       string zz_csv_histo = Form("ZZ_CSV_jet%i", ijet);
258       fillhisto(zz_csv_histo, i*cut_interval_CSV, ZZ_weight*evt_count_CSV_zz[i][ijet], "", nbins, binMin, binMax);
259       string z_csv_histo = Form("DY_CSV_jet%i", ijet);
260       fillhisto(z_csv_histo, i*cut_interval_CSV, DY_weight*evt_count_CSV_z[i][ijet], "", nbins, binMin, binMax);
261       string sqrtBackground_CSV = Form("sqrtBackground_CSV_jet%i", ijet);
262       fillhisto(sqrtBackground_CSV, i*cut_interval_CSV, sqrt((DY_weight*evt_count_CSV_z[i][ijet])+(ZZ_weight*evt_count_CSV_zz[i][ijet])), "", nbins, binMin, binMax);
263     }// jets
264   }// cuts
265
161  
162     ////////
163     // write histos to file:
# Line 275 | Line 170 | void MyHbbAnalyzer::Loop()
170       (*it2).second->Write();
171       delete (*it2).second;
172     }
173 <  
173 >
174     f->Write();
175     f->Close();
176  
282   // close output text file
283   myfile.close();
177    
178     ////////
179     // print stats
# Line 288 | Line 181 | void MyHbbAnalyzer::Loop()
181     cout << endl;
182     cout << endl;
183     cout << "**** stats (no normalization) ****" << endl;
184 <   cout << "allEvts: " << allEvts <<  endl;
185 <   cout << "preSelection: " << preSelection << endl;
186 <   cout << "pT_jj: " << pT_jj << endl;
187 <   cout << "pT_Z: " << pT_Z << endl;
188 <   cout << "CSV1: " << CSV1 << endl;
189 <   cout << "CSV2: " << CSV2 << endl;
190 <   cout << "DPhi: " << DPhi_ZH << endl;
191 <   cout << "Naj: " << N_aj << endl;
192 <   cout << "Mjj: " << M_jj << endl;
184 >   cout << "allEvts, ZH: " << allEvts << " , ZZ: " << allEvts_zz << ", DY: " << allEvts_z << endl;
185 >   cout << "preSelection, ZH: " << preSelection << " , ZZ: " << preSelection_zz << ", DY: " << preSelection_z <<  endl;
186 >   cout << "pT_jj, ZH: " << pT_jj << " , ZZ: " << pT_jj_zz << ", DY: " << pT_jj_z <<  endl;
187 >   cout << "pT_Z, ZH: " << pT_Z << " , ZZ: " << pT_Z_zz << ", DY: " << pT_Z_z <<  endl;
188 >   cout << "CSV1, ZH: " << CSV1 << " , ZZ: " << CSV1_zz << ", DY: " << CSV1_z <<  endl;
189 >   cout << "CSV2, ZH: " << CSV2 << " , ZZ: " << CSV2_zz << ", DY: " << CSV2_z <<  endl;
190 >   cout << "DPhi, ZH: " << DPhi_ZH << " , ZZ: " << DPhi_ZH_zz << ", DY: " << DPhi_ZH_z <<  endl;
191 >   cout << "Naj, ZH: " << N_aj << " , ZZ: " << N_aj_zz << ", DY: " << N_aj_z <<  endl;
192 >   cout << "Mjj, ZH: " << M_jj << " , ZZ: " << M_jj_zz << ", DY: " << M_jj_z <<  endl;
193     cout << endl;
194     cout << endl;
195     cout << "**** stats normalized to 10 fb-1 ****" << endl;
# Line 335 | Line 228 | void MyHbbAnalyzer::Loop()
228     cout << endl;
229     cout << "**** TOTAL SIGNIFICANCE before Mjj cut ****" << endl;
230     cout << "S = S/sqrt{B} = " << ((double)N_aj*ZH_weight)/sqrt((N_aj_zz*ZZ_weight) + (N_aj_z*DY_weight)) << endl;
231 <
231 >   cout << endl;
232 >   cout << endl;
233  
234   }// Loop
235   bool MyHbbAnalyzer::preSelect(){
236    bool passedPreSel = true;
237    // trigger requirement:
238 <  if (!HLT_IsoMu17_v5_trig) return false;
238 >  ////if (!HLT_IsoMu17_v5_trig) return false;
239    if (nMuons < 2) passedPreSel = false;
240    if (nJets < 2) passedPreSel = false;
241 +  int firstJetIdx, secondJetIdx;
242 +  jetIndices(firstJetIdx, secondJetIdx, bDisc_CSV);
243 +  // reject events with less than 2 CSV tags
244 +  if (firstJetIdx == -1 || secondJetIdx == -1) return false;
245 +  double mz = computeMmumu();
246 +  if (mz <= 75. || mz >= 105.) passedPreSel = false;
247    return passedPreSel;
248   }// preSelect
249  
# Line 403 | Line 303 | bool  MyHbbAnalyzer::Select_Mjj(){
303    if (Mjj < 95 || Mjj > 125) passedMjj = false;
304    return passedMjj;
305   }
306 < void MyHbbAnalyzer::jetIndices(int &index1, int &index2, double bDisc[5]){
306 > void MyHbbAnalyzer::jetIndices(int &index1, int &index2, double bDisc[9]){
307    int fJetIdx = -1, sJetIdx = -1;
308    double highestBdiscSum = 0;
309    for (int i = 0; i != nJets; ++i){
# Line 447 | Line 347 | void MyHbbAnalyzer::basicMuonDistributio
347    if (isDY()) ph_process = "DY";
348        
349    for (int i=0; i != nMuons; ++i) {
350 <    string muonpT = "muonPt_" + ph_process + cut;
351 <    string muoneta = "muonEta_" + ph_process + cut;
352 <    string muonphi = "muonPhi_" + ph_process + cut;
350 >    string muonpT = Form("muonPt_%i", i) + ph_process + cut;
351 >    string muoneta = Form("muonEta_%i", i) + ph_process + cut;
352 >    string muonphi = Form("muonPhi_%i", i) + ph_process + cut;
353  
354      //cout << muonpT << endl;
355            
# Line 457 | Line 357 | void MyHbbAnalyzer::basicMuonDistributio
357      fillhisto(muoneta, muonEta[i], ph_weight, "#mu #eta", 100, -5, 5);
358      fillhisto(muonphi, muonPhi[i], ph_weight, "#mu #phi", 80, -4, 4);
359    }
360 +
361 +  double mz = computeMmumu();
362 +  string Mz = "MZ+" + ph_process + cut;
363 +  fillhisto(Mz, mz, ph_weight, "", 400, 0, 400);
364 +  
365   }// basicMuonDistributions
366  
367   void MyHbbAnalyzer::basicJetDistributions(string cut, double ph_weight){
# Line 468 | Line 373 | void MyHbbAnalyzer::basicJetDistribution
373    if (isDY()){ ph_process = "DY";}
374        
375    for (int i=0; i != nJets; ++i) {
376 <    string jetpT = "jetPt_" + ph_process + cut;
377 <    string jeteta = "jetEta_" + ph_process + cut;
378 <    string jetphi = "jetPhi_" + ph_process + cut;
474 <
475 <    //cout << muonpT << endl;
376 >    string jetpT = Form("jetPt_%i", i) + ph_process + cut;
377 >    string jeteta = Form("jetEta_%i", i) + ph_process + cut;
378 >    string jetphi = Form("jetPhi_%i", i) + ph_process + cut;
379            
380      fillhisto(jetpT, jetPt[i], ph_weight, "jet pT", 400, 0, 400);
381      fillhisto(jeteta, jetEta[i], ph_weight, "jet #eta", 100, -5, 5);
# Line 483 | Line 386 | void MyHbbAnalyzer::basicJetDistribution
386    double Mjj = computeMjj();
387    string mjj = "Mjj_" + ph_process + cut;
388    fillhisto(mjj, Mjj, ph_weight, "", 1000, 0, 1000);
389 +  
390   }// basicJetDistributions
391  
392   double MyHbbAnalyzer::computeMjj(){
393    int firstJetIdx, secondJetIdx;
394    jetIndices(firstJetIdx, secondJetIdx, bDisc_CSV);
395 <  
395 >  // reject event with less than 2 CSV tags
396 >  if (firstJetIdx == -1 || secondJetIdx == -1) return false;
397    TLorentzVector firstJet_p4 = TLorentzVector(jetPx[firstJetIdx], jetPy[firstJetIdx], jetPz[firstJetIdx], jetP[firstJetIdx]);
398    TLorentzVector secondJet_p4 = TLorentzVector(jetPx[secondJetIdx], jetPy[secondJetIdx], jetPz[secondJetIdx], jetP[secondJetIdx]);
399  
# Line 497 | Line 402 | double MyHbbAnalyzer::computeMjj(){
402    return jj.M();
403   }// Mjj
404  
405 + double MyHbbAnalyzer::computeMmumu(){
406 +
407 +  double Mz = 0.;
408 +  TLorentzVector firstMu_p4 = TLorentzVector(muonPx[0], muonPy[0], muonPz[0], muonP[0]);
409 +  TLorentzVector secondMu_p4 = TLorentzVector(muonPx[1], muonPy[1], muonPz[1], muonP[1]);
410 +  TLorentzVector Z = firstMu_p4 + secondMu_p4;
411 +  Mz = Z.M();
412 +
413 +  return Mz;
414 +
415 + }// Mmumu
416 +
417   double MyHbbAnalyzer::computePtjj(){
418    double ptjj = 0.;
419    // get jet indices that maximize the b-tag discriminant
# Line 541 | Line 458 | double MyHbbAnalyzer::computeDPhi(){
458    return dphi;
459  
460   }// dPhi
461 <
462 <
463 <
464 <
461 > double MyHbbAnalyzer::DeltaPhi(const double phi1, const double phi2){
462 >  double delta = phi1-phi2;
463 >  if (delta > TMath::Pi()) delta -= 2.0*TMath::Pi();
464 >  if (delta < (-TMath::Pi())) delta += 2.0*TMath::Pi();
465 >  return fabs(delta);
466 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines