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 
48 
50 
53 
54 //stick this in common tools
55 #include "TEnum.h"
56 #include "TEnumConstant.h"
57 namespace {
58  template <typename MyEnum>
59  MyEnum strToEnum(std::string const& enumConstName) {
60  TEnum* en = TEnum::GetEnum(typeid(MyEnum));
61  if (en != nullptr) {
62  if (TEnumConstant const* enc = en->GetConstant(enumConstName.c_str())) {
63  return static_cast<MyEnum>(enc->GetValue());
64  } else {
65  throw cms::Exception("Configuration") << enumConstName << " is not a valid member of " << typeid(MyEnum).name();
66  }
67  }
68  throw cms::Exception("LogicError") << typeid(MyEnum).name() << " not recognised by ROOT";
69  }
70  template <>
73  if (enumConstName == "kNever")
74  return MyEnum::kNever;
75  else if (enumConstName == "kForSiStrips")
76  return MyEnum::kForSiStrips;
77  else if (enumConstName == "kAlways")
78  return MyEnum::kAlways;
79  else {
80  throw cms::Exception("InvalidConfiguration")
81  << enumConstName << " is not a valid member of " << typeid(MyEnum).name()
82  << " (or strToEnum needs updating, this is a manual translation found at " << __FILE__ << " line " << __LINE__
83  << ")";
84  }
85  }
86 
87 } // namespace
89 public:
90  enum class Charge { NEG = -1, POS = +1 };
91 
92 public:
94 
96 
97  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
98 
99  std::vector<std::unique_ptr<TrackingRegion>> regions(const edm::Event& iEvent,
100  const edm::EventSetup& iSetup) const override;
101 
102 private:
103  GlobalPoint getVtxPos(const edm::Event& iEvent, double& deltaZVertex) const;
104 
105  std::unique_ptr<TrackingRegion> createTrackingRegion(const reco::SuperCluster& superCluster,
106  const GlobalPoint& vtxPos,
107  const double deltaZVertex,
108  const Charge charge,
109  const MeasurementTrackerEvent* measTrackerEvent,
110  const MagneticField& magField,
111  const MultipleScatteringParametrisationMaker* msmaker) const;
112 
113 private:
114  void validateConfigSettings() const;
115 
116 private:
117  //there are 3 modes in which to define the Z area of the tracking region
118  //1) from first vertex in the passed vertices collection +/- originHalfLength in z (useZInVertex=true)
119  //2) the beamspot +/- nrSigmaForBSDeltaZ* zSigma of beamspot (useZInBeamspot=true)
120  // the zSigma of the beamspot can have a minimum value specified
121  // we do this because a common error is that beamspot has too small of a value
122  //3) defaultZ_ +/- originHalfLength (if useZInVertex and useZInBeamspot are both false)
123  double ptMin_;
131  double defaultZ_;
132  double minBSDeltaZ_;
133  bool precise_;
135 
139  std::vector<edm::EDGetTokenT<std::vector<reco::SuperClusterRef>>> superClustersTokens_;
140 
143 };
144 
145 namespace {
146  template <typename T>
147  edm::Handle<T> getHandle(const edm::Event& event, const edm::EDGetTokenT<T>& token) {
149  event.getByToken(token, handle);
150  return handle;
151  }
152 } // namespace
153 
156  : magFieldToken_{iC.esConsumes()} {
157  edm::ParameterSet regionPSet = cfg.getParameter<edm::ParameterSet>("RegionPSet");
158 
159  ptMin_ = regionPSet.getParameter<double>("ptMin");
160  originRadius_ = regionPSet.getParameter<double>("originRadius");
161  originHalfLength_ = regionPSet.getParameter<double>("originHalfLength");
162  deltaPhiRegion_ = regionPSet.getParameter<double>("deltaPhiRegion");
163  deltaEtaRegion_ = regionPSet.getParameter<double>("deltaEtaRegion");
164  useZInVertex_ = regionPSet.getParameter<bool>("useZInVertex");
165  useZInBeamspot_ = regionPSet.getParameter<bool>("useZInBeamspot");
166  nrSigmaForBSDeltaZ_ = regionPSet.getParameter<double>("nrSigmaForBSDeltaZ");
167  defaultZ_ = regionPSet.getParameter<double>("defaultZ");
168  minBSDeltaZ_ = regionPSet.getParameter<double>("minBSDeltaZ");
169  precise_ = regionPSet.getParameter<bool>("precise");
170  whereToUseMeasTracker_ = strToEnum<RectangularEtaPhiTrackingRegion::UseMeasurementTracker>(
171  regionPSet.getParameter<std::string>("whereToUseMeasTracker"));
172 
173  validateConfigSettings();
174 
175  auto verticesTag = regionPSet.getParameter<edm::InputTag>("vertices");
176  auto beamSpotTag = regionPSet.getParameter<edm::InputTag>("beamSpot");
177  auto superClustersTags = regionPSet.getParameter<std::vector<edm::InputTag>>("superClusters");
178  auto measTrackerEventTag = regionPSet.getParameter<edm::InputTag>("measurementTrackerEvent");
179 
180  if (useZInVertex_) {
181  verticesToken_ = iC.consumes(verticesTag);
182  } else {
183  beamSpotToken_ = iC.consumes(beamSpotTag);
184  }
186  measTrackerEventToken_ = iC.consumes(measTrackerEventTag);
187  }
188  for (const auto& tag : superClustersTags) {
189  superClustersTokens_.emplace_back(iC.consumes(tag));
190  }
191  if (precise_) {
192  msmakerToken_ = iC.esConsumes();
193  }
194 }
195 
198 
199  desc.add<double>("ptMin", 1.5);
200  desc.add<double>("originRadius", 0.2);
201  desc.add<double>("originHalfLength", 15.0)
202  ->setComment("z range is +/- this value except when using the beamspot (useZInBeamspot=true)");
203  desc.add<double>("deltaPhiRegion", 0.4);
204  desc.add<double>("deltaEtaRegion", 0.1);
205  desc.add<bool>("useZInVertex", false)
206  ->setComment("use the leading vertex position +/-orginHalfLength, mutually exclusive with useZInBeamspot");
207  desc.add<bool>("useZInBeamspot", true)
208  ->setComment(
209  "use the beamspot position +/- nrSigmaForBSDeltaZ* sigmaZ_{bs}, mutually exclusive with useZInVertex");
210  desc.add<double>("nrSigmaForBSDeltaZ", 3.0)
211  ->setComment("# of sigma to extend the z region when using the beamspot, only active if useZInBeamspot=true");
212  desc.add<double>("minBSDeltaZ", 0.0)
213  ->setComment("a minimum value of the beamspot sigma z to use, only active if useZInBeamspot=true");
214  desc.add<double>("defaultZ", 0.)
215  ->setComment("the default z position, only used if useZInVertex and useZInBeamspot are both false");
216  desc.add<bool>("precise", true);
217  desc.add<std::string>("whereToUseMeasTracker", "kNever");
218  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"))
219  ->setComment("only used if useZInBeamspot is true");
220  desc.add<edm::InputTag>("vertices", edm::InputTag())->setComment("only used if useZInVertex is true");
221  desc.add<std::vector<edm::InputTag>>("superClusters",
222  std::vector<edm::InputTag>{edm::InputTag{"hltEgammaSuperClustersToPixelMatch"}});
223  desc.add<edm::InputTag>("measurementTrackerEvent", edm::InputTag());
224 
225  edm::ParameterSetDescription descRegion;
226  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
227 
228  descriptions.add("trackingRegionsFromSuperClusters", descRegion);
229 }
230 
231 std::vector<std::unique_ptr<TrackingRegion>> TrackingRegionsFromSuperClustersProducer::regions(
232  const edm::Event& iEvent, const edm::EventSetup& iSetup) const {
233  std::vector<std::unique_ptr<TrackingRegion>> trackingRegions;
234 
235  double deltaZVertex = 0;
236  GlobalPoint vtxPos = getVtxPos(iEvent, deltaZVertex);
237 
238  const MeasurementTrackerEvent* measTrackerEvent = nullptr;
240  measTrackerEvent = getHandle(iEvent, measTrackerEventToken_).product();
241  }
242  auto const& magField = iSetup.getData(magFieldToken_);
243  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
244  if (precise_) {
245  msmaker = &iSetup.getData(msmakerToken_);
246  }
247 
248  for (auto& superClustersToken : superClustersTokens_) {
249  auto superClustersHandle = getHandle(iEvent, superClustersToken);
250  for (auto& superClusterRef : *superClustersHandle) {
251  //do both charge hypothesises
253  *superClusterRef, vtxPos, deltaZVertex, Charge::POS, measTrackerEvent, magField, msmaker));
255  *superClusterRef, vtxPos, deltaZVertex, Charge::NEG, measTrackerEvent, magField, msmaker));
256  }
257  }
258  return trackingRegions;
259 }
260 
262  if (useZInVertex_) {
263  auto verticesHandle = getHandle(iEvent, verticesToken_);
264  //we throw if the vertices are not there but if no vertex is
265  //recoed in the event, we default to 0,0,defaultZ as the vertex
266  if (!verticesHandle->empty()) {
267  deltaZVertex = originHalfLength_;
268  const auto& pv = verticesHandle->front();
269  return GlobalPoint(pv.x(), pv.y(), pv.z());
270  } else {
271  deltaZVertex = originHalfLength_;
272  return GlobalPoint(0, 0, defaultZ_);
273  }
274  } else {
275  auto beamSpotHandle = getHandle(iEvent, beamSpotToken_);
276  const reco::BeamSpot::Point& bsPos = beamSpotHandle->position();
277 
278  if (useZInBeamspot_) {
279  //as this is what has been done traditionally for e/gamma, others just use sigmaZ
280  const double bsSigmaZ = std::sqrt(beamSpotHandle->sigmaZ() * beamSpotHandle->sigmaZ() +
281  beamSpotHandle->sigmaZ0Error() * beamSpotHandle->sigmaZ0Error());
282  const double sigmaZ = std::max(bsSigmaZ, minBSDeltaZ_);
283  deltaZVertex = nrSigmaForBSDeltaZ_ * sigmaZ;
284 
285  return GlobalPoint(bsPos.x(), bsPos.y(), bsPos.z());
286  } else {
287  deltaZVertex = originHalfLength_;
288  return GlobalPoint(bsPos.x(), bsPos.y(), defaultZ_);
289  }
290  }
291 }
292 
294  const reco::SuperCluster& superCluster,
295  const GlobalPoint& vtxPos,
296  const double deltaZVertex,
297  const Charge charge,
298  const MeasurementTrackerEvent* measTrackerEvent,
299  const MagneticField& magField,
300  const MultipleScatteringParametrisationMaker* msmaker) const {
301  const GlobalPoint clusterPos(superCluster.position().x(), superCluster.position().y(), superCluster.position().z());
302  const double energy = superCluster.energy();
303 
304  auto fts = trackingTools::ftsFromVertexToPoint(magField, clusterPos, vtxPos, energy, static_cast<int>(charge));
305  return std::make_unique<RectangularEtaPhiTrackingRegion>(fts.momentum(),
306  vtxPos,
307  ptMin_,
309  deltaZVertex,
312  magField,
313  msmaker,
314  precise_,
316  measTrackerEvent);
317 }
318 
321  throw cms::Exception("InvalidConfiguration")
322  << " when constructing TrackingRegionsFromSuperClustersProducer both useZInVertex (" << useZInVertex_
323  << ") and useZInBeamspot (" << useZInBeamspot_ << ") can not be true as they are mutually exclusive options"
324  << std::endl;
325  }
326 }
327 
329 
334  "TrackingRegionsFromSuperClustersProducer");
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &iEvent, const edm::EventSetup &iSetup) const override
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
RectangularEtaPhiTrackingRegion::UseMeasurementTracker whereToUseMeasTracker_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FreeTrajectoryState ftsFromVertexToPoint(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
TrackingRegionsFromSuperClustersProducer(const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc)
GlobalPoint getVtxPos(const edm::Event &iEvent, double &deltaZVertex) const
std::vector< edm::EDGetTokenT< std::vector< reco::SuperClusterRef > > > superClustersTokens_
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
def pv(vc)
Definition: MetAnalyzer.py:7
bool getData(T &iHolder) const
Definition: EventSetup.h:122
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double energy() const
cluster energy
Definition: CaloCluster.h:149
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::VertexCollection > verticesToken_
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 MultipleScatteringParametrisationMaker *msmaker) const
edm::EDGetTokenT< MeasurementTrackerEvent > measTrackerEventToken_
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > msmakerToken_
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: event.py:1