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