예제 #1
0
파일: MERGE.C 프로젝트: aashaqshah/cmssw-1
// Save to .root file
void SaveOutput(TString name,TList &list)
{
	TFile *out = new TFile(name,"RECREATE");
	TDirectory *pwd = gDirectory;
	for(int i=0;i<list.GetSize();i++)
	{
		TDecayMode *dm = list.At(i);
		TDirectory *subdir = out->mkdir(dm->GetName());
		subdir->cd();
		subdir->Append(dm);
		subdir->Append(dm->histograms);
		pwd->cd();
	}
	if(!genDesc) cout<<"WARNING! No Generator description in files!"<<endl;
	else out->Append(genDesc);
	if(userHisto)
	{
		
		TDecayMode *uh = (TDecayMode*) userHisto;
		cout<<"INFO: Appending user histograms"<<endl;
		TDirectoryFile *histos = out->mkdir("USER_HISTOGRAMS");
		TIter  nexthist(uh->histograms);
		TKey  *key_hist=0;
		TH1D *h;
		while(h=(TH1D*)nexthist()) histos->Append(h);
	}
	out->Write();
	out->Close();
	delete out;
}
예제 #2
0
void pv_dist(const string& fFile, const string& fTitle, const string& fNameExt) {
  
   TH1F *h;
    
   TFile file(fFile.c_str());
   TDirectoryFile *dir = (TDirectoryFile*)file.Get("offsetAnalysis");
   TDirectoryFile *subDir = (TDirectoryFile*)dir->Get("PrimaryVertices");

   h = (TH1F*)subDir->Get("h_NofPVs"); 
   
   string name = h->GetName();
   string fileName = name + "__" + fNameExt + ".png";
   
   h->SetTitle(fTitle.c_str());
   
   TCanvas *c = new TCanvas("c","",1120,800);
   c->cd();
     
   h->SetLineWidth(2);
   h->Draw();
   
   c->SetLogy();
   c->SaveAs(fileName.c_str());
   
   delete c;
}
Double_t MakeHistsForSlides(TString goodFile, TString badFile, TString rootFile)
{
  //Extracting the histogram
  TFile* f = TFile::Open(rootFile);
  TDirectoryFile* dirFile = (TDirectoryFile*)(f->Get("AliAnalysisTaskCalibEmcal"));
  TList* list = (TList*)(dirFile->Get("histogram"));
  TH2D* cellVAmplitude = (TH2D*)(list->FindObject("_histogram_cell_id_amplitude"));

    
  //Getting a Good Cell
  TH1D* goodC = new TH1D();
  ifstream myFile(goodFile);
  TString title = "";

  const int num = 500;

  if(myFile.is_open())
    {
      string line = "";
      std::getline(myFile,line);

      int index = 0;
      double chi2 = 0.0;
      
      while(myFile >> index >> chi2 && index < num)
	{
	  //cout << index << "\t" << chi2 << endl;
	  title = Form("Energy distribution of Cell %d",index);
	  TH1D* goodCell = cellVAmplitude->ProjectionY("goodCell", index+1,index+1);
	  goodC = (TH1D*)goodCell->Clone();
	}
    }
예제 #4
0
std::pair<TH3F*,TH3F*> getEffHists(const char *file, const char *dirC, 
				     const char *histN, const char *histD){

     TFile *efile = new TFile(file,"read");
     TDirectoryFile *efileDIR = (TDirectoryFile*) efile->GetDirectory(dirC);

     TIter next(efileDIR->GetListOfKeys());
     TKey *key;

     Char_t name[100];

     TH3F *hpneff3d=0;
     TH3F *hpdeff3d=0;

     while ((key=(TKey*)next())) {
	sprintf(name,"%s",key->GetName());
	if(strcmp((key->GetName()),(histN))==0){
	  //cout<<"[getEffHists] Your numerator for Eff "<<name<<endl; 
	   hpneff3d = (TH3F*) efileDIR->Get(name);
	}
	if(strcmp((key->GetName()),(histD))==0){
	  //cout<<"[getEffHists] Your denominator for Eff "<<name<<endl; 
	   hpdeff3d = (TH3F*) efileDIR->Get(name);
	}
     }

     //efileDIR->Close(); 
     //efile->Close(); 
     return std::pair<TH3F*,TH3F*>(hpneff3d,hpdeff3d);
  }
예제 #5
0
void overlay_plots(const string& fFile0, const string& fFile1, const double fYmax, const string& fPlot, const string& fLegendEnt1, const string& fLegendEnt2, const string& fName) {
  
   TProfile *p[2];
 
   TFile file0(fFile0.c_str());
   TDirectoryFile *subDir = (TDirectoryFile*)file0.Get("offsetAnalysis");
   p[0] = (TProfile*)subDir->Get(fPlot.c_str());

   TFile file1(fFile1.c_str());
   subDir = (TDirectoryFile*)file1.Get("offsetAnalysis");
   p[1] = (TProfile*)subDir->Get(fPlot.c_str()); 

   p[0]->SetTitleOffset(1.5,"Y");
   p[0]->GetXaxis()->SetTitleSize(0.04);
   p[0]->GetYaxis()->SetTitleSize(0.04);
   
   double ymax = ((p[0]->GetMaximum())>(p[1]->GetMaximum())) ? p[0]->GetMaximum() : p[1]->GetMaximum();
   
   p[0]->GetYaxis()->SetRangeUser(0.,fYmax);
   
   TCanvas *c = new TCanvas("c","",800,800);
   c->cd();
  
   p[0]->SetLineWidth(3);
   p[0]->SetLineColor(kRed);
   p[0]->SetFillColor(kRed);
   p[0]->Draw("hist");
   p[1]->SetLineWidth(3);
   p[1]->SetLineColor(kBlack);
   p[1]->SetMarkerStyle(20);
   p[1]->SetMarkerColor(kBlack);
   p[1]->Draw("sames");
   
   TLegend *legend = new TLegend(.57,.77,.9,.87);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
//    legend->SetFillStyle(0);
   legend->SetMargin(0.12);
   legend->AddEntry(p[0],fLegendEnt1.c_str(),"l");
   legend->AddEntry(p[1],fLegendEnt2.c_str(),"l");
   legend->Draw();
   
   TLatex l;
   l.SetTextAlign(12);
   l.SetTextSize(0.04);
   l.SetTextFont(62);
   l.SetNDC();
   l.DrawLatex(0.15,0.85,"CMS 2009 Preliminary");
   
   string fileName = fName;
   c->SetGridy();
   c->SaveAs(fileName.c_str());
   
   delete legend;
   delete c;
}
예제 #6
0
int
main (int argc, char *argv[])
{
  map<string, string> opt;
  vector<string> argVector;
  parseOptions (argc, argv, opt, argVector);
  if (argVector.size () != 1 || opt.count ("help"))
    {
      printHelp (argv[0]);
      return 0;
    }
  TFile *fin;
  if (!(fin = TFile::Open (argVector.at (0).c_str (), "update")))
    {
      cout << "Failed to open " << argVector.at (0) << "!" << endl;
      return 0;
    }
  TIter next0 (fin->GetListOfKeys ());
  TObject *obj0;
  TH1D *cutFlow = 0;
  TDirectoryFile *dir = 0;
  while ((obj0 = next0 ()))
    {
      string obj0Class = ((TKey *) obj0)->GetClassName (),
             obj0Name = obj0->GetName ();

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

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

  return 0;
}
예제 #7
0
파일: filechk.C 프로젝트: Andrej-CMS/cmssw
int filechk(string fname)
{
  //TFile f("DQM_V0001_SiStrip_R000062940.root");
  TFile f(fname.c_str());

  if (f.IsZombie()){
    //cout << "File corrupted" << endl;
  return -1;
  }
  else
  {
    if ( fname.find("_SiStrip_") != string::npos ){
      TString rnStr = fname.substr(fname.find("_R") + 2, 9);
      TString runDirStr("Run ");
      runDirStr += rnStr.Atoi();
      TDirectoryFile* runDir = (TDirectoryFile*)f.FindObjectAny(runDirStr);
      if ( runDir == 0 )
        return 0; 
      
      TDirectoryFile* tracking = (TDirectoryFile*)runDir->FindObjectAny("Tracking");
      if ( tracking == 0 )
        return 0;
      
      TDirectoryFile* sistrip = (TDirectoryFile*)runDir->FindObjectAny("SiStrip");
      if ( sistrip == 0 )
        return 0;  
       
      TDirectoryFile* hist = (TDirectoryFile*)tracking->FindObjectAny("reportSummaryMap");
      if ( hist == 0 )
        return 0;
       
      hist = (TDirectoryFile*)sistrip->FindObjectAny("reportSummaryMap");
      if ( hist == 0 )
        return 0; 
      
      return 1;
    }
    
    //TH2F* hist;
    //hist = (TH2F*)f.FindObjectAny("reportSummaryMap");
    TDirectoryFile* hist;	
    //hist = (TDirectoryFile*)f.FindObjectAny("reportSummaryContents");
    hist = (TDirectoryFile*)f.FindObjectAny("reportSummaryMap");
    if (0 == hist) 
    {
      TDirectoryFile* hist2;
      hist2 = (TDirectoryFile*)f.FindObjectAny("EventInfo");
      if (0 != hist2)
        return 1;

      //cout << "File is incomplete" << endl;
      return 0;
    }
    else
    {
      //cout << "File is OK" << endl;
      return 1;
    }
  }
}
예제 #8
0
void histoBook::loadRootDir( TDirectory* tDir, string path ){

	//cout << "histoBook.loadRootDir] Path : " << path << endl;

	TList* list;

	if ( tDir ){
		list = tDir->GetListOfKeys();  
	} else {
		cout << "[histoBook.loadRootDir] Bad Directory Given " << endl;
		return;
	}

	TIter next(list);  
	TKey* key;  
	TObject* obj;   
	
	while ( (key = (TKey*)next()) ) {    
		
		obj = key->ReadObj() ;    
		
		if ( 0 == strcmp(obj->IsA()->GetName(),"TDirectoryFile") ){
			TDirectoryFile* dir = (TDirectoryFile*)obj;
			
			string nPath = path + dir->GetName();
			if ( path == (string) "" )
				nPath = path + dir->GetName();
			else 
				nPath = path + "/" + dir->GetName();

			cd( nPath );
			loadRootDir( dir, nPath );
		} else if ( obj ){
			if (    (strcmp(obj->IsA()->GetName(),"TProfile")!=0) && (!obj->InheritsFrom("TH2") && (!obj->InheritsFrom("TH1"))) ) {      
				// not a 1d or 2d histogram
			} else {
				// add it to the book
				//cout << "Adding : " << obj->GetName() << endl;
				add( obj->GetName(), (TH1*)obj->Clone( obj->GetName() ) );
			}    
			
		}
	}	

}
int GetCoefficient(TString txtFile, TString rootFile)
{
  //Extracting the histogram
  TFile* f = TFile::Open(rootFile);
  TDirectoryFile* dirFile = (TDirectoryFile*)(f->Get("AliAnalysisTaskCalibEmcal"));
  TList* list = (TList*)(dirFile->Get("histogram"));
  TH2D* cellVAmplitude = (TH2D*)(list->FindObject("_histogram_cell_id_amplitude"));
  
  //cout << __FILE__ << __LINE__ << endl;

  //Cell Tower range to analyse
  const Int_t CVALow = 0;
  const Int_t CVAHigh = 17670;
  
  //cout << __FILE__ << __LINE__ << endl;

  //Obtaining a histogram of the Good cells.
  TList* goodHistList = new TList;
  ifstream goodFile(txtFile);
  int numCells = 0;
  if(goodFile.is_open())
    {

      //cout << __FILE__ << __LINE__ << endl;

      string line = "";
      std::getline(goodFile,line);
      int index = 0;
      double chi2 = 0.0;
      
      //cout << __FILE__ << __LINE__ << endl;

      //for(index = 0; index < 3; index++)
      while(goodFile >> index >> chi2)
	{
	  //cout << Form("cell%d",index) << endl;
	  TH1D* cell = cellVAmplitude->ProjectionY(Form("cell%d",index),index+1,index+1);
	  goodHistList->Add(cell);
	  numCells++;
	}
      
    }
예제 #10
0
// Noise section
Stat_t AnalysisClass::doHisto(Char_t * Variable, Char_t *SubDetName, Char_t *Layer,Char_t *label){
  TH1 *hHisto=0; 
  if (debug)   cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) 	cout << "Found SubDet " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		hHisto = (TH1*) d3;
		if(hHisto->GetEntries()!=0) {
		  pPar[0]=hHisto->GetMean();
		  pPar[1]=hHisto->GetRMS();  
		  if (debug) cout << "Histo Title " << hHisto->GetTitle() << " mean: " << hHisto->GetMean() << " rms: " << hHisto->GetRMS() << " " << hHisto->GetEntries() << endl;
		}
		else{
		  cout<<"Empty Histogram "<< hHisto->GetTitle() << endl;
		  pPar[0]=-10; pPar[1]=-10;
		}
	      }
	    }
	  }
	}
      }
    }
  return hHisto->GetEntries();  
}
예제 #11
0
// This will generate the following PDFs:
// -- hDQ_muScTDiff_[DetName]_[BankName].png
void GenerateTDiffPlots(std::string filename) {

  std::cout << "Generating pulse shape plots..." << std::endl;

  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetCanvasBorderMode(0); // turn off canvas borders


  TFile* file = new TFile(filename.c_str(), "READ");

  // The histograms
  TH1F *hDQ_muScTDiff;

  // Loop through the histograms in the file and get the island histograms (bank and channel names may differ between runs)
  TDirectoryFile* dir = (TDirectoryFile*) file->Get("DataQuality_LowLevel");
  
  TIter nextDirKey(dir->GetListOfKeys()); // get the list of keys in the directory (all histograms should be in this folder)
  TKey *dirKey;
  
  while ( (dirKey = (TKey*)nextDirKey()) ) {
    // Get the names of all the histograms and count them up
    if (strcmp(dirKey->ReadObj()->ClassName(), "TH1F") == 0) {

      TCanvas *c1 = new TCanvas();

      std::string histogram_name = dirKey->ReadObj()->GetName();
      std::string histogram_location = "DataQuality_LowLevel/" + histogram_name;
      std::string pngname = "data_quality_figs/" + histogram_name + ".png";

      if (histogram_name.find("muScTDiff") != std::string::npos) {
	file->GetObject(histogram_location.c_str(),hDQ_muScTDiff);

	hDQ_muScTDiff->GetYaxis()->SetTitleOffset(1.3);
	hDQ_muScTDiff->Draw();
	c1->Print(pngname.c_str());
      }
    }
  }
}
void plotProducer2(const string& fFile, const string& fPlot, const string& fNameExt, const string& fExt, const string& fSwitch) {
  
   TH2F *h;
    
   TFile file(fFile.c_str());
   TDirectoryFile *dir = (TDirectoryFile*)file.Get("offsetAnalysis");
   TDirectoryFile *subDir = (TDirectoryFile*)dir->Get("PrimaryVertices");

   h = (TH2F*)subDir->Get(fPlot.c_str());

   string name = h->GetName();
   string fileName = name + "__" + fNameExt + "." + fExt;
   
   TCanvas *c = new TCanvas("c","",1120,800);
   c->cd();
     
   h->Draw(fSwitch.c_str());

   c->SaveAs(fileName.c_str());
   
   delete c;
}
void plotProducer(const string& fFile, const string& fPlot, const string& fNameExt, const string& fExt, const string& fSwitch) {
  
   TH1F *h;
    
   TFile file(fFile.c_str());
   TDirectoryFile *dir = (TDirectoryFile*)file.Get("offsetAnalysis");
   TDirectoryFile *subDir = (TDirectoryFile*)dir->Get("PrimaryVertices");

   h = (TH1F*)subDir->Get(fPlot.c_str());

   string name = h->GetName();
   string fileName = name + "__" + fNameExt + "." + fExt;
   
   TCanvas *c = new TCanvas("c","",1120,800);
   c->cd();
     
   //h->SetLineWidth(2);
   h->Draw();
   
   if ( fSwitch.find("log") != string::npos ) c->SetLogy();
   c->SaveAs(fileName.c_str());
   
   delete c;
}
예제 #14
0
void mySelector::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.
  TString option = GetOption();
  TString output = "gr_";
  output += option;
  output += ".root";
  TFile *hfile = new TFile(output,"RECREATE","FONLL CCbar cross section");
  
  hfile->cd();
  const Int_t npoint = eventnumber;
  Float_t x[npoint];
  Float_t y[npoint];
  Float_t ylow[npoint];
  Float_t yup[npoint];
  for(int i=0;i<npoint;i++)
    {
      x[i] = Pt[i];
      y[i] = Central[i];
      ylow[i] = Down[i];
      yup[i] = Up[i];
    }
  //TGraph *grFONLLD0 = new TGraph(npoint,Pt,Central);
  TDirectoryFile *ratioErr = new TDirectoryFile(option,"ratio error of scale pp500 to pp200 ");
  ratioErr->SetName(option);
  ratioErr->Add(hRatio);
  TGraph *grFONLLRatio = new TGraph(npoint,x,y);
  grFONLLRatio->SetName("grFONLLRatio");
  TGraph *grFONLLRatio_u = new TGraph(npoint,x,yup);
  grFONLLRatio_u->SetName("grFONLLRatio_u");
  TGraph *grFONLLRatio_d = new TGraph(npoint,x,ylow);
  grFONLLRatio_d->SetName("grFONLLRatio_d");
  grFONLLRatio->Print();
  ///grFONLLRatio->Write();
  ratioErr->Add(grFONLLRatio);
  grFONLLRatio_u->Print();
  //grFONLLRatio_u->Write();
  ratioErr->Add(grFONLLRatio_u);
  grFONLLRatio_d->Print();
  //grFONLLRatio_d->Write();
  ratioErr->Add(grFONLLRatio_d);
  ratioErr->Write();
  hfile->Print();
  hfile->Close();
  tNow.Set();
  cout<<"----------End of job----------"<<endl;
  tNow.Print();
}
예제 #15
0
void readMCPerform(TString filename="QAresults_AOD.root", Int_t drawOnlyDzerDplus = 1, Int_t runNumber=-1)
{

  const Int_t totTrending=5;
  Float_t vecForTrend[totTrending];
  TString varForTrending[totTrending]={"nDzeroCandperEv","nDplusCandperEv","nDsCandperEv","nLcCandperEv","nDstarCandperEv"};

  

  TTree* trtree=new TTree("trendingHF","tree of trending variables");
  trtree->Branch("nrun",&runNumber,"nrun/I");
  for(Int_t j=0; j<totTrending; j++){
    trtree->Branch(varForTrending[j].Data(),&vecForTrend[j],Form("%s/F",varForTrending[j].Data()));
    vecForTrend[j]=-99.;
  }

  TFile *ff = new TFile(filename.Data());

  Int_t color[5] = {kBlack, kRed, kGreen, kBlue, kOrange};

  TDirectoryFile *dirD2H = (TDirectoryFile *)ff->Get("PWG3_D2H_QA");
  if(!dirD2H){
    printf("Directory PWG3_D2H_QA not found in file %s\n",filename.Data());
    return;
  }
  TList *listD2H = (TList *)dirD2H->Get("nEntriesQA");
  if(!listD2H){
    printf("TList nEntriesQA not found in file %s\n",filename.Data());
    return;  
  }
  TH1F *hNentries = (TH1F *)listD2H->FindObject("hNentries");
  TH2F *hHasSelBit = (TH2F *)listD2H->FindObject("HasSelBit");

  TCanvas *cqa = new TCanvas("cqa", "cqa", 800, 500);
  cqa->Divide(2, 1);
  cqa->cd(1);
  hNentries->Draw();
  cqa->cd(2);
  hHasSelBit->Draw("colz");
  cqa->SaveAs("plot_D2HQA.png");

  Double_t nEv=hNentries->GetBinContent(10);
  vecForTrend[0]=hHasSelBit->GetBinContent(1)/nEv;
  vecForTrend[1]=hHasSelBit->GetBinContent(2)/nEv;
  vecForTrend[2]=hHasSelBit->GetBinContent(3)/nEv;
  vecForTrend[3]=hHasSelBit->GetBinContent(4)/nEv;
  vecForTrend[4]=hHasSelBit->GetBinContent(5)/nEv;


  TDirectoryFile *dir = (TDirectoryFile *)ff->Get("PWGHF_D2H_MCPerform");
  TList* list = 0x0;
  if (dir)
  {
    list = (TList *)dir->Get("coutputDperfQA");
    if(list){
    
      TH1F *hn = (TH1F *)list->FindObject("fHistNEvents");
      TH1F *hnGenD = (TH1F *)list->FindObject("fHistNGenD");
      Int_t entries = hn->GetBinContent(3);
      
      TH2F *fHistNCand = (TH2F *)list->FindObject("fHistNCand");
      TH1F *fHistNCandDzero = (TH1F *)fHistNCand->ProjectionY("fHistNCandDzero", 1, 1);
      TH1F *fHistNCandDplus = (TH1F *)fHistNCand->ProjectionY("fHistNCandDplus", 2, 2);
      TH1F *fHistNCandDstar = (TH1F *)fHistNCand->ProjectionY("fHistNCandDstar", 3, 3);
      TH1F *fHistNCandDs = (TH1F *)fHistNCand->ProjectionY("fHistNCandDs", 4, 4);
      TH1F *fHistNCandLc = (TH1F *)fHistNCand->ProjectionY("fHistNCandLc", 5, 5);
      
      TString names[5] = {"Dzero", "Dplus", "Dstar", "Ds", "Lc2pkpi"};
      TString type[2] = {"Prompt", "Feeddown"};
      const Int_t nDecays = 5;
      TH2F *fHistXvtxResVsPt[2 * nDecays];
      TH2F *fHistYvtxResVsPt[2 * nDecays];
      TH2F *fHistZvtxResVsPt[2 * nDecays];
      TH2F *fHistInvMassVsPt[2 * nDecays];
      TH2F *fHistDecLenVsPt[2 * nDecays];
      TH2F *fHistNormDLxyVsPt[2 * nDecays];
      TH2F *fHistCosPointVsPt[2 * nDecays];
      
      TH3F *fHistPtYMultGenDauInAcc[2 * nDecays];
      TH3F *fHistPtYMultRecoFilt[2 * nDecays];
      
      TProfile *fHistXvtxRes[2 * nDecays];
      TProfile *fHistYvtxRes[2 * nDecays];
      TProfile *fHistZvtxRes[2 * nDecays];
      TProfile *fHistXvtxMean[2 * nDecays];
      TProfile *fHistYvtxMean[2 * nDecays];
      TProfile *fHistZvtxMean[2 * nDecays];
      
      TH1F *fHistXvtxRes2[2 * nDecays];
      TH1F *fHistYvtxRes2[2 * nDecays];
      TH1F *fHistZvtxRes2[2 * nDecays];
      
      TProfile *fHistInvMass[2 * nDecays];
      TProfile *fHistDecLen[2 * nDecays];
      TProfile *fHistCosp[2 * nDecays];
      
      TH1F *fHistInvMassRes[2 * nDecays];
      
      TH1F *hEffPt[2 * nDecays];
      TH1F *htemp;
      
      for (Int_t j = 0; j < 5; j++)
	{ //decays
	  for (Int_t i = 0; i < 2; i++)
	    { //prompt and fd
	      Int_t index = j * 2 + i;
	      fHistXvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hXvtxResVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistYvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hYvtxResVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistZvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hZvtxResVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistInvMassVsPt[index] = (TH2F *)list->FindObject(Form("hInvMassVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistDecLenVsPt[index] = (TH2F *)list->FindObject(Form("hDecLenVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistCosPointVsPt[index] = (TH2F *)list->FindObject(Form("hCosPointVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistPtYMultGenDauInAcc[index] = (TH3F *)list->FindObject(Form("hPtYMult%sGenDauInAcc%s", type[i].Data(), names[j].Data()));
	      fHistPtYMultRecoFilt[index] = (TH3F *)list->FindObject(Form("hPtYMult%sRecoFilt%s", type[i].Data(), names[j].Data()));
	      
	      fHistXvtxMean[index] = (TProfile *)fHistXvtxResVsPt[index]->ProfileX(Form("hXvtxMean%s%s", type[i].Data(), names[j].Data()));
	      fHistXvtxMean[index]->SetLineColor(color[j]);
	      fHistXvtxMean[index]->SetLineWidth(2);
	      fHistXvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistXvtxMean[index]->GetYaxis()->SetTitle("Xvtx (reco-true) mean (#mum)");
	      fHistXvtxMean[index]->SetTitle("Xvtx residual vs pT");

	      fHistYvtxMean[index] = (TProfile *)fHistYvtxResVsPt[index]->ProfileX(Form("hYvtxMean%s%s", type[i].Data(), names[j].Data()));
	      fHistYvtxMean[index]->SetLineColor(color[j]);
	      fHistYvtxMean[index]->SetLineWidth(2);
	      fHistYvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistYvtxMean[index]->GetYaxis()->SetTitle("Yvtx (reco-true) mean (#mum)");
	      fHistYvtxMean[index]->SetTitle("Yvtx residual vs pT");

	      fHistZvtxMean[index] = (TProfile *)fHistZvtxResVsPt[index]->ProfileX(Form("hZvtxMean%s%s", type[i].Data(), names[j].Data()));
	      fHistZvtxMean[index]->SetLineColor(color[j]);
	      fHistZvtxMean[index]->SetLineWidth(2);
	      fHistZvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistZvtxMean[index]->GetYaxis()->SetTitle("Zvtx (reco-true) mean (#mum)");
	      fHistZvtxMean[index]->SetTitle("Zvtx residual vs pT");

	      fHistXvtxRes[index] = (TProfile *)fHistXvtxResVsPt[index]->ProfileX(Form("hXvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s");
	      fHistYvtxRes[index] = (TProfile *)fHistYvtxResVsPt[index]->ProfileX(Form("hYvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s");
	      fHistZvtxRes[index] = (TProfile *)fHistZvtxResVsPt[index]->ProfileX(Form("hZvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s");
	      fHistXvtxRes2[index] = (TH1F *)fHistXvtxResVsPt[index]->ProjectionX(Form("hXvtxRes2%s%s", type[i].Data(), names[j].Data()));
	      fHistYvtxRes2[index] = (TH1F *)fHistYvtxResVsPt[index]->ProjectionX(Form("hYvtxRes2%s%s", type[i].Data(), names[j].Data()));
	      fHistZvtxRes2[index] = (TH1F *)fHistZvtxResVsPt[index]->ProjectionX(Form("hZvtxRes2%s%s", type[i].Data(), names[j].Data()));
	      fHistXvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistXvtxRes[index]->GetYaxis()->SetTitle("Xvtx (reco-true) RMS (#mum)");
	      fHistXvtxRes[index]->SetTitle("Xvtx resolution vs pT");
	      fHistYvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistYvtxRes[index]->GetYaxis()->SetTitle("Yvtx (reco-true) RMS (#mum)");
	      fHistYvtxRes[index]->SetTitle("Yvtx resolution vs pT");
	      fHistZvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistZvtxRes[index]->GetYaxis()->SetTitle("Zvtx (reco-true) RMS (#mum)");
	      fHistZvtxRes[index]->SetTitle("Zvtx resolution vs pT");

	      fHistXvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistXvtxRes2[index]->GetYaxis()->SetTitle("Xvtx (reco-true) RMS (#mum)");
	      fHistXvtxRes2[index]->SetTitle("Xvtx resolution vs pT");
	      fHistYvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistYvtxRes2[index]->GetYaxis()->SetTitle("Yvtx (reco-true) RMS (#mum)");
	      fHistYvtxRes2[index]->SetTitle("Yvtx resolution vs pT");
	      fHistZvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistZvtxRes2[index]->GetYaxis()->SetTitle("Zvtx (reco-true) RMS (#mum)");
	      fHistZvtxRes2[index]->SetTitle("Zvtx resolution vs pT");

	      fHistXvtxRes2[index]->SetLineColor(color[j]);
	      fHistYvtxRes2[index]->SetLineColor(color[j]);
	      fHistZvtxRes2[index]->SetLineColor(color[j]);
	      fHistXvtxRes2[index]->SetMarkerColor(color[j]);
	      fHistXvtxRes2[index]->SetMarkerStyle(20);
	      fHistYvtxRes2[index]->SetMarkerColor(color[j]);
	      fHistYvtxRes2[index]->SetMarkerStyle(20);
	      fHistZvtxRes2[index]->SetMarkerColor(color[j]);
	      fHistZvtxRes2[index]->SetMarkerStyle(20);
	      fHistXvtxRes2[index]->SetLineWidth(2);
	      fHistYvtxRes2[index]->SetLineWidth(2);
	      fHistZvtxRes2[index]->SetLineWidth(2);
	      fHistXvtxRes2[index]->Sumw2();
	      fHistYvtxRes2[index]->Sumw2();
	      fHistZvtxRes2[index]->Sumw2();

	      fHistInvMass[index] = (TProfile *)fHistInvMassVsPt[index]->ProfileX(Form("hInvMassVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistInvMass[index]->SetLineColor(color[j]);
	      fHistInvMass[index]->SetLineWidth(2);
	      fHistInvMass[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistInvMass[index]->GetYaxis()->SetTitle("Inv Mass (GeV/c2)");
	      fHistInvMass[index]->SetTitle("Inv Mass vs pT");

	      fHistDecLen[index] = (TProfile *)fHistDecLenVsPt[index]->ProfileX(Form("hDecLenVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistDecLen[index]->SetLineColor(color[j]);
	      fHistDecLen[index]->SetLineWidth(2);
	      fHistDecLen[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistDecLen[index]->GetYaxis()->SetTitle("Dec Len (#mum)");
	      fHistDecLen[index]->SetTitle("Prompt Dec Len vs pT");

	      fHistCosp[index] = (TProfile *)fHistCosPointVsPt[index]->ProfileX(Form("hCosPVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistCosp[index]->SetLineColor(color[j]);
	      fHistCosp[index]->SetLineWidth(2);
	      fHistCosp[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistCosp[index]->GetYaxis()->SetTitle("Cos Point");
	      fHistCosp[index]->SetTitle("Prompt CosPoint vs pT");

	      if (index % 2 == 1)
		fHistDecLen[index]->SetTitle("FeedDown Dec Len vs pT");

	      htemp = (TH1F *)fHistPtYMultGenDauInAcc[index]->ProjectionX(Form("hPtDen%s%s", type[i].Data(), names[j].Data()));
	      hEffPt[index] = (TH1F *)fHistPtYMultRecoFilt[index]->ProjectionX(Form("hPtNum%s%s", type[i].Data(), names[j].Data()));
	      fHistPtYMultGenDauInAcc[index]->Sumw2();
	      fHistPtYMultRecoFilt[index]->Sumw2();
	      hEffPt[index]->Sumw2();
	      hEffPt[index]->Divide(htemp);
	      hEffPt[index]->SetLineColor(color[j]);
	      hEffPt[index]->SetLineWidth(2);
	      hEffPt[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      hEffPt[index]->GetYaxis()->SetTitle("Prompt Efficiency");
	      hEffPt[index]->SetTitle("Prompt Efficiency");
	      hEffPt[index]->SetStats(0);
	      fHistCosp[index]->SetStats(0);
	      fHistDecLen[index]->SetStats(0);

	      if (index % 2 == 1)
		{
		  hEffPt[index]->GetYaxis()->SetTitle("Feeddown Efficiency");
		  hEffPt[index]->SetTitle("Feeddown Efficiency");
		}

	      fHistInvMassRes[index] = new TH1F(*hEffPt[index]);
	      for (Int_t jj = 1; jj < hEffPt[index]->GetNbinsX() + 1; jj++)
		{
		  TH1F *hTemp = (TH1F *)fHistInvMassVsPt[index]->ProjectionY("htemp", jj, jj);
		  fHistInvMassRes[index]->SetBinContent(jj, hTemp->GetRMS());
		  fHistInvMassRes[index]->SetBinError(jj, hTemp->GetRMSError());
		  fHistInvMassRes[index]->SetLineColor(color[j]);
		  fHistInvMassRes[index]->SetLineWidth(2);
		  fHistInvMassRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
		  fHistInvMassRes[index]->GetYaxis()->SetTitle("Inv Mass RMS (GeV/c2)");
		  fHistInvMassRes[index]->SetTitle("Inv Mass RMS vs pT");
		  if (index == 0)
		    printf("D0: pt=%f, res=%f \n", fHistInvMassRes[index]->GetBinCenter(jj), fHistInvMassRes[index]->GetBinContent(jj));
		  TH1F *hTempX = (TH1F *)fHistXvtxResVsPt[index]->ProjectionY("htempX", jj, jj);
		  TH1F *hTempY = (TH1F *)fHistYvtxResVsPt[index]->ProjectionY("htempY", jj, jj);
		  TH1F *hTempZ = (TH1F *)fHistZvtxResVsPt[index]->ProjectionY("htempZ", jj, jj);

		  fHistXvtxRes2[index]->SetBinContent(jj, hTempX->GetRMS());
		  fHistXvtxRes2[index]->SetBinError(jj, hTempX->GetRMSError());

		  fHistYvtxRes2[index]->SetBinContent(jj, hTempY->GetRMS());
		  fHistYvtxRes2[index]->SetBinError(jj, hTempY->GetRMSError());

		  fHistZvtxRes2[index]->SetBinContent(jj, hTempZ->GetRMS());
		  fHistZvtxRes2[index]->SetBinError(jj, hTempZ->GetRMSError());
		}
	    }
	}

      fHistNCandDplus->SetLineColor(2);
      fHistNCandDstar->SetLineColor(3);
      fHistNCandDs->SetLineColor(4);
      fHistNCandLc->SetLineColor(kOrange);
      fHistNCandDplus->SetLineWidth(2);
      fHistNCandDstar->SetLineWidth(2);
      fHistNCandDs->SetLineWidth(2);
      fHistNCandLc->SetLineWidth(2);

      fHistNCandDzero->GetXaxis()->SetTitle("pT (GeV/c)");
      fHistNCandDzero->GetYaxis()->SetTitle("counts");
      TLegend *leg = new TLegend(0.6, 0.7, 0.8, 0.9);
      leg->AddEntry(fHistNCandDzero, "Dzero", "l");
      leg->AddEntry(fHistNCandDplus, "Dplus", "l");
      leg->AddEntry(fHistNCandDstar, "Dstar", "l");
      leg->AddEntry(fHistNCandDs, "Ds", "l");
      leg->AddEntry(fHistNCandLc, "Lc", "l");

      TLegend *leg1 = new TLegend(0.5, 0.7, 0.7, 0.9);
      leg1->AddEntry(fHistYvtxRes2[0], "Dzero", "pl");
      leg1->AddEntry(fHistYvtxRes2[2], "Dplus", "pl");
      if (drawOnlyDzerDplus == 0)
	leg1->AddEntry(fHistYvtxRes2[6], "Ds", "pl");
      if (drawOnlyDzerDplus == 0)
	leg1->AddEntry(fHistYvtxRes2[8], "Lc", "pl");

      TLegend *leg2 = new TLegend(0.5, 0.7, 0.7, 0.9);
      leg2->AddEntry(fHistYvtxMean[0], "Dzero", "l");
      leg2->AddEntry(fHistYvtxMean[2], "Dplus", "l");
      if (drawOnlyDzerDplus == 0)
	leg2->AddEntry(fHistYvtxMean[6], "Ds", "l");
      if (drawOnlyDzerDplus == 0)
	leg2->AddEntry(fHistYvtxMean[8], "Lc", "l");

      TLegend *leg3 = new TLegend(0.2, 0.7, 0.4, 0.9);
      leg3->AddEntry(fHistNCandDzero, "Dzero", "l");
      leg3->AddEntry(fHistNCandDplus, "Dplus", "l");
      if (drawOnlyDzerDplus == 0)
	leg3->AddEntry(fHistNCandDstar, "Dstar", "l");
      if (drawOnlyDzerDplus == 0)
	leg3->AddEntry(fHistNCandDs, "Ds", "l");
      if (drawOnlyDzerDplus == 0)
	leg3->AddEntry(fHistNCandLc, "Lc", "l");

      TLegend *leg4 = new TLegend(0.7, 0.7, 0.9, 0.9);
      leg4->AddEntry(fHistNCandDzero, "Dzero", "l");
      leg4->AddEntry(fHistNCandDplus, "Dplus", "l");
      if (drawOnlyDzerDplus == 0)
	leg4->AddEntry(fHistNCandDstar, "Dstar", "l");
      if (drawOnlyDzerDplus == 0)
	leg4->AddEntry(fHistNCandDs, "Ds", "l");
      if (drawOnlyDzerDplus == 0)
	leg4->AddEntry(fHistNCandLc, "Lc", "l");

      TCanvas *c0_1 = new TCanvas("c0_1", "c0_1", 500, 500);
      hnGenD->SetTitle("number of generated D mesons");
      hnGenD->Draw();
      c0_1->SaveAs("plotDgen.png");

      TCanvas *c0_2 = new TCanvas("c0_2", "c0_2", 500, 500);
      c0_2->SetLogy();

      fHistNCandDs->SetTitle("Candidates passing filtering cuts");
      fHistNCandDs->Draw("");
      c0_2->Update();
      TPaveStats *stats = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats->SetName("h1stats");
      stats->SetY1NDC(0.5);
      stats->SetY2NDC(0.35);
      c0_2->Update();

      fHistNCandDplus->Draw("sames");
      c0_2->Update();
      TPaveStats *stats2 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats2->SetName("h2stats");
      stats2->SetY1NDC(0.8);
      stats2->SetY2NDC(.65);
      c0_2->Update();

      fHistNCandDstar->Draw("sames");
      c0_2->Update();
      TPaveStats *stats3 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats3->SetName("h3stats");
      stats3->SetY1NDC(0.65);
      stats3->SetY2NDC(.5);
      c0_2->Update();

      fHistNCandDzero->Draw("sames");
      c0_2->Update();
      TPaveStats *stats4 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats4->SetName("h4stats");
      stats4->SetY1NDC(0.95);
      stats4->SetY2NDC(.8);
      c0_2->Update();

      fHistNCandLc->Draw("sames");
      c0_2->Update();
      TPaveStats *stats5 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats5->SetName("h1stats");
      stats5->SetY1NDC(0.35);
      stats5->SetY2NDC(.2);
      c0_2->Update();
      leg->Draw();
      c0_2->SaveAs("plotDcandpt.png");

      TCanvas *c0_3 = new TCanvas("c0_3", "c0_3", 500, 500);
      fHistInvMass[0]->SetMinimum(1.6);
      fHistInvMass[0]->SetMaximum(2.4);
      fHistInvMass[0]->Draw();
      fHistInvMass[2]->Draw("sames");
      fHistInvMass[4]->Draw("sames");
      fHistInvMass[6]->Draw("sames");
      fHistInvMass[8]->Draw("sames");
      leg->Draw();
      c0_3->SaveAs("plotDcandInvMass.png");

      TCanvas *c0_4 = new TCanvas("c0_4", "c0_4", 500, 500);
      //fHistInvMassRes[0]->SetMinimum(1.6);
      //fHistInvMassRes[0]->SetMaximum(2.4);

      fHistInvMassRes[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistInvMassRes[0]->SetTitle("D0 Inv Mass RMS vs pT");
      fHistInvMassRes[0]->Draw("");
      //  fHistInvMassRes[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistInvMassRes[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistInvMassRes[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistInvMassRes[8]->Draw("sames");
      //leg->Draw();
      c0_4->SaveAs("plotD0candInvMassWidth.png");

      fHistXvtxMean[0]->SetStats(0);
      fHistYvtxMean[0]->SetStats(0);
      fHistZvtxMean[0]->SetStats(0);
      fHistXvtxMean[2]->SetStats(0);
      fHistYvtxMean[2]->SetStats(0);
      fHistZvtxMean[2]->SetStats(0);
      fHistXvtxRes2[0]->SetStats(0);
      fHistYvtxRes2[0]->SetStats(0);
      fHistZvtxRes2[0]->SetStats(0);
      fHistXvtxRes2[2]->SetStats(0);
      fHistYvtxRes2[2]->SetStats(0);
      fHistZvtxRes2[2]->SetStats(0);

      TCanvas *cc = new TCanvas("cc", "cc", 1200, 500);
      cc->Divide(3, 1);
      cc->cd(1);
      fHistXvtxMean[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistXvtxMean[0]->SetMinimum(-300.);
      fHistXvtxMean[0]->SetMaximum(300.);
      fHistXvtxMean[0]->Draw();

      fHistXvtxMean[2]->Draw("sames");
      leg2->Draw();

      cc->cd(2);

      fHistYvtxMean[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistYvtxMean[0]->SetMinimum(-300.);
      fHistYvtxMean[0]->SetMaximum(300.);
      fHistYvtxMean[0]->Draw();
      fHistYvtxMean[2]->Draw("sames");
      leg2->Draw();

      cc->cd(3);
      fHistZvtxMean[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistZvtxMean[0]->SetMinimum(-300.);
      fHistZvtxMean[0]->SetMaximum(300.);
      fHistZvtxMean[0]->Draw();
      fHistZvtxMean[2]->Draw("sames");
      leg2->Draw();
      cc->SaveAs("plotXYZVtxMean.png");
      /////////

      TCanvas *ccr = new TCanvas("ccr", "ccr", 1200, 500);
      ccr->Divide(3, 1);
      ccr->cd(1);
      fHistXvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistXvtxRes2[0]->SetMinimum(0.);
      fHistXvtxRes2[0]->SetMaximum(500.);
      fHistXvtxRes2[0]->Draw();
      fHistXvtxRes2[2]->Draw("sames");
      leg2->Draw();

      ccr->cd(2);
      fHistYvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistYvtxRes2[0]->SetMinimum(0.);
      fHistYvtxRes2[0]->SetMaximum(500.);
      fHistYvtxRes2[0]->Draw();
      fHistYvtxRes2[2]->Draw("sames");
      leg2->Draw();

      ccr->cd(3);
      fHistZvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistZvtxRes2[0]->SetMinimum(0.);
      fHistZvtxRes2[0]->SetMaximum(500.);
      fHistZvtxRes2[0]->Draw();
      fHistZvtxRes2[2]->Draw("sames");
      leg2->Draw();
      ccr->SaveAs("plotXYZVtxRMS.png");

      TCanvas *ccc = new TCanvas("ccc", "ccc", 1200, 800);
      ccc->Divide(3, 2);
      ccc->cd(1);
      fHistDecLen[0]->GetYaxis()->SetTitleOffset(1.45);
      fHistDecLen[0]->Draw();
      fHistDecLen[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[8]->Draw("sames");
      leg3->Draw();

      ccc->cd(2);
      fHistCosp[0]->GetYaxis()->SetTitleOffset(1.45);
      fHistCosp[0]->Draw();
      fHistCosp[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[8]->Draw("sames");
      leg4->Draw();

      ccc->cd(3);
      hEffPt[0]->GetYaxis()->SetTitleOffset(1.45);
      hEffPt[0]->Draw();
      hEffPt[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[8]->Draw("sames");
      leg3->Draw();

      ccc->cd(4);
      fHistDecLen[1]->GetYaxis()->SetTitleOffset(1.45);
      fHistDecLen[1]->Draw();
      fHistDecLen[3]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[5]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[7]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[9]->Draw("sames");
      leg3->Draw();

      ccc->cd(5);
      fHistCosp[1]->GetYaxis()->SetTitleOffset(1.45);
      fHistCosp[1]->Draw();
      fHistCosp[3]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[5]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[7]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[9]->Draw("sames");
      leg4->Draw();

      ccc->cd(6);
      hEffPt[1]->GetYaxis()->SetTitleOffset(1.45);
      hEffPt[1]->Draw();
      hEffPt[3]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[5]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[7]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[9]->Draw("sames");
      leg3->Draw();

      ccc->SaveAs("plot_DL_cosp_Eff_prompt_fd.png");
    }
  }

  trtree->Fill();

  if(runNumber>0){
    TFile* foutfile=new TFile("trendingHF.root","recreate");
    trtree->Write();
    TDirectory* outdir=foutfile->mkdir(dirD2H->GetName());
    outdir->cd();
    listD2H->Write(listD2H->GetName(),1);
    foutfile->cd();
    if(dir && list){
      TDirectory* outdir2=foutfile->mkdir(dir->GetName());
      outdir2->cd();
      list->Write(list->GetName(),1);
    }
    foutfile->Close();
    delete foutfile;
  }
}
예제 #16
0
//______________________________________________________________________________
void processJpsi2eeQAplots(const Char_t* filename="jpsi_Default.root", 
			   TString suffix = "eps",
			   const Char_t* outfile="Jpsi2eeQAplots_output.root") {
  //
 
  //  
  TFile* file = TFile::Open(filename);
  
  // event wise histograms 
  TH1F* zDistrib = (TH1F*)GetHistogram(file, "default", "Event", "Z");
  
  // electron candidate histograms
  TH2F* tpcDedx = (TH2F*)GetHistogram(file, "default", "Track_ev1+", "P_InnerParam_TPC_signal");
  tpcDedx->Add((TH2F*)GetHistogram(file, "default", "Track_ev1-", "P_InnerParam_TPC_signal"));
  TH2F* tpcNsigmaEle = (TH2F*)GetHistogram(file, "default", "Track_ev1+", "P_InnerParam_TPC_nSigma_Electrons");
  tpcNsigmaEle->Add((TH2F*)GetHistogram(file, "default", "Track_ev1-", "P_InnerParam_TPC_nSigma_Electrons"));
  
  // pair candidate histograms
  TH1F* invmass_pp = (TH1F*)GetHistogram(file, "default", "Pair_ev1+_ev1+", "pM");
  TH1F* invmass_pm = (TH1F*)GetHistogram(file, "default", "Pair_ev1+_ev1-", "pM");
  TH1F* invmass_mm = (TH1F*)GetHistogram(file, "default", "Pair_ev1-_ev1-", "pM");
    
  // draw stuff
  TLatex* latex=new TLatex();
  latex->SetNDC();
  latex->SetTextSize(0.04);
  latex->SetTextFont(42);
  TCanvas* c1=new TCanvas("fig_dq_tpcDedx", "");
  if(tpcDedx) {
    tpcDedx->SetStats(kFALSE);
    tpcDedx->GetXaxis()->SetRangeUser(0.0,10.0);
    tpcDedx->GetYaxis()->SetRangeUser(40.0,120.0);
    tpcDedx->SetTitle("");
    tpcDedx->Draw("colz");
    latex->DrawLatex(0.12, 0.83, "J/#psi electron candidates");
  }
  
  TCanvas* c2=new TCanvas("fig_dq_tpcNsigmaElectron", "");
  if(tpcNsigmaEle) {
    tpcNsigmaEle->SetStats(kFALSE);
    tpcNsigmaEle->GetYaxis()->SetRangeUser(-5.0,5.0);
    tpcNsigmaEle->GetXaxis()->SetRangeUser(0.0,10.0);
    tpcNsigmaEle->SetTitle("");
    tpcNsigmaEle->Draw("colz");
    latex->DrawLatex(0.12, 0.83, "J/#psi electron candidates");
  }
  
  TCanvas* c3=new TCanvas("fig_dq_eeInvMass", "");
  if(invmass_pm) {
    invmass_pm->SetStats(kFALSE);
    invmass_pm->SetTitle("");
    invmass_pm->SetLineColor(1);
    invmass_pm->GetYaxis()->SetTitle(Form("Pairs per %.0f MeV/c^{2}", 1000.0*invmass_pm->GetXaxis()->GetBinWidth(1)));
    invmass_pm->GetXaxis()->SetTitle("m_{e^{+}e^{-}} (GeV/c^{2})");
    invmass_pm->Draw();
  }
  if(invmass_pp) {
    invmass_pp->SetLineColor(2);
    invmass_pp->Draw((invmass_pm ? "same" : ""));
  }
  if(invmass_mm) {
    invmass_mm->SetLineColor(4);
    invmass_mm->Draw((invmass_mm ? "same" : ""));
  }
  if(invmass_pm || invmass_mm || invmass_pp)
    latex->DrawLatex(0.12, 0.85, "J/#psi candidates");
  if(invmass_pm && zDistrib && zDistrib->Integral()>1.);
    latex->DrawLatex(0.12, 0.80, Form("candidates / event = %.3f", invmass_pm->Integral() / zDistrib->Integral()));
  TLegend* legend=new TLegend(0.7,0.7,0.89,0.89);
  legend->SetTextFont(42);
  legend->SetBorderSize(0);
  legend->SetFillColor(0);
  if(invmass_pm) legend->AddEntry(invmass_pm, "+- pairs", "l");
  if(invmass_pp) legend->AddEntry(invmass_pp, "++ pairs", "l");
  if(invmass_mm) legend->AddEntry(invmass_mm, "-- pairs", "l");
  if(invmass_mm || invmass_pm || invmass_pp) legend->Draw();
  
  c1->SaveAs(Form("fig_dq_tpcDedx.%s",suffix.Data()));
  c2->SaveAs(Form("fig_dq_tpcNsigmaElectron.%s",suffix.Data()));
  c3->SaveAs(Form("fig_dq_eeInvMass.%s",suffix.Data()));


  //  TFile* save=new TFile(outputName, "RECREATE");
  // c1->Write();
  // c2->Write();
  // c3->Write();
  // save->Close();


  // Added by jsatya

  TFile *fout = TFile::Open(outfile,"UPDATE");
  fout->ls();
  
  TDirectoryFile *cdd = NULL;
  cdd = (TDirectoryFile*)fout->Get("DQ");
  if(!cdd) {
    Printf("Warning: DQ <dir> doesn't exist, creating a new one");
    cdd = (TDirectoryFile*)fout->mkdir("DQ");
  }
  cdd->cd();
  cdd->ls();



  if (invmass_pp){
    invmass_pp->SetName(Form("fig_dq_%s_pp", invmass_pp->GetName()));
    invmass_pp->Write();
  }
  
  if (invmass_pm){
    invmass_pm->SetName(Form("fig_dq_%s_pm", invmass_pm->GetName()));
    invmass_pm->Write();
  }
  if (invmass_mm){
    invmass_mm->SetName(Form("fig_dq_%s_mm", invmass_mm->GetName()));
    invmass_mm->Write();
  }
  
  tpcNsigmaEle->SetName(Form("fig_dq_%s", tpcNsigmaEle->GetName()));
  tpcNsigmaEle->Write();
  
  tpcDedx->SetName(Form("fig_dq_%s", tpcDedx->GetName()));
  tpcDedx->Write();
  
  fout->cd();
  fout->Close();
  
}
예제 #17
0
void stack_in_cone_contribs(const string& fFile, const double fYmax, const string& fTitleExt, const string& fNameExt) {

   string title = "<E> in R_{cone}=0.5 -- "+ fTitleExt +";#eta;<E> [GeV]";
   
   TFile file(fFile.c_str());
   TDirectoryFile *subDir = (TDirectoryFile*)file.Get("offsetAnalysis");
   
   TProfile *p_AEC5EB  = (TProfile*)subDir->Get("p_AvgEinC5EB");
   TProfile *p_AEC5EE  = (TProfile*)subDir->Get("p_AvgEinC5EE");
   TProfile *p_AEC5HB  = (TProfile*)subDir->Get("p_AvgEinC5HB");
   TProfile *p_AEC5HE  = (TProfile*)subDir->Get("p_AvgEinC5HE");
   TProfile *p_AEC5HFl = (TProfile*)subDir->Get("p_AvgEinC5HFl");
   TProfile *p_AEC5HFs = (TProfile*)subDir->Get("p_AvgEinC5HFs");
//    TProfile *p_AEC5HO  = (TProfile*)subDir->Get("p_AvgEinC5HO");
   
   TH1D *h_AEC5EB  = p_AEC5EB->ProjectionX();
   TH1D *h_AEC5EE  = p_AEC5EE->ProjectionX();
   TH1D *h_AEC5HB  = p_AEC5HB->ProjectionX();
   TH1D *h_AEC5HE  = p_AEC5HE->ProjectionX();
   TH1D *h_AEC5HFl = p_AEC5HFl->ProjectionX();
   TH1D *h_AEC5HFs = p_AEC5HFs->ProjectionX();
   //TH1D *h_AEC5HO  = p_AEC5HO->ProjectionX();
   
   h_AEC5EB->SetFillColor(50);
   h_AEC5EE->SetFillColor(8);
   h_AEC5HB->SetFillColor(4);
   h_AEC5HE->SetFillColor(6);
   h_AEC5HFl->SetFillColor(16);
   h_AEC5HFs->SetFillColor(12);
   //h_AEC5HO->SetFillColor(7);
   
//    TCanvas *c = new TCanvas("c", "",1120,800);
   TCanvas *c = new TCanvas("c", "",800,800);
   c->cd();
   
   TH2F *h_bg = new TH2F("h_bg",title.c_str(),100,-5.,5.,100,0.,fYmax);
   h_bg->GetXaxis()->SetTitleSize(0.05);
   h_bg->GetYaxis()->SetTitleSize(0.05);
   h_bg->SetTitleOffset(1.,"X");
   h_bg->SetTitleOffset(1.3,"Y");
   h_bg->Draw();
   
   THStack *hs = new THStack("hs","");
   
   hs->Add(h_AEC5EB);
   hs->Add(h_AEC5EE);
   hs->Add(h_AEC5HB);
   hs->Add(h_AEC5HE);
   hs->Add(h_AEC5HFl);
   hs->Add(h_AEC5HFs);
   //hs->Add(h_AEC5HO);
   hs->Draw("histsame");
   
   TLegend *legend = new TLegend(.65,.6,.75,.85);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
//    legend->SetFillStyle(0);
//    legend->SetTextFont(42);
   legend->AddEntry(h_AEC5EB,"EB","f");
   legend->AddEntry(h_AEC5HB,"HB","f");
   legend->AddEntry(h_AEC5EE,"EE","f");
   legend->AddEntry(h_AEC5HE,"HE","f");
   legend->AddEntry(h_AEC5HFl,"HFl","f");
   legend->AddEntry(h_AEC5HFs,"HFs","f");
   //legend->AddEntry(h_AEC5HO,"HO","f");
   legend->Draw();
   
   string fileName = "h_AvgEinC5_stacked_" + fNameExt;
   
   c->SetGridy();
   gPad->Modified();
   gPad->Update();
   c->SaveAs(fileName.c_str());

   delete legend;
   delete hs;
   delete c;
}
예제 #18
0
파일: Slimmer.C 프로젝트: RohanBhandari/MJ
void Slimmer(TString InputCfAName, TString output_filename)
{
    
  TChain * chainA = new TChain("/configurableAnalysis/eventA");   
  TChain * chainB = new TChain("/configurableAnalysis/eventB");    
  chainA->Add(InputCfAName);
  chainB->Add(InputCfAName);

  InitializeA(chainA);
  InitializeB(chainB);
  
  chainA->SetBranchStatus("*",0);
  chainB->SetBranchStatus("*",0);

  chainA->SetBranchStatus("els_conversion_dist",1);
  chainA->SetBranchStatus("els_conversion_dcot",1);
  chainA->SetBranchStatus("PU_TrueNumInteractions",1);
  chainA->SetBranchStatus("rho_kt6PFJetsForIsolation2011",1);
  chainA->SetBranchStatus("els_PFphotonIsoR03",1);
  chainA->SetBranchStatus("els_PFneutralHadronIsoR03",1);
  chainA->SetBranchStatus("els_PFchargedHadronIsoR03",1);
  chainA->SetBranchStatus("els_hasMatchedConversion",1);

  chainB->SetBranchStatus("mus_charge",1);
  chainB->SetBranchStatus("mus_pt",1);
  chainB->SetBranchStatus("mus_eta",1);
  chainB->SetBranchStatus("mus_et",1);
  chainB->SetBranchStatus("mus_phi",1);
  chainB->SetBranchStatus("mus_px",1);
  chainB->SetBranchStatus("mus_py",1);
  chainB->SetBranchStatus("mus_pz",1);
  chainB->SetBranchStatus("mus_tk_chi2",1);
  chainB->SetBranchStatus("mus_tk_ndof",1);
  chainB->SetBranchStatus("mus_tk_numvalhits",1);
  chainB->SetBranchStatus("mus_tk_numvalPixelhits",1);
  chainB->SetBranchStatus("mus_tk_px",1);
  chainB->SetBranchStatus("mus_tk_py",1);
  chainB->SetBranchStatus("mus_tk_pz",1);
  chainB->SetBranchStatus("mus_tk_pt",1);
  chainB->SetBranchStatus("mus_tk_ptErr",1);
  chainB->SetBranchStatus("mus_tk_numpixelWthMeasr",1);
  chainB->SetBranchStatus("mus_tk_vx",1);
  chainB->SetBranchStatus("mus_tk_vy",1);
  chainB->SetBranchStatus("mus_tk_vz",1);
  chainB->SetBranchStatus("mus_tk_d0dum",1);
  chainB->SetBranchStatus("mus_tk_phi",1);
  chainB->SetBranchStatus("mus_cm_pt",1);
  chainB->SetBranchStatus("mus_cm_ptErr",1);
  chainB->SetBranchStatus("mus_cm_chi2",1);
  chainB->SetBranchStatus("mus_cm_ndof",1);
  chainB->SetBranchStatus("mus_stamu_pt",1);
  chainB->SetBranchStatus("mus_stamu_ptErr",1);
  chainB->SetBranchStatus("mus_tIso",1);
  chainB->SetBranchStatus("mus_cIso",1);
  chainB->SetBranchStatus("mus_energy",1);
  chainB->SetBranchStatus("mus_ecalIso",1);
  chainB->SetBranchStatus("mus_hcalIso",1);
  chainB->SetBranchStatus("mus_ecalvetoDep",1);
  chainB->SetBranchStatus("mus_hcalvetoDep",1);
  chainB->SetBranchStatus("mus_id_GlobalMuonPromptTight",1);
  chainB->SetBranchStatus("mus_id_AllTrackerMuons",1);
  chainB->SetBranchStatus("mus_id_AllGlobalMuons",1);
  chainB->SetBranchStatus("mus_isTrackerMuon",1);
  chainB->SetBranchStatus("mus_isGlobalMuon",1);
  chainB->SetBranchStatus("mus_num_matches",1);
  chainB->SetBranchStatus("mus_isPFMuon",1);
  chainB->SetBranchStatus("mus_numberOfMatchedStations",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumChargedHadronPt",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumChargedParticlePt",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumNeutralHadronEt",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumNeutralHadronEtHighThreshold",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumPhotonEt",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumPhotonEtHighThreshold",1);
  chainB->SetBranchStatus("mus_pfIsolationR03_sumPUPt",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumChargedHadronPt",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumChargedParticlePt",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumNeutralHadronEt",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumNeutralHadronEtHighThreshold",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumPhotonEt",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumPhotonEtHighThreshold",1);
  chainB->SetBranchStatus("mus_pfIsolationR04_sumPUPt",1);
  chainB->SetBranchStatus("mus_dB",1);

  chainB->SetBranchStatus("pfcand_pdgId",1);
  chainB->SetBranchStatus("pfcand_particleId",1);
  chainB->SetBranchStatus("pfcand_pt",1);
  chainB->SetBranchStatus("pfcand_pz",1);
  chainB->SetBranchStatus("pfcand_px",1);
  chainB->SetBranchStatus("pfcand_py",1);
  chainB->SetBranchStatus("pfcand_eta",1);
  chainB->SetBranchStatus("pfcand_phi",1);
  chainB->SetBranchStatus("pfcand_theta",1);
  chainB->SetBranchStatus("pfcand_energy",1);
  chainB->SetBranchStatus("pfcand_charge",1);

  chainB->SetBranchStatus("pf_mus_pt",1);
  chainB->SetBranchStatus("pf_mus_eta",1);
  chainB->SetBranchStatus("pf_mus_et",1);
  chainB->SetBranchStatus("pf_mus_tk_chi2",1);
  chainB->SetBranchStatus("pf_mus_tk_ndof",1);
  chainB->SetBranchStatus("pf_mus_tk_numvalhits",1);
  chainB->SetBranchStatus("pf_mus_tk_numvalPixelhits",1);
  chainB->SetBranchStatus("pf_mus_tk_pt",1);
  chainB->SetBranchStatus("pf_mus_tk_ptErr",1);
  chainB->SetBranchStatus("pf_mus_cm_pt",1);
  chainB->SetBranchStatus("pf_mus_cm_ptErr",1);
  chainB->SetBranchStatus("pf_mus_cm_chi2",1);
  chainB->SetBranchStatus("pf_mus_cm_ndof",1);
  chainB->SetBranchStatus("pf_mus_stamu_pt",1);
  chainB->SetBranchStatus("pf_mus_stamu_ptErr",1);
  chainB->SetBranchStatus("pf_mus_tIso",1);
  chainB->SetBranchStatus("pf_mus_cIso",1);
  chainB->SetBranchStatus("pf_mus_energy",1);
  chainB->SetBranchStatus("pf_mus_ecalIso",1);
  chainB->SetBranchStatus("pf_mus_hcalIso",1);
  chainB->SetBranchStatus("pf_mus_tk_d0dum",1);
  chainB->SetBranchStatus("pf_mus_tk_phi",1);
  chainB->SetBranchStatus("pf_mus_phi",1);
  chainB->SetBranchStatus("pf_mus_px",1);
  chainB->SetBranchStatus("pf_mus_py",1);
  chainB->SetBranchStatus("pf_mus_pz",1);
  chainB->SetBranchStatus("pf_mus_id_GlobalMuonPromptTight",1);
  chainB->SetBranchStatus("pf_mus_charge",1);
  chainB->SetBranchStatus("pf_mus_num_matches",1);
  chainB->SetBranchStatus("pf_mus_tk_numpixelWthMeasr",1);
  chainB->SetBranchStatus("pf_mus_tk_vz",1);
  chainB->SetBranchStatus("mus_tk_LayersWithMeasurement",1);
  chainB->SetBranchStatus("pf_mus_isTrackerMuon",1);
  chainB->SetBranchStatus("pf_mus_isGlobalMuon",1);
  chainB->SetBranchStatus("pf_mus_chargedHadronIso",1);
  chainB->SetBranchStatus("pf_mus_neutralHadronIso",1);
  chainB->SetBranchStatus("pf_mus_photonIso",1);

  chainB->SetBranchStatus("els_pt",1);
  chainB->SetBranchStatus("els_ptError",1);
  chainB->SetBranchStatus("els_n_inner_layer");
  chainB->SetBranchStatus("els_px",1);
  chainB->SetBranchStatus("els_py",1);
  chainB->SetBranchStatus("els_pz",1);
  chainB->SetBranchStatus("els_et",1);
  chainB->SetBranchStatus("els_eta",1);
  chainB->SetBranchStatus("els_phi",1);
  chainB->SetBranchStatus("els_charge",1);
  chainB->SetBranchStatus("els_isEB",1);
  chainB->SetBranchStatus("els_isEE",1);
  chainB->SetBranchStatus("els_simpleEleId70relIso",1);
  chainB->SetBranchStatus("els_simpleEleId70cIso",1);
  chainB->SetBranchStatus("els_simpleEleId80cIso",1);
  chainB->SetBranchStatus("els_simpleEleId80relIso",1);
  chainB->SetBranchStatus("els_simpleEleId85cIso",1);
  chainB->SetBranchStatus("els_simpleEleId85relIso",1);
  chainB->SetBranchStatus("els_simpleEleId90cIso",1);
  chainB->SetBranchStatus("els_simpleEleId90relIso",1);
  chainB->SetBranchStatus("els_simpleEleId95cIso",1);
  chainB->SetBranchStatus("els_simpleEleId95relIso",1);
  chainB->SetBranchStatus("els_tIso",1);
  chainB->SetBranchStatus("els_cIso",1);
  chainB->SetBranchStatus("els_hcalIso",1);
  chainB->SetBranchStatus("els_ecalIso",1);
  chainB->SetBranchStatus("els_d0dum",1);
  chainB->SetBranchStatus("els_tk_phi",1);
  chainB->SetBranchStatus("els_tk_pt",1);
  chainB->SetBranchStatus("els_tk_pz",1);
  chainB->SetBranchStatus("els_robustTightId",1);
  chainB->SetBranchStatus("els_dr03EcalRecHitSumEt",1);
  chainB->SetBranchStatus("els_dr03TkSumPt",1);
  chainB->SetBranchStatus("els_dr03HcalTowerSumEt",1);
  chainB->SetBranchStatus("els_sigmaIEtaIEta",1);
  chainB->SetBranchStatus("els_dPhiIn",1);
  chainB->SetBranchStatus("els_dEtaIn",1);
  chainB->SetBranchStatus("els_dPhiOut",1);
  chainB->SetBranchStatus("els_dEtaOut",1);
  chainB->SetBranchStatus("els_scEta",1);
  chainB->SetBranchStatus("els_hadOverEm",1);
  chainB->SetBranchStatus("els_isEB",1);
  chainB->SetBranchStatus("els_isEE",1);
  chainB->SetBranchStatus("els_energy",1);
  chainB->SetBranchStatus("els_scEnergy",1);
  chainB->SetBranchStatus("els_scE2x5Max",1);
  chainB->SetBranchStatus("els_scE5x5",1);
  chainB->SetBranchStatus("els_scE1x5",1);
  chainB->SetBranchStatus("els_dr03HcalDepth1TowerSumEt",1);
  chainB->SetBranchStatus("els_dr03HcalDepth2TowerSumEt",1);
  chainB->SetBranchStatus("els_eOverPIn",1);
  chainB->SetBranchStatus("els_numlosthits",1);
  chainB->SetBranchStatus("els_vx",1);
  chainB->SetBranchStatus("els_vy",1);
  chainB->SetBranchStatus("els_vz",1);
  chainB->SetBranchStatus("els_caloEnergy",1);

  chainB->SetBranchStatus("pf_els_pt",1);
  chainB->SetBranchStatus("pf_els_ptError",1);
  chainB->SetBranchStatus("pf_els_n_inner_layer");
  chainB->SetBranchStatus("pf_els_px",1);
  chainB->SetBranchStatus("pf_els_py",1);
  chainB->SetBranchStatus("pf_els_pz",1);
  chainB->SetBranchStatus("pf_els_et",1);
  chainB->SetBranchStatus("pf_els_eta",1);
  chainB->SetBranchStatus("pf_els_phi",1);
  chainB->SetBranchStatus("pf_els_charge",1);
  chainB->SetBranchStatus("pf_els_isEB",1);
  chainB->SetBranchStatus("pf_els_isEE",1);
  chainB->SetBranchStatus("pf_els_simpleEleId70relIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId70cIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId80cIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId80relIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId85cIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId85relIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId90cIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId90relIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId95cIso",1);
  chainB->SetBranchStatus("pf_els_simpleEleId95relIso",1);
  chainB->SetBranchStatus("pf_els_tIso",1);
  chainB->SetBranchStatus("pf_els_cIso",1);
  chainB->SetBranchStatus("pf_els_hcalIso",1);
  chainB->SetBranchStatus("pf_els_ecalIso",1);
  chainB->SetBranchStatus("pf_els_d0dum",1);
  chainB->SetBranchStatus("pf_els_tk_phi",1);
  chainB->SetBranchStatus("pf_els_robustTightId",1);
  chainB->SetBranchStatus("pf_els_dr03EcalRecHitSumEt",1);
  chainB->SetBranchStatus("pf_els_dr03TkSumPt",1);
  chainB->SetBranchStatus("pf_els_dr03HcalTowerSumEt",1);
  chainB->SetBranchStatus("pf_els_sigmaIEtaIEta",1);
  chainB->SetBranchStatus("pf_els_dPhiIn",1);
  chainB->SetBranchStatus("pf_els_dEtaIn",1);
  chainB->SetBranchStatus("pf_els_dPhiOut",1);
  chainB->SetBranchStatus("pf_els_dEtaOut",1);
  chainB->SetBranchStatus("pf_els_scEta",1);
  chainB->SetBranchStatus("pf_els_hadOverEm",1);
  chainB->SetBranchStatus("pf_els_isEB",1);
  chainB->SetBranchStatus("pf_els_isEE",1);
  chainB->SetBranchStatus("pf_els_energy",1);
  chainB->SetBranchStatus("pf_els_scEnergy",1);
  chainB->SetBranchStatus("pf_els_scE2x5Max",1);
  chainB->SetBranchStatus("pf_els_scE5x5",1);
  chainB->SetBranchStatus("pf_els_scE1x5",1);
  chainB->SetBranchStatus("pf_els_dr03HcalDepth1TowerSumEt",1);
  chainB->SetBranchStatus("pf_els_dr03HcalDepth2TowerSumEt",1);
  chainB->SetBranchStatus("pf_els_eOverPIn",1);
  chainB->SetBranchStatus("pf_els_numlosthits",1);
  chainB->SetBranchStatus("pf_els_vx",1);
  chainB->SetBranchStatus("pf_els_vy",1);
  chainB->SetBranchStatus("pf_els_vz",1);
  chainB->SetBranchStatus("pf_els_chargedHadronIso",1);
  chainB->SetBranchStatus("pf_els_neutralHadronIso",1);
  chainB->SetBranchStatus("pf_els_photonIso",1);

  chainB->SetBranchStatus("jets_AK5PFclean_rawPt",1);
  chainB->SetBranchStatus("jets_AK5PFclean_et",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_TC_highPur",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_TC_highEff",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_secVertexHighPur",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_secVertexHighEff",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_secVertexCombined",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_jetProb",1);
  chainB->SetBranchStatus("jets_AK5PFclean_btag_jetBProb",1);
  chainB->SetBranchStatus("jets_AK5PFclean_jetCharge",1);
  chainB->SetBranchStatus("jets_AK5PFclean_partonFlavour",1);
  chainB->SetBranchStatus("jets_AK5PFclean_parton_Id",1);
  chainB->SetBranchStatus("jets_AK5PFclean_parton_motherId",1);
  chainB->SetBranchStatus("jets_AK5PFclean_energy",1);
  chainB->SetBranchStatus("jets_AK5PFclean_pt",1);
  chainB->SetBranchStatus("jets_AK5PFclean_px",1);
  chainB->SetBranchStatus("jets_AK5PFclean_py",1);
  chainB->SetBranchStatus("jets_AK5PFclean_gen_pt",1);
  chainB->SetBranchStatus("jets_AK5PFclean_gen_phi",1);
  chainB->SetBranchStatus("jets_AK5PFclean_pz",1);
  chainB->SetBranchStatus("jets_AK5PFclean_eta",1);
  chainB->SetBranchStatus("jets_AK5PFclean_ehf",1);
  chainB->SetBranchStatus("jets_AK5PFclean_phi",1);
  chainB->SetBranchStatus("jets_AK5PFclean_neutralEmE",1);
  chainB->SetBranchStatus("jets_AK5PFclean_chgEmE",1);
  chainB->SetBranchStatus("jets_AK5PFclean_neutralHadE",1);
  chainB->SetBranchStatus("jets_AK5PFclean_chgHadE",1);
  chainB->SetBranchStatus("jets_AK5PFclean_mu_Mult",1);
  chainB->SetBranchStatus("jets_AK5PFclean_neutral_Mult",1);
  chainB->SetBranchStatus("jets_AK5PFclean_chg_Mult",1);
  chainB->SetBranchStatus("jets_AK5PFclean_corrFactorRaw",1);
  chainB->SetBranchStatus("jets_AK5PFclean_photonEnergy",1);

  chainB->SetBranchStatus("jets_AK5PF_et",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_TC_highPur",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_TC_highEff",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_secVertexHighPur",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_secVertexHighEff",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_secVertexCombined",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_jetProb",1);
  chainB->SetBranchStatus("jets_AK5PF_btag_jetBProb",1);
  chainB->SetBranchStatus("jets_AK5PF_jetCharge",1);
  chainB->SetBranchStatus("jets_AK5PF_partonFlavour",1);
  chainB->SetBranchStatus("jets_AK5PF_parton_Id",1);
  chainB->SetBranchStatus("jets_AK5PF_parton_motherId",1);
  chainB->SetBranchStatus("jets_AK5PF_energy",1);
  chainB->SetBranchStatus("jets_AK5PF_pt",1);
  chainB->SetBranchStatus("jets_AK5PF_px",1);
  chainB->SetBranchStatus("jets_AK5PF_py",1);
  chainB->SetBranchStatus("jets_AK5PF_gen_pt",1);
  chainB->SetBranchStatus("jets_AK5PF_gen_phi",1);
  chainB->SetBranchStatus("jets_AK5PF_pz",1);
  chainB->SetBranchStatus("jets_AK5PF_eta",1);
  chainB->SetBranchStatus("jets_AK5PF_ehf",1);
  chainB->SetBranchStatus("jets_AK5PF_phi",1);
  chainB->SetBranchStatus("jets_AK5PF_neutralEmE",1);
  chainB->SetBranchStatus("jets_AK5PF_chgEmE",1);
  chainB->SetBranchStatus("jets_AK5PF_neutralHadE",1);
  chainB->SetBranchStatus("jets_AK5PF_chgHadE",1);
  chainB->SetBranchStatus("jets_AK5PF_mu_Mult",1);
  chainB->SetBranchStatus("jets_AK5PF_neutral_Mult",1);
  chainB->SetBranchStatus("jets_AK5PF_chg_Mult",1);
  chainB->SetBranchStatus("jets_AK5PF_corrFactorRaw",1);
  chainB->SetBranchStatus("jets_AK5PF_photonEnergy",1);	
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_px",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_py",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_pz",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_energy",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_phi",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_eta",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_index",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT10_nconstituents",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_px",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_py",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_pz",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_energy",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_phi",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_eta",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_index",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT15_nconstituents",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_px",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_py",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_pz",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_energy",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_phi",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_eta",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_index",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT20_nconstituents",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_px",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_py",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_pz",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_energy",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_phi",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_eta",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_index",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT25_nconstituents",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_px",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_py",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_pz",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_energy",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_phi",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_eta",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_index",1);
  chainB->SetBranchStatus("fastjets_AK5PFclean_R1p2_R0p5pT30_nconstituents",1);
  

  chainB->SetBranchStatus("pfmets_et",1);
  chainB->SetBranchStatus("pfmets_ex",1);
  chainB->SetBranchStatus("pfmets_ey",1);
  chainB->SetBranchStatus("pfmets_phi",1);
  chainB->SetBranchStatus("pfmets_sumEt",1);
  chainB->SetBranchStatus("pfmets_gen_et",1);
  chainB->SetBranchStatus("pfmets_gen_phi",1);

  chainB->SetBranchStatus("pfTypeImets_et",1);
  chainB->SetBranchStatus("pfTypeImets_ex",1);
  chainB->SetBranchStatus("pfTypeImets_ey",1);
  chainB->SetBranchStatus("pfTypeImets_phi",1);
  chainB->SetBranchStatus("pfTypeImets_sumEt",1);
  chainB->SetBranchStatus("pfTypeImets_gen_et",1);
  chainB->SetBranchStatus("pfTypeImets_gen_phi",1);

  chainB->SetBranchStatus("pv_x",1);
  chainB->SetBranchStatus("pv_y",1);
  chainB->SetBranchStatus("pv_z",1);
  chainB->SetBranchStatus("pv_tracksSize",1);
  chainB->SetBranchStatus("pv_ndof",1);
  chainB->SetBranchStatus("pv_isFake",1);
  chainB->SetBranchStatus("Npv",1);

  chainB->SetBranchStatus("run",1);
  chainB->SetBranchStatus("event",1);
  chainB->SetBranchStatus("lumiblock",1);
  chainB->SetBranchStatus("bunchCrossing",1);

  chainB->SetBranchStatus("beamSpot_y",1);
  chainB->SetBranchStatus("beamSpot_x",1);

  chainB->SetBranchStatus("weight",1);
  chainB->SetBranchStatus("model_params",1);

  // Make the new file
  TFile *newFile = new TFile(output_filename.Data(),"RECREATE");
  TDirectoryFile *dir = new TDirectoryFile("configurableAnalysis","configurableAnalysis");
  dir->cd();
  TTree *newtreeA = chainA->CloneTree(0);
  TTree *newtreeB = chainB->CloneTree(0);

  Int_t nentries = (Int_t)chainB->GetEntries();

  for (int iEnt = 0; iEnt<nentries; iEnt++) {
    chainA->GetEntry(iEnt);
    chainB->GetEntry(iEnt);
    newtreeA->Fill();
    newtreeB->Fill();
  }

  newtreeA->AutoSave();
  newtreeB->AutoSave();
  newFile->Write();
  newFile->Close();

}
예제 #19
0
void CreatePictureBooks(const char* data_dir, int first_run, const int n_runs) {

  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetCanvasBorderMode(0); // turn off canvas borders



  // Create the canvases
  TCanvas* trend_canvas = new TCanvas("trend_canvas", "trend_canvas");

  TFile* files[n_runs];
  TCanvas* individual_canvases[n_runs];

  // Names for opening, closing and saving to PDFs
  std::stringstream individual_basepdfname[n_runs];
  std::string individual_openpdfname[n_runs];
  std::string individual_closepdfname[n_runs];

  for (int iRun = 0; iRun < n_runs; ++iRun) {

    int run_number = first_run + iRun;

    // Open up the file for this run
    std::stringstream filename;
    filename << data_dir << "/hist/hist0" << run_number << ".root";
    files[iRun] = new TFile(filename.str().c_str(), "READ");

    // Create an individual canvas for this run
    std::stringstream canvasname;
    canvasname << "individual_canvas_run0" << run_number;
    individual_canvases[iRun] = new TCanvas(canvasname.str().c_str(),canvasname.str().c_str());

    // Open a PDF for each run
    individual_basepdfname[iRun].str("");
    individual_basepdfname[iRun] << "DQ_LowLevel_RunPlots_Run0" << run_number << ".pdf";
    
    individual_openpdfname[iRun] =  individual_basepdfname[iRun].str() + "[";
    individual_closepdfname[iRun] = individual_basepdfname[iRun].str() + "]";
    individual_canvases[iRun]->Print(individual_openpdfname[iRun].c_str());
  }



  // Get the names of all the histograms
  std::vector<std::string> histogram_names;

  TIter nextFileKey(files[0]->GetListOfKeys()); // get the list of keys for the top level in the first file (all files should be the same)
  TKey *fileKey;
        
  while (fileKey = (TKey*)nextFileKey()) {

    // Get the directory for low-level data quality plots first
    if (strcmp(fileKey->ReadObj()->ClassName(), "TDirectoryFile") == 0) {
      // Check that the directory has the correct name
      if (strcmp(fileKey->ReadObj()->GetName(), "DataQuality_LowLevel") == 0) {

	TDirectoryFile* dir = (TDirectoryFile*) fileKey->ReadObj();
	
	TIter nextDirKey(dir->GetListOfKeys()); // get the list of keys in the directory (all histograms should be in this folder)
	TKey *dirKey;
        
	while (dirKey = (TKey*)nextDirKey()) {

	  // Get the names of all the histograms and count them up
	  if (strcmp(dirKey->ReadObj()->ClassName(), "TH1F") == 0 ||
	      strcmp(dirKey->ReadObj()->ClassName(), "TH2F") == 0) {

	    histogram_names.push_back(dirKey->ReadObj()->GetName());
	  } // end if (class is TH1F)

	} // end while loop (through keys in the directory)
      } // end if (directory is DataQuality_LowLevel)
    } // end if (class is TDirectoryFile)
  } // end while loop (through keys in file)

  // Reorder the histogram names so that channels from the same board are next to each other (might make it easier to print 4 plots on the same page)
  std::vector<std::string> ordered_histogram_names = OrderHistogramNames(histogram_names);

  std::stringstream trend_basepdfname;
  trend_basepdfname << "DQ_LowLevel_TrendPlots_Runs0" << first_run << "-" << first_run + n_runs << ".pdf";
  std::string trend_openpdfname = trend_basepdfname.str() + "[";
  std::string trend_closepdfname = trend_basepdfname.str() + "]";

  trend_canvas->Print(trend_openpdfname.c_str());



  // Now we have the histogram names, so loop though them
  for (int iHist = 0; iHist < ordered_histogram_names.size(); ++iHist) {

    std::string histname = ordered_histogram_names.at(iHist);
    std::string fullhistname = "DataQuality_LowLevel/" + histname;

    // Check to see if we actually want this plot
    if ( !WantPlot(histname)) {
      continue;
    }


    // Create the trend plot
    std::string trendplotname = histname + "_TrendPlot";
    std::string trendplottitle = "Trend plot of " + histname;

    // Get some useful information from the histogram in the first run file (for the y-axis range of the trend plot)
    TH1F* hist = (TH1F*) files[0]->Get(fullhistname.c_str());

    TH2F* trend_plot = new TH2F(trendplotname.c_str(), trendplottitle.c_str(), n_runs, first_run, first_run+n_runs, hist->GetNbinsX(), hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());

    trend_plot->GetYaxis()->SetTitle(hist->GetXaxis()->GetTitle());
    trend_plot->GetYaxis()->SetLabelSize(0.03);

    trend_plot->GetXaxis()->SetTitle("Run Number");
    trend_plot->GetXaxis()->SetLabelSize(0.03);

    trend_plot->GetZaxis()->SetTitle(hist->GetYaxis()->GetTitle());
    trend_plot->GetZaxis()->SetLabelSize(0.03);
    trend_plot->GetZaxis()->SetTitleOffset(0.85);
    trend_plot->GetZaxis()->SetTitleSize(0.03);
    trend_plot->SetStats(false);

    // Set the fraction trend plots to have a maximum of 1 so that red = bad
    if (histname.find("Fraction") != std::string::npos) {
      trend_plot->GetZaxis()->SetRangeUser(0,1);
    }
    // Copy the axis labels so that they show the detector and channel names
    else if (histname.find("hDQ_IslandRate") != std::string::npos) {
      for (int jBin = 1; jBin < hist->GetNbinsX(); ++jBin) {
	trend_plot->GetYaxis()->SetBinLabel(jBin, hist->GetXaxis()->GetBinLabel(jBin));
      }
      trend_plot->GetYaxis()->SetTitle(false);
      trend_plot->GetYaxis()->SetLabelSize(0.02);
      trend_plot->GetZaxis()->SetLabelSize(0.02);
    }

    // Check to see if we want this histogram as an individual or a trend plot
    bool want_trend_plot = WantAsTrendPlot(histname);

    // Loop through the runs
    for (int iRun = 0; iRun < n_runs; ++iRun) {
      
      // Make sure this file exists (there may be some missing in our golden run ranges)
      if (files[iRun]->IsZombie())
	continue;

      // Get the histogram
      TH1* hist = (TH1*) files[iRun]->Get(fullhistname.c_str());
      
      if (want_trend_plot == false) {

	// Print the histogram out directly to the individual picture book
	individual_canvases[iRun]->cd();
	ZoomIndividualPlot(hist);
	hist->Draw("COLZ");
	individual_canvases[iRun]->SetLogz(WantLogZ(histname)); // change to a log-z scale if we want to
	individual_canvases[iRun]->Update();
	individual_canvases[iRun]->Print(individual_basepdfname[iRun].str().c_str());
      
      }
      else {
	// Fill this histogram into the trend plot
	for (int iBin = 1; iBin <= hist->GetNbinsX(); ++iBin) {
	  trend_plot->Fill(first_run + iRun, hist->GetBinCenter(iBin), hist->GetBinContent(iBin)); // (x = run #, y = time stamp, z = N_TPI)
	} // end for loop (filling trend plot)
      } // end if (trend plot)
    } // end for loop (through runs)

    // Now export the trend plot to PDF (if applicable)
    if (want_trend_plot) {
      trend_canvas->cd();
      ZoomTrendPlot(trend_plot);
      trend_plot->Draw("COLZ");
      trend_canvas->Print(trend_basepdfname.str().c_str());
    }
  }


  // Now go through and clean up
  for (int iRun = 0; iRun < n_runs; ++iRun) {
    individual_canvases[iRun]->Print(individual_closepdfname[iRun].c_str());
  }
  trend_canvas->Print(trend_closepdfname.c_str());
}
/////// main func. ///////
int make2Droot_total_noPtWeight(char *dirName = "8rap9pt2gev", char *dateName = "no"){

  using namespace std;

	////////////////////////////////////////////////
	////// read in Acceptance file
	// *** without pt weight
	TFile *fAccPR = new TFile("../001_Acceptance/AccAna_8rap9pt2gev_PRMC_boosted.root");
	TFile *fAccNP = new TFile("../001_Acceptance/AccAna_8rap9pt2gev_NPMC_boosted.root");
	// *** with pt weight
	//TFile *fAccPR = new TFile("../001_Acceptance_weight_8rap9pt2gev/AccAna_isPrompt1_Pbp_kyo01.root");
	//TFile *fAccNP = new TFile("../001_Acceptance_weight_8rap9pt2gev/AccAna_isPrompt0_Pbp_kyo01.root");
	TH2D* h2D_Acc_pt_y_PRMC_Pbp = (TH2D*)fAccPR->Get("h2D_Acc_pt_y_Pbp");
	TH2D* h2D_Acc_pt_y_PRMC_pPb = (TH2D*)fAccPR->Get("h2D_Acc_pt_y_pPb");
	TH2D* h2D_Acc_pt_y_NPMC_Pbp = (TH2D*)fAccNP->Get("h2D_Acc_pt_y_Pbp");
	TH2D* h2D_Acc_pt_y_NPMC_pPb = (TH2D*)fAccNP->Get("h2D_Acc_pt_y_pPb");
	//TH2D* h2D_Acc_pt_y_NPMC_Pbp = (TH2D*)fAccNP->Get("h2D_Acc_noWeight_pt_y_Pbp"); //un-weighted!
	//TH2D* h2D_Acc_pt_y_NPMC_pPb = (TH2D*)fAccNP->Get("h2D_Acc_noWeight_pt_y_pPb");
	h2D_Acc_pt_y_PRMC_Pbp->SetName("h2D_Acc_pt_y_PRMC_Pbp");
	h2D_Acc_pt_y_PRMC_pPb->SetName("h2D_Acc_pt_y_PRMC_pPb");
	h2D_Acc_pt_y_NPMC_Pbp->SetName("h2D_Acc_pt_y_NPMC_Pbp");
	h2D_Acc_pt_y_NPMC_pPb->SetName("h2D_Acc_pt_y_NPMC_pPb");
	cout << "4 Acc TH2D : "<<h2D_Acc_pt_y_PRMC_Pbp<<" "<<h2D_Acc_pt_y_PRMC_pPb<<" "<<h2D_Acc_pt_y_NPMC_Pbp<<" "<<h2D_Acc_pt_y_NPMC_pPb<<endl;
	
	TH2D* h2D_Acc_Den_pt_y_PRMC_Pbp = (TH2D*)fAccPR->Get("h2D_Den_pt_y_Pbp");
	TH2D* h2D_Acc_Den_pt_y_PRMC_pPb = (TH2D*)fAccPR->Get("h2D_Den_pt_y_pPb"); 
	TH2D* h2D_Acc_Den_pt_y_NPMC_Pbp = (TH2D*)fAccNP->Get("h2D_Den_pt_y_Pbp"); //WRONG!! weighted!
	TH2D* h2D_Acc_Den_pt_y_NPMC_pPb = (TH2D*)fAccNP->Get("h2D_Den_pt_y_pPb"); //WRONG!! weighted!
	h2D_Acc_Den_pt_y_PRMC_Pbp->SetName("h2D_Acc_Den_pt_y_PRMC_Pbp");
	h2D_Acc_Den_pt_y_PRMC_pPb->SetName("h2D_Acc_Den_pt_y_PRMC_pPb");
	h2D_Acc_Den_pt_y_NPMC_Pbp->SetName("h2D_Acc_Den_pt_y_NPMC_Pbp");
	h2D_Acc_Den_pt_y_NPMC_pPb->SetName("h2D_Acc_Den_pt_y_NPMC_pPb");
	
	TH2D* h2D_Acc_Num_pt_y_PRMC_Pbp = (TH2D*)fAccPR->Get("h2D_Num_pt_y_Pbp");
	TH2D* h2D_Acc_Num_pt_y_PRMC_pPb = (TH2D*)fAccPR->Get("h2D_Num_pt_y_pPb");
	TH2D* h2D_Acc_Num_pt_y_NPMC_Pbp = (TH2D*)fAccNP->Get("h2D_Num_pt_y_Pbp");  //WRONG!! weighted!
	TH2D* h2D_Acc_Num_pt_y_NPMC_pPb = (TH2D*)fAccNP->Get("h2D_Num_pt_y_pPb");  //WRONG!! weighted!
	h2D_Acc_Num_pt_y_PRMC_Pbp->SetName("h2D_Acc_Num_pt_y_PRMC_Pbp");
	h2D_Acc_Num_pt_y_PRMC_pPb->SetName("h2D_Acc_Num_pt_y_PRMC_pPb");
	h2D_Acc_Num_pt_y_NPMC_Pbp->SetName("h2D_Acc_Num_pt_y_NPMC_Pbp");
	h2D_Acc_Num_pt_y_NPMC_pPb->SetName("h2D_Acc_Num_pt_y_NPMC_pPb");


	////////////////////////////////////////////////
	////// read in Efficiency file
	// *** without pt weight
	TFile *fEffPRPbp = new TFile("../002_Efficiency_zVtx_embedded/EffCounting_8rap9pt2gev_PRMCpythia_Pbp_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1.root");
	TFile *fEffPRpPb = new TFile("../002_Efficiency_zVtx_embedded/EffCounting_8rap9pt2gev_PRMCpythia_pPb_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1.root");
	TFile *fEffNPPbp = new TFile("../002_Efficiency_zVtx_embedded/EffCounting_8rap9pt2gev_NPMCpythia_Pbp_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1.root");
	TFile *fEffNPpPb = new TFile("../002_Efficiency_zVtx_embedded/EffCounting_8rap9pt2gev_NPMCpythia_pPb_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1.root");
	/*
	/// *** with pt weight
	TFile *fEffPRPbp = new TFile("../001_Acceptance_weight_8rap9pt2gev/EffCounting_8rap9pt2gev_PRMCpythia_Pbp_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1_kyo01.root");
	TFile *fEffPRpPb = new TFile("../001_Acceptance_weight_8rap9pt2gev/EffCounting_8rap9pt2gev_PRMCpythia_pPb_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1_kyo01.root");
	TFile *fEffNPPbp = new TFile("../001_Acceptance_weight_8rap9pt2gev/EffCounting_8rap9pt2gev_NPMCpythia_Pbp_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1_kyo01.root");
	TFile *fEffNPpPb = new TFile("../001_Acceptance_weight_8rap9pt2gev/EffCounting_8rap9pt2gev_NPMCpythia_pPb_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1_kyo01.root");
	*/
	TH2D* h2D_Eff_pt_y_PRMC_Pbp = (TH2D*)fEffPRPbp->Get("h2D_Eff_pt_y"); //weighted!
	TH2D* h2D_Eff_pt_y_PRMC_pPb = (TH2D*)fEffPRpPb->Get("h2D_Eff_pt_y");
	TH2D* h2D_Eff_pt_y_NPMC_Pbp = (TH2D*)fEffNPPbp->Get("h2D_Eff_pt_y"); //unweighted!
	TH2D* h2D_Eff_pt_y_NPMC_pPb = (TH2D*)fEffNPpPb->Get("h2D_Eff_pt_y");
	//TH2D* h2D_Eff_pt_y_NPMC_Pbp = (TH2D*)fEffNPPbp->Get("h2D_Eff_noWeight_pt_y"); //unweighted!
	//TH2D* h2D_Eff_pt_y_NPMC_pPb = (TH2D*)fEffNPpPb->Get("h2D_Eff_noWeight_pt_y");
	h2D_Eff_pt_y_PRMC_Pbp->SetName("h2D_Eff_pt_y_PRMC_Pbp");
	h2D_Eff_pt_y_PRMC_pPb->SetName("h2D_Eff_pt_y_PRMC_pPb");
	h2D_Eff_pt_y_NPMC_Pbp->SetName("h2D_Eff_pt_y_NPMC_Pbp");
	h2D_Eff_pt_y_NPMC_pPb->SetName("h2D_Eff_pt_y_NPMC_pPb");
	cout << "4 Eff TH2D : "<<h2D_Eff_pt_y_PRMC_Pbp<<" "<<h2D_Eff_pt_y_PRMC_pPb<<" "<<h2D_Eff_pt_y_NPMC_Pbp<<" "<<h2D_Eff_pt_y_NPMC_pPb<<endl;
	TH2D* h2D_Eff_Den_pt_y_PRMC_Pbp = (TH2D*)fEffPRPbp->Get("h2D_Den_pt_y");
	TH2D* h2D_Eff_Den_pt_y_PRMC_pPb = (TH2D*)fEffPRpPb->Get("h2D_Den_pt_y");
	TH2D* h2D_Eff_Den_pt_y_NPMC_Pbp = (TH2D*)fEffNPPbp->Get("h2D_Den_pt_y");
	TH2D* h2D_Eff_Den_pt_y_NPMC_pPb = (TH2D*)fEffNPpPb->Get("h2D_Den_pt_y");
	//TH2D* h2D_Eff_Den_pt_y_NPMC_Pbp = (TH2D*)fEffNPPbp->Get("h2D_Den_noWeight_pt_y");
	//TH2D* h2D_Eff_Den_pt_y_NPMC_pPb = (TH2D*)fEffNPpPb->Get("h2D_Den_noWeight_pt_y");
	h2D_Eff_Den_pt_y_PRMC_Pbp->SetName("h2D_Eff_Den_pt_y_PRMC_Pbp");
	h2D_Eff_Den_pt_y_PRMC_pPb->SetName("h2D_Eff_Den_pt_y_PRMC_pPb");
	h2D_Eff_Den_pt_y_NPMC_Pbp->SetName("h2D_Eff_Den_pt_y_NPMC_Pbp");
	h2D_Eff_Den_pt_y_NPMC_pPb->SetName("h2D_Eff_Den_pt_y_NPMC_pPb");
	
	TH2D* h2D_Eff_Num_pt_y_PRMC_Pbp = (TH2D*)fEffPRPbp->Get("h2D_Num_pt_y");
	TH2D* h2D_Eff_Num_pt_y_PRMC_pPb = (TH2D*)fEffPRpPb->Get("h2D_Num_pt_y");
	TH2D* h2D_Eff_Num_pt_y_NPMC_Pbp = (TH2D*)fEffNPPbp->Get("h2D_Num_pt_y");
	TH2D* h2D_Eff_Num_pt_y_NPMC_pPb = (TH2D*)fEffNPpPb->Get("h2D_Num_pt_y");
	//TH2D* h2D_Eff_Num_pt_y_NPMC_Pbp = (TH2D*)fEffNPPbp->Get("h2D_Num_noWeight_pt_y");
	//TH2D* h2D_Eff_Num_pt_y_NPMC_pPb = (TH2D*)fEffNPpPb->Get("h2D_Num_noWeight_pt_y");
	h2D_Eff_Num_pt_y_PRMC_Pbp->SetName("h2D_Eff_Num_pt_y_PRMC_Pbp");
	h2D_Eff_Num_pt_y_PRMC_pPb->SetName("h2D_Eff_Num_pt_y_PRMC_pPb");
	h2D_Eff_Num_pt_y_NPMC_Pbp->SetName("h2D_Eff_Num_pt_y_NPMC_Pbp");
	h2D_Eff_Num_pt_y_NPMC_pPb->SetName("h2D_Eff_Num_pt_y_NPMC_pPb");
	
	////////////////////////////////////////////////
	////// read in fromfit file
	TFile* fFitPbp = new TFile("./2Dhist_fitRes_8rap9pt2gev_Pbp.root");
	TFile* fFitpPb = new TFile("./2Dhist_fitRes_8rap9pt2gev_pPb.root");
	TH2D* h2D_fit_pt_y_PR_Pbp = (TH2D*)fFitPbp->Get("h2D_nPrompt");	
	TH2D* h2D_fit_pt_y_NP_Pbp = (TH2D*)fFitPbp->Get("h2D_nNonprompt");	
	TH2D* h2D_fit_pt_y_nSig_Pbp = (TH2D*)fFitPbp->Get("h2D_nSig");	
	TH2D* h2D_fit_pt_y_nBkg_Pbp = (TH2D*)fFitPbp->Get("h2D_nBkg");	
	TH2D* h2D_fit_pt_y_bFrac_Pbp = (TH2D*)fFitPbp->Get("h2D_bFraction");	
	TH2D* h2D_fit_pt_y_ctErrmin_Pbp = (TH2D*)fFitPbp->Get("h2D_ctErrmin");	
	TH2D* h2D_fit_pt_y_ctErrmax_Pbp = (TH2D*)fFitPbp->Get("h2D_ctErrmax");	
	TH2D* h2D_fit_pt_y_PR_pPb = (TH2D*)fFitpPb->Get("h2D_nPrompt");	
	TH2D* h2D_fit_pt_y_NP_pPb = (TH2D*)fFitpPb->Get("h2D_nNonprompt");	
	TH2D* h2D_fit_pt_y_nSig_pPb = (TH2D*)fFitpPb->Get("h2D_nSig");	
	TH2D* h2D_fit_pt_y_nBkg_pPb = (TH2D*)fFitpPb->Get("h2D_nBkg");	
	TH2D* h2D_fit_pt_y_bFrac_pPb = (TH2D*)fFitpPb->Get("h2D_bFraction");	
	TH2D* h2D_fit_pt_y_ctErrmin_pPb = (TH2D*)fFitpPb->Get("h2D_ctErrmin");	
	TH2D* h2D_fit_pt_y_ctErrmax_pPb = (TH2D*)fFitpPb->Get("h2D_ctErrmax");	
	h2D_fit_pt_y_PR_Pbp->SetName("h2D_fit_pt_y_PR_Pbp");
	h2D_fit_pt_y_PR_pPb->SetName("h2D_fit_pt_y_PR_pPb");
	h2D_fit_pt_y_NP_Pbp->SetName("h2D_fit_pt_y_NP_Pbp");
	h2D_fit_pt_y_NP_pPb->SetName("h2D_fit_pt_y_NP_pPb");
	h2D_fit_pt_y_nSig_Pbp->SetName("h2D_fit_pt_y_nSig_Pbp");
	h2D_fit_pt_y_nSig_pPb->SetName("h2D_fit_pt_y_nSig_pPb");
	h2D_fit_pt_y_nBkg_Pbp->SetName("h2D_fit_pt_y_nBkg_Pbp");
	h2D_fit_pt_y_nBkg_pPb->SetName("h2D_fit_pt_y_nBkg_pPb");
	h2D_fit_pt_y_bFrac_Pbp->SetName("h2D_fit_pt_y_bFrac_Pbp");
	h2D_fit_pt_y_bFrac_pPb->SetName("h2D_fit_pt_y_bFrac_pPb");
	h2D_fit_pt_y_ctErrmin_Pbp->SetName("h2D_fit_pt_y_ctErrmin_Pbp");
	h2D_fit_pt_y_ctErrmin_pPb->SetName("h2D_fit_pt_y_ctErrmin_pPb");
	h2D_fit_pt_y_ctErrmax_Pbp->SetName("h2D_fit_pt_y_ctErrmax_Pbp");
	h2D_fit_pt_y_ctErrmax_pPb->SetName("h2D_fit_pt_y_ctErrmax_pPb");
	
	cout << "4 yield TH2D : "<<h2D_fit_pt_y_PR_Pbp<<" "<<h2D_fit_pt_y_PR_pPb<<" "<<h2D_fit_pt_y_NP_Pbp<<" "<<h2D_fit_pt_y_NP_pPb<<endl;
	cout << "2 nSig TH2D : "<<h2D_fit_pt_y_nSig_Pbp<<" "<<h2D_fit_pt_y_nSig_pPb<<endl;
	cout << "2 nBkg TH2D : "<<h2D_fit_pt_y_nBkg_Pbp<<" "<<h2D_fit_pt_y_nBkg_pPb<<endl;
	cout << "2 bFrac TH2D : "<<h2D_fit_pt_y_bFrac_Pbp<<" "<<h2D_fit_pt_y_bFrac_pPb<<endl;
	cout << "2 ctErrmin TH2D : "<<h2D_fit_pt_y_ctErrmin_Pbp<<" "<<h2D_fit_pt_y_ctErrmin_pPb<<endl;
	cout << "2 ctErrmax TH2D : "<<h2D_fit_pt_y_ctErrmax_Pbp<<" "<<h2D_fit_pt_y_ctErrmax_pPb<<endl;
	
	////////////////////////////////////////////////
	////// data corrected yield = rawYield/(Acc*Eff)
	TH2D* h2D_corrY_PR_Pbp = (TH2D*)h2D_fit_pt_y_PR_Pbp->Clone("h2D_corrY_PR_Pbp");
	h2D_corrY_PR_Pbp->SetName("h2D_corrY_PR_Pbp");
	h2D_corrY_PR_Pbp->Divide(h2D_Acc_pt_y_PRMC_Pbp);
	h2D_corrY_PR_Pbp->Divide(h2D_Eff_pt_y_PRMC_Pbp);
	TH2D* h2D_corrY_NP_Pbp = (TH2D*)h2D_fit_pt_y_NP_Pbp->Clone("h2D_corrY_NP_Pbp");
	h2D_corrY_NP_Pbp->SetName("h2D_corrY_NP_Pbp");
	h2D_corrY_NP_Pbp->Divide(h2D_Acc_pt_y_NPMC_Pbp);
	h2D_corrY_NP_Pbp->Divide(h2D_Eff_pt_y_NPMC_Pbp);
	TH2D* h2D_corrY_PR_pPb = (TH2D*)h2D_fit_pt_y_PR_pPb->Clone("h2D_corrY_PR_pPb");
	h2D_corrY_PR_pPb->SetName("h2D_corrY_PR_pPb");
	h2D_corrY_PR_pPb->Divide(h2D_Acc_pt_y_PRMC_pPb);
	h2D_corrY_PR_pPb->Divide(h2D_Eff_pt_y_PRMC_pPb);
	TH2D* h2D_corrY_NP_pPb = (TH2D*)h2D_fit_pt_y_NP_pPb->Clone("h2D_corrY_NP_pPb");
	h2D_corrY_NP_pPb->SetName("h2D_corrY_NP_pPb");
	h2D_corrY_NP_pPb->Divide(h2D_Acc_pt_y_NPMC_pPb);
	h2D_corrY_NP_pPb->Divide(h2D_Eff_pt_y_NPMC_pPb);
	
	////////////////////////////////////////////////
	////// MC corrected yield RECO/(Acc*Eff)
	TH2D* h2D_MCcorrY_PR_Pbp = (TH2D*)h2D_Eff_Num_pt_y_PRMC_Pbp->Clone("h2D_MCcorrY_PR_Pbp");
	h2D_MCcorrY_PR_Pbp->SetName("h2D_MCcorrY_PR_Pbp");
	h2D_MCcorrY_PR_Pbp->Divide(h2D_Acc_pt_y_PRMC_Pbp);
	h2D_MCcorrY_PR_Pbp->Divide(h2D_Eff_pt_y_PRMC_Pbp);
	TH2D* h2D_MCcorrY_NP_Pbp = (TH2D*)h2D_Eff_Num_pt_y_NPMC_Pbp->Clone("h2D_MCcorrY_NP_Pbp");
	h2D_MCcorrY_NP_Pbp->SetName("h2D_MCcorrY_NP_Pbp");
	h2D_MCcorrY_NP_Pbp->Divide(h2D_Acc_pt_y_NPMC_Pbp);
	h2D_MCcorrY_NP_Pbp->Divide(h2D_Eff_pt_y_NPMC_Pbp);
	TH2D* h2D_MCcorrY_PR_pPb = (TH2D*)h2D_Eff_Num_pt_y_PRMC_pPb->Clone("h2D_MCcorrY_PR_pPb");
	h2D_MCcorrY_PR_pPb->SetName("h2D_MCcorrY_PR_pPb");
	h2D_MCcorrY_PR_pPb->Divide(h2D_Acc_pt_y_PRMC_pPb);
	h2D_MCcorrY_PR_pPb->Divide(h2D_Eff_pt_y_PRMC_pPb);
	TH2D* h2D_MCcorrY_NP_pPb = (TH2D*)h2D_Eff_Num_pt_y_NPMC_pPb->Clone("h2D_MCcorrY_NP_pPb");
	h2D_MCcorrY_NP_pPb->SetName("h2D_MCcorrY_NP_pPb");
	h2D_MCcorrY_NP_pPb->Divide(h2D_Acc_pt_y_NPMC_pPb);
	h2D_MCcorrY_NP_pPb->Divide(h2D_Eff_pt_y_NPMC_pPb);
	
	
	////////////////////////////////////////////////
	////// save as a root file
	TFile *outFile = new TFile(Form("total2Dhist_%s_noPtWeight.root",dirName),"RECREATE");
	std::cout << "dirName: " << dirName << std::endl;
	cout << "total2Dhist_"<<dirName<<"_noPtWeight.root has been created :) " <<endl;	

	outFile->cd();
	//Acc	
	h2D_Acc_pt_y_PRMC_Pbp->Write();
	h2D_Acc_pt_y_PRMC_pPb->Write();
	h2D_Acc_pt_y_NPMC_Pbp->Write();
	h2D_Acc_pt_y_NPMC_pPb->Write();
	//Eff
	h2D_Eff_pt_y_PRMC_Pbp->Write();
	h2D_Eff_pt_y_PRMC_pPb->Write();
	h2D_Eff_pt_y_NPMC_Pbp->Write();
	h2D_Eff_pt_y_NPMC_pPb->Write();
	//raw yield
	h2D_fit_pt_y_PR_Pbp->Write();	
	h2D_fit_pt_y_PR_pPb->Write();	
	h2D_fit_pt_y_NP_Pbp->Write();	
	h2D_fit_pt_y_NP_pPb->Write();	
	//corrYield
	h2D_corrY_PR_Pbp->Write();	
	h2D_corrY_PR_pPb->Write();	
	h2D_corrY_NP_Pbp->Write();	
	h2D_corrY_NP_pPb->Write();	
	
	// DIRECTORY : num, den distributions for acc & eff
	TDirectoryFile *otherMCInfo = new TDirectoryFile("otherMCInfo","otherMCInfo");
	otherMCInfo->cd();
	// acc den & num
	h2D_Acc_Den_pt_y_PRMC_Pbp->Write();
	h2D_Acc_Den_pt_y_PRMC_pPb->Write();
	h2D_Acc_Den_pt_y_NPMC_Pbp->Write();
	h2D_Acc_Den_pt_y_NPMC_pPb->Write();
	h2D_Acc_Num_pt_y_PRMC_Pbp->Write();
	h2D_Acc_Num_pt_y_PRMC_pPb->Write();
	h2D_Acc_Num_pt_y_NPMC_Pbp->Write();
	h2D_Acc_Num_pt_y_NPMC_pPb->Write();
	// eff den & num
	h2D_Eff_Den_pt_y_PRMC_Pbp->Write();
	h2D_Eff_Den_pt_y_PRMC_pPb->Write();
	h2D_Eff_Den_pt_y_NPMC_Pbp->Write();
	h2D_Eff_Den_pt_y_NPMC_pPb->Write();
	h2D_Eff_Num_pt_y_PRMC_Pbp->Write();
	h2D_Eff_Num_pt_y_PRMC_pPb->Write();
	h2D_Eff_Num_pt_y_NPMC_Pbp->Write();
	h2D_Eff_Num_pt_y_NPMC_pPb->Write();
	// MC corrYield
	h2D_MCcorrY_PR_Pbp->Write();	
	h2D_MCcorrY_PR_pPb->Write();	
	h2D_MCcorrY_NP_Pbp->Write();	
	h2D_MCcorrY_NP_pPb->Write();	
	otherMCInfo->Write();
	
	// DIRECTORY : other information for fittng
	outFile->cd();
	TDirectoryFile *otherFitInfo = new TDirectoryFile("otherFitInfo","otherFitInfo");
	otherFitInfo->cd();
	h2D_fit_pt_y_nSig_Pbp->Write();	
	h2D_fit_pt_y_nSig_pPb->Write();	
	h2D_fit_pt_y_nBkg_Pbp->Write();	
	h2D_fit_pt_y_nBkg_pPb->Write();	
	h2D_fit_pt_y_bFrac_Pbp->Write();	
	h2D_fit_pt_y_bFrac_pPb->Write();	
	h2D_fit_pt_y_ctErrmin_Pbp->Write();	
	h2D_fit_pt_y_ctErrmin_pPb->Write();	
	h2D_fit_pt_y_ctErrmax_Pbp->Write();	
	h2D_fit_pt_y_ctErrmax_pPb->Write();	
	otherFitInfo->Write();
		
	outFile->Close();
	
	return 0;

} // end of main func
예제 #21
0
void RebinCFContainer(const char *infile="AnalysisResults.root",Int_t rebinVar=0, Int_t myEff=3, const char * name="Nch"){

  gSystem->SetIncludePath("-I. -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_PHYSICS -I$ALICE_PHYSICS/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/RAW -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/STEER/STEERBase -I$ALICE_ROOT/STEER/ESD -I$ALICE_ROOT/STEER/AOD -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -I$ALICE_PHYSICS/PWGPP -g");

  // gROOT->LoadMacro("AliSingleTrackEffCuts.cxx++g");
  // gROOT->LoadMacro("AliCFSingleTrackEfficiencyTask.cxx++g");

  gROOT->SetStyle("Plain");
  gStyle->SetPalette(1);
  gStyle->SetOptStat(0);
  gStyle->SetPalette(1);
  gStyle->SetCanvasColor(0);
  gStyle->SetFrameFillColor(0);
  gStyle->SetOptTitle(0);
  
  
  TFile* file = TFile::Open(infile,"read");
  
  TDirectoryFile *d = 0;
  AliCFContainer *dataIni = 0;
  d = (TDirectoryFile*)file->Get(Form("PWGPP_CFSingleTrack"));
  if(!d) {
    cout<<" no directory "<<endl;
    return;
  }
  dataIni = (AliCFContainer*) (d->Get(Form("container%s",name)));
  if(!dataIni){
    cout <<" no container"<<endl;
  }
  //
  // Do an slice of the container to make sure to remove outliers
  //
  const UInt_t ipt = 0;
  const UInt_t ieta  = 1;
  const UInt_t iphi = 2;
  const UInt_t itheta = 3;
  const UInt_t izvtx = 4;
  const UInt_t imult = 5;
  const UInt_t icent = 6;
  Int_t nvars = 7;
  Int_t* ivarSlice = new Int_t[nvars];
  ivarSlice[0]= ipt;    ivarSlice[1] = ieta;   ivarSlice[2] = iphi;  ivarSlice[3] = itheta;
  ivarSlice[4]= izvtx;  ivarSlice[5] = imult;  ivarSlice[6] = icent;
  Double_t *mins = new Double_t[nvars];
  Double_t *maxs = new Double_t[nvars];
  mins[ipt] = ptmin;        maxs[ipt] = ptmax;
  mins[ieta] = etamin;      maxs[ieta] = etamax;
  mins[iphi] = phimin;      maxs[iphi] = phimax;
  mins[itheta] = thetamin;  maxs[itheta] = thetamax;
  mins[izvtx] = zvtxmin;    maxs[izvtx] = zvtxmax;
  mins[imult] = multmin;    maxs[imult] = multmax;
  mins[icent] = centmin;    maxs[icent] = centmax;
  AliCFContainer *data = (AliCFContainer*)dataIni->MakeSlice(nvars,ivarSlice,mins,maxs);
  cout<< "  ... slice done"<<endl;
  cout<< "  the new container has "<< data->GetNStep() << " steps"<<endl;
  

  //
  // *********** NUMERATOR
  //
  AliCFGridSparse* gridSparse = 0;		
  if( myEff == 1 )  gridSparse = (AliCFGridSparse*)data->GetGrid(1); // GenAcc
  else if( myEff == 2 )  gridSparse = (AliCFGridSparse*)data->GetGrid(6); // Rec (acc + cuts) draw reco properties
  else if( myEff == 3 )  gridSparse = (AliCFGridSparse*)data->GetGrid(7); // RecPID
  else if( myEff == 4 )  gridSparse = (AliCFGridSparse*)data->GetGrid(3); // Rec (no cuts)
  else if( myEff == 5 )  gridSparse = (AliCFGridSparse*)data->GetGrid(4); // RecAcc
  else if( myEff == 6 )  gridSparse = (AliCFGridSparse*)data->GetGrid(5); // Rec (acc + cuts) draw kine properties

  THnSparse* numData = (THnSparse*)gridSparse->GetGrid();
  
  // method 2: defining a new THnSparse changing only the axis of interest
  Printf("Method 2 ");
  THnSparse* newnumData = (THnSparse*)numData->Clone("numNew");
  newnumData->Reset();

  Int_t nLimits=0;
  Double_t* newLimits =0;
  TString varname="";
  if(rebinVar==0) {
    varname="pt";
    nLimits = 17;
    newLimits = new Double_t[nLimits+1];
    newLimits[0]=0;
    newLimits[1]=0.25;
    newLimits[2]=0.5;
    newLimits[3]=0.75;
    newLimits[4]=1;
    newLimits[5]=1.5;
    newLimits[6]=2;
    newLimits[7]=2.5;
    newLimits[8]=3;
    newLimits[9]=4;
    newLimits[10]=5;
    newLimits[11]=6;
    newLimits[12]=7;
    newLimits[13]=8;
    newLimits[14]=10;
    newLimits[15]=12;
    newLimits[16]=14;
    newLimits[17]=16;
  } else if (rebinVar==1) {
    varname="eta";
    nLimits = 9;
    newLimits = new Double_t[nLimits+1];
    newLimits[0]=-0.9;
    newLimits[1]=-0.7;
    newLimits[2]=-0.5;
    newLimits[3]=-0.3;
    newLimits[4]=-0.1;
    newLimits[5]=0.1;
    newLimits[6]=0.3;
    newLimits[7]=0.5;
    newLimits[8]=0.7;
    newLimits[9]=0.9;
  } else if (rebinVar==2) {
    varname="phi";
    nLimits = 9;
    newLimits = new Double_t[nLimits+1];
    for(Int_t i=0; i<=nLimits; i++) newLimits[i]=(Double_t)phimin + (phimax-phimin)/nLimits*(Double_t)i ;
    
  }
  const Int_t nnewLimits = nLimits;
  
  
  TAxis* axis = (TAxis*)newnumData->GetAxis(rebinVar);
  axis->Set(nnewLimits,newLimits);
  newnumData->SetBinEdges(rebinVar,newLimits);
  
  newnumData->RebinnedAdd(numData, 1);
  
  // checking the bin contents
  TH1D* h1 = (TH1D*)numData->Projection(rebinVar);
  Float_t sum = 0;
  Float_t sumnew = 0;
  Printf("Original THnSparse");
  for (Int_t ibin = 1; ibin<=h1->GetNbinsX(); ibin++){
    Printf("ibin = %d, low edge = %f, content = %f",ibin,h1->GetBinLowEdge(ibin),h1->GetBinContent(ibin));
    sum+=h1->GetBinContent(ibin);
  }

  Printf("THnSparse changing only one axis");
  TH1D* h2num = (TH1D*)newnumData->Projection(rebinVar);
  for (Int_t ibin = 1; ibin<=h2num->GetNbinsX(); ibin++){
    Printf("ibin = %d, low edge = %f, content = %f",ibin,h2num->GetBinLowEdge(ibin),h2num->GetBinContent(ibin));
    sumnew+=h2num->GetBinContent(ibin);
  }
  
  Printf("sum = %f, sumnew = %f",sum, sumnew);

  //  
  // *********** DENOMINATOR RECPID
  //
  Printf("DENOMINATOR");
  
  AliCFGridSparse* gridSparse2 = 0;
  if( myEff == 1 )  gridSparse2 = (AliCFGridSparse*)data->GetGrid(0); // LimAcc
  else gridSparse2 = (AliCFGridSparse*)data->GetGrid(1);              // GenAcc

  THnSparse* denData = (THnSparse*)gridSparse2->GetGrid();
  
  // method 2: defining a new THnSparse changing only the axis of interest
  Printf("Method 2 ");
  THnSparse* newdenData = (THnSparse*)denData->Clone("denNew");
  newdenData->Reset();
  
  TAxis* axis2 = (TAxis*)newdenData->GetAxis(rebinVar);
  axis2->Set(nnewLimits,newLimits);
  newdenData->SetBinEdges(rebinVar,newLimits);
  
  newdenData->RebinnedAdd(denData, 1);
  
  // checking the bin contents
  TH1D* h1d = (TH1D*)denData->Projection(rebinVar);
  sum = 0;
  sumnew = 0;
  Printf("Original THnSparse");
  for (Int_t ibin = 1; ibin<=h1d->GetNbinsX(); ibin++){
    Printf("ibin = %d, low edge = %f, content = %f",ibin,h1d->GetBinLowEdge(ibin),h1d->GetBinContent(ibin));
    sum+=h1d->GetBinContent(ibin);
  }
  
  Printf("THnSparse changing only one axis");
  TH1D* h2 = (TH1D*)newdenData->Projection(rebinVar);
  for (Int_t ibin = 1; ibin<=h2->GetNbinsX(); ibin++){
    Printf("ibin = %d, low edge = %f, content = %f",ibin,h2->GetBinLowEdge(ibin),h2->GetBinContent(ibin));
    sumnew+=h2->GetBinContent(ibin);
  }
  
  Printf("sum = %f, sumnew = %f",sum, sumnew);
  
  TH1D* heff = (TH1D*)h2num->Clone("heff");
  heff->Divide(h2num, h2,1,1,"B");
  //  heff->GetXaxis()->SetRangeUser(0,23.5);
  TFile* fout = NULL;
  if( myEff == 1 ) {
    fout = new TFile(Form("efficiency_STE_GenAcc_over_LimAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE");
    heff->Write(Form("h_%s_effCFLimAccGenAcc",varname.Data()));
    h2num->Write(Form("h_%s_LimAcc",varname.Data()));
    h2->Write(Form("h_%s_GenAcc",varname.Data()));
  }
  else if( myEff == 2 ) {
    fout = new TFile(Form("efficiency_STE_RecPPR_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE");
    heff->Write(Form("h_%s_effCFRecPPRGenAcc",varname.Data()));
    h2num->Write(Form("h_%s_RecPPR",varname.Data()));
    h2->Write(Form("h_%s_GenAcc",varname.Data()));
  }
  else if( myEff == 3 ) {
    fout = new TFile(Form("efficiency_STE_RecPID_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE");
    heff->Write(Form("h_%s_effCFRecPIDGenAcc",varname.Data()));
    h2num->Write(Form("h_%s_RecPID",varname.Data()));
    h2->Write(Form("h_%s_GenAcc",varname.Data()));
  }
  else if( myEff == 4 ) {
    fout = new TFile(Form("efficiency_STE_Rec_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE");
    heff->Write(Form("h_%s_effCFRecGenAcc",varname.Data()));
    h2num->Write(Form("h_%s_Rec",varname.Data()));
    h2->Write(Form("h_%s_GenAcc",varname.Data()));
  }
  else if( myEff == 5 ) {
    fout = new TFile(Form("efficiency_STE_RecAcc_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE");
    heff->Write(Form("h_%s_effCFRecAccGenAcc",varname.Data()));
    h2num->Write(Form("h_%s_RecAcc",varname.Data()));
    h2->Write(Form("h_%s_GenAcc",varname.Data()));
  }
  else if( myEff == 6 ) {
    fout = new TFile(Form("efficiency_STE_RecPPRKine_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE");
    heff->Write(Form("h_%s_effCFRecPPRKineGenAcc",varname.Data()));
    h2num->Write(Form("h_%s_RecPPRKine",varname.Data()));
    h2->Write(Form("h_%s_GenAcc",varname.Data()));
  }
  fout->Close();

}
void advancedNoiseAnalysis( unsigned int runNumber, unsigned int loop = 1) {
  
  string inputFileName = "./histo/run00" + toString( runNumber ) + "-ped-histo.root";
  string outputFileName = "./histo/run00" + toString( runNumber ) + "-adv-noise.root";
  

  // before opening the input and the output files, try to see if they
  // are not opened yet and in case close them before continue   
  TList * listOfOpenedFile = (TList*) gROOT->GetListOfFiles();
  for ( int i = 0; i < listOfOpenedFile->GetSize() ; ++i ) {
    TFile * file = (TFile*) listOfOpenedFile->At( i ) ;
    TString fileName(file->GetName());
    TString inputFileName1( inputFileName.c_str() );
    TString outputFileName1( outputFileName.c_str() );

    if (  ( fileName.Contains( inputFileName1 ) ) ||
	  ( inputFileName1.Contains( fileName ) ) ||
	  ( fileName.Contains( outputFileName1 ) ) ||
	  ( outputFileName1.Contains( fileName ) ) ) {
      cout << "Closing " << fileName << " before reopen " << endl;
      file->Close();
    }
  }


  // close also all the previously opened canvas
  TList * listOfOpenedCanvas = (TList*) gROOT->GetListOfCanvases();
  for ( int i = 0 ; i < listOfOpenedCanvas->GetSize() ; ++i ) {
    TCanvas * canvas = (TCanvas*) listOfOpenedCanvas->At( i );
    TString canvasName2 = canvas->GetName();
    if ( canvasName2.Contains( "det" ) ) {
      canvas->Close();
    }
  }

	 
  // now safely open the file
  TFile * inputFile = TFile::Open( inputFileName.c_str() ) ;
  TFile * outputFile = TFile::Open( outputFileName.c_str(), "RECREATE") ;
  TList * outputHistoList = new TList;

  // look into the inputFile for a folder named
  string pedeProcessorFolderName = "PedestalAndNoiseCalculator";
  TDirectoryFile * pedeProcessorFolder = (TDirectoryFile*) inputFile->Get( pedeProcessorFolderName.c_str() );
  
  if ( pedeProcessorFolder == 0 ) { 
    cerr << "No pedestal processor folder found in file " << inputFileName << endl;
    return ;
  }

  // this folder should contain one folder for each loop.
  string loopFolderName = "loop-" + toString( loop );
  TDirectoryFile * loopFolder = (TDirectoryFile *) pedeProcessorFolder->Get( loopFolderName.c_str() );
  
  if ( loopFolder == 0 ) {
    cerr << "No " << loopFolderName << " found in file " << inputFileName << endl;
    return ;
  }

  // guess the number of sensors from the number of subfolder in the loopfolder
  size_t nDetector = loopFolder->GetListOfKeys()->GetSize();
  cout << "This file contains " << nDetector << " detectors" << endl;

  // prepare arrays to store the mean and the rms of the noise distribution
  if ( noiseMean == NULL ) {
    delete [] noiseMean;
    noiseMean = NULL;
  }
  if ( noiseRMS == NULL ) {
    delete [] noiseRMS;
    noiseRMS = NULL;
  }
  if ( channel == NULL ) {
    delete [] channel;
    channel = NULL;
  }

  noiseMean = new double[ nDetector * kNChan ];
  noiseRMS  = new double[ nDetector * kNChan ];
  channel   = new double[ kNChan ];

  string canvasName = "comparison";
  string canvasTitle = "Noise comparison";

  TCanvas * comparisonCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  comparisonCanvas->Divide(1,2);
  
  TPad * topPad = (TPad*) comparisonCanvas->cd(1);
  topPad->Divide( nDetector );
  
  TPad * middlePad = (TPad *) comparisonCanvas->cd(2);
  middlePad->Divide( kNChan );


  // for each detector we have to get the noise map and to prepare 4
  // separe histos and maps
  for ( unsigned int iDetector = 0; iDetector < nDetector; iDetector++ ) {

    // get the noise map.
    string noiseMapName = "detector-" + toString( iDetector ) ;
    noiseMapName += "/NoiseMap-d" + toString( iDetector )  ;
    noiseMapName += "-l" + toString( loop ) ;
 
    TH2D * noiseMap = ( TH2D* ) loopFolder->Get( noiseMapName.c_str() ); 
    

    // create a folder in the output file
    TDirectory * subfolder = outputFile->mkdir( string( "detector_" + toString( iDetector ) ).c_str(),
						string( "detector_" + toString( iDetector ) ).c_str()
						);
    subfolder->cd();

    
    string canvasName = "det" + toString( iDetector );
    string canvasTitle = "Detector " + toString( iDetector );
    
    TCanvas * canvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
    canvas->Divide( kNChan, 2 );

    // ok now start the loop on channels
    for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) { 
	
      if ( iDetector == 0 ) channel[iChan] = iChan - 0.5;

      string tempName = "NoiseMap_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      string tempTitle = "NoiseMap Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ;

      TH2D * noiseMapCh = new TH2D ( tempName.c_str() , tempTitle.c_str(), 
				     kXPixel / kNChan , -0.5 + xLimit[ iChan ] , -0.5 + xLimit[ iChan + 1 ],
				     kYPixel, -0.5, -0.5 + kYPixel );
      noiseMapCh->SetXTitle("X [pixel]");
      noiseMapCh->SetYTitle("Y [pixel]");
      noiseMapCh->SetZTitle("Noise [ADC]");
      noiseMapCh->SetStats( false );
      outputHistoList->Add( noiseMapCh ) ;

      tempName = "NoiseDist_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      
      tempTitle = "NoiseDist Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ; 

      TH1D * noiseDistCh = new TH1D( tempName.c_str(), tempTitle.c_str(), 50, 0., 10. );
      noiseDistCh->SetXTitle("Noise [ADC]");
      noiseDistCh->SetLineColor( kColor[iDetector]  );
      noiseDistCh->SetLineStyle( iChan + 2 );
      noiseDistCh->SetLineWidth( 2 );
      outputHistoList->Add( noiseDistCh );

      // let's start looping on pixels now
      for ( size_t yPixel = 1 ; yPixel <= kYPixel ; ++yPixel ) {
	for ( size_t xPixel = xLimit[ iChan ] + 1; xPixel <= xLimit[ iChan +1 ] ; ++xPixel ) {
	  double noise = noiseMap->GetBinContent( xPixel , yPixel );
	  noiseMapCh->Fill( xPixel - 1 , yPixel - 1, noise );
	  noiseDistCh->Fill( noise );
	  
	}
      }

      canvas->cd( iChan + 1 ) ;
      noiseMapCh->Draw("colz");
      canvas->cd( iChan + kNChan + 1  );
      noiseDistCh->Draw();
      
      topPad->cd( iDetector + 1 );
      if ( iChan == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }

      middlePad->cd( iChan + 1 );
      if ( iDetector == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }


      noiseMean[ kNChan * iDetector + iChan ] = noiseDistCh->GetMean();
      noiseRMS[ kNChan * iDetector  + iChan ] = noiseDistCh->GetRMS();
    }
    canvas->Write();

  }

  canvasName = "summary";
  canvasTitle = "Noise summary";

  TCanvas * summaryCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  summaryCanvas->SetGridx(1);
  TLegend * legend = new TLegend(0.5, 4.8, 1.5, 4.3,"","br");;
  

  for ( size_t iDetector = 0 ; iDetector < nDetector ; ++iDetector ) {
    
    TGraphErrors * gr = new TGraphErrors( kNChan, channel, &noiseMean[ iDetector * kNChan ], NULL, &noiseRMS[ iDetector * kNChan ] );
    gr->SetName( string( "NoisePerChannel_d" + toString( iDetector )).c_str());
    gr->SetTitle(string("Detector " + toString( iDetector )).c_str());
    gr->GetXaxis()->SetTitle("Channel #");
    gr->GetYaxis()->SetTitle("Noise [ADC]");
    gr->GetXaxis()->SetNdivisions( 5 );
    gr->GetXaxis()->SetLabelSize( 0 );
    gr->SetMarkerStyle( iDetector + 1 );
    gr->SetMarkerColor( kColor[iDetector] );
    gr->SetLineColor( kColor[iDetector] );
    gr->SetLineWidth( 2 );

    
    legend->AddEntry( gr, string("Detector " + toString( iDetector )).c_str(), "LP");

    if ( iDetector == 0 ) {
      gr->Draw("ALP");
    } else {
      gr->Draw("LP");
    }
    

  }

  
  
  legend->Draw();

  for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) {
    
    TPaveLabel * label = new TPaveLabel( iChan - 0.75 , 3.2 , iChan -0.25 , 3, string("Ch " + toString( iChan ) ).c_str());
    label->Draw();
  }


  summaryCanvas->Write();
  comparisonCanvas->Write();

  outputHistoList->Write();

  

 
} 
예제 #23
0
void drawCorrection(const char* filenameEffCont = "mergedAnalysisResults_proofPbPb_128.root"){

  gStyle->SetOptTitle(1);
  gStyle->SetOptStat(0);
  //gSystem->Load("libANALYSIS");
  //gSystem->Load("libANALYSISalice");
  Int_t markerStyle = 20;
  Int_t markerColor = 1;
  Int_t fillColor   = 9;

  //_______________________________________________________________//
  //Open the input file
  TFile *f = TFile::Open(filenameEffCont);
  if(!f->IsOpen()) {
    Printf("File not found!!!");
    break;
  }
  
  //_______________________________________________________________//
  //Get the TDirectoryFile
  TDirectoryFile *dirEffCont = dynamic_cast<TDirectoryFile *>(f->Get("PWGCFEbyE.outputBalanceFunctionEffContAnalysis"));
  if(!dirEffCont) {
    Printf("TDirectoryFile not found!!!");
    break;
  }

  //_______________________________________________________________//
  TList *listEffCont[nCentralityBins];
  TString listName;
  TString listName1;
  TString histName;
  TString histName1;

  TH3D* h1d[nCentralityBins];
  TH3D* h1n[nCentralityBins];
  TH3D* h2d[nCentralityBins];
  TH3D* h2n[nCentralityBins];
  TH3F* h3d[nCentralityBins];
  TH3F* h4d[nCentralityBins];
  TH3F* fHistCorrectionPlus[nCentralityBins];
  TH3F* fHistCorrectionMinus[nCentralityBins];

  TCanvas *correctionMatrix[nCentralityBins]; 
  TString canvasName;

  for(Int_t iBin = 0; iBin < nCentralityBins; iBin++) {
    Printf("================Centrality: %s================",  strCentrality[iBin].Data());
    
    listName = "listEffContBF_V0M_"; listName += strCentrality[iBin].Data(); listName +="_10";
    listName1 = "listQA_V0M_"; listName1 += strCentrality[iBin].Data(); listName1 +="_10";
    listEffCont[iBin] = dynamic_cast<TList *>(dirEffCont->Get(listName.Data()));
    listEffCont[iBin]->ls();

    //____________Efficiency Plus
    //correction->cd(1);
    h1d[iBin] = dynamic_cast<TH3D*>(listEffCont[iBin]->FindObject("fHistGeneratedEtaPtPhiPlus"));
    h1d[iBin]->Sumw2();
    h1n[iBin] = dynamic_cast<TH3D*>(listEffCont[iBin]->FindObject("fHistSurvivedEtaPtPhiPlus"));
    h1n[iBin]->Sumw2();
    h1n[iBin]->Divide(h1d[iBin]);
    //h1d->GetYaxis()->SetTitleOffset(1.5);
    //h1d->SetTitle("Efficiency (+)");
    //h1d->SetName("fHistEfficiencyPlus");
    //h1d->Draw("P");
    
    //____________Efficiency Minus
    //correction->cd(2);
    h2d[iBin] = dynamic_cast<TH3D*>(listEffCont[iBin]->FindObject("fHistGeneratedEtaPtPhiMinus"));
    h2d[iBin]->Sumw2();
    h2n[iBin] = dynamic_cast<TH3D*>(listEffCont[iBin]->FindObject("fHistSurvivedEtaPtPhiMinus"));
    h2n[iBin]->Sumw2();
    h2n[iBin]->Divide(h2d[iBin]);
    //h2d->GetYaxis()->SetTitleOffset(1.5);
    //h2d->SetTitle("Efficiency (-)");
    //h2d->SetName("fHistEfficiencyMinus");
    //h2d->Draw("P");
    
    //__________Contamination
    //correction->cd(3);
    h4d[iBin] = dynamic_cast<TH3F*>(listEffCont[iBin]->FindObject("fHistContaminationPrimaries"));
    h4d[iBin]->SetName("fHistContaminationPrimaries");
    h4d[iBin]->Sumw2();
  
    h3d[iBin] = dynamic_cast<TH3F*>(listEffCont[iBin]->FindObject("fHistContaminationSecondaries"));
    h3d[iBin]->SetName("fHistContaminationSecondaries");
    h3d[iBin]->Sumw2();

    h4d[iBin]->Add(h3d[iBin]);
    h3d[iBin]->Divide(h4d[iBin]);
    //h3d->GetYaxis()->SetTitleOffset(2.0);
    //h3d->GetXaxis()->SetTitleOffset(1.5);
    //h3d->SetTitle("Contamination Secondaries");
    //h3d->Draw("P");
 
    //_____________________________________________________________
    //CORRECTION

    Int_t binsX = h3d[0]->GetNbinsX();
    Int_t binsY = h3d[0]->GetNbinsY();
    Int_t binsZ = h3d[0]->GetNbinsZ();

    for (Int_t iHistBinsX = 1; iHistBinsX <binsX+1 ; iHistBinsX++) {
      for (Int_t iHistBinsY = 1; iHistBinsY <binsY+1 ; iHistBinsY++) {
	for (Int_t iHistBinsZ = 1; iHistBinsZ <binsZ+1 ; iHistBinsZ++) {
	  h3d[iBin]->SetBinContent(iHistBinsX,iHistBinsY,iHistBinsZ,1 - h3d[iBin]->GetBinContent(iHistBinsX,iHistBinsY,iHistBinsZ));
	}
      }
    }
        
    correctionMatrix[iBin] = new TCanvas(canvasName.Data(),canvasName.Data(),0,0+iBin*50,1400,1000);
    correctionMatrix[iBin]->Divide(2,1);
    
    //Correction Maps Plus 
    histName = "fHistCorrectionPlus"; 
    histName += strCentrality[iBin].Data();
    correctionMatrix[iBin]->cd(1);
    fHistCorrectionPlus[iBin] = dynamic_cast<TH3F *>(h3d[iBin]->Clone());
    fHistCorrectionPlus[iBin]->Divide(h1n[iBin]);  
    fHistCorrectionPlus[iBin]->SetName(histName.Data());
    fHistCorrectionPlus[iBin]->GetYaxis()->SetTitleOffset(2.0);
    fHistCorrectionPlus[iBin]->GetXaxis()->SetTitleOffset(1.5);
    fHistCorrectionPlus[iBin]->GetZaxis()->SetTitleOffset(2.0);
    fHistCorrectionPlus[iBin]->SetTitle("Correction Plus");
    fHistCorrectionPlus[iBin]->DrawCopy("");
    
    //Correction Maps Minus 
    histName1 = "fHistCorrectionMinus"; 
    histName1 += strCentrality[iBin].Data();
    correctionMatrix[iBin]->cd(2);
    fHistCorrectionMinus[iBin] = dynamic_cast<TH3F *>(h3d[iBin]->Clone());
    fHistCorrectionMinus[iBin]->Divide(h2n[iBin]);
    fHistCorrectionMinus[iBin]->SetName(histName1.Data());
    fHistCorrectionMinus[iBin]->GetYaxis()->SetTitleOffset(2.0);
    fHistCorrectionMinus[iBin]->GetXaxis()->SetTitleOffset(1.5);
    fHistCorrectionMinus[iBin]->GetZaxis()->SetTitleOffset(2.0);
    fHistCorrectionMinus[iBin]->SetTitle("Correction Minus");
    fHistCorrectionMinus[iBin]->DrawCopy("");
  }
  
  //____________________________________________________________
  //Output files
  TFile *fCorrectionMaps = TFile::Open("CorrectionMaps.root",
					  "recreate");
  
  for(Int_t iBin = 0; iBin < nCentralityBins; iBin++) {
    fHistCorrectionPlus[iBin]->Write();
    fHistCorrectionMinus[iBin]->Write();
  }
  fCorrectionMaps->Close();  
}
예제 #24
0
void makeMuonTimingPlot (std::string fname)
{
    TFile file(fname.c_str());
    TDirectoryFile *dir = (TDirectoryFile*)file.Get("Muons");

    TList *hlist = dir->GetListOfKeys();
    TH1F *h1;
    bool foundHist = false;
    for (auto hist : *hlist)    
    {
        TString name = hist->GetName();
        if (!name.Contains("hMuTimeP")) continue;

        TH1F *h0 = (TH1F*)dir->Get(name.Data());        
        if (!foundHist)
        {
            h1 = (TH1F*)h0->Clone();
            h1->Sumw2();
            foundHist = true;
        }
        else
        {
            h1->Add(h0);
        }        
    }

    TH1F *h2 = new TH1F("h2", "h2", 200, -100, 100);
    h2->GetXaxis()->SetTitle("muon time (ns)");
    h2->GetYaxis()->SetTitle("Fraction of Muons/ns");
    h2->GetYaxis()->SetTitleOffset(1.1);
    h2->GetXaxis()->SetTitleOffset(0.8);        
    h2->SetTitle("CSC Muon Time");
    h2->SetTitleFont(42);
    h2->SetTitleSize(0.052);    
 
    h2->Sumw2();
    h2->SetLineColor(kCyan+3);
    h2->SetFillColor(kCyan+3);

    for (int ibin = 1; ibin <= 200; ibin++)
    {
        h2->SetBinContent(ibin, h1->GetBinContent(ibin));
        h2->SetBinError(ibin, h1->GetBinError(ibin));
        if (ibin == 200)
            h2->SetEntries(h1->GetEntries());
    }
    
    TCanvas c1("c1", "c1", 600, 400);
    gStyle->SetOptStat("");

    double rms = h2->GetRMS();
    double avg = h2->GetMean();
    
    TLatex cms(0.17, 0.83, "CMS");
    cms.SetNDC();
    cms.SetTextFont(61);
    cms.SetTextSize(0.06);

    TLatex prelim(0.17, 0.81, "Preliminary");
    prelim.SetNDC();
    prelim.SetTextAlign(13);
    prelim.SetTextFont(52);
    prelim.SetTextSize(0.0456);

    TLatex data(0.17, 0.76, "Data 2016");
    data.SetNDC();
    data.SetTextAlign(13);
    data.SetTextFont(52);
    data.SetTextSize(0.0456);

    TLatex lumi(0.9, 0.93, "4.0 fb^{-1} (13 TeV)");
    lumi.SetNDC();
    lumi.SetTextAlign(31);
    lumi.SetTextFont(42);
    lumi.SetTextSize(0.052);    

    TLatex mean(0.7, 0.81, Form("Mean  %2.1f", avg));
    mean.SetNDC();
    mean.SetTextAlign(11);
    mean.SetTextFont(61);
    mean.SetTextSize(0.06);

    TLatex stdev(0.7, 0.76, Form("RMS   %2.1f", rms));
    stdev.SetNDC();
    stdev.SetTextAlign(11);
    stdev.SetTextFont(61);
    stdev.SetTextSize(0.06);

    h2->GetXaxis()->SetRangeUser(-6*rms,6*rms);   
    TH1F* h2norm = (TH1F*)h2->DrawNormalized("hist");
    gPad->Update();
    cms.Draw();
    prelim.Draw();
    data.Draw();
    lumi.Draw();
    mean.Draw();
    stdev.Draw();
    
    TPaveText *title = (TPaveText*)gPad->GetPrimitive("title");
    title->SetBorderSize(0);
    title->SetFillColor(0);
    title->SetFillStyle(0);    
    title->SetX1NDC(0.13);
    title->SetY1NDC(0.88);
    title->SetX2NDC(0.9);
    title->SetY2NDC(0.98);
    title->SetTextFont(42);
    title->SetTextSize(0.052);    
    title->SetTextAlign(11);
    
    c1.Print("plots/muon_time_all.pdf");
    c1.Print("plots/muon_time_all.png");
    c1.Print("plots/muon_time_all.root");
}
예제 #25
0
void mergeForest(TString fname = "/data/jisun/temp/*.root",
		 TString outfile="/data/jisun/pp_2015_HeavyFlavor_AOD_tkpt1_D0pt1_eta2p5_D3d1_Prob0p05_1202.root",
		 bool failOnError = true)
{
  // First, find on of the files within 'fname' and use it to make a
  // list of trees. Unfortunately we have to know in advance at least
  // one of the tree names. hiEvtAnalyzer/HiTree is a safe choice for
  // HiForests. We also assume that every TTree is inside a
  // TDirectoryFile which is in the top level of the root file.
  TChain *dummyChain = new TChain("hltanalysis/HltTree");
  dummyChain->Add(fname);
  TFile *testFile = dummyChain->GetFile();
  TList *topKeyList = testFile->GetListOfKeys();

  std::vector<TString> trees;
  std::vector<TString> dir;

  for(int i = 0; i < topKeyList->GetEntries(); ++i)
  {
    TDirectoryFile *dFile = (TDirectoryFile*)testFile->Get(topKeyList->At(i)->GetName());
    if(strcmp(dFile->ClassName(), "TDirectoryFile") != 0) continue;
    
    TList *bottomKeyList = dFile->GetListOfKeys();

    for(int j = 0; j < bottomKeyList->GetEntries(); ++j)
    {
      TString treeName = dFile->GetName();
      treeName += "/";
      treeName += bottomKeyList->At(j)->GetName();

      TTree* tree = (TTree*)testFile->Get(treeName);
      if(strcmp(tree->ClassName(), "TTree") != 0 && strcmp(tree->ClassName(), "TNtuple") != 0) continue;

      trees.push_back(treeName);
      dir.push_back(dFile->GetName());
    }
  }

  testFile->Close();
  delete dummyChain;

  // Now use the list of tree names to make a new root file, filling
  // it with the trees from 'fname'.
  const int Ntrees = trees.size();
  TChain* ch[Ntrees];

  Long64_t nentries = 0;
  for(int i = 0; i < Ntrees; ++i){
    ch[i] = new TChain(trees[i]);
    ch[i]->Add(fname);
    std::cout << "Tree loaded : " << trees[i] << std::endl;
    std::cout << "Entries : " << ch[i]->GetEntries() << std::endl;

    // If the number of entries in this tree is different from other
    // trees there is a problem. Quit and inform the user without
    // producing output.
    if(failOnError)
    {
      if(strcmp(trees[i],"HiForest/HiForestVersion") == 0) continue;
      if(i == 0) nentries = ch[i]->GetEntries();
      else if (nentries != ch[i]->GetEntries())
      {
	std::cout << "ERROR: number of entries in this tree does not match." << std::endl;
	std::cout << "First inconsistent file: " <<ch[i]->GetFile()->GetName()<<std::endl;
	std::cout << "Exiting. Please check input." << std::endl;
	return;
      }
    }
    else
    {
      std::cout << "WARN: error checking disabled" << std::endl;
    }
  }

  TFile* file = new TFile(outfile, "RECREATE");

  for(int i = 0; i < Ntrees; ++i)
  {
    file->cd();
    std::cout << trees[i] << std::endl;
    if (i==0)
    {
      file->mkdir(dir[i])->cd();
    }
    else
    {
      if ( dir[i] != dir[i-1] )
  	file->mkdir(dir[i])->cd();
      else
  	file->cd(dir[i]);
    }
    ch[i]->Merge(file,0,"keep");
    delete ch[i];
  }
  //file->Write();
  file->Close();

  std::cout << "Done. Output: " << outfile << std::endl;
}
예제 #26
0
Stat_t AnalysisClass::doFit(Int_t RunNumber,Char_t *Variable, Char_t *SubDetName, Char_t *Layer,Char_t *label){
  TH1 *htoFit=0; 
  pLanGausS[0]=0; pLanGausS[1]=0; pLanGausS[2]=0; pLanGausS[3]=0;
  epLanGausS[0]=0; epLanGausS[1]=0; epLanGausS[2]=0; epLanGausS[3]=0;

  if (debug)   cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) cout << "Found " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		htoFit = (TH1*) d3;
		if (debug) cout << "Found " << Variable << endl;
		
		if (htoFit->GetEntries()!=0) {
		  cout<<"Fitting "<< htoFit->GetTitle() <<endl;
		  // Setting fit range and start values
		  Double_t fr[2];
		  Double_t sv[4], pllo[4], plhi[4];
		  fr[0]=0.5*htoFit->GetMean();
		  fr[1]=3.0*htoFit->GetMean();
	      
		  // (EM) parameters setting good for signal only 
		  Int_t imax=htoFit->GetMaximumBin();
		  Double_t xmax=htoFit->GetBinCenter(imax);
		  Double_t ymax=htoFit->GetBinContent(imax);
		  Int_t i[2];
		  Int_t iArea[2];
	      
		  i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
		  i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
		  
		  iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
		  iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
		  Double_t AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width");
		  
		  sv[1]=xmax;
		  sv[2]=htoFit->Integral(i[0],i[1],"width");
		  sv[3]=AreaFWHM/(4*ymax);
		  sv[0]=sv[3];
		  
		  plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0;
		  pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0      ; pllo[3]= 1.0;
		  
		  // create different landau+gaussians for different runs
		  Char_t FunName[100];
		  sprintf(FunName,"FitfcnLG_%s%d",htoFit->GetName(),fRun);  
		  TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
		  if (ffitold) delete ffitold;
		  
		  langausFit = new TF1(FunName,langaufun,fr[0],fr[1],4);
		  langausFit->SetParameters(sv);
		  langausFit->SetParNames("Width","MP","Area","GSigma");
		  
		  for (Int_t i=0; i<4; i++) {
		    langausFit->SetParLimits(i,pllo[i],plhi[i]);
		  }  
		  
		  htoFit->Fit(langausFit,"R0");  // "R" fit in a range,"0" quiet fit
		  
		  langausFit->SetRange(fr[0],fr[1]);
		  pLanGausS=langausFit->GetParameters();
		  epLanGausS=langausFit->GetParErrors();
		  
		  chi2GausS =langausFit->GetChisquare();  // obtain chi^2
		  nDofGausS = langausFit->GetNDF();           // obtain ndf
		  
		  Double_t sPeak, sFWHM;
		  langaupro(pLanGausS,sPeak,sFWHM);
		  pLanConv[0]=sPeak;
		  pLanConv[1]=sFWHM;
		  cout << "langaupro:  max  " << sPeak << endl;
		  cout << "langaupro:  FWHM " << sFWHM << endl;
		  
		  TCanvas *cAll = new TCanvas("Fit",htoFit->GetTitle(),1);
		  Char_t fitFileName[60];
		  sprintf(fitFileName,"Fits/Run_%d/%s/Fit_%s.png",RunNumber,SubDetName,htoFit->GetTitle());
		  htoFit->Draw("pe");
		  htoFit->SetStats(100);
		  langausFit->Draw("lsame");
		  gStyle->SetOptFit(1111111);
		  
		  cAll->Print(fitFileName,"png");
		}
		else {  
		  pLanGausS[0]=-10; pLanGausS[1]=-10; pLanGausS[2]=-10; pLanGausS[3]=-10;
		  epLanGausS[0]=-10; epLanGausS[1]=-10; epLanGausS[2]=-10; epLanGausS[3]=-10;
		  pLanConv[0]=-10;   pLanConv[1]=-10;   chi2GausS=-10;  nDofGausS=-10;    
		}
	      }
	    }
	  }
	}
      }
    }
	
  return htoFit->GetEntries();
  
}
예제 #27
0
void drawDCAcontamination(){
gStyle->SetOptStat(0);
    TFile * file = TFile::Open("/Users/sandrobjelogrlic/Analysis/HFCorrelations/Results/MCCE/83_12022015/10f7a/AnalysisResults.root");
    
    TDirectoryFile * dir = (TDirectoryFile*)file->Get("PWGHF_HFCJ_SE_EffY_DEffY_vsPt_32_bins_SE_RECO_reco_2_348_sigmas");
    TList * list = (TList*)dir->Get("OutputMCSE_RECO");
    
    TH1D * isPhysPrimDCA = (TH1D*)list->FindObject("isPhysPrimDCA");
    TH1D * isSecondaryDCA = (TH1D*)list->FindObject("isSecondaryDCA");
    
    isPhysPrimDCA->GetXaxis()->SetRangeUser(0,2);
    
    isPhysPrimDCA->SetLineColor(2);
    isSecondaryDCA->SetLineColor(4);
     isPhysPrimDCA->SetTitle("; DCA_{XY} (cm); Counts");
    isPhysPrimDCA->GetYaxis()->SetTitleOffset(1.2);
    
    TPaveText * PaveText = new TPaveText(0.5,0.55,0.8,0.7,"NDC");
    PaveText->SetBorderSize(0);
    PaveText->SetFillColor(0);
    PaveText->SetName("pave");
   // PaveText->AddText("THIS THESIS");
   // PaveText->AddText(" ");
    PaveText->AddText("Phytia, pp #sqrt{s} = 7 TeV");
    //PaveText->AddText(" ");
   // PaveText->AddText("Fraction of Primary tracks as funct");
    
    TLine * cut = new TLine(0.25,0,0.25,10000000);
    cut->SetLineStyle(2);
    
    TLegend * legend = new TLegend(0.4,0.7,0.8,0.85);
    //  TLegend * legend = new TLegend(0.1, 1.2*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()),0.4, 1.6*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()));
    legend->SetFillColor(0);
    legend->SetTextSize(0.03);
    
    legend->SetBorderSize(0);
    legend->AddEntry(isPhysPrimDCA,"Primary tracks","l");
    legend->AddEntry(isSecondaryDCA,"Secondary tracks","l");
    legend->AddEntry(cut,"Standard cut, DCA_{XY} < 0.25 cm","l");
    //legend->AddEntry(h_Perugia2011,"Pythia, Perugia 2011 tune","lep");
    
    
    
    
    TCanvas * c1 = new TCanvas("c1","c1",0,0,1000,1000);
    c1->cd();
    c1->SetLogy();
    isPhysPrimDCA->Draw();
    isSecondaryDCA->Draw("same");
    legend->Draw("same");
    PaveText->Draw("same");
    cut->Draw("same");
    
    
    
   // cout << "Integral is " << getIntegral(DCA,isPhysPrimDCA) << endl;
    TLegend * legend2 = new TLegend(0.4,0.7,0.8,0.85);
    //  TLegend * legend = new TLegend(0.1, 1.2*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()),0.4, 1.6*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()));
    legend2->SetFillColor(0);
    legend2->SetTextSize(0.03);
    
    legend2->SetBorderSize(0);
 
    legend2->AddEntry(cut,"Standard cut, DCA_{XY} < 0.25 cm","l");
    
    TPaveText * PaveText2 = new TPaveText(0.5,0.3,0.8,0.5,"NDC");
    PaveText2->SetBorderSize(0);
    PaveText2->SetFillColor(0);
    PaveText2->SetName("pave2");
    // PaveText->AddText("THIS THESIS");
    // PaveText->AddText(" ");
    PaveText2->AddText("PYTHIA, pp #sqrt{s} = 7 TeV");
    TH1D * contamination = (TH1D*)isPhysPrimDCA->Clone("contamination");
    contamination->Reset();
    contamination->SetTitle("; DCA_{XY} (cm); Purity");
    
    contamination->GetYaxis()->SetRangeUser(0.8,1.05);
    contamination->GetXaxis()->SetRangeUser(0,1);
    contamination->SetLineColor(1);
    contamination->SetLineWidth(2);
    contamination->GetYaxis()->SetTitleOffset(1.4);


    Double_t dcavalue = 0;
    
    for(Int_t k=0; k<2000; k++){
     
        dcavalue += 0.001;
        contamination->SetBinContent(k+1,getPurity(dcavalue,isPhysPrimDCA,isSecondaryDCA));
    }
    
    TLine * cut2 = new TLine(0.25,0.8,0.25,1.05);
    cut2->SetLineStyle(2);
    
    TCanvas * c2 = new TCanvas("c2","c2",0,0,1000,1000); c2->cd();
    contamination->Draw();
    PaveText2->Draw("same");
    cut2->Draw("same");
    legend2->Draw("same");
    
    
     c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.pdf");
     c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.eps");
    c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.png");
     c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.root");
    c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.pdf");
     c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.png");
     c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.eps");
     c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.root");
   
}
예제 #28
0
void plotROC(TString input1, TString label1, TString input2 , TString label2,  TString input3,  TString label3, TString input4, TString label4,  TString input5,  TString label5  ){


	gROOT->SetStyle("Plain");
	gStyle->SetPadGridX(0);
	gStyle->SetPadGridY(0);
	gStyle->SetOptStat(0);
	TCanvas *cROC = new TCanvas("cROC","cROC", 700, 700);

	cROC->SetTickx(1);
	cROC->SetTicky(1);
	TLegend *leg = new TLegend(0.15625,0.321654,0.4765625,0.603839,NULL,"brNDC");
	leg->SetBorderSize(0);
	leg->SetTextSize(0.035);
	leg->SetLineColor(1);
	leg->SetLineStyle(1);
	leg->SetLineWidth(1);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);




	//TFile * _file0 = new TFile("TMVA_sL_optimized.root");
	//TFile * _file1 = new TFile ("TMVA_QCD_BBvsGSP_fat.root");
	TFile * file1 = new TFile(input1);
	file1->cd();
	TDirectoryFile * d = (TDirectoryFile *)file1->Get("Method_BDT/BDTG");
	d->cd();
	//cROC->cd();
	MVA_BDTG_rejBvsS->SetTitle("");
	MVA_BDTG_rejBvsS->SetLineColor(kBlue+1);
        MVA_BDTG_rejBvsS->SetLineWidth(3);
        MVA_BDTG_rejBvsS->Draw();
	leg->AddEntry(MVA_BDTG_rejBvsS, label1);
	if(input2!=""){
		TFile * file2 = new TFile(input2);
		file2->cd();
		TDirectoryFile * d2 = file2->Get("Method_BDT/BDTG");
		d2->cd();
		MVA_BDTG_rejBvsS->SetLineColor(kGreen+2);
		MVA_BDTG_rejBvsS->SetLineWidth(3);
		MVA_BDTG_rejBvsS->Draw("same");
		leg->AddEntry(MVA_BDTG_rejBvsS, label2);

	}
	if(input3!=""){
		TFile * file3 = new TFile(input3);
		file3->cd();
		TDirectoryFile * d3 = file3->Get("Method_BDT/BDTG");
		d3->cd();
		MVA_BDTG_rejBvsS->SetLineColor(kRed+2);
		MVA_BDTG_rejBvsS->SetLineWidth(3);
		MVA_BDTG_rejBvsS->Draw("same");
		leg->AddEntry(MVA_BDTG_rejBvsS, label3);
	
	}
	if(input4!=""){
		TFile * file4 = new TFile(input4);
		file4->cd();
		TDirectoryFile * d4 = file4->Get("Method_BDT/BDTG");
		d4->cd();
		MVA_BDTG_rejBvsS->SetLineColor(kOrange+2);
		MVA_BDTG_rejBvsS->SetLineWidth(3);
		MVA_BDTG_rejBvsS->Draw("same");
		leg->AddEntry(MVA_BDTG_rejBvsS, label4);
	
	}
	if(input5!=""){
		TFile * file5 = new TFile(input5);
		file5->cd();
		MVA_BDTG_rejBvsS->SetLineColor(kPink+2);
		MVA_BDTG_rejBvsS->SetLineWidth(3);	
		TDirectoryFile * d5 = file5->Get("Method_BDT/BDTG");
		d5->cd();
		MVA_BDTG_rejBvsS->Draw("same");
		leg->AddEntry(MVA_BDTG_rejBvsS, label5);

	}
	leg->Draw();
	cROC->Print("roc_.png");
}
예제 #29
0
//Noise section
Stat_t AnalysisClass::doNoiseFit(Int_t RunNumber, Char_t *Variable, Char_t *SubDetName, Char_t *Layer, Char_t *label){
  TH1 *hNtoFit=0;
  if (debug) cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) cout << "Found " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		hNtoFit = (TH1*) d3;
		if (debug) cout << "Found " << Variable << endl;
		if (hNtoFit->GetEntries()!=0) {
		  cout<<"Fitting "<< hNtoFit->GetTitle() <<endl;
		  // Setting fit range and start values
		  Double_t fr[2];
		  Double_t sv[3], pllo[3], plhi[3];
		  fr[0]=hNtoFit->GetMean()-5*hNtoFit->GetRMS();
		  fr[1]=hNtoFit->GetMean()+5*hNtoFit->GetRMS();
		  
		  Int_t imax=hNtoFit->GetMaximumBin();
		  Double_t xmax=hNtoFit->GetBinCenter(imax);
		  Double_t ymax=hNtoFit->GetBinContent(imax);
		  Int_t i[2];
		  Int_t iArea[2];
		  
		  i[0]=hNtoFit->GetXaxis()->FindBin(fr[0]);
		  i[1]=hNtoFit->GetXaxis()->FindBin(fr[1]);
		  
		  iArea[0]=hNtoFit->GetXaxis()->FindBin(fr[0]);
		  iArea[1]=hNtoFit->GetXaxis()->FindBin(fr[1]);
		  Double_t AreaFWHM=hNtoFit->Integral(iArea[0],iArea[1],"width");
		  
		  sv[2]=AreaFWHM/(4*ymax);
		  sv[1]=xmax;
		  sv[0]=hNtoFit->Integral(i[0],i[1],"width");
		  
		  plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.;
		  pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3;
		  Char_t FunName[100];
		  sprintf(FunName,"FitfcnLG_%s%d",hNtoFit->GetName(),fRun);
		  TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
		  if (ffitold) delete ffitold;
		  
		  gausFit = new TF1(FunName,Gauss,fr[0],fr[1],3);
		  gausFit->SetParameters(sv);
		  gausFit->SetParNames("Constant","GaussPeak","Sigma");
		  
		  for (Int_t i=0; i<3; i++) {
		    gausFit->SetParLimits(i,pllo[i],plhi[i]);
		  }
		  hNtoFit->Fit(gausFit,"R0");
		  
		  gausFit->SetRange(fr[0],fr[1]);
		  pGausS=gausFit->GetParameters();
		  epGausS=gausFit->GetParErrors();
		  
		  chi2GausS =langausFit->GetChisquare(); // obtain chi^2
		  nDofGausS = langausFit->GetNDF();// obtain ndf
		  
		  TCanvas *cAllN = new TCanvas("NoiseFit",hNtoFit->GetTitle(),1);
		  Char_t fitFileName[60];
		  sprintf(fitFileName,"Fits/Run_%d/%s/Fit_%s.png",RunNumber,SubDetName,hNtoFit->GetTitle());
		  hNtoFit->Draw("pe");
		  gStyle->SetOptFit(1111111);
		  gausFit->Draw("lsame");
   
		  cAllN->Print(fitFileName,"png");
		}else {
		  pGausS[0]=-10; pGausS[1]=-10; pGausS[2]=-10;
		  epGausS[0]=-10; epGausS[1]=-10; epGausS[2]=-10;
		}
	      }
	    }
	  }
	}
      }
    }
 
  return hNtoFit->GetEntries();
}
예제 #30
0
void DrawEfficiency(const char* channel, Int_t selection = 0, Int_t ieff = 7){

	gROOT->SetStyle("Plain");
	gStyle->SetPalette(1);
	gStyle->SetOptStat(0);
	gStyle->SetPalette(1);
	gStyle->SetCanvasColor(0);
	gStyle->SetFrameFillColor(0);
	gStyle->SetOptTitle(0);
	
	gSystem->SetIncludePath("-I. -I$ALICE_ROOT/include  -I$ROOTSYS/include");
	gSystem->Load("libANALYSIS");
	gSystem->Load("libANALYSISalice");
	gSystem->Load("$ALICE_ROOT/CORRFW/libCORRFW") ;
	gSystem->Load("libPWGHFbase");
	gSystem->Load("libPWGHFvertexingHF");
		
	Int_t mcAcc_over_mcLimAcc = 0x001;
	Int_t recPPR_over_mcAcc = 0x002;
	Int_t recPID_over_mcAcc = 0x004;

	// pt index
	Int_t ipt =0;

	Int_t stepNum = -1;
	Int_t stepDen = -1;
	
	// Read the  container from file
	TFile* f = new TFile("AnalysisResults.root");	
	TString directoryName;
	TString containerName;
	TString cutName;
	TString outfileName;

	if (channel == "D0") {
		if (selection == 0){
			directoryName = "PWG3_D2H_CFtaskD0toKpi";
			containerName = "CFHFccontainer0";
			cutName = "Cuts";
			outfileName = "fileEff_D0_from_c.root";
		}
		else if (selection == 1){
			directoryName = "PWG3_D2H_CFtaskD0toKpiKeepD0fromBOnly";
			containerName = "CFHFccontainer0D0fromB";
			cutName = "Cuts";
			outfileName = "fileEff_D0_from_b.root";
		}
		else if (selection == 2){
			directoryName = "PWG3_D2H_CFtaskD0toKpiKeepD0fromB";
			containerName = "CFHFccontainer0allD0";
			cutName = "Cuts";
			outfileName = "fileEff_D0_from_c_and_b.root";
		}
		else {
			Printf("not a valid selection, return");
			return;
		}
	}
	else if (channel == "D0_New"){
		if (selection == 0){
			directoryName = "PWG3_D2H_CFtaskD0toKpi_NEW";
			containerName = "CFHFccontainer0_New";
			cutName = "Cuts_New";
			//directoryName = "PWG3_D2H_CFtaskD0toKpi_CommonFramework";
			//containerName = "CFHFccontainer0_CommonFramework";
			//cutName = "Cuts_CommonFramework";
			outfileName = "fileEff_D0_CommonFramework_from_c.root";
		}
		else if (selection == 1){
			directoryName = "PWG3_D2H_CFtaskD0toKpiKeepDfromBOnly";
			containerName = "CFHFccontainer0DfromB_New";
			cutName = "Cuts_New";
			//directoryName = "PWG3_D2H_CFtaskD0toKpiKeepDfromBOnly_CommonFramework";
			//containerName = "CFHFccontainer0DfromB_CommonFramework";	
			//cutName = "Cuts_CommonFramework";
			outfileName = "fileEff_D0_CommonFramework_from_b.root";
		}
		else if (selection == 2){
			directoryName = "PWG3_D2H_CFtaskD0toKpiKeepDfromB_NEW";
			containerName = "CFHFccontainer0allD_New";
			cutName = "Cuts_New";
			//directoryName = "PWG3_D2H_CFtaskD0toKpiKeepDfromB_CommonFramework";
			//containerName = "CFHFccontainer0allD_CommonFramework";
			//cutName = "Cuts_CommonFramework";
			outfileName = "fileEff_D0_CommonFramework_from_c_and_b.root";
		}
		else {
			Printf("not a valid selection, return");
			return;
		}
	}
	else if (channel == "Dplus_New"){
		if (selection == 0){
			directoryName = "PWG3_D2H_CFtaskDplustoKpipi_NEW";
			containerName = "CFHFccontainer0_New_3Prong";
			cutName = "Cuts_3Prong";
			//directoryName = "PWG3_D2H_CFtaskDplustoKpipi_CommonFramework";
			//containerName = "CFHFccontainer0_3Prong_CommonFramework";
			//cutName =  "Cuts_3Prong_CommonFramework";
			outfileName = "fileEff_Dplus_CommonFramework_from_c.root";
		}
		else if (selection == 1){
			directoryName = "PWG3_D2H_CFtaskDplustoKpipiKeepDfromBOnly";
			containerName = "CFHFccontainer0DfromB_New_3Prong";
			cutName = "Cuts_3Prong";
			//directoryName = "PWG3_D2H_CFtaskDplustoKpipiKeepDfromBOnly_CommonFramework";
			//containerName = "CFHFccontainer0DfromB_3Prong_CommonFramework";
			//cutName =  "Cuts_3Prong_CommonFramework";
			outfileName = "fileEff_Dplus_CommonFramework_from_b.root";
		}
		else if (selection == 2){
			directoryName = "PWG3_D2H_CFtaskDplustoKpipiKeepDfromB_NEW";
			containerName = "CFHFccontainer0allD_New_3Prong";
			cutName = "Cuts_3Prong";
			//directoryName = "PWG3_D2H_CFtaskDplustoKpipiKeepDfromB_CommonFramework";
			//containerName = "CFHFccontainer0allD_3Prong_CommonFramework";
			//cutName =  "Cuts_3Prong_CommonFramework";
			outfileName = "fileEff_Dplus_CommonFramework_from_c_and_b.root";
		}
		else {
			Printf("not a valid selection, return");
			return;
		}
	}
	else {
		Printf("not a valid channel, return");
		return;
	}

	Printf("Opening file Analysisresults.root");
	Printf("Reading Directory \"%s\"",directoryName.Data());
	Printf("Getting CF Container \"%s\"",containerName.Data());
	Printf("Getting Cut Object \"%s\"",cutName.Data());


	TDirectoryFile* d = (TDirectoryFile*)f->Get(directoryName.Data());
	if (!d){
		Printf("Directory does not exist! Check directory name (%s) in file AnalysisResults.root - returning...", directoryName.Data());
		return;
	}
	AliCFContainer *data = (AliCFContainer*) (d->Get(containerName.Data()));
	AliRDHFCuts *cutsRDHF = (AliRDHFCuts*)(d->Get(cutName.Data()));

	if (!data){
		Printf("Container does not exist! Check container name (%s) in directory %s - returning...", containerName.Data(), directoryName.Data());
		return;
	}
	
	TFile* fileEff = new TFile(outfileName.Data(), "RECREATE");
	TString plotDir(Form("EffPlots/%s",channel));
	gSystem->Exec(Form("mkdir EffPlots"));
	gSystem->Exec(Form("mkdir %s",plotDir.Data()));
	
	//construct the efficiency grid from the data container 
	AliCFEffGrid *eff = new AliCFEffGrid("eff"," The efficiency",*data);

	TCanvas *ceffpt = new TCanvas("ceffpt","Efficiency vs pt",50,50,550,550);
	ceffpt->cd();
	ceffpt->SetLeftMargin(0.15);
	ceffpt->SetRightMargin(0.05);
	TH1D *hpteffCF = 0x0; //the efficiency vs pt

	if (ieff & mcAcc_over_mcLimAcc){
		AliCFEffGrid *eff = new AliCFEffGrid("eff"," The efficiency",*data);
		stepDen = (Int_t)(AliCFTaskVertexingHF::kStepGeneratedLimAcc);	
		stepNum = (Int_t)(AliCFTaskVertexingHF::kStepAcceptance);	
		printf("Calculating efficiency for mcAcc_over_mcLimAcc: stepDen = %d, stepNum = %d\n",stepDen,stepNum);	
		eff->CalculateEfficiency(stepNum,stepDen); //eff= step1/step0
		
		//canvas
		ceffpt->cd();

		//The efficiency along the variables
		hpteffCF = eff->Project(ipt); 
		SetHistoEff(hpteffCF,8,20,"mcAcc_over_mcLimAcc");
		hpteffCF->Draw("hist");
		hpteffCF->Draw("err same");
		fileEff->cd();
		hpteffCF->Write("hpteffCF_mcAcc_over_mcLimAcc");
		
		// printing png files
		ceffpt->Print(Form("%s/effpt_mcAcc_over_mcLimAcc.png", plotDir.Data()));
		ceffpt->Print(Form("%s/effpt_mcAcc_over_mcLimAcc.eps", plotDir.Data()));
		ceffpt->Print(Form("%s/effpt_mcAcc_over_mcLimAcc.gif", plotDir.Data()));
		delete eff;
		eff = 0x0;
	}

	if (ieff & recPPR_over_mcAcc){
		AliCFEffGrid *eff = new AliCFEffGrid("eff"," The efficiency",*data);
		stepDen = (Int_t)(AliCFTaskVertexingHF::kStepAcceptance);	
		stepNum = (Int_t)(AliCFTaskVertexingHF::kStepRecoPPR);	
		printf("Calculating efficiency for RecPPR_over_mcAcc: stepDen = %d, stepNum = %d\n",stepDen,stepNum);	
		eff->CalculateEfficiency(stepNum,stepDen); //eff= step1/step0
		
		//canvas
		ceffpt->cd();
		
		//The efficiency along the variables
		hpteffCF = eff->Project(ipt); 
		SetHistoEff(hpteffCF,8,20, "recAnCuts_over_mcAcc");
		hpteffCF->Draw("hist");
		hpteffCF->Draw("err same");
		fileEff->cd();
		hpteffCF->Write("hpteffCF_RecAnCut_over_mcAcc");
		
		// printing png files
		ceffpt->Print(Form("%s/effpt_RecAnCut_over_mcAcc.png", plotDir.Data()));
		ceffpt->Print(Form("%s/effpt_RecAnCut_over_mcAcc.eps", plotDir.Data()));
		ceffpt->Print(Form("%s/effpt_RecAnCut_over_mcAcc.gif", plotDir.Data()));
		delete eff;
		eff = 0x0;
	}

	if (ieff & recPID_over_mcAcc){
		AliCFEffGrid *eff = new AliCFEffGrid("eff"," The efficiency",*data);
		stepDen = (Int_t)(AliCFTaskVertexingHF::kStepAcceptance);	
		stepNum = (Int_t)(AliCFTaskVertexingHF::kStepRecoPID);	
		printf("Calculating efficiency for RecPID_over_mcAcc: stepDen = %d, stepNum = %d\n",stepDen,stepNum);	
		eff->CalculateEfficiency(stepNum,stepDen); //eff= step1/step0
		
		//canvas
		ceffpt->cd();
		
		//The efficiency along the variables
		hpteffCF = eff->Project(ipt); 
		SetHistoEff(hpteffCF,8,20,"recPID_over_mcAcc");
		hpteffCF->Draw("hist");
		hpteffCF->Draw("err same");
		fileEff->cd();
		hpteffCF->Write("hpteffCF_RecPID_over_mcAcc");
		
		// printing png files
		ceffpt->Print(Form("%s/effpt_RecPID_over_mcAcc.png", plotDir.Data()));
		ceffpt->Print(Form("%s/effpt_RecPID_over_mcAcc.eps", plotDir.Data()));
		ceffpt->Print(Form("%s/effpt_RecPID_over_mcAcc.gif", plotDir.Data()));
		delete eff;
		eff = 0x0;
	}
	
	cutsRDHF->Write("Cuts");

	// writing single distributions
	TH1D *hMCAccpt = data->ShowProjection(ipt, AliCFTaskVertexingHF::kStepAcceptance);
	SetHistoDistribution(hMCAccpt, 1, 20);
	hMCAccpt->Draw();
	TH1D *hMCLimAccpt = data->ShowProjection(ipt, AliCFHeavyFlavourTaskMultiVarMultiStep::kStepGeneratedLimAcc);
	SetHistoDistribution(hMCLimAccpt, 4, 20);
	TH1D *hRecoAnCutspt = data->ShowProjection(ipt, AliCFTaskVertexingHF::kStepRecoPPR);
	SetHistoDistribution(hRecoAnCutspt, 8, 20);
	TH1D *hRecoPIDpt = data->ShowProjection(ipt, AliCFTaskVertexingHF::kStepRecoPID);
	SetHistoDistribution(hRecoPIDpt, 6, 20);
	hMCAccpt->Write("hMCAccpt");
	hMCLimAccpt->Write("hMCLimAccpt");
	hRecoAnCutspt->Write("hRecoAnCutspt");
	hRecoPIDpt->Write("hRecoPIDpt");

	//	fileEff->Close(); // commented out to see the canvas on the screen....

}