CMS 3D CMS Logo

FastTrackDeDxProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastTrackDeDxProducer
4 // Class: FastTrackDeDxProducer
5 //
13 // Original author: Sam Bein
14 // Created: Wednesday Dec 26 14:17:19 CEST 2018
15 // Author of derivative code: andrea
16 // Created: Thu May 31 14:09:02 CEST 2007
17 // Code Updates: loic Quertenmont (querten)
18 // Created: Thu May 10 14:09:02 CEST 2008
19 //
20 //
21 
22 #include <memory>
23 
30 
35 
42 
52 
54 
56 
61 
62 //
63 // class declaration
64 //
65 
67 public:
69  ~FastTrackDeDxProducer() override = default;
70  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
71 
72 private:
73  void beginRun(edm::Run const& run, const edm::EventSetup&) override;
74  void produce(edm::Event&, const edm::EventSetup&) override;
75 
76  void makeCalibrationMap(const TrackerGeometry& tkGeom);
78  float trackMomentum,
79  float& cosine,
80  reco::DeDxHitCollection& dedxHits,
81  int& NClusterSaturating);
82 
83  // ----------member data ---------------------------
84  //BaseDeDxEstimator* m_estimator;
85 
86  std::unique_ptr<BaseDeDxEstimator> m_estimator;
87 
89 
92 
93  unsigned int MaxNrStrips;
94 
96 
97  std::vector<std::vector<float>> calibGains;
98  unsigned int m_off;
99 
102 
103  bool usePixel;
104  bool useStrip;
106  bool shapetest;
108  bool nothick;
109 };
110 
111 using namespace reco;
112 using namespace std;
113 using namespace edm;
114 
117  desc.add<string>("estimator", "generic");
118  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
119  desc.add<bool>("UsePixel", false);
120  desc.add<bool>("UseStrip", true);
121  desc.add<double>("MeVperADCStrip", 3.61e-06 * 265);
122  desc.add<double>("MeVperADCPixel", 3.61e-06);
123  desc.add<bool>("ShapeTest", true);
124  desc.add<bool>("UseCalibration", false);
125  desc.add<string>("calibrationPath", "");
126  desc.add<string>("Reccord", "SiStripDeDxMip_3D_Rcd");
127  desc.add<string>("ProbabilityMode", "Accumulation");
128  desc.add<double>("fraction", 0.4);
129  desc.add<double>("exponent", -2.0);
130  desc.add<bool>("convertFromGeV2MeV", true);
131  desc.add<bool>("nothick", false);
132  desc.add<edm::InputTag>("simHits");
133  desc.add<edm::InputTag>("simHit2RecHitMap");
134  descriptions.add("FastTrackDeDxProducer", desc);
135 }
136 
138  : simHitsToken(consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("simHits"))),
139  simHit2RecHitMapToken(
140  consumes<FastTrackerRecHitRefCollection>(iConfig.getParameter<edm::InputTag>("simHit2RecHitMap"))) {
141  produces<ValueMap<DeDxData>>();
142 
143  string estimatorName = iConfig.getParameter<string>("estimator");
144  if (estimatorName == "median")
145  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new MedianDeDxEstimator(iConfig));
146  else if (estimatorName == "generic")
147  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new GenericAverageDeDxEstimator(iConfig));
148  else if (estimatorName == "truncated")
149  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new TruncatedAverageDeDxEstimator(iConfig));
150  //else if(estimatorName == "unbinnedFit") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new UnbinnedFitDeDxEstimator(iConfig));//estimator used in FullSimVersion
151  else if (estimatorName == "productDiscrim")
152  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new ProductDeDxDiscriminator(iConfig));
153  else if (estimatorName == "btagDiscrim")
154  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new BTagLikeDeDxDiscriminator(iConfig));
155  else if (estimatorName == "smirnovDiscrim")
156  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new SmirnovDeDxDiscriminator(iConfig));
157  else if (estimatorName == "asmirnovDiscrim")
158  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new ASmirnovDeDxDiscriminator(iConfig));
159  else
160  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc") << " estimator name does not exist";
161 
162  //Commented for now, might be used in the future
163  // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
164 
165  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
166 
167  usePixel = iConfig.getParameter<bool>("UsePixel");
168  useStrip = iConfig.getParameter<bool>("UseStrip");
169  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
170  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
171 
172  shapetest = iConfig.getParameter<bool>("ShapeTest");
173  useCalibration = iConfig.getParameter<bool>("UseCalibration");
174  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
175 
176  convertFromGeV2MeV = iConfig.getParameter<bool>("convertFromGeV2MeV");
177  nothick = iConfig.getParameter<bool>("nothick");
178 
179  if (!usePixel && !useStrip)
180  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc")
181  << " neither pixel hits nor strips hits will be used to compute de/dx";
182 }
183 
184 // ------------ method called once each job just before starting event loop ------------
186  if (useCalibration && calibGains.empty()) {
188  iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom);
189  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
190 
192  }
193 
194  m_estimator->beginRun(run, iSetup);
195 }
196 
198  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
199  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
200 
201  edm::Handle<reco::TrackCollection> trackCollectionHandle;
202  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
203  const auto& trackCollection = *trackCollectionHandle;
204  std::vector<DeDxData> dedxEstimate(trackCollection.size());
205 
206  for (unsigned int j = 0; j < trackCollection.size(); j++) {
207  const reco::TrackRef track = reco::TrackRef(trackCollectionHandle.product(), j);
208 
209  int NClusterSaturating = 0;
210  DeDxHitCollection dedxHits;
211 
212  auto const& trajParams = track->extra()->trajParams();
213  assert(trajParams.size() == track->recHitsSize());
214 
215  auto hb = track->recHitsBegin();
216  dedxHits.reserve(track->recHitsSize() / 2);
217 
218  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
219  const FastTrackerRecHit& recHit = static_cast<const FastTrackerRecHit&>(*(*(hb + h)));
220  if (!recHit.isValid())
221  continue; //FastTrackerRecHit recHit = *(hb+h);
222  auto trackDirection = trajParams[h].direction();
223  float cosine = trackDirection.z() / trackDirection.mag();
224  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
225  }
226 
227  sort(dedxHits.begin(), dedxHits.end(), less<DeDxHit>());
228  std::pair<float, float> val_and_error = m_estimator->dedx(dedxHits);
229  //WARNING: Since the dEdX Error is not properly computed for the moment
230  //It was decided to store the number of saturating cluster in that dataformat
231  val_and_error.second = NClusterSaturating;
232  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size());
233  }
234 
235  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
236  // fill the association map and put it into the event
237  filler.fill();
238  iEvent.put(std::move(trackDeDxEstimateAssociation));
239 }
240 
242  float trackMomentum,
243  float& cosine,
244  reco::DeDxHitCollection& dedxHits,
245  int& NClusterSaturating) {
246  if (!recHit.isValid())
247  return;
248 
249  auto const& thit = static_cast<BaseTrackerRecHit const&>(recHit);
250  if (!thit.isValid())
251  return;
252  if (!thit.hasPositionAndError())
253  return;
254 
255  if (recHit.isPixel()) {
256  if (!usePixel)
257  return;
258 
259  auto& detUnit = *(recHit.detUnit());
260  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
261  if (nothick)
262  pathLen = 1.0;
263  float charge = recHit.energyLoss() / pathLen;
264  if (convertFromGeV2MeV)
265  charge *= 1000;
266  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, recHit.geographicalId()));
267  } else if (!recHit.isPixel()) { // && !recHit.isMatched()){//check what recHit.isMatched is doing
268  if (!useStrip)
269  return;
270  auto& detUnit = *(recHit.detUnit());
271  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
272  if (nothick)
273  pathLen = 1.0;
274  float dedxOfRecHit = recHit.energyLoss() / pathLen;
275  if (convertFromGeV2MeV)
276  dedxOfRecHit *= 1000;
277  if (!shapetest) {
278  dedxHits.push_back(DeDxHit(dedxOfRecHit, trackMomentum, pathLen, recHit.geographicalId()));
279  }
280  }
281 }
282 
283 //define this as a plug-in
FastTrackDeDxProducer::useCalibration
bool useCalibration
Definition: FastTrackDeDxProducer.cc:105
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
StripGeomDetUnit.h
FastTrackDeDxProducer::makeCalibrationMap
void makeCalibrationMap(const TrackerGeometry &tkGeom)
FastTrackDeDxProducer::FastTrackDeDxProducer
FastTrackDeDxProducer(const edm::ParameterSet &)
Definition: FastTrackDeDxProducer.cc:137
TrackerGeometry.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
DeDxData.h
ESHandle.h
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::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
PSimHitContainer.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco::DeDxHitCollection
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:41
FastTrackDeDxProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: FastTrackDeDxProducer.cc:115
cms::cuda::assert
assert(be >=bs)
EDProducer.h
GluedGeomDet.h
FastTrackerRecHit
Definition: FastTrackerRecHit.h:40
GenericAverageDeDxEstimator
Definition: GenericAverageDeDxEstimator.h:8
SmirnovDeDxDiscriminator.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
MedianDeDxEstimator
Definition: MedianDeDxEstimator.h:8
edm::Handle< reco::TrackCollection >
ProductDeDxDiscriminator.h
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
FastTrackDeDxProducer::simHitsToken
edm::EDGetTokenT< edm::PSimHitContainer > simHitsToken
Definition: FastTrackDeDxProducer.cc:100
edm::Ref< TrackCollection >
FastTrackDeDxProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: FastTrackDeDxProducer.cc:197
FastTrackDeDxProducer::meVperADCStrip
float meVperADCStrip
Definition: FastTrackDeDxProducer.cc:91
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
MakerMacros.h
FastTrackDeDxProducer::m_calibrationPath
std::string m_calibrationPath
Definition: FastTrackDeDxProducer.cc:95
TrackDeDxHits.h
h
Track.h
MedianDeDxEstimator.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
TrackFwd.h
ASmirnovDeDxDiscriminator.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FastTrackDeDxProducer::m_tracksTag
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
Definition: FastTrackDeDxProducer.cc:88
GenericAverageDeDxEstimator.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
BTagLikeDeDxDiscriminator.h
FastTrackDeDxProducer::nothick
bool nothick
Definition: FastTrackDeDxProducer.cc:108
DeDxHit.h
DeDxTools.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
edm::ESHandle< TrackerGeometry >
reco::btau::trackMomentum
Definition: TaggingVariable.h:41
TrajTrackAssociation.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FastTrackDeDxProducer::beginRun
void beginRun(edm::Run const &run, const edm::EventSetup &) override
Definition: FastTrackDeDxProducer.cc:185
FastTrackDeDxProducer::usePixel
bool usePixel
Definition: FastTrackDeDxProducer.cc:103
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
BaseDeDxEstimator.h
edm::ParameterSet
Definition: ParameterSet.h:47
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
Event.h
reco::DeDxHit
Definition: DeDxHit.h:11
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
FastTrackDeDxProducer::m_off
unsigned int m_off
Definition: FastTrackDeDxProducer.cc:98
FastTrackDeDxProducer::simHit2RecHitMapToken
edm::EDGetTokenT< FastTrackerRecHitRefCollection > simHit2RecHitMapToken
Definition: FastTrackDeDxProducer.cc:101
iEvent
int iEvent
Definition: GenABIO.cc:224
TruncatedAverageDeDxEstimator.h
FastTrackDeDxProducer::processHit
void processHit(const FastTrackerRecHit &recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
Definition: FastTrackDeDxProducer.cc:241
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
FastTrackerRecHitCollection.h
BTagLikeDeDxDiscriminator
Definition: BTagLikeDeDxDiscriminator.h:8
FastTrackDeDxProducer::convertFromGeV2MeV
bool convertFromGeV2MeV
Definition: FastTrackDeDxProducer.cc:107
get
#define get
FastTrackerRecHitRefCollection
std::vector< FastTrackerRecHitRef > FastTrackerRecHitRefCollection
Definition: FastTrackerRecHitCollection.h:10
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:60
ValueMap.h
UnbinnedFitDeDxEstimator.h
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
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
FastTrackDeDxProducer::shapetest
bool shapetest
Definition: FastTrackDeDxProducer.cc:106
PixelGeomDetUnit.h
FastTrackDeDxProducer::m_estimator
std::unique_ptr< BaseDeDxEstimator > m_estimator
Definition: FastTrackDeDxProducer.cc:86
FastTrackDeDxProducer::calibGains
std::vector< std::vector< float > > calibGains
Definition: FastTrackDeDxProducer.cc:97
ASmirnovDeDxDiscriminator
Definition: ASmirnovDeDxDiscriminator.h:8
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
FastTrackDeDxProducer::MaxNrStrips
unsigned int MaxNrStrips
Definition: FastTrackDeDxProducer.cc:93
FastTrackDeDxProducer::meVperADCPixel
float meVperADCPixel
Definition: FastTrackDeDxProducer.cc:90
FastTrackerRecHit.h
FastTrackDeDxProducer::useStrip
bool useStrip
Definition: FastTrackDeDxProducer.cc:104
edm::helper::Filler
Definition: ValueMap.h:22
reco::DeDxData
Definition: DeDxData.h:8
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
ParameterSet.h
FastTrackDeDxProducer
Definition: FastTrackDeDxProducer.cc:66
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
SmirnovDeDxDiscriminator
Definition: SmirnovDeDxDiscriminator.h:8
TrackerGeometry::offsetDU
unsigned int offsetDU(SubDetector sid) const
Definition: TrackerGeometry.h:72
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
FastTrackDeDxProducer::~FastTrackDeDxProducer
~FastTrackDeDxProducer() override=default
ProductDeDxDiscriminator
Definition: ProductDeDxDiscriminator.h:8
TrackerGeometry
Definition: TrackerGeometry.h:14