CMS 3D CMS Logo

CTPPSPixelLocalTrackProducer.cc
Go to the documentation of this file.
2 
12 
16 
18 
22 
23 
26 
27 #include <string>
28 #include <vector>
29 
31 
33 
35 
38 
39 
41 {
42 public:
44 
46 
47  void produce(edm::Event&, const edm::EventSetup&) override;
48  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
49 
50 private:
56 
61  std::vector<uint32_t> listOfAllPlanes_;
62 
63  std::unique_ptr<RPixDetPatternFinder> patternFinder_;
64  std::unique_ptr<RPixDetTrackFinder> trackFinder_ ;
65 
67 
68 };
69 
70 //------------------------------------------------------------------------------------------------//
71 
73 {
74  inputTag_ = parameterSet.getParameter<std::string> ("label");
75  verbosity_ = parameterSet.getUntrackedParameter<int> ("verbosity");
76  maxHitPerRomanPot_ = parameterSet.getParameter<int> ("maxHitPerRomanPot");
77  maxHitPerPlane_ = parameterSet.getParameter<int> ("maxHitPerPlane");
78  maxTrackPerRomanPot_ = parameterSet.getParameter<int> ("maxTrackPerRomanPot");
79  maxTrackPerPattern_ = parameterSet.getParameter<int> ("maxTrackPerPattern");
80  numberOfPlanesPerPot_ = parameterSet.getParameter<int> ("numberOfPlanesPerPot");
81 
82  std::string patternFinderAlgorithm = parameterSet.getParameter<std::string>("patternFinderAlgorithm");
83  std::string trackFitterAlgorithm = parameterSet.getParameter<std::string>("trackFinderAlgorithm" );
84 
85  // pattern algorithm selector
86  if(patternFinderAlgorithm == "RPixRoadFinder"){
87  patternFinder_ = std::unique_ptr<RPixRoadFinder>(new RPixRoadFinder(parameterSet));
88  }
89  else{
90  throw cms::Exception("CTPPSPixelLocalTrackProducer") << "Pattern finder algorithm" << patternFinderAlgorithm << " does not exist";
91  }
92 
93  listOfAllPlanes_.reserve(6);
94  for(uint32_t i=0; i<numberOfPlanesPerPot_; ++i){
95  listOfAllPlanes_.push_back(i);
96  }
97 
98  //tracking algorithm selector
99  if(trackFitterAlgorithm == "RPixPlaneCombinatoryTracking"){
100  trackFinder_ = std::unique_ptr<RPixPlaneCombinatoryTracking>(new RPixPlaneCombinatoryTracking(parameterSet));
101  }
102  else{
103  throw cms::Exception("CTPPSPixelLocalTrackProducer") << "Tracking fitter algorithm" << trackFitterAlgorithm << " does not exist";
104  }
105  trackFinder_->setListOfPlanes(listOfAllPlanes_);
106  trackFinder_->initialize();
107 
108  tokenCTPPSPixelRecHit_ = consumes<edm::DetSetVector<CTPPSPixelRecHit> >(edm::InputTag(inputTag_));
109 
110  produces<edm::DetSetVector<CTPPSPixelLocalTrack> > ();
111 
112 }
113 
114 //------------------------------------------------------------------------------------------------//
115 
117 }
118 
119 //------------------------------------------------------------------------------------------------//
120 
123 
124  desc.add<std::string> ("label" , "ctppsPixelRecHits" )
125  ->setComment( "label of the RecHits input for the tracking algorithm" );
126  desc.add<std::string> ("patternFinderAlgorithm" , "RPixRoadFinder" )
127  ->setComment( "algorithm type for pattern finder" );
128  desc.add<std::string> ("trackFinderAlgorithm" , "RPixPlaneCombinatoryTracking")
129  ->setComment( "algorithm type for track finder" );
130  desc.add<uint> ("trackMinNumberOfPoints" , 3 )
131  ->setComment( "minimum number of planes to produce a track" );
132  desc.addUntracked<int> ("verbosity" , 0 )
133  ->setComment( "verbosity for track producer" );
134  desc.add<double> ("maximumChi2OverNDF" , 5. )
135  ->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 )
149  ->setComment( "number of planes per pot" );
150  desc.add<double> ("roadRadius" , 1.0 )
151  ->setComment( "radius of pattern search window" );
152  desc.add<int> ("minRoadSize" , 3 )
153  ->setComment( "minimum number of points in a pattern" );
154  desc.add<int> ("maxRoadSize" , 20 )
155  ->setComment( "maximum number of points in a pattern" );
156 
157  descriptions.add("ctppsPixelLocalTracks", desc);
158 }
159 
160 //------------------------------------------------------------------------------------------------//
161 
163  // Step A: get inputs
164 
166  iEvent.getByToken(tokenCTPPSPixelRecHit_, recHits);
167  edm::DetSetVector<CTPPSPixelRecHit> recHitVector(*recHits);
168 
169  // get geometry
170  edm::ESHandle<CTPPSGeometry> geometryHandler;
171  iSetup.get<VeryForwardRealGeometryRecord>().get(geometryHandler);
172  const CTPPSGeometry &geometry = *geometryHandler;
173  geometryWatcher_.check(iSetup);
174 
175  std::vector<CTPPSPixelDetId> listOfPotWithHighOccupancyPlanes;
176  std::map<CTPPSPixelDetId, uint32_t> mapHitPerPot;
177 
178  for(const auto & recHitSet : recHitVector){
179 
180  if(verbosity_>2) edm::LogInfo("CTPPSPixelLocalTrackProducer")<<"Hits found in plane = "<<recHitSet.detId()<< " number = " << recHitSet.size() ;
181  CTPPSPixelDetId tmpRomanPotId = CTPPSPixelDetId(recHitSet.detId()).getRPId();
182  uint32_t hitOnPlane = recHitSet.size();
183 
184  //Get the number of hits per pot
185  if(mapHitPerPot.find(tmpRomanPotId)==mapHitPerPot.end()){
186  mapHitPerPot[tmpRomanPotId] = hitOnPlane;
187  }
188  else mapHitPerPot[tmpRomanPotId]+=hitOnPlane;
189 
190  //check is the plane occupancy is too high and save the corresponding pot
191  if(maxHitPerPlane_>=0 && hitOnPlane>(uint32_t)maxHitPerPlane_){
192  if(verbosity_>2) edm::LogInfo("CTPPSPixelLocalTrackProducer")<<" ---> To many hits in the plane, pot will be excluded from tracking cleared";
193  listOfPotWithHighOccupancyPlanes.push_back(tmpRomanPotId);
194  }
195  }
196 
197  //remove rechit for pot with too many hits or containing planes with too many hits
198  for(const auto & recHitSet : recHitVector){
199  const auto tmpDetectorId = CTPPSPixelDetId(recHitSet.detId());
200  const auto tmpRomanPotId = tmpDetectorId.getRPId();
201 
202  if((maxHitPerRomanPot_>=0 && mapHitPerPot[tmpRomanPotId]>(uint32_t)maxHitPerRomanPot_) ||
203  find (listOfPotWithHighOccupancyPlanes.begin(), listOfPotWithHighOccupancyPlanes.end(), tmpRomanPotId) != listOfPotWithHighOccupancyPlanes.end() ){
204  edm::DetSet<CTPPSPixelRecHit> &tmpDetSet = recHitVector[tmpDetectorId];
205  tmpDetSet.clear();
206  }
207 
208  }
209 
211 
212  // Pattern finder
213 
214  patternFinder_->clear();
215  patternFinder_->setHits(&recHitVector);
216  patternFinder_->setGeometry(&geometry);
217  patternFinder_->findPattern();
218  std::vector<RPixDetPatternFinder::Road> patternVector = patternFinder_->getPatterns();
219 
220  //loop on all the patterns
221  int numberOfTracks = 0;
222 
223  for(const auto & pattern : patternVector){
224  CTPPSPixelDetId firstHitDetId = CTPPSPixelDetId(pattern.at(0).detId);
225  CTPPSPixelDetId romanPotId = firstHitDetId.getRPId();
226 
227  std::map<CTPPSPixelDetId, std::vector<RPixDetPatternFinder::PointInPlane> > hitOnPlaneMap; //hit of the pattern organized by plane
228 
229  //loop on all the hits of the pattern
230  for(const auto & hit : pattern){
231  CTPPSPixelDetId hitDetId = CTPPSPixelDetId(hit.detId);
232  CTPPSPixelDetId tmpRomanPotId = hitDetId.getRPId();
233 
234 
235  if(tmpRomanPotId!=romanPotId){ //check that the hits belong to the same tracking station
236  throw cms::Exception("CTPPSPixelLocalTrackProducer") << "Hits in the pattern must belong to the same tracking station";
237  }
238 
239  if(hitOnPlaneMap.find(hitDetId)==hitOnPlaneMap.end()){ //add the plane key in case it is the first hit of that plane
240  std::vector<RPixDetPatternFinder::PointInPlane> hitOnPlane;
241  hitOnPlane.push_back(hit);
242  hitOnPlaneMap[hitDetId] = hitOnPlane;
243  }
244  else hitOnPlaneMap[hitDetId].push_back(hit); //add the hit to an existing plane key
245 
246  }
247 
248  trackFinder_->clear();
249  trackFinder_->setRomanPotId(romanPotId);
250  trackFinder_->setHits(&hitOnPlaneMap);
251  trackFinder_->setGeometry(&geometry);
252  trackFinder_->setZ0(geometry.getRPTranslation(romanPotId).z());
253  trackFinder_->findTracks();
254  std::vector<CTPPSPixelLocalTrack> tmpTracksVector = trackFinder_->getLocalTracks();
255 
256  if(verbosity_>2)edm::LogInfo("CTPPSPixelLocalTrackProducer")<<"tmpTracksVector = "<<tmpTracksVector.size();
257  if(maxTrackPerPattern_>=0 && tmpTracksVector.size()>(uint32_t)maxTrackPerPattern_){
258  if(verbosity_>2)edm::LogInfo("CTPPSPixelLocalTrackProducer")<<" ---> To many tracks in the pattern, cleared";
259  continue;
260  }
261 
262 
263  for(const auto & track : tmpTracksVector){
264  ++numberOfTracks;
265  edm::DetSet<CTPPSPixelLocalTrack> &tmpDetSet = foundTracks.find_or_insert(romanPotId);
266  tmpDetSet.push_back(track);
267  }
268 
269 
270  }
271 
272  if(verbosity_>1) edm::LogInfo("CTPPSPixelLocalTrackProducer")<<"Number of tracks will be saved = "<<numberOfTracks;
273 
274  for(const auto & track : foundTracks){
275  if(verbosity_>1) edm::LogInfo("CTPPSPixelLocalTrackProducer")<<"Track found in detId = "<<track.detId()<< " number = " << track.size() ;
276  if(maxTrackPerRomanPot_>=0 && track.size()>(uint32_t)maxTrackPerRomanPot_){
277  if(verbosity_>1) edm::LogInfo("CTPPSPixelLocalTrackProducer")<<" ---> To many tracks in the pot, cleared";
278  CTPPSPixelDetId tmpRomanPotId = CTPPSPixelDetId(track.detId());
279  edm::DetSet<CTPPSPixelLocalTrack> &tmpDetSet = foundTracks[tmpRomanPotId];
280  tmpDetSet.clear();
281  }
282  }
283 
284  iEvent.put(std::make_unique<edm::DetSetVector<CTPPSPixelLocalTrack> >(foundTracks));
285 
286  return;
287 
288 }
289 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::ESWatcher< VeryForwardRealGeometryRecord > geometryWatcher_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
void push_back(const T &t)
Definition: DetSet.h:68
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:20
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
int iEvent
Definition: GenABIO.cc:230
std::unique_ptr< RPixDetTrackFinder > trackFinder_
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
ParameterDescriptionBase * add(U const &iLabel, T const &value)
The manager class for TOTEM RP geometry.
Definition: CTPPSGeometry.h:33
void run(const edm::DetSetVector< CTPPSPixelRecHit > &input, edm::DetSetVector< CTPPSPixelLocalTrack > &output)
CLHEP::Hep3Vector getRPTranslation(unsigned int id) const
edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelRecHit > > tokenCTPPSPixelRecHit_
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::unique_ptr< RPixDetPatternFinder > patternFinder_
void clear()
Definition: DetSet.h:69
CTPPSPixelLocalTrackProducer(const edm::ParameterSet &parameterSet)
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11