CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <string>
12 #include <sstream>
13 #include <vector>
14 
15 // user include files
18 
26 
29 
30 //
31 // class decleration
32 //
33 
35 {
36 public:
37 
39 
40 private:
41 
42  virtual void beginRun(const edm::Run&,const edm::EventSetup&) override;
43  virtual void beginJob() override ;
44  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
45 
46  // Member data
47 
49 
51 
53 
54  std::string particleString(int) const;
55 
59  ) const;
60 
62  HepMC::GenVertex::particles_in_const_iterator,
63  HepMC::GenVertex::particles_in_const_iterator,
64  HepMC::GenVertex::particles_out_const_iterator,
65  HepMC::GenVertex::particles_out_const_iterator
66  ) const;
67 };
68 
69 
70 VertexHistoryAnalyzer::VertexHistoryAnalyzer(const edm::ParameterSet& config) : classifier_(config,consumesCollector())
71 {
72  vertexProducer_ = config.getUntrackedParameter<edm::InputTag> ("vertexProducer");
73  consumes<edm::View<reco::Vertex>>(vertexProducer_);
74 }
75 
76 
78 {
79  // Set the classifier for a new event
80  classifier_.newEvent(event, setup);
81 
82  // Vertex collection
84  event.getByLabel(vertexProducer_, vertexCollection);
85 
86  // Get a constant reference to the track history associated to the classifier
87  VertexHistory const & tracer = classifier_.history();
88 
89  // Loop over the track collection.
90  for (std::size_t index = 0; index < vertexCollection->size(); index++)
91  {
92  std::cout << std::endl << "History for vertex #" << index << " : " << std::endl;
93 
94  // Classify the track and detect for fakes
96  {
97  // Get the list of TrackingParticles associated to
99 
100  // Loop over all simParticles
101  for (std::size_t hindex=0; hindex<simParticles.size(); hindex++)
102  {
103  std::cout << " simParticles [" << hindex << "] : "
104  << particleString(simParticles[hindex]->pdgId())
105  << std::endl;
106  }
107 
108  // Get the list of TrackingVertexes associated to
109  VertexHistory::SimVertexTrail simVertexes(tracer.simVertexTrail());
110 
111  // Loop over all simVertexes
112  if ( !simVertexes.empty() )
113  {
114  for (std::size_t hindex=0; hindex<simVertexes.size(); hindex++)
115  {
116  std::cout << " simVertex [" << hindex << "] : "
117  << vertexString(
118  simVertexes[hindex]->sourceTracks(),
119  simVertexes[hindex]->daughterTracks()
120  )
121  << std::endl;
122  }
123  }
124  else
125  std::cout << " simVertex no found" << std::endl;
126 
127  // Get the list of GenParticles associated to
129 
130  // Loop over all genParticles
131  for (std::size_t hindex=0; hindex<genParticles.size(); hindex++)
132  {
133  std::cout << " genParticles [" << hindex << "] : "
134  << particleString(genParticles[hindex]->pdg_id())
135  << std::endl;
136  }
137 
138  // Get the list of TrackingVertexes associated to
139  VertexHistory::GenVertexTrail genVertexes(tracer.genVertexTrail());
140 
141  // Loop over all simVertexes
142  if ( !genVertexes.empty() )
143  {
144  for (std::size_t hindex=0; hindex<genVertexes.size(); hindex++)
145  {
146  std::cout << " genVertex [" << hindex << "] : "
147  << vertexString(
148  genVertexes[hindex]->particles_in_const_begin(),
149  genVertexes[hindex]->particles_in_const_end(),
150  genVertexes[hindex]->particles_out_const_begin(),
151  genVertexes[hindex]->particles_out_const_end()
152  )
153  << std::endl;
154  }
155  }
156  else
157  std::cout << " genVertex no found" << std::endl;
158  }
159  else
160  std::cout << " fake vertex" << std::endl;
161 
162  std::cout << " vertex categories : " << classifier_;
163  std::cout << std::endl;
164  }
165 }
166 
167 
168 void
170 {
171  // Get the particles table.
172  setup.getData( pdt_ );
173 }
174 
175 void
177 {
178 
179 }
180 
181 
183 {
184  ParticleData const * pid;
185 
186  std::ostringstream vDescription;
187 
188  HepPDT::ParticleID particleType(pdgId);
189 
190  if (particleType.isValid())
191  {
192  pid = pdt_->particle(particleType);
193  if (pid)
194  vDescription << pid->name();
195  else
196  vDescription << pdgId;
197  }
198  else
199  vDescription << pdgId;
200 
201  return vDescription.str();
202 }
203 
204 
208 ) const
209 {
210  ParticleData const * pid;
211 
212  std::ostringstream vDescription;
213 
214  for (std::size_t j = 0; j < in.size(); j++)
215  {
216  if (!j) vDescription << "(";
217 
218  HepPDT::ParticleID particleType(in[j]->pdgId());
219 
220  if (particleType.isValid())
221  {
222  pid = pdt_->particle(particleType);
223  if (pid)
224  vDescription << pid->name();
225  else
226  vDescription << in[j]->pdgId();
227  }
228  else
229  vDescription << in[j]->pdgId();
230 
231  if (j == in.size() - 1) vDescription << ")";
232  else vDescription << ",";
233  }
234 
235  vDescription << "->";
236 
237  for (std::size_t j = 0; j < out.size(); j++)
238  {
239  if (!j) vDescription << "(";
240 
241  HepPDT::ParticleID particleType(out[j]->pdgId());
242 
243  if (particleType.isValid())
244  {
245  pid = pdt_->particle(particleType);
246  if (pid)
247  vDescription << pid->name();
248  else
249  vDescription << out[j]->pdgId();
250  }
251  else
252  vDescription << out[j]->pdgId();
253 
254  if (j == out.size() - 1) vDescription << ")";
255  else vDescription << ",";
256  }
257 
258  return vDescription.str();
259 }
260 
261 
263  HepMC::GenVertex::particles_in_const_iterator in_begin,
264  HepMC::GenVertex::particles_in_const_iterator in_end,
265  HepMC::GenVertex::particles_out_const_iterator out_begin,
266  HepMC::GenVertex::particles_out_const_iterator out_end
267 ) const
268 {
269  ParticleData const * pid;
270 
271  std::ostringstream vDescription;
272 
273  std::size_t j = 0;
274 
275  HepMC::GenVertex::particles_in_const_iterator in, itmp;
276 
277  for (in = in_begin; in != in_end; in++, j++)
278  {
279  if (!j) vDescription << "(";
280 
281  HepPDT::ParticleID particleType((*in)->pdg_id());
282 
283  if (particleType.isValid())
284  {
285  pid = pdt_->particle(particleType);
286  if (pid)
287  vDescription << pid->name();
288  else
289  vDescription << (*in)->pdg_id();
290  }
291  else
292  vDescription << (*in)->pdg_id();
293 
294  itmp = in;
295 
296  if (++itmp == in_end) vDescription << ")";
297  else vDescription << ",";
298  }
299 
300  vDescription << "->";
301  j = 0;
302 
303  HepMC::GenVertex::particles_out_const_iterator out, otmp;
304 
305  for (out = out_begin; out != out_end; out++, j++)
306  {
307  if (!j) vDescription << "(";
308 
309  HepPDT::ParticleID particleType((*out)->pdg_id());
310 
311  if (particleType.isValid())
312  {
313  pid = pdt_->particle(particleType);
314  if (pid)
315  vDescription << pid->name();
316  else
317  vDescription << (*out)->pdg_id();
318  }
319  else
320  vDescription << (*out)->pdg_id();
321 
322  otmp = out;
323 
324  if (++otmp == out_end) vDescription << ")";
325  else vDescription << ",";
326  }
327 
328  return vDescription.str();
329 }
330 
331 
This class traces the simulated and generated history of a given track.
Definition: VertexHistory.h:18
T getUntrackedParameter(std::string const &, T const &) const
VertexHistory const & history() const
Returns a reference to the vertex history used in the classification.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string vertexString(const TrackingParticleRefVector &, const TrackingParticleRefVector &) const
SimVertexTrail const & simVertexTrail() const
Return all the simulated vertices in the history.
Definition: HistoryBase.h:53
Get track history and classify it in function of their .
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
tuple vertexCollection
void getData(T &iHolder) const
Definition: EventSetup.h:79
std::vector< const HepMC::GenParticle * > GenParticleTrail
GenParticle trail type.
Definition: HistoryBase.h:18
edm::ESHandle< ParticleDataTable > pdt_
std::string particleString(int) const
int j
Definition: DBlmapReader.cc:9
bool is(Category category) const
Returns track flag for a given category.
std::vector< const HepMC::GenVertex * > GenVertexTrail
GenVertex trail type.
Definition: HistoryBase.h:21
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
HepPDT::ParticleData ParticleData
VertexHistoryAnalyzer(const edm::ParameterSet &)
tuple pid
Definition: sysUtil.py:22
SimParticleTrail const & simParticleTrail() const
Return all the simulated particle in the history.
Definition: HistoryBase.h:59
VertexClassifier const & evaluate(reco::VertexBaseRef const &)
Classify the RecoVertex in categories.
size_type size() const
Size of the RefVector.
Definition: RefVector.h:99
tuple cout
Definition: gather_cfg.py:145
virtual void newEvent(edm::Event const &, edm::EventSetup const &)
Pre-process event information (for accessing reconstraction information)
GenVertexTrail const & genVertexTrail() const
Return all generated vertex in the history.
Definition: HistoryBase.h:65
std::vector< TrackingVertexRef > SimVertexTrail
SimVertex trail type.
Definition: HistoryBase.h:30
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
GenParticleTrail const & genParticleTrail() const
Return all generated particle in the history.
Definition: HistoryBase.h:71
tuple particleType
Definition: Run.h:43
std::vector< TrackingParticleRef > SimParticleTrail
SimParticle trail type.
Definition: HistoryBase.h:27
virtual void beginJob() override