CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
42 public:
44 
46 
47  void produce(edm::Event &, const edm::EventSetup &) override;
48  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
49 
50 private:
56 
62  std::vector<uint32_t> listOfAllPlanes_;
63 
64  std::unique_ptr<RPixDetPatternFinder> patternFinder_;
65  std::unique_ptr<RPixDetTrackFinder> trackFinder_;
66 
68 };
69 
70 //------------------------------------------------------------------------------------------------//
71 
73  inputTag_ = parameterSet.getParameter<edm::InputTag>("tag");
74  verbosity_ = parameterSet.getUntrackedParameter<int>("verbosity");
75  maxHitPerRomanPot_ = parameterSet.getParameter<int>("maxHitPerRomanPot");
76  maxHitPerPlane_ = parameterSet.getParameter<int>("maxHitPerPlane");
77  maxTrackPerRomanPot_ = parameterSet.getParameter<int>("maxTrackPerRomanPot");
78  maxTrackPerPattern_ = parameterSet.getParameter<int>("maxTrackPerPattern");
79  numberOfPlanesPerPot_ = parameterSet.getParameter<int>("numberOfPlanesPerPot");
80 
81  std::string patternFinderAlgorithm = parameterSet.getParameter<std::string>("patternFinderAlgorithm");
82  std::string trackFitterAlgorithm = parameterSet.getParameter<std::string>("trackFinderAlgorithm");
83 
84  // pattern algorithm selector
85  if (patternFinderAlgorithm == "RPixRoadFinder") {
86  patternFinder_ = std::make_unique<RPixRoadFinder>(parameterSet);
87  } else {
88  throw cms::Exception("CTPPSPixelLocalTrackProducer")
89  << "Pattern finder algorithm" << patternFinderAlgorithm << " does not exist";
90  }
91 
92  listOfAllPlanes_.reserve(6);
93  for (uint32_t i = 0; i < numberOfPlanesPerPot_; ++i) {
94  listOfAllPlanes_.push_back(i);
95  }
96 
97  //tracking algorithm selector
98  if (trackFitterAlgorithm == "RPixPlaneCombinatoryTracking") {
99  trackFinder_ = std::make_unique<RPixPlaneCombinatoryTracking>(parameterSet);
100  } else {
101  throw cms::Exception("CTPPSPixelLocalTrackProducer")
102  << "Tracking fitter algorithm" << trackFitterAlgorithm << " does not exist";
103  }
104  trackFinder_->setListOfPlanes(listOfAllPlanes_);
105  trackFinder_->initialize();
106 
107  tokenCTPPSPixelRecHit_ = consumes<edm::DetSetVector<CTPPSPixelRecHit>>(inputTag_);
108  tokenCTPPSGeometry_ = esConsumes<CTPPSGeometry, VeryForwardRealGeometryRecord>();
109 
110  produces<edm::DetSetVector<CTPPSPixelLocalTrack>>();
111 }
112 
113 //------------------------------------------------------------------------------------------------//
114 
116 
117 //------------------------------------------------------------------------------------------------//
118 
121 
122  desc.add<edm::InputTag>("tag", edm::InputTag("ctppsPixelRecHits"))
123  ->setComment("inputTag of the RecHits input for the tracking algorithm");
124  desc.add<std::string>("patternFinderAlgorithm", "RPixRoadFinder")->setComment("algorithm type for pattern finder");
125  desc.add<std::string>("trackFinderAlgorithm", "RPixPlaneCombinatoryTracking")
126  ->setComment("algorithm type for track finder");
127  desc.add<uint>("trackMinNumberOfPoints", 3)->setComment("minimum number of planes to produce a track");
128  desc.addUntracked<int>("verbosity", 0)->setComment("verbosity for track producer");
129  desc.add<double>("maximumChi2OverNDF", 5.)->setComment("maximum Chi2OverNDF for accepting the track");
130  desc.add<double>("maximumXLocalDistanceFromTrack", 0.2)
131  ->setComment("maximum x distance in mm to associate a point not used for fit to the track");
132  desc.add<double>("maximumYLocalDistanceFromTrack", 0.3)
133  ->setComment("maximum y distance in mm to associate a point not used for fit to the track");
134  desc.add<int>("maxHitPerPlane", 20)
135  ->setComment("maximum hits per plane, events with higher number will not be fitted");
136  desc.add<int>("maxHitPerRomanPot", 60)
137  ->setComment("maximum hits per roman pot, events with higher number will not be fitted");
138  desc.add<int>("maxTrackPerRomanPot", 10)
139  ->setComment("maximum tracks per roman pot, events with higher track will not be saved");
140  desc.add<int>("maxTrackPerPattern", 5)
141  ->setComment("maximum tracks per pattern, events with higher track will not be saved");
142  desc.add<int>("numberOfPlanesPerPot", 6)->setComment("number of planes per pot");
143  desc.add<double>("roadRadius", 1.0)->setComment("radius of pattern search window");
144  desc.add<int>("minRoadSize", 3)->setComment("minimum number of points in a pattern");
145  desc.add<int>("maxRoadSize", 20)->setComment("maximum number of points in a pattern");
146 
147  descriptions.add("ctppsPixelLocalTracks", desc);
148 }
149 
150 //------------------------------------------------------------------------------------------------//
151 
153  // Step A: get inputs
154 
156  iEvent.getByToken(tokenCTPPSPixelRecHit_, recHits);
157  edm::DetSetVector<CTPPSPixelRecHit> recHitVector(*recHits);
158 
159  // get geometry
161  const CTPPSGeometry &geometry = *geometryHandler;
162  geometryWatcher_.check(iSetup);
163 
164  std::vector<CTPPSPixelDetId> listOfPotWithHighOccupancyPlanes;
165  std::map<CTPPSPixelDetId, uint32_t> mapHitPerPot;
166 
167  for (const auto &recHitSet : recHitVector) {
168  if (verbosity_ > 2)
169  edm::LogInfo("CTPPSPixelLocalTrackProducer")
170  << "Hits found in plane = " << recHitSet.detId() << " number = " << recHitSet.size();
171  CTPPSPixelDetId tmpRomanPotId = CTPPSPixelDetId(recHitSet.detId()).rpId();
172  uint32_t hitOnPlane = recHitSet.size();
173 
174  //Get the number of hits per pot
175  if (mapHitPerPot.find(tmpRomanPotId) == mapHitPerPot.end()) {
176  mapHitPerPot[tmpRomanPotId] = hitOnPlane;
177  } else
178  mapHitPerPot[tmpRomanPotId] += hitOnPlane;
179 
180  //check is the plane occupancy is too high and save the corresponding pot
181  if (maxHitPerPlane_ >= 0 && hitOnPlane > (uint32_t)maxHitPerPlane_) {
182  if (verbosity_ > 2)
183  edm::LogInfo("CTPPSPixelLocalTrackProducer")
184  << " ---> To many hits in the plane, pot will be excluded from tracking cleared";
185  listOfPotWithHighOccupancyPlanes.push_back(tmpRomanPotId);
186  }
187  }
188 
189  //remove rechit for pot with too many hits or containing planes with too many hits
190  for (const auto &recHitSet : recHitVector) {
191  const auto tmpDetectorId = CTPPSPixelDetId(recHitSet.detId());
192  const auto tmpRomanPotId = tmpDetectorId.rpId();
193 
194  if ((maxHitPerRomanPot_ >= 0 && mapHitPerPot[tmpRomanPotId] > (uint32_t)maxHitPerRomanPot_) ||
195  find(listOfPotWithHighOccupancyPlanes.begin(), listOfPotWithHighOccupancyPlanes.end(), tmpRomanPotId) !=
196  listOfPotWithHighOccupancyPlanes.end()) {
197  edm::DetSet<CTPPSPixelRecHit> &tmpDetSet = recHitVector[tmpDetectorId];
198  tmpDetSet.clear();
199  }
200  }
201 
203 
204  // Pattern finder
205 
206  patternFinder_->clear();
207  patternFinder_->setHits(&recHitVector);
208  patternFinder_->setGeometry(&geometry);
209  patternFinder_->findPattern();
210  std::vector<RPixDetPatternFinder::Road> patternVector = patternFinder_->getPatterns();
211 
212  //loop on all the patterns
213  int numberOfTracks = 0;
214 
215  for (const auto &pattern : patternVector) {
216  CTPPSPixelDetId firstHitDetId = CTPPSPixelDetId(pattern.at(0).detId);
217  CTPPSPixelDetId romanPotId = firstHitDetId.rpId();
218 
219  std::map<CTPPSPixelDetId, std::vector<RPixDetPatternFinder::PointInPlane>>
220  hitOnPlaneMap; //hit of the pattern organized by plane
221 
222  //loop on all the hits of the pattern
223  for (const auto &hit : pattern) {
224  CTPPSPixelDetId hitDetId = CTPPSPixelDetId(hit.detId);
225  CTPPSPixelDetId tmpRomanPotId = hitDetId.rpId();
226 
227  if (tmpRomanPotId != romanPotId) { //check that the hits belong to the same tracking station
228  throw cms::Exception("CTPPSPixelLocalTrackProducer")
229  << "Hits in the pattern must belong to the same tracking station";
230  }
231 
232  if (hitOnPlaneMap.find(hitDetId) ==
233  hitOnPlaneMap.end()) { //add the plane key in case it is the first hit of that plane
234  std::vector<RPixDetPatternFinder::PointInPlane> hitOnPlane;
235  hitOnPlane.push_back(hit);
236  hitOnPlaneMap[hitDetId] = hitOnPlane;
237  } else
238  hitOnPlaneMap[hitDetId].push_back(hit); //add the hit to an existing plane key
239  }
240 
241  trackFinder_->clear();
242  trackFinder_->setRomanPotId(romanPotId);
243  trackFinder_->setHits(&hitOnPlaneMap);
244  trackFinder_->setGeometry(&geometry);
245  trackFinder_->setZ0(geometry.rpTranslation(romanPotId).z());
246  trackFinder_->findTracks(iEvent.getRun().id().run());
247  std::vector<CTPPSPixelLocalTrack> tmpTracksVector = trackFinder_->getLocalTracks();
248 
249  if (verbosity_ > 2)
250  edm::LogInfo("CTPPSPixelLocalTrackProducer") << "tmpTracksVector = " << tmpTracksVector.size();
251  if (maxTrackPerPattern_ >= 0 && tmpTracksVector.size() > (uint32_t)maxTrackPerPattern_) {
252  if (verbosity_ > 2)
253  edm::LogInfo("CTPPSPixelLocalTrackProducer") << " ---> To many tracks in the pattern, cleared";
254  continue;
255  }
256 
257  for (const auto &track : tmpTracksVector) {
258  ++numberOfTracks;
259  edm::DetSet<CTPPSPixelLocalTrack> &tmpDetSet = foundTracks.find_or_insert(romanPotId);
260  tmpDetSet.push_back(track);
261  }
262  }
263 
264  if (verbosity_ > 1)
265  edm::LogInfo("CTPPSPixelLocalTrackProducer") << "Number of tracks will be saved = " << numberOfTracks;
266 
267  for (const auto &track : foundTracks) {
268  if (verbosity_ > 1)
269  edm::LogInfo("CTPPSPixelLocalTrackProducer")
270  << "Track found in detId = " << track.detId() << " number = " << track.size();
271  if (maxTrackPerRomanPot_ >= 0 && track.size() > (uint32_t)maxTrackPerRomanPot_) {
272  if (verbosity_ > 1)
273  edm::LogInfo("CTPPSPixelLocalTrackProducer") << " ---> Too many tracks in the pot, cleared";
274  CTPPSPixelDetId tmpRomanPotId = CTPPSPixelDetId(track.detId());
275  edm::DetSet<CTPPSPixelLocalTrack> &tmpDetSet = foundTracks[tmpRomanPotId];
276  tmpDetSet.clear();
277  }
278  }
279 
280  iEvent.put(std::make_unique<edm::DetSetVector<CTPPSPixelLocalTrack>>(foundTracks));
281 
282  return;
283 }
284 
void setComment(std::string const &value)
T getUntrackedParameter(std::string const &, T const &) const
edm::ESWatcher< VeryForwardRealGeometryRecord > geometryWatcher_
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > tokenCTPPSGeometry_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void push_back(const T &t)
Definition: DetSet.h:66
RunID const & id() const
Definition: RunBase.h:39
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
RunNumber_t run() const
Definition: RunID.h:36
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Run const & getRun() const
Definition: Event.cc:112
tuple patternFinderAlgorithm
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
static std::string const input
Definition: EdmProvDump.cc:47
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:234
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:78
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< RPixDetTrackFinder > trackFinder_
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
ParameterDescriptionBase * add(U const &iLabel, T const &value)
The manager class for TOTEM RP geometry.
Definition: CTPPSGeometry.h:30
void run(const edm::DetSetVector< CTPPSPixelRecHit > &input, edm::DetSetVector< CTPPSPixelLocalTrack > &output)
Log< level::Info, false > LogInfo
edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelRecHit > > tokenCTPPSPixelRecHit_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::unique_ptr< RPixDetPatternFinder > patternFinder_
Vector rpTranslation(unsigned int id) const
void clear()
Definition: DetSet.h:71
CTPPSPixelLocalTrackProducer(const edm::ParameterSet &parameterSet)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157