CMS 3D CMS Logo

DeDxHitInfoProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxHitInfoProducer
4 // Class: DeDxHitInfoProducer
5 //
13 //
14 // Original Author: loic Quertenmont (querten)
15 // Created: Mon Nov 21 14:09:02 CEST 2014
16 //
17 
19 
20 // system include files
21 
22 using namespace reco;
23 using namespace std;
24 using namespace edm;
25 
27  : usePixel(iConfig.getParameter<bool>("usePixel")),
28  useStrip(iConfig.getParameter<bool>("useStrip")),
29  MeVperADCPixel(iConfig.getParameter<double>("MeVperADCPixel")),
30  MeVperADCStrip(iConfig.getParameter<double>("MeVperADCStrip")),
31  minTrackHits(iConfig.getParameter<unsigned>("minTrackHits")),
32  minTrackPt(iConfig.getParameter<double>("minTrackPt")),
33  minTrackPtPrescale(iConfig.getParameter<double>("minTrackPtPrescale")),
34  maxTrackEta(iConfig.getParameter<double>("maxTrackEta")),
35  m_calibrationPath(iConfig.getParameter<string>("calibrationPath")),
36  useCalibration(iConfig.getParameter<bool>("useCalibration")),
37  shapetest(iConfig.getParameter<bool>("shapeTest")),
38  lowPtTracksPrescalePass(iConfig.getParameter<uint32_t>("lowPtTracksPrescalePass")),
39  lowPtTracksPrescaleFail(iConfig.getParameter<uint32_t>("lowPtTracksPrescaleFail")),
40  lowPtTracksEstimator(iConfig.getParameter<edm::ParameterSet>("lowPtTracksEstimatorParameters")),
41  lowPtTracksDeDxThreshold(iConfig.getParameter<double>("lowPtTracksDeDxThreshold")) {
42  produces<reco::DeDxHitInfoCollection>();
43  produces<reco::DeDxHitInfoAss>();
44  produces<edm::ValueMap<int>>("prescale");
45 
46  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
47  m_tkGeomToken = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
48 
49  if (!usePixel && !useStrip)
50  edm::LogError("DeDxHitsProducer") << "No Pixel Hits NOR Strip Hits will be saved. Running this module is useless";
51 }
52 
54 
55 // ------------ method called once each job just before starting event loop ------------
57  tkGeom = iSetup.getHandle(m_tkGeomToken);
58  if (useCalibration && calibGains.empty()) {
59  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
60 
62  }
63 }
64 
66  edm::Handle<reco::TrackCollection> trackCollectionHandle;
67  iEvent.getByToken(m_tracksTag, trackCollectionHandle);
68  const TrackCollection& trackCollection(*trackCollectionHandle.product());
69 
70  // creates the output collection
71  auto resultdedxHitColl = std::make_unique<reco::DeDxHitInfoCollection>();
72 
73  std::vector<int> indices;
74  std::vector<int> prescales;
75  uint64_t state[2] = {iEvent.id().event(), iEvent.id().luminosityBlock()};
76  for (unsigned int j = 0; j < trackCollection.size(); j++) {
78 
79  //track selection
80  bool passPt = (track.pt() >= minTrackPt), passLowDeDx = false, passHighDeDx = false, pass = passPt;
81  if (!pass && (track.pt() >= minTrackPtPrescale)) {
82  if (lowPtTracksPrescalePass > 0) {
83  passHighDeDx = ((xorshift128p(state) % lowPtTracksPrescalePass) == 0);
84  }
85  if (lowPtTracksPrescaleFail > 0) {
86  passLowDeDx = ((xorshift128p(state) % lowPtTracksPrescaleFail) == 0);
87  }
88  pass = passHighDeDx || passLowDeDx;
89  }
90  if (!pass || std::abs(track.eta()) > maxTrackEta || track.numberOfValidHits() < minTrackHits) {
91  indices.push_back(-1);
92  continue;
93  }
94 
95  reco::DeDxHitInfo hitDeDxInfo;
96  auto const& trajParams = track.extra()->trajParams();
97  auto hb = track.recHitsBegin();
98  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
99  auto recHit = *(hb + h);
101  continue;
102 
103  auto trackDirection = trajParams[h].direction();
104  float cosine = trackDirection.z() / trackDirection.mag();
105 
106  processHit(recHit, track.p(), cosine, hitDeDxInfo, trajParams[h].position());
107  }
108 
109  if (!passPt) {
110  std::vector<DeDxHit> hits;
111  hits.reserve(hitDeDxInfo.size());
112  for (unsigned int i = 0, n = hitDeDxInfo.size(); i < n; ++i) {
113  if (hitDeDxInfo.detId(i).subdetId() <= 2) {
114  hits.push_back(DeDxHit(hitDeDxInfo.charge(i) / hitDeDxInfo.pathlength(i) * MeVperADCPixel, 0, 0, 0));
115  } else {
116  if (shapetest && !DeDxTools::shapeSelection(*hitDeDxInfo.stripCluster(i)))
117  continue;
118  hits.push_back(DeDxHit(hitDeDxInfo.charge(i) / hitDeDxInfo.pathlength(i) * MeVperADCStrip, 0, 0, 0));
119  }
120  }
121  std::sort(hits.begin(), hits.end(), std::less<DeDxHit>());
123  if (passLowDeDx) {
125  } else {
126  indices.push_back(-1);
127  continue;
128  }
129  } else {
130  if (passHighDeDx) {
132  } else {
133  indices.push_back(-1);
134  continue;
135  }
136  }
137  } else {
138  prescales.push_back(1);
139  }
140  indices.push_back(resultdedxHitColl->size());
141  resultdedxHitColl->push_back(hitDeDxInfo);
142  }
144 
145  edm::OrphanHandle<reco::DeDxHitInfoCollection> dedxHitCollHandle = iEvent.put(std::move(resultdedxHitColl));
146 
147  //create map passing the handle to the matched collection
148  auto dedxMatch = std::make_unique<reco::DeDxHitInfoAss>(dedxHitCollHandle);
150  filler.insert(trackCollectionHandle, indices.begin(), indices.end());
151  filler.fill();
152  iEvent.put(std::move(dedxMatch));
153 
154  auto dedxPrescale = std::make_unique<edm::ValueMap<int>>();
155  edm::ValueMap<int>::Filler pfiller(*dedxPrescale);
156  pfiller.insert(dedxHitCollHandle, prescales.begin(), prescales.end());
157  pfiller.fill();
158  iEvent.put(std::move(dedxPrescale), "prescale");
159 }
160 
162  const float trackMomentum,
163  const float cosine,
164  reco::DeDxHitInfo& hitDeDxInfo,
165  const LocalPoint& hitLocalPos) {
166  auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
167  if (!thit.isValid())
168  return;
169 
170  float cosineAbs = std::max(0.00000001f, std::abs(cosine)); //make sure cosine is not 0
171 
172  auto const& clus = thit.firstClusterRef();
173  if (!clus.isValid())
174  return;
175 
176  if (clus.isPixel()) {
177  if (!usePixel)
178  return;
179 
180  const auto* detUnit = recHit->detUnit();
181  if (detUnit == nullptr)
182  detUnit = tkGeom->idToDet(thit.geographicalId());
183  float pathLen = detUnit->surface().bounds().thickness() / cosineAbs;
184  float chargeAbs = clus.pixelCluster().charge();
185  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.pixelCluster());
186  } else if (clus.isStrip() && !thit.isMatched()) {
187  if (!useStrip)
188  return;
189 
190  const auto* detUnit = recHit->detUnit();
191  if (detUnit == nullptr)
192  detUnit = tkGeom->idToDet(thit.geographicalId());
193  int NSaturating = 0;
194  float pathLen = detUnit->surface().bounds().thickness() / cosineAbs;
195  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()), NSaturating, *detUnit, calibGains, m_off);
196  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, clus.stripCluster());
197  } else if (clus.isStrip() && thit.isMatched()) {
198  if (!useStrip)
199  return;
200  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
201  if (!matchedHit)
202  return;
203 
204  const auto* detUnitM = matchedHit->monoHit().detUnit();
205  if (detUnitM == nullptr)
206  detUnitM = tkGeom->idToDet(matchedHit->monoHit().geographicalId());
207  int NSaturating = 0;
208  float pathLen = detUnitM->surface().bounds().thickness() / cosineAbs;
209  float chargeAbs =
210  DeDxTools::getCharge(&(matchedHit->monoHit().stripCluster()), NSaturating, *detUnitM, calibGains, m_off);
211  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->monoHit().stripCluster());
212 
213  const auto* detUnitS = matchedHit->stereoHit().detUnit();
214  if (detUnitS == nullptr)
215  detUnitS = tkGeom->idToDet(matchedHit->stereoHit().geographicalId());
216  NSaturating = 0;
217  pathLen = detUnitS->surface().bounds().thickness() / cosineAbs;
218  chargeAbs =
219  DeDxTools::getCharge(&(matchedHit->stereoHit().stripCluster()), NSaturating, *detUnitS, calibGains, m_off);
220  hitDeDxInfo.addHit(chargeAbs, pathLen, thit.geographicalId(), hitLocalPos, matchedHit->stereoHit().stripCluster());
221  }
222 }
223 
224 //define this as a plug-in
dedxEstimators_cff.lowPtTracksDeDxThreshold
lowPtTracksDeDxThreshold
Definition: dedxEstimators_cff.py:26
DeDxHitInfoProducer::MeVperADCPixel
const float MeVperADCPixel
Definition: DeDxHitInfoProducer.h:57
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
DeDxHitInfoProducer::useCalibration
const bool useCalibration
Definition: DeDxHitInfoProducer.h:66
reco::DeDxHitInfo::detId
DetId detId(size_t i) const
Definition: DeDxHitInfo.h:44
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
edm::Association::Filler
Definition: Association.h:78
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::Handle::product
T const * product() const
Definition: Handle.h:70
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
DeDxHitInfoProducer::DeDxHitInfoProducer
DeDxHitInfoProducer(const edm::ParameterSet &)
Definition: DeDxHitInfoProducer.cc:26
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
DeDxHitInfoProducer::useStrip
const bool useStrip
Definition: DeDxHitInfoProducer.h:56
dedxEstimators_cff.useCalibration
useCalibration
Definition: dedxEstimators_cff.py:16
DeDxHitInfoProducer::processHit
void processHit(const TrackingRecHit *recHit, const float trackMomentum, const float cosine, reco::DeDxHitInfo &hitDeDxInfo, const LocalPoint &hitLocalPos)
Definition: DeDxHitInfoProducer.cc:161
DeDxHitInfoProducer::xorshift128p
uint64_t xorshift128p(uint64_t state[2])
Definition: DeDxHitInfoProducer.h:79
TrackerSingleRecHit::stripCluster
SiStripCluster const & stripCluster() const
Definition: TrackerSingleRecHit.h:55
DeDxHitInfoProducer::maxTrackEta
const float maxTrackEta
Definition: DeDxHitInfoProducer.h:63
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
DeDxHitInfoProducer::usePixel
const bool usePixel
Definition: DeDxHitInfoProducer.h:55
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
DeDxHitInfoProducer::lowPtTracksPrescaleFail
const unsigned int lowPtTracksPrescaleFail
Definition: DeDxHitInfoProducer.h:69
DeDxHitInfoProducer::~DeDxHitInfoProducer
~DeDxHitInfoProducer() override
Definition: DeDxHitInfoProducer.cc:53
edm::Handle< reco::TrackCollection >
DeDxHitInfoProducer::minTrackPtPrescale
const float minTrackPtPrescale
Definition: DeDxHitInfoProducer.h:62
TrackingRecHit::geographicalId
DetId geographicalId() const
Definition: TrackingRecHit.h:120
reco::DeDxHitInfo::charge
float charge(size_t i) const
Definition: DeDxHitInfo.h:42
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
DeDxHitInfoProducer::m_tkGeomToken
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > m_tkGeomToken
Definition: DeDxHitInfoProducer.h:77
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
reco::DeDxHitInfo::stripCluster
const SiStripCluster * stripCluster(size_t i) const
Definition: DeDxHitInfo.h:66
reco::DeDxHitInfo::pathlength
float pathlength(size_t i) const
Definition: DeDxHitInfo.h:43
DeDxHitInfoProducer::minTrackPt
const float minTrackPt
Definition: DeDxHitInfoProducer.h:61
h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DeDxHitInfoProducer
Definition: DeDxHitInfoProducer.h:35
DeDxHitInfoProducer::beginRun
void beginRun(edm::Run const &run, const edm::EventSetup &) override
Definition: DeDxHitInfoProducer.cc:56
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
reco::Track
Definition: Track.h:27
GenericTruncatedAverageDeDxEstimator::dedx
std::pair< float, float > dedx(const reco::DeDxHitCollection &Hits) override
Definition: GenericTruncatedAverageDeDxEstimator.h:16
reco::btau::trackMomentum
Definition: TaggingVariable.h:41
SiStripMatchedRecHit2D::stereoHit
SiStripRecHit2D stereoHit() const
Definition: SiStripMatchedRecHit2D.h:25
dedxEstimators_cff.maxTrackEta
maxTrackEta
Definition: dedxEstimators_cff.py:9
dedxEstimators_cff.minTrackPtPrescale
minTrackPtPrescale
Definition: dedxEstimators_cff.py:8
Point3DBase< float, LocalTag >
HLT_FULL_cff.MeVperADCStrip
MeVperADCStrip
Definition: HLT_FULL_cff.py:52817
dedxEstimators_cff.useStrip
useStrip
Definition: dedxEstimators_cff.py:11
dedxEstimators_cff.lowPtTracksPrescaleFail
lowPtTracksPrescaleFail
Definition: dedxEstimators_cff.py:21
DeDxTools::shapeSelection
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:12
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
DeDxHitInfoProducer::MeVperADCStrip
const float MeVperADCStrip
Definition: DeDxHitInfoProducer.h:58
reco::DeDxHitInfo
Definition: DeDxHitInfo.h:14
Bounds::thickness
virtual float thickness() const =0
edm::ParameterSet
Definition: ParameterSet.h:47
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
reco::DeDxHit
Definition: DeDxHit.h:11
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
hltrates_dqm_sourceclient-live_cfg.prescales
prescales
Definition: hltrates_dqm_sourceclient-live_cfg.py:90
DeDxHitInfoProducer::tkGeom
edm::ESHandle< TrackerGeometry > tkGeom
Definition: DeDxHitInfoProducer.h:76
SiStripMatchedRecHit2D::monoHit
SiStripRecHit2D monoHit() const
Definition: SiStripMatchedRecHit2D.h:26
iEvent
int iEvent
Definition: GenABIO.cc:224
align_cfg.minTrackPt
minTrackPt
Definition: align_cfg.py:22
trackerHitRTTI::isFromDet
bool isFromDet(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:36
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
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
reco::DeDxHitInfo::size
size_t size() const
Definition: DeDxHitInfo.h:41
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HLT_FULL_cff.MeVperADCPixel
MeVperADCPixel
Definition: HLT_FULL_cff.py:52816
HLT_FULL_cff.minTrackHits
minTrackHits
Definition: HLT_FULL_cff.py:32638
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DeDxHitInfoProducer::calibGains
std::vector< std::vector< float > > calibGains
Definition: DeDxHitInfoProducer.h:73
TrackingRecHit
Definition: TrackingRecHit.h:21
DeDxHitInfoProducer::m_tracksTag
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
Definition: DeDxHitInfoProducer.h:53
DeDxHitInfoProducer::lowPtTracksDeDxThreshold
const float lowPtTracksDeDxThreshold
Definition: DeDxHitInfoProducer.h:71
dedxEstimators_cff.lowPtTracksPrescalePass
lowPtTracksPrescalePass
Definition: dedxEstimators_cff.py:20
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::OrphanHandle
Definition: EDProductfwd.h:39
DeDxHitInfoProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: DeDxHitInfoProducer.cc:65
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
DeDxTools::getCharge
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float >> &calibGains, const unsigned int &m_off)
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
DeDxHitInfoProducer::shapetest
const bool shapetest
Definition: DeDxHitInfoProducer.h:67
DeDxHitInfoProducer::lowPtTracksPrescalePass
const unsigned int lowPtTracksPrescalePass
Definition: DeDxHitInfoProducer.h:69
DeDxHitInfoProducer::m_off
unsigned int m_off
Definition: DeDxHitInfoProducer.h:74
DeDxHitInfoProducer::minTrackHits
const unsigned int minTrackHits
Definition: DeDxHitInfoProducer.h:60
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
DeDxHitInfoProducer::lowPtTracksEstimator
GenericTruncatedAverageDeDxEstimator lowPtTracksEstimator
Definition: DeDxHitInfoProducer.h:70
edm::helper::Filler
Definition: ValueMap.h:22
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmdumpme.indices
indices
Definition: dqmdumpme.py:50
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
DeDxHitInfoProducer.h
TrackerGeometry::offsetDU
unsigned int offsetDU(SubDetector sid) const
Definition: TrackerGeometry.h:72
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
dedxEstimators_cff.usePixel
usePixel
Definition: dedxEstimators_cff.py:12
reco::DeDxHitInfo::addHit
void addHit(const float charge, const float pathlength, const DetId &detId, const LocalPoint &pos, const SiStripCluster &stripCluster)
Definition: DeDxHitInfo.h:89
DeDxHitInfoProducer::m_calibrationPath
const std::string m_calibrationPath
Definition: DeDxHitInfoProducer.h:65
TrackerSingleRecHit::detUnit
const GeomDetUnit * detUnit() const override
Definition: TrackerSingleRecHit.h:36