CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
magneticfield::bLayer Class Reference

#include <bLayer.h>

Public Member Functions

 bLayer (handles::const_iterator begin, handles::const_iterator end, bool debugFlag=false)
 Constructor from list of volumes. More...
 
MagBLayerbuildMagBLayer () const
 Construct the MagBLayer upon request. More...
 
double minR () const
 Return sector at i (handling periodicity) More...
 
const float RN () const
 Distance from center along normal of sectors. More...
 
const handlesvolumes () const
 Return the list of all volumes. More...
 
 ~bLayer ()=default
 Destructor. More...
 

Private Member Functions

int bin (int i) const
 

Private Attributes

const bool debug
 
MagBLayermlayer
 
std::vector< bSectorsectors
 
int size
 
handles theVolumes
 

Detailed Description

Definition at line 17 of file bLayer.h.

Constructor & Destructor Documentation

bLayer::bLayer ( handles::const_iterator  begin,
handles::const_iterator  end,
bool  debugFlag = false 
)

Constructor from list of volumes.

Definition at line 21 of file bLayer.cc.

References bin(), gather_cfg::cout, ddbox, ddtrap, debug, mps_fire::i, hltrates_dqm_sourceclient-live_cfg::offset, SurfaceOrientation::outer, precomputed_value_sort(), magneticfield::printUniqueNames(), svgfig::rotate(), GloballyPositioned< T >::rotation(), sectors, size, theVolumes, tolerance, TkRotation< T >::zx(), TkRotation< T >::zy(), and TkRotation< T >::zz().

22  : size(end - begin), theVolumes(begin, end), mlayer(nullptr), debug(debugFlag) {
23  // Sort in phi
25 
26  if (debug) {
27  std::cout << " elements: " << theVolumes.size() << " unique volumes: ";
28  printUniqueNames(theVolumes.begin(), theVolumes.end());
29  }
30 
31  // Find sectors in phi
32  handles::iterator secBegin = theVolumes.begin();
33  handles::iterator secEnd = secBegin;
34  int binOffset = 0;
35 
36  const Surface& refSurf = (*secBegin)->surface(outer);
37 
38  int newbegin = 0;
39  int newend = 0;
40 
41  // A sector is made of several volumes in R, and, for planar layers
42  // (box and traps) also in phi, so it might cross the -phi boundary.
43  // For those, we have to look for the end of first sector and rotate the
44  // vector of volumes.
45  // ASSUMPTION: all volumes in a layer must be of compatible type.
46 
47  if (size == 1) { // Only one volume; this is the case for barrel
48  // cylinders.
49  // FIXME sectors.push_back(bSector(theVolumes.begin(),theVolumes.end());
50  if (debug)
51  std::cout << " Sector is just one volume." << std::endl;
52 
53  } else if (size == 12 || // In this case, each volume is a sector.
54  (((*secBegin)->shape() != DDSolidShape::ddtrap) && (*secBegin)->shape() != DDSolidShape::ddbox)) {
55  secEnd = secBegin + size / 12;
56 
57  } else { // there are more than one volume per sector.
58  float tolerance = 0.025; // 250 micron
59  do {
60  if (debug)
61  std::cout << (*secBegin)->name << " " << (*secBegin)->copyno << std::endl;
62  ++secBegin;
63  } while (
64  (secBegin != theVolumes.end()) &&
65  (*secBegin)->sameSurface(
66  refSurf,
67  outer,
68  tolerance)); // This works only if outer surface is a plane, otherwise sameSurface returns always true!
69 
70  secEnd = secBegin;
71  secBegin = theVolumes.begin() + bin((secEnd - theVolumes.begin()) - size / 12);
72  ;
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), outer, tolerance))) {
83  std::cout << "*** ERROR: Big mess while looking for sectors " << (*secBegin)->name << " " << (*secBegin)->copyno
84  << " " << (*(secEnd - 1))->name << " " << (*(secEnd - 1))->copyno << std::endl;
85  }
86  }
87 
88  if (debug) {
89  std::cout << " First sector: volumes " << secEnd - theVolumes.begin() << " from " << newbegin
90  << " (phi = " << (*secBegin)->center().phi() << ") "
91  << " to " << newend << " (phi = " << (*secEnd)->center().phi() << ") "
92  << " # " << (*secBegin)->copyno << " ";
93  std::cout << GlobalVector(refSurf.rotation().zx(), refSurf.rotation().zy(), refSurf.rotation().zz()) << std::endl;
94  }
95 
96  if (size != 1) { // Build the 12 sectors
97  int offset = size / 12;
98  sectors.resize(12);
99  for (int i = 0; i < 12; ++i) {
100  int isec = (i + binOffset) % 12;
101  sectors[isec >= 0 ? isec : isec + 12] =
102  bSector(theVolumes.begin() + ((i)*offset), theVolumes.begin() + ((i + 1) * offset), debug);
103  }
104  }
105 
106  if (debug)
107  std::cout << "-----------------------" << std::endl;
108 }
void printUniqueNames(handles::const_iterator begin, handles::const_iterator end, bool uniq=true)
Just for debugging...
const bool debug
Definition: bLayer.h:54
const double tolerance
std::vector< bSector > sectors
Definition: bLayer.h:50
T zx() const
T zz() const
T zy() const
#define end
Definition: vmac.h:39
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
handles theVolumes
Definition: bLayer.h:51
#define begin
Definition: vmac.h:32
const RotationType & rotation() const
MagBLayer * mlayer
Definition: bLayer.h:53
int bin(int i) const
Definition: bLayer.cc:110
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:705
Global3DVector GlobalVector
Definition: GlobalVector.h:10
magneticfield::bLayer::~bLayer ( )
default

Destructor.

Member Function Documentation

int bLayer::bin ( int  i) const
private

Definition at line 110 of file bLayer.cc.

References size.

Referenced by bLayer().

110  {
111  i = i % size;
112  return (i >= 0 ? i : i + size);
113 }
MagBLayer * bLayer::buildMagBLayer ( ) const

Construct the MagBLayer upon request.

Definition at line 131 of file bLayer.cc.

References gather_cfg::cout, debug, mps_fire::i, minR(), mlayer, sectors, size, and theVolumes.

Referenced by volumes().

131  {
132  if (mlayer == nullptr) {
133  // If we have only one volume, do not build any MagBSector.
134  if (sectors.empty()) {
135  if (debug && size != 0) {
136  std::cout << "ERROR: bLayer::buildMagBLayer, 0 sectors but " << size << " volumes" << std::endl;
137  }
138  // Technically we might have only one bSector built and we would
139  // not need a separate MagBLayer constructor...
140  mlayer = new MagBLayer(theVolumes.front()->magVolume, minR());
141  }
142 
143  // If we have several sectors, create the MagBSector
144  std::vector<MagBSector*> mSectors;
145  for (unsigned int i = 0; i < sectors.size(); ++i) {
146  mSectors.push_back(sectors[i].buildMagBSector());
147  }
148  mlayer = new MagBLayer(mSectors, minR());
149  }
150  return mlayer;
151 }
const bool debug
Definition: bLayer.h:54
std::vector< bSector > sectors
Definition: bLayer.h:50
double minR() const
Return sector at i (handling periodicity)
Definition: bLayer.cc:121
handles theVolumes
Definition: bLayer.h:51
MagBLayer * mlayer
Definition: bLayer.h:53
double bLayer::minR ( ) const

Return sector at i (handling periodicity)

Min R (conservative guess).

Definition at line 121 of file bLayer.cc.

References theVolumes.

Referenced by buildMagBLayer(), and volumes().

121  {
122  // ASSUMPTION: a layer is only 1 volume thick (by construction).
123  return theVolumes.front()->minR();
124 }
handles theVolumes
Definition: bLayer.h:51
const float magneticfield::bLayer::RN ( ) const
inline

Distance from center along normal of sectors.

Definition at line 26 of file bLayer.h.

References theVolumes.

26 { return theVolumes.front()->RN(); }
handles theVolumes
Definition: bLayer.h:51
const handles& magneticfield::bLayer::volumes ( ) const
inline

Return the list of all volumes.

Definition at line 29 of file bLayer.h.

References buildMagBLayer(), minR(), and theVolumes.

29 { return theVolumes; }
handles theVolumes
Definition: bLayer.h:51

Member Data Documentation

const bool magneticfield::bLayer::debug
private
MagBLayer* magneticfield::bLayer::mlayer
mutableprivate

Definition at line 53 of file bLayer.h.

Referenced by buildMagBLayer().

std::vector<bSector> magneticfield::bLayer::sectors
private

Definition at line 50 of file bLayer.h.

Referenced by bLayer(), and buildMagBLayer().

int magneticfield::bLayer::size
private
handles magneticfield::bLayer::theVolumes
private

Definition at line 51 of file bLayer.h.

Referenced by bLayer(), buildMagBLayer(), minR(), RN(), and volumes().