CMS 3D CMS Logo

CTPPSPixelLocalTrackProducer.cc
Go to the documentation of this file.
2 
12 
17 
19 
23 
26 
27 #include <memory>
28 
29 #include <string>
30 #include <vector>
31 
33 
35 
37 
40 
43 
44 namespace {
45  constexpr int rocMask = 0xE000;
46  constexpr int rocOffset = 13;
47  constexpr int rocSizeInPixels = 4160;
48 } // namespace
49 
51 public:
53 
55 
56  void produce(edm::Event &, const edm::EventSetup &) override;
57  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
58 
59 private:
60  const int verbosity_;
61  const int maxHitPerPlane_;
62  const int maxHitPerRomanPot_;
65 
69 
71 
72  const uint32_t numberOfPlanesPerPot_;
73 
74  std::unique_ptr<RPixDetPatternFinder> patternFinder_;
75  std::unique_ptr<RPixDetTrackFinder> trackFinder_;
76 };
77 
78 //------------------------------------------------------------------------------------------------//
79 
81  : verbosity_(parameterSet.getUntrackedParameter<int>("verbosity")),
82  maxHitPerPlane_(parameterSet.getParameter<int>("maxHitPerPlane")),
83  maxHitPerRomanPot_(parameterSet.getParameter<int>("maxHitPerRomanPot")),
84  maxTrackPerRomanPot_(parameterSet.getParameter<int>("maxTrackPerRomanPot")),
85  maxTrackPerPattern_(parameterSet.getParameter<int>("maxTrackPerPattern")),
86  tokenCTPPSPixelRecHit_(
87  consumes<edm::DetSetVector<CTPPSPixelRecHit>>(parameterSet.getParameter<edm::InputTag>("tag"))),
89  tokenCTPPSPixelAnalysisMask_(esConsumes<CTPPSPixelAnalysisMask, CTPPSPixelAnalysisMaskRcd>()),
90  numberOfPlanesPerPot_(parameterSet.getParameter<int>("numberOfPlanesPerPot")) {
92  std::string trackFitterAlgorithm = parameterSet.getParameter<std::string>("trackFinderAlgorithm");
93 
94  // pattern algorithm selector
95  if (patternFinderAlgorithm == "RPixRoadFinder") {
96  patternFinder_ = std::make_unique<RPixRoadFinder>(parameterSet);
97  } else {
98  throw cms::Exception("CTPPSPixelLocalTrackProducer")
99  << "Pattern finder algorithm" << patternFinderAlgorithm << " does not exist";
100  }
101 
102  std::vector<uint32_t> listOfAllPlanes;
103  for (uint32_t i = 0; i < numberOfPlanesPerPot_; ++i) {
104  listOfAllPlanes.push_back(i);
105  }
106 
107  //tracking algorithm selector
108  if (trackFitterAlgorithm == "RPixPlaneCombinatoryTracking") {
109  trackFinder_ = std::make_unique<RPixPlaneCombinatoryTracking>(parameterSet);
110  } else {
111  throw cms::Exception("CTPPSPixelLocalTrackProducer")
112  << "Tracking fitter algorithm" << trackFitterAlgorithm << " does not exist";
113  }
114  trackFinder_->setListOfPlanes(listOfAllPlanes);
115  trackFinder_->initialize();
116  produces<edm::DetSetVector<CTPPSPixelLocalTrack>>();
117 }
118 
119 //------------------------------------------------------------------------------------------------//
120 
122 
123 //------------------------------------------------------------------------------------------------//
124 
127 
128  desc.add<edm::InputTag>("tag", edm::InputTag("ctppsPixelRecHits"))
129  ->setComment("inputTag of the RecHits input for the tracking algorithm");
130  desc.add<std::string>("patternFinderAlgorithm", "RPixRoadFinder")->setComment("algorithm type for pattern finder");
131  desc.add<std::string>("trackFinderAlgorithm", "RPixPlaneCombinatoryTracking")
132  ->setComment("algorithm type for track finder");
133  desc.add<uint>("trackMinNumberOfPoints", 3)->setComment("minimum number of planes to produce a track");
134  desc.addUntracked<int>("verbosity", 0)->setComment("verbosity for track producer");
135  desc.add<double>("maximumChi2OverNDF", 5.)->setComment("maximum Chi2OverNDF for accepting the track");
136  desc.add<double>("maximumXLocalDistanceFromTrack", 0.2)
137  ->setComment("maximum x distance in mm to associate a point not used for fit to the track");
138  desc.add<double>("maximumYLocalDistanceFromTrack", 0.3)
139  ->setComment("maximum y distance in mm to associate a point not used for fit to the track");
140  desc.add<int>("maxHitPerPlane", 20)
141  ->setComment("maximum hits per plane, events with higher number will not be fitted");
142  desc.add<int>("maxHitPerRomanPot", 60)
143  ->setComment("maximum hits per roman pot, events with higher number will not be fitted");
144  desc.add<int>("maxTrackPerRomanPot", 10)
145  ->setComment("maximum tracks per roman pot, events with higher track will not be saved");
146  desc.add<int>("maxTrackPerPattern", 5)
147  ->setComment("maximum tracks per pattern, events with higher track will not be saved");
148  desc.add<int>("numberOfPlanesPerPot", 6)->setComment("number of planes per pot");
149  desc.add<double>("roadRadius", 1.0)->setComment("radius of pattern search window");
150  desc.add<int>("minRoadSize", 3)->setComment("minimum number of points in a pattern");
151  desc.add<int>("maxRoadSize", 20)->setComment("maximum number of points in a pattern");
152  //parameter for 2-plane-pot reconstruction patch in run 3
153  desc.add<double>("roadRadiusBadPot", 0.5)->setComment("radius of pattern search window for 2 plane pot");
154 
155  descriptions.add("ctppsPixelLocalTracks", desc);
156 }
157 
158 //------------------------------------------------------------------------------------------------//
159 
161  // Step A: get inputs
162 
166 
167  // get geometry
169  const CTPPSGeometry &geometry = *geometryHandler;
170  geometryWatcher_.check(iSetup);
171 
172  // get mask
173 
174  // 2 planes pot flag vector 0=45-220, 1=45-210, 2=56-210, 3=56-220
175  bool is2PlanePotV[4] = {false};
176 
177  if (!recHits->empty()) {
178  const auto &mask = iSetup.getData(tokenCTPPSPixelAnalysisMask_);
179 
180  // Read Mask checking if 4 planes are masked and pot needs special treatment
181  std::map<uint32_t, CTPPSPixelROCAnalysisMask> const &maschera = mask.analysisMask;
182 
183  // vector of masked rocs
184  bool maskV[4][6][6] = {{{false}}};
185 
186  for (auto const &det : maschera) {
187  CTPPSPixelDetId detId(det.first);
188  unsigned int rocNum = (det.first & rocMask) >> rocOffset;
189  if (rocNum > 5 || detId.plane() > 5)
190  throw cms::Exception("InvalidRocOrPlaneNumber") << "roc number from mask: " << rocNum;
191 
192  if (detId.arm() == 0 && detId.rp() == 3) {
193  if (detId.station() == 2) { // pot 45-220-far
194  if (det.second.maskedPixels.size() == rocSizeInPixels || det.second.fullMask == true) { // roc fully masked
195  maskV[0][detId.plane()][rocNum] = true;
196  }
197  } else if (detId.station() == 0) { // pot 45-210-far
198  if (det.second.maskedPixels.size() == rocSizeInPixels || det.second.fullMask == true) { // roc fully masked
199  maskV[1][detId.plane()][rocNum] = true;
200  }
201  }
202  } else if (detId.arm() == 1 && detId.rp() == 3) {
203  if (detId.station() == 0) { // pot 56-210-far
204  if (det.second.maskedPixels.size() == rocSizeInPixels || det.second.fullMask == true) { // roc fully masked
205  maskV[2][detId.plane()][rocNum] = true;
206  }
207  } else if (detId.station() == 2) { // pot 56-220-far
208  if (det.second.maskedPixels.size() == rocSizeInPixels || det.second.fullMask == true) { // roc fully masked
209  maskV[3][detId.plane()][rocNum] = true;
210  }
211  }
212  }
213  }
214  // search for specific pattern that requires special reconstruction (use of two plane tracks)
215 
216  for (unsigned int i = 0; i < 4; i++) {
217  unsigned int numberOfMaskedPlanes = 0;
218  for (unsigned int j = 0; j < 6; j++) {
219  if (maskV[i][j][0] && maskV[i][j][1] && maskV[i][j][4] && maskV[i][j][5])
220  numberOfMaskedPlanes++;
221  }
222  if (numberOfMaskedPlanes == 4)
223  is2PlanePotV[i] = true; // search for exactly 4 planes fully masked
224  edm::LogInfo("CTPPSPixelLocalTrackProducer") << " Masked planes in Pot #" << i << " = " << numberOfMaskedPlanes;
225  if (is2PlanePotV[i])
226  edm::LogInfo("CTPPSPixelLocalTrackProducer")
227  << " Enabling 2 plane track reconstruction for pot #" << i << " (0=45-220, 1=45-210, 2=56-210, 3=56-220) ";
228  }
229  }
230  std::vector<CTPPSPixelDetId> listOfPotWithHighOccupancyPlanes;
231  std::map<CTPPSPixelDetId, uint32_t> mapHitPerPot;
232 
233  for (const auto &recHitSet : recHitVector) {
234  if (verbosity_ > 2)
235  edm::LogInfo("CTPPSPixelLocalTrackProducer")
236  << "Hits found in plane = " << recHitSet.detId() << " number = " << recHitSet.size();
237  CTPPSPixelDetId tmpRomanPotId = CTPPSPixelDetId(recHitSet.detId()).rpId();
238  uint32_t hitOnPlane = recHitSet.size();
239 
240  //Get the number of hits per pot
241  if (mapHitPerPot.find(tmpRomanPotId) == mapHitPerPot.end()) {
242  mapHitPerPot[tmpRomanPotId] = hitOnPlane;
243  } else
244  mapHitPerPot[tmpRomanPotId] += hitOnPlane;
245 
246  //check is the plane occupancy is too high and save the corresponding pot
247  if (maxHitPerPlane_ >= 0 && hitOnPlane > (uint32_t)maxHitPerPlane_) {
248  if (verbosity_ > 2)
249  edm::LogInfo("CTPPSPixelLocalTrackProducer")
250  << " ---> Too many hits in the plane, pot will be excluded from tracking cleared";
251  listOfPotWithHighOccupancyPlanes.push_back(tmpRomanPotId);
252  }
253  }
254 
255  //remove rechit for pot with too many hits or containing planes with too many hits
256  for (const auto &recHitSet : recHitVector) {
257  const auto tmpDetectorId = CTPPSPixelDetId(recHitSet.detId());
258  const auto tmpRomanPotId = tmpDetectorId.rpId();
259 
260  if ((maxHitPerRomanPot_ >= 0 && mapHitPerPot[tmpRomanPotId] > (uint32_t)maxHitPerRomanPot_) ||
261  find(listOfPotWithHighOccupancyPlanes.begin(), listOfPotWithHighOccupancyPlanes.end(), tmpRomanPotId) !=
262  listOfPotWithHighOccupancyPlanes.end()) {
263  edm::DetSet<CTPPSPixelRecHit> &tmpDetSet = recHitVector[tmpDetectorId];
264  tmpDetSet.clear();
265  }
266  }
267 
269 
270  // Pattern finder
271 
272  patternFinder_->clear();
273  patternFinder_->setHits(&recHitVector);
274  patternFinder_->setGeometry(&geometry);
275  patternFinder_->findPattern(is2PlanePotV);
276  std::vector<RPixDetPatternFinder::Road> patternVector = patternFinder_->getPatterns();
277 
278  //loop on all the patterns
279  int numberOfTracks = 0;
280 
281  for (const auto &pattern : patternVector) {
282  CTPPSPixelDetId firstHitDetId = CTPPSPixelDetId(pattern.at(0).detId);
283  CTPPSPixelDetId romanPotId = firstHitDetId.rpId();
284 
285  std::map<CTPPSPixelDetId, std::vector<RPixDetPatternFinder::PointInPlane>>
286  hitOnPlaneMap; //hit of the pattern organized by plane
287 
288  //loop on all the hits of the pattern
289  for (const auto &hit : pattern) {
290  CTPPSPixelDetId hitDetId = CTPPSPixelDetId(hit.detId);
291  CTPPSPixelDetId tmpRomanPotId = hitDetId.rpId();
292 
293  if (tmpRomanPotId != romanPotId) { //check that the hits belong to the same tracking station
294  throw cms::Exception("CTPPSPixelLocalTrackProducer")
295  << "Hits in the pattern must belong to the same tracking station";
296  }
297 
298  if (hitOnPlaneMap.find(hitDetId) ==
299  hitOnPlaneMap.end()) { //add the plane key in case it is the first hit of that plane
300  std::vector<RPixDetPatternFinder::PointInPlane> hitOnPlane;
301  hitOnPlane.push_back(hit);
302  hitOnPlaneMap[hitDetId] = hitOnPlane;
303  } else
304  hitOnPlaneMap[hitDetId].push_back(hit); //add the hit to an existing plane key
305  }
306 
307  trackFinder_->clear();
308  trackFinder_->setRomanPotId(romanPotId);
309  trackFinder_->setHits(&hitOnPlaneMap);
310  trackFinder_->setGeometry(&geometry);
311  trackFinder_->setZ0(geometry.rpTranslation(romanPotId).z());
312  trackFinder_->findTracks(iEvent.getRun().id().run());
313  std::vector<CTPPSPixelLocalTrack> tmpTracksVector = trackFinder_->getLocalTracks();
314 
315  if (verbosity_ > 2)
316  edm::LogInfo("CTPPSPixelLocalTrackProducer") << "tmpTracksVector = " << tmpTracksVector.size();
317  if (maxTrackPerPattern_ >= 0 && tmpTracksVector.size() > (uint32_t)maxTrackPerPattern_) {
318  if (verbosity_ > 2)
319  edm::LogInfo("CTPPSPixelLocalTrackProducer") << " ---> To many tracks in the pattern, cleared";
320  continue;
321  }
322 
323  for (const auto &track : tmpTracksVector) {
324  ++numberOfTracks;
325  edm::DetSet<CTPPSPixelLocalTrack> &tmpDetSet = foundTracks.find_or_insert(romanPotId);
326  tmpDetSet.push_back(track);
327  }
328  }
329 
330  if (verbosity_ > 1)
331  edm::LogInfo("CTPPSPixelLocalTrackProducer") << "Number of tracks will be saved = " << numberOfTracks;
332 
333  for (const auto &track : foundTracks) {
334  if (verbosity_ > 1)
335  edm::LogInfo("CTPPSPixelLocalTrackProducer")
336  << "Track found in detId = " << track.detId() << " number = " << track.size();
337  if (maxTrackPerRomanPot_ >= 0 && track.size() > (uint32_t)maxTrackPerRomanPot_) {
338  if (verbosity_ > 1)
339  edm::LogInfo("CTPPSPixelLocalTrackProducer") << " ---> Too many tracks in the pot, cleared";
340  CTPPSPixelDetId tmpRomanPotId = CTPPSPixelDetId(track.detId());
341  edm::DetSet<CTPPSPixelLocalTrack> &tmpDetSet = foundTracks[tmpRomanPotId];
342  tmpDetSet.clear();
343  }
344  }
345 
346  iEvent.put(std::make_unique<edm::DetSetVector<CTPPSPixelLocalTrack>>(foundTracks));
347 
348  return;
349 }
350 
edm::ESWatcher< VeryForwardRealGeometryRecord > geometryWatcher_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::ESGetToken< CTPPSPixelAnalysisMask, CTPPSPixelAnalysisMaskRcd > tokenCTPPSPixelAnalysisMask_
void push_back(const T &t)
Definition: DetSet.h:66
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelRecHit > > tokenCTPPSPixelRecHit_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &, const edm::EventSetup &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
Event setup record containing the real (actual) geometry information.
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:225
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< RPixDetTrackFinder > trackFinder_
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:84
Channel-mask mapping.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > tokenCTPPSGeometry_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
The manager class for TOTEM RP geometry.
Definition: CTPPSGeometry.h:30
Log< level::Info, false > LogInfo
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::unique_ptr< RPixDetPatternFinder > patternFinder_
HLT enums.
void clear()
Definition: DetSet.h:71
CTPPSPixelLocalTrackProducer(const edm::ParameterSet &parameterSet)