CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MagBLayer.cc
Go to the documentation of this file.
1 // #include "Utilities/Configuration/interface/Architecture.h"
2 
3 /*
4  * See header file for a description of this class.
5  *
6  * \author N. Amapane - INFN Torino
7  */
8 
14 
16 
17 #include <iostream>
18 
19 using namespace std;
20 
21 MagBLayer::MagBLayer(vector<MagBSector*>& sectors, double rMin)
22  : theSectors(sectors), theSingleVolume(nullptr), theRMin(rMin), theBinFinder(nullptr) {
23  // LogTrace("MagGeometry") << "Building MagBLayer with " << theSectors.size()
24  // << " sectors, minR " << theRMin << endl;
25  //FIXME: PeriodicBinFinderInPhi gets *center* of first bin
26  theBinFinder = new PeriodicBinFinderInPhi<float>(theSectors.front()->minPhi() + Geom::pi() / 12., 12);
27 }
28 
30 MagBLayer::MagBLayer(MagVolume* aVolume, double rMin) : theSingleVolume(nullptr), theRMin(rMin), theBinFinder(nullptr) {
31  // LogTrace("MagGeometry") << "Building MagBLayer with " << 0
32  // << " sectors, minR " << theRMin << endl;
33 }
34 
36  delete theBinFinder;
37 
38  delete theSingleVolume;
39 
40  for (vector<MagBSector*>::const_iterator isec = theSectors.begin(); isec != theSectors.end(); ++isec) {
41  delete (*isec);
42  }
43 }
44 
45 const MagVolume* MagBLayer::findVolume(const GlobalPoint& gp, double tolerance) const {
46  const MagVolume* result = nullptr;
47 
48  //In case the layer is composed of a single volume...
49  if (theSingleVolume) {
50  // LogTrace("MagGeometry") << " Trying the unique volume " << endl;
51  if (theSingleVolume->inside(gp, tolerance)) {
52  result = theSingleVolume;
53  // LogTrace("MagGeometry") << "***In unique bsector"
54  // << (result==0? " failed " : " OK ") <<endl;
55  }
56  return result;
57  }
58 
59  // Normal cases - query the sectors.
60 
61  Geom::Phi<float> phi = gp.phi();
62 
63  // FIXME assume sectors are sorted in phi!
64  int bin = theBinFinder->binIndex(phi);
65  LogTrace("MagGeometry") << " Trying sector at phi " << theSectors[bin]->minPhi() << " " << phi << endl;
66  result = theSectors[bin]->findVolume(gp, tolerance);
67  LogTrace("MagGeometry") << "***In guessed bsector" << (result == nullptr ? " failed " : " OK ") << endl;
68 
69  if (result == nullptr) { // If fails, can be in previous bin.
70  LogTrace("MagGeometry") << " Trying sector at phi " << theSectors[theBinFinder->binIndex(bin - 1)]->minPhi()
71  << " " << phi << endl;
72 
73  result = theSectors[theBinFinder->binIndex(bin - 1)]->findVolume(gp, tolerance);
74  LogTrace("MagGeometry") << "***In previous bsector" << (result == nullptr ? " failed " : " OK ") << endl;
75  }
76  return result;
77 }
PeriodicBinFinderInPhi< float > * theBinFinder
Definition: MagBLayer.h:49
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
const MagVolume * findVolume(const GlobalPoint &gp, double tolerance) const
Find the volume containing a point, with a given tolerance.
Definition: MagBLayer.cc:45
const double tolerance
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
MagBLayer(std::vector< MagBSector * > &sectors, double rMin)
Constructor.
Definition: MagBLayer.cc:21
#define LogTrace(id)
tuple result
Definition: mps_fire.py:311
virtual bool inside(const GlobalPoint &gp, double tolerance=0.) const =0
std::vector< MagBSector * > theSectors
Definition: MagBLayer.h:45
MagVolume * theSingleVolume
Definition: MagBLayer.h:46
constexpr double pi()
Definition: Pi.h:31
virtual ~MagBLayer()
Destructor.
Definition: MagBLayer.cc:35