ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/GeneralToolBox.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/GeneralToolBox.C (file contents):
Revision 1.2 by buchmann, Thu Feb 16 16:04:58 2012 UTC vs.
Revision 1.22 by fronga, Tue Nov 13 13:27:37 2012 UTC

# Line 17 | Line 17
17   #include <netdb.h>
18   #include <stdio.h>
19   #include <string.h>
20 + #include <assert.h>
21  
22   #include <TFile.h>
23   #include <TTree.h>
# Line 38 | Line 39
39   #include <TPaveText.h>
40   #include <TRandom.h>
41   #include <TGraphErrors.h>
42 + #include <TROOT.h>
43   #ifndef Verbosity
44   #define Verbosity 0
45   #endif
# Line 58 | Line 60 | namespace PlottingSetup {
60      vector<float> global_ratio_binning;
61      int publicmode=0;
62      int PaperMode=0; // PaperMode=true will suppress "Preliminary" in DrawPrelim()
63 +    int Approved=0; // Approved=true will only plot approved plots
64 +    bool is2012=true;
65 +    bool is53reco=true;
66 +    bool openBox = true;
67   }
68  
69   bool dopng=false;
# Line 119 | Line 125 | string topdir(string child) {
125          return tempdirectory.substr(0,ichar);
126        }
127      }
128 +    return "TOPDIRFAILURE";
129   }
130  
131   template < typename CHAR_TYPE,
# Line 250 | Line 257 | void ensure_directory_exists(string this
257    }
258   }
259  
260 + void DeadEnd(string message) {
261 +  dout << endl;
262 +  dout << "\033[1;31m     _                _                  _  " << endl;
263 +  dout << "\033[1;31m  __| | ___  __ _  __| |   ___ _ __   __| | " << endl;
264 +  dout << "\033[1;31m / _` |/ _ \\/ _` |/ _` |  / _ \\ '_ \\ / _` | " << endl;
265 +  dout << "\033[1;31m| (_| |  __/ (_| | (_| | |  __/ | | | (_| | " << endl;
266 +  dout << "\033[1;31m \\__,_|\\___|\\__,_|\\__,_|  \\___|_| |_|\\__,_| " << endl;
267 +  dout << "\033[1;31m                                            " << endl;
268 +  dout << "" << endl;
269 +  dout << " A totally fatal error has occurred: " << endl;
270 +  dout << " " << message << endl;
271 +  dout << endl;
272 +  dout << "If you do not know how to deal with this error message please call Customer Support Mumbai (or Zurich...) \033[0m" << endl;
273 +  dout << "   ... aborting now ... " << endl;
274 +  assert(0);
275 + }
276 +
277 +
278 + void SanityChecks() {
279 +  //this function gets called whenever samples are initialized (see ActiveSamples.C)
280 +  //whatever is necessary for the code to run should be put here.
281 +  
282 +  if(gROOT->GetVersionInt()<53200) {
283 +    DeadEnd("ROOT version outdated, you are using "+any2string(gROOT->GetVersionInt())+" but the earliest recommended version is 5.32.00");
284 +  }
285 +  
286 +  
287 + }
288 +
289   void initialize_log() {
290    if(!PlottingSetup::publicmode) {
291      dout << "____________________________________________________________" << endl;
# Line 278 | Line 314 | void initialize_log() {
314      dout << "        PUBLIC MODE     " << endl;
315    }
316    time_t rawtime;
281  struct tm * timeinfo;
317    time ( &rawtime );
318    dout << "       Analysis run on " << asctime (localtime ( &rawtime ));
319    dout << "____________________________________________________________" << endl;
# Line 289 | Line 324 | void extract_cbaf_dir(string curpath) {
324    int position=curpath.find("/Plotting");
325    if(position<0) position=curpath.find("/DistributedModelCalculations");
326    if(position<0) position=curpath.find("/various_assignments");
327 +  if(position<0) position=curpath.find("/exchange");
328    PlottingSetup::cbafbasedir=curpath.substr(0,position);
329   }
330  
# Line 296 | Line 332 | void set_directory(string basedir="") {
332    if(basedir.substr(0,1)=="/") basedir=basedir.substr(1,basedir.length()-1);
333    if(basedir.substr(basedir.length()-1,1)!="/") basedir+="/";
334    char currentpath[1024];
335 <  char *path = getcwd(currentpath,1024);
335 >  getcwd(currentpath,1024);
336    PlottingSetup::basedirectory=(string)currentpath+"/Plots/"+basedir;
337    ensure_directory_exists(PlottingSetup::basedirectory);
338    initialize_log();
# Line 321 | Line 357 | string extract_directory(string savethis
357   string extract_root_dir(string name) {
358      int position = -1;
359      if(name.substr(0,1)=="/") name=name.substr(1,name.length()-1);
360 <    for(int ipos=0;ipos<name.length();ipos++) {
360 >    for(int ipos=0;ipos<(int)name.length();ipos++) {
361          if(name.substr(ipos,1)=="/") position=ipos;
362      }
363      if(position==-1) return "";
# Line 331 | Line 367 | string extract_root_dir(string name) {
367   string extract_root_filename(string name) {
368      int position = -1;
369      if(name.substr(0,1)=="/") name=name.substr(1,name.length()-1);
370 <    for(int ipos=0;ipos<name.length();ipos++) {
370 >    for(int ipos=0;ipos<(int)name.length();ipos++) {
371          if(name.substr(ipos,1)=="/") position=ipos;
372      }
373      return name.substr(position+1,name.length()-position-1);
# Line 414 | Line 450 | void write_entry(string entry,int width,
450    int currwidth=entry.size();
451    while(currwidth<width) {
452      entry=" "+entry;
453 <    if(entry.size()<width) entry=entry+" ";
453 >    if((int)entry.size()<width) entry=entry+" ";
454      currwidth=entry.size();
455    }
456    bool do_special=false;
# Line 428 | Line 464 | void write_entry(string entry,int width,
464   void make_nice_table(vector<vector <string> > &entries) {
465    int ncolumns=write_first_line(entries);
466    int cellwidth=(int)(((float)(60-(ncolumns+1)))/(ncolumns));
467 <  for(int iline=0;iline<entries.size();iline++) {
467 >  for(int iline=0;iline<(int)entries.size();iline++) {
468      vector<string> currline = entries[iline];
469      dout << " |";
470 <    for(int ientry=0;ientry<currline.size();ientry++) {
470 >    for(int ientry=0;ientry<(int)currline.size();ientry++) {
471        write_entry(currline[ientry],cellwidth);
472      }
473      dout << endl;
# Line 443 | Line 479 | void make_nice_table(vector<vector <stri
479   void make_nice_jzb_table(vector<vector <string> > &entries) {
480    int ncolumns=write_first_line(entries);
481    int cellwidth=(int)(((float)(60-(ncolumns+1)))/(ncolumns));
482 <  for(int iline=0;iline<entries.size();iline++) {
482 >  for(int iline=0;iline<(int)entries.size();iline++) {
483      vector<string> currline = entries[iline];
484      dout << " |";
485 <    for(int ientry=0;ientry<currline.size();ientry++) {
485 >    for(int ientry=0;ientry<(int)currline.size();ientry++) {
486        write_entry(currline[ientry],cellwidth,iline,ientry);
487      }
488      dout << endl;
# Line 547 | Line 583 | void DrawPrelim(float writelumi=generalt
583    string prel=" Preliminary";
584    if(PlottingSetup::PaperMode) prel="";
585    //prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement
586 +  if(PlottingSetup::is53reco) prel += " 53X";
587 +  string energy="7 TeV";
588 +  if(PlottingSetup::is2012) energy="8 TeV";
589    if(writelumi == 0) {
590 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = 7 TeV";
591 <    else prelimtext << "CMS" << prel << ", #sqrt{s} = 7 TeV";
590 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy;
591 >    else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy;
592    } else {
593 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = 7 TeV, L_{int} = " << std::setprecision(2) <<writelumi<<" "<<barn<<"^{-1}";
594 <    else prelimtext << "CMS" << prel << ", #sqrt{s} = 7 TeV, L_{int} = " << std::setprecision(2) <<writelumi<<" "<<barn<<"^{-1}";
593 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
594 >     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
595    }
596    TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC");
597    eventSelectionPaveText->SetFillStyle(4000);
598    eventSelectionPaveText->SetBorderSize(0);
599    eventSelectionPaveText->SetFillColor(kWhite);
600    eventSelectionPaveText->SetTextFont(42);
601 +  //eventSelectionPaveText->SetTextFont(62); // paper style
602    eventSelectionPaveText->SetTextSize(0.042);
603    eventSelectionPaveText->AddText(prelimtext.str().c_str());
604    eventSelectionPaveText->Draw();
# Line 596 | Line 636 | TGraph* make_nice_ratio(int nbins,float
636      bincontent[i]=0;
637      errors[i]=0;
638    }
639 <  float currlimit=binning[0];
639 > //  float currlimit=binning[0];
640    int currtoplim=1;
641    for(int ibin=1;ibin<=histo->GetNbinsX();ibin++)
642    {
# Line 629 | Line 669 | float computeProductError(float a, float
669      return val;
670   }
671  
672 + TGraphAsymmErrors *SysAndStatRatio(TH1F *h1,TH1F *h2, TH1F *sys, int id, vector<float>binning, bool precise=false) {
673 +    int absJZBbinsNumber = binning.size()-1;
674 +    TGraphAsymmErrors* graph = new TGraphAsymmErrors(absJZBbinsNumber);
675 +    for(int i=0;i<absJZBbinsNumber;i++)
676 +        {
677 +                float xCenter=h1->GetBinCenter(i+1);
678 +                float xWidth=(h1->GetBinWidth(i+1))*0.5;
679 +                float nominatorError = h1->GetBinError(i+1);
680 +                float nominator=h1->GetBinContent(i+1);
681 +                float denominatorError=h2->GetBinError(i+1);
682 +                float denominator=h2->GetBinContent(i+1);
683 +                float errorN = 0;
684 +                float errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError);
685 +                float syserr=sys->GetBinContent(i+1);
686 +                float errorsys=0;
687 +                if(id==1) // (is data)
688 +                {
689 +                        if(!precise) errorP = computeRatioError(nominator,statErrorP(nominator),denominator,statErrorP(denominator));
690 +                        else         errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError);
691 +                        errorsys=computeRatioError(nominator,syserr,denominator,0);
692 +                        errorP = TMath::Sqrt(errorsys*errorsys+errorP*errorP);
693 +                        errorN = errorP; // symmetrize using statErrorP
694 +                } else {
695 +                        errorN = computeRatioError(nominator,nominatorError,denominator,denominatorError);
696 +                        errorsys=computeRatioError(nominator,syserr,denominator,0);
697 +                        errorN = TMath::Sqrt(errorsys*errorsys+errorP*errorP);
698 +                        errorP = errorN; // symmetrize using statErrorP
699 +                }
700 +                if(denominator!=0) {
701 +                        graph->SetPoint(i, xCenter, nominator/denominator);
702 +                        graph->SetPointError(i,xWidth,xWidth,errorN,errorP);
703 +                }
704 +                else {
705 +                        graph->SetPoint(i, xCenter, -999);
706 +                        graph->SetPointError(i,xWidth,xWidth,errorN,errorP);
707 +                }
708 +        }      
709 +        return graph;
710 + }
711 +    
712 +
713   TGraphAsymmErrors *histRatio(TH1F *h1,TH1F *h2, int id, vector<float>binning, bool precise=false)
714   {
715          int absJZBbinsNumber = binning.size()-1;
716          TGraphAsymmErrors* graph = new TGraphAsymmErrors(absJZBbinsNumber);
717          
718 <        for(unsigned int i=0;i<absJZBbinsNumber;i++)
718 >        for(int i=0;i<absJZBbinsNumber;i++)
719          {
720                  float xCenter=h1->GetBinCenter(i+1);
721                  float xWidth=(h1->GetBinWidth(i+1))*0.5;
# Line 746 | Line 827 | void splitupcut(string incut, vector<str
827      int paranthesis_open=0;
828      int substr_start=0;
829      string currchar="";
830 <    for (int ichar=0;ichar<incut.length();ichar++)
830 >    for (int ichar=0;ichar<(int)incut.length();ichar++)
831      {
832          currchar=incut.substr(ichar,1);
833   //        if(currchar=="(") paranthesis_open++;
# Line 759 | Line 840 | void splitupcut(string incut, vector<str
840      partvector.push_back(incut.substr(substr_start,incut.length()-substr_start));
841      if(Verbosity>1) {
842          dout << "[ splitupcut() ] : The cut vector now contains the following elements: "<< endl;
843 <        for (int ipart=0;ipart<partvector.size();ipart++)
843 >        for (int ipart=0;ipart<(int)partvector.size();ipart++)
844          {
845              dout << "     - " << partvector[ipart] << endl;
846          }
# Line 768 | Line 849 | void splitupcut(string incut, vector<str
849  
850   int atleastvalue(string expression, int &morethanlessthan) // takes in an expression such as ">2" or ">=3" and returns e.g. 3 (in both examples)
851   {
852 <  int retval=0;
852 > //  int retval=0;
853    if(expression.substr(0,1)==">"&&expression.substr(1,1)=="=") {
854   //    dout << "The expression " << expression << " is saying that we have at least " << atoi(expression.substr(2,1).c_str()) << " jets" << endl;
855      morethanlessthan=1;
# Line 794 | Line 875 | int atleastvalue(string expression, int
875      morethanlessthan=-1;
876      return 1+atoi(expression.substr(2,1).c_str());
877    }
878 +  
879 +  return -1234567;
880   }
881  
882   int do_jet_cut(string incut, int *nJets) {
# Line 829 | Line 912 | int do_jet_cut(string incut, int *nJets)
912      dout << "Is of type >" << endl;
913      return 0;
914    }
915 +  return -12345;
916   }
917  
918   string interpret_cut(string incut, bool &isJetCut, int *permittednJets)
# Line 862 | Line 946 | string interpret_cut(string incut, bool
946    
947      if(incut=="id1==0") return "ee";
948      if(incut=="id1==1") return "#mu#mu";
949 <    if(incut=="abs(mll-91.2)<20") return "|m_{l^{+}l^{-}}-m_{Z}|<20";
949 >    if(incut=="abs(mll-91)<10") return "|m_{l^{+}l^{-}}-m_{Z}|<10";
950      if(incut=="pfJetGoodID[0]") return "";
951      if(incut=="pfJetGoodID[1]") return "";
952      if((int)incut.find("pfJetGoodNum")>-1) {
# Line 894 | Line 978 | string interpret_cuts(vector<string> &cu
978      int finalJetCut=-1;
979      int permittednJets[20];
980      for(int ijet=0;ijet<20;ijet++) permittednJets[ijet]=1;
981 <    int morethanlessthan=0;//-1: less than, 0: exactly, 1: more than
982 <    for(int icut=0;icut<cutparts.size();icut++)
981 > //    int morethanlessthan=0;//-1: less than, 0: exactly, 1: more than
982 >    for(int icut=0;icut<(int)cutparts.size();icut++)
983      {
984          if(icut==0) nicecut<<interpret_cut(cutparts[icut],isJetCut,permittednJets);
985          else {
# Line 960 | Line 1044 | TH1F * makehistofromfunction(TF1 *f1,TH1
1044    histo->SetTitle(histoname.str().c_str());
1045    histo->SetName(histoname.str().c_str());
1046    int nbins=histo->GetNbinsX();
1047 <  float low=histo->GetBinLowEdge(1);
1048 <  float hi=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX());
1047 > //  float low=histo->GetBinLowEdge(1);
1048 > //  float hi=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX());
1049    
1050    for(int i=0;i<=nbins;i++) {
1051      histo->SetBinContent(i,(f1->Integral(histo->GetBinLowEdge(i),histo->GetBinLowEdge(i)+histo->GetBinWidth(i)))/histo->GetBinWidth(i));
# Line 1231 | Line 1315 | Double_t MarcosChi2TestX(const TH1* h1,
1315     return prob;
1316   }
1317  
1318 < void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio") {
1318 > /*void save_with_difference(TH1F *obs, vector<TH1F*> predictions, vector<float> prediction_weights, vector<float> prediction_uncerts, TVirtualPad *canvas, string savemeas) {
1319 >  if(predictions.size()<1) {
1320 >    write_warning(__FUNCTION__,"Cannot make a pred-obs prediction plot because the prediction vector is empty. aborting!");
1321 >    return;
1322 >  }
1323 >  TH1F *comppred = predictions[0]->Clone("comppred");
1324 >  comppred->Scale(prediction_weights[0]);
1325 >  for(int i=1;i<predictions.size();i++) comppred->Add(predictions[i],prediction_weights[i]);
1326 >  
1327 >  TH1F *statpred = (TH1F*)comppred->Clone("statpred");
1328 >  for(int i=1;i<=statpred->GetNbinsX();i++) statpred->SetBinContent(0);
1329 >  
1330 >  TH1F *syspred = predictions[0];
1331 >  for(int i=1;i<=syspred->GetNbinsX();i++) syspred->SetBinContent(i,prediction_weights[0]*prediction_weights[0]*prediction_uncerts[0]*prediction_uncerts[0]*syspred->GetBinContent(i)*syspred->GetBinContent(i));
1332 >  for(int i=1;i<predictions.size();i++) {
1333 >    for(int ibin=1;ibin<=predictions[i]->GetNbinsX();ibin++) {
1334 >      float newentry=syspred->GetBinContent(ibin);
1335 >      newentry+=(predictions[i]->GetBinContent(ibin))*(predictions[i]->GetBinContent(ibin))*prediction_weights[i]*prediction_weights[i]*prediction_uncerts[i]*prediction_uncerts[i];
1336 >      syspred->SetBinContent(ibin,newentry);
1337 >    }
1338 >  }
1339 >  for(int ibin=1;ibin<=syspred->GetNbinsX();ibin++) {
1340 >    syspred->SetBinError(ibin,syspred->GetBinContent(i)+statpred->GetBinError());
1341 >    syspred->SetBinContent(ibin,0);
1342 >  }
1343 >  
1344 >  
1345 > }
1346 > */
1347 > void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) {
1348    //this function saves the pad being passed as well as a new one including the ratio.
1349    CompleteSave(canvas,savemeas);
1350  
# Line 1283 | Line 1396 | void save_with_ratio(TH1F *nominator, TH
1396  
1397  
1398    TGraphAsymmErrors *eratio;
1399 +  TH1F *SystDown;
1400 +  TH1F *SystUp;
1401 +  
1402    if(!do_bpred_ratio) eratio = produce_ratio_graph(ratio);
1403    else {
1404       bool using_data=false;
1405       if((int)savemeas.find("Data")>0) using_data=true;
1406       eratio = histRatio(nominator,denominator,using_data,PlottingSetup::global_ratio_binning,false);
1407 +     if(syshisto!=0) {
1408 +       SystDown = (TH1F*)syshisto->Clone("SystDown");
1409 +       SystUp = (TH1F*)syshisto->Clone("SystUp");
1410 +       for(int i=1;i<=syshisto->GetNbinsX();i++) {
1411 +         SystDown->SetBinContent(i,1-syshisto->GetBinContent(i));
1412 +         SystUp->SetBinContent(i,1+syshisto->GetBinContent(i));
1413 +       }
1414 +       SystDown->SetLineColor(TColor::GetColor("#006DE1"));
1415 +       SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1416 +     }
1417       for(int i=1;i<=ratio->GetNbinsX();i++) {
1418          ratio->SetBinContent(i,0);
1419          ratio->SetBinError(i,0);
1420       }
1421 +    
1422    }
1423    eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1424 +  
1425  
1426    ratio->SetTitle("");
1427 <  ratio->GetYaxis()->SetRangeUser(0.5,1.5);
1427 >  ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1428    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1429    if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0);
1430    ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
# Line 1313 | Line 1441 | void save_with_ratio(TH1F *nominator, TH
1441    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1442    ratio->SetMarkerSize(0);
1443    ratio->Draw("e2");
1444 <  eratio->Draw("2");
1444 >  if(syshisto!=0) {
1445 > //    sysratio->Draw("2");
1446 > //    eratio->Draw("2,same");
1447 >    eratio->Draw("2");
1448 >    SystDown->Draw("histo,same");
1449 >    SystUp->Draw("histo,same");
1450 >  } else {
1451 >    eratio->Draw("2");
1452 >  }
1453    ratio->Draw("same,axis");
1454    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1455    oneline->SetLineStyle(2);
# Line 1330 | Line 1466 | void save_with_ratio(TH1F *nominator, TH
1466    
1467    Double_t chi2;
1468    Int_t ndf,igood;
1469 <  Double_t res=0.0;
1469 > //  Double_t res=0.0;
1470    Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW");
1471  
1472    stringstream Chi2text;
# Line 1345 | Line 1481 | void save_with_ratio(TH1F *nominator, TH
1481    chi2probbox->SetTextSize(0.08);
1482    chi2probbox->SetTextAlign(11);
1483    chi2probbox->Draw();
1484 +  
1485 +  stringstream CompRatio;
1486 +  CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral();
1487 +  TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str());
1488 +  CompleteRatio->SetTextSize(0.08);
1489 +  CompleteRatio->SetTextAlign(31);
1490 +  CompleteRatio->Draw();
1491 +  
1492    CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1493  
1494   //  float KS   = nominator->KolmogorovTest(denominator);
# Line 1356 | Line 1500 | void save_with_ratio(TH1F *nominator, TH
1500    delete main_canvas;
1501   }
1502  
1503 + void save_with_ratio_and_sys_band(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, float systematic, string yaxistitle="SysRatio") {
1504 +  //this function saves the pad being passed as well as a new one including the SysRatio.
1505 +  CompleteSave(canvas,savemeas);
1506 +
1507 +  float bottommargin=gStyle->GetPadBottomMargin();
1508 +  float canvas_height=gStyle->GetCanvasDefH();
1509 +  float canvas_width=gStyle->GetCanvasDefW();
1510 +  float SysRatiospace=0.25;// space the SysRatio should take up (relative to original pad)
1511 +  
1512 +  float SysRatiobottommargin=0.3;
1513 +  float SysRatiotopmargin=0.1;
1514 +  
1515 +  float xstretchfactor=((1-SysRatiospace)*(1-gStyle->GetPadTopMargin()))/((1)*SysRatiospace);
1516 +  
1517 +  TCanvas *MainCanvas = new TCanvas("MainCanvas","MainCanvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+SysRatiospace)));
1518 +  TPad *MainPad = new TPad("MainPad","MainPad",0,1-(1.0/(1+SysRatiospace)),1,1);//top (main) pad
1519 +  TPad *CoverPad = new TPad("CoverPad","CoverPad",gStyle->GetPadLeftMargin()-0.008,1-(1.0/(1+SysRatiospace))-0.04,1,1-(1.0/(1+SysRatiospace))+0.103);//pad covering up the x scale
1520 +  TPad *BottomPad = new TPad("BottomPad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+SysRatiospace))-0.015); //bottom pad
1521 +  
1522 +  MainCanvas->Range(0,0,1,1);
1523 +  MainCanvas->SetBorderSize(0);
1524 +  MainCanvas->SetFrameFillColor(0);
1525 +  
1526 +  MainPad->Draw();
1527 +  MainPad->cd();
1528 +  MainPad->Range(0,0,1,1);
1529 +  MainPad->SetFillColor(kWhite);
1530 +  MainPad->SetBorderSize(0);
1531 +  MainPad->SetFrameFillColor(0);
1532 +  canvas->Range(0,0,1,1);
1533 +  canvas->Draw("same");
1534 +  MainPad->Modified();
1535 +  MainCanvas->cd();
1536 +  CoverPad->Draw();
1537 +  CoverPad->cd();
1538 +  CoverPad->Range(0,0,1,1);
1539 +  CoverPad->SetFillColor(kWhite);
1540 +  CoverPad->SetBorderSize(0);
1541 +  CoverPad->SetFrameFillColor(0);
1542 +  CoverPad->Modified();
1543 +  MainCanvas->cd();
1544 +  BottomPad->SetTopMargin(SysRatiotopmargin);
1545 +  BottomPad->SetBottomMargin(SysRatiobottommargin);
1546 +  BottomPad->Draw();
1547 +  BottomPad->cd();
1548 +  BottomPad->Range(0,0,1,1);
1549 +  BottomPad->SetFillColor(kWhite);
1550 +  TH1F *SysRatio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1551 +  SysRatio->Divide(denominator);
1552 +
1553 +
1554 +
1555 +  SysRatio->SetTitle("");
1556 +  SysRatio->GetYaxis()->SetRangeUser(0.0,2.0);
1557 +  SysRatio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
1558 +  SysRatio->GetXaxis()->CenterTitle();
1559 +  SysRatio->GetYaxis()->SetTitle(yaxistitle.c_str());
1560 +  SysRatio->GetYaxis()->SetTitleOffset(0.4);
1561 +  SysRatio->GetYaxis()->CenterTitle();
1562 +  SysRatio->SetStats(0);
1563 +  SysRatio->GetXaxis()->SetLabelSize(xstretchfactor*SysRatio->GetXaxis()->GetLabelSize());
1564 +  SysRatio->GetYaxis()->SetLabelSize(xstretchfactor*SysRatio->GetYaxis()->GetLabelSize());
1565 +  SysRatio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1566 +  SysRatio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1567 +  SysRatio->GetYaxis()->SetNdivisions(502,false);
1568 +  SysRatio->SetFillColor(TColor::GetColor("#58D3F7"));
1569 +  TBox *sysbox = new TBox(SysRatio->GetXaxis()->GetBinLowEdge(1),1-systematic,SysRatio->GetXaxis()->GetBinLowEdge(SysRatio->GetNbinsX())+SysRatio->GetXaxis()->GetBinWidth(SysRatio->GetNbinsX()),1+systematic);
1570 +  sysbox->SetFillColor(TColor::GetColor("#82FA58")); // light green
1571 +  
1572 +  SysRatio->Draw("e1");
1573 +  sysbox->Draw();
1574 +  SysRatio->Draw("e1,same");
1575 +  SysRatio->Draw("e1,axis,same");
1576 +  
1577 +  TLine *oneline = new TLine(SysRatio->GetXaxis()->GetBinLowEdge(1),1,SysRatio->GetXaxis()->GetBinLowEdge(SysRatio->GetNbinsX())+SysRatio->GetXaxis()->GetBinWidth(SysRatio->GetNbinsX()),1);
1578 +  oneline->SetLineStyle(2);
1579 +  oneline->SetLineColor(kBlue);
1580 +  oneline->Draw("same");
1581 +
1582 +  MainCanvas->cd();
1583 +  MainCanvas->Modified();
1584 +  MainCanvas->cd();
1585 +  MainCanvas->SetSelected(MainCanvas);
1586 +  
1587 +  CompleteSave(MainCanvas,savemeas+"_withSYSSysRatio");
1588 +  delete SysRatio;
1589 +  delete MainCanvas;
1590 + }
1591  
1592 < TH1F* CollapseStack(THStack stack) {
1592 > TH1F* CollapseStack(THStack stack,TString hname="base") {
1593     TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0)));
1594 <   TH1F *basehisto = (TH1F*)bhist->Clone("base");
1594 >   TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1595     TIter next(stack.GetHists());
1596     TH1F *h;
1597     int counter=0;
# Line 1388 | Line 1620 | void flag_this_change(string function, i
1620    if(checked==2) write_info(function,peakmodificationwarning.str());
1621   }
1622  
1623 < void write_analysis_type(bool isonpeak) {
1623 > void write_analysis_type(bool isonpeak, bool dobtag) {
1624   //http://www.network-science.de/ascii/, ogre
1625    if(!PlottingSetup::publicmode) {
1626      if(isonpeak) {
1627 + //font: big    
1628          dout << "\033[1;34m" << endl;
1629 <        dout <<  "    //\\\\                                  _                          _           _     " << endl;
1630 <        dout <<  "   //  \\\\     ___  _ __  _ __   ___  __ _| | __     __ _ _ __   __ _| |_   _ ___(_)___" << endl;
1631 <        dout <<  "  //    \\\\   / _ \\| '_ \\| '_ \\ / _ \\/ _` | |/ /    / _` | '_ \\ / _` | | | | / __| / __|" << endl;
1632 <        dout <<  " //      \\\\ | (_) | | | | |_) |  __/ (_| |   <    | (_| | | | | (_| | | |_| \\__ \\ \\__ \\" << endl;
1633 <        dout <<  "//        \\\\ \\___/|_| |_| .__/ \\___|\\__,_|_|\\_\\    \\__,_|_| |_|\\__,_|_|\\__, |___/_|___/" << endl;
1634 <        dout <<  "                        |_|                                            |___/" << endl;
1629 >        dout <<  "                             _ __________                                                         " << endl;
1630 >        dout <<  "                            | |___  /  _ \\                                                       " << endl;
1631 >        dout <<  "       /\\           ___     | |  / /| |_) |                                                       " << endl;
1632 >        dout <<  "      /  \\         /  _|_   | | / / |  _ <                                                         " << endl;
1633 >        dout <<  "     /    \\        | (_| |__| |/ /__| |_) |                                                       " << endl;
1634 >        dout <<  "                   \\___|\\____//_____|____/                                                       " << endl;
1635      } else {
1636 + //font: big    
1637          dout << "\033[1;33m" << endl;
1638 <        dout <<  "                    __  __                  _                          _           _     " << endl;
1639 <        dout <<  "              ___  / _|/ _|_ __   ___  __ _| | __     __ _ _ __   __ _| |_   _ ___(_)___ " << endl;
1640 <        dout <<  "    /\\       / _ \\| |_| |_| '_ \\ / _ \\/ _` | |/ /    / _` | '_ \\ / _` | | | | / __| / __|" << endl;
1641 <        dout <<  " __/  \\__   | (_) |  _|  _| |_) |  __/ (_| |   <    | (_| | | | | (_| | | |_| \\__ \\ \\__ \\" << endl;
1642 <        dout <<  "             \\___/|_| |_| | .__/ \\___|\\__,_|_|\\_\\    \\__,_|_| |_|\\__,_|_|\\__, |___/_|___/" << endl;
1643 <        dout <<  "                          |_|                                            |___/           " << endl;
1638 >        dout <<  "                    _      _ __________                                                             " << endl;
1639 >        dout <<  "                   (_)    | |___  /  _ \\                                                            " << endl;
1640 >        dout <<  "       /\\           _     | |  / /| |_) |                                                           " << endl;
1641 >        dout <<  "    /\\/  \\         | |_   | | / / |  _ <                                                            " << endl;
1642 >        dout <<  "   /      \\        | | |__| |/ /__| |_) |                                                           " << endl;
1643 >        dout <<  "                   |_|\\____//_____|____/                                                            " << endl;
1644      }
1645 <    dout << "\033[0m" << endl;
1645 >  
1646 >    if(dobtag) {
1647 > //font: big    
1648 >        dout <<  "\033[1;32m                  \\     /                                                                " << endl;
1649 >        dout <<  "             \\    o ^ o    /                                                             " << endl;
1650 >        dout <<  "               \\ (     ) /                                                               " << endl;
1651 >        dout <<  "    ____________(%%%%%%%)____________        _          _ __________                     " << endl;
1652 >        dout <<  "   (     /   /  )%%%%%%%(  \\   \\     )      | |        | |___  /  _ \\                    " << endl;
1653 >        dout <<  "   (___/___/__/           \\__\\___\\___)      | |__      | |  / /| |_) |                   " << endl;
1654 >        dout <<  "      (     /  /(%%%%%%%)\\  \\     )         | '_ \\ _   | | / / |  _ <                    " << endl;
1655 >        dout <<  "       (__/___/ (%%%%%%%) \\___\\__)          | |_) | |__| |/ /__| |_) |                   " << endl;
1656 >        dout <<  "               /(       )\\                  |_.__/ \\____//_____|____/                    " << endl;
1657 >        dout <<  "             /   (%%%%%)   \\                                                             " << endl;
1658 >        dout <<  "                  (%%%)                                                                  " << endl;
1659 >        dout <<  "                    !                                                                    " << endl;
1660    }
1661 +  } else {
1662 +    //we're in public! don't advertise what we're up to :-)
1663 +       dout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
1664 +       dout << "                              Starting the analysis                     " << endl;
1665 +       dout << "                                     i:" << !isonpeak << " , b " << dobtag << endl;
1666 +       dout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
1667 +  }
1668 +  dout << "\033[0m" << endl;
1669 +
1670   }
1671  
1672  
# Line 1418 | Line 1675 | vector<string> StringSplit(string str, s
1675          vector<string> results;
1676          
1677          int cutAt;
1678 <        while( (cutAt = str.find_first_of(delim)) != str.npos )
1678 >        while( (cutAt = str.find_first_of(delim)) != (int)str.npos )
1679          {
1680                  if(cutAt > 0)
1681                  {
# Line 1435 | Line 1692 | vector<string> StringSplit(string str, s
1692  
1693   void manually_set_jzb_cuts(vector<float> &jzb_cut,string jzbcut_string) {
1694          vector<string> jzbcutvector = StringSplit(jzbcut_string,",");
1695 <        for(int i=0;i<jzbcutvector.size();i++) {
1695 >        for(int i=0;i<(int)jzbcutvector.size();i++) {
1696                  jzb_cut.push_back(atoi(jzbcutvector[i].c_str()));
1697                  dout << "Added a JZB cut manually at " << atoi(jzbcutvector[i].c_str()) << endl;
1698          }
# Line 1449 | Line 1706 | void process_directory(TString directory
1706          dp = opendir (directory);
1707          if (dp != NULL)
1708          {
1709 <                while (ep = readdir (dp))
1709 >                while ((ep = readdir (dp)))
1710                  {
1711                          string filename=(string)ep->d_name;
1712 <                        if(filename.find(".root")!=-1)
1712 >                        if((int)filename.find(".root")!=-1)
1713                          {
1714                                  files.push_back(string(directory)+filename);
1715                          }
# Line 1463 | Line 1720 | void process_directory(TString directory
1720                  perror ("Couldn't open the directory");
1721   }
1722  
1723 + void ClearHisto(TH1* histo) {
1724 +    for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also reset over- and underflow
1725 +        histo->SetBinContent(ix,0);
1726 +        histo->SetBinContent(ix,0);
1727 +    }
1728 + }
1729 +
1730 + void AddSquared(TH1F *histo, TH1F *addthis, float weight) {
1731 +    for(int ix=1;ix<=addthis->GetNbinsX()+1;ix++) {//also include over- and underflow
1732 +        float bincenter=addthis->GetBinCenter(ix);
1733 +        int nBinHisto= histo->FindBin(bincenter);
1734 +        float old_content=histo->GetBinContent(nBinHisto);
1735 +        histo->SetBinContent(nBinHisto,old_content+((addthis->GetBinContent(ix))*(addthis->GetBinContent(ix))*weight));
1736 +    }
1737 + }
1738 +
1739 + void SQRT(TH1* histo) {
1740 +    for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also include over- and underflow
1741 +        histo->SetBinContent(ix,TMath::Sqrt(histo->GetBinContent(ix)));
1742 +    }
1743 + }
1744 +
1745   /*string GetCompleteHostname() {
1746    struct addrinfo hints, *info, *p;
1747    int gai_result;
# Line 1494 | Line 1773 | const char* concatenate (const char* a,
1773    return bla.str().c_str();
1774   }
1775  
1776 +
1777 + string ReplaceCharacter(string originalstring,string replacethis,string replacewiththis)
1778 + {
1779 +        int pos = originalstring.find(replacethis);
1780 +        while(pos != -1) {
1781 +          originalstring.replace(pos, replacewiththis.length(), replacewiththis);
1782 +          pos = originalstring.find(replacethis);
1783 +        }
1784 +        return originalstring;
1785 + }
1786 +
1787 + string removefunnystring(string name) {
1788 +  name=ReplaceCharacter(name,"[","_");
1789 +  name=ReplaceCharacter(name,"]","_");
1790 +  name=ReplaceCharacter(name,"{","_");
1791 +  name=ReplaceCharacter(name,"}","_");
1792 +  name=ReplaceCharacter(name,".","_");
1793 +  name=ReplaceCharacter(name,",","_");
1794 +  name=ReplaceCharacter(name,";","_");
1795 +  name=ReplaceCharacter(name,":","_");
1796 +  name=ReplaceCharacter(name,"'","_");
1797 +  name=ReplaceCharacter(name,"$","_");
1798 +  name=ReplaceCharacter(name,"@","_");
1799 +  name=ReplaceCharacter(name,"#","_");
1800 +  name=ReplaceCharacter(name,"+","_");
1801 +  name=ReplaceCharacter(name,"-","_");
1802 +  name=ReplaceCharacter(name,"/","_");
1803 +  return name;
1804 + }
1805 +
1806   stringstream all_bugs;
1807  
1808   void bug_tracker(string function, int line, string description) {
# Line 1531 | Line 1840 | void bug_tracker(string function, int li
1840   //TODO: Write a bug summary at the end.
1841  
1842   float pSTAR(float mglu, float mlsp, float mchi2) {
1843 <        float mz=91.2;
1843 >        float mz=91.0;
1844          float res=((mchi2*mchi2)-(mlsp+mz)*(mlsp+mz));
1845          res*=((mchi2*mchi2)-(mlsp-mz)*(mlsp-mz));
1846          res=TMath::Sqrt(res)/(2*mchi2);
1847          return res;
1848   }
1849 +
1850 + float generalizedpSTAR(float massmother, float massdaughter1, float massdaughter2) {
1851 +        float res=((massmother*massmother)-(massdaughter1+massdaughter2)*(massdaughter1+massdaughter2));
1852 +        res*=((massmother*massmother)-(massdaughter1-massdaughter2)*(massdaughter1-massdaughter2));
1853 +        res=TMath::Sqrt(res)/(2*massmother);
1854 +        return res;
1855 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines