CMS 3D CMS Logo

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