27 #include "CLHEP/Units/GlobalSystemOfUnits.h"
51 #include <boost/algorithm/string/replace.hpp>
58 using namespace magneticfield;
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;
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;
351 for (
int i = 0;
i<nESectors; ++
i) {
354 << (*(
eVolumes.begin()+((
i)*offset)))->center().phi()
361 << sectors.size() <<
" sectors " << endl;
406 for (vector<bLayer>::const_iterator ilay = layers.begin();
407 ilay!= layers.end(); ++ilay) {
408 mBLayers.push_back((*ilay).buildMagBLayer());
412 cout <<
"*** BARREL ********************************************" << endl
413 <<
"Number of different volumes = " << bVolCount << endl
414 <<
"Number of interpolators built = " << bInterpolators.size() << endl
415 <<
"Number of MagBLayers built = " <<
mBLayers.size() << endl;
425 for (vector<eSector>::const_iterator isec = sectors.begin();
426 isec!= sectors.end(); ++isec) {
427 mESectors.push_back((*isec).buildMagESector());
431 cout <<
"*** ENDCAP ********************************************" << endl
432 <<
"Number of different volumes = " << eVolCount << endl
433 <<
"Number of interpolators built = " << eInterpolators.size() << endl
434 <<
"Number of MagESector built = " <<
mESectors.size() << endl;
443 for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
446 if (interpolators.find((*vol)->magFile)!=interpolators.end()) {
447 mp = interpolators[(*vol)->magFile];
449 edm::LogError(
"MagGeoBuilderFromDDDbuildMagVolumes") <<
"No interpolator found for file " << (*vol)->magFile
450 <<
" vol: " << (*vol)->volumeno <<
"\n" << interpolators.size() <<endl;
455 int key = ((*vol)->volumeno)*100+(*vol)->copyno;
458 key = ((*vol)->volumeno)*100;
466 edm::LogInfo(
"MagneticField|VolumeBasedMagneticFieldESProducer") <<
"Applying scaling factor " << sf <<
" to "<< (*vol)->volumeno <<
"["<< (*vol)->copyno <<
"] (key:" << key <<
")" << endl;
476 if ((*vol)->copyno==(*vol)->masterSector) {
480 (*vol)->magVolume->setIsIron((*vol)->isIron());
483 (*vol)->magVolume->volumeNo = (*vol)->volumeno;
484 (*vol)->magVolume->copyno = (*vol)->copyno;
495 cout <<
"Building interpolator from "
497 <<
" at " << vol->
center()
503 cout <<
"***WARNING wrong sector? " << endl;
518 cerr <<
"MagGeoBuilderFromDDD: exception in reading table; " << exc.
what() << endl;
550 interpolators.erase(vol->
magFile);
568 cout <<
"Grid has 3 dimensions "
569 <<
" number of nodes is " << sizes.
w <<
" " << sizes.
h
570 <<
" " << sizes.
d << endl;
572 const double tolerance = 0.03;
575 size_t dumpCount = 0;
576 for (
int j=0;
j < sizes.
h;
j++) {
577 for (
int k=0;
k < sizes.
d;
k++) {
578 for (
int i=0;
i < sizes.
w;
i++) {
580 if (! tempVolume.inside(lp, tolerance)) {
581 if (++dumpCount < 2) {
583 cout <<
"GRID ERROR: " <<
i <<
" " <<
j <<
" " <<
k
586 <<
" R= " << gp.perp() <<
" phi=" << gp.phi() << endl;
593 cout <<
"Volume:" << vol->
volumeno <<
" : Number of grid points outside the MagVolume: " << dumpCount <<
"/" << sizes.
w*sizes.
h*sizes.
d << endl;
602 cout <<
"--------------------------------------------------" << endl;
603 cout <<
" inside(center) test" << endl;
604 for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
606 for (handles::const_iterator
i=volumes.begin();
i!=volumes.end();
608 if ((*
i)==(*vol))
continue;
610 if ((*i)->magVolume->inside((*vol)->center())) {
611 cout <<
"*** ERROR: center of V " << (*vol)->volumeno <<
" is inside V "
612 << (*i)->volumeno <<endl;
616 if ((*vol)->magVolume->inside((*vol)->center())) {
617 cout <<
"V " << (*vol)->volumeno <<
" OK " << endl;
619 cout <<
"*** ERROR: center of volume is not inside it, "
620 << (*vol)->volumeno << endl;
623 cout <<
"--------------------------------------------------" << endl;
636 vector<MagVolume6Faces*>
v;
638 for (handles::const_iterator
i=
bVolumes.begin();
640 v.push_back((*i)->magVolume);
646 vector<MagVolume6Faces*>
v;
648 for (handles::const_iterator
i=
eVolumes.begin();
650 v.push_back((*i)->magVolume);
669 const std::vector<double>&
values)
671 if (keys.size() != values.size()) {
672 throw cms::Exception(
"InvalidParameter") <<
"Invalid field scaling parameters 'scalingVolumes' and 'scalingFactors' ";
674 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.
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.
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)