CMS 3D CMS Logo

ME0SimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
6  : MuonSimHitMatcher(ps, std::move(iC)) {
7  simHitPSet_ = ps.getParameterSet("me0SimHit");
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(me0_geom_);
18  if (me0_geom_.isValid()) {
19  geometry_ = &*me0_geom_;
20  } else {
21  hasGeometry_ = false;
22  edm::LogWarning("ME0SimHitMatcher") << "+++ Info: ME0 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("ME0SimHitMatcher") << "nTrackIds " << track_ids_.size() << " nSelectedME0SimHits " << hits_.size()
37  << endl;
38  edm::LogInfo("ME0SimHitMatcher") << "detids ME0 " << detIds().size() << endl;
39 
40  const auto& me0_ch_ids = detIds();
41  for (const auto& id : me0_ch_ids) {
42  const auto& me0_simhits = MuonSimHitMatcher::hitsInChamber(id);
43  const auto& me0_simhits_gp = simHitsMeanPosition(me0_simhits);
44  edm::LogInfo("ME0SimHitMatcher") << "me0chid " << ME0DetId(id) << ": nHits " << me0_simhits.size() << " phi "
45  << me0_simhits_gp.phi() << " nCh " << chamber_to_hits_[id].size() << endl;
46  const auto& strips = hitStripsInDetId(id);
47  edm::LogInfo("ME0SimHitMatcher") << "nStrip " << strips.size() << endl;
48  edm::LogInfo("ME0SimHitMatcher") << "strips : ";
49  for (const auto& p : strips) {
50  edm::LogInfo("ME0SimHitMatcher") << p;
51  }
52  }
53  }
54  }
55 }
56 
58  for (const auto& track_id : track_ids_) {
59  for (const auto& h : simHits_) {
60  if (h.trackId() != track_id)
61  continue;
62  int pdgid = h.particleType();
63  if (simMuOnly_ && std::abs(pdgid) != 13)
64  continue;
65  // discard electron hits in the ME0 chambers
66  if (discardEleHits_ && std::abs(pdgid) == 11)
67  continue;
68 
69  const ME0DetId& layer_id(h.detUnitId());
70  detid_to_hits_[h.detUnitId()].push_back(h);
71  hits_.push_back(h);
72  chamber_to_hits_[layer_id.layerId().rawId()].push_back(h);
73  superChamber_to_hits_[layer_id.chamberId().rawId()].push_back(h);
74  }
75  }
76 
77  // find pads with hits
78  const auto& detids = detIds();
79  for (const auto& d : detids) {
80  ME0DetId id(d);
81  const auto& hits = hitsInDetId(d);
82  const auto& roll = dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(id);
83  // int max_npads = roll->npads();
84  set<int> pads;
85  for (const auto& h : hits) {
86  const LocalPoint& lp = h.entryPoint();
87  pads.insert(1 + static_cast<int>(roll->padTopology().channel(lp)));
88  }
89  detids_to_pads_[d] = pads;
90  }
91 }
92 
93 std::set<unsigned int> ME0SimHitMatcher::detIds() const {
94  std::set<unsigned int> result;
95  for (const auto& p : detid_to_hits_)
96  result.insert(p.first);
97  return result;
98 }
99 
100 std::set<unsigned int> ME0SimHitMatcher::chamberIds() const {
101  std::set<unsigned int> result;
102  for (const auto& p : chamber_to_hits_)
103  result.insert(p.first);
104  return result;
105 }
106 
107 std::set<unsigned int> ME0SimHitMatcher::superChamberIds() const {
108  std::set<unsigned int> result;
109  for (const auto& p : superChamber_to_hits_)
110  result.insert(p.first);
111  return result;
112 }
113 
115  if (superChamber_to_hits_.find(detid) == superChamber_to_hits_.end())
116  return no_hits_;
117  return superChamber_to_hits_.at(detid);
118 }
119 
120 int ME0SimHitMatcher::nLayersWithHitsInSuperChamber(unsigned int detid) const {
121  set<int> layers_with_hits;
122  const auto& hits = hitsInSuperChamber(detid);
123  for (const auto& h : hits) {
124  const ME0DetId& idd(h.detUnitId());
125  layers_with_hits.insert(idd.layer());
126  }
127  return layers_with_hits.size();
128 }
129 
130 std::set<unsigned int> ME0SimHitMatcher::superChamberIdsCoincidences(int min_n_layers) const {
131  set<unsigned int> result;
132  // loop over the super chamber Ids
133  for (const auto& p : superChamberIds()) {
134  if (nLayersWithHitsInSuperChamber(p) >= min_n_layers) {
135  result.insert(p);
136  }
137  }
138  return result;
139 }
140 
141 int ME0SimHitMatcher::nCoincidenceChambers(int min_n_layers) const {
142  return superChamberIdsCoincidences(min_n_layers).size();
143 }
144 
146  if (sim_hits.empty())
147  return -1.f;
148 
149  float sums = 0.f;
150  size_t n = 0;
151  for (const auto& h : sim_hits) {
152  const LocalPoint& lp = h.entryPoint();
153  float s;
154  const auto& d = h.detUnitId();
155  s = dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(d)->strip(lp);
156  sums += s;
157  ++n;
158  }
159  if (n == 0)
160  return -1.f;
161  return sums / n;
162 }
163 
164 std::set<int> ME0SimHitMatcher::hitStripsInDetId(unsigned int detid, int margin_n_strips) const {
165  set<int> result;
166  const auto& simhits = hitsInDetId(detid);
167  ME0DetId id(detid);
168  int max_nstrips = dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(id)->nstrips();
169  for (const auto& h : simhits) {
170  const LocalPoint& lp = h.entryPoint();
171  int central_strip =
172  1 + static_cast<int>(dynamic_cast<const ME0Geometry*>(geometry_)->etaPartition(id)->topology().channel(lp));
173  int smin = central_strip - margin_n_strips;
174  smin = (smin > 0) ? smin : 1;
175  int smax = central_strip + margin_n_strips;
176  smax = (smax <= max_nstrips) ? smax : max_nstrips;
177  for (int ss = smin; ss <= smax; ++ss)
178  result.insert(ss);
179  }
180  return result;
181 }
182 
183 std::set<int> ME0SimHitMatcher::hitPadsInDetId(unsigned int detid) const {
184  set<int> none;
185  if (detids_to_pads_.find(detid) == detids_to_pads_.end())
186  return none;
187  return detids_to_pads_.at(detid);
188 }
189 
190 std::set<int> ME0SimHitMatcher::hitPartitions() const {
191  std::set<int> result;
192 
193  const auto& detids = detIds();
194  for (const auto& id : detids) {
195  ME0DetId idd(id);
196  result.insert(idd.roll());
197  }
198  return result;
199 }
200 
202  int result = 0;
203  const auto& pad_ids = detIds();
204  for (const auto& id : pad_ids) {
205  result += hitPadsInDetId(id).size();
206  }
207  return result;
208 }
T getParameter(std::string const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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
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
d
Definition: ztail.py:151
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:48
void match(const SimTrack &t, const SimVertex &v)
do the matching
std::set< unsigned int > superChamberIds() const
T get() const
Definition: EventSetup.h:73
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
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