CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OMTFConfiguration.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <algorithm>
3 
6 
11 
13 
16 
18 unsigned int OMTFConfiguration::nLayers;
23 unsigned int OMTFConfiguration::nPhiBits;
24 unsigned int OMTFConfiguration::nPhiBins;
25 unsigned int OMTFConfiguration::nRefHits;
29 unsigned int OMTFConfiguration::nInputs;
31 
32 std::map<int,int> OMTFConfiguration::hwToLogicLayer;
33 std::map<int,int> OMTFConfiguration::logicToHwLayer;
34 std::map<int,int> OMTFConfiguration::logicToLogic;
37 std::vector<std::vector<int> > OMTFConfiguration::processorPhiVsRefLayer;
39 std::vector<std::vector<std::vector<std::pair<int,int> > > >OMTFConfiguration::regionPhisVsRefLayerVsProcessor;
40 
41 std::vector<std::vector<RefHitDef> >OMTFConfiguration::refHitsDefs;
42 
45 
46 std::vector<unsigned int> OMTFConfiguration::barrelMin;
47 std::vector<unsigned int> OMTFConfiguration::barrelMax;
48 
49 std::vector<unsigned int> OMTFConfiguration::endcap10DegMin;
50 std::vector<unsigned int> OMTFConfiguration::endcap10DegMax;
51 
52 std::vector<unsigned int> OMTFConfiguration::endcap20DegMin;
53 std::vector<unsigned int> OMTFConfiguration::endcap20DegMax;
56 RefHitDef::RefHitDef(unsigned int aInput,
57  int aPhiMin, int aPhiMax,
58  unsigned int aRegion,
59  unsigned int aRefLayer):
60  iInput(aInput),
61  iRegion(aRegion),
62  iRefLayer(aRefLayer),
63  range(std::pair<int,int>(aPhiMin,aPhiMax)){}
66 bool RefHitDef::fitsRange(int iPhi) const{
67 
68  return iPhi>=range.first &&
69  iPhi<range.second;
70 
71 }
74 std::ostream & operator << (std::ostream &out, const RefHitDef & aRefHitDef){
75 
76 
77  out<<"iRefLayer: "<<aRefHitDef.iRefLayer
78  <<" iInput: "<<aRefHitDef.iInput
79  <<" iRegion: "<<aRefHitDef.iRegion
80  <<" range: ("<<aRefHitDef.range.first
81  <<", "<<aRefHitDef.range.second<<std::endl;
82 
83  return out;
84 }
88 
89  if(theConfig.getParameter<bool>("configFromXML")){
90  if (!theConfig.exists("configXMLFile") ) return;
91  std::string fName = theConfig.getParameter<edm::FileInPath>("configXMLFile").fullPath();
92 
93  XMLConfigReader myReader;
94  myReader.setConfigFile(fName);
95  configure(&myReader);
96  }
97 }
101 
103  std::vector<int> aLayer1D(nInputs,0);
104 
107  aLayer2D.assign(nLayers,aLayer1D);
108 
111  aLayer3D.assign(nLogicRegions,aLayer2D);
112 
114  measurements4D.assign(nProcessors,aLayer3D);
115  measurements4Dref.assign(nProcessors,aLayer3D);
116 }
120 
121  aReader->readConfig(this);
123 
124 }
127 void OMTFConfiguration::configure(std::shared_ptr<L1TMuonOverlapParams> omtfParams){
128 
130  minPdfVal = 0.001;
131  nPdfAddrBits = omtfParams->nPdfAddrBits();
132  nPdfValBits = omtfParams->nPdfValBits();
133  nHitsPerLayer = omtfParams->nHitsPerLayer();
134  nPhiBits = omtfParams->nPhiBits();
135  nPhiBins = omtfParams->nPhiBins();
136  nRefHits = omtfParams->nRefHits();
137  nTestRefHits = omtfParams->nTestRefHits();
138  nProcessors = omtfParams->nProcessors();
139  nLogicRegions = omtfParams->nLogicRegions();
140  nInputs = omtfParams->nInputs();
141  nLayers = omtfParams->nLayers();
142  nRefLayers = omtfParams->nRefLayers();
143  nGoldenPatterns = omtfParams->nGoldenPatterns();
144 
149 
153 
154  std::vector<int> *connectedSectorsStartVec = omtfParams->connectedSectorsStart();
155  std::vector<int> *connectedSectorsEndVec = omtfParams->connectedSectorsEnd();
156 
157  std::copy(connectedSectorsStartVec->begin(), connectedSectorsStartVec->begin()+6, barrelMin.begin());
158  std::copy(connectedSectorsStartVec->begin()+6, connectedSectorsStartVec->begin()+12, endcap10DegMin.begin());
159  std::copy(connectedSectorsStartVec->begin()+12, connectedSectorsStartVec->end(), endcap20DegMin.begin());
160 
161  std::copy(connectedSectorsEndVec->begin(), connectedSectorsEndVec->begin()+6, barrelMax.begin());
162  std::copy(connectedSectorsEndVec->begin()+6, connectedSectorsEndVec->begin()+12, endcap10DegMax.begin());
163  std::copy(connectedSectorsEndVec->begin()+12, connectedSectorsEndVec->end(), endcap20DegMax.begin());
164 
166  std::vector<L1TMuonOverlapParams::LayerMapNode> *layerMap = omtfParams->layerMap();
167 
168  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
169  L1TMuonOverlapParams::LayerMapNode aNode = layerMap->at(iLayer);
170  hwToLogicLayer[aNode.hwNumber] = aNode.logicNumber;
171  logicToHwLayer[aNode.logicNumber] = aNode.hwNumber;
172  logicToLogic[aNode.logicNumber] = aNode.connectedToLayer;
173  if(aNode.bendingLayer) bendingLayers.insert(aNode.logicNumber);
174  }
177 
178  std::vector<L1TMuonOverlapParams::RefLayerMapNode> *refLayerMap = omtfParams->refLayerMap();
179  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
180  L1TMuonOverlapParams::RefLayerMapNode aNode = refLayerMap->at(iRefLayer);
181  refToLogicNumber[aNode.refLayer] = aNode.logicNumber;
182  }
184  std::vector<int> vector1D(OMTFConfiguration::nRefLayers,OMTFConfiguration::nPhiBins);
186 
189  OMTFConfiguration::vector1D_A aLayer1D(OMTFConfiguration::nLayers);
192  aLayer2D.assign(OMTFConfiguration::nLogicRegions,aLayer1D);
195 
198  std::vector<std::pair<int,int> > aRefHit1D(OMTFConfiguration::nLogicRegions,std::pair<int,int>(9999,9999));
200  std::vector<std::vector<std::pair<int,int> > > aRefHit2D;
201  aRefHit2D.assign(OMTFConfiguration::nRefLayers,aRefHit1D);
204 
205  //Vector of ref hit definitions
206  std::vector<RefHitDef> aRefHitsDefs(OMTFConfiguration::nRefHits);
208  refHitsDefs.assign(OMTFConfiguration::nProcessors,aRefHitsDefs);
209 
210  std::vector<int> *phiStartMap = omtfParams->globalPhiStartMap();
211  std::vector<L1TMuonOverlapParams::RefHitNode> *refHitMap = omtfParams->refHitMap();
212  std::vector<L1TMuonOverlapParams::LayerInputNode> *layerInputMap = omtfParams->layerInputMap();
213  unsigned int tmpIndex = 0;
214  for(unsigned int iProcessor=0;iProcessor<OMTFConfiguration::nProcessors;++iProcessor){
215  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
216  int iPhiStart = phiStartMap->at(iRefLayer+iProcessor*OMTFConfiguration::nRefLayers);
217  processorPhiVsRefLayer[iProcessor][iRefLayer] = iPhiStart;
218  }
219  for(unsigned int iRefHit=0;iRefHit<OMTFConfiguration::nRefHits;++iRefHit){
220  int iPhiMin = refHitMap->at(iRefHit+iProcessor*OMTFConfiguration::nRefHits).iPhiMin;
221  int iPhiMax = refHitMap->at(iRefHit+iProcessor*OMTFConfiguration::nRefHits).iPhiMax;
222  unsigned int iInput = refHitMap->at(iRefHit+iProcessor*OMTFConfiguration::nRefHits).iInput;
223  unsigned int iRegion = refHitMap->at(iRefHit+iProcessor*OMTFConfiguration::nRefHits).iRegion;
224  unsigned int iRefLayer = refHitMap->at(iRefHit+iProcessor*OMTFConfiguration::nRefHits).iRefLayer;
225  regionPhisVsRefLayerVsProcessor[iProcessor][iRefLayer][iRegion] = std::pair<int,int>(iPhiMin,iPhiMax);
226  refHitsDefs[iProcessor][iRefHit] = RefHitDef(iInput,iPhiMin,iPhiMax,iRegion,iRefLayer);
227  }
228  for(unsigned int iLogicRegion=0;iLogicRegion<OMTFConfiguration::nLogicRegions;++iLogicRegion){
229  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
230  tmpIndex = iLayer+iLogicRegion*OMTFConfiguration::nLayers + iProcessor*OMTFConfiguration::nLogicRegions*OMTFConfiguration::nLayers;
231  unsigned int iFirstInput = layerInputMap->at(tmpIndex).iFirstInput;
232  unsigned int nInputs = layerInputMap->at(tmpIndex).nInputs;
233  OMTFConfiguration::connections[iProcessor][iLogicRegion][iLayer] = std::pair<unsigned int, unsigned int>(iFirstInput,nInputs);
235  if(iProcessor!=0) OMTFConfiguration::connections[iProcessor][iLogicRegion][iLayer] = OMTFConfiguration::connections[0][iLogicRegion][iLayer];
236  }
237  }
238  }
239 
241 
242 }
245 std::ostream & operator << (std::ostream &out, const OMTFConfiguration & aConfig){
246 
247 
248  out<<"nLayers: "<<aConfig.nLayers
249  <<" nHitsPerLayer: "<<aConfig.nHitsPerLayer
250  <<" nRefLayers: "<<aConfig.nRefLayers
251  <<" nPdfAddrBits: "<<aConfig.nPdfAddrBits
252  <<" nPdfValBits: "<<aConfig.nPdfValBits
253  <<std::endl;
254 
255  for(unsigned int iProcessor = 0;iProcessor<aConfig.nProcessors; ++iProcessor){
256  out<<"Processor: "<<iProcessor;
257  for(unsigned int iRefLayer=0;iRefLayer<aConfig.nRefLayers;++iRefLayer){
258  out<<" "<<aConfig.processorPhiVsRefLayer[iProcessor][iRefLayer];
259  }
260  out<<std::endl;
261  }
262 
263  return out;
264 
265 }
269  unsigned int coneSize,
270  int iPhi){
271 
272  if(iPhi<0) iPhi+=OMTFConfiguration::nPhiBins;
273  if(iPhiStart<0) iPhiStart+=OMTFConfiguration::nPhiBins;
274 
275  if(iPhiStart+(int)coneSize<(int)OMTFConfiguration::nPhiBins){
276  return iPhiStart<=iPhi && iPhiStart+(int)coneSize>iPhi;
277  }
278  else if(iPhi>(int)OMTFConfiguration::nPhiBins/2){
279  return iPhiStart<=iPhi;
280  }
281  else if(iPhi<(int)OMTFConfiguration::nPhiBins/2){
282  return iPhi<iPhiStart+(int)coneSize-(int)OMTFConfiguration::nPhiBins;
283  }
284  return false;
285 }
288 unsigned int OMTFConfiguration::getRegionNumber(unsigned int iProcessor,
289  unsigned int iRefLayer,
290  int iPhi){
291 
292  if(iPhi>=(int)OMTFConfiguration::nPhiBins) return 99;
293 
294  float logicRegionWidth = 360.0/(OMTFConfiguration::nLogicRegions*OMTFConfiguration::nProcessors);
295  unsigned int logicRegionSize = logicRegionWidth/360.0*OMTFConfiguration::nPhiBins;
296 
297  unsigned int iRegion = 0;
298  int iPhiStart = OMTFConfiguration::processorPhiVsRefLayer[iProcessor][iRefLayer];
299 
301  while(!OMTFConfiguration::isInRegionRange(iPhiStart,logicRegionSize,iPhi) && iRegion<OMTFConfiguration::nLogicRegions){
302  ++iRegion;
303  iPhiStart+=logicRegionSize;
304  }
305 
306  if(iRegion>OMTFConfiguration::nLogicRegions-1) iRegion = 99;
307  return iRegion;
308 }
311 unsigned int OMTFConfiguration::getRegionNumberFromMap(unsigned int iProcessor,
312  unsigned int iRefLayer,
313  int iPhi){
314  for(unsigned int iRegion=0;iRegion<OMTFConfiguration::nLogicRegions;++iRegion){
315  if(iPhi>=OMTFConfiguration::regionPhisVsRefLayerVsProcessor[iProcessor][iRefLayer][iRegion].first &&
316  iPhi<=OMTFConfiguration::regionPhisVsRefLayerVsProcessor[iProcessor][iRefLayer][iRegion].second)
317  return iRegion;
318  }
319 
320  return 99;
321 }
324 int OMTFConfiguration::globalPhiStart(unsigned int iProcessor){
325 
326  return *std::min_element(OMTFConfiguration::processorPhiVsRefLayer[iProcessor].begin(),
328 
329 }
332 uint32_t OMTFConfiguration::getLayerNumber(uint32_t rawId){
333 
334  uint32_t aLayer = 0;
335 
336  DetId detId(rawId);
337  if (detId.det() != DetId::Muon){
338  std::cout << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
339  return rawId;
340  }
341 
342  switch (detId.subdetId()) {
343  case MuonSubdetId::RPC: {
344  RPCDetId aId(rawId);
345  bool isBarrel = (aId.region()==0);
346  if(isBarrel) aLayer = aId.station() <=2 ?
347  2*( aId.station()-1)+ aId.layer()
348  : aId.station()+2;
349  else aLayer = aId.station();
350  aLayer+= 10*(!isBarrel);
351  break;
352  }
353  case MuonSubdetId::DT: {
354  DTChamberId dt(rawId);
355  aLayer = dt.station();
356  break;
357  }
358  case MuonSubdetId::CSC: {
359  CSCDetId csc(rawId);
360  aLayer = csc.station();
361  if(csc.ring()==2 && csc.station()==1) aLayer = 4;
362  if(csc.station()==4) aLayer = 5;
363  break;
364  }
365  }
366 
367  int hwNumber = aLayer+100*detId.subdetId();
368 
369  return hwNumber;
370 }
bool fitsRange(int iPhi) const
static unsigned int getRegionNumber(unsigned int iProcessor, unsigned int iRefLayer, int iPhi)
T getParameter(std::string const &) const
float dt
Definition: AMPTWrapper.h:126
static unsigned int nLayers
OMTFConfiguration(const edm::ParameterSet &cfg)
static unsigned int nInputs
unsigned int hwNumber
short layer number used within OMTF emulator
static vector4D measurements4D
static std::vector< unsigned int > endcap20DegMax
static vector3D_A connections
bool isBarrel(GeomDetEnumerators::SubDetector m)
static bool isInRegionRange(int iPhiStart, unsigned int coneSize, int iPhi)
static float minPdfVal
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< vector2D_A > vector3D_A
static int globalPhiStart(unsigned int iProcessor)
unsigned int logicNumber
logic numer of the layer
static std::vector< unsigned int > endcap10DegMin
static std::vector< unsigned int > barrelMax
unsigned int iInput
Hit input number within a cone.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
static unsigned int nProcessors
static unsigned int nLogicRegions
static vector4D measurements4Dref
static std::map< int, int > logicToLogic
std::vector< vector2D > vector3D
U second(std::pair< T, U > const &p)
static unsigned int nPdfAddrBits
static const int CSC
Definition: MuonSubdetId.h:13
std::vector< vector1D > vector2D
static std::vector< unsigned int > barrelMin
void configure(XMLConfigReader *aReader)
static unsigned int nTestRefHits
static unsigned int nHitsPerLayer
static std::vector< std::vector< int > > processorPhiVsRefLayer
std::vector< std::pair< unsigned int, unsigned int > > vector1D_A
Map of connections.
std::vector< int > vector1D
static unsigned int nPhiBins
RefHitDef(unsigned int aInput=15, int aPhiMin=5760, int aPhiMax=5760, unsigned int aRegion=99, unsigned int aRefLayer=99)
#define end
Definition: vmac.h:37
void readConfig(const std::string fName)
bool bendingLayer
Is this a bending layers?
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
static std::vector< int > refToLogicNumber
static unsigned int nPhiBits
void setConfigFile(const std::string &fName)
int ring() const
Definition: CSCDetId.h:75
int layer() const
Definition: RPCDetId.h:108
Definition: DetId.h:18
static std::map< int, int > hwToLogicLayer
unsigned int refLayer
Reference layer number.
static unsigned int nRefLayers
std::pair< int, int > range
static unsigned int getRegionNumberFromMap(unsigned int iProcessor, unsigned int iRefLayer, int iPhi)
static std::map< int, int > logicToHwLayer
static unsigned int nRefHits
static std::set< int > bendingLayers
#define begin
Definition: vmac.h:30
static const int RPC
Definition: MuonSubdetId.h:14
unsigned int iRefLayer
Reference layer logic number (0-7)
unsigned int logicNumber
Corresponding logical layer number.
int station() const
Definition: CSCDetId.h:86
tuple cout
Definition: gather_cfg.py:145
static const int DT
Definition: MuonSubdetId.h:12
unsigned int iRegion
Region number assigned to this referecne hit.
static unsigned int nGoldenPatterns
std::vector< vector1D_A > vector2D_A
int station() const
Return the station number.
Definition: DTChamberId.h:51
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
static std::vector< unsigned int > endcap10DegMax
static std::vector< std::vector< std::vector< std::pair< int, int > > > > regionPhisVsRefLayerVsProcessor
static std::vector< unsigned int > endcap20DegMin
std::vector< vector3D > vector4D
static unsigned int nPdfValBits
static uint32_t getLayerNumber(uint32_t rawId)
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96
static std::vector< std::vector< RefHitDef > > refHitsDefs