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  edm::Handle<DigiSimLinks> digiSimLinks;
20  LogTrace("MuonTruth") <<"getting CSC Strip DigiSimLink collection - "<<linksTag;
21  event.getByLabel(linksTag, digiSimLinks);
22  theDigiSimLinks = digiSimLinks.product();
23 
24  edm::Handle<DigiSimLinks> wireDigiSimLinks;
25  LogTrace("MuonTruth") <<"getting CSC Wire DigiSimLink collection - "<<wireLinksTag;
26  event.getByLabel(wireLinksTag, wireDigiSimLinks);
27  theWireDigiSimLinks = wireDigiSimLinks.product();
28 
29  // get CSC Geometry to use CSCLayer methods
31  setup.get<MuonGeometryRecord>().get( mugeom );
32  cscgeom = &*mugeom;
33 
34  // get CSC Bad Chambers (ME4/2)
36  setup.get<CSCBadChambersRcd>().get(badChambers);
37  cscBadChambers = badChambers.product();
38 
39  theSimHitMap.clear();
40 
41  if (crossingframe) {
42 
44  LogTrace("MuonTruth") <<"getting CrossingFrame<PSimHit> collection - "<<CSCsimHitsXFTag;
45  event.getByLabel(CSCsimHitsXFTag, cf);
46 
47  std::auto_ptr<MixCollection<PSimHit> >
48  CSCsimhits( new MixCollection<PSimHit>(cf.product()) );
49  LogTrace("MuonTruth") <<"... size = "<<CSCsimhits->size();
50 
51  for(MixCollection<PSimHit>::MixItr hitItr = CSCsimhits->begin();
52  hitItr != CSCsimhits->end(); ++hitItr)
53  {
54  theSimHitMap[hitItr->detUnitId()].push_back(*hitItr);
55  }
56 
57  } else if (!CSCsimHitsTag.label().empty()){
58 
60  LogTrace("MuonTruth") <<"getting PSimHit collection - "<<CSCsimHitsTag;
61  event.getByLabel(CSCsimHitsTag, CSCsimhits);
62  LogTrace("MuonTruth") <<"... size = "<<CSCsimhits->size();
63 
64  for(edm::PSimHitContainer::const_iterator hitItr = CSCsimhits->begin();
65  hitItr != CSCsimhits->end(); ++hitItr)
66  {
67  theSimHitMap[hitItr->detUnitId()].push_back(*hitItr);
68  }
69  }
70 }
71 
73 {
74  if(theChargeMap.size() == 0) return 0.;
75 
76  float muonCharge = 0.;
77  for(std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.begin();
78  chargeMapItr != theChargeMap.end(); ++chargeMapItr)
79  {
80  if( abs(particleType(chargeMapItr->first)) == 13)
81  {
82  muonCharge += chargeMapItr->second;
83  }
84  }
85 
86  return muonCharge / theTotalCharge;
87 }
88 
89 
90 std::vector<PSimHit> MuonTruth::simHits()
91 {
92  std::vector<PSimHit> result;
93  for(std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.begin();
94  chargeMapItr != theChargeMap.end(); ++chargeMapItr)
95  {
96  std::vector<PSimHit> trackHits = hitsFromSimTrack(chargeMapItr->first);
97  result.insert(result.end(), trackHits.begin(), trackHits.end());
98  }
99 
100  return result;
101 }
102 
103 
104 std::vector<PSimHit> MuonTruth::muonHits()
105 {
106  std::vector<PSimHit> result;
107  std::vector<PSimHit> allHits = simHits();
108  std::vector<PSimHit>::const_iterator hitItr = allHits.begin(), lastHit = allHits.end();
109 
110  for( ; hitItr != lastHit; ++hitItr)
111  {
112  if(abs((*hitItr).particleType()) == 13)
113  {
114  result.push_back(*hitItr);
115  }
116  }
117  return result;
118 }
119 
120 
121 std::vector<MuonTruth::SimHitIdpr> MuonTruth::associateCSCHitId(const CSCRecHit2D * cscrechit) {
122  std::vector<SimHitIdpr> simtrackids;
123 
124  theDetId = cscrechit->geographicalId().rawId();
125  int nchannels = cscrechit->nStrips();
126  const CSCLayerGeometry * laygeom = cscgeom->layer(cscrechit->cscDetId())->geometry();
127 
129 
130  if (layerLinks != theDigiSimLinks->end()) {
131 
132  for(int idigi = 0; idigi < nchannels; ++idigi) {
133  // strip and readout channel numbers may differ in ME1/1A
134  int istrip = cscrechit->channels(idigi);
135  int channel = laygeom->channel(istrip);
136 
137  for (LayerLinks::const_iterator link=layerLinks->begin(); link!=layerLinks->end(); ++link) {
138  int ch = static_cast<int>(link->channel());
139  if (ch == channel) {
140  SimHitIdpr currentId(link->SimTrackId(), link->eventId());
141  if (find(simtrackids.begin(), simtrackids.end(), currentId) == simtrackids.end())
142  simtrackids.push_back(currentId);
143  }
144  }
145  }
146 
147  } else edm::LogWarning("MuonTruth")
148  <<"*** WARNING in MuonTruth::associateCSCHitId - CSC layer "<<theDetId<<" has no DigiSimLinks !"<<std::endl;
149 
150  return simtrackids;
151 }
152 
153 
154 std::vector<MuonTruth::SimHitIdpr> MuonTruth::associateHitId(const TrackingRecHit & hit)
155 {
156  std::vector<SimHitIdpr> simtrackids;
157 
158  const TrackingRecHit * hitp = &hit;
159  const CSCRecHit2D * cscrechit = dynamic_cast<const CSCRecHit2D *>(hitp);
160 
161  if (cscrechit) {
162 
163  theDetId = cscrechit->geographicalId().rawId();
164  int nchannels = cscrechit->nStrips();
165  const CSCLayerGeometry * laygeom = cscgeom->layer(cscrechit->cscDetId())->geometry();
166 
168 
169  if (layerLinks != theDigiSimLinks->end()) {
170 
171  for(int idigi = 0; idigi < nchannels; ++idigi) {
172  // strip and readout channel numbers may differ in ME1/1A
173  int istrip = cscrechit->channels(idigi);
174  int channel = laygeom->channel(istrip);
175 
176  for (LayerLinks::const_iterator link=layerLinks->begin(); link!=layerLinks->end(); ++link) {
177  int ch = static_cast<int>(link->channel());
178  if (ch == channel) {
179  SimHitIdpr currentId(link->SimTrackId(), link->eventId());
180  if (find(simtrackids.begin(), simtrackids.end(), currentId) == simtrackids.end())
181  simtrackids.push_back(currentId);
182  }
183  }
184  }
185 
186  } else edm::LogWarning("MuonTruth")
187  <<"*** WARNING in MuonTruth::associateHitId - CSC layer "<<theDetId<<" has no DigiSimLinks !"<<std::endl;
188 
189  } else edm::LogWarning("MuonTruth")<<"*** WARNING in MuonTruth::associateHitId, null dynamic_cast !";
190 
191  return simtrackids;
192 }
193 
194 
196 {
197  std::vector<PSimHit> result;
199 
200  if (theSimHitMap.find(theDetId) != theSimHitMap.end())
201  hits = theSimHitMap[theDetId];
202 
203  edm::PSimHitContainer::const_iterator hitItr = hits.begin(), lastHit = hits.end();
204 
205  for( ; hitItr != lastHit; ++hitItr)
206  {
207  unsigned int hitTrack = hitItr->trackId();
208  EncodedEventId hitEvId = hitItr->eventId();
209 
210  if(hitTrack == truthId.first && hitEvId == truthId.second)
211  {
212  result.push_back(*hitItr);
213  }
214  }
215  return result;
216 }
217 
218 
220 {
221  int result = 0;
222  std::vector<PSimHit> hits = hitsFromSimTrack(truthId);
223  if(!hits.empty())
224  {
225  result = hits[0].particleType();
226  }
227  return result;
228 }
229 
230 
231 void MuonTruth::analyze(const CSCRecHit2D & recHit)
232 {
233  theChargeMap.clear();
234  theTotalCharge = 0.;
235  theDetId = recHit.geographicalId().rawId();
236 
237  int nchannels = recHit.nStrips();
238  const CSCLayerGeometry * laygeom = cscgeom->layer(recHit.cscDetId())->geometry();
239 
240  for(int idigi = 0; idigi < nchannels; ++idigi)
241  {
242  // strip and readout channel numbers may differ in ME1/1A
243  int istrip = recHit.channels(idigi);
244  int channel = laygeom->channel(istrip);
245  float weight = recHit.adcs(idigi,0);//DL: I think this is wrong before and after...seems to assume one time binadcContainer[idigi];
246 
248 
249  if(layerLinks != theDigiSimLinks->end())
250  {
251  addChannel(*layerLinks, channel, weight);
252  }
253  }
254 }
255 
256 
257 void MuonTruth::analyze(const CSCStripDigi & stripDigi, int rawDetIdCorrespondingToCSCLayer)
258 {
259  theDetId = rawDetIdCorrespondingToCSCLayer;
260  theChargeMap.clear();
261  theTotalCharge = 0.;
262 
264  if(layerLinks != theDigiSimLinks->end())
265  {
266  addChannel(*layerLinks, stripDigi.getStrip(), 1.);
267  }
268 }
269 
270 
271 void MuonTruth::analyze(const CSCWireDigi & wireDigi, int rawDetIdCorrespondingToCSCLayer)
272 {
273  theDetId = rawDetIdCorrespondingToCSCLayer;
274  theChargeMap.clear();
275  theTotalCharge = 0.;
276 
278 
279  if(layerLinks != theDigiSimLinks->end())
280  {
281  // In the simulation digis, the channel labels for wires and strips must be distinct, therefore:
282  int wireDigiInSimulation = wireDigi.getWireGroup() + 100;
283  //
284  addChannel(*layerLinks, wireDigiInSimulation, 1.);
285  }
286 }
287 
288 
289 void MuonTruth::addChannel(const LayerLinks &layerLinks, int channel, float weight)
290 {
291  LayerLinks::const_iterator linkItr = layerLinks.begin(),
292  lastLayerLink = layerLinks.end();
293 
294  for ( ; linkItr != lastLayerLink; ++linkItr)
295  {
296  int linkChannel = linkItr->channel();
297  if(linkChannel == channel)
298  {
299  float charge = linkItr->fraction() * weight;
301  // see if it's in the map
302  SimHitIdpr truthId(linkItr->SimTrackId(),linkItr->eventId());
303  std::map<SimHitIdpr, float>::const_iterator chargeMapItr = theChargeMap.find(truthId);
304  if(chargeMapItr == theChargeMap.end())
305  {
306  theChargeMap[truthId] = charge;
307  }
308  else
309  {
310  theChargeMap[truthId] += charge;
311  }
312  }
313  }
314 }
315 
316 
std::map< unsigned int, edm::PSimHitContainer > theSimHitMap
Definition: MuonTruth.h:71
iterator end()
Definition: DetSet.h:61
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: MuonTruth.h:29
edm::InputTag CSCsimHitsTag
Definition: MuonTruth.h:68
iterator find(det_id_type id)
Definition: DetSetVector.h:285
edm::InputTag linksTag
Definition: MuonTruth.h:64
int particleType(SimHitIdpr truthId)
Definition: MuonTruth.cc:219
edm::InputTag CSCsimHitsXFTag
Definition: MuonTruth.h:69
edm::InputTag wireLinksTag
Definition: MuonTruth.h:65
#define abs(x)
Definition: mlp_lapack.h:159
const DigiSimLinks * theWireDigiSimLinks
Definition: MuonTruth.h:62
const CSCGeometry * cscgeom
Definition: MuonTruth.h:73
std::map< SimHitIdpr, float > theChargeMap
Definition: MuonTruth.h:56
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &)
Definition: MuonTruth.cc:154
std::vector< PSimHit > muonHits()
Definition: MuonTruth.cc:104
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double charge(const std::vector< uint8_t > &Ampls)
std::vector< PSimHit > simHits()
Definition: MuonTruth.cc:90
int getStrip() const
Definition: CSCStripDigi.h:39
bool crossingframe
Definition: MuonTruth.h:67
std::string link(std::string &nm, std::string &ns)
Definition: hierarchy.cc:24
const CSCBadChambers * cscBadChambers
Definition: MuonTruth.h:46
unsigned int theDetId
Definition: MuonTruth.h:59
std::vector< PSimHit > hitsFromSimTrack(SimHitIdpr truthId)
Definition: MuonTruth.cc:195
tuple result
Definition: query.py:137
std::vector< SimHitIdpr > associateCSCHitId(const CSCRecHit2D *)
Definition: MuonTruth.cc:121
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:231
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
#define LogTrace(id)
tuple conf
Definition: dbtoconf.py:185
int channel(int strip) const
iterator begin()
Definition: DetSet.h:60
float theTotalCharge
Definition: MuonTruth.h:57
MuonTruth(const edm::Event &, const edm::EventSetup &, const edm::ParameterSet &)
Definition: MuonTruth.cc:8
int getWireGroup() const
default
Definition: CSCWireDigi.h:24
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
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
int weight
Definition: histoStyle.py:50
float muonFraction()
analyze() must be called before any of the following
Definition: MuonTruth.cc:72
const DigiSimLinks * theDigiSimLinks
Definition: MuonTruth.h:61
collection_type::const_iterator const_iterator
Definition: DetSet.h:34
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
void addChannel(const LayerLinks &layerLinks, int channel, float weight=1.)
Definition: MuonTruth.cc:289
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")