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
SiStripMatchedRecHit2D::monoId
unsigned int monoId() const
Definition: SiStripMatchedRecHit2D.h:29
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
DeDxEstimatorProducer::beginRun
void beginRun(edm::Run const &run, const edm::EventSetup &) override
Definition: DeDxEstimatorProducer.cc:92
edm::Handle::product
T const * product() const
Definition: Handle.h:70
SiStripMatchedRecHit2D::stereoCluster
SiStripCluster const & stereoCluster() const
Definition: SiStripMatchedRecHit2D.h:40
DeDxTools::makeCalibrationMap
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
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
dedxEstimators_cff.useCalibration
useCalibration
Definition: dedxEstimators_cff.py:16
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
TrackingRecHit::det
const GeomDet * det() const
Definition: TrackingRecHit.h:122
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco::DeDxHitCollection
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:41
cms::cuda::assert
assert(be >=bs)
GluedGeomDet::monoDet
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
GenericAverageDeDxEstimator
Definition: GenericAverageDeDxEstimator.h:8
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
MedianDeDxEstimator
Definition: MedianDeDxEstimator.h:8
edm::Handle< reco::TrackCollection >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
edm::Ref< TrackCollection >
DeDxTools::getCharge
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
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
h
DeDxEstimatorProducer.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
reco::btau::trackMomentum
Definition: TaggingVariable.h:41
DeDxEstimatorProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DeDxEstimatorProducer.cc:28
dedxEstimators_cff.useStrip
useStrip
Definition: dedxEstimators_cff.py:11
GluedGeomDet
Definition: GluedGeomDet.h:7
DeDxTools::shapeSelection
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:9
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
SiStripMatchedRecHit2D::stereoId
unsigned int stereoId() const
Definition: SiStripMatchedRecHit2D.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
reco::DeDxHit
Definition: DeDxHit.h:11
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::isFromDet
bool isFromDet(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:36
GenericTruncatedAverageDeDxEstimator
Definition: GenericTruncatedAverageDeDxEstimator.h:9
edm::EventSetup
Definition: EventSetup.h:57
BTagLikeDeDxDiscriminator
Definition: BTagLikeDeDxDiscriminator.h:8
DeDxEstimatorProducer::~DeDxEstimatorProducer
~DeDxEstimatorProducer() override
Definition: DeDxEstimatorProducer.cc:89
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:60
reco::get
T get(const Candidate &c)
Definition: component.h:60
TrackingRecHit
Definition: TrackingRecHit.h:21
GluedGeomDet::stereoDet
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
TruncatedAverageDeDxEstimator
Definition: TruncatedAverageDeDxEstimator.h:9
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
SiStripMatchedRecHit2D::monoCluster
SiStripCluster const & monoCluster() const
Definition: SiStripMatchedRecHit2D.h:41
DeDxEstimatorProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: DeDxEstimatorProducer.cc:103
DeDxEstimatorProducer::DeDxEstimatorProducer
DeDxEstimatorProducer(const edm::ParameterSet &)
Definition: DeDxEstimatorProducer.cc:47
DeDxEstimatorProducer
Definition: DeDxEstimatorProducer.h:45
ASmirnovDeDxDiscriminator
Definition: ASmirnovDeDxDiscriminator.h:8
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::helper::Filler
Definition: ValueMap.h:22
reco::DeDxData
Definition: DeDxData.h:8
UnbinnedFitDeDxEstimator
Definition: UnbinnedFitDeDxEstimator.h:14
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeDxEstimatorProducer::processHit
void processHit(const TrackingRecHit *recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
Definition: DeDxEstimatorProducer.cc:149
edm::Event
Definition: Event.h:73
SmirnovDeDxDiscriminator
Definition: SmirnovDeDxDiscriminator.h:8
edm::InputTag
Definition: InputTag.h:15
dedxEstimators_cff.usePixel
usePixel
Definition: dedxEstimators_cff.py:12
ProductDeDxDiscriminator
Definition: ProductDeDxDiscriminator.h:8