CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MuonTruth Class Reference

#include <MuonTruth.h>

Public Types

typedef edm::DetSetVector< StripDigiSimLinkDigiSimLinks
 
typedef edm::DetSet< StripDigiSimLinkLayerLinks
 
typedef std::pair< uint32_t, EncodedEventIdSimHitIdpr
 
typedef edm::DetSetVector< StripDigiSimLinkWireDigiSimLinks
 

Public Member Functions

void analyze (const CSCRecHit2D &recHit)
 
void analyze (const CSCStripDigi &stripDigi, int rawDetIdCorrespondingToCSCLayer)
 
void analyze (const CSCWireDigi &wireDigi, int rawDetIdCorrespondingToCSCLayer)
 
void initEvent (const edm::Event &, const edm::EventSetup &)
 
float muonFraction ()
 analyze() must be called before any of the following More...
 
std::vector< PSimHitmuonHits ()
 
 MuonTruth (const edm::Event &, const edm::EventSetup &, const edm::ParameterSet &)
 
 MuonTruth (const edm::ParameterSet &, edm::ConsumesCollector &&iC)
 
std::vector< PSimHitsimHits ()
 

Public Attributes

const CSCBadChamberscscBadChambers
 

Private Member Functions

void addChannel (const LayerLinks &layerLinks, int channel, float weight=1.)
 
std::vector< PSimHithitsFromSimTrack (SimHitIdpr truthId)
 
int particleType (SimHitIdpr truthId)
 

Private Attributes

bool crossingframe
 
const CSCGeometrycscgeom
 
edm::InputTag CSCsimHitsTag
 
edm::InputTag CSCsimHitsXFTag
 
edm::InputTag linksTag
 
std::map< SimHitIdpr, float > theChargeMap
 
unsigned int theDetId
 
const DigiSimLinkstheDigiSimLinks
 
std::map< unsigned int, edm::PSimHitContainertheSimHitMap
 
float theTotalCharge
 
const DigiSimLinkstheWireDigiSimLinks
 
edm::InputTag wireLinksTag
 

Detailed Description

Definition at line 24 of file MuonTruth.h.

Member Typedef Documentation

◆ DigiSimLinks

Definition at line 26 of file MuonTruth.h.

◆ LayerLinks

Definition at line 28 of file MuonTruth.h.

◆ SimHitIdpr

typedef std::pair<uint32_t, EncodedEventId> MuonTruth::SimHitIdpr

Definition at line 29 of file MuonTruth.h.

◆ WireDigiSimLinks

Definition at line 27 of file MuonTruth.h.

Constructor & Destructor Documentation

◆ MuonTruth() [1/2]

MuonTruth::MuonTruth ( const edm::Event event,
const edm::EventSetup setup,
const edm::ParameterSet conf 
)

Definition at line 8 of file MuonTruth.cc.

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 }

References initEvent(), and singleTopDQM_cfi::setup.

◆ MuonTruth() [2/2]

MuonTruth::MuonTruth ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  iC 
)

Definition at line 22 of file MuonTruth.cc.

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 {
35  if (crossingframe) {
37  } else if (!CSCsimHitsTag.label().empty()) {
39  }
40 }

References crossingframe, CSCsimHitsTag, CSCsimHitsXFTag, edm::InputTag::label(), linksTag, and wireLinksTag.

Member Function Documentation

◆ addChannel()

void MuonTruth::addChannel ( const LayerLinks layerLinks,
int  channel,
float  weight = 1. 
)
private

Definition at line 206 of file MuonTruth.cc.

206  {
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 }

References edm::DetSet< T >::begin(), ALCARECOTkAlJpsiMuMu_cff::charge, edm::DetSet< T >::end(), theChargeMap, theTotalCharge, and mps_merge::weight.

Referenced by analyze().

◆ analyze() [1/3]

void MuonTruth::analyze ( const CSCRecHit2D recHit)

Definition at line 156 of file MuonTruth.cc.

156  {
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 }

References addChannel(), CSCLayerGeometry::channel(), cscgeom, edm::DetSetVector< T >::end(), edm::DetSetVector< T >::find(), geometry, CSCGeometry::layer(), rpcPointValidation_cfi::recHit, theChargeMap, theDetId, theDigiSimLinks, and theTotalCharge.

Referenced by CSCTruthTest::analyze().

◆ analyze() [2/3]

void MuonTruth::analyze ( const CSCStripDigi stripDigi,
int  rawDetIdCorrespondingToCSCLayer 
)

Definition at line 179 of file MuonTruth.cc.

179  {
180  theDetId = rawDetIdCorrespondingToCSCLayer;
181  theChargeMap.clear();
182  theTotalCharge = 0.;
183 
185  if (layerLinks != theDigiSimLinks->end()) {
186  addChannel(*layerLinks, stripDigi.getStrip(), 1.);
187  }
188 }

References addChannel(), edm::DetSetVector< T >::end(), edm::DetSetVector< T >::find(), CSCStripDigi::getStrip(), theChargeMap, theDetId, theDigiSimLinks, and theTotalCharge.

◆ analyze() [3/3]

void MuonTruth::analyze ( const CSCWireDigi wireDigi,
int  rawDetIdCorrespondingToCSCLayer 
)

Definition at line 190 of file MuonTruth.cc.

190  {
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 }

References addChannel(), edm::DetSetVector< T >::end(), edm::DetSetVector< T >::find(), CSCWireDigi::getWireGroup(), theChargeMap, theDetId, theDigiSimLinks, theTotalCharge, and theWireDigiSimLinks.

◆ hitsFromSimTrack()

std::vector< PSimHit > MuonTruth::hitsFromSimTrack ( MuonTruth::SimHitIdpr  truthId)
private

Definition at line 130 of file MuonTruth.cc.

130  {
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 }

References newFWLiteAna::found, mps_fire::result, theDetId, and theSimHitMap.

Referenced by particleType(), and simHits().

◆ initEvent()

void MuonTruth::initEvent ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 42 of file MuonTruth.cc.

42  {
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 }

References crossingframe, cscBadChambers, cscgeom, CSCsimHitsTag, CSCsimHitsXFTag, TTClusterAssociation_cfi::digiSimLinks, get, edm::InputTag::label(), linksTag, LogTrace, edm::Handle< T >::product(), edm::ESHandle< T >::product(), singleTopDQM_cfi::setup, theDigiSimLinks, theSimHitMap, theWireDigiSimLinks, and wireLinksTag.

Referenced by MuonTruth().

◆ muonFraction()

float MuonTruth::muonFraction ( )

analyze() must be called before any of the following

Definition at line 89 of file MuonTruth.cc.

89  {
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 }

References funct::abs(), particleType(), theChargeMap, and theTotalCharge.

Referenced by CSCTruthTest::analyze().

◆ muonHits()

std::vector< PSimHit > MuonTruth::muonHits ( )

Definition at line 117 of file MuonTruth.cc.

117  {
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 }

References funct::abs(), mps_fire::result, and simHits().

◆ particleType()

int MuonTruth::particleType ( MuonTruth::SimHitIdpr  truthId)
private

Definition at line 147 of file MuonTruth.cc.

147  {
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 }

References hfClusterShapes_cfi::hits, hitsFromSimTrack(), and mps_fire::result.

Referenced by muonFraction().

◆ simHits()

std::vector< PSimHit > MuonTruth::simHits ( )

Definition at line 105 of file MuonTruth.cc.

105  {
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 }

References hitsFromSimTrack(), mps_fire::result, and theChargeMap.

Referenced by ntupleDataFormat.TrackingParticle::bestMatchingTrack(), and muonHits().

Member Data Documentation

◆ crossingframe

bool MuonTruth::crossingframe
private

Definition at line 67 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

◆ cscBadChambers

const CSCBadChambers* MuonTruth::cscBadChambers

Definition at line 47 of file MuonTruth.h.

Referenced by initEvent().

◆ cscgeom

const CSCGeometry* MuonTruth::cscgeom
private

Definition at line 73 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

◆ CSCsimHitsTag

edm::InputTag MuonTruth::CSCsimHitsTag
private

Definition at line 68 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

◆ CSCsimHitsXFTag

edm::InputTag MuonTruth::CSCsimHitsXFTag
private

Definition at line 69 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

◆ linksTag

edm::InputTag MuonTruth::linksTag
private

Definition at line 64 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

◆ theChargeMap

std::map<SimHitIdpr, float> MuonTruth::theChargeMap
private

Definition at line 56 of file MuonTruth.h.

Referenced by addChannel(), analyze(), muonFraction(), and simHits().

◆ theDetId

unsigned int MuonTruth::theDetId
private

Definition at line 59 of file MuonTruth.h.

Referenced by analyze(), and hitsFromSimTrack().

◆ theDigiSimLinks

const DigiSimLinks* MuonTruth::theDigiSimLinks
private

Definition at line 61 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

◆ theSimHitMap

std::map<unsigned int, edm::PSimHitContainer> MuonTruth::theSimHitMap
private

Definition at line 71 of file MuonTruth.h.

Referenced by hitsFromSimTrack(), and initEvent().

◆ theTotalCharge

float MuonTruth::theTotalCharge
private

Definition at line 57 of file MuonTruth.h.

Referenced by addChannel(), analyze(), and muonFraction().

◆ theWireDigiSimLinks

const DigiSimLinks* MuonTruth::theWireDigiSimLinks
private

Definition at line 62 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

◆ wireLinksTag

edm::InputTag MuonTruth::wireLinksTag
private

Definition at line 65 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
MuonTruth::initEvent
void initEvent(const edm::Event &, const edm::EventSetup &)
Definition: MuonTruth.cc:42
geometry
ESHandle< TrackerGeometry > geometry
Definition: TkLasBeamFitter.cc:200
MuonTruth::wireLinksTag
edm::InputTag wireLinksTag
Definition: MuonTruth.h:65
edm::Handle::product
T const * product() const
Definition: Handle.h:70
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::DetSetVector::end
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
SimHitIdpr
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: TrackerHitAssociator.h:54
MuonTruth::theDetId
unsigned int theDetId
Definition: MuonTruth.h:59
MuonTruth::hitsFromSimTrack
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:130
CSCWireDigi::getWireGroup
int getWireGroup() const
default
Definition: CSCWireDigi.h:22
mps_merge.weight
weight
Definition: mps_merge.py:88
MuonTruth::theDigiSimLinks
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
MuonTruth::CSCsimHitsXFTag
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:69
CSCStripDigi::getStrip
int getStrip() const
Definition: CSCStripDigi.h:41
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:8
MixCollection
Definition: MixCollection.h:11
CSCLayerGeometry
Definition: CSCLayerGeometry.h:25
edm::ESHandle< CSCGeometry >
MuonTruth::simHits
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:105
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
MuonTruth::crossingframe
bool crossingframe
Definition: MuonTruth.h:67
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
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
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
get
#define get
MuonTruth::DigiSimLinks
edm::DetSetVector< StripDigiSimLink > DigiSimLinks
Definition: MuonTruth.h:26
CSCBadChambersRcd
Definition: CSCBadChambersRcd.h:5
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CSCLayerGeometry::channel
int channel(int strip) const
Definition: CSCLayerGeometry.h:112
MuonTruth::cscBadChambers
const CSCBadChambers * cscBadChambers
Definition: MuonTruth.h:47
mps_fire.result
result
Definition: mps_fire.py:311
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:224
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
event
Definition: event.py:1
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
edm::InputTag
Definition: InputTag.h:15
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