CMS 3D CMS Logo

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