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>("UsePixel", false);
34  desc.add<bool>("UseStrip", true);
35  desc.add<double>("MeVperADCPixel", 3.61e-06);
36  desc.add<double>("MeVperADCStrip", 3.61e-06 * 265);
37  desc.add<bool>("ShapeTest", true);
38  desc.add<bool>("UseCalibration", false);
39  desc.add<string>("calibrationPath", "");
40  desc.add<string>("Record", "SiStripDeDxMip_3D_Rcd");
41  desc.add<string>("ProbabilityMode", "Accumulation");
42  desc.add<double>("fraction", 0.4);
43  desc.add<double>("exponent", -2.0);
44  desc.add<bool>("truncate", true);
45 
46  descriptions.add("DeDxEstimatorProducer", desc);
47 }
48 
51  produces<ValueMap<DeDxData>>();
52 
53  auto cCollector = consumesCollector();
54  string estimatorName = iConfig.getParameter<string>("estimator");
55  if (estimatorName == "median")
56  m_estimator = std::make_unique<MedianDeDxEstimator>(iConfig);
57  else if (estimatorName == "generic")
58  m_estimator = std::make_unique<GenericAverageDeDxEstimator>(iConfig);
59  else if (estimatorName == "truncated")
60  m_estimator = std::make_unique<TruncatedAverageDeDxEstimator>(iConfig);
61  else if (estimatorName == "genericTruncated")
62  m_estimator = std::make_unique<GenericTruncatedAverageDeDxEstimator>(iConfig);
63  else if (estimatorName == "unbinnedFit")
64  m_estimator = std::make_unique<UnbinnedFitDeDxEstimator>(iConfig);
65  else if (estimatorName == "productDiscrim")
66  m_estimator = std::make_unique<ProductDeDxDiscriminator>(iConfig, cCollector);
67  else if (estimatorName == "btagDiscrim")
68  m_estimator = std::make_unique<BTagLikeDeDxDiscriminator>(iConfig, cCollector);
69  else if (estimatorName == "smirnovDiscrim")
70  m_estimator = std::make_unique<SmirnovDeDxDiscriminator>(iConfig, cCollector);
71  else if (estimatorName == "asmirnovDiscrim")
72  m_estimator = std::make_unique<ASmirnovDeDxDiscriminator>(iConfig, cCollector);
73 
74  //Commented for now, might be used in the future
75  // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
76 
77  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
78 
79  usePixel = iConfig.getParameter<bool>("UsePixel");
80  useStrip = iConfig.getParameter<bool>("UseStrip");
81  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
82  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
83 
84  shapetest = iConfig.getParameter<bool>("ShapeTest");
85  useCalibration = iConfig.getParameter<bool>("UseCalibration");
86  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
87 
88  if (!usePixel && !useStrip)
89  edm::LogWarning("DeDxHitsProducer")
90  << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
91 }
92 
94 
95 // ------------ method called once each job just before starting event loop ------------
97  tkGeom = &iSetup.getData(tkGeomToken);
98  if (useCalibration && calibGains.empty()) {
99  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
100 
102  }
103 
104  m_estimator->beginRun(run, iSetup);
105 }
106 
108  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
109  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
110 
111  edm::Handle<reco::TrackCollection> trackCollectionHandle;
112  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
113 
114  std::vector<DeDxData> dedxEstimate(trackCollectionHandle->size());
115 
116  for (unsigned int j = 0; j < trackCollectionHandle->size(); j++) {
117  const reco::TrackRef track = reco::TrackRef(trackCollectionHandle.product(), j);
118 
119  int NClusterSaturating = 0;
120  DeDxHitCollection dedxHits;
121 
122  auto const& trajParams = track->extra()->trajParams();
123  assert(trajParams.size() == track->recHitsSize());
124  auto hb = track->recHitsBegin();
125  dedxHits.reserve(track->recHitsSize() / 2);
126  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
127  auto recHit = *(hb + h);
129  continue;
130 
131  auto trackDirection = trajParams[h].direction();
132  float cosine = trackDirection.z() / trackDirection.mag();
133  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
134  }
135 
136  sort(dedxHits.begin(), dedxHits.end(), less<DeDxHit>());
137  std::pair<float, float> val_and_error = m_estimator->dedx(dedxHits);
138 
139  //WARNING: Since the dEdX Error is not properly computed for the moment
140  //It was decided to store the number of saturating cluster in that dataformat
141  val_and_error.second = NClusterSaturating;
142  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size());
143  }
145 
146  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
147 
148  // fill the association map and put it into the event
149  filler.fill();
150  iEvent.put(std::move(trackDeDxEstimateAssociation));
151 }
152 
154  float trackMomentum,
155  float& cosine,
156  reco::DeDxHitCollection& dedxHits,
157  int& NClusterSaturating) {
158  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
159  if (!thit.isValid())
160  return;
161 
162  auto const& clus = thit.firstClusterRef();
163  if (!clus.isValid())
164  return;
165 
166  if (clus.isPixel()) {
167  if (!usePixel)
168  return;
169 
170  const auto* detUnit = recHit->detUnit();
171  if (detUnit == nullptr)
172  detUnit = tkGeom->idToDet(thit.geographicalId());
173  float pathLen = detUnit->surface().bounds().thickness() / fabs(cosine);
174  float chargeAbs = clus.pixelCluster().charge();
175  float charge = meVperADCPixel * chargeAbs / pathLen;
176  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, thit.geographicalId()));
177  } else if (clus.isStrip() && !thit.isMatched()) {
178  if (!useStrip)
179  return;
180 
181  const auto* detUnit = recHit->detUnit();
182  if (detUnit == nullptr)
183  detUnit = tkGeom->idToDet(thit.geographicalId());
184  int NSaturating = 0;
185  float pathLen = detUnit->surface().bounds().thickness() / fabs(cosine);
186  float chargeAbs = deDxTools::getCharge(&(clus.stripCluster()), NSaturating, *detUnit, calibGains, m_off);
187  float charge = meVperADCStrip * chargeAbs / pathLen;
188  if (!shapetest || (shapetest && deDxTools::shapeSelection(clus.stripCluster()))) {
189  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, thit.geographicalId()));
190  if (NSaturating > 0)
191  NClusterSaturating++;
192  }
193  } else if (clus.isStrip() && thit.isMatched()) {
194  if (!useStrip)
195  return;
196  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
197  if (!matchedHit)
198  return;
199  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
200  if (gdet == nullptr)
201  gdet = static_cast<const GluedGeomDet*>(tkGeom->idToDet(thit.geographicalId()));
202 
203  auto& detUnitM = *(gdet->monoDet());
204  int NSaturating = 0;
205  float pathLen = detUnitM.surface().bounds().thickness() / fabs(cosine);
206  float chargeAbs = deDxTools::getCharge(&(matchedHit->monoCluster()), NSaturating, detUnitM, calibGains, m_off);
207  float charge = meVperADCStrip * chargeAbs / pathLen;
208  if (!shapetest || (shapetest && deDxTools::shapeSelection(matchedHit->monoCluster()))) {
209  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, matchedHit->monoId()));
210  if (NSaturating > 0)
211  NClusterSaturating++;
212  }
213 
214  auto& detUnitS = *(gdet->stereoDet());
215  NSaturating = 0;
216  pathLen = detUnitS.surface().bounds().thickness() / fabs(cosine);
217  chargeAbs = deDxTools::getCharge(&(matchedHit->stereoCluster()), NSaturating, detUnitS, calibGains, m_off);
218  charge = meVperADCStrip * chargeAbs / pathLen;
219  if (!shapetest || (shapetest && deDxTools::shapeSelection(matchedHit->stereoCluster()))) {
220  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, matchedHit->stereoId()));
221  if (NSaturating > 0)
222  NClusterSaturating++;
223  }
224  }
225 }
226 
227 //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:303
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
T const * product() const
Definition: Handle.h:70
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:41
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
unsigned int stereoId() const
assert(be >=bs)
std::unique_ptr< BaseDeDxEstimator > m_estimator
const GeomDet * det() const
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