CMS 3D CMS Logo

VertexHistoryAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * VertexHistoryAnalyzer.C
3  *
4  * Created by Victor Eduardo Bazterra on 5/31/07.
5  *
6  */
7 
8 // system include files
9 #include <iostream>
10 #include <memory>
11 #include <sstream>
12 #include <string>
13 #include <vector>
14 
15 // user include files
18 
26 
29 
30 //
31 // class decleration
32 //
33 
35 public:
36  explicit VertexHistoryAnalyzer(const edm::ParameterSet &);
37 
38 private:
39  virtual void beginRun(const edm::Run &, const edm::EventSetup &);
40  void beginJob() override;
41  void analyze(const edm::Event &, const edm::EventSetup &) override;
42 
43  // Member data
44 
46 
48 
50 
51  std::string particleString(int) const;
52 
54 
55  std::string vertexString(HepMC::GenVertex::particles_in_const_iterator,
56  HepMC::GenVertex::particles_in_const_iterator,
57  HepMC::GenVertex::particles_out_const_iterator,
58  HepMC::GenVertex::particles_out_const_iterator) const;
59 };
60 
62  : classifier_(config, consumesCollector()) {
63  vertexProducer_ = config.getUntrackedParameter<edm::InputTag>("vertexProducer");
64  consumes<edm::View<reco::Vertex>>(vertexProducer_);
65 }
66 
68  // Set the classifier for a new event
70 
71  // Vertex collection
73  event.getByLabel(vertexProducer_, vertexCollection);
74 
75  // Get a constant reference to the track history associated to the classifier
76  VertexHistory const &tracer = classifier_.history();
77 
78  // Loop over the track collection.
79  for (std::size_t index = 0; index < vertexCollection->size(); index++) {
80  std::cout << std::endl << "History for vertex #" << index << " : " << std::endl;
81 
82  // Classify the track and detect for fakes
84  // Get the list of TrackingParticles associated to
86 
87  // Loop over all simParticles
88  for (std::size_t hindex = 0; hindex < simParticles.size(); hindex++) {
89  std::cout << " simParticles [" << hindex << "] : " << particleString(simParticles[hindex]->pdgId())
90  << std::endl;
91  }
92 
93  // Get the list of TrackingVertexes associated to
94  VertexHistory::SimVertexTrail simVertexes(tracer.simVertexTrail());
95 
96  // Loop over all simVertexes
97  if (!simVertexes.empty()) {
98  for (std::size_t hindex = 0; hindex < simVertexes.size(); hindex++) {
99  std::cout << " simVertex [" << hindex << "] : "
100  << vertexString(simVertexes[hindex]->sourceTracks(), simVertexes[hindex]->daughterTracks())
101  << std::endl;
102  }
103  } else
104  std::cout << " simVertex no found" << std::endl;
105 
106  // Get the list of GenParticles associated to
108 
109  // Loop over all genParticles
110  for (std::size_t hindex = 0; hindex < genParticles.size(); hindex++) {
111  std::cout << " genParticles [" << hindex << "] : " << particleString(genParticles[hindex]->pdg_id())
112  << std::endl;
113  }
114 
115  // Get the list of TrackingVertexes associated to
116  VertexHistory::GenVertexTrail genVertexes(tracer.genVertexTrail());
117 
118  // Loop over all simVertexes
119  if (!genVertexes.empty()) {
120  for (std::size_t hindex = 0; hindex < genVertexes.size(); hindex++) {
121  std::cout << " genVertex [" << hindex << "] : "
122  << vertexString(genVertexes[hindex]->particles_in_const_begin(),
123  genVertexes[hindex]->particles_in_const_end(),
124  genVertexes[hindex]->particles_out_const_begin(),
125  genVertexes[hindex]->particles_out_const_end())
126  << std::endl;
127  }
128  } else
129  std::cout << " genVertex no found" << std::endl;
130  } else
131  std::cout << " fake vertex" << std::endl;
132 
133  std::cout << " vertex categories : " << classifier_;
134  std::cout << std::endl;
135  }
136 }
137 
139  // Get the particles table.
140  setup.getData(pdt_);
141 }
142 
144 
146  ParticleData const *pid;
147 
148  std::ostringstream vDescription;
149 
151 
152  if (particleType.isValid()) {
153  pid = pdt_->particle(particleType);
154  if (pid)
155  vDescription << pid->name();
156  else
157  vDescription << pdgId;
158  } else
159  vDescription << pdgId;
160 
161  return vDescription.str();
162 }
163 
165  const TrackingParticleRefVector &out) const {
166  ParticleData const *pid;
167 
168  std::ostringstream vDescription;
169 
170  for (std::size_t j = 0; j < in.size(); j++) {
171  if (!j)
172  vDescription << "(";
173 
175 
176  if (particleType.isValid()) {
177  pid = pdt_->particle(particleType);
178  if (pid)
179  vDescription << pid->name();
180  else
181  vDescription << in[j]->pdgId();
182  } else
183  vDescription << in[j]->pdgId();
184 
185  if (j == in.size() - 1)
186  vDescription << ")";
187  else
188  vDescription << ",";
189  }
190 
191  vDescription << "->";
192 
193  for (std::size_t j = 0; j < out.size(); j++) {
194  if (!j)
195  vDescription << "(";
196 
198 
199  if (particleType.isValid()) {
200  pid = pdt_->particle(particleType);
201  if (pid)
202  vDescription << pid->name();
203  else
204  vDescription << out[j]->pdgId();
205  } else
206  vDescription << out[j]->pdgId();
207 
208  if (j == out.size() - 1)
209  vDescription << ")";
210  else
211  vDescription << ",";
212  }
213 
214  return vDescription.str();
215 }
216 
217 std::string VertexHistoryAnalyzer::vertexString(HepMC::GenVertex::particles_in_const_iterator in_begin,
218  HepMC::GenVertex::particles_in_const_iterator in_end,
219  HepMC::GenVertex::particles_out_const_iterator out_begin,
220  HepMC::GenVertex::particles_out_const_iterator out_end) const {
221  ParticleData const *pid;
222 
223  std::ostringstream vDescription;
224 
225  std::size_t j = 0;
226 
227  HepMC::GenVertex::particles_in_const_iterator in, itmp;
228 
229  for (in = in_begin; in != in_end; in++, j++) {
230  if (!j)
231  vDescription << "(";
232 
233  HepPDT::ParticleID particleType((*in)->pdg_id());
234 
235  if (particleType.isValid()) {
236  pid = pdt_->particle(particleType);
237  if (pid)
238  vDescription << pid->name();
239  else
240  vDescription << (*in)->pdg_id();
241  } else
242  vDescription << (*in)->pdg_id();
243 
244  itmp = in;
245 
246  if (++itmp == in_end)
247  vDescription << ")";
248  else
249  vDescription << ",";
250  }
251 
252  vDescription << "->";
253  j = 0;
254 
255  HepMC::GenVertex::particles_out_const_iterator out, otmp;
256 
257  for (out = out_begin; out != out_end; out++, j++) {
258  if (!j)
259  vDescription << "(";
260 
261  HepPDT::ParticleID particleType((*out)->pdg_id());
262 
263  if (particleType.isValid()) {
264  pid = pdt_->particle(particleType);
265  if (pid)
266  vDescription << pid->name();
267  else
268  vDescription << (*out)->pdg_id();
269  } else
270  vDescription << (*out)->pdg_id();
271 
272  otmp = out;
273 
274  if (++otmp == out_end)
275  vDescription << ")";
276  else
277  vDescription << ",";
278  }
279 
280  return vDescription.str();
281 }
282 
HiggsValidation_cfi.pdg_id
pdg_id
Definition: HiggsValidation_cfi.py:6
VertexHistoryAnalyzer::beginJob
void beginJob() override
Definition: VertexHistoryAnalyzer.cc:143
VertexCategories::is
bool is(Category category) const
Returns track flag for a given category.
Definition: VertexCategories.h:61
HistoryBase::SimParticleTrail
std::vector< TrackingParticleRef > SimParticleTrail
SimParticle trail type.
Definition: HistoryBase.h:30
EDAnalyzer.h
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
ESHandle.h
edm::Run
Definition: Run.h:45
gather_cfg.cout
cout
Definition: gather_cfg.py:144
VertexHistoryAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: VertexHistoryAnalyzer.cc:67
HistoryBase::GenParticleTrail
std::vector< const HepMC::GenParticle * > GenParticleTrail
HepMC::GenParticle trail type.
Definition: HistoryBase.h:15
VertexHistoryAnalyzer
Definition: VertexHistoryAnalyzer.cc:34
edm::RefVector< TrackingParticleCollection >
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
config
Definition: config.py:1
MakerMacros.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
VertexClassifier.h
HistoryBase::simVertexTrail
const SimVertexTrail & simVertexTrail() const
Return all the simulated vertices in the history.
Definition: HistoryBase.h:52
HistoryBase::GenVertexTrail
std::vector< const HepMC::GenVertex * > GenVertexTrail
GenVertex trail type.
Definition: HistoryBase.h:24
edm::ESHandle< ParticleDataTable >
VertexClassifier::newEvent
virtual void newEvent(edm::Event const &, edm::EventSetup const &)
Pre-process event information (for accessing reconstraction information)
Definition: VertexClassifier.cc:33
HistoryBase::genParticleTrail
const GenParticleTrail & genParticleTrail() const
Return all generated particle (HepMC::GenParticle) in the history.
Definition: HistoryBase.h:61
HistoryBase::genVertexTrail
const GenVertexTrail & genVertexTrail() const
Return all generated vertex in the history.
Definition: HistoryBase.h:58
VertexClassifier
Get track history and classify it in function of their .
Definition: VertexClassifier.h:18
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
VertexHistoryAnalyzer::VertexHistoryAnalyzer
VertexHistoryAnalyzer(const edm::ParameterSet &)
Definition: VertexHistoryAnalyzer.cc:61
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ParticleDataTable.h
VertexHistory
This class traces the simulated and generated history of a given track.
Definition: VertexHistory.h:18
recoMuon::in
Definition: RecoMuonEnumerators.h:6
VertexHistoryAnalyzer::beginRun
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: VertexHistoryAnalyzer.cc:138
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
edm::EventSetup
Definition: EventSetup.h:58
VertexHistoryAnalyzer::particleString
std::string particleString(int) const
Definition: VertexHistoryAnalyzer.cc:145
VertexHistoryAnalyzer::vertexProducer_
edm::InputTag vertexProducer_
Definition: VertexHistoryAnalyzer.cc:47
writedatasetfile.run
run
Definition: writedatasetfile.py:27
HistoryBase::simParticleTrail
const SimParticleTrail & simParticleTrail() const
Return all the simulated particle in the history.
Definition: HistoryBase.h:55
VertexHistoryAnalyzer::vertexString
std::string vertexString(const TrackingParticleRefVector &, const TrackingParticleRefVector &) const
Definition: VertexHistoryAnalyzer.cc:164
Frameworkfwd.h
spclusmultinvestigator_cfi.vertexCollection
vertexCollection
Definition: spclusmultinvestigator_cfi.py:4
VertexClassifier::evaluate
const VertexClassifier & evaluate(reco::VertexBaseRef const &)
Classify the RecoVertex in categories.
Definition: VertexClassifier.cc:47
EventSetup.h
edm::RefToBase< reco::Vertex >
VertexClassifier::history
const VertexHistory & history() const
Returns a reference to the vertex history used in the classification.
Definition: VertexClassifier.h:41
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
VertexCategories::Fake
Definition: VertexCategories.h:12
ParameterSet.h
PbPb_ZMuSkimMuonDPG_cff.particleType
particleType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:27
VertexHistoryAnalyzer::classifier_
VertexClassifier classifier_
Definition: VertexHistoryAnalyzer.cc:45
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
VertexHistoryAnalyzer::pdt_
edm::ESHandle< ParticleDataTable > pdt_
Definition: VertexHistoryAnalyzer.cc:49
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
edm::InputTag
Definition: InputTag.h:15
HistoryBase::SimVertexTrail
std::vector< TrackingVertexRef > SimVertexTrail
SimVertex trail type.
Definition: HistoryBase.h:33