CMS 3D CMS Logo

HSCPDeDxInfoProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HSCPDeDxInfoProducer
4 // Class: HSCPDeDxInfoProducer
5 //
13 //
14 // Original Author: andrea
15 // Created: Thu May 31 14:09:02 CEST 2007
16 // Code Updates: loic Quertenmont (querten)
17 // Created: Thu May 10 14:09:02 CEST 2008
18 //
19 //
20 
22 
23 // system include files
24 
25 using namespace reco;
26 using namespace std;
27 using namespace edm;
28 
30  produces<ValueMap<susybsm::HSCPDeDxInfo> >();
31 
32  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips", 255);
33  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits", 4);
34  MinTrackMomentum = iConfig.getUntrackedParameter<double>("minTrackMomentum", 0.0);
35  MaxTrackMomentum = iConfig.getUntrackedParameter<double>("maxTrackMomentum", 99999.0);
36  MinTrackEta = iConfig.getUntrackedParameter<double>("minTrackEta", -5.0);
37  MaxTrackEta = iConfig.getUntrackedParameter<double>("maxTrackEta", 5.0);
38 
39  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
40  m_trajTrackAssociationTag =
41  consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation"));
42  useTrajectory = iConfig.getUntrackedParameter<bool>("UseTrajectory", true);
43 
44  usePixel = iConfig.getParameter<bool>("UsePixel");
45  useStrip = iConfig.getParameter<bool>("UseStrip");
46  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
47  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
48 
49  shapetest = iConfig.getParameter<bool>("ShapeTest");
50  useCalibration = iConfig.getParameter<bool>("UseCalibration");
51  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
52 
53  // Reccord = iConfig.getUntrackedParameter<std::string> ("Reccord" , "SiStripDeDxMip_3D_Rcd");
54  // ProbabilityMode = iConfig.getUntrackedParameter<std::string> ("ProbabilityMode" , "Accumulation");
55  // Prob_ChargePath = NULL;
56 
57  if (!usePixel && !useStrip)
58  edm::LogWarning("DeDxHitsProducer")
59  << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
60 }
61 
63 
64 // ------------ method called once each job just before starting event loop ------------
66  if (useCalibration && calibGains.empty()) {
68  iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom);
69  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
70 
71  DeDxTools::makeCalibrationMap(m_calibrationPath, *tkGeom, calibGains, m_off);
72  }
73 
74  // DeDxTools::buildDiscrimMap(run, iSetup, Reccord, ProbabilityMode, Prob_ChargePath);
75 }
76 
78  unique_ptr<ValueMap<susybsm::HSCPDeDxInfo> > trackDeDxAssociation(new ValueMap<susybsm::HSCPDeDxInfo>);
79  ValueMap<susybsm::HSCPDeDxInfo>::Filler filler(*trackDeDxAssociation);
80 
81  edm::Handle<reco::TrackCollection> trackCollectionHandle;
82  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
83 
84  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
85  if (useTrajectory)
86  iEvent.getByToken(m_trajTrackAssociationTag, trajTrackAssociationHandle);
87 
88  std::vector<susybsm::HSCPDeDxInfo> dEdxInfos(trackCollectionHandle->size());
89 
91  if (useTrajectory)
92  cit = trajTrackAssociationHandle->begin();
93  for (unsigned int j = 0; j < trackCollectionHandle->size(); j++) {
94  const reco::TrackRef track = reco::TrackRef(trackCollectionHandle.product(), j);
95 
96  susybsm::HSCPDeDxInfo hscpDeDxInfo;
97 
98  if (useTrajectory) { //trajectory allows to take into account the local direction of the particle on the module sensor --> muc much better 'dx' measurement
99  const edm::Ref<std::vector<Trajectory> > traj = cit->key;
100  cit++;
101  const vector<TrajectoryMeasurement>& measurements = traj->measurements();
102  for (vector<TrajectoryMeasurement>::const_iterator it = measurements.begin(); it != measurements.end(); it++) {
103  TrajectoryStateOnSurface trajState = it->updatedState();
104  if (!trajState.isValid())
105  continue;
106 
107  const TrackingRecHit* recHit = (*it->recHit()).hit();
108  if (!recHit)
109  continue;
110  LocalVector trackDirection = trajState.localDirection();
111  float cosine = trackDirection.z() / trackDirection.mag();
112 
113  processHit(recHit, trajState.localMomentum().mag(), cosine, hscpDeDxInfo, trajState.localPosition());
114  }
115 
116  } else { //assume that the particles trajectory is a straight line originating from the center of the detector (can be improved)
117  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
118  const TrackingRecHit* recHit = &(*(track->recHit(h)));
119  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
120  if (!thit.isValid())
121  continue; //make sure it's a tracker hit
122 
123  const GlobalVector& ModuleNormal = recHit->detUnit()->surface().normalVector();
124  float cosine =
125  (track->px() * ModuleNormal.x() + track->py() * ModuleNormal.y() + track->pz() * ModuleNormal.z()) /
126  track->p();
127 
128  processHit(recHit, track->p(), cosine, hscpDeDxInfo, LocalPoint(0.0, 0.0));
129  }
130  }
131 
132  dEdxInfos[j] = hscpDeDxInfo;
133  }
135 
136  filler.insert(trackCollectionHandle, dEdxInfos.begin(), dEdxInfos.end());
137  filler.fill();
138  iEvent.put(std::move(trackDeDxAssociation));
139 }
140 
142  float trackMomentum,
143  float& cosine,
144  susybsm::HSCPDeDxInfo& hscpDeDxInfo,
145  LocalPoint HitLocalPos) {
146  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
147  if (!thit.isValid())
148  return;
149 
150  auto const& clus = thit.firstClusterRef();
151  if (!clus.isValid())
152  return;
153 
154  if (clus.isPixel()) {
155  if (!usePixel)
156  return;
157 
158  auto& detUnit = *(recHit->detUnit());
159  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
160  float chargeAbs = clus.pixelCluster().charge();
161  hscpDeDxInfo.charges.push_back(chargeAbs);
162  hscpDeDxInfo.pathlengths.push_back(pathLen);
163  hscpDeDxInfo.detIds.push_back(thit.geographicalId());
164  hscpDeDxInfo.localPosXs.push_back(HitLocalPos.x());
165  hscpDeDxInfo.localPosYs.push_back(HitLocalPos.y());
166  hscpDeDxInfo.clusterIndices.push_back(clus.key());
167  } else if (clus.isStrip() && !thit.isMatched()) {
168  if (!useStrip)
169  return;
170 
171  auto& detUnit = *(recHit->detUnit());
172  int NSaturating = 0;
173  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
174  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()), NSaturating, detUnit, calibGains, m_off);
175  hscpDeDxInfo.charges.push_back(chargeAbs);
176  hscpDeDxInfo.pathlengths.push_back(pathLen);
177  hscpDeDxInfo.detIds.push_back(thit.geographicalId());
178  hscpDeDxInfo.localPosXs.push_back(HitLocalPos.x());
179  hscpDeDxInfo.localPosYs.push_back(HitLocalPos.y());
180  hscpDeDxInfo.clusterIndices.push_back(clus.key());
181  } else if (clus.isStrip() && thit.isMatched()) {
182  if (!useStrip)
183  return;
184  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
185  if (!matchedHit)
186  return;
187 
188  auto& detUnitM = *(matchedHit->monoHit().detUnit());
189  int NSaturating = 0;
190  float pathLen = detUnitM.surface().bounds().thickness() / fabs(cosine);
191  float chargeAbs =
192  DeDxTools::getCharge(&(matchedHit->monoHit().stripCluster()), NSaturating, detUnitM, calibGains, m_off);
193  hscpDeDxInfo.charges.push_back(chargeAbs);
194  hscpDeDxInfo.pathlengths.push_back(pathLen);
195  hscpDeDxInfo.detIds.push_back(thit.geographicalId());
196  hscpDeDxInfo.localPosXs.push_back(HitLocalPos.x());
197  hscpDeDxInfo.localPosYs.push_back(HitLocalPos.y());
198  const OmniClusterRef monoClusterRef = matchedHit->monoClusterRef();
199  hscpDeDxInfo.clusterIndices.push_back(monoClusterRef.key());
200 
201  auto& detUnitS = *(matchedHit->stereoHit().detUnit());
202  NSaturating = 0;
203  pathLen = detUnitS.surface().bounds().thickness() / fabs(cosine);
204  chargeAbs =
205  DeDxTools::getCharge(&(matchedHit->stereoHit().stripCluster()), NSaturating, detUnitS, calibGains, m_off);
206  hscpDeDxInfo.charges.push_back(chargeAbs);
207  hscpDeDxInfo.pathlengths.push_back(pathLen);
208  hscpDeDxInfo.detIds.push_back(thit.geographicalId());
209  hscpDeDxInfo.localPosXs.push_back(HitLocalPos.x());
210  hscpDeDxInfo.localPosYs.push_back(HitLocalPos.y());
211  const OmniClusterRef stereoClusterRef = matchedHit->stereoClusterRef();
212  hscpDeDxInfo.clusterIndices.push_back(stereoClusterRef.key());
213  }
214 }
215 
216 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float > > &calibGains, const unsigned int &m_off)
Definition: DeDxTools.cc:214
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
LocalVector localDirection() const
OmniClusterRef const & stereoClusterRef() const
GlobalVector normalVector() const
Definition: Plane.h:41
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
T y() const
Definition: PV3DBase.h:60
const Bounds & bounds() const
Definition: Surface.h:89
std::vector< float > localPosYs
Definition: HSCPDeDxInfo.h:19
key_type key() const
Accessor for product key.
Definition: Ref.h:250
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void makeCalibrationMap(const std::string &m_calibrationPath, const TrackerGeometry &tkGeom, std::vector< std::vector< float > > &calibGains, const unsigned int &m_off)
Definition: DeDxTools.cc:252
std::vector< float > pathlengths
Definition: HSCPDeDxInfo.h:16
LocalVector localMomentum() const
HSCPDeDxInfoProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T mag() const
Definition: PV3DBase.h:64
unsigned int offsetDU(SubDetector sid) const
T z() const
Definition: PV3DBase.h:61
void produce(edm::Event &, const edm::EventSetup &) override
OmniClusterRef const & monoClusterRef() const
std::vector< uint32_t > detIds
Definition: HSCPDeDxInfo.h:17
std::vector< float > charges
Definition: HSCPDeDxInfo.h:15
SiStripRecHit2D stereoHit() const
T const * product() const
Definition: Handle.h:69
virtual float thickness() const =0
SiStripCluster const & stripCluster() const
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
const GeomDetUnit * detUnit() const override
const Surface * surface() const final
SiStripRecHit2D monoHit() const
fixed size matrix
HLT enums.
virtual const GeomDetUnit * detUnit() const
T get() const
Definition: EventSetup.h:73
std::vector< uint32_t > clusterIndices
Definition: HSCPDeDxInfo.h:20
const_iterator begin() const
first iterator over the map (read only)
std::vector< float > localPosXs
Definition: HSCPDeDxInfo.h:18
T x() const
Definition: PV3DBase.h:59
unsigned int key() const
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
void beginRun(edm::Run const &run, const edm::EventSetup &) override
void processHit(const TrackingRecHit *recHit, float trackMomentum, float &cosine, susybsm::HSCPDeDxInfo &hscpDeDxInfo, LocalPoint HitLocalPos)