CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonCaloDistanceProducer.cc
Go to the documentation of this file.
2 
4 
7 
13 
17 
19 
20 #include <string>
21 #include <vector>
22 #include <boost/foreach.hpp>
23 
25  : srcSelectedMuons_(cfg.getParameter<edm::InputTag>("selectedMuons"))
26 {
27  // maps of detId to distance traversed by muon through detector volume
28  produces<reco::CandidateCollection>("muons");
29  produces<detIdToFloatMap>("distancesMuPlus");
30  produces<detIdToFloatMap>("distancesMuMinus");
31  produces<detIdToFloatMap>("depositsMuPlus");
32  produces<detIdToFloatMap>("depositsMuMinus");
33 
34  edm::ParameterSet cfgTrackAssociator = cfg.getParameter<edm::ParameterSet>("trackAssociator");
35  trackAssociatorParameters_.loadParameters(cfgTrackAssociator);
37 }
38 
40 {
41 // nothing to be done yet...
42 }
43 
45 {
46  std::auto_ptr<detIdToFloatMap> distanceMuPlus(new detIdToFloatMap());
47  std::auto_ptr<detIdToFloatMap> distanceMuMinus(new detIdToFloatMap());
48  std::auto_ptr<detIdToFloatMap> depositMuPlus(new detIdToFloatMap());
49  std::auto_ptr<detIdToFloatMap> depositMuMinus(new detIdToFloatMap());
50 
51  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons_);
52  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
53  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
54 
55  if ( muPlus.isNonnull() ) fillDistanceMap(evt, es, &(*muPlus), *distanceMuPlus, *depositMuPlus);
56  if ( muMinus.isNonnull() ) fillDistanceMap(evt, es, &(*muMinus), *distanceMuMinus, *depositMuMinus);
57 
58  std::auto_ptr<reco::CandidateCollection> muons(new reco::CandidateCollection);
59  if ( muPlus.isNonnull() ) muons->push_back(new reco::ShallowCloneCandidate(muPlus));
60  if ( muMinus.isNonnull() ) muons->push_back(new reco::ShallowCloneCandidate(muMinus));
61 
62  // References to the muons themselves
63  evt.put(muons, "muons");
64 
65  // maps of detId to distance traversed by muon through calorimeter cell
66  evt.put(distanceMuPlus, "distancesMuPlus");
67  evt.put(distanceMuMinus, "distancesMuMinus");
68 
69  // maps of detId to energy deposited in calorimeter cell
70  evt.put(depositMuPlus, "depositsMuPlus");
71  evt.put(depositMuMinus, "depositsMuMinus");
72 }
73 
75 {
77 
78  BOOST_FOREACH(const EcalRecHit * rh, trackDetMatchInfo.crossedEcalRecHits)
79  depositMap[rh->detid().rawId()]+=rh->energy();
80 
81  BOOST_FOREACH(const HBHERecHit * rh, trackDetMatchInfo.crossedHcalRecHits)
82  depositMap[rh->detid().rawId()]+=rh->energy();
83 
84  BOOST_FOREACH(const HORecHit * rh, trackDetMatchInfo.crossedHORecHits)
85  depositMap[rh->detid().rawId()]+=rh->energy();
86 
87  typedef std::map<std::string, const std::vector<DetId>*> CaloToDetIdMap;
88  CaloToDetIdMap caloToDetIdMap;
89  caloToDetIdMap["ecal"] = &(trackDetMatchInfo.crossedEcalIds);
90  caloToDetIdMap["hcal"] = &(trackDetMatchInfo.crossedHcalIds);
91  caloToDetIdMap["ho"] = &(trackDetMatchInfo.crossedHOIds);
92  caloToDetIdMap["es"] = &(trackDetMatchInfo.crossedPreshowerIds);
93 
95  es.get<CaloGeometryRecord>().get(caloGeo);
96 
97  for ( CaloToDetIdMap::const_iterator caloToDetIdEntry = caloToDetIdMap.begin();
98  caloToDetIdEntry != caloToDetIdMap.end(); ++caloToDetIdEntry ) {
99  std::vector<SteppingHelixStateInfo>::const_iterator itHelixState_first, itHelixState_last;
100  if ( caloToDetIdEntry->first == "ecal" ) {
101  itHelixState_first = trackAssociator_.getCachedTrajector().getEcalTrajectory().begin();
102  itHelixState_last = trackAssociator_.getCachedTrajector().getEcalTrajectory().end();
103  } else if ( caloToDetIdEntry->first == "hcal" ) {
104  itHelixState_first = trackAssociator_.getCachedTrajector().getHcalTrajectory().begin();
105  itHelixState_last = trackAssociator_.getCachedTrajector().getHcalTrajectory().end();
106  } else if ( caloToDetIdEntry->first == "ho" ) {
107  itHelixState_first = trackAssociator_.getCachedTrajector().getHOTrajectory().begin();
108  itHelixState_last = trackAssociator_.getCachedTrajector().getHOTrajectory().end();
109  } else if ( caloToDetIdEntry->first == "es" ) {
110  itHelixState_first = trackAssociator_.getCachedTrajector().getPreshowerTrajectory().begin();
111  itHelixState_last = trackAssociator_.getCachedTrajector().getPreshowerTrajectory().end();
112  } else assert(0);
113 
114  // copy trajectory points
115  std::vector<GlobalPoint> trajectory;
116  for ( std::vector<SteppingHelixStateInfo>::const_iterator helixState = itHelixState_first;
117  helixState != itHelixState_last; ++helixState ) {
118  trajectory.push_back(helixState->position());
119  }
120 
121  // iterate over crossed detIds
122  for ( std::vector<DetId>::const_iterator detId = caloToDetIdEntry->second->begin();
123  detId != caloToDetIdEntry->second->end(); ++detId ) {
124  if ( detId->rawId() == 0 ) continue;
125 
126  const CaloSubdetectorGeometry* subDetGeo = caloGeo->getSubdetectorGeometry(*detId);
127  const CaloCellGeometry* caloCellGeo = subDetGeo->getGeometry(*detId);
128  GlobalPoint previousPoint;
129  bool previousPoint_initialized;
130  float distanceWithinDetId = 0;
131  for ( std::vector<GlobalPoint>::const_iterator point = trajectory.begin();
132  point != trajectory.end(); ++point ) {
133  if ( previousPoint_initialized ) {
134  float dx = point->x() - previousPoint.x();
135  float dy = point->y() - previousPoint.y();
136  float dz = point->z() - previousPoint.z();
137  float distanceBetweenPoints = sqrt(dx*dx + dy*dy + dz*dz);
138  int numSteps = 100;
139  int numStepsWithinDetId = 0;
140  for ( int iStep = 0; iStep <= numSteps; ++iStep ){
141  float stepX = previousPoint.x() + iStep*dx/numSteps;
142  float stepY = previousPoint.y() + iStep*dy/numSteps;
143  float stepZ = previousPoint.z() + iStep*dz/numSteps;
144  GlobalPoint stepPoint(stepX, stepY, stepZ);
145  bool isWithinDetId = caloCellGeo->inside(stepPoint);
146  if ( isWithinDetId ) ++numStepsWithinDetId;
147  }
148  distanceWithinDetId += (numStepsWithinDetId/float(numSteps + 1))*distanceBetweenPoints;
149  }
150  previousPoint = (*point);
151  previousPoint_initialized = true;
152  }
153  distanceMap[detId->rawId()] = distanceWithinDetId;
154  }
155  }
156 }
157 
159 
std::vector< DetId > crossedPreshowerIds
T getParameter(std::string const &) const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
std::vector< const HBHERecHit * > crossedHcalRecHits
const std::vector< SteppingHelixStateInfo > & getHOTrajectory() const
const DetId & detid() const
Definition: CaloRecHit.h:20
const std::vector< SteppingHelixStateInfo > & getHcalTrajectory() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< DetId > crossedEcalIds
void useDefaultPropagator()
use the default propagator
T y() const
Definition: PV3DBase.h:63
std::map< uint32_t, float > detIdToFloatMap
TrackDetMatchInfo getTrackDetMatchInfo(const edm::Event &, const edm::EventSetup &, TrackDetectorAssociator &, const TrackAssociatorParameters &, const reco::Candidate *)
const std::vector< SteppingHelixStateInfo > & getPreshowerTrajectory() const
const CachedTrajectory & getCachedTrajector() const
trajector information
std::vector< DetId > crossedHcalIds
std::vector< const EcalRecHit * > crossedEcalRecHits
hits in detector elements crossed by a track
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual void produce(edm::Event &, const edm::EventSetup &)
void fillDistanceMap(edm::Event &, const edm::EventSetup &, const reco::Candidate *, detIdToFloatMap &, detIdToFloatMap &)
const std::vector< SteppingHelixStateInfo > & getEcalTrajectory() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
float energy() const
Definition: CaloRecHit.h:17
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
std::vector< DetId > crossedHOIds
bool inside(const GlobalPoint &point) const
Returns true if the specified point is inside this cell.
const T & get() const
Definition: EventSetup.h:55
tuple muons
Definition: patZpeak.py:38
TrackDetectorAssociator trackAssociator_
std::vector< const HORecHit * > crossedHORecHits
MuonCaloDistanceProducer(const edm::ParameterSet &)
TrackAssociatorParameters trackAssociatorParameters_
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
reco::CandidateBaseRef getTheMuPlus(const std::vector< reco::CandidateBaseRef > &)
T x() const
Definition: PV3DBase.h:62
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
void loadParameters(const edm::ParameterSet &)