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 std::vector<MuonTruth::SimHitIdpr> MuonTruth::associateCSCHitId(const CSCRecHit2D * cscrechit) {
148  std::vector<SimHitIdpr> simtrackids;
149 
150  theDetId = cscrechit->geographicalId().rawId();
151  int nchannels = cscrechit->nStrips();
152  const CSCLayerGeometry * laygeom = cscgeom->layer(cscrechit->cscDetId())->geometry();
153 
155 
156  if (layerLinks != theDigiSimLinks->end()) {
157 
158  for(int idigi = 0; idigi < nchannels; ++idigi) {
159  // strip and readout channel numbers may differ in ME1/1A
160  int istrip = cscrechit->channels(idigi);
161  int channel = laygeom->channel(istrip);
162 
163  for (LayerLinks::const_iterator link=layerLinks->begin(); link!=layerLinks->end(); ++link) {
164  int ch = static_cast<int>(link->channel());
165  if (ch == channel) {
166  SimHitIdpr currentId(link->SimTrackId(), link->eventId());
167  if (find(simtrackids.begin(), simtrackids.end(), currentId) == simtrackids.end())
168  simtrackids.push_back(currentId);
169  }
170  }
171  }
172 
173  } else edm::LogWarning("MuonTruth")
174  <<"*** WARNING in MuonTruth::associateCSCHitId - CSC layer "<<theDetId<<" has no DigiSimLinks !"<<std::endl;
175 
176  return simtrackids;
177 }
178 
179 
180 std::vector<MuonTruth::SimHitIdpr> MuonTruth::associateHitId(const TrackingRecHit & hit)
181 {
182  std::vector<SimHitIdpr> simtrackids;
183 
184  const TrackingRecHit * hitp = &hit;
185  const CSCRecHit2D * cscrechit = dynamic_cast<const CSCRecHit2D *>(hitp);
186 
187  if (cscrechit) {
188 
189  theDetId = cscrechit->geographicalId().rawId();
190  int nchannels = cscrechit->nStrips();
191  const CSCLayerGeometry * laygeom = cscgeom->layer(cscrechit->cscDetId())->geometry();
192 
194 
195  if (layerLinks != theDigiSimLinks->end()) {
196 
197  for(int idigi = 0; idigi < nchannels; ++idigi) {
198  // strip and readout channel numbers may differ in ME1/1A
199  int istrip = cscrechit->channels(idigi);
200  int channel = laygeom->channel(istrip);
201 
202  for (LayerLinks::const_iterator link=layerLinks->begin(); link!=layerLinks->end(); ++link) {
203  int ch = static_cast<int>(link->channel());
204  if (ch == channel) {
205  SimHitIdpr currentId(link->SimTrackId(), link->eventId());
206  if (find(simtrackids.begin(), simtrackids.end(), currentId) == simtrackids.end())
207  simtrackids.push_back(currentId);
208  }
209  }
210  }
211 
212  } else edm::LogWarning("MuonTruth")
213  <<"*** WARNING in MuonTruth::associateHitId - CSC layer "<<theDetId<<" has no DigiSimLinks !"<<std::endl;
214 
215  } else edm::LogWarning("MuonTruth")<<"*** WARNING in MuonTruth::associateHitId, null dynamic_cast !";
216 
217  return simtrackids;
218 }
219 
220 
222 {
223  std::vector<PSimHit> result;
225 
226  if (theSimHitMap.find(theDetId) != theSimHitMap.end())
227  hits = theSimHitMap[theDetId];
228 
229  edm::PSimHitContainer::const_iterator hitItr = hits.begin(), lastHit = hits.end();
230 
231  for( ; hitItr != lastHit; ++hitItr)
232  {
233  unsigned int hitTrack = hitItr->trackId();
234  EncodedEventId hitEvId = hitItr->eventId();
235 
236  if(hitTrack == truthId.first && hitEvId == truthId.second)
237  {
238  result.push_back(*hitItr);
239  }
240  }
241  return result;
242 }
243 
244 
246 {
247  int result = 0;
248  std::vector<PSimHit> hits = hitsFromSimTrack(truthId);
249  if(!hits.empty())
250  {
251  result = hits[0].particleType();
252  }
253  return result;
254 }
255 
256 
257 void MuonTruth::analyze(const CSCRecHit2D & recHit)
258 {
259  theChargeMap.clear();
260  theTotalCharge = 0.;
261  theDetId = recHit.geographicalId().rawId();
262 
263  int nchannels = recHit.nStrips();
264  const CSCLayerGeometry * laygeom = cscgeom->layer(recHit.cscDetId())->geometry();
265 
266  for(int idigi = 0; idigi < nchannels; ++idigi)
267  {
268  // strip and readout channel numbers may differ in ME1/1A
269  int istrip = recHit.channels(idigi);
270  int channel = laygeom->channel(istrip);
271  float weight = recHit.adcs(idigi,0);//DL: I think this is wrong before and after...seems to assume one time binadcContainer[idigi];
272 
274 
275  if(layerLinks != theDigiSimLinks->end())
276  {
277  addChannel(*layerLinks, channel, weight);
278  }
279  }
280 }
281 
282 
283 void MuonTruth::analyze(const CSCStripDigi & stripDigi, int rawDetIdCorrespondingToCSCLayer)
284 {
285  theDetId = rawDetIdCorrespondingToCSCLayer;
286  theChargeMap.clear();
287  theTotalCharge = 0.;
288 
290  if(layerLinks != theDigiSimLinks->end())
291  {
292  addChannel(*layerLinks, stripDigi.getStrip(), 1.);
293  }
294 }
295 
296 
297 void MuonTruth::analyze(const CSCWireDigi & wireDigi, int rawDetIdCorrespondingToCSCLayer)
298 {
299  theDetId = rawDetIdCorrespondingToCSCLayer;
300  theChargeMap.clear();
301  theTotalCharge = 0.;
302 
304 
305  if(layerLinks != theDigiSimLinks->end())
306  {
307  // In the simulation digis, the channel labels for wires and strips must be distinct, therefore:
308  int wireDigiInSimulation = wireDigi.getWireGroup() + 100;
309  //
310  addChannel(*layerLinks, wireDigiInSimulation, 1.);
311  }
312 }
313 
314 
315 void MuonTruth::addChannel(const LayerLinks &layerLinks, int channel, float weight)
316 {
317  LayerLinks::const_iterator linkItr = layerLinks.begin(),
318  lastLayerLink = layerLinks.end();
319 
320  for ( ; linkItr != lastLayerLink; ++linkItr)
321  {
322  int linkChannel = linkItr->channel();
323  if(linkChannel == channel)
324  {
325  float charge = linkItr->fraction() * weight;
326  theTotalCharge += charge;
327  // see if it's in the map
328  SimHitIdpr truthId(linkItr->SimTrackId(),linkItr->eventId());
329  std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.find(truthId);
330  if(chargeMapItr == theChargeMap.end())
331  {
332  theChargeMap[truthId] = charge;
333  }
334  else
335  {
336  theChargeMap[truthId] += charge;
337  }
338  }
339  }
340 }
341 
342 
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:76
iterator end()
Definition: DetSet.h:60
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: MuonTruth.h:30
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:73
CSCDetId cscDetId() const
Definition: CSCRecHit2D.h:52
iterator find(det_id_type id)
Definition: DetSetVector.h:294
edm::InputTag linksTag
Definition: MuonTruth.h:69
int particleType(SimHitIdpr truthId)
Definition: MuonTruth.cc:245
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:74
edm::InputTag wireLinksTag
Definition: MuonTruth.h:70
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:67
const CSCGeometry * cscgeom
Definition: MuonTruth.h:78
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:61
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &)
Definition: MuonTruth.cc:180
std::vector< PSimHit > muonHits()
Definition: MuonTruth.cc:130
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:116
int getStrip() const
Definition: CSCStripDigi.h:51
bool crossingframe
Definition: MuonTruth.h:72
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:51
unsigned int theDetId
Definition: MuonTruth.h:64
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:221
tuple result
Definition: query.py:137
unsigned int nStrips() const
Definition: CSCRecHit2D.h:56
std::vector< SimHitIdpr > associateCSCHitId(const CSCRecHit2D *)
Definition: MuonTruth.cc:147
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:257
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:62
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:42
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:66
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:315
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void initEvent(const edm::Event &, const edm::EventSetup &)
Definition: MuonTruth.cc:43