27 #include "CLHEP/Units/GlobalSystemOfUnits.h" 51 #include <boost/algorithm/string/replace.hpp> 63 geometryVersion(geometryVersion_),
67 if (
debug)
cout <<
"Constructing a MagGeoBuilderFromDDD" <<endl;
71 for (handles::const_iterator
i=
bVolumes.begin();
76 for (handles::const_iterator
i=
eVolumes.begin();
85 int ivolumes = volumes.size();
86 int isurfaces = ivolumes*6;
92 set<const void *> ptrs;
94 handles::const_iterator
first = volumes.begin();
95 handles::const_iterator
last = volumes.end();
97 for (handles::const_iterator
i=first;
i!=
last; ++
i){
98 if (
int((*i)->shape())>4)
continue;
99 for (
int side = 0; side < 6; ++side) {
100 int references = (*i)->references(side);
101 if ((*i)->isPlaneMatched(side)) {
103 bool firstOcc = (ptrs.insert(&((*i)->surface(side)))).
second;
104 if (firstOcc) iref_ass+=references;
106 cout <<
"*** Only 1 ref, vol: " << (*i)->volumeno <<
" # " 107 << (*i)->copyno <<
" side: " << side << endl;
110 iref_nass+=references;
112 cout <<
"*** Ref_nass >1 " <<endl;
117 iunique = ptrs.size();
119 cout <<
" volumes " << ivolumes << endl
120 <<
" surfaces " << isurfaces << endl
121 <<
" assigned " << iassigned << endl
122 <<
" unique " << iunique << endl
123 <<
" iref_ass " << iref_ass << endl
124 <<
" iref_nass " << iref_nass << endl;
133 if (
debug)
cout <<
"**********************************************************" <<endl;
136 map<string, MagProviderInterpol*> bInterpolators;
137 map<string, MagProviderInterpol*> eInterpolators;
150 while(go&& doSubDets) {
157 throw cms::Exception(
"NoMAGFinDDD")<<
" Neither the top node, nor any child node of the DDCompactView is \"MAGF\" but the top node is instead \""<<topNodeName<<
"\"";
163 <<
" rotation: " << fv.
rotation() << endl;
170 if (
debug)
cout << endl <<
"Name: " << name << endl
201 TableFileMap::const_iterator itable =
theGridFiles->find(key);
208 string magFile = (*itable).second.first;
211 conv << setfill(
'0') << setw(3) << v->
volumeno <<
" " << setw(2) << v->
copyno;
212 conv >> svol >> ssec;
213 boost::replace_all(magFile,
"[v]",svol);
214 boost::replace_all(magFile,
"[s]",ssec);
215 int masterSector = (*itable).second.second;
216 if (masterSector==0) masterSector=v->
copyno;
235 if ((fabs(Z)<647. || (R>350. && fabs(Z)<662.)) &&
236 !(fabs(Z)>480 && R<172)
265 cout <<
"Number of volumes (barrel): " <<
bVolumes.size() <<endl
266 <<
"Number of volumes (endcap): " <<
eVolumes.size() <<endl;
267 cout <<
"**********************************************************" <<endl;
277 cout <<
"-----------------------" << endl;
278 cout <<
"SUMMARY: Barrel " << endl;
281 cout << endl <<
"SUMMARY: Endcaps " << endl;
283 cout <<
"-----------------------" << endl;
299 if (
debug)
cout <<
" R layers: " << rmin <<
" " << rmax << endl;
304 for (handles::const_iterator
i=first;
i!=
last; ++
i){
305 hisR.
fill((*i)->RN());
307 vector<float> rClust = hisR.
clusterize(resolution);
309 handles::const_iterator ringStart =
first;
310 handles::const_iterator separ =
first;
312 for (
unsigned int i=0;
i<rClust.size() - 1; ++
i) {
313 if (
debug)
cout <<
" Layer at RN = " << rClust[
i];
314 float rSepar = (rClust[
i] + rClust[
i+1])/2.
f;
315 while ((*separ)->RN() < rSepar) ++separ;
317 bLayer thislayer(ringStart, separ);
318 layers.push_back(thislayer);
322 if (
debug)
cout <<
" Layer at RN = " << rClust.back();
323 bLayer thislayer(separ, last);
324 layers.push_back(thislayer);
327 if (
debug)
cout <<
"Barrel: Found " << rClust.size() <<
" clusters in R, " 328 << layers.size() <<
" layers " << endl << endl;
333 vector<eSector> sectors;
336 float phireso = 0.05;
341 hisPhi.
fill((*i)->minPhi());
343 vector<float> phiClust = hisPhi.
clusterize(phireso);
344 int nESectors = phiClust.size();
345 if (
debug && (nESectors%12)!=0)
cout <<
"ERROR: unexpected # of sectors: " << nESectors << endl;
352 float lastBinPhi = phiClust.back();
353 handles::reverse_iterator ri =
eVolumes.rbegin();
354 while ((*ri)->center().phi()>lastBinPhi) {++ri;}
358 handles::iterator newbeg = ri.base();
364 for (
int i = 0;
i<nESectors; ++
i) {
366 cout <<
" Sector at phi = " 367 << (*(
eVolumes.begin()+((
i)*offset)))->center().phi()
371 for (handles::const_iterator iv=
eVolumes.begin()+((
i)*offset); iv!=
eVolumes.begin()+((
i+1)*offset); ++iv){
372 if (secCopyNo>=0&& (*iv)->copyno!=secCopyNo)
cout <<
"ERROR: volume copyno" << (*iv)->name <<
":" << (*iv)->copyno <<
" differs from others in same sectors " << secCopyNo << endl;
373 secCopyNo = (*iv)->copyno;
382 << sectors.size() <<
" sectors " << endl;
427 for (vector<bLayer>::const_iterator ilay = layers.begin();
428 ilay!= layers.end(); ++ilay) {
429 mBLayers.push_back((*ilay).buildMagBLayer());
433 cout <<
"*** BARREL ********************************************" << endl
434 <<
"Number of different volumes = " << bVolCount << endl
435 <<
"Number of interpolators built = " << bInterpolators.size() << endl
436 <<
"Number of MagBLayers built = " <<
mBLayers.size() << endl;
446 for (vector<eSector>::const_iterator isec = sectors.begin();
447 isec!= sectors.end(); ++isec) {
448 mESectors.push_back((*isec).buildMagESector());
452 cout <<
"*** ENDCAP ********************************************" << endl
453 <<
"Number of different volumes = " << eVolCount << endl
454 <<
"Number of interpolators built = " << eInterpolators.size() << endl
455 <<
"Number of MagESector built = " <<
mESectors.size() << endl;
464 for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
467 if (interpolators.find((*vol)->magFile)!=interpolators.end()) {
468 mp = interpolators[(*vol)->magFile];
470 edm::LogError(
"MagGeoBuilderFromDDDbuildMagVolumes") <<
"No interpolator found for file " << (*vol)->magFile
471 <<
" vol: " << (*vol)->volumeno <<
"\n" << interpolators.size() <<endl;
476 int key = ((*vol)->volumeno)*100+(*vol)->copyno;
479 key = ((*vol)->volumeno)*100;
487 edm::LogInfo(
"MagneticField|VolumeBasedMagneticFieldESProducer") <<
"Applying scaling factor " << sf <<
" to "<< (*vol)->volumeno <<
"["<< (*vol)->copyno <<
"] (key:" << key <<
")" << endl;
497 if ((*vol)->copyno==(*vol)->masterSector) {
501 (*vol)->magVolume->setIsIron((*vol)->isIron());
504 (*vol)->magVolume->volumeNo = (*vol)->volumeno;
505 (*vol)->magVolume->copyno = (*vol)->copyno;
516 cout <<
"Building interpolator from " 518 <<
" at " << vol->
center()
525 cout <<
"***WARNING wrong sector? " << endl;
540 cerr <<
"MagGeoBuilderFromDDD: exception in reading table; " << exc.
what() << endl;
572 interpolators.erase(vol->
magFile);
590 cout <<
"Grid has 3 dimensions " 591 <<
" number of nodes is " << sizes.
w <<
" " << sizes.
h 592 <<
" " << sizes.
d << endl;
597 size_t dumpCount = 0;
598 for (
int j=0; j < sizes.
h; j++) {
599 for (
int k=0;
k < sizes.
d;
k++) {
600 for (
int i=0;
i < sizes.
w;
i++) {
602 if (! tempVolume.inside(lp, tolerance)) {
603 if (++dumpCount < 2) {
605 cout <<
"GRID ERROR: " <<
i <<
" " << j <<
" " <<
k 608 <<
" R= " << gp.perp() <<
" phi=" << gp.phi() << endl;
615 cout <<
"Volume:" << vol->
volumeno <<
" : Number of grid points outside the MagVolume: " << dumpCount <<
"/" << sizes.
w*sizes.
h*sizes.
d << endl;
624 cout <<
"--------------------------------------------------" << endl;
625 cout <<
" inside(center) test" << endl;
626 for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
628 for (handles::const_iterator
i=volumes.begin();
i!=volumes.end();
630 if ((*
i)==(*vol))
continue;
632 if ((*i)->magVolume->inside((*vol)->center())) {
633 cout <<
"*** ERROR: center of V " << (*vol)->volumeno <<
":" << (*vol)->copyno <<
" is inside V " 634 << (*i)->volumeno <<
":" << (*i)->copyno << endl;
638 if ((*vol)->magVolume->inside((*vol)->center())) {
639 cout <<
"V " << (*vol)->volumeno <<
" OK " << endl;
641 cout <<
"*** ERROR: center of volume is not inside it, " 642 << (*vol)->volumeno << endl;
645 cout <<
"--------------------------------------------------" << endl;
658 vector<MagVolume6Faces*>
v;
660 for (handles::const_iterator
i=
bVolumes.begin();
662 v.push_back((*i)->magVolume);
668 vector<MagVolume6Faces*>
v;
670 for (handles::const_iterator
i=
eVolumes.begin();
672 v.push_back((*i)->magVolume);
691 const std::vector<double>&
values)
693 if (keys.size() != values.size()) {
694 throw cms::Exception(
"InvalidParameter") <<
"Invalid field scaling parameters 'scalingVolumes' and 'scalingFactors' ";
696 for (
unsigned int i=0;
i<keys.size(); ++
i) {
virtual char const * what() const
unsigned short copyno
copy number
std::vector< MagBLayer * > mBLayers
std::vector< volumeHandle * > handles
const GloballyPositioned< float > * placement() const
FIXME: currently returns max RN (to be fixed?). Used by: bLayer::maxR()
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
static HepMC::IO_HEPEVT conv
ROOT::Math::Plane3D::Vector Vector
std::vector< VolumeSide > sides() const
The surfaces and they orientation, as required to build a MagVolume.
Geom::Phi< T > phi() const
std::vector< MagBLayer * > barrelLayers() const
Get barrel layers.
const GlobalPoint & center() const
Return the center of the volume.
GloballyPositioned< float >::LocalPoint LocalPoint
type of data representation of DDCompactView
DDSolidShape shape() const
Shape of the solid.
void summary(handles &volumes)
std::vector< MagVolume6Faces * > barrelVolumes() const
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
U second(std::pair< T, U > const &p)
virtual ~MagGeoBuilderFromDDD()
Destructor.
virtual void build(const DDCompactView &cpv)
std::vector< float > clusterize(float resolution)
virtual const char * what() const
void testInside(handles &volumes)
std::string magFile
Name of magnetic field table file.
std::vector< MagESector * > endcapSectors() const
Get endcap layers.
static MFGrid * build(const std::string &name, const GloballyPositioned< float > &vol)
Build interpolator for a binary grid file.
const DDTranslation & translation() const
The absolute translation of the current node.
MagGeoBuilderFromDDD(std::string tableSet_, int geometryVersion, bool debug=false)
Constructor.
unsigned short volumeno
volume number
const magneticfield::TableFileMap * theGridFiles
bool firstChild()
set the current node to the first child ...
GloballyPositioned< float >::GlobalPoint GlobalPoint
void buildInterpolator(const volumeHandle *vol, std::map< std::string, MagProviderInterpol * > &interpolators)
bool nextSibling()
set the current node to the next sibling ...
void setScaling(const std::vector< int > &keys, const std::vector< double > &values)
Point3DBase< T, GlobalTag > PositionType
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
std::vector< MagVolume6Faces * > endcapVolumes() const
const RotationType & rotation() const
int masterSector
The sector for which an interpolator for this class of volumes should be built.
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
std::string fullPath() const
std::vector< MagESector * > mESectors
std::map< int, std::pair< std::string, int > > TableFileMap
const PositionType & position() const
Provides an exploded view of the detector (tree-view)
std::map< int, double > theScalingFactors
void buildMagVolumes(const handles &volumes, std::map< std::string, MagProviderInterpol * > &interpolators)
def rotate(angle, cx=0, cy=0)
const std::string & name() const
Returns the name.
void ownsFieldProvider(bool o)
void setGridFiles(const magneticfield::TableFileMap &gridFiles)