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