CMS 3D CMS Logo

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