CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
PrimaryVertexSorter< ParticlesCollection > Class Template Reference

#include <PrimaryVertexSorter.h>

Inheritance diagram for PrimaryVertexSorter< ParticlesCollection >:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Types

typedef edm::Association< reco::VertexCollectionCandToVertex
 
typedef edm::ValueMap< int > CandToVertexQuality
 
typedef ParticlesCollection PFCollection
 
typedef edm::ValueMap< float > VertexScore
 
- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

 PrimaryVertexSorter (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 
std::vector< reco::VertexsortedList (const reco::VertexCollection &primaryVertex) const
 
 ~PrimaryVertexSorter ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

PrimaryVertexAssignment assignmentAlgo_
 
bool produceOriginalMapping_
 
bool producePFNoPileUp_
 
bool producePFPileUp_
 
bool produceSortedVertices_
 
int qualityCut_
 
PrimaryVertexSorting sortingAlgo_
 
edm::EDGetTokenT< PFCollectiontokenCandidates_
 Candidates to be analyzed. More...
 
edm::EDGetTokenT< edm::View< reco::Candidate > > tokenJets_
 
edm::EDGetTokenT< reco::VertexCollectiontokenVertices_
 vertices More...
 
bool useMET_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

template<class ParticlesCollection>
class PrimaryVertexSorter< ParticlesCollection >

Author
Andrea Rizzi

class to sort VertexCollection in decreasing order of the sum of the squared track pT's

Definition at line 32 of file PrimaryVertexSorter.h.

Member Typedef Documentation

template<class ParticlesCollection>
typedef edm::Association<reco::VertexCollection> PrimaryVertexSorter< ParticlesCollection >::CandToVertex

Definition at line 35 of file PrimaryVertexSorter.h.

template<class ParticlesCollection>
typedef edm::ValueMap<int> PrimaryVertexSorter< ParticlesCollection >::CandToVertexQuality

Definition at line 36 of file PrimaryVertexSorter.h.

template<class ParticlesCollection>
typedef ParticlesCollection PrimaryVertexSorter< ParticlesCollection >::PFCollection

Definition at line 39 of file PrimaryVertexSorter.h.

template<class ParticlesCollection>
typedef edm::ValueMap<float> PrimaryVertexSorter< ParticlesCollection >::VertexScore

Definition at line 37 of file PrimaryVertexSorter.h.

Constructor & Destructor Documentation

template<class ParticlesCollection >
PrimaryVertexSorter< ParticlesCollection >::PrimaryVertexSorter ( const edm::ParameterSet iConfig)
explicit

Definition at line 81 of file PrimaryVertexSorter.h.

References PrimaryVertexSorter< ParticlesCollection >::produceOriginalMapping_, PrimaryVertexSorter< ParticlesCollection >::producePFNoPileUp_, PrimaryVertexSorter< ParticlesCollection >::producePFPileUp_, and PrimaryVertexSorter< ParticlesCollection >::produceSortedVertices_.

81  :
82  assignmentAlgo_(iConfig.getParameterSet("assignment")),
83  sortingAlgo_(iConfig.getParameterSet("sorting")),
84  tokenCandidates_(consumes<ParticlesCollection>(iConfig.getParameter<edm::InputTag>("particles"))),
85  tokenVertices_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
87  produceOriginalMapping_(iConfig.getParameter<bool>("produceAssociationToOriginalVertices")),
88  produceSortedVertices_(iConfig.getParameter<bool>("produceSortedVertices")),
89  producePFPileUp_(iConfig.getParameter<bool>("producePileUpCollection")),
90  producePFNoPileUp_(iConfig.getParameter<bool>("produceNoPileUpCollection")),
91  qualityCut_(iConfig.getParameter<int>("qualityForPrimary")),
92  useMET_(iConfig.getParameter<bool>("usePVMET"))
93 {
94 
95 using namespace std;
96 using namespace edm;
97 using namespace reco;
98 
100  produces< CandToVertex> ("original");
101  produces< CandToVertexQuality> ("original");
102  produces< VertexScore> ("original");
103  }
105  produces< reco::VertexCollection> ();
106  produces< CandToVertex> ();
107  produces< CandToVertexQuality> ();
108  produces< VertexScore> ();
109  }
110 
111  if(producePFPileUp_){
113  produces< PFCollection> ("originalPileUp");
115  produces< PFCollection> ("PileUp");
116  }
117 
118  if(producePFNoPileUp_){
120  produces< PFCollection> ("originalNoPileUp");
122  produces< PFCollection> ("NoPileUp");
123  }
124 
125 
126 }
T getParameter(std::string const &) const
PrimaryVertexSorting sortingAlgo_
edm::EDGetTokenT< PFCollection > tokenCandidates_
Candidates to be analyzed.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ParameterSet const & getParameterSet(std::string const &) const
PrimaryVertexAssignment assignmentAlgo_
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::VertexCollection > tokenVertices_
vertices
edm::EDGetTokenT< edm::View< reco::Candidate > > tokenJets_
template<class ParticlesCollection>
PrimaryVertexSorter< ParticlesCollection >::~PrimaryVertexSorter ( )
inline

Definition at line 43 of file PrimaryVertexSorter.h.

References PrimaryVertexSorter< ParticlesCollection >::produce().

43 {}

Member Function Documentation

template<class ParticlesCollection >
void PrimaryVertexSorter< ParticlesCollection >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Definition at line 133 of file PrimaryVertexSorter.h.

References PrimaryVertexSorter< ParticlesCollection >::assignmentAlgo_, PrimaryVertexAssignment::chargedHadronVertex(), edm::helper::Filler< Map >::fill(), edm::EventSetup::get(), edm::Event::getByToken(), mps_fire::i, training_settings::idx, edm::helper::Filler< Map >::insert(), fwrapper::jets, eostools::move(), lumidbDDL::newToOld(), lumidbDDL::oldToNew(), HadronAndPartonSelector_cfi::particles, packedPFCandidateRefMixer_cfi::pf, PrimaryVertexSorter< ParticlesCollection >::produceOriginalMapping_, PrimaryVertexSorter< ParticlesCollection >::producePFNoPileUp_, PrimaryVertexSorter< ParticlesCollection >::producePFPileUp_, PrimaryVertexSorter< ParticlesCollection >::produceSortedVertices_, edm::Handle< T >::product(), edm::Event::put(), MetAnalyzer::pv(), PrimaryVertexSorter< ParticlesCollection >::qualityCut_, alignCSCRings::s, PrimaryVertexSorting::score(), PrimaryVertexSorter< ParticlesCollection >::sortingAlgo_, PrimaryVertexSorter< ParticlesCollection >::tokenCandidates_, PrimaryVertexSorter< ParticlesCollection >::tokenJets_, PrimaryVertexSorter< ParticlesCollection >::tokenVertices_, PrimaryVertexSorter< ParticlesCollection >::useMET_, and ecalDrivenElectronSeedsParameters_cff::vertices.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), HTMLExport.HTMLExportStatic::export(), and PrimaryVertexSorter< ParticlesCollection >::~PrimaryVertexSorter().

133  {
134 
135 using namespace std;
136 using namespace edm;
137 using namespace reco;
138 
140  iEvent.getByToken( tokenJets_, jets);
141 
143  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
144 
145 
147  iEvent.getByToken( tokenVertices_, vertices);
148 
149  Handle<ParticlesCollection> particlesHandle;
150  iEvent.getByToken( tokenCandidates_, particlesHandle);
151 
152  ParticlesCollection particles = *particlesHandle.product();
153  std::vector<int> pfToPVVector;
154  std::vector<PrimaryVertexAssignment::Quality> pfToPVQualityVector;
155  //reverse mapping
156  std::vector< std::vector<int> > pvToPFVector(vertices->size());
157  std::vector< std::vector<const reco::Candidate *> > pvToCandVector(vertices->size());
158  std::vector< std::vector<PrimaryVertexAssignment::Quality> > pvToPFQualityVector(vertices->size());
159  std::vector<float> vertexScoreOriginal(vertices->size());
160  std::vector<float> vertexScore(vertices->size());
161 
162  for(auto const & pf : particles) {
163  std::pair<int,PrimaryVertexAssignment::Quality> vtxWithQuality=assignmentAlgo_.chargedHadronVertex(*vertices,pf,*jets,*builder);
164  pfToPVVector.push_back(vtxWithQuality.first);
165  pfToPVQualityVector.push_back(vtxWithQuality.second);
166  }
167 
168  //Invert the mapping
169  for(size_t i = 0; i < pfToPVVector.size();i++)
170  {
171  auto pv = pfToPVVector[i];
172  auto qual = pfToPVQualityVector[i];
173  if(pv >=0 and qual >= qualityCut_){
174  pvToPFVector[pv].push_back(i);
175 // std::cout << i << std::endl;
176 // const typename ParticlesCollection::value_type & cp = particles[i];
177 // std::cout << "CP " << &cp << std::endl;
178  pvToCandVector[pv].push_back( &particles[i] );
179  pvToPFQualityVector[pv].push_back(qual);
180  }
181  }
182 
183  //Use multimap for sorting of indices
184  std::multimap<float,int> scores;
185  for(unsigned int i=0;i<vertices->size();i++){
186  float s=sortingAlgo_.score((*vertices)[i],pvToCandVector[i],useMET_);
187  vertexScoreOriginal[i]=s;
188  scores.insert(std::pair<float,int>(-s,i));
189  }
190 
191  //create indices
192  std::vector<int> oldToNew(vertices->size()), newToOld(vertices->size());
193  size_t newIdx=0;
194  for(auto const & idx : scores)
195  {
196 // std::cout << newIdx << " score: " << idx.first << " oldidx: " << idx.second << " "<< producePFPileUp_ << std::endl;
197  vertexScore[newIdx]=-idx.first;
198  oldToNew[idx.second]=newIdx;
199  newToOld[newIdx]=idx.second;
200  newIdx++;
201  }
202 
203 
204 
205 
207  unique_ptr< CandToVertex> pfCandToOriginalVertexOutput( new CandToVertex(vertices) );
208  unique_ptr< CandToVertexQuality> pfCandToOriginalVertexQualityOutput( new CandToVertexQuality() );
209  CandToVertex::Filler cand2VertexFiller(*pfCandToOriginalVertexOutput);
210  CandToVertexQuality::Filler cand2VertexQualityFiller(*pfCandToOriginalVertexQualityOutput);
211 
212  cand2VertexFiller.insert(particlesHandle,pfToPVVector.begin(),pfToPVVector.end());
213  cand2VertexQualityFiller.insert(particlesHandle,pfToPVQualityVector.begin(),pfToPVQualityVector.end());
214 
215  cand2VertexFiller.fill();
216  cand2VertexQualityFiller.fill();
217  iEvent.put(std::move(pfCandToOriginalVertexOutput) ,"original");
218  iEvent.put(std::move(pfCandToOriginalVertexQualityOutput) ,"original");
219 
220  unique_ptr< VertexScore> vertexScoreOriginalOutput( new VertexScore );
221  VertexScore::Filler vertexScoreOriginalFiller(*vertexScoreOriginalOutput);
222  vertexScoreOriginalFiller.insert(vertices,vertexScoreOriginal.begin(),vertexScoreOriginal.end());
223  vertexScoreOriginalFiller.fill();
224  iEvent.put(std::move(vertexScoreOriginalOutput) ,"original");
225 
226  }
227 
229  std::vector<int> pfToSortedPVVector;
230 // std::vector<int> pfToSortedPVQualityVector;
231  for(size_t i=0;i<pfToPVVector.size();i++) {
232  pfToSortedPVVector.push_back(oldToNew[pfToPVVector[i]]);
233 // pfToSortedPVQualityVector.push_back(pfToPVQualityVector[i]); //same as old!
234  }
235 
236  unique_ptr< reco::VertexCollection> sortedVerticesOutput( new reco::VertexCollection );
237  for(size_t i=0;i<vertices->size();i++){
238  sortedVerticesOutput->push_back((*vertices)[newToOld[i]]);
239  }
240  edm::OrphanHandle<reco::VertexCollection> oh = iEvent.put(std::move(sortedVerticesOutput));
241  unique_ptr< CandToVertex> pfCandToVertexOutput( new CandToVertex(oh) );
242  unique_ptr< CandToVertexQuality> pfCandToVertexQualityOutput( new CandToVertexQuality() );
243  CandToVertex::Filler cand2VertexFiller(*pfCandToVertexOutput);
244  CandToVertexQuality::Filler cand2VertexQualityFiller(*pfCandToVertexQualityOutput);
245 
246  cand2VertexFiller.insert(particlesHandle,pfToSortedPVVector.begin(),pfToSortedPVVector.end());
247  cand2VertexQualityFiller.insert(particlesHandle,pfToPVQualityVector.begin(),pfToPVQualityVector.end());
248 
249  cand2VertexFiller.fill();
250  cand2VertexQualityFiller.fill();
251  iEvent.put(std::move(pfCandToVertexOutput ));
252  iEvent.put(std::move(pfCandToVertexQualityOutput ));
253 
254  unique_ptr< VertexScore> vertexScoreOutput( new VertexScore );
255  VertexScore::Filler vertexScoreFiller(*vertexScoreOutput);
256  vertexScoreFiller.insert(oh,vertexScore.begin(),vertexScore.end());
257  vertexScoreFiller.fill();
258  iEvent.put(std::move(vertexScoreOutput));
259 
260 
261  }
262 
263 
264  unique_ptr< PFCollection > pfCollectionNOPUOriginalOutput( new PFCollection );
265  unique_ptr< PFCollection > pfCollectionNOPUOutput( new PFCollection );
266  unique_ptr< PFCollection > pfCollectionPUOriginalOutput( new PFCollection );
267  unique_ptr< PFCollection > pfCollectionPUOutput( new PFCollection );
268 
269  for(size_t i=0;i<particles.size();i++) {
270  auto pv = pfToPVVector[i];
271  auto qual = pfToPVQualityVector[i];
272 
273 
275  if(pv == newToOld[0] and qual >= qualityCut_)
276  pfCollectionNOPUOutput->push_back(particles[i]);
277 
279  if(pv != newToOld[0] and qual >= qualityCut_)
280  pfCollectionPUOutput->push_back(particles[i]);
281 
283  if(pv == 0 and qual >= qualityCut_)
284  pfCollectionNOPUOriginalOutput->push_back(particles[i]);
285 
287  if(pv != 0 and qual >= qualityCut_)
288  pfCollectionPUOriginalOutput->push_back(particles[i]);
289 
290  }
291  if(producePFNoPileUp_ && produceSortedVertices_) iEvent.put(std::move(pfCollectionNOPUOutput),"NoPileUp" );
292  if(producePFPileUp_ && produceSortedVertices_) iEvent.put(std::move(pfCollectionPUOutput), "PileUp");
293  if(producePFNoPileUp_ && produceOriginalMapping_) iEvent.put(std::move(pfCollectionNOPUOriginalOutput),"originalNoPileUp" );
294  if(producePFPileUp_ && produceOriginalMapping_) iEvent.put(std::move(pfCollectionPUOriginalOutput),"originalPileUp" );
295 
296 
297 }
edm::Association< reco::VertexCollection > CandToVertex
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
PrimaryVertexSorting sortingAlgo_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< PFCollection > tokenCandidates_
Candidates to be analyzed.
ParticlesCollection PFCollection
vector< PseudoJet > jets
def oldToNew(schema)
Definition: lumidbDDL.py:399
def pv(vc)
Definition: MetAnalyzer.py:6
helper::Filler< ValueMap< int > > Filler
Definition: ValueMap.h:168
edm::ValueMap< float > VertexScore
T const * product() const
Definition: Handle.h:81
PrimaryVertexAssignment assignmentAlgo_
const T & get() const
Definition: EventSetup.h:56
float score(const reco::Vertex &pv, const std::vector< const reco::Candidate * > &candidates, bool useMet) const
edm::ValueMap< int > CandToVertexQuality
fixed size matrix
HLT enums.
def newToOld(schema)
Definition: lumidbDDL.py:413
edm::EDGetTokenT< reco::VertexCollection > tokenVertices_
vertices
def move(src, dest)
Definition: eostools.py:510
std::pair< int, PrimaryVertexAssignment::Quality > chargedHadronVertex(const reco::VertexCollection &vertices, const reco::TrackRef &trackRef, const reco::Track *track, const edm::View< reco::Candidate > &jets, const TransientTrackBuilder &builder) const
edm::EDGetTokenT< edm::View< reco::Candidate > > tokenJets_
template<class ParticlesCollection>
VertexCollection PrimaryVertexSorter< ParticlesCollection >::sortedList ( const reco::VertexCollection primaryVertex) const

Definition at line 8 of file PrimaryVertexSorter.cc.

Referenced by QualityCutsAnalyzer::LoopOverJetTracksAssociation().

9 {
10  VertexCollection pvs = unsortedPVColl;
11  sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
12  return pvs;
13 }
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9

Member Data Documentation

template<class ParticlesCollection>
PrimaryVertexAssignment PrimaryVertexSorter< ParticlesCollection >::assignmentAlgo_
private
template<class ParticlesCollection>
bool PrimaryVertexSorter< ParticlesCollection >::produceOriginalMapping_
private
template<class ParticlesCollection>
bool PrimaryVertexSorter< ParticlesCollection >::producePFNoPileUp_
private
template<class ParticlesCollection>
bool PrimaryVertexSorter< ParticlesCollection >::producePFPileUp_
private
template<class ParticlesCollection>
bool PrimaryVertexSorter< ParticlesCollection >::produceSortedVertices_
private
template<class ParticlesCollection>
int PrimaryVertexSorter< ParticlesCollection >::qualityCut_
private
template<class ParticlesCollection>
PrimaryVertexSorting PrimaryVertexSorter< ParticlesCollection >::sortingAlgo_
private
template<class ParticlesCollection>
edm::EDGetTokenT<PFCollection> PrimaryVertexSorter< ParticlesCollection >::tokenCandidates_
private

Candidates to be analyzed.

Definition at line 53 of file PrimaryVertexSorter.h.

Referenced by PrimaryVertexSorter< ParticlesCollection >::produce().

template<class ParticlesCollection>
edm::EDGetTokenT<edm::View<reco::Candidate> > PrimaryVertexSorter< ParticlesCollection >::tokenJets_
private
template<class ParticlesCollection>
edm::EDGetTokenT<reco::VertexCollection> PrimaryVertexSorter< ParticlesCollection >::tokenVertices_
private

vertices

Definition at line 56 of file PrimaryVertexSorter.h.

Referenced by PrimaryVertexSorter< ParticlesCollection >::produce().

template<class ParticlesCollection>
bool PrimaryVertexSorter< ParticlesCollection >::useMET_
private