示例#1
0
void makeCentralityTable(int nbins = 40, const string label = "hf", const char * tag = "HFhitBins", double MXS = 0.){

   // This macro assumes all inefficiency is in the most peripheral bin.
   double EFF = 1. - MXS;

   // Retrieving data
  int nFiles = 1;
  vector<string> infiles;
  //  TFile* infile = new TFile("/net/hisrv0001/home/yetkin/pstore02/ana/Hydjet_MinBias_d20100222/Hydjet_MinBias_4TeV_runs1to300.root");
  //  fwlite::Event event(infile);
  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs1to10.root");
  //  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs11to20.root");
  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs21to30.root");
  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs31to40.root");
  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs41to50.root");
  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs51to60.root");
  //  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs61to70.root");
  //  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs71to80.root");
  //  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs81to90.root")
  //  infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs91to100.root");

  fwlite::ChainEvent event(infiles);

  vector<int> runnums;

  // Creating output table
  TFile* outFile = new TFile("tables.root","update");
   TDirectory* dir = outFile->mkdir(tag);
   dir->cd();

  TH1D::SetDefaultSumw2();
  CentralityBins* bins = new CentralityBins("noname","Test tag", nbins);
  bins->table_.reserve(nbins);

  // Setting up variables & branches
  double binboundaries[nbinsMax+1];
  vector<float> values;

  // Determining bins of cross section
  // loop over events
  unsigned int events=0;
  for(event.toBegin(); !event.atEnd(); ++event, ++events){
     edm::EventBase const & ev = event;
    if( events % 100 == 0 ) cout<<"Processing event : "<<events<<endl;
    edm::Handle<edm::GenHIEvent> mc;
    ev.getByLabel(edm::InputTag("heavyIon"),mc);
    edm::Handle<reco::Centrality> cent;
    ev.getByLabel(edm::InputTag("hiCentrality"),cent);

    double b = mc->b();
    double npart = mc->Npart();
    double ncoll = mc->Ncoll();
    double nhard = mc->Nhard();

    double hf = cent->EtHFhitSum();
    double hftp = cent->EtHFtowerSumPlus();
    double hftm = cent->EtHFtowerSumMinus();
    double eb = cent->EtEBSum();
    double eep = cent->EtEESumPlus();
    double eem = cent->EtEESumMinus();

    double parameter = 0;
    if(label.compare("npart") == 0) parameter = npart;
    if(label.compare("ncoll") == 0) parameter = ncoll;
    if(label.compare("nhard") == 0) parameter = nhard;
    if(label.compare("b") == 0) parameter = b;
    if(label.compare("hf") == 0) parameter = hf;
    if(label.compare("hft") == 0) parameter = hftp + hftm;
    if(label.compare("eb") == 0) parameter = eb;
    if(label.compare("ee") == 0) parameter = eep+eem;

    values.push_back(parameter);
    
    int run = event.id().run();
    if(runnums.size() == 0 || runnums[runnums.size()-1] != run) runnums.push_back(run);
  }
  
  if(label.compare("b") == 0) sort(values.begin(),values.end(),descend);
  else sort(values.begin(),values.end());

  double max = values[events-1];
  binboundaries[nbins] = max;

  cout<<"-------------------------------------"<<endl;
  cout<<label.data()<<" based cuts are : "<<endl;
  cout<<"(";

  int bin = 0;
  for(int i = 0; i< nbins; ++i){
     // Find the boundary 
     int offset = (int)(MXS*events);
     double xsec = events*(1 + MXS);
     // Below should be replaced with an integral
     // when inefficiency is better parametrized 
     // than a step function.

     int entry = (int)(i*(xsec/nbins)) - offset;
     binboundaries[i] = values[entry];

     cout<<" "<<binboundaries[i];
     if(i < nbins - 1) cout<<",";
     else cout<<")"<<endl;
  }
  cout<<"-------------------------------------"<<endl;

  // Determining Glauber results in various bins
  TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,500,0,500);
  TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,2000,0,2000);
  TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,250,0,250);
  TH2D* hb = new TH2D("hb","",nbins,binboundaries,300,0,30);

  for(event.toBegin(); !event.atEnd(); ++event){
     edm::EventBase const & ev = event;
     edm::Handle<edm::GenHIEvent> mc;
     ev.getByLabel(edm::InputTag("heavyIon"),mc);
     edm::Handle<reco::Centrality> cent;
     ev.getByLabel(edm::InputTag("hiCentrality"),cent);

     double b = mc->b();
     double npart = mc->Npart();
     double ncoll = mc->Ncoll();
     double nhard = mc->Nhard();

     double hf = cent->EtHFhitSum();
     double hftp = cent->EtHFtowerSumPlus();
     double hftm = cent->EtHFtowerSumMinus();
     double eb = cent->EtEBSum();
     double eep = cent->EtEESumPlus();
     double eem = cent->EtEESumMinus();

     double parameter = 0;

     if(label.compare("npart") == 0) parameter = npart;
     if(label.compare("ncoll") == 0) parameter = ncoll;
     if(label.compare("nhard") == 0) parameter = nhard;
     if(label.compare("b") == 0) parameter = b;
     if(label.compare("hf") == 0) parameter = hf;
     if(label.compare("hft") == 0) parameter = hftp + hftm;
     if(label.compare("eb") == 0) parameter = eb;
     if(label.compare("ee") == 0) parameter = eep+eem;
    
     hNpart->Fill(parameter,npart);
     hNcoll->Fill(parameter,ncoll);
     hNhard->Fill(parameter,nhard);
     hb->Fill(parameter,b);
  }

  // Fitting Glauber distributions in bins to get mean and sigma values


  TF1* fGaus = new TF1("fb","gaus(0)",0,2); 
  fGaus->SetParameter(0,1);
  fGaus->SetParameter(1,0.04);
  fGaus->SetParameter(2,0.02); 
  
  fitSlices(hNpart,fGaus);
  fitSlices(hNcoll,fGaus);
  fitSlices(hNhard,fGaus);
  fitSlices(hb,fGaus);

 /*
  hNpart->FitSlicesY();
  hNcoll->FitSlicesY();
  hNhard->FitSlicesY();
  hb->FitSlicesY();
 */

  TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1");
  TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2");
  TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1");
  TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2");
  TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1");
  TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2");
  TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1");
  TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2");

  cout<<"-------------------------------------"<<endl;
  cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;


  // Enter values in table
  for(int i = 0; i < nbins; ++i){
     bins->table_[nbins-i-1].n_part_mean = hNpartMean->GetBinContent(i);
     bins->table_[nbins-i-1].n_part_var = hNpartSigma->GetBinContent(i);
     bins->table_[nbins-i-1].n_coll_mean = hNcollMean->GetBinContent(i);
     bins->table_[nbins-i-1].n_coll_var = hNcollSigma->GetBinContent(i);
     bins->table_[nbins-i-1].b_mean = hbMean->GetBinContent(i);
     bins->table_[nbins-i-1].b_var = hbSigma->GetBinContent(i);
     bins->table_[nbins-i-1].n_hard_mean = hNhardMean->GetBinContent(i);
     bins->table_[nbins-i-1].n_hard_var = hNhardSigma->GetBinContent(i);
     bins->table_[nbins-i-1].bin_edge = binboundaries[i];

     cout<<i<<" "
	 <<hNpartMean->GetBinContent(i)<<" "
	 <<hNpartSigma->GetBinContent(i)<<" "
	 <<hNcollMean->GetBinContent(i)<<" "
	 <<hNcollSigma->GetBinContent(i)<<" "
	 <<hbMean->GetBinContent(i)<<" "
	 <<hbSigma->GetBinContent(i)<<" "
	 <<binboundaries[i]<<" "
	 <<endl;
  }
  cout<<"-------------------------------------"<<endl;

  // Save the table in output file

  if(onlySaveTable){

     TH1D* hh = (TH1D*)gDirectory->Get("hNpart_0");
     hh->Delete();
     hh = (TH1D*)gDirectory->Get("hNcoll_0");
     hh->Delete();
     hh = (TH1D*)gDirectory->Get("hNhard_0");
     hh->Delete();
     hh = (TH1D*)gDirectory->Get("hb_0");
     hh->Delete();

     hNpart->Delete();
     hNpartMean->Delete();
     hNpartSigma->Delete();
     hNcoll->Delete();
     hNcollMean->Delete();
     hNcollSigma->Delete();
     hNhard->Delete();
     hNhardMean->Delete();
     hNhardSigma->Delete();
     hb->Delete();
     hbMean->Delete();
     hbSigma->Delete();
  }
  
  for(int i = 0; i < runnums.size(); ++i){
     CentralityBins* binsForRun = (CentralityBins*) bins->Clone();
     binsForRun->SetName(Form("run%d",runnums[i]));
     binsForRun->Write();
  }
  
  bins->Delete();
  outFile->Write();
  
}
示例#2
0
void makeTable(int nbins = 40, const string label = "HFhits", const char * tag = "Preliminary_NoEffCor_AMPT_d1107", const char* dataset = "DATA"){

  bool DATA = false;
  bool SIM = true;
  bool MC = false;
  double EFF = 1;
  double MXS = 1. - EFF;

   // Retrieving data
  int maxEvents = -200;
  vector<int> runnums;
  
  //  const char* infileName = Form("/net/hisrv0001/home/yetkin/hidsk0001/analysis/prod/%s_RECO_391/test.root",dataset);
  const char* infileName = Form("/net/hisrv0001/home/yetkin/hidsk0001/centrality/prod/%s/test.root",dataset);

  //  TFile* infile = new TFile(infileName,"read");
  TChain* t = new TChain("HltTree");
  //  TChain* t = new TChain("hltanalysis/HltTree");

  t->Add(infileName);

  // Creating output table
  TFile* outFile = new TFile("tables_d1108.root","update");
   TDirectory* dir = outFile->mkdir(tag);
   dir->cd();
   TNtuple* nt = new TNtuple("nt","","hf:bin:b:npart:ncoll:nhard");
   CentralityBins* bins = new CentralityBins("noname","Test tag", nbins);
   bins->table_.reserve(nbins);

  TH1D::SetDefaultSumw2();

  int runMC = 1;
  TFile * inputMCfile;
  CentralityBins* inputMCtable;
  
  if(DATA){
    inputMCfile = new TFile("tables_d1103.root","read");
    inputMCtable = (CentralityBins*)inputMCfile->Get("CentralityTable_HFhits40_AMPT2760GeV_v1_mc_MC_38Y_V12/run1");
  }

  // Setting up variables & branches
  double binboundaries[nbinsMax+1];
  vector<float> values;

  float b,npart,ncoll,nhard,hf,hfhit,eb,ee,etmr,parameter;
  int npix,ntrks;
  //  TTree* t = (TTree*)infile->Get("HltTree");
  int run;

  if(SIM){
    t->SetBranchAddress("b",&b);
    t->SetBranchAddress("Npart",&npart);
    t->SetBranchAddress("Ncoll",&ncoll);
    t->SetBranchAddress("Nhard",&nhard);
  }

  t->SetBranchAddress("hiHFhit",&hfhit);
  t->SetBranchAddress("hiHF",&hf);
  t->SetBranchAddress("hiEB",&eb);
  t->SetBranchAddress("hiEE",&ee);
  t->SetBranchAddress("hiET",&etmr);
  t->SetBranchAddress("hiNpix",&npix);
  t->SetBranchAddress("hiNtracks",&ntrks);
  t->SetBranchAddress("Run",&run);

  bool binNpart = label.compare("Npart") == 0;
  bool binNcoll = label.compare("Ncoll") == 0;
  bool binNhard = label.compare("Nhard") == 0;
  bool binB = label.compare("b") == 0;
  bool binHF = label.compare("HFtowers") == 0;
  bool binHFhit = label.compare("HFhits") == 0;
  bool binEB = label.compare("EB") == 0;
  bool binEE = label.compare("EE") == 0;
  bool binETMR = label.compare("ETMR") == 0;
  bool binNpix = label.compare("PixelHits") == 0;
  bool binNtrks = label.compare("Ntracks") == 0;

  // Determining bins of cross section
  // loop over events
  unsigned int events=t->GetEntries();
  for(unsigned int iev = 0; iev < events && (maxEvents < 0 || iev< maxEvents); ++iev){
    if( iev % 100 == 0 ) cout<<"Processing event : "<<iev<<endl;
    t->GetEntry(iev);

    if(binNpart) parameter = npart;
    if(binNcoll) parameter = ncoll;
    if(binNhard) parameter = nhard;
    if(binB) parameter = b;
    if(binHF) parameter = hf;
    if(binHFhit) parameter = hfhit;
    if(binEB) parameter = eb;
    if(binEE) parameter = ee;
    if(binETMR) parameter = etmr;
    if(binNpix) parameter = npix;
    if(binNtrks) parameter = ntrks;
 
    values.push_back(parameter);
    if(runnums.size() == 0 || runnums[runnums.size()-1] != run) runnums.push_back(run);
  }
  
  if(label.compare("b") == 0) sort(values.begin(),values.end(),descend);
  else sort(values.begin(),values.end());

  double max = values[events-1];
  binboundaries[nbins] = max;

  cout<<"-------------------------------------"<<endl;
  cout<<label.data()<<" based cuts are : "<<endl;
  cout<<"(";

  int bin = 0;
  double dev = events;
  for(int i = 0; i< nbins; ++i){
     // Find the boundary 
    int entry = (int)(i*(dev/nbins));
    binboundaries[i] = values[entry];

     cout<<" "<<binboundaries[i];
     if(i < nbins - 1) cout<<",";
     else cout<<")"<<endl;
  }

  cout<<"-------------------------------------"<<endl;

  if(!DATA){

  // Determining Glauber results in various bins
  dir->cd();
  TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,500,0,500);
  TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,2000,0,2000);
  TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,250,0,250);
  TH2D* hb = new TH2D("hb","",nbins,binboundaries,300,0,30);

  for(unsigned int iev = 0; iev < events && (maxEvents < 0 || iev< maxEvents); ++iev){
     if( iev % 100 == 0 ) cout<<"Processing event : "<<iev<<endl;
     t->GetEntry(iev);
     if(binNpart) parameter = npart;
     if(binNcoll) parameter = ncoll;
     if(binNhard) parameter = nhard;
     if(binB) parameter = b;
     if(binHF) parameter = hf;
     if(binHFhit) parameter = hfhit;
     if(binEB) parameter = eb;
     if(binEE) parameter = ee;
     if(binETMR) parameter = etmr;
     if(binNpix) parameter = npix;
     if(binNtrks) parameter = ntrks;
    
     hNpart->Fill(parameter,npart);
     hNcoll->Fill(parameter,ncoll);
     hNhard->Fill(parameter,nhard);
     hb->Fill(parameter,b);
     int bin = hNpart->GetXaxis()->FindBin(parameter) - 1;
     if(bin < 0) bin = 0;
     if(bin >= nbins) bin = nbins - 1;
     nt->Fill(hf,bin,b,npart,ncoll,nhard);
  }

  // Fitting Glauber distributions in bins to get mean and sigma values

  dir->cd();
  TF1* fGaus = new TF1("fb","gaus(0)",0,2); 
  fGaus->SetParameter(0,1);
  fGaus->SetParameter(1,0.04);
  fGaus->SetParameter(2,0.02); 
  
  fitSlices(hNpart,fGaus);
  fitSlices(hNcoll,fGaus);
  fitSlices(hNhard,fGaus);
  fitSlices(hb,fGaus);

  TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1");
  TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2");
  TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1");
  TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2");
  TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1");
  TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2");
  TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1");
  TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2");

  cout<<"-------------------------------------"<<endl;
  cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;

  // Enter values in table
  for(int i = 0; i < nbins; ++i){
     int ii = nbins-i;
     bins->table_[i].n_part_mean = hNpartMean->GetBinContent(ii);
     bins->table_[i].n_part_var = hNpartSigma->GetBinContent(ii);
     bins->table_[i].n_coll_mean = hNcollMean->GetBinContent(ii);
     bins->table_[i].n_coll_var = hNcollSigma->GetBinContent(ii);
     bins->table_[i].b_mean = hbMean->GetBinContent(ii);
     bins->table_[i].b_var = hbSigma->GetBinContent(ii);
     bins->table_[i].n_hard_mean = hNhardMean->GetBinContent(ii);
     bins->table_[i].n_hard_var = hNhardSigma->GetBinContent(ii);
     bins->table_[i].bin_edge = binboundaries[ii-1];

     cout<<i<<" "
	 <<hNpartMean->GetBinContent(ii)<<" "
	 <<hNpartSigma->GetBinContent(ii)<<" "
	 <<hNcollMean->GetBinContent(ii)<<" "
	 <<hNcollSigma->GetBinContent(ii)<<" "
	 <<hbMean->GetBinContent(ii)<<" "
	 <<hbSigma->GetBinContent(ii)<<" "
	 <<binboundaries[ii]<<" "
	 <<endl;
  }
  cout<<"-------------------------------------"<<endl;

  // Save the table in output file
  if(onlySaveTable){

     hNpart->Delete();
     hNpartMean->Delete();
     hNpartSigma->Delete();
     hNcoll->Delete();
     hNcollMean->Delete();
     hNcollSigma->Delete();
     hNhard->Delete();
     hNhardMean->Delete();
     hNhardSigma->Delete();
     hb->Delete();
     hbMean->Delete();
     hbSigma->Delete();
  }
 
  }else{
    cout<<"-------------------------------------"<<endl;
    cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;

    // Enter values in table
    for(int i = 0; i < nbins; ++i){
      int ii = nbins-i;
      bins->table_[i].n_part_mean = inputMCtable->NpartMeanOfBin(i);
      bins->table_[i].n_part_var = inputMCtable->NpartSigmaOfBin(i);
      bins->table_[i].n_coll_mean = inputMCtable->NcollMeanOfBin(i);
      bins->table_[i].n_coll_var = inputMCtable->NcollSigmaOfBin(i);
      bins->table_[i].b_mean = inputMCtable->bMeanOfBin(i);
      bins->table_[i].b_var = inputMCtable->bSigmaOfBin(i);
      bins->table_[i].n_hard_mean = inputMCtable->NhardMeanOfBin(i);
      bins->table_[i].n_hard_var = inputMCtable->NhardSigmaOfBin(i);
      bins->table_[i].bin_edge = binboundaries[ii-1];

      cout<<i<<" "
	  <<bins->table_[i].n_part_mean<<" "
          <<bins->table_[i].n_part_var<<" "
          <<bins->table_[i].n_coll_mean<<" "
          <<bins->table_[i].n_coll_var<<" "
          <<bins->table_[i].b_mean<<" "
          <<bins->table_[i].b_var<<" "
          <<bins->table_[i].n_hard_mean<<" "
          <<bins->table_[i].n_hard_var<<" "
          <<bins->table_[i].bin_edge<<" "<<endl;

    }
    cout<<"-------------------------------------"<<endl;

  }


  outFile->cd(); 
  dir->cd();

  bins->SetName(Form("run%d",1));
  bins->Write();
  nt->Write();  
  bins->Delete();
  outFile->Write();
  
}
示例#3
0
//------------------------------------------------------------------------
void makeSmearedTable(const int nbins = 100, const string label = "HFtowersPlusTrunc", const char * tag = "CentralityTable_HFtowersPlusTrunc_SmearedGlauber_sigma74_eff0_v5", int eff = 0) {

 TH1::SetDefaultSumw2();
 const char * inputMCforest = Form("/tmp/azsigmon/HiForest_pPb_Hijing_NEWFIX_v2.root");

 ProduceResponsePlots2(inputMCforest);

 bool plot = false;
 if(plot) {
   TCanvas *c1 = new TCanvas();
   Npart_vs_PtGenPlusEta4[0]->Draw("colz");
   TCanvas *c2 = new TCanvas();
   PtGenPlusEta4_vs_HFplusEta4[0]->Draw("colz");
   TCanvas *c3 = new TCanvas();
   Npart_vs_PtGenMinusEta4[0]->Draw("colz");
   TCanvas *c4 = new TCanvas();
   PtGenMinusEta4_vs_HFminusEta4[0]->Draw("colz");
   TCanvas *c5 = new TCanvas();
   Npart_vs_Ngentrk[0]->Draw("colz");
   TCanvas *c6 = new TCanvas();
   Ngentrk_vs_Ntracks[0]->Draw("colz");
 }

 bool binHFplusTrunc = label.compare("HFtowersPlusTrunc") == 0;
 bool binHFminusTrunc = label.compare("HFtowersMinusTrunc") == 0;
 bool binTracks = label.compare("Tracks") == 0;

 if (binHFplusTrunc) {
   getProjections(Npart_vs_PtGenPlusEta4[eff],Proj1,"Proj1",1,30);
   getProjections(PtGenPlusEta4_vs_HFplusEta4[eff],Proj2,"Proj2",1,140);
 }
 else if (binHFminusTrunc) {
   getProjections(Npart_vs_PtGenMinusEta4[0],Proj1,"Proj1",1,30);
   getProjections(PtGenMinusEta4_vs_HFminusEta4[0],Proj2,"Proj2",1,140);
 }
 else if (binTracks) {
   getProjections(Npart_vs_Ngentrk[0],Proj1,"Proj1",1,30);
   getProjections(Ngentrk_vs_Ntracks[0],Proj2,"Proj2",1,200);
 }

 //input Glauber ntuple
 const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/Standard/Phob_Glau_pPb_sNN70mb_v15_1M_dmin04.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/D/D04914/Phob_Glau_pPb_sNN70mb_v15_1M_D04914.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/D/D06006/Phob_Glau_pPb_sNN70mb_v15_1M_D06006.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/R/R649/Phob_Glau_pPb_sNN70mb_v15_1M_R649.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/R/R675/Phob_Glau_pPb_sNN70mb_v15_1M_R675.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/dmin/dmin00/Phob_Glau_pPb_sNN70mb_v15_1M_dmin00.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/dmin/dmin08/Phob_Glau_pPb_sNN70mb_v15_1M_dmin08.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/sigma/sigma66/Phob_Glau_pPb_sNN66mb_v15_1M_dmin04.root");
 //const char * infilename = Form("/afs/cern.ch/work/t/tuos/public/pPb/Glauber/1M/sigma/sigma74/Phob_Glau_pPb_sNN74mb_v15_1M_dmin04.root");
 TChain * t = new TChain("nt_p_Pb");
 t->Add(infilename);

 //output
 //const char* outfilename = "out/tables_Glauber2012B_AmptResponse_d20130116_v4.root";
 //const char* outfilename = "out/tables_Glauber2012B_EposLHCResponse_d20130118_v4.root";
 const char* outfilename = "out/tables_Glauber2012B_HijingResponse_d20130130_v5.root";
 TFile * outf = new TFile(outfilename,"update");
 outf->cd();
 TDirectory* dir = outf->mkdir(tag);
 dir->cd();
 TNtuple* nt = new TNtuple("nt","","HFbyPt:genPt:Bin:b:Npart:Ncoll:Nhard");
 CentralityBins * outputTable = new CentralityBins(Form("run%d",1), tag, nbins);
 outputTable->table_.reserve(nbins);

 ofstream txtfile("out/output.txt");
 txtfile << "Input Glauber tree: " << infilename << endl << "Input MC HiForest HIJING" << endl;

 //Setting up variables and branches
 double binboundaries[nbins+1];
 vector<float> values;

 float b, npart, ncoll, nhard, parameter;

 t->SetBranchAddress("B",&b);
 t->SetBranchAddress("Npart",&npart);
 t->SetBranchAddress("Ncoll",&ncoll);
 nhard = 0;

 //Event loop 1
 unsigned int Nevents = t->GetEntries();
 txtfile << "Number of events = " << Nevents << endl << endl;
 for(unsigned int iev = 0; iev < Nevents; iev++) {
   if(iev%20000 == 0) cout<<"Processing event: " << iev << endl;
   t->GetEntry(iev);

   if (binHFplusTrunc) parameter = getHFplusByPt(npart);
   if (binHFminusTrunc) parameter = getHFminusByPt(npart);
   if (binTracks) parameter = getTracksByGen(npart);

   values.push_back(parameter);
 }

 if(label.compare("b") == 0) sort(values.begin(),values.end(),descend);
 else sort(values.begin(),values.end());

 //Finding the bin boundaries
 txtfile << "-------------------------------------" << endl;
 txtfile << label.data() << " based cuts are: " << endl;
 txtfile << "(";

 int size = values.size();
 binboundaries[nbins] = values[size-1];

 for(int i = 0; i < nbins; i++) {
   int entry = (int)(i*(size/nbins));
   if(entry < 0 || i == 0) binboundaries[i] = 0;
   else binboundaries[i] = values[entry];
   txtfile << binboundaries[i] << ", ";
 }
 txtfile << binboundaries[nbins] << ")" << endl << "-------------------------------------" << endl;

 // Determining Glauber results in various bins
 TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,40,0,40);
 TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,40,0,40);
 TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,50,0,50);
 TH2D* hb = new TH2D("hb","",nbins,binboundaries,600,0,30);

 for(unsigned int iev = 0; iev < Nevents; iev++) {
   if( iev % 20000 == 0 ) cout<<"Processing event : " << iev << endl;
   t->GetEntry(iev);

   if (binHFplusTrunc) parameter = getHFplusByPt(npart);
   if (binHFminusTrunc) parameter = getHFminusByPt(npart);
   if (binTracks) parameter = getTracksByGen(npart);

   hNpart->Fill(parameter,npart);
   hNcoll->Fill(parameter,ncoll);
   hNhard->Fill(parameter,nhard);
   hb->Fill(parameter,b);

   int bin = hNpart->GetXaxis()->FindBin(parameter) - 1;
   if(bin < 0) bin = 0;
   if(bin >= nbins) bin = nbins - 1;
   nt->Fill(parameter, et, bin, b, npart, ncoll, nhard);
 }

 TCanvas *cf = new TCanvas();
 TF1* fGaus = new TF1("fb","gaus(0)",0,2);
 fitSlices(hNpart,fGaus);
 fitSlices(hNcoll,fGaus);
 fitSlices(hNhard,fGaus);
 fitSlices(hb,fGaus);

 TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1");
 TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2");
 TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1");
 TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2");
 TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1");
 TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2");
 TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1");
 TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2");

 txtfile<<"-------------------------------------"<<endl;
 txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;
 for(int i = 0; i < nbins; i++){
   int ii = nbins-i;
   outputTable->table_[i].n_part_mean = hNpartMean->GetBinContent(ii);
   outputTable->table_[i].n_part_var = hNpartSigma->GetBinContent(ii);
   outputTable->table_[i].n_coll_mean = hNcollMean->GetBinContent(ii);
   outputTable->table_[i].n_coll_var = hNcollSigma->GetBinContent(ii);
   outputTable->table_[i].b_mean = hbMean->GetBinContent(ii);
   outputTable->table_[i].b_var = hbSigma->GetBinContent(ii);
   outputTable->table_[i].n_hard_mean = hNhardMean->GetBinContent(ii);
   outputTable->table_[i].n_hard_var = hNhardSigma->GetBinContent(ii);
   outputTable->table_[i].bin_edge = binboundaries[ii-1];

   txtfile << i << " " << hNpartMean->GetBinContent(ii) << " " << hNpartSigma->GetBinContent(ii) << " " << hNcollMean->GetBinContent(ii) << " " << hNcollSigma->GetBinContent(ii) << " " << hbMean->GetBinContent(ii) << " " <<hbSigma->GetBinContent(ii) << " " << binboundaries[ii-1] << " " <<endl;
 }
 txtfile<<"-------------------------------------"<<endl;

 outf->cd();
 dir->cd();
 outputTable->Write();
 nt->Write();
 for(int ih = 0; ih < nhist; ih++) {
   Npart_vs_PtGenPlusEta4[ih]->Write();
   PtGenPlusEta4_vs_HFplusEta4[ih]->Write();
   Npart_vs_PtGenMinusEta4[ih]->Write();
   PtGenMinusEta4_vs_HFminusEta4[ih]->Write();
   Npart_vs_Ngentrk[ih]->Write();
   Ngentrk_vs_Ntracks[ih]->Write();
 }
 outf->Write();
 txtfile.close();

}
示例#4
0
void makeTable2(int nbins = 100, const string label = "HFtowersPlusTrunc", const char * tag = "CentralityTable_HFplus100_PA2012B_v538x01_offline", bool isMC = false, int runNum = 1) {

 TH1D::SetDefaultSumw2();

 //Intput files with HiTrees
 const int nTrees = 1;
 //string inFileNames[nTrees] = {"/tmp/azsigmon/HiForest_pPb_Hijing_NEWFIX_v2.root"};
 //string inFileNames[nTrees] = {"/tmp/azsigmon/HiForest_pPb_Epos_336800.root"};
 string inFileNames[nTrees] = {"/tmp/azsigmon/PA2013_HiForest_Express_r0_pilot_minbias_v0.root"};
 TChain * t = new TChain("hiEvtAnalyzer/HiTree");
 for (int i = 0; i<nTrees; i++) {
    t->Add(inFileNames[i].data());
 }

 //Output files and tables
 TFile * outFile = new TFile("out/datatables_Glauber2012B_d20130121_v5.root","recreate");
 //TFile * outFile = new TFile("out/tables_Ampt_d20121115_v3.root","update");
 //TFile * outFile = new TFile("out/tables_Epos_d20121115_v3.root","update");
 //TFile * outFile = new TFile("out/tables_Hijing_d20130119_v4.root","update");
 TDirectory* dir = outFile->mkdir(tag);
 dir->cd();
 TNtuple * nt = new TNtuple("nt","","value:bin:b:npart:ncoll:nhard");
 CentralityBins * bins = new CentralityBins(Form("run%d",runNum), tag, nbins);
 bins->table_.reserve(nbins);

 ofstream txtfile("out/output.txt");
 txtfile << "First input tree: " << inFileNames[0].data() << endl;

 //For data extra inputfile with Glauber centrality table and efficiency file
 TFile * effFile;
 TH1F * hEff; 
 TFile * inputMCfile;
 CentralityBins* inputMCtable;
 if(!isMC){
   //effFile = new TFile("out/efficiencies_Ampt.root","read");
   //effFile = new TFile("out/efficiencies_Hijing.root","read");
   effFile = new TFile("out/efficiencies_EposLHC_v2.root","read");
   hEff = (TH1F*)effFile->Get(Form("%s/hEff",label.data()));
   //inputMCfile = new TFile("out/tables_Glauber2012_AmptResponse_d20121115_v3.root","read");
   //inputMCfile = new TFile("out/tables_Glauber2012_HijingResponse_d20121115_v3.root","read");
   inputMCfile = new TFile("out/tables_Glauber2012B_EposLHCResponse_d20130118_v4.root","read");
   inputMCtable = (CentralityBins*)inputMCfile->Get(Form("CentralityTable_%s_SmearedGlauber_v4/run1",label.data()));
   //txtfile << "Using AMPT efficiency and AMPT smeared Glauber table" << endl << endl;
   txtfile << "Using EPOS efficiency and EPOS smeared Glauber table" << endl << endl;
   //txtfile << "Using HIJING efficiency and HIJING smeared Glauber table" << endl << endl;
 }

 //Setting up variables and branches
 double binboundaries[nbins+1];
 vector<float> values;
 TH1F * hist;
 if(!isMC) hist = new TH1F("hist","",hEff->GetNbinsX(),hEff->GetBinLowEdge(1),hEff->GetBinLowEdge(hEff->GetNbinsX()));

 float vtxZ, b, npart, ncoll, nhard, hf, hfplus, hfpluseta4, hfminuseta4, hfminus, hfhit, ee, eb;
 int run, npix, npixtrks, ntrks;
 t->SetBranchAddress("vz",&vtxZ);
 t->SetBranchAddress("run",&run);
 if(isMC){
    t->SetBranchAddress("b",&b);
    t->SetBranchAddress("Npart",	&npart);
    t->SetBranchAddress("Ncoll",	&ncoll);
    t->SetBranchAddress("Nhard",	&nhard);
 }
 t->SetBranchAddress("hiHF",		&hf);
 t->SetBranchAddress("hiHFplus",	&hfplus);
 t->SetBranchAddress("hiHFplusEta4",	&hfpluseta4);
 t->SetBranchAddress("hiHFminus",	&hfminus);
 t->SetBranchAddress("hiHFminusEta4",	&hfminuseta4);
 t->SetBranchAddress("hiHFhit",		&hfhit);
 t->SetBranchAddress("hiEE",		&ee);
 t->SetBranchAddress("hiEB",		&eb);
 t->SetBranchAddress("hiNpix",		&npix);
 t->SetBranchAddress("hiNpixelTracks",	&npixtrks);
 t->SetBranchAddress("hiNtracks",	&ntrks);
 //t->SetBranchAddress("hiNtracksOffline",	&ntrks);

 bool binB = label.compare("b") == 0;
 bool binNpart = label.compare("Npart") == 0;
 bool binNcoll = label.compare("Ncoll") == 0;
 bool binNhard = label.compare("Nhard") == 0;
 bool binHF = label.compare("HFtowers") == 0;
 bool binHFplus = label.compare("HFtowersPlus") == 0;
 bool binHFminus = label.compare("HFtowersMinus") == 0;
 bool binHFplusTrunc = label.compare("HFtowersPlusTrunc") == 0;
 bool binHFminusTrunc = label.compare("HFtowersMinusTrunc") == 0;
 bool binNpix = label.compare("PixelHits") == 0;
 bool binNpixTrks = label.compare("PixelTracks") == 0;
 bool binNtrks = label.compare("Tracks") == 0;

 //Event loop
 unsigned int Nevents = t->GetEntries();
 txtfile << "Number of events = " << Nevents << endl << endl;
 for(unsigned int iev = 0; iev < Nevents; iev++) {
   if(iev%10000 == 0) cout<<"Processing event: " << iev << endl;
   t->GetEntry(iev);

   //if(run!=runNum) continue;

   float parameter = -1;
   if(binB) parameter = b;
   if(binNpart) parameter = npart;
   if(binNcoll) parameter = ncoll;
   if(binNhard) parameter = nhard;
   if(binHF) parameter = hf;
   if(binHFplus) parameter = hfplus;
   if(binHFminus) parameter = hfminus;
   if(binHFplusTrunc) parameter = hfpluseta4;
   if(binHFminusTrunc) parameter = hfminuseta4;
   if(binNpix) parameter = npix;
   if(binNpixTrks) parameter = npixtrks;
   if(binNtrks) parameter = ntrks;

   values.push_back(parameter);

   if(!isMC) {
     hist->Fill(parameter);
   }

 }

 //Sorting the centrality variable vector
 if(binB) sort(values.begin(),values.end(),descend);
 else sort(values.begin(),values.end());

 //Finding the bin boundaries
 txtfile << "-------------------------------------" << endl;
 txtfile << label.data() << " based cuts are: " << endl;
 txtfile << "(";

 int size = values.size();
 binboundaries[nbins] = values[size-1];

 if(isMC) {
   for(int i = 0; i < nbins; i++) {
      int entry = (int)(i*(size/nbins));
      if(entry < 0 || i == 0) binboundaries[i] = 0;
      else binboundaries[i] = values[entry];
   }
 }
 else {
      TH1F * corr = (TH1F*)hist->Clone("corr");
      //TCanvas *c1 = new TCanvas();
      //c1->SetLogy();
      //corr->DrawCopy("hist");
      for (int j=1; j<corr->GetNbinsX(); j++) {
        if (hEff->GetBinContent(j) != 0) {
          corr->SetBinContent(j,corr->GetBinContent(j)/hEff->GetBinContent(j));
          corr->SetBinError(j,corr->GetBinError(j)/hEff->GetBinContent(j));
        }
      }
      //corr->SetLineColor(2);
      //corr->DrawCopy("hist same");
      //cout << "total integral = " << corr->Integral();
      float prev = 0;
      binboundaries[0] = 0;
      int j = 1;
      for (int i = 1; i < corr->GetNbinsX(); i++) {
        if(j>=nbins) continue;
        float a = corr->Integral(1,i,"");
        a = a/corr->Integral();
	//if(i<100) cout << i << " bin in x fraction of total integral = " << a << " j = " << j << endl;
        if (a > (float)j/nbins && prev < (float)j/nbins) {
		binboundaries[j] = corr->GetBinLowEdge(i+1);
		j++;
	}
        prev = a;
      }
 }
 for(int i = 0; i < nbins; i++) {
  if(binboundaries[i] < 0) binboundaries[i] = 0;
  txtfile << binboundaries[i] << ", ";
 }
 txtfile << binboundaries[nbins] << ")" << endl << "-------------------------------------" << endl;

 //***Determining Glauber results for MC and filling the table***
 if(isMC) {

  dir->cd();
  TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,40,0,40);
  TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,40,0,40);
  TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,50,0,50);
  TH2D* hb = new TH2D("hb","",nbins,binboundaries,600,0,30);

  for(unsigned int iev = 0; iev < Nevents; iev++) {
     if( iev % 5000 == 0 ) cout<<"Processing event : " << iev << endl;
     t->GetEntry(iev);

     float parameter = -1;
     if(binB) parameter = b;
     if(binNpart) parameter = npart;
     if(binNcoll) parameter = ncoll;
     if(binNhard) parameter = nhard;
     if(binHF) parameter = hf;
     if(binHFplus) parameter = hfplus;
     if(binHFminus) parameter = hfminus;
     if(binHFplusTrunc) parameter = hfpluseta4;
     if(binHFminusTrunc) parameter = hfminuseta4;
     if(binNpix) parameter = npix;
     if(binNpixTrks) parameter = npixtrks;
     if(binNtrks) parameter = ntrks;

     hNpart->Fill(parameter,npart);
     hNcoll->Fill(parameter,ncoll);
     hNhard->Fill(parameter,nhard);
     hb->Fill(parameter,b);
     int bin = hNpart->GetXaxis()->FindBin(parameter) - 1;
     if(bin < 0) bin = 0;
     if(bin >= nbins) bin = nbins - 1;
     nt->Fill(parameter,bin,b,npart,ncoll,nhard);
  }

  TF1* fGaus = new TF1("fb","gaus(0)",0,2);
  fitSlices(hNpart,fGaus);
  fitSlices(hNcoll,fGaus);
  fitSlices(hNhard,fGaus);
  fitSlices(hb,fGaus);

  TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1");
  TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2");
  TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1");
  TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2");
  TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1");
  TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2");
  TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1");
  TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2");

  txtfile<<"-------------------------------------"<<endl;
  txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;
  for(int i = 0; i < nbins; i++){
     int ii = nbins-i;
     bins->table_[i].n_part_mean = hNpartMean->GetBinContent(ii);
     bins->table_[i].n_part_var = hNpartSigma->GetBinContent(ii);
     bins->table_[i].n_coll_mean = hNcollMean->GetBinContent(ii);
     bins->table_[i].n_coll_var = hNcollSigma->GetBinContent(ii);
     bins->table_[i].b_mean = hbMean->GetBinContent(ii);
     bins->table_[i].b_var = hbSigma->GetBinContent(ii);
     bins->table_[i].n_hard_mean = hNhardMean->GetBinContent(ii);
     bins->table_[i].n_hard_var = hNhardSigma->GetBinContent(ii);
     bins->table_[i].bin_edge = binboundaries[ii-1];

     txtfile << i << " " << hNpartMean->GetBinContent(ii) << " " << hNpartSigma->GetBinContent(ii) << " " << hNcollMean->GetBinContent(ii) << " " << hNcollSigma->GetBinContent(ii) << " " << hbMean->GetBinContent(ii) << " " <<hbSigma->GetBinContent(ii) << " " << binboundaries[ii-1] << " " <<endl;
  }
  txtfile<<"-------------------------------------"<<endl;

 } //***end of MC part***

 else { //***Data table with inputMCtable***

    txtfile<<"-------------------------------------"<<endl;
    txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;
    for(int i = 0; i < nbins; i++){
      int ii = nbins-i;
      bins->table_[i].n_part_mean = inputMCtable->NpartMeanOfBin(i);
      bins->table_[i].n_part_var = inputMCtable->NpartSigmaOfBin(i);
      bins->table_[i].n_coll_mean = inputMCtable->NcollMeanOfBin(i);
      bins->table_[i].n_coll_var = inputMCtable->NcollSigmaOfBin(i);
      bins->table_[i].b_mean = inputMCtable->bMeanOfBin(i);
      bins->table_[i].b_var = inputMCtable->bSigmaOfBin(i);
      bins->table_[i].n_hard_mean = inputMCtable->NhardMeanOfBin(i);
      bins->table_[i].n_hard_var = inputMCtable->NhardSigmaOfBin(i);
      bins->table_[i].ecc2_mean  = inputMCtable->eccentricityMeanOfBin(i);
      bins->table_[i].ecc2_var = inputMCtable->eccentricitySigmaOfBin(i);
      bins->table_[i].bin_edge = binboundaries[ii-1];

      txtfile << i << " " << bins->table_[i].n_part_mean << " " << bins->table_[i].n_part_var << " " << bins->table_[i].n_coll_mean << " " << bins->table_[i].n_coll_var << " " <<bins->table_[i].b_mean << " " << bins->table_[i].b_var << " " << bins->table_[i].n_hard_mean << " " << bins->table_[i].n_hard_var << " " << bins->table_[i].bin_edge << " " << endl;
    }
    txtfile<<"-------------------------------------"<<endl;

 } //***end of Data part***

 outFile->cd();
 dir->cd();
 bins->Write();
 nt->Write();  
 bins->Delete();
 outFile->Write();
 txtfile.close();

}