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 
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 
30 using namespace ctfseeding;
31 using namespace std;
32 
33 
35 {
36  std::ostringstream str;
37  str << "Layer="<<name<<", hitBldr: "<<hitBuilder<<", useErrorsFromParam: ";
38  if (useErrorsFromParam) {
39  str <<"true,"<<" errRPhi: "<<hitErrorRPhi<<", errRZ: "<<hitErrorRZ;
40  }
41  else str<<"false";
42 
43  str << ", useRingSelector: ";
44  if (useRingSelector) {
45  str <<"true,"<<" Rings: ("<<minRing<<","<<maxRing<<")";
46  } else str<<"false";
47 
48  return str.str();
49 }
50 
52 {
53  std::vector<std::string> namesPset = cfg.getParameter<std::vector<std::string> >("layerList");
54  std::vector<std::vector<std::string> > layerNamesInSets = this->layerNamesInSets(namesPset);
55 
56  // debug printout of layers
57  typedef std::vector<std::string>::const_iterator IS;
58  typedef std::vector<std::vector<std::string> >::const_iterator IT;
59  std::ostringstream str;
60  // The following should not be set to cout
61 // for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
62 // str << "SET: ";
63 // for (IS is = it->begin(); is != it->end(); is++) str << *is <<" ";
64 // str << std::endl;
65 // }
66 // std::cout << str.str() << std::endl;
67 
68  map<string,LayerSpec> mapConfig; // for debug printout only!
69 
70  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
71  vector<LayerSpec> layersInSet;
72  for (IS is = it->begin(); is != it->end(); is++) {
73  LayerSpec layer;
74 
75  layer.name = *is;
76  //std::cout << "layer name in config: " << *is << std::endl;
77  edm::ParameterSet cfgLayer = layerConfig(layer.name, cfg);
78 
79  layer.usePixelHitProducer = true;
80  layer.useMatchedRecHits = true;
81  layer.useRPhiRecHits = true;
82  layer.useStereoRecHits = true;
83  if (cfgLayer.exists("HitProducer")) {
84  layer.pixelHitProducer = cfgLayer.getParameter<string>("HitProducer");
85  }else{
86  layer.usePixelHitProducer = false;
87  }
88  if (cfgLayer.exists("matchedRecHits")) {
89  layer.matchedRecHits = cfgLayer.getParameter<edm::InputTag>("matchedRecHits");
90  }else{
91  layer.useMatchedRecHits = false;
92  }
93  if (cfgLayer.exists("rphiRecHits")) {
94  layer.rphiRecHits = cfgLayer.getParameter<edm::InputTag>("rphiRecHits");
95  }else{
96  layer.useRPhiRecHits = false;
97  }
98  if (cfgLayer.exists("stereoRecHits")) {
99  layer.stereoRecHits= cfgLayer.getParameter<edm::InputTag>("stereoRecHits");
100  }else{
101  layer.useStereoRecHits = false;
102  }
103 
104  layer.hitBuilder = cfgLayer.getParameter<string>("TTRHBuilder");
105 
106  layer.useErrorsFromParam = cfgLayer.exists("useErrorsFromParam") ? cfgLayer.getParameter<bool>("useErrorsFromParam") : false;
107  if(layer.useErrorsFromParam) {
108  layer.hitErrorRPhi = cfgLayer.getParameter<double>("hitErrorRPhi");
109  layer.hitErrorRZ = cfgLayer.getParameter<double>("hitErrorRZ");
110  }
111 
112  layer.useRingSelector = cfgLayer.exists("useRingSlector") ? cfgLayer.getParameter<bool>("useRingSlector") : false;
113  if (layer.useRingSelector) {
114  layer.minRing = cfgLayer.getParameter<int>("minRing");
115  layer.maxRing = cfgLayer.getParameter<int>("maxRing");
116  }
117 
118  layer.useSimpleRphiHitsCleaner = cfgLayer.exists("useSimpleRphiHitsCleaner") ? cfgLayer.getParameter<bool>("useSimpleRphiHitsCleaner") : true;
119 
120  layersInSet.push_back(layer);
121  mapConfig[layer.name]=layer;
122  }
123  theLayersInSets.push_back(layersInSet);
124  }
125 
126  // debug printout
127  // The following should not be set to cout
128 // for (map<string,LayerSpec>::const_iterator im = mapConfig.begin(); im != mapConfig.end(); im++) {
129 // std::cout << (*im).second.print() << std::endl;
130 // }
131 }
132 
133 edm::ParameterSet SeedingLayerSetsBuilder::layerConfig(const std::string & nameLayer,const edm::ParameterSet& cfg) const
134 {
136 
137  for (string::size_type iEnd=nameLayer.size(); iEnd > 0; --iEnd) {
138  string name = nameLayer.substr(0,iEnd);
139  if (cfg.exists(name)) return cfg.getParameter<edm::ParameterSet>(name);
140  }
141  cout <<"configuration for layer: "<<nameLayer<<" not found, job will probably crash!"<<endl;
142  return result;
143 }
144 
145 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets( const vector<string> & namesPSet)
146 {
147  std::vector<std::vector<std::string> > result;
148  for (std::vector<std::string>::const_iterator is=namesPSet.begin(); is < namesPSet.end(); ++is) {
149  vector<std::string> layersInSet;
150  string line = *is;
152  while (pos != string::npos ) {
153  pos=line.find("+");
154  string layer = line.substr(0,pos);
155  layersInSet.push_back(layer);
156  line=line.substr(pos+1,string::npos);
157  }
158  result.push_back(layersInSet);
159  }
160  return result;
161 }
162 
164 {
165  typedef std::vector<SeedingLayer> Set;
167 
169  es.get<TrackerRecoGeometryRecord>().get( tracker );
170 
171  std::vector<BarrelDetLayer*> bpx = tracker->barrelLayers();
172  std::vector<BarrelDetLayer*> tib = tracker->tibLayers();
173  std::vector<BarrelDetLayer*> tob = tracker->tobLayers();
174 
175  std::vector<ForwardDetLayer*> fpx_pos = tracker->posForwardLayers();
176  std::vector<ForwardDetLayer*> tid_pos = tracker->posTidLayers();
177  std::vector<ForwardDetLayer*> tec_pos = tracker->posTecLayers();
178 
179  std::vector<ForwardDetLayer*> fpx_neg = tracker->negForwardLayers();
180  std::vector<ForwardDetLayer*> tid_neg = tracker->negTidLayers();
181  std::vector<ForwardDetLayer*> tec_neg = tracker->negTecLayers();
182 
183  typedef std::vector<std::vector<LayerSpec> >::const_iterator IT;
184  typedef std::vector<LayerSpec>::const_iterator IS;
185 
186  for (IT it = theLayersInSets.begin(); it != theLayersInSets.end(); it++) {
187  Set set;
188  bool setOK = true;
189  for (IS is = it->begin(), isEnd = it->end(); is < isEnd; ++is) {
190  const LayerSpec & layer = (*is);
191  std::string name = layer.name;
192  const DetLayer * detLayer =0;
194  int idLayer = 0;
195  bool nameOK = true;
196  HitExtractor * extractor = 0;
197 
198  //
199  // BPIX
200  //
201  if (name.substr(0,4) == "BPix") {
202  idLayer = atoi(name.substr(4,1).c_str());
204  detLayer=bpx[idLayer-1];
205  }
206  //
207  // FPIX
208  //
209  else if (name.substr(0,4) == "FPix") {
210  idLayer = atoi(name.substr(4,1).c_str());
211  if ( name.find("pos") != string::npos ) {
213  detLayer = fpx_pos[idLayer-1];
214  } else {
216  detLayer = fpx_neg[idLayer-1];
217  }
218  }
219  //
220  // TIB
221  //
222  else if (name.substr(0,3) == "TIB") {
223  idLayer = atoi(name.substr(3,1).c_str());
225  detLayer=tib[idLayer-1];
226  }
227  //
228  // TID
229  //
230  else if (name.substr(0,3) == "TID") {
231  idLayer = atoi(name.substr(3,1).c_str());
232  if ( name.find("pos") != string::npos ) {
234  detLayer = tid_pos[idLayer-1];
235  } else {
237  detLayer = tid_neg[idLayer-1];
238  }
239  }
240  //
241  // TOB
242  //
243  else if (name.substr(0,3) == "TOB") {
244  idLayer = atoi(name.substr(3,1).c_str());
246  detLayer=tob[idLayer-1];
247  }
248  //
249  // TEC
250  //
251  else if (name.substr(0,3) == "TEC") {
252  idLayer = atoi(name.substr(3,1).c_str());
253  if ( name.find("pos") != string::npos ) {
255  detLayer = tec_pos[idLayer-1];
256  } else {
258  detLayer = tec_neg[idLayer-1];
259  }
260  }
261  else {
262  nameOK = false;
263  setOK = false;
264  }
265 
266  if(nameOK) {
267  if ( detLayer->subDetector() == GeomDetEnumerators::PixelBarrel ||
269  extractor = new HitExtractorPIX(side,idLayer,layer.pixelHitProducer);
270  } else {
271  HitExtractorSTRP extSTRP(detLayer,side,idLayer);
272  if (layer.useMatchedRecHits) extSTRP.useMatchedHits(layer.matchedRecHits);
273  if (layer.useRPhiRecHits) extSTRP.useRPhiHits(layer.rphiRecHits);
274  if (layer.useStereoRecHits) extSTRP.useStereoHits(layer.stereoRecHits);
275  if (layer.useRingSelector) extSTRP.useRingSelector(layer.minRing,layer.maxRing);
277  extractor = extSTRP.clone();
278  }
279 
281  es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
282 
283  if (layer.useErrorsFromParam) {
284  set.push_back( SeedingLayer( name, detLayer, builder.product(),
285  extractor, true, layer.hitErrorRPhi,layer.hitErrorRZ));
286  } else {
287  set.push_back( SeedingLayer( name, detLayer, builder.product(), extractor));
288  }
289  }
290 
291  }
292  if(setOK) result.push_back(set);
293  }
294  return result;
295 }
T getParameter(std::string const &) const
void useMatchedHits(const edm::InputTag &m)
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
uint16_t size_type
void useRPhiHits(const edm::InputTag &m)
tuple result
Definition: query.py:137
std::vector< LinkConnSpec >::const_iterator IT
void useRingSelector(int minRing, int maxRing)
virtual HitExtractorSTRP * clone() const
void useSimpleRphiHitsCleaner(bool use)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
ctfseeding::SeedingLayerSets layers(const edm::EventSetup &es) const
tuple cout
Definition: gather_cfg.py:41
void useStereoHits(const edm::InputTag &m)
edm::ParameterSet layerConfig(const std::string &nameLayer, const edm::ParameterSet &cfg) const
std::vector< std::vector< SeedingLayer > > SeedingLayerSets
std::vector< std::vector< std::string > > layerNamesInSets(const std::vector< std::string > &namesPSet)