CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeDxHitInfoProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxHitInfoProducer
4 // Class: DeDxHitInfoProducer
5 //
13 //
14 // Original Author: loic Quertenmont (querten)
15 // Created: Mon Nov 21 14:09:02 CEST 2014
16 //
17 
19 
20 // system include files
21 
22 
23 using namespace reco;
24 using namespace std;
25 using namespace edm;
26 
28  useTrajectory ( iConfig.getParameter<bool> ("useTrajectory") ),
29  usePixel ( iConfig.getParameter<bool> ("usePixel") ),
30  useStrip ( iConfig.getParameter<bool> ("useStrip") ),
31  MeVperADCPixel ( iConfig.getParameter<double> ("MeVperADCPixel") ),
32  MeVperADCStrip ( iConfig.getParameter<double> ("MeVperADCStrip") ),
33  minTrackHits ( iConfig.getParameter<unsigned>("minTrackHits") ),
34  minTrackPt ( iConfig.getParameter<double> ("minTrackPt" ) ),
35  maxTrackEta ( iConfig.getParameter<double> ("maxTrackEta" ) ),
36  m_calibrationPath ( iConfig.getParameter<string> ("calibrationPath")),
37  useCalibration ( iConfig.getParameter<bool> ("useCalibration") ),
38  shapetest ( iConfig.getParameter<bool> ("shapeTest") )
39 {
40  produces<reco::DeDxHitInfoCollection >();
41  produces<reco::DeDxHitInfoAss >();
42 
43  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
44  m_trajTrackAssociationTag = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation"));
45 
46  if(!usePixel && !useStrip)
47  edm::LogError("DeDxHitsProducer") << "No Pixel Hits NOR Strip Hits will be saved. Running this module is useless";
48 }
49 
50 
52 
53 // ------------ method called once each job just before starting event loop ------------
55 {
56  if(useCalibration && calibGains.size()==0){
58  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
59  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
60 
62  }
63 }
64 
65 
66 
68 {
69  edm::Handle<reco::TrackCollection> trackCollectionHandle;
70  iEvent.getByToken(m_tracksTag,trackCollectionHandle);
71  const TrackCollection& trackCollection(*trackCollectionHandle.product());
72 
73  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
74  if(useTrajectory)iEvent.getByToken(m_trajTrackAssociationTag, trajTrackAssociationHandle);
75 
76  // creates the output collection
77  std::auto_ptr<reco::DeDxHitInfoCollection> resultdedxHitColl(new reco::DeDxHitInfoCollection);
78 
79  std::vector<int> indices;
80 
82  if(useTrajectory)cit = trajTrackAssociationHandle->begin();
83  for(unsigned int j=0;j<trackCollection.size();j++){
84  const reco::Track& track = trackCollection[j];
85 
86  //track selection
87  if(track.pt()<minTrackPt || std::abs(track.eta())>maxTrackEta ||track.numberOfValidHits()<minTrackHits){
88  cit++;
89  indices.push_back(-1);
90  continue;
91  }
92 
93  reco::DeDxHitInfo hitDeDxInfo;
94 
95  if(useTrajectory){ //trajectory allows to take into account the local direction of the particle on the module sensor --> muc much better 'dx' measurement
96  const edm::Ref<std::vector<Trajectory> > traj = cit->key; cit++;
97  const vector<TrajectoryMeasurement> & measurements = traj->measurements();
98  for(vector<TrajectoryMeasurement>::const_iterator it = measurements.begin(); it!=measurements.end(); it++){
99  const TrajectoryStateOnSurface& trajState=it->updatedState();
100  if( !trajState.isValid()) continue;
101 
102  const TrackingRecHit* recHit=(*it->recHit()).hit();
103  if(!recHit)continue;
104  const LocalVector& trackDirection = trajState.localDirection();
105  float cosine = trackDirection.z()/trackDirection.mag();
106 
107  processHit(recHit, trajState.localMomentum().mag(), cosine, hitDeDxInfo, trajState.localPosition());
108  }
109 
110  }else{ //assume that the particles trajectory is a straight line originating from the center of the detector (can be improved)
111  for(unsigned int h=0;h<track.recHitsSize();h++){
112  const TrackingRecHit* recHit = &(*(track.recHit(h)));
113  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
114  if(!thit.isValid())continue;//make sure it's a tracker hit
115 
116  const GlobalVector& ModuleNormal = recHit->detUnit()->surface().normalVector();
117  float cosine = (track.px()*ModuleNormal.x()+track.py()*ModuleNormal.y()+track.pz()*ModuleNormal.z())/track.p();
118 
119  processHit(recHit, track.p(), cosine, hitDeDxInfo, LocalPoint(0.0,0.0));
120  }
121  }
122 
123  indices.push_back(resultdedxHitColl->size());
124  resultdedxHitColl->push_back(hitDeDxInfo);
125  }
127 
128 
129  edm::OrphanHandle<reco::DeDxHitInfoCollection> dedxHitCollHandle = iEvent.put(resultdedxHitColl);
130 
131  //create map passing the handle to the matched collection
132  std::auto_ptr<reco::DeDxHitInfoAss> dedxMatch(new reco::DeDxHitInfoAss(dedxHitCollHandle));
133  reco::DeDxHitInfoAss::Filler filler(*dedxMatch);
134  filler.insert(trackCollectionHandle, indices.begin(), indices.end());
135  filler.fill();
136  iEvent.put(dedxMatch);
137 }
138 
139 void DeDxHitInfoProducer::processHit(const TrackingRecHit* recHit, const float trackMomentum, const float cosine, reco::DeDxHitInfo& hitDeDxInfo, const LocalPoint& hitLocalPos){
140  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
141  if(!thit.isValid())return;
142 
143  float cosineAbs = std::max(0.00000001f,std::abs(cosine));//make sure cosine is not 0
144 
145  auto const & clus = thit.firstClusterRef();
146  if(!clus.isValid())return;
147 
148  if(clus.isPixel()){
149  if(!usePixel) return;
150 
151  auto& detUnit = *(recHit->detUnit());
152  float pathLen = detUnit.surface().bounds().thickness()/cosineAbs;
153  float chargeAbs = clus.pixelCluster().charge();
154  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.pixelCluster() );
155  }else if(clus.isStrip() && !thit.isMatched()){
156  if(!useStrip) return;
157 
158  auto& detUnit = *(recHit->detUnit());
159  int NSaturating = 0;
160  float pathLen = detUnit.surface().bounds().thickness()/cosineAbs;
161  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, detUnit, calibGains, m_off);
162  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.stripCluster() );
163  }else if(clus.isStrip() && thit.isMatched()){
164  if(!useStrip) return;
165  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
166  if(!matchedHit)return;
167 
168  auto& detUnitM = *(matchedHit->monoHit().detUnit());
169  int NSaturating = 0;
170  float pathLen = detUnitM.surface().bounds().thickness()/cosineAbs;
171  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoHit().stripCluster()),NSaturating, detUnitM, calibGains, m_off);
172  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->monoHit().stripCluster() );
173 
174  auto& detUnitS = *(matchedHit->stereoHit().detUnit());
175  NSaturating = 0;
176  pathLen = detUnitS.surface().bounds().thickness()/cosineAbs;
177  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoHit().stripCluster()),NSaturating, detUnitS, calibGains, m_off);
178  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->stereoHit().stripCluster() );
179  }
180 }
181 
182 
183 
184 //define this as a plug-in
double p() const
momentum vector magnitude
Definition: TrackBase.h:602
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
LocalVector localDirection() const
std::vector< std::vector< float > > calibGains
GlobalVector normalVector() const
Definition: Plane.h:45
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
T y() const
Definition: PV3DBase.h:63
const Bounds & bounds() const
Definition: Surface.h:128
virtual void produce(edm::Event &, const edm::EventSetup &) override
key_type key() const
Accessor for product key.
Definition: Ref.h:264
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:614
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
LocalVector localMomentum() const
virtual float thickness() const =0
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:638
DeDxHitInfoProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
tuple minTrackPt
Definition: align_cfg.py:22
void processHit(const TrackingRecHit *recHit, const float trackMomentum, const float cosine, reco::DeDxHitInfo &hitDeDxInfo, const LocalPoint &hitLocalPos)
const std::string m_calibrationPath
double pt() const
track transverse momentum
Definition: TrackBase.h:608
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
double f[11][100]
void addHit(const float charge, const float pathlength, const DetId &detId, const LocalPoint &pos, const SiStripCluster &stripCluster)
Definition: DeDxHitInfo.h:82
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:807
const unsigned int minTrackHits
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:626
edm::EDGetTokenT< TrajTrackAssociationCollection > m_trajTrackAssociationTag
const GeomDetUnit * detUnit() const
std::vector< DeDxHitInfo > DeDxHitInfoCollection
Definition: DeDxHitInfo.h:97
SiStripRecHit2D stereoHit() const
T const * product() const
Definition: Handle.h:81
SiStripCluster const & stripCluster() const
const T & get() const
Definition: EventSetup.h:56
string const
Definition: compareJSON.py:14
SiStripRecHit2D monoHit() const
virtual const GeomDetUnit * detUnit() const
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:114
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
virtual void beginRun(edm::Run const &run, const edm::EventSetup &) override
T x() const
Definition: PV3DBase.h:62
virtual const Surface * surface() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:620
Definition: Run.h:43