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

Definition at line 27 of file MuonTruth.h.

Definition at line 29 of file MuonTruth.h.

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

Definition at line 30 of file MuonTruth.h.

Definition at line 28 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().

8  :
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 }
T getParameter(std::string const &) const
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:70
edm::InputTag linksTag
Definition: MuonTruth.h:66
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:71
edm::InputTag wireLinksTag
Definition: MuonTruth.h:67
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:64
bool crossingframe
Definition: MuonTruth.h:69
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63
void initEvent(const edm::Event &, const edm::EventSetup &)
Definition: MuonTruth.cc:43
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.

22  :
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 
41 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:70
edm::InputTag linksTag
Definition: MuonTruth.h:66
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:71
edm::InputTag wireLinksTag
Definition: MuonTruth.h:67
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:64
bool crossingframe
Definition: MuonTruth.h:69
std::string const & label() const
Definition: InputTag.h:36
edm::DetSetVector< StripDigiSimLink > DigiSimLinks
Definition: MuonTruth.h:27
std::vector< PSimHit > PSimHitContainer
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63

Member Function Documentation

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

Definition at line 240 of file MuonTruth.cc.

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

Referenced by analyze().

241 {
242  LayerLinks::const_iterator linkItr = layerLinks.begin(),
243  lastLayerLink = layerLinks.end();
244 
245  for ( ; linkItr != lastLayerLink; ++linkItr)
246  {
247  int linkChannel = linkItr->channel();
248  if(linkChannel == channel)
249  {
250  float charge = linkItr->fraction() * weight;
252  // see if it's in the map
253  SimHitIdpr truthId(linkItr->SimTrackId(),linkItr->eventId());
254  std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.find(truthId);
255  if(chargeMapItr == theChargeMap.end())
256  {
257  theChargeMap[truthId] = charge;
258  }
259  else
260  {
261  theChargeMap[truthId] += charge;
262  }
263  }
264  }
265 }
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
float theTotalCharge
Definition: MuonTruth.h:59
std::pair< uint32_t, EncodedEventId > SimHitIdpr
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
void MuonTruth::analyze ( const CSCRecHit2D recHit)

Definition at line 182 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(), geometry, CSCGeometry::layer(), CSCRecHit2D::nStrips(), DetId::rawId(), theChargeMap, theDetId, theDigiSimLinks, and theTotalCharge.

Referenced by CSCTruthTest::analyze().

183 {
184  theChargeMap.clear();
185  theTotalCharge = 0.;
186  theDetId = recHit.geographicalId().rawId();
187 
188  int nchannels = recHit.nStrips();
189  const CSCLayerGeometry * laygeom = cscgeom->layer(recHit.cscDetId())->geometry();
190 
191  for(int idigi = 0; idigi < nchannels; ++idigi)
192  {
193  // strip and readout channel numbers may differ in ME1/1A
194  int istrip = recHit.channels(idigi);
195  int channel = laygeom->channel(istrip);
196  float weight = recHit.adcs(idigi,0);//DL: I think this is wrong before and after...seems to assume one time binadcContainer[idigi];
197 
199 
200  if(layerLinks != theDigiSimLinks->end())
201  {
202  addChannel(*layerLinks, channel, weight);
203  }
204  }
205 }
CSCDetId cscDetId() const
Definition: CSCRecHit2D.h:52
iterator find(det_id_type id)
Definition: DetSetVector.h:290
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
Definition: weight.py:1
const CSCGeometry * cscgeom
Definition: MuonTruth.h:75
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
int channels(unsigned int i) const
Extracting strip channel numbers comprising the rechit - low.
Definition: CSCRecHit2D.h:55
unsigned int theDetId
Definition: MuonTruth.h:61
unsigned int nStrips() const
Definition: CSCRecHit2D.h:56
float adcs(unsigned int strip, unsigned int timebin) const
Map of strip ADCs for strips comprising the rechit.
Definition: CSCRecHit2D.h:68
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
int channel(int strip) const
float theTotalCharge
Definition: MuonTruth.h:59
ESHandle< TrackerGeometry > geometry
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:124
DetId geographicalId() const
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:240
void MuonTruth::analyze ( const CSCStripDigi stripDigi,
int  rawDetIdCorrespondingToCSCLayer 
)

Definition at line 208 of file MuonTruth.cc.

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

209 {
210  theDetId = rawDetIdCorrespondingToCSCLayer;
211  theChargeMap.clear();
212  theTotalCharge = 0.;
213 
215  if(layerLinks != theDigiSimLinks->end())
216  {
217  addChannel(*layerLinks, stripDigi.getStrip(), 1.);
218  }
219 }
iterator find(det_id_type id)
Definition: DetSetVector.h:290
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
int getStrip() const
Definition: CSCStripDigi.h:51
unsigned int theDetId
Definition: MuonTruth.h:61
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
float theTotalCharge
Definition: MuonTruth.h:59
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:240
void MuonTruth::analyze ( const CSCWireDigi wireDigi,
int  rawDetIdCorrespondingToCSCLayer 
)

Definition at line 222 of file MuonTruth.cc.

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

223 {
224  theDetId = rawDetIdCorrespondingToCSCLayer;
225  theChargeMap.clear();
226  theTotalCharge = 0.;
227 
229 
230  if(layerLinks != theDigiSimLinks->end())
231  {
232  // In the simulation digis, the channel labels for wires and strips must be distinct, therefore:
233  int wireDigiInSimulation = wireDigi.getWireGroup() + 100;
234  //
235  addChannel(*layerLinks, wireDigiInSimulation, 1.);
236  }
237 }
iterator find(det_id_type id)
Definition: DetSetVector.h:290
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:64
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
unsigned int theDetId
Definition: MuonTruth.h:61
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
float theTotalCharge
Definition: MuonTruth.h:59
int getWireGroup() const
default
Definition: CSCWireDigi.h:24
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:240
std::vector< PSimHit > MuonTruth::hitsFromSimTrack ( MuonTruth::SimHitIdpr  truthId)
private

Definition at line 148 of file MuonTruth.cc.

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

Referenced by particleType(), and simHits().

149 {
150  std::vector<PSimHit> result;
151 
152  auto found = theSimHitMap.find(theDetId);
153  if (found != theSimHitMap.end()) {
154 
155  for(auto const& hit: found->second)
156  {
157  unsigned int hitTrack = hit.trackId();
158  EncodedEventId hitEvId = hit.eventId();
159 
160  if(hitTrack == truthId.first && hitEvId == truthId.second)
161  {
162  result.push_back(hit);
163  }
164  }
165  }
166  return result;
167 }
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:73
unsigned int theDetId
Definition: MuonTruth.h:61
void MuonTruth::initEvent ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 43 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< T >::product(), theDigiSimLinks, theSimHitMap, theWireDigiSimLinks, and wireLinksTag.

Referenced by MuonTruth().

43  {
44 
46  LogTrace("MuonTruth") <<"getting CSC Strip DigiSimLink collection - "<<linksTag;
47  event.getByLabel(linksTag, digiSimLinks);
48  theDigiSimLinks = digiSimLinks.product();
49 
50  edm::Handle<DigiSimLinks> wireDigiSimLinks;
51  LogTrace("MuonTruth") <<"getting CSC Wire DigiSimLink collection - "<<wireLinksTag;
52  event.getByLabel(wireLinksTag, wireDigiSimLinks);
53  theWireDigiSimLinks = wireDigiSimLinks.product();
54 
55  // get CSC Geometry to use CSCLayer methods
57  setup.get<MuonGeometryRecord>().get( mugeom );
58  cscgeom = &*mugeom;
59 
60  // get CSC Bad Chambers (ME4/2)
62  setup.get<CSCBadChambersRcd>().get(badChambers);
63  cscBadChambers = badChambers.product();
64 
65  theSimHitMap.clear();
66 
67  if (crossingframe) {
68 
70  LogTrace("MuonTruth") <<"getting CrossingFrame<PSimHit> collection - "<<CSCsimHitsXFTag;
71  event.getByLabel(CSCsimHitsXFTag, cf);
72 
73  std::unique_ptr<MixCollection<PSimHit> >
74  CSCsimhits( new MixCollection<PSimHit>(cf.product()) );
75  LogTrace("MuonTruth") <<"... size = "<<CSCsimhits->size();
76 
77  for(MixCollection<PSimHit>::MixItr hitItr = CSCsimhits->begin();
78  hitItr != CSCsimhits->end(); ++hitItr)
79  {
80  theSimHitMap[hitItr->detUnitId()].push_back(*hitItr);
81  }
82 
83  } else if (!CSCsimHitsTag.label().empty()){
84 
86  LogTrace("MuonTruth") <<"getting PSimHit collection - "<<CSCsimHitsTag;
87  event.getByLabel(CSCsimHitsTag, CSCsimhits);
88  LogTrace("MuonTruth") <<"... size = "<<CSCsimhits->size();
89 
90  for(edm::PSimHitContainer::const_iterator hitItr = CSCsimhits->begin();
91  hitItr != CSCsimhits->end(); ++hitItr)
92  {
93  theSimHitMap[hitItr->detUnitId()].push_back(*hitItr);
94  }
95  }
96 }
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:73
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:70
edm::InputTag linksTag
Definition: MuonTruth.h:66
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:71
edm::InputTag wireLinksTag
Definition: MuonTruth.h:67
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:64
const CSCGeometry * cscgeom
Definition: MuonTruth.h:75
bool crossingframe
Definition: MuonTruth.h:69
const CSCBadChambers * cscBadChambers
Definition: MuonTruth.h:48
#define LogTrace(id)
T const * product() const
Definition: Handle.h:81
std::string const & label() const
Definition: InputTag.h:36
T get() const
Definition: EventSetup.h:63
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63
T const * product() const
Definition: ESHandle.h:86
float MuonTruth::muonFraction ( )

analyze() must be called before any of the following

Definition at line 98 of file MuonTruth.cc.

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

Referenced by CSCTruthTest::analyze().

99 {
100  if(theChargeMap.empty()) return 0.;
101 
102  float muonCharge = 0.;
103  for(std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.begin();
104  chargeMapItr != theChargeMap.end(); ++chargeMapItr)
105  {
106  if( abs(particleType(chargeMapItr->first)) == 13)
107  {
108  muonCharge += chargeMapItr->second;
109  }
110  }
111 
112  return muonCharge / theTotalCharge;
113 }
int particleType(SimHitIdpr truthId)
Definition: MuonTruth.cc:170
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float theTotalCharge
Definition: MuonTruth.h:59
std::vector< PSimHit > MuonTruth::muonHits ( )

Definition at line 130 of file MuonTruth.cc.

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

131 {
132  std::vector<PSimHit> result;
133  std::vector<PSimHit> allHits = simHits();
134  std::vector<PSimHit>::const_iterator hitItr = allHits.begin(), lastHit = allHits.end();
135 
136  for( ; hitItr != lastHit; ++hitItr)
137  {
138  if(abs((*hitItr).particleType()) == 13)
139  {
140  result.push_back(*hitItr);
141  }
142  }
143  return result;
144 }
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:116
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int MuonTruth::particleType ( MuonTruth::SimHitIdpr  truthId)
private

Definition at line 170 of file MuonTruth.cc.

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

Referenced by muonFraction().

171 {
172  int result = 0;
173  const std::vector<PSimHit>& hits = hitsFromSimTrack(truthId);
174  if(!hits.empty())
175  {
176  result = hits[0].particleType();
177  }
178  return result;
179 }
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:148
std::vector< PSimHit > MuonTruth::simHits ( )

Definition at line 116 of file MuonTruth.cc.

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

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

117 {
118  std::vector<PSimHit> result;
119  for(std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.begin();
120  chargeMapItr != theChargeMap.end(); ++chargeMapItr)
121  {
122  std::vector<PSimHit> trackHits = hitsFromSimTrack(chargeMapItr->first);
123  result.insert(result.end(), trackHits.begin(), trackHits.end());
124  }
125 
126  return result;
127 }
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:148

Member Data Documentation

bool MuonTruth::crossingframe
private

Definition at line 69 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

const CSCBadChambers* MuonTruth::cscBadChambers

Definition at line 48 of file MuonTruth.h.

Referenced by initEvent().

const CSCGeometry* MuonTruth::cscgeom
private

Definition at line 75 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

edm::InputTag MuonTruth::CSCsimHitsTag
private

Definition at line 70 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

edm::InputTag MuonTruth::CSCsimHitsXFTag
private

Definition at line 71 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

edm::InputTag MuonTruth::linksTag
private

Definition at line 66 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().

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

Definition at line 58 of file MuonTruth.h.

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

unsigned int MuonTruth::theDetId
private

Definition at line 61 of file MuonTruth.h.

Referenced by analyze(), and hitsFromSimTrack().

const DigiSimLinks* MuonTruth::theDigiSimLinks
private

Definition at line 63 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

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

Definition at line 73 of file MuonTruth.h.

Referenced by hitsFromSimTrack(), and initEvent().

float MuonTruth::theTotalCharge
private

Definition at line 59 of file MuonTruth.h.

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

const DigiSimLinks* MuonTruth::theWireDigiSimLinks
private

Definition at line 64 of file MuonTruth.h.

Referenced by analyze(), and initEvent().

edm::InputTag MuonTruth::wireLinksTag
private

Definition at line 67 of file MuonTruth.h.

Referenced by initEvent(), and MuonTruth().