11 #include "CLHEP/Units/GlobalPhysicalConstants.h"
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
23 std::cout <<
"HGCalDDDConstants for " << nam <<
" initialized with "
24 <<
layers(
false) <<
":" <<
layers(
true) <<
" layers and "
26 <<
":" <<
maxCells(
true) <<
" cells" << std::endl;
33 int subSec,
bool reco)
const {
37 if (i < 0)
return std::pair<int,int>(-1,-1);
41 std::pair<int,int> cellAssignment( (x>0)?1:0, -1 );
47 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
48 cellAssignment=
assignCell(x, y, h, bl, tl, alpha, index.second);
54 cellAssignment=
assignCell(x, y, h, bl, tl, alpha, index.second);
57 return cellAssignment;
61 float bl,
float tl,
float alpha,
62 float cellSize)
const {
64 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
65 float b = 2*h*bl/(tl-bl);
68 int phiSector = (x0 > 0) ? 1 : 0;
69 if (alpha < 0) {x0 -= 0.5*(tl+bl); phiSector = 0;}
70 else if (alpha > 0) {x0 += 0.5*(tl+bl); phiSector = 1;}
74 int ky = floor((y+h)/cellSize);
75 if( ky*cellSize> y+h) ky--;
76 if(ky<0)
return std::pair<int,int>(-1,-1);
77 if( (ky+1)*cellSize < (y+
h) ) ky++;
78 int max_ky_allowed=floor(2*h/cellSize);
79 if(ky>max_ky_allowed-1)
return std::pair<int,int>(-1,-1);
83 int kx = floor(fabs(x0)/cellSize);
84 if( kx*cellSize > fabs(x0) ) kx--;
85 if(kx<0)
return std::pair<int,int>(-1,-1);
86 if( (kx+1)*cellSize < fabs(x0) ) kx++;
87 int max_kx_allowed=floor( ((ky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) );
88 if(kx>max_kx_allowed-1)
return std::pair<int,int>(-1,-1);
93 for (
int iky=0; iky<ky; ++iky) {
94 int cellsInRow( floor( ((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) ) );
100 return std::pair<int,int>(phiSector,icell);
108 if (i < 0)
return std::pair<int,int>(-1,-1);
115 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
122 return findCell(cell, h, bl, tl, alpha, index.second);
126 float tl,
float alpha,
127 float cellSize)
const {
130 if(cell<0)
return std::pair<int,int>(-1,-1);
133 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
134 float b = 2*h*bl/(tl-bl);
136 int kymax( floor((2*h)/cellSize) );
138 for (
int iky=0; iky<kymax; ++iky) {
142 int cellsInRow( floor( ((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) ) );
143 if (testCell+cellsInRow > cell)
break;
144 testCell += cellsInRow;
149 return std::pair<int,int>(kx,ky);
154 bool ok = ((lay > 0 && lay <= (int)(
layers(reco))) &&
155 (mod > 0 && mod <=
sectors()) &&
156 (cell >=0 && cell <=
maxCells(lay,reco)));
159 if (!ok)
std::cout <<
"HGCalDDDConstants: Layer " << lay <<
":"
160 << (lay > 0 && (lay <= (int)(
layers(reco)))) <<
" Module "
161 << mod <<
":" << (mod > 0 && mod <=
sectors()) <<
" Cell "
162 << cell <<
":" << (cell >=0 && cell <=
maxCells(lay,reco))
163 <<
":" <<
maxCells(reco) << std::endl;
169 int subSec,
bool reco)
const {
173 if (i < 0)
return std::pair<float,float>(999999.,999999.);
174 std::pair<int,int> kxy =
findCell(cell, lay, subSec, reco);
181 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
188 float cellSize = index.second;
189 float x = (kxy.first+0.5)*cellSize;
190 if (alpha < 0) x -= 0.5*(tl+bl);
191 else if (alpha > 0) x -= 0.5*(tl+bl);
192 if (subSec != 1) x = -
x;
193 float y = ((kxy.second+0.5)*cellSize-
h);
194 return std::pair<float,float>(
x,
y);
200 for (
unsigned int i = 0;
i<
layers(reco); ++
i) {
224 return maxCells(h, bl, tl, alpha, index.second);
228 float cellSize)
const {
230 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
231 float b = 2*h*bl/(tl-bl);
235 int kymax = floor((2*h)/cellSize);
236 for (
int iky=0; iky<kymax; ++iky)
238 int cellsInRow=floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize));
239 ncells += cellsInRow;
251 int kymax = floor((2*h)/index.second);
256 int subsector,
int incrx,
257 int incry,
bool half)
const {
259 int subSec = half ? subsector : 0;
260 std::pair<int,int> kxy =
findCell(cell, layer, subSec,
true);
261 int kx = kxy.first + incrx;
262 int ky = kxy.second + incry;
263 if (ky < 0 || ky >
maxRows(layer,
true)) {
265 return std::pair<int,int>(cell,sector*subsector);
268 subsector =-subsector;
269 }
else if (kx >
maxCells(layer,
true)) {
272 subsector =-subsector;
274 else if (sector >
nSectors) sector = 1;
276 cell =
newCell(kx, ky, layer, subSec);
277 return std::pair<int,int>(cell,sector*subsector);
281 int incrz,
bool half)
const {
283 int layer = lay + incrz;
284 if (layer <= 0 || layer > (
int)(
layers(
true)))
return std::pair<int,int>(cell,0);
285 int subSec = half ? subsector : 0;
286 std::pair<float,float>
xy =
locateCell(cell, lay, subSec,
true);
287 std::pair<int,int> kcell =
assignCell(xy.first, xy.second, layer, subSec,
289 return std::pair<int,int>(kcell.second,layer);
298 float cellSize = index.second;
299 float a = (alpha==0) ?
305 for (
int iky=0; iky<ky; ++iky)
327 return numberCells(h, bl, tl, alpha, index.second);
329 std::vector<int> ncell;
335 float tl,
float alpha,
336 float cellSize)
const {
338 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
339 float b = 2*h*bl/(tl-bl);
340 int kymax = floor((2*h)/cellSize);
341 std::vector<int> ncell;
342 for (
int iky=0; iky<kymax; ++iky)
343 ncell.push_back(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
352 if (i < 0)
return std::pair<int,int>(-1,-1);
360 if(depth<0)
return std::pair<int,int>(-1,-1);
364 float a = (half) ? (h/(tl-bl)) : (2*h/(tl-bl));
365 float b = 2*h*bl/(tl-bl);
366 for (
int iky=0; iky<ky; ++iky)
370 std::cout <<
"simToReco: input " << cell <<
":" << lay <<
":" << half
371 <<
" kxy " << kxy.first <<
":" << kxy.second <<
" output "
372 << kx <<
":" << depth <<
" cell factor=" <<
cellFactor_[
i] << std::endl;
374 return std::pair<int,int>(kx,
depth);
383 DDValue val(attribute, value, 0);
403 bool dodet(
true),
first(
true);
405 std::vector<hgtrform> trforms;
411 int isd = (name.find(sdTag) == std::string::npos) ? -1 : 1;
414 int nsiz = (int)(copy.size());
415 int lay = (nsiz > 0) ? copy[nsiz-1] : -1;
416 int sec = (nsiz > 1) ? copy[nsiz-2] : -1;
417 int zp = (nsiz > 3) ? copy[nsiz-4] : -1;
418 if (zp !=1 ) zp = -1;
419 if (first) {first =
false; zpFirst = zp;}
422 0.5*(trp.
y1()+trp.
y2()),
424 int subs = (trp.
alpha1()>0 ? 1 : 0);
427 if (lay == (
int)(
k+1)) {
439 fv.
rotation().GetComponents( x, y, z ) ;
440 const CLHEP::HepRep3x3
rotation ( x.X(), y.X(), z.X(),
442 x.Z(), y.Z(), z.Z() );
444 const CLHEP::Hep3Vector h3v ( fv.
translation().X(),
450 trforms.push_back(mytrf);
455 edm::LogError(
"HGCalGeom") <<
"HGCalDDDConstants : mismatch in # of bins "
457 <<
" between geometry and specpar";
458 throw cms::Exception(
"DDException") <<
"HGCalDDDConstants: mismatch between geometry and specpar";
460 for (
unsigned int i=0;
i<
layer_.size(); ++
i) {
461 for (
unsigned int k=0;
k<
layer_.size(); ++
k) {
470 << sdTag <<
" with " <<
nSectors <<
" sectors and "
471 << trforms.size() <<
" transformation matrices" << std::endl;
482 for (
unsigned int i=0;
i<
layer_.size(); ++
i) {
519 for (
unsigned int i=0;
i<
layer_.size(); ++
i) {
520 for (
unsigned int i1=0; i1<trforms.size(); ++i1) {
521 if (!trforms[i1].used &&
layerGroup_[trforms[i1].lay-1] == (
int)(
i+1)) {
522 trform_.push_back(trforms[i1]);
525 trforms[i1].used =
true;
527 for (
unsigned int i2=i1+1; i2<trforms.size(); ++i2) {
528 if (!trforms[i2].used && trforms[i2].zp == trforms[i1].zp &&
530 trforms[i2].sec == trforms[i1].sec &&
531 trforms[i2].subsec == trforms[i1].subsec) {
534 trforms[i2].used =
true;
546 for (
unsigned int k=0;
k<
trform_.size(); ++
k) {
563 std::cout <<
"HGCalDDDConstants: " << nCells <<
" entries for cellSize_"
569 if ((nCells-1)%8 != 7)
std::cout << std::endl;
575 std::cout <<
"HGCalDDDConstants: " << nCells <<
" entries for cellFactor_"
581 if ((nCells-1)%8 != 7)
std::cout << std::endl;
587 std::cout <<
"HGCalDDDConstants: " << nCells <<
" entries for layerGroup_"
593 if ((nCells-1)%8 != 7)
std::cout << std::endl;
602 const std::vector<double> & fvec = value.
doubles();
603 int nval = fvec.size();
606 edm::LogError(
"HGCalGeom") <<
"HGCalDDDConstants : # of " << str
607 <<
" bins " << nval <<
" < " << nmin
609 throw cms::Exception(
"DDException") <<
"HGCalDDDConstants: cannot get array " << str;
612 if (nval < 1 && nmin == 0) {
613 edm::LogError(
"HGCalGeom") <<
"HGCalDDDConstants : # of " << str
614 <<
" bins " << nval <<
" < 2 ==> illegal"
615 <<
" (nmin=" << nmin <<
")";
616 throw cms::Exception(
"DDException") <<
"HGCalDDDConstants: cannot get array " << str;
623 edm::LogError(
"HGCalGeom") <<
"HGCalDDDConstants: cannot get array "
625 throw cms::Exception(
"DDException") <<
"HGCalDDDConstants: cannot get array " << str;
627 std::vector<double> fvec;
635 if (lay<1 || lay>(
int)(
layerIndex.size()))
return std::pair<int,float>(-1,0);
636 if (reco && lay>(
int)(
depthIndex.size()))
return std::pair<int,float>(-1,0);
639 return std::pair<int,float>(
i,cell);
double halfZ(void) const
half of the z-Axis
const double k_ScaleFromDDD
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
bool isValid(int lay, int mod, int cell, bool reco) const
double x1(void) const
Half-length along x of the side at y=-pDy1 of the face at -pDz.
std::vector< double > cellSize_
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
nav_type copyNumbers() const
return the stack of copy numbers
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
int maxRows(int lay, bool reco) const
std::vector< int > numberCells(int lay, bool reco) const
std::vector< int > depth_
std::vector< hgtrap > moduler_
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
type of data representation of DDCompactView
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
A DDSolid represents the shape of a part.
std::vector< int > depthIndex
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
T x() const
Cartesian x coordinate.
void loadGeometry(const DDFilteredView &fv, const std::string &tag)
unsigned int layers(bool reco) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
void initialize(const DDCompactView &cpv, std::string name)
bool next()
set current node to the next node in the filtered tree
std::pair< int, int > findCell(int cell, int lay, int subSec, bool reco) const
std::pair< int, float > getIndex(int lay, bool reco) 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::...
const double k_horizontalShift
Interface to a Trapezoid.
double y1(void) const
Half-length along y of the face at -pDz.
std::vector< int > cellFactor_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void loadSpecPars(const DDFilteredView &fv)
std::pair< int, int > simToReco(int cell, int layer, bool half) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
std::vector< hgtrform > trform_
std::vector< int > layer_
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &, int &) const
std::vector< int > layerGroup_
double alpha1(void) const
Angle with respect to the y axis from the centre of the side at y=-pDy1 to the centre at y=+pDy1 of t...
DDsvalues_type mergedSpecifics() const
HGCalDDDConstants(const DDCompactView &cpv, std::string &name)
double x2(void) const
Half-length along x of the side at y=+pDy1 of the face at -pDz.
std::pair< int, int > newCell(int cell, int layer, int sector, int subsector, int incrx, int incry, bool half) const
bool firstChild()
set the current node to the first child ...
double y2(void) const
Half-length along y of the face at +pDz.
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
const DDTranslation & translation() const
The absolute translation of the current node.
std::pair< float, float > locateCell(int cell, int lay, int subSec, bool reco) const
std::vector< hgtrap > modules_
int maxCells(bool reco) const
T mod(const T &a, const T &b)
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
std::vector< int > layerIndex
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.