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

Comparing UserCode/cbrown/AnalysisFramework/Plotting/Modules/LimitCalculation.C (file contents):
Revision 1.2 by buchmann, Tue Jul 19 15:04:16 2011 UTC vs.
Revision 1.10 by buchmann, Wed Aug 17 14:24:51 2011 UTC

# Line 1 | Line 1
1   #include <iostream>
2   #include <vector>
3   #include <sys/stat.h>
4 + #include <fstream>
5  
6   #include <TCut.h>
7   #include <TROOT.h>
# Line 22 | Line 23 | using namespace PlottingSetup;
23  
24  
25   void rediscover_the_top(string mcjzb, string datajzb) {
26 <  cout << "Hi! today we are going to (try to) rediscover the top!" << endl;
26 >  dout << "Hi! today we are going to (try to) rediscover the top!" << endl;
27    TCanvas *c3 = new TCanvas("c3","c3");
28    c3->SetLogy(1);
29    vector<float> binning;
# Line 62 | Line 63 | void rediscover_the_top(string mcjzb, st
63    TH1F *datapredictiont = allsamples.Draw("datapredictiont",    "-"+datajzb, nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,  luminosity);
64    TH1F *datapredictiono = allsamples.Draw("datapredictiono",    "-"+datajzb, nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,  luminosity);
65    datapredictiont->Add(datapredictiono,-1);
66 <  cout << "Second way of doing this !!!! Analytical shape to the left :-D" << endl;
66 >  dout << "Second way of doing this !!!! Analytical shape to the left :-D" << endl;
67    vector<TF1*> functions = do_cb_fit_to_plot(datapredictiont,10);
68    datapredictiont->SetMarkerColor(kRed);
69    datapredictiont->SetLineColor(kRed);
# Line 141 | Line 142 | ratio_binning.push_back(80);
142    ratio->Divide(datapredictiontb);
143    
144    for (int i=0;i<=ratio_binning.size();i++) {
145 <    cout << observedtb->GetBinLowEdge(i+1) << ";"<<observedtb->GetBinContent(i+1) << ";" << datapredictiontb->GetBinContent(i+1) << " --> " << ratio->GetBinContent(i+1) << "+/-" << ratio->GetBinError(i+1) << endl;
145 >    dout << observedtb->GetBinLowEdge(i+1) << ";"<<observedtb->GetBinContent(i+1) << ";" << datapredictiontb->GetBinContent(i+1) << " --> " << ratio->GetBinContent(i+1) << "+/-" << ratio->GetBinError(i+1) << endl;
146    }
147    
148   //  ratio->Divide(datapredictiontb);
# Line 167 | Line 168 | ratio_binning.push_back(80);
168    
169   }
170  
170 void calculate_upper_limits(string mcjzb, string datajzb) {
171  write_warning("calculate_upper_limits","Upper limit calculation temporarily deactivated");
172 //  write_warning("calculate_upper_limits","Calculation of SUSY upper limits has been temporarily suspended in favor of top discovery");
173 //  rediscover_the_top(mcjzb,datajzb);
174 /*  
175  TCanvas *c3 = new TCanvas("c3","c3");
176  c3->SetLogy(1);
177  vector<float> binning;
178  //binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
179  binning.push_back(50);
180  binning.push_back(100);
181  binning.push_back(150);
182  binning.push_back(200);
183  binning.push_back(500);
184  TH1F *datapredictiona = allsamples.Draw("datapredictiona",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity);
185  TH1F *datapredictionb = allsamples.Draw("datapredictionb",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
186  TH1F *datapredictionc = allsamples.Draw("datapredictionc",    datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
187  TH1F *dataprediction = (TH1F*)datapredictiona->Clone();
188  dataprediction->Add(datapredictionb,-1);
189  dataprediction->Add(datapredictionc);
190  TH1F *puresignal     = allsamples.Draw("puresignal",        mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
191  TH1F *signalpred     = allsamples.Draw("signalpred",    "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
192  TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
193  TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
194  TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
195  signalpred->Add(signalpredlo,-1);
196  signalpred->Add(signalpredro);
197  puresignal->Add(signalpred,-1);//subtracting signal contamination
198  ofstream myfile;
199  myfile.open ("ShapeFit_log.txt");
200  establish_upper_limits(puredata,dataprediction,puresignal,"LM4",myfile);
201  myfile.close();
202 */
203 }
204
171   vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, bool doobserved=false) {
172    float sigma95=0.0,sigma95A=0.0;
173 <  cout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << 1<< ") " << endl;
174 <  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, 1);
173 >  int nuisancemodel=1;
174 >  dout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
175 >  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
176    if(doobserved) {
177 <    cout << "Now calling : CL95A(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << 1<< ") " << endl;
178 <    sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], 1);
177 >    dout << "Now calling : CLA(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << nuisancemodel<< ") " << endl;
178 >    sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], nuisancemodel);
179    }
180    vector<float> sigmas;
181    sigmas.push_back(sigma95);
# Line 217 | Line 184 | vector<float> compute_one_upper_limit(fl
184   }
185  
186   void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doobserved) {
187 <  cout << "Doing counting experiment ... " << endl;
187 >  dout << "Doing counting experiment ... " << endl;
188    vector<vector<string> > limits;
189    vector<vector<float> > vlimits;
190    
# Line 225 | Line 192 | void compute_upper_limits_from_counting_
192    for(int isample=0;isample<signalsamples.collection.size();isample++) {
193      vector<string> rows;
194      vector<float> vrows;
195 <    cout << "Considering sample " << signalsamples.collection[isample].samplename << endl;
195 >    dout << "Considering sample " << signalsamples.collection[isample].samplename << endl;
196      rows.push_back(signalsamples.collection[isample].samplename);
197      for(int ibin=0;ibin<jzbcuts.size();ibin++) {
198 <      cout << "_________________________________________________________________________________" << endl;
198 >      dout << "_________________________________________________________________________________" << endl;
199        float JZBcutat=uncertainties[isample*jzbcuts.size()+ibin][0];
200        float mceff=uncertainties[isample*jzbcuts.size()+ibin][1];
201        float staterr=uncertainties[isample*jzbcuts.size()+ibin][2];
202        float systerr=uncertainties[isample*jzbcuts.size()+ibin][3];
203        float toterr =uncertainties[isample*jzbcuts.size()+ibin][4];
204 <      float observed,null,result;
205 <      fill_result_histos(observed, null,null,null,null,null,null,null,mcjzb,JZBcutat,(int)5,result,(signalsamples.FindSample(signalsamples.collection[isample].filename)),signalsamples);
204 >      float observed,observederr,null,result;
205 >      fill_result_histos(observed,observederr, null,null,null,null,null,null,null,mcjzb,JZBcutat,14000,(int)5,result,(signalsamples.FindSample(signalsamples.collection[isample].filename)),signalsamples);
206        observed-=result;//this is the actual excess we see!
207        float expected=observed/luminosity;
208        
209 <      cout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl;
209 >      dout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl;
210        vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,doobserved);
211        
212        if(doobserved) {
# Line 257 | Line 224 | void compute_upper_limits_from_counting_
224      limits.push_back(rows);
225      vlimits.push_back(vrows);
226    }//end of sample loop
227 <  cout << endl << endl << "PAS table 3: " << endl << endl;
228 <  cout << "\t";
227 >  dout << endl << endl << "PAS table 3: " << endl << endl;
228 >  dout << "\t";
229    for (int irow=0;irow<jzbcuts.size();irow++) {
230 <    cout << jzbcuts[irow] << "\t";
230 >    dout << jzbcuts[irow] << "\t";
231    }
232 <  cout << endl;
232 >  dout << endl;
233    for(int irow=0;irow<limits.size();irow++) {
234      for(int ientry=0;ientry<limits[irow].size();ientry++) {
235 <      cout << limits[irow][ientry] << "\t";
235 >      dout << limits[irow][ientry] << "\t";
236      }
237 <    cout << endl;
237 >    dout << endl;
238    }
239    
240    if(!doobserved) {
241 <    cout << endl << endl << "LIMITS: " << endl;
242 <    cout << "\t";
241 >    dout << endl << endl << "LIMITS: " << endl;
242 >    dout << "\t";
243      for (int irow=0;irow<jzbcuts.size();irow++) {
244 <      cout << jzbcuts[irow] << "\t";
244 >      dout << jzbcuts[irow] << "\t";
245      }
246 <    cout << endl;
246 >    dout << endl;
247      for(int irow=0;irow<limits.size();irow++) {
248 <      cout << limits[irow][0] << "\t";
248 >      dout << limits[irow][0] << "\t";
249        for(int ientry=0;ientry<jzbcuts.size();ientry++) {
250 <        cout << Round(vlimits[irow][2*ientry] / vlimits[irow][2*ientry+1],3)<< "\t";
250 >        dout << Round(vlimits[irow][2*ientry] / vlimits[irow][2*ientry+1],3)<< "\t";
251        }
252 <      cout << endl;
252 >      dout << endl;
253      }
254    }//do observed
255 +  
256 +  dout << endl << endl << "Final selection efficiencies with total statistical and systematic errors, and corresponding observed and expected upper limits (UL) on ($\\sigma\\times$  BR $\\times$ acceptance) for the LM4 and LM8 scenarios, in the different regions. The last column contains the predicted ($\\sigma \\times $BR$\\times$ acceptance) at NLO obtained from Monte Carlo simulation." << endl;
257 +  dout << "Scenario \t Efficiency [%] \t Upper limits [pb] \t Prediction [pb]" << endl;
258 +  for(int icut=0;icut<jzbcuts.size();icut++) {
259 +    dout << "Region with JZB>" << jzbcuts[icut] << endl;
260 +    for(int isample=0;isample<signalsamples.collection.size();isample++) {
261 +      dout << limits[isample][0] << "\t" << Round(100*uncertainties[isample*jzbcuts.size()+icut][1],1) << "+/-" << Round(100*uncertainties[isample*jzbcuts.size()+icut][2],1) << " (stat) +/- " << Round(100*uncertainties[isample*jzbcuts.size()+icut][3],1) << " (syst) \t" << Round((vlimits[isample][2*icut]),3) << "\t" << Round(vlimits[isample][2*icut+1],3) << endl;
262 +    }
263 +    dout << endl;
264 +  }
265 +  
266 +  write_warning("compute_upper_limits_from_counting_experiment","Still need to update the script");
267   }
268  
290 void susy_scan_axis_labeling(TH2F *histo) {
291  histo->GetXaxis()->SetTitle("#Chi_{2}^{0}-LSP");
292  histo->GetXaxis()->CenterTitle();
293  histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
294  histo->GetYaxis()->CenterTitle();
295 }
269  
270 < void scan_susy_space(string mcjzb, string datajzb) {
271 <  TCanvas *c3 = new TCanvas("c3","c3");
272 <  vector<float> binning;
273 <  binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
274 <  float arrbinning[binning.size()];
275 <  for(int i=0;i<binning.size();i++) arrbinning[i]=binning[i];
276 <  TH1F *puredata   = allsamples.Draw("puredata",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
277 <  puredata->SetMarkerSize(DataMarkerSize);
278 <  TH1F *allbgs   = allsamples.Draw("allbgs",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
279 <  TH1F *allbgsb   = allsamples.Draw("allbgsb",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
280 <  TH1F *allbgsc   = allsamples.Draw("allbgsc",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
281 <  allbgs->Add(allbgsb,-1);
282 <  allbgs->Add(allbgsc);
283 <  int ndata=puredata->Integral();
284 <  ofstream myfile;
285 <  myfile.open ("susyscan_log.txt");
286 <  TFile *susyscanfile = new TFile("/scratch/fronga/SMS/T5z_SqSqToQZQZ_38xFall10.root");
287 <  TTree *suevents = (TTree*)susyscanfile->Get("events");
288 <  TH2F *exclusionmap = new TH2F("exclusionmap","",20,0,500,20,0,1000);
289 <  TH2F *exclusionmap1s = new TH2F("exclusionmap1s","",20,0,500,20,0,1000);
290 <  TH2F *exclusionmap2s = new TH2F("exclusionmap2s","",20,0,500,20,0,1000);
291 <  TH2F *exclusionmap3s = new TH2F("exclusionmap3s","",20,0,500,20,0,1000);
292 <  
293 <  susy_scan_axis_labeling(exclusionmap);
294 <  susy_scan_axis_labeling(exclusionmap1s);
295 <  susy_scan_axis_labeling(exclusionmap2s);
296 <  susy_scan_axis_labeling(exclusionmap3s);
297 <  
298 <  Int_t MyPalette[100];
299 <  Double_t r[]    = {0., 0.0, 1.0, 1.0, 1.0};
300 <  Double_t g[]    = {0., 0.0, 0.0, 1.0, 1.0};
301 <  Double_t b[]    = {0., 1.0, 0.0, 0.0, 1.0};
302 <  Double_t stop[] = {0., .25, .50, .75, 1.0};
303 <  Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 100);
304 <  for (int i=0;i<100;i++) MyPalette[i] = FI+i;
305 <  
306 <  gStyle->SetPalette(100, MyPalette);
307 <  
308 <  for(int m23=50;m23<500;m23+=25) {
309 <    for (int m0=(2*(m23-50)+150);m0<=1000;m0+=50)
310 <    {
311 <      c3->cd();
312 <      stringstream drawcondition;
313 <      drawcondition << "pfJetGoodNum>=3&&(TMath::Abs(masses[0]-"<<m0<<")<10&&TMath::Abs(masses[2]-masses[3]-"<<m23<<")<10)&&mll>5&&id1==id2";
314 <      TH1F *puresignal = new TH1F("puresignal","puresignal",binning.size()-1,arrbinning);
315 <      TH1F *puresignall= new TH1F("puresignall","puresignal",binning.size()-1,arrbinning);
316 <      stringstream drawvar,drawvar2;
317 <      drawvar<<mcjzb<<">>puresignal";
318 <      drawvar2<<"-"<<mcjzb<<">>puresignall";
319 <      suevents->Draw(drawvar.str().c_str(),drawcondition.str().c_str());
320 <      suevents->Draw(drawvar2.str().c_str(),drawcondition.str().c_str());
321 <      if(puresignal->Integral()<60) {
322 <        delete puresignal;
323 <        continue;
324 <      }
325 <      puresignal->Add(puresignall,-1);//we need to correct for the signal contamination - we effectively only see (JZB>0)-(JZB<0) !!
326 <      puresignal->Scale(ndata/(20*puresignal->Integral()));//normalizing it to 5% of the data
327 <      stringstream saveas;
328 <      saveas<<"Model_Scan/m0_"<<m0<<"__m23_"<<m23;
329 <      cout << "PLEASE KEEP IN MIND THAT SIGNAL CONTAMINATION IS NOT REALLY TAKEN CARE OF YET DUE TO LOW STATISTICS! SHOULD BE SOMETHING LIKE THIS : "<< endl;
330 < //        TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
331 < //        TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
332 < //        TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
333 < //        signalpred->Add(signalpredlo,-1);
334 < //        signalpred->Add(signalpredro);
335 < //        puresignal->Add(signalpred,-1);//subtracting signal contamination
336 < //---------------------
337 < //      cout << "(m0,m23)=("<<m0<<","<<m23<<") contains " << puresignal->Integral() << endl;
338 < //    TH1F *puresignal = allsamples.Draw("puresignal",mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
339 <      vector<float> results=establish_upper_limits(puredata,allbgs,puresignal,saveas.str(),myfile);  
340 <      if(results.size()==0) {
341 <        delete puresignal;
369 <        continue;
370 <      }
371 <      exclusionmap->Fill(m23,m0,results[0]);
372 <      exclusionmap1s->Fill(m23,m0,results[1]);
373 <      exclusionmap2s->Fill(m23,m0,results[2]);
374 <      exclusionmap3s->Fill(m23,m0,results[3]);
375 <      delete puresignal;
376 <      cout << "(m0,m23)=("<<m0<<","<<m23<<") : 3 sigma at " << results[3] << endl;
377 <    }
378 <  }//end of model scan for loop
379 <  
380 <  cout << "Exclusion Map contains" << exclusionmap->Integral() << " (integral) and entries: " << exclusionmap->GetEntries() << endl;
381 <  c3->cd();
382 <  exclusionmap->Draw("CONTZ");
383 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_Mean_values");
384 <  exclusionmap->Draw("COLZ");
385 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_Mean_values");
386 <  
387 <  exclusionmap1s->Draw("CONTZ");
388 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_1sigma_values");
389 <  exclusionmap1s->Draw("COLZ");
390 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_1sigma_values");
391 <  
392 <  exclusionmap2s->Draw("CONTZ");
393 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_2sigma_values");
394 <  exclusionmap2s->Draw("COLZ");
395 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_2sigma_values");
396 <  
397 <  exclusionmap3s->Draw("CONTZ");
398 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_3sigma_values");
399 <  exclusionmap3s->Draw("COLZ");
400 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_3sigma_values");
401 <  
402 <  TFile *exclusion_limits = new TFile("exclusion_limits.root","RECREATE");
403 <  exclusionmap->Write();
404 <  exclusionmap1s->Write();
405 <  exclusionmap2s->Write();
406 <  exclusionmap3s->Write();
407 <  exclusion_limits->Close();
408 <  susyscanfile->Close();
270 >
271 > /********************************************************************** new : Limits using SHAPES ***********************************
272 >
273 >
274 >   SSSSSSSSSSSSSSS hhhhhhh                                                                                      
275 > SS:::::::::::::::Sh:::::h                                                                                      
276 > S:::::SSSSSS::::::Sh:::::h                                                                                      
277 > S:::::S     SSSSSSSh:::::h                                                                                      
278 > S:::::S             h::::h hhhhh         aaaaaaaaaaaaa  ppppp   ppppppppp       eeeeeeeeeeee        ssssssssss  
279 > S:::::S             h::::hh:::::hhh      a::::::::::::a p::::ppp:::::::::p    ee::::::::::::ee    ss::::::::::s  
280 > S::::SSSS          h::::::::::::::hh    aaaaaaaaa:::::ap:::::::::::::::::p  e::::::eeeee:::::eess:::::::::::::s
281 >  SS::::::SSSSS     h:::::::hhh::::::h            a::::app::::::ppppp::::::pe::::::e     e:::::es::::::ssss:::::s
282 >    SSS::::::::SS   h::::::h   h::::::h    aaaaaaa:::::a p:::::p     p:::::pe:::::::eeeee::::::e s:::::s  ssssss
283 >       SSSSSS::::S  h:::::h     h:::::h  aa::::::::::::a p:::::p     p:::::pe:::::::::::::::::e    s::::::s      
284 >            S:::::S h:::::h     h:::::h a::::aaaa::::::a p:::::p     p:::::pe::::::eeeeeeeeeee        s::::::s  
285 >            S:::::S h:::::h     h:::::ha::::a    a:::::a p:::::p    p::::::pe:::::::e           ssssss   s:::::s
286 > SSSSSSS     S:::::S h:::::h     h:::::ha::::a    a:::::a p:::::ppppp:::::::pe::::::::e          s:::::ssss::::::s
287 > S::::::SSSSSS:::::S h:::::h     h:::::ha:::::aaaa::::::a p::::::::::::::::p  e::::::::eeeeeeee  s::::::::::::::s
288 > S:::::::::::::::SS  h:::::h     h:::::h a::::::::::aa:::ap::::::::::::::pp    ee:::::::::::::e   s:::::::::::ss  
289 > SSSSSSSSSSSSSSS    hhhhhhh     hhhhhhh  aaaaaaaaaa  aaaap::::::pppppppp        eeeeeeeeeeeeee    sssssssssss    
290 >                                                         p:::::p                                                
291 >                                                         p:::::p                                                
292 >                                                        p:::::::p                                                
293 >                                                        p:::::::p                                                
294 >                                                        p:::::::p                                                
295 >                                                        ppppppppp                                                
296 >                                                                                                                
297 >
298 > *********************************************************************** new : Limits using SHAPES ***********************************/
299 >
300 >
301 > void limit_shapes_for_systematic_effect(TFile *limfile, string identifier, string mcjzb, string datajzb, int JES,vector<float> binning, TCanvas *limcan) {
302 >  dout << "Creatig shape templates ... ";
303 >  if(identifier!="") dout << "for systematic called "<<identifier;
304 >  dout << endl;
305 >  int dataormc=mcwithsignal;//this is only for tests - for real life you want dataormc=data !!!
306 >  if(dataormc!=data) write_warning(__FUNCTION__,"WATCH OUT! Not using data for limits!!!! this is ok for tests, but not ok for anything official!");
307 >  
308 >  TCut limitnJetcut;
309 >  if(JES==noJES) limitnJetcut=cutnJets;
310 >  else {
311 >    if(JES==JESdown) limitnJetcut=cutnJetsJESdown;
312 >    if(JES==JESup) limitnJetcut=cutnJetsJESup;
313 >  }
314 >  TH1F *ZOSSFP = allsamples.Draw("ZOSSFP",datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
315 >  TH1F *ZOSOFP = allsamples.Draw("ZOSOFP",datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
316 >  TH1F *ZOSSFN = allsamples.Draw("ZOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
317 >  TH1F *ZOSOFN = allsamples.Draw("ZOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
318 >  
319 >  TH1F *SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
320 >  TH1F *SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
321 >  TH1F *SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
322 >  TH1F *SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
323 >  
324 >  TH1F *LZOSSFP = allsamples.Draw("LZOSSFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
325 >  TH1F *LZOSOFP = allsamples.Draw("LZOSOFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
326 >  TH1F *LZOSSFN = allsamples.Draw("LZOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
327 >  TH1F *LZOSOFN = allsamples.Draw("LZOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
328 >  
329 >  TH1F *LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
330 >  TH1F *LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
331 >  TH1F *LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
332 >  TH1F *LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
333 >  
334 >  string obsname="data_obs";
335 >  string predname="background";
336 >  string signalname="signal";
337 >  if(identifier!="") {
338 >    obsname=("data_"+identifier);
339 >    predname=("background_"+identifier);
340 >    signalname="signal_"+identifier;
341 >  }
342    
343 <  myfile.close();
343 >  TH1F *obs = (TH1F*)ZOSSFP->Clone();
344 >  obs->SetName(obsname.c_str());
345 >  obs->Write();
346 >  TH1F *pred = (TH1F*)ZOSSFN->Clone();
347 >  pred->Add(ZOSOFP,1.0/3);
348 >  pred->Add(ZOSOFN,-1.0/3);
349 >  pred->Add(SBOSSFP,1.0/3);
350 >  pred->Add(SBOSSFN,-1.0/3);
351 >  pred->Add(SBOSOFP,1.0/3);
352 >  pred->Add(SBOSOFN,-1.0/3);
353 >  pred->SetName(predname.c_str());
354 >  pred->Write();
355 >  
356 > //  TH1F *Lobs = (TH1F*)LZOSSFP->Clone();
357 > //  TH1F *Lpred = (TH1F*)LZOSSFN->Clone();
358 >  
359 >  TH1F *Lobs = new TH1F("Lobs","Lobs",binning.size()-1,&binning[0]);
360 >  TH1F *Lpred = new TH1F("Lpred","Lpred",binning.size()-1,&binning[0]);
361 >  Lobs->Add(LZOSSFP);
362 >  Lpred->Add(LZOSSFN);
363 >  Lpred->Add(LZOSOFP,1.0/3);
364 >  Lpred->Add(LZOSOFN,-1.0/3);
365 >  Lpred->Add(LSBOSSFP,1.0/3);
366 >  Lpred->Add(LSBOSSFN,-1.0/3);
367 >  Lpred->Add(LSBOSOFP,1.0/3);
368 >  Lpred->Add(LSBOSOFN,-1.0/3);
369 >  TH1F *signal = (TH1F*)Lobs->Clone();
370 >  signal->Add(Lpred,-1);
371 >  signal->SetName(signalname.c_str());
372 >  signal->Write();
373 >  
374 >  delete Lobs;
375 >  delete Lpred;
376 >  
377 >  delete ZOSSFP;
378 >  delete ZOSOFP;
379 >  delete ZOSSFN;
380 >  delete ZOSOFN;
381 >  
382 >  delete SBOSSFP;
383 >  delete SBOSOFP;
384 >  delete SBOSSFN;
385 >  delete SBOSOFN;
386 >  
387 >  delete LZOSSFP;
388 >  delete LZOSOFP;
389 >  delete LZOSSFN;
390 >  delete LZOSOFN;
391 >  
392 >  delete LSBOSSFP;
393 >  delete LSBOSOFP;
394 >  delete LSBOSSFN;
395 >  delete LSBOSOFN;
396 >
397   }
398  
399 + void prepare_datacard(TFile *f) {
400 + TH1F *dataob = (TH1F*)f->Get("data_obs");
401 + TH1F *signal = (TH1F*)f->Get("signal");
402 + TH1F *background = (TH1F*)f->Get("background");
403 +
404 + ofstream datacard;
405 + ensure_directory_exists(get_directory()+"/limits");
406 + datacard.open ((get_directory()+"/limits/susydatacard.txt").c_str());
407 + datacard << "Writing this to a file.\n";
408 + datacard << "imax 1\n";
409 + datacard << "jmax 1\n";
410 + datacard << "kmax *\n";
411 + datacard << "---------------\n";
412 + datacard << "shapes * * limitfile.root $PROCESS $PROCESS_$SYSTEMATIC\n";
413 + datacard << "---------------\n";
414 + datacard << "bin 1\n";
415 + datacard << "observation "<<dataob->Integral()<<"\n";
416 + datacard << "------------------------------\n";
417 + datacard << "bin             1          1\n";
418 + datacard << "process         signal     background\n";
419 + datacard << "process         0          1\n";
420 + datacard << "rate            "<<signal->Integral()<<"         "<<background->Integral()<<"\n";
421 + datacard << "--------------------------------\n";
422 + datacard << "lumi     lnN    1.10       1.0\n";
423 + datacard << "bgnorm   lnN    1.00       1.4  uncertainty on our prediction (40%)\n";
424 + datacard << "JES    shape    1          1    uncertainty on background shape and normalization\n";
425 + datacard << "peak   shape    1          1    uncertainty on signal resolution. Assume the histogram is a 2 sigma shift, \n";
426 + datacard << "#                                so divide the unit gaussian by 2 before doing the interpolation\n";
427 + datacard.close();
428 + }
429  
430  
431 <
431 > void prepare_limits(string mcjzb, string datajzb, float jzbpeakerrordata, float jzbpeakerrormc, vector<float> jzbbins) {
432 >  ensure_directory_exists(get_directory()+"/limits");
433 >  TFile *limfile = new TFile((get_directory()+"/limits/limitfile.root").c_str(),"RECREATE");
434 >  TCanvas *limcan = new TCanvas("limcan","Canvas for calculating limits");
435 >  limit_shapes_for_systematic_effect(limfile,"",mcjzb,datajzb,noJES,jzbbins,limcan);
436 >  limit_shapes_for_systematic_effect(limfile,"peakUp",newjzbexpression(mcjzb,jzbpeakerrormc),newjzbexpression(datajzb,jzbpeakerrordata),noJES,jzbbins,limcan);
437 >  limit_shapes_for_systematic_effect(limfile,"peakDown",newjzbexpression(mcjzb,-jzbpeakerrormc),newjzbexpression(datajzb,-jzbpeakerrordata),noJES,jzbbins,limcan);
438 >  limit_shapes_for_systematic_effect(limfile,"JESUp",mcjzb,datajzb,JESup,jzbbins,limcan);
439 >  limit_shapes_for_systematic_effect(limfile,"JESDown",mcjzb,datajzb,JESdown,jzbbins,limcan);
440 >  
441 >  prepare_datacard(limfile);
442 >  limfile->Close();
443 >  write_info("prepare_limits","limitfile.root and datacard.txt have been generated. You can now use them to calculate limits!");
444 >  
445 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines