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  minTrackPtPrescale( iConfig.getParameter<double> ("minTrackPtPrescale") ),
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  lowPtTracksPrescalePass( iConfig.getParameter<uint32_t>("lowPtTracksPrescalePass") ),
40  lowPtTracksPrescaleFail( iConfig.getParameter<uint32_t>("lowPtTracksPrescaleFail") ),
41  lowPtTracksEstimator(iConfig.getParameter<edm::ParameterSet>("lowPtTracksEstimatorParameters")),
42  lowPtTracksDeDxThreshold(iConfig.getParameter<double>("lowPtTracksDeDxThreshold"))
43 {
44  produces<reco::DeDxHitInfoCollection >();
45  produces<reco::DeDxHitInfoAss >();
46  produces<edm::ValueMap<int> >("prescale");
47 
48  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
49 
50  if(!usePixel && !useStrip)
51  edm::LogError("DeDxHitsProducer") << "No Pixel Hits NOR Strip Hits will be saved. Running this module is useless";
52 }
53 
54 
56 
57 // ------------ method called once each job just before starting event loop ------------
59 {
60  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
61  if(useCalibration && calibGains.empty()){
62  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
63 
65  }
66 }
67 
68 
69 
71 {
72  edm::Handle<reco::TrackCollection> trackCollectionHandle;
73  iEvent.getByToken(m_tracksTag,trackCollectionHandle);
74  const TrackCollection& trackCollection(*trackCollectionHandle.product());
75 
76  // creates the output collection
77  auto resultdedxHitColl = std::make_unique<reco::DeDxHitInfoCollection>();
78 
79  std::vector<int> indices; std::vector<int> prescales;
80  uint64_t state[2] = { iEvent.id().event(), iEvent.id().luminosityBlock() };
81  for(unsigned int j=0;j<trackCollection.size();j++){
82  const reco::Track& track = trackCollection[j];
83 
84  //track selection
85  bool passPt = (track.pt() >= minTrackPt), passLowDeDx = false, passHighDeDx = false, pass = passPt;
86  if (!pass && (track.pt() >= minTrackPtPrescale)) {
87  if (lowPtTracksPrescalePass > 0) {
88  passHighDeDx = ((xorshift128p(state) % lowPtTracksPrescalePass) == 0);
89  }
90  if (lowPtTracksPrescaleFail > 0) {
91  passLowDeDx = ((xorshift128p(state) % lowPtTracksPrescaleFail) == 0);
92  }
93  pass = passHighDeDx || passLowDeDx;
94  }
95  if(!pass || std::abs(track.eta())>maxTrackEta ||track.numberOfValidHits()<minTrackHits){
96  indices.push_back(-1);
97  continue;
98  }
99 
100  reco::DeDxHitInfo hitDeDxInfo;
101  auto const & trajParams = track.extra()->trajParams();
102  auto hb = track.recHitsBegin();
103  for(unsigned int h=0;h<track.recHitsSize();h++){
104  auto recHit = *(hb+h);
105  if(!recHit->isValid()) continue;
106 
107  auto trackDirection = trajParams[h].direction();
108  float cosine = trackDirection.z()/trackDirection.mag();
109 
110  processHit(recHit, track.p(), cosine, hitDeDxInfo, trajParams[h].position());
111  }
112 
113  if (!passPt) {
114  std::vector<DeDxHit> hits; hits.reserve(hitDeDxInfo.size());
115  for (unsigned int i = 0, n = hitDeDxInfo.size(); i < n; ++i) {
116  if (hitDeDxInfo.detId(i).subdetId() <= 2) {
117  hits.push_back( DeDxHit(hitDeDxInfo.charge(i)/hitDeDxInfo.pathlength(i) * MeVperADCPixel, 0,0,0) );
118  } else {
119  if (shapetest && !DeDxTools::shapeSelection(*hitDeDxInfo.stripCluster(i))) continue;
120  hits.push_back( DeDxHit(hitDeDxInfo.charge(i)/hitDeDxInfo.pathlength(i) * MeVperADCStrip, 0,0,0) );
121  }
122  }
123  std::sort(hits.begin(), hits.end(), std::less<DeDxHit>());
125  if (passLowDeDx) {
126  prescales.push_back(lowPtTracksPrescaleFail);
127  } else {
128  indices.push_back(-1);
129  continue;
130  }
131  } else {
132  if (passHighDeDx) {
133  prescales.push_back(lowPtTracksPrescalePass);
134  } else {
135  indices.push_back(-1);
136  continue;
137  }
138 
139  }
140  } else {
141  prescales.push_back(1);
142  }
143  indices.push_back(resultdedxHitColl->size());
144  resultdedxHitColl->push_back(hitDeDxInfo);
145  }
147 
148 
149  edm::OrphanHandle<reco::DeDxHitInfoCollection> dedxHitCollHandle = iEvent.put(std::move(resultdedxHitColl));
150 
151  //create map passing the handle to the matched collection
152  auto dedxMatch = std::make_unique<reco::DeDxHitInfoAss>(dedxHitCollHandle);
154  filler.insert(trackCollectionHandle, indices.begin(), indices.end());
155  filler.fill();
156  iEvent.put(std::move(dedxMatch));
157 
158  auto dedxPrescale = std::make_unique<edm::ValueMap<int>>();
159  edm::ValueMap<int>::Filler pfiller(*dedxPrescale);
160  pfiller.insert(dedxHitCollHandle, prescales.begin(), prescales.end());
161  pfiller.fill();
162  iEvent.put(std::move(dedxPrescale), "prescale");
163 }
164 
165 void DeDxHitInfoProducer::processHit(const TrackingRecHit* recHit, const float trackMomentum, const float cosine, reco::DeDxHitInfo& hitDeDxInfo, const LocalPoint& hitLocalPos){
166  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
167  if(!thit.isValid())return;
168 
169  float cosineAbs = std::max(0.00000001f,std::abs(cosine));//make sure cosine is not 0
170 
171  auto const & clus = thit.firstClusterRef();
172  if(!clus.isValid())return;
173 
174 
175  if(clus.isPixel()){
176  if(!usePixel) return;
177 
178  const auto * detUnit = recHit->detUnit();
179  if (detUnit == nullptr) detUnit = tkGeom->idToDet(thit.geographicalId());
180  float pathLen = detUnit->surface().bounds().thickness()/cosineAbs;
181  float chargeAbs = clus.pixelCluster().charge();
182  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.pixelCluster() );
183  }else if(clus.isStrip() && !thit.isMatched()){
184  if(!useStrip) return;
185 
186  const auto * detUnit = recHit->detUnit();
187  if (detUnit == nullptr) detUnit = tkGeom->idToDet(thit.geographicalId());
188  int NSaturating = 0;
189  float pathLen = detUnit->surface().bounds().thickness()/cosineAbs;
190  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, *detUnit, calibGains, m_off);
191  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.stripCluster() );
192  }else if(clus.isStrip() && thit.isMatched()){
193  if(!useStrip) return;
194  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
195  if(!matchedHit)return;
196 
197  const auto * detUnitM = matchedHit->monoHit().detUnit();
198  if (detUnitM == nullptr) detUnitM = tkGeom->idToDet(matchedHit->monoHit().geographicalId());
199  int NSaturating = 0;
200  float pathLen = detUnitM->surface().bounds().thickness()/cosineAbs;
201  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoHit().stripCluster()),NSaturating, *detUnitM, calibGains, m_off);
202  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->monoHit().stripCluster() );
203 
204  const auto * detUnitS = matchedHit->stereoHit().detUnit();
205  if (detUnitS == nullptr) detUnitS = tkGeom->idToDet(matchedHit->stereoHit().geographicalId());
206  NSaturating = 0;
207  pathLen = detUnitS->surface().bounds().thickness()/cosineAbs;
208  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoHit().stripCluster()),NSaturating, *detUnitS, calibGains, m_off);
209  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->stereoHit().stripCluster() );
210  }
211 }
212 
213 
214 
215 //define this as a plug-in
double p() const
momentum vector magnitude
Definition: TrackBase.h:615
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
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:508
#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
float charge(size_t i) const
Definition: DeDxHitInfo.h:42
GenericTruncatedAverageDeDxEstimator lowPtTracksEstimator
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const Bounds & bounds() const
Definition: Surface.h:120
void produce(edm::Event &, const edm::EventSetup &) override
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
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
const unsigned int lowPtTracksPrescalePass
int iEvent
Definition: GenABIO.cc:230
const float lowPtTracksDeDxThreshold
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
DeDxHitInfoProducer(const edm::ParameterSet &)
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:10
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:621
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:820
const unsigned int minTrackHits
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
const unsigned int lowPtTracksPrescaleFail
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
uint64_t xorshift128p(uint64_t state[2])
SiStripRecHit2D stereoHit() const
T const * product() const
Definition: Handle.h:81
unsigned long long uint64_t
Definition: Time.h:15
virtual float thickness() const =0
SiStripCluster const & stripCluster() const
size_t size() const
Definition: DeDxHitInfo.h:41
const T & get() const
Definition: EventSetup.h:55
const GeomDetUnit * detUnit() const override
SiStripRecHit2D monoHit() const
std::pair< float, float > dedx(const reco::DeDxHitCollection &Hits) override
edm::EventID id() const
Definition: EventBase.h:60
fixed size matrix
HLT enums.
virtual const GeomDetUnit * detUnit() const
float pathlength(size_t i) const
Definition: DeDxHitInfo.h:43
const TrackerGeomDet * idToDet(DetId) const override
DetId geographicalId() const
void beginRun(edm::Run const &run, const edm::EventSetup &) override
edm::ESHandle< TrackerGeometry > tkGeom
const SiStripCluster * stripCluster(size_t i) const
Definition: DeDxHitInfo.h:63
def move(src, dest)
Definition: eostools.py:510
DetId detId(size_t i) const
Definition: DeDxHitInfo.h:44
const float minTrackPtPrescale
Definition: Run.h:43