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> |
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; |
183 |
|
|
184 |
|
} |
185 |
|
|
186 |
< |
vector<float> compute_one_upper_limit(float mceff,float mcefferr, int ibin, string mcjzb, string plotfilename, bool doobserved) { |
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; |
173 |
– |
int nuisancemodel=0; |
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" |
208 |
|
return sigmas; |
209 |
|
} else { |
210 |
|
int nlimittoysused=1; |
211 |
< |
//if(doobserved) nlimittoysused=nlimittoys; |
212 |
< |
nlimittoysused=nlimittoys; |
213 |
< |
dout << "Now calling : CL95(" << luminosity << "," << lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl; |
214 |
< |
sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel); |
215 |
< |
|
216 |
< |
/* 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; |
217 |
< |
/* 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; |
218 |
< |
LimitResult limit = roostats_limit(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0); |
219 |
< |
dout << "Now interpreting and saving results ... " << endl; |
220 |
< |
vector<float> sigmas; |
221 |
< |
sigmas.push_back(limit.GetExpectedLimit());//expected |
222 |
< |
sigmas.push_back(limit.GetObservedLimit());//observed |
223 |
< |
//up to here for backward compatibility |
224 |
< |
sigmas.push_back(limit.GetOneSigmaHighRange());//expected, up |
225 |
< |
sigmas.push_back(limit.GetTwoSigmaHighRange());//expected, 2 up |
226 |
< |
sigmas.push_back(limit.GetOneSigmaLowRange());//expected, down |
227 |
< |
sigmas.push_back(limit.GetTwoSigmaLowRange());//expected, 2 down |
228 |
< |
*/ |
229 |
< |
// float limit = roostats_cl95(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0); |
230 |
< |
if(doobserved) { |
231 |
< |
dout << "Now calling : CLA(" << luminosity << "," << lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << nuisancemodel<< ") " << endl; |
232 |
< |
sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], nuisancemodel); |
233 |
< |
} |
234 |
< |
// vector<float> sigmas; |
235 |
< |
// sigmas.push_back(limit); |
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 |
> |
string completehostname=GetCompleteHostname(); |
246 |
> |
gethostname(hostname,1023); |
247 |
> |
if((!((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))))&&retval==256) { |
248 |
> |
//running via CRAB and encountered the same problem too often: place a problem file to mark this problem! |
249 |
> |
stringstream markproblem; |
250 |
> |
markproblem << "touch " << PlottingSetup::basedirectory << "/exchange/problemswhilesettinglimits.txt"; |
251 |
> |
gSystem->Exec(markproblem.str().c_str()); |
252 |
> |
} |
253 |
> |
LimitDroplet limres; |
254 |
> |
limres.readDroplet(repname.str()); |
255 |
> |
dout << limres << endl; |
256 |
> |
remove(repname.str().c_str()); |
257 |
> |
sigma95=limres.observed; |
258 |
> |
|
259 |
> |
|
260 |
> |
///------------------------------------------ < /NEW > ---------------------------------------------------------- |
261 |
|
vector<float> sigmas; |
262 |
|
sigmas.push_back(sigma95); |
263 |
< |
sigmas.push_back(sigma95A); |
263 |
> |
if(doexpected) { |
264 |
> |
sigmas.push_back(limres.expected); |
265 |
> |
sigmas.push_back(limres.upper68); |
266 |
> |
sigmas.push_back(limres.lower68); |
267 |
> |
sigmas.push_back(limres.upper95); |
268 |
> |
sigmas.push_back(limres.lower95); |
269 |
> |
} |
270 |
> |
|
271 |
|
return sigmas; |
272 |
|
|
273 |
|
|
274 |
< |
} |
229 |
< |
write_warning(__FUNCTION__,"STILL MISSING SIGMAS, LIMITS, EVERYTHING ..."); |
274 |
> |
}//end of mc efficiency is ok |
275 |
|
} |
276 |
|
|
277 |
< |
void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doobserved) { |
277 |
> |
void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doexpected, int flipped) { |
278 |
|
dout << "Doing counting experiment ... " << endl; |
279 |
|
vector<vector<string> > limits; |
280 |
|
vector<vector<float> > vlimits; |
299 |
|
// float expected=observed/luminosity; |
300 |
|
string plotfilename=(string)(TString(signalsamples.collection[isample].samplename)+TString("___JZB_geq_")+TString(any2string(JZBcutat))+TString(".png")); |
301 |
|
dout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl; |
302 |
< |
vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doobserved); |
302 |
> |
vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doexpected,flipped); |
303 |
|
|
304 |
< |
if(doobserved) { |
304 |
> |
if(doexpected) { |
305 |
|
// rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")"); |
306 |
|
rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(signalsamples.collection[isample].xs)+")"); |
307 |
|
vrows.push_back(sigmas[0]); |
335 |
|
dout << endl; |
336 |
|
} |
337 |
|
|
338 |
< |
if(!doobserved) { |
338 |
> |
if(!doexpected) { |
339 |
|
dout << endl << endl << "LIMITS: (Tex)" << endl; |
340 |
|
tout << "\\begin{table}[hbtp]" << endl; |
341 |
< |
tout << "\\renewcommand{\arraystretch}{1.3}" << endl; |
341 |
> |
tout << "\\renewcommand{\\arraystretch}{1.3}" << endl; |
342 |
|
tout << "\\begin{center}" << endl; |
343 |
|
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; |
344 |
|
tout << "" << endl; |
374 |
|
} |
375 |
|
dout << endl; |
376 |
|
} |
332 |
– |
|
333 |
– |
write_warning(__FUNCTION__,"Still need to update the script"); |
377 |
|
} |
378 |
|
|
379 |
|
|
426 |
|
TH1F *ZOSSFN = allsamples.Draw("ZOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity); |
427 |
|
TH1F *ZOSOFN = allsamples.Draw("ZOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity); |
428 |
|
|
429 |
< |
TH1F *SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
430 |
< |
TH1F *SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
431 |
< |
TH1F *SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
432 |
< |
TH1F *SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
429 |
> |
TH1F *SBOSSFP; |
430 |
> |
TH1F *SBOSOFP; |
431 |
> |
TH1F *SBOSSFN; |
432 |
> |
TH1F *SBOSOFN; |
433 |
|
|
434 |
|
TH1F *LZOSSFP = allsamples.Draw("LZOSSFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4")); |
435 |
|
TH1F *LZOSOFP = allsamples.Draw("LZOSOFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4")); |
436 |
|
TH1F *LZOSSFN = allsamples.Draw("LZOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4")); |
437 |
|
TH1F *LZOSOFN = allsamples.Draw("LZOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4")); |
438 |
|
|
439 |
< |
TH1F *LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
440 |
< |
TH1F *LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
441 |
< |
TH1F *LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
442 |
< |
TH1F *LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
439 |
> |
TH1F *LSBOSSFP; |
440 |
> |
TH1F *LSBOSOFP; |
441 |
> |
TH1F *LSBOSSFN; |
442 |
> |
TH1F *LSBOSOFN; |
443 |
> |
|
444 |
> |
flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak |
445 |
> |
if(PlottingSetup::RestrictToMassPeak) { |
446 |
> |
SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
447 |
> |
SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
448 |
> |
SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
449 |
> |
SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity); |
450 |
> |
|
451 |
> |
LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
452 |
> |
LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
453 |
> |
LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
454 |
> |
LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4")); |
455 |
> |
} |
456 |
|
|
457 |
|
string obsname="data_obs"; |
458 |
|
string predname="background"; |
463 |
|
signalname="signal_"+identifier; |
464 |
|
} |
465 |
|
|
466 |
< |
TH1F *obs = (TH1F*)ZOSSFP->Clone(); |
466 |
> |
TH1F *obs = (TH1F*)ZOSSFP->Clone("observation"); |
467 |
|
obs->SetName(obsname.c_str()); |
468 |
|
obs->Write(); |
469 |
< |
TH1F *pred = (TH1F*)ZOSSFN->Clone(); |
470 |
< |
pred->Add(ZOSOFP,1.0/3); |
471 |
< |
pred->Add(ZOSOFN,-1.0/3); |
472 |
< |
pred->Add(SBOSSFP,1.0/3); |
473 |
< |
pred->Add(SBOSSFN,-1.0/3); |
474 |
< |
pred->Add(SBOSOFP,1.0/3); |
475 |
< |
pred->Add(SBOSOFN,-1.0/3); |
469 |
> |
TH1F *pred = (TH1F*)ZOSSFN->Clone("prediction"); |
470 |
> |
flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak |
471 |
> |
if(PlottingSetup::RestrictToMassPeak) { |
472 |
> |
pred->Add(ZOSOFP,1.0/3); |
473 |
> |
pred->Add(ZOSOFN,-1.0/3); |
474 |
> |
pred->Add(SBOSSFP,1.0/3); |
475 |
> |
pred->Add(SBOSSFN,-1.0/3); |
476 |
> |
pred->Add(SBOSOFP,1.0/3); |
477 |
> |
pred->Add(SBOSOFN,-1.0/3); |
478 |
> |
} else { |
479 |
> |
pred->Add(ZOSOFP,1.0); |
480 |
> |
pred->Add(ZOSOFN,-1.0); |
481 |
> |
} |
482 |
> |
|
483 |
|
pred->SetName(predname.c_str()); |
484 |
|
pred->Write(); |
485 |
|
|
490 |
|
TH1F *Lpred = new TH1F("Lpred","Lpred",binning.size()-1,&binning[0]); |
491 |
|
Lobs->Add(LZOSSFP); |
492 |
|
Lpred->Add(LZOSSFN); |
493 |
< |
Lpred->Add(LZOSOFP,1.0/3); |
494 |
< |
Lpred->Add(LZOSOFN,-1.0/3); |
495 |
< |
Lpred->Add(LSBOSSFP,1.0/3); |
496 |
< |
Lpred->Add(LSBOSSFN,-1.0/3); |
497 |
< |
Lpred->Add(LSBOSOFP,1.0/3); |
498 |
< |
Lpred->Add(LSBOSOFN,-1.0/3); |
493 |
> |
flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak |
494 |
> |
if(PlottingSetup::RestrictToMassPeak) { |
495 |
> |
Lpred->Add(LZOSOFP,1.0/3); |
496 |
> |
Lpred->Add(LZOSOFN,-1.0/3); |
497 |
> |
Lpred->Add(LSBOSSFP,1.0/3); |
498 |
> |
Lpred->Add(LSBOSSFN,-1.0/3); |
499 |
> |
Lpred->Add(LSBOSOFP,1.0/3); |
500 |
> |
Lpred->Add(LSBOSOFN,-1.0/3); |
501 |
> |
} else { |
502 |
> |
Lpred->Add(LZOSOFP,1.0); |
503 |
> |
Lpred->Add(LZOSOFN,-1.0); |
504 |
> |
} |
505 |
> |
|
506 |
|
TH1F *signal = (TH1F*)Lobs->Clone(); |
507 |
|
signal->Add(Lpred,-1); |
508 |
|
signal->SetName(signalname.c_str()); |
516 |
|
delete ZOSSFN; |
517 |
|
delete ZOSOFN; |
518 |
|
|
519 |
< |
delete SBOSSFP; |
520 |
< |
delete SBOSOFP; |
521 |
< |
delete SBOSSFN; |
522 |
< |
delete SBOSOFN; |
519 |
> |
if(PlottingSetup::RestrictToMassPeak) { |
520 |
> |
delete SBOSSFP; |
521 |
> |
delete SBOSOFP; |
522 |
> |
delete SBOSSFN; |
523 |
> |
delete SBOSOFN; |
524 |
> |
} |
525 |
|
|
526 |
|
delete LZOSSFP; |
527 |
|
delete LZOSOFP; |
528 |
|
delete LZOSSFN; |
529 |
|
delete LZOSOFN; |
530 |
|
|
531 |
< |
delete LSBOSSFP; |
532 |
< |
delete LSBOSOFP; |
533 |
< |
delete LSBOSSFN; |
534 |
< |
delete LSBOSOFN; |
531 |
> |
if(PlottingSetup::RestrictToMassPeak) { |
532 |
> |
delete LSBOSSFP; |
533 |
> |
delete LSBOSOFP; |
534 |
> |
delete LSBOSSFN; |
535 |
> |
delete LSBOSOFN; |
536 |
> |
} |
537 |
|
|
538 |
|
} |
539 |
|
|