CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
32 namespace {
35  int> nameToEnumId(const std::string& name) {
36  GeomDetEnumerators::SubDetector subdet = GeomDetEnumerators::invalidDet;
37  SeedingLayer::Side side = SeedingLayer::Barrel;
38  int idLayer = 0;
39 
40  size_t index;
41  //
42  // BPIX
43  //
44  if ((index = name.find("BPix")) != string::npos) {
46  side = SeedingLayer::Barrel;
47  idLayer = atoi(name.substr(index+4,1).c_str());
48  }
49  //
50  // FPIX
51  //
52  else if ((index = name.find("FPix")) != string::npos) {
54  idLayer = atoi(name.substr(index+4,1).c_str());
55  if ( name.find("pos") != string::npos ) {
57  } else {
59  }
60  }
61  //
62  // TIB
63  //
64  else if ((index = name.find("TIB")) != string::npos) {
65  subdet = GeomDetEnumerators::TIB;
66  side = SeedingLayer::Barrel;
67  idLayer = atoi(name.substr(index+3,1).c_str());
68  }
69  //
70  // TID
71  //
72  else if ((index = name.find("TID")) != string::npos) {
73  subdet = GeomDetEnumerators::TID;
74  idLayer = atoi(name.substr(index+3,1).c_str());
75  if ( name.find("pos") != string::npos ) {
77  } else {
79  }
80  }
81  //
82  // TOB
83  //
84  else if ((index = name.find("TOB")) != string::npos) {
85  subdet = GeomDetEnumerators::TOB;
86  side = SeedingLayer::Barrel;
87  idLayer = atoi(name.substr(index+3,1).c_str());
88  }
89  //
90  // TEC
91  //
92  else if ((index = name.find("TEC")) != string::npos) {
93  subdet = GeomDetEnumerators::TEC;
94  idLayer = atoi(name.substr(index+3,1).c_str());
95  if ( name.find("pos") != string::npos ) {
97  } else {
99  }
100  }
101  return std::make_tuple(subdet, side, idLayer);
102  }
103 }
104 
105 SeedingLayerSetsBuilder::LayerSpec::LayerSpec(unsigned short index, const std::string& layerName, const edm::ParameterSet& cfgLayer, edm::ConsumesCollector& iC):
106  nameIndex(index),
107  hitBuilder(cfgLayer.getParameter<string>("TTRHBuilder"))
108 {
109  usePixelHitProducer = false;
110  if (cfgLayer.exists("HitProducer")) {
111  pixelHitProducer = cfgLayer.getParameter<string>("HitProducer");
112  usePixelHitProducer = true;
113  }
114 
115  bool skipClusters = cfgLayer.exists("skipClusters");
116  if (skipClusters) {
117  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" ready for skipping";
118  }
119  else{
120  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" not skipping ";
121  }
122 
123  auto subdetData = nameToEnumId(layerName);
124  subdet = std::get<0>(subdetData);
125  side = std::get<1>(subdetData);
126  idLayer = std::get<2>(subdetData);
127  if(subdet == GeomDetEnumerators::PixelBarrel ||
129  extractor = std::make_shared<HitExtractorPIX>(side, idLayer, pixelHitProducer, iC);
130  }
131  else if(subdet != GeomDetEnumerators::invalidDet) { // strip
132  std::shared_ptr<HitExtractorSTRP> extr = std::make_shared<HitExtractorSTRP>(subdet, side, idLayer, clusterChargeCut(cfgLayer) );
133  if (cfgLayer.exists("matchedRecHits")) {
134  extr->useMatchedHits(cfgLayer.getParameter<edm::InputTag>("matchedRecHits"), iC);
135  }
136  if (cfgLayer.exists("rphiRecHits")) {
137  extr->useRPhiHits(cfgLayer.getParameter<edm::InputTag>("rphiRecHits"), iC);
138  }
139  if (cfgLayer.exists("stereoRecHits")) {
140  extr->useStereoHits(cfgLayer.getParameter<edm::InputTag>("stereoRecHits"), iC);
141  }
142  if (cfgLayer.exists("useRingSlector") && cfgLayer.getParameter<bool>("useRingSlector")) {
143  extr->useRingSelector(cfgLayer.getParameter<int>("minRing"),
144  cfgLayer.getParameter<int>("maxRing"));
145  }
146  bool useSimpleRphiHitsCleaner = cfgLayer.exists("useSimpleRphiHitsCleaner") ? cfgLayer.getParameter<bool>("useSimpleRphiHitsCleaner") : true;
147  extr->useSimpleRphiHitsCleaner(useSimpleRphiHitsCleaner);
148 
149  double minAbsZ = cfgLayer.exists("MinAbsZ") ? cfgLayer.getParameter<double>("MinAbsZ") : 0.;
150  if(minAbsZ > 0.) {
151  extr->setMinAbsZ(minAbsZ);
152  }
153  if(skipClusters) {
154  bool useProjection = cfgLayer.exists("useProjection") ? cfgLayer.getParameter<bool>("useProjection") : false;
155  if(useProjection) {
156  LogDebug("SeedingLayerSetsBuilder")<<layerName<<" will project partially masked matched rechit";
157  }
158  else {
159  extr->setNoProjection();
160  }
161  }
162  extractor = std::move(extr);
163  }
164  if(extractor && skipClusters) {
165  extractor->useSkipClusters(cfgLayer.getParameter<edm::InputTag>("skipClusters"), iC);
166  }
167 }
169 
170 std::string SeedingLayerSetsBuilder::LayerSpec::print(const std::vector<std::string>& names) const
171 {
172  std::ostringstream str;
173  str << "Layer="<<names[nameIndex]<<", hitBldr: "<<hitBuilder;
174 
175  str << ", useRingSelector: ";
176  HitExtractorSTRP *ext = nullptr;
177  if((ext = dynamic_cast<HitExtractorSTRP *>(extractor.get())) &&
178  ext->useRingSelector()) {
179  auto minMaxRing = ext->getMinMaxRing();
180  str <<"true,"<<" Rings: ("<< std::get<0>(minMaxRing) <<","<< std::get<1>(minMaxRing) <<")";
181  } else str<<"false";
182 
183  return str.str();
184 }
185 
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 
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.size() == 0)
208  else
209  theNumberOfLayersInSet = layerNamesInSets[0].size();
210 
211 
212  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
213  if(it->size() != theNumberOfLayersInSet)
214  throw cms::Exception("Configuration") << "Assuming all SeedingLayerSets to have same number of layers. LayerSet " << (it-layerNamesInSets.begin()) << " has " << it->size() << " while 0th has " << theNumberOfLayersInSet;
215  for(const std::string& layerName: *it) {
216  auto found = std::find(theLayerNames.begin(), theLayerNames.end(), layerName);
217  unsigned short layerIndex = 0;
218  if(found != theLayerNames.end()) {
219  layerIndex = found-theLayerNames.begin();
220  }
221  else {
223  throw cms::Exception("Assert") << "Too many layers in " << __FILE__ << ":" << __LINE__ << ", we may have to enlarge the index type from unsigned short to unsigned int";
224  }
225 
226  layerIndex = theLayers.size();
227  theLayers.emplace_back(theLayerNames.size(), layerName, layerConfig(layerName, cfg), iC);
228  theLayerNames.push_back(layerName);
229  }
230  theLayerSetIndices.push_back(layerIndex);
231  }
232  }
233  theLayerDets.resize(theLayers.size());
234  theTTRHBuilders.resize(theLayers.size());
235 
236  // debug printout
237  // The following should not be set to cout
238  //for(const LayerSpec& layer: theLayers) {
239  // std::cout << layer.print(theLayerNames) << std::endl;
240  //}
241 }
242 
244 
246 {
248 
249  for (string::size_type iEnd=nameLayer.size(); iEnd > 0; --iEnd) {
250  string name = nameLayer.substr(0,iEnd);
251  if (cfg.exists(name)) return cfg.getParameter<edm::ParameterSet>(name);
252  }
253  edm::LogError("SeedingLayerSetsBuilder") <<"configuration for layer: "<<nameLayer<<" not found, job will probably crash!";
254  return result;
255 }
256 
257 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets( const vector<string> & namesPSet)
258 {
259  std::vector<std::vector<std::string> > result;
260  for (std::vector<std::string>::const_iterator is=namesPSet.begin(); is < namesPSet.end(); ++is) {
261  vector<std::string> layersInSet;
262  string line = *is;
263  string::size_type pos=0;
264  while (pos != string::npos ) {
265  pos=line.find("+");
266  string layer = line.substr(0,pos);
267  layersInSet.push_back(layer);
268  line=line.substr(pos+1,string::npos);
269  }
270  result.push_back(layersInSet);
271  }
272  return result;
273 }
274 
277  es.get<TrackerRecoGeometryRecord>().get( htracker );
278  const GeometricSearchTracker& tracker = *htracker;
279 
280  const std::vector<BarrelDetLayer const*>& bpx = tracker.barrelLayers();
281  const std::vector<BarrelDetLayer const*>& tib = tracker.tibLayers();
282  const std::vector<BarrelDetLayer const*>& tob = tracker.tobLayers();
283 
284  const std::vector<ForwardDetLayer const*>& fpx_pos = tracker.posForwardLayers();
285  const std::vector<ForwardDetLayer const*>& tid_pos = tracker.posTidLayers();
286  const std::vector<ForwardDetLayer const*>& tec_pos = tracker.posTecLayers();
287 
288  const std::vector<ForwardDetLayer const*>& fpx_neg = tracker.negForwardLayers();
289  const std::vector<ForwardDetLayer const*>& tid_neg = tracker.negTidLayers();
290  const std::vector<ForwardDetLayer const*>& tec_neg = tracker.negTecLayers();
291 
292  for(size_t i=0, n=theLayers.size(); i<n; ++i) {
293  const LayerSpec& layer = theLayers[i];
294  const DetLayer * detLayer = nullptr;
295  int index = layer.idLayer-1;
296 
298  detLayer = bpx[index];
299  }
300  else if (layer.subdet == GeomDetEnumerators::PixelEndcap) {
301  if (layer.side == SeedingLayer::PosEndcap) {
302  detLayer = fpx_pos[index];
303  } else {
304  detLayer = fpx_neg[index];
305  }
306  }
307  else if (layer.subdet == GeomDetEnumerators::TIB) {
308  detLayer = tib[index];
309  }
310  else if (layer.subdet == GeomDetEnumerators::TID) {
311  if (layer.side == SeedingLayer::PosEndcap) {
312  detLayer = tid_pos[index];
313  } else {
314  detLayer = tid_neg[index];
315  }
316  }
317  else if (layer.subdet == GeomDetEnumerators::TOB) {
318  detLayer = tob[index];
319  }
320  else if (layer.subdet == GeomDetEnumerators::TEC) {
321  if (layer.side == SeedingLayer::PosEndcap) {
322  detLayer = tec_pos[index];
323  } else {
324  detLayer = tec_neg[index];
325  }
326  }
327  else {
328  throw cms::Exception("Configuration") << "Did not find DetLayer for layer " << theLayerNames[layer.nameIndex];
329  }
330 
332  es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
333 
334  theLayerDets[i] = detLayer;
335  theTTRHBuilders[i] = builder.product();
336  }
337 }
338 
340 {
341  updateEventSetup(es);
342 
343  typedef std::vector<SeedingLayer> Set;
345 
346  for(size_t i=0, n=theLayerSetIndices.size(); i<n; i += theNumberOfLayersInSet) {
347  Set set;
348  for(size_t j=0; j<theNumberOfLayersInSet; ++j) {
349  const unsigned short layerIndex = theLayerSetIndices[i+j];
350  const LayerSpec& layer = theLayers[layerIndex];
351  const DetLayer *detLayer = theLayerDets[layerIndex];
352 
353  set.push_back( SeedingLayer( theLayerNames[layerIndex], layerIndex, detLayer, theTTRHBuilders[layerIndex], layer.extractor.get()));
354  }
355  result.push_back(set);
356  }
357  return result;
358 }
359 
361  // We want to evaluate both in the first invocation (to properly
362  // initialize ESWatcher), and this way we avoid one branch compared
363  // to || (should be tiny effect)
364  return geometryWatcher_.check(es) | trhWatcher_.check(es);
365 }
366 
368 void
370  std::vector<unsigned int> & indices, ctfseeding::SeedingLayer::Hits & hits) const {
371  indices.reserve(theLayers.size());
372  for(unsigned int i=0; i<theLayers.size(); ++i) {
373  // The index of the first hit of this layer
374  indices.push_back(hits.size());
375 
376  // Obtain and copy the hits
378  std::move(tmp.begin(), tmp.end(), std::back_inserter(hits));
379  }
380 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
ctfseeding::SeedingLayerSets layers(const edm::EventSetup &es)
tuple cfg
Definition: looper.py:293
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:7
uint16_t size_type
tuple result
Definition: mps_fire.py:84
std::vector< const TransientTrackingRecHitBuilder * > theTTRHBuilders
GeomDetEnumerators::SubDetector subdet
void updateEventSetup(const edm::EventSetup &es)
std::vector< ForwardDetLayer const * > const & negForwardLayers() const
def move
Definition: eostools.py:510
std::shared_ptr< ctfseeding::HitExtractor > extractor
int j
Definition: DBlmapReader.cc:9
std::vector< LinkConnSpec >::const_iterator IT
edm::ESWatcher< TransientRecHitRecord > trhWatcher_
std::vector< LayerSetIndex > theLayerSetIndices
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:56
T const * product() const
Definition: ESHandle.h:86
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::vector< ForwardDetLayer const * > const & negTecLayers() const
std::tuple< int, int > getMinMaxRing() const
edm::ParameterSet layerConfig(const std::string &nameLayer, const edm::ParameterSet &cfg) const
std::vector< const DetLayer * > theLayerDets
std::vector< BarrelDetLayer const * > const & barrelLayers() const
ctfseeding::SeedingLayer::Side side
std::vector< std::vector< SeedingLayer > > SeedingLayerSets
std::vector< std::vector< std::string > > layerNamesInSets(const std::vector< std::string > &namesPSet)