CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonTruth.cc
Go to the documentation of this file.
7 
9  theDigiSimLinks(0),
10  theWireDigiSimLinks(0),
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 }
21 
23  theDigiSimLinks(0),
24  theWireDigiSimLinks(0),
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 }
42 
44 
45  edm::Handle<DigiSimLinks> digiSimLinks;
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::auto_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 }
97 
99 {
100  if(theChargeMap.size() == 0) 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 }
114 
115 
116 std::vector<PSimHit> MuonTruth::simHits()
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 }
128 
129 
130 std::vector<PSimHit> MuonTruth::muonHits()
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 }
145 
146 
147 
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 }
168 
169 
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 }
180 
181 
182 void MuonTruth::analyze(const CSCRecHit2D & recHit)
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 }
206 
207 
208 void MuonTruth::analyze(const CSCStripDigi & stripDigi, int rawDetIdCorrespondingToCSCLayer)
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 }
220 
221 
222 void MuonTruth::analyze(const CSCWireDigi & wireDigi, int rawDetIdCorrespondingToCSCLayer)
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 }
238 
239 
240 void MuonTruth::addChannel(const LayerLinks &layerLinks, int channel, float weight)
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 }
266 
267 
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:73
iterator end()
Definition: DetSet.h:60
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: MuonTruth.h:30
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:70
CSCDetId cscDetId() const
Definition: CSCRecHit2D.h:52
iterator find(det_id_type id)
Definition: DetSetVector.h:294
edm::InputTag linksTag
Definition: MuonTruth.h:66
int particleType(SimHitIdpr truthId)
Definition: MuonTruth.cc:170
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
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:58
std::vector< PSimHit > muonHits()
Definition: MuonTruth.cc:130
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:116
int getStrip() const
Definition: CSCStripDigi.h:51
bool crossingframe
Definition: MuonTruth.h:69
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int channels(unsigned int i) const
Extracting strip channel numbers comprising the rechit - low.
Definition: CSCRecHit2D.h:55
const CSCBadChambers * cscBadChambers
Definition: MuonTruth.h:48
unsigned int theDetId
Definition: MuonTruth.h:61
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:148
tuple result
Definition: query.py:137
unsigned int nStrips() const
Definition: CSCRecHit2D.h:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float adcs(unsigned int strip, unsigned int timebin) const
Map of strip ADCs for strips comprising the rechit.
Definition: CSCRecHit2D.h:68
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void analyze(const CSCRecHit2D &recHit)
Definition: MuonTruth.cc:182
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:365
#define LogTrace(id)
tuple conf
Definition: dbtoconf.py:185
int channel(int strip) const
iterator begin()
Definition: DetSet.h:59
float theTotalCharge
Definition: MuonTruth.h:59
MuonTruth(const edm::Event &, const edm::EventSetup &, const edm::ParameterSet &)
Definition: MuonTruth.cc:8
T const * product() const
Definition: Handle.h:81
int getWireGroup() const
default
Definition: CSCWireDigi.h:24
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
std::string const & label() const
Definition: InputTag.h:43
ESHandle< TrackerGeometry > geometry
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:124
std::vector< PSimHit > PSimHitContainer
DetId geographicalId() const
int weight
Definition: histoStyle.py:50
float muonFraction()
analyze() must be called before any of the following
Definition: MuonTruth.cc:98
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:63
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:240
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void initEvent(const edm::Event &, const edm::EventSetup &)
Definition: MuonTruth.cc:43