Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:25

0001 // #include "Utilities/Configuration/interface/Architecture.h"
0002 
0003 /*
0004  *  See header file for a description of this class.
0005  *
0006  *  \author N. Amapane - INFN Torino
0007  */
0008 
0009 #include "MagneticField/Layers/interface/MagBLayer.h"
0010 #include "MagneticField/Layers/interface/MagBSector.h"
0011 #include "MagneticField/VolumeGeometry/interface/MagVolume.h"
0012 #include "Utilities/BinningTools/interface/PeriodicBinFinderInPhi.h"
0013 #include "DataFormats/GeometryVector/interface/Phi.h"
0014 
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 
0017 #include <iostream>
0018 
0019 using namespace std;
0020 
0021 MagBLayer::MagBLayer(vector<MagBSector*>& sectors, double rMin)
0022     : theSectors(sectors), theSingleVolume(nullptr), theRMin(rMin), theBinFinder(nullptr) {
0023   //   LogTrace("MagGeometry") << "Building MagBLayer with " << theSectors.size()
0024   //          << " sectors, minR " << theRMin << endl;
0025   //FIXME: PeriodicBinFinderInPhi gets *center* of first bin
0026   theBinFinder = new PeriodicBinFinderInPhi<float>(theSectors.front()->minPhi() + Geom::pi() / 12., 12);
0027 }
0028 
0029 /// Constructor for a trivial layer consisting of one single volume.
0030 MagBLayer::MagBLayer(MagVolume* aVolume, double rMin) : theSingleVolume(nullptr), theRMin(rMin), theBinFinder(nullptr) {
0031   //   LogTrace("MagGeometry") << "Building MagBLayer with " << 0
0032   //          << " sectors, minR " << theRMin << endl;
0033 }
0034 
0035 MagBLayer::~MagBLayer() {
0036   delete theBinFinder;
0037 
0038   delete theSingleVolume;
0039 
0040   for (vector<MagBSector*>::const_iterator isec = theSectors.begin(); isec != theSectors.end(); ++isec) {
0041     delete (*isec);
0042   }
0043 }
0044 
0045 const MagVolume* MagBLayer::findVolume(const GlobalPoint& gp, double tolerance) const {
0046   const MagVolume* result = nullptr;
0047 
0048   //In case the layer is composed of a single volume...
0049   if (theSingleVolume) {
0050     //    LogTrace("MagGeometry") << "   Trying the unique volume " << endl;
0051     if (theSingleVolume->inside(gp, tolerance)) {
0052       result = theSingleVolume;
0053       //       LogTrace("MagGeometry") << "***In unique bsector"
0054       //          << (result==0? " failed " : " OK ") <<endl;
0055     }
0056     return result;
0057   }
0058 
0059   // Normal cases - query the sectors.
0060 
0061   Geom::Phi<float> phi = gp.phi();
0062 
0063   // FIXME assume sectors are sorted in phi!
0064   int bin = theBinFinder->binIndex(phi);
0065   LogTrace("MagGeometry") << "   Trying sector at phi " << theSectors[bin]->minPhi() << " " << phi << endl;
0066   result = theSectors[bin]->findVolume(gp, tolerance);
0067   LogTrace("MagGeometry") << "***In guessed bsector" << (result == nullptr ? " failed " : " OK ") << endl;
0068 
0069   if (result == nullptr) {  // If fails, can be in previous bin.
0070     LogTrace("MagGeometry") << "   Trying sector at phi " << theSectors[theBinFinder->binIndex(bin - 1)]->minPhi()
0071                             << " " << phi << endl;
0072 
0073     result = theSectors[theBinFinder->binIndex(bin - 1)]->findVolume(gp, tolerance);
0074     LogTrace("MagGeometry") << "***In previous bsector" << (result == nullptr ? " failed " : " OK ") << endl;
0075   }
0076   return result;
0077 }