CMS 3D CMS Logo

SeedingLayerSetsBuilder.cc
Go to the documentation of this file.
2 
6 
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 
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  nameIndex(index),
103  hitBuilder(cfgLayer.getParameter<string>("TTRHBuilder"))
104 {
105  usePixelHitProducer = false;
106  if (cfgLayer.exists("HitProducer")) {
107  pixelHitProducer = cfgLayer.getParameter<string>("HitProducer");
108  usePixelHitProducer = true;
109  }
110 
111  bool skipClusters = cfgLayer.exists("skipClusters");
112  if (skipClusters) {
113  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" ready for skipping";
114  }
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);
125  extractor = std::make_unique<HitExtractorPIX>(side, idLayer, pixelHitProducer, iC);
126  }
127  else if(subdet != GeomDetEnumerators::invalidDet) { // strip
128  auto extr = std::make_unique<HitExtractorSTRP>(subdet, side, idLayer, clusterChargeCut(cfgLayer) );
129  if (cfgLayer.exists("matchedRecHits")) {
130  extr->useMatchedHits(cfgLayer.getParameter<edm::InputTag>("matchedRecHits"), iC);
131  }
132  if (cfgLayer.exists("rphiRecHits")) {
133  extr->useRPhiHits(cfgLayer.getParameter<edm::InputTag>("rphiRecHits"), iC);
134  }
135  if (cfgLayer.exists("stereoRecHits")) {
136  extr->useStereoHits(cfgLayer.getParameter<edm::InputTag>("stereoRecHits"), iC);
137  }
138  if (cfgLayer.exists("useRingSlector") && cfgLayer.getParameter<bool>("useRingSlector")) {
139  extr->useRingSelector(cfgLayer.getParameter<int>("minRing"),
140  cfgLayer.getParameter<int>("maxRing"));
141  }
142  bool useSimpleRphiHitsCleaner = cfgLayer.exists("useSimpleRphiHitsCleaner") ? cfgLayer.getParameter<bool>("useSimpleRphiHitsCleaner") : true;
143  extr->useSimpleRphiHitsCleaner(useSimpleRphiHitsCleaner);
144 
145  double minAbsZ = cfgLayer.exists("MinAbsZ") ? cfgLayer.getParameter<double>("MinAbsZ") : 0.;
146  if(minAbsZ > 0.) {
147  extr->setMinAbsZ(minAbsZ);
148  }
149  if(skipClusters) {
150  bool useProjection = cfgLayer.exists("useProjection") ? cfgLayer.getParameter<bool>("useProjection") : false;
151  if(useProjection) {
152  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" will project partially masked matched rechit";
153  }
154  else {
155  extr->setNoProjection();
156  }
157  }
158  extractor = std::move(extr);
159  }
160  if(extractor && skipClusters) {
161  extractor->useSkipClusters(cfgLayer.getParameter<edm::InputTag>("skipClusters"), iC);
162  }
163 }
164 
165 std::string SeedingLayerSetsBuilder::LayerSpec::print(const std::vector<std::string>& names) const
166 {
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())) &&
173  ext->useRingSelector()) {
174  auto minMaxRing = ext->getMinMaxRing();
175  str <<"true,"<<" Rings: ("<< std::get<0>(minMaxRing) <<","<< std::get<1>(minMaxRing) <<")";
176  } else str<<"false";
177 
178  return str.str();
179 }
180 
182  SeedingLayerSetsBuilder(cfg, iC)
183 {}
185 {
186  std::vector<std::string> namesPset = cfg.getParameter<std::vector<std::string> >("layerList");
187  std::vector<std::vector<std::string> > layerNamesInSets = this->layerNamesInSets(namesPset);
188 
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 
206  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
207  if(it->size() != theNumberOfLayersInSet)
208  throw cms::Exception("Configuration") << "Assuming all SeedingLayerSets to have same number of layers. LayerSet " << (it-layerNamesInSets.begin()) << " has " << it->size() << " while 0th has " << theNumberOfLayersInSet;
209  for(const std::string& layerName: *it) {
210  auto found = std::find(theLayerNames.begin(), theLayerNames.end(), layerName);
211  unsigned short layerIndex = 0;
212  if(found != theLayerNames.end()) {
213  layerIndex = found-theLayerNames.begin();
214  }
215  else {
217  throw cms::Exception("Assert") << "Too many layers in " << __FILE__ << ":" << __LINE__ << ", we may have to enlarge the index type from unsigned short to unsigned int";
218  }
219 
220  layerIndex = theLayers.size();
221  theLayers.emplace_back(theLayerNames.size(), layerName, layerConfig(layerName, cfg), iC);
222  theLayerNames.push_back(layerName);
223  }
224  theLayerSetIndices.push_back(layerIndex);
225  }
226  }
227  theLayerDets.resize(theLayers.size());
228  theTTRHBuilders.resize(theLayers.size());
229 
230  // debug printout
231  // The following should not be set to cout
232  //for(const LayerSpec& layer: theLayers) {
233  // std::cout << layer.print(theLayerNames) << std::endl;
234  //}
235 }
236 
238 
241  empty.setAllowAnything(); // for now accept any parameter in the PSets, consider improving later
242 
243  desc.add<std::vector<std::string> >("layerList", {});
244  desc.add<edm::ParameterSetDescription>("BPix", empty);
245  desc.add<edm::ParameterSetDescription>("FPix", empty);
246  desc.add<edm::ParameterSetDescription>("TIB", empty);
247  desc.add<edm::ParameterSetDescription>("TID", empty);
248  desc.add<edm::ParameterSetDescription>("TOB", empty);
249  desc.add<edm::ParameterSetDescription>("TEC", empty);
250  desc.add<edm::ParameterSetDescription>("MTIB", empty);
251  desc.add<edm::ParameterSetDescription>("MTID", empty);
252  desc.add<edm::ParameterSetDescription>("MTOB", empty);
253  desc.add<edm::ParameterSetDescription>("MTEC", empty);
254 }
255 
257 {
259 
260  for (string::size_type iEnd=nameLayer.size(); iEnd > 0; --iEnd) {
261  string name = nameLayer.substr(0,iEnd);
262  if (cfg.exists(name)) return cfg.getParameter<edm::ParameterSet>(name);
263  }
264  edm::LogError("SeedingLayerSetsBuilder") <<"configuration for layer: "<<nameLayer<<" not found, job will probably crash!";
265  return result;
266 }
267 
268 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets( const vector<string> & namesPSet)
269 {
270  std::vector<std::vector<std::string> > result;
271  for (std::vector<std::string>::const_iterator is=namesPSet.begin(); is < namesPSet.end(); ++is) {
272  vector<std::string> layersInSet;
273  string line = *is;
275  while (pos != string::npos ) {
276  pos=line.find("+");
277  string layer = line.substr(0,pos);
278  layersInSet.push_back(layer);
279  line=line.substr(pos+1,string::npos);
280  }
281  result.push_back(layersInSet);
282  }
283  return result;
284 }
285 
287  // We want to evaluate both in the first invocation (to properly
288  // initialize ESWatcher), and this way we avoid one branch compared
289  // to || (should be tiny effect)
290  if(! (geometryWatcher_.check(es) | trhWatcher_.check(es)) )
291  return;
292 
294  es.get<TrackerRecoGeometryRecord>().get( htracker );
295  const GeometricSearchTracker& tracker = *htracker;
296 
297  const std::vector<BarrelDetLayer const*>& bpx = tracker.barrelLayers();
298  const std::vector<BarrelDetLayer const*>& tib = tracker.tibLayers();
299  const std::vector<BarrelDetLayer const*>& tob = tracker.tobLayers();
300 
301  const std::vector<ForwardDetLayer const*>& fpx_pos = tracker.posForwardLayers();
302  const std::vector<ForwardDetLayer const*>& tid_pos = tracker.posTidLayers();
303  const std::vector<ForwardDetLayer const*>& tec_pos = tracker.posTecLayers();
304 
305  const std::vector<ForwardDetLayer const*>& fpx_neg = tracker.negForwardLayers();
306  const std::vector<ForwardDetLayer const*>& tid_neg = tracker.negTidLayers();
307  const std::vector<ForwardDetLayer const*>& tec_neg = tracker.negTecLayers();
308 
309  for(const auto& layer: theLayers) {
310  const DetLayer * detLayer = nullptr;
311  int index = layer.idLayer-1;
312 
313  if (layer.subdet == GeomDetEnumerators::PixelBarrel) {
314  detLayer = bpx[index];
315  }
316  else if (layer.subdet == GeomDetEnumerators::PixelEndcap) {
317  if (layer.side == TrackerDetSide::PosEndcap) {
318  detLayer = fpx_pos[index];
319  } else {
320  detLayer = fpx_neg[index];
321  }
322  }
323  else if (layer.subdet == GeomDetEnumerators::TIB) {
324  detLayer = tib[index];
325  }
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  }
333  else if (layer.subdet == GeomDetEnumerators::TOB) {
334  detLayer = tob[index];
335  }
336  else if (layer.subdet == GeomDetEnumerators::TEC) {
337  if (layer.side == TrackerDetSide::PosEndcap) {
338  detLayer = tec_pos[index];
339  } else {
340  detLayer = tec_neg[index];
341  }
342  }
343  else {
344  throw cms::Exception("Configuration") << "Did not find DetLayer for layer " << theLayerNames[layer.nameIndex];
345  }
346 
348  es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
349 
350  theLayerDets[layer.nameIndex] = detLayer;
351  theTTRHBuilders[layer.nameIndex] = builder.product();
352  }
353 }
354 
355 std::vector<SeedingLayerSetsBuilder::SeedingLayerId> SeedingLayerSetsBuilder::layers() const {
356  std::vector<SeedingLayerId> ret;
357  ret.reserve(numberOfLayers());
358  for(const auto& layer: theLayers) {
359  ret.emplace_back(layer.subdet, layer.side, layer.idLayer);
360  }
361  return ret;
362 }
363 
364 std::unique_ptr<SeedingLayerSetsHits> SeedingLayerSetsBuilder::hits(const edm::Event& ev, const edm::EventSetup& es) {
365  updateEventSetup(es);
366 
367  auto ret = std::make_unique<SeedingLayerSetsHits>(theNumberOfLayersInSet,
369  &theLayerNames,
370  &theLayerDets);
371 
372  for(auto& layer: theLayers) {
373  ret->addHits(layer.nameIndex, layer.extractor->hits((const TkTransientTrackingRecHitBuilder &)(*theTTRHBuilders[layer.nameIndex]), ev, es));
374  }
375  ret->shrink_to_fit();
376  return ret;
377 }
#define LogDebug(id)
T getParameter(std::string const &) const
static const HistoName names[]
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)
void setAllowAnything()
allow any parameter label/value pairs
std::vector< std::string > theLayerNames
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
std::vector< const TransientTrackingRecHitBuilder * > theTTRHBuilders
GeomDetEnumerators::SubDetector subdet
std::tuple< GeomDetEnumerators::SubDetector, TrackerDetSide, int > SeedingLayerId
void updateEventSetup(const edm::EventSetup &es)
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_
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
const T & get() const
Definition: EventSetup.h:59
unsigned short numberOfLayers() const
std::vector< ForwardDetLayer const * > const & negTidLayers() const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< ForwardDetLayer const * > const & posTidLayers() const
std::string print(const std::vector< std::string > &names) const
static void fillDescriptions(edm::ParameterSetDescription &desc)
Definition: memstream.h:15
std::vector< ForwardDetLayer const * > const & negTecLayers() const
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:510
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)