コード例 #1
0
ファイル: CompareDxy.C プロジェクト: Hosein47/usercode
void CompareDxy(const TString & file1, const TString & file2)
{
  setTDRStyle();

  TFile inputFileData(file1, "READ");
  TFile inputFileSim(file2, "READ");

  TDirectory * dirData = (TDirectory*)inputFileData.Get("demo");
  TH1F * histoData = (TH1F*)dirData->Get("standAloneMuons_dxy");

  TDirectory * dirSim = (TDirectory*)inputFileSim.Get("demo");
  TH1F * histoSim = (TH1F*)dirSim->Get("standAloneMuons_dxy");

  double norm = histoData->Integral(1, histoData->FindBin(40.));
  if( norm ) histoData->Scale(1/norm);

  norm = histoSim->Integral(1, histoSim->FindBin(40.));
  if( norm ) histoSim->Scale(1/norm);

  histoSim->SetLineColor(kRed);

  TCanvas * canvas = new TCanvas();

  histoData->Draw();
  histoSim->Draw("Same");

  canvas->SaveAs("compareDxy.png");
  canvas->SaveAs("compareDxy.pdf");
}
コード例 #2
0
/*************************************************************************************
 * 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;
  }
}
コード例 #3
0
ファイル: overlay.C プロジェクト: bluejelibaby/AnalysisV2
// -----------------------------------------------------------------------------
//
TH1* getHisto( std::string nameFile,
	       std::string nameHist,
	       std::string Dirname, 
	       int rebin ) {
  std::string name = nameFile;
  TFile* file =  new TFile(name.c_str());
  if (file) { std::cout << "Opened file: " << file->GetName() << std::endl; }
  else { 
    std::cout << "Could not find file: " << name << std::endl; 
    return 0; 
  }
  
  TDirectory* dir = (TDirectory*)file->Get(Dirname.c_str());
  if (dir) { std::cout << "Opened dir: " << dir->GetName() << std::endl; }
  else { 
    std::cout << "Could not find dir: " << Dirname << std::endl; 
    return 0; 
  }
  
  int low = 375;
  TH1* hist = 0;
  if ( false || nameHist.find("HtMultiplicity_HT375") == std::string::npos ) { 
    hist = (TH1*)dir->Get(nameHist.c_str());
  } else {
    
    for ( uint ii = low; ii <= 975; ii+=100 ) {
      std::stringstream tmp; tmp << "HtMultiplicity_HT" << ii << nameHist.substr(20);
      if ( !hist ) { 
	dir->cd();
	TH1D* temp = (TH1D*)dir->Get( "HtMultiplicity_HT375_aT0" );
	//TH1D* temp = (TH1D*)file->Get( tmp.str().c_str() );
	if (temp) { hist = (TH1D*)temp->Clone(); } 
	else { std::cout << "1 Unable to retrieve histo with name " << tmp.str() << std::endl; }
      } else { 
	dir->cd();
	TH1D* temp = (TH1D*)dir->Get( tmp.str().c_str() );
	if (temp) { hist->Add( (TH1D*)temp ); } 
	else { std::cout << "2 Unable to retrieve histo with name " << tmp.str() << std::endl; }
      }
    }

  }
  if (hist) { std::cout << "Opened histo: " << hist->GetName() << std::endl; }
  else { 
    std::cout << "Could not find histo: " << nameHist << std::endl; 
    return 0; 
  }

  hist->SetLineWidth(3);
  if ( rebin > 0 ) { hist->Rebin(rebin); }
  hist->GetXaxis()->SetTitleSize(0.055);
  hist->GetYaxis()->SetTitleSize(0.055);
  hist->GetXaxis()->SetLabelSize(0.05);
  hist->GetYaxis()->SetLabelSize(0.05);
  hist->SetStats(kFALSE);
  return hist;
}
コード例 #4
0
void CompareCFLADiffCuts()
{
  TFile newFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/15-NoOppChargeCut/All/CFs.root");
  TDirectory *newDir = newFile.GetDirectory("Merged");
  vector<TH1D*> newCFs;
  newCFs.push_back((TH1D*)newDir->Get("CFLamALam010"));
  newCFs.push_back((TH1D*)newDir->Get("CFLamALam1030"));
  newCFs.push_back((TH1D*)newDir->Get("CFLamALam3050"));

  TFile oldFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/08-NewAvgSepCuts/All/CFs.root");
  TDirectory *oldDir = oldFile.GetDirectory("Merged");
  vector<TH1D*> oldCFs;
  oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam010"));
  oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam1030"));
  oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam3050"));

  TFile *compareFile = new TFile("Compare.root","update");
  TDirectory *dir = compareFile->GetDirectory("Delta");
  if(!dir) dir = compareFile->mkdir("Delta");
  for(UInt_t i = 0; i < newCFs.size(); i++) {
    // TH1D *ratio = (TH1D*)newCFs[i]->Clone();
    // TString name = ratio->GetName();
    // ratio->SetName(name + "Ratio");
    // ratio->SetTitle(name + "Ratio");
    // ratio->Divide(oldCFs[i]);

    // TH1D *barlowRatio = ComputeRogerBarlowRatio(newCFs[i], oldCFs[i]);
    // barlowRatio->SetName(name + "BarlowRatio");
    // barlowRatio->SetTitle(name + "BarlowRatio");

    TString name = newCFs[i]->GetName();
    TH1D *barlowDifference = ComputeRogerBarlowDifference(newCFs[i], oldCFs[i]);
    barlowDifference->SetName(name + "BarlowDifference");
    barlowDifference->SetTitle(name + "BarlowDifference");
    
    dir->cd();
    // ratio->Write();
    // barlowRatio->Write();
    barlowDifference->Write(barlowDifference->GetName(), TObject::kOverwrite);
    Chi2TestWithZero(barlowDifference);
    FitWithConstant(barlowDifference, compareFile);
    // LookAtMean(barlowDifference);
    RebinHist(barlowDifference, compareFile);
    ManuallyRebin(barlowDifference, compareFile);
  }
    
  compareFile->Close();
}
コード例 #5
0
void create_module_info(TString dir = "/castor/cern.ch/user/r/rougny/vcalH2L_7/GainRun_173484"){
  ofstream t;
  t.open("module_info.txt");
  if(! t.is_open()){
    cout << "[create_module_info] Could not open output txt file. Exiting ..." << endl;
    exit(1);
  }

  for(int i=0 ; i<40 ; ++i){
    ostringstream f_str("");
    f_str << "rfio://" << dir << "/" << i << ".root";
    cout << "Opening file : " << f_str.str() << endl;
    TFile* f = TFile::Open(f_str.str().c_str() , "READ");
    vector<TString> dir_list = makedirlist(f , "Module");
    
    for(int m = 0 ; m < dir_list.size() ; ++m){
      
      TDirectory* dir = f->GetDirectory(dir_list[m]);
      int detid = getDetId(((TH1*) dir->Get(((TKey*) dir->GetListOfKeys()->At(0))->GetName()))->GetName());
    
      t << detid << "  " << i << "  " << dir_list[m].Remove(0,dir_list[m].First('y')+2) << endl;
    
    }


    f->Close();
  
  }

  t.close();

}
コード例 #6
0
ファイル: rootExample.cpp プロジェクト: niklask/ROOTexample
void loadRootFile()
{

    TFile* pRootFile = new TFile("myfile.root", "READ");

    if (pRootFile != NULL) {
        TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
        if (pTestDir != NULL) {
            pTestDir->cd();

            MyROOTObject* pMyObj = NULL;
            std::string name = "testobj";
            pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
            if (pMyObj != NULL) {
                std::cout << *pMyObj << std::endl;
                delete pMyObj;
            }
        }

        if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
            delete pTestDir;
            pRootFile->Close();
            delete pRootFile;
        }
    }    

}
コード例 #7
0
ファイル: rootExample.cpp プロジェクト: niklask/ROOTexample
void appendRootFile()
{

    TFile* pRootFile = new TFile("myfile.root", "UPDATE");

    if (pRootFile != NULL) {
        TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
        if (pTestDir != NULL) {
            pTestDir->cd();

            MyROOTObject* pMyObj = NULL;
            std::string name = "testobj";
            pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
            if (pMyObj != NULL) {
                std::cout << *pMyObj << std::endl;
                delete pMyObj;
            }

												name = "newobj";
												MyROOTObject* pNewObj = NULL;
												pNewObj = new MyROOTObject(42, 5.9e2, name);
            if (pNewObj != NULL) {
                std::cout << *pMyObj << std::endl;
																pNewObj->Write(pNewObj->GetName());
                delete pNewObj;
            }
        }

        if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
            pRootFile->Close();
            delete pRootFile;
        }
    }    

}
コード例 #8
0
ファイル: pythia.C プロジェクト: CMSRA1/bryn
void merged() {
  
  std::vector<std::string> files;
  files.push_back("QCDJets_Pythia_15.root");
  files.push_back("QCDJets_Pythia_30.root");
  files.push_back("QCDJets_Pythia_80.root");
  files.push_back("QCDJets_Pythia_170.root");
  files.push_back("QCDJets_Pythia_300.root");
  files.push_back("QCDJets_Pythia_470.root");
  files.push_back("QCDJets_Pythia_800.root");
  files.push_back("QCDJets_Pythia_1400.root");
  
  for ( int i = 0; i < files.size(); ++i ) {
    TFile* f = new TFile(std::string(files[i]).c_str(),"READ");
    if ( f ) {
      TDirectory* d = (TDirectory*)f->Get("susyTree");
      if ( d ) {
	TTree* t = (TTree*)d->Get("tree");
	if ( t ) {
	  std::cout << " TFile: " << files[i] 
		    << " Entries: " << t->GetEntries() 
		    << std::endl;
	} else {
	  std::cout << " NULL TTree ptr!" << std::endl;
	}
      } else {
	std::cout << " NULL TDirectory ptr!" << std::endl;
      }
      f->Close();
      delete f;
    } else {
      std::cout << " NULL TFile ptr!" << std::endl;
    }
  }
}
コード例 #9
0
ファイル: macro.C プロジェクト: niklask/ROOTexample
void macro()
{
    cout << "Example macro for testing the ROOTobject library from CINT"
         << endl;

    TFile* pRootFile = new TFile("myfile.root", "READ");

    if (pRootFile != NULL) {
        TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
        if (pTestDir != NULL) {
            pTestDir->cd();

            MyROOTObject* pMyObj = NULL;
            std::string name = "testobj";
            pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
            if (pMyObj != NULL) {
                std::cout << *pMyObj << std::endl;
            }
        }

        if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
            pRootFile->Close();
            delete pRootFile;
        }
    }

}
コード例 #10
0
TH1F* getHisto(string filename, string directoryname, string histoname) {
  TFile *file = new TFile(filename.c_str(),"READ");
  if (!file) {
    cout << "Could not open file " << filename << endl;
    return 0;
  }

  TDirectory *dir = (TDirectory*)file->FindObjectAny(directoryname.c_str());
  if (!dir) {
    cout << "Could not find directory " << directoryname << endl;
    delete file;
    return 0;
  }

  TH1F *hist = (TH1F*)dir->Get(histoname.c_str());
  if (!hist) {
    cout << "Could not find histogram " <<  histoname << " in directory " << directoryname << endl;
    delete dir;
    delete file;
    return 0;
  }

  hist->SetDirectory(0);
  delete dir;
  delete file;
  return hist;

}
コード例 #11
0
//------------------------------------------------------------------------------
// getTreeFromFile
//------------------------------------------------------------------------------
TTree* getTreeFromFile(const char* infname, Bool_t loadFromDir = kTRUE)
{
  bool verbose = false;

  if (verbose) {
    cout << "--- Open file " << infname << endl;
  }
  
  TFile* inf = new TFile(infname,"read");
  assert(inf);

  TTree* t = 0;
  if (loadFromDir) {
    TDirectory *dir = (TDirectory*)inf->FindObjectAny("ElectronValidationMod");
    assert(dir);
    

    t = (TTree*)dir->Get("ElectronIDOptimizationTree");
    assert(t);
  } else {
    t = (TTree*)inf->Get("ElectronIDOptimizationTree");  
  }

  if (verbose) {
    cout << "---\tRecovered tree " << t->GetName()
	 << " with "<< t->GetEntries() << " entries" << endl;
  }
  
  return t;
}
コード例 #12
0
//------------------------------------------------------------------------------
// getTreeFromFile
//------------------------------------------------------------------------------
TTree* getTreeFromFile(const char* infname, const char* tname)
{
  bool verbose = false;

  if (verbose) {
    cout << "--- Open file " << infname << endl;
  }
  
  TFile* inf = new TFile(infname,"read");
  assert(inf);

  TTree* t = (TTree*)inf->Get(tname);
  
  if (!t) {
    TDirectory *dir = (TDirectory*)inf->FindObjectAny("eleIDdir");
    if (!dir) {
      cout << "Cannot get Directory HwwNtuplerMod from file " << infname << endl;
      assert(dir);
    }
    t = (TTree*)dir->Get(tname);
  }

  if (!t) {
    cout << "Cannot get Tree with name " << tname << " from file " << infname << endl;
  }
  assert(t);


  if (verbose) {
    cout << "---\tRecovered tree " << t->GetName()
	 << " with "<< t->GetEntries() << " entries" << endl;
  }
  
  return t;
}
コード例 #13
0
TH1* getHisto(char * filename, char* histoName, char * dirName, int nBin, double lumi)
{
  TH1 * hpt_=0;
  TFile *file0 = TFile::Open(filename);
  if(!file0) return hpt_;
  TDirectory *dir;
  TH2D * hMuPt;

  if(dirName == "0") {
    hMuPt = (TH2D*) file0->Get(histoName);
  } else {
    dir = (TDirectory*) file0->Get(dirName);
    if(!dir) return hpt_;
    hMuPt = (TH2D*) dir->Get(histoName);
  }

  if(hMuPt) {
  hpt_ = (TH1*) hMuPt->Clone();
  hpt_->Sumw2();
  hpt_->Scale(1./lumi); // this take into into account the luminosity
  hpt_->SetLineWidth(2);
  hpt_->Rebin(nBin);
  double nBinX=hpt_->GetNbinsX();

  // overFlow
  hpt_->SetBinContent((int)nBinX,hpt_->GetBinContent((int)nBinX)+hpt_->GetBinContent((int)nBinX+1));
  hpt_->SetDirectory(0);
  file0->Close();
  hpt_->SetLineWidth(3);
  }
  return hpt_;
}
コード例 #14
0
ファイル: compare.C プロジェクト: tj710/TTEmulator
TObject * getHistogram2(TFile * f, string algo,string histoName, string range = "GLOBAL")
{
string prefix = "JetTag";
string d = prefix+"_"+algo+"_"+range;
TDirectory * dir  =(TDirectory *) f->Get(d.c_str());
return dir->Get((histoName+"_"+algo+"_"+range).c_str());
}
コード例 #15
0
// -----------------------------------------------------------------------------
//
TH1* getHisto( TString path,
	       TString nameHist,
	       TString nameFile,
	       TString Dirname, 
	       int rebin ) {
  TString name = path + nameFile;
  TFile* file =  new TFile(name);
  // file->ls();
  TDirectory* dir = (TDirectory*)file->Get(Dirname);
  //  dir->ls();

  if( !dir) {
    std::cout << " dir " << Dirname << std::endl;
  }
  TH1* hist = (TH1*)dir->Get(nameHist);
  if (!hist) {
    std::cout << " name: " << nameHist
	      << " file: " << nameFile
	      << " dir: " <<  Dirname
	      << std::endl;
    abort();

  }
  hist->SetLineWidth(1);
  if ( rebin > 0 ) { hist->Rebin(rebin); }
  hist->GetXaxis()->SetTitleSize(0.055);
  hist->GetYaxis()->SetTitleSize(0.055);
  hist->GetXaxis()->SetLabelSize(0.05);
  hist->GetYaxis()->SetLabelSize(0.05);
  hist->SetStats(kFALSE);
  return hist;
}
コード例 #16
0
Double_t getNEvents(string filename) {

  //Get Number of Events in the Sample
  TFile *file = new TFile(filename.c_str(),"READ");
  if (!file) {
    cout << "Could not open file " << filename << endl;
    return 0;
  }

  TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod");
  if (!dir) {
    cout << "Could not find directory AnaFwkMod"
         << " in file " << filename << endl;
    delete file;
    return 0;
  }

  TH1F *hist = (TH1F*)dir->Get("hDAllEvents");
  if (!hist) {
    cout << "Could not find histogram hDEvents in directory AnaFwkMod"
         << " in file " << filename << endl;
    delete dir;
    delete file;
    return 0;
  }  
  return hist->Integral();
}
コード例 #17
0
ファイル: FitOmegaCut.C プロジェクト: cmenpgroup/jlab
void FitOmega_OneTarget(char *rootFile, char* fDir="ReconCuts", Int_t iRun=0, Int_t iTgt=0, Int_t iCut=0, Int_t iFit=3, Int_t iClose=1)
{
	Int_t i;
	Float_t yield;

	TH1D *hist; // original histogram

    char hname[50];
	char plotFilePrefix[100];
    
	// data files contain the trees
	printf("Analyzing file %s\n",rootFile);  
	TFile *fd = new TFile(rootFile,"READ"); // open up the ROOT file

    TDirectory *tmp = fd->GetDirectory(fDir);
	
    sprintf(hname,"%s",HistName[iCut]);
    cout << hname << endl;
	hist = (TH1D*)tmp->Get(hname); // get the histogram from the ROOT file

    sprintf(plotFilePrefix,"FitOmega_%s_%s",RunName[iRun],hname);
    
    yield = FitOmega(hist,plotFilePrefix);//, iFit, iClose);

	// open text file for the yields
	char OutFile[100];
	sprintf(OutFile,"%s.yld",plotFilePrefix);
	ofstream fout(OutFile);
    
	fout<<RunName[iRun]<<"\t"<<TgtName[iTgt]<<"\t"<<yield<<"\t"<<sqrt(yield)<<endl;

	fout.close(); // close the text file
//	fd->Close();  // close ROOT file
}
コード例 #18
0
double getweight(TFile *file, double xsec) {
 
  TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod");
  TH1D *hallevts = (TH1D*)dir->Get("hDTotalMCWeight");
  
  return xsec/hallevts->GetSumOfWeights();
  
}
コード例 #19
0
TH1D* getHists( TFile *f, TString folders, TString hname ) {

  TDirectory *TDir = (TDirectory*)( f->Get( folders ) );

  TH1D* inh= (TH1D*)( TDir->Get( hname ) );
  cout<<"here2"<<endl;
  return inh;
}
コード例 #20
0
ファイル: compare.C プロジェクト: HeinerTholen/cmssw
TObject * getHistogram(TFile * f, string algo,string histoName, string range = "GLOBAL")
{
string prefix = "DQMData/Btag/JetTag";
string d = prefix+"_"+algo+"_"+range;
 cout <<" DIR "<<d<<endl;
TDirectory * dir  =(TDirectory *) f->Get(d.c_str());
return dir->Get((histoName+"_"+algo+"_"+range).c_str());
}
コード例 #21
0
ファイル: PlotEC.C プロジェクト: cmenpgroup/jlab
//
// OverlayEC_xy_local - overlay histogram of EC x vs y
//
//                  fAna = output from eg2a DMS
//                  fDir = ROOT directory
//                  HistName1 = 1st histogram name
//                  HistName2 = 2nd histogram name
//                  target = target name
//
void OverlayEC_xy_local(char *fAna="Ana.root", char *fDir, char *HistName1, char *HistName2, char *target)
{
	Int_t i;
    TH2D *hist1[6];
    TH2D *hist2[6];

    // Canvas to plot histogram
	TCanvas *c1 = new TCanvas("c1","c1",0,0,1200,800);
	c1->SetBorderMode(1);  //Bordermode (-1=down, 0 = no border, 1=up)
	c1->SetBorderSize(5);
	gStyle->SetOptStat(1111);
	c1->SetFillStyle(4000);
    c1->Divide(3,2);
    
	// data files contain the trees
	printf("Analyzing file %s\n",fAna);
	TFile *fm = new TFile(fAna,"READ");
    TDirectory *tmp = fm->GetDirectory(fDir);
    
    for(i=0; i<NSECTORS; i++){
        gPad->SetLeftMargin(Lmar);
        gPad->SetRightMargin(Rmar);
        gPad->SetFillColor(0);
        
        c1->cd(i+1);
        sprintf(hname,"EC_XvsY_local_%s%i",HistName1,i+1);
        hist1[i] = (TH2D*)tmp->Get(hname);
        sprintf(htitle,"Sector %i, %s",i+1,target);
        hist1[i]->SetTitle(htitle);
        hist1[i]->GetXaxis()->CenterTitle();
        hist1[i]->GetYaxis()->CenterTitle();
        hist1[i]->GetYaxis()->SetTitleOffset(yoff);
        hist1[i]->Draw("colz");
        
        sprintf(hname,"EC_XvsY_local_%s%i",HistName2,i+1);
        hist2[i] = (TH2D*)tmp->Get(hname);
        hist2[i]->SetMarkerColor(1);
        hist2[i]->Draw("same");

    }
    
    sprintf(OutCan,"OL_EC_XvsY_local_%s_VS_%s_%s.gif",HistName1,HistName2,target);
    c1->Print(OutCan);
    sprintf(OutCan,"OL_EC_XvsY_local_%s_VS_%s_%s.eps",HistName1,HistName2,target);
    c1->Print(OutCan);
}
コード例 #22
0
ファイル: playHist1D.C プロジェクト: mengzx/Work_CMS
// -----------------------------------------------------------------------------
//
TH1D* playHist1D::getHist1D( TFile *f, TString dirname, TString hname){
  TDirectory *TDir = (TDirectory*)( f->Get( dirname ) );
  if( TDir ){
    TH1D* hh= (TH1D*)( TDir->Get( hname ) );
    //    hh->SetDirectory(0);
    //    f->Close();
    return hh;
  } else { return 0; }
}
コード例 #23
0
ファイル: MergeScaled.C プロジェクト: Andrej-CMS/cmssw
void mergeAll(const TString & inputFileName, const int color1, const int color2, TLegend * legend, const TString & when, const TString & options = "")
{
  TFile * inputFile = new TFile(inputFileName);
  TH1F * histo1 = (TH1F*)inputFile->Get("hRecBestRes_Mass");
  TDirectory * profileDir = (TDirectory*)inputFile->Get("Mass_fine_P");
  TProfile * histo2 = (TProfile*)profileDir->Get("Mass_fine_PProf");

  histo1->Rebin(8);
  histo2->Rebin(2);

  ScaleFraction scaleFraction;
  pair<TH1*, TH1*> newHistosUpsilon1S = scaleFraction.scale(histo1, histo2, 9, 9.8, "1");

  if( first ) {
    newHistosUpsilon1S.first->Draw(options);
    first = false;
  }
  else {
    newHistosUpsilon1S.first->Draw(options+"same");
  }
  newHistosUpsilon1S.first->SetLineColor(color1);
  newHistosUpsilon1S.second->Scale(newHistosUpsilon1S.first->Integral("width")/newHistosUpsilon1S.second->Integral("width"));
  newHistosUpsilon1S.second->Draw("same");
  newHistosUpsilon1S.second->SetLineColor(color2);

  legend->AddEntry(newHistosUpsilon1S.first, "mass "+when+" correction");
  legend->AddEntry(newHistosUpsilon1S.second, "mass prob "+when+" correction");

  pair<TH1*, TH1*> newHistosUpsilon2S = scaleFraction.scale(histo1, histo2, 9.8, 10.2, "2");

  newHistosUpsilon2S.first->Draw(options+"same");
  newHistosUpsilon2S.first->SetLineColor(color1);
  newHistosUpsilon2S.second->Scale(newHistosUpsilon2S.first->Integral("width")/newHistosUpsilon2S.second->Integral("width"));
  newHistosUpsilon2S.second->Draw("same");
  newHistosUpsilon2S.second->SetLineColor(color2);

  pair<TH1*, TH1*> newHistosUpsilon3S = scaleFraction.scale(histo1, histo2, 10.2, 10.8, "3");

  newHistosUpsilon3S.first->Draw(options+"same");
  newHistosUpsilon3S.first->SetLineColor(color1);
  newHistosUpsilon3S.second->Scale(newHistosUpsilon3S.first->Integral("width")/newHistosUpsilon3S.second->Integral("width"));
  newHistosUpsilon3S.second->Draw("same");
  newHistosUpsilon3S.second->SetLineColor(color2);


//   newHistosUpsilon1S.first->SetLineWidth(2);
//   newHistosUpsilon1S.second->SetLineWidth(2);
//   newHistosUpsilon2S.first->SetLineWidth(2);
//   newHistosUpsilon2S.second->SetLineWidth(2);
//   newHistosUpsilon3S.first->SetLineWidth(2);
//   newHistosUpsilon3S.second->SetLineWidth(2);

  newHistosUpsilon1S.first->GetXaxis()->SetTitle("Mass (GeV)");
  newHistosUpsilon1S.first->GetYaxis()->SetTitle("arbitrary units");
}
コード例 #24
0
int produceEnergyHistos(CSPrereqs& csp)
{
    cout << endl << "Mapping " << csp.name << " TOF histogram to energy domain..." << endl;

    // open input file
    TFile* inputFile = new TFile(inputFileName.c_str(),"READ");
    if(!inputFile->IsOpen())
    {
        cerr << "Error: failed to open " << inputFileName << "  to fill histos." << endl;
        return 1;
    }

    // create output file
    TFile* outputFile = new TFile(outputFileName.c_str(),"RECREATE");

    for(auto& channelName : config.cs.DETECTOR_NAMES)
    {
        TDirectory* detectorDirectory = inputFile->GetDirectory(channelName.c_str());
        if(!detectorDirectory)
        {
            cerr << "Error: failed to find " << channelName << " directory in " << inputFileName << "." << endl;
            return 1;
        }

        TDirectory* outputDirectory = outputFile->mkdir(channelName.c_str(),channelName.c_str());

        // find TOF histograms in input file
        for(int i=0; i<config.target.TARGET_ORDER.size(); i++)
        {
            string targetName = config.target.TARGET_ORDER[i];
            string TOFHistoName = targetName + "TOFCorrected";

            detectorDirectory->cd();

            TH1D* TOF = (TH1D*)detectorDirectory->Get(TOFHistoName.c_str());
            if(!TOF)
            {
                cerr << "Error: failed to open " << TOFHistoName << " in " << inputFileName << endl;
                return 1;
            }

            outputDirectory->cd();

            TH1D* correctedEnergy = convertTOFtoEnergy(TOF, targetName + "Energy");
            TOF->Write();
            correctedEnergy->Write();
        }
    }

    outputFile->Close();
    inputFile->Close();

    return 0;
}
コード例 #25
0
ファイル: compare.C プロジェクト: tj710/TTEmulator
TObject * getHistogram(TFile * f, string algo,string histoName, string range, string suffix)
{
string prefix = "DQMData/Run 1/Btag/Run summary/JetTag";
string d = prefix+"_"+algo+"_"+range;
 cout <<" STR: "<<d<<endl; 
 cout <<" DIR: "<<  f->Get(d.c_str())<<endl;
 cout <<" HIS: "<<  (histoName+"_"+algo+"_"+range+suffix).c_str()<<endl;

 TDirectory * dir  =(TDirectory *) f->Get(d.c_str());
 return dir->Get((histoName+"_"+algo+"_"+range+suffix).c_str());
}
コード例 #26
0
vector<TH1D*> getHists( TFile *f, vector<TString> folders, TString hname ) {
  vector<TH1D*> inh;

  for( unsigned int i=0; i<folders.size(); i++ ){

    TDirectory *TDir = (TDirectory*)( f->Get( folders[i] ) );

    inh.push_back( (TH1D*)( TDir->Get( hname ) ) );
  }
  cout<<"here1"<<endl;
  return inh;
}
コード例 #27
0
void TestDraw()
{
  
  TFile f("MomentumResolutionMatrices.root");
  TDirectory *dir = (TDirectory*)f.GetDirectory("Normalized");
  TH2F* matrix = (TH2F*) dir->Get("fResMatrixLLMixedAllRebinNorm");

  TString histTitle = "Resolution Matrix #Lambda#Lambda";
  Bool_t isLogZ = kTRUE;
  DrawSmearMatrixPretty(matrix, histTitle, isLogZ);

}
コード例 #28
0
void fill(TDirectory & out, TObject * o, double w) {
  TDirectory * dir;
  TH1F * th1f;
  TH1D * th1d;
  TH2F * th2f;
  TH2D * th2d;
  if((dir  = dynamic_cast<TDirectory*>(o)) != 0) {
    const char * name = dir->GetName();
    TDirectory * outDir = dynamic_cast<TDirectory*>(out.Get(name));
    if(outDir == 0) {
      cerr << "can't find directory " << name << " in output file" << endl;
      exit(-1);
    }
    TIter next(dir->GetListOfKeys());
    TKey *key;
    while( (key = dynamic_cast<TKey*>(next())) ) {
      string className(key->GetClassName());
      string name(key->GetName());
      TObject * obj = dir->Get(name.c_str());
      if(obj == 0) {
	cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl;
	exit(-1);
      }
      fill(*outDir, obj, w);
    }
  } else if((th1f = dynamic_cast<TH1F*>(o)) != 0) {
    const char * name = th1f->GetName();
    TH1F * outTh1f = dynamic_cast<TH1F*>(out.Get(name));
    if(outTh1f == 0) {
      cerr <<"error: histogram TH1F" << name << " not found in directory " << out.GetName() << endl;
      exit(-1);	
    }
    outTh1f->Add(th1f, w);
  } else if((th1d = dynamic_cast<TH1D*>(o)) != 0) {
    const char * name = th1d->GetName();
    TH1D * outTh1d = dynamic_cast<TH1D*>(out.Get(name));
    if(outTh1d == 0) {
      cerr <<"error: histogram TH1D" << name << " not found in directory " << out.GetName() << endl;
      exit(-1);	
    } 
    outTh1d->Add(th1d, w);
  } else if((th2f = dynamic_cast<TH2F*>(o)) != 0) {
    const char * name = th2f->GetName();
    TH2F * outTh2f = dynamic_cast<TH2F*>(out.Get(name));
    if(outTh2f == 0) {
      cerr <<"error: histogram TH2F" << name << " not found in directory " << out.GetName() << endl;
      exit(-1);	
    }
    outTh2f->Add(th2f, w);
  } else if((th2d = dynamic_cast<TH2D*>(o)) != 0) {
    const char * name = th2d->GetName();
    TH2D * outTh2d = dynamic_cast<TH2D*>(out.Get(name));
    if(outTh2d == 0) {
      cerr <<"error: histogram TH2D" << name << " not found in directory " << out.GetName() << endl;
      exit(-1);	
    }
    outTh2d->Add(th2d, w);
  }
}
コード例 #29
0
ファイル: AnalyzePlots.C プロジェクト: cms-tamu/MuJetAnalysis
TH1F* getHist(TFile* file, TString hname){
	TIter next(file->GetListOfKeys());
	TKey *key;
	while((key = (TKey*)next())){
		TDirectory* dir = file->GetDirectory(key->GetName());
		if(dir->FindKey(hname) != 0){
			TH1F *h = (TH1F*)dir->Get(hname);
			return h;
		}
	}
	cout << "hname: " << hname << endl;
	return NULL;
}
コード例 #30
0
ファイル: NormalizeNtuple.C プロジェクト: sixie/EWKAna
//--------------------------------------------------------------------------------------------------
// Get Total Number of Events in the sample
//--------------------------------------------------------------------------------------------------
Double_t getNormalizationWeight(string filename, string datasetName) {
  // Get Normalization Weight Factor

  //Get Number of Events in the Sample
  Double_t NEvents = 1;
  TFile *file = new TFile(filename.c_str(),"READ");
  TDirectory *dir = 0;
  TH1F *hist = 0;
  if (!file) {
    cout << "Could not open file " << filename << endl;
  } else {
    
    hist = (TH1F*)file->Get("hDAllEvents");
    if (!hist) {
      dir = (TDirectory*)file->FindObjectAny("AnaFwkMod");
      if (!dir) {
        cout << "Could not find directory AnaFwkMod"
             << " in file " << filename << endl;
        delete file;
      } else {
        
        hist = (TH1F*)dir->Get("hDAllEvents");
        if (!hist) {
          cout << "Could not find histogram hDEvents in directory AnaFwkMod"
               << " in file " << filename << endl;
          delete dir;
          delete file;
        }
      }
    }
  }

  if (hist) {
    NEvents = hist->Integral();
  }

  //Get CrossSection
  Double_t Weight = 1.0;
  if (datasetName.find("data") == string::npos) {
    mithep::SimpleTable xstab("/home/sixie/CMSSW_analysis/src/MitPhysics/data/xs.dat");
    cerr << "Use xs table: " << "$CMSSW_BASE/src/MitPhysics/data/xs.dat" << endl;
    Double_t CrossSection = xstab.Get(datasetName.c_str());
    Weight = CrossSection / NEvents;
    cerr << datasetName << " : " << CrossSection << " " << NEvents << " " << Weight << endl;
  }

//   if (dir) delete dir;
//   if (file) delete file;
  return Weight;

}