CMS 3D CMS Logo

CandidateSeededTrackingRegionsProducer.h
Go to the documentation of this file.
1 #ifndef CandidateSeededTrackingRegionsProducer_h
2 #define CandidateSeededTrackingRegionsProducer_h
3 
7 
23 
50 public:
52 
54  : token_field(iC.esConsumes()) {
55  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
56 
57  // operation mode
58  std::string modeString = regPSet.getParameter<std::string>("mode");
59  if (modeString == "BeamSpotFixed")
61  else if (modeString == "BeamSpotSigma")
63  else if (modeString == "VerticesFixed")
65  else if (modeString == "VerticesSigma")
67  else
68  edm::LogError("CandidateSeededTrackingRegionsProducer") << "Unknown mode string: " << modeString;
69 
70  // basic inputs
71  token_input = iC.consumes<reco::CandidateView>(regPSet.getParameter<edm::InputTag>("input"));
72  m_maxNRegions = regPSet.getParameter<int>("maxNRegions");
73  token_beamSpot = iC.consumes<reco::BeamSpot>(regPSet.getParameter<edm::InputTag>("beamSpot"));
74  m_maxNVertices = 1;
76  token_vertex = iC.consumes<reco::VertexCollection>(regPSet.getParameter<edm::InputTag>("vertexCollection"));
77  m_maxNVertices = regPSet.getParameter<int>("maxNVertices");
78  }
79 
80  // RectangularEtaPhiTrackingRegion parameters:
81  m_ptMin = regPSet.getParameter<double>("ptMin");
82  m_originRadius = regPSet.getParameter<double>("originRadius");
83  m_zErrorBeamSpot = regPSet.getParameter<double>("zErrorBeamSpot");
84  m_deltaEta = regPSet.getParameter<double>("deltaEta");
85  m_deltaPhi = regPSet.getParameter<double>("deltaPhi");
86  m_precise = regPSet.getParameter<bool>("precise");
88  regPSet.getParameter<std::string>("whereToUseMeasurementTracker"));
91  iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
92  }
93  m_searchOpt = false;
94  if (regPSet.exists("searchOpt"))
95  m_searchOpt = regPSet.getParameter<bool>("searchOpt");
96 
97  // mode-dependent z-halflength of tracking regions
98  if (m_mode == VERTICES_SIGMA)
99  m_nSigmaZVertex = regPSet.getParameter<double>("nSigmaZVertex");
100  if (m_mode == VERTICES_FIXED)
101  m_zErrorVetex = regPSet.getParameter<double>("zErrorVetex");
102  m_nSigmaZBeamSpot = -1.;
103  if (m_mode == BEAM_SPOT_SIGMA) {
104  m_nSigmaZBeamSpot = regPSet.getParameter<double>("nSigmaZBeamSpot");
105  if (m_nSigmaZBeamSpot < 0.)
106  edm::LogError("CandidateSeededTrackingRegionsProducer")
107  << "nSigmaZBeamSpot must be positive for BeamSpotSigma mode!";
108  }
109  if (m_precise) {
110  token_msmaker = iC.esConsumes();
111  }
112  }
113 
114  ~CandidateSeededTrackingRegionsProducer() override = default;
115 
118 
119  desc.add<std::string>("mode", "BeamSpotFixed");
120 
121  desc.add<edm::InputTag>("input", edm::InputTag(""));
122  desc.add<int>("maxNRegions", 10);
123  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
124  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
125  desc.add<int>("maxNVertices", 1);
126 
127  desc.add<double>("ptMin", 0.9);
128  desc.add<double>("originRadius", 0.2);
129  desc.add<double>("zErrorBeamSpot", 24.2);
130  desc.add<double>("deltaEta", 0.5);
131  desc.add<double>("deltaPhi", 0.5);
132  desc.add<bool>("precise", true);
133 
134  desc.add<double>("nSigmaZVertex", 3.);
135  desc.add<double>("zErrorVetex", 0.2);
136  desc.add<double>("nSigmaZBeamSpot", 4.);
137 
138  desc.add<std::string>("whereToUseMeasurementTracker", "ForSiStrips");
139  desc.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
140 
141  desc.add<bool>("searchOpt", false);
142 
143  // Only for backwards-compatibility
144  edm::ParameterSetDescription descRegion;
145  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
146 
147  descriptions.add("seededTrackingRegionsFromBeamSpotFixedZLength", descRegion);
148  }
149 
150  std::vector<std::unique_ptr<TrackingRegion> > regions(const edm::Event& e, const edm::EventSetup& es) const override {
151  std::vector<std::unique_ptr<TrackingRegion> > result;
152 
153  // pick up the candidate objects of interest
155  e.getByToken(token_input, objects);
156  size_t n_objects = objects->size();
157  if (n_objects == 0)
158  return result;
159 
160  // always need the beam spot (as a fall back strategy for vertex modes)
162  e.getByToken(token_beamSpot, bs);
163  if (!bs.isValid())
164  return result;
165 
166  // this is a default origin for all modes
167  GlobalPoint default_origin(bs->x0(), bs->y0(), bs->z0());
168 
169  // vector of origin & halfLength pairs:
170  std::vector<std::pair<GlobalPoint, float> > origins;
171 
172  // fill the origins and halfLengths depending on the mode
174  origins.push_back(std::make_pair(
175  default_origin, (m_mode == BEAM_SPOT_FIXED) ? m_zErrorBeamSpot : m_nSigmaZBeamSpot * bs->sigmaZ()));
176  } else if (m_mode == VERTICES_FIXED || m_mode == VERTICES_SIGMA) {
178  e.getByToken(token_vertex, vertices);
179  int n_vert = 0;
180  for (reco::VertexCollection::const_iterator v = vertices->begin();
181  v != vertices->end() && n_vert < m_maxNVertices;
182  ++v) {
183  if (v->isFake() || !v->isValid())
184  continue;
185 
186  origins.push_back(std::make_pair(GlobalPoint(v->x(), v->y(), v->z()),
187  (m_mode == VERTICES_FIXED) ? m_zErrorVetex : m_nSigmaZVertex * v->zError()));
188  ++n_vert;
189  }
190  // no-vertex fall-back case:
191  if (origins.empty()) {
192  origins.push_back(std::make_pair(
193  default_origin, (m_nSigmaZBeamSpot > 0.) ? m_nSigmaZBeamSpot * bs->z0Error() : m_zErrorBeamSpot));
194  }
195  }
196 
200  e.getByToken(token_measurementTracker, hmte);
201  measurementTracker = hmte.product();
202  }
203 
204  const auto& field = es.getData(token_field);
205  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
206  if (m_precise) {
207  msmaker = &es.getData(token_msmaker);
208  }
209 
210  // create tracking regions (maximum MaxNRegions of them) in directions of the
211  // objects of interest (we expect that the collection was sorted in decreasing pt order)
212  int n_regions = 0;
213  for (size_t i = 0; i < n_objects && n_regions < m_maxNRegions; ++i) {
214  const reco::Candidate& object = (*objects)[i];
215  GlobalVector direction(object.momentum().x(), object.momentum().y(), object.momentum().z());
216 
217  for (size_t j = 0; j < origins.size() && n_regions < m_maxNRegions; ++j) {
218  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(direction,
219  origins[j].first,
220  m_ptMin,
222  origins[j].second,
223  m_deltaEta,
224  m_deltaPhi,
225  field,
226  msmaker,
227  m_precise,
230  m_searchOpt));
231  ++n_regions;
232  }
233  }
234  //std::cout<<"n_seeded_regions = "<<n_regions<<std::endl;
235  edm::LogInfo("CandidateSeededTrackingRegionsProducer") << "produced " << n_regions << " regions";
236 
237  return result;
238  }
239 
240 private:
242 
248 
249  float m_ptMin;
252  float m_deltaEta;
253  float m_deltaPhi;
254  bool m_precise;
260 
264 };
265 
266 #endif
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > token_msmaker
RectangularEtaPhiTrackingRegion::UseMeasurementTracker m_whereToUseMeasurementTracker
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool exists(std::string const &parameterName) const
checks if a parameter exists
CandidateSeededTrackingRegionsProducer(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::EDGetTokenT< reco::VertexCollection > token_vertex
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > token_field
Log< level::Error, false > LogError
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &e, const edm::EventSetup &es) const override
U second(std::pair< T, U > const &p)
~CandidateSeededTrackingRegionsProducer() override=default
edm::EDGetTokenT< MeasurementTrackerEvent > token_measurementTracker
bool getData(T &iHolder) const
Definition: EventSetup.h:122
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Info, false > LogInfo
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)