CMS 3D CMS Logo

bLayer.cc
Go to the documentation of this file.
1 // #include "Utilities/Configuration/interface/Architecture.h"
2 
3 /*
4  * See header file for a description of this class.
5  *
6  * \author N. Amapane - INFN Torino
7  */
8 
13 
15 
16 using namespace SurfaceOrientation;
17 
18 //The ctor is in charge of finding sectors inside the layer.
20  handles::const_iterator end) :
21  size(end-begin),
22  theVolumes(begin,end),
23  mlayer(nullptr)
24 {
25  // Sort in phi
27 
29  std::cout << " elements: " << theVolumes.size() << " unique volumes: ";
31  }
32 
33 
34  // Find sectors in phi
35  handles::iterator secBegin = theVolumes.begin();
36  handles::iterator secEnd;
37  int binOffset = 0;
38 
39  const Surface & refSurf = (*secBegin)->surface(outer);
40 
41  int newbegin=0;
42  int newend=0;
43 
44  // A sector is made of several volumes in R, and, for planar layers
45  // (box and traps) also in phi, so it might cross the -phi boundary.
46  // For those, we have to look for the end of first sector and rotate the
47  // vector of volumes.
48  // ASSUMPTION: all volumes in a layer must be of compatible type.
49 
50 
51  if (size==1) { // Only one volume; this is the case for barrel
52  // cylinders.
53  // FIXME sectors.push_back(bSector(theVolumes.begin(),theVolumes.end());
54  if (MagGeoBuilderFromDDD::debug) std::cout <<" Sector is just one volume." << std::endl;
55 
56  } else if (size==12 || // In this case, each volume is a sector.
57  (((*secBegin)->shape()!=DDSolidShape::ddtrap) && (*secBegin)->shape()!=DDSolidShape::ddbox)) {
58  secEnd = secBegin+size/12;
59 
60  } else { // there are more than one volume per sector.
61  float tolerance = 0.025; // 250 micron
62  do {
63  if (MagGeoBuilderFromDDD::debug) std::cout << (*secBegin)->name
64  << " " << (*secBegin)->copyno << std::endl;
65  ++secBegin;
66  } while ((secBegin != theVolumes.end()) &&
67  (*secBegin)->sameSurface(refSurf,outer, tolerance)); // This works only if outer surface is a plane, otherwise sameSurface returns always true!
68 
69  secEnd = secBegin;
70  secBegin = theVolumes.begin()+bin((secEnd-theVolumes.begin())-size/12);;
71  newend = secEnd-theVolumes.begin();
72  newbegin = secBegin-theVolumes.begin();
73 
74  // Rotate the begin of the first sector to the vector beginning.
75  rotate(theVolumes.begin(),secBegin,theVolumes.end());
76  secBegin = theVolumes.begin();
77  secEnd = secBegin+size/12;
78 
79  // Test it is correct...
80  if (!((*secBegin)->sameSurface((*(secEnd-1))->surface(outer),
81  outer, tolerance))) {
82  std::cout << "*** ERROR: Big mess while looking for sectors "
83  << (*secBegin)->name << " " << (*secBegin)->copyno << " "
84  << (*(secEnd-1))->name << " " << (*(secEnd-1))->copyno
85  << std::endl;
86  }
87  }
88 
90  std::cout << " First sector: volumes " << secEnd-theVolumes.begin()
91  << " from " << newbegin
92  << " (phi = " << (*secBegin)->center().phi() << ") "
93  << " to " << newend
94  << " (phi = " << (*secEnd)->center().phi() << ") "
95  << " # " << (*secBegin)->copyno << " ";
96  std::cout << GlobalVector( refSurf.rotation().zx(), refSurf.rotation().zy(),
97  refSurf.rotation().zz()) << std::endl;
98  }
99 
100  if (size!=1) { // Build the 12 sectors
101  int offset = size/12;
102  sectors.resize(12);
103  for (int i = 0; i<12; ++i) {
104  int isec = (i+binOffset)%12;
105  sectors[isec>=0?isec:isec+12] = bSector(theVolumes.begin()+((i)*offset),
106  theVolumes.begin()+((i+1)*offset));
107  }
108  }
109 
110  if (MagGeoBuilderFromDDD::debug) std::cout << "-----------------------" << std::endl;
111 
112 }
113 
115 
117  i = i%size;
118  return (i>=0?i:i+size);
119 }
120 
121 // const MagGeoBuilderFromDDD::bSector &
122 // MagGeoBuilderFromDDD::bLayer::sector(int i) const {
123 // i = i%12;
124 // return sectors[i>=0?i:i+12];
125 // }
126 
127 
129  // ASSUMPTION: a layer is only 1 volume thick (by construction).
130  return theVolumes.front()->minR();
131 }
132 
133 // double MagGeoBuilderFromDDD::bLayer::maxR() const {
134 // // ASSUMPTION: a layer is only 1 volume thick (by construction).
135 // return theVolumes.front()->maxR();
136 // }
137 
139  if (mlayer==nullptr) {
140 
141  // If we have only one volume, do not build any MagBSector.
142  if (sectors.empty()) {
143  if (MagGeoBuilderFromDDD::debug && size!=0) {
144  std::cout << "ERROR: bLayer::buildMagBLayer, 0 sectors but "
145  << size << " volumes" << std::endl;
146  }
147  // Technically we might have only one bSector built and we would
148  // not need a separate MagBLayer constructor...
149  mlayer = new MagBLayer(theVolumes.front()->magVolume, minR());
150  }
151 
152  // If we have several sectors, create the MagBSector
153  std::vector<MagBSector*> mSectors;
154  for (unsigned int i=0; i<sectors.size(); ++i) {
155  mSectors.push_back(sectors[i].buildMagBSector());
156  }
157  mlayer = new MagBLayer(mSectors, minR());
158  }
159  return mlayer;
160 }
161 
size
Write out results.
const double tolerance
#define nullptr
T zx() const
T zz() const
int bin(int i) const
Definition: bLayer.cc:116
T zy() const
#define end
Definition: vmac.h:39
static void printUniqueNames(handles::const_iterator begin, handles::const_iterator end, bool uniq=true)
Just for debugging...
std::vector< bSector > sectors
Definition: bLayer.h:52
#define begin
Definition: vmac.h:32
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
MagBLayer * buildMagBLayer() const
Construct the MagBLayer upon request.
Definition: bLayer.cc:138
const RotationType & rotation() const
bLayer(handles::const_iterator begin, handles::const_iterator end)
Constructor from list of volumes.
Definition: bLayer.cc:19
double minR() const
Return sector at i (handling periodicity)
Definition: bLayer.cc:128
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:704
Global3DVector GlobalVector
Definition: GlobalVector.h:10