CMS 3D CMS Logo

DeDxEstimatorProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxEstimatorProducer
4 // Class: DeDxEstimatorProducer
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 
21 // system include files
24 
25 using namespace reco;
26 using namespace std;
27 using namespace edm;
28 
31  desc.add<string>("estimator", "generic");
32  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
33  desc.add<bool>("UseDeDxHits", false);
34  desc.add<edm::InputTag>("pixelDeDxHits", {});
35  desc.add<edm::InputTag>("stripDeDxHits", {});
36  desc.add<bool>("UsePixel", false);
37  desc.add<bool>("UseStrip", true);
38  desc.add<double>("MeVperADCPixel", 3.61e-06);
39  desc.add<double>("MeVperADCStrip", 3.61e-06 * 265);
40  desc.add<bool>("ShapeTest", true);
41  desc.add<bool>("UseCalibration", false);
42  desc.add<string>("calibrationPath", "");
43  desc.add<string>("Record", "SiStripDeDxMip_3D_Rcd");
44  desc.add<string>("ProbabilityMode", "Accumulation");
45  desc.add<double>("fraction", 0.4);
46  desc.add<double>("exponent", -2.0);
47  desc.add<bool>("truncate", true);
48 
49  descriptions.add("DeDxEstimatorProducer", desc);
50 }
51 
54  produces<ValueMap<DeDxData>>();
55 
56  auto cCollector = consumesCollector();
57  string estimatorName = iConfig.getParameter<string>("estimator");
58  if (estimatorName == "median")
59  m_estimator = std::make_unique<MedianDeDxEstimator>(iConfig);
60  else if (estimatorName == "generic")
61  m_estimator = std::make_unique<GenericAverageDeDxEstimator>(iConfig);
62  else if (estimatorName == "truncated")
63  m_estimator = std::make_unique<TruncatedAverageDeDxEstimator>(iConfig);
64  else if (estimatorName == "genericTruncated")
65  m_estimator = std::make_unique<GenericTruncatedAverageDeDxEstimator>(iConfig);
66  else if (estimatorName == "unbinnedFit")
67  m_estimator = std::make_unique<UnbinnedFitDeDxEstimator>(iConfig);
68  else if (estimatorName == "likelihoodFit")
69  m_estimator = std::make_unique<LikelihoodFitDeDxEstimator>(iConfig);
70  else if (estimatorName == "productDiscrim")
71  m_estimator = std::make_unique<ProductDeDxDiscriminator>(iConfig, cCollector);
72  else if (estimatorName == "btagDiscrim")
73  m_estimator = std::make_unique<BTagLikeDeDxDiscriminator>(iConfig, cCollector);
74  else if (estimatorName == "smirnovDiscrim")
75  m_estimator = std::make_unique<SmirnovDeDxDiscriminator>(iConfig, cCollector);
76  else if (estimatorName == "asmirnovDiscrim")
77  m_estimator = std::make_unique<ASmirnovDeDxDiscriminator>(iConfig, cCollector);
78 
79  //Commented for now, might be used in the future
80  // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
81 
82  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
83 
84  useDeDxHits = iConfig.getParameter<bool>("UseDeDxHits");
85  m_pixelDeDxHitsTag = consumes<reco::TrackDeDxHitsCollection>(iConfig.getParameter<edm::InputTag>("pixelDeDxHits"));
86  m_stripDeDxHitsTag = consumes<reco::TrackDeDxHitsCollection>(iConfig.getParameter<edm::InputTag>("stripDeDxHits"));
87 
88  usePixel = iConfig.getParameter<bool>("UsePixel");
89  useStrip = iConfig.getParameter<bool>("UseStrip");
90  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
91  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
92 
93  shapetest = iConfig.getParameter<bool>("ShapeTest");
94  useCalibration = iConfig.getParameter<bool>("UseCalibration");
95  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
96 
97  if (!usePixel && !useStrip)
98  edm::LogWarning("DeDxHitsProducer")
99  << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
100 }
101 
103 
104 // ------------ method called once each job just before starting event loop ------------
106  tkGeom = &iSetup.getData(tkGeomToken);
107  if (useCalibration && calibGains.empty()) {
108  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
109 
111  }
112 
113  m_estimator->beginRun(run, iSetup);
114 }
115 
117  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
118  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
119 
120  edm::Handle<reco::TrackCollection> trackCollectionHandle;
121  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
122  const auto& pixelDeDxHits = iEvent.getHandle(m_pixelDeDxHitsTag);
123  const auto& stripDeDxHits = iEvent.getHandle(m_stripDeDxHitsTag);
124 
125  std::vector<DeDxData> dedxEstimate(trackCollectionHandle->size());
126 
127  for (unsigned int j = 0; j < trackCollectionHandle->size(); j++) {
128  const reco::TrackRef track = reco::TrackRef(trackCollectionHandle, j);
129 
130  int NClusterSaturating = 0;
131  DeDxHitCollection dedxHits;
132 
133  dedxHits.reserve(track->recHitsSize() / 2);
134  if (useDeDxHits) {
135  if (usePixel)
136  dedxHits = (*pixelDeDxHits)[track];
137  if (useStrip) {
138  const auto& hits = (*stripDeDxHits)[track];
139  dedxHits.insert(dedxHits.end(), hits.begin(), hits.end());
140  }
141  } else {
142  auto const& trajParams = track->extra()->trajParams();
143  assert(trajParams.size() == track->recHitsSize());
144  auto hb = track->recHitsBegin();
145  dedxHits.reserve(track->recHitsSize() / 2);
146  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
147  auto recHit = *(hb + h);
149  continue;
150 
151  auto trackDirection = trajParams[h].direction();
152  float cosine = trackDirection.z() / trackDirection.mag();
153  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
154  }
155  }
156 
157  sort(dedxHits.begin(), dedxHits.end(), less<DeDxHit>());
158  std::pair<float, float> val_and_error = m_estimator->dedx(dedxHits);
159 
160  //WARNING: Since the dEdX Error is not properly computed for the moment
161  //It was decided to store the number of saturating cluster in that dataformat
162  val_and_error.second = NClusterSaturating;
163  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size());
164  }
166 
167  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
168 
169  // fill the association map and put it into the event
170  filler.fill();
171  iEvent.put(std::move(trackDeDxEstimateAssociation));
172 }
173 
175  float trackMomentum,
176  float& cosine,
177  reco::DeDxHitCollection& dedxHits,
178  int& NClusterSaturating) {
179  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
180  if (!thit.isValid())
181  return;
182 
183  auto const& clus = thit.firstClusterRef();
184  if (!clus.isValid())
185  return;
186 
187  if (clus.isPixel()) {
188  if (!usePixel)
189  return;
190 
191  const auto* detUnit = recHit->detUnit();
192  if (detUnit == nullptr)
193  detUnit = tkGeom->idToDet(thit.geographicalId());
194  float pathLen = detUnit->surface().bounds().thickness() / fabs(cosine);
195  float chargeAbs = clus.pixelCluster().charge();
196  float charge = meVperADCPixel * chargeAbs / pathLen;
197  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, thit.geographicalId()));
198  } else if (clus.isStrip() && !thit.isMatched()) {
199  if (!useStrip)
200  return;
201 
202  const auto* detUnit = recHit->detUnit();
203  if (detUnit == nullptr)
204  detUnit = tkGeom->idToDet(thit.geographicalId());
205  int NSaturating = 0;
206  float pathLen = detUnit->surface().bounds().thickness() / fabs(cosine);
207  float chargeAbs = deDxTools::getCharge(&(clus.stripCluster()), NSaturating, *detUnit, calibGains, m_off);
208  float charge = meVperADCStrip * chargeAbs / pathLen;
209  if (!shapetest || (shapetest && deDxTools::shapeSelection(clus.stripCluster()))) {
210  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, thit.geographicalId()));
211  if (NSaturating > 0)
212  NClusterSaturating++;
213  }
214  } else if (clus.isStrip() && thit.isMatched()) {
215  if (!useStrip)
216  return;
217  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
218  if (!matchedHit)
219  return;
220  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
221  if (gdet == nullptr)
222  gdet = static_cast<const GluedGeomDet*>(tkGeom->idToDet(thit.geographicalId()));
223 
224  auto& detUnitM = *(gdet->monoDet());
225  int NSaturating = 0;
226  float pathLen = detUnitM.surface().bounds().thickness() / fabs(cosine);
227  float chargeAbs = deDxTools::getCharge(&(matchedHit->monoCluster()), NSaturating, detUnitM, calibGains, m_off);
228  float charge = meVperADCStrip * chargeAbs / pathLen;
229  if (!shapetest || (shapetest && deDxTools::shapeSelection(matchedHit->monoCluster()))) {
230  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, matchedHit->monoId()));
231  if (NSaturating > 0)
232  NClusterSaturating++;
233  }
234 
235  auto& detUnitS = *(gdet->stereoDet());
236  NSaturating = 0;
237  pathLen = detUnitS.surface().bounds().thickness() / fabs(cosine);
238  chargeAbs = deDxTools::getCharge(&(matchedHit->stereoCluster()), NSaturating, detUnitS, calibGains, m_off);
239  charge = meVperADCStrip * chargeAbs / pathLen;
240  if (!shapetest || (shapetest && deDxTools::shapeSelection(matchedHit->stereoCluster()))) {
241  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, matchedHit->stereoId()));
242  if (NSaturating > 0)
243  NClusterSaturating++;
244  }
245  }
246 }
247 
248 //define this as a plug-in
DeDxEstimatorProducer(const edm::ParameterSet &)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isFromDet(TrackingRecHit const &hit)
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
unsigned int offsetDU(SubDetector sid) const
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:45
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
edm::EDGetTokenT< reco::TrackDeDxHitsCollection > m_stripDeDxHitsTag
unsigned int stereoId() const
assert(be >=bs)
std::unique_ptr< BaseDeDxEstimator > m_estimator
const GeomDet * det() const
edm::EDGetTokenT< reco::TrackDeDxHitsCollection > m_pixelDeDxHitsTag
virtual float thickness() const =0
void beginRun(edm::Run const &run, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
SiStripCluster const & monoCluster() const
void processHit(const TrackingRecHit *recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const TrackerGeomDet * idToDet(DetId) const override
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
void makeCalibrationMap(const std::string &m_calibrationPath, const TrackerGeometry &tkGeom, std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
unsigned int monoId() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:13
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const TrackerGeometry * tkGeom
SiStripCluster const & stereoCluster() const
fixed size matrix
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
Log< level::Warning, false > LogWarning
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
std::vector< std::vector< float > > calibGains
const Bounds & bounds() const
Definition: Surface.h:87