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.1 by buchmann, Tue Jul 19 08:15:45 2011 UTC vs.
Revision 1.30 by buchmann, Wed Nov 16 14:50:33 2011 UTC

# Line 1 | Line 1
1 + /****
2 +
3 + Off peak status (RestrictToMassPeak) :
4 +
5 + x  Necessary adaptations identified
6 + x  Started working on necessary adaptations
7 + x  Necessary adaptations implemented
8 + x  Necessary adaptations tested
9 +
10 + DONE!
11 +
12 +
13 + ****/
14   #include <iostream>
15   #include <vector>
16   #include <sys/stat.h>
17 + #include <fstream>
18  
19   #include <TCut.h>
20   #include <TROOT.h>
# Line 14 | Line 28
28   #include <TF1.h>
29   #include <TSQLResult.h>
30   #include <TProfile.h>
31 + #include <TSystem.h>
32 + #include "LimitDroplet.C"
33  
34   //#include "TTbar_stuff.C"
35   using namespace std;
# Line 22 | Line 38 | using namespace PlottingSetup;
38  
39  
40   void rediscover_the_top(string mcjzb, string datajzb) {
41 <  cout << "Hi! today we are going to (try to) rediscover the top!" << endl;
41 >  dout << "Hi! today we are going to (try to) rediscover the top!" << endl;
42    TCanvas *c3 = new TCanvas("c3","c3");
43    c3->SetLogy(1);
44    vector<float> binning;
# Line 62 | Line 78 | void rediscover_the_top(string mcjzb, st
78    TH1F *datapredictiont = allsamples.Draw("datapredictiont",    "-"+datajzb, nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,  luminosity);
79    TH1F *datapredictiono = allsamples.Draw("datapredictiono",    "-"+datajzb, nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,  luminosity);
80    datapredictiont->Add(datapredictiono,-1);
81 <  cout << "Second way of doing this !!!! Analytical shape to the left :-D" << endl;
81 >  dout << "Second way of doing this !!!! Analytical shape to the left :-D" << endl;
82    vector<TF1*> functions = do_cb_fit_to_plot(datapredictiont,10);
83    datapredictiont->SetMarkerColor(kRed);
84    datapredictiont->SetLineColor(kRed);
# Line 141 | Line 157 | ratio_binning.push_back(80);
157    ratio->Divide(datapredictiontb);
158    
159    for (int i=0;i<=ratio_binning.size();i++) {
160 <    cout << observedtb->GetBinLowEdge(i+1) << ";"<<observedtb->GetBinContent(i+1) << ";" << datapredictiontb->GetBinContent(i+1) << " --> " << ratio->GetBinContent(i+1) << "+/-" << ratio->GetBinError(i+1) << endl;
160 >    dout << observedtb->GetBinLowEdge(i+1) << ";"<<observedtb->GetBinContent(i+1) << ";" << datapredictiontb->GetBinContent(i+1) << " --> " << ratio->GetBinContent(i+1) << "+/-" << ratio->GetBinError(i+1) << endl;
161    }
162    
163   //  ratio->Divide(datapredictiontb);
# Line 167 | Line 183 | ratio_binning.push_back(80);
183    
184   }
185  
186 < void calculate_upper_limits(string mcjzb, string datajzb) {
187 <  write_warning("calculate_upper_limits","Upper limit calculation temporarily deactivated");
188 < //  write_warning("calculate_upper_limits","Calculation of SUSY upper limits has been temporarily suspended in favor of top discovery");
189 < //  rediscover_the_top(mcjzb,datajzb);
190 < /*  
191 <  TCanvas *c3 = new TCanvas("c3","c3");
192 <  c3->SetLogy(1);
193 <  vector<float> binning;
194 <  //binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
195 <  binning.push_back(50);
196 <  binning.push_back(100);
197 <  binning.push_back(150);
198 <  binning.push_back(200);
199 <  binning.push_back(500);
200 <  TH1F *datapredictiona = allsamples.Draw("datapredictiona",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity);
201 <  TH1F *datapredictionb = allsamples.Draw("datapredictionb",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
202 <  TH1F *datapredictionc = allsamples.Draw("datapredictionc",    datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
203 <  TH1F *dataprediction = (TH1F*)datapredictiona->Clone();
204 <  dataprediction->Add(datapredictionb,-1);
205 <  dataprediction->Add(datapredictionc);
206 <  TH1F *puresignal     = allsamples.Draw("puresignal",        mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
207 <  TH1F *signalpred     = allsamples.Draw("signalpred",    "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
208 <  TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
209 <  TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
210 <  TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
211 <  signalpred->Add(signalpredlo,-1);
212 <  signalpred->Add(signalpredro);
213 <  puresignal->Add(signalpred,-1);//subtracting signal contamination
214 <  ofstream myfile;
215 <  myfile.open ("ShapeFit_log.txt");
216 <  establish_upper_limits(puredata,dataprediction,puresignal,"LM4",myfile);
217 <  myfile.close();
218 < */
186 > vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, string plotfilename, bool doexpected, int flipped) {
187 >  float sigma95=-9.9,sigma95A=-9.9;
188 > /*
189 > USAGE OF ROOSTATS_CL95
190 > " Double_t             limit = roostats_cl95(ilum, slum, eff, seff, bck, sbck, n, gauss = false, nuisanceModel, method, plotFileName, seed); \n"
191 > " LimitResult expected_limit = roostats_clm(ilum, slum, eff, seff, bck, sbck, ntoys, nuisanceModel, method, seed); \n"
192 > " Double_t     average_limit = roostats_cla(ilum, slum, eff, seff, bck, sbck, nuisanceModel, method, seed); \n"
193 > "                                                                     \n"
194 > "
195 > " Double_t obs_limit = limit.GetObservedLimit();                      \n"
196 > " Double_t exp_limit = limit.GetExpectedLimit();                      \n"
197 > " Double_t exp_up    = limit.GetOneSigmaHighRange();                  \n"
198 > " Double_t exp_down  = limit.GetOneSigmaLowRange();                   \n"
199 > " Double_t exp_2up   = limit.GetTwoSigmaHighRange();                  \n"
200 > " Double_t exp_2down = limit.GetTwoSigmaLowRange();                   \n"
201 > */
202 >  if(mceff<=0) {
203 >    write_warning(__FUNCTION__,"Cannot compute upper limit in this configuration as the efficiency is negative:");
204 >    dout << "mc efficiency=" << mceff << " +/- " << mcefferr;
205 >    vector<float> sigmas;
206 >    sigmas.push_back(-1);
207 >    sigmas.push_back(-1);
208 >    return sigmas;
209 >  } else {
210 >    int nlimittoysused=1;
211 >    
212 >    ///------------------------------------------ < NEW > ----------------------------------------------------------
213 >    
214 >    int secondssince1970=time(NULL);
215 >    stringstream repname;
216 >    repname << PlottingSetup::cbafbasedir << "/exchange/report_" << secondssince1970 << "_"<<plotfilename<< "__"<< ".txt";
217 >    
218 >      /* - report filename [1]
219 >         - luminosity [2]
220 >         - lumi uncert [3]
221 >         - MC efficiency [4]
222 >         - MC efficiency error [5]
223 >         - Npred [6]
224 >         - Nprederr [7]
225 >         - Nobs [8]
226 >         - JZB cut [9]
227 >         - plot name  [10]*/
228 >
229 >  if(flipped==0) dout << "Calling limit capsule instead of calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
230 >  if(flipped>0) dout << "Calling limit capsule instead of calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << flippedNpred[ibin] << "," << flippedNprederr[ibin] << "," << flippedNobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
231 >    
232 >    stringstream command;
233 >    if(flipped==0) command << PlottingSetup::cbafbasedir << "/DistributedModelCalculations/Limits/TimedLimitCapsule.exec " << repname.str() << " " << luminosity << " " << luminosity*lumiuncert << " " << mceff << " " << mcefferr << " " << Npred[ibin] << " " << Nprederr[ibin] << " " << Nobs[ibin] << " " << -1 << " " << PlottingSetup::basedirectory << "/" << plotfilename << " " << doexpected;
234 >    if(flipped>0) command << PlottingSetup::cbafbasedir << "/DistributedModelCalculations/Limits/TimedLimitCapsule.exec " << repname.str() << " " << luminosity << " " << luminosity*lumiuncert << " " << mceff << " " << mcefferr << " " << flippedNpred[ibin] << " " << flippedNprederr[ibin] << " " << flippedNobs[ibin] << " " << -1 << " " << PlottingSetup::basedirectory << "/" << plotfilename << " " << doexpected;
235 >    dout << command.str() << endl;
236 >    
237 >    int retval = 256;
238 >    int attempts=0;
239 >    while(!(retval==0||attempts>=3)) {//try up to 3 times
240 >        attempts++;
241 >        dout << "Starting limit calculation (TimedLimitCapsule) now : Attempt " << attempts << endl;
242 >        retval=gSystem->Exec(command.str().c_str());
243 >    }
244 >    char hostname[1023];
245 >    gethostname(hostname,1023);
246 >    if((!((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))))&&retval==256) {
247 >        //running via CRAB and encountered the same problem too often: place a problem file to mark this problem!
248 >        stringstream markproblem;
249 >        markproblem << "touch " << PlottingSetup::basedirectory << "/exchange/problemswhilesettinglimits.txt";
250 >        gSystem->Exec(markproblem.str().c_str());      
251 >    }
252 >    LimitDroplet limres;
253 >    limres.readDroplet(repname.str());
254 >    dout << limres << endl;
255 >    remove(repname.str().c_str());
256 >    sigma95=limres.observed;
257 >
258 >    
259 >    ///------------------------------------------ < /NEW > ----------------------------------------------------------
260 >  vector<float> sigmas;
261 >  sigmas.push_back(sigma95);
262 >  if(doexpected) {
263 >    sigmas.push_back(limres.expected);
264 >    sigmas.push_back(limres.upper68);
265 >    sigmas.push_back(limres.lower68);
266 >    sigmas.push_back(limres.upper95);
267 >    sigmas.push_back(limres.lower95);
268 >  }
269 >  
270 >  return sigmas;
271 >  
272 >
273 >  }//end of mc efficiency is ok
274   }
275  
276 < void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts) {
277 <  cout << "Doing counting experiment ... " << endl;
276 > void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doexpected, int flipped) {
277 >  dout << "Doing counting experiment ... " << endl;
278 >  vector<vector<string> > limits;
279 >  vector<vector<float> > vlimits;
280 >  
281    
282    for(int isample=0;isample<signalsamples.collection.size();isample++) {
283 <    cout << "Considering sample " << signalsamples.collection[isample].samplename << endl;
283 >    vector<string> rows;
284 >    vector<float> vrows;
285 >    dout << "Considering sample " << signalsamples.collection[isample].samplename << endl;
286 >    rows.push_back(signalsamples.collection[isample].samplename);
287      for(int ibin=0;ibin<jzbcuts.size();ibin++) {
288 <      cout << "   Considering bin " << jzbcuts[ibin] << endl;
289 <      for(int isyst=0;isyst<uncertainties[isample*jzbcuts.size()+ibin].size();isyst++) {
290 <        if(isyst==0) {
291 <          if(uncertainties[isample*jzbcuts.size()+ibin][isyst]!=jzbcuts[ibin]) cout << "WATCH OUT THERE SEEMS TO BE A PROBLEM - THE TEST BIN DOESN'T CORRESPOND TO YOUR BIN!" << endl;
292 <          continue;
293 <        }
294 <        cout << "     Considering syst " << isyst << " : " << uncertainties[isample*jzbcuts.size()+ibin][isyst] << endl;
295 <      }//end of syst loop
288 >      dout << "_________________________________________________________________________________" << endl;
289 >      float JZBcutat=uncertainties[isample*jzbcuts.size()+ibin][0];
290 >      float mceff=uncertainties[isample*jzbcuts.size()+ibin][1];
291 >      float staterr=uncertainties[isample*jzbcuts.size()+ibin][2];
292 >      float systerr=uncertainties[isample*jzbcuts.size()+ibin][3];
293 >      float toterr =uncertainties[isample*jzbcuts.size()+ibin][4];
294 >      float observed,observederr,null,result;
295 >      
296 > //      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);
297 > //      observed-=result;//this is the actual excess we see!
298 > //      float expected=observed/luminosity;
299 >      string plotfilename=(string)(TString(signalsamples.collection[isample].samplename)+TString("___JZB_geq_")+TString(any2string(JZBcutat))+TString(".png"));
300 >      dout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl;
301 >      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doexpected,flipped);
302 >      
303 >      if(doexpected) {
304 > //      rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
305 >        rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(signalsamples.collection[isample].xs)+")");
306 >        vrows.push_back(sigmas[0]);
307 >        vrows.push_back(sigmas[1]);
308 > //      vrows.push_back(expected);
309 >        vrows.push_back(signalsamples.collection[isample].xs);
310 >      }
311 >      else {
312 > //      rows.push_back(any2string(sigmas[0])+"("+any2string(expected)+")");
313 >        rows.push_back(any2string(sigmas[0]));
314 >        vrows.push_back(sigmas[0]);
315 >        vrows.push_back(signalsamples.collection[isample].xs);
316 > //      vrows.push_back(expected);
317 >      }
318      }//end of bin loop
319 +    limits.push_back(rows);
320 +    vlimits.push_back(vrows);
321    }//end of sample loop
322 +  dout << endl << endl << endl << "_________________________________________________________________________________________________" << endl << endl;
323 +  dout << endl << endl << "PAS table 3:   (notation: limit [95%CL])" << endl << endl;
324 +  dout << "\t";
325 +  for (int irow=0;irow<jzbcuts.size();irow++) {
326 +    dout << jzbcuts[irow] << "\t";
327 +  }
328 +  dout << endl;
329 +  for(int irow=0;irow<limits.size();irow++) {
330 +    for(int ientry=0;ientry<limits[irow].size();ientry++) {
331 +      if (limits[irow][ientry]>0) dout << limits[irow][ientry] << "\t";
332 +      else dout << " (N/A) \t";
333 +    }
334 +    dout << endl;
335 +  }
336 +  
337 +  if(!doexpected) {
338 +    dout << endl << endl << "LIMITS: (Tex)" << endl;
339 +    tout << "\\begin{table}[hbtp]" << endl;
340 +    tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
341 +    tout << "\\begin{center}" << endl;
342 +    tout << "\\caption{Observed upper limits on the cross section of different LM benchmark points " << (ConsiderSignalContaminationForLimits?"  (accounting for signal contamination)":"  (not accounting for signal contamination)") << "}\\label{tab:lmresults}" << endl;
343 +    tout << "" << endl;
344 +    tout << "\\begin{tabular}{ | l | ";
345 +    for (int irow=0;irow<jzbcuts.size();irow++) tout << " l |";
346 +    tout << "} " << endl << " \\hline " << endl << "& \t ";
347 +    for (int irow=0;irow<jzbcuts.size();irow++) {
348 +      tout << "JZB $>$ " << jzbcuts[irow] << " GeV & \t ";
349 +    }
350 +    tout << " \\\\ \\hline " << endl;
351 +    for(int irow=0;irow<limits.size();irow++) {
352 +      tout << limits[irow][0] << " \t";
353 +      for(int ientry=0;ientry<jzbcuts.size();ientry++) {
354 +        if(vlimits[irow][2*ientry]>0) tout << " & " << Round(vlimits[irow][2*ientry],2) << " \t (" << Round(vlimits[irow][2*ientry] / vlimits[irow][2*ientry+1],3)<< "x \\sigma ) \t";
355 +        else tout << " & ( N / A ) \t";
356 + //      dout << Round(vlimits[irow][2*ientry],3) << " / " << Round(vlimits[irow][2*ientry+1],3)<< "\t";
357 +      }
358 +      tout << " \\\\ \\hline " << endl;
359 +    }
360 +      tout << "\\end{tabular}" << endl;
361 +      tout << "      \\end{tabular}"<< endl;
362 +      tout << "\\end{center}"<< endl;
363 +      tout << "\\end{table} "<< endl;
364 +
365 +  }//do observed
366 +  
367 +  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;
368 +  dout << "Scenario \t Efficiency [%] \t Upper limits [pb] \t \\sigma [pb]" << endl;
369 +  for(int icut=0;icut<jzbcuts.size();icut++) {
370 +    dout << "Region with JZB>" << jzbcuts[icut] << (ConsiderSignalContaminationForLimits?"  (accounting for signal contamination)":"  (not accounting for signal contamination)") << endl;
371 +    for(int isample=0;isample<signalsamples.collection.size();isample++) {
372 +      dout << limits[isample][0] << "\t" << Round(100*uncertainties[isample*jzbcuts.size()+icut][1],3) << "+/-" << Round(100*uncertainties[isample*jzbcuts.size()+icut][2],3) << " (stat) +/- " << Round(100*uncertainties[isample*jzbcuts.size()+icut][3],3) << " (syst) \t" << Round((vlimits[isample][2*icut]),3) << "\t" << Round(vlimits[isample][2*icut+1],3) << endl;
373 +    }
374 +    dout << endl;
375 +  }
376   }
377  
223 void susy_scan_axis_labeling(TH2F *histo) {
224  histo->GetXaxis()->SetTitle("#Chi_{2}^{0}-LSP");
225  histo->GetXaxis()->CenterTitle();
226  histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
227  histo->GetYaxis()->CenterTitle();
228 }
378  
379 < void scan_susy_space(string mcjzb, string datajzb) {
380 <  TCanvas *c3 = new TCanvas("c3","c3");
381 <  vector<float> binning;
382 <  binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
383 <  /*
384 <  binning.push_back(50);
385 <  binning.push_back(75);
386 <  binning.push_back(100);
387 <  binning.push_back(150);
388 <  binning.push_back(200);
389 <  binning.push_back(500);
390 <  */
391 <  float arrbinning[binning.size()];
392 <  for(int i=0;i<binning.size();i++) arrbinning[i]=binning[i];
393 <  TH1F *puredata   = allsamples.Draw("puredata",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
394 <  puredata->SetMarkerSize(DataMarkerSize);
395 <  TH1F *allbgs   = allsamples.Draw("allbgs",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
396 <  TH1F *allbgsb   = allsamples.Draw("allbgsb",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
397 <  TH1F *allbgsc   = allsamples.Draw("allbgsc",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
398 <  allbgs->Add(allbgsb,-1);
399 <  allbgs->Add(allbgsc);
400 <  int ndata=puredata->Integral();
401 <  ofstream myfile;
402 <  myfile.open ("susyscan_log.txt");
403 <  TFile *susyscanfile = new TFile("/scratch/fronga/SMS/T5z_SqSqToQZQZ_38xFall10.root");
404 <  TTree *suevents = (TTree*)susyscanfile->Get("events");
405 <  TH2F *exclusionmap = new TH2F("exclusionmap","",20,0,500,20,0,1000);
406 <  TH2F *exclusionmap1s = new TH2F("exclusionmap1s","",20,0,500,20,0,1000);
407 <  TH2F *exclusionmap2s = new TH2F("exclusionmap2s","",20,0,500,20,0,1000);
408 <  TH2F *exclusionmap3s = new TH2F("exclusionmap3s","",20,0,500,20,0,1000);
409 <  
410 <  susy_scan_axis_labeling(exclusionmap);
411 <  susy_scan_axis_labeling(exclusionmap1s);
412 <  susy_scan_axis_labeling(exclusionmap2s);
413 <  susy_scan_axis_labeling(exclusionmap3s);
414 <  
415 <  Int_t MyPalette[100];
416 <  Double_t r[]    = {0., 0.0, 1.0, 1.0, 1.0};
417 <  Double_t g[]    = {0., 0.0, 0.0, 1.0, 1.0};
418 <  Double_t b[]    = {0., 1.0, 0.0, 0.0, 1.0};
419 <  Double_t stop[] = {0., .25, .50, .75, 1.0};
420 <  Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 100);
421 <  for (int i=0;i<100;i++) MyPalette[i] = FI+i;
422 <  
423 <  gStyle->SetPalette(100, MyPalette);
424 <  
425 <  for(int m23=50;m23<500;m23+=25) {
426 <    for (int m0=(2*(m23-50)+150);m0<=1000;m0+=50)
427 <    {
428 <      c3->cd();
429 <      stringstream drawcondition;
430 <      drawcondition << "pfJetGoodNum>=3&&(TMath::Abs(masses[0]-"<<m0<<")<10&&TMath::Abs(masses[2]-masses[3]-"<<m23<<")<10)&&mll>5&&id1==id2";
431 <      TH1F *puresignal = new TH1F("puresignal","puresignal",binning.size()-1,arrbinning);
432 <      TH1F *puresignall= new TH1F("puresignall","puresignal",binning.size()-1,arrbinning);
433 <      stringstream drawvar,drawvar2;
434 <      drawvar<<mcjzb<<">>puresignal";
435 <      drawvar2<<"-"<<mcjzb<<">>puresignall";
436 <      suevents->Draw(drawvar.str().c_str(),drawcondition.str().c_str());
437 <      suevents->Draw(drawvar2.str().c_str(),drawcondition.str().c_str());
438 <      if(puresignal->Integral()<60) {
439 <        delete puresignal;
440 <        continue;
441 <      }
442 <      puresignal->Add(puresignall,-1);//we need to correct for the signal contamination - we effectively only see (JZB>0)-(JZB<0) !!
443 <      puresignal->Scale(ndata/(20*puresignal->Integral()));//normalizing it to 5% of the data
444 <      stringstream saveas;
445 <      saveas<<"Model_Scan/m0_"<<m0<<"__m23_"<<m23;
446 <      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;
447 < //        TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
448 < //        TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
449 < //        TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
450 < //        signalpred->Add(signalpredlo,-1);
451 < //        signalpred->Add(signalpredro);
452 < //        puresignal->Add(signalpred,-1);//subtracting signal contamination
453 < //---------------------
454 < //      cout << "(m0,m23)=("<<m0<<","<<m23<<") contains " << puresignal->Integral() << endl;
306 < //    TH1F *puresignal = allsamples.Draw("puresignal",mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
307 <      vector<float> results=establish_upper_limits(puredata,allbgs,puresignal,saveas.str(),myfile);  
308 <      if(results.size()==0) {
309 <        delete puresignal;
310 <        continue;
311 <      }
312 <      exclusionmap->Fill(m23,m0,results[0]);
313 <      exclusionmap1s->Fill(m23,m0,results[1]);
314 <      exclusionmap2s->Fill(m23,m0,results[2]);
315 <      exclusionmap3s->Fill(m23,m0,results[3]);
316 <      delete puresignal;
317 <      cout << "(m0,m23)=("<<m0<<","<<m23<<") : 3 sigma at " << results[3] << endl;
318 <    }
319 <  }//end of model scan for loop
379 >
380 > /********************************************************************** new : Limits using SHAPES ***********************************
381 >
382 >
383 >   SSSSSSSSSSSSSSS hhhhhhh                                                                                      
384 > SS:::::::::::::::Sh:::::h                                                                                      
385 > S:::::SSSSSS::::::Sh:::::h                                                                                      
386 > S:::::S     SSSSSSSh:::::h                                                                                      
387 > S:::::S             h::::h hhhhh         aaaaaaaaaaaaa  ppppp   ppppppppp       eeeeeeeeeeee        ssssssssss  
388 > S:::::S             h::::hh:::::hhh      a::::::::::::a p::::ppp:::::::::p    ee::::::::::::ee    ss::::::::::s  
389 > S::::SSSS          h::::::::::::::hh    aaaaaaaaa:::::ap:::::::::::::::::p  e::::::eeeee:::::eess:::::::::::::s
390 >  SS::::::SSSSS     h:::::::hhh::::::h            a::::app::::::ppppp::::::pe::::::e     e:::::es::::::ssss:::::s
391 >    SSS::::::::SS   h::::::h   h::::::h    aaaaaaa:::::a p:::::p     p:::::pe:::::::eeeee::::::e s:::::s  ssssss
392 >       SSSSSS::::S  h:::::h     h:::::h  aa::::::::::::a p:::::p     p:::::pe:::::::::::::::::e    s::::::s      
393 >            S:::::S h:::::h     h:::::h a::::aaaa::::::a p:::::p     p:::::pe::::::eeeeeeeeeee        s::::::s  
394 >            S:::::S h:::::h     h:::::ha::::a    a:::::a p:::::p    p::::::pe:::::::e           ssssss   s:::::s
395 > SSSSSSS     S:::::S h:::::h     h:::::ha::::a    a:::::a p:::::ppppp:::::::pe::::::::e          s:::::ssss::::::s
396 > S::::::SSSSSS:::::S h:::::h     h:::::ha:::::aaaa::::::a p::::::::::::::::p  e::::::::eeeeeeee  s::::::::::::::s
397 > S:::::::::::::::SS  h:::::h     h:::::h a::::::::::aa:::ap::::::::::::::pp    ee:::::::::::::e   s:::::::::::ss  
398 > SSSSSSSSSSSSSSS    hhhhhhh     hhhhhhh  aaaaaaaaaa  aaaap::::::pppppppp        eeeeeeeeeeeeee    sssssssssss    
399 >                                                         p:::::p                                                
400 >                                                         p:::::p                                                
401 >                                                        p:::::::p                                                
402 >                                                        p:::::::p                                                
403 >                                                        p:::::::p                                                
404 >                                                        ppppppppp                                                
405 >                                                                                                                
406 >
407 > *********************************************************************** new : Limits using SHAPES ***********************************/
408 >
409 >
410 > void limit_shapes_for_systematic_effect(TFile *limfile, string identifier, string mcjzb, string datajzb, int JES,vector<float> binning, TCanvas *limcan) {
411 >  dout << "Creatig shape templates ... ";
412 >  if(identifier!="") dout << "for systematic called "<<identifier;
413 >  dout << endl;
414 >  int dataormc=mcwithsignal;//this is only for tests - for real life you want dataormc=data !!!
415 >  if(dataormc!=data) write_warning(__FUNCTION__,"WATCH OUT! Not using data for limits!!!! this is ok for tests, but not ok for anything official!");
416 >  
417 >  TCut limitnJetcut;
418 >  if(JES==noJES) limitnJetcut=cutnJets;
419 >  else {
420 >    if(JES==JESdown) limitnJetcut=cutnJetsJESdown;
421 >    if(JES==JESup) limitnJetcut=cutnJetsJESup;
422 >  }
423 >  TH1F *ZOSSFP = allsamples.Draw("ZOSSFP",datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
424 >  TH1F *ZOSOFP = allsamples.Draw("ZOSOFP",datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
425 >  TH1F *ZOSSFN = allsamples.Draw("ZOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
426 >  TH1F *ZOSOFN = allsamples.Draw("ZOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
427 >  
428 >  TH1F *SBOSSFP;
429 >  TH1F *SBOSOFP;
430 >  TH1F *SBOSSFN;
431 >  TH1F *SBOSOFN;
432 >  
433 >  TH1F *LZOSSFP = allsamples.Draw("LZOSSFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
434 >  TH1F *LZOSOFP = allsamples.Draw("LZOSOFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
435 >  TH1F *LZOSSFN = allsamples.Draw("LZOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
436 >  TH1F *LZOSOFN = allsamples.Draw("LZOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
437 >  
438 >  TH1F *LSBOSSFP;
439 >  TH1F *LSBOSOFP;
440 >  TH1F *LSBOSSFN;
441 >  TH1F *LSBOSOFN;
442 >  
443 >  flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
444 >  if(PlottingSetup::RestrictToMassPeak) {
445 >      SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
446 >      SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
447 >      SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
448 >      SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
449 >      
450 >      LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
451 >      LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
452 >      LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
453 >      LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
454 >  }
455    
456 <  cout << "Exclusion Map contains" << exclusionmap->Integral() << " (integral) and entries: " << exclusionmap->GetEntries() << endl;
457 <  c3->cd();
458 <  exclusionmap->Draw("CONTZ");
459 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_Mean_values");
460 <  exclusionmap->Draw("COLZ");
461 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_Mean_values");
462 <  
463 <  exclusionmap1s->Draw("CONTZ");
329 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_1sigma_values");
330 <  exclusionmap1s->Draw("COLZ");
331 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_1sigma_values");
332 <  
333 <  exclusionmap2s->Draw("CONTZ");
334 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_2sigma_values");
335 <  exclusionmap2s->Draw("COLZ");
336 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_2sigma_values");
337 <  
338 <  exclusionmap3s->Draw("CONTZ");
339 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_3sigma_values");
340 <  exclusionmap3s->Draw("COLZ");
341 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_3sigma_values");
342 <  
343 <  TFile *exclusion_limits = new TFile("exclusion_limits.root","RECREATE");
344 <  exclusionmap->Write();
345 <  exclusionmap1s->Write();
346 <  exclusionmap2s->Write();
347 <  exclusionmap3s->Write();
348 <  exclusion_limits->Close();
349 <  susyscanfile->Close();
456 >  string obsname="data_obs";
457 >  string predname="background";
458 >  string signalname="signal";
459 >  if(identifier!="") {
460 >    obsname=("data_"+identifier);
461 >    predname=("background_"+identifier);
462 >    signalname="signal_"+identifier;
463 >  }
464    
465 <  myfile.close();
466 < }
465 >  TH1F *obs = (TH1F*)ZOSSFP->Clone("observation");
466 >  obs->SetName(obsname.c_str());
467 >  obs->Write();
468 >  TH1F *pred = (TH1F*)ZOSSFN->Clone("prediction");
469 >    flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
470 >  if(PlottingSetup::RestrictToMassPeak) {
471 >    pred->Add(ZOSOFP,1.0/3);
472 >    pred->Add(ZOSOFN,-1.0/3);
473 >    pred->Add(SBOSSFP,1.0/3);
474 >    pred->Add(SBOSSFN,-1.0/3);
475 >    pred->Add(SBOSOFP,1.0/3);
476 >    pred->Add(SBOSOFN,-1.0/3);
477 >  } else {
478 >    pred->Add(ZOSOFP,1.0);
479 >    pred->Add(ZOSOFN,-1.0);
480 >  }
481 >    
482 >  pred->SetName(predname.c_str());
483 >  pred->Write();
484 >  
485 > //  TH1F *Lobs = (TH1F*)LZOSSFP->Clone();
486 > //  TH1F *Lpred = (TH1F*)LZOSSFN->Clone();
487 >  
488 >  TH1F *Lobs = new TH1F("Lobs","Lobs",binning.size()-1,&binning[0]);
489 >  TH1F *Lpred = new TH1F("Lpred","Lpred",binning.size()-1,&binning[0]);
490 >  Lobs->Add(LZOSSFP);
491 >  Lpred->Add(LZOSSFN);
492 >    flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
493 >  if(PlottingSetup::RestrictToMassPeak) {
494 >    Lpred->Add(LZOSOFP,1.0/3);
495 >    Lpred->Add(LZOSOFN,-1.0/3);
496 >    Lpred->Add(LSBOSSFP,1.0/3);
497 >    Lpred->Add(LSBOSSFN,-1.0/3);
498 >    Lpred->Add(LSBOSOFP,1.0/3);
499 >    Lpred->Add(LSBOSOFN,-1.0/3);
500 >  } else {
501 >    Lpred->Add(LZOSOFP,1.0);
502 >    Lpred->Add(LZOSOFN,-1.0);
503 >  }
504  
505 +  TH1F *signal = (TH1F*)Lobs->Clone();
506 +  signal->Add(Lpred,-1);
507 +  signal->SetName(signalname.c_str());
508 +  signal->Write();
509 +  
510 +  delete Lobs;
511 +  delete Lpred;
512 +  
513 +  delete ZOSSFP;
514 +  delete ZOSOFP;
515 +  delete ZOSSFN;
516 +  delete ZOSOFN;
517 +  
518 +  if(PlottingSetup::RestrictToMassPeak) {
519 +    delete SBOSSFP;
520 +    delete SBOSOFP;
521 +    delete SBOSSFN;
522 +    delete SBOSOFN;
523 +  }
524 +  
525 +  delete LZOSSFP;
526 +  delete LZOSOFP;
527 +  delete LZOSSFN;
528 +  delete LZOSOFN;
529 +  
530 +  if(PlottingSetup::RestrictToMassPeak) {
531 +    delete LSBOSSFP;
532 +    delete LSBOSOFP;
533 +    delete LSBOSSFN;
534 +    delete LSBOSOFN;
535 +  }
536  
537 + }
538  
539 + void prepare_datacard(TFile *f) {
540 + TH1F *dataob = (TH1F*)f->Get("data_obs");
541 + TH1F *signal = (TH1F*)f->Get("signal");
542 + TH1F *background = (TH1F*)f->Get("background");
543  
544 + ofstream datacard;
545 + ensure_directory_exists(get_directory()+"/limits");
546 + datacard.open ((get_directory()+"/limits/susydatacard.txt").c_str());
547 + datacard << "Writing this to a file.\n";
548 + datacard << "imax 1\n";
549 + datacard << "jmax 1\n";
550 + datacard << "kmax *\n";
551 + datacard << "---------------\n";
552 + datacard << "shapes * * limitfile.root $PROCESS $PROCESS_$SYSTEMATIC\n";
553 + datacard << "---------------\n";
554 + datacard << "bin 1\n";
555 + datacard << "observation "<<dataob->Integral()<<"\n";
556 + datacard << "------------------------------\n";
557 + datacard << "bin             1          1\n";
558 + datacard << "process         signal     background\n";
559 + datacard << "process         0          1\n";
560 + datacard << "rate            "<<signal->Integral()<<"         "<<background->Integral()<<"\n";
561 + datacard << "--------------------------------\n";
562 + datacard << "lumi     lnN    1.10       1.0\n";
563 + datacard << "bgnorm   lnN    1.00       1.4  uncertainty on our prediction (40%)\n";
564 + datacard << "JES    shape    1          1    uncertainty on background shape and normalization\n";
565 + datacard << "peak   shape    1          1    uncertainty on signal resolution. Assume the histogram is a 2 sigma shift, \n";
566 + datacard << "#                                so divide the unit gaussian by 2 before doing the interpolation\n";
567 + datacard.close();
568 + }
569 +
570 +
571 + void prepare_limits(string mcjzb, string datajzb, float jzbpeakerrordata, float jzbpeakerrormc, vector<float> jzbbins) {
572 +  ensure_directory_exists(get_directory()+"/limits");
573 +  TFile *limfile = new TFile((get_directory()+"/limits/limitfile.root").c_str(),"RECREATE");
574 +  TCanvas *limcan = new TCanvas("limcan","Canvas for calculating limits");
575 +  limit_shapes_for_systematic_effect(limfile,"",mcjzb,datajzb,noJES,jzbbins,limcan);
576 +  limit_shapes_for_systematic_effect(limfile,"peakUp",newjzbexpression(mcjzb,jzbpeakerrormc),newjzbexpression(datajzb,jzbpeakerrordata),noJES,jzbbins,limcan);
577 +  limit_shapes_for_systematic_effect(limfile,"peakDown",newjzbexpression(mcjzb,-jzbpeakerrormc),newjzbexpression(datajzb,-jzbpeakerrordata),noJES,jzbbins,limcan);
578 +  limit_shapes_for_systematic_effect(limfile,"JESUp",mcjzb,datajzb,JESup,jzbbins,limcan);
579 +  limit_shapes_for_systematic_effect(limfile,"JESDown",mcjzb,datajzb,JESdown,jzbbins,limcan);
580 +  
581 +  prepare_datacard(limfile);
582 +  limfile->Close();
583 +  write_info("prepare_limits","limitfile.root and datacard.txt have been generated. You can now use them to calculate limits!");
584 +  
585 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines