CMS 3D CMS Logo

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