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) {
43  side = SeedingLayer::Barrel;
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;
63  side = SeedingLayer::Barrel;
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;
83  side = SeedingLayer::Barrel;
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_shared<HitExtractorPIX>(side, idLayer, pixelHitProducer, iC);
126  }
127  else if(subdet != GeomDetEnumerators::invalidDet) { // strip
128  std::shared_ptr<HitExtractorSTRP> extr = std::make_shared<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 }
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 
184  SeedingLayerSetsBuilder(cfg, iC)
185 {}
187 {
188  std::vector<std::string> namesPset = cfg.getParameter<std::vector<std::string> >("layerList");
189  std::vector<std::vector<std::string> > layerNamesInSets = this->layerNamesInSets(namesPset);
190 
191  // debug printout of layers
192  typedef std::vector<std::string>::const_iterator IS;
193  typedef std::vector<std::vector<std::string> >::const_iterator IT;
194  std::ostringstream str;
195  // The following should not be set to cout
196 // for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
197 // str << "SET: ";
198 // for (IS is = it->begin(); is != it->end(); is++) str << *is <<" ";
199 // str << std::endl;
200 // }
201 // std::cout << str.str() << std::endl;
202  if(layerNamesInSets.size() == 0)
204  else
205  theNumberOfLayersInSet = layerNamesInSets[0].size();
206 
207 
208  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
209  if(it->size() != theNumberOfLayersInSet)
210  throw cms::Exception("Configuration") << "Assuming all SeedingLayerSets to have same number of layers. LayerSet " << (it-layerNamesInSets.begin()) << " has " << it->size() << " while 0th has " << theNumberOfLayersInSet;
211  for(const std::string& layerName: *it) {
212  auto found = std::find(theLayerNames.begin(), theLayerNames.end(), layerName);
213  unsigned short layerIndex = 0;
214  if(found != theLayerNames.end()) {
215  layerIndex = found-theLayerNames.begin();
216  }
217  else {
219  throw cms::Exception("Assert") << "Too many layers in " << __FILE__ << ":" << __LINE__ << ", 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 
242 {
244 
245  for (string::size_type iEnd=nameLayer.size(); iEnd > 0; --iEnd) {
246  string name = nameLayer.substr(0,iEnd);
247  if (cfg.exists(name)) return cfg.getParameter<edm::ParameterSet>(name);
248  }
249  edm::LogError("SeedingLayerSetsBuilder") <<"configuration for layer: "<<nameLayer<<" not found, job will probably crash!";
250  return result;
251 }
252 
253 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets( const vector<string> & namesPSet)
254 {
255  std::vector<std::vector<std::string> > result;
256  for (std::vector<std::string>::const_iterator is=namesPSet.begin(); is < namesPSet.end(); ++is) {
257  vector<std::string> layersInSet;
258  string line = *is;
260  while (pos != string::npos ) {
261  pos=line.find("+");
262  string layer = line.substr(0,pos);
263  layersInSet.push_back(layer);
264  line=line.substr(pos+1,string::npos);
265  }
266  result.push_back(layersInSet);
267  }
268  return result;
269 }
270 
273  es.get<TrackerRecoGeometryRecord>().get( htracker );
274  const GeometricSearchTracker& tracker = *htracker;
275 
276  const std::vector<BarrelDetLayer const*>& bpx = tracker.barrelLayers();
277  const std::vector<BarrelDetLayer const*>& tib = tracker.tibLayers();
278  const std::vector<BarrelDetLayer const*>& tob = tracker.tobLayers();
279 
280  const std::vector<ForwardDetLayer const*>& fpx_pos = tracker.posForwardLayers();
281  const std::vector<ForwardDetLayer const*>& tid_pos = tracker.posTidLayers();
282  const std::vector<ForwardDetLayer const*>& tec_pos = tracker.posTecLayers();
283 
284  const std::vector<ForwardDetLayer const*>& fpx_neg = tracker.negForwardLayers();
285  const std::vector<ForwardDetLayer const*>& tid_neg = tracker.negTidLayers();
286  const std::vector<ForwardDetLayer const*>& tec_neg = tracker.negTecLayers();
287 
288  for(size_t i=0, n=theLayers.size(); i<n; ++i) {
289  const LayerSpec& layer = theLayers[i];
290  const DetLayer * detLayer = nullptr;
291  int index = layer.idLayer-1;
292 
294  detLayer = bpx[index];
295  }
296  else if (layer.subdet == GeomDetEnumerators::PixelEndcap) {
297  if (layer.side == SeedingLayer::PosEndcap) {
298  detLayer = fpx_pos[index];
299  } else {
300  detLayer = fpx_neg[index];
301  }
302  }
303  else if (layer.subdet == GeomDetEnumerators::TIB) {
304  detLayer = tib[index];
305  }
306  else if (layer.subdet == GeomDetEnumerators::TID) {
307  if (layer.side == SeedingLayer::PosEndcap) {
308  detLayer = tid_pos[index];
309  } else {
310  detLayer = tid_neg[index];
311  }
312  }
313  else if (layer.subdet == GeomDetEnumerators::TOB) {
314  detLayer = tob[index];
315  }
316  else if (layer.subdet == GeomDetEnumerators::TEC) {
317  if (layer.side == SeedingLayer::PosEndcap) {
318  detLayer = tec_pos[index];
319  } else {
320  detLayer = tec_neg[index];
321  }
322  }
323  else {
324  throw cms::Exception("Configuration") << "Did not find DetLayer for layer " << theLayerNames[layer.nameIndex];
325  }
326 
328  es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
329 
330  theLayerDets[i] = detLayer;
331  theTTRHBuilders[i] = builder.product();
332  }
333 }
334 
336 {
337  updateEventSetup(es);
338 
339  typedef std::vector<SeedingLayer> Set;
341 
342  for(size_t i=0, n=theLayerSetIndices.size(); i<n; i += theNumberOfLayersInSet) {
343  Set set;
344  for(size_t j=0; j<theNumberOfLayersInSet; ++j) {
345  const unsigned short layerIndex = theLayerSetIndices[i+j];
346  const LayerSpec& layer = theLayers[layerIndex];
347  const DetLayer *detLayer = theLayerDets[layerIndex];
348 
349  set.push_back( SeedingLayer( theLayerNames[layerIndex], layerIndex, detLayer, theTTRHBuilders[layerIndex], layer.extractor.get()));
350  }
351  result.push_back(set);
352  }
353  return result;
354 }
355 
357  // We want to evaluate both in the first invocation (to properly
358  // initialize ESWatcher), and this way we avoid one branch compared
359  // to || (should be tiny effect)
360  return geometryWatcher_.check(es) | trhWatcher_.check(es);
361 }
362 
364 void
366  std::vector<unsigned int> & indices, ctfseeding::SeedingLayer::Hits & hits) const {
367  indices.reserve(theLayers.size());
368  for(unsigned int i=0; i<theLayers.size(); ++i) {
369  // The index of the first hit of this layer
370  indices.push_back(hits.size());
371 
372  // Obtain and copy the hits
374  std::move(tmp.begin(), tmp.end(), std::back_inserter(hits));
375  }
376 }
#define LogDebug(id)
T getParameter(std::string const &) const
ctfseeding::SeedingLayerSets layers(const edm::EventSetup &es)
static const HistoName names[]
std::vector< ForwardDetLayer const * > const & posForwardLayers() const
std::vector< LayerSpec > theLayers
edm::ESWatcher< TrackerRecoGeometryRecord > geometryWatcher_
LayerSpec(unsigned short index, const std::string &layerName, const edm::ParameterSet &cfgLayer, edm::ConsumesCollector &iC)
std::vector< std::string > theLayerNames
bool exists(std::string const &parameterName) const
checks if a parameter exists
float clusterChargeCut(const edm::ParameterSet &conf, const char *name="clusterChargeCut")
std::vector< HitPointer > Hits
Definition: SeedingLayer.h:28
std::vector< BarrelDetLayer const * > const & tobLayers() const
bool ev
bool check(const edm::EventSetup &es)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
uint16_t size_type
std::vector< const TransientTrackingRecHitBuilder * > theTTRHBuilders
GeomDetEnumerators::SubDetector subdet
void updateEventSetup(const edm::EventSetup &es)
std::vector< ForwardDetLayer const * > const & negForwardLayers() const
std::shared_ptr< ctfseeding::HitExtractor > extractor
std::vector< LinkConnSpec >::const_iterator IT
edm::ESWatcher< TransientRecHitRecord > trhWatcher_
std::vector< LayerSetIndex > theLayerSetIndices
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:55
std::vector< ForwardDetLayer const * > const & negTidLayers() const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< ForwardDetLayer const * > const & posTidLayers() const
std::string print(const std::vector< std::string > &names) const
void hits(const edm::Event &ev, const edm::EventSetup &es, std::vector< unsigned int > &indices, ctfseeding::SeedingLayer::Hits &hits) const
std::tuple< GeomDetEnumerators::SubDetector, ctfseeding::SeedingLayer::Side, int > SeedingLayerId
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
ctfseeding::SeedingLayer::Side side
std::vector< std::vector< SeedingLayer > > SeedingLayerSets
static std::vector< std::vector< std::string > > layerNamesInSets(const std::vector< std::string > &namesPSet)