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::rawToDecId(ds.detId()) % 10);
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  unsigned int detId = TotemRPDetId::rawToDecId(ids.detId());
192  unsigned int rpId = TotemRPDetId::rpOfDet(detId);
193  unsigned int plane = detId % 10;
195 
196  RPData &data = rpData[rpId];
197 
198  for (auto &h : ids)
199  {
200  if (uDir)
201  {
202  auto &ods = data.hits_U.find_or_insert(ids.detId());
203  ods.push_back(h);
204  data.planeOccupancy_U[plane]++;
205  } else {
206  auto &ods = data.hits_V.find_or_insert(ids.detId());
207  ods.push_back(h);
208  data.planeOccupancy_V[plane]++;
209  }
210  }
211  }
212 
213  // track recognition pot by pot
214  for (auto it : rpData)
215  {
216  unsigned int rpId = it.first;
217  RPData &data = it.second;
218 
219  // merge default and exceptional settings (if available)
220  unsigned int minPlanesPerProjectionToFit_U = minPlanesPerProjectionToFit;
221  unsigned int minPlanesPerProjectionToFit_V = minPlanesPerProjectionToFit;
222  double threshold_U = threshold;
223  double threshold_V = threshold;
224 
225  auto setIt = exceptionalSettings.find(rpId);
226  if (setIt != exceptionalSettings.end())
227  {
228  minPlanesPerProjectionToFit_U = setIt->second.minPlanesPerProjectionToFit_U;
229  minPlanesPerProjectionToFit_V = setIt->second.minPlanesPerProjectionToFit_V;
230  threshold_U = setIt->second.threshold_U;
231  threshold_V = setIt->second.threshold_V;
232  }
233 
234  auto &uColl = data.planeOccupancy_U;
235  auto &vColl = data.planeOccupancy_V;
236 
237  if (verbosity > 5)
238  {
239  LogVerbatim("TotemRPUVPatternFinder")
240  << "\tRP " << rpId
241  << "\n\t\tall planes: u = " << uColl.size() << ", v = " << vColl.size();
242  }
243 
244  // count planes with clean data (no showers, noise, ...)
245  unsigned int uPlanes = 0, vPlanes = 0;
246  for (auto pit : uColl)
247  if (pit.second <= maxHitsPerPlaneToSearch)
248  uPlanes++;
249 
250  for (auto pit : vColl)
251  if (pit.second <= maxHitsPerPlaneToSearch)
252  vPlanes++;
253 
254  if (verbosity > 5)
255  LogVerbatim("TotemRPUVPatternFinder") << "\t\tplanes with clean data: u = " << uPlanes << ", v = " << vPlanes;
256 
257  // discard RPs with too few reasonable planes
259  continue;
260 
261  // prepare data containers
262  DetSet<TotemRPUVPattern> &patterns = patternsVector.find_or_insert(rpId);
263 
264  // "typical" z0 for the RP
265  double z0 = geometry->GetRPDevice(rpId)->translation().z();
266 
267  // u then v recognition
268  recognizeAndSelect(TotemRPUVPattern::projU, z0, threshold_U, minPlanesPerProjectionToFit_U, data.hits_U, patterns);
269 
270  recognizeAndSelect(TotemRPUVPattern::projV, z0, threshold_V, minPlanesPerProjectionToFit_V, data.hits_V, patterns);
271 
272  if (verbosity > 5)
273  {
274  LogVerbatim("TotemRPUVPatternFinder") << "\t\tpatterns:";
275  for (const auto &p : patterns)
276  {
277  unsigned int n_hits = 0;
278  for (auto &hds : p.getHits())
279  n_hits += hds.size();
280 
281  LogVerbatim("TotemRPUVPatternFinder")
282  << "\t\t\tproj = " << ((p.getProjection() == TotemRPUVPattern::projU) ? "U" : "V")
283  << ", a = " << p.getA()
284  << ", b = " << p.getB()
285  << ", w = " << p.getW()
286  << ", fittable = " << p.getFittable()
287  << ", hits = " << n_hits;
288  }
289  }
290  }
291 
292  // save output
293  event.put(make_unique<DetSetVector<TotemRPUVPattern>>(patternsVector));
294 }
295 
296 //----------------------------------------------------------------------------------------------------
297 
T getParameter(std::string const &) const
TotemRPUVPatternFinder(const edm::ParameterSet &conf)
PhiMemoryImage patterns[9]
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.
static unsigned int rpOfDet(unsigned int i)
returns ID of RP for given detector ID &#39;&#39;i&#39;&#39;
Definition: TotemRPDetId.h:141
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void resetGeometry(const TotemRPGeometry *_g)
static unsigned int rawToDecId(unsigned int raw)
fast conversion Raw to Decimal ID
Definition: TotemRPDetId.h:120
bool isStripsCoordinateUDirection() const
Definition: TotemRPDetId.h:95
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 –&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 ...
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
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 ...