CMS 3D CMS Logo

PF_PU_FirstVertexTracks.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PF_PU_AssoMap
4 // Class: PF_PU_FirstVertexTracks
5 //
10 //
11 // Original Author: Matthias Geisler
12 // Created: Wed Apr 18 14:48:37 CEST 2012
13 // $Id: PF_PU_FirstVertexTracks.cc,v 1.1 2012/11/21 09:57:30 mgeisler Exp $
14 //
15 //
17 
18 // system include files
19 #include <vector>
20 #include <string>
21 
22 // user include files
24 
29 
34 
35 //
36 // constants, enums and typedefs
37 //
38 
39 using namespace edm;
40 using namespace std;
41 using namespace reco;
42 
43 typedef vector<pair<TrackRef, int> > TrackQualityPairVector;
44 
45 //
46 // static data member definitions
47 //
48 
49 //
50 // constructors and destructor
51 //
53  //now do what ever other initialization is needed
54 
55  input_AssociationType_ = iConfig.getParameter<edm::InputTag>("AssociationType");
56 
57  token_TrackToVertexAssMap_ = mayConsume<TrackToVertexAssMap>(iConfig.getParameter<InputTag>("AssociationMap"));
58  token_VertexToTrackAssMap_ = mayConsume<VertexToTrackAssMap>(iConfig.getParameter<InputTag>("AssociationMap"));
59 
60  token_generalTracksCollection_ = consumes<TrackCollection>(iConfig.getParameter<InputTag>("TrackCollection"));
61 
62  token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
63 
64  input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
65 
66  //register your products
67 
68  if (input_AssociationType_.label() == "TracksToVertex") {
69  produces<TrackCollection>("T2V");
70  } else {
71  if (input_AssociationType_.label() == "VertexToTracks") {
72  produces<TrackCollection>("V2T");
73  } else {
74  if (input_AssociationType_.label() == "Both") {
75  produces<TrackCollection>("T2V");
76  produces<TrackCollection>("V2T");
77  } else {
78  std::cout << "No correct InputTag for AssociationType!" << std::endl;
79  std::cout << "Won't produce any TrackCollection!" << std::endl;
80  }
81  }
82  }
83 }
84 
86  // do anything here that needs to be done at desctruction time
87  // (e.g. close files, deallocate resources etc.)
88 }
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called to produce the data ------------
96  unique_ptr<TrackCollection> t2v_firstvertextracks(new TrackCollection());
97  unique_ptr<TrackCollection> v2t_firstvertextracks(new TrackCollection());
98 
99  bool t2vassmap = false;
100  bool v2tassmap = false;
101 
102  //get the input vertex<->general track association map
105 
106  string asstype = input_AssociationType_.label();
107 
108  if ((asstype == "TracksToVertex") || (asstype == "Both")) {
109  if (iEvent.getByToken(token_TrackToVertexAssMap_, t2vAM)) {
110  t2vassmap = true;
111  }
112  }
113 
114  if ((asstype == "VertexToTracks") || (asstype == "Both")) {
115  if (iEvent.getByToken(token_VertexToTrackAssMap_, v2tAM)) {
116  v2tassmap = true;
117  }
118  }
119 
120  if (!t2vassmap && !v2tassmap) {
121  cout << "No input collection could be found" << endl;
122  return;
123  }
124 
125  //get the input track collection
126  Handle<TrackCollection> input_trckcollH;
127  iEvent.getByToken(token_generalTracksCollection_, input_trckcollH);
128 
129  if (t2vassmap) {
130  const TrackQualityPairVector trckcoll = t2vAM->begin()->val;
131 
132  //get the tracks associated to the first vertex and store them in a track collection
133  for (unsigned int trckcoll_ite = 0; trckcoll_ite < trckcoll.size(); trckcoll_ite++) {
134  float quality = trckcoll[trckcoll_ite].second;
135 
136  if (quality >= input_MinQuality_) {
137  TrackRef AMtrkref = trckcoll[trckcoll_ite].first;
138 
139  for (unsigned int index_input_trck = 0; index_input_trck < input_trckcollH->size(); index_input_trck++) {
140  TrackRef input_trackref = TrackRef(input_trckcollH, index_input_trck);
141 
142  if (TrackMatch(*AMtrkref, *input_trackref)) {
143  t2v_firstvertextracks->push_back(*AMtrkref);
144  break;
145  }
146  }
147  }
148  }
149 
150  iEvent.put(std::move(t2v_firstvertextracks), "T2V");
151  }
152 
153  if (v2tassmap) {
154  //get the input vertex collection
155  Handle<VertexCollection> input_vtxcollH;
156  iEvent.getByToken(token_VertexCollection_, input_vtxcollH);
157 
158  VertexRef firstVertexRef(input_vtxcollH, 0);
159 
161 
162  for (v2t_ite = v2tAM->begin(); v2t_ite != v2tAM->end(); v2t_ite++) {
163  TrackRef AMtrkref = v2t_ite->key;
164 
165  for (unsigned int index_input_trck = 0; index_input_trck < input_trckcollH->size(); index_input_trck++) {
166  TrackRef input_trackref = TrackRef(input_trckcollH, index_input_trck);
167 
168  if (TrackMatch(*AMtrkref, *input_trackref)) {
169  for (unsigned v_ite = 0; v_ite < (v2t_ite->val).size(); v_ite++) {
170  VertexRef vtxref = (v2t_ite->val)[v_ite].first;
171  float quality = (v2t_ite->val)[v_ite].second;
172 
173  if ((vtxref == firstVertexRef) && (quality >= input_MinQuality_)) {
174  v2t_firstvertextracks->push_back(*AMtrkref);
175  }
176  }
177  }
178  }
179  }
180 
181  iEvent.put(std::move(v2t_firstvertextracks), "V2T");
182  }
183 }
184 
185 bool PF_PU_FirstVertexTracks::TrackMatch(const Track& track1, const Track& track2) {
186  return ((track1).eta() == (track2).eta() && (track1).phi() == (track2).phi() && (track1).chi2() == (track2).chi2() &&
187  (track1).ndof() == (track2).ndof() && (track1).p() == (track2).p());
188 }
189 
190 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
192  //The following says we do not know what parameters are allowed so do no validation
193  // Please change this to state exactly what you do use, even if it is no parameters
195  desc.setUnknown();
196  descriptions.addDefault(desc);
197 }
198 
199 //define this as a plug-in
Handle.h
PF_PU_FirstVertexTracks::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PF_PU_FirstVertexTracks.cc:95
MessageLogger.h
PF_PU_FirstVertexTracks.h
PF_PU_FirstVertexTracks::TrackMatch
virtual bool TrackMatch(const reco::Track &, const reco::Track &)
Definition: PF_PU_FirstVertexTracks.cc:185
TrackBase.h
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
PF_PU_FirstVertexTracks
Definition: PF_PU_FirstVertexTracks.h:49
TrackQualityPairVector
std::vector< TrackQualityPair > TrackQualityPairVector
Definition: PF_PU_AssoMapAlgos.h:75
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< TrackCollection >
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:122
ndof
Definition: HIMultiTrackSelector.h:49
edm::first
T first(std::pair< T, U > const &p)
Definition: ParameterSet.cc:217
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
PVValHelper::eta
Definition: PVValidationHelpers.h:70
reco::Track
Definition: Track.h:27
GsfElectron.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
edm::helpers::KeyVal::val
V val
Definition: AssociationMapHelpers.h:33
PF_PU_FirstVertexTracks::~PF_PU_FirstVertexTracks
~PF_PU_FirstVertexTracks() override
Definition: PF_PU_FirstVertexTracks.cc:85
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PF_PU_FirstVertexTracks::PF_PU_FirstVertexTracks
PF_PU_FirstVertexTracks(const edm::ParameterSet &)
Definition: PF_PU_FirstVertexTracks.cc:52
iEvent
int iEvent
Definition: GenABIO.cc:224
OneToManyWithQualityGeneric.h
edm::EventSetup
Definition: EventSetup.h:58
edm::helpers::KeyVal::key
K key
Definition: AssociationMapHelpers.h:32
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::AssociationMap::begin
const_iterator begin() const
first iterator over the map (read only)
Definition: AssociationMap.h:169
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
View.h
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
TrackQualityPairVector
vector< pair< TrackRef, int > > TrackQualityPairVector
Definition: PF_PU_FirstVertexTracks.cc:43
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
PF_PU_FirstVertexTracks::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PF_PU_FirstVertexTracks.cc:191