Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major JME developments for 73x #6273

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b3156a0
Puppi's First Commit
violatingcp Sep 23, 2014
1aeb9a5
Small fixes to Puppi
violatingcp Sep 23, 2014
b85a249
fixed bugs so Sal can take over
violatingcp Oct 22, 2014
d0c7938
Adding new fastjet 3.1.0 features.
rappoccio Oct 2, 2014
e9f404c
Merged rappoccio_fj310_73x_rebase from repository rappoccio
rappoccio Nov 3, 2014
d491678
Merged refs/pull/5500/head from repository cms-sw
rappoccio Nov 3, 2014
887d426
Bare copy of CommonTools/Puppi to CommonTools/PileupModules which is …
rappoccio Nov 3, 2014
26f346a
Changing Puppi to use PileupModules everywhere
rappoccio Nov 3, 2014
7d598f6
First merge of Puppi into the PileupModules package
rappoccio Nov 4, 2014
b1b1009
Implementing the vast majority of the code review suggestions
rappoccio Nov 4, 2014
a424704
Implementing Puppi with code review suggestions
rappoccio Nov 4, 2014
e38a1ea
Fixing git mistake
rappoccio Nov 4, 2014
6f0b751
Getting running verison of PileupModules. Need to do some gymnastics …
rappoccio Nov 4, 2014
c2ea865
Adding soft drop
rappoccio Nov 4, 2014
c76e853
Adding several runtime bug fixes, and also adding our new goodies to …
rappoccio Nov 6, 2014
b820dee
Merged rappoccio_pileup_73x from repository rappoccio
rappoccio Nov 7, 2014
a4565c7
Validation sequence for miniAOD packedGenParticles
lecriste Nov 8, 2014
a010156
cherry-pick and merge to HcalDetDiagTimingMonitor
Oct 8, 2014
22ce151
Added functionality to HcalBaseDQMonitor from HcalMonitorModule to ch…
Oct 10, 2014
399264e
another conflict resolution in HcalMonitorClient
Oct 14, 2014
c3bbd68
fixed a conflict in a comment
Oct 17, 2014
213ae86
removed dummy method in HcalEtaPhiHists...again
Nov 7, 2014
854854c
EDProducer moved from prevalidation to validation step
lecriste Nov 12, 2014
347bbad
Validation harvesting step decoupled from DQM harvesting step
lecriste Nov 12, 2014
0c0932a
Merged HcalDQMMigrate11 from repository cowden
Nov 12, 2014
16c3f80
removed refVector() and ptrVector() calls to edm::View<T>
ferencek Nov 13, 2014
8745b32
removed RefToBaseVector constructor from Handle<View<T> >
ferencek Nov 13, 2014
ffd8913
fixed missing migration
slava77devel Nov 14, 2014
70c9d13
Move the miniAOD validation in the prevalidation sequence
lecriste Nov 14, 2014
296cb95
Replace use of boost::mutex
Dr15Jones Nov 14, 2014
2bdfa34
cleaned up memory allocated by new
Nov 15, 2014
a525577
fix priority for injection
boudoul Nov 15, 2014
68c500d
Add contexts for exceptions in LocalCacheFile.
bbockelm Nov 16, 2014
cd6ee68
Merge pull request #6433 from bbockelm/LocalCacheFile-exception-messages
cmsbuild Nov 17, 2014
a934d0d
added RunManager to master thread and more accurate conversion of eve…
civanch Nov 17, 2014
415c624
Added the missing Done Checking dependency message needed by the IBs …
smuzaffar Nov 17, 2014
a3e7037
added RunAction to the master thread
civanch Nov 17, 2014
bcd9594
Merge pull request #6441 from smuzaffar/CMSSW_7_3_X
smuzaffar Nov 17, 2014
570a2f0
added RunAction to the master thread
civanch Nov 17, 2014
19bbd28
Add missing header <sys/time.h> for gettimeofday
Nov 17, 2014
e5b3278
Merge pull request #6444 from davidlt/add-missing-header-gettimeofday
davidlt Nov 17, 2014
6e9aeca
inserted byte in TCDS data block reading
smorovic Nov 11, 2014
1345300
* reading event type from FED header instead of L1 history
smorovic Nov 11, 2014
bae1c21
Merge pull request #6446 from Martin-Grunewald/MiscFixes
cmsbuild Nov 17, 2014
cecb74b
Merge pull request #6445 from smorovic/event-type-73X
cmsbuild Nov 17, 2014
2088f60
Merge pull request #6443 from civanch/run_action
cmsbuild Nov 17, 2014
d30b791
Merge pull request #6337 from cowden/HcalDQMMigrate11
cmsbuild Nov 17, 2014
3d7d026
Merge pull request #6425 from boudoul/prio_73X
davidlange6 Nov 17, 2014
5be37e7
Merge pull request #6411 from Dr15Jones/removeUseOfBoostMutex
davidlange6 Nov 17, 2014
cecbf52
Merge pull request #6298 from lecriste/miniAOD_Validation_Sequence
cmsbuild Nov 17, 2014
4872c3f
Update printout and make pythia8 interface explicitly fail when pythi…
bendavid Nov 17, 2014
69dce88
Merge pull request #6385 from ferencek/RefVectorAndPtrVectorCleanup_f…
davidlange6 Nov 17, 2014
39f16d8
Merge pull request #6455 from bendavid/pythia8checkinit_73x
cmsbuild Nov 17, 2014
470ec82
Merge pull request #6456 from jalimena/hltIntegration1e34menuPhotonFix
cmsbuild Nov 17, 2014
07b000d
Merging with Dinko's commits
rappoccio Nov 18, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CommonTools/CandAlgos/plugins/CandViewRefMerger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ class CandViewRefMerger : public edm::EDProducer {
for(std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator i = srcTokens_.begin(); i != srcTokens_.end(); ++i) {
edm::Handle<reco::CandidateView> src;
evt.getByToken(*i, src);
reco::CandidateBaseRefVector refs = src->refVector();
for(reco::CandidateBaseRefVector::const_iterator j = refs.begin(); j != refs.end(); ++j)
out->push_back(*j);
for(size_t j = 0; j < src->size(); ++j)
out->push_back(src->refAt(j));
}
evt.put(out);
}
Expand Down
10 changes: 10 additions & 0 deletions CommonTools/PileupModules/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<use name="DataFormats/Common"/>
<use name="DataFormats/ParticleFlowCandidate"/>
<use name="FWCore/ParameterSet"/>
<use name="root"/>
<use name="rootrflx"/>
<use name="rootcore"/>
<use name="fastjet"/>
<export>
<lib name="1"/>
</export>
52 changes: 52 additions & 0 deletions CommonTools/PileupModules/interface/PuppiAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef CommonTools_PileupModules_PuppiAlgo_h
#define CommonTools_PileupModules_PuppiAlgo_h

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "fastjet/PseudoJet.hh"
#include <vector>

class PuppiAlgo{
public:
PuppiAlgo(edm::ParameterSet &iConfig);
~PuppiAlgo();
//Computing Mean and RMS
void reset();
void add(const fastjet::PseudoJet &iParticle,const double &iVal,const unsigned int iAlgo);
void computeMedRMS(const unsigned int &iAlgo,const double &iPVFrac);
//Get the Weight
double compute(std::vector<double> const &iVals,double iChi2) const;
//Helpers
inline double ptMin() const { return fPtMin; }
inline double etaMin() const { return fEtaMin; }
inline double etaMax() const { return fEtaMax; }
inline int numAlgos () const { return fNAlgos;}
inline int algoId ( unsigned int iAlgo) const { return fAlgoId.at(iAlgo); }
inline bool isCharged ( unsigned int iAlgo) const { return fCharged.at(iAlgo); }
inline double coneSize ( unsigned int iAlgo) const { return fConeSize.at(iAlgo); }
inline double neutralPt (int iNPV) const { return fNeutralPtMin + iNPV * fNeutralPtSlope; }

private:
unsigned int fNAlgos;
float fEtaMax;
float fEtaMin;
float fPtMin ;
double fNeutralPtMin;
double fNeutralPtSlope;
std::vector<float> fPups;
std::vector<float> fPupsPV;
std::vector<int> fAlgoId;
std::vector<bool> fCharged;
std::vector<bool> fAdjust;
std::vector<int> fCombId;
std::vector<double> fConeSize;
std::vector<double> fRMSPtMin;
std::vector<double> fRMSScaleFactor;
std::vector<double> fRMS;
std::vector<double> fMedian;
std::vector<double> fMean;
std::vector<int> fNCount;
};


#endif
69 changes: 69 additions & 0 deletions CommonTools/PileupModules/interface/PuppiContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef COMMONTOOLS_PUPPI_PUPPICONTAINER_H_
#define COMMONTOOLS_PUPPI_PUPPICONTAINER_H_

#include "CommonTools/PileupModules/interface/PuppiAlgo.h"
#include "CommonTools/PileupModules/interface/RecoObj.h"
#include "fastjet/internal/base.hh"
#include "fastjet/PseudoJet.hh"

//FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh


//......................
class PuppiContainer{
public:


// Helper class designed to store Puppi information inside of fastjet pseudojets.
// In CMSSW we use the user_index to refer to the index of the input collection,
// but Puppi uses it to decide between NHs, PV CHs, and PU CHs. Instead,
// make that a register.
class PuppiUserInfo : public fastjet::PseudoJet::UserInfoBase {
public :
PuppiUserInfo( int puppi_register = -1) : puppi_register_(puppi_register) {}
virtual ~PuppiUserInfo(){}

void set_puppi_register(int i) { puppi_register_ = i; }

inline int puppi_register() const { return puppi_register_; }

protected :
int puppi_register_; /// Used by puppi algorithm to decide neutrals vs PV vs PU
};




PuppiContainer(const edm::ParameterSet &iConfig);
~PuppiContainer();
void initialize(const std::vector<RecoObj> &iRecoObjects);
std::vector<fastjet::PseudoJet> const & pfParticles() const { return fPFParticles; }
std::vector<fastjet::PseudoJet> const & pvParticles() const { return fChargedPV; }
std::vector<double> const & puppiWeights() ;
std::vector<fastjet::PseudoJet> const & puppiParticles() const { return fPupParticles;}

protected:
double goodVar (fastjet::PseudoJet const &iPart,std::vector<fastjet::PseudoJet> const &iParts, int iOpt,double iRCone);
void getRMSAvg (int iOpt,std::vector<fastjet::PseudoJet> const &iConstits,std::vector<fastjet::PseudoJet> const &iParticles,std::vector<fastjet::PseudoJet> const &iChargeParticles);
double getChi2FromdZ(double iDZ);
int getPuppiId ( float iPt, float iEta);
double var_within_R (int iId, const std::vector<fastjet::PseudoJet> & particles, const fastjet::PseudoJet& centre, double R);

std::vector<RecoObj> fRecoParticles;
std::vector<fastjet::PseudoJet> fPFParticles;
std::vector<fastjet::PseudoJet> fChargedPV;
std::vector<fastjet::PseudoJet> fPupParticles;
std::vector<double> fWeights;
std::vector<double> fVals;
bool fApplyCHS;
bool fUseExp;
double fNeutralMinPt;
double fNeutralSlope;
double fPuppiWeightCut;
int fNAlgos;
int fNPV;
double fPVFrac;
std::vector<PuppiAlgo> fPuppiAlgo;
};
#endif

31 changes: 31 additions & 0 deletions CommonTools/PileupModules/interface/RecoObj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef CommonTools_PileupModules_PUPPI_RECOOBJ_HH
#define CommonTools_PileupModules_PUPPI_RECOOBJ_HH

class RecoObj
{
public:
RecoObj():
pt(0), eta(0), phi(0), m(0),
id(0),pfType(-1),vtxId(-1),
trkChi2(0),vtxChi2(0),
time(0),depth(0),
expProb(0),expChi2PU(0),expChi2(0),
dZ(0),d0(0),charge(0)
{}
~RecoObj(){}

float pt, eta, phi, m; // kinematics
int id;
int pfType;
int vtxId; // Vertex Id from Vertex Collection
float trkChi2; // Track Chi2
float vtxChi2; // Vertex Chi2
float time,depth; // Usefule Info
float expProb;
float expChi2PU;
float expChi2;
float dZ;
float d0;
int charge;
};
#endif
15 changes: 15 additions & 0 deletions CommonTools/PileupModules/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<export>
</export>
<library name="CommonToolsPileupModules_plugins" file="*.cc">
<use name="DataFormats/ParticleFlowCandidate"/>
<use name="DataFormats/JetReco"/>
<use name="FWCore/Framework"/>
<use name="FWCore/MessageLogger"/>
<use name="FWCore/ParameterSet"/>
<use name="JetMETCorrections/Objects"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/ParticleFlow"/>
<use name="CommonTools/PileupModules"/>
<use name="fastjet"/>
<use name="fastjet-contrib"/>
</library>
202 changes: 202 additions & 0 deletions CommonTools/PileupModules/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
//Main File
#include "fastjet/PseudoJet.hh"
#include "CommonTools/PileupModules/plugins/PuppiProducer.h"



// ------------------------------------------------------------------------------------------
PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
fDZCut = iConfig.getParameter<double>("DeltaZCut");
fPuppiContainer = std::unique_ptr<PuppiContainer> ( new PuppiContainer(iConfig) );

tokenPFCandidates_
= consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
tokenVertices_
= consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexName"));


produces<edm::ValueMap<float> > ("PuppiWeights");
produces<edm::ValueMap<LorentzVector> > ("PuppiP4s");
produces<PFOutputCollection>();


}
// ------------------------------------------------------------------------------------------
PuppiProducer::~PuppiProducer(){
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {

// Get PFCandidate Collection
edm::Handle<CandidateView> hPFProduct;
iEvent.getByToken(tokenPFCandidates_,hPFProduct);
const CandidateView *pfCol = hPFProduct.product();

// Get vertex collection w/PV as the first entry?
edm::Handle<reco::VertexCollection> hVertexProduct;
iEvent.getByToken(tokenVertices_,hVertexProduct);
const reco::VertexCollection *pvCol = hVertexProduct.product();

//Fill the reco objects
fRecoObjCollection.clear();
for(CandidateView::const_iterator itPF = pfCol->begin(); itPF!=pfCol->end(); itPF++) {
RecoObj pReco;
pReco.pt = itPF->pt();
pReco.eta = itPF->eta();
pReco.phi = itPF->phi();
pReco.m = itPF->mass();
pReco.charge = itPF->charge();
const reco::Vertex *closestVtx = 0;
double pDZ = -9999;
double pD0 = -9999;
int pVtxId = -9999;
bool lFirst = true;
const pat::PackedCandidate *lPack = dynamic_cast<const pat::PackedCandidate*>(&(*itPF));
if(lPack == 0 ) {
const reco::PFCandidate *pPF = dynamic_cast<const reco::PFCandidate*>(&(*itPF));
for(reco::VertexCollection::const_iterator iV = pvCol->begin(); iV!=pvCol->end(); ++iV) {
if(lFirst) {
if ( pPF->trackRef().isNonnull() ) pDZ = pPF->trackRef() ->dz(iV->position());
else if ( pPF->gsfTrackRef().isNonnull() ) pDZ = pPF->gsfTrackRef()->dz(iV->position());
if ( pPF->trackRef().isNonnull() ) pD0 = pPF->trackRef() ->d0();
else if ( pPF->gsfTrackRef().isNonnull() ) pD0 = pPF->gsfTrackRef()->d0();
lFirst = false;
if(pDZ > -9999) pVtxId = 0;
}
if(iV->trackWeight(pPF->trackRef())>0) {
closestVtx = &(*iV);
break;
}
pVtxId++;
}
} else if(lPack->vertexRef().isNonnull() ) {
pDZ = lPack->dz();
pD0 = lPack->dxy();
closestVtx = &(*(lPack->vertexRef()));
pVtxId = (lPack->fromPV() != (pat::PackedCandidate::PVUsedInFit));
if(lPack->fromPV() == (pat::PackedCandidate::PVLoose || pat::PackedCandidate::PVTight)) closestVtx = 0;
}
pReco.dZ = pDZ;
pReco.d0 = pD0;

if(closestVtx == 0) pReco.vtxId = -1;
if(closestVtx != 0) pReco.vtxId = pVtxId;
//if(closestVtx != 0) pReco.vtxChi2 = closestVtx->trackWeight(itPF->trackRef());
//Set the id for Puppi Algo: 0 is neutral pfCandidate, id = 1 for particles coming from PV and id = 2 for charged particles from non-leading vertex
pReco.id = 0;

if(closestVtx != 0 && pVtxId == 0 && fabs(pReco.charge) > 0) pReco.id = 1;
if(closestVtx != 0 && pVtxId > 0 && fabs(pReco.charge) > 0) pReco.id = 2;
//Add a dZ cut if wanted (this helps)
if(fUseDZ && pDZ > -9999 && closestVtx == 0 && (fabs(pDZ) < fDZCut)) pReco.id = 1;
if(fUseDZ && pDZ > -9999 && closestVtx == 0 && (fabs(pDZ) > fDZCut)) pReco.id = 2;

//std::cout << "pVtxId = " << pVtxId << ", and charge = " << itPF->charge() << ", and closestVtx = " << closestVtx << ", and id = " << pReco.id << std::endl;

fRecoObjCollection.push_back(pReco);
}
fPuppiContainer->initialize(fRecoObjCollection);

//Compute the weights
const std::vector<double> lWeights = fPuppiContainer->puppiWeights();
//Fill it into the event
std::auto_ptr<edm::ValueMap<float> > lPupOut(new edm::ValueMap<float>());
edm::ValueMap<float>::Filler lPupFiller(*lPupOut);
lPupFiller.insert(hPFProduct,lWeights.begin(),lWeights.end());
lPupFiller.fill();

//Fill a new PF Candidate Collection and write out the ValueMap of the new p4s.
// Since the size of the ValueMap must be equal to the input collection, we need
// to search the "puppi" particles to find a match for each input. If none is found,
// the input is set to have a four-vector of 0,0,0,0
const std::vector<fastjet::PseudoJet> lCandidates = fPuppiContainer->puppiParticles();
fPuppiCandidates.reset( new PFOutputCollection );
std::auto_ptr<edm::ValueMap<LorentzVector> > p4PupOut(new edm::ValueMap<LorentzVector>());
LorentzVectorCollection puppiP4s;
for ( auto i0 = hPFProduct->begin(),
i0begin = hPFProduct->begin(),
i0end = hPFProduct->end(); i0 != i0end; ++i0 ) {
//for(unsigned int i0 = 0; i0 < lCandidates.size(); i0++) {
//reco::PFCandidate pCand;
reco::PFCandidate const * tmpCandPF = dynamic_cast<reco::PFCandidate const *>( &*i0 );
if ( tmpCandPF == 0 ) {
throw cms::Exception("LogicError") << "Non-PFCandidates treated as PFCandidates in PuppiProducer." << std::endl;
}
auto id = (tmpCandPF != 0) ? tmpCandPF->translatePdgIdToType(i0->pdgId()) : reco::PFCandidate::X;
reco::PFCandidate pCand( i0->charge(),
i0->p4(),
id );
LorentzVector pVec = i0->p4();
int val = i0 - i0begin;

// Find the Puppi particle matched to the input collection using the "user_index" of the object.
auto puppiMatched = find_if( lCandidates.begin(), lCandidates.end(), [&val]( fastjet::PseudoJet const & i ){ return i.user_index() == val; } );
if ( puppiMatched != lCandidates.end() ) {
pVec.SetPxPyPzE(puppiMatched->px(),puppiMatched->py(),puppiMatched->pz(),puppiMatched->E());
} else {
pVec.SetPxPyPzE( 0, 0, 0, 0);
}
pCand.setP4(pVec);
puppiP4s.push_back( pVec );
fPuppiCandidates->push_back(pCand);
}

//Compute the modified p4s
edm::ValueMap<LorentzVector>::Filler p4PupFiller(*p4PupOut);
p4PupFiller.insert(hPFProduct,puppiP4s.begin(), puppiP4s.end() );
p4PupFiller.fill();

iEvent.put(lPupOut,"PuppiWeights");
iEvent.put(p4PupOut,"PuppiP4s");
iEvent.put(fPuppiCandidates);
}

// ------------------------------------------------------------------------------------------
void PuppiProducer::beginJob() {
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::endJob() {
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::beginRun(edm::Run&, edm::EventSetup const&) {
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::endRun(edm::Run&, edm::EventSetup const&) {
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&) {
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&) {
}
// ------------------------------------------------------------------------------------------
void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);
}
//define this as a plug-in
DEFINE_FWK_MODULE(PuppiProducer);
Loading