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 };
136 
137 namespace {
138  template <typename T>
139  edm::Handle<T> getHandle(const edm::Event& event, const edm::EDGetTokenT<T>& token) {
141  event.getByToken(token, handle);
142  return handle;
143  }
144 } // namespace
145 
147  edm::ConsumesCollector&& iC) {
148  edm::ParameterSet regionPSet = cfg.getParameter<edm::ParameterSet>("RegionPSet");
149 
150  ptMin_ = regionPSet.getParameter<double>("ptMin");
151  originRadius_ = regionPSet.getParameter<double>("originRadius");
152  originHalfLength_ = regionPSet.getParameter<double>("originHalfLength");
153  deltaPhiRegion_ = regionPSet.getParameter<double>("deltaPhiRegion");
154  deltaEtaRegion_ = regionPSet.getParameter<double>("deltaEtaRegion");
155  useZInVertex_ = regionPSet.getParameter<bool>("useZInVertex");
156  useZInBeamspot_ = regionPSet.getParameter<bool>("useZInBeamspot");
157  nrSigmaForBSDeltaZ_ = regionPSet.getParameter<double>("nrSigmaForBSDeltaZ");
158  defaultZ_ = regionPSet.getParameter<double>("defaultZ");
159  minBSDeltaZ_ = regionPSet.getParameter<double>("minBSDeltaZ");
160  precise_ = regionPSet.getParameter<bool>("precise");
161  whereToUseMeasTracker_ = strToEnum<RectangularEtaPhiTrackingRegion::UseMeasurementTracker>(
162  regionPSet.getParameter<std::string>("whereToUseMeasTracker"));
163 
165 
166  auto verticesTag = regionPSet.getParameter<edm::InputTag>("vertices");
167  auto beamSpotTag = regionPSet.getParameter<edm::InputTag>("beamSpot");
168  auto superClustersTags = regionPSet.getParameter<std::vector<edm::InputTag>>("superClusters");
169  auto measTrackerEventTag = regionPSet.getParameter<edm::InputTag>("measurementTrackerEvent");
170 
171  if (useZInVertex_) {
172  verticesToken_ = iC.consumes<reco::VertexCollection>(verticesTag);
173  } else {
174  beamSpotToken_ = iC.consumes<reco::BeamSpot>(beamSpotTag);
175  }
177  measTrackerEventToken_ = iC.consumes<MeasurementTrackerEvent>(measTrackerEventTag);
178  }
179  for (const auto& tag : superClustersTags) {
180  superClustersTokens_.emplace_back(iC.consumes<std::vector<reco::SuperClusterRef>>(tag));
181  }
182 }
183 
186 
187  desc.add<double>("ptMin", 1.5);
188  desc.add<double>("originRadius", 0.2);
189  desc.add<double>("originHalfLength", 15.0)
190  ->setComment("z range is +/- this value except when using the beamspot (useZInBeamspot=true)");
191  desc.add<double>("deltaPhiRegion", 0.4);
192  desc.add<double>("deltaEtaRegion", 0.1);
193  desc.add<bool>("useZInVertex", false)
194  ->setComment("use the leading vertex position +/-orginHalfLength, mutually exclusive with useZInBeamspot");
195  desc.add<bool>("useZInBeamspot", true)
196  ->setComment(
197  "use the beamspot position +/- nrSigmaForBSDeltaZ* sigmaZ_{bs}, mutually exclusive with useZInVertex");
198  desc.add<double>("nrSigmaForBSDeltaZ", 3.0)
199  ->setComment("# of sigma to extend the z region when using the beamspot, only active if useZInBeamspot=true");
200  desc.add<double>("minBSDeltaZ", 0.0)
201  ->setComment("a minimum value of the beamspot sigma z to use, only active if useZInBeamspot=true");
202  desc.add<double>("defaultZ", 0.)
203  ->setComment("the default z position, only used if useZInVertex and useZInBeamspot are both false");
204  desc.add<bool>("precise", true);
205  desc.add<std::string>("whereToUseMeasTracker", "kNever");
206  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"))
207  ->setComment("only used if useZInBeamspot is true");
208  desc.add<edm::InputTag>("vertices", edm::InputTag())->setComment("only used if useZInVertex is true");
209  desc.add<std::vector<edm::InputTag>>("superClusters",
210  std::vector<edm::InputTag>{edm::InputTag{"hltEgammaSuperClustersToPixelMatch"}});
211  desc.add<edm::InputTag>("measurementTrackerEvent", edm::InputTag());
212 
213  edm::ParameterSetDescription descRegion;
214  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
215 
216  descriptions.add("trackingRegionsFromSuperClusters", descRegion);
217 }
218 
219 std::vector<std::unique_ptr<TrackingRegion>> TrackingRegionsFromSuperClustersProducer::regions(
220  const edm::Event& iEvent, const edm::EventSetup& iSetup) const {
221  std::vector<std::unique_ptr<TrackingRegion>> trackingRegions;
222 
223  double deltaZVertex = 0;
224  GlobalPoint vtxPos = getVtxPos(iEvent, deltaZVertex);
225 
226  const MeasurementTrackerEvent* measTrackerEvent = nullptr;
228  measTrackerEvent = getHandle(iEvent, measTrackerEventToken_).product();
229  }
230  edm::ESHandle<MagneticField> magFieldHandle;
231  iSetup.get<IdealMagneticFieldRecord>().get(magFieldHandle);
232 
233  for (auto& superClustersToken : superClustersTokens_) {
234  auto superClustersHandle = getHandle(iEvent, superClustersToken);
235  for (auto& superClusterRef : *superClustersHandle) {
236  //do both charge hypothesises
237  trackingRegions.emplace_back(
238  createTrackingRegion(*superClusterRef, vtxPos, deltaZVertex, Charge::POS, measTrackerEvent, *magFieldHandle));
239  trackingRegions.emplace_back(
240  createTrackingRegion(*superClusterRef, vtxPos, deltaZVertex, Charge::NEG, measTrackerEvent, *magFieldHandle));
241  }
242  }
243  return trackingRegions;
244 }
245 
247  if (useZInVertex_) {
248  auto verticesHandle = getHandle(iEvent, verticesToken_);
249  //we throw if the vertices are not there but if no vertex is
250  //recoed in the event, we default to 0,0,defaultZ as the vertex
251  if (!verticesHandle->empty()) {
252  deltaZVertex = originHalfLength_;
253  const auto& pv = verticesHandle->front();
254  return GlobalPoint(pv.x(), pv.y(), pv.z());
255  } else {
256  deltaZVertex = originHalfLength_;
257  return GlobalPoint(0, 0, defaultZ_);
258  }
259  } else {
260  auto beamSpotHandle = getHandle(iEvent, beamSpotToken_);
261  const reco::BeamSpot::Point& bsPos = beamSpotHandle->position();
262 
263  if (useZInBeamspot_) {
264  //as this is what has been done traditionally for e/gamma, others just use sigmaZ
265  const double bsSigmaZ = std::sqrt(beamSpotHandle->sigmaZ() * beamSpotHandle->sigmaZ() +
266  beamSpotHandle->sigmaZ0Error() * beamSpotHandle->sigmaZ0Error());
267  const double sigmaZ = std::max(bsSigmaZ, minBSDeltaZ_);
268  deltaZVertex = nrSigmaForBSDeltaZ_ * sigmaZ;
269 
270  return GlobalPoint(bsPos.x(), bsPos.y(), bsPos.z());
271  } else {
272  deltaZVertex = originHalfLength_;
273  return GlobalPoint(bsPos.x(), bsPos.y(), defaultZ_);
274  }
275  }
276 }
277 
279  const reco::SuperCluster& superCluster,
280  const GlobalPoint& vtxPos,
281  const double deltaZVertex,
282  const Charge charge,
283  const MeasurementTrackerEvent* measTrackerEvent,
284  const MagneticField& magField) const {
285  const GlobalPoint clusterPos(superCluster.position().x(), superCluster.position().y(), superCluster.position().z());
286  const double energy = superCluster.energy();
287 
288  auto fts = trackingTools::ftsFromVertexToPoint(magField, clusterPos, vtxPos, energy, static_cast<int>(charge));
289  return std::make_unique<RectangularEtaPhiTrackingRegion>(fts.momentum(),
290  vtxPos,
291  ptMin_,
293  deltaZVertex,
297  precise_,
298  measTrackerEvent);
299 }
300 
303  throw cms::Exception("InvalidConfiguration")
304  << " when constructing TrackingRegionsFromSuperClustersProducer both useZInVertex (" << useZInVertex_
305  << ") and useZInBeamspot (" << useZInBeamspot_ << ") can not be true as they are mutually exclusive options"
306  << std::endl;
307  }
308 }
309 
311 
316  "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
ESHandle.h
reco::SuperCluster
Definition: SuperCluster.h:18
TrackingRegionsFromSuperClustersProducer::TrackingRegionsFromSuperClustersProducer
TrackingRegionsFromSuperClustersProducer(const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc)
Definition: TrackingRegionsFromSuperClustersProducer.cc:146
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT< reco::VertexCollection >
TrackingRegionsFromSuperClustersProducer::deltaPhiRegion_
double deltaPhiRegion_
Definition: TrackingRegionsFromSuperClustersProducer.cc:122
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TrackingRegionsFromSuperClustersProducer
Definition: TrackingRegionsFromSuperClustersProducer.cc:84
TrackingRegionsFromSuperClustersProducer::getVtxPos
GlobalPoint getVtxPos(const edm::Event &iEvent, double &deltaZVertex) const
Definition: TrackingRegionsFromSuperClustersProducer.cc:246
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:184
TrackingRegionsFromSuperClustersProducer::Charge::NEG
TrackingRegionProducer.h
TrackingRegionsFromSuperClustersProducer::precise_
bool precise_
Definition: TrackingRegionsFromSuperClustersProducer.cc:128
TrackingRegionsFromSuperClustersProducer::verticesToken_
edm::EDGetTokenT< reco::VertexCollection > verticesToken_
Definition: TrackingRegionsFromSuperClustersProducer.cc:131
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
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
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
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
edm::EDGetTokenT::isUninitialized
bool isUninitialized() const
Definition: EDGetToken.h:70
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:278
reco::BeamSpot
Definition: BeamSpot.h:21
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
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
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
MeasurementTrackerEvent
Definition: MeasurementTrackerEvent.h:15
edm::ParameterSet
Definition: ParameterSet.h:36
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
get
#define get
cc
InputTag.h
reco::CaloCluster::position
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
looper.cfg
cfg
Definition: looper.py:297
VertexFwd.h
TrackingRegionsFromSuperClustersProducer::minBSDeltaZ_
double minBSDeltaZ_
Definition: TrackingRegionsFromSuperClustersProducer.cc:127
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
SuperClusterFwd.h
SuperCluster.h
Exception
Definition: hltDiff.cc:246
TrackingRegionProducer
Definition: TrackingRegionProducer.h:12
TrackingRegionsFromSuperClustersProducer::validateConfigSettings
void validateConfigSettings() const
Definition: TrackingRegionsFromSuperClustersProducer.cc:301
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
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:219
ParameterSet.h
edm::ParameterDescriptionNode::setComment
void setComment(std::string const &value)
Definition: ParameterDescriptionNode.cc:106
hltSeeds_cff.trackingRegions
trackingRegions
Definition: hltSeeds_cff.py:12
fftjetvertexadder_cfi.sigmaZ
sigmaZ
Definition: fftjetvertexadder_cfi.py:32
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:39
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
TrackingRegionEDProducerT.h