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 
31 
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& run, 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  //BaseDeDxEstimator* m_estimator;
86 
87  std::unique_ptr<BaseDeDxEstimator> m_estimator;
88 
90 
93 
94  unsigned int MaxNrStrips;
95 
97 
98  std::vector<std::vector<float>> calibGains;
99  unsigned int m_off;
100 
104 
105  bool usePixel;
106  bool useStrip;
108  bool shapetest;
110  bool nothick;
111 };
112 
113 using namespace reco;
114 using namespace std;
115 using namespace edm;
116 
119  desc.add<string>("estimator", "generic");
120  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
121  desc.add<bool>("UsePixel", false);
122  desc.add<bool>("UseStrip", true);
123  desc.add<double>("MeVperADCStrip", 3.61e-06 * 265);
124  desc.add<double>("MeVperADCPixel", 3.61e-06);
125  desc.add<bool>("ShapeTest", true);
126  desc.add<bool>("UseCalibration", false);
127  desc.add<string>("calibrationPath", "");
128  desc.add<string>("Reccord", "SiStripDeDxMip_3D_Rcd");
129  desc.add<string>("ProbabilityMode", "Accumulation");
130  desc.add<double>("fraction", 0.4);
131  desc.add<double>("exponent", -2.0);
132  desc.add<bool>("convertFromGeV2MeV", true);
133  desc.add<bool>("nothick", false);
134  desc.add<edm::InputTag>("simHits");
135  desc.add<edm::InputTag>("simHit2RecHitMap");
136  descriptions.add("FastTrackDeDxProducer", desc);
137 }
138 
140  : simHitsToken(consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("simHits"))),
141  simHit2RecHitMapToken(
142  consumes<FastTrackerRecHitRefCollection>(iConfig.getParameter<edm::InputTag>("simHit2RecHitMap"))),
144  produces<ValueMap<DeDxData>>();
145 
146  auto cCollector = consumesCollector();
147  string estimatorName = iConfig.getParameter<string>("estimator");
148  if (estimatorName == "median")
149  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new MedianDeDxEstimator(iConfig));
150  else if (estimatorName == "generic")
151  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new GenericAverageDeDxEstimator(iConfig));
152  else if (estimatorName == "truncated")
153  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new TruncatedAverageDeDxEstimator(iConfig));
154  //else if(estimatorName == "unbinnedFit") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new UnbinnedFitDeDxEstimator(iConfig));//estimator used in FullSimVersion
155  else if (estimatorName == "productDiscrim")
156  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new ProductDeDxDiscriminator(iConfig, cCollector));
157  else if (estimatorName == "btagDiscrim")
158  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new BTagLikeDeDxDiscriminator(iConfig, cCollector));
159  else if (estimatorName == "smirnovDiscrim")
160  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new SmirnovDeDxDiscriminator(iConfig, cCollector));
161  else if (estimatorName == "asmirnovDiscrim")
162  m_estimator = std::unique_ptr<BaseDeDxEstimator>(new ASmirnovDeDxDiscriminator(iConfig, cCollector));
163  else
164  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc") << " estimator name does not exist";
165 
166  //Commented for now, might be used in the future
167  // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
168 
169  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
170 
171  usePixel = iConfig.getParameter<bool>("UsePixel");
172  useStrip = iConfig.getParameter<bool>("UseStrip");
173  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
174  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
175 
176  shapetest = iConfig.getParameter<bool>("ShapeTest");
177  useCalibration = iConfig.getParameter<bool>("UseCalibration");
178  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
179 
180  convertFromGeV2MeV = iConfig.getParameter<bool>("convertFromGeV2MeV");
181  nothick = iConfig.getParameter<bool>("nothick");
182 
183  if (!usePixel && !useStrip)
184  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc")
185  << " neither pixel hits nor strips hits will be used to compute de/dx";
186 }
187 
188 // ------------ method called once each job just before starting event loop ------------
190  if (useCalibration && calibGains.empty()) {
192  iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom);
193  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
194 
196  }
197 
198  m_estimator->beginRun(run, iSetup);
199 }
200 
202  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
203  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
204 
205  edm::Handle<reco::TrackCollection> trackCollectionHandle;
206  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
207  const auto& trackCollection = *trackCollectionHandle;
208  std::vector<DeDxData> dedxEstimate(trackCollection.size());
209 
210  for (unsigned int j = 0; j < trackCollection.size(); j++) {
211  const reco::TrackRef track = reco::TrackRef(trackCollectionHandle.product(), j);
212 
213  int NClusterSaturating = 0;
214  DeDxHitCollection dedxHits;
215 
216  auto const& trajParams = track->extra()->trajParams();
217  assert(trajParams.size() == track->recHitsSize());
218 
219  auto hb = track->recHitsBegin();
220  dedxHits.reserve(track->recHitsSize() / 2);
221 
222  for (unsigned int h = 0; h < track->recHitsSize(); h++) {
223  const FastTrackerRecHit& recHit = static_cast<const FastTrackerRecHit&>(*(*(hb + h)));
224  if (!recHit.isValid())
225  continue; //FastTrackerRecHit recHit = *(hb+h);
226  auto trackDirection = trajParams[h].direction();
227  float cosine = trackDirection.z() / trackDirection.mag();
228  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
229  }
230 
231  sort(dedxHits.begin(), dedxHits.end(), less<DeDxHit>());
232  std::pair<float, float> val_and_error = m_estimator->dedx(dedxHits);
233  //WARNING: Since the dEdX Error is not properly computed for the moment
234  //It was decided to store the number of saturating cluster in that dataformat
235  val_and_error.second = NClusterSaturating;
236  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size());
237  }
238 
239  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
240  // fill the association map and put it into the event
241  filler.fill();
242  iEvent.put(std::move(trackDeDxEstimateAssociation));
243 }
244 
246  float trackMomentum,
247  float& cosine,
248  reco::DeDxHitCollection& dedxHits,
249  int& NClusterSaturating) {
250  if (!recHit.isValid())
251  return;
252 
253  auto const& thit = static_cast<BaseTrackerRecHit const&>(recHit);
254  if (!thit.isValid())
255  return;
256  if (!thit.hasPositionAndError())
257  return;
258 
259  if (recHit.isPixel()) {
260  if (!usePixel)
261  return;
262 
263  auto& detUnit = *(recHit.detUnit());
264  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
265  if (nothick)
266  pathLen = 1.0;
267  float charge = recHit.energyLoss() / pathLen;
268  if (convertFromGeV2MeV)
269  charge *= 1000;
270  dedxHits.push_back(DeDxHit(charge, trackMomentum, pathLen, recHit.geographicalId()));
271  } else if (!recHit.isPixel()) { // && !recHit.isMatched()){//check what recHit.isMatched is doing
272  if (!useStrip)
273  return;
274  auto& detUnit = *(recHit.detUnit());
275  float pathLen = detUnit.surface().bounds().thickness() / fabs(cosine);
276  if (nothick)
277  pathLen = 1.0;
278  float dedxOfRecHit = recHit.energyLoss() / pathLen;
279  if (convertFromGeV2MeV)
280  dedxOfRecHit *= 1000;
281  if (!shapetest) {
282  dedxHits.push_back(DeDxHit(dedxOfRecHit, trackMomentum, pathLen, recHit.geographicalId()));
283  }
284  }
285 }
286 
287 //define this as a plug-in
FastTrackDeDxProducer::useCalibration
bool useCalibration
Definition: FastTrackDeDxProducer.cc:107
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
StripGeomDetUnit.h
FastTrackDeDxProducer::makeCalibrationMap
void makeCalibrationMap(const TrackerGeometry &tkGeom)
FastTrackDeDxProducer::FastTrackDeDxProducer
FastTrackDeDxProducer(const edm::ParameterSet &)
Definition: FastTrackDeDxProducer.cc:139
TrackerGeometry.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
DeDxData.h
ESHandle.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
PSimHitContainer.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
FastTrackDeDxProducer::tkGeomToken
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken
Definition: FastTrackDeDxProducer.cc:103
reco::DeDxHitCollection
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:41
FastTrackDeDxProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: FastTrackDeDxProducer.cc:117
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:46
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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:101
edm::Ref< TrackCollection >
FastTrackDeDxProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: FastTrackDeDxProducer.cc:201
FastTrackDeDxProducer::meVperADCStrip
float meVperADCStrip
Definition: FastTrackDeDxProducer.cc:92
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
MakerMacros.h
FastTrackDeDxProducer::m_calibrationPath
std::string m_calibrationPath
Definition: FastTrackDeDxProducer.cc:96
TrackDeDxHits.h
h
Track.h
MedianDeDxEstimator.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
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:89
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:110
DeDxHit.h
DeDxTools.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:16
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
FastTrackDeDxProducer::beginRun
void beginRun(edm::Run const &run, const edm::EventSetup &) override
Definition: FastTrackDeDxProducer.cc:189
FastTrackDeDxProducer::usePixel
bool usePixel
Definition: FastTrackDeDxProducer.cc:105
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
BaseDeDxEstimator.h
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
Event.h
reco::DeDxHit
Definition: DeDxHit.h:11
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
FastTrackDeDxProducer::m_off
unsigned int m_off
Definition: FastTrackDeDxProducer.cc:99
FastTrackDeDxProducer::simHit2RecHitMapToken
edm::EDGetTokenT< FastTrackerRecHitRefCollection > simHit2RecHitMapToken
Definition: FastTrackDeDxProducer.cc:102
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:245
edm::stream::EDProducer
Definition: EDProducer.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
FastTrackerRecHitCollection.h
BTagLikeDeDxDiscriminator
Definition: BTagLikeDeDxDiscriminator.h:8
FastTrackDeDxProducer::convertFromGeV2MeV
bool convertFromGeV2MeV
Definition: FastTrackDeDxProducer.cc:109
get
#define get
FastTrackerRecHitRefCollection
std::vector< FastTrackerRecHitRef > FastTrackerRecHitRefCollection
Definition: FastTrackerRecHitCollection.h:10
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:60
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
edm::Transition::BeginRun
Exception
Definition: hltDiff.cc:245
FastTrackDeDxProducer::shapetest
bool shapetest
Definition: FastTrackDeDxProducer.cc:108
PixelGeomDetUnit.h
FastTrackDeDxProducer::m_estimator
std::unique_ptr< BaseDeDxEstimator > m_estimator
Definition: FastTrackDeDxProducer.cc:87
FastTrackDeDxProducer::calibGains
std::vector< std::vector< float > > calibGains
Definition: FastTrackDeDxProducer.cc:98
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:94
FastTrackDeDxProducer::meVperADCPixel
float meVperADCPixel
Definition: FastTrackDeDxProducer.cc:91
FastTrackerRecHit.h
FastTrackDeDxProducer::useStrip
bool useStrip
Definition: FastTrackDeDxProducer.cc:106
ConsumesCollector.h
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:67
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
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