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 using namespace ctfseeding;
30 using namespace std;
31 
35  int idLayer = 0;
36 
37  size_t index;
38  //
39  // BPIX
40  //
41  if ((index = name.find("BPix")) != string::npos) {
44  idLayer = atoi(name.substr(index + 4, 1).c_str());
45  }
46  //
47  // FPIX
48  //
49  else if ((index = name.find("FPix")) != string::npos) {
51  idLayer = atoi(name.substr(index + 4).c_str());
52  if (name.find("pos") != string::npos) {
54  } else {
56  }
57  }
58  //
59  // TIB
60  //
61  else if ((index = name.find("TIB")) != string::npos) {
62  subdet = GeomDetEnumerators::TIB;
64  idLayer = atoi(name.substr(index + 3, 1).c_str());
65  }
66  //
67  // TID
68  //
69  else if ((index = name.find("TID")) != string::npos) {
70  subdet = GeomDetEnumerators::TID;
71  idLayer = atoi(name.substr(index + 3, 1).c_str());
72  if (name.find("pos") != string::npos) {
74  } else {
76  }
77  }
78  //
79  // TOB
80  //
81  else if ((index = name.find("TOB")) != string::npos) {
82  subdet = GeomDetEnumerators::TOB;
84  idLayer = atoi(name.substr(index + 3, 1).c_str());
85  }
86  //
87  // TEC
88  //
89  else if ((index = name.find("TEC")) != string::npos) {
90  subdet = GeomDetEnumerators::TEC;
91  idLayer = atoi(name.substr(index + 3, 1).c_str());
92  if (name.find("pos") != string::npos) {
94  } else {
96  }
97  }
98  return std::make_tuple(subdet, side, idLayer);
99 }
100 
102  const std::string& layerName,
103  const edm::ParameterSet& cfgLayer,
105  : nameIndex(index), hitBuilder(cfgLayer.getParameter<string>("TTRHBuilder")) {
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  } else {
116  LogDebug("SeedingLayerSetsBuilder") << layerName << " not skipping ";
117  }
118 
119  auto subdetData = nameToEnumId(layerName);
120  subdet = std::get<0>(subdetData);
121  side = std::get<1>(subdetData);
122  idLayer = std::get<2>(subdetData);
124  extractor = std::make_unique<HitExtractorPIX>(side, idLayer, pixelHitProducer, iC);
125  } else if (subdet != GeomDetEnumerators::invalidDet) { // strip
126  auto extr = std::make_unique<HitExtractorSTRP>(subdet, side, idLayer, clusterChargeCut(cfgLayer));
127  if (cfgLayer.exists("matchedRecHits")) {
128  extr->useMatchedHits(cfgLayer.getParameter<edm::InputTag>("matchedRecHits"), iC);
129  }
130  if (cfgLayer.exists("rphiRecHits")) {
131  extr->useRPhiHits(cfgLayer.getParameter<edm::InputTag>("rphiRecHits"), iC);
132  }
133  if (cfgLayer.exists("stereoRecHits")) {
134  extr->useStereoHits(cfgLayer.getParameter<edm::InputTag>("stereoRecHits"), iC);
135  }
136  if (cfgLayer.exists("useRingSlector") && cfgLayer.getParameter<bool>("useRingSlector")) {
137  extr->useRingSelector(cfgLayer.getParameter<int>("minRing"), cfgLayer.getParameter<int>("maxRing"));
138  }
140  cfgLayer.exists("useSimpleRphiHitsCleaner") ? cfgLayer.getParameter<bool>("useSimpleRphiHitsCleaner") : true;
141  extr->useSimpleRphiHitsCleaner(useSimpleRphiHitsCleaner);
142 
143  double minAbsZ = cfgLayer.exists("MinAbsZ") ? cfgLayer.getParameter<double>("MinAbsZ") : 0.;
144  if (minAbsZ > 0.) {
145  extr->setMinAbsZ(minAbsZ);
146  }
147  if (skipClusters) {
148  bool useProjection = cfgLayer.exists("useProjection") ? cfgLayer.getParameter<bool>("useProjection") : false;
149  if (useProjection) {
150  LogDebug("SeedingLayerSetsBuilder") << layerName << " will project partially masked matched rechit";
151  } else {
152  extr->setNoProjection();
153  }
154  }
155  extractor = std::move(extr);
156  }
157  if (extractor && skipClusters) {
158  extractor->useSkipClusters(cfgLayer.getParameter<edm::InputTag>("skipClusters"), iC);
159  }
160 }
161 
162 std::string SeedingLayerSetsBuilder::LayerSpec::print(const std::vector<std::string>& names) const {
163  std::ostringstream str;
164  str << "Layer=" << names[nameIndex] << ", hitBldr: " << hitBuilder;
165 
166  str << ", useRingSelector: ";
167  HitExtractorSTRP* ext = nullptr;
168  if ((ext = dynamic_cast<HitExtractorSTRP*>(extractor.get())) && ext->useRingSelector()) {
169  auto minMaxRing = ext->getMinMaxRing();
170  str << "true,"
171  << " Rings: (" << std::get<0>(minMaxRing) << "," << std::get<1>(minMaxRing) << ")";
172  } else
173  str << "false";
174 
175  return str.str();
176 }
177 //FastSim specific constructor
180  const edm::InputTag& fastsimHitTag)
181  : SeedingLayerSetsBuilder(cfg, iC) {
183 }
185  : SeedingLayerSetsBuilder(cfg, iC) {}
187  std::vector<std::string> namesPset = cfg.getParameter<std::vector<std::string> >("layerList");
188  std::vector<std::vector<std::string> > layerNamesInSets = this->layerNamesInSets(namesPset);
189  // debug printout of layers
190  typedef std::vector<std::string>::const_iterator IS;
191  typedef std::vector<std::vector<std::string> >::const_iterator IT;
192  std::ostringstream str;
193  // The following should not be set to cout
194  // for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
195  // str << "SET: ";
196  // for (IS is = it->begin(); is != it->end(); is++) str << *is <<" ";
197  // str << std::endl;
198  // }
199  // std::cout << str.str() << std::endl;
200  if (layerNamesInSets.empty())
202  else
203  theNumberOfLayersInSet = layerNamesInSets[0].size();
204 
205  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
206  if (it->size() != theNumberOfLayersInSet)
207  throw cms::Exception("Configuration")
208  << "Assuming all SeedingLayerSets to have same number of layers. LayerSet " << (it - layerNamesInSets.begin())
209  << " has " << it->size() << " while 0th has " << theNumberOfLayersInSet;
210  for (const std::string& layerName : *it) {
211  auto found = std::find(theLayerNames.begin(), theLayerNames.end(), layerName);
212  unsigned short layerIndex = 0;
213  if (found != theLayerNames.end()) {
214  layerIndex = found - theLayerNames.begin();
215  } else {
217  throw cms::Exception("Assert")
218  << "Too many layers in " << __FILE__ << ":" << __LINE__
219  << ", we may have to enlarge the index type from unsigned short to unsigned int";
220  }
221 
222  layerIndex = theLayers.size();
223  theLayers.emplace_back(theLayerNames.size(), layerName, layerConfig(layerName, cfg), iC);
224  theLayerNames.push_back(layerName);
225  }
226  theLayerSetIndices.push_back(layerIndex);
227  }
228  }
229  theLayerDets.resize(theLayers.size());
230  theTTRHBuilders.resize(theLayers.size());
231 
232  // debug printout
233  // The following should not be set to cout
234  //for(const LayerSpec& layer: theLayers) {
235  // std::cout << layer.print(theLayerNames) << std::endl;
236  //}
237 }
238 
240 
243  empty.setAllowAnything(); // for now accept any parameter in the PSets, consider improving later
244 
245  desc.add<std::vector<std::string> >("layerList", {});
246  desc.add<edm::ParameterSetDescription>("BPix", empty);
247  desc.add<edm::ParameterSetDescription>("FPix", empty);
248  desc.add<edm::ParameterSetDescription>("TIB", empty);
249  desc.add<edm::ParameterSetDescription>("TID", empty);
250  desc.add<edm::ParameterSetDescription>("TOB", empty);
251  desc.add<edm::ParameterSetDescription>("TEC", empty);
252  desc.add<edm::ParameterSetDescription>("MTIB", empty);
253  desc.add<edm::ParameterSetDescription>("MTID", empty);
254  desc.add<edm::ParameterSetDescription>("MTOB", empty);
255  desc.add<edm::ParameterSetDescription>("MTEC", empty);
256 }
257 
259  const edm::ParameterSet& cfg) const {
261 
262  for (string::size_type iEnd = nameLayer.size(); iEnd > 0; --iEnd) {
263  string name = nameLayer.substr(0, iEnd);
264  if (cfg.exists(name))
265  return cfg.getParameter<edm::ParameterSet>(name);
266  }
267  edm::LogError("SeedingLayerSetsBuilder")
268  << "configuration for layer: " << nameLayer << " not found, job will probably crash!";
269  return result;
270 }
271 
272 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets(const vector<string>& namesPSet) {
273  std::vector<std::vector<std::string> > result;
274  for (std::vector<std::string>::const_iterator is = namesPSet.begin(); is < namesPSet.end(); ++is) {
275  vector<std::string> layersInSet;
276  string line = *is;
278  while (pos != string::npos) {
279  pos = line.find("+");
280  string layer = line.substr(0, pos);
281  layersInSet.push_back(layer);
282  line = line.substr(pos + 1, string::npos);
283  }
284  result.push_back(layersInSet);
285  }
286  return result;
287 }
288 
290  // We want to evaluate both in the first invocation (to properly
291  // initialize ESWatcher), and this way we avoid one branch compared
292  // to || (should be tiny effect)
293  if (!(geometryWatcher_.check(es) | trhWatcher_.check(es)))
294  return;
295 
297  es.get<TrackerRecoGeometryRecord>().get(htracker);
298  const GeometricSearchTracker& tracker = *htracker;
299 
300  const std::vector<BarrelDetLayer const*>& bpx = tracker.barrelLayers();
301  const std::vector<BarrelDetLayer const*>& tib = tracker.tibLayers();
302  const std::vector<BarrelDetLayer const*>& tob = tracker.tobLayers();
303 
304  const std::vector<ForwardDetLayer const*>& fpx_pos = tracker.posForwardLayers();
305  const std::vector<ForwardDetLayer const*>& tid_pos = tracker.posTidLayers();
306  const std::vector<ForwardDetLayer const*>& tec_pos = tracker.posTecLayers();
307 
308  const std::vector<ForwardDetLayer const*>& fpx_neg = tracker.negForwardLayers();
309  const std::vector<ForwardDetLayer const*>& tid_neg = tracker.negTidLayers();
310  const std::vector<ForwardDetLayer const*>& tec_neg = tracker.negTecLayers();
311 
312  for (const auto& layer : theLayers) {
313  const DetLayer* detLayer = nullptr;
314  int index = layer.idLayer - 1;
315 
316  if (layer.subdet == GeomDetEnumerators::PixelBarrel) {
317  detLayer = bpx[index];
318  } else if (layer.subdet == GeomDetEnumerators::PixelEndcap) {
319  if (layer.side == TrackerDetSide::PosEndcap) {
320  detLayer = fpx_pos[index];
321  } else {
322  detLayer = fpx_neg[index];
323  }
324  } else if (layer.subdet == GeomDetEnumerators::TIB) {
325  detLayer = tib[index];
326  } else if (layer.subdet == GeomDetEnumerators::TID) {
327  if (layer.side == TrackerDetSide::PosEndcap) {
328  detLayer = tid_pos[index];
329  } else {
330  detLayer = tid_neg[index];
331  }
332  } else if (layer.subdet == GeomDetEnumerators::TOB) {
333  detLayer = tob[index];
334  } else if (layer.subdet == GeomDetEnumerators::TEC) {
335  if (layer.side == TrackerDetSide::PosEndcap) {
336  detLayer = tec_pos[index];
337  } else {
338  detLayer = tec_neg[index];
339  }
340  } else {
341  throw cms::Exception("Configuration") << "Did not find DetLayer for layer " << theLayerNames[layer.nameIndex];
342  }
343 
345  es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
346 
347  theLayerDets[layer.nameIndex] = detLayer;
348  theTTRHBuilders[layer.nameIndex] = builder.product();
349  }
350 }
351 
352 std::vector<SeedingLayerSetsBuilder::SeedingLayerId> SeedingLayerSetsBuilder::layers() const {
353  std::vector<SeedingLayerId> ret;
354  ret.reserve(numberOfLayers());
355  for (const auto& layer : theLayers) {
356  ret.emplace_back(layer.subdet, layer.side, layer.idLayer);
357  }
358  return ret;
359 }
360 
361 std::unique_ptr<SeedingLayerSetsHits> SeedingLayerSetsBuilder::hits(const edm::Event& ev, const edm::EventSetup& es) {
362  updateEventSetup(es);
363 
364  auto ret = std::make_unique<SeedingLayerSetsHits>(
366 
367  for (auto& layer : theLayers) {
368  ret->addHits(
369  layer.nameIndex,
370  layer.extractor->hits((const TkTransientTrackingRecHitBuilder&)(*theTTRHBuilders[layer.nameIndex]), ev, es));
371  }
372  ret->shrink_to_fit();
373  return ret;
374 }
375 //new function for FastSim only
377  const edm::Event& ev, const edm::EventSetup& es) {
378  updateEventSetup(es);
379 
381  ev.getByToken(fastSimrecHitsToken_, fastSimrechits_); //using FastSim RecHits
382  edm::ESHandle<TrackerTopology> trackerTopology;
383  es.get<TrackerTopologyRcd>().get(trackerTopology);
384  const TrackerTopology* const tTopo = trackerTopology.product();
386 
387  auto ret = std::make_unique<SeedingLayerSetsHits>(
389 
390  for (auto& layer : theLayers) {
391  layerhits_.clear();
392  for (auto& rh : *fastSimrechits_) {
395  int idLayer = 0;
396  if ((rh.det()->geographicalId()).subdetId() == PixelSubdetector::PixelBarrel) {
398  side = TrackerDetSide::Barrel;
399  idLayer = tTopo->pxbLayer(rh.det()->geographicalId());
400  } else if ((rh.det()->geographicalId()).subdetId() == PixelSubdetector::PixelEndcap) {
402  idLayer = tTopo->pxfDisk(rh.det()->geographicalId());
403  if (tTopo->pxfSide(rh.det()->geographicalId()) == 1)
405  else
407  }
408 
409  if (layer.subdet == subdet && layer.side == side && layer.idLayer == idLayer) {
410  BaseTrackerRecHit const& b(rh);
411  auto ptrHit = (BaseTrackerRecHit*)(b.clone());
412  layerhits_.emplace_back(ptrHit);
413  } else
414  continue;
415  }
416  ret->addHits(layer.nameIndex, std::move(layerhits_));
417  }
418  ret->shrink_to_fit();
419  return ret;
420 }
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::vector< const DetLayer * > theLayerDets
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:525
void setAllowAnything()
allow any parameter label/value pairs
edm::EDGetTokenT< FastTrackerRecHitCollection > fastSimrecHitsToken_
std::vector< std::string > theLayerNames
ret
prodAgent to be discontinued
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:19
std::vector< SeedingLayerId > layers() const
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)
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)
std::vector< const TransientTrackingRecHitBuilder * > theTTRHBuilders
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:118
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:73
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< BarrelDetLayer const * > const & barrelLayers() const
static std::vector< std::vector< std::string > > layerNamesInSets(const std::vector< std::string > &namesPSet)