Example #1
0
void
dumpToPDF(string inName, string fitName){
  TFile *fin = TFile::Open(inName.c_str(), "read"); assert(fin);


  string outName = inName;
  outName.replace(outName.find(".root"), 5, ".pdf");

  //fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root";
  TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit);

  TCanvas c1;
  c1.Print(Form("%s[", outName.c_str()), "pdf"); //Open .pdf

  //get list of keys
  int nplots = fin->GetNkeys(); 
  int nfits = fFit->GetNkeys(); 
  printf("nplots: %i, nfits: %i\n", nplots, nfits);
  if(nplots != nfits){
    cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl;
    abort();
  }
  TList* plots = fin->GetListOfKeys();  
  TList* fits  = fFit->GetListOfKeys();
  for(int i=0; i<nplots; ++i){
    TKey* plot = (TKey*) plots->At(i);
    TKey* fit = (TKey*) fits->At(i);//assume they're in the same order for now

    if(!fin->GetKey(plot->GetName())){
      cout<<"Didn't find "<<plot<<". Removing."<<endl;
      abort();
    }
    if(!fFit->GetKey(fit->GetName())){
      cout<<"Didn't find "<<fit<<". Removing."<<endl;
      abort();
    }
    TCanvas* c = new TCanvas();
    c->Divide(1,2);

    TCanvas* cPlot = (TCanvas*) fin->Get(plot->GetName());
    c->cd(1);
    cPlot->DrawClonePad();

    TCanvas* cFit  = (TCanvas*) fFit->Get(fit->GetName());
    c->cd(2);
    cFit->DrawClonePad();

    string bookmarkName = "Title: ";
    bookmarkName += plot->GetName();

    c->Print(outName.c_str(), bookmarkName.c_str());
  }

  c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .pdf

}
/*************************************************************************************
 * getKS: Searches through the histograms in the plotter output, adds the MC together
 *        for each field, and compares the MC with the Data histogram using a KS test
 *  input:  the main() arguments array
 *  output: writes to stdout the (human-readable) KS statistics of pairs of histograms
 *
 *  Structure-wise: this is fine, can be implemented into class easily.
 ***********************************/
void getKS(const char* argv[]) {
  //open the input TFile
  TFile *f = new TFile(argv[2]);
  f->cd();

  //get the filesystem information from the file
  TList *alokDirs = (TList*) f->GetListOfKeys();

  //loop through the directories in the input file
  for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) {
    TDirectory *cDir  = (TDirectory*) f->Get(alokDirs->At(idir)->GetName());
    TList *alokHistos = (TList*)      cDir->GetListOfKeys();

    // create the MC histogram and start collecting relevant MC histograms
    // from the current directory
    TList *aloh   = new TList;
    // loop through keys (histograms) in current directory
    for(int ihisto=0; alokHistos->At(ihisto) != alokHistos->Last(); ihisto++) {
      if(TString(alokHistos->At(ihisto)->GetName()).Contains("MC8TeV")) {
        TH1F *cHisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName());
        aloh->Add(cHisto);
      }
    }
 
    //merge the data histograms into one histogram
    TH1F *MCHisto = (TH1F*) (aloh->Last())->Clone(TString(cDir->GetName()) + TString("MCHisto"));
    aloh->RemoveLast();
    MCHisto->Merge(aloh);

    cout<<"-------------------- "<<cDir->GetName()<<" -----------------------"<<endl;
    //now create the data histogram and run the KS test
    TH1F *DataHisto = (TH1F*) cDir->Get(alokHistos->Last()->GetName());
    cout<<"  ---> KS Test: "<<cDir->GetName()<<" has probability "<<MCHisto->KolmogorovTest(DataHisto, "D")<<"\n"<<endl;
  }
}
Example #3
0
  void initialize( const char* countdbfn = "counts.root" )
  {
    XSWeightTool::update( "Xsection8TeV_bkg_v4.txt" );
    XSWeightTool::update( "Xsection8TeV_sig_v4.txt" );
    // XSWeightTool::print();

    using namespace std;

    TFile* f = TFile::Open( countdbfn, "read" );
    if( f == NULL || f->IsZombie() )
    {
      return;
    }

    TIter next( f->GetListOfKeys() ); 
    TKey *key;
    int nhist = 0;
    while( (key = (TKey*)next()) ) {
      nhist++;
      // cout << "Key " << nhist << endl;
      // cout << " Classname " << key->GetClassName() << endl;
      // cout << " Title " <<key->GetTitle() << endl;
      if( key->ReadObj()->InheritsFrom( TH1::Class() ) )
      {
	TH1* h = (TH1*)( key->ReadObj() );
	long run_num = TString( h->GetName() ).Atoi();
	num_events[run_num] = h->GetBinContent( 1 );
	// cout << " Run, # of events : " << run_num << ", " <<  h->GetBinContent( 21 ) << endl;
      }
    }
    // cout << "Done" << endl;
  }
Example #4
0
File: Drawgrid.C Project: XuQiao/HI
void Drawgrid(){

        if (!TClass::GetDict("NBD")) {
                gROOT->ProcessLine(".L /afs/cern.ch/user/q/qixu/CMSSW_6_2_5/src/Centrality/NBD_Glauber_fit/NBD/NBDclass.C+");
        }
	
	int sth=0;
	int Gth=0;
	TFile *fs = TFile::Open(Form("G%d%d.root",sth,Gth),"Read");
        tl = fs->GetListOfKeys();
        key = ((TKey*) tl->At(0));
        NBD *n0 = (NBD*)key->ReadObj();
	cout<<n0->mubest<<"\t"<<n0->kbest<<endl;
	cout<<n0->chis<<"\t"<<n0->Ndf<<endl;
	TGraph2D *gr2;
	TCanvas *c1 = new TCanvas();
//	c1->SetLogz();
	gr2 = n0->gr2;
	int N = gr2->GetN();
	double *z = gr2->GetZ();
	double *x = gr2->GetX();
	double *y = gr2->GetY();
	for(int i=0;i<N;i++){
		z[i]=-z[i];
		y[i]=-y[i];
	}
	gr2 = new TGraph2D(N,x,y,z);
	gr2->Draw("surf1");
}
Example #5
0
int main(int argc, char **argv){
    if (argc<2) {
        cout<<"usage: inpector <filename> "<<endl;
        return 0;
    }

    vector<mTree> m_trees;
    
    string fn = argv[1];
    TFile *f = TFile::Open(fn.c_str());
    
    TIter nextkey( f->GetListOfKeys() );
    TKey *key;
    while ( (key = (TKey*)nextkey())) {
        TObject *obj = key->ReadObj();
        if ( obj->IsA()->InheritsFrom( "TTree" ) ) {
            TTree *tree = (TTree*)f->Get(obj->GetName());
            int exist=0;
            for(vector<mTree>::iterator i=m_trees.begin();i!=m_trees.end();i++)
                if (obj->GetName()==(*i).name) exist=1;
            if (!exist) m_trees.push_back(mTree(tree));
        }
    }
    cout<<m_trees.size()<<endl;
    for (vector<mTree>::iterator it = m_trees.begin();it != m_trees.end(); it++)
        it->print();
f->Close();        
    return 0;
}
Example #6
0
pair<Double_t, Double_t> getnLLIn(TString fname, int nJets, TString hyptype) {
 
  TFile *f = TFile::Open(fname.Data(), "READ");
  vector<TH1F*> vhistos;
  
  TList *l_keys = f->GetListOfKeys();
  for(int i = 0; i< l_keys->GetSize(); i++) {
    TString histoName(l_keys->At(i)->GetName());
    if(histoName.Contains(Form("hnJetinZwindow_%s", hyptype.Data()) ) )
      vhistos.push_back((TH1F*)f->Get(histoName.Data()));
    }

  
  Double_t nllIn = 0.;
  Double_t nllInErr2 = 0.;
  for(unsigned int j = 0; j < vhistos.size(); j++) {
    if(nJets <= 1) {
      nllIn      += vhistos.at(j)->GetBinContent(nJets+1);
      nllInErr2  += getError2(vhistos.at(j), nJets+1, nJets+1);
    } else {
      Int_t binHigh = vhistos.at(j)->GetNbinsX() + 1;
      for(Int_t i = 3; i <= binHigh; i++) 
	nllIn   += vhistos.at(j)->GetBinContent(i);
      nllInErr2 += getError2(vhistos.at(j), 3, binHigh);
    }
  }
  
  return make_pair(nllIn, nllInErr2 );  
  f->Close();
  vhistos.clear();
}
Example #7
0
pair<Double_t, Double_t> getnEMuIn(TString fname, int nJets) {
 
  TFile *f = TFile::Open(fname.Data(), "READ");
  vector<TH1F*> vhistos_em;
  
  TList *l_keys = f->GetListOfKeys();
  for(int i = 0; i< l_keys->GetSize(); i++) {
    TString histoName(l_keys->At(i)->GetName());
    if(histoName.EndsWith("em") && histoName.Contains("hnJetinZwindow"))
      vhistos_em.push_back((TH1F*)f->Get(histoName.Data()));
    }

  
  Double_t nEMuIn = 0.;
  Double_t nEMuInErr2 = 0.;
  for(unsigned int j = 0; j < vhistos_em.size(); j++) {
    if(nJets <= 1) {
      nEMuIn      += vhistos_em.at(j)->GetBinContent(nJets+1);
      nEMuInErr2  += getError2(vhistos_em.at(j), nJets+1, nJets+1);
    } else {
      Int_t binHigh = vhistos_em.at(j)->GetNbinsX() + 1;
      for(Int_t i = 3; i <= binHigh; i++) 
	nEMuIn   += vhistos_em.at(j)->GetBinContent(i);
      nEMuInErr2 += getError2(vhistos_em.at(j), 3, binHigh);
    }
  }
  
  return make_pair(nEMuIn, nEMuInErr2 );  
  f->Close();
}
void validateInput(const char* filename, int level=0)
{
  TFile* file = new TFile(filename, "update");
  TIter nextDirectory(file->GetListOfKeys());
  TKey* idir;
  while((idir = (TKey*)nextDirectory())){
    file->cd();
    if( idir->IsFolder() ){
      if( level>-1 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
      file->cd(idir->GetName());
      validateFolder(file, idir->GetName(), level);
    }
    else{
      if( level> 0 ){ std::cout << "Found histogram: " << idir->GetName() << std::endl; }
      if( level>-1 ){ 
	TH1F* h = (TH1F*)file->Get(idir->GetName());
	if(h->Integral() == 0){
	  std::cout << "----- E R R O R ----- : histogram has 0 integral please fix this: --> " << idir->GetName() << std::endl; 
	}
      }
    }
  }
  file->Close();
  return;
}
Example #9
0
void efficiencies( TString fin = "TMVA.root", Int_t type = 2, Bool_t useTMVAStyle = kTRUE )
{
   // argument: type = 1 --> plot efficiency(B) versus eff(S)
   //           type = 2 --> plot rejection (B) versus efficiency (S)
  
   // set style and remove existing canvas'
   TMVAGlob::Initialize( useTMVAStyle );

   // checks if file with name "fin" is already open, and if not opens one
   TFile* file = TMVAGlob::OpenFile( fin );  

   // check if multi-cut MVA or only one set of MVAs
   Bool_t multiMVA=kFALSE;
   TIter nextDir(file->GetListOfKeys());
   TKey *key;
   // loop over all directories and check if
   // one contains the key word 'multicutMVA'
   while ((key = (TKey*)nextDir())) {
      TClass *cl = gROOT->GetClass(key->GetClassName());
      if (!cl->InheritsFrom("TDirectory")) continue;    
      TDirectory *d = (TDirectory*)key->ReadObj();    
      TString path(d->GetPath());
      if (path.Contains("multicutMVA")){         
         multiMVA=kTRUE;
         plot_efficiencies( file, type, d );
      }
   }
   plot_efficiencies( file, type, gDirectory );

   return;
}
Example #10
0
void FillHistograms(TString SAMPLE)
{
  cout<<"Processing sample "<<SAMPLE<<endl;
  //TString PATH("root://eoscms//eos/cms/store/cmst3/user/kkousour/ttH/flat/");
  TString PATH("/afs/cern.ch/work/k/kkousour/private/CMSSW_7_4_12/src/KKousour/TopAnalysis/prod/ttH/");
  TFile *inf  = TFile::Open(PATH+"flatTree_"+SAMPLE+".root");
  TFile *outf = TFile::Open(TString::Format("Histo_%s.root",SAMPLE.Data()),"RECREATE");

  TIter nextKey(inf->GetListOfKeys());
  TKey *key;
  while ((key = (TKey*)nextKey())) {
    TString dirName(key->GetName());
    cout<<"Found directory "<<dirName<<endl;
    
    TH1F *hPass = (TH1F*)inf->Get(dirName+"/TriggerPass");
    outf->mkdir(dirName);  
    TDirectory *dir = (TDirectory*)outf->Get(dirName); 
    TTree *tr   = (TTree*)inf->Get(dirName+"/events");
    
    TreeClass myTree(tr);
    dir->cd();
    hPass->Write("TriggerPass");
    myTree.Loop(dir);
    cout<<"Loop finished"<<endl;
    dir->Close();
    delete tr;
  }
  outf->Close();
  inf->Close();
}
Example #11
0
int stripTrees(char* filename = "all.root") {
  
  char outfilename[100];
  std::string filenameString(filename);
  std::cout << filenameString.size() << std::endl; 
  std::string filenameStripped = filenameString.substr(filenameString.size()-5, filenameString.size());
  //  filenameStripped.erase(filenameStripped
  sprintf(outfilename, "%s_histograms.root", filenameString.c_str());

  std::vector<TTree*> trees;
  std::vector<TH1F*> th1fs;
  std::vector<TH2F*> th2fs;
  std::vector<TProfile*> tprofiles;

  TFile* f = new TFile(filename);

  // Create an iterator on the list of keys
  TIter nextTopLevelKey = NULL;
  nextTopLevelKey=(f->GetListOfKeys());
  
  TKey *keyTopLevel;
  while (keyTopLevel = (TKey*)nextTopLevelKey()) {
    
    TString name(keyTopLevel->GetName());
    TString className(keyTopLevel->GetClassName());
    
    if ((className.CompareTo("TTree") != 0) || 
	((name.CompareTo("plotvariables") == 0) || (name.CompareTo("inputfiles") == 0))) {
      std::cout << "Adding " << keyTopLevel->GetName() << std::endl;
      
      if (className.CompareTo("TTree") == 0)
	trees.push_back((TTree*) f->Get(name));
      else if (className.CompareTo("TH1F") == 0)
	th1fs.push_back((TH1F*) f->Get(name));
      else if (className.CompareTo("TH2F") == 0)
	th2fs.push_back((TH2F*) f->Get(name));
      else if (className.CompareTo("TProfile") == 0)
	tprofiles.push_back((TProfile*) f->Get(name));
    }
  }

  TFile* out = new TFile(outfilename, "recreate");
  out->cd();
  for (unsigned int i=0; i<trees.size(); i++) 
    trees[i]->Write();

  for (unsigned int i=0; i<th1fs.size(); i++) 
    th1fs[i]->Write();

  for (unsigned int i=0; i<th2fs.size(); i++) 
    th2fs[i]->Write();

  for (unsigned int i=0; i<tprofiles.size(); i++) 
    tprofiles[i]->Write();

  out->Close();
  
  return 0;
}
Example #12
0
pair<Double_t, Double_t> getkFromAll(TString fname, int nJets, TString hyp_type) {
  
  
  TFile *f = TFile::Open(fname.Data(), "READ");
  vector<TH1F*> vhistos_ee;
  vector<TH1F*> vhistos_mm;
  
  TList *l_keys = f->GetListOfKeys();
  for(int i = 0; i< l_keys->GetSize(); i++) {
    TString histoName(l_keys->At(i)->GetName());
    if(histoName.EndsWith("ee") && histoName.Contains("hnJetinZwindow"))
      vhistos_ee.push_back((TH1F*)f->Get(histoName.Data()));
    if(histoName.EndsWith("mm") && histoName.Contains("hnJetinZwindow"))
      vhistos_mm.push_back((TH1F*)f->Get(histoName.Data()));
  }
  
 //get the numbers for ee
  Double_t nEvts_in_ee = 0.0;
  Double_t nEvts_inErr2_ee = 0.0;
  for(unsigned int j = 0 ; j < vhistos_ee.size(); j++) {
    if(nJets <= 1) {
      nEvts_in_ee     += vhistos_ee.at(j)->GetBinContent(nJets+1);
      nEvts_inErr2_ee += getError2(vhistos_ee.at(j), nJets+1, nJets+1);
    } else {
      Int_t binHigh = vhistos_ee.at(j)->GetNbinsX() + 1;
      for(Int_t i = 3; i <= binHigh; i++) 
	nEvts_in_ee +=vhistos_ee.at(j)->GetBinContent(i);
      nEvts_inErr2_ee = getError2(vhistos_ee.at(j), 3, binHigh);
    }
  }
  
  Double_t nEvts_in_mm = 0.0;
  Double_t nEvts_inErr2_mm = 0.0;
  for(unsigned int j = 0 ; j < vhistos_mm.size(); j++) {
    if(nJets <=1) {
      nEvts_in_mm += vhistos_mm.at(j)->GetBinContent(nJets+1);
      nEvts_inErr2_mm += getError2(vhistos_mm.at(j), nJets+1, nJets+1);
    } else {
      Int_t binHigh = vhistos_mm.at(j)->GetNbinsX() + 1;
      for(Int_t i = 3; i <= binHigh; i++) 
	nEvts_in_mm +=   vhistos_mm.at(j)->GetBinContent(i);
      nEvts_inErr2_mm += getError2(vhistos_mm.at(j), 3, binHigh);
    }
  }
  
  Double_t k     = 0.;
  Double_t kErr2 = 0.; 
  if(hyp_type == "mm") {
    k = 0.5*sqrt(nEvts_in_mm/nEvts_in_ee);
    kErr2 = (1./16.)*(nEvts_inErr2_mm/nEvts_in_ee/nEvts_in_mm + nEvts_inErr2_ee*nEvts_in_mm/pow(nEvts_in_ee,3));
  } else if(hyp_type == "ee") {
    k = 0.5*sqrt(nEvts_in_ee/nEvts_in_mm);
    kErr2 = (1./16.)*(nEvts_inErr2_ee/nEvts_in_mm/nEvts_in_ee + nEvts_inErr2_mm*nEvts_in_ee/pow(nEvts_in_mm,3));
  }

  f->Close();
  return make_pair(k, kErr2);

}
Example #13
0
TTree *getTree(const std::string &arg)
{
	std::string::size_type pos = arg.find('@');

	std::string fileName;
	if (pos == std::string::npos)
		fileName = arg;
	else
		fileName = arg.substr(pos + 1);

	TFile *file = TFile::Open(fileName.c_str());
	if (!file) {
		std::cerr << "ROOT file \"" << fileName << "\" could not be "
		             "opened for reading." << std::endl;
		return 0;
	}

	TTree *tree = 0;
	if (pos == std::string::npos) {
		TIter next(file->GetListOfKeys());
		TObject *obj;
		TString treeName;
		while((obj = next())) {
			TString name = static_cast<TKey*>(obj)->GetName();
			TTree *cur = dynamic_cast<TTree*>(file->Get(name));
			if (!cur || name == treeName)
				continue;

			if (tree) {
				std::cerr << "ROOT file \"" << fileName
				          << "\" contains more than one tree. "
				             "Please use <tree>@<file> syntax."
				          << std::endl;
				return 0;
			}

			tree = cur;
			treeName = name;
		}
	} else {
		TString name(arg.substr(0, pos).c_str());
		tree = dynamic_cast<TTree*>(file->Get(name));

		if (!tree) {
			std::cerr << "ROOT file \"" << fileName << "\" does "
			             "not contain a tree named \"" << name
			          << "\"." << std::endl;
			return 0;
		}
	}

	return tree;
}
Example #14
0
int
main (int argc, char *argv[])
{
  map<string, string> opt;
  vector<string> argVector;
  parseOptions (argc, argv, opt, argVector);
  if (argVector.size () != 1 || opt.count ("help"))
    {
      printHelp (argv[0]);
      return 0;
    }
  TFile *fin;
  if (!(fin = TFile::Open (argVector.at (0).c_str (), "update")))
    {
      cout << "Failed to open " << argVector.at (0) << "!" << endl;
      return 0;
    }
  TIter next0 (fin->GetListOfKeys ());
  TObject *obj0;
  TH1D *cutFlow = 0;
  TDirectoryFile *dir = 0;
  while ((obj0 = next0 ()))
    {
      string obj0Class = ((TKey *) obj0)->GetClassName (),
             obj0Name = obj0->GetName ();

      if (obj0Class == "TDirectoryFile")
        {
          dir = (TDirectoryFile *) fin->Get (obj0Name.c_str ());
          TIter next1 (dir->GetListOfKeys ());
          TObject *obj1;
          while ((obj1 = next1 ()))
            {
              string obj1Class = ((TKey *) obj1)->GetClassName (),
                     obj1Name = obj1->GetName ();

              if (obj1Class == "TH1D" && obj1Name.length () >= 7 && ((obj1Name.substr (obj1Name.length () - 7, 7) == "CutFlow" || obj1Name.substr (obj1Name.length () - 7, 7) == "cutFlow")
               || (obj1Name.length () >= 9 && (obj1Name.substr (obj1Name.length () - 9, 9) == "Selection" || obj1Name.substr (obj1Name.length () - 9, 9) == "selection"))
               || (obj1Name.length () >= 8 && (obj1Name.substr (obj1Name.length () - 8, 8) == "MinusOne" || obj1Name.substr (obj1Name.length () - 8, 8) == "minusOne")))
               && !dir->Get ((obj1Name + "LowerLimit").c_str ()) && !dir->Get ((obj1Name + "UpperLimit").c_str ()))
                {
                  cutFlow = (TH1D *) dir->Get (obj1Name.c_str ());
                  cutFlow->SetDirectory (0);
                  getLimits (cutFlow, dir);
                }
            }
        }
    }
  fin->Close ();

  return 0;
}
Example #15
0
map<string, TH1F *> histoToMap (string file, string type)
	{
	map<string, TH1F *> histoMap;
        TKey *key = 0;
        TFile * myFile = new TFile(file.c_str());

        TIter iter (myFile->GetListOfKeys());
        while((key = (TKey*) iter()))
		{
                histoMap[key->GetName()] = (TH1F*)key->ReadObj();
		}
//	myFile->Close();
	return histoMap;
	}
Example #16
0
Int_t Compare(TDirectory* from) {
   TFile * reffile = new TFile("dt_reference.root");
   
   TIter next(reffile->GetListOfKeys());
   TH1 *ref, *draw;
   const char* name;
   Int_t comp;
   Int_t fail = 0;
   TKey* key;

   while ((key=(TKey*)next())) {
      if (strcmp(key->GetClassName(),"TH1F")
          && strcmp(key->GetClassName(),"TH2F") ) 
        continue; //may be a TList of TStreamerInfo
      ref = (TH1*)reffile->Get(key->GetName());
      name = ref->GetName();
      if (strncmp(name,"ref",3)) continue;
      name += 3;
      draw = (TH1*)from->Get(name);
      if (!draw) {
         if (!gSkipped.FindObject(name)) {
            cerr << "Miss: " << name << endl;
            fail++;
         }
         continue;
      }
      comp = HistCompare(ref,draw);
      if (comp!=0) {
         cerr << "Fail: " << name << ":" << comp << endl;
         fail++;
         if (gInteractiveTest) {
            TCanvas * canv = new TCanvas();
            canv->Divide(2,1);
            canv->cd(1); 
            TString reftitle = "Ref: ";
            reftitle.Append(ref->GetTitle());
            ref->SetTitle(reftitle);
            ref->Draw();
            canv->cd(2); draw->Draw();
            return 1;
         }
      } else {
         if (gQuietLevel<1) cerr << "Succ: " << name << ":" << comp << endl;
      }
   }
   delete reffile;
   return fail;
}
Example #17
0
//================================================
void mode1()
{
  TString filename = "Rootfiles/Run14_AuAu200.StudyLumiDep.root";
  TFile *fin = TFile::Open(filename.Data());
  TFile *fout = TFile::Open(Form("%s_filter.root",filename.Data()),"recreate");
  TKey *key;
  TIter nextkey(fin->GetListOfKeys());
  while ((key = (TKey*)nextkey())) 
    {
      TObject *obj = key->ReadObj();   
      if ( obj->IsA()->InheritsFrom( "TH2" ) ) continue;
      obj->Write();
    }
  fout->Close();
  fin->Close();
}
void printCutflowData(string s) {
  TFile* f = TFile::Open(s.c_str());


  TList * AllKeys=f->GetListOfKeys();
  int NKeys = AllKeys->GetEntries();
  //cout << NKeys << endl;
  TIter next(AllKeys);
  TKey *key;
  vector<TKey* > cutflowKeys;
  for(int i =0 ; i < NKeys ; i++)
  {
    key=(TKey*)next();
    string name = key->GetTitle();
    if(name.find("CutFlow") != std::string::npos)
    {
      cutflowKeys.push_back(key);
      //cout << name << endl;
      
    }
  }
  TCanvas * c1 = new TCanvas;
  TH1F *h = (TH1F*)cutflowKeys[0]->ReadObj();
  for(int i=1; i<cutflowKeys.size();i++)
  {
    TH1F *temp = (TH1F*)cutflowKeys[i]->ReadObj();
    h->Add(temp);
  } 
  
  int Ndecimals = 2;
    enum CutEnum {
    NxAOD=0, NDxAOD=1, ALLEVTS=2, DUPLICATE=3, TRIGGER=4, GRL=5, DQ=6, VERTEX=7, TWO_LOOSE_GAM=8, AMBIGUITY=9,
    TRIG_MATCH=10, GAM_TIGHTID=11, GAM_ISOLATION=12, RELPTCUTS=13, MASSCUT=14, PASSALL=15 };

  TString format("  %-24s%10."); format+=Ndecimals; format+="f%11.2f%%%11.2f%%\n";
  int all_bin = h->FindBin(ALLEVTS);
  printf("  %-24s%10s%12s%12s\n","Event selection","Nevents","Cut rej.","Tot. eff.");
  for (int bin=1;bin<=h->GetNbinsX();++bin) {
    double ntot=h->GetBinContent(all_bin), n=h->GetBinContent(bin), nprev=h->GetBinContent(bin-1);
    TString cutName(h->GetXaxis()->GetBinLabel(bin));
    cutName.ReplaceAll("#it{m}_{#gamma#gamma}","m_yy");
    if (bin==1||nprev==0||n==nprev)
      printf(format.Data(),cutName.Data(),n,-1e-10,n/ntot*100);
    else // if the cut does something, print more information
      printf(format.Data(),cutName.Data(),n,(n-nprev)/nprev*100,n/ntot*100);
  }
}
Example #19
0
vector<TH1*>
GetAllTH1(TFile& rootfile)
{
  TH1 *h=0;
  TKey *obj=0;
  TListIter li(rootfile.GetListOfKeys());
  vector<TH1*> histvec;

  while (obj = static_cast<TKey*>(li.Next()))
    {
      h = dynamic_cast<TH1*>(obj->ReadObj());
      if (h!=NULL) 
	histvec.push_back(h);
    }
  cout << histvec.size() << endl;
  return histvec;
}
Example #20
0
TGraphAsymmErrors * myGraph(std::string fname){
	TFile * f = TFile::Open(fname.c_str());
	TList * l1 = f->GetListOfKeys();
	cout<<l1->At(0)->GetName()<<endl;
	TDirectory * d1 = (TDirectory*)f->Get(l1->At(0)->GetName());
	TList * l2 = d1->GetListOfKeys();
	cout<<l2->At(0)->GetName()<<endl;
	TDirectory * d2 = (TDirectory*)d1->Get(l2->At(0)->GetName());
	TList * l3 = d2->GetListOfKeys();
	cout<<l3->GetSize()<<endl;
	cout<<l3->At(8)->GetName()<<endl;
	TDirectory * d3 =  (TDirectory*)d2->Get(l3->At(8)->GetName());
	TDirectory * d4 =  (TDirectory*)d3->Get("Btag");
	TDirectory * d5 =  (TDirectory*)d4->Get("Integrated");
	TList * l4 = d5->GetListOfKeys();
	cout<<l4->At(4)->GetName()<<endl;
	TGraphAsymmErrors * tga = (TGraphAsymmErrors*)d5->Get(l4->At(4)->GetName());
	return tga;
}
Example #21
0
void FillHistograms(TString SAMPLE)
{
  cout<<"Processing sample "<<SAMPLE<<endl;
  TString PATH("../../prod/ttbar/");
  TFile *inf  = TFile::Open(PATH+"flatTree_"+SAMPLE+".root");
  TFile *outf = TFile::Open(TString::Format("Histo_%s.root",SAMPLE.Data()),"RECREATE");

  TIter nextKey(inf->GetListOfKeys());
  TKey *key;
  while ((key = (TKey*)nextKey())) {
    TString dirName(key->GetName());
    cout<<"Found directory "<<dirName<<endl;
    
    TH1F *hPass = (TH1F*)inf->Get(dirName+"/TriggerPass");
    outf->mkdir(dirName);  
    TDirectory *dir = (TDirectory*)outf->Get(dirName); 
    TTree *tr   = (TTree*)inf->Get(dirName+"/events");
    if (dirName.Contains("Boost")) {
      TreeClassBoosted myTree(tr);
      dir->cd();
      hPass->Write("TriggerPass");
      myTree.Loop(dir);
      cout<<"Loop finished"<<endl;
      dir->Close();
      cout<<"directory closed"<<endl;
      delete tr;
      cout<<"Tree deleted"<<endl;
    }
    else {
      TreeClassResolved myTree(tr);
      dir->cd();
      hPass->Write("TriggerPass");
      myTree.Loop(dir);
      cout<<"Loop finished"<<endl;
      dir->Close();
      cout<<"directory closed"<<endl;
      delete tr;
      cout<<"Tree deleted"<<endl;
    }
  }
  outf->Close();
  inf->Close();
}
Example #22
0
void superimposeHistos()
{
  TFile* bFile = TFile::Open("Electron_In_Jets_900GeV_bJets.root");
  TFile* cFile = TFile::Open("Electron_In_Jets_900GeV_cJets.root");
  TFile* udsgFile = TFile::Open("Electron_In_Jets_900GeV_udsgJets.root");
  
  TIter next(bFile->GetListOfKeys());
  TFile* newFile = new TFile("testFile.root", "RECREATE");
  while(TKey* key = (TKey*)next())
  {
    TH1F* bHist = (TH1F*)bFile->Get(key->GetName());
    bHist->SetFillColor(2);
    
    TH1F* cHist = (TH1F*)cFile->Get(key->GetName());
    cHist->SetFillColor(3);
    
    TH1F* udsgHist = (TH1F*)udsgFile->Get(key->GetName());
    udsgHist->SetFillColor(4);
    
    THStack* stack = new THStack(bHist->GetName(), bHist->GetTitle());
    stack->Add(udsgHist, "hist ][");
    stack->Add(cHist, "hist ][");
    stack->Add(bHist, "hist ][");
    
    TLegend* legend = new TLegend(0.5, 0.68, 0.88, 0.88);
    legend->AddEntry(bHist, "b-Jets");
    legend->AddEntry(cHist, "c-Jets");
    legend->AddEntry(udsgHist, "udsg-Jets");
    
    TCanvas* canvas = new TCanvas(bHist->GetName());
    stack->Draw();
    stack->GetXaxis()->SetTitle(bHist->GetXaxis()->GetTitle());
    legend->Draw();
    canvas->Write(canvas->GetName());
  }
  
  newFile->Close();
  bFile->Close();
  cFile->Close();
  udsgFile->Close();
}
Example #23
0
vector<TH1*>
GetAllTH1(TFile& rootfile)
{
  TH1 *h=0;
  TKey *obj=0;
  TListIter li(rootfile.GetListOfKeys());
  vector<TH1*> histvec;

  while (obj = static_cast<TKey*>(li.Next()))
    {
      h = dynamic_cast<TH1*>(obj->ReadObj());
      if (h!=NULL && h->InheritsFrom("TH1"))
	{
	  string s(h->GetName());
	  if ( s.find("adc") != string::npos ) 
	    histvec.push_back(h);
	}
    }
  cout << histvec.size() << endl;
  return histvec;
}
Example #24
0
void AdaptFileStructure(TString fileName)
{
  TFile* f = TFile::Open(fileName.Data(), "READ");
  TList* cList = new TList();
  cList->SetName("cList");
  cList->SetOwner(kTRUE);
  for (Int_t i = 0; i < gFile->GetNkeys(); i++) {
    TObject* obj = f->GetListOfKeys()->At(i);
    TString name = obj->GetName();
    TObject* obj2 = f->Get(name.Data());
    cList->Add(obj2); 
  }
  
  TString fileNameOutput = fileName;
  fileNameOutput.ReplaceAll(".root", "_commonStructure.root");
  TFile* fOut = TFile::Open(fileNameOutput.Data(), "RECREATE");
  fOut->mkdir("PWGLF_PPVsMultXCheck_MC");
  fOut->cd("PWGLF_PPVsMultXCheck_MC");
  cList->Write("cList", TObject::kSingleKey);
  fOut->Close();
  f->Close();
}
void plotr(int top){
  if (setup("vm","","pol__")==kFALSE) return;

  c = new TCanvas("R", "R");
  ct = new TCanvas("ct","ct");
  c->AddExec("tnail","tnail()");

  int itop = top-1;
  TFile* fy = _fyexp[itop];

  int nq2wbins = fy->GetNkeys();
  int nrows = 4;
  int ncols = nq2wbins/nrows;
  c->Divide(nrows, ncols);
  TIter nextkey(fy->GetListOfKeys());
  TKey *key;
  int iq2wbin = 0;
  while (key = (TKey*)nextkey()) {
    TString Q2Wdirname = key->GetName();
    if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue;
    cout << "Q2Wdirname = " << Q2Wdirname << endl;
    TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hRvVar",Q2Wdirname.Data());
    TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hRvVar",Q2Wdirname.Data());
    cout << "hname_pos = " << hname_pos << endl;
    cout << "hname_neg = " << hname_neg << endl;
    TH1D* hpos = (TH1D*)fy->Get(hname_pos);
    TH1D* hneg = (TH1D*)fy->Get(hname_neg);
    if (hpos==NULL || hneg==NULL) cout << "histogram not found" << endl;

    //cosmetics and display
    hpos->SetLineColor(kRed);
    hneg->SetLineColor(kBlue);
    c->cd(iq2wbin+1);
    hpos->Draw();
    hneg->Draw("sames");
    iq2wbin+=1;
  }
  c->Update();
}
Example #26
0
void readin(){
	char name[200];
	//sprintf(name, "Analysis_calib%d_wtq%d.root", 2, 1);
	sprintf(name, "CMS_calib%d_wtq%d.root", 2, 1);
	TFile* fin = TFile::Open(name);
  
   TObject *obj; 
   TKey *key;
   TIter next(fin->GetListOfKeys());
  
   while((key = (TKey*)next())){
     obj=key->ReadObj();
     cout<<obj->GetName()<<endl;
  }


   /*

   int countline = 0;
   cout<<REF_FCAL<<endl;

   for(int ic=0; ic<NCENT; ic++){
       for(int det0=0; det0<REF_FCAL; det0++){
           for(int har=0; har<NHAR; har++){
               for(int sub=0; sub<2; sub++){
                   for(int pos=0; pos<3; pos++){
                       sprintf(name, "gr_CMS_Cal_ic%d_ref%d_ih%d_pos%d_sub%d", ic, det0, har, pos, sub);
                       key =(TKey*) next(); countline++; if(strcmp(key->GetName(),name)){ cout<<"something is wrong "<< name<<" "<<key->GetName()<<" "<<countline<<endl;break;}
                       gr_CMS_Cal[ic][det0][har][pos+3*sub] = (TGraphErrors*)key->ReadObj();

                   }
               }
           }
       } 
   }

   */

}
Example #27
0
void rescaleBoundaryHists(std::string infile, int numSamples=-1){

  TFile* f = new TFile(infile.c_str(), "UPDATE");
  TDirectory* dir = 0;

  TIter dir_it(f->GetListOfKeys());
  TKey* dir_k;
  while ((dir_k = (TKey *)dir_it())) {
    if (TString(dir_k->GetClassName()) != "TDirectoryFile") continue;
    std::string dir_name = std::string(dir_k->GetTitle());
    if(dir_name == "") continue;
    dir = (TDirectory*)dir_k->ReadObj();
    if(dir == 0) continue;
    TIter hist_it(dir->GetListOfKeys(), kIterBackward);
    TKey* hist_k;
    while ((hist_k = (TKey *)hist_it())) {
      std::string hist_name = (hist_k->GetTitle());
      if (hist_name.find("_HI") != std::string::npos || hist_name.find("_LOW") != std::string::npos || hist_name.find("h_n_mt2bins") != std::string::npos) {
        TH1* h = (TH1*)hist_k->ReadObj();
        if(numSamples==-1)
            h->Scale(1.0/h->GetEntries());
        else
            h->Scale(1.0/numSamples);
        dir->cd();
        h->Write("",TObject::kOverwrite);
      }
    }
  }

  delete dir;

  gDirectory->GetList()->Delete();
  
  f->Write("",TObject::kOverwrite);
  f->Close();
  delete f;

}
Example #28
0
void RsnTrainInfo(TString analysisMgrFile = "analysis.root") {
   LoadLibsBase();
   TFile *f = TFile::Open(analysisMgrFile.Data(),"READ");
   //   f->ls();
   TList *l = f->GetListOfKeys();
   AliAnalysisManager *mgr = 0;
   TIter next(l);
   TKey *key;
   while ((key=(TKey *)next())) {
      if (!strcmp(key->GetClassName(), "AliAnalysisManager")) {
         mgr = (AliAnalysisManager *)f->Get(key->GetName());
         Printf("");
         PrintManager(mgr);
      }

   }


   while ((mgr = (AliAnalysisManager *) next())) {

   }
   Printf("");
}
void plotasym(int top){
  if (setup("vm","","pol__")==kFALSE) return;

  THStack* hs = new THStack(TString::Format("asym_top%d",top), TString::Format("asym_top%d",top));

  int itop = top-1;
  TFile* fy = _fyexp[itop];
  TIter nextkey(fy->GetListOfKeys());
  TKey *key;
  while (key = (TKey*)nextkey()) {
    TString Q2Wdirname = key->GetName();
    if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue;
    cout << "Q2Wdirname = " << Q2Wdirname << endl;
    TString hname = TString::Format("%s/hAsym/Varset1/hAsym_ACC_CORR_phi",Q2Wdirname.Data());
    cout << "hname = " << hname << endl;
    TH1D* h = (TH1D*)fy->Get(hname);
    if (h==NULL) cout << "histogram not found" << endl;
    //h->Draw();
    hs->Add(h,"e1");
  }
  TCanvas *c = new TCanvas(hs->GetName(),hs->GetTitle());
  hs->Draw("pads");

}
Example #30
0
// input: - Input file (result from TMVA)
//        - use of TMVA plotting TStyle
void mvas( TString fin = "TMVA.root", HistType htype = MVAType, Bool_t useTMVAStyle = kTRUE )
{
   // set style and remove existing canvas'
   TMVAGlob::Initialize( useTMVAStyle );

   // switches
   const Bool_t Save_Images     = kTRUE;

   // checks if file with name "fin" is already open, and if not opens one
   TFile* file = TMVAGlob::OpenFile( fin );  

   // define Canvas layout here!
   Int_t xPad = 1; // no of plots in x
   Int_t yPad = 1; // no of plots in y
   Int_t noPad = xPad * yPad ; 
   const Int_t width = 600;   // size of canvas

   // this defines how many canvases we need
   TCanvas *c = 0;

   // counter variables
   Int_t countCanvas = 0;

   // search for the right histograms in full list of keys
   TIter next(file->GetListOfKeys());
   TKey *key(0);   
   while ((key = (TKey*)next())) {

      if (!TString(key->GetName()).BeginsWith("Method_")) continue;
      if( ! gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory") ) continue;

      TString methodName;
      TMVAGlob::GetMethodName(methodName,key);

      TDirectory* mDir = (TDirectory*)key->ReadObj();

      TIter keyIt(mDir->GetListOfKeys());
      TKey *titkey;
      while ((titkey = (TKey*)keyIt())) {
         if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;

         TDirectory *titDir = (TDirectory *)titkey->ReadObj();
         TString methodTitle;
         TMVAGlob::GetMethodTitle(methodTitle,titDir);

         cout << "--- Found directory for method: " << methodName << "::" << methodTitle << flush;
         TString hname = "MVA_" + methodTitle;
         if      (htype == ProbaType  ) hname += "_Proba";
         else if (htype == RarityType ) hname += "_Rarity";
         TH1* sig = dynamic_cast<TH1*>(titDir->Get( hname + "_S" ));
         TH1* bgd = dynamic_cast<TH1*>(titDir->Get( hname + "_B" ));

         if (sig==0 || bgd==0) {
            if     (htype == MVAType)     
               cout << "mva distribution not available (this is normal for Cut classifier)" << endl;
            else if(htype == ProbaType)   
               cout << "probability distribution not available (this is normal for Cut classifier)" << endl;
            else if(htype == RarityType)  
               cout << "rarity distribution not available (this is normal for Cut classifier)" << endl;
            else if(htype == CompareType) 
               cout << "overtraining check not available (this is normal for Cut classifier)" << endl;
            else cout << endl;
         } 
         else {
            cout << endl;
            // chop off useless stuff
            sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) );
            if      (htype == ProbaType) 
               sig->SetTitle( Form("TMVA probability for classifier: %s", methodTitle.Data()) );
            else if (htype == RarityType) 
               sig->SetTitle( Form("TMVA Rarity for classifier: %s", methodTitle.Data()) );
            else if (htype == CompareType) 
               sig->SetTitle( Form("TMVA overtraining check for classifier: %s", methodTitle.Data()) );
         
            // create new canvas
            TString ctitle = ((htype == MVAType) ? 
                              Form("TMVA response %s",methodTitle.Data()) : 
                              (htype == ProbaType) ? 
                              Form("TMVA probability %s",methodTitle.Data()) :
                              (htype == CompareType) ? 
                              Form("TMVA comparison %s",methodTitle.Data()) :
                              Form("TMVA Rarity %s",methodTitle.Data()));
         
            TString cname = ((htype == MVAType) ? 
                             Form("output_%s",methodTitle.Data()) : 
                             (htype == ProbaType) ? 
                             Form("probability_%s",methodTitle.Data()) :
                             (htype == CompareType) ? 
                             Form("comparison_%s",methodTitle.Data()) :
                             Form("rarity_%s",methodTitle.Data()));

            c = new TCanvas( Form("canvas%d", countCanvas+1), ctitle, 
                             countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 ); 
    
            // set the histogram style
            TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
   
            // normalise both signal and background
            TMVAGlob::NormalizeHists( sig, bgd );
   
            // frame limits (choose judicuous x range)
            Float_t nrms = 4;
            cout << "--- Mean and RMS (S): " << sig->GetMean() << ", " << sig->GetRMS() << endl;
            cout << "--- Mean and RMS (B): " << bgd->GetMean() << ", " << bgd->GetRMS() << endl;
            Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), 
                                                  bgd->GetMean() - nrms*bgd->GetRMS() ),
                                       sig->GetXaxis()->GetXmin() );
            Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), 
                                                  bgd->GetMean() + nrms*bgd->GetRMS() ),
                                       sig->GetXaxis()->GetXmax() );
            Float_t ymin = 0;
            Float_t maxMult = (htype == CompareType) ? 1.3 : 1.2;
            Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult;
   
            // build a frame
            Int_t nb = 500;
            TString hFrameName(TString("frame") + methodTitle);
            TObject *o = gROOT->FindObject(hFrameName);
            if(o) delete o;
            TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), 
                                    nb, xmin, xmax, nb, ymin, ymax );
            frame->GetXaxis()->SetTitle( methodTitle + ((htype == MVAType || htype == CompareType) ? " response" : "") );
            if      (htype == ProbaType  ) frame->GetXaxis()->SetTitle( "Signal probability" );
            else if (htype == RarityType ) frame->GetXaxis()->SetTitle( "Signal rarity" );
            frame->GetYaxis()->SetTitle("Normalized");
            TMVAGlob::SetFrameStyle( frame );
   
            // eventually: draw the frame
            frame->Draw();  
    
            c->GetPad(0)->SetLeftMargin( 0.105 );
            frame->GetYaxis()->SetTitleOffset( 1.2 );

            // Draw legend               
            TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, 
                                          c->GetLeftMargin() + (htype == CompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() );
            legend->SetFillStyle( 1 );
            legend->AddEntry(sig,TString("Signal")     + ((htype == CompareType) ? " (test sample)" : ""), "F");
            legend->AddEntry(bgd,TString("Background") + ((htype == CompareType) ? " (test sample)" : ""), "F");
            legend->SetBorderSize(1);
            legend->SetMargin( (htype == CompareType ? 0.2 : 0.3) );
            legend->Draw("same");

            // overlay signal and background histograms
            sig->Draw("samehist");
            bgd->Draw("samehist");
   
            if (htype == CompareType) {
               // if overtraining check, load additional histograms
               TH1* sigOv = 0;
               TH1* bgdOv = 0;

               TString ovname = hname += "_Train";
               sigOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_S" ));
               bgdOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_B" ));
      
               if (sigOv == 0 || bgdOv == 0) {
                  cout << "+++ Problem in \"mvas.C\": overtraining check histograms do not exist" << endl;
               }
               else {
                  cout << "--- Found comparison histograms for overtraining check" << endl;

                  TLegend *legend2= new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12,
                                                 1 - c->GetRightMargin(), 1 - c->GetTopMargin() );
                  legend2->SetFillStyle( 1 );
                  legend2->SetBorderSize(1);
                  legend2->AddEntry(sigOv,"Signal (training sample)","P");
                  legend2->AddEntry(bgdOv,"Background (training sample)","P");
                  legend2->SetMargin( 0.1 );
                  legend2->Draw("same");
               }
               Int_t col = sig->GetLineColor();
               sigOv->SetMarkerColor( col );
               sigOv->SetMarkerSize( 0.7 );
               sigOv->SetMarkerStyle( 20 );
               sigOv->SetLineWidth( 1 );
               sigOv->SetLineColor( col );
               sigOv->Draw("e1same");
      
               col = bgd->GetLineColor();
               bgdOv->SetMarkerColor( col );
               bgdOv->SetMarkerSize( 0.7 );
               bgdOv->SetMarkerStyle( 20 );
               bgdOv->SetLineWidth( 1 );
               bgdOv->SetLineColor( col );
               bgdOv->Draw("e1same");

               ymax = TMath::Max( ymax, TMath::Max( sigOv->GetMaximum(), bgdOv->GetMaximum() )*maxMult );
               frame->GetYaxis()->SetLimits( 0, ymax );
      
               // for better visibility, plot thinner lines
               sig->SetLineWidth( 1 );
               bgd->SetLineWidth( 1 );

               // perform K-S test
               cout << "--- Perform Kolmogorov-Smirnov tests" << endl;
               Double_t kolS = sig->KolmogorovTest( sigOv );
               Double_t kolB = bgd->KolmogorovTest( bgdOv );
               cout << "--- Goodness of signal (background) consistency: " << kolS << " (" << kolB << ")" << endl;

               TString probatext = Form( "Kolmogorov-Smirnov test: signal (background) probability = %5.3g (%5.3g)", kolS, kolB );
               TText* tt = new TText( 0.12, 0.74, probatext );
               tt->SetNDC(); tt->SetTextSize( 0.032 ); tt->AppendPad(); 
            }

            // redraw axes
            frame->Draw("sameaxis");

            // text for overflows
            Int_t    nbin = sig->GetNbinsX();
            Double_t dxu  = sig->GetBinWidth(0);
            Double_t dxo  = sig->GetBinWidth(nbin+1);
            TString uoflow = Form( "U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%", 
                                   sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100,
                                   sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 );
            TText* t = new TText( 0.975, 0.115, uoflow );
            t->SetNDC();
            t->SetTextSize( 0.030 );
            t->SetTextAngle( 90 );
            t->AppendPad();    
   
            // update canvas
            c->Update();

            // save canvas to file

            TMVAGlob::plot_logo(1.058);
            if (Save_Images) {
               if      (htype == MVAType)     TMVAGlob::imgconv( c, Form("plots/mva_%s",     methodTitle.Data()) );
               else if (htype == ProbaType)   TMVAGlob::imgconv( c, Form("plots/proba_%s",   methodTitle.Data()) ); 
               else if (htype == CompareType) TMVAGlob::imgconv( c, Form("plots/overtrain_%s", methodTitle.Data()) ); 
               else                           TMVAGlob::imgconv( c, Form("plots/rarity_%s",  methodTitle.Data()) ); 
            }
            countCanvas++;
         }
      }
   }
}