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.21 by buchmann, Wed Sep 14 12:02:01 2011 UTC vs.
Revision 1.28 by buchmann, Mon Nov 7 15:24:59 2011 UTC

# Line 1 | Line 1
1 + /****
2 +
3 + Off peak status (RestrictToMassPeak) :
4 +
5 + x  Necessary adaptations identified
6 + x  Started working on necessary adaptations
7 + x  Necessary adaptations implemented
8 + x  Necessary adaptations tested
9 +
10 + DONE!
11 +
12 +
13 + ****/
14   #include <iostream>
15   #include <vector>
16   #include <sys/stat.h>
# Line 170 | Line 183 | ratio_binning.push_back(80);
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;
188   /*
189   USAGE OF ROOSTATS_CL95
# Line 213 | Line 226 | USAGE OF ROOSTATS_CL95
226           - JZB cut [9]
227           - plot name  [10]*/
228  
229 <  dout << "Calling limit capsule instead of calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
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 <    command << PlottingSetup::cbafbasedir << "/DistributedModelCalculations/Limits/LimitCapsule.exec " << repname.str() << " " << luminosity << " " << luminosity*lumiuncert << " " << mceff << " " << mcefferr << " " << Npred[ibin] << " " << Nprederr[ibin] << " " << Nobs[ibin] << " " << -1 << " " << plotfilename;
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>=5)) {//try up to 5 times
239 >    while(!(retval==0||attempts>=3)) {//try up to 3 times
240          attempts++;
241 <        dout << "Starting limit calculation (LimitCapsule) now : Attempt " << attempts << endl;
241 >        dout << "Starting limit calculation (TimedLimitCapsule) now : Attempt " << attempts << endl;
242          retval=gSystem->Exec(command.str().c_str());
243      }
244      
# Line 231 | Line 246 | USAGE OF ROOSTATS_CL95
246      limres.readDroplet(repname.str());
247      dout << limres << endl;
248      remove(repname.str().c_str());
249 <    sigma95=limres.expected;
249 >    sigma95=limres.observed;
250  
251      
252      ///------------------------------------------ < /NEW > ----------------------------------------------------------
238    //if(doobserved) nlimittoysused=nlimittoys;
239 //    nlimittoysused=nlimittoys;
240 //  dout << "Now calling : CL95(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << Nobs[ibin] << "," << false << "," << nuisancemodel<< ") " << endl;
241 //  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
242 //  sigma95 = CL95(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], Nobs[ibin], false, nuisancemodel);
243  
244 /*  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;
245 /*  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;
246  LimitResult limit = roostats_limit(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0);
247  dout << "Now interpreting and saving results ... " << endl;
248  vector<float> sigmas;
249  sigmas.push_back(limit.GetExpectedLimit());//expected
250  sigmas.push_back(limit.GetObservedLimit());//observed
251  //up to here for backward compatibility
252  sigmas.push_back(limit.GetOneSigmaHighRange());//expected, up
253  sigmas.push_back(limit.GetTwoSigmaHighRange());//expected, 2 up
254  sigmas.push_back(limit.GetOneSigmaLowRange());//expected, down
255  sigmas.push_back(limit.GetTwoSigmaLowRange());//expected, 2 down
256 */
257 //  float limit = roostats_cl95(luminosity,lumiuncert*luminosity,mceff,mcefferr,Npred[ibin],Nprederr[ibin],nlimittoysused,false,nuisancemodel,limitmethod,plotfilename,0);
258  if(doobserved) {
259 write_warning(__FUNCTION__,"OBSERVED LIMITS HAVE BEEN SWITCHED OFF TEMPORARILY");
260 //    dout << "Now calling : CLA(" << luminosity << "," <<  lumiuncert*luminosity << "," << mceff << "," << mcefferr << "," << Npred[ibin] << "," << Nprederr[ibin] << "," << nuisancemodel<< ") " << endl;
261 //    sigma95A = CLA(luminosity, lumiuncert*luminosity, mceff, mcefferr, Npred[ibin], Nprederr[ibin], nuisancemodel);
262  }
263 //  vector<float> sigmas;
264 //  sigmas.push_back(limit);
253    vector<float> sigmas;
254    sigmas.push_back(sigma95);
255 <  sigmas.push_back(sigma95A);
255 >  if(doexpected) {
256 >    sigmas.push_back(limres.expected);
257 >    sigmas.push_back(limres.upper68);
258 >    sigmas.push_back(limres.lower68);
259 >    sigmas.push_back(limres.upper95);
260 >    sigmas.push_back(limres.lower95);
261 >  }
262 >  
263    return sigmas;
264    
265  
266 <  }
272 <  write_warning(__FUNCTION__,"STILL MISSING SIGMAS, LIMITS, EVERYTHING ...");
266 >  }//end of mc efficiency is ok
267   }
268  
269 < void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doobserved) {
269 > void compute_upper_limits_from_counting_experiment(vector<vector<float> > uncertainties,vector<float> jzbcuts, string mcjzb, bool doexpected, int flipped) {
270    dout << "Doing counting experiment ... " << endl;
271    vector<vector<string> > limits;
272    vector<vector<float> > vlimits;
# Line 297 | Line 291 | void compute_upper_limits_from_counting_
291   //      float expected=observed/luminosity;
292        string plotfilename=(string)(TString(signalsamples.collection[isample].samplename)+TString("___JZB_geq_")+TString(any2string(JZBcutat))+TString(".png"));
293        dout << "Sample: " << signalsamples.collection[isample].samplename << ", JZB>"<<JZBcutat<< " : " << mceff << " +/- " << staterr << " (stat) +/- " << systerr << " (syst) --> toterr = " << toterr << endl;
294 <      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doobserved);
294 >      vector<float> sigmas = compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,doexpected,flipped);
295        
296 <      if(doobserved) {
296 >      if(doexpected) {
297   //      rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(expected)+")");
298          rows.push_back(any2string(sigmas[0])+";"+any2string(sigmas[1])+";"+"("+any2string(signalsamples.collection[isample].xs)+")");
299          vrows.push_back(sigmas[0]);
# Line 333 | Line 327 | void compute_upper_limits_from_counting_
327      dout << endl;
328    }
329    
330 <  if(!doobserved) {
330 >  if(!doexpected) {
331      dout << endl << endl << "LIMITS: (Tex)" << endl;
332      tout << "\\begin{table}[hbtp]" << endl;
333      tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
# Line 372 | Line 366 | void compute_upper_limits_from_counting_
366      }
367      dout << endl;
368    }
375  
376  write_warning(__FUNCTION__,"Still need to update the script");
369   }
370  
371  
# Line 426 | Line 418 | void limit_shapes_for_systematic_effect(
418    TH1F *ZOSSFN = allsamples.Draw("ZOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,dataormc,luminosity);
419    TH1F *ZOSOFN = allsamples.Draw("ZOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,dataormc,luminosity);
420    
421 <  TH1F *SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
422 <  TH1F *SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
423 <  TH1F *SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
424 <  TH1F *SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
421 >  TH1F *SBOSSFP;
422 >  TH1F *SBOSOFP;
423 >  TH1F *SBOSSFN;
424 >  TH1F *SBOSOFN;
425    
426    TH1F *LZOSSFP = allsamples.Draw("LZOSSFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
427    TH1F *LZOSOFP = allsamples.Draw("LZOSOFP",mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
428    TH1F *LZOSSFN = allsamples.Draw("LZOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
429    TH1F *LZOSOFN = allsamples.Draw("LZOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,mc,luminosity,allsamples.FindSample("LM4"));
430    
431 <  TH1F *LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
432 <  TH1F *LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
433 <  TH1F *LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
434 <  TH1F *LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
431 >  TH1F *LSBOSSFP;
432 >  TH1F *LSBOSOFP;
433 >  TH1F *LSBOSSFN;
434 >  TH1F *LSBOSOFN;
435 >  
436 >  flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
437 >  if(PlottingSetup::RestrictToMassPeak) {
438 >      SBOSSFP = allsamples.Draw("SBOSSFP",datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
439 >      SBOSOFP = allsamples.Draw("SBOSOFP",datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
440 >      SBOSSFN = allsamples.Draw("SBOSSFN","-"+datajzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
441 >      SBOSOFN = allsamples.Draw("SBOSOFN","-"+datajzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,dataormc,luminosity);
442 >      
443 >      LSBOSSFP = allsamples.Draw("LSBOSSFP",mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
444 >      LSBOSOFP = allsamples.Draw("LSBOSOFP",mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
445 >      LSBOSSFN = allsamples.Draw("LSBOSSFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSSF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
446 >      LSBOSOFN = allsamples.Draw("LSBOSOFN","-"+mcjzb,binning, "JZB4limits", "events",cutOSOF&&limitnJetcut&&basiccut&&sidebandcut,mc,luminosity,allsamples.FindSample("LM4"));
447 >  }
448    
449    string obsname="data_obs";
450    string predname="background";
# Line 450 | Line 455 | void limit_shapes_for_systematic_effect(
455      signalname="signal_"+identifier;
456    }
457    
458 <  TH1F *obs = (TH1F*)ZOSSFP->Clone();
458 >  TH1F *obs = (TH1F*)ZOSSFP->Clone("observation");
459    obs->SetName(obsname.c_str());
460    obs->Write();
461 <  TH1F *pred = (TH1F*)ZOSSFN->Clone();
462 <  pred->Add(ZOSOFP,1.0/3);
463 <  pred->Add(ZOSOFN,-1.0/3);
464 <  pred->Add(SBOSSFP,1.0/3);
465 <  pred->Add(SBOSSFN,-1.0/3);
466 <  pred->Add(SBOSOFP,1.0/3);
467 <  pred->Add(SBOSOFN,-1.0/3);
461 >  TH1F *pred = (TH1F*)ZOSSFN->Clone("prediction");
462 >    flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
463 >  if(PlottingSetup::RestrictToMassPeak) {
464 >    pred->Add(ZOSOFP,1.0/3);
465 >    pred->Add(ZOSOFN,-1.0/3);
466 >    pred->Add(SBOSSFP,1.0/3);
467 >    pred->Add(SBOSSFN,-1.0/3);
468 >    pred->Add(SBOSOFP,1.0/3);
469 >    pred->Add(SBOSOFN,-1.0/3);
470 >  } else {
471 >    pred->Add(ZOSOFP,1.0);
472 >    pred->Add(ZOSOFN,-1.0);
473 >  }
474 >    
475    pred->SetName(predname.c_str());
476    pred->Write();
477    
# Line 470 | Line 482 | void limit_shapes_for_systematic_effect(
482    TH1F *Lpred = new TH1F("Lpred","Lpred",binning.size()-1,&binning[0]);
483    Lobs->Add(LZOSSFP);
484    Lpred->Add(LZOSSFN);
485 <  Lpred->Add(LZOSOFP,1.0/3);
486 <  Lpred->Add(LZOSOFN,-1.0/3);
487 <  Lpred->Add(LSBOSSFP,1.0/3);
488 <  Lpred->Add(LSBOSSFN,-1.0/3);
489 <  Lpred->Add(LSBOSOFP,1.0/3);
490 <  Lpred->Add(LSBOSOFN,-1.0/3);
485 >    flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
486 >  if(PlottingSetup::RestrictToMassPeak) {
487 >    Lpred->Add(LZOSOFP,1.0/3);
488 >    Lpred->Add(LZOSOFN,-1.0/3);
489 >    Lpred->Add(LSBOSSFP,1.0/3);
490 >    Lpred->Add(LSBOSSFN,-1.0/3);
491 >    Lpred->Add(LSBOSOFP,1.0/3);
492 >    Lpred->Add(LSBOSOFN,-1.0/3);
493 >  } else {
494 >    Lpred->Add(LZOSOFP,1.0);
495 >    Lpred->Add(LZOSOFN,-1.0);
496 >  }
497 >
498    TH1F *signal = (TH1F*)Lobs->Clone();
499    signal->Add(Lpred,-1);
500    signal->SetName(signalname.c_str());
# Line 489 | Line 508 | void limit_shapes_for_systematic_effect(
508    delete ZOSSFN;
509    delete ZOSOFN;
510    
511 <  delete SBOSSFP;
512 <  delete SBOSOFP;
513 <  delete SBOSSFN;
514 <  delete SBOSOFN;
511 >  if(PlottingSetup::RestrictToMassPeak) {
512 >    delete SBOSSFP;
513 >    delete SBOSOFP;
514 >    delete SBOSSFN;
515 >    delete SBOSOFN;
516 >  }
517    
518    delete LZOSSFP;
519    delete LZOSOFP;
520    delete LZOSSFN;
521    delete LZOSOFN;
522    
523 <  delete LSBOSSFP;
524 <  delete LSBOSOFP;
525 <  delete LSBOSSFN;
526 <  delete LSBOSOFN;
523 >  if(PlottingSetup::RestrictToMassPeak) {
524 >    delete LSBOSSFP;
525 >    delete LSBOSOFP;
526 >    delete LSBOSSFN;
527 >    delete LSBOSOFN;
528 >  }
529  
530   }
531  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines