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.8 by buchmann, Wed Jul 27 12:16:15 2011 UTC vs.
Revision 1.25 by buchmann, Mon Sep 26 15:48:20 2011 UTC

# Line 15 | 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 168 | Line 170 | ratio_binning.push_back(80);
170    
171   }
172  
173 < vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, bool doobserved=false) {
174 <  float sigma95=0.0,sigma95A=0.0;
175 <  int nuisancemodel=1;
176 <  dout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
177 <  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
178 <  if(doobserved) {
179 <    dout << "Now calling : CLA(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << nuisancemodel<< ") " << endl;
180 <    sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], nuisancemodel);
181 <  }
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 >    stringstream command;
219 >    command << PlottingSetup::cbafbasedir << "/DistributedModelCalculations/Limits/NewLimitCapsule.exec " << repname.str() << " " << luminosity << " " << luminosity*lumiuncert << " " << mceff << " " << mcefferr << " " << Npred[ibin] << " " << Nprederr[ibin] << " " << Nobs[ibin] << " " << -1 << " " << PlottingSetup::basedirectory << "/" << plotfilename << " " << doexpected;
220 >    dout << command.str() << endl;
221 >    
222 >    int retval = 256;
223 >    int attempts=0;
224 >    while(!(retval==0||attempts>=5)) {//try up to 5 times
225 >        attempts++;
226 >        dout << "Starting limit calculation (LimitCapsule) now : Attempt " << attempts << endl;
227 >        retval=gSystem->Exec(command.str().c_str());
228 >    }
229 >    
230 >    LimitDroplet limres;
231 >    limres.readDroplet(repname.str());
232 >    dout << limres << endl;
233 >    remove(repname.str().c_str());
234 >    sigma95=limres.observed;
235 >
236 >    
237 >    ///------------------------------------------ < /NEW > ----------------------------------------------------------
238    vector<float> sigmas;
239    sigmas.push_back(sigma95);
240 <  sigmas.push_back(sigma95A);
240 >  if(doexpected) {
241 >    sigmas.push_back(limres.expected);
242 >    sigmas.push_back(limres.upper68);
243 >    sigmas.push_back(limres.lower68);
244 >    sigmas.push_back(limres.upper95);
245 >    sigmas.push_back(limres.lower95);
246 >  }
247 >  
248    return sigmas;
249 +  
250 +
251 +  }//end of mc efficiency is ok
252   }
253  
254 < void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doobserved) {
254 > void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doexpected) {
255    dout << "Doing counting experiment ... " << endl;
256    vector<vector<string> > limits;
257    vector<vector<float> > vlimits;
# Line 201 | Line 269 | void compute_upper_limits_from_counting_
269        float staterr=uncertainties[isample*jzbcuts.size()+ibin][2];
270        float systerr=uncertainties[isample*jzbcuts.size()+ibin][3];
271        float toterr =uncertainties[isample*jzbcuts.size()+ibin][4];
272 <      float observed,null,result;
205 <      fill_result_histos(observed, null,null,null,null,null,null,null,mcjzb,JZBcutat,(int)5,result,(signalsamples.FindSample(signalsamples.collection[isample].filename)),signalsamples);
206 <      observed-=result;//this is the actual excess we see!
207 <      float expected=observed/luminosity;
272 >      float observed,observederr,null,result;
273        
274 + //      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);
275 + //      observed-=result;//this is the actual excess we see!
276 + //      float expected=observed/luminosity;
277 +      string plotfilename=(string)(TString(signalsamples.collection[isample].samplename)+TString("___JZB_geq_")+TString(any2string(JZBcutat))+TString(".png"));
278        dout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl;
279 <      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,doobserved);
279 >      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doexpected);
280        
281 <      if(doobserved) {
282 <        rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
281 >      if(doexpected) {
282 > //      rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
283 >        rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(signalsamples.collection[isample].xs)+")");
284          vrows.push_back(sigmas[0]);
285          vrows.push_back(sigmas[1]);
286 <        vrows.push_back(expected);
286 > //      vrows.push_back(expected);
287 >        vrows.push_back(signalsamples.collection[isample].xs);
288        }
289        else {
290 <        rows.push_back(any2string(sigmas[0])+"("+any2string(expected)+")");
290 > //      rows.push_back(any2string(sigmas[0])+"("+any2string(expected)+")");
291 >        rows.push_back(any2string(sigmas[0]));
292          vrows.push_back(sigmas[0]);
293 <        vrows.push_back(expected);
293 >        vrows.push_back(signalsamples.collection[isample].xs);
294 > //      vrows.push_back(expected);
295        }
296      }//end of bin loop
297      limits.push_back(rows);
298      vlimits.push_back(vrows);
299    }//end of sample loop
300 <  dout << endl << endl << "PAS table 3: " << endl << endl;
300 >  dout << endl << endl << endl << "_________________________________________________________________________________________________" << endl << endl;
301 >  dout << endl << endl << "PAS table 3:   (notation: limit [95%CL])" << endl << endl;
302    dout << "\t";
303    for (int irow=0;irow<jzbcuts.size();irow++) {
304      dout << jzbcuts[irow] << "\t";
# Line 232 | Line 306 | void compute_upper_limits_from_counting_
306    dout << endl;
307    for(int irow=0;irow<limits.size();irow++) {
308      for(int ientry=0;ientry<limits[irow].size();ientry++) {
309 <      dout << limits[irow][ientry] << "\t";
309 >      if (limits[irow][ientry]>0) dout << limits[irow][ientry] << "\t";
310 >      else dout << " (N/A) \t";
311      }
312      dout << endl;
313    }
314    
315 <  if(!doobserved) {
316 <    dout << endl << endl << "LIMITS: " << endl;
317 <    dout << "\t";
315 >  if(!doexpected) {
316 >    dout << endl << endl << "LIMITS: (Tex)" << endl;
317 >    tout << "\\begin{table}[hbtp]" << endl;
318 >    tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
319 >    tout << "\\begin{center}" << endl;
320 >    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;
321 >    tout << "" << endl;
322 >    tout << "\\begin{tabular}{ | l | ";
323 >    for (int irow=0;irow<jzbcuts.size();irow++) tout << " l |";
324 >    tout << "} " << endl << " \\hline " << endl << "& \t ";
325      for (int irow=0;irow<jzbcuts.size();irow++) {
326 <      dout << jzbcuts[irow] << "\t";
326 >      tout << "JZB $>$ " << jzbcuts[irow] << " GeV & \t ";
327      }
328 <    dout << endl;
328 >    tout << " \\\\ \\hline " << endl;
329      for(int irow=0;irow<limits.size();irow++) {
330 <      dout << limits[irow][0] << "\t";
330 >      tout << limits[irow][0] << " \t";
331        for(int ientry=0;ientry<jzbcuts.size();ientry++) {
332 <        dout << Round(vlimits[irow][2*ientry] / vlimits[irow][2*ientry+1],3)<< "\t";
332 >        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";
333 >        else tout << " & ( N / A ) \t";
334 > //      dout << Round(vlimits[irow][2*ientry],3) << " / " << Round(vlimits[irow][2*ientry+1],3)<< "\t";
335        }
336 <      dout << endl;
336 >      tout << " \\\\ \\hline " << endl;
337      }
338 +      tout << "\\end{tabular}" << endl;
339 +      tout << "      \\end{tabular}"<< endl;
340 +      tout << "\\end{center}"<< endl;
341 +      tout << "\\end{table} "<< endl;
342 +
343    }//do observed
344    
345    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;
346 <  dout << "Scenario \t Efficiency [%] \t Upper limits [pb] \t Prediction [pb]" << endl;
346 >  dout << "Scenario \t Efficiency [%] \t Upper limits [pb] \t \\sigma [pb]" << endl;
347    for(int icut=0;icut<jzbcuts.size();icut++) {
348 <    dout << "Region with JZB>" << jzbcuts[icut] << endl;
348 >    dout << "Region with JZB>" << jzbcuts[icut] << (ConsiderSignalContaminationForLimits?"  (accounting for signal contamination)":"  (not accounting for signal contamination)") << endl;
349      for(int isample=0;isample<signalsamples.collection.size();isample++) {
350 <      dout << limits[isample][0] << "\t" << Round(100*uncertainties[isample*jzbcuts.size()+icut][1],1) << "+/-" << Round(100*uncertainties[isample*jzbcuts.size()+icut][2],1) << " (stat) +/- " << Round(100*uncertainties[isample*jzbcuts.size()+icut][3],1) << " (syst) \t" << Round((vlimits[isample][2*icut]),3) << "\t" << Round(vlimits[isample][2*icut+1],3) << endl;
350 >      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;
351      }
352      dout << endl;
353    }
265  
266  write_warning("compute_upper_limits_from_counting_experiment","Still need to update the script");
354   }
355  
356  
# Line 442 | Line 529 | void prepare_limits(string mcjzb, string
529    limfile->Close();
530    write_info("prepare_limits","limitfile.root and datacard.txt have been generated. You can now use them to calculate limits!");
531    
532 < }
532 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines