CMS 3D CMS Logo

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