CMS 3D CMS Logo

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