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.4 by buchmann, Wed Jul 20 12:26:11 2011 UTC vs.
Revision 1.18 by buchmann, Fri Sep 2 06:23: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 167 | Line 168 | ratio_binning.push_back(80);
168    
169   }
170  
171 < void calculate_upper_limits(string mcjzb, string datajzb) {
172 <  write_warning("calculate_upper_limits","Upper limit calculation temporarily deactivated");
173 < //  write_warning("calculate_upper_limits","Calculation of SUSY upper limits has been temporarily suspended in favor of top discovery");
174 < //  rediscover_the_top(mcjzb,datajzb);
175 < /*  
176 <  TCanvas *c3 = new TCanvas("c3","c3");
177 <  c3->SetLogy(1);
178 <  vector<float> binning;
179 <  //binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
180 <  binning.push_back(50);
181 <  binning.push_back(100);
182 <  binning.push_back(150);
183 <  binning.push_back(200);
184 <  binning.push_back(500);
185 <  TH1F *datapredictiona = allsamples.Draw("datapredictiona",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity);
186 <  TH1F *datapredictionb = allsamples.Draw("datapredictionb",    "-"+datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
187 <  TH1F *datapredictionc = allsamples.Draw("datapredictionc",    datajzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity);
188 <  TH1F *dataprediction = (TH1F*)datapredictiona->Clone();
189 <  dataprediction->Add(datapredictionb,-1);
190 <  dataprediction->Add(datapredictionc);
191 <  TH1F *puresignal     = allsamples.Draw("puresignal",        mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
192 <  TH1F *signalpred     = allsamples.Draw("signalpred",    "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
193 <  TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
194 <  TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
195 <  TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
196 <  signalpred->Add(signalpredlo,-1);
197 <  signalpred->Add(signalpredro);
198 <  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 <
205 < vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, bool doobserved=false) {
206 <  float sigma95=0.0,sigma95A=0.0;
207 <  int nuisancemodel=1;
171 > vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, string plotfilename, bool doobserved) {
172 >  float sigma95=-9.9,sigma95A=-9.9;
173 >  int nuisancemodel=0;
174 > /*
175 > USAGE OF ROOSTATS_CL95
176 > " Double_t             limit = roostats_cl95(ilum, slum, eff, seff, bck, sbck, n, gauss = false, nuisanceModel, method, plotFileName, seed); \n"
177 > " LimitResult expected_limit = roostats_clm(ilum, slum, eff, seff, bck, sbck, ntoys, nuisanceModel, method, seed); \n"
178 > " Double_t     average_limit = roostats_cla(ilum, slum, eff, seff, bck, sbck, nuisanceModel, method, seed); \n"
179 > "                                                                     \n"
180 > "
181 > " Double_t obs_limit = limit.GetObservedLimit();                      \n"
182 > " Double_t exp_limit = limit.GetExpectedLimit();                      \n"
183 > " Double_t exp_up    = limit.GetOneSigmaHighRange();                  \n"
184 > " Double_t exp_down  = limit.GetOneSigmaLowRange();                   \n"
185 > " Double_t exp_2up   = limit.GetTwoSigmaHighRange();                  \n"
186 > " Double_t exp_2down = limit.GetTwoSigmaLowRange();                   \n"
187 > */
188 >  if(mceff<=0) {
189 >    write_warning(__FUNCTION__,"Cannot compute upper limit in this configuration as the efficiency is negative:");
190 >    dout << "mc efficiency=" << mceff << " +/- " << mcefferr;
191 >    vector<float> sigmas;
192 >    sigmas.push_back(-1);
193 >    sigmas.push_back(-1);
194 >    return sigmas;
195 >  } else {
196 >    int nlimittoysused=1;
197 >    //if(doobserved) nlimittoysused=nlimittoys;
198 >    nlimittoysused=nlimittoys;
199    dout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
200    sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
201 +  
202 + /*  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;
203 + /*  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;
204 +  LimitResult limit = roostats_limit(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0);
205 +  dout << "Now interpreting and saving results ... " << endl;
206 +  vector<float> sigmas;
207 +  sigmas.push_back(limit.GetExpectedLimit());//expected
208 +  sigmas.push_back(limit.GetObservedLimit());//observed
209 +  //up to here for backward compatibility
210 +  sigmas.push_back(limit.GetOneSigmaHighRange());//expected, up
211 +  sigmas.push_back(limit.GetTwoSigmaHighRange());//expected, 2 up
212 +  sigmas.push_back(limit.GetOneSigmaLowRange());//expected, down
213 +  sigmas.push_back(limit.GetTwoSigmaLowRange());//expected, 2 down
214 + */
215 + //  float limit = roostats_cl95(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0);
216    if(doobserved) {
217      dout << "Now calling : CLA(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << nuisancemodel<< ") " << endl;
218      sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], nuisancemodel);
219    }
220 + //  vector<float> sigmas;
221 + //  sigmas.push_back(limit);
222    vector<float> sigmas;
223    sigmas.push_back(sigma95);
224    sigmas.push_back(sigma95A);
225    return sigmas;
226 +  
227 +
228 +  }
229 +  write_warning(__FUNCTION__,"STILL MISSING SIGMAS, LIMITS, EVERYTHING ...");
230   }
231  
232   void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doobserved) {
# Line 235 | Line 247 | void compute_upper_limits_from_counting_
247        float staterr=uncertainties[isample*jzbcuts.size()+ibin][2];
248        float systerr=uncertainties[isample*jzbcuts.size()+ibin][3];
249        float toterr =uncertainties[isample*jzbcuts.size()+ibin][4];
250 <      float observed,null,result;
239 <      fill_result_histos(observed, null,null,null,null,null,null,null,mcjzb,JZBcutat,(int)5,result,(signalsamples.FindSample(signalsamples.collection[isample].filename)),signalsamples);
240 <      observed-=result;//this is the actual excess we see!
241 <      float expected=observed/luminosity;
250 >      float observed,observederr,null,result;
251        
252 + //      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);
253 + //      observed-=result;//this is the actual excess we see!
254 + //      float expected=observed/luminosity;
255 +      string plotfilename=(string)(TString(signalsamples.collection[isample].samplename)+TString("___JZB_geq_")+TString(any2string(JZBcutat))+TString(".png"));
256        dout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl;
257 <      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,doobserved);
257 >      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doobserved);
258        
259        if(doobserved) {
260 <        rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
260 > //      rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
261 >        rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(signalsamples.collection[isample].xs)+")");
262          vrows.push_back(sigmas[0]);
263          vrows.push_back(sigmas[1]);
264 <        vrows.push_back(expected);
264 > //      vrows.push_back(expected);
265 >        vrows.push_back(signalsamples.collection[isample].xs);
266        }
267        else {
268 <        rows.push_back(any2string(sigmas[0])+"("+any2string(expected)+")");
268 > //      rows.push_back(any2string(sigmas[0])+"("+any2string(expected)+")");
269 >        rows.push_back(any2string(sigmas[0]));
270          vrows.push_back(sigmas[0]);
271 <        vrows.push_back(expected);
271 >        vrows.push_back(signalsamples.collection[isample].xs);
272 > //      vrows.push_back(expected);
273        }
274      }//end of bin loop
275      limits.push_back(rows);
276      vlimits.push_back(vrows);
277    }//end of sample loop
278 <  dout << endl << endl << "PAS table 3: " << endl << endl;
278 >  dout << endl << endl << endl << "_________________________________________________________________________________________________" << endl << endl;
279 >  dout << endl << endl << "PAS table 3:   (notation: limit [95%CL])" << endl << endl;
280    dout << "\t";
281    for (int irow=0;irow<jzbcuts.size();irow++) {
282      dout << jzbcuts[irow] << "\t";
# Line 266 | Line 284 | void compute_upper_limits_from_counting_
284    dout << endl;
285    for(int irow=0;irow<limits.size();irow++) {
286      for(int ientry=0;ientry<limits[irow].size();ientry++) {
287 <      dout << limits[irow][ientry] << "\t";
287 >      if (limits[irow][ientry]>0) dout << limits[irow][ientry] << "\t";
288 >      else dout << " (N/A) \t";
289      }
290      dout << endl;
291    }
292    
293    if(!doobserved) {
294 <    dout << endl << endl << "LIMITS: " << endl;
295 <    dout << "\t";
294 >    dout << endl << endl << "LIMITS: (Tex)" << endl;
295 >    tout << "\\begin{table}[hbtp]" << endl;
296 >    tout << "\\renewcommand{\arraystretch}{1.3}" << endl;
297 >    tout << "\\begin{center}" << endl;
298 >    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;
299 >    tout << "" << endl;
300 >    tout << "\\begin{tabular}{ | l | ";
301 >    for (int irow=0;irow<jzbcuts.size();irow++) tout << " l |";
302 >    tout << "} " << endl << " \\hline " << endl << "& \t ";
303      for (int irow=0;irow<jzbcuts.size();irow++) {
304 <      dout << jzbcuts[irow] << "\t";
304 >      tout << "JZB $>$ " << jzbcuts[irow] << " GeV & \t ";
305      }
306 <    dout << endl;
306 >    tout << " \\\\ \\hline " << endl;
307      for(int irow=0;irow<limits.size();irow++) {
308 <      dout << limits[irow][0] << "\t";
308 >      tout << limits[irow][0] << " \t";
309        for(int ientry=0;ientry<jzbcuts.size();ientry++) {
310 <        dout << Round(vlimits[irow][2*ientry] / vlimits[irow][2*ientry+1],3)<< "\t";
310 >        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";
311 >        else tout << " & ( N / A ) \t";
312 > //      dout << Round(vlimits[irow][2*ientry],3) << " / " << Round(vlimits[irow][2*ientry+1],3)<< "\t";
313        }
314 <      dout << endl;
314 >      tout << " \\\\ \\hline " << endl;
315      }
316 +      tout << "\\end{tabular}" << endl;
317 +      tout << "      \\end{tabular}"<< endl;
318 +      tout << "\\end{center}"<< endl;
319 +      tout << "\\end{table} "<< endl;
320 +
321    }//do observed
322    
323    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;
324 <  dout << "Scenario \t Efficiency [%] \t Upper limits [pb] \t Prediction [pb]" << endl;
324 >  dout << "Scenario \t Efficiency [%] \t Upper limits [pb] \t \\sigma [pb]" << endl;
325    for(int icut=0;icut<jzbcuts.size();icut++) {
326 <    dout << "Region with JZB>" << jzbcuts[icut] << endl;
326 >    dout << "Region with JZB>" << jzbcuts[icut] << (ConsiderSignalContaminationForLimits?"  (accounting for signal contamination)":"  (not accounting for signal contamination)") << endl;
327      for(int isample=0;isample<signalsamples.collection.size();isample++) {
328 <      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;
328 >      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;
329      }
330      dout << endl;
331    }
332    
333 <  write_warning("compute_upper_limits_from_counting_experiment","Still need to update the script");
333 >  write_warning(__FUNCTION__,"Still need to update the script");
334   }
335  
303 void susy_scan_axis_labeling(TH2F *histo) {
304  histo->GetXaxis()->SetTitle("#Chi_{2}^{0}-LSP");
305  histo->GetXaxis()->CenterTitle();
306  histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
307  histo->GetYaxis()->CenterTitle();
308 }
336  
337 < void scan_susy_space(string mcjzb, string datajzb) {
338 <  TCanvas *c3 = new TCanvas("c3","c3");
339 <  vector<float> binning;
340 <  binning=allsamples.get_optimal_binsize(mcjzb,cutmass&&cutOSSF&&cutnJets,20,50,800);
341 <  float arrbinning[binning.size()];
342 <  for(int i=0;i<binning.size();i++) arrbinning[i]=binning[i];
343 <  TH1F *puredata   = allsamples.Draw("puredata",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
344 <  puredata->SetMarkerSize(DataMarkerSize);
345 <  TH1F *allbgs   = allsamples.Draw("allbgs",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
346 <  TH1F *allbgsb   = allsamples.Draw("allbgsb",  "-"+datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
347 <  TH1F *allbgsc   = allsamples.Draw("allbgsc",  datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data,luminosity);
348 <  allbgs->Add(allbgsb,-1);
349 <  allbgs->Add(allbgsc);
350 <  int ndata=puredata->Integral();
351 <  ofstream myfile;
352 <  myfile.open ("susyscan_log.txt");
353 <  TFile *susyscanfile = new TFile("/scratch/fronga/SMS/T5z_SqSqToQZQZ_38xFall10.root");
354 <  TTree *suevents = (TTree*)susyscanfile->Get("events");
355 <  TH2F *exclusionmap = new TH2F("exclusionmap","",20,0,500,20,0,1000);
356 <  TH2F *exclusionmap1s = new TH2F("exclusionmap1s","",20,0,500,20,0,1000);
357 <  TH2F *exclusionmap2s = new TH2F("exclusionmap2s","",20,0,500,20,0,1000);
358 <  TH2F *exclusionmap3s = new TH2F("exclusionmap3s","",20,0,500,20,0,1000);
359 <  
360 <  susy_scan_axis_labeling(exclusionmap);
361 <  susy_scan_axis_labeling(exclusionmap1s);
362 <  susy_scan_axis_labeling(exclusionmap2s);
363 <  susy_scan_axis_labeling(exclusionmap3s);
364 <  
365 <  Int_t MyPalette[100];
366 <  Double_t r[]    = {0., 0.0, 1.0, 1.0, 1.0};
367 <  Double_t g[]    = {0., 0.0, 0.0, 1.0, 1.0};
368 <  Double_t b[]    = {0., 1.0, 0.0, 0.0, 1.0};
369 <  Double_t stop[] = {0., .25, .50, .75, 1.0};
370 <  Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 100);
371 <  for (int i=0;i<100;i++) MyPalette[i] = FI+i;
372 <  
373 <  gStyle->SetPalette(100, MyPalette);
347 <  
348 <  for(int m23=50;m23<500;m23+=25) {
349 <    for (int m0=(2*(m23-50)+150);m0<=1000;m0+=50)
350 <    {
351 <      c3->cd();
352 <      stringstream drawcondition;
353 <      drawcondition << "pfJetGoodNum>=3&&(TMath::Abs(masses[0]-"<<m0<<")<10&&TMath::Abs(masses[2]-masses[3]-"<<m23<<")<10)&&mll>5&&id1==id2";
354 <      TH1F *puresignal = new TH1F("puresignal","puresignal",binning.size()-1,arrbinning);
355 <      TH1F *puresignall= new TH1F("puresignall","puresignal",binning.size()-1,arrbinning);
356 <      stringstream drawvar,drawvar2;
357 <      drawvar<<mcjzb<<">>puresignal";
358 <      drawvar2<<"-"<<mcjzb<<">>puresignall";
359 <      suevents->Draw(drawvar.str().c_str(),drawcondition.str().c_str());
360 <      suevents->Draw(drawvar2.str().c_str(),drawcondition.str().c_str());
361 <      if(puresignal->Integral()<60) {
362 <        delete puresignal;
363 <        continue;
364 <      }
365 <      puresignal->Add(puresignall,-1);//we need to correct for the signal contamination - we effectively only see (JZB>0)-(JZB<0) !!
366 <      puresignal->Scale(ndata/(20*puresignal->Integral()));//normalizing it to 5% of the data
367 <      stringstream saveas;
368 <      saveas<<"Model_Scan/m0_"<<m0<<"__m23_"<<m23;
369 <      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;
370 < //        TH1F *signalpredlo   = allsamples.Draw("signalpredlo",  "-"+mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
371 < //        TH1F *signalpredro   = allsamples.Draw("signalpredro",      mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
372 < //        TH1F *puredata       = allsamples.Draw("puredata",          datajzb,binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data,luminosity);
373 < //        signalpred->Add(signalpredlo,-1);
374 < //        signalpred->Add(signalpredro);
375 < //        puresignal->Add(signalpred,-1);//subtracting signal contamination
376 < //---------------------
377 < //      dout << "(m0,m23)=("<<m0<<","<<m23<<") contains " << puresignal->Integral() << endl;
378 < //    TH1F *puresignal = allsamples.Draw("puresignal",mcjzb,  binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,  luminosity,allsamples.FindSample("LM4"));
379 <      vector<float> results=establish_upper_limits(puredata,allbgs,puresignal,saveas.str(),myfile);  
380 <      if(results.size()==0) {
381 <        delete puresignal;
382 <        continue;
383 <      }
384 <      exclusionmap->Fill(m23,m0,results[0]);
385 <      exclusionmap1s->Fill(m23,m0,results[1]);
386 <      exclusionmap2s->Fill(m23,m0,results[2]);
387 <      exclusionmap3s->Fill(m23,m0,results[3]);
388 <      delete puresignal;
389 <      dout << "(m0,m23)=("<<m0<<","<<m23<<") : 3 sigma at " << results[3] << endl;
390 <    }
391 <  }//end of model scan for loop
337 >
338 > /********************************************************************** new : Limits using SHAPES ***********************************
339 >
340 >
341 >   SSSSSSSSSSSSSSS hhhhhhh                                                                                      
342 > SS:::::::::::::::Sh:::::h                                                                                      
343 > S:::::SSSSSS::::::Sh:::::h                                                                                      
344 > S:::::S     SSSSSSSh:::::h                                                                                      
345 > S:::::S             h::::h hhhhh         aaaaaaaaaaaaa  ppppp   ppppppppp       eeeeeeeeeeee        ssssssssss  
346 > S:::::S             h::::hh:::::hhh      a::::::::::::a p::::ppp:::::::::p    ee::::::::::::ee    ss::::::::::s  
347 > S::::SSSS          h::::::::::::::hh    aaaaaaaaa:::::ap:::::::::::::::::p  e::::::eeeee:::::eess:::::::::::::s
348 >  SS::::::SSSSS     h:::::::hhh::::::h            a::::app::::::ppppp::::::pe::::::e     e:::::es::::::ssss:::::s
349 >    SSS::::::::SS   h::::::h   h::::::h    aaaaaaa:::::a p:::::p     p:::::pe:::::::eeeee::::::e s:::::s  ssssss
350 >       SSSSSS::::S  h:::::h     h:::::h  aa::::::::::::a p:::::p     p:::::pe:::::::::::::::::e    s::::::s      
351 >            S:::::S h:::::h     h:::::h a::::aaaa::::::a p:::::p     p:::::pe::::::eeeeeeeeeee        s::::::s  
352 >            S:::::S h:::::h     h:::::ha::::a    a:::::a p:::::p    p::::::pe:::::::e           ssssss   s:::::s
353 > SSSSSSS     S:::::S h:::::h     h:::::ha::::a    a:::::a p:::::ppppp:::::::pe::::::::e          s:::::ssss::::::s
354 > S::::::SSSSSS:::::S h:::::h     h:::::ha:::::aaaa::::::a p::::::::::::::::p  e::::::::eeeeeeee  s::::::::::::::s
355 > S:::::::::::::::SS  h:::::h     h:::::h a::::::::::aa:::ap::::::::::::::pp    ee:::::::::::::e   s:::::::::::ss  
356 > SSSSSSSSSSSSSSS    hhhhhhh     hhhhhhh  aaaaaaaaaa  aaaap::::::pppppppp        eeeeeeeeeeeeee    sssssssssss    
357 >                                                         p:::::p                                                
358 >                                                         p:::::p                                                
359 >                                                        p:::::::p                                                
360 >                                                        p:::::::p                                                
361 >                                                        p:::::::p                                                
362 >                                                        ppppppppp                                                
363 >                                                                                                                
364 >
365 > *********************************************************************** new : Limits using SHAPES ***********************************/
366 >
367 >
368 > void limit_shapes_for_systematic_effect(TFile *limfile, string identifier, string mcjzb, string datajzb, int JES,vector<float> binning, TCanvas *limcan) {
369 >  dout << "Creatig shape templates ... ";
370 >  if(identifier!="") dout << "for systematic called "<<identifier;
371 >  dout << endl;
372 >  int dataormc=mcwithsignal;//this is only for tests - for real life you want dataormc=data !!!
373 >  if(dataormc!=data) write_warning(__FUNCTION__,"WATCH OUT! Not using data for limits!!!! this is ok for tests, but not ok for anything official!");
374    
375 <  dout << "Exclusion Map contains" << exclusionmap->Integral() << " (integral) and entries: " << exclusionmap->GetEntries() << endl;
376 <  c3->cd();
377 <  exclusionmap->Draw("CONTZ");
378 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_Mean_values");
379 <  exclusionmap->Draw("COLZ");
380 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_Mean_values");
381 <  
382 <  exclusionmap1s->Draw("CONTZ");
383 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_1sigma_values");
384 <  exclusionmap1s->Draw("COLZ");
385 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_1sigma_values");
386 <  
387 <  exclusionmap2s->Draw("CONTZ");
388 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_2sigma_values");
389 <  exclusionmap2s->Draw("COLZ");
390 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_2sigma_values");
391 <  
392 <  exclusionmap3s->Draw("CONTZ");
393 <  CompleteSave(c3,"Model_Scan/CONT/Model_Scan_3sigma_values");
394 <  exclusionmap3s->Draw("COLZ");
395 <  CompleteSave(c3,"Model_Scan/COL/Model_Scan_3sigma_values");
396 <  
397 <  TFile *exclusion_limits = new TFile("exclusion_limits.root","RECREATE");
398 <  exclusionmap->Write();
399 <  exclusionmap1s->Write();
400 <  exclusionmap2s->Write();
401 <  exclusionmap3s->Write();
402 <  exclusion_limits->Close();
403 <  susyscanfile->Close();
375 >  TCut limitnJetcut;
376 >  if(JES==noJES) limitnJetcut=cutnJets;
377 >  else {
378 >    if(JES==JESdown) limitnJetcut=cutnJetsJESdown;
379 >    if(JES==JESup) limitnJetcut=cutnJetsJESup;
380 >  }
381 >  TH1F *ZOSSFP = allsamples.Draw("ZOSSFP",datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
382 >  TH1F *ZOSOFP = allsamples.Draw("ZOSOFP",datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
383 >  TH1F *ZOSSFN = allsamples.Draw("ZOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
384 >  TH1F *ZOSOFN = allsamples.Draw("ZOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
385 >  
386 >  TH1F *SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
387 >  TH1F *SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
388 >  TH1F *SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
389 >  TH1F *SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
390 >  
391 >  TH1F *LZOSSFP = allsamples.Draw("LZOSSFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
392 >  TH1F *LZOSOFP = allsamples.Draw("LZOSOFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
393 >  TH1F *LZOSSFN = allsamples.Draw("LZOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
394 >  TH1F *LZOSOFN = allsamples.Draw("LZOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
395 >  
396 >  TH1F *LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
397 >  TH1F *LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
398 >  TH1F *LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
399 >  TH1F *LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
400 >  
401 >  string obsname="data_obs";
402 >  string predname="background";
403 >  string signalname="signal";
404 >  if(identifier!="") {
405 >    obsname=("data_"+identifier);
406 >    predname=("background_"+identifier);
407 >    signalname="signal_"+identifier;
408 >  }
409    
410 <  myfile.close();
410 >  TH1F *obs = (TH1F*)ZOSSFP->Clone();
411 >  obs->SetName(obsname.c_str());
412 >  obs->Write();
413 >  TH1F *pred = (TH1F*)ZOSSFN->Clone();
414 >  pred->Add(ZOSOFP,1.0/3);
415 >  pred->Add(ZOSOFN,-1.0/3);
416 >  pred->Add(SBOSSFP,1.0/3);
417 >  pred->Add(SBOSSFN,-1.0/3);
418 >  pred->Add(SBOSOFP,1.0/3);
419 >  pred->Add(SBOSOFN,-1.0/3);
420 >  pred->SetName(predname.c_str());
421 >  pred->Write();
422 >  
423 > //  TH1F *Lobs = (TH1F*)LZOSSFP->Clone();
424 > //  TH1F *Lpred = (TH1F*)LZOSSFN->Clone();
425 >  
426 >  TH1F *Lobs = new TH1F("Lobs","Lobs",binning.size()-1,&binning[0]);
427 >  TH1F *Lpred = new TH1F("Lpred","Lpred",binning.size()-1,&binning[0]);
428 >  Lobs->Add(LZOSSFP);
429 >  Lpred->Add(LZOSSFN);
430 >  Lpred->Add(LZOSOFP,1.0/3);
431 >  Lpred->Add(LZOSOFN,-1.0/3);
432 >  Lpred->Add(LSBOSSFP,1.0/3);
433 >  Lpred->Add(LSBOSSFN,-1.0/3);
434 >  Lpred->Add(LSBOSOFP,1.0/3);
435 >  Lpred->Add(LSBOSOFN,-1.0/3);
436 >  TH1F *signal = (TH1F*)Lobs->Clone();
437 >  signal->Add(Lpred,-1);
438 >  signal->SetName(signalname.c_str());
439 >  signal->Write();
440 >  
441 >  delete Lobs;
442 >  delete Lpred;
443 >  
444 >  delete ZOSSFP;
445 >  delete ZOSOFP;
446 >  delete ZOSSFN;
447 >  delete ZOSOFN;
448 >  
449 >  delete SBOSSFP;
450 >  delete SBOSOFP;
451 >  delete SBOSSFN;
452 >  delete SBOSOFN;
453 >  
454 >  delete LZOSSFP;
455 >  delete LZOSOFP;
456 >  delete LZOSSFN;
457 >  delete LZOSOFN;
458 >  
459 >  delete LSBOSSFP;
460 >  delete LSBOSOFP;
461 >  delete LSBOSSFN;
462 >  delete LSBOSOFN;
463 >
464   }
465  
466 + void prepare_datacard(TFile *f) {
467 + TH1F *dataob = (TH1F*)f->Get("data_obs");
468 + TH1F *signal = (TH1F*)f->Get("signal");
469 + TH1F *background = (TH1F*)f->Get("background");
470 +
471 + ofstream datacard;
472 + ensure_directory_exists(get_directory()+"/limits");
473 + datacard.open ((get_directory()+"/limits/susydatacard.txt").c_str());
474 + datacard << "Writing this to a file.\n";
475 + datacard << "imax 1\n";
476 + datacard << "jmax 1\n";
477 + datacard << "kmax *\n";
478 + datacard << "---------------\n";
479 + datacard << "shapes * * limitfile.root $PROCESS $PROCESS_$SYSTEMATIC\n";
480 + datacard << "---------------\n";
481 + datacard << "bin 1\n";
482 + datacard << "observation "<<dataob->Integral()<<"\n";
483 + datacard << "------------------------------\n";
484 + datacard << "bin             1          1\n";
485 + datacard << "process         signal     background\n";
486 + datacard << "process         0          1\n";
487 + datacard << "rate            "<<signal->Integral()<<"         "<<background->Integral()<<"\n";
488 + datacard << "--------------------------------\n";
489 + datacard << "lumi     lnN    1.10       1.0\n";
490 + datacard << "bgnorm   lnN    1.00       1.4  uncertainty on our prediction (40%)\n";
491 + datacard << "JES    shape    1          1    uncertainty on background shape and normalization\n";
492 + datacard << "peak   shape    1          1    uncertainty on signal resolution. Assume the histogram is a 2 sigma shift, \n";
493 + datacard << "#                                so divide the unit gaussian by 2 before doing the interpolation\n";
494 + datacard.close();
495 + }
496  
497  
498 <
498 > void prepare_limits(string mcjzb, string datajzb, float jzbpeakerrordata, float jzbpeakerrormc, vector<float> jzbbins) {
499 >  ensure_directory_exists(get_directory()+"/limits");
500 >  TFile *limfile = new TFile((get_directory()+"/limits/limitfile.root").c_str(),"RECREATE");
501 >  TCanvas *limcan = new TCanvas("limcan","Canvas for calculating limits");
502 >  limit_shapes_for_systematic_effect(limfile,"",mcjzb,datajzb,noJES,jzbbins,limcan);
503 >  limit_shapes_for_systematic_effect(limfile,"peakUp",newjzbexpression(mcjzb,jzbpeakerrormc),newjzbexpression(datajzb,jzbpeakerrordata),noJES,jzbbins,limcan);
504 >  limit_shapes_for_systematic_effect(limfile,"peakDown",newjzbexpression(mcjzb,-jzbpeakerrormc),newjzbexpression(datajzb,-jzbpeakerrordata),noJES,jzbbins,limcan);
505 >  limit_shapes_for_systematic_effect(limfile,"JESUp",mcjzb,datajzb,JESup,jzbbins,limcan);
506 >  limit_shapes_for_systematic_effect(limfile,"JESDown",mcjzb,datajzb,JESdown,jzbbins,limcan);
507 >  
508 >  prepare_datacard(limfile);
509 >  limfile->Close();
510 >  write_info("prepare_limits","limitfile.root and datacard.txt have been generated. You can now use them to calculate limits!");
511 >  
512 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines