CMS 3D CMS Logo

SeedingLayerSetsBuilder.cc
Go to the documentation of this file.
10 
14 
17 
19 
20 #include "HitExtractorPIX.h"
21 #include "HitExtractorSTRP.h"
22 
23 #include <iostream>
24 #include <sstream>
25 #include <ostream>
26 #include <fstream>
27 #include <map>
28 
29 
30 using namespace ctfseeding;
31 using namespace std;
32 
36  int idLayer = 0;
37 
38  size_t index;
39  //
40  // BPIX
41  //
42  if ((index = name.find("BPix")) != string::npos) {
45  idLayer = atoi(name.substr(index+4,1).c_str());
46  }
47  //
48  // FPIX
49  //
50  else if ((index = name.find("FPix")) != string::npos) {
52  idLayer = atoi(name.substr(index+4).c_str());
53  if ( name.find("pos") != string::npos ) {
55  } else {
57  }
58  }
59  //
60  // TIB
61  //
62  else if ((index = name.find("TIB")) != string::npos) {
63  subdet = GeomDetEnumerators::TIB;
65  idLayer = atoi(name.substr(index+3,1).c_str());
66  }
67  //
68  // TID
69  //
70  else if ((index = name.find("TID")) != string::npos) {
71  subdet = GeomDetEnumerators::TID;
72  idLayer = atoi(name.substr(index+3,1).c_str());
73  if ( name.find("pos") != string::npos ) {
75  } else {
77  }
78  }
79  //
80  // TOB
81  //
82  else if ((index = name.find("TOB")) != string::npos) {
83  subdet = GeomDetEnumerators::TOB;
85  idLayer = atoi(name.substr(index+3,1).c_str());
86  }
87  //
88  // TEC
89  //
90  else if ((index = name.find("TEC")) != string::npos) {
91  subdet = GeomDetEnumerators::TEC;
92  idLayer = atoi(name.substr(index+3,1).c_str());
93  if ( name.find("pos") != string::npos ) {
95  } else {
97  }
98  }
99  return std::make_tuple(subdet, side, idLayer);
100 }
101 
103  nameIndex(index),
104  hitBuilder(cfgLayer.getParameter<string>("TTRHBuilder"))
105 {
106  usePixelHitProducer = false;
107  if (cfgLayer.exists("HitProducer")) {
108  pixelHitProducer = cfgLayer.getParameter<string>("HitProducer");
109  usePixelHitProducer = true;
110  }
111 
112  bool skipClusters = cfgLayer.exists("skipClusters");
113  if (skipClusters) {
114  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" ready for skipping";
115  }
116  else{
117  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" not skipping ";
118  }
119 
120  auto subdetData = nameToEnumId(layerName);
121  subdet = std::get<0>(subdetData);
122  side = std::get<1>(subdetData);
123  idLayer = std::get<2>(subdetData);
126  extractor = std::make_unique<HitExtractorPIX>(side, idLayer, pixelHitProducer, iC);
127  }
128  else if(subdet != GeomDetEnumerators::invalidDet) { // strip
129  auto extr = std::make_unique<HitExtractorSTRP>(subdet, side, idLayer, clusterChargeCut(cfgLayer) );
130  if (cfgLayer.exists("matchedRecHits")) {
131  extr->useMatchedHits(cfgLayer.getParameter<edm::InputTag>("matchedRecHits"), iC);
132  }
133  if (cfgLayer.exists("rphiRecHits")) {
134  extr->useRPhiHits(cfgLayer.getParameter<edm::InputTag>("rphiRecHits"), iC);
135  }
136  if (cfgLayer.exists("stereoRecHits")) {
137  extr->useStereoHits(cfgLayer.getParameter<edm::InputTag>("stereoRecHits"), iC);
138  }
139  if (cfgLayer.exists("useRingSlector") && cfgLayer.getParameter<bool>("useRingSlector")) {
140  extr->useRingSelector(cfgLayer.getParameter<int>("minRing"),
141  cfgLayer.getParameter<int>("maxRing"));
142  }
143  bool useSimpleRphiHitsCleaner = cfgLayer.exists("useSimpleRphiHitsCleaner") ? cfgLayer.getParameter<bool>("useSimpleRphiHitsCleaner") : true;
144  extr->useSimpleRphiHitsCleaner(useSimpleRphiHitsCleaner);
145 
146  double minAbsZ = cfgLayer.exists("MinAbsZ") ? cfgLayer.getParameter<double>("MinAbsZ") : 0.;
147  if(minAbsZ > 0.) {
148  extr->setMinAbsZ(minAbsZ);
149  }
150  if(skipClusters) {
151  bool useProjection = cfgLayer.exists("useProjection") ? cfgLayer.getParameter<bool>("useProjection") : false;
152  if(useProjection) {
153  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" will project partially masked matched rechit";
154  }
155  else {
156  extr->setNoProjection();
157  }
158  }
159  extractor = std::move(extr);
160  }
161  if(extractor && skipClusters) {
162  extractor->useSkipClusters(cfgLayer.getParameter<edm::InputTag>("skipClusters"), iC);
163  }
164 }
165 
166 std::string SeedingLayerSetsBuilder::LayerSpec::print(const std::vector<std::string>& names) const
167 {
168  std::ostringstream str;
169  str << "Layer="<<names[nameIndex]<<", hitBldr: "<<hitBuilder;
170 
171  str << ", useRingSelector: ";
172  HitExtractorSTRP *ext = nullptr;
173  if((ext = dynamic_cast<HitExtractorSTRP *>(extractor.get())) &&
174  ext->useRingSelector()) {
175  auto minMaxRing = ext->getMinMaxRing();
176  str <<"true,"<<" Rings: ("<< std::get<0>(minMaxRing) <<","<< std::get<1>(minMaxRing) <<")";
177  } else str<<"false";
178 
179  return str.str();
180 }
181 //FastSim specific constructor
183  SeedingLayerSetsBuilder(cfg, iC)
184 {
186 }
188  SeedingLayerSetsBuilder(cfg, iC)
189 {}
191 {
192  std::vector<std::string> namesPset = cfg.getParameter<std::vector<std::string> >("layerList");
193  std::vector<std::vector<std::string> > layerNamesInSets = this->layerNamesInSets(namesPset);
194  // debug printout of layers
195  typedef std::vector<std::string>::const_iterator IS;
196  typedef std::vector<std::vector<std::string> >::const_iterator IT;
197  std::ostringstream str;
198  // The following should not be set to cout
199 // for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
200 // str << "SET: ";
201 // for (IS is = it->begin(); is != it->end(); is++) str << *is <<" ";
202 // str << std::endl;
203 // }
204 // std::cout << str.str() << std::endl;
205  if(layerNamesInSets.empty())
207  else
208  theNumberOfLayersInSet = layerNamesInSets[0].size();
209 
210 
211  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
212  if(it->size() != theNumberOfLayersInSet)
213  throw cms::Exception("Configuration") << "Assuming all SeedingLayerSets to have same number of layers. LayerSet " << (it-layerNamesInSets.begin()) << " has " << it->size() << " while 0th has " << theNumberOfLayersInSet;
214  for(const std::string& layerName: *it) {
215  auto found = std::find(theLayerNames.begin(), theLayerNames.end(), layerName);
216  unsigned short layerIndex = 0;
217  if(found != theLayerNames.end()) {
218  layerIndex = found-theLayerNames.begin();
219  }
220  else {
222  throw cms::Exception("Assert") << "Too many layers in " << __FILE__ << ":" << __LINE__ << ", we may have to enlarge the index type from unsigned short to unsigned int";
223  }
224 
225  layerIndex = theLayers.size();
226  theLayers.emplace_back(theLayerNames.size(), layerName, layerConfig(layerName, cfg), iC);
227  theLayerNames.push_back(layerName);
228  }
229  theLayerSetIndices.push_back(layerIndex);
230  }
231  }
232  theLayerDets.resize(theLayers.size());
233  theTTRHBuilders.resize(theLayers.size());
234 
235  // debug printout
236  // The following should not be set to cout
237  //for(const LayerSpec& layer: theLayers) {
238  // std::cout << layer.print(theLayerNames) << std::endl;
239  //}
240 }
241 
243 
246  empty.setAllowAnything(); // for now accept any parameter in the PSets, consider improving later
247 
248  desc.add<std::vector<std::string> >("layerList", {});
249  desc.add<edm::ParameterSetDescription>("BPix", empty);
250  desc.add<edm::ParameterSetDescription>("FPix", empty);
251  desc.add<edm::ParameterSetDescription>("TIB", empty);
252  desc.add<edm::ParameterSetDescription>("TID", empty);
253  desc.add<edm::ParameterSetDescription>("TOB", empty);
254  desc.add<edm::ParameterSetDescription>("TEC", empty);
255  desc.add<edm::ParameterSetDescription>("MTIB", empty);
256  desc.add<edm::ParameterSetDescription>("MTID", empty);
257  desc.add<edm::ParameterSetDescription>("MTOB", empty);
258  desc.add<edm::ParameterSetDescription>("MTEC", empty);
259 }
260 
262 {
264 
265  for (string::size_type iEnd=nameLayer.size(); iEnd > 0; --iEnd) {
266  string name = nameLayer.substr(0,iEnd);
267  if (cfg.exists(name)) return cfg.getParameter<edm::ParameterSet>(name);
268  }
269  edm::LogError("SeedingLayerSetsBuilder") <<"configuration for layer: "<<nameLayer<<" not found, job will probably crash!";
270  return result;
271 }
272 
273 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets( const vector<string> & namesPSet)
274 {
275  std::vector<std::vector<std::string> > result;
276  for (std::vector<std::string>::const_iterator is=namesPSet.begin(); is < namesPSet.end(); ++is) {
277  vector<std::string> layersInSet;
278  string line = *is;
280  while (pos != string::npos ) {
281  pos=line.find("+");
282  string layer = line.substr(0,pos);
283  layersInSet.push_back(layer);
284  line=line.substr(pos+1,string::npos);
285  }
286  result.push_back(layersInSet);
287  }
288  return result;
289 }
290 
292  // We want to evaluate both in the first invocation (to properly
293  // initialize ESWatcher), and this way we avoid one branch compared
294  // to || (should be tiny effect)
295  if(! (geometryWatcher_.check(es) | trhWatcher_.check(es)) )
296  return;
297 
299  es.get<TrackerRecoGeometryRecord>().get( htracker );
300  const GeometricSearchTracker& tracker = *htracker;
301 
302  const std::vector<BarrelDetLayer const*>& bpx = tracker.barrelLayers();
303  const std::vector<BarrelDetLayer const*>& tib = tracker.tibLayers();
304  const std::vector<BarrelDetLayer const*>& tob = tracker.tobLayers();
305 
306  const std::vector<ForwardDetLayer const*>& fpx_pos = tracker.posForwardLayers();
307  const std::vector<ForwardDetLayer const*>& tid_pos = tracker.posTidLayers();
308  const std::vector<ForwardDetLayer const*>& tec_pos = tracker.posTecLayers();
309 
310  const std::vector<ForwardDetLayer const*>& fpx_neg = tracker.negForwardLayers();
311  const std::vector<ForwardDetLayer const*>& tid_neg = tracker.negTidLayers();
312  const std::vector<ForwardDetLayer const*>& tec_neg = tracker.negTecLayers();
313 
314  for(const auto& layer: theLayers) {
315  const DetLayer * detLayer = nullptr;
316  int index = layer.idLayer-1;
317 
318  if (layer.subdet == GeomDetEnumerators::PixelBarrel) {
319  detLayer = bpx[index];
320  }
321  else if (layer.subdet == GeomDetEnumerators::PixelEndcap) {
322  if (layer.side == TrackerDetSide::PosEndcap) {
323  detLayer = fpx_pos[index];
324  } else {
325  detLayer = fpx_neg[index];
326  }
327  }
328  else if (layer.subdet == GeomDetEnumerators::TIB) {
329  detLayer = tib[index];
330  }
331  else if (layer.subdet == GeomDetEnumerators::TID) {
332  if (layer.side == TrackerDetSide::PosEndcap) {
333  detLayer = tid_pos[index];
334  } else {
335  detLayer = tid_neg[index];
336  }
337  }
338  else if (layer.subdet == GeomDetEnumerators::TOB) {
339  detLayer = tob[index];
340  }
341  else if (layer.subdet == GeomDetEnumerators::TEC) {
342  if (layer.side == TrackerDetSide::PosEndcap) {
343  detLayer = tec_pos[index];
344  } else {
345  detLayer = tec_neg[index];
346  }
347  }
348  else {
349  throw cms::Exception("Configuration") << "Did not find DetLayer for layer " << theLayerNames[layer.nameIndex];
350  }
351 
353  es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
354 
355  theLayerDets[layer.nameIndex] = detLayer;
356  theTTRHBuilders[layer.nameIndex] = builder.product();
357  }
358 }
359 
360 std::vector<SeedingLayerSetsBuilder::SeedingLayerId> SeedingLayerSetsBuilder::layers() const {
361  std::vector<SeedingLayerId> ret;
362  ret.reserve(numberOfLayers());
363  for(const auto& layer: theLayers) {
364  ret.emplace_back(layer.subdet, layer.side, layer.idLayer);
365  }
366  return ret;
367 }
368 
369 std::unique_ptr<SeedingLayerSetsHits> SeedingLayerSetsBuilder::hits(const edm::Event& ev, const edm::EventSetup& es) {
370  updateEventSetup(es);
371 
372  auto ret = std::make_unique<SeedingLayerSetsHits>(theNumberOfLayersInSet,
374  &theLayerNames,
375  &theLayerDets);
376 
377  for(auto& layer: theLayers) {
378  ret->addHits(layer.nameIndex, layer.extractor->hits((const TkTransientTrackingRecHitBuilder &)(*theTTRHBuilders[layer.nameIndex]), ev, es));
379  }
380  ret->shrink_to_fit();
381  return ret;
382 }
383 //new function for FastSim only
384 std::unique_ptr<SeedingLayerSetsHits> SeedingLayerSetsBuilder::makeSeedingLayerSetsHitsforFastSim(const edm::Event& ev, const edm::EventSetup& es) {
385  updateEventSetup(es);
386 
388  ev.getByToken(fastSimrecHitsToken_,fastSimrechits_); //using FastSim RecHits
389  edm::ESHandle<TrackerTopology> trackerTopology;
390  es.get<TrackerTopologyRcd>().get(trackerTopology);
391  const TrackerTopology* const tTopo = trackerTopology.product();
393 
394  auto ret = std::make_unique<SeedingLayerSetsHits>(theNumberOfLayersInSet,
396  &theLayerNames,
397  &theLayerDets);
398 
399  for(auto& layer: theLayers) {
400  layerhits_.clear();
401  for(auto &rh : *fastSimrechits_){
404  int idLayer = 0;
405  if( (rh.det()->geographicalId()).subdetId() == PixelSubdetector::PixelBarrel){
407  side = TrackerDetSide::Barrel;
408  idLayer = tTopo->pxbLayer(rh.det()->geographicalId());
409  }
410  else if ((rh.det()->geographicalId()).subdetId() == PixelSubdetector::PixelEndcap){
412  idLayer = tTopo->pxfDisk(rh.det()->geographicalId());
413  if(tTopo->pxfSide(rh.det()->geographicalId())==1)
415  else
417  }
418 
419  if(layer.subdet == subdet && layer.side == side && layer.idLayer == idLayer){
420  BaseTrackerRecHit const & b(rh);
421  auto ptrHit = (BaseTrackerRecHit *)(b.clone());
422  layerhits_.emplace_back(ptrHit);
423  }
424  else continue;
425  }
426  ret->addHits(layer.nameIndex, std::move(layerhits_));
427  }
428  ret->shrink_to_fit();
429  return ret;
430 }
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::vector< ForwardDetLayer const * > const & posForwardLayers() const
std::vector< LayerSpec > theLayers
SeedingLayerSetsBuilder()=default
edm::ESWatcher< TrackerRecoGeometryRecord > geometryWatcher_
LayerSpec(unsigned short index, const std::string &layerName, const edm::ParameterSet &cfgLayer, edm::ConsumesCollector &iC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void setAllowAnything()
allow any parameter label/value pairs
edm::EDGetTokenT< FastTrackerRecHitCollection > fastSimrecHitsToken_
std::vector< std::string > theLayerNames
unsigned int pxfDisk(const DetId &id) const
std::unique_ptr< SeedingLayerSetsHits > makeSeedingLayerSetsHitsforFastSim(const edm::Event &ev, const edm::EventSetup &es)
TrackerDetSide
Definition: TrackerDetSide.h:4
std::unique_ptr< ctfseeding::HitExtractor > extractor
bool exists(std::string const &parameterName) const
checks if a parameter exists
float clusterChargeCut(const edm::ParameterSet &conf, const char *name="clusterChargeCut")
std::vector< BarrelDetLayer const * > const & tobLayers() const
bool ev
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< SeedingLayerId > layers() const
uint16_t size_type
const std::string names[nVars_]
std::vector< const TransientTrackingRecHitBuilder * > theTTRHBuilders
GeomDetEnumerators::SubDetector subdet
std::tuple< GeomDetEnumerators::SubDetector, TrackerDetSide, int > SeedingLayerId
void updateEventSetup(const edm::EventSetup &es)
virtual TrackingRecHit * clone() const =0
std::vector< ForwardDetLayer const * > const & negForwardLayers() const
std::unique_ptr< SeedingLayerSetsHits > hits(const edm::Event &ev, const edm::EventSetup &es)
std::vector< SeedingLayerSetsHits::LayerSetIndex > theLayerSetIndices
std::vector< LinkConnSpec >::const_iterator IT
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::ESWatcher< TransientRecHitRecord > trhWatcher_
unsigned int pxbLayer(const DetId &id) const
static SeedingLayerId nameToEnumId(const std::string &name)
void useRingSelector(int minRing, int maxRing)
std::vector< BarrelDetLayer const * > const & tibLayers() const
std::vector< ForwardDetLayer const * > const & posTecLayers() const
double b
Definition: hdecay.h:120
unsigned short numberOfLayers() const
std::vector< ForwardDetLayer const * > const & negTidLayers() const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
std::vector< ForwardDetLayer const * > const & posTidLayers() const
T get() const
Definition: EventSetup.h:71
std::string print(const std::vector< std::string > &names) const
unsigned int pxfSide(const DetId &id) const
static void fillDescriptions(edm::ParameterSetDescription &desc)
std::vector< HitPointer > OwnedHits
Definition: memstream.h:15
std::vector< ForwardDetLayer const * > const & negTecLayers() const
#define str(s)
T const * product() const
Definition: ESHandle.h:86
std::tuple< int, int > getMinMaxRing() const
edm::ParameterSet layerConfig(const std::string &nameLayer, const edm::ParameterSet &cfg) const
def move(src, dest)
Definition: eostools.py:511
std::vector< const DetLayer * > theLayerDets
std::vector< BarrelDetLayer const * > const & barrelLayers() const
static std::vector< std::vector< std::string > > layerNamesInSets(const std::vector< std::string > &namesPSet)