CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::VertexCollection
CandToVertex
 
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, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
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 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
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::VertexCollection
tokenVertices_
 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::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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 84 of file PrimaryVertexSorter.h.

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

84  :
85  assignmentAlgo_(iConfig.getParameterSet("assignment")),
86  sortingAlgo_(iConfig.getParameterSet("sorting")),
87  tokenCandidates_(consumes<ParticlesCollection>(iConfig.getParameter<InputTag>("particles"))),
88  tokenVertices_(consumes<VertexCollection>(iConfig.getParameter<InputTag>("vertices"))),
90  produceOriginalMapping_(iConfig.getParameter<bool>("produceAssociationToOriginalVertices")),
91  produceSortedVertices_(iConfig.getParameter<bool>("produceSortedVertices")),
92  producePFPileUp_(iConfig.getParameter<bool>("producePileUpCollection")),
93  producePFNoPileUp_(iConfig.getParameter<bool>("produceNoPileUpCollection")),
94  qualityCut_(iConfig.getParameter<int>("qualityForPrimary")),
95  useMET_(iConfig.getParameter<bool>("usePVMET"))
96 {
97 
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_
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.

43 {}

Member Function Documentation

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

Implements edm::stream::EDProducerBase.

Definition at line 133 of file PrimaryVertexSorter.h.

References edm::helper::Filler< Map >::fill(), edm::EventSetup::get(), edm::Event::getByToken(), i, customizeTrackingMonitorSeedNumber::idx, edm::helper::Filler< Map >::insert(), fwrapper::jets, lumidbDDL::newToOld(), lumidbDDL::oldToNew(), edm::Handle< T >::product(), edm::Event::put(), MetAnalyzer::pv(), alignCSCRings::s, and HLT_25ns14e33_v1_cff::vertices.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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

References python.multivaluedict::sort().

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

Definition at line 49 of file PrimaryVertexSorter.h.

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

Definition at line 63 of file PrimaryVertexSorter.h.

template<class ParticlesCollection>
PrimaryVertexSorting PrimaryVertexSorter< ParticlesCollection >::sortingAlgo_
private

Definition at line 50 of file PrimaryVertexSorter.h.

template<class ParticlesCollection>
edm::EDGetTokenT<PFCollection> PrimaryVertexSorter< ParticlesCollection >::tokenCandidates_
private

Candidates to be analyzed.

Definition at line 53 of file PrimaryVertexSorter.h.

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

Definition at line 57 of file PrimaryVertexSorter.h.

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

vertices

Definition at line 56 of file PrimaryVertexSorter.h.

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

Definition at line 64 of file PrimaryVertexSorter.h.