CMS 3D CMS Logo

ME0SimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
7  : MuonSimHitMatcher(ps, std::move(iC)) {
8  simHitPSet_ = ps.getParameterSet("me0SimHit");
9  verbose_ = simHitPSet_.getParameter<int>("verbose");
10  simMuOnly_ = simHitPSet_.getParameter<bool>("simMuOnly");
11  discardEleHits_ = simHitPSet_.getParameter<bool>("discardEleHits");
12 
13  simHitInput_ = iC.consumes<edm::PSimHitContainer>(
15 }
16 
19  const edm::EventSetup& iSetup) {
20  iSetup.get<MuonGeometryRecord>().get(me0_geom_);
21  if (me0_geom_.isValid()) {
22  geometry_ = &*me0_geom_;
23  } else {
24  hasGeometry_ = false;
25  edm::LogWarning("ME0SimHitMatcher")
26  << "+++ Info: ME0 geometry is unavailable. +++\n";
27  }
28  MuonSimHitMatcher::init(iEvent, iSetup);
29 }
30 
32 void ME0SimHitMatcher::match(const SimTrack& track, const SimVertex& vertex) {
33  // instantiates the track ids and simhits
34  MuonSimHitMatcher::match(track, vertex);
35 
36  if (hasGeometry_) {
38 
39  if (verbose_) {
40  edm::LogInfo("ME0SimHitMatcher")
41  << "nTrackIds " << track_ids_.size() << " nSelectedME0SimHits "
42  << hits_.size() << endl;
43  edm::LogInfo("ME0SimHitMatcher")
44  << "detids ME0 " << detIds().size() << endl;
45 
46  const auto& me0_ch_ids = detIds();
47  for (const auto& id : me0_ch_ids) {
48  const auto& me0_simhits = MuonSimHitMatcher::hitsInChamber(id);
49  const auto& me0_simhits_gp = simHitsMeanPosition(me0_simhits);
50  edm::LogInfo("ME0SimHitMatcher")
51  << "me0chid " << ME0DetId(id) << ": nHits " << me0_simhits.size()
52  << " phi " << me0_simhits_gp.phi() << " nCh "
53  << chamber_to_hits_[id].size() << endl;
54  const auto& strips = hitStripsInDetId(id);
55  edm::LogInfo("ME0SimHitMatcher") << "nStrip " << strips.size() << endl;
56  edm::LogInfo("ME0SimHitMatcher") << "strips : ";
57  for (const auto& p : strips) {
58  edm::LogInfo("ME0SimHitMatcher") << p;
59  }
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) continue;
69  int pdgid = h.particleType();
70  if (simMuOnly_ && std::abs(pdgid) != 13) continue;
71  // discard electron hits in the ME0 chambers
72  if (discardEleHits_ && std::abs(pdgid) == 11) continue;
73 
74  const ME0DetId& layer_id(h.detUnitId());
75  detid_to_hits_[h.detUnitId()].push_back(h);
76  hits_.push_back(h);
77  chamber_to_hits_[layer_id.layerId().rawId()].push_back(h);
78  superChamber_to_hits_[layer_id.chamberId().rawId()].push_back(h);
79  }
80  }
81 
82  // find pads with hits
83  const auto& detids = detIds();
84  for (const auto& d : detids) {
85  ME0DetId id(d);
86  const auto& hits = hitsInDetId(d);
87  const auto& roll =
88  dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(id);
89  // int max_npads = roll->npads();
90  set<int> pads;
91  for (const auto& h : hits) {
92  const LocalPoint& lp = h.entryPoint();
93  pads.insert(1 + static_cast<int>(roll->padTopology().channel(lp)));
94  }
95  detids_to_pads_[d] = pads;
96  }
97 }
98 
99 std::set<unsigned int> ME0SimHitMatcher::detIds() const {
100  std::set<unsigned int> result;
101  for (const auto& p : detid_to_hits_) result.insert(p.first);
102  return result;
103 }
104 
105 std::set<unsigned int> ME0SimHitMatcher::chamberIds() const {
106  std::set<unsigned int> result;
107  for (const auto& p : chamber_to_hits_) result.insert(p.first);
108  return result;
109 }
110 
111 std::set<unsigned int> ME0SimHitMatcher::superChamberIds() const {
112  std::set<unsigned int> result;
113  for (const auto& p : superChamber_to_hits_) result.insert(p.first);
114  return result;
115 }
116 
118  unsigned int detid) const {
119  if (superChamber_to_hits_.find(detid) == superChamber_to_hits_.end())
120  return no_hits_;
121  return superChamber_to_hits_.at(detid);
122 }
123 
124 int ME0SimHitMatcher::nLayersWithHitsInSuperChamber(unsigned int detid) const {
125  set<int> layers_with_hits;
126  const auto& hits = hitsInSuperChamber(detid);
127  for (const auto& h : hits) {
128  const ME0DetId& idd(h.detUnitId());
129  layers_with_hits.insert(idd.layer());
130  }
131  return layers_with_hits.size();
132 }
133 
135  int min_n_layers) const {
136  set<unsigned int> result;
137  // loop over the super chamber Ids
138  for (const auto& p : superChamberIds()) {
139  if (nLayersWithHitsInSuperChamber(p) >= min_n_layers) {
140  result.insert(p);
141  }
142  }
143  return result;
144 }
145 
146 int ME0SimHitMatcher::nCoincidenceChambers(int min_n_layers) const {
147  return superChamberIdsCoincidences(min_n_layers).size();
148 }
149 
151  const edm::PSimHitContainer& sim_hits) const {
152  if (sim_hits.empty()) return -1.f;
153 
154  float sums = 0.f;
155  size_t n = 0;
156  for (const auto& h : sim_hits) {
157  const LocalPoint& lp = h.entryPoint();
158  float s;
159  const auto& d = h.detUnitId();
160  s = dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(d)->strip(lp);
161  sums += s;
162  ++n;
163  }
164  if (n == 0) return -1.f;
165  return sums / n;
166 }
167 
168 std::set<int> ME0SimHitMatcher::hitStripsInDetId(unsigned int detid,
169  int margin_n_strips) const {
170  set<int> result;
171  const auto& simhits = hitsInDetId(detid);
172  ME0DetId id(detid);
173  int max_nstrips =
174  dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(id)->nstrips();
175  for (const auto& h : simhits) {
176  const LocalPoint& lp = h.entryPoint();
177  int central_strip =
178  1 + static_cast<int>(dynamic_cast<const ME0Geometry*>(geometry_)
179  ->etaPartition(id)
180  ->topology()
181  .channel(lp));
182  int smin = central_strip - margin_n_strips;
183  smin = (smin > 0) ? smin : 1;
184  int smax = central_strip + margin_n_strips;
185  smax = (smax <= max_nstrips) ? smax : max_nstrips;
186  for (int ss = smin; ss <= smax; ++ss) result.insert(ss);
187  }
188  return result;
189 }
190 
191 std::set<int> ME0SimHitMatcher::hitPadsInDetId(unsigned int detid) const {
192  set<int> none;
193  if (detids_to_pads_.find(detid) == detids_to_pads_.end()) return none;
194  return detids_to_pads_.at(detid);
195 }
196 
197 std::set<int> ME0SimHitMatcher::hitPartitions() const {
198  std::set<int> result;
199 
200  const auto& detids = detIds();
201  for (const auto& id : detids) {
202  ME0DetId idd(id);
203  result.insert(idd.roll());
204  }
205  return result;
206 }
207 
209  int result = 0;
210  const auto& pad_ids = detIds();
211  for (const auto& id : pad_ids) {
212  result += hitPadsInDetId(id).size();
213  }
214  return result;
215 }
T getParameter(std::string const &) const
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
std::set< int > hitPartitions() const
const TrackingGeometry * geometry_
edm::PSimHitContainer hits_
std::set< unsigned int > chamberIds() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::set< int > hitPadsInDetId(unsigned int) const
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
std::set< unsigned int > superChamberIdsCoincidences(int min_n_layers=4) const
std::map< unsigned int, std::set< int > > detids_to_pads_
edm::ESHandle< ME0Geometry > me0_geom_
std::vector< unsigned > track_ids_
int iEvent
Definition: GenABIO.cc:224
GlobalPoint simHitsMeanPosition(const edm::PSimHitContainer &sim_hits) const
int nPadsWithHits() const
edm::PSimHitContainer simHits_
edm::ParameterSet simHitPSet_
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int nCoincidenceChambers(int min_n_layers=4) const
std::set< unsigned int > detIds() const
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
edm::PSimHitContainer no_hits_
ParameterSet const & getParameterSet(std::string const &) const
const edm::PSimHitContainer & hitsInDetId(unsigned int) const
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
ME0SimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
void match(const SimTrack &t, const SimVertex &v)
do the matching
int nLayersWithHitsInSuperChamber(unsigned int) const
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
int roll() const
Definition: ME0DetId.h:62
void match(const SimTrack &t, const SimVertex &v)
do the matching
std::set< unsigned int > superChamberIds() const
T get() const
Definition: EventSetup.h:71
std::vector< PSimHit > PSimHitContainer
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
bool isValid() const
Definition: ESHandle.h:44
const edm::PSimHitContainer & hitsInChamber(unsigned int) const
def move(src, dest)
Definition: eostools.py:511
std::map< unsigned int, edm::PSimHitContainer > superChamber_to_hits_
const edm::PSimHitContainer & hitsInSuperChamber(unsigned int) const