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 // Modifications: Tamas Almos Vami (2022)
17 
18 // system include files
19 #include <memory>
20 
42 
43 using namespace reco;
44 using namespace std;
45 using namespace edm;
46 
48 public:
49  explicit DeDxHitInfoProducer(const edm::ParameterSet&);
50  ~DeDxHitInfoProducer() override;
51 
52 private:
53  void beginRun(edm::Run const& run, const edm::EventSetup&) override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55 
56  void makeCalibrationMap(const TrackerGeometry& tkGeom_);
57  void processRec(reco::DeDxHitInfo&, const SiStripRecHit2D&, const LocalPoint&, const LocalVector&, const float&);
58  void processHit(const TrackingRecHit* recHit,
59  const float trackMomentum,
60  const LocalVector& trackDirection,
61  reco::DeDxHitInfo& hitDeDxInfo,
62  std::vector<float>& hitMomentum,
63  const LocalPoint& hitLocalPos);
64 
65  // ----------member data ---------------------------
66  const bool usePixel_;
67  const bool useStrip_;
68  const float theMeVperADCPixel_;
69  const float theMeVperADCStrip_;
70 
71  const unsigned int minTrackHits_;
72  const float minTrackPt_;
73  const float minTrackPtPrescale_;
74  const float maxTrackEta_;
75 
77  const bool useCalibration_;
78  const bool doShapeTest_;
79  const bool usePixelShape_;
80  const bool storeMomentumAtHit_;
81 
82  const unsigned int lowPtTracksPrescalePass_, lowPtTracksPrescaleFail_;
86 
94 
95  std::vector<std::vector<float>> calibGains_;
96  unsigned int offsetDU_;
97 
99  uint64_t x = state[0];
100  uint64_t const y = state[1];
101  state[0] = y;
102  x ^= x << 23; // a
103  state[1] = x ^ y ^ (x >> 17) ^ (y >> 26); // b, c
104  return state[1] + y;
105  }
106 };
107 
109  : usePixel_(iConfig.getParameter<bool>("usePixel")),
110  useStrip_(iConfig.getParameter<bool>("useStrip")),
111  theMeVperADCPixel_(iConfig.getParameter<double>("MeVperADCPixel")),
112  theMeVperADCStrip_(iConfig.getParameter<double>("MeVperADCStrip")),
113  minTrackHits_(iConfig.getParameter<unsigned>("minTrackHits")),
114  minTrackPt_(iConfig.getParameter<double>("minTrackPt")),
115  minTrackPtPrescale_(iConfig.getParameter<double>("minTrackPtPrescale")),
116  maxTrackEta_(iConfig.getParameter<double>("maxTrackEta")),
117  calibrationPath_(iConfig.getParameter<string>("calibrationPath")),
118  useCalibration_(iConfig.getParameter<bool>("useCalibration")),
119  doShapeTest_(iConfig.getParameter<bool>("shapeTest")),
120  usePixelShape_(not iConfig.getParameter<edm::InputTag>("clusterShapeCache").label().empty()),
121  storeMomentumAtHit_(iConfig.getParameter<bool>("storeMomentumAtHit")),
122  lowPtTracksPrescalePass_(iConfig.getParameter<uint32_t>("lowPtTracksPrescalePass")),
123  lowPtTracksPrescaleFail_(iConfig.getParameter<uint32_t>("lowPtTracksPrescaleFail")),
124  lowPtTracksEstimator_(iConfig.getParameter<edm::ParameterSet>("lowPtTracksEstimatorParameters")),
125  lowPtTracksDeDxThreshold_(iConfig.getParameter<double>("lowPtTracksDeDxThreshold")),
126  usePixelForPrescales_(iConfig.getParameter<bool>("usePixelForPrescales")),
127  tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))),
128  pixShapeCacheToken_(consumes<SiPixelClusterShapeCache>(iConfig.getParameter<edm::InputTag>("clusterShapeCache"))),
130  clShapeToken_(
131  esConsumes<ClusterShapeHitFilter, CkfComponentsRecord>(edm::ESInputTag("", "ClusterShapeHitFilter"))) {
132  produces<reco::DeDxHitInfoCollection>();
133  produces<reco::DeDxHitInfoAss>();
134  produces<edm::ValueMap<int>>("prescale");
136  produces<edm::ValueMap<std::vector<float>>>("momentumAtHit");
137 
138  if (!usePixel_ && !useStrip_)
139  edm::LogError("DeDxHitsProducer") << "No Pixel Hits NOR Strip Hits will be saved. Running this module is useless";
140 }
141 
143 
144 // ------------ method called once each job just before starting event loop ------------
145 void DeDxHitInfoProducer::beginRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
146  tkGeom_ = iSetup.getHandle(tkGeomToken_);
147  if (useCalibration_ && calibGains_.empty()) {
148  offsetDU_ = tkGeom_->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
149 
151  }
152 }
153 
155  edm::Handle<reco::TrackCollection> trackCollectionHandle;
156  iEvent.getByToken(tracksToken_, trackCollectionHandle);
157  const TrackCollection& trackCollection(*trackCollectionHandle.product());
158 
159  clShape_ = iSetup.getHandle(clShapeToken_);
160  if (usePixelShape_)
162 
163  // creates the output collection
164  auto resultdedxHitColl = std::make_unique<reco::DeDxHitInfoCollection>();
165 
166  std::vector<int> indices;
167  std::vector<int> prescales;
168  std::vector<std::vector<float>> hitMomenta;
169  uint64_t state[2] = {iEvent.id().event(), iEvent.id().luminosityBlock()};
170  for (unsigned int j = 0; j < trackCollection.size(); j++) {
172 
173  //track selection
174  bool passPt = (track.pt() >= minTrackPt_), passLowDeDx = false, passHighDeDx = false, pass = passPt;
175  if (!pass && (track.pt() >= minTrackPtPrescale_)) {
176  if (lowPtTracksPrescalePass_ > 0) {
177  passHighDeDx = ((xorshift128p(state) % lowPtTracksPrescalePass_) == 0);
178  }
179  if (lowPtTracksPrescaleFail_ > 0) {
180  passLowDeDx = ((xorshift128p(state) % lowPtTracksPrescaleFail_) == 0);
181  }
182  pass = passHighDeDx || passLowDeDx;
183  }
184  if (!pass || std::abs(track.eta()) > maxTrackEta_ || track.numberOfValidHits() < minTrackHits_) {
185  indices.push_back(-1);
186  continue;
187  }
188 
189  reco::DeDxHitInfo hitDeDxInfo;
190  std::vector<float> hitMomentum;
191  auto const& trajParams = track.extra()->trajParams();
192  auto hb = track.recHitsBegin();
193  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
194  auto recHit = *(hb + h);
196  continue;
197 
198  const auto& traj = trajParams[h];
199  processHit(recHit, traj.momentum().mag(), traj.direction(), hitDeDxInfo, hitMomentum, traj.position());
200  }
201  assert(!storeMomentumAtHit_ || hitMomentum.size() == hitDeDxInfo.size());
202 
203  if (!passPt) {
204  std::vector<DeDxHit> hits;
205  hits.reserve(hitDeDxInfo.size());
206  for (unsigned int i = 0, n = hitDeDxInfo.size(); i < n; ++i) {
207  if (hitDeDxInfo.detId(i).subdetId() <= 2 && usePixelForPrescales_) {
208  hits.push_back(DeDxHit(hitDeDxInfo.charge(i) / hitDeDxInfo.pathlength(i) * theMeVperADCPixel_, 0, 0, 0));
209  } else if (hitDeDxInfo.detId(i).subdetId() > 2) {
210  if (doShapeTest_ && !deDxTools::shapeSelection(*hitDeDxInfo.stripCluster(i)))
211  continue;
212  hits.push_back(DeDxHit(hitDeDxInfo.charge(i) / hitDeDxInfo.pathlength(i) * theMeVperADCStrip_, 0, 0, 0));
213  }
214  }
215 
216  // In case we have a pixel only track, but usePixelForPrescales_ is false
217  if (hits.empty()) {
218  indices.push_back(-1);
219  continue;
220  }
221  std::sort(hits.begin(), hits.end(), std::less<DeDxHit>());
223  if (passLowDeDx) {
225  } else {
226  indices.push_back(-1);
227  continue;
228  }
229  } else {
230  if (passHighDeDx) {
232  } else {
233  indices.push_back(-1);
234  continue;
235  }
236  }
237  } else {
238  prescales.push_back(1);
239  }
240  indices.push_back(resultdedxHitColl->size());
241  resultdedxHitColl->push_back(hitDeDxInfo);
243  hitMomenta.push_back(hitMomentum);
244  }
246 
247  edm::OrphanHandle<reco::DeDxHitInfoCollection> dedxHitCollHandle = iEvent.put(std::move(resultdedxHitColl));
248 
249  //create map passing the handle to the matched collection
250  auto dedxMatch = std::make_unique<reco::DeDxHitInfoAss>(dedxHitCollHandle);
252  filler.insert(trackCollectionHandle, indices.begin(), indices.end());
253  filler.fill();
254  iEvent.put(std::move(dedxMatch));
255 
256  auto dedxPrescale = std::make_unique<edm::ValueMap<int>>();
257  edm::ValueMap<int>::Filler pfiller(*dedxPrescale);
258  pfiller.insert(dedxHitCollHandle, prescales.begin(), prescales.end());
259  pfiller.fill();
260  iEvent.put(std::move(dedxPrescale), "prescale");
261 
262  if (storeMomentumAtHit_) {
263  auto dedxMomenta = std::make_unique<edm::ValueMap<std::vector<float>>>();
264  edm::ValueMap<std::vector<float>>::Filler mfiller(*dedxMomenta);
265  mfiller.insert(dedxHitCollHandle, hitMomenta.begin(), hitMomenta.end());
266  mfiller.fill();
267  iEvent.put(std::move(dedxMomenta), "momentumAtHit");
268  }
269 }
270 
272  const SiStripRecHit2D& recHit,
273  const LocalPoint& lpos,
274  const LocalVector& ldir,
275  const float& cos) {
276  uint8_t type(0);
277  int meas;
278  float pred;
279  const auto& usable = clShape_->getSizes(recHit, {}, ldir, meas, pred);
280  if (usable && meas <= int(std::abs(pred)) + 4)
282  if (clShape_->isCompatible(recHit, ldir))
284  if (usable)
286 
287  int NSaturating(0);
288  const auto& detId = recHit.geographicalId();
289  const auto* detUnit = recHit.detUnit();
290  if (detUnit == nullptr)
291  detUnit = tkGeom_->idToDet(detId);
292  const auto pathLen = detUnit->surface().bounds().thickness() / cos;
293  float chargeAbs = deDxTools::getCharge(&(recHit.stripCluster()), NSaturating, *detUnit, calibGains_, offsetDU_);
294  hitDeDxInfo.addHit(chargeAbs, pathLen, detId, lpos, type, recHit.stripCluster());
295 }
296 
298  const float trackMomentum,
299  const LocalVector& trackDirection,
300  reco::DeDxHitInfo& hitDeDxInfo,
301  std::vector<float>& hitMomentum,
302  const LocalPoint& hitLocalPos) {
303  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
304  if (!thit.isValid())
305  return;
306 
307  //make sure cosine is not 0
308  float cosine = trackDirection.z() / trackDirection.mag();
309  float cosineAbs = std::max(0.00000001f, std::abs(cosine));
310 
311  auto const& clus = thit.firstClusterRef();
312  if (!clus.isValid())
313  return;
314 
315  const auto* detUnit = recHit->detUnit();
316  if (detUnit == nullptr) {
317  detUnit = tkGeom_->idToDet(thit.geographicalId());
318  }
319  float pathLen = detUnit->surface().bounds().thickness() / cosineAbs;
320 
321  if (clus.isPixel()) {
322  if (!usePixel_)
323  return;
324 
325  uint8_t type(0);
326  const auto& pixelDet = *dynamic_cast<const PixelGeomDetUnit*>(detUnit);
327  const auto& pixelRecHit = *dynamic_cast<const SiPixelRecHit*>(recHit);
329  ClusterShape().determineShape(pixelDet, clus.pixelCluster(), data);
330  if (data.isComplete)
332  if (usePixelShape_ && clShape_->isCompatible(pixelRecHit, trackDirection, *pixShapeCache_))
334  if (data.isComplete && data.isStraight && data.hasBigPixelsOnlyInside)
336 
337  float chargeAbs = clus.pixelCluster().charge();
338  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, type, clus.pixelCluster());
339  } else if (clus.isStrip() && !thit.isMatched()) {
340  if (!useStrip_)
341  return;
342 
343  processRec(hitDeDxInfo, {thit.geographicalId(), clus}, hitLocalPos, trackDirection, cosineAbs);
344  } else if (clus.isStrip() && thit.isMatched()) {
345  if (!useStrip_)
346  return;
347  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
348  if (!matchedHit)
349  return;
351  hitMomentum.push_back(trackMomentum);
352 
353  processRec(hitDeDxInfo, matchedHit->monoHit(), hitLocalPos, trackDirection, cosineAbs);
354  processRec(hitDeDxInfo, matchedHit->stereoHit(), hitLocalPos, trackDirection, cosineAbs);
355  }
356  if (storeMomentumAtHit_ && (clus.isPixel() || clus.isStrip()))
357  hitMomentum.push_back(trackMomentum);
358 }
359 
360 //define this as a plug-in
float pathlength(size_t i) const
Definition: DeDxHitInfo.h:47
const unsigned int minTrackHits_
const std::string calibrationPath_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< SiPixelClusterShapeCache > pixShapeCacheToken_
SiStripRecHit2D stereoHit() const
bool isFromDet(TrackingRecHit const &hit)
T z() const
Definition: PV3DBase.h:61
void processRec(reco::DeDxHitInfo &, const SiStripRecHit2D &, const LocalPoint &, const LocalVector &, const float &)
unsigned int offsetDU(SubDetector sid) const
T const * product() const
Definition: Handle.h:70
const unsigned int lowPtTracksPrescaleFail_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ESHandle< ClusterShapeHitFilter > clShape_
static constexpr int Compatible
Definition: DeDxHitInfo.h:40
void produce(edm::Event &, const edm::EventSetup &) override
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
Log< level::Error, false > LogError
assert(be >=bs)
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, PixelData const *pd=nullptr) const
const edm::EDGetTokenT< reco::TrackCollection > tracksToken_
virtual float thickness() const =0
char const * label
int iEvent
Definition: GenABIO.cc:224
const unsigned int lowPtTracksPrescalePass_
DeDxHitInfoProducer(const edm::ParameterSet &)
void addHit(const float charge, const float pathlength, const DetId &detId, const LocalPoint &pos, const uint8_t &type, const SiStripCluster &stripCluster)
Definition: DeDxHitInfo.h:94
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
T mag() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
const SiStripCluster * stripCluster(size_t i) const
Definition: DeDxHitInfo.h:71
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
edm::ESHandle< TrackerGeometry > tkGeom_
static constexpr int Calibration
Definition: DeDxHitInfo.h:40
DetId detId(size_t i) const
Definition: DeDxHitInfo.h:48
trackCollection
Definition: JetHT_cfg.py:51
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const TrackerGeomDet * idToDet(DetId) const override
void makeCalibrationMap(const std::string &m_calibrationPath, const TrackerGeometry &tkGeom, std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
uint64_t xorshift128p(uint64_t state[2])
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
bool getSizes(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, int &part, ClusterData::ArrayType &meas, std::pair< float, float > &predr, PixelData const *pd=nullptr) const
unsigned long long uint64_t
Definition: Time.h:13
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:13
size_t size() const
Definition: DeDxHitInfo.h:45
const edm::ESGetToken< ClusterShapeHitFilter, CkfComponentsRecord > clShapeToken_
~DeDxHitInfoProducer() override
static constexpr int Complete
Definition: DeDxHitInfo.h:40
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void processHit(const TrackingRecHit *recHit, const float trackMomentum, const LocalVector &trackDirection, reco::DeDxHitInfo &hitDeDxInfo, std::vector< float > &hitMomentum, const LocalPoint &hitLocalPos)
GenericTruncatedAverageDeDxEstimator lowPtTracksEstimator_
edm::Handle< SiPixelClusterShapeCache > pixShapeCache_
float x
SiStripRecHit2D monoHit() const
std::pair< float, float > dedx(const reco::DeDxHitCollection &Hits) override
float charge(size_t i) const
Definition: DeDxHitInfo.h:46
std::vector< std::vector< float > > calibGains_
void beginRun(edm::Run const &run, const edm::EventSetup &) override
const float lowPtTracksDeDxThreshold_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
Our base class.
Definition: SiPixelRecHit.h:23
const Bounds & bounds() const
Definition: Surface.h:87