Example #1
0
void CopyDir(TDirectory *source) {
   //copy all objects and subdirs of directory source as a subdir of the current directory   
   source->ls();
   TDirectory *savdir = gDirectory;
   TDirectory *adir = savdir->mkdir(source->GetName());
   adir->cd();
   //loop on all entries of this directory
   TKey *key;
   TIter nextkey(source->GetListOfKeys());
   while ((key = (TKey*)nextkey())) {
      const char *classname = key->GetClassName();
      TClass *cl = gROOT->GetClass(classname);
      if (!cl) continue;
      if (cl->InheritsFrom(TDirectory::Class())) {
         source->cd(key->GetName());
         TDirectory *subdir = gDirectory;
         adir->cd();
         CopyDir(subdir);
         adir->cd();
      } else if (cl->InheritsFrom(TTree::Class())) {
         TTree *T = (TTree*)source->Get(key->GetName());
         adir->cd();
         TTree *newT = T->CloneTree(-1,"fast");
         newT->Write();
      } else {
         source->cd();
         TObject *obj = key->ReadObj();
         adir->cd();
         obj->Write();
         delete obj;
     }
  }
  adir->SaveSelf(kTRUE);
  savdir->cd();
}
void CompDir(TDirectory *t1, TDirectory *tref, int run1, int runref) {
   t1->cd();
   //loop on all entries of this directory
   TKey *key;
   TIter nextkey(t1->GetListOfKeys());
   while ((key = (TKey*)nextkey())) {
      const char *classname = key->GetClassName();
      TClass *cl = gROOT->GetClass(classname);
      if (!cl) continue;
      if (cl->InheritsFrom("TDirectory")) {
         t1->cd(key->GetName());
         TDirectory *subdir = gDirectory;
         tref->cd(key->GetName());
         TDirectory *subdirref = gDirectory;
         CompDir(subdir,subdirref,run1,runref);
      } else if (cl->InheritsFrom("TObjArray")) {
         TObjArray *subdir = (TObjArray*)t1->Get(key->GetName());
         TObjArray *subdirref = (TObjArray*)tref->Get(key->GetName());
         CompDir(subdir,subdirref,run1,runref);
      } else if (TString(classname) == "TH1F") {
         TH1 *h1 = (TH1*)t1->Get(key->GetName());
         TH1 *href = (TH1*)tref->Get(key->GetName());
         CompHist(h1,href,run1,runref);
      } else {
         // do nothing
     }
  }
}
Example #3
0
TDirectory* fileDirectory( TDirectory *target, std::string s) 
{
    TDirectory *retval = 0;

    // loop over all keys in this directory
    TIter nextkey(target->GetListOfKeys());
    TKey *key, *oldkey=0;
    while((key = (TKey*)nextkey())) 
    {
	//keep only the highest cycle number for each key
	if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;

	// read object from file
	target->cd();
	TObject *obj = key->ReadObj();
	
	if(obj->IsA()->InheritsFrom(TDirectory::Class())) 
	{
	    // it's a subdirectory
	    //cout << "Found subdirectory " << obj->GetName() << endl;
	    if(strcmp(s.c_str(), obj->GetName()) == 0) return (TDirectory*)obj;
	    
	    if((retval = fileDirectory((TDirectory*)obj, s))) break;
	    
	}
	else break;
    }
    return retval;
}
Example #4
0
void th2polyUSA()
{
   Int_t i, bin;
   const Int_t nx = 48;
   char *states [nx] = {
      "alabama",      "arizona",        "arkansas",       "california",
      "colorado",     "connecticut",    "delaware",       "florida",
      "georgia",      "idaho",          "illinois",       "indiana",
      "iowa",         "kansas",         "kentucky",       "louisiana",
      "maine",        "maryland",       "massachusetts",  "michigan",
      "minnesota",    "mississippi",    "missouri",       "montana",
      "nebraska",     "nevada",         "new_hampshire",  "new_jersey",
      "new_mexico",   "new_york",       "north_carolina", "north_dakota",
      "ohio",         "oklahoma",       "oregon",         "pennsylvania",
      "rhode_island", "south_carolina", "south_dakota",   "tennessee",
      "texas",        "utah",           "vermont",        "virginia",
      "washington",   "west_virginia",  "wisconsin",      "wyoming"
   };
   Float_t pop[nx] = {
    4708708, 6595778,  2889450, 36961664, 5024748,  3518288,  885122, 18537969,
    9829211, 1545801, 12910409,  6423113, 3007856,  2818747, 4314113,  4492076,
    1318301, 5699478,  6593587,  9969727, 5266214,  2951996, 5987580,   974989,
    1796619, 2643085,  1324575,  8707739, 2009671, 19541453, 9380884,   646844,
   11542645, 3687050,  3825657, 12604767, 1053209,  4561242,  812383,  6296254,
   24782302, 2784572,   621760,  7882590, 6664195,  1819777, 5654774,   544270
   };

   gStyle->SetCanvasPreferGL(true);
   TCanvas *usa = new TCanvas("USA", "USA");
   usa->ToggleEventStatus();
   Double_t lon1 = -130;
   Double_t lon2 = -65;
   Double_t lat1 = 24;
   Double_t lat2 = 50;
   TH2Poly *p = new TH2Poly("USA","USA Population",lon1,lon2,lat1,lat2);

   TFile *f;
   f = TFile::Open("http://root.cern.ch/files/usa.root");

   // Define the TH2Poly bins.
   TMultiGraph *mg;
   TKey *key;
   TIter nextkey(gDirectory->GetListOfKeys());
   while (key = (TKey*)nextkey()) {
      obj = key->ReadObj();
      if (obj->InheritsFrom("TMultiGraph")) {
         mg = (TMultiGraph*)obj;
         bin = p->AddBin(mg);
      }
   }

   // Fill TH2Poly.
   for (i=0; i<nx; i++) p->Fill(states[i], pop[i]);

   gStyle->SetOptStat(11);
   gStyle->SetPalette(1);
   p->Draw("gllego");
}
Example #5
0
//________________________________________________________________________________
void FindPeaks(Int_t np=10) {
  TString Out("Results.");
  Out += gSystem->BaseName(gDirectory->GetName());
  Out.ReplaceAll(".root","");
  Out.ReplaceAll(" ","");
  out.open(Out, ios::out);
  TIter nextkey(gDirectory->GetListOfKeys() );
  TKey *key;
  Int_t i = 0;
  Int_t nhists = 0;
  while ((key = (TKey*) nextkey())) {
    TObject *obj = key->ReadObj();
    if (! obj->IsA()->InheritsFrom( "TH1" ) ) continue;
    TH1 *h1 = (TH1*)obj;
    if (h1->GetEntries() < 1000) continue;
    nhists++;
  }
  Int_t nxy = nhists;
  Int_t nx =  (Int_t) TMath::Sqrt(nxy) + 1;
  Int_t ny = nxy/nx + 1;
  c2 = new TCanvas("Anodes","Anodes");
  c2->Divide(nx,ny);
  nextkey.Reset();
  Int_t histNo = 1;
  while ((key = (TKey*) nextkey())) {
    TObject *obj = key->ReadObj();
    if (! obj->IsA()->InheritsFrom( "TH1" ) ) continue;
    if ( obj->IsA()->InheritsFrom( "TH1C" ) ||
	 obj->IsA()->InheritsFrom( "TH1S" ) ||
	 obj->IsA()->InheritsFrom( "TH1I" ) ||
	 obj->IsA()->InheritsFrom( "TH1F" ) ) {
      cout << "Found histogram " << obj->GetName() << endl;
      TH1 *h1 = (TH1*)obj;
      if (h1->GetEntries() < 1000) {
	TString LineH("  {\"");  LineH +=  h1->GetName(); LineH += "\"";
	TString Line("");
	LineH +=  ",-99";
	for (Int_t p = 0; p < np; p++) Line += ",0,0";
	Line += "},// dead";
	cout << LineH << Line << endl;
	out  << LineH << Line << endl;
	continue;
      }
      peaks(h1,np,histNo);
      histNo++;
      //      break;
      if (i < 99) {
	cout << "Type something" << endl;
	cin >> i;
	if (i <= 0) break;
      }
    }
Example #6
0
// helper function to add and weight all plots in the subsamples
void addDir(const std::string& path, const std::vector< std::pair< TFile*, double > >& files, TFile *target, int verbose) 
{
  // loop all objects in the file
  std::vector< std::pair< TFile*, double > >::const_iterator first=files.begin();
  first->first->cd(path.c_str());
  TIter nextkey(gDirectory->GetListOfKeys());
  TKey *key=0;
  while ( (key = (TKey*)nextkey())) {
    // read object from first source file
    first->first->cd(path.c_str());
    TObject *obj = key->ReadObj();
    if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
      // if descendant of TH1 -> mergeit
      TH1 *h1 = (TH1*)obj;
      h1->Sumw2();
      h1->Scale(first->second);
      // loop over all source files and add the content of the
      // corresponding histogram to the one pointed to by "h1"
      for(std::vector< std::pair< TFile*, double > >::const_iterator file=first+1; file!=files.end(); ++file) {
	// make sure we are at the correct directory level by cd'ing to path
	file->first->cd(path.c_str());
	TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
	if ( h2 ) {
	  h2->Sumw2();
	  h1->Add(h2,file->second);
	  delete h2; // don't know if this is necessary, i.e. if
	  // h2 is created by the call to gDirectory above.
	}
      }
    }
    else if (obj->IsA()->InheritsFrom( "TDirectory"  ) ) {
      // for a subdirectory
      if(verbose>1) std::cout << "Found subdirectory " << obj->GetName() << std::endl;
      // create a new subdir of same name and title in the target file
      target->cd();
      TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
      // newdir is now the starting point of another round of merging
      // newdir still knows its depth within the target file via
      // GetPath(), so we can still figure out where we are in the recursion
      addDir(newdir->GetName(),files,target, verbose);
    }
    if ( obj ) {
      target->cd(path.c_str());
      obj->Write( key->GetName() );
    }
    delete obj;
  }
  target->Write();
  delete key;
}
TList* ExtractAllHistograms(TFile* f) {
	TIter nextkey(f->GetListOfKeys());
	TKey *key;
	result = new TList();
	while (key = (TKey*)nextkey()) {
		cout << "Key: " << key->GetName() << endl;
		TObject* obj = key->ReadObj();
		if(obj->InheritsFrom("TPad")) {
			WorkOnPad((TPad*)obj);
		}
		else if(obj->InheritsFrom("TH1")) {
			WorkOnHist((TH1*)obj);
		}
	}
	return result;
}
Example #8
0
void read_histograms(TString file){
    
    TIter nextkey(fName[file]->GetListOfKeys());
    TKey *key;
    
    while((key=(TKey*)nextkey())){
        TString className=key->ReadObj()->ClassName();
        TString keyName=key->GetName();
        if(className=="TH1F" && (keyName.Contains("EventCategories") )){
            TH1F *h=(TH1F*)key->ReadObj();
            h->SetStats(kFALSE);
            hName[h->GetName()+file]=h;
        }
    }
    
}
Example #9
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();
}
Example #10
0
TH1* merge_histos(TList *sourcelist){
  TH1 *htot;

  TFile *first_source = (TFile*)sourcelist->First();
  TDirectory *current_sourcedir = gDirectory;
  //gain time, do not add the objects in the list in memory
  Bool_t status = TH1::AddDirectoryStatus();
  TH1::AddDirectory(kFALSE);
  
  
  // loop over all keys in this directory
  TChain *globChain = 0;
  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key, *oldkey=0;
  while ( (key = (TKey*)nextkey())) {

    //keep only the highest cycle number for each key
    if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;
    
    // read object from first source file
    TObject *obj = key->ReadObj();
    
    // if the object is named "tot_edp_hbcoil" merge it
    if ( obj->FindObject("Tot_Edep_HBCoil")) {

      //      cout << "Merging histogram " << obj->GetName() << endl;
      htot = (TH1*)obj;
      
      // loop over all source files and add the content of the
      // correspondant histogram to the one pointed to by "h1"
      TFile *nextsource = (TFile*)sourcelist->After( first_source );
      while ( nextsource ) {
	// make sure we are at the correct directory level by cd'ing to path
	TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(htot->GetName());
	if (key2) {
	  TH1 *htemp = (TH1*)key2->ReadObj();
	  htot->Add(htemp);
	  delete htemp;
	}
	
	nextsource = (TFile*)sourcelist->After( nextsource );
      }
    }   
  }

  return htot;
}
Example #11
0
NoiseEvolution(char* path_, char* RunsList_){


  GetRuns(path_,RunsList_);

  //Open Reference File
  sprintf(refFile,"%s/Display_PedNoise_RunNb_%d.root",path,iov[0]);
  cout << "\nReference File " << refFile << endl;
  refFile_= new TRFIOFile(refFile);

  //Get Histo Names
  refFile_->cd("Noises");
  TIter nextkey(gDirectory->GetListOfKeys());
  TKey *key;
  while (key = (TKey*)nextkey()) {    
    const char * title;
    title=key->GetTitle();
    if (strncmp(title,"Noises_",6)==0 && strstr(title,"Cumulative")== NULL){
      vHistoNames.push_back(string(title));
      vHistoNBinsX.push_back(((TH1F*)key->ReadObj())->GetNbinsX());
      
      char tmp[128];
      LayerName(title,tmp);
      string tmp1(tmp);
      int i=0;
      while (i<vLayerName.size() && tmp1!=vLayerName[i]){i++;}
      if (i==vLayerName.size())
	vLayerName.push_back(tmp1);      
    }
  }

  book();

  
  for (int i=1;i<iovDim;i++){

    sprintf(inFile,"%s/Display_PedNoise_RunNb_%d.root",path,iov[i]);
    cout << "\nAnalyzing File " << inFile << endl;
    inFile_= new TRFIOFile(inFile);
  
    loop(iov[i]);
  }
  
  save();
}
Example #12
0
void TTSelector::Begin(TTree *){
  TString option = GetOption();
  TObjArray *strobj = option.Tokenize(" ");
  gTrigger = ((TObjString*)strobj->At(0))->GetString().Atoi();
  
  gMode = ((TObjString*)strobj->At(1))->GetString().Atoi();
  CreateMap();
  TString filedir=ginFile;
  filedir.Remove(filedir.Last('.')-4);
  fFile = new TFile(goutFile,"RECREATE");
  fTree = new TTree("M","Tree for GSI Prt Analysis");  
  fEvent = new TPrtEvent();
  fTree->Branch("TPrtEvent", "TPrtEvent", &fEvent, 64000, 2);

  TFile f(gcFile);
  TIter nextkey(f.GetListOfKeys());
  TKey *key;

  while ((key = (TKey*)nextkey())) {
    TGraph *gr = (TGraph*)key->ReadObj();
    TString name = gr->GetName();
    Int_t channel = name.Atoi();

    gGr[channel]= new TGraph(*gr);
  }
  f.Close();

  if(gMode == 1){
    TFile f2(gtFile);
    TIter nextkey2(f2.GetListOfKeys());
    TKey *key2;

    while ((key2 = (TKey*)nextkey2())) {
      TGraph *gr = (TGraph*)key2->ReadObj();
      TString name = gr->GetName();
      Int_t channel = name.Atoi();

      gGrDiff[channel]= new TGraph(*gr);
    }
    f2.Close();
  }
  std::cout<<"Initialization successful"<<std::endl;
  
}
Example #13
0
static int press_key(int m)
        {
        int ch;
        int k;

        if (etu1<2) { Wdisp(); return(1); }   /* 23.10.89 ennen etu1==1 */
        k=sur_wait(1000L*(long)tut_wait_c,Wdisp,1);

        if (k) ch=nextkey(""); else ch=m;
        while (ch!=m && ch!=CODE_LEFT)
            {
            if (ch==CODE_HELP) { etu2=0; ch=m; break; }
            BEEP;
            k=sur_wait(1000L*(long)tut_wait_c,Wdisp,1);
            if (k) ch=nextkey(""); else ch=m;
            }

        return(1);
        }
Example #14
0
void CompDir(TObjArray *t1, TObjArray *tref, int run1, int runref) {
   //loop on all entries of this directory
   if (t1->GetSize()==0) return;
   const char* classname = t1->Last()->ClassName();
   TClass *cl = gROOT->GetClass(classname);
   TKey *key;
   TObjArrayIter nextkey(t1);
   while ((key = (TKey*)nextkey())) {
      if (!tref->FindObject(key->GetName())) continue;
      if (!cl) continue;
      if (cl->InheritsFrom("TDirectory")) {
         CompDir((TDirectory*) key, (TDirectory*) tref->FindObject(key->GetName()),run1,runref);
      } else if (cl->InheritsFrom("TObjArray")) {
         CompDir((TObjArray*) key, (TObjArray*) tref->FindObject(key->GetName()),run1,runref);
      } else if (TString(classname) == "TH1F") {
         CompHist((TH1F*) key, (TH1F*) tref->FindObject(key->GetName()),run1,runref);
      } else {
         // do nothing
     }
  }
}
Example #15
0
int nextch(char *valinta)
        {
        extern int muste_mousewheel;
        int m;

muste_mousewheel=FALSE;

        if (etu==2)
            {
            headline(valinta);
            m=tutch();
            while (m==255) m=tutch();
            if (m!=0) return(m);
            }
        if (etu==1) { m=nextkey(valinta); tutsave(m); return(m); }

		m=nextkey(valinta);
		
muste_mousewheel=TRUE;		
        return (m);
        }
Example #16
0
//------------------------------------------------------------------------------
void
THistWrite::listKeys(TDirectory *td) {
//------------------------------------------------------------------------------

  MsgStream log(msgSvc(), name());

  log << MSG::INFO << "printing keys for: " << td->GetPath()
      << "  (" << td->GetList()->GetSize() << ")" << endmsg;
  TIter nextkey(td->GetList());
  while (TKey *key = (TKey*)nextkey()) {
    if (key != 0) {
      log << MSG::INFO << key->GetName() << " ("
	  << key->IsA()->GetName() << ") "
// 	  << key->GetObjectStat()
// 	  << "  " << key->IsOnHeap()
	  << key->GetCycle()
       	  << endmsg;
    } else { log << MSG::INFO << "key == 0" << endmsg; }

  }

  return;
}
Example #17
0
TList* GetListOfDirectories(TDirectory* dir, const char* match = 0) {
  TIter  nextkey(dir->GetListOfKeys());
  TList* sl     = new TList();
  TKey*  key    = 0;
  TKey*  oldkey = 0;

  while (( key = (TKey*)nextkey() )) {
    TObject *obj = key->ReadObj();
    if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
      TString theName = obj->GetName();
      if (!match) {
	cout << " -> " << theName << endl;
	sl->Add(obj);
      }
      else if (theName.Contains(match)) {
	cout << " -> " << theName << endl;
	sl->Add(obj);
      }
    }
  } // End of while

  return sl;
}
//Clone the file excluding the histogram (code stolen from Rene Brun)
void copyDir(TDirectory *source,std::string iSkipHist,bool iFirst=true) { 
  //copy all objects and subdirs of directory source as a subdir of the current directory   
  TDirectory *savdir = gDirectory;
  TDirectory *adir   = savdir;
  if(!iFirst) adir   = savdir->mkdir(source->GetName());
  if(!iFirst) adir->cd();
  //loop on all entries of this directory
  TKey *key;
  TIter nextkey(source->GetListOfKeys());
  while ((key = (TKey*)nextkey())) {
    const char *classname = key->GetClassName();
    TClass *cl = gROOT->GetClass(classname);
    if (!cl) continue;
    if (cl->InheritsFrom(TDirectory::Class())) {
      source->cd(key->GetName());
      TDirectory *subdir = gDirectory;
      adir->cd();
      copyDir(subdir,iSkipHist,false);
      adir->cd();
    } else {
      source->cd();
      TObject *obj = key->ReadObj();
      std::string pFullName = std::string(adir->GetName())+"/"+std::string(obj->GetName());
      std::string iSkipHist2 = iSkipHist;
      std::string fine_binning = "_fine_binning";
      iSkipHist2.replace(iSkipHist2.find(fine_binning), fine_binning.length(),"");
      if(pFullName.find(iSkipHist) != std::string::npos || pFullName.find(iSkipHist2) != std::string::npos) {
	continue;
      }
      adir->cd();
      obj->Write();
      delete obj;
    }
  }
  adir->SaveSelf(kTRUE);
  savdir->cd();
}
/**
Removes no dir markers from source text.
*/
void CResourceLoader::RemoveNoDirMarkers(TDes& aText)
    {
    TInt nextkey(0);
    while (nextkey < aText.Length())
        {
        nextkey = aText.Locate(KDirNotFound);
        if (nextkey != KErrNotFound)
            {
            aText.Delete(nextkey, 1);
            nextkey++;    
            }
        else
            {
            break;
            }     
        }
    }
Example #20
0
static 
 mk_compend(gk_string *Have, gk_string *Avoid, char *curstr, char *endtype)
{
	char fname[BUFSIZ];
	FILE * f;
	FILE * MorphFopen();
	int i;
	char line[BUFSIZ];
	char savestem[MAXWORDSIZE];
	gk_string TmpHave;
	gk_string TmpAvoid;

	sprintf(line,"endtables/basics/%s.end",  endtype );

	if( ! (f=MorphFopen(line,"r")) ) {
		fprintf(stderr,"could not open [%s]\n", endtype );
		return(-1);
	}
	while(fgets(line,sizeof line,f)) {
		char curendstr[MAXWORDSIZE];

		strcpy(savestem,curstr);

		if( is_blank(line) )
			continue;
		if( Is_comment(line) )
			continue;

		TmpHave = * Have;
		TmpAvoid = * Avoid;

		nextkey(line,curendstr);

		update_end(&TmpHave,&TmpAvoid,savestem,curendstr,line);
	}
	fclose(f);
}
Example #21
0
void RecoMuonValHistoPublisher(char* newFile="NEW_FILE",char* refFile="REF_FILE")
{
  //gROOT->ProcessLine(".x HistoCompare_Tracks.C");
 gROOT ->Reset();
 gROOT ->SetBatch();

 //=========  settings ====================

 char* dataType = "DATATYPE";

 gROOT->SetStyle("Plain");
 gStyle->SetPadGridX(kTRUE);
 gStyle->SetPadGridY(kTRUE);
 gStyle->SetPadRightMargin(0.07);
 gStyle->SetPadLeftMargin(0.13);
 //gStyle->SetTitleXSize(0.07); 
 //gStyle->SetTitleXOffset(0.6); 
 //tyle->SetTitleYSize(0.3);
 //gStyle->SetLabelSize(0.6) 
 //gStyle->SetTextSize(0.5);
 char* refLabel("REF_LABEL, REF_RELEASE REFSELECTION");
 char* newLabel("NEW_LABEL, NEW_RELEASE NEWSELECTION");

 Float_t maxPT=1500.;

 char* fastSim = "IS_FSIM";

 //=============================================


 delete gROOT->GetListOfFiles()->FindObject(refFile);
 delete gROOT->GetListOfFiles()->FindObject(newFile); 

//INPUT FILE IS DEFINED HERE, passed from python wrapper
 TText* te = new TText();
 TFile * sfile = new TFile(newFile);
 TDirectory * sdir=gDirectory;
 TFile * rfile = new TFile(refFile);
 TDirectory * rdir=gDirectory;

//check datatype
 if (dataType == "RECO") {
   if(sfile->cd("DQMData/Run 1/Muons/Run summary")) {;}
   else {
     cout << " Muon Histos for " << dataType << " not found" << endl;
     return;
   }
 }
 else {
   cout << " Data type " << dataType << " not allowed: only RECO is considered" << endl;
   return;
 }
 sdir=gDirectory;
 TIter nextkey( sdir->GetListOfKeys() );
 TList *sl = new TList();
 TKey *key, *oldkey=0;
 cout << "- New DQM muon reco collections: " << endl;
 while ( key = (TKey*)nextkey() ) {
   TObject *obj = key->ReadObj();
   if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
     TString theName = obj->GetName();
     if (theName.Contains("RecoMuonV")) {
       cout << " -> " << theName << endl;
       sl->Add(obj);
     }
   }
 }
 if (sl->GetSize()>0) {
   TString collname2 =sl->At(0)->GetName(); 
 }
 else {
   cout << " No DQM muon reco histos found in NEW file " << endl;
   return;
 }
 
 if (dataType == "RECO") {
   if(rfile->cd("DQMData/Run 1/Muons/Run summary")) {;}
   else {
     cout << " Muon Histos for " << dataType << " not found" << endl;
     return;
   }
 }
 rdir=gDirectory;
 TIter nextkeyr( rdir->GetListOfKeys() );
 TList *rl = new TList();
 TKey *keyr, *oldkeyr=0;
 cout << "- Ref DQM muon reco collections: " << endl;
 while ( keyr = (TKey*)nextkeyr() ) {
   TObject *obj = keyr->ReadObj();
   if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
     TString theName = obj->GetName();
     if (theName.Contains("RecoMuonV")) {
       cout << " -> " << theName << endl;
       rl->Add(obj);
     }
   }
 }
 if (rl->GetSize()>0) {
   TString collname1=rl->At(0)->GetName();
  }
 else {
   cout << " No DQM muon reco histos found in REF file " << endl;
   return;
 }

 TCanvas *canvas;
 
 TH1F *sh1,*rh1;
 TH1F *sh2,*rh2;
 TH1F *sh3,*rh3;
 TH1F *sh4,*rh4;
 TH1F *sh5,*rh5;
 TH1F *sh6,*rh6;
 
 TIter iter_r( rl );
 TIter iter_s( sl );
 TKey * myKey1, *myKey2;
 while ( (myKey1 = (TKey*)iter_r()) ) {
   TString myName = myKey1->GetName();
   collname1 = myName;
   myKey2 = (TKey*)iter_s();
   if (!myKey2) continue;
   collname2 = myKey2->GetName();
      if ( (collname1 != collname2) && (collname1+"FS" != collname2) && (collname1 != collname2+"FS") ) {
     cout << " Different collection names, please check: " << collname1 << " : " << collname2 << endl;
     continue;
   }

   TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/");
   newDir+=myName;
   gSystem->mkdir(newDir,kTRUE);
 
   //rh1 = 0;
   //sh1 = 0;
   //===== For each monitored type as defined in muonValidation_cff.py 
 
   //===== reco muon distributions: GLB
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt",sh1);
   rh1->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p_{T}/p_{T}");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrP",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrP",sh2);
   rh2->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p/p");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3);
   if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3);
   if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3);
   rh3->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p_{T}/p_{T} vs #sigma(#eta)");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4);
   if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4);
   if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4);
   rh4->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p_{T}/p_{T} vs #sigma(p_{T})");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecHistosGlb","Distributions for GlobalMuons (GLB)",1000,1050);

   // Normalize to the same number of "new" events:
   NormalizeHistograms(rh1,sh1);
   NormalizeHistograms(rh2,sh2);

   plot4histos(canvas,
	       sh1,rh1,sh2,rh2,
	       sh3,rh3,sh4,rh4,
	       te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoGlb.pdf");   
   delete l;
   delete canvas;

   //==== efficiencies and fractions GLB
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffP",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffP",sh1);
   //if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("GlobalMuon(GLB) #epsilon vs. p");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffEta",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffEta",sh2);
   rh2->GetYaxis()->SetTitle("GlobalMuon(GLB) #epsilon vs. #eta");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractP",rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractP",sh3);
   rh3->GetYaxis()->SetTitle("GlobalMuon(GLB) fraction vs. p");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractEta",rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractEta",sh4);
   rh4->GetYaxis()->SetTitle("GlobalMuon(GLB) fraction vs. #eta");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecEffHistosGlb","Distributions for GlobalMuons (GLB), efficiencies and fractions",1000,1050);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoGlbEff.pdf");
   delete l;
   delete canvas;

   //===== reco muon distributions: GLBPF
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T}");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrP",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrP",sh2);
   rh2->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p/p");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3);
   if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3);
   if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3);
   rh3->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T} vs #sigma(#eta)");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4);
   if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4);
   if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4);
   rh4->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T} vs #sigma(p_{T})");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecHistosGlbPF","Distributions for PFGlobalMuons (GLBPF)",1000,1050);

   // Normalize to the same number of "new" events:
   NormalizeHistograms(rh1,sh1);
   NormalizeHistograms(rh2,sh2);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoGlbPF.pdf");
   delete l;
   delete canvas;

   //==== efficiencies and fractions GLBPF
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffP",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffP",sh1);
   //if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #epsilon vs. p");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffEta",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffEta",sh2);
   rh2->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #epsilon vs. #eta");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractP",rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractP",sh3);
   rh3->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) fraction vs. p");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractEta",rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractEta",sh4);
   rh4->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) fraction vs. #eta");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecEffHistosGlbPF","Distributions for PFGlobalMuons (GLBPF), efficiencies and fractions",1000,1050);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoGlbPFEff.pdf");
   delete l;
   delete canvas;


   //===== reco muon distributions: STA
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p_{T}/p_{T}");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrP",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrP",sh2);
   rh2->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p/p");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3);
   if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3);
   if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3);
   rh3->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p_{T}/p_{T} vs #sigma(#eta)");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4);
   if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4);
   if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4);
   rh4->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p_{T}/p_{T} vs #sigma(p_{T})");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecHistosSta","Distributions for StandAloneMuons (STA)",1000,1050);

   // Normalize to the same number of "new" events:
   NormalizeHistograms(rh1,sh1);
   NormalizeHistograms(rh2,sh2);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoSta.pdf");
   delete l;
   delete canvas;

   //==== efficiencies and fractions STA
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffP",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffP",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("StandAloneMuon(STA) #epsilon vs. p");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffEta",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffEta",sh2);
   rh2->GetYaxis()->SetTitle("StandAloneMuon(STA) #epsilon vs. #eta");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractP",rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractP",sh3);
   rh3->GetYaxis()->SetTitle("StandAloneMuon(STA) fraction vs. p");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractEta",rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractEta",sh4);
   rh4->GetYaxis()->SetTitle("StandAloneMuon(STA) fraction vs. #eta");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecEffHistosSta","Distributions for StandAloneMuons (STA), efficiencies and fractions",1000,1050);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoStaEff.pdf");
   delete l;
   delete canvas;

   //===== reco muon distributions: TRK
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p_{T}/p_{T}");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrP",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrP",sh2);
   rh2->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p/p");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3);
   if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3);
   if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3);
   rh3->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p_{T}/p_{T} vs #sigma(#eta)");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4);
   if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4);
   if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4);
   rh4->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p_{T}/p_{T} vs #sigma(p_{T})");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecHistosTrk","Distributions for TrackerMuons (TRK)",1000,1050);

   // Normalize to the same number of "new" events:
   NormalizeHistograms(rh1,sh1);
   NormalizeHistograms(rh2,sh2);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoTrk.pdf");
   delete l;
   delete canvas;


   //==== efficiencies and fractions TRK
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffP",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffP",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("TrackerMuon(TRK) #epsilon vs. p");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffEta",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffEta",sh2);
   rh2->GetYaxis()->SetTitle("TrackerMuon(TRK) #epsilon vs. #eta");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractP",rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractP",sh3);
   rh3->GetYaxis()->SetTitle("TrackerMuon(TRK) fraction vs. p");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractEta",rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractEta",sh4);
   rh4->GetYaxis()->SetTitle("TrackerMuon(TRK) fraction vs. #eta");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecEffHistosTrk","Distributions for TrackerMuons (TRK), efficiencies and fractions",1000,1050);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoTrkEff.pdf");
   delete l;
   delete canvas;

   //
   //===== reco muon distributions: Tight Muons
   //
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("Tight Muon #Delta p_{T}/p_{T}");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrP",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrP",sh2);
   rh2->GetYaxis()->SetTitle("Tight Muon #Delta p/p");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3);
   if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3);
   if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3);
   rh3->GetYaxis()->SetTitle("Tight Muon #Delta p_{T}/p_{T} vs #sigma(#eta)");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4);
   if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4);
   if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4);
   rh4->GetYaxis()->SetTitle("Tigh Muon) #Delta p_{T}/p_{T} vs #sigma(p_{T})");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecHistosTgt","Distributions for Tight Muons",1000,1050);

   // Normalize to the same number of "new" events:
   NormalizeHistograms(rh1,sh1);
   NormalizeHistograms(rh2,sh2);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoTgt.pdf");
   delete l;
   delete canvas;


   //==== efficiencies and fractions Tight Muons
   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffP",rh1);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffP",sh1);
  // if(! rh1 && sh1) continue;
   rh1->GetYaxis()->SetTitle("Tight Muon #epsilon vs. p");
   rh1->GetYaxis()->SetTitleSize(0.05);
   rh1->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffEta",rh2);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffEta",sh2);
   rh2->GetYaxis()->SetTitle("Tight Muon #epsilon vs. #eta");
   rh2->GetYaxis()->SetTitleSize(0.05);
   rh2->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractP",rh3);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractP",sh3);
   rh3->GetYaxis()->SetTitle("Tight Muon fraction vs. p");
   rh3->GetYaxis()->SetTitleSize(0.05);
   rh3->GetYaxis()->SetTitleOffset(1.2);

   rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractEta",rh4);
   sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractEta",sh4);
   rh4->GetYaxis()->SetTitle("Tight Muon fraction vs. #eta");
   rh4->GetYaxis()->SetTitleSize(0.05);
   rh4->GetYaxis()->SetTitleOffset(1.2);

   canvas = new TCanvas("RecEffHistosTgt","Distributions for Tight Muons, efficiencies and fractions",1000,1050);

   plot4histos(canvas,
               sh1,rh1,sh2,rh2,
               sh3,rh3,sh4,rh4,
               te,"UU",-1);

   canvas->cd();

   l = new TLegend(0.20,0.48,0.90,0.53);
   l->SetTextSize(0.016);
   l->SetLineColor(1);
   l->SetLineWidth(1);
   l->SetLineStyle(1);
   l->SetFillColor(0);
   l->SetBorderSize(3);
   l->AddEntry(rh1,refLabel,"LPF");
   l->AddEntry(sh1,newLabel,"LPF");
   l->Draw();
   canvas->Print(newDir+"/muonRecoTgtEff.pdf");
   delete l;
   delete canvas;


   //
   // Merge pdf histograms together into larger files, and name them based on the collection names
   //
 gSystem->Exec("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf "
	       +newDir+"/muonRecoGlb.pdf "
	       +newDir+"/muonRecoGlbEff.pdf "
               +newDir+"/muonRecoGlbPF.pdf "
               +newDir+"/muonRecoGlbPFEff.pdf "
               +newDir+"/muonRecoSta.pdf "
               +newDir+"/muonRecoStaEff.pdf "
               +newDir+"/muonRecoTrk.pdf "
               +newDir+"/muonRecoTrkEff.pdf "
               +newDir+"/muonRecoTgt.pdf "
               +newDir+"/muonRecoTgtEff.pdf ");
 gSystem->Exec("mv merged.pdf "+newDir+"/../"+myName+".pdf");
 gSystem->Exec("rm -r "+newDir);
 
 }  // end of "while loop"
 
}
Example #22
0
void EWKcorr_Ele() {
  
//  Int_t iso=00; Int_t pt=3;  

  Target = TFile::Open( "Total_FRcorr60_60.root", "RECREATE" );
  char faa[100]; 
  FileList = new TList();
  strcpy(faa,"");
  sprintf(faa,"SingleElectron_FR60_60.root");
  FileList->Add( TFile::Open(faa) ); 
  strcpy(faa,"");
  sprintf(faa,"Wjets_FR60_60.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"DY_10-50_FR60_60.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"DY_50_FR60_60.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"ttbar_FR60_60.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Wgamma_FR60_60.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
/*
  sprintf(faa,"Zjet_20-30_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_30-50_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_50-80_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_80-120_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_120-170_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_170-230_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_230-300_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
  strcpy(faa,"");
  sprintf(faa,"Zjet_300_FR60_28.root");
  FileList->Add( TFile::Open(faa) );
*/
  FileList->Print();

  TString path( (char*)strstr( Target->GetPath(), ":" ) );
  path.Remove( 0, 2 );

  TFile *first_source = (TFile*)FileList->First();
  first_source->cd( path );
  TDirectory *current_sourcedir = gDirectory;

  // loop over all keys in this directory
  TChain *globChain = 0;
  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key;
  while ( (key = (TKey*)nextkey())) {

    // read object from first source file
    first_source->cd( path );
    TObject *obj = key->ReadObj();
    if ( obj->IsA()->InheritsFrom( "TH1F" ) || obj->IsA()->InheritsFrom( "TH2F" ) ) {
      // descendant of TH1F -> merge it

      //      cout << "Merging histogram " << obj->GetName() << endl;
      TH1F *h1 = (TH1F*)obj;

      // loop over all source files and add the content of the
      // correspondant histogram to the one pointed to by "h1"
      TFile *nextsource = (TFile*)FileList->After( first_source );
      Int_t scal=0;
      while ( nextsource ) {
        
        // make sure we are at the correct directory level by cd'ing to path
        nextsource->cd( path );
        TH1F *h2 = (TH1F*)gDirectory->Get( h1->GetName() );
        h1->SetDefaultSumw2(true);
        if ( h2 ) {
          h2->SetDefaultSumw2(true);
          h1->Add( h2 , scaling[scal] );  //scale factor not need if is need the same as to be applied to h1
          cout<<"file "<<nextsource->GetName()<<endl;
	  cout<<"scaling "<<scaling[scal]<<" scal "<<scal<<endl;
          delete h2; // don't know if this is necessary, i.e. if 
                     // h2 is created by the call to gDirectory above.
        }
	
        nextsource = (TFile*)FileList->After( nextsource );
	scal++;
      }
    }
    // now write the merged histogram (which is "in" obj) to the target file
    // note that this will just store obj in the current directory level,
    // which is not persistent until the complete directory itself is stored
    // by "target->Write()" below
    if ( obj ) {
      Target->cd();
      obj->Write( key->GetName() );
    }
    
  } // while ( ( TKey *key = (TKey*)nextkey() ) )
  
  Target->Write();
  
  Target->cd();
  getFakerate2(h_nEvents, h_nEventsFO, h_FOrate);
  getFakerate1(h_nVertex1, h_nVertex0, h_nVertex2);
  h_FOrate->Write("h_FOrate3");
  h_nEvents->Write("h_Events2");
  h_nEventsFO->Write("h_EventsFO2");
  h_nVertex1->Write("h_nVertex1_2");
  h_nVertex0->Write("h_nVertex0_2");
  h_nVertex2->Write("h_nVertex3");
  delete h_nVertex2;
  delete h_FOrate;
  Target->Close();

}   
Example #23
0
void MergeRootfile( char *core, TDirectory *target, TList *sourcelist ) {
  printf("merging only histos with core=%s=\n",core);

  //  cout << "Target path: " << target->GetPath() << endl;
  TString path( (char*)strstr( target->GetPath(), ":" ) );
  path.Remove( 0, 2 );

  TFile *first_source = (TFile*)sourcelist->First();
  first_source->cd( path );
  TDirectory *current_sourcedir = gDirectory;

  int nh=0;
  // loop over all keys in this directory
  TChain *globChain = 0;
  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key;
  while ( (key = (TKey*)nextkey())) {
    const char *name=key->GetName();
    char * c1=strstr(name,core);
    if(c1==0) continue;
    if(c1-name>2) continue;
    nh++;
    if(nh%100==0) printf("nh=%d addingX %s\n",nh,name);
    
    // read object from first source file
    first_source->cd( path );
    TObject *obj = key->ReadObj();
    
    if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
      // descendant of TH1 -> merge it
      
      //      cout << "Merging histogram " << obj->GetName() << endl;
      TH1 *h1 = (TH1*)obj;

      // loop over all source files and add the content of the
      // correspondant histogram to the one pointed to by "h1"
      TFile *nextsource = (TFile*)sourcelist->After( first_source );
      while ( nextsource ) {
        
        // make sure we are at the correct directory level by cd'ing to path
        nextsource->cd( path );
        TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
        if ( h2 ) {
          h1->Add( h2 );
          delete h2; // don't know if this is necessary, i.e. if 
                     // h2 is created by the call to gDirectory above.
        }

        nextsource = (TFile*)sourcelist->After( nextsource );
      }
    }
    else if ( obj->IsA()->InheritsFrom( "TTree" ) ) {
      
      // loop over all source files create a chain of Trees "globChain"
      const char* obj_name= obj->GetName();

      globChain = new TChain(obj_name);
      globChain->Add(first_source->GetName());
      TFile *nextsource = (TFile*)sourcelist->After( first_source );
      //      const char* file_name = nextsource->GetName();
      // cout << "file name  " << file_name << endl;
     while ( nextsource ) {
     	  
       globChain->Add(nextsource->GetName());
       nextsource = (TFile*)sourcelist->After( nextsource );
     }
     
    } else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
      // it's a subdirectory
      
      cout << "Found subdirectory " << obj->GetName() << endl;
      
      // create a new subdir of same name and title in the target file
      target->cd();
      TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );

      // newdir is now the starting point of another round of merging
      // newdir still knows its depth within the target file via
      // GetPath(), so we can still figure out where we are in the recursion
      MergeRootfile( core,newdir, sourcelist );
      
    } else {
      
      // object is of no type that we know or can handle
      cout << "Unknown object type, name: " 
           << obj->GetName() << " title: " << obj->GetTitle() << endl;
    }
    
    // now write the merged histogram (which is "in" obj) to the target file
    // note that this will just store obj in the current directory level,
    // which is not persistent until the complete directory itself is stored
    // by "target->Write()" below
    if ( obj ) {
      target->cd();
      
      //!!if the object is a tree, it is stored in globChain...
      if(obj->IsA()->InheritsFrom( "TTree" ))
	globChain->Write( key->GetName() );
      else
	obj->Write( key->GetName() );
    }
    
  } // while ( ( TKey *key = (TKey*)nextkey() ) )
  
  // save modifications to target file
  target->Write();
  
}
Example #24
0
static PyObject *
dbm_has_key(register dbmobject *dp, PyObject *args)
{
    datum key;

    if (!PyArg_ParseTuple(args, "s#:has_key", &key.dptr, &key.dsize))
        return NULL;
    check_dbmobject_open(dp);
    return PyInt_FromLong((long) gdbm_exists(dp->di_dbm, key));
}

PyDoc_STRVAR(dbm_firstkey__doc__,
"firstkey() -> key\n\
It's possible to loop over every key in the database using this method\n\
and the nextkey() method. The traversal is ordered by GDBM's internal\n\
hash values, and won't be sorted by the key values. This method\n\
returns the starting key.");

static PyObject *
dbm_firstkey(register dbmobject *dp, PyObject *unused)
{
    register PyObject *v;
    datum key;

    check_dbmobject_open(dp);
    key = gdbm_firstkey(dp->di_dbm);
    if (key.dptr) {
        v = PyString_FromStringAndSize(key.dptr, key.dsize);
        free(key.dptr);
        return v;
Example #25
0
prepDataFiles(){
//	TDirectory *theDr = (TDirectory*) myFile->Get("eleIDdir");///denom_pt/fit_eff_plots");
	//theDr->ls();
	int myIndex;	
	
	TSystemDirectory dir(thePath, thePath);
	TSystemFile *file;
	TString fname;
	TIter next(dir.GetListOfFiles());
	while ((file=(TSystemFile*)next())) {
		fname = file->GetName();
		if (fname.BeginsWith("TnP")&& fname.Contains("mc")) {
	
			ofstream myfile;

			TFile *myFile = new TFile(fname);
			TIter nextkey(myFile->GetListOfKeys());
			TKey *key;
			while (key = (TKey*)nextkey()) {
				TString theTypeClasse = key->GetClassName();
				TString theNomClasse = key->GetTitle();
				if ( theTypeClasse == "TDirectoryFile"){
					TDirectory *theDr = (TDirectory*) myFile->Get(theNomClasse);
					TIter nextkey2(theDr->GetListOfKeys());
					TKey *key2;
					while (key2 = (TKey*)nextkey2()) {
						TString theTypeClasse2 = key2->GetClassName();
						TString theNomClasse2 = key2->GetTitle();	
						myfile.open (theNomClasse2+".info");
						if ( theTypeClasse == "TDirectoryFile"){
							cout << "avant " << endl;
							TDirectory *theDr2 = (TDirectory*) myFile->Get(theNomClasse+"/"+theNomClasse2);
							cout << "apres " << endl;
							TIter nextkey3(theDr2->GetListOfKeys());
							TKey *key3;
							while (key3 = (TKey*)nextkey3()) {
								TString theTypeClasse3 = key3->GetClassName();
								TString theNomClasse3 = key3->GetTitle();	
								if ((theNomClasse3.Contains("FromMC"))) {

									TString localClasse3 = theNomClasse3;
									localClasse3.ReplaceAll("__","%");
									cout << "apres " << localClasse3 << endl;
									TObjArray* listBin = localClasse3.Tokenize('%');
									TString first = ((TObjString*)listBin->At(0))->GetString();
									TString second = ((TObjString*)listBin->At(2))->GetString();
									myfile << first;
									myfile << " " << second << " ";
									cout << "coucou la on va récupérer le rooFitResult " << endl;

									RooFitResult *theResults = (RooFitResult*) myFile->Get(theNomClasse+"/"+theNomClasse2+"/"+theNomClasse3+"/fitresults");
									theResults->Print();
									RooArgList theParam = theResults->floatParsFinal();
									int taille = theParam.getSize();
									for (int m = 0 ; m < taille ; m++){
										cout << "m=" << m << endl;
									RooAbsArg *theArg = (RooAbsArg*) theParam.at(m);
									RooAbsReal *theReal = (RooAbsReal*) theArg;
										myfile << theReal->getVal() << " " ;
									}		
															
									myfile << "\n";

								}
							}
						}
						myfile.close();

					}
			
				}
			}
			delete myFile;
		}
	
	}

}
Example #26
0
void th2polyEurope(Int_t npoints=500000)
{
   Int_t i,j;
   Double_t lon1 = -25;
   Double_t lon2 =  35;
   Double_t lat1 =  34;
   Double_t lat2 =  72;
   Double_t R = (lat2-lat1)/(lon2-lon1);
   Int_t W    = 800;
   Int_t H    = (Int_t)(R*800);
   gStyle->SetStatX(0.28);
   gStyle->SetStatY(0.45);
   gStyle->SetStatW(0.15);

   // Canvas used to draw TH2Poly (the map)
   TCanvas *ce = new TCanvas("ce", "ce",0,0,W,H);
   ce->ToggleEventStatus();
   ce->SetGridx();
   ce->SetGridy();

   // Real surfaces taken from Wikipedia.
   const Int_t nx = 36;
   // see http://en.wikipedia.org/wiki/Area_and_population_of_European_countries
   const char *countries[nx] = {
      "france",     "spain",  "sweden",  "germany",       "finland",
      "norway",     "poland", "italy",   "yugoslavia",    "united_kingdom",
      "romania",    "belarus","greece",  "czechoslovakia","bulgaria",
      "iceland",    "hungary","portugal","austria",       "ireland",
      "lithuania",  "latvia", "estonia", "denmark",       "netherlands",
      "switzerland","moldova","belgium", "albania",       "cyprus",
      "luxembourg", "andorra","malta",   "liechtenstein", "san_marino", "monaco" };
   Float_t surfaces[nx] = {
      547030,        505580,   449964,      357021,        338145,
      324220,        312685,   301230,      255438,        244820,
      237500,        207600,   131940,      127711,        110910,
      103000,         93030,    89242,       83870,         70280,
      65200,         64589,    45226,       43094,         41526,
      41290,         33843,    30528,       28748,          9250,
      2586,           468,      316,         160,            61, 2};

   TH1F *h = new TH1F("h","Countries surfaces (in km^{2})",3,0,3);
   for (i=0; i<nx; i++) h->Fill(countries[i], surfaces[i]);
   h->LabelsDeflate();

   TFile::SetCacheFileDir(".");
   TFile *f;
   f = TFile::Open("http://root.cern.ch/files/europe.root","cacheread");

   if (!f) {
      printf("Cannot access europe.root. Is internet working ?\n");
      return;
   }

   TH2Poly *p = new TH2Poly(
             "Europe",
             "Europe (bin contents are normalized to the surfaces in km^{2})",
             lon1,lon2,lat1,lat2);
   p->GetXaxis()->SetNdivisions(520);
   p->GetXaxis()->SetTitle("longitude");
   p->GetYaxis()->SetTitle("latitude");

   p->SetContour(100);

   TMultiGraph *mg;
   TKey *key;
   TIter nextkey(gDirectory->GetListOfKeys());
   while ((key = (TKey*)nextkey())) {
      TObject *obj = key->ReadObj();
      if (obj->InheritsFrom("TMultiGraph")) {
         mg = (TMultiGraph*)obj;
         p->AddBin(mg);
      }
   }

   TRandom r;
   Double_t longitude, latitude;
   Double_t x, y, pi4 = TMath::Pi()/4, alpha = TMath::Pi()/360;

   gBenchmark->Start("Partitioning");
   p->ChangePartition(100, 100);
   gBenchmark->Show("Partitioning");

   // Fill TH2Poly according to a Mercator projection.
   gBenchmark->Start("Filling");
   for (i=0; i<npoints; i++) {
      longitude = r.Uniform(lon1,lon2);
      latitude  = r.Uniform(lat1,lat2);
      x         = longitude;
      y         = 38*TMath::Log(TMath::Tan(pi4+alpha*latitude));
      p->Fill(x,y);
   }
   gBenchmark->Show("Filling");

   Int_t nbins = p->GetNumberOfBins();
   Double_t maximum = p->GetMaximum();


   // h2 contains the surfaces computed from TH2Poly.
   TH1F *h2 = (TH1F *)h->Clone("h2");
   h2->Reset();
   for (j=0; j<nx; j++) {
      for (i=0; i<nbins; i++) {
         if (strstr(countries[j],p->GetBinName(i+1))) {
            h2->Fill(countries[j],p->GetBinContent(i+1));
            h2->SetBinError(j, p->GetBinError(i+1));
         }
      }
   }

   // Normalize the TH2Poly bin contents to the real surfaces.
   Double_t scale = surfaces[0]/maximum;
   for (i=0; i<nbins; i++) p->SetBinContent(i+1, scale*p->GetBinContent(i+1));

   gStyle->SetOptStat(1111);
   p->Draw("COLZ");

   TCanvas *c1 = new TCanvas("c1", "c1",W+10,0,W-20,H);
   c1->SetRightMargin(0.047);

   scale = h->GetMaximum()/h2->GetMaximum();

   h->SetStats(0);
   h->SetLineColor(kRed-3);
   h->SetLineWidth(2);
   h->SetMarkerStyle(20);
   h->SetMarkerColor(kBlue);
   h->SetMarkerSize(0.8);
   h->Draw("LP");
   h->GetXaxis()->SetLabelFont(42);
   h->GetXaxis()->SetLabelSize(0.03);
   h->GetYaxis()->SetLabelFont(42);

   h2->Scale(scale);
   Double_t scale2=TMath::Sqrt(scale);
   for (i=0; i<nx; i++) h2->SetBinError(i+1, scale2*h2->GetBinError(i+1));
   h2->Draw("E SAME");
   h2->SetMarkerStyle(20);
   h2->SetMarkerSize(0.8);

   TLegend *leg = new TLegend(0.5,0.67,0.92,0.8,NULL,"NDC");
   leg->SetTextFont(42);
   leg->SetTextSize(0.025);
   leg->AddEntry(h,"Real countries surfaces from Wikipedia (in km^{2})","lp");
   leg->AddEntry(h2,"Countries surfaces from TH2Poly (with errors)","lp");
   leg->Draw();
   leg->Draw();

   Double_t wikiSum = h->Integral();
   Double_t polySum = h2->Integral();
   Double_t error = TMath::Abs(wikiSum-polySum)/wikiSum;
   printf("THPoly Europe surface estimation error wrt wikipedia = %f per cent when using %d points\n",100*error,npoints);
}
Example #27
0
void hmerge_( TDirectory *target, TList *sourcelist, double crossArray[] ) {

  //cout << "Target path: " << target->GetPath() << endl;
  TString rpath( (char*)strstr( target->GetPath(), ":" ) );
  rpath.Remove( 0, 2 );

  TFile *first_source = (TFile*)sourcelist->First();

  first_source->cd( rpath );
  TDirectory *current_sourcedir = gDirectory;
  //gain time, do not add the objects in the list in memory
  Bool_t status = TH1::AddDirectoryStatus();
  TH1::AddDirectory(kFALSE);

  // loop over all keys in this directory
  TChain *globChain = 0;
  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key, *oldkey=0;
  while ( (key = (TKey*)nextkey())) {

    //keep only the highest cycle number for each key
    if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;

    // read object from first source file
    first_source->cd( rpath );
    TObject *obj = key->ReadObj();

    if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
      // descendant of TH1 -> merge it

      //cout << "Merging histogram " << obj->GetName() << endl;
      TH1 *h1 = (TH1*)obj;
      h1->Sumw2();

      // Scale by the cross-section factor
      h1->Scale(crossArray[0]);

      // loop over all source files and add the content of the
      // correspondant histogram to the one pointed to by "h1"
      TFile *nextsource = (TFile*)sourcelist->After( first_source );

      int q = 1; // This keeps track of which
                 // cross section factor to use
      while ( nextsource ) {
        // make sure we are at the correct directory level by cd'ing to rpath
        nextsource->cd( rpath );
        TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
        if (key2) {
           TH1 *h2 = (TH1*)key2->ReadObj();
           h2->Sumw2();

           // Scale by the cross-section factor before adding.
           h2->Scale(crossArray[q]);
           h1->Add( h2 );
           q++;
           delete h2;
        }

        nextsource = (TFile*)sourcelist->After( nextsource );
      }

    } else if ( obj->IsA()->InheritsFrom( "TTree" ) ) {

      // loop over all source files create a chain of Trees "globChain"
      const char* obj_name= obj->GetName();

      globChain = new TChain(obj_name);
      globChain->Add(first_source->GetName());
      TFile *nextsource = (TFile*)sourcelist->After( first_source );
      while ( nextsource ) {
        globChain->Add(nextsource->GetName());
        nextsource = (TFile*)sourcelist->After( nextsource );
      }

    } else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {

      cout << "Found subdirectory " << obj->GetName() << endl;

      // create a new subdir of same name and title in the target file
      target->cd();
      TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );

      // newdir is now the starting point of another round of merging
      // newdir still knows its depth within the target file via
      // GetPath(), so we can still figure out where we are in the recursion
      hmerge_( newdir, sourcelist,crossArray );

    } else {

      // object is of no type that we know or can handle
      cout << "Unknown object type, name: "
           << obj->GetName() << " title: " << obj->GetTitle() << endl;

    }

    // now write the merged histogram (which is "in" obj) to the target file
    // note that this will just store obj in the current directory level,
    // which is not persistent until the complete directory itself is stored
    // by "target->Write()" below
    if ( obj ) {
      target->cd();

      //!!if the object is a tree, it is stored in globChain...
        if(obj->IsA()->InheritsFrom( "TTree" ))
          globChain->Merge(target->GetFile(),0,"keep");
        else
        obj->Write( key->GetName() );
    }

  } // while ( ( TKey *key = (TKey*)nextkey() ) )

  // save modifications to target file
  target->SaveSelf(kTRUE);
  TH1::AddDirectory(status);

}
Example #28
0
void getHistoInfo ()
{
 
  listHistos = new TList();    // Histograms normalized to one
  nHistList = 0;
  
  // loop over root files
  for (int j=0; j< inputRootFile.size(); j++) 
    {
      int numMax = 0;

      // Access input ROOT file (can access over secure shell)
      
      TFile *rootTFile = new TFile((inputRootFile.at(j)).c_str()); // open root file
      std::cout <<"inputRootFile.at(j)).c_str()  "<<inputRootFile.at(j).c_str()<<std::endl;
      TDirectory *current_sourcedir = gDirectory;
      TIter nextkey( current_sourcedir->GetListOfKeys() );
      TKey *key;
      
      // loop over keys(ROOT objects) within the root file
      while ((key = (TKey*)nextkey())) 
        {
	  TObject *obj = key->ReadObj();
	  
	  TH1 *histoObj = (TH1*)obj;
	  TH1* h1 = 0; //points to the new copied hist we will make
	  int totalbins = 0;
	  // rename histogram
          if ( obj->IsA()->InheritsFrom( "TH1" ) ) 
            {

              string histname = obj->GetName();
              
              size_t found = histname.find("lumi");
              string theProcess = "lumi";

              string new_theProcess = "_" + theProcess;
              histname.erase(found-1, new_theProcess.size());
              string histName = histname;
 
	      int numBins = histoObj->GetXaxis()->GetNbins();
	      double lowerEdge = histoObj->GetXaxis()->GetXmin();
	      double upperEdge = histoObj->GetXaxis()->GetXmax();

	      if ( obj->IsA()->InheritsFrom( "TH2" ) ) 
		{
		  int numBinsY = histoObj->GetYaxis()->GetNbins();
		  double lowerEdgeY = histoObj->GetYaxis()->GetXmin();
		  double upperEdgeY = histoObj->GetYaxis()->GetXmax();
		  h1 = new TH2F (histName.c_str(), histName.c_str(),
				 numBins, lowerEdge, upperEdge,
				 numBinsY, lowerEdgeY, upperEdgeY);
	      
		  //here (and below) GetSize() will allow us to
		  //iterate over 1 or 2d hists.  We pick up overflow
		  //bins too, but that's fine
		  TH2F* tmp1 = static_cast<TH2F*>(h1);
		  totalbins = tmp1->GetSize();
		} else {
	      h1 = new TH1F (histName.c_str(), histName.c_str(),
				   numBins, lowerEdge, upperEdge);
	      TH1F* tmp2 = static_cast<TH1F*>(h1);
	      totalbins = tmp2->GetSize();
	      }

	      // Apply scale factor?
	      if (inputApplyScaleFactor.at(j) == "True")
		{
		  for (int k=0; k <= totalbins; k++)
		    {
		      double scf = inputScaleFactor.at(j);
		      h1->SetBinContent(k,(histoObj->GetBinContent(k)*scf));
		      h1->SetBinError(k,(histoObj->GetBinError(k))*scf);
		    }
		} else
		{
		  for (int k=0; k <= totalbins; k++)
		    {
		      h1->SetBinContent(k,(histoObj->GetBinContent(k)));
		      h1->SetBinError(k,(histoObj->GetBinError(k)));
		    }
		}
              h1 = Rebinh(h1);
	      listHistos->Add(h1);
	      nHistList++;
	      theHistNameStrings.push_back(histName);
	      numMax++;
	    } // close if loop InheritsFrom("TH1")
	} // close while loop
      // If first input ROOT file (Data), store total number of histograms
      if (j == 0)
        numHistos = numMax;
      // Else exit the code if a ROOT file has a different number of histograms
      else
        {
          if (numMax != numHistos)
            {
              cerr << "ERROR: Input Root Files DO NOT have the same number"
                   << " of histograms." << endl;
              exit (1);
            }
        }
    } // close for loop over root files
} // close getHistoInfo function
Example #29
0
function main(in mode) {
	//seems to be used only for VAL.PERIOD and RAISEUNPOSTEDMINIMUM
	//garbagecollect;
	//y2k2
	// daybook batch header validation and interface routines

	interactive = not SYSTEM.a(33);

	//equ printtypes to register(10)<3>
	//equ tstore2 to register(10)<4>

	//removed so we can call raise.unposted.minimum without setting @id
	//t=field(@id,'*',1)
	//IF t NE CURR.COMPANY THEN
	// IF t THEN
	// *CURR.COMPANY=t
	// CALL INIT.COMPANY(t)
	// if interactive then
	// MSG='YOU HAVE JUST CHANGED BACK TO ':QUOTE(CURR.COMPANY):' COMPANY'
	// GOSUB NOTE3
	// end
	// END
	// END

	win.redisplaylist = "";
	var tt = "";
	//do not set valid because valid used in prewrite to indicate failed
	//valid=1

	//none used from web
	if (mode eq "DEF.BATCH.REF") {

		if (not(win.wlocked or RECORD)) {
			if (not(ID.field("*", 1))) {
				ID = ID.fieldstore("*", 1, 1, fin.currcompany);
			}
			if (not(ID.field("*", 2))) {
				ID = ID.fieldstore("*", 2, 1, win.registerx(10).a(1));
			}

			tt = ":%" ^ ID.field("*", 1, 2) ^ "%:BATCHES:" ^ ID.field("*", 1, 2) ^ "*";
			//eg t=":%H*INV%:BATCHES:H*INV*"

			tt = nextkey(tt, "");

			ID = tt;
			win.isdflt = tt.field("*", 3);
			ANS = "";
		}
		win.registerx(4) = win.isdflt;

/*
	/////////////
} else if (mode eq "F2.BATCH.REF") {
	/////////////
	gosub keychange();
	if (not win.valid) {
		return 0;
	}

	if (authorised("JOURNAL ACCESS POSTED", msg, "")) {
		if (not(decide("", "Posted batches" _VM_ "Unposted batches", reply))) {
			return 0;
		}
	}else{
		reply = 2;
	}
	if (reply == 1) {
		suffix = "";
	}else{
		suffix = "*U";
	}

	var refs = getbatchcodes(fin.currcompany, win.registerx(10).a(1), suffix, fin.batches);
	if (not refs) {
		msg = "No batches found";
		goto invalid2;
	}

	//select a batch
	if (suffix) {
		temp = "Entered by";
	}else{
		temp = "Posted By";
	}
	var params = "BATCH_REFERENCE:5:R::Batch\\FIRST_VOUCHER:10:R::1st Vouch.\\CONTRA_ACCOUNT_NAME:30:::First account\\WHO:10:::" ^ temp ^ "\\23:7:R:[ADDCENT]:Period\\ACTION:1:::";
	tt = "Which batch(es) do you want ?";
	if (suffix) {
		tt ^= "|(unposted batches)";
	}
	ANS = pop_up(0, 0, "@BATCHES", refs, params, "T", "1", tt, "", "", "", "K");
	if (not ANS) {
		return 0;
	}
	ANS.converter(FM, VM);
	if (ANS.index(VM, 1)) {
		while (true) {
		///BREAK;
		if (not(ANS.index(VM ^ VM, 1))) break;;
			ANS.swapper(VM ^ VM, VM);
		}//loop;
		win.newbrowse = 1;
		ANS.transfer(win.browsenext);
		win.reset = 4;
	}
	ANS = ANS.field("*", 3);

	//force prefix into @ID
	if (suffix) {
		ID = ID.fieldstore("*", 4, 1, suffix[2]);
	}

	DATA ^= "" "\r";

	return 0;
}

	//////////////
valbatchref:
	//////////////
	gosub EOF_516();
	if (not win.valid) {
		return;
	}
	if (win.is ne win.registerx(4) and win.is ne win.isorig) {

		gosub keychange();
		if (not win.valid) {
			return;
		}

		//query by voucher number
		if (win.is[1] == "V") {
			if (not(win.is.readv(fin.vouchers, ID.field("*", 2) ^ "*" ^ win.is.substr(2, 99) ^ "*" ^ fin.currcompany, 12))) {
				{}
			}
		}

		suffix = "";
		if (var(".U").index(win.is[1], 1)) {
			suffix = "*U";
			win.is.splicer(1, 1, "");
		}
		if (not(tt.read(win.srcfile, ID.fieldstore("*", 3, 1, win.is) ^ suffix))) {
			msg = DQ ^ (win.is ^ DQ) ^ " " "NO SUCH BATCH - IF YOU WANT TO START A|NEW BATCH JUST PRESS [Enter]";
			win.is = "";
			gosub invalid2();
			win.reset = 4;
			return;
		}
		if (suffix) {
			ID = ID.fieldstore("*", 4, 1, "U");
		}

		//check allowed access to posted batches
		if (not(ID.field("*", 4))) {
			if (not(authorised("JOURNAL ACCESS POSTED BATCHES", msg, ""))) {
				goto invalid2;
			}
		}

		//check if own batch
		if (not(tt.locate(USERNAME, temp, 25))) {
			if (not(authorised("JOURNAL ACCESS OTHER PEOPLES", msg, ""))) {
				win.is = "";
				goto invalid2;
			}
		}

	}
	return;

} else if (mode eq "DEF.PERIOD") {

	win.isdflt = fin.currperiod ^ "/" ^ addcent(fin.curryear);

*/


	} else if (mode eq "VAL.PERIOD") {

		//also used by REVERSALS and REVAL
		win.isdflt = "";
		if (not win.is) {
			return 0 ;
		}
		if (win.is == win.isorig) {
			return 0 ;
		}

		//no leading zero
		if (win.is[1] == "0") {
			win.is.splicer(1, 1, "");
		}

		//add current year
		win.is.converter(" ", "/");
		tt = win.is.field("/", 2);
		if (tt == "") {
			if (win.is > fin.currperiod) {
				tt = (addcent(fin.curryear - 1)).oconv("R(0)#2");
			}else{
				tt = fin.curryear;
			}
			win.is = win.is.fieldstore("/", 2, 1, tt);
		}else{
			win.is = win.is.fieldstore("/", 2, 1, var("00" ^ tt).substr(-2, 2));
		}

		//check period
		//var isperiod = win.is;
		gosub chkperiod(win.is);
		if (not win.valid)
			return 0;


	} else if (mode.field(".", 1) eq "TRACE") {

		var action = mode.field(".", 2);
		if (action == "A" and authorised("JOURNAL REPOST WITHOUT RECORD", msg, "NEOSYS")) {
			return 0;
		}
		RECORD.inserter(24, 1, action);
		RECORD.inserter(25, 1, USERNAME);
		//R=INSERT(R,26,1,0,ICONV(DATE(),'HEX'))
		RECORD.inserter(26, 1, var().date());
		RECORD.inserter(27, 1, var().time());


	} else if (mode.field("*", 1) == "RAISE.UNPOSTED.MINIMUM") {
		raisebatchtype = mode.field("*", 2);
		if (not raisebatchtype) {
			raisebatchtype = win.registerx(10).a(1);
		}

		//if this is the lowest batch number then update the minimum batch number
		var seqkey = "%" ^ fin.currcompany ^ "*" ^ raisebatchtype ^ "*U%";
		var min,max;
		if (min.read(fin.batches, seqkey ^ "*")) {
			min = min.a(1);
			if (min == ID.field("*", 3)) {
				if (max.read(fin.batches, seqkey)) {
					max = max.a(1);
				} else {
					max = min;
				}
				//go from minimum+1 to maximum but stopping at any existing batch;
				for (var min = 1; min <= max; ++min) {
					if (not(tt.read(fin.batches, fin.currcompany ^ "*" ^ raisebatchtype ^ "*" ^ min ^ "*U"))) {
						tt = "";
					}
					///BREAK;
					if (tt)
						break;;
				};//min;
			}
			if (min > max) {
				min = max;
			}
			min.writev(fin.batches, seqkey ^ "*", 1);
		}

	} else {
		//unknown mode
		msg = "SYSTEM ERROR IN DAYBOOK.SUBS3|INVALID MODE " ^ (DQ ^ (mode ^ DQ)) ^ " IGNORED";
		//goto note3;
		return invalid(msg);
	}

	return 0;

}
void compareplots_noRatio(){
  vector<TFile*> files; 
  files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/ttbarMergedFxFx8TeVCTEQ6M-extracted.root"));
  files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_30/ttbarMergedFxFxMS30GeVMECut10GeV8TeVCTEQ6M-extracted.root"));   
  files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbarMergedMS100GeV8TeVCTEQ6M-extracted.root"));   
  files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbarMergedMS100GeVMCCut50GeV8TeVCTEQ6M-extracted.root"));   
  


  
  vector<TString> names;
  names.push_back("ttbar +0/1 Jet, #mu_{Q}=10 GeV #mu_{ME} = 10 GeV");
  names.push_back("ttbar +0/1 Jet, #mu_{Q}=30 GeV #mu_{ME} = 10 GeV");
  names.push_back("ttbar +0/1 Jet, #mu_{Q}=100 GeV #mu_{ME} = 10 GeV");
  names.push_back("ttbar +0/1 Jet, #mu_{Q}=100 GeV #mu_{ME} = 50 GeV");
  
  
  vector<TString> titles;
  titles.push_back("Gen-Jet p_{T}  with pos weights (GeV)");
  titles.push_back("Gen-Jet p_{T} with neg weights (GeV)");
  titles.push_back("Gen-Jet p_{T} (GeV)");
  titles.push_back("Gen_Jet #phi with pos. weights");
  titles.push_back("Gen_Jet #phi with neg. weights");
  titles.push_back("Gen_Jet #phi");
  titles.push_back("Gen Jet #theta with pos weights");
  titles.push_back("Gen Jet #theta with neg weights");
  titles.push_back("Gen Jet #theta");
  titles.push_back("Gen Jet Energy with pos weights (GeV) ");
  titles.push_back("Gen Jet Energy with neg weights (GeV)");
  titles.push_back("Gen Jet Energy (GeV)");
  titles.push_back("p_{T} of hardest Gen-Jet with pos weights (GeV)");
  titles.push_back("p_{T} of hardest Gen-Jet with neg weights (GeV)");
  titles.push_back("p_{T} of hardest Gen-Jet (GeV)");
  titles.push_back("p_{T} of 2nd hardest Gen-Jet with pos weights (GeV)");
  titles.push_back("p_{T} of 2nd hardest Gen-Jet with neg weights (GeV)");
  titles.push_back("p_{T} of 2nd hardest Gen-Jet (GeV)");
  titles.push_back("#eta of hardest Gen-Jets with pos weights");
  titles.push_back("#eta of hardest Gen-Jets with neg weights");
  titles.push_back("#eta of hardest Gen-Jets");
  titles.push_back("Number of Gen-Jets with pos. weights");
  titles.push_back("Number of Gen-Jets with neg. weights");
  titles.push_back("Number of Gen-Jets");

  TFile *vergleich = new TFile("vergleich_ttbar_0Jet.root","RECREATE");

// Show no statistics box
gStyle->SetOptStat(0);

TH1::SetDefaultSumw2();

// Main program part
  TIter nextkey(files.at(0)->GetListOfKeys());
  TKey *key;
  bool first=true;
  TCanvas* c = new TCanvas();
  c->Print("plots.pdf[");

  // Save also as pictures
  int pictureNumber = 0;

  int run = 0;
  while (key = (TKey*)nextkey()) {
    pictureNumber++;
    TString pictureName = TString::Format("%d.png",pictureNumber);


    vector<TH1F*> histos;
    histos.push_back((TH1F*)key->ReadObj());
    for(size_t i=1;i<files.size();i++){
      histos.push_back((TH1F*)files.at(i)->Get(histos.at(0)->GetName()));
    }
		       
    for(size_t i=0;i<histos.size();i++){
      if(i == 0){
	histos.at(i)->SetLineColor(kBlack);
      }
      if(i == 1){
	histos.at(i)->SetLineColor(kRed);
      }
      if(i == 2){
	histos.at(i)->SetLineColor(kBlue);
      }
      if(i == 3){
	histos.at(i)->SetLineColor(kGreen+2);
      }
      if(i == 4){
	histos.at(i)->SetLineColor(kMagenta-7);
      }
      if(i == 5){
	histos.at(i)->SetLineColor(kOrange+7);
      }
    }
   
    for(size_t i=0;i<histos.size();i++){
      histos.at(i)->Sumw2();
      histos.at(i)->Scale(1./histos.at(i)->Integral(),"width");
    }

// Set axis title
histos.at(0)->GetYaxis()->SetTitle("Normalized units"); 
std::string const histogramName = histos.at(1)->GetName();
histos.at(0)->GetXaxis()->SetLabelSize(0.05);
histos.at(0)->GetXaxis()->SetLabelOffset(0.006);
histos.at(0)->GetYaxis()->SetLabelSize(0.05);
histos.at(0)->GetYaxis()->SetLabelOffset(0.006);
histos.at(0)->GetXaxis()->SetTitleSize(0.06);
histos.at(0)->GetXaxis()->SetTitleOffset(1.1);
histos.at(0)->GetYaxis()->SetTitleSize(0.06);
histos.at(0)->GetYaxis()->SetTitleOffset(1.15);
	

 histos.at(0)->GetXaxis()->SetTitle(titles.at(run));
 run = run+1;
 if(run == (3*8)){
   run = 0;
 }

// If only two histograms per plot make a ratio plot
if(histos.size() == 2)
{

//create main pad  
                                                                                                                                                          
           TPad *mainPad = new TPad("","",0.0,0.0,1.0,1.0);
           mainPad->SetNumber(1);
           mainPad->SetBottomMargin(0.15);
           mainPad->SetRightMargin(0.04);
	   mainPad->SetLeftMargin(0.13);
           mainPad->Draw();
	   gStyle->SetOptTitle(0);
           //create ratio pad                                                                                                                                                           
           /*TPad *ratioPad = new TPad("","",0.0,0.0,1.0,0.3);
           ratioPad->SetTopMargin(0.0);
           ratioPad->SetBottomMargin(0.4);
           ratioPad->SetLeftMargin(0.13);                                                                                                                                             
           ratioPad->SetRightMargin(0.04);
           gStyle->SetOptTitle(0);
           ratioPad->SetFillColor(0);
           ratioPad->SetNumber(2);
           ratioPad->SetGridy();                                                                                                                                                      
           ratioPad->Draw();*/

// Draw both histograms first
c->cd(1);

histos.at(0)->Draw("histo E");
histos.at(1)->Draw("histo same E");

// Show legend and statistical tests in first pad
    for(size_t i=0;i<histos.size()-1;i=i+2){

      double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1));
      ksresult=floor(ksresult*1000+0.5)/1000;
      double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW");
      chi2result=floor(chi2result*1000+0.5)/1000;

      stringstream ss;
      //ss << "     KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result << " Private Work"; 
      ss << "            Private Work";
      const char * ch = & ss.str().c_str();;
      TLatex * ks = new TLatex(0.1, 0.9-0.03*i, ch );
      ks->SetTextColor(histos.at(i)->GetLineColor());
      ks->SetNDC();
      ks->Draw("");      

    }

    TLegend* l = new TLegend(0.40,0.9,0.69,0.99);
    // Options for legend
    l->SetBorderSize(0);
    l->SetLineStyle(0);
    l->SetTextSize(0.049);
    l->SetFillStyle(0);
    for(size_t i=0;i<names.size();i++){
      l->AddEntry(histos.at(i),names.at(i),"L");
    }
    l->Draw("same");

/*
// Clone histograms and draw ratio plot
c->cd(2);
 TH1F* ratioHisto = (TH1F*)histos.at(0)->Clone();
ratioHisto->Divide(histos.at(1));
ratioHisto->SetLineColor(kBlue);
ratioHisto->SetStats(false);
ratioHisto->GetYaxis()->SetTitle("Ratio #frac{noFxFx}{FxFx}");
// Same Size like in histogram
ratioHisto->SetLabelSize(histos.at(0)->GetLabelSize() * 0.7 / 0.3);
ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("Y") * 0.3 / 0.7), "Y");
ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("Y") * 0.7 / 0.3), "Y");
ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("X")), "X");
ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("X") * 0.7 / 0.3), "X");
// Use nicer range
ratioHisto->GetYaxis()->SetRangeUser(0, 2.2);
ratioHisto->GetYaxis()->SetNdivisions(503);
ratioHisto->GetYaxis()->SetLabelSize(0.06 * 0.7 / 0.3);
ratioHisto->Draw();*/
}
else
{
        TPad *mainPad = new TPad("","",0.0,0.0,1.0,1.0);
        mainPad->SetNumber(1);
        mainPad->SetBottomMargin(0.15);
        mainPad->SetRightMargin(0.04);
        mainPad->SetLeftMargin(0.13);
        mainPad->Draw();
        gStyle->SetOptTitle(0);
        //mainPad->SetLogx(1);
	c->cd(1);

    histos.at(0)->Draw("histo E");
    for(size_t i=0;i<histos.size();i++){
      histos.at(i)->Draw("histo same E");
    }


    for(size_t i=0;i<histos.size()-1;i=i+2){
      /*
      double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1));
      ksresult=floor(ksresult*1000+0.5)/1000;
      double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW");
      chi2result=floor(chi2result*1000+0.5)/1000;

      stringstream ss;
      ss << "KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result; 
      const char * ch = & ss.str().c_str();;
      TText * ks = new TText(0.1, 0.9-0.03*i, ch );
      ks->SetTextColor(histos.at(i)->GetLineColor());
      ks->SetNDC();
      ks->Draw("");      
      */
    }

    TLegend* l = new TLegend(0.65,0.5,0.9,0.7);
    l->SetBorderSize(0);
    l->SetLineStyle(0);
    //    l->SetTextSize(0.039);
    l->SetFillStyle(0);
    for(size_t i=0;i<names.size();i++){
      l->AddEntry(histos.at(i),names.at(i),"L");
    }
    l->Draw("same");
}

    c->Print("plots.pdf");
    c->SaveAs(pictureName);
    vergleich->WriteTObject(c);

}
  c->Print("plots.pdf]");


}