test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual ~TotemRPUVPatternFinder();
42 
43  virtual void produce(edm::Event& e, const edm::EventSetup& c) override;
44 
45  private:
48 
49  unsigned int verbosity;
50 
53 
56 
59 
62 
64  double threshold;
65 
67  double max_a_toFit;
68 
70  struct RPSettings
71  {
74  };
75 
77  std::map<unsigned int, RPSettings> exceptionalSettings;
78 
80 
83  unsigned int planes_required,
85 };
86 
87 //----------------------------------------------------------------------------------------------------
88 
89 using namespace std;
90 using namespace edm;
91 
92 //----------------------------------------------------------------------------------------------------
93 
95  tagRecHit(conf.getParameter<edm::InputTag>("tagRecHit")),
96  verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
97  minPlanesPerProjectionToSearch(conf.getParameter<unsigned int>("minPlanesPerProjectionToSearch")),
98  minPlanesPerProjectionToFit(conf.getParameter<unsigned int>("minPlanesPerProjectionToFit")),
99  maxHitsPerPlaneToSearch(conf.getParameter<unsigned int>("maxHitsPerPlaneToSearch")),
100  lrcgn(new FastLineRecognition(conf.getParameter<double>("clusterSize_a"), conf.getParameter<double>("clusterSize_b"))),
101  threshold(conf.getParameter<double>("threshold")),
102  max_a_toFit(conf.getParameter<double>("max_a_toFit"))
103 {
104  for (const auto &ps : conf.getParameter< vector<ParameterSet> >("exceptionalSettings"))
105  {
106  unsigned int rpId = ps.getParameter<unsigned int>("rpId");
107 
108  RPSettings settings;
109  settings.minPlanesPerProjectionToFit_U = ps.getParameter<unsigned int>("minPlanesPerProjectionToFit_U");
110  settings.minPlanesPerProjectionToFit_V = ps.getParameter<unsigned int>("minPlanesPerProjectionToFit_V");
111  settings.threshold_U = ps.getParameter<double>("threshold_U");
112  settings.threshold_V = ps.getParameter<double>("threshold_V");
113 
114  exceptionalSettings[rpId] = settings;
115  }
116 
117  detSetVectorTotemRPRecHitToken = consumes<edm::DetSetVector<TotemRPRecHit> >(tagRecHit);
118 
119  produces<DetSetVector<TotemRPUVPattern>>();
120 }
121 
122 //----------------------------------------------------------------------------------------------------
123 
125 {
126  delete lrcgn;
127 }
128 
129 //----------------------------------------------------------------------------------------------------
130 
132  double z0, double threshold_loc, unsigned int planes_required,
134 {
135  // run recognition
136  DetSet<TotemRPUVPattern> newPatterns;
137  lrcgn->getPatterns(hits, z0, threshold_loc, newPatterns);
138 
139  // set pattern properties and copy to the global pattern collection
140  for (auto &p : newPatterns)
141  {
142  p.setProjection(proj);
143 
144  p.setFittable(true);
145 
146  set<unsigned int> planes;
147  for (const auto &ds : p.getHits())
148  planes.insert(TotemRPDetId(ds.detId()).plane());
149 
150  if (planes.size() < planes_required)
151  p.setFittable(false);
152 
153  if (fabs(p.getA()) > max_a_toFit)
154  p.setFittable(false);
155 
156  patterns.push_back(p);
157  }
158 }
159 
160 //----------------------------------------------------------------------------------------------------
161 
163 {
164  if (verbosity > 5)
165  LogVerbatim("TotemRPUVPatternFinder")
166  << ">> TotemRPUVPatternFinder::produce " << event.id().run() << ":" << event.id().event();
167 
168  // geometry
170  es.get<VeryForwardRealGeometryRecord>().get(geometry);
171  if (geometryWatcher.check(es))
172  lrcgn->resetGeometry(geometry.product());
173 
174  // get input
176  event.getByToken(detSetVectorTotemRPRecHitToken, input);
177 
178  // prepare output
179  DetSetVector<TotemRPUVPattern> patternsVector;
180 
181  // split input per RP and per U/V projection
182  struct RPData
183  {
184  DetSetVector<TotemRPRecHit> hits_U, hits_V;
185  map<uint8_t, uint16_t> planeOccupancy_U, planeOccupancy_V;
186  };
187  map<unsigned int, RPData> rpData;
188 
189  for (auto &ids : *input)
190  {
191  TotemRPDetId detId(ids.detId());
192  unsigned int plane = detId.plane();
193  bool uDir = detId.isStripsCoordinateUDirection();
194 
195  CTPPSDetId rpId = detId.getRPId();
196 
197  RPData &data = rpData[rpId];
198 
199  for (auto &h : ids)
200  {
201  if (uDir)
202  {
203  auto &ods = data.hits_U.find_or_insert(ids.detId());
204  ods.push_back(h);
205  data.planeOccupancy_U[plane]++;
206  } else {
207  auto &ods = data.hits_V.find_or_insert(ids.detId());
208  ods.push_back(h);
209  data.planeOccupancy_V[plane]++;
210  }
211  }
212  }
213 
214  // track recognition pot by pot
215  for (auto it : rpData)
216  {
217  TotemRPDetId rpId(it.first);
218  unsigned int rpDecId = rpId.getRPDecimalId();
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(rpDecId);
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 " << rpDecId
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(rpDecId);
265 
266  // "typical" z0 for the RP
267  double z0 = geometry->GetRPDevice(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 
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
FastLineRecognition * lrcgn
the line recognition algorithm
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void resetGeometry(const TotemRPGeometry *_g)
uint32_t getRPDecimalId() const
Definition: TotemRPDetId.h:93
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
const PhiMemoryImage patterns[9]
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 –&gt; 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 ...
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
edm::EDGetTokenT< edm::DetSetVector< TotemRPRecHit > > detSetVectorTotemRPRecHitToken
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Class performing optimized hough transform to recognize lines.
edm::ESWatcher< VeryForwardRealGeometryRecord > geometryWatcher
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int maxHitsPerPlaneToSearch
above this limit, planes are considered noisy
double max_a_toFit
maximal angle (in any projection) to mark candidate as fittable - controls track parallelity ...