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>("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);
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
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
SiStripMatchedRecHit2D::monoId
unsigned int monoId() const
Definition: SiStripMatchedRecHit2D.h:29
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
DeDxEstimatorProducer::beginRun
void beginRun(edm::Run const &run, const edm::EventSetup &) override
Definition: DeDxEstimatorProducer.cc:95
edm::Handle::product
T const * product() const
Definition: Handle.h:70
SiStripMatchedRecHit2D::stereoCluster
SiStripCluster const & stereoCluster() const
Definition: SiStripMatchedRecHit2D.h:40
DeDxEstimatorProducer::calibGains
std::vector< std::vector< float > > calibGains
Definition: DeDxEstimatorProducer.h:78
DeDxEstimatorProducer::meVperADCPixel
float meVperADCPixel
Definition: DeDxEstimatorProducer.h:69
DeDxEstimatorProducer::m_calibrationPath
std::string m_calibrationPath
Definition: DeDxEstimatorProducer.h:74
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
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:89281
DeDxEstimatorProducer::usePixel
bool usePixel
Definition: DeDxEstimatorProducer.h:67
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DeDxEstimatorProducer::useStrip
bool useStrip
Definition: DeDxEstimatorProducer.h:68
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
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
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 >
DeDxEstimatorProducer::shapetest
bool shapetest
Definition: DeDxEstimatorProducer.h:76
DeDxEstimatorProducer::m_tracksTag
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
Definition: DeDxEstimatorProducer.h:65
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
h
DeDxEstimatorProducer.h
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
DeDxEstimatorProducer::m_estimator
std::unique_ptr< BaseDeDxEstimator > m_estimator
Definition: DeDxEstimatorProducer.h:63
DeDxEstimatorProducer::useCalibration
bool useCalibration
Definition: DeDxEstimatorProducer.h:75
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
reco::btau::trackMomentum
Definition: TaggingVariable.h:41
DeDxEstimatorProducer::m_off
unsigned int m_off
Definition: DeDxEstimatorProducer.h:79
DeDxEstimatorProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DeDxEstimatorProducer.cc:29
DeDxEstimatorProducer::tkGeom
const TrackerGeometry * tkGeom
Definition: DeDxEstimatorProducer.h:82
GluedGeomDet
Definition: GluedGeomDet.h:7
DeDxTools::shapeSelection
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:12
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
Bounds::thickness
virtual float thickness() const =0
SiStripMatchedRecHit2D::stereoId
unsigned int stereoId() const
Definition: SiStripMatchedRecHit2D.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
reco::DeDxHit
Definition: DeDxHit.h:11
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
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
DeDxTools::makeCalibrationMap
void makeCalibrationMap(const std::string &m_calibrationPath, const TrackerGeometry &tkGeom, std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
edm::EventSetup
Definition: EventSetup.h:58
DeDxEstimatorProducer::~DeDxEstimatorProducer
~DeDxEstimatorProducer() override
Definition: DeDxEstimatorProducer.cc:92
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:60
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
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
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
edm::Transition::BeginRun
DeDxTools::getCharge
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
DeDxEstimatorProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: DeDxEstimatorProducer.cc:106
DeDxEstimatorProducer::DeDxEstimatorProducer
DeDxEstimatorProducer(const edm::ParameterSet &)
Definition: DeDxEstimatorProducer.cc:48
DeDxEstimatorProducer
Definition: DeDxEstimatorProducer.h:45
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
DeDxEstimatorProducer::meVperADCStrip
float meVperADCStrip
Definition: DeDxEstimatorProducer.h:70
ConsumesCollector.h
edm::helper::Filler
Definition: ValueMap.h:22
reco::DeDxData
Definition: DeDxData.h:8
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeDxEstimatorProducer::tkGeomToken
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken
Definition: DeDxEstimatorProducer.h:81
DeDxEstimatorProducer::processHit
void processHit(const TrackingRecHit *recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
Definition: DeDxEstimatorProducer.cc:152
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
TrackerGeometry::offsetDU
unsigned int offsetDU(SubDetector sid) const
Definition: TrackerGeometry.h:72
edm::InputTag
Definition: InputTag.h:15
TrackerGeometry
Definition: TrackerGeometry.h:14