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.3 by buchmann, Wed Jul 20 08:52:17 2011 UTC vs.
Revision 1.23 by buchmann, Thu Sep 15 08:58:43 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 14 | Line 15
15   #include <TF1.h>
16   #include <TSQLResult.h>
17   #include <TProfile.h>
18 + #include <TSystem.h>
19 + #include "LimitDroplet.C"
20  
21   //#include "TTbar_stuff.C"
22   using namespace std;
# Line 167 | Line 170 | ratio_binning.push_back(80);
170    
171   }
172  
173 < void calculate_upper_limits(string mcjzb, string datajzb) {
174 <  write_warning("calculate_upper_limits","Upper limit calculation temporarily deactivated");
175 < //  write_warning("calculate_upper_limits","Calculation of SUSY upper limits has been temporarily suspended in favor of top discovery");
176 < //  rediscover_the_top(mcjzb,datajzb);
177 < /*  
178 <  TCanvas *c3 = new TCanvas("c3","c3");
179 <  c3->SetLogy(1);
180 <  vector<float> binning;
181 <  //binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
182 <  binning.push_back(50);
183 <  binning.push_back(100);
184 <  binning.push_back(150);
185 <  binning.push_back(200);
186 <  binning.push_back(500);
187 <  TH1F *datapredictiona = allsamples.Draw("datapredictiona",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity);
188 <  TH1F *datapredictionb = allsamples.Draw("datapredictionb",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
189 <  TH1F *datapredictionc = allsamples.Draw("datapredictionc",    datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
190 <  TH1F *dataprediction = (TH1F*)datapredictiona->Clone();
191 <  dataprediction->Add(datapredictionb,-1);
192 <  dataprediction->Add(datapredictionc);
193 <  TH1F *puresignal     = allsamples.Draw("puresignal",        mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
194 <  TH1F *signalpred     = allsamples.Draw("signalpred",    "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
195 <  TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
196 <  TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
197 <  TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
198 <  signalpred->Add(signalpredlo,-1);
199 <  signalpred->Add(signalpredro);
200 <  puresignal->Add(signalpred,-1);//subtracting signal contamination
201 <  ofstream myfile;
202 <  myfile.open ("ShapeFit_log.txt");
203 <  establish_upper_limits(puredata,dataprediction,puresignal,"LM4",myfile);
204 <  myfile.close();
205 < */
206 < }
207 <
208 < vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, bool doobserved=false) {
209 <  float sigma95=0.0,sigma95A=0.0;
210 <  dout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << 1<< ") " << endl;
211 <  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, 1);
212 <  if(doobserved) {
213 <    dout << "Now calling : CL95A(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << 1<< ") " << endl;
214 <    sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], 1);
173 > vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, string plotfilename, bool doexpected) {
174 >  float sigma95=-9.9,sigma95A=-9.9;
175 > /*
176 > USAGE OF ROOSTATS_CL95
177 > " Double_t             limit = roostats_cl95(ilum, slum, eff, seff, bck, sbck, n, gauss = false, nuisanceModel, method, plotFileName, seed); \n"
178 > " LimitResult expected_limit = roostats_clm(ilum, slum, eff, seff, bck, sbck, ntoys, nuisanceModel, method, seed); \n"
179 > " Double_t     average_limit = roostats_cla(ilum, slum, eff, seff, bck, sbck, nuisanceModel, method, seed); \n"
180 > "                                                                     \n"
181 > "
182 > " Double_t obs_limit = limit.GetObservedLimit();                      \n"
183 > " Double_t exp_limit = limit.GetExpectedLimit();                      \n"
184 > " Double_t exp_up    = limit.GetOneSigmaHighRange();                  \n"
185 > " Double_t exp_down  = limit.GetOneSigmaLowRange();                   \n"
186 > " Double_t exp_2up   = limit.GetTwoSigmaHighRange();                  \n"
187 > " Double_t exp_2down = limit.GetTwoSigmaLowRange();                   \n"
188 > */
189 >  if(mceff<=0) {
190 >    write_warning(__FUNCTION__,"Cannot compute upper limit in this configuration as the efficiency is negative:");
191 >    dout << "mc efficiency=" << mceff << " +/- " << mcefferr;
192 >    vector<float> sigmas;
193 >    sigmas.push_back(-1);
194 >    sigmas.push_back(-1);
195 >    return sigmas;
196 >  } else {
197 >    int nlimittoysused=1;
198 >    
199 >    ///------------------------------------------ < NEW > ----------------------------------------------------------
200 >    
201 >    int secondssince1970=time(NULL);
202 >    stringstream repname;
203 >    repname << PlottingSetup::cbafbasedir << "/exchange/report_" << secondssince1970 << "_"<<plotfilename<< "__"<< ".txt";
204 >    
205 >      /* - report filename [1]
206 >         - luminosity [2]
207 >         - lumi uncert [3]
208 >         - MC efficiency [4]
209 >         - MC efficiency error [5]
210 >         - Npred [6]
211 >         - Nprederr [7]
212 >         - Nobs [8]
213 >         - JZB cut [9]
214 >         - plot name  [10]*/
215 >
216 >  dout << "Calling limit capsule instead of calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
217 >    
218 >    write_warning(__FUNCTION__,"To update to roostats, replace LimitCapsule.exec with NewLimitCapsule.exec below (line"+string(any2string(__LINE__))+")");
219 >    stringstream command; // if you want to use roostats instead of cmscl95, please replace "LimitCapsule.exec" below with "NewLimitCapsule.exec"
220 >    command << PlottingSetup::cbafbasedir << "/DistributedModelCalculations/Limits/LimitCapsule.exec " << repname.str() << " " << luminosity << " " << luminosity*lumiuncert << " " << mceff << " " << mcefferr << " " << Npred[ibin] << " " << Nprederr[ibin] << " " << Nobs[ibin] << " " << -1 << " " << PlottingSetup::basedirectory << "/" << plotfilename << " " << doexpected;
221 >    dout << command.str() << endl;
222 >    
223 >    int retval = 256;
224 >    int attempts=0;
225 >    while(!(retval==0||attempts>=5)) {//try up to 5 times
226 >        attempts++;
227 >        dout << "Starting limit calculation (LimitCapsule) now : Attempt " << attempts << endl;
228 >        retval=gSystem->Exec(command.str().c_str());
229 >    }
230 >    
231 >    LimitDroplet limres;
232 >    limres.readDroplet(repname.str());
233 >    dout << limres << endl;
234 >    remove(repname.str().c_str());
235 >    sigma95=limres.observed;
236 >
237 >    
238 >    ///------------------------------------------ < /NEW > ----------------------------------------------------------
239 >    //if(doexpected) nlimittoysused=nlimittoys;
240 > //    nlimittoysused=nlimittoys;
241 > //  dout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
242 > //  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
243 > //  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
244 >  
245 > /*  dout << "Now calling : roostats_cl95(" << luminosity << "," << lumiuncert*luminosity << ","<<mceff <<","<<mcefferr<<","<<Npred[ibin]<<","<<Nprederr[ibin] << ",n=" << nlimittoysused << ",gauss=" << false << ",nuisanceModel="<<nuisancemodel<<",method="<<limitmethod<<",plotfilename="<<plotfilename<<",seed=0) " << endl;
246 > /*  dout << "Now calling : roostats_limit(" << luminosity << "," << lumiuncert*luminosity << ","<<mceff <<","<<mcefferr<<","<<Npred[ibin]<<","<<Nprederr[ibin] << ",n=" << nlimittoysused << ",gauss=" << false << ", nuisanceModel="<<nuisancemodel<<",method="<<limitmethod<<",plotfilename="<<plotfilename<<",seed=1) " << endl;
247 >  LimitResult limit = roostats_limit(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0);
248 >  dout << "Now interpreting and saving results ... " << endl;
249 >  vector<float> sigmas;
250 >  sigmas.push_back(limit.GetExpectedLimit());//expected
251 >  sigmas.push_back(limit.GetObservedLimit());//observed
252 >  //up to here for backward compatibility
253 >  sigmas.push_back(limit.GetOneSigmaHighRange());//expected, up
254 >  sigmas.push_back(limit.GetTwoSigmaHighRange());//expected, 2 up
255 >  sigmas.push_back(limit.GetOneSigmaLowRange());//expected, down
256 >  sigmas.push_back(limit.GetTwoSigmaLowRange());//expected, 2 down
257 > */
258 > //  float limit = roostats_cl95(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0);
259 >  if(doexpected) {
260 > write_warning(__FUNCTION__,"EXPECTED LIMITS HAVE BEEN SWITCHED OFF TEMPORARILY");
261 > //    dout << "Now calling : CLA(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << nuisancemodel<< ") " << endl;
262 > //    sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], nuisancemodel);
263    }
264 + //  vector<float> sigmas;
265 + //  sigmas.push_back(limit);
266    vector<float> sigmas;
267    sigmas.push_back(sigma95);
268    sigmas.push_back(sigma95A);
269    return sigmas;
270 +  
271 +
272 +  }
273 +  write_warning(__FUNCTION__,"STILL MISSING SIGMAS, LIMITS, EVERYTHING ...");
274   }
275  
276 < void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doobserved) {
276 > void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doexpected) {
277    dout << "Doing counting experiment ... " << endl;
278    vector<vector<string> > limits;
279    vector<vector<float> > vlimits;
# Line 234 | Line 291 | void compute_upper_limits_from_counting_
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,null,result;
238 <      fill_result_histos(observed, null,null,null,null,null,null,null,mcjzb,JZBcutat,(int)5,result,(signalsamples.FindSample(signalsamples.collection[isample].filename)),signalsamples);
239 <      observed-=result;//this is the actual excess we see!
240 <      float expected=observed/luminosity;
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,doobserved);
301 >      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doexpected);
302        
303 <      if(doobserved) {
304 <        rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
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);
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)+")");
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(expected);
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 << "PAS table 3: " << endl << endl;
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";
# Line 265 | Line 328 | void compute_upper_limits_from_counting_
328    dout << endl;
329    for(int irow=0;irow<limits.size();irow++) {
330      for(int ientry=0;ientry<limits[irow].size();ientry++) {
331 <      dout << limits[irow][ientry] << "\t";
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(!doobserved) {
338 <    dout << endl << endl << "LIMITS: " << endl;
339 <    dout << "\t";
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 <      dout << jzbcuts[irow] << "\t";
348 >      tout << "JZB $>$ " << jzbcuts[irow] << " GeV & \t ";
349      }
350 <    dout << endl;
350 >    tout << " \\\\ \\hline " << endl;
351      for(int irow=0;irow<limits.size();irow++) {
352 <      dout << limits[irow][0] << "\t";
352 >      tout << limits[irow][0] << " \t";
353        for(int ientry=0;ientry<jzbcuts.size();ientry++) {
354 <        dout << Round(vlimits[irow][2*ientry] / vlimits[irow][2*ientry+1],3)<< "\t";
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 <      dout << endl;
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 Prediction [pb]" << 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] << endl;
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[icut][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;
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  
300 void susy_scan_axis_labeling(TH2F *histo) {
301  histo->GetXaxis()->SetTitle("#Chi_{2}^{0}-LSP");
302  histo->GetXaxis()->CenterTitle();
303  histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
304  histo->GetYaxis()->CenterTitle();
305 }
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 <  float arrbinning[binning.size()];
384 <  for(int i=0;i<binning.size();i++) arrbinning[i]=binning[i];
385 <  TH1F *puredata   = allsamples.Draw("puredata",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
386 <  puredata->SetMarkerSize(DataMarkerSize);
387 <  TH1F *allbgs   = allsamples.Draw("allbgs",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
388 <  TH1F *allbgsb   = allsamples.Draw("allbgsb",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
389 <  TH1F *allbgsc   = allsamples.Draw("allbgsc",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
390 <  allbgs->Add(allbgsb,-1);
391 <  allbgs->Add(allbgsc);
392 <  int ndata=puredata->Integral();
393 <  ofstream myfile;
394 <  myfile.open ("susyscan_log.txt");
395 <  TFile *susyscanfile = new TFile("/scratch/fronga/SMS/T5z_SqSqToQZQZ_38xFall10.root");
396 <  TTree *suevents = (TTree*)susyscanfile->Get("events");
397 <  TH2F *exclusionmap = new TH2F("exclusionmap","",20,0,500,20,0,1000);
398 <  TH2F *exclusionmap1s = new TH2F("exclusionmap1s","",20,0,500,20,0,1000);
399 <  TH2F *exclusionmap2s = new TH2F("exclusionmap2s","",20,0,500,20,0,1000);
400 <  TH2F *exclusionmap3s = new TH2F("exclusionmap3s","",20,0,500,20,0,1000);
401 <  
402 <  susy_scan_axis_labeling(exclusionmap);
403 <  susy_scan_axis_labeling(exclusionmap1s);
404 <  susy_scan_axis_labeling(exclusionmap2s);
405 <  susy_scan_axis_labeling(exclusionmap3s);
406 <  
407 <  Int_t MyPalette[100];
408 <  Double_t r[]    = {0., 0.0, 1.0, 1.0, 1.0};
409 <  Double_t g[]    = {0., 0.0, 0.0, 1.0, 1.0};
410 <  Double_t b[]    = {0., 1.0, 0.0, 0.0, 1.0};
411 <  Double_t stop[] = {0., .25, .50, .75, 1.0};
412 <  Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 100);
413 <  for (int i=0;i<100;i++) MyPalette[i] = FI+i;
414 <  
415 <  gStyle->SetPalette(100, MyPalette);
344 <  
345 <  for(int m23=50;m23<500;m23+=25) {
346 <    for (int m0=(2*(m23-50)+150);m0<=1000;m0+=50)
347 <    {
348 <      c3->cd();
349 <      stringstream drawcondition;
350 <      drawcondition << "pfJetGoodNum>=3&&(TMath::Abs(masses[0]-"<<m0<<")<10&&TMath::Abs(masses[2]-masses[3]-"<<m23<<")<10)&&mll>5&&id1==id2";
351 <      TH1F *puresignal = new TH1F("puresignal","puresignal",binning.size()-1,arrbinning);
352 <      TH1F *puresignall= new TH1F("puresignall","puresignal",binning.size()-1,arrbinning);
353 <      stringstream drawvar,drawvar2;
354 <      drawvar<<mcjzb<<">>puresignal";
355 <      drawvar2<<"-"<<mcjzb<<">>puresignall";
356 <      suevents->Draw(drawvar.str().c_str(),drawcondition.str().c_str());
357 <      suevents->Draw(drawvar2.str().c_str(),drawcondition.str().c_str());
358 <      if(puresignal->Integral()<60) {
359 <        delete puresignal;
360 <        continue;
361 <      }
362 <      puresignal->Add(puresignall,-1);//we need to correct for the signal contamination - we effectively only see (JZB>0)-(JZB<0) !!
363 <      puresignal->Scale(ndata/(20*puresignal->Integral()));//normalizing it to 5% of the data
364 <      stringstream saveas;
365 <      saveas<<"Model_Scan/m0_"<<m0<<"__m23_"<<m23;
366 <      dout << "PLEASE KEEP IN MIND THAT SIGNAL CONTAMINATION IS NOT REALLY TAKEN CARE OF YET DUE TO LOW STATISTICS! SHOULD BE SOMETHING LIKE THIS : "<< endl;
367 < //        TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
368 < //        TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
369 < //        TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
370 < //        signalpred->Add(signalpredlo,-1);
371 < //        signalpred->Add(signalpredro);
372 < //        puresignal->Add(signalpred,-1);//subtracting signal contamination
373 < //---------------------
374 < //      dout << "(m0,m23)=("<<m0<<","<<m23<<") contains " << puresignal->Integral() << endl;
375 < //    TH1F *puresignal = allsamples.Draw("puresignal",mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
376 <      vector<float> results=establish_upper_limits(puredata,allbgs,puresignal,saveas.str(),myfile);  
377 <      if(results.size()==0) {
378 <        delete puresignal;
379 <        continue;
380 <      }
381 <      exclusionmap->Fill(m23,m0,results[0]);
382 <      exclusionmap1s->Fill(m23,m0,results[1]);
383 <      exclusionmap2s->Fill(m23,m0,results[2]);
384 <      exclusionmap3s->Fill(m23,m0,results[3]);
385 <      delete puresignal;
386 <      dout << "(m0,m23)=("<<m0<<","<<m23<<") : 3 sigma at " << results[3] << endl;
387 <    }
388 <  }//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 <  dout << "Exclusion Map contains" << exclusionmap->Integral() << " (integral) and entries: " << exclusionmap->GetEntries() << endl;
418 <  c3->cd();
419 <  exclusionmap->Draw("CONTZ");
420 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_Mean_values");
421 <  exclusionmap->Draw("COLZ");
422 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_Mean_values");
423 <  
424 <  exclusionmap1s->Draw("CONTZ");
425 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_1sigma_values");
426 <  exclusionmap1s->Draw("COLZ");
427 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_1sigma_values");
428 <  
429 <  exclusionmap2s->Draw("CONTZ");
430 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_2sigma_values");
431 <  exclusionmap2s->Draw("COLZ");
432 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_2sigma_values");
433 <  
434 <  exclusionmap3s->Draw("CONTZ");
435 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_3sigma_values");
436 <  exclusionmap3s->Draw("COLZ");
437 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_3sigma_values");
438 <  
439 <  TFile *exclusion_limits = new TFile("exclusion_limits.root","RECREATE");
440 <  exclusionmap->Write();
441 <  exclusionmap1s->Write();
442 <  exclusionmap2s->Write();
443 <  exclusionmap3s->Write();
444 <  exclusion_limits->Close();
445 <  susyscanfile->Close();
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 = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
429 >  TH1F *SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
430 >  TH1F *SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
431 >  TH1F *SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
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 = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
439 >  TH1F *LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
440 >  TH1F *LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
441 >  TH1F *LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
442 >  
443 >  string obsname="data_obs";
444 >  string predname="background";
445 >  string signalname="signal";
446 >  if(identifier!="") {
447 >    obsname=("data_"+identifier);
448 >    predname=("background_"+identifier);
449 >    signalname="signal_"+identifier;
450 >  }
451    
452 <  myfile.close();
452 >  TH1F *obs = (TH1F*)ZOSSFP->Clone();
453 >  obs->SetName(obsname.c_str());
454 >  obs->Write();
455 >  TH1F *pred = (TH1F*)ZOSSFN->Clone();
456 >  pred->Add(ZOSOFP,1.0/3);
457 >  pred->Add(ZOSOFN,-1.0/3);
458 >  pred->Add(SBOSSFP,1.0/3);
459 >  pred->Add(SBOSSFN,-1.0/3);
460 >  pred->Add(SBOSOFP,1.0/3);
461 >  pred->Add(SBOSOFN,-1.0/3);
462 >  pred->SetName(predname.c_str());
463 >  pred->Write();
464 >  
465 > //  TH1F *Lobs = (TH1F*)LZOSSFP->Clone();
466 > //  TH1F *Lpred = (TH1F*)LZOSSFN->Clone();
467 >  
468 >  TH1F *Lobs = new TH1F("Lobs","Lobs",binning.size()-1,&binning[0]);
469 >  TH1F *Lpred = new TH1F("Lpred","Lpred",binning.size()-1,&binning[0]);
470 >  Lobs->Add(LZOSSFP);
471 >  Lpred->Add(LZOSSFN);
472 >  Lpred->Add(LZOSOFP,1.0/3);
473 >  Lpred->Add(LZOSOFN,-1.0/3);
474 >  Lpred->Add(LSBOSSFP,1.0/3);
475 >  Lpred->Add(LSBOSSFN,-1.0/3);
476 >  Lpred->Add(LSBOSOFP,1.0/3);
477 >  Lpred->Add(LSBOSOFN,-1.0/3);
478 >  TH1F *signal = (TH1F*)Lobs->Clone();
479 >  signal->Add(Lpred,-1);
480 >  signal->SetName(signalname.c_str());
481 >  signal->Write();
482 >  
483 >  delete Lobs;
484 >  delete Lpred;
485 >  
486 >  delete ZOSSFP;
487 >  delete ZOSOFP;
488 >  delete ZOSSFN;
489 >  delete ZOSOFN;
490 >  
491 >  delete SBOSSFP;
492 >  delete SBOSOFP;
493 >  delete SBOSSFN;
494 >  delete SBOSOFN;
495 >  
496 >  delete LZOSSFP;
497 >  delete LZOSOFP;
498 >  delete LZOSSFN;
499 >  delete LZOSOFN;
500 >  
501 >  delete LSBOSSFP;
502 >  delete LSBOSOFP;
503 >  delete LSBOSSFN;
504 >  delete LSBOSOFN;
505 >
506   }
507  
508 + void prepare_datacard(TFile *f) {
509 + TH1F *dataob = (TH1F*)f->Get("data_obs");
510 + TH1F *signal = (TH1F*)f->Get("signal");
511 + TH1F *background = (TH1F*)f->Get("background");
512 +
513 + ofstream datacard;
514 + ensure_directory_exists(get_directory()+"/limits");
515 + datacard.open ((get_directory()+"/limits/susydatacard.txt").c_str());
516 + datacard << "Writing this to a file.\n";
517 + datacard << "imax 1\n";
518 + datacard << "jmax 1\n";
519 + datacard << "kmax *\n";
520 + datacard << "---------------\n";
521 + datacard << "shapes * * limitfile.root $PROCESS $PROCESS_$SYSTEMATIC\n";
522 + datacard << "---------------\n";
523 + datacard << "bin 1\n";
524 + datacard << "observation "<<dataob->Integral()<<"\n";
525 + datacard << "------------------------------\n";
526 + datacard << "bin             1          1\n";
527 + datacard << "process         signal     background\n";
528 + datacard << "process         0          1\n";
529 + datacard << "rate            "<<signal->Integral()<<"         "<<background->Integral()<<"\n";
530 + datacard << "--------------------------------\n";
531 + datacard << "lumi     lnN    1.10       1.0\n";
532 + datacard << "bgnorm   lnN    1.00       1.4  uncertainty on our prediction (40%)\n";
533 + datacard << "JES    shape    1          1    uncertainty on background shape and normalization\n";
534 + datacard << "peak   shape    1          1    uncertainty on signal resolution. Assume the histogram is a 2 sigma shift, \n";
535 + datacard << "#                                so divide the unit gaussian by 2 before doing the interpolation\n";
536 + datacard.close();
537 + }
538  
539  
540 <
540 > void prepare_limits(string mcjzb, string datajzb, float jzbpeakerrordata, float jzbpeakerrormc, vector<float> jzbbins) {
541 >  ensure_directory_exists(get_directory()+"/limits");
542 >  TFile *limfile = new TFile((get_directory()+"/limits/limitfile.root").c_str(),"RECREATE");
543 >  TCanvas *limcan = new TCanvas("limcan","Canvas for calculating limits");
544 >  limit_shapes_for_systematic_effect(limfile,"",mcjzb,datajzb,noJES,jzbbins,limcan);
545 >  limit_shapes_for_systematic_effect(limfile,"peakUp",newjzbexpression(mcjzb,jzbpeakerrormc),newjzbexpression(datajzb,jzbpeakerrordata),noJES,jzbbins,limcan);
546 >  limit_shapes_for_systematic_effect(limfile,"peakDown",newjzbexpression(mcjzb,-jzbpeakerrormc),newjzbexpression(datajzb,-jzbpeakerrordata),noJES,jzbbins,limcan);
547 >  limit_shapes_for_systematic_effect(limfile,"JESUp",mcjzb,datajzb,JESup,jzbbins,limcan);
548 >  limit_shapes_for_systematic_effect(limfile,"JESDown",mcjzb,datajzb,JESdown,jzbbins,limcan);
549 >  
550 >  prepare_datacard(limfile);
551 >  limfile->Close();
552 >  write_info("prepare_limits","limitfile.root and datacard.txt have been generated. You can now use them to calculate limits!");
553 >  
554 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines