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 }
14 
18  if (gem_geom_.isValid()) {
19  geometry_ = dynamic_cast<const GEMGeometry*>(&*gem_geom_);
20  } else {
21  hasGeometry_ = false;
22  edm::LogWarning("GEMSimHitMatcher") << "+++ Info: GEM geometry is unavailable. +++\n";
23  }
25 }
26 
29  // instantiates the track ids and simhits
31 
32  if (hasGeometry_) {
34 
35  if (verbose_) {
36  edm::LogInfo("GEMSimHitMatcher") << "nTrackIds " << track_ids_.size() << " nSelectedGEMSimHits " << hits_.size()
37  << endl;
38  edm::LogInfo("GEMSimHitMatcher") << "detids GEM " << detIds(0).size() << endl;
39 
40  const auto& gem_ch_ids = detIds();
41  for (const auto& id : gem_ch_ids) {
42  const auto& gem_simhits = MuonSimHitMatcher::hitsInDetId(id);
43  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
44  edm::LogInfo("GEMSimHitMatcher") << "gemchid " << GEMDetId(id) << ": nHits " << gem_simhits.size() << " phi "
45  << gem_simhits_gp.phi() << " nCh " << chamber_to_hits_[id].size() << endl;
46  const auto& strips = hitStripsInDetId(id);
47  edm::LogInfo("GEMSimHitMatcher") << "nStrip " << strips.size() << endl;
48  edm::LogInfo("GEMSimHitMatcher") << "strips : ";
49  for (const auto& p : strips) {
50  edm::LogInfo("GEMSimHitMatcher") << p;
51  }
52  }
53  const auto& gem_sch_ids = superChamberIds();
54  for (const auto& id : gem_sch_ids) {
55  const auto& gem_simhits = hitsInSuperChamber(id);
56  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
57  edm::LogInfo("GEMSimHitMatcher") << "gemschid " << GEMDetId(id) << ": " << nCoincidencePadsWithHits() << " | "
58  << gem_simhits.size() << " " << gem_simhits_gp.phi() << " "
59  << superchamber_to_hits_[id].size() << endl;
60  }
61  }
62  }
63 }
64 
66  for (const auto& track_id : track_ids_) {
67  for (const auto& h : simHits_) {
68  if (h.trackId() != track_id)
69  continue;
70  int pdgid = h.particleType();
71  if (simMuOnly_ && std::abs(pdgid) != 13)
72  continue;
73  // discard electron hits in the GEM chambers
74  if (discardEleHits_ && pdgid == 11)
75  continue;
76 
77  const GEMDetId& p_id(h.detUnitId());
78  detid_to_hits_[h.detUnitId()].push_back(h);
79  hits_.push_back(h);
80  chamber_to_hits_[p_id.chamberId().rawId()].push_back(h);
81  superchamber_to_hits_[p_id.superChamberId().rawId()].push_back(h);
82  }
83  }
84 
85  // find pads with hits
86  const auto& detids = detIds();
87  // find 2-layer coincidence pads with hits
88  for (const auto& d : detids) {
89  GEMDetId id(d);
90  const auto& hits = hitsInDetId(d);
91  const auto& roll = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id);
92  // int max_npads = roll->npads();
93  set<int> pads;
94  for (const auto& h : hits) {
95  const LocalPoint& lp = h.entryPoint();
96  pads.insert(1 + static_cast<int>(roll->padTopology().channel(lp)));
97  }
98  detids_to_pads_[d] = pads;
99  }
100 
101  // find 2-layer coincidence pads with hits
102  for (const auto& d : detids) {
103  GEMDetId id1(d);
104  if (id1.layer() != 1)
105  continue;
106 
107  // find pads with hits in layer1
108  const auto& hits1 = hitsInDetId(d);
109  const auto& roll1 = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id1);
110  set<int> pads1;
111  set<int> pads2;
112  set<int> copads;
113 
114  for (const auto& h : hits1) {
115  const LocalPoint& lp = h.entryPoint();
116  pads1.insert(1 + static_cast<int>(roll1->padTopology().channel(lp)));
117  if (verbose_)
118  edm::LogInfo("GEMSimHitMatcher") << "GEMHits detid1 " << id1 << " pad1 "
119  << 1 + static_cast<int>(roll1->padTopology().channel(lp)) << std::endl;
120  }
121 
122  // find pads with hits in layer2
123  for (const auto& d2 : detids) {
124  // staggered geometry???? improve here !!
125  GEMDetId id2(d2);
126  // does layer 2 has simhits?
127  if (id2.layer() != 2 or id2.region() != id1.region() or id2.ring() != id1.ring() or
128  id2.station() != id1.station() or abs(id2.roll() - id1.roll()) > 1)
129  continue;
130  const auto& hits2 = hitsInDetId(id2());
131  const auto& roll2 = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id2);
132  for (const auto& h : hits2) {
133  const LocalPoint& lp = h.entryPoint();
134  pads2.insert(1 + static_cast<int>(roll2->padTopology().channel(lp)));
135  if (verbose_)
136  edm::LogInfo("GEMSimHitMatcher") << "GEMHits detid2 " << id2 << " pad2 "
137  << 1 + static_cast<int>(roll2->padTopology().channel(lp)) << std::endl;
138  }
139  }
140 
141  for (const auto& pad1 : pads1) {
142  for (const auto& pad2 : pads2) {
143  if (abs(pad1 - pad2) <= 2) {
144  if (copads.find(pad1) == copads.end())
145  copads.insert(pad1);
146  if (copads.find(pad2) == copads.end())
147  copads.insert(pad2);
148  }
149  }
150  }
151 
152  if (copads.empty())
153  continue;
154 
155  // detids here is layer1 id
156  detids_to_copads_[d] = copads;
157  }
158 }
159 
160 std::set<unsigned int> GEMSimHitMatcher::detIds(int gem_type) const {
161  std::set<unsigned int> result;
162  for (const auto& p : detid_to_hits_) {
163  const auto& id = p.first;
164  if (gem_type > 0) {
165  GEMDetId detId(id);
166  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
167  continue;
168  }
169  result.insert(id);
170  }
171  return result;
172 }
173 
174 std::set<unsigned int> GEMSimHitMatcher::detIdsCoincidences() const {
175  std::set<unsigned int> result;
176  for (const auto& p : detids_to_copads_)
177  result.insert(p.first);
178  return result;
179 }
180 
181 std::set<unsigned int> GEMSimHitMatcher::chamberIds(int gem_type) const {
182  std::set<unsigned int> result;
183  for (const auto& p : chamber_to_hits_) {
184  const auto& id = p.first;
185  if (gem_type > 0) {
186  GEMDetId detId(id);
187  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
188  continue;
189  }
190  result.insert(id);
191  }
192  return result;
193 }
194 
195 std::set<unsigned int> GEMSimHitMatcher::superChamberIds() const {
196  std::set<unsigned int> result;
197  for (const auto& p : superchamber_to_hits_)
198  result.insert(p.first);
199  return result;
200 }
201 
202 std::set<unsigned int> GEMSimHitMatcher::superChamberIdsCoincidences() const {
203  std::set<unsigned int> result;
204  for (const auto& p : detids_to_copads_) {
205  const GEMDetId& p_id(p.first);
206  result.insert(p_id.superChamberId().rawId());
207  }
208  return result;
209 }
210 
212  if (MuonHitHelper::isGEM(detid)) {
213  const GEMDetId id(detid);
214  if (superchamber_to_hits_.find(id.chamberId().rawId()) == superchamber_to_hits_.end())
215  return no_hits_;
216  return superchamber_to_hits_.at(id.chamberId().rawId());
217  }
218 
219  return no_hits_;
220 }
221 
222 int GEMSimHitMatcher::nLayersWithHitsInSuperChamber(unsigned int detid) const {
223  set<int> layers_with_hits;
224  const auto& hits = hitsInSuperChamber(detid);
225  for (const auto& h : hits) {
226  const GEMDetId& idd(h.detUnitId());
227  layers_with_hits.insert(idd.layer());
228  }
229  return layers_with_hits.size();
230 }
231 
232 bool GEMSimHitMatcher::hitStation(int st, int nlayers) const {
233  int nst = 0;
234  for (const auto& ddt : chamberIds()) {
235  const GEMDetId id(ddt);
236  if (id.station() != st)
237  continue;
238 
239  const int nl(nLayersWithHitsInSuperChamber(id.rawId()));
240  if (nl < nlayers)
241  continue;
242  ++nst;
243  }
244  return nst;
245 }
246 
248 
250  if (sim_hits.empty())
251  return -0.0; // point "zero"
252 
253  float central = -0.0;
254  size_t n = 0;
255  for (const auto& h : sim_hits) {
256  LocalPoint lp(0., 0., 0.); // local central
257  GlobalPoint gp;
258  if (MuonHitHelper::isGEM(h.detUnitId())) {
259  gp = geometry_->idToDet(h.detUnitId())->surface().toGlobal(lp);
260  }
261  central = gp.perp();
262  if (n >= 1)
263  edm::LogWarning("GEMSimHitMatcher") << "warning! find more than one simhits in GEM chamber " << std::endl;
264  ++n;
265  }
266 
267  return central;
268 }
269 
271  if (sim_hits.empty())
272  return -1.f;
273 
274  float sums = 0.f;
275  size_t n = 0;
276  for (const auto& h : sim_hits) {
277  const LocalPoint& lp = h.entryPoint();
278  const auto& d = h.detUnitId();
279  sums += dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(d)->strip(lp);
280  ++n;
281  }
282  if (n == 0)
283  return -1.f;
284  return sums / n;
285 }
286 
287 std::set<int> GEMSimHitMatcher::hitStripsInDetId(unsigned int detid, int margin_n_strips) const {
288  set<int> result;
289  const auto& simhits = MuonSimHitMatcher::hitsInDetId(detid);
290  GEMDetId id(detid);
291  int max_nstrips = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->nstrips();
292  for (const auto& h : simhits) {
293  const LocalPoint& lp = h.entryPoint();
294  int central_strip =
295  static_cast<int>(dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->topology().channel(lp));
296  int smin = central_strip - margin_n_strips;
297  smin = (smin > 0) ? smin : 1;
298  int smax = central_strip + margin_n_strips;
299  smax = (smax <= max_nstrips) ? smax : max_nstrips;
300  for (int ss = smin; ss <= smax; ++ss)
301  result.insert(ss);
302  }
303  return result;
304 }
305 
306 std::set<int> GEMSimHitMatcher::hitPadsInDetId(unsigned int detid) const {
307  set<int> none;
308  if (detids_to_pads_.find(detid) == detids_to_pads_.end())
309  return none;
310  return detids_to_pads_.at(detid);
311 }
312 
313 std::set<int> GEMSimHitMatcher::hitCoPadsInDetId(unsigned int detid) const {
314  set<int> none;
315  if (detids_to_copads_.find(detid) == detids_to_copads_.end())
316  return none;
317  return detids_to_copads_.at(detid);
318 }
319 
320 std::set<int> GEMSimHitMatcher::hitPartitions() const {
321  std::set<int> result;
322 
323  const auto& detids = detIds();
324  for (const auto& id : detids) {
325  GEMDetId idd(id);
326  result.insert(idd.roll());
327  }
328  return result;
329 }
330 
332  int result = 0;
333  const auto& pad_ids = detIds();
334  for (const auto& id : pad_ids) {
335  result += hitPadsInDetId(id).size();
336  }
337  return result;
338 }
339 
341  int result = 0;
342  const auto& copad_ids = detIdsCoincidences();
343  for (const auto& id : copad_ids) {
344  result += hitCoPadsInDetId(id).size();
345  }
346  return result;
347 }
SimVertex
Definition: SimVertex.h:5
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
GEMDetId::ring
constexpr int ring() const
Definition: GEMDetId.h:170
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:81
GEMSimHitMatcher::nLayersWithHitsInSuperChamber
int nLayersWithHitsInSuperChamber(unsigned int) const
Definition: GEMSimHitMatcher.cc:222
relativeConstraints.station
station
Definition: relativeConstraints.py:67
GEMSimHitMatcher::superChamberIdsCoincidences
std::set< unsigned int > superChamberIdsCoincidences() const
Definition: GEMSimHitMatcher.cc:202
MuonSimHitMatcher::verbose_
bool verbose_
Definition: MuonSimHitMatcher.h:78
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
globals_cff.id1
id1
Definition: globals_cff.py:32
GEMSimHitMatcher::detIdsCoincidences
std::set< unsigned int > detIdsCoincidences() const
Definition: GEMSimHitMatcher.cc:174
GEMSimHitMatcher::gem_geom_
edm::ESHandle< GEMGeometry > gem_geom_
Definition: GEMSimHitMatcher.h:78
edm::LogInfo
Definition: MessageLogger.h:254
MuonSimHitMatcher::detid_to_hits_
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
Definition: MuonSimHitMatcher.h:103
central
Definition: L1ECALPrefiringWeightProducer.cc:36
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:196
GEMSimHitMatcher::init
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
Definition: GEMSimHitMatcher.cc:16
GEMSimHitMatcher::nCoincidencePadsWithHits
int nCoincidencePadsWithHits() const
Definition: GEMSimHitMatcher.cc:340
MuonSimHitMatcher::simHits_
edm::PSimHitContainer simHits_
Definition: MuonSimHitMatcher.h:94
GEMSimHitMatcher.h
none
Definition: EcalBoundaryInfoCalculator.h:24
GEMSimHitMatcher::hitStation
bool hitStation(int, int) const
Definition: GEMSimHitMatcher.cc:232
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
GEMSimHitMatcher::superChamberIds
std::set< unsigned int > superChamberIds() const
Definition: GEMSimHitMatcher.cc:195
TrackingGeometry::idToDet
virtual const GeomDet * idToDet(DetId) const =0
h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
GEMSimHitMatcher::hitCoPadsInDetId
std::set< int > hitCoPadsInDetId(unsigned int) const
Definition: GEMSimHitMatcher.cc:313
ecaldqm::topology
const CaloTopology * topology(nullptr)
GEMSimHitMatcher::hitPartitions
std::set< int > hitPartitions() const
Definition: GEMSimHitMatcher.cc:320
GEMSimHitMatcher::GEMSimHitMatcher
GEMSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
Definition: GEMSimHitMatcher.cc:5
MuonSimHitMatcher::simHitPSet_
edm::ParameterSet simHitPSet_
Definition: MuonSimHitMatcher.h:106
GEMSimHitMatcher::nStations
int nStations(int nl=2) const
Definition: GEMSimHitMatcher.cc:247
Point3DBase< float, LocalTag >
MuonSimHitMatcher::track_ids_
std::vector< unsigned > track_ids_
Definition: MuonSimHitMatcher.h:96
MuonSimHitMatcher::no_hits_
edm::PSimHitContainer no_hits_
Definition: MuonSimHitMatcher.h:99
edm::LogWarning
Definition: MessageLogger.h:141
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
GEMSimHitMatcher::detIds
std::set< unsigned int > detIds(int gem_type=MuonHitHelper::GEM_ALL) const
Definition: GEMSimHitMatcher.cc:160
MuonSimHitMatcher::discardEleHits_
bool discardEleHits_
Definition: MuonSimHitMatcher.h:77
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:36
GEMSimHitMatcher::simHitsMeanStrip
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
Definition: GEMSimHitMatcher.cc:270
MuonSimHitMatcher
Definition: MuonSimHitMatcher.h:33
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:188
GEMDetId
Definition: GEMDetId.h:17
MuonSimHitMatcher::hasGeometry_
bool hasGeometry_
Definition: MuonSimHitMatcher.h:79
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonSimHitMatcher::chamber_to_hits_
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
Definition: MuonSimHitMatcher.h:104
edm::EventSetup
Definition: EventSetup.h:57
GEMSimHitMatcher::superchamber_to_hits_
std::map< unsigned int, edm::PSimHitContainer > superchamber_to_hits_
Definition: GEMSimHitMatcher.h:80
get
#define get
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
MuonSimHitMatcher::simHitInput_
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
Definition: MuonSimHitMatcher.h:85
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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:6
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
GEMSimHitMatcher::detids_to_copads_
std::map< unsigned int, std::set< int > > detids_to_copads_
Definition: GEMSimHitMatcher.h:86
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:76
GEMSimHitMatcher::matchSimHitsToSimTrack
void matchSimHitsToSimTrack()
Definition: GEMSimHitMatcher.cc:65
GEMSimHitMatcher::simHitsGEMCentralPosition
float simHitsGEMCentralPosition(const edm::PSimHitContainer &sim_hits) const
Definition: GEMSimHitMatcher.cc:249
GEMSimHitMatcher::hitPadsInDetId
std::set< int > hitPadsInDetId(unsigned int) const
Definition: GEMSimHitMatcher.cc:306
GEMDetId::station
constexpr int station() const
Definition: GEMDetId.h:173
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:303
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:181
globals_cff.id2
id2
Definition: globals_cff.py:33
GEMSimHitMatcher::hitsInSuperChamber
const edm::PSimHitContainer & hitsInSuperChamber(unsigned int) const
Definition: GEMSimHitMatcher.cc:211
MuonSimHitMatcher::hits_
edm::PSimHitContainer hits_
Definition: MuonSimHitMatcher.h:102
edm::Event
Definition: Event.h:73
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:30
MuonSimHitMatcher::init
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
Definition: MuonSimHitMatcher.cc:17
GEMSimHitMatcher::hitStripsInDetId
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
Definition: GEMSimHitMatcher.cc:287
GEMSimHitMatcher::nPadsWithHits
int nPadsWithHits() const
Definition: GEMSimHitMatcher.cc:331
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:39
edm::ParameterSet::getParameterSet
ParameterSet const & getParameterSet(std::string const &) const
Definition: ParameterSet.cc:2121
GEMSimHitMatcher::detids_to_pads_
std::map< unsigned int, std::set< int > > detids_to_pads_
Definition: GEMSimHitMatcher.h:83
nlayers
Definition: HIMultiTrackSelector.h:48
GEMSimHitMatcher::match
void match(const SimTrack &t, const SimVertex &v)
do the matching
Definition: GEMSimHitMatcher.cc:28