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.5 by buchmann, Tue Apr 10 13:44:59 2012 UTC vs.
Revision 1.11 by buchmann, Wed Jun 6 08:24:13 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 58 | Line 59 | namespace PlottingSetup {
59      vector<float> global_ratio_binning;
60      int publicmode=0;
61      int PaperMode=0; // PaperMode=true will suppress "Preliminary" in DrawPrelim()
62 +    int Approved=0; // Approved=true will only plot approved plots
63 +    bool is2012=true;
64   }
65  
66   bool dopng=false;
# Line 119 | Line 122 | string topdir(string child) {
122          return tempdirectory.substr(0,ichar);
123        }
124      }
125 +    return "TOPDIRFAILURE";
126   }
127  
128   template < typename CHAR_TYPE,
# Line 278 | Line 282 | void initialize_log() {
282      dout << "        PUBLIC MODE     " << endl;
283    }
284    time_t rawtime;
281  struct tm * timeinfo;
285    time ( &rawtime );
286    dout << "       Analysis run on " << asctime (localtime ( &rawtime ));
287    dout << "____________________________________________________________" << endl;
# Line 297 | Line 300 | void set_directory(string basedir="") {
300    if(basedir.substr(0,1)=="/") basedir=basedir.substr(1,basedir.length()-1);
301    if(basedir.substr(basedir.length()-1,1)!="/") basedir+="/";
302    char currentpath[1024];
303 <  char *path = getcwd(currentpath,1024);
303 >  getcwd(currentpath,1024);
304    PlottingSetup::basedirectory=(string)currentpath+"/Plots/"+basedir;
305    ensure_directory_exists(PlottingSetup::basedirectory);
306    initialize_log();
# Line 322 | Line 325 | string extract_directory(string savethis
325   string extract_root_dir(string name) {
326      int position = -1;
327      if(name.substr(0,1)=="/") name=name.substr(1,name.length()-1);
328 <    for(int ipos=0;ipos<name.length();ipos++) {
328 >    for(int ipos=0;ipos<(int)name.length();ipos++) {
329          if(name.substr(ipos,1)=="/") position=ipos;
330      }
331      if(position==-1) return "";
# Line 332 | Line 335 | string extract_root_dir(string name) {
335   string extract_root_filename(string name) {
336      int position = -1;
337      if(name.substr(0,1)=="/") name=name.substr(1,name.length()-1);
338 <    for(int ipos=0;ipos<name.length();ipos++) {
338 >    for(int ipos=0;ipos<(int)name.length();ipos++) {
339          if(name.substr(ipos,1)=="/") position=ipos;
340      }
341      return name.substr(position+1,name.length()-position-1);
# Line 415 | Line 418 | void write_entry(string entry,int width,
418    int currwidth=entry.size();
419    while(currwidth<width) {
420      entry=" "+entry;
421 <    if(entry.size()<width) entry=entry+" ";
421 >    if((int)entry.size()<width) entry=entry+" ";
422      currwidth=entry.size();
423    }
424    bool do_special=false;
# Line 429 | Line 432 | void write_entry(string entry,int width,
432   void make_nice_table(vector<vector <string> > &entries) {
433    int ncolumns=write_first_line(entries);
434    int cellwidth=(int)(((float)(60-(ncolumns+1)))/(ncolumns));
435 <  for(int iline=0;iline<entries.size();iline++) {
435 >  for(int iline=0;iline<(int)entries.size();iline++) {
436      vector<string> currline = entries[iline];
437      dout << " |";
438 <    for(int ientry=0;ientry<currline.size();ientry++) {
438 >    for(int ientry=0;ientry<(int)currline.size();ientry++) {
439        write_entry(currline[ientry],cellwidth);
440      }
441      dout << endl;
# Line 444 | Line 447 | void make_nice_table(vector<vector <stri
447   void make_nice_jzb_table(vector<vector <string> > &entries) {
448    int ncolumns=write_first_line(entries);
449    int cellwidth=(int)(((float)(60-(ncolumns+1)))/(ncolumns));
450 <  for(int iline=0;iline<entries.size();iline++) {
450 >  for(int iline=0;iline<(int)entries.size();iline++) {
451      vector<string> currline = entries[iline];
452      dout << " |";
453 <    for(int ientry=0;ientry<currline.size();ientry++) {
453 >    for(int ientry=0;ientry<(int)currline.size();ientry++) {
454        write_entry(currline[ientry],cellwidth,iline,ientry);
455      }
456      dout << endl;
# Line 548 | Line 551 | void DrawPrelim(float writelumi=generalt
551    string prel=" Preliminary";
552    if(PlottingSetup::PaperMode) prel="";
553    //prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement
554 +  string energy="7 TeV";
555 +  if(PlottingSetup::is2012) energy="8 TeV";
556    if(writelumi == 0) {
557 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = 7 TeV";
558 <    else prelimtext << "CMS" << prel << ", #sqrt{s} = 7 TeV";
557 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy;
558 >    else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy;
559    } else {
560 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = 7 TeV, L_{int} = " << std::setprecision(2) <<writelumi<<" "<<barn<<"^{-1}";
561 <    else prelimtext << "CMS" << prel << ", #sqrt{s} = 7 TeV, L_{int} = " << std::setprecision(2) <<writelumi<<" "<<barn<<"^{-1}";
560 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
561 >     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
562    }
563    TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC");
564    eventSelectionPaveText->SetFillStyle(4000);
565    eventSelectionPaveText->SetBorderSize(0);
566    eventSelectionPaveText->SetFillColor(kWhite);
567    eventSelectionPaveText->SetTextFont(42);
568 +  //eventSelectionPaveText->SetTextFont(62); // paper style
569    eventSelectionPaveText->SetTextSize(0.042);
570    eventSelectionPaveText->AddText(prelimtext.str().c_str());
571    eventSelectionPaveText->Draw();
# Line 597 | Line 603 | TGraph* make_nice_ratio(int nbins,float
603      bincontent[i]=0;
604      errors[i]=0;
605    }
606 <  float currlimit=binning[0];
606 > //  float currlimit=binning[0];
607    int currtoplim=1;
608    for(int ibin=1;ibin<=histo->GetNbinsX();ibin++)
609    {
# Line 635 | Line 641 | TGraphAsymmErrors *histRatio(TH1F *h1,TH
641          int absJZBbinsNumber = binning.size()-1;
642          TGraphAsymmErrors* graph = new TGraphAsymmErrors(absJZBbinsNumber);
643          
644 <        for(unsigned int i=0;i<absJZBbinsNumber;i++)
644 >        for(int i=0;i<absJZBbinsNumber;i++)
645          {
646                  float xCenter=h1->GetBinCenter(i+1);
647                  float xWidth=(h1->GetBinWidth(i+1))*0.5;
# Line 747 | Line 753 | void splitupcut(string incut, vector<str
753      int paranthesis_open=0;
754      int substr_start=0;
755      string currchar="";
756 <    for (int ichar=0;ichar<incut.length();ichar++)
756 >    for (int ichar=0;ichar<(int)incut.length();ichar++)
757      {
758          currchar=incut.substr(ichar,1);
759   //        if(currchar=="(") paranthesis_open++;
# Line 760 | Line 766 | void splitupcut(string incut, vector<str
766      partvector.push_back(incut.substr(substr_start,incut.length()-substr_start));
767      if(Verbosity>1) {
768          dout << "[ splitupcut() ] : The cut vector now contains the following elements: "<< endl;
769 <        for (int ipart=0;ipart<partvector.size();ipart++)
769 >        for (int ipart=0;ipart<(int)partvector.size();ipart++)
770          {
771              dout << "     - " << partvector[ipart] << endl;
772          }
# Line 769 | Line 775 | void splitupcut(string incut, vector<str
775  
776   int atleastvalue(string expression, int &morethanlessthan) // takes in an expression such as ">2" or ">=3" and returns e.g. 3 (in both examples)
777   {
778 <  int retval=0;
778 > //  int retval=0;
779    if(expression.substr(0,1)==">"&&expression.substr(1,1)=="=") {
780   //    dout << "The expression " << expression << " is saying that we have at least " << atoi(expression.substr(2,1).c_str()) << " jets" << endl;
781      morethanlessthan=1;
# Line 795 | Line 801 | int atleastvalue(string expression, int
801      morethanlessthan=-1;
802      return 1+atoi(expression.substr(2,1).c_str());
803    }
804 +  
805 +  return -1234567;
806   }
807  
808   int do_jet_cut(string incut, int *nJets) {
# Line 830 | Line 838 | int do_jet_cut(string incut, int *nJets)
838      dout << "Is of type >" << endl;
839      return 0;
840    }
841 +  return -12345;
842   }
843  
844   string interpret_cut(string incut, bool &isJetCut, int *permittednJets)
# Line 895 | Line 904 | string interpret_cuts(vector<string> &cu
904      int finalJetCut=-1;
905      int permittednJets[20];
906      for(int ijet=0;ijet<20;ijet++) permittednJets[ijet]=1;
907 <    int morethanlessthan=0;//-1: less than, 0: exactly, 1: more than
908 <    for(int icut=0;icut<cutparts.size();icut++)
907 > //    int morethanlessthan=0;//-1: less than, 0: exactly, 1: more than
908 >    for(int icut=0;icut<(int)cutparts.size();icut++)
909      {
910          if(icut==0) nicecut<<interpret_cut(cutparts[icut],isJetCut,permittednJets);
911          else {
# Line 961 | Line 970 | TH1F * makehistofromfunction(TF1 *f1,TH1
970    histo->SetTitle(histoname.str().c_str());
971    histo->SetName(histoname.str().c_str());
972    int nbins=histo->GetNbinsX();
973 <  float low=histo->GetBinLowEdge(1);
974 <  float hi=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX());
973 > //  float low=histo->GetBinLowEdge(1);
974 > //  float hi=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX());
975    
976    for(int i=0;i<=nbins;i++) {
977      histo->SetBinContent(i,(f1->Integral(histo->GetBinLowEdge(i),histo->GetBinLowEdge(i)+histo->GetBinWidth(i)))/histo->GetBinWidth(i));
# Line 1331 | Line 1340 | void save_with_ratio(TH1F *nominator, TH
1340    
1341    Double_t chi2;
1342    Int_t ndf,igood;
1343 <  Double_t res=0.0;
1343 > //  Double_t res=0.0;
1344    Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW");
1345  
1346    stringstream Chi2text;
# Line 1346 | Line 1355 | void save_with_ratio(TH1F *nominator, TH
1355    chi2probbox->SetTextSize(0.08);
1356    chi2probbox->SetTextAlign(11);
1357    chi2probbox->Draw();
1358 +  
1359 +  stringstream CompRatio;
1360 +  CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral();
1361 +  TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str());
1362 +  CompleteRatio->SetTextSize(0.08);
1363 +  CompleteRatio->SetTextAlign(31);
1364 +  CompleteRatio->Draw();
1365 +  
1366    CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1367  
1368   //  float KS   = nominator->KolmogorovTest(denominator);
# Line 1389 | Line 1406 | void flag_this_change(string function, i
1406    if(checked==2) write_info(function,peakmodificationwarning.str());
1407   }
1408  
1409 < void write_analysis_type(bool isonpeak) {
1409 > void write_analysis_type(bool isonpeak, bool dobtag) {
1410   //http://www.network-science.de/ascii/, ogre
1411    if(!PlottingSetup::publicmode) {
1412      if(isonpeak) {
1413 + //font: big    
1414          dout << "\033[1;34m" << endl;
1415 <        dout <<  "    //\\\\                                  _                          _           _     " << endl;
1416 <        dout <<  "   //  \\\\     ___  _ __  _ __   ___  __ _| | __     __ _ _ __   __ _| |_   _ ___(_)___" << endl;
1417 <        dout <<  "  //    \\\\   / _ \\| '_ \\| '_ \\ / _ \\/ _` | |/ /    / _` | '_ \\ / _` | | | | / __| / __|" << endl;
1418 <        dout <<  " //      \\\\ | (_) | | | | |_) |  __/ (_| |   <    | (_| | | | | (_| | | |_| \\__ \\ \\__ \\" << endl;
1419 <        dout <<  "//        \\\\ \\___/|_| |_| .__/ \\___|\\__,_|_|\\_\\    \\__,_|_| |_|\\__,_|_|\\__, |___/_|___/" << endl;
1420 <        dout <<  "                        |_|                                            |___/" << endl;
1415 >        dout <<  "                             _ __________                                                         " << endl;
1416 >        dout <<  "                            | |___  /  _ \\                                                       " << endl;
1417 >        dout <<  "       /\\           ___     | |  / /| |_) |                                                       " << endl;
1418 >        dout <<  "      /  \\         /  _|_   | | / / |  _ <                                                         " << endl;
1419 >        dout <<  "     /    \\        | (_| |__| |/ /__| |_) |                                                       " << endl;
1420 >        dout <<  "                   \\___|\\____//_____|____/                                                       " << endl;
1421      } else {
1404        dout << "\033[1;33m" << endl;
1405 /*      dout <<  "                    __  __                  _                          _           _     " << endl;
1406        dout <<  "              ___  / _|/ _|_ __   ___  __ _| | __     __ _ _ __   __ _| |_   _ ___(_)___ " << endl;
1407        dout <<  "    /\\       / _ \\| |_| |_| '_ \\ / _ \\/ _` | |/ /    / _` | '_ \\ / _` | | | | / __| / __|" << endl;
1408        dout <<  " /\\/  \\__   | (_) |  _|  _| |_) |  __/ (_| |   <    | (_| | | | | (_| | | |_| \\__ \\ \\__ \\" << endl;
1409        dout <<  "             \\___/|_| |_| | .__/ \\___|\\__,_|_|\\_\\    \\__,_|_| |_|\\__,_|_|\\__, |___/_|___/" << endl;
1410        dout <<  "                          |_|                                            |___/           " << endl;*/
1411        
1422   //font: big    
1423 +        dout << "\033[1;33m" << endl;
1424          dout <<  "                    _      _ __________                                                             " << endl;
1425          dout <<  "                   (_)    | |___  /  _ \\                                                            " << endl;
1426          dout <<  "       /\\           _     | |  / /| |_) |                                                           " << endl;
# Line 1417 | Line 1428 | void write_analysis_type(bool isonpeak)
1428          dout <<  "   /      \\        | | |__| |/ /__| |_) |                                                           " << endl;
1429          dout <<  "                   |_|\\____//_____|____/                                                            " << endl;
1430      }
1431 <    dout << "\033[0m" << endl;
1431 >  
1432 >    if(dobtag) {
1433 > //font: big    
1434 >        dout <<  "\033[1;32m                  \\     /                                                                " << endl;
1435 >        dout <<  "             \\    o ^ o    /                                                             " << endl;
1436 >        dout <<  "               \\ (     ) /                                                               " << endl;
1437 >        dout <<  "    ____________(%%%%%%%)____________        _          _ __________                     " << endl;
1438 >        dout <<  "   (     /   /  )%%%%%%%(  \\   \\     )      | |        | |___  /  _ \\                    " << endl;
1439 >        dout <<  "   (___/___/__/           \\__\\___\\___)      | |__      | |  / /| |_) |                   " << endl;
1440 >        dout <<  "      (     /  /(%%%%%%%)\\  \\     )         | '_ \\ _   | | / / |  _ <                    " << endl;
1441 >        dout <<  "       (__/___/ (%%%%%%%) \\___\\__)          | |_) | |__| |/ /__| |_) |                   " << endl;
1442 >        dout <<  "               /(       )\\                  |_.__/ \\____//_____|____/                    " << endl;
1443 >        dout <<  "             /   (%%%%%)   \\                                                             " << endl;
1444 >        dout <<  "                  (%%%)                                                                  " << endl;
1445 >        dout <<  "                    !                                                                    " << endl;
1446 >  }
1447 >  } else {
1448 >    //we're in public! don't advertise what we're up to :-)
1449 >       dout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
1450 >       dout << "                              Starting the analysis                     " << endl;
1451 >       dout << "                                     i:" << !isonpeak << " , b " << dobtag << endl;
1452 >       dout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
1453    }
1454 +  dout << "\033[0m" << endl;
1455 +
1456   }
1457  
1458  
# Line 1427 | Line 1461 | vector<string> StringSplit(string str, s
1461          vector<string> results;
1462          
1463          int cutAt;
1464 <        while( (cutAt = str.find_first_of(delim)) != str.npos )
1464 >        while( (cutAt = str.find_first_of(delim)) != (int)str.npos )
1465          {
1466                  if(cutAt > 0)
1467                  {
# Line 1444 | Line 1478 | vector<string> StringSplit(string str, s
1478  
1479   void manually_set_jzb_cuts(vector<float> &jzb_cut,string jzbcut_string) {
1480          vector<string> jzbcutvector = StringSplit(jzbcut_string,",");
1481 <        for(int i=0;i<jzbcutvector.size();i++) {
1481 >        for(int i=0;i<(int)jzbcutvector.size();i++) {
1482                  jzb_cut.push_back(atoi(jzbcutvector[i].c_str()));
1483                  dout << "Added a JZB cut manually at " << atoi(jzbcutvector[i].c_str()) << endl;
1484          }
# Line 1458 | Line 1492 | void process_directory(TString directory
1492          dp = opendir (directory);
1493          if (dp != NULL)
1494          {
1495 <                while (ep = readdir (dp))
1495 >                while ((ep = readdir (dp)))
1496                  {
1497                          string filename=(string)ep->d_name;
1498 <                        if(filename.find(".root")!=-1)
1498 >                        if((int)filename.find(".root")!=-1)
1499                          {
1500                                  files.push_back(string(directory)+filename);
1501                          }
# Line 1503 | Line 1537 | const char* concatenate (const char* a,
1537    return bla.str().c_str();
1538   }
1539  
1540 +
1541 + string ReplaceCharacter(string originalstring,string replacethis,string replacewiththis)
1542 + {
1543 +        int pos = originalstring.find(replacethis);
1544 +        while(pos != -1) {
1545 +          originalstring.replace(pos, replacewiththis.length(), replacewiththis);
1546 +          pos = originalstring.find(replacethis);
1547 +        }
1548 +        return originalstring;
1549 + }
1550 +
1551 + string removefunnystring(string name) {
1552 +  name=ReplaceCharacter(name,"[","_");
1553 +  name=ReplaceCharacter(name,"]","_");
1554 +  name=ReplaceCharacter(name,"{","_");
1555 +  name=ReplaceCharacter(name,"}","_");
1556 +  name=ReplaceCharacter(name,".","_");
1557 +  name=ReplaceCharacter(name,",","_");
1558 +  name=ReplaceCharacter(name,";","_");
1559 +  name=ReplaceCharacter(name,":","_");
1560 +  name=ReplaceCharacter(name,"'","_");
1561 +  name=ReplaceCharacter(name,"$","_");
1562 +  name=ReplaceCharacter(name,"@","_");
1563 +  name=ReplaceCharacter(name,"#","_");
1564 +  name=ReplaceCharacter(name,"+","_");
1565 +  name=ReplaceCharacter(name,"-","_");
1566 +  name=ReplaceCharacter(name,"/","_");
1567 +  return name;
1568 + }
1569 +
1570   stringstream all_bugs;
1571  
1572   void bug_tracker(string function, int line, string description) {
# Line 1548 | Line 1612 | float pSTAR(float mglu, float mlsp, floa
1612   }
1613  
1614   float generalizedpSTAR(float massmother, float massdaughter1, float massdaughter2) {
1551        float mz=91.2;
1615          float res=((massmother*massmother)-(massdaughter1+massdaughter2)*(massdaughter1+massdaughter2));
1616          res*=((massmother*massmother)-(massdaughter1-massdaughter2)*(massdaughter1-massdaughter2));
1617          res=TMath::Sqrt(res)/(2*massmother);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines