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 
36 
43 
53 
55 
57 
62 
63 //
64 // class declaration
65 //
66 
68 public:
70  ~FastTrackDeDxProducer() override = default;
71  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
72 
73 private:
74  void beginRun(edm::Run const&, const edm::EventSetup&) override;
75  void produce(edm::Event&, const edm::EventSetup&) override;
76 
77  void makeCalibrationMap(const TrackerGeometry& tkGeom);
79  float trackMomentum,
80  float& cosine,
81  reco::DeDxHitCollection& dedxHits,
82  int& NClusterSaturating);
83 
84  // ----------member data ---------------------------
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 offsetDU_;
99 
103 
104  bool usePixel;
105  bool useStrip;
107  bool shapetest;
109  bool nothick;
110 };
111 
112 using namespace reco;
113 using namespace std;
114 using namespace edm;
115 
118  desc.add<string>("estimator", "generic");
119  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
120  desc.add<bool>("UsePixel", false);
121  desc.add<bool>("UseStrip", true);
122  desc.add<double>("MeVperADCStrip", 3.61e-06 * 265);
123  desc.add<double>("MeVperADCPixel", 3.61e-06);
124  desc.add<bool>("ShapeTest", true);
125  desc.add<bool>("UseCalibration", false);
126  desc.add<string>("calibrationPath", "");
127  desc.add<string>("Record", "SiStripDeDxMip_3D_Rcd");
128  desc.add<string>("ProbabilityMode", "Accumulation");
129  desc.add<double>("fraction", 0.4);
130  desc.add<double>("exponent", -2.0);
131  desc.add<bool>("convertFromGeV2MeV", true);
132  desc.add<bool>("nothick", false);
133  desc.add<edm::InputTag>("simHits");
134  desc.add<edm::InputTag>("simHit2RecHitMap");
135  descriptions.add("FastTrackDeDxProducer", desc);
136 }
137 
139  : simHitsToken(consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("simHits"))),
140  simHit2RecHitMapToken(
141  consumes<FastTrackerRecHitRefCollection>(iConfig.getParameter<edm::InputTag>("simHit2RecHitMap"))) {
142  produces<ValueMap<DeDxData>>();
143 
144  auto cCollector = consumesCollector();
145  string estimatorName = iConfig.getParameter<string>("estimator");
146  if (estimatorName == "median")
147  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new MedianDeDxEstimator(iConfig));
148  else if (estimatorName == "generic")
149  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new GenericAverageDeDxEstimator(iConfig));
150  else if (estimatorName == "truncated")
151  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new TruncatedAverageDeDxEstimator(iConfig));
152  //else if(estimatorName == "unbinnedFit") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new UnbinnedFitDeDxEstimator(iConfig));//estimator used in FullSimVersion
153  else if (estimatorName == "productDiscrim")
154  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new ProductDeDxDiscriminator(iConfig, cCollector));
155  else if (estimatorName == "btagDiscrim")
156  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new BTagLikeDeDxDiscriminator(iConfig, cCollector));
157  else if (estimatorName == "smirnovDiscrim")
158  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new SmirnovDeDxDiscriminator(iConfig, cCollector));
159  else if (estimatorName == "asmirnovDiscrim")
160  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new ASmirnovDeDxDiscriminator(iConfig, cCollector));
161  else
162  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc") << " estimator name does not exist";
163 
164  //Commented for now, might be used in the future
165  // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
166 
167  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
168 
169  usePixel = iConfig.getParameter<bool>("UsePixel");
170  useStrip = iConfig.getParameter<bool>("UseStrip");
171  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
172  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
173 
174  shapetest = iConfig.getParameter<bool>("ShapeTest");
175  useCalibration = iConfig.getParameter<bool>("UseCalibration");
176  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
177 
178  convertFromGeV2MeV = iConfig.getParameter<bool>("convertFromGeV2MeV");
179  nothick = iConfig.getParameter<bool>("nothick");
180 
181  if (!usePixel && !useStrip)
182  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc")
183  << " neither pixel hits nor strips hits will be used to compute de/dx";
184 
185  if (useCalibration) {
186  tkGeomToken = esConsumes<edm::Transition::BeginRun>();
187  }
188 }
189 
190 // ------------ method called once each job just before starting event loop ------------
192  if (useCalibration && calibGains.empty()) {
193  auto const& tkGeom = iSetup.getData(tkGeomToken);
194  offsetDU_ = tkGeom.offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
195 
197  }
198 
199  m_estimator->beginRun(run, iSetup);
200 }
201 
203  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
204  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
205 
206  edm::Handle<reco::TrackCollection> trackCollectionHandle;
207  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
208  const auto& trackCollection = *trackCollectionHandle;
209  std::vector<DeDxData> dedxEstimate(trackCollection.size());
210 
211  for (unsigned int j = 0; j < trackCollection.size(); j++) {
212  const reco::TrackRef track = reco::TrackRef(trackCollectionHandle.product(), j);
213 
214  int NClusterSaturating = 0;
215  DeDxHitCollection dedxHits;
216 
217  auto const& trajParams = track->extra()->trajParams();
218  assert(trajParams.size() == track->recHitsSize());
219 
220  auto hb = track->recHitsBegin();
221  dedxHits.reserve(track->recHitsSize() / 2);
222 
223  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
224  const FastTrackerRecHit& recHit = static_cast<const FastTrackerRecHit&>(*(*(hb + h)));
225  if (!recHit.isValid())
226  continue; //FastTrackerRecHit recHit = *(hb+h);
227  auto trackDirection = trajParams[h].direction();
228  float cosine = trackDirection.z() / trackDirection.mag();
229  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
230  }
231 
232  sort(dedxHits.begin(), dedxHits.end(), less<DeDxHit>());
233  std::pair<float, float> val_and_error = m_estimator->dedx(dedxHits);
234  //WARNING: Since the dEdX Error is not properly computed for the moment
235  //It was decided to store the number of saturating cluster in that dataformat
236  val_and_error.second = NClusterSaturating;
237  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size());
238  }
239 
240  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
241  // fill the association map and put it into the event
242  filler.fill();
243  iEvent.put(std::move(trackDeDxEstimateAssociation));
244 }
245 
247  float trackMomentum,
248  float& cosine,
249  reco::DeDxHitCollection& dedxHits,
250  int& NClusterSaturating) {
251  if (!recHit.isValid())
252  return;
253 
254  auto const& thit = static_cast<BaseTrackerRecHit const&>(recHit);
255  if (!thit.isValid())
256  return;
257  if (!thit.hasPositionAndError())
258  return;
259 
260  if (recHit.isPixel()) {
261  if (!usePixel)
262  return;
263 
264  auto& detUnit = *(recHit.detUnit());
265  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
266  if (nothick)
267  pathLen = 1.0;
268  float charge = recHit.energyLoss() / pathLen;
269  if (convertFromGeV2MeV)
270  charge *= 1000;
271  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, recHit.geographicalId()));
272  } else if (!recHit.isPixel()) { // && !recHit.isMatched()){//check what recHit.isMatched is doing
273  if (!useStrip)
274  return;
275  auto& detUnit = *(recHit.detUnit());
276  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
277  if (nothick)
278  pathLen = 1.0;
279  float dedxOfRecHit = recHit.energyLoss() / pathLen;
280  if (convertFromGeV2MeV)
281  dedxOfRecHit *= 1000;
282  if (!shapetest) {
283  dedxHits.push_back(DeDxHit(dedxOfRecHit, trackMomentum, pathLen, recHit.geographicalId()));
284  }
285  }
286 }
287 
288 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void makeCalibrationMap(const TrackerGeometry &tkGeom)
FastTrackDeDxProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void processHit(const FastTrackerRecHit &recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:45
assert(be >=bs)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken
std::vector< std::vector< float > > calibGains
int iEvent
Definition: GenABIO.cc:224
~FastTrackDeDxProducer() override=default
edm::EDGetTokenT< FastTrackerRecHitRefCollection > simHit2RecHitMapToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
trackCollection
Definition: JetHT_cfg.py:51
void beginRun(edm::Run const &, const edm::EventSetup &) override
edm::EDGetTokenT< edm::PSimHitContainer > simHitsToken
void makeCalibrationMap(const std::string &m_calibrationPath, const TrackerGeometry &tkGeom, std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< FastTrackerRecHitRef > FastTrackerRecHitRefCollection
fixed size matrix
HLT enums.
std::unique_ptr< BaseDeDxEstimator > m_estimator
std::vector< PSimHit > PSimHitContainer
void produce(edm::Event &, const edm::EventSetup &) override
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