CMS 3D CMS Logo

DTSimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
6  : MuonSimHitMatcher(ps, std::move(iC)) {
7  simHitPSet_ = ps.getParameterSet("dtSimHit");
8  verbose_ = simHitPSet_.getParameter<int>("verbose");
9  simMuOnly_ = simHitPSet_.getParameter<bool>("simMuOnly");
10  discardEleHits_ = simHitPSet_.getParameter<bool>("discardEleHits");
11 
13 }
14 
17  iSetup.get<MuonGeometryRecord>().get(dt_geom_);
18  if (dt_geom_.isValid()) {
19  geometry_ = &*dt_geom_;
20  } else {
21  hasGeometry_ = false;
22  edm::LogWarning("DTSimHitMatcher") << "+++ Info: DT geometry is unavailable. +++\n";
23  }
24  MuonSimHitMatcher::init(iEvent, iSetup);
25 }
26 
29  // instantiates the track ids and simhits
30  MuonSimHitMatcher::match(track, vertex);
31 
32  if (hasGeometry_) {
34 
35  if (verbose_) {
36  edm::LogInfo("DTSimHitMatcher") << "nTrackIds " << track_ids_.size() << " nSelectedDTSimHits " << hits_.size()
37  << endl;
38  edm::LogInfo("DTSimHitMatcher") << "detids DT " << detIds(0).size() << endl;
39 
40  const auto& dt_det_ids = detIds(0);
41  for (const auto& id : dt_det_ids) {
42  const auto& dt_simhits = MuonSimHitMatcher::hitsInDetId(id);
43  const auto& dt_simhits_gp = simHitsMeanPosition(dt_simhits);
44  edm::LogInfo("DTSimHitMatcher") << "DTWireId " << DTWireId(id) << ": nHits " << dt_simhits.size() << " eta "
45  << dt_simhits_gp.eta() << " phi " << dt_simhits_gp.phi() << " nCh "
46  << chamber_to_hits_[id].size() << endl;
47  }
48  }
49  }
50 }
51 
53  for (const auto& track_id : track_ids_) {
54  for (const auto& h : simHits_) {
55  if (h.trackId() != track_id)
56  continue;
57  int pdgid = h.particleType();
58  if (simMuOnly_ && std::abs(pdgid) != 13)
59  continue;
60  // discard electron hits in the DT chambers
61  if (discardEleHits_ && pdgid == 11)
62  continue;
63 
64  const DTWireId layer_id(h.detUnitId());
65  detid_to_hits_[h.detUnitId()].push_back(h);
66  hits_.push_back(h);
67  layer_to_hits_[layer_id.layerId().rawId()].push_back(h);
68  superlayer_to_hits_[layer_id.superlayerId().rawId()].push_back(h);
69  chamber_to_hits_[layer_id.chamberId().rawId()].push_back(h);
70  }
71  }
72 }
73 
74 std::set<unsigned int> DTSimHitMatcher::detIds(int dt_type) const {
75  std::set<unsigned int> result;
76  for (const auto& p : detid_to_hits_) {
77  const auto& id = p.first;
78  if (dt_type > 0) {
79  DTWireId detId(id);
80  if (MuonHitHelper::toDTType(detId.wheel(), detId.station()) != dt_type)
81  continue;
82  }
83  result.insert(id);
84  }
85  return result;
86 }
87 
88 std::set<unsigned int> DTSimHitMatcher::chamberIds(int dt_type) const {
89  std::set<unsigned int> result;
90  for (const auto& p : chamber_to_hits_) {
91  const auto& id = p.first;
92  if (dt_type > 0) {
93  DTChamberId detId(id);
94  if (MuonHitHelper::toDTType(detId.wheel(), detId.station()) != dt_type)
95  continue;
96  }
97  result.insert(id);
98  }
99  return result;
100 }
101 
102 std::set<unsigned int> DTSimHitMatcher::layerIds() const {
103  std::set<unsigned int> result;
104  for (const auto& p : layer_to_hits_)
105  result.insert(p.first);
106  return result;
107 }
108 
109 std::set<unsigned int> DTSimHitMatcher::superlayerIds() const {
110  std::set<unsigned int> result;
111  for (const auto& p : superlayer_to_hits_)
112  result.insert(p.first);
113  return result;
114 }
115 
116 const edm::PSimHitContainer& DTSimHitMatcher::hitsInLayer(unsigned int detid) const {
117  if (!MuonHitHelper::isDT(detid))
118  return no_hits_;
119 
120  const DTWireId id(detid);
121  if (layer_to_hits_.find(id.layerId().rawId()) == layer_to_hits_.end())
122  return no_hits_;
123  return layer_to_hits_.at(id.layerId().rawId());
124 }
125 
127  if (!MuonHitHelper::isDT(detid))
128  return no_hits_;
129 
130  const DTWireId id(detid);
131  if (superlayer_to_hits_.find(id.superlayerId().rawId()) == superlayer_to_hits_.end())
132  return no_hits_;
133  return superlayer_to_hits_.at(id.superlayerId().rawId());
134 }
135 
136 const edm::PSimHitContainer& DTSimHitMatcher::hitsInChamber(unsigned int detid) const {
137  if (!MuonHitHelper::isDT(detid))
138  return no_hits_;
139 
140  const DTWireId id(detid);
141  if (chamber_to_hits_.find(id.chamberId().rawId()) == chamber_to_hits_.end())
142  return no_hits_;
143  return chamber_to_hits_.at(id.chamberId().rawId());
144 }
145 
146 bool DTSimHitMatcher::hitStation(int st, int nsuperlayers, int nlayers) const {
147  int nst = 0;
148  for (const auto& ddt : chamberIds()) {
149  const DTChamberId id(ddt);
150  if (id.station() != st)
151  continue;
152 
153  // require at least 1 superlayer
154  const int nsl(nSuperLayersWithHitsInChamber(id.rawId()));
155  if (nsl < nsuperlayers)
156  continue;
157 
158  // require at least 3 layers hit per chamber
159  const int nl(nLayersWithHitsInChamber(id.rawId()));
160  if (nl < nlayers)
161  continue;
162  ++nst;
163  }
164  return nst;
165 }
166 
167 int DTSimHitMatcher::nStations(int nsuperlayers, int nlayers) const {
168  return (hitStation(1, nsuperlayers, nlayers) + hitStation(2, nsuperlayers, nlayers) +
169  hitStation(3, nsuperlayers, nlayers) + hitStation(4, nsuperlayers, nlayers));
170 }
171 
172 int DTSimHitMatcher::nCellsWithHitsInLayer(unsigned int detid) const {
173  set<int> layers_with_hits;
174  const auto& hits = hitsInLayer(detid);
175  for (const auto& h : hits) {
176  if (MuonHitHelper::isDT(detid)) {
177  const DTWireId idd(h.detUnitId());
178  layers_with_hits.insert(idd.wire());
179  }
180  }
181  return layers_with_hits.size();
182 }
183 
184 int DTSimHitMatcher::nLayersWithHitsInSuperLayer(unsigned int detid) const {
185  set<int> layers_with_hits;
186  const auto& hits = hitsInSuperLayer(detid);
187  for (const auto& h : hits) {
188  if (MuonHitHelper::isDT(detid)) {
189  const DTLayerId idd(h.detUnitId());
190  layers_with_hits.insert(idd.layer());
191  }
192  }
193  return layers_with_hits.size();
194 }
195 
196 int DTSimHitMatcher::nSuperLayersWithHitsInChamber(unsigned int detid) const {
197  set<int> sl_with_hits;
198  const auto& hits = MuonSimHitMatcher::hitsInChamber(detid);
199  for (const auto& h : hits) {
200  if (MuonHitHelper::isDT(detid)) {
201  const DTSuperLayerId idd(h.detUnitId());
202  sl_with_hits.insert(idd.superLayer());
203  }
204  }
205  return sl_with_hits.size();
206 }
207 
208 int DTSimHitMatcher::nLayersWithHitsInChamber(unsigned int detid) const {
209  int nLayers = 0;
210  const auto& superLayers(dynamic_cast<const DTGeometry*>(geometry_)->chamber(DTChamberId(detid))->superLayers());
211  for (const auto& sl : superLayers) {
212  nLayers += nLayersWithHitsInSuperLayer(sl->id().rawId());
213  }
214  return nLayers;
215 }
217  if (sim_hits.empty())
218  return -1.f;
219 
220  float sums = 0.f;
221  size_t n = 0;
222  for (const auto& h : sim_hits) {
223  const LocalPoint& lp = h.entryPoint();
224  float s;
225  const auto& d = h.detUnitId();
226  if (MuonHitHelper::isDT(d)) {
227  // find nearest wire
228  s = dynamic_cast<const DTGeometry*>(geometry_)->layer(DTLayerId(d))->specificTopology().channel(lp);
229  } else
230  continue;
231  sums += s;
232  ++n;
233  }
234  if (n == 0)
235  return -1.f;
236  return sums / n;
237 }
238 
239 std::set<unsigned int> DTSimHitMatcher::hitWiresInDTLayerId(unsigned int detid, int margin_n_wires) const {
240  set<unsigned int> result;
241  if (MuonHitHelper::isDT(detid)) {
242  DTLayerId id(detid);
243  int max_nwires = dynamic_cast<const DTGeometry*>(geometry_)->layer(id)->specificTopology().channels();
244  for (int wn = 0; wn <= max_nwires; ++wn) {
245  DTWireId wid(id, wn);
246  for (const auto& h : MuonSimHitMatcher::hitsInDetId(wid.rawId())) {
247  if (verbose_)
248  edm::LogInfo("DTSimHitMatcher") << "central DTWireId " << wid << " simhit " << h << endl;
249  int smin = wn - margin_n_wires;
250  smin = (smin > 0) ? smin : 1;
251  int smax = wn + margin_n_wires;
252  smax = (smax <= max_nwires) ? smax : max_nwires;
253  for (int ss = smin; ss <= smax; ++ss) {
254  DTWireId widd(id, ss);
255  if (verbose_)
256  edm::LogInfo("DTSimHitMatcher") << "\tadding DTWireId to collection " << widd << endl;
257  result.insert(widd.rawId());
258  }
259  }
260  }
261  }
262  return result;
263 }
264 
265 std::set<unsigned int> DTSimHitMatcher::hitWiresInDTSuperLayerId(unsigned int detid, int margin_n_wires) const {
266  set<unsigned int> result;
267  const auto& layers(dynamic_cast<const DTGeometry*>(geometry_)->superLayer(DTSuperLayerId(detid))->layers());
268  for (const auto& l : layers) {
269  if (verbose_)
270  edm::LogInfo("DTSimHitMatcher") << "hitWiresInDTSuperLayerId::l id " << l->id() << endl;
271  const auto& p(hitWiresInDTLayerId(l->id().rawId(), margin_n_wires));
272  result.insert(p.begin(), p.end());
273  }
274  return result;
275 }
276 
277 std::set<unsigned int> DTSimHitMatcher::hitWiresInDTChamberId(unsigned int detid, int margin_n_wires) const {
278  set<unsigned int> result;
279  const auto& superLayers(dynamic_cast<const DTGeometry*>(geometry_)->chamber(DTChamberId(detid))->superLayers());
280  for (const auto& sl : superLayers) {
281  if (verbose_)
282  edm::LogInfo("DTSimHitMatcher") << "hitWiresInDTChamberId::sl id " << sl->id() << endl;
283  const auto& p(hitWiresInDTSuperLayerId(sl->id().rawId(), margin_n_wires));
284  result.insert(p.begin(), p.end());
285  }
286  return result;
287 }
288 
289 void DTSimHitMatcher::dtChamberIdsToString(const std::set<unsigned int>& set) const {
290  for (const auto& p : set) {
291  DTChamberId detId(p);
292  edm::LogInfo("DTSimHitMatcher") << " " << detId << "\n";
293  }
294 }
295 
296 std::set<unsigned int> DTSimHitMatcher::chamberIdsStation(int station) const {
297  set<unsigned int> result;
298  switch (station) {
299  case 1: {
300  const auto& p1(chamberIds(MuonHitHelper::DT_MB21p));
301  const auto& p2(chamberIds(MuonHitHelper::DT_MB11p));
302  const auto& p3(chamberIds(MuonHitHelper::DT_MB01));
303  const auto& p4(chamberIds(MuonHitHelper::DT_MB11n));
304  const auto& p5(chamberIds(MuonHitHelper::DT_MB21n));
305  result.insert(p1.begin(), p1.end());
306  result.insert(p2.begin(), p2.end());
307  result.insert(p3.begin(), p3.end());
308  result.insert(p4.begin(), p4.end());
309  result.insert(p5.begin(), p5.end());
310  break;
311  }
312  case 2: {
313  const auto& p1(chamberIds(MuonHitHelper::DT_MB22p));
314  const auto& p2(chamberIds(MuonHitHelper::DT_MB12p));
315  const auto& p3(chamberIds(MuonHitHelper::DT_MB02));
316  const auto& p4(chamberIds(MuonHitHelper::DT_MB12n));
317  const auto& p5(chamberIds(MuonHitHelper::DT_MB22n));
318  result.insert(p1.begin(), p1.end());
319  result.insert(p2.begin(), p2.end());
320  result.insert(p3.begin(), p3.end());
321  result.insert(p4.begin(), p4.end());
322  result.insert(p5.begin(), p5.end());
323  break;
324  }
325  case 3: {
326  const auto& p1(chamberIds(MuonHitHelper::DT_MB23p));
327  const auto& p2(chamberIds(MuonHitHelper::DT_MB13p));
328  const auto& p3(chamberIds(MuonHitHelper::DT_MB03));
329  const auto& p4(chamberIds(MuonHitHelper::DT_MB13n));
330  const auto& p5(chamberIds(MuonHitHelper::DT_MB23n));
331  result.insert(p1.begin(), p1.end());
332  result.insert(p2.begin(), p2.end());
333  result.insert(p3.begin(), p3.end());
334  result.insert(p4.begin(), p4.end());
335  result.insert(p5.begin(), p5.end());
336  break;
337  }
338  case 4: {
339  const auto& p1(chamberIds(MuonHitHelper::DT_MB24p));
340  const auto& p2(chamberIds(MuonHitHelper::DT_MB14p));
341  const auto& p3(chamberIds(MuonHitHelper::DT_MB04));
342  const auto& p4(chamberIds(MuonHitHelper::DT_MB14n));
343  const auto& p5(chamberIds(MuonHitHelper::DT_MB24n));
344  result.insert(p1.begin(), p1.end());
345  result.insert(p2.begin(), p2.end());
346  result.insert(p3.begin(), p3.end());
347  result.insert(p4.begin(), p4.end());
348  result.insert(p5.begin(), p5.end());
349  break;
350  }
351  };
352  return result;
353 }
static bool isDT(unsigned int detId)
check detid type
Definition: MuonHitHelper.cc:3
T getParameter(std::string const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
constexpr int nLayers
Definition: Common.h:13
const TrackingGeometry * geometry_
std::set< unsigned int > detIds(int type=MuonHitHelper::DT_ALL) const
edm::PSimHitContainer hits_
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const edm::PSimHitContainer & hitsInChamber(unsigned int) const
void matchSimHitsToSimTrack()
int nLayersWithHitsInSuperLayer(unsigned int) const
std::set< unsigned int > hitWiresInDTSuperLayerId(unsigned int, int margin_n_wires=0) const
std::set< unsigned int > chamberIdsStation(int station) const
std::set< unsigned int > hitWiresInDTChamberId(unsigned int, int margin_n_wires=0) const
std::vector< unsigned > track_ids_
DTSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
std::set< unsigned int > chamberIds(int type=MuonHitHelper::DT_ALL) const
int iEvent
Definition: GenABIO.cc:224
GlobalPoint simHitsMeanPosition(const edm::PSimHitContainer &sim_hits) const
edm::PSimHitContainer simHits_
const edm::PSimHitContainer & hitsInSuperLayer(unsigned int) const
edm::ParameterSet simHitPSet_
double p4[4]
Definition: TauolaWrapper.h:92
void match(const SimTrack &t, const SimVertex &v)
do the matching
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int nStations(int nsl=1, int nl=3) const
const edm::PSimHitContainer & hitsInLayer(unsigned int) const
double f[11][100]
double p2[4]
Definition: TauolaWrapper.h:90
d
Definition: ztail.py:151
edm::ESHandle< DTGeometry > dt_geom_
std::set< unsigned int > hitWiresInDTLayerId(unsigned int, int margin_n_wires=0) const
edm::PSimHitContainer no_hits_
int nLayersWithHitsInChamber(unsigned int) const
std::set< unsigned int > layerIds() const
bool hitStation(int, int, int) const
ParameterSet const & getParameterSet(std::string const &) const
const edm::PSimHitContainer & hitsInDetId(unsigned int) const
void match(const SimTrack &t, const SimVertex &v)
do the matching
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
std::map< unsigned int, edm::PSimHitContainer > superlayer_to_hits_
double p1[4]
Definition: TauolaWrapper.h:89
T get() const
Definition: EventSetup.h:73
float simHitsMeanWire(const edm::PSimHitContainer &sim_hits) const
std::vector< PSimHit > PSimHitContainer
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
int station() const
Return the station number.
Definition: DTChamberId.h:42
bool isValid() const
Definition: ESHandle.h:44
static int toDTType(int wh, int st)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
const edm::PSimHitContainer & hitsInChamber(unsigned int) const
void dtChamberIdsToString(const std::set< unsigned int > &) const
def move(src, dest)
Definition: eostools.py:511
int nSuperLayersWithHitsInChamber(unsigned int) const
std::set< unsigned int > superlayerIds() const
int nCellsWithHitsInLayer(unsigned int) const
double p3[4]
Definition: TauolaWrapper.h:91
std::map< unsigned int, edm::PSimHitContainer > layer_to_hits_