29 #include "CLHEP/Units/GlobalSystemOfUnits.h"
53 #include <boost/algorithm/string/replace.hpp>
60 using namespace magneticfield;
65 geometryVersion(geometryVersion_),
69 if (
debug)
cout <<
"Constructing a MagGeoBuilderFromDDD" <<endl;
73 for (handles::const_iterator
i=
bVolumes.begin();
78 for (handles::const_iterator
i=
eVolumes.begin();
87 int ivolumes = volumes.size();
88 int isurfaces = ivolumes*6;
94 set<const void *> ptrs;
96 handles::const_iterator
first = volumes.begin();
97 handles::const_iterator
last = volumes.end();
99 for (handles::const_iterator
i=first;
i!=
last; ++
i){
100 if (
int((*i)->shape())>4)
continue;
101 for (
int side = 0; side < 6; ++side) {
102 int references = (*i)->references(side);
103 if ((*i)->isPlaneMatched(side)) {
105 bool firstOcc = (ptrs.insert(&((*i)->surface(side)))).
second;
106 if (firstOcc) iref_ass+=references;
108 cout <<
"*** Only 1 ref, vol: " << (*i)->volumeno <<
" # "
109 << (*i)->copyno <<
" side: " << side << endl;
112 iref_nass+=references;
114 cout <<
"*** Ref_nass >1 " <<endl;
119 iunique = ptrs.size();
121 cout <<
" volumes " << ivolumes << endl
122 <<
" surfaces " << isurfaces << endl
123 <<
" assigned " << iassigned << endl
124 <<
" unique " << iunique << endl
125 <<
" iref_ass " << iref_ass << endl
126 <<
" iref_nass " << iref_nass << endl;
135 if (
debug)
cout <<
"**********************************************************" <<endl;
138 map<string, MagProviderInterpol*> bInterpolators;
139 map<string, MagProviderInterpol*> eInterpolators;
152 while(go&& doSubDets) {
159 throw cms::Exception(
"NoMAGFinDDD")<<
" Neither the top node, nor any child node of the DDCompactView is \"MAGF\" but the top node is instead \""<<topNodeName<<
"\"";
165 <<
" rotation: " << fv.
rotation() << endl;
172 if (
debug)
cout << endl <<
"Name: " << name << endl
203 TableFileMap::const_iterator itable =
theGridFiles->find(key);
210 string magFile = (*itable).second.first;
213 conv << setfill(
'0') << setw(3) << v->
volumeno <<
" " << setw(2) << v->
copyno;
214 conv >> svol >> ssec;
215 boost::replace_all(magFile,
"[v]",svol);
216 boost::replace_all(magFile,
"[s]",ssec);
217 int masterSector = (*itable).second.second;
218 if (masterSector==0) masterSector=v->
copyno;
237 if ((fabs(Z)<647. || (R>350. && fabs(Z)<662.)) &&
238 !(fabs(Z)>480 && R<172)
267 cout <<
"Number of volumes (barrel): " <<
bVolumes.size() <<endl
268 <<
"Number of volumes (endcap): " <<
eVolumes.size() <<endl;
269 cout <<
"**********************************************************" <<endl;
279 cout <<
"-----------------------" << endl;
280 cout <<
"SUMMARY: Barrel " << endl;
283 cout << endl <<
"SUMMARY: Endcaps " << endl;
285 cout <<
"-----------------------" << endl;
292 vector<bLayer> layers;
301 if (
debug)
cout <<
" R layers: " << rmin <<
" " << rmax << endl;
306 for (handles::const_iterator
i=first;
i!=
last; ++
i){
307 hisR.
fill((*i)->RN());
309 vector<float> rClust = hisR.
clusterize(resolution);
311 handles::const_iterator ringStart =
first;
312 handles::const_iterator separ =
first;
314 for (
unsigned int i=0;
i<rClust.size() - 1; ++
i) {
315 if (
debug)
cout <<
" Layer at RN = " << rClust[
i];
316 float rSepar = (rClust[
i] + rClust[
i+1])/2.
f;
317 while ((*separ)->RN() < rSepar) ++separ;
319 bLayer thislayer(ringStart, separ);
320 layers.push_back(thislayer);
324 if (
debug)
cout <<
" Layer at RN = " << rClust.back();
325 bLayer thislayer(separ, last);
326 layers.push_back(thislayer);
329 if (
debug)
cout <<
"Barrel: Found " << rClust.size() <<
" clusters in R, "
330 << layers.size() <<
" layers " << endl << endl;
338 float phireso = 0.05;
343 hisPhi.
fill((*i)->minPhi());
345 vector<float> phiClust = hisPhi.
clusterize(phireso);
346 int nESectors = phiClust.size();
347 if (
debug && (nESectors%12)!=0)
cout <<
"ERROR: unexpected # of sectors: " << nESectors << endl;
353 for (
int i = 0;
i<nESectors; ++
i) {
356 << (*(
eVolumes.begin()+((
i)*offset)))->center().phi()
363 << sectors.size() <<
" sectors " << endl;
408 for (vector<bLayer>::const_iterator ilay = layers.begin();
409 ilay!= layers.end(); ++ilay) {
410 mBLayers.push_back((*ilay).buildMagBLayer());
414 cout <<
"*** BARREL ********************************************" << endl
415 <<
"Number of different volumes = " << bVolCount << endl
416 <<
"Number of interpolators built = " << bInterpolators.size() << endl
417 <<
"Number of MagBLayers built = " <<
mBLayers.size() << endl;
427 for (vector<eSector>::const_iterator isec = sectors.begin();
428 isec!= sectors.end(); ++isec) {
429 mESectors.push_back((*isec).buildMagESector());
433 cout <<
"*** ENDCAP ********************************************" << endl
434 <<
"Number of different volumes = " << eVolCount << endl
435 <<
"Number of interpolators built = " << eInterpolators.size() << endl
436 <<
"Number of MagESector built = " <<
mESectors.size() << endl;
445 for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
448 if (interpolators.find((*vol)->magFile)!=interpolators.end()) {
449 mp = interpolators[(*vol)->magFile];
451 edm::LogError(
"MagGeoBuilderFromDDDbuildMagVolumes") <<
"No interpolator found for file " << (*vol)->magFile
452 <<
" vol: " << (*vol)->volumeno <<
"\n" << interpolators.size() <<endl;
457 int key = ((*vol)->volumeno)*100+(*vol)->copyno;
460 key = ((*vol)->volumeno)*100;
468 edm::LogInfo(
"MagneticField|VolumeBasedMagneticFieldESProducer") <<
"Applying scaling factor " << sf <<
" to "<< (*vol)->volumeno <<
"["<< (*vol)->copyno <<
"] (key:" << key <<
")" << endl;
478 if ((*vol)->copyno==(*vol)->masterSector) {
482 (*vol)->magVolume->setIsIron((*vol)->isIron());
485 (*vol)->magVolume->volumeNo = (*vol)->volumeno;
486 (*vol)->magVolume->copyno = (*vol)->copyno;
497 cout <<
"Building interpolator from "
499 <<
" at " << vol->
center()
505 cout <<
"***WARNING wrong sector? " << endl;
520 cerr <<
"MagGeoBuilderFromDDD: exception in reading table; " << exc.
what() << endl;
552 interpolators.erase(vol->
magFile);
570 cout <<
"Grid has 3 dimensions "
571 <<
" number of nodes is " << sizes.
w <<
" " << sizes.
h
572 <<
" " << sizes.
d << endl;
574 const double tolerance = 0.03;
577 size_t dumpCount = 0;
578 for (
int j=0;
j < sizes.
h;
j++) {
579 for (
int k=0;
k < sizes.
d;
k++) {
580 for (
int i=0;
i < sizes.
w;
i++) {
582 if (! tempVolume.inside(lp, tolerance)) {
583 if (++dumpCount < 2) {
585 cout <<
"GRID ERROR: " <<
i <<
" " <<
j <<
" " <<
k
588 <<
" R= " << gp.perp() <<
" phi=" << gp.phi() << endl;
595 cout <<
"Volume:" << vol->
volumeno <<
" : Number of grid points outside the MagVolume: " << dumpCount <<
"/" << sizes.
w*sizes.
h*sizes.
d << endl;
604 cout <<
"--------------------------------------------------" << endl;
605 cout <<
" inside(center) test" << endl;
606 for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
608 for (handles::const_iterator
i=volumes.begin();
i!=volumes.end();
610 if ((*
i)==(*vol))
continue;
612 if ((*i)->magVolume->inside((*vol)->center())) {
613 cout <<
"*** ERROR: center of V " << (*vol)->volumeno <<
" is inside V "
614 << (*i)->volumeno <<endl;
618 if ((*vol)->magVolume->inside((*vol)->center())) {
619 cout <<
"V " << (*vol)->volumeno <<
" OK " << endl;
621 cout <<
"*** ERROR: center of volume is not inside it, "
622 << (*vol)->volumeno << endl;
625 cout <<
"--------------------------------------------------" << endl;
638 vector<MagVolume6Faces*>
v;
640 for (handles::const_iterator
i=
bVolumes.begin();
642 v.push_back((*i)->magVolume);
648 vector<MagVolume6Faces*>
v;
650 for (handles::const_iterator
i=
eVolumes.begin();
652 v.push_back((*i)->magVolume);
671 const std::vector<double>&
values)
673 if (keys.size() != values.size()) {
674 throw cms::Exception(
"InvalidParameter") <<
"Invalid field scaling parameters 'scalingVolumes' and 'scalingFactors' ";
676 for (
unsigned int i=0;
i<keys.size(); ++
i) {
const double Z[kNumberCalorimeter]
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.
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.
unsigned int offset(bool)
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
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
const PositionType & position() const
Provides an exploded view of the detector (tree-view)
std::map< int, double > theScalingFactors
void setGridFiles(const std::auto_ptr< magneticfield::TableFileMap > gridFiles)
std::auto_ptr< magneticfield::TableFileMap > theGridFiles
void buildMagVolumes(const handles &volumes, std::map< std::string, MagProviderInterpol * > &interpolators)
const std::string & name() const
Returns the name.
void ownsFieldProvider(bool o)