Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "MagneticField/GeomBuilder/src/bLayer.h"
00012 #include "MagneticField/VolumeGeometry/interface/MagVolume6Faces.h"
00013 #include "MagneticField/Layers/interface/MagBLayer.h"
00014 #include "MagneticField/Layers/interface/MagVerbosity.h"
00015
00016 #include "Utilities/General/interface/precomputed_value_sort.h"
00017
00018 using namespace SurfaceOrientation;
00019
00020
00021 MagGeoBuilderFromDDD::bLayer::bLayer(handles::const_iterator begin,
00022 handles::const_iterator end) :
00023 size(end-begin),
00024 theVolumes(begin,end),
00025 mlayer(0)
00026 {
00027
00028 precomputed_value_sort(theVolumes.begin(), theVolumes.end(), ExtractPhi());
00029
00030 if (MagGeoBuilderFromDDD::debug) {
00031 std::cout << " elements: " << theVolumes.size() << " unique volumes: ";
00032 volumeHandle::printUniqueNames(theVolumes.begin(), theVolumes.end());
00033 }
00034
00035
00036
00037 handles::iterator secBegin = theVolumes.begin();
00038 handles::iterator secEnd;
00039 int binOffset = 0;
00040
00041 const Surface & refSurf = (*secBegin)->surface(outer);
00042
00043 int newbegin=0;
00044 int newend=0;
00045
00046
00047
00048
00049
00050
00051
00052
00053 if (size==1) {
00054
00055
00056 if (MagGeoBuilderFromDDD::debug) std::cout <<" Sector is just one volume." << std::endl;
00057
00058 } else if (size==12 ||
00059 (((*secBegin)->shape()!=ddtrap) && (*secBegin)->shape()!=ddbox)) {
00060 secEnd = secBegin+size/12;
00061
00062 } else {
00063 float tolerance = 0.025;
00064 do {
00065 if (MagGeoBuilderFromDDD::debug) std::cout << (*secBegin)->name
00066 << " " << (*secBegin)->copyno << std::endl;
00067 ++secBegin;
00068 } while ((secBegin != theVolumes.end()) &&
00069 (*secBegin)->sameSurface(refSurf,outer, tolerance));
00070
00071 secEnd = secBegin;
00072 secBegin = theVolumes.begin()+bin((secEnd-theVolumes.begin())-size/12);;
00073 newend = secEnd-theVolumes.begin();
00074 newbegin = secBegin-theVolumes.begin();
00075
00076
00077 rotate(theVolumes.begin(),secBegin,theVolumes.end());
00078 secBegin = theVolumes.begin();
00079 secEnd = secBegin+size/12;
00080
00081
00082 if (!((*secBegin)->sameSurface((*(secEnd-1))->surface(outer),
00083 outer, tolerance))) {
00084 std::cout << "*** ERROR: Big mess while looking for sectors "
00085 << (*secBegin)->name << " " << (*secBegin)->copyno << " "
00086 << (*(secEnd-1))->name << " " << (*(secEnd-1))->copyno
00087 << std::endl;
00088 }
00089 }
00090
00091 if (MagGeoBuilderFromDDD::debug) {
00092 std::cout << " First sector: volumes " << secEnd-theVolumes.begin()
00093 << " from " << newbegin
00094 << " (phi = " << (*secBegin)->center().phi() << ") "
00095 << " to " << newend
00096 << " (phi = " << (*secEnd)->center().phi() << ") "
00097 << " # " << (*secBegin)->copyno << " ";
00098 std::cout << GlobalVector( refSurf.rotation().zx(), refSurf.rotation().zy(),
00099 refSurf.rotation().zz()) << std::endl;
00100 }
00101
00102 if (size!=1) {
00103 int offset = size/12;
00104 sectors.resize(12);
00105 for (int i = 0; i<12; ++i) {
00106 int isec = (i+binOffset)%12;
00107 sectors[isec>=0?isec:isec+12] = bSector(theVolumes.begin()+((i)*offset),
00108 theVolumes.begin()+((i+1)*offset));
00109 }
00110 }
00111
00112 if (MagGeoBuilderFromDDD::debug) std::cout << "-----------------------" << std::endl;
00113
00114 }
00115
00116 MagGeoBuilderFromDDD::bLayer::~bLayer(){}
00117
00118 int MagGeoBuilderFromDDD::bLayer::bin(int i) const {
00119 i = i%size;
00120 return (i>=0?i:i+size);
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130 double MagGeoBuilderFromDDD::bLayer::minR() const {
00131
00132 return theVolumes.front()->minR();
00133 }
00134
00135
00136
00137
00138
00139
00140 MagBLayer * MagGeoBuilderFromDDD::bLayer::buildMagBLayer() const {
00141 if (mlayer==0) {
00142
00143
00144 if (sectors.size()==0) {
00145 if (MagGeoBuilderFromDDD::debug && size!=0) {
00146 std::cout << "ERROR: bLayer::buildMagBLayer, 0 sectors but "
00147 << size << " volumes" << std::endl;
00148 }
00149
00150
00151 mlayer = new MagBLayer(theVolumes.front()->magVolume, minR());
00152 }
00153
00154
00155 std::vector<MagBSector*> mSectors;
00156 for (unsigned int i=0; i<sectors.size(); ++i) {
00157 mSectors.push_back(sectors[i].buildMagBSector());
00158 }
00159 mlayer = new MagBLayer(mSectors, minR());
00160 }
00161 return mlayer;
00162 }
00163