CMS 3D CMS Logo

TotemRPUVPatternFinder.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 *
7 ****************************************************************************/
8 
16 
22 
25 
27 
28 //----------------------------------------------------------------------------------------------------
29 
37 {
38  public:
40 
41  ~TotemRPUVPatternFinder() override;
42 
43  void produce(edm::Event& e, const edm::EventSetup& c) override;
45 
46  private:
49 
50  unsigned int verbosity;
51 
54 
57 
60 
63 
65  double threshold;
66 
68  double max_a_toFit;
69 
71  struct RPSettings
72  {
75  };
76 
78  std::map<unsigned int, RPSettings> exceptionalSettings;
79 
81 
83  void recognizeAndSelect(TotemRPUVPattern::ProjectionType proj, double z0, double threshold,
84  unsigned int planes_required,
86 };
87 
88 //----------------------------------------------------------------------------------------------------
89 
90 using namespace std;
91 using namespace edm;
92 
93 //----------------------------------------------------------------------------------------------------
94 
96  tagRecHit(conf.getParameter<edm::InputTag>("tagRecHit")),
97  verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
98  minPlanesPerProjectionToSearch(conf.getParameter<unsigned int>("minPlanesPerProjectionToSearch")),
99  minPlanesPerProjectionToFit(conf.getParameter<unsigned int>("minPlanesPerProjectionToFit")),
100  maxHitsPerPlaneToSearch(conf.getParameter<unsigned int>("maxHitsPerPlaneToSearch")),
101  lrcgn(new FastLineRecognition(conf.getParameter<double>("clusterSize_a"), conf.getParameter<double>("clusterSize_b"))),
102  threshold(conf.getParameter<double>("threshold")),
103  max_a_toFit(conf.getParameter<double>("max_a_toFit"))
104 {
105  for (const auto &ps : conf.getParameter< vector<ParameterSet> >("exceptionalSettings"))
106  {
107  unsigned int rpId = ps.getParameter<unsigned int>("rpId");
108 
109  RPSettings settings;
110  settings.minPlanesPerProjectionToFit_U = ps.getParameter<unsigned int>("minPlanesPerProjectionToFit_U");
111  settings.minPlanesPerProjectionToFit_V = ps.getParameter<unsigned int>("minPlanesPerProjectionToFit_V");
112  settings.threshold_U = ps.getParameter<double>("threshold_U");
113  settings.threshold_V = ps.getParameter<double>("threshold_V");
114 
115  exceptionalSettings[rpId] = settings;
116  }
117 
118  detSetVectorTotemRPRecHitToken = consumes<edm::DetSetVector<TotemRPRecHit> >(tagRecHit);
119 
120  produces<DetSetVector<TotemRPUVPattern>>();
121 }
122 
123 //----------------------------------------------------------------------------------------------------
124 
126 {
127  delete lrcgn;
128 }
129 
130 //----------------------------------------------------------------------------------------------------
131 
133  double z0, double threshold_loc, unsigned int planes_required,
135 {
136  // run recognition
137  DetSet<TotemRPUVPattern> newPatterns;
138  lrcgn->getPatterns(hits, z0, threshold_loc, newPatterns);
139 
140  // set pattern properties and copy to the global pattern collection
141  for (auto &p : newPatterns)
142  {
143  p.setProjection(proj);
144 
145  p.setFittable(true);
146 
147  set<unsigned int> planes;
148  for (const auto &ds : p.getHits())
149  planes.insert(TotemRPDetId(ds.detId()).plane());
150 
151  if (planes.size() < planes_required)
152  p.setFittable(false);
153 
154  if (fabs(p.getA()) > max_a_toFit)
155  p.setFittable(false);
156 
157  patterns.push_back(p);
158  }
159 }
160 
161 //----------------------------------------------------------------------------------------------------
162 
164 {
165  if (verbosity > 5)
166  LogVerbatim("TotemRPUVPatternFinder")
167  << ">> TotemRPUVPatternFinder::produce " << event.id().run() << ":" << event.id().event();
168 
169  // geometry
171  es.get<VeryForwardRealGeometryRecord>().get(geometry);
172  if (geometryWatcher.check(es))
173  lrcgn->resetGeometry(geometry.product());
174 
175  // get input
177  event.getByToken(detSetVectorTotemRPRecHitToken, input);
178 
179  // prepare output
180  DetSetVector<TotemRPUVPattern> patternsVector;
181 
182  // split input per RP and per U/V projection
183  struct RPData
184  {
185  DetSetVector<TotemRPRecHit> hits_U, hits_V;
186  map<uint8_t, uint16_t> planeOccupancy_U, planeOccupancy_V;
187  };
188  map<unsigned int, RPData> rpData;
189 
190  for (auto &ids : *input)
191  {
192  TotemRPDetId detId(ids.detId());
193  unsigned int plane = detId.plane();
194  bool uDir = detId.isStripsCoordinateUDirection();
195 
196  CTPPSDetId rpId = detId.getRPId();
197 
198  RPData &data = rpData[rpId];
199 
200  for (auto &h : ids)
201  {
202  if (uDir)
203  {
204  auto &ods = data.hits_U.find_or_insert(ids.detId());
205  ods.push_back(h);
206  data.planeOccupancy_U[plane]++;
207  } else {
208  auto &ods = data.hits_V.find_or_insert(ids.detId());
209  ods.push_back(h);
210  data.planeOccupancy_V[plane]++;
211  }
212  }
213  }
214 
215  // track recognition pot by pot
216  for (auto it : rpData)
217  {
218  CTPPSDetId rpId(it.first);
219  RPData &data = it.second;
220 
221  // merge default and exceptional settings (if available)
222  unsigned int minPlanesPerProjectionToFit_U = minPlanesPerProjectionToFit;
223  unsigned int minPlanesPerProjectionToFit_V = minPlanesPerProjectionToFit;
224  double threshold_U = threshold;
225  double threshold_V = threshold;
226 
227  auto setIt = exceptionalSettings.find(rpId);
228  if (setIt != exceptionalSettings.end())
229  {
230  minPlanesPerProjectionToFit_U = setIt->second.minPlanesPerProjectionToFit_U;
231  minPlanesPerProjectionToFit_V = setIt->second.minPlanesPerProjectionToFit_V;
232  threshold_U = setIt->second.threshold_U;
233  threshold_V = setIt->second.threshold_V;
234  }
235 
236  auto &uColl = data.planeOccupancy_U;
237  auto &vColl = data.planeOccupancy_V;
238 
239  if (verbosity > 5)
240  {
241  LogVerbatim("TotemRPUVPatternFinder")
242  << "\tRP " << rpId
243  << "\n\t\tall planes: u = " << uColl.size() << ", v = " << vColl.size();
244  }
245 
246  // count planes with clean data (no showers, noise, ...)
247  unsigned int uPlanes = 0, vPlanes = 0;
248  for (auto pit : uColl)
249  if (pit.second <= maxHitsPerPlaneToSearch)
250  uPlanes++;
251 
252  for (auto pit : vColl)
253  if (pit.second <= maxHitsPerPlaneToSearch)
254  vPlanes++;
255 
256  if (verbosity > 5)
257  LogVerbatim("TotemRPUVPatternFinder") << "\t\tplanes with clean data: u = " << uPlanes << ", v = " << vPlanes;
258 
259  // discard RPs with too few reasonable planes
261  continue;
262 
263  // prepare data containers
264  DetSet<TotemRPUVPattern> &patterns = patternsVector.find_or_insert(rpId);
265 
266  // "typical" z0 for the RP
267  double z0 = geometry->getRP(rpId)->translation().z();
268 
269  // u then v recognition
270  recognizeAndSelect(TotemRPUVPattern::projU, z0, threshold_U, minPlanesPerProjectionToFit_U, data.hits_U, patterns);
271 
272  recognizeAndSelect(TotemRPUVPattern::projV, z0, threshold_V, minPlanesPerProjectionToFit_V, data.hits_V, patterns);
273 
274  if (verbosity > 5)
275  {
276  LogVerbatim("TotemRPUVPatternFinder") << "\t\tpatterns:";
277  for (const auto &p : patterns)
278  {
279  unsigned int n_hits = 0;
280  for (auto &hds : p.getHits())
281  n_hits += hds.size();
282 
283  LogVerbatim("TotemRPUVPatternFinder")
284  << "\t\t\tproj = " << ((p.getProjection() == TotemRPUVPattern::projU) ? "U" : "V")
285  << ", a = " << p.getA()
286  << ", b = " << p.getB()
287  << ", w = " << p.getW()
288  << ", fittable = " << p.getFittable()
289  << ", hits = " << n_hits;
290  }
291  }
292  }
293 
294  // save output
295  event.put(make_unique<DetSetVector<TotemRPUVPattern>>(patternsVector));
296 }
297 
298 //----------------------------------------------------------------------------------------------------
299 
300 void
302 {
304 
305  desc.add<edm::InputTag>( "tagRecHit", edm::InputTag( "totemRPRecHitProducer" ) )
306  ->setComment( "input rechits collection to retrieve" );
307  desc.addUntracked<unsigned int>( "verbosity", 0 );
308  desc.add<unsigned int>( "maxHitsPerPlaneToSearch", 5 )
309  ->setComment( "minimum threshold of hits multiplicity to flag the pattern as dirty" );
310  desc.add<unsigned int>( "minPlanesPerProjectionToSearch", 3 )
311  ->setComment( "minimal number of reasonable (= not empty and not dirty) planes per projection and per RP, to start the pattern search" );
312  desc.add<double>( "clusterSize_a", 0.02 /* rad */ )
313  ->setComment( "(full) cluster size (in rad) in slope-intercept space" );
314  desc.add<double>( "clusterSize_b", 0.3 /* mm */ );
315 
316  desc.add<double>( "threshold", 2.99 )
317  ->setComment( "minimal weight of (Hough) cluster to accept it as candidate\n"
318  " weight of cluster = sum of weights of contributing points\n"
319  " weight of point = sigma0 / sigma_of_point\n"
320  "most often: weight of point ~ 1, thus cluster weight is roughly number of contributing points" );
321 
322  desc.add<unsigned int>( "minPlanesPerProjectionToFit", 3 )
323  ->setComment( "minimal number of planes (in the recognised patterns) per projection and per RP, to tag the candidate as fittable" );
324 
325  desc.add<bool>( "allowAmbiguousCombination", false )
326  ->setComment( "whether to allow combination of most significant U and V pattern, in case there several of them.\n"
327  "don't set it to True, unless you have reason" );
328 
329  desc.add<double>( "max_a_toFit", 10.0 )
330  ->setComment( "maximal angle (in any projection) to mark the candidate as fittable -> controls track parallelity with beam\n"
331  "huge value -> no constraint" );
332 
333  edm::ParameterSetDescription exceptions_validator;
334  exceptions_validator.add<unsigned int>( "rpId" )
335  ->setComment( "RP id according to CTPPSDetId" );
336  exceptions_validator.add<unsigned int>( "minPlanesPerProjectionToFit_U" );
337  exceptions_validator.add<unsigned int>( "minPlanesPerProjectionToFit_V" );
338  exceptions_validator.add<double>( "threshold_U" );
339  exceptions_validator.add<double>( "threshold_V" );
340 
341  std::vector<edm::ParameterSet> exceptions_default;
342  desc.addVPSet( "exceptionalSettings", exceptions_validator, exceptions_default );
343 
344  descr.add( "totemRPUVPatternFinder", desc );
345 }
346 
347 //----------------------------------------------------------------------------------------------------
348 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
T getParameter(std::string const &) const
TotemRPUVPatternFinder(const edm::ParameterSet &conf)
void push_back(const T &t)
Definition: DetSet.h:68
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
FastLineRecognition * lrcgn
the line recognition algorithm
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint32_t plane() const
Definition: TotemRPDetId.h:49
void getPatterns(const edm::DetSetVector< TotemRPRecHit > &input, double _z0, double threshold, edm::DetSet< TotemRPUVPattern > &patterns)
Event setup record containing the real (actual) geometry information.
static std::string const input
Definition: EdmProvDump.cc:44
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:254
block of (exceptional) settings for 1 RP
std::map< unsigned int, RPSettings > exceptionalSettings
exceptional settings: RP Id –> settings
double threshold
minimal weight of (Hough) cluster to accept it as candidate
void recognizeAndSelect(TotemRPUVPattern::ProjectionType proj, double z0, double threshold, unsigned int planes_required, const edm::DetSetVector< TotemRPRecHit > &hits, edm::DetSet< TotemRPUVPattern > &patterns)
executes line recognition in a projection
unsigned char minPlanesPerProjectionToFit
minimal required number of active planes per projection to mark track candidate as fittable ...
void resetGeometry(const CTPPSGeometry *_g)
DDTranslation translation() const
Definition: DetGeomDesc.h:84
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
edm::EDGetTokenT< edm::DetSetVector< TotemRPRecHit > > detSetVectorTotemRPRecHitToken
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Class performing optimized hough transform to recognize lines.
edm::ESWatcher< VeryForwardRealGeometryRecord > geometryWatcher
void produce(edm::Event &e, const edm::EventSetup &c) override
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
unsigned char minPlanesPerProjectionToSearch
minimal required number of active planes per projection to even start track recognition ...
Class to recognize straight line tracks, based on optimized Hough trasform.
ESHandle< TrackerGeometry > geometry
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static void fillDescriptions(edm::ConfigurationDescriptions &)
unsigned int maxHitsPerPlaneToSearch
above this limit, planes are considered noisy
T const * product() const
Definition: ESHandle.h:86
const DetGeomDesc * getRP(unsigned int id) const
returns geometry of a RP box
double max_a_toFit
maximal angle (in any projection) to mark candidate as fittable - controls track parallelity ...
Definition: event.py:1