Skip to content

Commit

Permalink
switch pfcandanalyzer to vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
R. Alex Barbieri committed Jan 20, 2016
1 parent 252ebc4 commit 2013f49
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 89 deletions.
19 changes: 9 additions & 10 deletions HeavyIonsAnalysis/JetAnalysis/interface/HiPFCandAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ inline float rndDP(float value, int nPlaces)
}

//----------------------------------------------------------------
const Int_t MAXPARTICLE = 10000;
//
// DiJet ana Event Data Tree definition
//
Expand All @@ -60,15 +59,15 @@ class TreePFCandEventData
Float_t jdphi_;
// -- particle info --
Int_t nPFpart_, nGENpart_, njets_;
Int_t pfId_[MAXPARTICLE], genPDGId_[MAXPARTICLE];
Float_t pfEnergy_[MAXPARTICLE], jetEnergy_[MAXPARTICLE];
Float_t pfPt_[MAXPARTICLE], genPt_[MAXPARTICLE], jetPt_[MAXPARTICLE];
Float_t pfEta_[MAXPARTICLE], genEta_[MAXPARTICLE], jetEta_[MAXPARTICLE];
Float_t pfPhi_[MAXPARTICLE], genPhi_[MAXPARTICLE], jetPhi_[MAXPARTICLE];
Float_t pfVsPt_[MAXPARTICLE];
Float_t pfVsPtInitial_[MAXPARTICLE];
Float_t pfVsPtEqualized_[MAXPARTICLE];
Float_t pfArea_[MAXPARTICLE];
std::vector<Int_t> pfId_, genPDGId_;
std::vector<Float_t> pfEnergy_, jetEnergy_;
std::vector<Float_t> pfPt_, genPt_, jetPt_;
std::vector<Float_t> pfEta_, genEta_, jetEta_;
std::vector<Float_t> pfPhi_, genPhi_, jetPhi_;
std::vector<Float_t> pfVsPt_;
std::vector<Float_t> pfVsPtInitial_;
std::vector<Float_t> pfVsPtEqualized_;
std::vector<Float_t> pfArea_;
Float_t sumpt[20];
Float_t vn[200];
Float_t psin[200];
Expand Down
134 changes: 55 additions & 79 deletions HeavyIonsAnalysis/JetAnalysis/src/HiPFCandAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ HiPFCandAnalyzer::HiPFCandAnalyzer(const edm::ParameterSet& iConfig)
etaBins_ = iConfig.getParameter<int>("etaBins");
fourierOrder_ = iConfig.getParameter<int>("fourierOrder");

doVS_ = iConfig.getUntrackedParameter<bool>("doVS",0);
doVS_ = iConfig.getUntrackedParameter<bool>("doVS",false);
if(doVS_){
edm::InputTag vsTag = iConfig.getParameter<edm::InputTag>("bkg");
srcVorFloat_ = consumes<std::vector<float> >(vsTag);
Expand All @@ -67,19 +67,20 @@ HiPFCandAnalyzer::HiPFCandAnalyzer(const edm::ParameterSet& iConfig)


// debug
verbosity_ = iConfig.getUntrackedParameter<int>("verbosity", 0);
verbosity_ = iConfig.getUntrackedParameter<int>("verbosity", false);

doJets_ = iConfig.getUntrackedParameter<bool>("doJets",0);
doJets_ = iConfig.getUntrackedParameter<bool>("doJets",false);
if(doJets_){
jetLabel_ = consumes<pat::JetCollection>(iConfig.getParameter<edm::InputTag>("jetLabel"));
}
doUEraw_ = iConfig.getUntrackedParameter<bool>("doUEraw",0);
doUEraw_ = iConfig.getUntrackedParameter<bool>("doUEraw",false);

doMC_ = iConfig.getUntrackedParameter<bool>("doMC",0);
doMC_ = iConfig.getUntrackedParameter<bool>("doMC",false);
std::cout << "doMC_ = " << doMC_ << std::endl;
if(doMC_){
genLabel_ = consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("genLabel"));
}
skipCharged_ = iConfig.getUntrackedParameter<bool>("skipCharged",0);
skipCharged_ = iConfig.getUntrackedParameter<bool>("skipCharged",false);



Expand All @@ -104,7 +105,6 @@ HiPFCandAnalyzer::~HiPFCandAnalyzer()
void
HiPFCandAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{

pfEvt_.Clear();

// Fill PF info
Expand Down Expand Up @@ -132,7 +132,7 @@ HiPFCandAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetu
pfEvt_.ueraw[iue] = vue[iue];
}
}

for(unsigned icand=0;icand<pfCandidateColl->size(); icand++) {
const reco::PFCandidate pfCandidate = pfCandidateColl->at(icand);
reco::CandidateViewRef ref(candidates_,icand);
Expand All @@ -153,19 +153,18 @@ HiPFCandAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetu
int id = pfCandidate.particleId();
if(skipCharged_ && (abs(id) == 1 || abs(id) == 3)) continue;

pfEvt_.pfId_[pfEvt_.nPFpart_] = id;
pfEvt_.pfPt_[pfEvt_.nPFpart_] = rndSF(pt,4);
pfEvt_.pfEnergy_[pfEvt_.nPFpart_] = rndSF(energy,4);
pfEvt_.pfVsPt_[pfEvt_.nPFpart_] = rndSF(vsPt,4);
pfEvt_.pfVsPtInitial_[pfEvt_.nPFpart_] = rndSF(vsPtInitial,4);
pfEvt_.pfArea_[pfEvt_.nPFpart_] = rndSF(vsArea,4);
pfEvt_.pfEta_[pfEvt_.nPFpart_] = rndDP(pfCandidate.eta(),3);
pfEvt_.pfPhi_[pfEvt_.nPFpart_] = rndDP(pfCandidate.phi(),3);
pfEvt_.pfId_.push_back( id );
pfEvt_.pfPt_.push_back( rndSF(pt,4) );
pfEvt_.pfEnergy_.push_back( rndSF(energy,4) );
pfEvt_.pfVsPt_.push_back( rndSF(vsPt,4) );
pfEvt_.pfVsPtInitial_.push_back( rndSF(vsPtInitial,4) );
pfEvt_.pfArea_.push_back( rndSF(vsArea,4) );
pfEvt_.pfEta_.push_back( rndDP(pfCandidate.eta(),3) );
pfEvt_.pfPhi_.push_back( rndDP(pfCandidate.phi(),3) );
pfEvt_.nPFpart_++;

}


// Fill GEN info
if(doMC_){
edm::Handle<reco::GenParticleCollection> genParticles;
Expand All @@ -179,10 +178,10 @@ HiPFCandAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetu
double pt = gen.pt();

if(gen.status()==1 && fabs(eta)<3.0 && pt> genPtMin_){
pfEvt_.genPDGId_[pfEvt_.nGENpart_] = gen.pdgId();
pfEvt_.genPt_[pfEvt_.nGENpart_] = rndSF(pt,4);
pfEvt_.genEta_[pfEvt_.nGENpart_] = rndDP(eta,3);
pfEvt_.genPhi_[pfEvt_.nGENpart_] = rndDP(gen.phi(),3);
pfEvt_.genPDGId_.push_back( gen.pdgId() );
pfEvt_.genPt_.push_back( rndSF(pt,4) );
pfEvt_.genEta_.push_back( rndDP(eta,3) );
pfEvt_.genPhi_.push_back( rndDP(gen.phi(),3) );
pfEvt_.nGENpart_++;
}
}
Expand All @@ -201,10 +200,10 @@ HiPFCandAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetu
double pt = jet.pt();
double energy = jet.energy();
if(pt>jetPtMin_){
pfEvt_.jetPt_[pfEvt_.njets_] = pt;
pfEvt_.jetEnergy_[pfEvt_.njets_] = energy;
pfEvt_.jetEta_[pfEvt_.njets_] = jet.eta();
pfEvt_.jetPhi_[pfEvt_.njets_] = jet.phi();
pfEvt_.jetPt_.push_back( pt );
pfEvt_.jetEnergy_.push_back( energy );
pfEvt_.jetEta_.push_back( jet.eta() );
pfEvt_.jetPhi_.push_back( jet.phi() );
pfEvt_.njets_++;
}
}
Expand All @@ -214,33 +213,6 @@ HiPFCandAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetu
pfTree_->Fill();
}

/*
void HiPFCandAnalyzer::FillEventInfo(const edm::Event& iEvent, const edm::EventSetup& iSetup, TreePFCandEventData & tr)
{
// General Info
tr.run_ = iEvent.id().run();
tr.evt_ = iEvent.id().event();
tr.lumi_ = iEvent.luminosityBlock();
if(!genOnly_&&sampleType_<10){
// HI Event info
edm::Handle<reco::Centrality> cent;
iEvent.getByLabel(edm::InputTag("hiCentrality"),cent);
Double_t hf = cent->EtHFhitSum();
// Get Centrality bin
cbins_ = getCentralityBinsFromDB(iSetup);
tr.cent_ = cbins_->getBin(hf)*(100./cbins_->getNbins());
}
if (isMC_&&sampleType_<10) {
edm::Handle<edm::GenHIEvent> mchievt;
iEvent.getByLabel(edm::InputTag("heavyIon"),mchievt);
tr.b_ = mchievt->b();
tr.npart_ = mchievt->Npart();
tr.ncoll_ = mchievt->Ncoll();
}
}
*/
void HiPFCandAnalyzer::beginJob()
{

Expand All @@ -256,22 +228,10 @@ void HiPFCandAnalyzer::beginJob()
// ------------ method called once each job just after ending the event loop ------------
void
HiPFCandAnalyzer::endJob() {
// ===== Done =====
/* if (verbosity_>=1) {
cout << endl << "================ Ana Process Summaries =============" << endl;
cout << " AnaJet: " << jetsrc_ << endl;
if (refJetType_>=0) cout << " RefJet: " << refjetsrc_ << endl;
cout << " AnaTrk: " << trksrc_ << endl;
cout << "# HI Events : "<< numHiEvtSel_<< endl;
cout << "# Base Events: "<< numEvtSel_ << endl;
cout << "# Jet Events: "<< numJetEvtSel_<< endl;
}
*/
}

// constructors
TreePFCandEventData::TreePFCandEventData(){

}


Expand All @@ -282,22 +242,20 @@ void TreePFCandEventData::SetBranches(int etaBins, int fourierOrder, bool doUEra

// -- particle info --
tree_->Branch("nPFpart",&(this->nPFpart_),"nPFpart/I");
tree_->Branch("pfId",this->pfId_,"pfId[nPFpart]/I");
tree_->Branch("pfPt",this->pfPt_,"pfPt[nPFpart]/F");
tree_->Branch("pfEnergy",this->pfEnergy_,"pfEnergy[nPFpart]/F");
//tree_->Branch("pfVsPt",this->pfVsPt_,"pfVsPt[nPFpart]/F");
tree_->Branch("pfVsPtInitial",this->pfVsPtInitial_,"pfVsPtInitial[nPFpart]/F");
//tree_->Branch("pfArea",this->pfArea_,"pfArea[nPFpart]/F");
tree_->Branch("pfId",&(this->pfId_));
tree_->Branch("pfPt",&(this->pfPt_));
tree_->Branch("pfEnergy",&(this->pfEnergy_));
tree_->Branch("pfVsPtInitial",&(this->pfVsPtInitial_));

tree_->Branch("pfEta",this->pfEta_,"pfEta[nPFpart]/F");
tree_->Branch("pfPhi",this->pfPhi_,"pfPhi[nPFpart]/F");
tree_->Branch("pfEta",&(this->pfEta_));
tree_->Branch("pfPhi",&(this->pfPhi_));

// -- jet info --
if(doJets){
tree_->Branch("njets",&(this->njets_),"njets/I");
tree_->Branch("jetPt",this->jetPt_,"jetPt[njets]/F");
tree_->Branch("jetEta",this->jetEta_,"jetEta[njets]/F");
tree_->Branch("jetPhi",this->jetPhi_,"jetPhi[njets]/F");
tree_->Branch("jetPt",&(this->jetPt_));
tree_->Branch("jetEta",&(this->jetEta_));
tree_->Branch("jetPhi",&(this->jetPhi_));
}

tree_->Branch("vn",this->vn,Form("vn[%d][%d]/F",fourierOrder,etaBins));
Expand All @@ -310,10 +268,10 @@ void TreePFCandEventData::SetBranches(int etaBins, int fourierOrder, bool doUEra
// -- gen info --
if(doMC){
tree_->Branch("nGENpart",&(this->nGENpart_),"nGENpart/I");
tree_->Branch("genPDGId",this->genPDGId_,"genPDGId[nGENpart]/I");
tree_->Branch("genPt",this->genPt_,"genPt[nGENpart]/F");
tree_->Branch("genEta",this->genEta_,"genEta[nGENpart]/F");
tree_->Branch("genPhi",this->genPhi_,"genPhi[nGENpart]/F");
tree_->Branch("genPDGId",&(this->genPDGId_));
tree_->Branch("genPt",&(this->genPt_));
tree_->Branch("genEta",&(this->genEta_));
tree_->Branch("genPhi",&(this->genPhi_));
}

}
Expand All @@ -324,6 +282,24 @@ void TreePFCandEventData::Clear()
nPFpart_ = 0;
njets_ = 0;
nGENpart_ = 0;

pfId_.clear();
genPDGId_.clear();
pfEnergy_.clear();
jetEnergy_.clear();
pfPt_.clear();
genPt_.clear();
jetPt_.clear();
pfEta_.clear();
genEta_.clear();
jetEta_.clear();
pfPhi_.clear();
genPhi_.clear();
jetPhi_.clear();
pfVsPt_.clear();
pfVsPtInitial_.clear();
pfVsPtEqualized_.clear();
pfArea_.clear();
}

DEFINE_FWK_MODULE(HiPFCandAnalyzer);

0 comments on commit 2013f49

Please sign in to comment.