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("Configuration") <<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 
110 private:
111  double ptMin_;
112  double originRadius_;
117  bool precise_;
119 
123  std::vector<edm::EDGetTokenT<std::vector<reco::SuperClusterRef>> > superClustersTokens_;
124 
125 };
126 
127 
128 
129 namespace {
130  template<typename T>
131  edm::Handle<T> getHandle(const edm::Event& event,const edm::EDGetTokenT<T> & token){
133  event.getByToken(token,handle);
134  return handle;
135  }
136 }
137 
141 {
142  edm::ParameterSet regionPSet = cfg.getParameter<edm::ParameterSet>("RegionPSet");
143 
144  ptMin_ = regionPSet.getParameter<double>("ptMin");
145  originRadius_ = regionPSet.getParameter<double>("originRadius");
146  originHalfLength_ = regionPSet.getParameter<double>("originHalfLength");
147  deltaPhiRegion_ = regionPSet.getParameter<double>("deltaPhiRegion");
148  deltaEtaRegion_ = regionPSet.getParameter<double>("deltaEtaRegion");
149  useZInVertex_ = regionPSet.getParameter<bool>("useZInVertex");
150  precise_ = regionPSet.getParameter<bool>("precise");
151  whereToUseMeasTracker_ = strToEnum<RectangularEtaPhiTrackingRegion::UseMeasurementTracker>(regionPSet.getParameter<std::string>("whereToUseMeasTracker"));
152 
153  auto verticesTag = regionPSet.getParameter<edm::InputTag>("vertices");
154  auto beamSpotTag = regionPSet.getParameter<edm::InputTag>("beamSpot");
155  auto superClustersTags = regionPSet.getParameter<std::vector<edm::InputTag> >("superClusters");
156  auto measTrackerEventTag = regionPSet.getParameter<edm::InputTag>("measurementTrackerEvent");
157 
158  if(useZInVertex_){
159  verticesToken_ = iC.consumes<reco::VertexCollection>(verticesTag);
160  }else{
161  beamSpotToken_ = iC.consumes<reco::BeamSpot>(beamSpotTag);
162  }
164  measTrackerEventToken_ = iC.consumes<MeasurementTrackerEvent>(measTrackerEventTag);
165  }
166  for(const auto& tag : superClustersTags){
167  superClustersTokens_.emplace_back(iC.consumes<std::vector<reco::SuperClusterRef>>(tag));
168  }
169 }
170 
171 
172 
175 {
177 
178  desc.add<double>("ptMin", 1.5);
179  desc.add<double>("originRadius", 0.2);
180  desc.add<double>("originHalfLength", 15.0);
181  desc.add<double>("deltaPhiRegion",0.4);
182  desc.add<double>("deltaEtaRegion",0.1);
183  desc.add<bool>("useZInVertex", false);
184  desc.add<bool>("precise", true);
185  desc.add<std::string>("whereToUseMeasTracker","kNever");
186  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
187  desc.add<edm::InputTag>("vertices", edm::InputTag());
188  desc.add<std::vector<edm::InputTag> >("superClusters", std::vector<edm::InputTag>{edm::InputTag{"hltEgammaSuperClustersToPixelMatch"}});
189  desc.add<edm::InputTag>("measurementTrackerEvent",edm::InputTag());
190 
191  edm::ParameterSetDescription descRegion;
192  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
193 
194  descriptions.add("trackingRegionsFromSuperClusters", descRegion);
195 }
196 
197 
198 
199 std::vector<std::unique_ptr<TrackingRegion> >
201 regions(const edm::Event& iEvent, const edm::EventSetup& iSetup)const
202 {
203  std::vector<std::unique_ptr<TrackingRegion> > trackingRegions;
204 
205  double deltaZVertex=0;
206  GlobalPoint vtxPos = getVtxPos(iEvent,deltaZVertex);
207 
208  const MeasurementTrackerEvent *measTrackerEvent = nullptr;
210  measTrackerEvent = getHandle(iEvent,measTrackerEventToken_).product();
211  }
212  edm::ESHandle<MagneticField> magFieldHandle;
213  iSetup.get<IdealMagneticFieldRecord>().get(magFieldHandle);
214 
215  for(auto& superClustersToken : superClustersTokens_){
216  auto superClustersHandle = getHandle(iEvent,superClustersToken);
217  for(auto& superClusterRef : *superClustersHandle){
218  //do both charge hypothesises
219  trackingRegions.emplace_back(createTrackingRegion(*superClusterRef,vtxPos,deltaZVertex,Charge::POS,measTrackerEvent,*magFieldHandle));
220  trackingRegions.emplace_back(createTrackingRegion(*superClusterRef,vtxPos,deltaZVertex,Charge::NEG,measTrackerEvent,*magFieldHandle));
221  }
222  }
223  return trackingRegions;
224 }
225 
227 getVtxPos(const edm::Event& iEvent,double& deltaZVertex)const
228 {
229  if(useZInVertex_){
230  auto verticesHandle = getHandle(iEvent,verticesToken_);
231  if(!verticesHandle->empty()){
232  deltaZVertex = originHalfLength_;
233  const auto& pv = verticesHandle->front();
234  return GlobalPoint(pv.x(),pv.y(),pv.z());
235  }
236  }
237 
238  //if the vertex collection is empty or we dont want to use the z in the vertex
239  //we fall back to beamspot mode
240  auto beamSpotHandle = getHandle(iEvent,beamSpotToken_);
241  const reco::BeamSpot::Point& bsPos = beamSpotHandle->position();
242  //SH: this is what SeedFilter did, no idea what its trying to achieve....
243  const double sigmaZ = beamSpotHandle->sigmaZ();
244  const double sigmaZ0Error = beamSpotHandle->sigmaZ0Error();
245  deltaZVertex = 3*std::sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
246  // std::cout <<"z "<<bsPos.z()<<" deltaZ "<<deltaZVertex<<std::endl;
247  //deltaZVertex = 30.;
248  return GlobalPoint(bsPos.x(),bsPos.y(),bsPos.z());
249  //return GlobalPoint(bsPos.x(),bsPos.y(),0);
250 }
251 
252 std::unique_ptr<TrackingRegion>
254 createTrackingRegion(const reco::SuperCluster& superCluster,const GlobalPoint& vtxPos,
255  const double deltaZVertex,const Charge charge,
256  const MeasurementTrackerEvent* measTrackerEvent,
257  const MagneticField& magField)const
258 {
259  const GlobalPoint clusterPos(superCluster.position().x(), superCluster.position().y(), superCluster.position().z());
260  const double energy = superCluster.energy();
261 
262  FreeTrajectoryState freeTrajState = FTSFromVertexToPointFactory::get(magField, clusterPos, vtxPos, energy, static_cast<int>(charge));
263  return std::make_unique<RectangularEtaPhiTrackingRegion>(freeTrajState.momentum(),
264  vtxPos,
265  ptMin_,
267  deltaZVertex,
271  precise_,
272  measTrackerEvent);
273 }
274 
275 #endif
T getParameter(std::string const &) const
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