CMS 3D CMS Logo

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  usePixel ( iConfig.getParameter<bool> ("usePixel") ),
29  useStrip ( iConfig.getParameter<bool> ("useStrip") ),
30  MeVperADCPixel ( iConfig.getParameter<double> ("MeVperADCPixel") ),
31  MeVperADCStrip ( iConfig.getParameter<double> ("MeVperADCStrip") ),
32  minTrackHits ( iConfig.getParameter<unsigned>("minTrackHits") ),
33  minTrackPt ( iConfig.getParameter<double> ("minTrackPt" ) ),
34  maxTrackEta ( iConfig.getParameter<double> ("maxTrackEta" ) ),
35  m_calibrationPath ( iConfig.getParameter<string> ("calibrationPath")),
36  useCalibration ( iConfig.getParameter<bool> ("useCalibration") ),
37  shapetest ( iConfig.getParameter<bool> ("shapeTest") )
38 {
39  produces<reco::DeDxHitInfoCollection >();
40  produces<reco::DeDxHitInfoAss >();
41 
42  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
43 
44  if(!usePixel && !useStrip)
45  edm::LogError("DeDxHitsProducer") << "No Pixel Hits NOR Strip Hits will be saved. Running this module is useless";
46 }
47 
48 
50 
51 // ------------ method called once each job just before starting event loop ------------
53 {
54  if(useCalibration && calibGains.size()==0){
56  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
57  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
58 
60  }
61 }
62 
63 
64 
66 {
67  edm::Handle<reco::TrackCollection> trackCollectionHandle;
68  iEvent.getByToken(m_tracksTag,trackCollectionHandle);
69  const TrackCollection& trackCollection(*trackCollectionHandle.product());
70 
71  // creates the output collection
72  auto resultdedxHitColl = std::make_unique<reco::DeDxHitInfoCollection>();
73 
74  std::vector<int> indices;
75 
76  for(unsigned int j=0;j<trackCollection.size();j++){
77  const reco::Track& track = trackCollection[j];
78 
79  //track selection
80  if(track.pt()<minTrackPt || std::abs(track.eta())>maxTrackEta ||track.numberOfValidHits()<minTrackHits){
81  indices.push_back(-1);
82  continue;
83  }
84 
85  reco::DeDxHitInfo hitDeDxInfo;
86  auto const & trajParams = track.extra()->trajParams();
87  auto hb = track.recHitsBegin();
88  for(unsigned int h=0;h<track.recHitsSize();h++){
89  auto recHit = *(hb+h);
90  if(!recHit->isValid()) continue;
91 
92  auto trackDirection = trajParams[h].direction();
93  float cosine = trackDirection.z()/trackDirection.mag();
94 
95  processHit(recHit, track.p(), cosine, hitDeDxInfo, trajParams[h].position());
96  }
97 
98  indices.push_back(resultdedxHitColl->size());
99  resultdedxHitColl->push_back(hitDeDxInfo);
100  }
102 
103 
104  edm::OrphanHandle<reco::DeDxHitInfoCollection> dedxHitCollHandle = iEvent.put(std::move(resultdedxHitColl));
105 
106  //create map passing the handle to the matched collection
107  auto dedxMatch = std::make_unique<reco::DeDxHitInfoAss>(dedxHitCollHandle);
109  filler.insert(trackCollectionHandle, indices.begin(), indices.end());
110  filler.fill();
111  iEvent.put(std::move(dedxMatch));
112 }
113 
114 void DeDxHitInfoProducer::processHit(const TrackingRecHit* recHit, const float trackMomentum, const float cosine, reco::DeDxHitInfo& hitDeDxInfo, const LocalPoint& hitLocalPos){
115  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
116  if(!thit.isValid())return;
117 
118  float cosineAbs = std::max(0.00000001f,std::abs(cosine));//make sure cosine is not 0
119 
120  auto const & clus = thit.firstClusterRef();
121  if(!clus.isValid())return;
122 
123  if(clus.isPixel()){
124  if(!usePixel) return;
125 
126  auto& detUnit = *(recHit->detUnit());
127  float pathLen = detUnit.surface().bounds().thickness()/cosineAbs;
128  float chargeAbs = clus.pixelCluster().charge();
129  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.pixelCluster() );
130  }else if(clus.isStrip() && !thit.isMatched()){
131  if(!useStrip) return;
132 
133  auto& detUnit = *(recHit->detUnit());
134  int NSaturating = 0;
135  float pathLen = detUnit.surface().bounds().thickness()/cosineAbs;
136  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, detUnit, calibGains, m_off);
137  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.stripCluster() );
138  }else if(clus.isStrip() && thit.isMatched()){
139  if(!useStrip) return;
140  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
141  if(!matchedHit)return;
142 
143  auto& detUnitM = *(matchedHit->monoHit().detUnit());
144  int NSaturating = 0;
145  float pathLen = detUnitM.surface().bounds().thickness()/cosineAbs;
146  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoHit().stripCluster()),NSaturating, detUnitM, calibGains, m_off);
147  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->monoHit().stripCluster() );
148 
149  auto& detUnitS = *(matchedHit->stereoHit().detUnit());
150  NSaturating = 0;
151  pathLen = detUnitS.surface().bounds().thickness()/cosineAbs;
152  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoHit().stripCluster()),NSaturating, detUnitS, calibGains, m_off);
153  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->stereoHit().stripCluster() );
154  }
155 }
156 
157 
158 
159 //define this as a plug-in
double p() const
momentum vector magnitude
Definition: TrackBase.h:610
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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.
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:189
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#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
std::vector< std::vector< float > > calibGains
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const Bounds & bounds() const
Definition: Surface.h:120
virtual void produce(edm::Event &, const edm::EventSetup &) override
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
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
DeDxHitInfoProducer(const edm::ParameterSet &)
void processHit(const TrackingRecHit *recHit, const float trackMomentum, const float cosine, reco::DeDxHitInfo &hitDeDxInfo, const LocalPoint &hitLocalPos)
const std::string m_calibrationPath
unsigned int offsetDU(SubDetector sid) const
double pt() const
track transverse momentum
Definition: TrackBase.h:616
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
void addHit(const float charge, const float pathlength, const DetId &detId, const LocalPoint &pos, const SiStripCluster &stripCluster)
Definition: DeDxHitInfo.h:83
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:815
const unsigned int minTrackHits
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
const GeomDetUnit * detUnit() const
SiStripRecHit2D stereoHit() const
T const * product() const
Definition: Handle.h:81
virtual float thickness() const =0
SiStripCluster const & stripCluster() const
const T & get() const
Definition: EventSetup.h:56
SiStripRecHit2D monoHit() const
fixed size matrix
HLT enums.
virtual const GeomDetUnit * detUnit() const
virtual void beginRun(edm::Run const &run, const edm::EventSetup &) override
virtual const Surface * surface() const final
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42