CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastTimeDDDConstants.cc
Go to the documentation of this file.
2 
5 
11 #include "CLHEP/Units/GlobalPhysicalConstants.h"
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
13 
14 //#define DebugLog
15 
17 
18 #ifdef DebugLog
19  edm::LogInfo("HGCalGeom") << "FastTimeDDDConstants::FastTimeDDDConstants ( const DDCompactView& cpv ) constructor";
20 #endif
21  initialize(cpv);
22 
23 }
24 
26 #ifdef DebugLog
27  std::cout << "FastTimeDDDConstants:destructed!!!" << std::endl;
28 #endif
29 }
30 
32 
33  int copy(0);
34 #ifdef DebugLog
35  int column(0), rowmax(0);
36 #endif
37  double offsetX (0), offsetY(0);
38  while (offsetX < rOut) {
39 #ifdef DebugLog
40  column++;
41  int row(0);
42 #endif
43  while (offsetY <rOut) {
44 #ifdef DebugLog
45  row++;
46 #endif
47  double limit1 = sqrt((offsetX+cellSize)*(offsetX+cellSize) +
48  (offsetY+cellSize)*(offsetY+cellSize));
49  double limit2 = sqrt(offsetX*offsetX+offsetY*offsetY);
50  if (limit2 > rIn && limit1 < rOut) copy++;
51  offsetY += cellSize;
52  }
53 #ifdef DebugLog
54  if (row > rowmax) rowmax = row;
55 #endif
56  offsetY = 0;
57  offsetX += cellSize;
58  }
59 #ifdef DebugLog
60  std::cout << rowmax << " rows and " << column << " columns with total of "
61  << copy << " cells in a quadrant " << std::endl;
62 #endif
63  return 4*copy;
64 }
65 
66 std::pair<int,int> FastTimeDDDConstants::getXY(int copy) const {
67 
68  int iq = quadrant(copy);
69  if (iq != 0) {
70  int ism = copy - (iq-1)*nCells;
71  int jx(0), jy(0);
72  for (unsigned int k=0; k<firstY.size(); ++k) {
73  if (ism >= firstCell[k] && ism <= lastCell[k]) {
74  jx = k + 1;
75  jy = ism - firstCell[k] + firstY[k];
76  break;
77  }
78  }
79  int ix = (iq == 1 || iq == 4) ? (jx + nCols) : (nCols+1-jx);
80  int iy = (iq == 1 || iq == 2) ? (jy + nRows) : (nRows+1-jy);
81  return std::pair<int,int>(ix,iy);
82  } else {
83  return std::pair<int,int>(0,0);
84  }
85 }
86 
87 std::pair<int,int> FastTimeDDDConstants::getXY(double x, double y) const {
88 
89  int jx = floor(fabs(x)/cellSize);
90  int jy = floor(fabs(y)/cellSize);
91  int iq(0);
92  if (x < 0) {
93  if (y < 0) iq = 3;
94  else iq = 2;
95  } else {
96  if (y < 0) iq = 4;
97  else iq = 1;
98  }
99  int ix = (iq == 1 || iq == 4) ? (jx + nCols) : (nCols+1-jx);
100  int iy = (iq == 1 || iq == 2) ? (jy + nRows) : (nRows+1-jy);
101  if (isValidXY(ix,iy)) {
102  return std::pair<int,int>(ix,iy);
103  } else {
104  return std::pair<int,int>(0,0);
105  }
106 }
107 
108 bool FastTimeDDDConstants::isValidXY(int ix, int iy) const {
109  int iq = quadrant(ix,iy);
110  if (iq != 0) {
111  int kx = (iq == 1 || iq == 4) ? (ix-nCols) : (nCols-1-ix);
112  int ky = (iq == 1 || iq == 2) ? (iy-nRows) : (nRows-1-iy);
113  bool ok = (ky+1 >= firstY[kx] && ky+1 <= lastY[kx]);
114  return ok;
115  } else {
116  return false;
117  }
118 }
119 
121  bool ok = (copy > 0 && copy <= getCells());
122  return ok;
123 }
124 
125 int FastTimeDDDConstants::quadrant(int ix, int iy) const {
126  int iq(0);
127  if (ix>nCols && ix<=2*nCols) {
128  if (iy>nRows && iy<=2*nRows) iq = 1;
129  else if (iy>0 && iy<=nRows) iq = 4;
130  } else if (ix>0 && ix<=nCols) {
131  if (iy>nRows && iy<=2*nRows) iq = 2;
132  else if (iy>0 && iy<=nRows) iq = 3;
133  }
134  return iq;
135 }
136 
138  int iq(0);
139  if (copy > 4*nCells) {
140  } else if (copy > 3*nCells) {
141  iq = 4;
142  } else if (copy > 2*nCells) {
143  iq = 3;
144  } else if (copy > nCells) {
145  iq = 2;
146  } else if (copy > 0) {
147  iq = 1;
148  }
149  return iq;
150 }
151 
153 
154  std::string attribute = "Volume";
155  std::string value = "SFBX";
156  DDValue val(attribute, value, 0.0);
157 
159  filter.setCriteria(val, DDCompOp::equals);
160  DDFilteredView fv(cpv);
161  fv.addFilter(filter);
162  bool ok = fv.firstChild();
163 
164  if (ok) {
165  loadSpecPars(fv);
166  } else {
167  edm::LogError("HGCalGeom") << "FastTimeDDDConstants: cannot get filtered"
168  << " view for " << attribute
169  << " not matching " << value;
170  throw cms::Exception("DDException") << "FastTimeDDDConstants: cannot match " << attribute << " to " << value;
171  }
172 }
173 
175 
177 
178  // First and Last Row number in each column
179  firstY = dbl_to_int(getDDDArray("firstRow",sv));
180  lastY = dbl_to_int(getDDDArray("lastRow", sv));
181  if (firstY.size() != lastY.size()) {
182  edm::LogError("HGCalGeom") << "FastTimeDDDConstants: unequal numbers "
183  << firstY.size() << ":" << lastY.size()
184  << " elements for first and last rows";
185  throw cms::Exception("DDException") << "FastTimeDDDConstants: wrong array sizes for first/last Row";
186  }
187 
188  nCells = 0;
189  nCols = (int)(firstY.size());
190  nRows = 0;
191  for (int k=0; k<nCols; ++k) {
192  firstCell.push_back(nCells+1);
193  nCells += (lastY[k]-firstY[k]+1);
194  lastCell.push_back(nCells);
195  if (lastY[k] > nRows) nRows = lastY[k];
196  }
197 
198 #ifdef DebugLog
199  std::cout << "FastTimeDDDConstants: nCells = " << nCells << ", nRow = "
200  << 2*nRows << ", nColumns = " << 2*nCols << std::endl;
201  for (int k=0; k<nCols; ++k)
202  std::cout << "Column[" << k << "] Cells = " << firstCell[k] << ":"
203  << lastCell[k] << ", Rows = " << firstY[k] << ":" << lastY[k]
204  << std::endl;
205 #endif
206 
207  std::vector<double> gpar = getDDDArray("geomPars",sv);
208  if (gpar.size() < 3) {
209  edm::LogError("HGCalGeom") << "FastTimeDDDConstants: too few "
210  << gpar.size() << " elements for gpar";
211  throw cms::Exception("DDException") << "FastTimeDDDConstants: wrong array sizes for gpar";
212  }
213  rIn = gpar[0];
214  rOut = gpar[1];
215  cellSize = gpar[2];
216 #ifdef DebugLog
217  std::cout << "FastTimeDDDConstants: cellsize " << cellSize << " in region "
218  << rIn << ":" << rOut << std::endl;
219 #endif
220 
221  gpar = getDDDArray("geomType",sv);
222  cellType = int(gpar[0]);
223 #ifdef DebugLog
224  std::cout << "FastTimeDDDConstants: cell type " << cellType << std::endl;
225 #endif
226 }
227 
228 std::vector<double> FastTimeDDDConstants::getDDDArray(const std::string & str,
229  const DDsvalues_type & sv) const {
230 
231 #ifdef DebugLog
232  std::cout << "FastTimeDDDConstants:getDDDArray called for " << str << std::endl;
233 #endif
234  DDValue value(str);
235  if (DDfetch(&sv,value)) {
236 #ifdef DebugLog
237  std::cout << "FastTimeDDDConstants: " << value << std::endl;
238 #endif
239  const std::vector<double> & fvec = value.doubles();
240  int nval = fvec.size();
241  if (nval > 0) return fvec;
242  }
243  edm::LogError("HGCalGeom") << "FastTimeDDDConstants: cannot get array "
244  << str;
245  throw cms::Exception("DDException") << "FastTimeDDDConstants: cannot get array " << str;
246 }
247 
249 
void initialize(const DDCompactView &cpv)
int quadrant(int ix, int iy) const
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:139
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
bool isValidXY(int ix, int iy) const
type of data representation of DDCompactView
Definition: DDCompactView.h:77
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:80
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.cc:4
T x() const
Cartesian x coordinate.
FastTimeDDDConstants(const DDCompactView &cpv)
T sqrt(T t)
Definition: SSEVec.h:48
bool isValidCell(int copy) const
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
std::vector< int > firstCell
std::vector< int > firstY
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
void loadSpecPars(const DDFilteredView &fv)
std::vector< int > lastCell
#define column(...)
Definition: DbCore.h:74
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &) const
DDsvalues_type mergedSpecifics() const
std::vector< int > lastY
bool firstChild()
set the current node to the first child ...
tuple cout
Definition: gather_cfg.py:121
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
std::pair< int, int > getXY(int copy) const
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:245
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:32