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_.reset(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_.reset(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 doublets for CA triplets from the allowed layer pair combinations:(0,1),(1,2)
172  std::array<SeedingLayerSetsBuilder::SeedingLayerId,2> hitPair;
173  for(int i=0; i<2; i++){
175  hitPair[0] = Layer_tuple(hits[i]);
176  hitPair[1] = Layer_tuple(hits[i+1]);
177 
178  bool found;
180  found = false;
181  for(const auto p : layerPairs_){
182  pairCandidate = ls.slice(p,p+2);
183  if(hitPair[0] == seedingLayerIds[pairCandidate[0].index()] && hitPair[1] == seedingLayerIds[pairCandidate[1].index()]){
184  found = true;
185  break;
186  }
187  }
188  if(found)
189  break;
190  }
191  assert(found == true);
192  const DetLayer * fLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[i]->det()->geographicalId());
193  const DetLayer * sLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[i+1]->det()->geographicalId());
194  std::vector<BaseTrackerRecHit const *> fHits{hits[i]};
195  std::vector<BaseTrackerRecHit const *> sHits{hits[i+1]};
196 
197  //Important: doublets to be added to the cache
198  auto& layerCache = filler.layerHitMapCache();
199  const RecHitsSortedInPhi& firsthm = *layerCache.add(pairCandidate[0], std::make_unique<RecHitsSortedInPhi>(fHits, trackingRegion_->origin(),fLayer));
200  const RecHitsSortedInPhi& secondhm = *layerCache.add(pairCandidate[1], std::make_unique<RecHitsSortedInPhi>(sHits, trackingRegion_->origin(),sLayer));
201  HitDoublets res(firsthm,secondhm);
202  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*fLayer,*sLayer,firsthm,secondhm,*eventSetup_,0,res);
203  filler.addDoublets(pairCandidate, std::move(res)); //fill the formed doublet
204  }
205  std::vector<OrderedHitSeeds> tripletresult;
206  tripletresult.resize(ihd.regionSize());
207  for(auto& ntuplet : tripletresult)
208  ntuplet.reserve(3);
209  CAHitTriplGenerator_->hitNtuplets(ihd,tripletresult,*eventSetup_,*seedingLayer); //calling the function from the class, modifies tripletresult
210  return !tripletresult.empty();
211  }
212  }
213  //new for Phase1
215  {
216  if(hits.size() < 4)
217  {
218  throw cms::Exception("FastSimTracking") << "For the given configuration, SeedFinderSelector::pass requires at least 4 hits";
219  }
220 
221  if(!seedingLayer)
222  throw cms::Exception("FastSimTracking") << "ERROR: SeedingLayers pointer not set for CAHitQuadrupletGenerator";
223 
225  //constructing IntermediateHitDoublets to be passed onto CAHitQuadrupletGenerator::hitNtuplets()
226  IntermediateHitDoublets ihd(&layers);
227  const TrackingRegion& tr_ = *trackingRegion_;
228  auto filler = ihd.beginRegion(&tr_);
229 
230  //Forming doublets for CA quadruplets from the allowed layer pair combinations:(0,1),(1,2),(2,3)
231  std::array<SeedingLayerSetsBuilder::SeedingLayerId,2> hitPair;
232  for(int i=0; i<3; i++){
234  hitPair[0] = Layer_tuple(hits[i]);
235  hitPair[1] = Layer_tuple(hits[i+1]);
236 
237  bool found;
239  found = false;
240  for(const auto p : layerPairs_){
241  pairCandidate = ls.slice(p,p+2);
242  if(hitPair[0] == seedingLayerIds[pairCandidate[0].index()] && hitPair[1] == seedingLayerIds[pairCandidate[1].index()]){
243  found = true;
244  break;
245  }
246  }
247  if(found)
248  break;
249  }
250  assert(found == true);
251  const DetLayer * fLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[i]->det()->geographicalId());
252  const DetLayer * sLayer = measurementTracker_->geometricSearchTracker()->detLayer(hits[i+1]->det()->geographicalId());
253  std::vector<BaseTrackerRecHit const *> fHits{hits[i]};
254  std::vector<BaseTrackerRecHit const *> sHits{hits[i+1]};
255 
256  //Important: doublets to be added to the cache
257  auto& layerCache = filler.layerHitMapCache();
258  const RecHitsSortedInPhi& firsthm = *layerCache.add(pairCandidate[0], std::make_unique<RecHitsSortedInPhi>(fHits, trackingRegion_->origin(), fLayer));
259  const RecHitsSortedInPhi& secondhm = *layerCache.add(pairCandidate[1], std::make_unique<RecHitsSortedInPhi>(sHits, trackingRegion_->origin(), sLayer));
260  HitDoublets res(firsthm,secondhm);
261  HitPairGeneratorFromLayerPair::doublets(*trackingRegion_,*fLayer,*sLayer,firsthm,secondhm,*eventSetup_,0,res);
262  filler.addDoublets(pairCandidate, std::move(res)); //fill the formed doublet
263  }
264 
265  std::vector<OrderedHitSeeds> quadrupletresult;
266  quadrupletresult.resize(ihd.regionSize());
267  for(auto& ntuplet : quadrupletresult)
268  ntuplet.reserve(4);
269  CAHitQuadGenerator_->hitNtuplets(ihd,quadrupletresult,*eventSetup_,*seedingLayer); //calling the function from the class, modifies quadrupletresult
270  return !quadrupletresult.empty();
271  }
272 
273  return true;
274 
275 }
276 
277 //new for Phase1
279 {
280  const TrackerTopology* const tTopo = trackerTopology.product();
283  int idLayer = 0;
284 
285  if( (hit->det()->geographicalId()).subdetId() == PixelSubdetector::PixelBarrel){
287  side = TrackerDetSide::Barrel;
288  idLayer = tTopo->pxbLayer(hit->det()->geographicalId());
289  }
290  else if ((hit->det()->geographicalId()).subdetId() == PixelSubdetector::PixelEndcap){
292  idLayer = tTopo->pxfDisk(hit->det()->geographicalId());
293  if(tTopo->pxfSide(hit->det()->geographicalId())==1){
295  }
296  else{
298  }
299  }
300  return std::make_tuple(subdet, side, idLayer);
301 }
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
def create(alignables, pedeDump, additionalData, outputFile, config)
std::unique_ptr< SeedingLayerSetsHits > seedingLayer
unsigned int pxfDisk(const DetId &id) const
TrackerDetSide
Definition: TrackerDetSide.h:4
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)
#define nullptr
std::unique_ptr< HitTripletGeneratorFromPairAndLayers > pixelTripletGenerator_
Definition: Electron.h:6
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:62
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_