CMS 3D CMS Logo

SeedFinderSelector.cc
Go to the documentation of this file.
2 
3 // framework
6 
7 // track reco
21 // data formats
23 
25  : trackingRegion_(nullptr)
26  , eventSetup_(nullptr)
27  , measurementTracker_(nullptr)
28  , measurementTrackerLabel_(cfg.getParameter<std::string>("measurementTracker"))
29 {
30  if(cfg.exists("pixelTripletGeneratorFactory"))
31  {
32  const edm::ParameterSet & tripletConfig = cfg.getParameter<edm::ParameterSet>("pixelTripletGeneratorFactory");
33  pixelTripletGenerator_ = std::unique_ptr<HitTripletGeneratorFromPairAndLayers>{HitTripletGeneratorFromPairAndLayersFactory::get()->create(tripletConfig.getParameter<std::string>("ComponentName"),tripletConfig,consumesCollector)};
34  }
35 
36  if(cfg.exists("MultiHitGeneratorFactory"))
37  {
38  const edm::ParameterSet & tripletConfig = cfg.getParameter<edm::ParameterSet>("MultiHitGeneratorFactory");
39  multiHitGenerator_ = std::unique_ptr<MultiHitGeneratorFromPairAndLayers>{MultiHitGeneratorFromPairAndLayersFactory::get()->create(tripletConfig.getParameter<std::string>("ComponentName"),tripletConfig)};
40  }
41 
42  if(cfg.exists("CAHitTripletGeneratorFactory"))
43  {
44  const edm::ParameterSet & tripletConfig = cfg.getParameter<edm::ParameterSet>("CAHitTripletGeneratorFactory");
45  CAHitTriplGenerator_ = std::make_unique<CAHitTripletGenerator>(tripletConfig,consumesCollector);
46  seedingLayers_ = std::make_unique<SeedingLayerSetsBuilder>(cfg, consumesCollector, edm::InputTag("fastTrackerRecHits")); //calling the new FastSim specific constructor to make SeedingLayerSetsHits pointer for triplet iterations
47  layerPairs_ = cfg.getParameter<std::vector<unsigned>>("layerPairs"); //allowed layer pairs for CA triplets
48  }
49 
50  if(cfg.exists("CAHitQuadrupletGeneratorFactory"))
51  {
52  const edm::ParameterSet & quadrupletConfig = cfg.getParameter<edm::ParameterSet>("CAHitQuadrupletGeneratorFactory");
53  CAHitQuadGenerator_ = std::make_unique<CAHitQuadrupletGenerator>(quadrupletConfig, consumesCollector);
54  seedingLayers_ = std::make_unique<SeedingLayerSetsBuilder>(cfg, consumesCollector, edm::InputTag("fastTrackerRecHits")); //calling the new FastSim specific constructor to make SeedingLayerSetsHits pointer for quadruplet iterations
55  layerPairs_ = cfg.getParameter<std::vector<unsigned>>("layerPairs"); //allowed layer pairs for CA quadruplets
56  }
57 
59  {
60  throw cms::Exception("FastSimTracking") << "It is forbidden to specify together 'pixelTripletGeneratorFactory', 'CAHitTripletGeneratorFactory' and 'MultiHitGeneratorFactory' in configuration of SeedFinderSelection";
61  }
63  {
64  throw cms::Exception("FastSimTracking") << "It is forbidden to specify 'CAHitQuadrupletGeneratorFactory' together with 'pixelTripletGeneratorFactory', 'CAHitTripletGeneratorFactory' or 'MultiHitGeneratorFactory' in configuration of SeedFinderSelection";
65  }
66 }
67 
68 
70 
72 {
73  eventSetup_ = &es;
74 
75  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
76  es.get<CkfComponentsRecord>().get(measurementTrackerLabel_, measurementTrackerHandle);
78  measurementTracker_ = &(*measurementTrackerHandle);
79 
81  {
82  multiHitGenerator_->initES(es);
83  }
84 
85  //for CA triplet iterations
87  seedingLayer = seedingLayers_->makeSeedingLayerSetsHitsforFastSim(ev, es);
88  seedingLayerIds = seedingLayers_->layers();
89  CAHitTriplGenerator_->initEvent(ev,es);
90  }
91  //for CA quadruplet iterations
93  seedingLayer = seedingLayers_->makeSeedingLayerSetsHitsforFastSim(ev, es);
94  seedingLayerIds = seedingLayers_->layers();
95  CAHitQuadGenerator_->initEvent(ev,es);
96  }
97 }
98 
99 
100 bool SeedFinderSelector::pass(const std::vector<const FastTrackerRecHit *>& hits) const
101 {
103  {
104  throw cms::Exception("FastSimTracking") << "ERROR: event not initialized";
105  }
106  if(!trackingRegion_)
107  {
108  throw cms::Exception("FastSimTracking") << "ERROR: trackingRegion not set";
109  }
110 
111 
112  // check the inner 2 hits
113  if(hits.size() < 2)
114  {
115  throw cms::Exception("FastSimTracking") << "SeedFinderSelector::pass requires at least 2 hits";
116  }
117  const DetLayer * firstLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[0]->det()->geographicalId());
118  const DetLayer * secondLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[1]->det()->geographicalId());
119 
120  std::vector<BaseTrackerRecHit const *> firstHits{hits[0]};
121  std::vector<BaseTrackerRecHit const *> secondHits{hits[1]};
122 
123  const RecHitsSortedInPhi fhm(firstHits, trackingRegion_->origin(), firstLayer);
124  const RecHitsSortedInPhi shm(secondHits, trackingRegion_->origin(), secondLayer);
125 
126  HitDoublets result(fhm,shm);
127  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*firstLayer,*secondLayer,fhm,shm,*eventSetup_,0,result);
128 
129  if(result.empty())
130  {
131  return false;
132  }
133 
134  // check the inner 3 hits
136  {
137  if(hits.size() < 3)
138  {
139  throw cms::Exception("FastSimTracking") << "For the given configuration, SeedFinderSelector::pass requires at least 3 hits";
140  }
141  const DetLayer * thirdLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[2]->det()->geographicalId());
142  std::vector<const DetLayer *> thirdLayerDetLayer(1,thirdLayer);
143  std::vector<BaseTrackerRecHit const *> thirdHits{hits[2]};
144  const RecHitsSortedInPhi thm(thirdHits,trackingRegion_->origin(), thirdLayer);
145  const RecHitsSortedInPhi * thmp =&thm;
146 
148  {
149  OrderedHitTriplets tripletresult;
150  pixelTripletGenerator_->hitTriplets(*trackingRegion_,tripletresult,*eventSetup_,result,&thmp,thirdLayerDetLayer,1);
151  return !tripletresult.empty();
152  }
153  else if(multiHitGenerator_)
154  {
155  OrderedMultiHits tripletresult;
156  multiHitGenerator_->hitTriplets(*trackingRegion_,tripletresult,*eventSetup_,result,&thmp,thirdLayerDetLayer,1);
157  return !tripletresult.empty();
158  }
159  //new for Phase1
160  else if(CAHitTriplGenerator_)
161  {
162  if(!seedingLayer)
163  throw cms::Exception("FastSimTracking") << "ERROR: SeedingLayers pointer not set for CATripletGenerator";
164 
166  //constructing IntermediateHitDoublets to be passed onto CAHitTripletGenerator::hitNtuplets()
167  IntermediateHitDoublets ihd(&layers);
168  const TrackingRegion& tr_ = *trackingRegion_;
169  auto filler = ihd.beginRegion(&tr_);
170 
171  //forming the SeedingLayerId of the hits
172  std::array<SeedingLayerSetsBuilder::SeedingLayerId,3> hitPair;
173  hitPair[0] = Layer_tuple(hits[0]);
174  hitPair[1] = Layer_tuple(hits[1]);
175  hitPair[2] = Layer_tuple(hits[2]);
176 
177  //extracting the DetLayer of the hits
178  const DetLayer * fLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[0]->det()->geographicalId());
179  const DetLayer * sLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[1]->det()->geographicalId());
180  const DetLayer * tLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[2]->det()->geographicalId());
181 
182  //converting FastTrackerRecHit hits to BaseTrackerRecHit
183  std::vector<BaseTrackerRecHit const *> fHits{hits[0]};
184  std::vector<BaseTrackerRecHit const *> sHits{hits[1]};
185  std::vector<BaseTrackerRecHit const *> tHits{hits[2]};
186 
187  //forming the SeedingLayerSet for the hit doublets
188  SeedingLayerSetsHits::SeedingLayerSet pairCandidate1, pairCandidate2;
191  for(const auto p : layerPairs_){
192  pairCandidate = ls.slice(p,p+2);
193  if(p==0 && hitPair[0] == seedingLayerIds[pairCandidate[0].index()] && hitPair[1] == seedingLayerIds[pairCandidate[1].index()])
194  pairCandidate1=pairCandidate;
195  if(p==1 && hitPair[1] == seedingLayerIds[pairCandidate[0].index()] && hitPair[2] == seedingLayerIds[pairCandidate[1].index()])
196  pairCandidate2=pairCandidate;
197  }
198  }
199 
200  //Important: hits of the layer to be added to LayerHitMapCache
201  auto& layerCache = filler.layerHitMapCache();
202 
203  //doublets for CA triplets from the allowed layer pair combinations:(0,1),(1,2) and storing in filler
204  const RecHitsSortedInPhi & firsthm = *layerCache.add(pairCandidate1[0], std::make_unique<RecHitsSortedInPhi>(fHits, trackingRegion_->origin(), fLayer));
205  const RecHitsSortedInPhi & secondhm = *layerCache.add(pairCandidate1[1], std::make_unique<RecHitsSortedInPhi>(sHits, trackingRegion_->origin(), sLayer));
206  HitDoublets res1(firsthm,secondhm);
207  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*fLayer,*sLayer,firsthm,secondhm,*eventSetup_,0,res1);
208  filler.addDoublets(pairCandidate1, std::move(res1));
209  const RecHitsSortedInPhi & thirdhm = *layerCache.add(pairCandidate2[1], std::make_unique<RecHitsSortedInPhi>(tHits, trackingRegion_->origin(), tLayer));
210  HitDoublets res2(secondhm,thirdhm);
211  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*sLayer,*tLayer,secondhm,thirdhm,*eventSetup_,0,res2);
212  filler.addDoublets(pairCandidate2, std::move(res2));
213 
214  std::vector<OrderedHitSeeds> tripletresult;
215  tripletresult.resize(ihd.regionSize());
216  for(auto& ntuplet : tripletresult)
217  ntuplet.reserve(3);
218  CAHitTriplGenerator_->hitNtuplets(ihd,tripletresult,*eventSetup_,*seedingLayer); //calling the function from the class, modifies tripletresult
219  return !tripletresult[0].empty();
220  }
221  }
222  //new for Phase1
224  {
225  if(hits.size() < 4)
226  {
227  throw cms::Exception("FastSimTracking") << "For the given configuration, SeedFinderSelector::pass requires at least 4 hits";
228  }
229 
230  if(!seedingLayer)
231  throw cms::Exception("FastSimTracking") << "ERROR: SeedingLayers pointer not set for CAHitQuadrupletGenerator";
232 
234  //constructing IntermediateHitDoublets to be passed onto CAHitQuadrupletGenerator::hitNtuplets()
235  IntermediateHitDoublets ihd(&layers);
236  const TrackingRegion& tr_ = *trackingRegion_;
237  auto filler = ihd.beginRegion(&tr_);
238 
239  //forming the SeedingLayerId of the hits
240  std::array<SeedingLayerSetsBuilder::SeedingLayerId,4> hitPair;
241  hitPair[0] = Layer_tuple(hits[0]);
242  hitPair[1] = Layer_tuple(hits[1]);
243  hitPair[2] = Layer_tuple(hits[2]);
244  hitPair[3] = Layer_tuple(hits[3]);
245 
246  //extracting the DetLayer of the hits
247  const DetLayer * fLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[0]->det()->geographicalId());
248  const DetLayer * sLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[1]->det()->geographicalId());
249  const DetLayer * tLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[2]->det()->geographicalId());
250  const DetLayer * frLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[3]->det()->geographicalId());
251 
252  //converting FastTrackerRecHit hits to BaseTrackerRecHit
253  std::vector<BaseTrackerRecHit const *> fHits{hits[0]};
254  std::vector<BaseTrackerRecHit const *> sHits{hits[1]};
255  std::vector<BaseTrackerRecHit const *> tHits{hits[2]};
256  std::vector<BaseTrackerRecHit const *> frHits{hits[3]};
257 
258  //forming the SeedingLayerSet for the hit doublets
259  SeedingLayerSetsHits::SeedingLayerSet pairCandidate1, pairCandidate2, pairCandidate3;
262  for(const auto p : layerPairs_){
263  pairCandidate = ls.slice(p,p+2);
264  if(p==0 && hitPair[0] == seedingLayerIds[pairCandidate[0].index()] && hitPair[1] == seedingLayerIds[pairCandidate[1].index()])
265  pairCandidate1=pairCandidate;
266  if(p==1 && hitPair[1] == seedingLayerIds[pairCandidate[0].index()] && hitPair[2] == seedingLayerIds[pairCandidate[1].index()])
267  pairCandidate2=pairCandidate;
268  if(p==2 && hitPair[2] == seedingLayerIds[pairCandidate[0].index()] && hitPair[3] == seedingLayerIds[pairCandidate[1].index()])
269  pairCandidate3=pairCandidate;
270  }
271  }
272 
273  //Important: hits of the layer to be added to LayerHitMapCache
274  auto& layerCache = filler.layerHitMapCache();
275 
276  //doublets for CA quadruplets from the allowed layer pair combinations:(0,1),(1,2),(2,3) and storing in filler
277  const RecHitsSortedInPhi & firsthm = *layerCache.add(pairCandidate1[0], std::make_unique<RecHitsSortedInPhi>(fHits, trackingRegion_->origin(), fLayer));
278  const RecHitsSortedInPhi & secondhm = *layerCache.add(pairCandidate1[1], std::make_unique<RecHitsSortedInPhi>(sHits, trackingRegion_->origin(), sLayer));
279  HitDoublets res1(firsthm,secondhm);
280  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*fLayer,*sLayer,firsthm,secondhm,*eventSetup_,0,res1);
281  filler.addDoublets(pairCandidate1, std::move(res1));
282  const RecHitsSortedInPhi & thirdhm = *layerCache.add(pairCandidate2[1], std::make_unique<RecHitsSortedInPhi>(tHits, trackingRegion_->origin(), tLayer));
283  HitDoublets res2(secondhm,thirdhm);
284  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*sLayer,*tLayer,secondhm,thirdhm,*eventSetup_,0,res2);
285  filler.addDoublets(pairCandidate2, std::move(res2));
286  const RecHitsSortedInPhi & fourthhm = *layerCache.add(pairCandidate3[1], std::make_unique<RecHitsSortedInPhi>(frHits, trackingRegion_->origin(), frLayer));
287  HitDoublets res3(thirdhm, fourthhm);
288  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*tLayer,*frLayer,thirdhm,fourthhm,*eventSetup_,0,res3);
289  filler.addDoublets(pairCandidate3, std::move(res3));
290 
291  std::vector<OrderedHitSeeds> quadrupletresult;
292  quadrupletresult.resize(ihd.regionSize());
293  for(auto& ntuplet : quadrupletresult)
294  ntuplet.reserve(4);
295  CAHitQuadGenerator_->hitNtuplets(ihd,quadrupletresult,*eventSetup_,*seedingLayer); //calling the function from the class, modifies quadrupletresult
296  return !quadrupletresult[0].empty();
297  }
298 
299  return true;
300 
301 }
302 
303 //new for Phase1
305 {
306  const TrackerTopology* const tTopo = trackerTopology.product();
309  int idLayer = 0;
310 
311  if( (hit->det()->geographicalId()).subdetId() == PixelSubdetector::PixelBarrel){
313  side = TrackerDetSide::Barrel;
314  idLayer = tTopo->pxbLayer(hit->det()->geographicalId());
315  }
316  else if ((hit->det()->geographicalId()).subdetId() == PixelSubdetector::PixelEndcap){
318  idLayer = tTopo->pxfDisk(hit->det()->geographicalId());
319  if(tTopo->pxfSide(hit->det()->geographicalId())==1){
321  }
322  else{
324  }
325  }
326  return std::make_tuple(subdet, side, idLayer);
327 }
T getParameter(std::string const &) const
bool pass(const std::vector< const FastTrackerRecHit * > &hits) const
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
std::unique_ptr< CAHitQuadrupletGenerator > CAHitQuadGenerator_
const edm::EventSetup * eventSetup_
GlobalPoint const & origin() const
std::unique_ptr< SeedingLayerSetsHits > seedingLayer
unsigned int pxfDisk(const DetId &id) const
TrackerDetSide
Definition: TrackerDetSide.h:4
#define nullptr
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool ev
SeedFinderSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &&consumesCollector)
RegionFiller beginRegion(const TrackingRegion *region)
std::unique_ptr< HitTripletGeneratorFromPairAndLayers > pixelTripletGenerator_
std::vector< SeedingLayerSetsBuilder::SeedingLayerId > seedingLayerIds
SeedingLayerSetsBuilder::SeedingLayerId Layer_tuple(const FastTrackerRecHit *hit) const
std::tuple< GeomDetEnumerators::SubDetector, TrackerDetSide, int > SeedingLayerId
const GeomDet * det() const
std::vector< unsigned > layerPairs_
const TrackingRegion * trackingRegion_
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
HitDoublets doublets(const TrackingRegion &reg, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
edm::ESHandle< TrackerTopology > trackerTopology
unsigned int pxbLayer(const DetId &id) const
def ls(path, rec=False)
Definition: eostools.py:349
void initEvent(const edm::Event &ev, const edm::EventSetup &es)
std::unique_ptr< SeedingLayerSetsBuilder > seedingLayers_
T get() const
Definition: EventSetup.h:71
const MeasurementTracker * measurementTracker_
unsigned int pxfSide(const DetId &id) const
const GeometricSearchTracker * geometricSearchTracker() const
const std::string measurementTrackerLabel_
T const * product() const
Definition: ESHandle.h:86
std::unique_ptr< CAHitTripletGenerator > CAHitTriplGenerator_
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
std::unique_ptr< MultiHitGeneratorFromPairAndLayers > multiHitGenerator_