CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends
MagGeoBuilderFromDDD Class Reference

#include <MagGeoBuilderFromDDD.h>

Classes

class  bRod
 
class  bSlab
 
class  eLayer
 
class  eSector
 
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 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 magneticfield::handles &volumes, std::map< std::string, MagProviderInterpol * > &interpolators)
 
std::vector< MagVolume6Faces * > endcapVolumes () const
 
void summary (magneticfield::handles &volumes)
 
void testInside (magneticfield::handles &volumes)
 

Private Attributes

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

Friends

class MagGeometry
 
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 32 of file MagGeoBuilderFromDDD.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 56 of file MagGeoBuilderFromDDD.cc.

References gather_cfg::cout, and debug.

57  : tableSet(tableSet_), geometryVersion(geometryVersion_), theGridFiles(nullptr), debug(debug_) {
58  if (debug)
59  cout << "Constructing a MagGeoBuilderFromDDD" << endl;
60 }
const magneticfield::TableFileMap * theGridFiles
tuple cout
Definition: gather_cfg.py:144
MagGeoBuilderFromDDD::~MagGeoBuilderFromDDD ( )
virtual

Destructor.

Definition at line 62 of file MagGeoBuilderFromDDD.cc.

References bVolumes, eVolumes, and mps_fire::i.

62  {
63  for (handles::const_iterator i = bVolumes.begin(); i != bVolumes.end(); ++i) {
64  delete (*i);
65  }
66 
67  for (handles::const_iterator i = eVolumes.begin(); i != eVolumes.end(); ++i) {
68  delete (*i);
69  }
70 }
magneticfield::handles eVolumes
magneticfield::handles bVolumes

Member Function Documentation

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

Get barrel layers.

Definition at line 621 of file MagGeoBuilderFromDDD.cc.

References mBLayers.

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

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

Definition at line 625 of file MagGeoBuilderFromDDD.cc.

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

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

625  {
626  vector<MagVolume6Faces*> v;
627  v.reserve(bVolumes.size());
628  for (handles::const_iterator i = bVolumes.begin(); i != bVolumes.end(); ++i) {
629  v.push_back((*i)->magVolume);
630  }
631  return v;
632 }
magneticfield::handles bVolumes
void MagGeoBuilderFromDDD::build ( const DDCompactView cpv)
privatevirtual

Definition at line 117 of file MagGeoBuilderFromDDD.cc.

References buildInterpolator(), buildMagVolumes(), bVolumes, magneticfield::BaseVolumeHandle::center(), ClusterizingHistogram::clusterize(), conv, magneticfield::BaseVolumeHandle::copyno, gather_cfg::cout, debug, eVolumes, Exception, validate-o2o-wbm::f, ClusterizingHistogram::fill(), first, DDExpandedView::firstChild(), Geom::fpi(), Geom::ftwoPi(), DDExpandedView::geoHistory(), mps_fire::i, gpuVertexFinder::iv, submitPVResolutionJobs::key, dqmdumpme::last, LayerTriplets::layers(), DDExpandedView::logicalPart(), magneticfield::BaseVolumeHandle::magFile, magneticfield::BaseVolumeHandle::masterSector, mBLayers, mESectors, DDName::name(), DDBase< N, C >::name(), mergeVDriftHistosByStation::name, DDExpandedView::nextSibling(), hltrates_dqm_sourceclient-live_cfg::offset, PV3DBase< T, PVType, FrameType >::perp(), precomputed_value_sort(), dttmaxenums::R, dtDQMClient_cfg::resolution, svgfig::rotate(), DDExpandedView::rotation(), mergeVDriftHistosByStation::sectors, AlCaHLTBitMon_QueryRunRegistry::string, summary(), testInside(), theGridFiles, DDExpandedView::translation(), findQualityFiles::v, magneticfield::BaseVolumeHandle::volumeno, BeamSpotPI::Z, and PV3DBase< T, PVType, FrameType >::z().

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

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

Definition at line 500 of file MagGeoBuilderFromDDD.cc.

References MFGridFactory::build(), magneticfield::BaseVolumeHandle::center(), EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, magneticfield::BaseVolumeHandle::copyno, gather_cfg::cout, Dimensions::d, debug, contentValuesFiles::fullPath, edm::FileInPath::fullPath(), runTauDisplay::gp, getRunAppsInfo::grid, Dimensions::h, mps_fire::i, dqmiolumiharvest::j, isotrackApplyRegressor::k, magneticfield::BaseVolumeHandle::magFile, magneticfield::BaseVolumeHandle::masterSector, PV3DBase< T, PVType, FrameType >::phi(), Geom::pi(), magneticfield::BaseVolumeHandle::placement(), GloballyPositioned< T >::position(), hcal_runs::rf, makeMuonMisalignmentScenario::rot, GloballyPositioned< T >::rotation(), MagGeoBuilderFromDDD::volumeHandle::sides(), tableSet, magneticfield::BaseVolumeHandle::toExpand(), tolerance, magneticfield::BaseVolumeHandle::volumeno, Dimensions::w, MagException::what(), and cms::Exception::what().

Referenced by build().

501  {
502  // Phi of the master sector
503  double masterSectorPhi = (vol->masterSector - 1) * Geom::pi() / 6.;
504 
505  if (debug) {
506  cout << "Building interpolator from " << vol->volumeno << " copyno " << vol->copyno << " at " << vol->center()
507  << " phi: " << vol->center().phi() << " file: " << vol->magFile << " master : " << vol->masterSector << endl;
508 
509  if (fabs(vol->center().phi() - masterSectorPhi) > Geom::pi() / 9.) {
510  cout << "***WARNING wrong sector? " << endl;
511  }
512  }
513 
514  if (tableSet == "fake" || vol->magFile == "fake") {
515  interpolators[vol->magFile] = new magneticfield::FakeInterpolator();
516  return;
517  }
518 
519  string fullPath;
520 
521  try {
522  edm::FileInPath mydata("MagneticField/Interpolation/data/" + tableSet + "/" + vol->magFile);
523  fullPath = mydata.fullPath();
524  } catch (edm::Exception& exc) {
525  cerr << "MagGeoBuilderFromDDD: exception in reading table; " << exc.what() << endl;
526  if (!debug)
527  throw;
528  return;
529  }
530 
531  try {
532  if (vol->toExpand()) {
533  //FIXME: see discussion on mergeCylinders above.
534  // interpolators[vol->magFile] =
535  // MFGridFactory::build( fullPath, *(vol->placement()), vol->minPhi(), vol->maxPhi());
536  } else {
537  // If the table is in "local" coordinates, must create a reference
538  // frame that is appropriately rotated along the CMS Z axis.
539 
541 
542  if (vol->masterSector != 1) {
544 
545  GloballyPositioned<float>::RotationType rot(Vector(0, 0, 1), -masterSectorPhi);
546  Vector vpos(vol->placement()->position());
547 
549  vol->placement()->rotation() * rot);
550  }
551 
552  interpolators[vol->magFile] = MFGridFactory::build(fullPath, rf);
553  }
554  } catch (MagException& exc) {
555  cout << exc.what() << endl;
556  interpolators.erase(vol->magFile);
557  if (!debug)
558  throw;
559  return;
560  }
561 
562  if (debug) {
563  // Check that all grid points of the interpolator are inside the volume.
564  const MagVolume6Faces tempVolume(
565  vol->placement()->position(), vol->placement()->rotation(), vol->sides(), interpolators[vol->magFile]);
566 
567  const MFGrid* grid = dynamic_cast<const MFGrid*>(interpolators[vol->magFile]);
568  if (grid != nullptr) {
569  Dimensions sizes = grid->dimensions();
570  cout << "Grid has 3 dimensions "
571  << " number of nodes is " << sizes.w << " " << sizes.h << " " << sizes.d << endl;
572 
573  const double tolerance = 0.03;
574 
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++) {
579  MFGrid::LocalPoint lp = grid->nodePosition(i, j, k);
580  if (!tempVolume.inside(lp, tolerance)) {
581  if (++dumpCount < 2) {
582  MFGrid::GlobalPoint gp = tempVolume.toGlobal(lp);
583  cout << "GRID ERROR: " << i << " " << j << " " << k << " local: " << lp << " global: " << gp
584  << " R= " << gp.perp() << " phi=" << gp.phi() << endl;
585  }
586  }
587  }
588  }
589  }
590 
591  cout << "Volume:" << vol->volumeno << " : Number of grid points outside the MagVolume: " << dumpCount << "/"
592  << sizes.w * sizes.h * sizes.d << endl;
593  }
594  }
595 }
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
const double tolerance
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
GloballyPositioned< float >::LocalPoint LocalPoint
Definition: MFGrid.h:31
unsigned short volumeno
volume number
int w
Definition: MFGrid.h:16
unsigned short copyno
copy number
list rf
Definition: hcal_runs.py:75
const char * what() const override
Definition: MagExceptions.cc:5
char const * what() const noexceptoverride
Definition: Exception.cc:103
int masterSector
The sector for which an interpolator for this class of volumes should be built.
static MFGrid * build(const std::string &name, const GloballyPositioned< float > &vol)
Build interpolator for a binary grid file.
Point3DBase< T, GlobalTag > PositionType
const GlobalPoint & center() const
Return the center of the volume.
GloballyPositioned< float >::GlobalPoint GlobalPoint
Definition: MFGrid.h:29
Definition: MFGrid.h:27
int d
Definition: MFGrid.h:18
int h
Definition: MFGrid.h:17
const GloballyPositioned< float > * placement() const
Position and rotation.
std::vector< VolumeSide > sides() const override
The surfaces and they orientation, as required to build a MagVolume.
const RotationType & rotation() const
tuple cout
Definition: gather_cfg.py:144
constexpr double pi()
Definition: Pi.h:31
const PositionType & position() const
std::string magFile
Name of magnetic field table file.
void MagGeoBuilderFromDDD::buildMagVolumes ( const magneticfield::handles volumes,
std::map< std::string, MagProviderInterpol * > &  interpolators 
)
private

Definition at line 456 of file MagGeoBuilderFromDDD.cc.

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

Referenced by build().

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

Get endcap layers.

Definition at line 623 of file MagGeoBuilderFromDDD.cc.

References mESectors.

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

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

Definition at line 634 of file MagGeoBuilderFromDDD.cc.

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

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

634  {
635  vector<MagVolume6Faces*> v;
636  v.reserve(eVolumes.size());
637  for (handles::const_iterator i = eVolumes.begin(); i != eVolumes.end(); ++i) {
638  v.push_back((*i)->magVolume);
639  }
640  return v;
641 }
magneticfield::handles eVolumes
float MagGeoBuilderFromDDD::maxR ( ) const

Definition at line 643 of file MagGeoBuilderFromDDD.cc.

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

643  {
644  //FIXME: should get it from the actual geometry
645  return 900.;
646 }
float MagGeoBuilderFromDDD::maxZ ( ) const

Definition at line 648 of file MagGeoBuilderFromDDD.cc.

References geometryVersion.

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

648  {
649  //FIXME: should get it from the actual geometry
650  if (geometryVersion >= 160812)
651  return 2400.;
652  else if (geometryVersion >= 120812)
653  return 2000.;
654  else
655  return 1600.;
656 }
void MagGeoBuilderFromDDD::setGridFiles ( const magneticfield::TableFileMap gridFiles)
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 658 of file MagGeoBuilderFromDDD.cc.

References Exception, mps_fire::i, and theScalingFactors.

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

658  {
659  if (keys.size() != values.size()) {
660  throw cms::Exception("InvalidParameter")
661  << "Invalid field scaling parameters 'scalingVolumes' and 'scalingFactors' ";
662  }
663  for (unsigned int i = 0; i < keys.size(); ++i) {
665  }
666 }
std::map< int, double > theScalingFactors
void MagGeoBuilderFromDDD::summary ( magneticfield::handles volumes)
private

Definition at line 72 of file MagGeoBuilderFromDDD.cc.

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

Referenced by build().

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

Definition at line 597 of file MagGeoBuilderFromDDD.cc.

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

Referenced by build().

597  {
598  // test inside() for all volumes.
599  cout << "--------------------------------------------------" << endl;
600  cout << " inside(center) test" << endl;
601  for (handles::const_iterator vol = volumes.begin(); vol != volumes.end(); ++vol) {
602  for (handles::const_iterator i = volumes.begin(); i != volumes.end(); ++i) {
603  if ((*i) == (*vol))
604  continue;
605  //if ((*i)->magVolume == 0) continue;
606  if ((*i)->magVolume->inside((*vol)->center())) {
607  cout << "*** ERROR: center of V " << (*vol)->volumeno << ":" << (*vol)->copyno << " is inside V "
608  << (*i)->volumeno << ":" << (*i)->copyno << endl;
609  }
610  }
611 
612  if ((*vol)->magVolume->inside((*vol)->center())) {
613  cout << "V " << (*vol)->volumeno << " OK " << endl;
614  } else {
615  cout << "*** ERROR: center of volume is not inside it, " << (*vol)->volumeno << endl;
616  }
617  }
618  cout << "--------------------------------------------------" << endl;
619 }
tuple cout
Definition: gather_cfg.py:144

Friends And Related Function Documentation

friend class MagGeometry
friend

Definition at line 67 of file MagGeoBuilderFromDDD.h.

Definition at line 68 of file MagGeoBuilderFromDDD.h.

Definition at line 69 of file MagGeoBuilderFromDDD.h.

friend class TestMagVolume
friend

Definition at line 66 of file MagGeoBuilderFromDDD.h.

Member Data Documentation

magneticfield::handles MagGeoBuilderFromDDD::bVolumes
private

Definition at line 87 of file MagGeoBuilderFromDDD.h.

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

const bool MagGeoBuilderFromDDD::debug
private
magneticfield::handles MagGeoBuilderFromDDD::eVolumes
private

Definition at line 88 of file MagGeoBuilderFromDDD.h.

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

int MagGeoBuilderFromDDD::geometryVersion
private

Definition at line 94 of file MagGeoBuilderFromDDD.h.

Referenced by maxZ().

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

Definition at line 90 of file MagGeoBuilderFromDDD.h.

Referenced by barrelLayers(), and build().

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

Definition at line 91 of file MagGeoBuilderFromDDD.h.

Referenced by build(), and endcapSectors().

std::string MagGeoBuilderFromDDD::tableSet
private

Definition at line 93 of file MagGeoBuilderFromDDD.h.

Referenced by buildInterpolator().

const magneticfield::TableFileMap* MagGeoBuilderFromDDD::theGridFiles
private

Definition at line 97 of file MagGeoBuilderFromDDD.h.

Referenced by build(), and setGridFiles().

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

Definition at line 96 of file MagGeoBuilderFromDDD.h.

Referenced by buildMagVolumes(), and setScaling().