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  if (useDeDxHits) {
134  if (usePixel)
135  dedxHits = (*pixelDeDxHits)[track];
136  if (useStrip) {
137  const auto& hits = (*stripDeDxHits)[track];
138  dedxHits.insert(dedxHits.end(), hits.begin(), hits.end());
139  }
140  } else {
141  auto const& trajParams = track->extra()->trajParams();
142  assert(trajParams.size() == track->recHitsSize());
143  auto hb = track->recHitsBegin();
144  dedxHits.reserve(track->recHitsSize() / 2);
145  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
146  auto recHit = *(hb + h);
148  continue;
149 
150  auto trackDirection = trajParams[h].direction();
151  float cosine = trackDirection.z() / trackDirection.mag();
152  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
153  }
154  }
155 
156  sort(dedxHits.begin(), dedxHits.end(), less<DeDxHit>());
157  std::pair<float, float> val_and_error = m_estimator->dedx(dedxHits);
158 
159  //WARNING: Since the dEdX Error is not properly computed for the moment
160  //It was decided to store the number of saturating cluster in that dataformat
161  val_and_error.second = NClusterSaturating;
162  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size());
163  }
165 
166  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
167 
168  // fill the association map and put it into the event
169  filler.fill();
170  iEvent.put(std::move(trackDeDxEstimateAssociation));
171 }
172 
174  float trackMomentum,
175  float& cosine,
176  reco::DeDxHitCollection& dedxHits,
177  int& NClusterSaturating) {
178  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
179  if (!thit.isValid())
180  return;
181 
182  auto const& clus = thit.firstClusterRef();
183  if (!clus.isValid())
184  return;
185 
186  if (clus.isPixel()) {
187  if (!usePixel)
188  return;
189 
190  const auto* detUnit = recHit->detUnit();
191  if (detUnit == nullptr)
192  detUnit = tkGeom->idToDet(thit.geographicalId());
193  float pathLen = detUnit->surface().bounds().thickness() / fabs(cosine);
194  float chargeAbs = clus.pixelCluster().charge();
195  float charge = meVperADCPixel * chargeAbs / pathLen;
196  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, thit.geographicalId()));
197  } else if (clus.isStrip() && !thit.isMatched()) {
198  if (!useStrip)
199  return;
200 
201  const auto* detUnit = recHit->detUnit();
202  if (detUnit == nullptr)
203  detUnit = tkGeom->idToDet(thit.geographicalId());
204  int NSaturating = 0;
205  float pathLen = detUnit->surface().bounds().thickness() / fabs(cosine);
206  float chargeAbs = deDxTools::getCharge(&(clus.stripCluster()), NSaturating, *detUnit, calibGains, m_off);
207  float charge = meVperADCStrip * chargeAbs / pathLen;
208  if (!shapetest || (shapetest && deDxTools::shapeSelection(clus.stripCluster()))) {
209  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, thit.geographicalId()));
210  if (NSaturating > 0)
211  NClusterSaturating++;
212  }
213  } else if (clus.isStrip() && thit.isMatched()) {
214  if (!useStrip)
215  return;
216  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
217  if (!matchedHit)
218  return;
219  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
220  if (gdet == nullptr)
221  gdet = static_cast<const GluedGeomDet*>(tkGeom->idToDet(thit.geographicalId()));
222 
223  auto& detUnitM = *(gdet->monoDet());
224  int NSaturating = 0;
225  float pathLen = detUnitM.surface().bounds().thickness() / fabs(cosine);
226  float chargeAbs = deDxTools::getCharge(&(matchedHit->monoCluster()), NSaturating, detUnitM, calibGains, m_off);
227  float charge = meVperADCStrip * chargeAbs / pathLen;
228  if (!shapetest || (shapetest && deDxTools::shapeSelection(matchedHit->monoCluster()))) {
229  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, matchedHit->monoId()));
230  if (NSaturating > 0)
231  NClusterSaturating++;
232  }
233 
234  auto& detUnitS = *(gdet->stereoDet());
235  NSaturating = 0;
236  pathLen = detUnitS.surface().bounds().thickness() / fabs(cosine);
237  chargeAbs = deDxTools::getCharge(&(matchedHit->stereoCluster()), NSaturating, detUnitS, calibGains, m_off);
238  charge = meVperADCStrip * chargeAbs / pathLen;
239  if (!shapetest || (shapetest && deDxTools::shapeSelection(matchedHit->stereoCluster()))) {
240  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, matchedHit->stereoId()));
241  if (NSaturating > 0)
242  NClusterSaturating++;
243  }
244  }
245 }
246 
247 //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