CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
< StripDigiSimLink
DigiSimLinks
 
typedef edm::DetSet
< StripDigiSimLink
LayerLinks
 
typedef std::pair< uint32_t,
EncodedEventId
SimHitIdpr
 
typedef edm::DetSetVector
< StripDigiSimLink
WireDigiSimLinks
 

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::PSimHitContainer
theSimHitMap
 
float theTotalCharge
 
const DigiSimLinkstheWireDigiSimLinks
 
edm::InputTag wireLinksTag
 

Detailed Description

Definition at line 24 of file MuonTruth.h.

Member Typedef Documentation

Definition at line 26 of file MuonTruth.h.

Definition at line 28 of file MuonTruth.h.

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

Definition at line 29 of file MuonTruth.h.

Definition at line 27 of file MuonTruth.h.

Constructor & Destructor Documentation

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

Definition at line 8 of file MuonTruth.cc.

References initEvent().

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 {
19  initEvent(event, setup);
20 }
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:68
edm::InputTag linksTag
Definition: MuonTruth.h:64
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:69
edm::InputTag wireLinksTag
Definition: MuonTruth.h:65
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:62
bool crossingframe
Definition: MuonTruth.h:67
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
void initEvent(const edm::Event &, const edm::EventSetup &)
Definition: MuonTruth.cc:42
MuonTruth::MuonTruth ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  iC 
)

Definition at line 22 of file MuonTruth.cc.

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

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 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:68
edm::InputTag linksTag
Definition: MuonTruth.h:64
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:69
edm::InputTag wireLinksTag
Definition: MuonTruth.h:65
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:62
bool crossingframe
Definition: MuonTruth.h:67
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string const & label() const
Definition: InputTag.h:36
edm::DetSetVector< StripDigiSimLink > DigiSimLinks
Definition: MuonTruth.h:26
std::vector< PSimHit > PSimHitContainer
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61

Member Function Documentation

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

Definition at line 206 of file MuonTruth.cc.

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

Referenced by analyze().

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 }
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
float theTotalCharge
Definition: MuonTruth.h:57
std::pair< uint32_t, EncodedEventId > SimHitIdpr
int weight
Definition: histoStyle.py:51
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
void MuonTruth::analyze ( const CSCRecHit2D recHit)

Definition at line 156 of file MuonTruth.cc.

References CSCRecHit2D::adcs(), addChannel(), CSCLayerGeometry::channel(), CSCRecHit2D::channels(), CSCRecHit2D::cscDetId(), cscgeom, edm::DetSetVector< T >::end(), edm::DetSetVector< T >::find(), TrackingRecHit::geographicalId(), relativeConstraints::geometry, CSCGeometry::layer(), CSCRecHit2D::nStrips(), DetId::rawId(), theChargeMap, theDetId, theDigiSimLinks, theTotalCharge, and histoStyle::weight.

Referenced by CSCTruthTest::analyze().

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 }
CSCDetId cscDetId() const
Definition: CSCRecHit2D.h:58
iterator find(det_id_type id)
Definition: DetSetVector.h:264
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const CSCGeometry * cscgeom
Definition: MuonTruth.h:73
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
int channels(unsigned int i) const
Extracting strip channel numbers comprising the rechit - low.
Definition: CSCRecHit2D.h:61
unsigned int theDetId
Definition: MuonTruth.h:59
unsigned int nStrips() const
Definition: CSCRecHit2D.h:62
float adcs(unsigned int strip, unsigned int timebin) const
Map of strip ADCs for strips comprising the rechit.
Definition: CSCRecHit2D.h:74
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
int channel(int strip) const
float theTotalCharge
Definition: MuonTruth.h:57
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:105
DetId geographicalId() const
int weight
Definition: histoStyle.py:51
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:206
void MuonTruth::analyze ( const CSCStripDigi stripDigi,
int  rawDetIdCorrespondingToCSCLayer 
)

Definition at line 179 of file MuonTruth.cc.

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

179  {
180  theDetId = rawDetIdCorrespondingToCSCLayer;
181  theChargeMap.clear();
182  theTotalCharge = 0.;
183 
185  if (layerLinks != theDigiSimLinks->end()) {
186  addChannel(*layerLinks, stripDigi.getStrip(), 1.);
187  }
188 }
iterator find(det_id_type id)
Definition: DetSetVector.h:264
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
int getStrip() const
Definition: CSCStripDigi.h:41
unsigned int theDetId
Definition: MuonTruth.h:59
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
float theTotalCharge
Definition: MuonTruth.h:57
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:206
void MuonTruth::analyze ( const CSCWireDigi wireDigi,
int  rawDetIdCorrespondingToCSCLayer 
)

Definition at line 190 of file MuonTruth.cc.

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

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 }
iterator find(det_id_type id)
Definition: DetSetVector.h:264
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:62
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
unsigned int theDetId
Definition: MuonTruth.h:59
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
float theTotalCharge
Definition: MuonTruth.h:57
int getWireGroup() const
default
Definition: CSCWireDigi.h:22
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:206
std::vector< PSimHit > MuonTruth::hitsFromSimTrack ( MuonTruth::SimHitIdpr  truthId)
private

Definition at line 130 of file MuonTruth.cc.

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

Referenced by particleType(), and simHits().

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 }
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:71
tuple result
Definition: mps_fire.py:311
unsigned int theDetId
Definition: MuonTruth.h:59
void MuonTruth::initEvent ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 42 of file MuonTruth.cc.

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

Referenced by MuonTruth().

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 }
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:71
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:68
edm::InputTag linksTag
Definition: MuonTruth.h:64
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:69
edm::InputTag wireLinksTag
Definition: MuonTruth.h:65
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:62
const CSCGeometry * cscgeom
Definition: MuonTruth.h:73
#define LogTrace(id)
bool crossingframe
Definition: MuonTruth.h:67
const CSCBadChambers * cscBadChambers
Definition: MuonTruth.h:47
T const * product() const
Definition: Handle.h:70
T const * product() const
Definition: ESHandle.h:86
std::string const & label() const
Definition: InputTag.h:36
T get() const
Definition: EventSetup.h:88
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
float MuonTruth::muonFraction ( )

analyze() must be called before any of the following

Definition at line 89 of file MuonTruth.cc.

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

Referenced by CSCTruthTest::analyze().

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 }
int particleType(SimHitIdpr truthId)
Definition: MuonTruth.cc:147
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float theTotalCharge
Definition: MuonTruth.h:57
std::vector< PSimHit > MuonTruth::muonHits ( )

Definition at line 117 of file MuonTruth.cc.

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

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 }
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:105
tuple result
Definition: mps_fire.py:311
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int MuonTruth::particleType ( MuonTruth::SimHitIdpr  truthId)
private

Definition at line 147 of file MuonTruth.cc.

References hitsFromSimTrack(), and mps_fire::result.

Referenced by muonFraction().

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 }
tuple result
Definition: mps_fire.py:311
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:130
std::vector< PSimHit > MuonTruth::simHits ( )

Definition at line 105 of file MuonTruth.cc.

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

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

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 }
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
tuple result
Definition: mps_fire.py:311
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:130

Member Data Documentation

bool MuonTruth::crossingframe
private

Definition at line 67 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

const CSCBadChambers* MuonTruth::cscBadChambers

Definition at line 47 of file MuonTruth.h.

Referenced by initEvent().

const CSCGeometry* MuonTruth::cscgeom
private

Definition at line 73 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

edm::InputTag MuonTruth::CSCsimHitsTag
private

Definition at line 68 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

edm::InputTag MuonTruth::CSCsimHitsXFTag
private

Definition at line 69 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

edm::InputTag MuonTruth::linksTag
private

Definition at line 64 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

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

Definition at line 56 of file MuonTruth.h.

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

unsigned int MuonTruth::theDetId
private

Definition at line 59 of file MuonTruth.h.

Referenced by analyze(), and hitsFromSimTrack().

const DigiSimLinks* MuonTruth::theDigiSimLinks
private

Definition at line 61 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

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

Definition at line 71 of file MuonTruth.h.

Referenced by hitsFromSimTrack(), and initEvent().

float MuonTruth::theTotalCharge
private

Definition at line 57 of file MuonTruth.h.

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

const DigiSimLinks* MuonTruth::theWireDigiSimLinks
private

Definition at line 62 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

edm::InputTag MuonTruth::wireLinksTag
private

Definition at line 65 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().