00001 #include <iostream> 00002 #include <string.h> 00003 #include <fstream> 00004 #include <cmath> 00005 #include <TFile.h> 00006 #include <TH1F.h> 00007 #include <TMath.h> 00008 #include <TTree.h> 00009 #include "Utilities.h" 00010 00011 using namespace std; 00012 00013 int main(int argc, char**argv) 00014 { 00015 CommandLine c1; 00016 c1.parse(argc,argv); 00017 00018 std::string TreeFilename = c1.getValue<string> ("TreeFilename" ); 00019 std::string HistoFilename = c1.getValue<string> ("HistoFilename" ); 00020 bool UseRatioForResponse = c1.getValue<bool> ("UseRatioForResponse", true); 00021 bool IsPFJet = c1.getValue<bool> ("IsPFJet", false); 00022 int NJETS_MAX = c1.getValue<int> ("NJETS_MAX", 2); 00023 double JetPT_MIN = c1.getValue<double> ("JetPT_MIN", 1.0); 00024 double DR_MIN = c1.getValue<double> ("DR_MIN", 0.25); 00025 std::vector<double> pt_vec = c1.getVector<double>("RefPtBoundaries" ); 00026 std::vector<double> eta_vec = c1.getVector<double>("EtaBoundaries" ); 00027 if (!c1.check()) return 0; 00028 c1.print(); 00030 const int MAX_NETA = 83; 00031 const int MAX_NPT = 30; 00032 TH1F *hPtRef[MAX_NPT][MAX_NETA]; 00033 TH1F *hPtJet[MAX_NPT][MAX_NETA]; 00034 TH1F *hPtRefBarrel[MAX_NPT]; 00035 TH1F *hPtJetBarrel[MAX_NPT]; 00036 TH1F *hResponseBarrel[MAX_NPT]; 00037 TH1F *hResponse[MAX_NPT][MAX_NETA]; 00038 int NPT = pt_vec.size()-1; 00039 int NETA = eta_vec.size()-1; 00040 char name[1024]; 00041 bool cut_ptmin,cut_dR,cut_njets; 00042 float ptJet,ptGen,etaJet,emfJet,chfJet,etaGen,phiJet,phiGen,dR,resp; 00043 int rank; 00044 int i,j,ind_pt,ind_eta,responseBins(2200); 00045 double responseLow(-1000.),responseHigh(100.); 00046 unsigned int entry; 00047 if (UseRatioForResponse) 00048 { 00049 responseBins = 200; 00050 responseLow = 0.; 00051 responseHigh = 2; 00052 } 00053 std::vector<std::string> HistoNamesList; 00054 TFile *inf = new TFile(TreeFilename.c_str(),"R"); 00055 if (inf->IsZombie()) return(0); 00056 TFile *outf = new TFile(HistoFilename.c_str(),"RECREATE"); 00057 00058 TTree *tr = (TTree*)inf->Get("mcTruthTree"); 00059 TBranch *br_ptJet = (TBranch*)tr->GetBranch("ptJet"); 00060 br_ptJet->SetAddress(&ptJet); 00061 TBranch *br_ptGen = (TBranch*)tr->GetBranch("ptGen"); 00062 br_ptGen->SetAddress(&ptGen); 00063 TBranch *br_emfJet,*br_chfJet; 00064 if (!IsPFJet) 00065 { 00066 br_emfJet = (TBranch*)tr->GetBranch("emfJet"); 00067 br_emfJet->SetAddress(&emfJet); 00068 } 00069 else 00070 { 00071 br_chfJet = (TBranch*)tr->GetBranch("chfJet"); 00072 br_chfJet->SetAddress(&chfJet); 00073 } 00074 TBranch *br_etaJet = (TBranch*)tr->GetBranch("etaJet"); 00075 br_etaJet->SetAddress(&etaJet); 00076 TBranch *br_etaGen = (TBranch*)tr->GetBranch("etaGen"); 00077 br_etaGen->SetAddress(&etaGen); 00078 TBranch *br_phiJet = (TBranch*)tr->GetBranch("phiJet"); 00079 br_phiJet->SetAddress(&phiJet); 00080 TBranch *br_phiGen = (TBranch*)tr->GetBranch("phiGen"); 00081 br_phiGen->SetAddress(&phiGen); 00082 TBranch *br_dR = (TBranch*)tr->GetBranch("dR"); 00083 br_dR->SetAddress(&dR); 00084 TBranch *br_rank = (TBranch*)tr->GetBranch("rank"); 00085 br_rank->SetAddress(&rank); 00086 std::cout<<"Total entries:"<<tr->GetEntries()<<std::endl; 00087 if (NETA>1) 00088 { 00089 for (i=0;i<NPT;i++) 00090 { 00091 sprintf(name,"ptRef_RefPt%d_Barrel",i); 00092 hPtRefBarrel[i] = new TH1F(name,name,2000,0,2000); 00093 sprintf(name,"ptJet_RefPt%d_Barrel",i); 00094 hPtJetBarrel[i] = new TH1F(name,name,2000,0,2000); 00095 sprintf(name,"Response_RefPt%d_Barrel",i); 00096 hResponseBarrel[i] = new TH1F(name,name,responseBins,responseLow,responseHigh); 00097 for (j=0;j<NETA;j++) 00098 { 00099 sprintf(name,"ptRef_RefPt%d_Eta%d",i,j); 00100 hPtRef[i][j] = new TH1F(name,name,2000,0,2000); 00101 sprintf(name,"ptCalo_RefPt%d_Eta%d",i,j); 00102 hPtJet[i][j] = new TH1F(name,name,2000,0,2000); 00103 sprintf(name,"Response_RefPt%d_Eta%d",i,j); 00104 hResponse[i][j] = new TH1F(name,name,responseBins,responseLow,responseHigh); 00105 } 00106 } 00107 } 00108 else 00109 { 00110 for (i=0;i<NPT;i++) 00111 { 00112 sprintf(name,"ptRef_RefPt%d",i); 00113 hPtRefBarrel[i] = new TH1F(name,name,2000,0,2000); 00114 sprintf(name,"ptCalo_RefPt%d",i); 00115 hPtJetBarrel[i] = new TH1F(name,name,2000,0,2000); 00116 sprintf(name,"Response_RefPt%d",i); 00117 hResponseBarrel[i] = new TH1F(name,name,responseBins,responseLow,responseHigh); 00118 } 00119 } 00120 std::cout<<"Histograms booked"<<std::endl; 00121 for(entry=0;entry<tr->GetEntries();entry++) 00122 { 00123 if (entry % (tr->GetEntries()/10) == 0) 00124 std::cout<<"Entries: "<<entry<<std::endl; 00125 tr->GetEntry(entry); 00126 cut_ptmin = (ptJet>JetPT_MIN); 00127 cut_dR = (dR<DR_MIN); 00128 cut_njets = (rank<NJETS_MAX); 00129 if (cut_ptmin && cut_dR && cut_njets) 00130 { 00131 ind_pt = getBin(ptGen,pt_vec); 00132 ind_eta = getBin(etaJet,eta_vec); 00133 resp = 0.; 00134 if (UseRatioForResponse && ptGen>0) 00135 resp = ptJet/ptGen; 00136 else 00137 resp = ptJet - ptGen; 00138 if (NETA>1) 00139 { 00140 if (fabs(etaJet)<1.3 && ind_pt>=0) 00141 { 00142 hPtRefBarrel[ind_pt]->Fill(ptGen); 00143 hPtJetBarrel[ind_pt]->Fill(ptJet); 00144 hResponseBarrel[ind_pt]->Fill(resp); 00145 } 00146 if (ind_pt>=0 && ind_eta>=0 && NETA>1) 00147 { 00148 hPtRef[ind_pt][ind_eta]->Fill(ptGen); 00149 hPtJet[ind_pt][ind_eta]->Fill(ptJet); 00150 hResponse[ind_pt][ind_eta]->Fill(resp); 00151 } 00152 } 00153 if (NETA==1) 00154 if (ind_pt>=0) 00155 { 00156 hPtRefBarrel[ind_pt]->Fill(ptGen); 00157 hPtJetBarrel[ind_pt]->Fill(ptJet); 00158 hResponseBarrel[ind_pt]->Fill(resp); 00159 } 00160 } 00161 } 00162 outf->Write(); 00163 outf->Close(); 00164 }