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");
36  trackAssociatorParameters_.loadParameters(cfgTrackAssociator, iC);
38 }
39 
41 {
42 // nothing to be done yet...
43 }
44 
46 {
47  std::auto_ptr<detIdToFloatMap> distanceMuPlus(new detIdToFloatMap());
48  std::auto_ptr<detIdToFloatMap> distanceMuMinus(new detIdToFloatMap());
49  std::auto_ptr<detIdToFloatMap> depositMuPlus(new detIdToFloatMap());
50  std::auto_ptr<detIdToFloatMap> depositMuMinus(new detIdToFloatMap());
51 
52  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons_);
53  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
54  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
55 
56  if ( muPlus.isNonnull() ) fillDistanceMap(evt, es, &(*muPlus), *distanceMuPlus, *depositMuPlus);
57  if ( muMinus.isNonnull() ) fillDistanceMap(evt, es, &(*muMinus), *distanceMuMinus, *depositMuMinus);
58 
59  std::auto_ptr<reco::CandidateCollection> muons(new reco::CandidateCollection);
60  if ( muPlus.isNonnull() ) muons->push_back(new reco::ShallowCloneCandidate(muPlus));
61  if ( muMinus.isNonnull() ) muons->push_back(new reco::ShallowCloneCandidate(muMinus));
62 
63  // References to the muons themselves
64  evt.put(muons, "muons");
65 
66  // maps of detId to distance traversed by muon through calorimeter cell
67  evt.put(distanceMuPlus, "distancesMuPlus");
68  evt.put(distanceMuMinus, "distancesMuMinus");
69 
70  // maps of detId to energy deposited in calorimeter cell
71  evt.put(depositMuPlus, "depositsMuPlus");
72  evt.put(depositMuMinus, "depositsMuMinus");
73 }
74 
76 {
78 
79  BOOST_FOREACH(const EcalRecHit * rh, trackDetMatchInfo.crossedEcalRecHits)
80  depositMap[rh->detid().rawId()]+=rh->energy();
81 
82  BOOST_FOREACH(const HBHERecHit * rh, trackDetMatchInfo.crossedHcalRecHits)
83  depositMap[rh->detid().rawId()]+=rh->energy();
84 
85  BOOST_FOREACH(const HORecHit * rh, trackDetMatchInfo.crossedHORecHits)
86  depositMap[rh->detid().rawId()]+=rh->energy();
87 
88  typedef std::map<std::string, const std::vector<DetId>*> CaloToDetIdMap;
89  CaloToDetIdMap caloToDetIdMap;
90  caloToDetIdMap["ecal"] = &(trackDetMatchInfo.crossedEcalIds);
91  caloToDetIdMap["hcal"] = &(trackDetMatchInfo.crossedHcalIds);
92  caloToDetIdMap["ho"] = &(trackDetMatchInfo.crossedHOIds);
93  caloToDetIdMap["es"] = &(trackDetMatchInfo.crossedPreshowerIds);
94 
96  es.get<CaloGeometryRecord>().get(caloGeo);
97 
98  for ( CaloToDetIdMap::const_iterator caloToDetIdEntry = caloToDetIdMap.begin();
99  caloToDetIdEntry != caloToDetIdMap.end(); ++caloToDetIdEntry ) {
100  std::vector<SteppingHelixStateInfo>::const_iterator itHelixState_first, itHelixState_last;
101  if ( caloToDetIdEntry->first == "ecal" ) {
102  itHelixState_first = trackAssociator_.getCachedTrajector().getEcalTrajectory().begin();
103  itHelixState_last = trackAssociator_.getCachedTrajector().getEcalTrajectory().end();
104  } else if ( caloToDetIdEntry->first == "hcal" ) {
105  itHelixState_first = trackAssociator_.getCachedTrajector().getHcalTrajectory().begin();
106  itHelixState_last = trackAssociator_.getCachedTrajector().getHcalTrajectory().end();
107  } else if ( caloToDetIdEntry->first == "ho" ) {
108  itHelixState_first = trackAssociator_.getCachedTrajector().getHOTrajectory().begin();
109  itHelixState_last = trackAssociator_.getCachedTrajector().getHOTrajectory().end();
110  } else if ( caloToDetIdEntry->first == "es" ) {
111  itHelixState_first = trackAssociator_.getCachedTrajector().getPreshowerTrajectory().begin();
112  itHelixState_last = trackAssociator_.getCachedTrajector().getPreshowerTrajectory().end();
113  } else assert(0);
114 
115  // copy trajectory points
116  std::vector<GlobalPoint> trajectory;
117  for ( std::vector<SteppingHelixStateInfo>::const_iterator helixState = itHelixState_first;
118  helixState != itHelixState_last; ++helixState ) {
119  trajectory.push_back(helixState->position());
120  }
121 
122  // iterate over crossed detIds
123  for ( std::vector<DetId>::const_iterator detId = caloToDetIdEntry->second->begin();
124  detId != caloToDetIdEntry->second->end(); ++detId ) {
125  if ( detId->rawId() == 0 ) continue;
126 
127  const CaloSubdetectorGeometry* subDetGeo = caloGeo->getSubdetectorGeometry(*detId);
128  const CaloCellGeometry* caloCellGeo = subDetGeo->getGeometry(*detId);
129  GlobalPoint previousPoint;
130  bool previousPoint_initialized;
131  float distanceWithinDetId = 0;
132  for ( std::vector<GlobalPoint>::const_iterator point = trajectory.begin();
133  point != trajectory.end(); ++point ) {
134  if ( previousPoint_initialized ) {
135  float dx = point->x() - previousPoint.x();
136  float dy = point->y() - previousPoint.y();
137  float dz = point->z() - previousPoint.z();
138  float distanceBetweenPoints = sqrt(dx*dx + dy*dy + dz*dz);
139  int numSteps = 100;
140  int numStepsWithinDetId = 0;
141  for ( int iStep = 0; iStep <= numSteps; ++iStep ){
142  float stepX = previousPoint.x() + iStep*dx/numSteps;
143  float stepY = previousPoint.y() + iStep*dy/numSteps;
144  float stepZ = previousPoint.z() + iStep*dz/numSteps;
145  GlobalPoint stepPoint(stepX, stepY, stepZ);
146  bool isWithinDetId = caloCellGeo->inside(stepPoint);
147  if ( isWithinDetId ) ++numStepsWithinDetId;
148  }
149  distanceWithinDetId += (numStepsWithinDetId/float(numSteps + 1))*distanceBetweenPoints;
150  }
151  previousPoint = (*point);
152  previousPoint_initialized = true;
153  }
154  distanceMap[detId->rawId()] = distanceWithinDetId;
155  }
156  }
157 }
158 
160 
std::vector< DetId > crossedPreshowerIds
T getParameter(std::string const &) const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
tuple cfg
Definition: looper.py:259
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
assert(m_qm.get())
void useDefaultPropagator()
use the default propagator
const DetId & detid() const
Definition: EcalRecHit.h:71
T y() const
Definition: PV3DBase.h:63
std::map< uint32_t, float > detIdToFloatMap
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
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:113
float energy() const
Definition: CaloRecHit.h:17
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
std::vector< DetId > crossedHOIds
float energy() const
Definition: EcalRecHit.h:68
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
*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