CMS 3D CMS Logo

GEMSimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
6  : MuonSimHitMatcher(ps, std::move(iC)) {
7  simHitPSet_ = ps.getParameterSet("gemSimHit");
8  verbose_ = simHitPSet_.getParameter<int>("verbose");
9  simMuOnly_ = simHitPSet_.getParameter<bool>("simMuOnly");
10  discardEleHits_ = simHitPSet_.getParameter<bool>("discardEleHits");
11 
13  geomToken_ = iC.esConsumes<GEMGeometry, MuonGeometryRecord>();
14 }
15 
18  geometry_ = &iSetup.getData(geomToken_);
20 }
21 
24  clear();
25 
26  // instantiates the track ids and simhits
28 
29  // hard cut on non-GEM muons
30  if (std::abs(track.momentum().eta()) < 1.55)
31  return;
32 
34 
35  if (verbose_) {
36  edm::LogInfo("GEMSimHitMatcher") << "nTrackIds " << track_ids_.size() << " nSelectedGEMSimHits " << hits_.size();
37  edm::LogInfo("GEMSimHitMatcher") << "detids GEM " << detIds(0).size();
38 
39  const auto& gem_ch_ids = detIds();
40  for (const auto& id : gem_ch_ids) {
41  const auto& gem_simhits = MuonSimHitMatcher::hitsInDetId(id);
42  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
43  edm::LogInfo("GEMSimHitMatcher") << "gemchid " << GEMDetId(id) << ": nHits " << gem_simhits.size() << " phi "
44  << gem_simhits_gp.phi() << " nCh " << chamber_to_hits_[id].size();
45  const auto& strips = hitStripsInDetId(id);
46  edm::LogInfo("GEMSimHitMatcher") << "nStrip " << strips.size();
47  edm::LogInfo("GEMSimHitMatcher") << "strips : ";
48  for (const auto& p : strips) {
49  edm::LogInfo("GEMSimHitMatcher") << p;
50  }
51  }
52  const auto& gem_sch_ids = superChamberIds();
53  for (const auto& id : gem_sch_ids) {
54  const auto& gem_simhits = hitsInSuperChamber(id);
55  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
56  edm::LogInfo("GEMSimHitMatcher") << "gemschid " << GEMDetId(id) << ": " << nCoincidencePadsWithHits() << " | "
57  << gem_simhits.size() << " " << gem_simhits_gp.phi() << " "
58  << superchamber_to_hits_[id].size();
59  }
60  }
61 }
62 
64  for (const auto& track_id : track_ids_) {
65  for (const auto& h : simHits_) {
66  if (h.trackId() != track_id)
67  continue;
68 
69  const GEMDetId& p_id(h.detUnitId());
70 
71  int pdgid = h.particleType();
72 
73  // consider only the muon hits
74  if (simMuOnly_ && std::abs(pdgid) != 13)
75  continue;
76 
77  // discard electron hits in the GEM chambers
78  if (discardEleHits_ && std::abs(pdgid) == 11)
79  continue;
80 
81  detid_to_hits_[p_id.rawId()].push_back(h);
82  hits_.push_back(h);
83  chamber_to_hits_[p_id.chamberId().rawId()].push_back(h);
84  superchamber_to_hits_[p_id.superChamberId().rawId()].push_back(h);
85  }
86  }
87 
88  // find pads with hits
89  const auto& detids = detIds();
90  // find 2-layer coincidence pads with hits
91  for (const auto& d : detids) {
92  GEMDetId id(d);
93  const auto& hits = hitsInDetId(d);
94  const auto& roll = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id);
95  // int max_npads = roll->npads();
96  set<int> pads;
97  for (const auto& h : hits) {
98  const LocalPoint& lp = h.entryPoint();
99  pads.insert(static_cast<int>(roll->padTopology().channel(lp)));
100  }
101  detids_to_pads_[d] = pads;
102  }
103 
104  // find 2-layer coincidence pads with hits
105  for (const auto& d : detids) {
106  GEMDetId id1(d);
107  if (id1.layer() != 1)
108  continue;
109 
110  // find pads with hits in layer1
111  const auto& hits1 = hitsInDetId(d);
112  const auto& roll1 = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id1);
113  set<int> pads1;
114  set<int> pads2;
115  set<int> copads;
116 
117  for (const auto& h : hits1) {
118  const LocalPoint& lp = h.entryPoint();
119  pads1.insert(static_cast<int>(roll1->padTopology().channel(lp)));
120  if (verbose_)
121  edm::LogInfo("GEMSimHitMatcher") << "GEMHits detid1 " << id1 << " pad1 "
122  << static_cast<int>(roll1->padTopology().channel(lp)) << std::endl;
123  }
124 
125  // find pads with hits in layer2
126  for (const auto& d2 : detids) {
127  // staggered geometry???? improve here !!
128  GEMDetId id2(d2);
129  // does layer 2 has simhits?
130  if (id2.layer() != 2 or id2.region() != id1.region() or id2.ring() != id1.ring() or
131  id2.station() != id1.station() or abs(id2.roll() - id1.roll()) > 1)
132  continue;
133  const auto& hits2 = hitsInDetId(id2());
134  const auto& roll2 = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id2);
135  for (const auto& h : hits2) {
136  const LocalPoint& lp = h.entryPoint();
137  pads2.insert(static_cast<int>(roll2->padTopology().channel(lp)));
138  if (verbose_)
139  edm::LogInfo("GEMSimHitMatcher") << "GEMHits detid2 " << id2 << " pad2 "
140  << static_cast<int>(roll2->padTopology().channel(lp)) << std::endl;
141  }
142  }
143 
144  for (const auto& pad1 : pads1) {
145  for (const auto& pad2 : pads2) {
146  if (abs(pad1 - pad2) <= 2) {
147  if (copads.find(pad1) == copads.end())
148  copads.insert(pad1);
149  if (copads.find(pad2) == copads.end())
150  copads.insert(pad2);
151  }
152  }
153  }
154 
155  if (copads.empty())
156  continue;
157 
158  // detids here is layer1 id
159  detids_to_copads_[d] = copads;
160  }
161 }
162 
163 std::set<unsigned int> GEMSimHitMatcher::detIds(int gem_type) const {
164  std::set<unsigned int> result;
165  for (const auto& p : detid_to_hits_) {
166  const auto& id = p.first;
167  if (gem_type > 0) {
168  GEMDetId detId(id);
169  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
170  continue;
171  }
172  result.insert(id);
173  }
174  return result;
175 }
176 
177 std::set<unsigned int> GEMSimHitMatcher::detIdsCoincidences() const {
178  std::set<unsigned int> result;
179  for (const auto& p : detids_to_copads_)
180  result.insert(p.first);
181  return result;
182 }
183 
184 std::set<unsigned int> GEMSimHitMatcher::chamberIds(int gem_type) const {
185  std::set<unsigned int> result;
186  for (const auto& p : chamber_to_hits_) {
187  const auto& id = p.first;
188  if (gem_type > 0) {
189  GEMDetId detId(id);
190  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
191  continue;
192  }
193  result.insert(id);
194  }
195  return result;
196 }
197 
198 std::set<unsigned int> GEMSimHitMatcher::superChamberIds() const {
199  std::set<unsigned int> result;
200  for (const auto& p : superchamber_to_hits_)
201  result.insert(p.first);
202  return result;
203 }
204 
205 std::set<unsigned int> GEMSimHitMatcher::superChamberIdsCoincidences() const {
206  std::set<unsigned int> result;
207  for (const auto& p : detids_to_copads_) {
208  const GEMDetId& p_id(p.first);
209  result.insert(p_id.superChamberId().rawId());
210  }
211  return result;
212 }
213 
215  if (MuonHitHelper::isGEM(detid)) {
216  const GEMDetId id(detid);
217  if (superchamber_to_hits_.find(id.chamberId().rawId()) == superchamber_to_hits_.end())
218  return no_hits_;
219  return superchamber_to_hits_.at(id.chamberId().rawId());
220  }
221 
222  return no_hits_;
223 }
224 
225 int GEMSimHitMatcher::nLayersWithHitsInSuperChamber(unsigned int detid) const {
226  set<int> layers_with_hits;
227  const auto& hits = hitsInSuperChamber(detid);
228  for (const auto& h : hits) {
229  const GEMDetId& idd(h.detUnitId());
230  layers_with_hits.insert(idd.layer());
231  }
232  return layers_with_hits.size();
233 }
234 
235 bool GEMSimHitMatcher::hitStation(int st, int nlayers) const {
236  int nst = 0;
237  for (const auto& ddt : chamberIds()) {
238  const GEMDetId id(ddt);
239  if (id.station() != st)
240  continue;
241 
242  const int nl(nLayersWithHitsInSuperChamber(id.rawId()));
243  if (nl < nlayers)
244  continue;
245  ++nst;
246  }
247  return nst;
248 }
249 
251 
253  if (sim_hits.empty())
254  return -0.0; // point "zero"
255 
256  float central = -0.0;
257  size_t n = 0;
258  for (const auto& h : sim_hits) {
259  LocalPoint lp(0., 0., 0.); // local central
260  GlobalPoint gp;
261  if (MuonHitHelper::isGEM(h.detUnitId())) {
262  gp = geometry_->idToDet(h.detUnitId())->surface().toGlobal(lp);
263  }
264  central = gp.perp();
265  if (n >= 1)
266  edm::LogWarning("GEMSimHitMatcher") << "warning! find more than one simhits in GEM chamber " << std::endl;
267  ++n;
268  }
269 
270  return central;
271 }
272 
274  if (sim_hits.empty())
275  return -1.f;
276 
277  float sums = 0.f;
278  size_t n = 0;
279  for (const auto& h : sim_hits) {
280  const LocalPoint& lp = h.entryPoint();
281  const auto& d = h.detUnitId();
282  sums += dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(d)->strip(lp);
283  ++n;
284  }
285  if (n == 0)
286  return -1.f;
287  return sums / n;
288 }
289 
290 std::set<int> GEMSimHitMatcher::hitStripsInDetId(unsigned int detid, int margin_n_strips) const {
291  set<int> result;
292  const auto& simhits = MuonSimHitMatcher::hitsInDetId(detid);
293  GEMDetId id(detid);
294  int max_nstrips = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->nstrips();
295  for (const auto& h : simhits) {
296  const LocalPoint& lp = h.entryPoint();
297  int central_strip =
298  static_cast<int>(dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->topology().channel(lp));
299  int smin = central_strip - margin_n_strips;
300  smin = (smin > 0) ? smin : 0;
301  int smax = central_strip + margin_n_strips;
302  smax = (smax <= max_nstrips) ? smax : max_nstrips;
303  for (int ss = smin; ss <= smax; ++ss)
304  result.insert(ss);
305  }
306  return result;
307 }
308 
309 std::set<int> GEMSimHitMatcher::hitPadsInDetId(unsigned int detid) const {
310  set<int> none;
311  if (detids_to_pads_.find(detid) == detids_to_pads_.end())
312  return none;
313  return detids_to_pads_.at(detid);
314 }
315 
316 std::set<int> GEMSimHitMatcher::hitCoPadsInDetId(unsigned int detid) const {
317  set<int> none;
318  if (detids_to_copads_.find(detid) == detids_to_copads_.end())
319  return none;
320  return detids_to_copads_.at(detid);
321 }
322 
323 std::set<int> GEMSimHitMatcher::hitPartitions() const {
324  std::set<int> result;
325 
326  const auto& detids = detIds();
327  for (const auto& id : detids) {
328  GEMDetId idd(id);
329  result.insert(idd.roll());
330  }
331  return result;
332 }
333 
335  int result = 0;
336  const auto& pad_ids = detIds();
337  for (const auto& id : pad_ids) {
338  result += hitPadsInDetId(id).size();
339  }
340  return result;
341 }
342 
344  int result = 0;
345  const auto& copad_ids = detIdsCoincidences();
346  for (const auto& id : copad_ids) {
347  result += hitCoPadsInDetId(id).size();
348  }
349  return result;
350 }
351 
354 
355  superchamber_to_hits_.clear();
356  detids_to_pads_.clear();
357  detids_to_copads_.clear();
358 }
MuonSimHitMatcher::clear
void clear()
Definition: MuonSimHitMatcher.cc:139
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
SimVertex
Definition: SimVertex.h:5
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
GEMDetId::ring
constexpr int ring() const
Definition: GEMDetId.h:176
MuonHitHelper::toGEMType
static int toGEMType(int st, int ri)
Definition: MuonHitHelper.cc:49
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
MuonSimHitMatcher::geometry_
const TrackingGeometry * geometry_
Definition: MuonSimHitMatcher.h:84
GEMSimHitMatcher::nLayersWithHitsInSuperChamber
int nLayersWithHitsInSuperChamber(unsigned int) const
Definition: GEMSimHitMatcher.cc:225
relativeConstraints.station
station
Definition: relativeConstraints.py:67
GEMSimHitMatcher::superChamberIdsCoincidences
std::set< unsigned int > superChamberIdsCoincidences() const
Definition: GEMSimHitMatcher.cc:205
MuonSimHitMatcher::verbose_
bool verbose_
Definition: MuonSimHitMatcher.h:81
globals_cff.id1
id1
Definition: globals_cff.py:33
GEMSimHitMatcher::detIdsCoincidences
std::set< unsigned int > detIdsCoincidences() const
Definition: GEMSimHitMatcher.cc:177
MuonSimHitMatcher::detid_to_hits_
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
Definition: MuonSimHitMatcher.h:106
MuonSimHitMatcher::simHitsMeanPosition
GlobalPoint simHitsMeanPosition(const edm::PSimHitContainer &sim_hits) const
Definition: MuonSimHitMatcher.cc:99
MuonHitHelper::isGEM
static bool isGEM(unsigned int detId)
Definition: MuonHitHelper.cc:7
GEMDetId::superChamberId
constexpr GEMDetId superChamberId() const
Definition: GEMDetId.h:207
GEMSimHitMatcher::init
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
Definition: GEMSimHitMatcher.cc:17
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
GEMSimHitMatcher::nCoincidencePadsWithHits
int nCoincidencePadsWithHits() const
Definition: GEMSimHitMatcher.cc:343
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
GEMSimHitMatcher::hitStripsInDetId
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=1) const
Definition: GEMSimHitMatcher.cc:290
MuonSimHitMatcher::simHits_
edm::PSimHitContainer simHits_
Definition: MuonSimHitMatcher.h:97
GEMSimHitMatcher.h
none
Definition: EcalBoundaryInfoCalculator.h:24
GEMSimHitMatcher::hitStation
bool hitStation(int, int) const
Definition: GEMSimHitMatcher.cc:235
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
GEMSimHitMatcher::superChamberIds
std::set< unsigned int > superChamberIds() const
Definition: GEMSimHitMatcher.cc:198
TrackingGeometry::idToDet
virtual const GeomDet * idToDet(DetId) const =0
h
GEMSimHitMatcher::hitCoPadsInDetId
std::set< int > hitCoPadsInDetId(unsigned int) const
Definition: GEMSimHitMatcher.cc:316
GEMSimHitMatcher::hitPartitions
std::set< int > hitPartitions() const
Definition: GEMSimHitMatcher.cc:323
GEMSimHitMatcher::GEMSimHitMatcher
GEMSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
Definition: GEMSimHitMatcher.cc:5
MuonSimHitMatcher::simHitPSet_
edm::ParameterSet simHitPSet_
Definition: MuonSimHitMatcher.h:109
GEMSimHitMatcher::nStations
int nStations(int nl=2) const
Definition: GEMSimHitMatcher.cc:250
Point3DBase< float, LocalTag >
MuonSimHitMatcher::track_ids_
std::vector< unsigned > track_ids_
Definition: MuonSimHitMatcher.h:99
MuonSimHitMatcher::no_hits_
edm::PSimHitContainer no_hits_
Definition: MuonSimHitMatcher.h:102
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
GEMSimHitMatcher::detIds
std::set< unsigned int > detIds(int gem_type=MuonHitHelper::GEM_ALL) const
Definition: GEMSimHitMatcher.cc:163
MuonSimHitMatcher::discardEleHits_
bool discardEleHits_
Definition: MuonSimHitMatcher.h:80
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
HLTBitAnalyser_cfi.simhits
simhits
SIM objects.
Definition: HLTBitAnalyser_cfi.py:21
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
GEMSimHitMatcher::simHitsMeanStrip
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
Definition: GEMSimHitMatcher.cc:273
MuonSimHitMatcher
Definition: MuonSimHitMatcher.h:32
MuonSimHitMatcher::match
void match(const SimTrack &t, const SimVertex &v)
do the matching
Definition: MuonSimHitMatcher.cc:26
GEMDetId::roll
constexpr int roll() const
Definition: GEMDetId.h:194
GEMDetId
Definition: GEMDetId.h:18
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonSimHitMatcher::chamber_to_hits_
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
Definition: MuonSimHitMatcher.h:107
edm::EventSetup
Definition: EventSetup.h:58
GEMSimHitMatcher::superchamber_to_hits_
std::map< unsigned int, edm::PSimHitContainer > superchamber_to_hits_
Definition: GEMSimHitMatcher.h:84
MuonSimHitMatcher::simHitInput_
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
Definition: MuonSimHitMatcher.h:88
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
central
Definition: L1PrefiringWeightProducer.cc:40
MuonSimHitMatcher::hitsInDetId
const edm::PSimHitContainer & hitsInDetId(unsigned int) const
Definition: MuonSimHitMatcher.cc:87
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
SimTrack
Definition: SimTrack.h:9
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
GEMSimHitMatcher::detids_to_copads_
std::map< unsigned int, std::set< int > > detids_to_copads_
Definition: GEMSimHitMatcher.h:90
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
MuonSimHitMatcher::simMuOnly_
bool simMuOnly_
Definition: MuonSimHitMatcher.h:79
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
GEMSimHitMatcher::matchSimHitsToSimTrack
void matchSimHitsToSimTrack()
Definition: GEMSimHitMatcher.cc:63
GEMSimHitMatcher::simHitsGEMCentralPosition
float simHitsGEMCentralPosition(const edm::PSimHitContainer &sim_hits) const
Definition: GEMSimHitMatcher.cc:252
GEMSimHitMatcher::hitPadsInDetId
std::set< int > hitPadsInDetId(unsigned int) const
Definition: GEMSimHitMatcher.cc:309
GEMDetId::station
constexpr int station() const
Definition: GEMDetId.h:179
GEMGeometry
Definition: GEMGeometry.h:24
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
GEMSimHitMatcher::chamberIds
std::set< unsigned int > chamberIds(int gem_type=MuonHitHelper::GEM_ALL) const
Definition: GEMSimHitMatcher.cc:184
globals_cff.id2
id2
Definition: globals_cff.py:34
GEMSimHitMatcher::clear
void clear()
Definition: GEMSimHitMatcher.cc:352
GEMSimHitMatcher::hitsInSuperChamber
const edm::PSimHitContainer & hitsInSuperChamber(unsigned int) const
Definition: GEMSimHitMatcher.cc:214
MuonSimHitMatcher::hits_
edm::PSimHitContainer hits_
Definition: MuonSimHitMatcher.h:105
edm::Event
Definition: Event.h:73
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:29
MuonSimHitMatcher::init
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
Definition: MuonSimHitMatcher.cc:17
GEMSimHitMatcher::nPadsWithHits
int nPadsWithHits() const
Definition: GEMSimHitMatcher.cc:334
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
edm::InputTag
Definition: InputTag.h:15
DigiDM_cff.strips
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers....
Definition: DigiDM_cff.py:32
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
edm::ParameterSet::getParameterSet
ParameterSet const & getParameterSet(std::string const &) const
Definition: ParameterSet.cc:2128
GEMSimHitMatcher::geomToken_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Definition: GEMSimHitMatcher.h:82
GEMSimHitMatcher::detids_to_pads_
std::map< unsigned int, std::set< int > > detids_to_pads_
Definition: GEMSimHitMatcher.h:87
nlayers
Definition: HIMultiTrackSelector.h:48
GEMSimHitMatcher::match
void match(const SimTrack &t, const SimVertex &v)
do the matching
Definition: GEMSimHitMatcher.cc:23