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 
17 
23 
26 
28 
29 //----------------------------------------------------------------------------------------------------
30 
38 public:
40 
41  ~TotemRPUVPatternFinder() override;
42 
43  void produce(edm::Event &e, const edm::EventSetup &c) override;
45 
46 private:
50 
51  unsigned int verbosity;
52 
55 
57  unsigned char minPlanesPerProjectionToFit;
58 
60  unsigned int maxHitsPerPlaneToSearch;
61 
64 
66  double threshold;
67 
69  double max_a_toFit;
70 
72  struct RPSettings {
75  };
76 
78  std::map<unsigned int, RPSettings> exceptionalSettings;
79 
81 
84  double z0,
85  double threshold,
86  unsigned int planes_required,
89 };
90 
91 //----------------------------------------------------------------------------------------------------
92 
93 using namespace std;
94 using namespace edm;
95 
96 //----------------------------------------------------------------------------------------------------
97 
99  : tagRecHit(conf.getParameter<edm::InputTag>("tagRecHit")),
100  verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
101  minPlanesPerProjectionToSearch(conf.getParameter<unsigned int>("minPlanesPerProjectionToSearch")),
102  minPlanesPerProjectionToFit(conf.getParameter<unsigned int>("minPlanesPerProjectionToFit")),
103  maxHitsPerPlaneToSearch(conf.getParameter<unsigned int>("maxHitsPerPlaneToSearch")),
104  lrcgn(new FastLineRecognition(conf.getParameter<double>("clusterSize_a"),
105  conf.getParameter<double>("clusterSize_b"))),
106  threshold(conf.getParameter<double>("threshold")),
107  max_a_toFit(conf.getParameter<double>("max_a_toFit")) {
108  for (const auto &ps : conf.getParameter<vector<ParameterSet>>("exceptionalSettings")) {
109  unsigned int rpId = ps.getParameter<unsigned int>("rpId");
110 
111  RPSettings settings;
112  settings.minPlanesPerProjectionToFit_U = ps.getParameter<unsigned int>("minPlanesPerProjectionToFit_U");
113  settings.minPlanesPerProjectionToFit_V = ps.getParameter<unsigned int>("minPlanesPerProjectionToFit_V");
114  settings.threshold_U = ps.getParameter<double>("threshold_U");
115  settings.threshold_V = ps.getParameter<double>("threshold_V");
116 
117  exceptionalSettings[rpId] = settings;
118  }
119 
120  detSetVectorTotemRPRecHitToken = consumes<edm::DetSetVector<TotemRPRecHit>>(tagRecHit);
121  ctppsGeometryToken = esConsumes<CTPPSGeometry, VeryForwardRealGeometryRecord>();
122 
123  produces<DetSetVector<TotemRPUVPattern>>();
124 }
125 
126 //----------------------------------------------------------------------------------------------------
127 
129 
130 //----------------------------------------------------------------------------------------------------
131 
133  double z0,
134  double threshold_loc,
135  unsigned int planes_required,
137  DetSet<TotemRPUVPattern> &patterns) {
138  // run recognition
139  DetSet<TotemRPUVPattern> newPatterns;
140  lrcgn->getPatterns(hits, z0, threshold_loc, newPatterns);
141 
142  // set pattern properties and copy to the global pattern collection
143  for (auto &p : newPatterns) {
144  p.setProjection(proj);
145 
146  p.setFittable(true);
147 
148  set<unsigned int> planes;
149  for (const auto &ds : p.hits())
150  planes.insert(TotemRPDetId(ds.detId()).plane());
151 
152  if (planes.size() < planes_required)
153  p.setFittable(false);
154 
155  if (fabs(p.a()) > max_a_toFit)
156  p.setFittable(false);
157 
158  patterns.push_back(p);
159  }
160 }
161 
162 //----------------------------------------------------------------------------------------------------
163 
165  if (verbosity > 5)
166  LogVerbatim("TotemRPUVPatternFinder")
167  << ">> TotemRPUVPatternFinder::produce " << event.id().run() << ":" << event.id().event();
168 
169  // 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  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  TotemRPDetId detId(ids.detId());
191  unsigned int plane = detId.plane();
192  bool uDir = detId.isStripsCoordinateUDirection();
193 
194  CTPPSDetId rpId = detId.rpId();
195 
196  RPData &data = rpData[rpId];
197 
198  for (auto &h : ids) {
199  if (uDir) {
200  auto &ods = data.hits_U.find_or_insert(ids.detId());
201  ods.push_back(h);
202  data.planeOccupancy_U[plane]++;
203  } else {
204  auto &ods = data.hits_V.find_or_insert(ids.detId());
205  ods.push_back(h);
206  data.planeOccupancy_V[plane]++;
207  }
208  }
209  }
210 
211  // track recognition pot by pot
212  for (auto const &it : rpData) {
213  CTPPSDetId rpId(it.first);
214  RPData const &data = it.second;
215 
216  // merge default and exceptional settings (if available)
217  unsigned int minPlanesPerProjectionToFit_U = minPlanesPerProjectionToFit;
218  unsigned int minPlanesPerProjectionToFit_V = minPlanesPerProjectionToFit;
219  double threshold_U = threshold;
220  double threshold_V = threshold;
221 
222  auto setIt = exceptionalSettings.find(rpId);
223  if (setIt != exceptionalSettings.end()) {
224  minPlanesPerProjectionToFit_U = setIt->second.minPlanesPerProjectionToFit_U;
225  minPlanesPerProjectionToFit_V = setIt->second.minPlanesPerProjectionToFit_V;
226  threshold_U = setIt->second.threshold_U;
227  threshold_V = setIt->second.threshold_V;
228  }
229 
230  auto &uColl = data.planeOccupancy_U;
231  auto &vColl = data.planeOccupancy_V;
232 
233  if (verbosity > 5) {
234  LogVerbatim("TotemRPUVPatternFinder")
235  << "\tRP " << rpId << "\n\t\tall planes: u = " << uColl.size() << ", v = " << vColl.size();
236  }
237 
238  // count planes with clean data (no showers, noise, ...)
239  unsigned int uPlanes = 0, vPlanes = 0;
240  for (auto pit : uColl)
241  if (pit.second <= maxHitsPerPlaneToSearch)
242  uPlanes++;
243 
244  for (auto pit : vColl)
245  if (pit.second <= maxHitsPerPlaneToSearch)
246  vPlanes++;
247 
248  if (verbosity > 5)
249  LogVerbatim("TotemRPUVPatternFinder") << "\t\tplanes with clean data: u = " << uPlanes << ", v = " << vPlanes;
250 
251  // discard RPs with too few reasonable planes
253  continue;
254 
255  // prepare data containers
256  DetSet<TotemRPUVPattern> &patterns = patternsVector.find_or_insert(rpId);
257 
258  // "typical" z0 for the RP
259  double z0 = geometry->rp(rpId)->translation().z();
260 
261  // u then v recognition
262  recognizeAndSelect(TotemRPUVPattern::projU, z0, threshold_U, minPlanesPerProjectionToFit_U, data.hits_U, patterns);
263 
264  recognizeAndSelect(TotemRPUVPattern::projV, z0, threshold_V, minPlanesPerProjectionToFit_V, data.hits_V, patterns);
265 
266  if (verbosity > 5) {
267  LogVerbatim("TotemRPUVPatternFinder") << "\t\tpatterns:";
268  for (const auto &p : patterns) {
269  unsigned int n_hits = 0;
270  for (auto &hds : p.hits())
271  n_hits += hds.size();
272 
273  LogVerbatim("TotemRPUVPatternFinder")
274  << "\t\t\tproj = " << ((p.projection() == TotemRPUVPattern::projU) ? "U" : "V") << ", a = " << p.a()
275  << ", b = " << p.b() << ", w = " << p.w() << ", fittable = " << p.fittable() << ", hits = " << n_hits;
276  }
277  }
278  }
279 
280  // save output
281  event.put(make_unique<DetSetVector<TotemRPUVPattern>>(patternsVector));
282 }
283 
284 //----------------------------------------------------------------------------------------------------
285 
288 
289  desc.add<edm::InputTag>("tagRecHit", edm::InputTag("totemRPRecHitProducer"))
290  ->setComment("input rechits collection to retrieve");
291  desc.addUntracked<unsigned int>("verbosity", 0);
292  desc.add<unsigned int>("maxHitsPerPlaneToSearch", 5)
293  ->setComment("minimum threshold of hits multiplicity to flag the pattern as dirty");
294  desc.add<unsigned int>("minPlanesPerProjectionToSearch", 3)
295  ->setComment(
296  "minimal number of reasonable (= not empty and not dirty) planes per projection and per RP, to start the "
297  "pattern search");
298  desc.add<double>("clusterSize_a", 0.02 /* rad */)
299  ->setComment("(full) cluster size (in rad) in slope-intercept space");
300  desc.add<double>("clusterSize_b", 0.3 /* mm */);
301 
302  desc.add<double>("threshold", 2.99)
303  ->setComment(
304  "minimal weight of (Hough) cluster to accept it as candidate\n"
305  " weight of cluster = sum of weights of contributing points\n"
306  " weight of point = sigma0 / sigma_of_point\n"
307  "most often: weight of point ~ 1, thus cluster weight is roughly number of contributing points");
308 
309  desc.add<unsigned int>("minPlanesPerProjectionToFit", 3)
310  ->setComment(
311  "minimal number of planes (in the recognised patterns) per projection and per RP, to tag the candidate as "
312  "fittable");
313 
314  desc.add<bool>("allowAmbiguousCombination", false)
315  ->setComment(
316  "whether to allow combination of most significant U and V pattern, in case there several of them.\n"
317  "don't set it to True, unless you have reason");
318 
319  desc.add<double>("max_a_toFit", 10.0)
320  ->setComment(
321  "maximal angle (in any projection) to mark the candidate as fittable -> controls track parallelity with "
322  "beam\n"
323  "huge value -> no constraint");
324 
325  edm::ParameterSetDescription exceptions_validator;
326  exceptions_validator.add<unsigned int>("rpId")->setComment("RP id according to CTPPSDetId");
327  exceptions_validator.add<unsigned int>("minPlanesPerProjectionToFit_U");
328  exceptions_validator.add<unsigned int>("minPlanesPerProjectionToFit_V");
329  exceptions_validator.add<double>("threshold_U");
330  exceptions_validator.add<double>("threshold_V");
331 
332  std::vector<edm::ParameterSet> exceptions_default;
333  desc.addVPSet("exceptionalSettings", exceptions_validator, exceptions_default);
334 
335  descr.add("totemRPUVPatternFinder", desc);
336 }
337 
338 //----------------------------------------------------------------------------------------------------
339 
TotemRPUVPattern::projV
Definition: TotemRPUVPattern.h:34
elasticPlotDQMSource_cfi.tagRecHit
tagRecHit
Definition: elasticPlotDQMSource_cfi.py:5
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
VeryForwardRealGeometryRecord
Event setup record containing the real (actual) geometry information.
Definition: VeryForwardRealGeometryRecord.h:22
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
HIPAlignmentAlgorithm_cfi.verbosity
verbosity
Definition: HIPAlignmentAlgorithm_cfi.py:7
edm::DetSetVector< TotemRPRecHit >
TotemRPUVPatternFinder::RPSettings
block of (exceptional) settings for 1 RP
Definition: TotemRPUVPatternFinder.cc:77
TotemRPUVPatternFinder
Class to recognize straight line tracks, based on optimized Hough trasform.
Definition: TotemRPUVPatternFinder.cc:37
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
input
static const std::string input
Definition: EdmProvDump.cc:48
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::ESWatcher< VeryForwardRealGeometryRecord >
ESHandle.h
edm::DetSet
Definition: DetSet.h:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
FastLineRecognition::resetGeometry
void resetGeometry(const CTPPSGeometry *_g)
Definition: FastLineRecognition.h:34
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
geometry
Definition: geometry.py:1
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
TotemRPRecHit.h
TotemRPDetId::plane
uint32_t plane() const
Definition: TotemRPDetId.h:51
TotemRPUVPatternFinder::tagRecHit
edm::InputTag tagRecHit
Definition: TotemRPUVPatternFinder.cc:52
year_2016_postTS2_cff.rpId
rpId
Definition: year_2016_postTS2_cff.py:23
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
TotemRPUVPatternFinder::threshold
double threshold
minimal weight of (Hough) cluster to accept it as candidate
Definition: TotemRPUVPatternFinder.cc:71
TotemRPUVPatternFinder::RPSettings::minPlanesPerProjectionToFit_U
unsigned char minPlanesPerProjectionToFit_U
Definition: TotemRPUVPatternFinder.cc:78
CTPPSGeometry.h
MakerMacros.h
h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::ESHandle< CTPPSGeometry >
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TotemRPUVPatternFinder::detSetVectorTotemRPRecHitToken
edm::EDGetTokenT< edm::DetSetVector< TotemRPRecHit > > detSetVectorTotemRPRecHitToken
Definition: TotemRPUVPatternFinder.cc:53
amptDefault_cfi.proj
proj
Definition: amptDefault_cfi.py:13
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
TotemRPUVPatternFinder::max_a_toFit
double max_a_toFit
maximal angle (in any projection) to mark candidate as fittable - controls track parallelity
Definition: TotemRPUVPatternFinder.cc:74
createfilelist.int
int
Definition: createfilelist.py:10
FastLineRecognition
Class performing optimized hough transform to recognize lines.
Definition: FastLineRecognition.h:23
TotemRPUVPatternFinder::verbosity
unsigned int verbosity
Definition: TotemRPUVPatternFinder.cc:56
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
FastLineRecognition::getPatterns
void getPatterns(const edm::DetSetVector< TotemRPRecHit > &input, double _z0, double threshold, edm::DetSet< TotemRPUVPattern > &patterns)
Definition: FastLineRecognition.cc:86
TotemRPUVPatternFinder::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: TotemRPUVPatternFinder.cc:164
TotemRPUVPatternFinder::geometryWatcher
edm::ESWatcher< VeryForwardRealGeometryRecord > geometryWatcher
Definition: TotemRPUVPatternFinder.cc:85
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
TotemRPUVPatternFinder::RPSettings::threshold_V
double threshold_V
Definition: TotemRPUVPatternFinder.cc:79
DetSetVector.h
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
TotemRPUVPatternFinder::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: TotemRPUVPatternFinder.cc:286
TotemRPUVPatternFinder::RPSettings::minPlanesPerProjectionToFit_V
unsigned char minPlanesPerProjectionToFit_V
Definition: TotemRPUVPatternFinder.cc:78
get
#define get
TotemRPUVPatternFinder::ctppsGeometryToken
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > ctppsGeometryToken
Definition: TotemRPUVPatternFinder.cc:54
VeryForwardRealGeometryRecord.h
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord >
FastLineRecognition.h
TotemRPUVPatternFinder::lrcgn
FastLineRecognition * lrcgn
the line recognition algorithm
Definition: TotemRPUVPatternFinder.cc:68
TotemRPUVPatternFinder::recognizeAndSelect
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
Definition: TotemRPUVPatternFinder.cc:132
TotemRPUVPatternFinder::maxHitsPerPlaneToSearch
unsigned int maxHitsPerPlaneToSearch
above this limit, planes are considered noisy
Definition: TotemRPUVPatternFinder.cc:65
TotemRPUVPatternFinder::minPlanesPerProjectionToSearch
unsigned char minPlanesPerProjectionToSearch
minimal required number of active planes per projection to even start track recognition
Definition: TotemRPUVPatternFinder.cc:59
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
TotemRPUVPatternFinder::minPlanesPerProjectionToFit
unsigned char minPlanesPerProjectionToFit
minimal required number of active planes per projection to mark track candidate as fittable
Definition: TotemRPUVPatternFinder.cc:62
TotemRPUVPatternFinder::exceptionalSettings
std::map< unsigned int, RPSettings > exceptionalSettings
exceptional settings: RP Id --> settings
Definition: TotemRPUVPatternFinder.cc:83
TotemRPUVPatternFinder::TotemRPUVPatternFinder
TotemRPUVPatternFinder(const edm::ParameterSet &conf)
Definition: TotemRPUVPatternFinder.cc:98
ESWatcher.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TotemRPUVPattern::ProjectionType
ProjectionType
Definition: TotemRPUVPattern.h:29
TotemRPDetId.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TotemRPUVPattern::projU
Definition: TotemRPUVPattern.h:34
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
edm::DetSetVector::find_or_insert
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:234
TotemRPUVPattern.h
DetSet.h
TotemRPUVPatternFinder::RPSettings::threshold_U
double threshold_U
Definition: TotemRPUVPatternFinder.cc:79
ParameterSet.h
event
Definition: event.py:1
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
edm::Event
Definition: Event.h:73
TotemRPUVPatternFinder::~TotemRPUVPatternFinder
~TotemRPUVPatternFinder() override
Definition: TotemRPUVPatternFinder.cc:128
TotemRPDetId
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:29
edm::InputTag
Definition: InputTag.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37