CMS 3D CMS Logo

MuonTruth.cc
Go to the documentation of this file.
6 
8  : cscBadChambers(nullptr),
9  theTotalCharge(0.0),
10  theDetId(0),
11  theDigiSimLinks(nullptr),
12  theWireDigiSimLinks(nullptr),
13  linksTag(conf.getParameter<edm::InputTag>("CSClinksTag")),
14  wireLinksTag(conf.getParameter<edm::InputTag>("CSCwireLinksTag")),
15  // CrossingFrame used or not ?
16  crossingframe(conf.getParameter<bool>("crossingframe")),
17  CSCsimHitsTag(conf.getParameter<edm::InputTag>("CSCsimHitsTag")),
18  CSCsimHitsXFTag(conf.getParameter<edm::InputTag>("CSCsimHitsXFTag")),
19  geomToken_(iC.esConsumes<CSCGeometry, MuonGeometryRecord>()),
21  linksToken_(iC.consumes<DigiSimLinks>(linksTag)),
22  wireLinksToken_(iC.consumes<DigiSimLinks>(wireLinksTag)),
23  cscgeom(nullptr) {
24  if (crossingframe) {
26  } else if (!CSCsimHitsTag.label().empty()) {
28  }
29 }
30 
32  theChargeMap.clear();
33  theTotalCharge = 0.0;
34  theDetId = 0;
35 
36  LogTrace("MuonTruth") << "getting CSC Strip DigiSimLink collection - " << linksTag;
37  const edm::Handle<DigiSimLinks> &digiSimLinks = event.getHandle(linksToken_);
38  theDigiSimLinks = digiSimLinks.product();
39 
40  LogTrace("MuonTruth") << "getting CSC Wire DigiSimLink collection - " << wireLinksTag;
41  const edm::Handle<DigiSimLinks> &wireDigiSimLinks = event.getHandle(wireLinksToken_);
42  theWireDigiSimLinks = wireDigiSimLinks.product();
43 
44  // get CSC Geometry to use CSCLayer methods
45  const edm::ESHandle<CSCGeometry> &mugeom = setup.getHandle(geomToken_);
46  cscgeom = mugeom.product();
47 
48  // get CSC Bad Chambers (ME4/2)
49  const edm::ESHandle<CSCBadChambers> &badChambers = setup.getHandle(badToken_);
50  cscBadChambers = badChambers.product();
51 
52  theSimHitMap.clear();
53 
54  if (crossingframe) {
55  LogTrace("MuonTruth") << "getting CrossingFrame<PSimHit> collection - " << CSCsimHitsXFTag;
56  const edm::Handle<CrossingFrame<PSimHit>> &cf = event.getHandle(simHitsXFToken_);
57 
58  std::unique_ptr<MixCollection<PSimHit>> CSCsimhits(new MixCollection<PSimHit>(cf.product()));
59  LogTrace("MuonTruth") << "... size = " << CSCsimhits->size();
60 
61  for (MixCollection<PSimHit>::MixItr hitItr = CSCsimhits->begin(); hitItr != CSCsimhits->end(); ++hitItr) {
62  theSimHitMap[hitItr->detUnitId()].push_back(*hitItr);
63  }
64 
65  } else if (!CSCsimHitsTag.label().empty()) {
66  LogTrace("MuonTruth") << "getting PSimHit collection - " << CSCsimHitsTag;
67  const edm::Handle<edm::PSimHitContainer> &CSCsimhits = event.getHandle(simHitsToken_);
68  LogTrace("MuonTruth") << "... size = " << CSCsimhits->size();
69 
70  for (edm::PSimHitContainer::const_iterator hitItr = CSCsimhits->begin(); hitItr != CSCsimhits->end(); ++hitItr) {
71  theSimHitMap[hitItr->detUnitId()].push_back(*hitItr);
72  }
73  }
74 }
75 
77  if (theChargeMap.empty())
78  return 0.;
79 
80  float muonCharge = 0.;
81  for (std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.begin();
82  chargeMapItr != theChargeMap.end();
83  ++chargeMapItr) {
84  if (abs(particleType(chargeMapItr->first)) == 13) {
85  muonCharge += chargeMapItr->second;
86  }
87  }
88 
89  return muonCharge / theTotalCharge;
90 }
91 
92 std::vector<PSimHit> MuonTruth::simHits() {
93  std::vector<PSimHit> result;
94  for (std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.begin();
95  chargeMapItr != theChargeMap.end();
96  ++chargeMapItr) {
97  std::vector<PSimHit> trackHits = hitsFromSimTrack(chargeMapItr->first);
98  result.insert(result.end(), trackHits.begin(), trackHits.end());
99  }
100 
101  return result;
102 }
103 
104 std::vector<PSimHit> MuonTruth::muonHits() {
105  std::vector<PSimHit> result;
106  std::vector<PSimHit> allHits = simHits();
107  std::vector<PSimHit>::const_iterator hitItr = allHits.begin(), lastHit = allHits.end();
108 
109  for (; hitItr != lastHit; ++hitItr) {
110  if (abs((*hitItr).particleType()) == 13) {
111  result.push_back(*hitItr);
112  }
113  }
114  return result;
115 }
116 
117 std::vector<PSimHit> MuonTruth::hitsFromSimTrack(MuonTruth::SimHitIdpr truthId) {
118  std::vector<PSimHit> result;
119 
120  auto found = theSimHitMap.find(theDetId);
121  if (found != theSimHitMap.end()) {
122  for (auto const &hit : found->second) {
123  unsigned int hitTrack = hit.trackId();
124  EncodedEventId hitEvId = hit.eventId();
125 
126  if (hitTrack == truthId.first && hitEvId == truthId.second) {
127  result.push_back(hit);
128  }
129  }
130  }
131  return result;
132 }
133 
135  int result = 0;
136  const std::vector<PSimHit> &hits = hitsFromSimTrack(truthId);
137  if (!hits.empty()) {
138  result = hits[0].particleType();
139  }
140  return result;
141 }
142 
144  theChargeMap.clear();
145  theTotalCharge = 0.;
146  theDetId = recHit.geographicalId().rawId();
147 
148  int nchannels = recHit.nStrips();
149  const CSCLayerGeometry *laygeom = cscgeom->layer(recHit.cscDetId())->geometry();
150 
151  for (int idigi = 0; idigi < nchannels; ++idigi) {
152  // strip and readout channel numbers may differ in ME1/1A
153  int istrip = recHit.channels(idigi);
154  int channel = laygeom->channel(istrip);
155  float weight = recHit.adcs(idigi, 0); // DL: I think this is wrong before and after...seems to
156  // assume one time binadcContainer[idigi];
157 
159 
160  if (layerLinks != theDigiSimLinks->end()) {
161  addChannel(*layerLinks, channel, weight);
162  }
163  }
164 }
165 
166 void MuonTruth::analyze(const CSCStripDigi &stripDigi, int rawDetIdCorrespondingToCSCLayer) {
167  theDetId = rawDetIdCorrespondingToCSCLayer;
168  theChargeMap.clear();
169  theTotalCharge = 0.;
170 
172  if (layerLinks != theDigiSimLinks->end()) {
173  addChannel(*layerLinks, stripDigi.getStrip(), 1.);
174  }
175 }
176 
177 void MuonTruth::analyze(const CSCWireDigi &wireDigi, int rawDetIdCorrespondingToCSCLayer) {
178  theDetId = rawDetIdCorrespondingToCSCLayer;
179  theChargeMap.clear();
180  theTotalCharge = 0.;
181 
183 
184  if (layerLinks != theDigiSimLinks->end()) {
185  // In the simulation digis, the channel labels for wires and strips must be
186  // distinct, therefore:
187  int wireDigiInSimulation = wireDigi.getWireGroup() + 100;
188  //
189  addChannel(*layerLinks, wireDigiInSimulation, 1.);
190  }
191 }
192 
193 void MuonTruth::addChannel(const LayerLinks &layerLinks, int channel, float weight) {
194  LayerLinks::const_iterator linkItr = layerLinks.begin(), lastLayerLink = layerLinks.end();
195 
196  for (; linkItr != lastLayerLink; ++linkItr) {
197  int linkChannel = linkItr->channel();
198  if (linkChannel == channel) {
199  float charge = linkItr->fraction() * weight;
201  // see if it's in the map
202  SimHitIdpr truthId(linkItr->SimTrackId(), linkItr->eventId());
203  std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.find(truthId);
204  if (chargeMapItr == theChargeMap.end()) {
205  theChargeMap[truthId] = charge;
206  } else {
207  theChargeMap[truthId] += charge;
208  }
209  }
210  }
211 }
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:79
iterator end()
Definition: DetSet.h:58
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: MuonTruth.h:30
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
iterator find(det_id_type id)
Definition: DetSetVector.h:255
int particleType(SimHitIdpr truthId)
Definition: MuonTruth.cc:134
T const * product() const
Definition: Handle.h:70
Definition: weight.py:1
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:62
edm::EDGetTokenT< edm::PSimHitContainer > simHitsToken_
Definition: MuonTruth.h:77
const CSCGeometry * cscgeom
Definition: MuonTruth.h:81
std::string const & label() const
Definition: InputTag.h:36
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
std::vector< PSimHit > muonHits()
Definition: MuonTruth.cc:104
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > geomToken_
Definition: MuonTruth.h:71
int getStrip() const
Definition: CSCStripDigi.h:41
int channel(int strip) const
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:92
#define LogTrace(id)
T const * product() const
Definition: ESHandle.h:86
const CSCBadChambers * cscBadChambers
Definition: MuonTruth.h:47
unsigned int theDetId
Definition: MuonTruth.h:59
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:117
const edm::InputTag wireLinksTag
Definition: MuonTruth.h:65
MuonTruth(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
Definition: MuonTruth.cc:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< DigiSimLinks > wireLinksToken_
Definition: MuonTruth.h:75
const edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:69
const edm::InputTag linksTag
Definition: MuonTruth.h:64
void analyze(const CSCRecHit2D &recHit)
Definition: MuonTruth.cc:143
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:316
iterator begin()
Definition: DetSet.h:57
float theTotalCharge
Definition: MuonTruth.h:57
const edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:68
const edm::EDGetTokenT< DigiSimLinks > linksToken_
Definition: MuonTruth.h:74
HLT enums.
edm::EDGetTokenT< CrossingFrame< PSimHit > > simHitsXFToken_
Definition: MuonTruth.h:76
std::vector< PSimHit > PSimHitContainer
float muonFraction()
analyze() must be called before any of the following
Definition: MuonTruth.cc:76
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:105
const bool crossingframe
Definition: MuonTruth.h:67
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:193
const edm::ESGetToken< CSCBadChambers, CSCBadChambersRcd > badToken_
Definition: MuonTruth.h:72
Definition: event.py:1
int getWireGroup() const
default
Definition: CSCWireDigi.h:22
void initEvent(const edm::Event &, const edm::EventSetup &)
Definition: MuonTruth.cc:31