CMS 3D CMS Logo

TrackingRegionsFromSuperClustersProducer.cc
Go to the documentation of this file.
1 //******************************************************************************
2 //
3 // Part of the refactorisation of of the E/gamma pixel matching pre-2017
4 // This refactorisation converts the monolithic approach to a series of
5 // independent producer modules, with each modules performing a specific
6 // job as recommended by the 2017 tracker framework
7 //
8 // This module is called a Producer even though its not an ED producer
9 // This was done to be consistant with other TrackingRegion producers
10 // in RecoTracker/TkTrackingRegions
11 //
12 // The module closely follows the other TrackingRegion producers
13 // in RecoTracker/TkTrackingRegions and is intended to become an EDProducer
14 // by TrackingRegionEDProducerT<TrackingRegionsFromSuperClustersProducer>
15 
16 // This module c tracking regions from the superclusters. It mostly
17 // replicates the functionality of the SeedFilter class
18 // although unlike that class, it does not actually create seeds
19 //
20 // Author : Sam Harper (RAL), 2017
21 //
22 //*******************************************************************************
23 
32 
40 
44 
46 
49 
50 //stick this in common tools
51 #include "TEnum.h"
52 #include "TEnumConstant.h"
53 namespace {
54  template <typename MyEnum>
55  MyEnum strToEnum(std::string const& enumConstName) {
56  TEnum* en = TEnum::GetEnum(typeid(MyEnum));
57  if (en != nullptr) {
58  if (TEnumConstant const* enc = en->GetConstant(enumConstName.c_str())) {
59  return static_cast<MyEnum>(enc->GetValue());
60  } else {
61  throw cms::Exception("Configuration") << enumConstName << " is not a valid member of " << typeid(MyEnum).name();
62  }
63  }
64  throw cms::Exception("LogicError") << typeid(MyEnum).name() << " not recognised by ROOT";
65  }
66  template <>
69  if (enumConstName == "kNever")
70  return MyEnum::kNever;
71  else if (enumConstName == "kForSiStrips")
72  return MyEnum::kForSiStrips;
73  else if (enumConstName == "kAlways")
74  return MyEnum::kAlways;
75  else {
76  throw cms::Exception("InvalidConfiguration")
77  << enumConstName << " is not a valid member of " << typeid(MyEnum).name()
78  << " (or strToEnum needs updating, this is a manual translation found at " << __FILE__ << " line " << __LINE__
79  << ")";
80  }
81  }
82 
83 } // namespace
85 public:
86  enum class Charge { NEG = -1, POS = +1 };
87 
88 public:
90 
92 
93  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
94 
95  std::vector<std::unique_ptr<TrackingRegion>> regions(const edm::Event& iEvent,
96  const edm::EventSetup& iSetup) const override;
97 
98 private:
99  GlobalPoint getVtxPos(const edm::Event& iEvent, double& deltaZVertex) const;
100 
101  std::unique_ptr<TrackingRegion> createTrackingRegion(const reco::SuperCluster& superCluster,
102  const GlobalPoint& vtxPos,
103  const double deltaZVertex,
104  const Charge charge,
105  const MeasurementTrackerEvent* measTrackerEvent,
106  const MagneticField& magField) const;
107 
108 private:
109  void validateConfigSettings() const;
110 
111 private:
112  //there are 3 modes in which to define the Z area of the tracking region
113  //1) from first vertex in the passed vertices collection +/- originHalfLength in z (useZInVertex=true)
114  //2) the beamspot +/- nrSigmaForBSDeltaZ* zSigma of beamspot (useZInBeamspot=true)
115  // the zSigma of the beamspot can have a minimum value specified
116  // we do this because a common error is that beamspot has too small of a value
117  //3) defaultZ_ +/- originHalfLength (if useZInVertex and useZInBeamspot are both false)
118  double ptMin_;
126  double defaultZ_;
127  double minBSDeltaZ_;
128  bool precise_;
130 
134  std::vector<edm::EDGetTokenT<std::vector<reco::SuperClusterRef>>> superClustersTokens_;
135 
137 };
138 
139 namespace {
140  template <typename T>
141  edm::Handle<T> getHandle(const edm::Event& event, const edm::EDGetTokenT<T>& token) {
143  event.getByToken(token, handle);
144  return handle;
145  }
146 } // namespace
147 
150  : magFieldToken_{iC.esConsumes()} {
151  edm::ParameterSet regionPSet = cfg.getParameter<edm::ParameterSet>("RegionPSet");
152 
153  ptMin_ = regionPSet.getParameter<double>("ptMin");
154  originRadius_ = regionPSet.getParameter<double>("originRadius");
155  originHalfLength_ = regionPSet.getParameter<double>("originHalfLength");
156  deltaPhiRegion_ = regionPSet.getParameter<double>("deltaPhiRegion");
157  deltaEtaRegion_ = regionPSet.getParameter<double>("deltaEtaRegion");
158  useZInVertex_ = regionPSet.getParameter<bool>("useZInVertex");
159  useZInBeamspot_ = regionPSet.getParameter<bool>("useZInBeamspot");
160  nrSigmaForBSDeltaZ_ = regionPSet.getParameter<double>("nrSigmaForBSDeltaZ");
161  defaultZ_ = regionPSet.getParameter<double>("defaultZ");
162  minBSDeltaZ_ = regionPSet.getParameter<double>("minBSDeltaZ");
163  precise_ = regionPSet.getParameter<bool>("precise");
164  whereToUseMeasTracker_ = strToEnum<RectangularEtaPhiTrackingRegion::UseMeasurementTracker>(
165  regionPSet.getParameter<std::string>("whereToUseMeasTracker"));
166 
167  validateConfigSettings();
168 
169  auto verticesTag = regionPSet.getParameter<edm::InputTag>("vertices");
170  auto beamSpotTag = regionPSet.getParameter<edm::InputTag>("beamSpot");
171  auto superClustersTags = regionPSet.getParameter<std::vector<edm::InputTag>>("superClusters");
172  auto measTrackerEventTag = regionPSet.getParameter<edm::InputTag>("measurementTrackerEvent");
173 
174  if (useZInVertex_) {
175  verticesToken_ = iC.consumes(verticesTag);
176  } else {
177  beamSpotToken_ = iC.consumes(beamSpotTag);
178  }
180  measTrackerEventToken_ = iC.consumes(measTrackerEventTag);
181  }
182  for (const auto& tag : superClustersTags) {
183  superClustersTokens_.emplace_back(iC.consumes(tag));
184  }
185 }
186 
189 
190  desc.add<double>("ptMin", 1.5);
191  desc.add<double>("originRadius", 0.2);
192  desc.add<double>("originHalfLength", 15.0)
193  ->setComment("z range is +/- this value except when using the beamspot (useZInBeamspot=true)");
194  desc.add<double>("deltaPhiRegion", 0.4);
195  desc.add<double>("deltaEtaRegion", 0.1);
196  desc.add<bool>("useZInVertex", false)
197  ->setComment("use the leading vertex position +/-orginHalfLength, mutually exclusive with useZInBeamspot");
198  desc.add<bool>("useZInBeamspot", true)
199  ->setComment(
200  "use the beamspot position +/- nrSigmaForBSDeltaZ* sigmaZ_{bs}, mutually exclusive with useZInVertex");
201  desc.add<double>("nrSigmaForBSDeltaZ", 3.0)
202  ->setComment("# of sigma to extend the z region when using the beamspot, only active if useZInBeamspot=true");
203  desc.add<double>("minBSDeltaZ", 0.0)
204  ->setComment("a minimum value of the beamspot sigma z to use, only active if useZInBeamspot=true");
205  desc.add<double>("defaultZ", 0.)
206  ->setComment("the default z position, only used if useZInVertex and useZInBeamspot are both false");
207  desc.add<bool>("precise", true);
208  desc.add<std::string>("whereToUseMeasTracker", "kNever");
209  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"))
210  ->setComment("only used if useZInBeamspot is true");
211  desc.add<edm::InputTag>("vertices", edm::InputTag())->setComment("only used if useZInVertex is true");
212  desc.add<std::vector<edm::InputTag>>("superClusters",
213  std::vector<edm::InputTag>{edm::InputTag{"hltEgammaSuperClustersToPixelMatch"}});
214  desc.add<edm::InputTag>("measurementTrackerEvent", edm::InputTag());
215 
216  edm::ParameterSetDescription descRegion;
217  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
218 
219  descriptions.add("trackingRegionsFromSuperClusters", descRegion);
220 }
221 
222 std::vector<std::unique_ptr<TrackingRegion>> TrackingRegionsFromSuperClustersProducer::regions(
223  const edm::Event& iEvent, const edm::EventSetup& iSetup) const {
224  std::vector<std::unique_ptr<TrackingRegion>> trackingRegions;
225 
226  double deltaZVertex = 0;
227  GlobalPoint vtxPos = getVtxPos(iEvent, deltaZVertex);
228 
229  const MeasurementTrackerEvent* measTrackerEvent = nullptr;
231  measTrackerEvent = getHandle(iEvent, measTrackerEventToken_).product();
232  }
233  auto const& magField = iSetup.getData(magFieldToken_);
234 
235  for (auto& superClustersToken : superClustersTokens_) {
236  auto superClustersHandle = getHandle(iEvent, superClustersToken);
237  for (auto& superClusterRef : *superClustersHandle) {
238  //do both charge hypothesises
239  trackingRegions.emplace_back(
240  createTrackingRegion(*superClusterRef, vtxPos, deltaZVertex, Charge::POS, measTrackerEvent, magField));
241  trackingRegions.emplace_back(
242  createTrackingRegion(*superClusterRef, vtxPos, deltaZVertex, Charge::NEG, measTrackerEvent, magField));
243  }
244  }
245  return trackingRegions;
246 }
247 
249  if (useZInVertex_) {
250  auto verticesHandle = getHandle(iEvent, verticesToken_);
251  //we throw if the vertices are not there but if no vertex is
252  //recoed in the event, we default to 0,0,defaultZ as the vertex
253  if (!verticesHandle->empty()) {
254  deltaZVertex = originHalfLength_;
255  const auto& pv = verticesHandle->front();
256  return GlobalPoint(pv.x(), pv.y(), pv.z());
257  } else {
258  deltaZVertex = originHalfLength_;
259  return GlobalPoint(0, 0, defaultZ_);
260  }
261  } else {
262  auto beamSpotHandle = getHandle(iEvent, beamSpotToken_);
263  const reco::BeamSpot::Point& bsPos = beamSpotHandle->position();
264 
265  if (useZInBeamspot_) {
266  //as this is what has been done traditionally for e/gamma, others just use sigmaZ
267  const double bsSigmaZ = std::sqrt(beamSpotHandle->sigmaZ() * beamSpotHandle->sigmaZ() +
268  beamSpotHandle->sigmaZ0Error() * beamSpotHandle->sigmaZ0Error());
269  const double sigmaZ = std::max(bsSigmaZ, minBSDeltaZ_);
270  deltaZVertex = nrSigmaForBSDeltaZ_ * sigmaZ;
271 
272  return GlobalPoint(bsPos.x(), bsPos.y(), bsPos.z());
273  } else {
274  deltaZVertex = originHalfLength_;
275  return GlobalPoint(bsPos.x(), bsPos.y(), defaultZ_);
276  }
277  }
278 }
279 
281  const reco::SuperCluster& superCluster,
282  const GlobalPoint& vtxPos,
283  const double deltaZVertex,
284  const Charge charge,
285  const MeasurementTrackerEvent* measTrackerEvent,
286  const MagneticField& magField) const {
287  const GlobalPoint clusterPos(superCluster.position().x(), superCluster.position().y(), superCluster.position().z());
288  const double energy = superCluster.energy();
289 
290  auto fts = trackingTools::ftsFromVertexToPoint(magField, clusterPos, vtxPos, energy, static_cast<int>(charge));
291  return std::make_unique<RectangularEtaPhiTrackingRegion>(fts.momentum(),
292  vtxPos,
293  ptMin_,
295  deltaZVertex,
299  precise_,
300  measTrackerEvent);
301 }
302 
305  throw cms::Exception("InvalidConfiguration")
306  << " when constructing TrackingRegionsFromSuperClustersProducer both useZInVertex (" << useZInVertex_
307  << ") and useZInBeamspot (" << useZInBeamspot_ << ") can not be true as they are mutually exclusive options"
308  << std::endl;
309  }
310 }
311 
313 
318  "TrackingRegionsFromSuperClustersProducer");
ConfigurationDescriptions.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MeasurementTrackerEvent.h
TrackingRegionsFromSuperClustersProducer::originHalfLength_
double originHalfLength_
Definition: TrackingRegionsFromSuperClustersProducer.cc:120
BeamSpotPI::sigmaZ
Definition: BeamSpotPayloadInspectorHelper.h:35
ESHandle.h
reco::SuperCluster
Definition: SuperCluster.h:18
TrackingRegionsFromSuperClustersProducer::TrackingRegionsFromSuperClustersProducer
TrackingRegionsFromSuperClustersProducer(const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc)
Definition: TrackingRegionsFromSuperClustersProducer.cc:148
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT< reco::VertexCollection >
TrackingRegionsFromSuperClustersProducer::deltaPhiRegion_
double deltaPhiRegion_
Definition: TrackingRegionsFromSuperClustersProducer.cc:122
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TrackingRegionsFromSuperClustersProducer
Definition: TrackingRegionsFromSuperClustersProducer.cc:84
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
TrackingRegionsFromSuperClustersProducer::getVtxPos
GlobalPoint getVtxPos(const edm::Event &iEvent, double &deltaZVertex) const
Definition: TrackingRegionsFromSuperClustersProducer.cc:248
TrackingRegionsFromSuperClustersProducer::nrSigmaForBSDeltaZ_
double nrSigmaForBSDeltaZ_
Definition: TrackingRegionsFromSuperClustersProducer.cc:125
edm::Handle
Definition: AssociativeIterator.h:50
TrackingRegionsFromSuperClustersProducer::~TrackingRegionsFromSuperClustersProducer
~TrackingRegionsFromSuperClustersProducer() override
Definition: TrackingRegionsFromSuperClustersProducer.cc:91
TrackingRegionsFromSuperClustersProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TrackingRegionsFromSuperClustersProducer.cc:187
TrackingRegionsFromSuperClustersProducer::Charge::NEG
TrackingRegionProducer.h
TrackingRegionsFromSuperClustersProducer::precise_
bool precise_
Definition: TrackingRegionsFromSuperClustersProducer.cc:128
TrackingRegionsFromSuperClustersProducer::verticesToken_
edm::EDGetTokenT< reco::VertexCollection > verticesToken_
Definition: TrackingRegionsFromSuperClustersProducer.cc:131
TrackingRegionProducerFactory.h
TrackingRegionsFromSuperClustersProducer::useZInVertex_
bool useZInVertex_
Definition: TrackingRegionsFromSuperClustersProducer.cc:123
MakerMacros.h
TrackingRegionsFromSuperClustersProducer::ptMin_
double ptMin_
Definition: TrackingRegionsFromSuperClustersProducer.cc:118
trackingTools::ftsFromVertexToPoint
FreeTrajectoryState ftsFromVertexToPoint(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
Definition: ftsFromVertexToPoint.cc:17
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
TrackingRegionsFromSuperClustersProducer::createTrackingRegion
std::unique_ptr< TrackingRegion > createTrackingRegion(const reco::SuperCluster &superCluster, const GlobalPoint &vtxPos, const double deltaZVertex, const Charge charge, const MeasurementTrackerEvent *measTrackerEvent, const MagneticField &magField) const
Definition: TrackingRegionsFromSuperClustersProducer.cc:280
IdealMagneticFieldRecord.h
TrackingRegionsFromSuperClustersProducer::beamSpotToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: TrackingRegionsFromSuperClustersProducer.cc:132
TrackingRegionsFromSuperClustersProducer::Charge::POS
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
StringToEnumValue.h
AlignmentProducer_cff.beamSpotTag
beamSpotTag
Definition: AlignmentProducer_cff.py:50
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
ParameterSetDescription.h
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
qcdUeDQM_cfi.bsPos
bsPos
Definition: qcdUeDQM_cfi.py:39
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TrackingRegionsFromSuperClustersProducer::Charge
Charge
Definition: TrackingRegionsFromSuperClustersProducer.cc:86
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
TrackingRegionsFromSuperClustersProducer::superClustersTokens_
std::vector< edm::EDGetTokenT< std::vector< reco::SuperClusterRef > > > superClustersTokens_
Definition: TrackingRegionsFromSuperClustersProducer.cc:134
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
RectangularEtaPhiTrackingRegion::UseMeasurementTracker::kNever
MeasurementTrackerEvent
Definition: MeasurementTrackerEvent.h:16
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
TrackingRegionEDProducerT
Definition: TrackingRegionEDProducerT.h:12
edmplugin::PluginFactory
Definition: PluginFactory.h:34
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
TrackingRegionsFromSuperClustersProducer::useZInBeamspot_
bool useZInBeamspot_
Definition: TrackingRegionsFromSuperClustersProducer.cc:124
RectangularEtaPhiTrackingRegion.h
edm::EventSetup
Definition: EventSetup.h:57
TrackingRegionsFromSuperClustersProducer::originRadius_
double originRadius_
Definition: TrackingRegionsFromSuperClustersProducer.cc:119
TrackingRegionsFromSuperClustersProducer::whereToUseMeasTracker_
RectangularEtaPhiTrackingRegion::UseMeasurementTracker whereToUseMeasTracker_
Definition: TrackingRegionsFromSuperClustersProducer.cc:129
RectangularEtaPhiTrackingRegion::UseMeasurementTracker
UseMeasurementTracker
Definition: RectangularEtaPhiTrackingRegion.h:27
ftsFromVertexToPoint.h
cc
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord >
TrackingRegionsFromSuperClustersProducer::magFieldToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: TrackingRegionsFromSuperClustersProducer.cc:136
InputTag.h
reco::CaloCluster::position
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
looper.cfg
cfg
Definition: looper.py:297
VertexFwd.h
TrackingRegionsFromSuperClustersProducer::minBSDeltaZ_
double minBSDeltaZ_
Definition: TrackingRegionsFromSuperClustersProducer.cc:127
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
SuperClusterFwd.h
SuperCluster.h
Exception
Definition: hltDiff.cc:246
TrackingRegionProducer
Definition: TrackingRegionProducer.h:12
TrackingRegionsFromSuperClustersProducer::validateConfigSettings
void validateConfigSettings() const
Definition: TrackingRegionsFromSuperClustersProducer.cc:303
GlobalVector.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
TrackingRegionsFromSuperClustersProducer::measTrackerEventToken_
edm::EDGetTokenT< MeasurementTrackerEvent > measTrackerEventToken_
Definition: TrackingRegionsFromSuperClustersProducer.cc:133
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TrackingRegionsFromSuperClustersProducer::defaultZ_
double defaultZ_
Definition: TrackingRegionsFromSuperClustersProducer.cc:126
TrackingRegionsFromSuperClustersProducer::deltaEtaRegion_
double deltaEtaRegion_
Definition: TrackingRegionsFromSuperClustersProducer.cc:121
ConsumesCollector.h
reco::BeamSpot::Point
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
TrackingRegionsFromSuperClustersProducer::regions
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: TrackingRegionsFromSuperClustersProducer.cc:222
ParameterSet.h
hltSeeds_cff.trackingRegions
trackingRegions
Definition: hltSeeds_cff.py:12
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
MagneticField
Definition: MagneticField.h:19
GlobalPoint.h
reco::CaloCluster::energy
double energy() const
cluster energy
Definition: CaloCluster.h:149
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318
TrackingRegionEDProducerT.h