CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends
MagGeoBuilderFromDDD Class Reference

#include <MagGeoBuilderFromDDD.h>

Classes

class  bLayer
 
class  bRod
 
class  bSector
 
class  bSlab
 
class  eLayer
 
class  eSector
 
struct  ExtractAbsZ
 
struct  ExtractPhi
 
struct  ExtractPhiMax
 
struct  ExtractR
 
struct  ExtractRN
 
struct  ExtractZ
 
struct  LessDPhi
 
struct  LessZ
 
class  volumeHandle
 

Public Member Functions

std::vector< MagBLayer * > barrelLayers () const
 Get barrel layers. More...
 
std::vector< MagESector * > endcapSectors () const
 Get endcap layers. More...
 
 MagGeoBuilderFromDDD (std::string tableSet_, int geometryVersion, bool debug=false)
 Constructor. More...
 
float maxR () const
 
float maxZ () const
 
void setGridFiles (const magneticfield::TableFileMap &gridFiles)
 
void setScaling (const std::vector< int > &keys, const std::vector< double > &values)
 
virtual ~MagGeoBuilderFromDDD ()
 Destructor. More...
 

Private Types

typedef std::vector< volumeHandle * > handles
 
typedef ConstReferenceCountingPointer< SurfaceRCPS
 
typedef std::unary_function< const volumeHandle *, double > uFcn
 

Private Member Functions

std::vector< MagVolume6Faces * > barrelVolumes () const
 
virtual void build (const DDCompactView &cpv)
 
void buildInterpolator (const volumeHandle *vol, std::map< std::string, MagProviderInterpol * > &interpolators)
 
void buildMagVolumes (const handles &volumes, std::map< std::string, MagProviderInterpol * > &interpolators)
 
std::vector< MagVolume6Faces * > endcapVolumes () const
 
void summary (handles &volumes)
 
void testInside (handles &volumes)
 

Private Attributes

handles bVolumes
 
handles eVolumes
 
int geometryVersion
 
std::vector< MagBLayer * > mBLayers
 
std::vector< MagESector * > mESectors
 
std::string tableSet
 
const magneticfield::TableFileMaptheGridFiles
 
std::map< int, double > theScalingFactors
 

Static Private Attributes

static bool debug
 

Friends

class MagGeometry
 
class magneticfield::AutoMagneticFieldESProducer
 
class magneticfield::VolumeBasedMagneticFieldESProducer
 
class magneticfield::VolumeBasedMagneticFieldESProducerFromDB
 
class TestMagVolume
 

Detailed Description

Parse the XML magnetic geometry, build individual volumes and match their shared surfaces. Build MagVolume6Faces and organise them in a hierarchical structure. Build MagGeometry out of it.

Author
N. Amapane - INFN Torino

Definition at line 33 of file MagGeoBuilderFromDDD.h.

Member Typedef Documentation

typedef std::vector<volumeHandle*> MagGeoBuilderFromDDD::handles
private

Definition at line 78 of file MagGeoBuilderFromDDD.h.

Definition at line 59 of file MagGeoBuilderFromDDD.h.

typedef std::unary_function<const volumeHandle*, double> MagGeoBuilderFromDDD::uFcn
private

Definition at line 106 of file MagGeoBuilderFromDDD.h.

Constructor & Destructor Documentation

MagGeoBuilderFromDDD::MagGeoBuilderFromDDD ( std::string  tableSet_,
int  geometryVersion,
bool  debug = false 
)

Constructor.

Definition at line 61 of file MagGeoBuilderFromDDD.cc.

References gather_cfg::cout, and debug.

61  :
62  tableSet (tableSet_),
63  geometryVersion(geometryVersion_),
64  theGridFiles(nullptr)
65 {
66  debug = debug_;
67  if (debug) cout << "Constructing a MagGeoBuilderFromDDD" <<endl;
68 }
const magneticfield::TableFileMap * theGridFiles
MagGeoBuilderFromDDD::~MagGeoBuilderFromDDD ( )
virtual

Destructor.

Definition at line 70 of file MagGeoBuilderFromDDD.cc.

References bVolumes, eVolumes, and mps_fire::i.

70  {
71  for (handles::const_iterator i=bVolumes.begin();
72  i!=bVolumes.end(); ++i){
73  delete (*i);
74  }
75 
76  for (handles::const_iterator i=eVolumes.begin();
77  i!=eVolumes.end(); ++i){
78  delete (*i);
79  }
80 }

Member Function Documentation

vector< MagBLayer * > MagGeoBuilderFromDDD::barrelLayers ( ) const

Get barrel layers.

Definition at line 649 of file MagGeoBuilderFromDDD.cc.

References mBLayers.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

649  {
650  return mBLayers;
651 }
std::vector< MagBLayer * > mBLayers
vector< MagVolume6Faces * > MagGeoBuilderFromDDD::barrelVolumes ( ) const
private

Definition at line 657 of file MagGeoBuilderFromDDD.cc.

References bVolumes, mps_fire::i, and findQualityFiles::v.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

657  {
658  vector<MagVolume6Faces*> v;
659  v.reserve(bVolumes.size());
660  for (handles::const_iterator i=bVolumes.begin();
661  i!=bVolumes.end(); ++i){
662  v.push_back((*i)->magVolume);
663  }
664  return v;
665 }
void MagGeoBuilderFromDDD::build ( const DDCompactView cpv)
privatevirtual

Definition at line 128 of file MagGeoBuilderFromDDD.cc.

References buildInterpolator(), buildMagVolumes(), bVolumes, MagGeoBuilderFromDDD::volumeHandle::center(), ClusterizingHistogram::clusterize(), conv, MagGeoBuilderFromDDD::volumeHandle::copyno, gather_cfg::cout, debug, eVolumes, Exception, f, ClusterizingHistogram::fill(), plotBeamSpotDB::first, DDExpandedView::firstChild(), Geom::fpi(), Geom::ftwoPi(), DDExpandedView::geoHistory(), mps_fire::i, crabWrapper::key, plotBeamSpotDB::last, LayerTriplets::layers(), DDExpandedView::logicalPart(), MagGeoBuilderFromDDD::volumeHandle::magFile, MagGeoBuilderFromDDD::volumeHandle::masterSector, mBLayers, mESectors, DDName::name(), dataset::name, DDBase< N, C >::name(), DDExpandedView::nextSibling(), PFRecoTauDiscriminationByIsolation_cfi::offset, PV3DBase< T, PVType, FrameType >::perp(), precomputed_value_sort(), dttmaxenums::R, fftjetproducer_cfi::resolution, svgfig::rotate(), DDExpandedView::rotation(), AlCaHLTBitMon_QueryRunRegistry::string, summary(), testInside(), theGridFiles, DDExpandedView::translation(), findQualityFiles::v, MagGeoBuilderFromDDD::volumeHandle::volumeno, DOFs::Z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

129 {
130 // DDCompactView cpv;
131  DDExpandedView fv(cpva);
132 
133  if (debug) cout << "**********************************************************" <<endl;
134 
135  // The actual field interpolators
136  map<string, MagProviderInterpol*> bInterpolators;
137  map<string, MagProviderInterpol*> eInterpolators;
138 
139  // Counter of different volumes
140  int bVolCount = 0;
141  int eVolCount = 0;
142 
143  if (fv.logicalPart().name().name()!="MAGF") {
144  std::string topNodeName(fv.logicalPart().name().name());
145 
146  //see if one of the children is MAGF
147  bool doSubDets = fv.firstChild();
148 
149  bool go=true;
150  while(go&& doSubDets) {
151  if (fv.logicalPart().name().name()=="MAGF")
152  break;
153  else
154  go = fv.nextSibling();
155  }
156  if (!go) {
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<<"\"";
158  }
159  }
160  // Loop over MAGF volumes and create volumeHandles.
161  if (debug) { cout << endl << "*** MAGF: " << fv.geoHistory() << endl
162  << "translation: " << fv.translation() << endl
163  << " rotation: " << fv.rotation() << endl;
164  }
165 
166  bool doSubDets = fv.firstChild();
167  while (doSubDets){
168 
169  string name = fv.logicalPart().name().name();
170  if (debug) cout << endl << "Name: " << name << endl
171  << " " << fv.geoHistory() <<endl;
172 
173  // FIXME: single-volyme cylinders - this is feature has been removed
174  // and should be revisited.
175  // bool mergeCylinders=false;
176 
177  // If true, In the barrel, cylinders sectors will be skipped to build full
178  // cylinders out of sector copyno #1.
179  bool expand = false;
180 
181 // if (mergeCylinders) {
182 // if (name == "V_ZN_1"
183 // || name == "V_ZN_2") {
184 // if (debug && fv.logicalPart().solid().shape()!=ddtubs) {
185 // cout << "ERROR: MagGeoBuilderFromDDD::build: volume " << name
186 // << " should be a cylinder" << endl;
187 // }
188 // if(fv.copyno()==1) {
189 // expand = true;
190 // } else {
191 // //cout << "... to be skipped: "
192 // // << name << " " << fv.copyno() << endl;
193 // }
194 // }
195 // }
196 
197  volumeHandle* v = new volumeHandle(fv, expand);
198 
199  if (theGridFiles!=nullptr) {
200  int key = (v->volumeno)*100+v->copyno;
201  TableFileMap::const_iterator itable = theGridFiles->find(key);
202  if (itable == theGridFiles->end()) {
203  key = (v->volumeno)*100;
204  itable = theGridFiles->find(key);
205  }
206 
207  if (itable != theGridFiles->end()) {
208  string magFile = (*itable).second.first;
209  stringstream conv;
210  string svol, ssec;
211  conv << setfill('0') << setw(3) << v->volumeno << " " << setw(2) << v->copyno; // volume assumed to have 0s padding to 3 digits; sector assumed to have 0s padding to 2 digits
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;
217  v->magFile = magFile;
218  v->masterSector = masterSector;
219  } else {
220  edm::LogError("MagGeoBuilderFromDDDbuild") << "ERROR: no table spec found for V " << v->volumeno << ":" << v->copyno;
221  }
222  }
223 
224 
225  // Select volumes, build volume handles.
226  float Z = v->center().z();
227  float R = v->center().perp();
228 
229  // v 85l: Barrel is everything up to |Z| = 661.0, excluding
230  // volume #7, centered at 6477.5
231  // v 1103l: same numbers work fine. #16 instead of #7, same coords;
232  // see comment below for V6,7
233  //ASSUMPTION: no misalignment is applied to mag volumes.
234  //FIXME: implement barrel/endcap flags as DDD SpecPars.
235  if ((fabs(Z)<647. || (R>350. && fabs(Z)<662.)) &&
236  !(fabs(Z)>480 && R<172) // in 1103l we place V_6 and V_7 in the
237  // endcaps to preserve nice layer structure
238  // in the barrel. This does not hurt in v85l
239  // where there is a single V1
240  ) { // Barrel
241  if (debug) cout << " (Barrel)" <<endl;
242  bVolumes.push_back(v);
243 
244 
245  // Build the interpolator of the "master" volume (the one which is
246  // not replicated in phi)
247  // ASSUMPTION: copyno == sector.
248  if (v->copyno==v->masterSector) {
249  buildInterpolator(v, bInterpolators);
250  ++bVolCount;
251  }
252  } else { // Endcaps
253  if (debug) cout << " (Endcaps)" <<endl;
254  eVolumes.push_back(v);
255  if (v->copyno==v->masterSector) {
256  buildInterpolator(v, eInterpolators);
257  ++eVolCount;
258  }
259  }
260 
261  doSubDets = fv.nextSibling(); // end of loop over MAGF
262  }
263 
264  if (debug) {
265  cout << "Number of volumes (barrel): " << bVolumes.size() <<endl
266  << "Number of volumes (endcap): " << eVolumes.size() <<endl;
267  cout << "**********************************************************" <<endl;
268  }
269 
270  // Now all volumeHandles are there, and parameters for each of the planes
271  // are calculated.
272 
273  //----------------------------------------------------------------------
274  // Print summary information
275 
276  if (debug) {
277  cout << "-----------------------" << endl;
278  cout << "SUMMARY: Barrel " << endl;
279  summary(bVolumes);
280 
281  cout << endl << "SUMMARY: Endcaps " << endl;
282  summary(eVolumes);
283  cout << "-----------------------" << endl;
284  }
285 
286 
287  //----------------------------------------------------------------------
288  // Find barrel layers.
289 
290  vector<bLayer> layers; // the barrel layers
291  precomputed_value_sort(bVolumes.begin(), bVolumes.end(), ExtractRN());
292 
293  // Find the layers (in R)
294  const float resolution = 1.; // cm
295  float rmin = bVolumes.front()->RN()-resolution;
296  float rmax = bVolumes.back()->RN()+resolution;
297  ClusterizingHistogram hisR( int((rmax-rmin)/resolution) + 1, rmin, rmax);
298 
299  if (debug) cout << " R layers: " << rmin << " " << rmax << endl;
300 
301  handles::const_iterator first = bVolumes.begin();
302  handles::const_iterator last = bVolumes.end();
303 
304  for (handles::const_iterator i=first; i!=last; ++i){
305  hisR.fill((*i)->RN());
306  }
307  vector<float> rClust = hisR.clusterize(resolution);
308 
309  handles::const_iterator ringStart = first;
310  handles::const_iterator separ = first;
311 
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;
316 
317  bLayer thislayer(ringStart, separ);
318  layers.push_back(thislayer);
319  ringStart = separ;
320  }
321  {
322  if (debug) cout << " Layer at RN = " << rClust.back();
323  bLayer thislayer(separ, last);
324  layers.push_back(thislayer);
325  }
326 
327  if (debug) cout << "Barrel: Found " << rClust.size() << " clusters in R, "
328  << layers.size() << " layers " << endl << endl;
329 
330 
331  //----------------------------------------------------------------------
332  // Find endcap sectors
333  vector<eSector> sectors; // the endcap sectors
334 
335  // Find the number of sectors (should be 12 or 24 depending on the geometry model)
336  float phireso = 0.05; // rad
337  ClusterizingHistogram hisPhi( int((Geom::ftwoPi())/phireso) + 1,
338  -Geom::fpi(), Geom::fpi());
339 
340  for (handles::const_iterator i=eVolumes.begin(); i!=eVolumes.end(); ++i){
341  hisPhi.fill((*i)->minPhi());
342  }
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;
346 
347  //Sort in phi
348  precomputed_value_sort(eVolumes.begin(), eVolumes.end(), ExtractPhi());
349 
350  // Handle the -pi/pi boundary: volumes crossing it could be half at the begin and half at end of the sorted list.
351  // So, check if any of the volumes that should belong to the first bin (at -phi) are at the end of the list:
352  float lastBinPhi = phiClust.back();
353  handles::reverse_iterator ri = eVolumes.rbegin();
354  while ((*ri)->center().phi()>lastBinPhi) {++ri;}
355  if (ri!=eVolumes.rbegin()) {
356  // ri points to the first element that is within the last bin.
357  // We need to move the following element (ie ri.base()) to the beginning of the list,
358  handles::iterator newbeg = ri.base();
359  rotate(eVolumes.begin(),newbeg, eVolumes.end());
360  }
361 
362  //Group volumes in sectors
363  int offset = eVolumes.size()/nESectors;
364  for (int i = 0; i<nESectors; ++i) {
365  if (debug) {
366  cout << " Sector at phi = "
367  << (*(eVolumes.begin()+((i)*offset)))->center().phi()
368  << endl;
369  // Additional x-check: sectors are expected to be made by volumes with the same copyno
370  int secCopyNo = -1;
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;
374  }
375  }
376 
377  sectors.push_back(eSector(eVolumes.begin()+((i)*offset),
378  eVolumes.begin()+((i+1)*offset)));
379  }
380 
381  if (debug) cout << "Endcap: Found "
382  << sectors.size() << " sectors " << endl;
383 
384 
385  //----------------------------------------------------------------------
386  // Match surfaces.
387 
388 // cout << "------------------" << endl << "Now associating planes..." << endl;
389 
390 // // Loop on layers
391 // for (vector<bLayer>::const_iterator ilay = layers.begin();
392 // ilay!= layers.end(); ++ilay) {
393 // cout << "On Layer: " << ilay-layers.begin() << " RN: " << (*ilay).RN()
394 // <<endl;
395 
396 // // Loop on wheels
397 // for (vector<bWheel>::const_iterator iwheel = (*ilay).wheels.begin();
398 // iwheel != (*ilay).wheels.end(); ++iwheel) {
399 // cout << " On Wheel: " << iwheel- (*ilay).wheels.begin()<< " Z: "
400 // << (*iwheel).minZ() << " " << (*iwheel).maxZ() << " "
401 // << ((*iwheel).minZ()+(*iwheel).maxZ())/2. <<endl;
402 
403 // // Loop on sectors.
404 // for (int isector = 0; isector<12; ++isector) {
405 // // FIXME: create new constructor...
406 // bSectorNavigator navy(layers,
407 // ilay-layers.begin(),
408 // iwheel-(*ilay).wheels.begin(),isector);
409 
410 // const bSector & isect = (*iwheel).sector(isector);
411 
412 // isect.matchPlanes(navy); //FIXME refcount
413 // }
414 // }
415 // }
416 
417 
418  //----------------------------------------------------------------------
419  // Build MagVolumes and the MagGeometry hierarchy.
420 
421  //--- Barrel
422 
423  // Build MagVolumes and associate interpolators to them
424  buildMagVolumes(bVolumes, bInterpolators);
425 
426  // Build MagBLayers
427  for (vector<bLayer>::const_iterator ilay = layers.begin();
428  ilay!= layers.end(); ++ilay) {
429  mBLayers.push_back((*ilay).buildMagBLayer());
430  }
431 
432  if (debug) {
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;
437 
438  testInside(bVolumes); // FIXME: all volumes should be checked in one go.
439  }
440 
441  //--- Endcap
442  // Build MagVolumes and associate interpolators to them
443  buildMagVolumes(eVolumes, eInterpolators);
444 
445  // Build the MagESectors
446  for (vector<eSector>::const_iterator isec = sectors.begin();
447  isec!= sectors.end(); ++isec) {
448  mESectors.push_back((*isec).buildMagESector());
449  }
450 
451  if (debug) {
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;
456 
457  testInside(eVolumes); // FIXME: all volumes should be checked in one go.
458  }
459 }
std::vector< MagBLayer * > mBLayers
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
constexpr float ftwoPi()
Definition: Pi.h:36
static HepMC::IO_HEPEVT conv
constexpr float fpi()
Definition: Pi.h:35
void summary(handles &volumes)
void testInside(handles &volumes)
double f[11][100]
const magneticfield::TableFileMap * theGridFiles
void buildInterpolator(const volumeHandle *vol, std::map< std::string, MagProviderInterpol * > &interpolators)
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
std::vector< MagESector * > mESectors
Provides an exploded view of the detector (tree-view)
void buildMagVolumes(const handles &volumes, std::map< std::string, MagProviderInterpol * > &interpolators)
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:704
void MagGeoBuilderFromDDD::buildInterpolator ( const volumeHandle vol,
std::map< std::string, MagProviderInterpol * > &  interpolators 
)
private

Definition at line 510 of file MagGeoBuilderFromDDD.cc.

References MFGridFactory::build(), MagGeoBuilderFromDDD::volumeHandle::center(), MessageLogger_cfi::cerr, MagGeoBuilderFromDDD::volumeHandle::copyno, gather_cfg::cout, Dimensions::d, debug, edm::FileInPath::fullPath(), runTauDisplay::gp, listHistos::grid, Dimensions::h, mps_fire::i, gen::k, MagGeoBuilderFromDDD::volumeHandle::magFile, MagGeoBuilderFromDDD::volumeHandle::masterSector, PV3DBase< T, PVType, FrameType >::phi(), Geom::pi(), MagGeoBuilderFromDDD::volumeHandle::placement(), GloballyPositioned< T >::position(), makeMuonMisalignmentScenario::rot, GloballyPositioned< T >::rotation(), MagGeoBuilderFromDDD::volumeHandle::shape(), MagGeoBuilderFromDDD::volumeHandle::sides(), tableSet, MagGeoBuilderFromDDD::volumeHandle::toExpand(), RecoTauCleanerPlugins::tolerance, MagGeoBuilderFromDDD::volumeHandle::volumeno, Dimensions::w, MagException::what(), and cms::Exception::what().

Referenced by build().

510  {
511 
512  // Phi of the master sector
513  double masterSectorPhi = (vol->masterSector-1)*Geom::pi()/6.;
514 
515  if (debug) {
516  cout << "Building interpolator from "
517  << vol->volumeno << " copyno " << vol->copyno
518  << " at " << vol->center()
519  << " phi: " << vol->center().phi()
520  << " file: " << vol->magFile
521  << " master : " << vol->masterSector
522  << endl;
523 
524  if ( fabs(vol->center().phi() - masterSectorPhi) > Geom::pi()/9.) {
525  cout << "***WARNING wrong sector? " << endl;
526  }
527  }
528 
529  if (tableSet == "fake" || vol->magFile== "fake") {
530  interpolators[vol->magFile] = new magneticfield::FakeInterpolator();
531  return;
532  }
533 
534  string fullPath;
535 
536  try {
537  edm::FileInPath mydata("MagneticField/Interpolation/data/"+tableSet+"/"+vol->magFile);
538  fullPath = mydata.fullPath();
539  } catch (edm::Exception& exc) {
540  cerr << "MagGeoBuilderFromDDD: exception in reading table; " << exc.what() << endl;
541  if (!debug) throw;
542  return;
543  }
544 
545 
546  try{
547  if (vol->toExpand()){
548  //FIXME: see discussion on mergeCylinders above.
549 // interpolators[vol->magFile] =
550 // MFGridFactory::build( fullPath, *(vol->placement()), vol->minPhi(), vol->maxPhi());
551  } else {
552  // If the table is in "local" coordinates, must create a reference
553  // frame that is appropriately rotated along the CMS Z axis.
554 
555  GloballyPositioned<float> rf = *(vol->placement());
556 
557  if (vol->masterSector != 1) {
559 
560  GloballyPositioned<float>::RotationType rot(Vector(0,0,1), -masterSectorPhi);
561  Vector vpos(vol->placement()->position());
562 
563 
564  rf = GloballyPositioned<float>(GloballyPositioned<float>::PositionType(rot.multiplyInverse(vpos)), vol->placement()->rotation()*rot);
565  }
566 
567  interpolators[vol->magFile] =
568  MFGridFactory::build( fullPath, rf);
569  }
570  } catch (MagException& exc) {
571  cout << exc.what() << endl;
572  interpolators.erase(vol->magFile);
573  if (!debug) throw;
574  return;
575  }
576 
577 
578  if (debug) {
579  // Check that all grid points of the interpolator are inside the volume.
580  const MagVolume6Faces tempVolume(vol->placement()->position(),
581  vol->placement()->rotation(),
582  vol->shape(),
583  vol->sides(),
584  interpolators[vol->magFile]);
585 
586  const MFGrid* grid = dynamic_cast<const MFGrid*>(interpolators[vol->magFile]);
587  if (grid!=nullptr) {
588 
589  Dimensions sizes = grid->dimensions();
590  cout << "Grid has 3 dimensions "
591  << " number of nodes is " << sizes.w << " " << sizes.h
592  << " " << sizes.d << endl;
593 
594  const double tolerance = 0.03;
595 
596 
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++) {
601  MFGrid::LocalPoint lp = grid->nodePosition( i, j, k);
602  if (! tempVolume.inside(lp, tolerance)) {
603  if (++dumpCount < 2) {
604  MFGrid::GlobalPoint gp = tempVolume.toGlobal(lp);
605  cout << "GRID ERROR: " << i << " " << j << " " << k
606  << " local: " << lp
607  << " global: " << gp
608  << " R= " << gp.perp() << " phi=" << gp.phi() << endl;
609  }
610  }
611  }
612  }
613  }
614 
615  cout << "Volume:" << vol->volumeno << " : Number of grid points outside the MagVolume: " << dumpCount << "/" << sizes.w*sizes.h*sizes.d << endl;
616  }
617  }
618 }
const char * what() const override
Definition: MagExceptions.cc:6
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
GloballyPositioned< float >::LocalPoint LocalPoint
Definition: MFGrid.h:34
char const * what() const override
Definition: Exception.cc:141
int w
Definition: MFGrid.h:17
static MFGrid * build(const std::string &name, const GloballyPositioned< float > &vol)
Build interpolator for a binary grid file.
int k[5][pyjets_maxn]
GloballyPositioned< float >::GlobalPoint GlobalPoint
Definition: MFGrid.h:32
Definition: MFGrid.h:29
int d
Definition: MFGrid.h:19
int h
Definition: MFGrid.h:18
Point3DBase< T, GlobalTag > PositionType
constexpr double pi()
Definition: Pi.h:31
void MagGeoBuilderFromDDD::buildMagVolumes ( const handles volumes,
std::map< std::string, MagProviderInterpol * > &  interpolators 
)
private

Definition at line 462 of file MagGeoBuilderFromDDD.cc.

References crabWrapper::key, MagVolume::ownsFieldProvider(), GloballyPositioned< T >::position(), GloballyPositioned< T >::rotation(), and theScalingFactors.

Referenced by build().

462  {
463  // Build all MagVolumes setting the MagProviderInterpol
464  for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
465  ++vol){
466  const MagProviderInterpol* mp = nullptr;
467  if (interpolators.find((*vol)->magFile)!=interpolators.end()) {
468  mp = interpolators[(*vol)->magFile];
469  } else {
470  edm::LogError("MagGeoBuilderFromDDDbuildMagVolumes") << "No interpolator found for file " << (*vol)->magFile
471  << " vol: " << (*vol)->volumeno << "\n" << interpolators.size() <<endl;
472  }
473 
474  // Search for [volume,sector] in the list of scaling factors; sector = 0 handled as wildcard
475  // ASSUMPTION: copyno == sector.
476  int key = ((*vol)->volumeno)*100+(*vol)->copyno;
477  map<int, double>::const_iterator isf = theScalingFactors.find(key);
478  if (isf == theScalingFactors.end()) {
479  key = ((*vol)->volumeno)*100;
480  isf = theScalingFactors.find(key);
481  }
482 
483  double sf = 1.;
484  if (isf != theScalingFactors.end()) {
485  sf = (*isf).second;
486 
487  edm::LogInfo("MagneticField|VolumeBasedMagneticFieldESProducer") << "Applying scaling factor " << sf << " to "<< (*vol)->volumeno << "["<< (*vol)->copyno << "] (key:" << key << ")" << endl;
488  }
489 
490  const GloballyPositioned<float> * gpos = (*vol)->placement();
491  (*vol)->magVolume = new MagVolume6Faces(gpos->position(),
492  gpos->rotation(),
493  (*vol)->shape(),
494  (*vol)->sides(),
495  mp, sf);
496 
497  if ((*vol)->copyno==(*vol)->masterSector) {
498  (*vol)->magVolume->ownsFieldProvider(true);
499  }
500 
501  (*vol)->magVolume->setIsIron((*vol)->isIron());
502 
503  // The name and sector of the volume are saved for debug purposes only. They may be removed at some point...
504  (*vol)->magVolume->volumeNo = (*vol)->volumeno;
505  (*vol)->magVolume->copyno = (*vol)->copyno;
506  }
507 }
const RotationType & rotation() const
const PositionType & position() const
std::map< int, double > theScalingFactors
void ownsFieldProvider(bool o)
Definition: MagVolume.h:53
vector< MagESector * > MagGeoBuilderFromDDD::endcapSectors ( ) const

Get endcap layers.

Definition at line 653 of file MagGeoBuilderFromDDD.cc.

References mESectors.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

653  {
654  return mESectors;
655 }
std::vector< MagESector * > mESectors
vector< MagVolume6Faces * > MagGeoBuilderFromDDD::endcapVolumes ( ) const
private

Definition at line 667 of file MagGeoBuilderFromDDD.cc.

References eVolumes, mps_fire::i, and findQualityFiles::v.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

667  {
668  vector<MagVolume6Faces*> v;
669  v.reserve(eVolumes.size());
670  for (handles::const_iterator i=eVolumes.begin();
671  i!=eVolumes.end(); ++i){
672  v.push_back((*i)->magVolume);
673  }
674  return v;
675 }
float MagGeoBuilderFromDDD::maxR ( ) const

Definition at line 678 of file MagGeoBuilderFromDDD.cc.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

678  {
679  //FIXME: should get it from the actual geometry
680  return 900.;
681 }
float MagGeoBuilderFromDDD::maxZ ( ) const

Definition at line 683 of file MagGeoBuilderFromDDD.cc.

References geometryVersion.

Referenced by MagGeoBuilderFromDDD::bSector::bSector(), magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

683  {
684  //FIXME: should get it from the actual geometry
685  if (geometryVersion>=160812) return 2400.;
686  else if (geometryVersion>=120812) return 2000.;
687  else return 1600.;
688 }
void MagGeoBuilderFromDDD::setGridFiles ( const magneticfield::TableFileMap gridFiles)

Definition at line 703 of file MagGeoBuilderFromDDD.cc.

References theGridFiles.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

703  {
704  theGridFiles=&gridFiles;
705 }
const magneticfield::TableFileMap * theGridFiles
void MagGeoBuilderFromDDD::setScaling ( const std::vector< int > &  keys,
const std::vector< double > &  values 
)

Set scaling factors for individual volumes. "keys" is a vector of 100*volume number + sector (sector 0 = all sectors) "values" are the corresponding scaling factors

Definition at line 691 of file MagGeoBuilderFromDDD.cc.

References Exception, mps_fire::i, and theScalingFactors.

Referenced by magneticfield::VolumeBasedMagneticFieldESProducer::produce(), and magneticfield::VolumeBasedMagneticFieldESProducerFromDB::produce().

693 {
694  if (keys.size() != values.size()) {
695  throw cms::Exception("InvalidParameter") << "Invalid field scaling parameters 'scalingVolumes' and 'scalingFactors' ";
696  }
697  for (unsigned int i=0; i<keys.size(); ++i) {
699  }
700 }
std::map< int, double > theScalingFactors
void MagGeoBuilderFromDDD::summary ( handles volumes)
private

Definition at line 83 of file MagGeoBuilderFromDDD.cc.

References gather_cfg::cout, plotBeamSpotDB::first, mps_fire::i, plotBeamSpotDB::last, and edm::second().

Referenced by build().

83  {
84  // The final countdown.
85  int ivolumes = volumes.size(); // number of volumes
86  int isurfaces = ivolumes*6; // number of individual surfaces
87  int iassigned = 0; // How many have been assigned
88  int iunique = 0; // number of unique surfaces
89  int iref_ass = 0;
90  int iref_nass = 0;
91 
92  set<const void *> ptrs;
93 
94  handles::const_iterator first = volumes.begin();
95  handles::const_iterator last = volumes.end();
96 
97  for (handles::const_iterator i=first; i!=last; ++i){
98  if (int((*i)->shape())>4) continue; // FIXME: implement test for missing shapes...
99  for (int side = 0; side < 6; ++side) {
100  int references = (*i)->references(side);
101  if ((*i)->isPlaneMatched(side)) {
102  ++iassigned;
103  bool firstOcc = (ptrs.insert(&((*i)->surface(side)))).second;
104  if (firstOcc) iref_ass+=references;
105  if (references<2){
106  cout << "*** Only 1 ref, vol: " << (*i)->volumeno << " # "
107  << (*i)->copyno << " side: " << side << endl;
108  }
109  } else {
110  iref_nass+=references;
111  if (references>1){
112  cout << "*** Ref_nass >1 " <<endl;
113  }
114  }
115  }
116  }
117  iunique = ptrs.size();
118 
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;
125 }
U second(std::pair< T, U > const &p)
void MagGeoBuilderFromDDD::testInside ( handles volumes)
private

Definition at line 622 of file MagGeoBuilderFromDDD.cc.

References gather_cfg::cout, and mps_fire::i.

Referenced by build().

622  {
623  // test inside() for all volumes.
624  cout << "--------------------------------------------------" << endl;
625  cout << " inside(center) test" << endl;
626  for (handles::const_iterator vol=volumes.begin(); vol!=volumes.end();
627  ++vol){
628  for (handles::const_iterator i=volumes.begin(); i!=volumes.end();
629  ++i){
630  if ((*i)==(*vol)) continue;
631  //if ((*i)->magVolume == 0) 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;
635  }
636  }
637 
638  if ((*vol)->magVolume->inside((*vol)->center())) {
639  cout << "V " << (*vol)->volumeno << " OK " << endl;
640  } else {
641  cout << "*** ERROR: center of volume is not inside it, "
642  << (*vol)->volumeno << endl;
643  }
644  }
645  cout << "--------------------------------------------------" << endl;
646 }

Friends And Related Function Documentation

friend class MagGeometry
friend

Definition at line 68 of file MagGeoBuilderFromDDD.h.

Definition at line 71 of file MagGeoBuilderFromDDD.h.

Definition at line 69 of file MagGeoBuilderFromDDD.h.

Definition at line 70 of file MagGeoBuilderFromDDD.h.

friend class TestMagVolume
friend

Definition at line 67 of file MagGeoBuilderFromDDD.h.

Member Data Documentation

handles MagGeoBuilderFromDDD::bVolumes
private

Definition at line 119 of file MagGeoBuilderFromDDD.h.

Referenced by barrelVolumes(), build(), and ~MagGeoBuilderFromDDD().

bool MagGeoBuilderFromDDD::debug
staticprivate
handles MagGeoBuilderFromDDD::eVolumes
private

Definition at line 122 of file MagGeoBuilderFromDDD.h.

Referenced by build(), endcapVolumes(), and ~MagGeoBuilderFromDDD().

int MagGeoBuilderFromDDD::geometryVersion
private

Definition at line 128 of file MagGeoBuilderFromDDD.h.

Referenced by maxZ().

std::vector<MagBLayer*> MagGeoBuilderFromDDD::mBLayers
private

Definition at line 124 of file MagGeoBuilderFromDDD.h.

Referenced by barrelLayers(), and build().

std::vector<MagESector*> MagGeoBuilderFromDDD::mESectors
private

Definition at line 125 of file MagGeoBuilderFromDDD.h.

Referenced by build(), and endcapSectors().

std::string MagGeoBuilderFromDDD::tableSet
private

Definition at line 127 of file MagGeoBuilderFromDDD.h.

Referenced by buildInterpolator().

const magneticfield::TableFileMap* MagGeoBuilderFromDDD::theGridFiles
private

Definition at line 131 of file MagGeoBuilderFromDDD.h.

Referenced by build(), and setGridFiles().

std::map<int, double> MagGeoBuilderFromDDD::theScalingFactors
private

Definition at line 130 of file MagGeoBuilderFromDDD.h.

Referenced by buildMagVolumes(), and setScaling().