CMS 3D CMS Logo

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