ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/WZStudy.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/WZStudy.C (file contents):
Revision 1.1 by buchmann, Thu Oct 11 09:11:50 2012 UTC vs.
Revision 1.3 by buchmann, Fri Oct 12 15:45:14 2012 UTC

# Line 18 | Line 18
18  
19   using namespace std;
20  
21 < void CarryOutWZStudy() {
22 <    //we do not want the
23 <  
24 <  
25 <  string Zmass="((leptonId[0]==leptonId[1])*(leptonCharge[0]*leptonCharge[1]<0)*leptonPairMass[0]   +   ((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0))*(leptonId[0]==leptonId[2])*(leptonCharge[0]*leptonCharge[2]<0)*leptonPairMass[1]   +    ((((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0)))*(((leptonId[0]!=leptonId[2])||(leptonCharge[0]*leptonCharge[2]>0))))*(leptonId[1]==leptonId[2])*(leptonCharge[1]*leptonCharge[2]<0)*leptonPairMass[2])";
26 <  
27 <  
28 <  string WZPt1="((leptonId[0]==leptonId[1])*(leptonCharge[0]*leptonCharge[1]<0)*leptonPt[0]   +   ((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0))*(leptonId[0]==leptonId[2])*(leptonCharge[0]*leptonCharge[2]<0)*leptonPt[0]   +    ((((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0)))*(((leptonId[0]!=leptonId[2])||(leptonCharge[0]*leptonCharge[2]>0))))*(leptonId[1]==leptonId[2])*(leptonCharge[1]*leptonCharge[2]<0)*leptonPt[1])";
29 <  //this is the pt of the first lepton of the Z
30 <  
31 <  
32 <  string WZPt2="((leptonId[0]==leptonId[1])*(leptonCharge[0]*leptonCharge[1]<0)*leptonPt[1]   +   ((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0))*(leptonId[0]==leptonId[2])*(leptonCharge[0]*leptonCharge[2]<0)*leptonPt[2]   +    ((((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0)))*(((leptonId[0]!=leptonId[2])||(leptonCharge[0]*leptonCharge[2]>0))))*(leptonId[1]==leptonId[2])*(leptonCharge[1]*leptonCharge[2]<0)*leptonPt[2])";
33 <  //this is the pt of the second lepton of the Z
34 <  
35 <  string WZPt3="((leptonId[0]==leptonId[1])*(leptonCharge[0]*leptonCharge[1]<0)*leptonPt[2]   +   ((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0))*(leptonId[0]==leptonId[2])*(leptonCharge[0]*leptonCharge[2]<0)*leptonPt[1]   +    ((((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0)))*(((leptonId[0]!=leptonId[2])||(leptonCharge[0]*leptonCharge[2]>0))))*(leptonId[1]==leptonId[2])*(leptonCharge[1]*leptonCharge[2]<0)*leptonPt[0])";
36 <  //this is the pt of the lepton pertaining to the W
37 <  
38 <  TCut BasicCut("leptonPt[1]>20 && leptonPt[2]>20 && leptonPt[0]>30 && leptonNum>=3");
39 <  TCut ZmassWindow("abs((((leptonId[0]==leptonId[1])*(leptonCharge[0]*leptonCharge[1]<0)*leptonPairMass[0]   +   ((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0))*(leptonId[0]==leptonId[2])*(leptonCharge[0]*leptonCharge[2]<0)*leptonPairMass[1]   +    ((((leptonId[0]!=leptonId[1])||(leptonCharge[0]*leptonCharge[1]>0)))*(((leptonId[0]!=leptonId[2])||(leptonCharge[0]*leptonCharge[2]>0))))*(leptonId[1]==leptonId[2])*(leptonCharge[1]*leptonCharge[2]<0)*leptonPairMass[2]))-91)<10");
40 <  
41 <  
21 > string IdentifierForUnderlinedEntry(string Entry) {
22 >  if(Contains(Entry,"t_bar_t__")) return "ttbar";
23 >  if(Contains(Entry,"Single_top__")) return "SingleTop";
24 >  if(Contains(Entry,"W_Jets__")) return "W+Jets";
25 >  if(Contains(Entry,"WZ__")) return "WZ";
26 >  if(Contains(Entry,"Z_Jets")) return "Z+Jets";
27 >  if(Contains(Entry,"DATA")) return "Data";
28 >  if(Contains(Entry,"2l2q_")) return "ZZ->2l2q";
29 >  if(Contains(Entry,"4l_")) return "ZZ->4l";
30 >  return Entry;
31 > }
32 >
33 > void WZ_kin_plot(string variable, int nbins, float min, float high, string xlabel, TCut cut, string saveas) {
34    TCanvas *can = new TCanvas("can","can");
35    TPad *pad = new TPad("pad","pad",0,0,1,1);
36    pad->cd();
37  
38 <  THStack m_zmass = allsamples.DrawStack("m_zmass",Zmass,40,0,200, "m_{Z} [GeV]", "events", BasicCut,mc, luminosity);
39 <  TH1F *d_zmass = allsamples.Draw("d_zmass",Zmass,40,0,200, "m_{Z} [GeV]", "events", BasicCut,data, luminosity);
38 >  THStack stack = allsamples.DrawStack("stack",variable,nbins,min,high,xlabel, "events", cut,mc, luminosity);
39 >  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,min,high,xlabel, "events", cut,data, luminosity);
40    
41 <  d_zmass->Draw("e1");
42 <  m_zmass.Draw("same");
43 <  d_zmass->Draw("e1,same");
41 >  hdata->Draw("e1");
42 >  stack.Draw("same");
43 >  hdata->Draw("e1,same");
44    TLegend *kinleg = allsamples.allbglegend();
45    kinleg->Draw();
46    DrawPrelim();
55  save_with_ratio(d_zmass,m_zmass,pad->cd(),"WZ_study/Zmass");
47    
48 <  cout << "Numbers with Z mass:" << endl;
49 <  TIter nextSF = TIter(m_zmass.GetHists());
48 >  float total=0;
49 >  float wz=0;
50 >  cout << "Numbers with variable " << variable << " and cut " << cut << ": " << endl;
51 >  TIter nextSF = TIter(stack.GetHists());
52    TH1F *h;
53 +  stringstream spurity;
54 +  int bracecounter=0;
55 +
56 +
57    while ( h = (TH1F*)nextSF() ) {
58 <    cout << h->GetName() << " : " << h->Integral() << endl;
58 >    cout << IdentifierForUnderlinedEntry(h->GetName()) << " : " << h->Integral() << endl;
59 >    if(IdentifierForUnderlinedEntry(h->GetName())=="WZ") {
60 >      wz+=h->Integral();
61 >      total+=h->Integral();
62 >    } else {
63 >      if(IdentifierForUnderlinedEntry(h->GetName())!="Data") total+=h->Integral();
64 >    }
65 >    bracecounter++;
66 >    spurity << "#splitline{" << IdentifierForUnderlinedEntry(h->GetName()) << " : " << h->Integral() << "}{";
67    }
63  cout << "DATA : " << d_zmass->Integral() << endl;
64
65  TPad *pad2 = new TPad("pad","pad",0,0,1,1);
66  pad2->cd();
68    
69 <  THStack m_met = allsamples.DrawStack("m_met","met[4]",40,0,400, "raw PFMET [GeV]", "events", ZmassWindow&&BasicCut,mc, luminosity);
70 <  TH1F *d_met = allsamples.Draw("d_met","met[4]",40,0,400, "raw PFMET [GeV]", "events", ZmassWindow&&BasicCut,data, luminosity);
69 >  spurity << "#splitline{Purity: " << wz/total << "}{Nevents: " << total << "}";
70 >  for(int i=0;i<bracecounter;i++) spurity << "}";
71 >  
72 >  TPaveText *PurityPaveText = new TPaveText(0.60, 0.40,0.89, 0.6,"blNDC");
73 >  PurityPaveText->SetFillStyle(4000);
74 >  PurityPaveText->SetBorderSize(0);
75 >  PurityPaveText->SetFillColor(kWhite);
76 >  PurityPaveText->SetTextFont(42);
77 >  PurityPaveText->SetTextSize(0.021);
78 >  PurityPaveText->AddText(spurity.str().c_str());
79 >  PurityPaveText->Draw();
80 >
81 >  
82 > //  TText *purity = new TText(0.8,0.6,spurity.str().c_str());
83 > //  purity->Draw();
84 >  cout << "DATA : " << hdata->Integral() << endl;
85    
86 <  cout << "And with MET , using a 10 GeV window around the Z mass : " << endl;
87 <  nextSF = TIter(m_met.GetHists());
86 >  save_with_ratio(hdata,stack,pad->cd(),"WZ_study/"+saveas);
87 >  delete hdata;
88 >  delete can;
89 > }
90 >
91 > void write_report(TCut BasicCut, TCut cut, ofstream &report) {
92 >  THStack stack = allsamples.DrawStack("stack","tri_mll",10,0,1000,"m_{ll}", "events", BasicCut&&cut,mc, luminosity);
93 >  float total=0;
94 >  float wz=0;
95 >  TIter nextSF = TIter(stack.GetHists());
96 >  TH1F *h;
97    while ( h = (TH1F*)nextSF() ) {
98 <    cout << h->GetName() << " : " << h->Integral() << endl;
98 >    cout << IdentifierForUnderlinedEntry(h->GetName()) << " : " << h->Integral() << endl;
99 >    if(IdentifierForUnderlinedEntry(h->GetName())=="WZ") {
100 >      wz+=h->Integral();
101 >      total+=h->Integral();
102 >    } else {
103 >      if(IdentifierForUnderlinedEntry(h->GetName())!="Data") total+=h->Integral();
104 >    }
105 >    report << h->Integral() << ";";
106 >  }
107 >  report << wz/total << ";\n";
108 >  report << flush;
109 >
110 > }
111 >
112 > vector<string> producecuts(string variablename, float cut1, float cut2, float cut3, float cut4, float cut5, float cut6 ) {
113 >  float allcuts[6] = {cut1,cut2,cut3,cut4,cut5,cut5};
114 >  vector<string> cuts;
115 >  for(int i = 0; i < 6; ++i ) {
116 >    if(allcuts[i]<0) continue;
117 >    stringstream nowcut;
118 >    nowcut << variablename << allcuts[i];
119 >    cuts.push_back(nowcut.str());
120    }
121 <  cout << "DATA : " << d_met->Integral() << endl;
121 >  return cuts;
122 > }
123 >    
124 >
125 > void OptimizeSelection(TCut BasicCut) {
126 >  ofstream report;
127 >  report.open ("report3.txt");
128 >  
129 >  vector<string> mt   = producecuts("tri_mT>",0,10,20,30,40,50);
130 >  vector<string> et   = producecuts("met[4]>",0,10,20,30,40,50);
131 >  vector<string> mll  = producecuts("abs(tri_mll-91.2)<",10000,10,20,-1,-1,-1);
132 >  vector<string> mlll = producecuts("abs(tri_mlll-91)>",0,10,20,30,40,50);
133 >  
134 >  for(int imt=0;imt<mt.size();imt++) {
135 >    for(int iet=0;iet<et.size();iet++) {
136 >      for(int imll=0;imll<mll.size();imll++) {
137 >        for(int imlll=0;imlll<mlll.size();imlll++) {
138 >          stringstream cut;
139 >          cut << mt[imt] << " && " << et[iet] << " && " << mll[imll] << " && " << mlll[imlll];
140 >          report << mt[imt] << ";" << et[iet] << ";" << mll[imll] << ";" << mlll[imlll] <<";";
141 > //        cout << "Cut is : " << cut.str() << endl;
142 >          write_report(BasicCut, TCut(cut.str().c_str()),report);
143 >        }
144 >      }
145 >    }
146 >  }
147 >  report.close();
148 > }
149 >
150 > void CarryOutWZStudy() {
151 >  TCut BasicCut("leptonNum>2&&tri_pt1>30&&tri_pt2>20&&tri_pt3>20");
152 >  TCut Selection("abs(tri_mlll-91)>30 && tri_mT>40 && met[4] > 30 && abs(tri_mll-91)<10");
153 >  
154 > //  OptimizeSelection(BasicCut);
155 >  /*
156 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut,"Inclusive/Zmass");
157 >  WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut,"Inclusive/TrileptonMass");
158 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut,"Inclusive/mT");
159 >  WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut,"Inclusive/MET");
160 >  WZ_kin_plot("tri_pt1",40,0,400,"p_{T}^{1} [GeV]",BasicCut,"Inclusive/Pt1");
161 >  WZ_kin_plot("tri_pt2",40,0,400,"p_{T}^{2} [GeV]",BasicCut,"Inclusive/Pt2");
162 >  WZ_kin_plot("tri_pt3",40,0,400,"p_{T}^{3} [GeV]",BasicCut,"Inclusive/Pt3");
163 >
164 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/Zmass");
165 >  WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/TrileptonMass");
166 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/mT");
167 >  WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/MET");
168 >  
169 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/Zmass");
170 >  WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/TrileptonMass");
171 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/mT");
172 >  WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/MET");
173 >
174 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut,"CutFlow/Zmass__0_CutOnNothing");
175 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/Zmass__1_CutOn_MT");
176 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30"),"CutFlow/Zmass__2_CutOn_MT_n_Mll");
177 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30"),"CutFlow/Zmass__3_CutOn_MT_n_Mll_n_Met");
178 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30&&abs(tri_mll-91)<10"),"CutFlow/Zmass__4_CutOn_MT_n_Mll_n_Met_MllWindow");
179 >  
180 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut,"CutFlow/MT__0_CutOnNothing");
181 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/MT__1_CutOn_MT");
182 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30"),"CutFlow/MT__2_CutOn_MT_n_Mll");
183 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30"),"CutFlow/MT__3_CutOn_MT_n_Mll_n_Met");
184 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30&&abs(tri_mll-91)<10"),"CutFlow/MT__4_CutOn_MT_n_Mll_n_Met_MllWindow");
185 >  
186 >  WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut,"CutFlow/MET__0_CutOnNothing");
187 >  WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/MET__1_CutOn_MT");
188 >  WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30"),"CutFlow/MET__2_CutOn_MT_n_Mll");
189 >  WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30"),"CutFlow/MET__3_CutOn_MT_n_Mll_n_Met");
190 >  WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30&&abs(tri_mll-91)<10"),"CutFlow/MET__4_CutOn_MT_n_Mll_n_Met_MllWindow");
191 >
192 >  
193 >  WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&Selection,"Zmass");
194 >  WZ_kin_plot("tri_mlll",40,0,400,"m_{lll} [GeV]",BasicCut&&Selection,"TrileptonMass");
195 >  WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&Selection,"mT");
196 >  WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&Selection,"MET");
197 >  WZ_kin_plot("tri_pt1",40,0,400,"p_{T}^{1} [GeV]",BasicCut&&Selection,"Pt1");
198 >  WZ_kin_plot("tri_pt2",40,0,400,"p_{T}^{2} [GeV]",BasicCut&&Selection,"Pt2");
199 >  WZ_kin_plot("tri_pt3",40,0,400,"p_{T}^{3} [GeV]",BasicCut&&Selection,"Pt3");
200 >  
201 >
202 >  TCut SF("tri_id1==tri_id2");
203 >  TCut OF("tri_id1!=tri_id2");
204 >  
205 >  TH1F *sfdata = allsamples.Draw("sfdata","tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&SF,data, luminosity);
206 >  TH1F *ofdata = allsamples.Draw("ofdata","tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&OF,data, luminosity);
207 >  
208 >  // all MC samples
209 >  TH1F *sfmc   = allsamples.Draw("sfmc"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&SF,mc  , luminosity);
210 >  TH1F *ofmc   = allsamples.Draw("ofmc"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&OF,mc  , luminosity);
211 >  
212 >  // WZ only
213 >  TH1F *sfwz   = allsamples.Draw("sfwz"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&SF,mc  , luminosity,allsamples.FindSample("WZJetsTo3"));
214 >  TH1F *ofwz   = allsamples.Draw("ofwz"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&OF,mc  , luminosity,allsamples.FindSample("WZJetsTo3"));
215 >  
216 >  dout << "SF events: " << sfdata->Integral() << "   (mc : " << sfmc->Integral() << " , wz : " << sfwz->Integral() << " )   WZ purity: " << 100*sfwz->Integral()/sfmc->Integral() << " %" << endl;
217 >  dout << "OF events: " << ofdata->Integral() << "   (mc : " << ofmc->Integral() << " , wz : " << ofwz->Integral() << " )   WZ purity: " << 100*ofwz->Integral()/ofmc->Integral() << " %" << endl;
218 >  
219 >  dout << "RATIO : SF / OF = " << sfdata->Integral() / ofdata->Integral() << " +/- " << (sfdata->Integral()/ofdata->Integral()) * TMath::Sqrt(1/sfdata->Integral()+1/ofdata->Integral()) << " (stat) " << endl;
220 >  */
221    
222    
223    
80  d_met->Draw("e1");
81  m_met.Draw("same");
82  d_met->Draw("e1,same");
83  kinleg->Draw();
84  DrawPrelim();
85  save_with_ratio(d_met,m_met,pad2->cd(),"WZ_study/MET");
224    
87
88  delete can;
225   }
226  
227   void WZstudy() {
# Line 95 | Line 231 | void WZstudy() {
231    cout << "Going to set essential cut to new triggers" << endl;
232    TCut essential_bkp = essentialcut;
233    write_warning(__FUNCTION__,"Need to define trigger requirement for WZ!");
234 <  essentialcut=TCut("");
234 >  essentialcut=TCut("mll>5||mll<6");
235    cout << "Essential cut is now " << (const char*) essentialcut << endl;
236    
237    CarryOutWZStudy();
# Line 106 | Line 242 | void WZstudy() {
242    cout << "Essential cut is now " << (const char*) essentialcut << "   (restored)" << endl;
243    switch_overunderflow(false);
244   }
245 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines