CMS 3D CMS Logo

bRod.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author N. Amapane - INFN Torino
5  */
6 
7 #include "bRod.h"
8 #include "printUniqueNames.h"
13 
14 #include <iostream>
15 
16 using namespace SurfaceOrientation;
17 using namespace magneticfield;
18 
19 //The ctor is in charge of finding slabs inside the rod.
20 bRod::bRod(handles::const_iterator begin, handles::const_iterator end, bool debugVal)
21  : volumes(begin, end), mrod(nullptr), debug(debugVal) {
23 
24  // Clusterize in Z
25  const float resolution = 5.; // cm
26  float zmin = volumes.front()->center().z() - resolution;
27  float zmax = volumes.back()->center().z() + resolution;
28  ClusterizingHistogram hisZ(int((zmax - zmin) / resolution) + 1, zmin, zmax);
29 
30  if (debug)
31  std::cout << " Z slabs: " << zmin << " " << zmax << std::endl;
32 
33  handles::const_iterator first = volumes.begin();
34  handles::const_iterator last = volumes.end();
35 
36  for (handles::const_iterator i = first; i != last; ++i) {
37  hisZ.fill((*i)->center().z());
38  }
39  std::vector<float> zClust = hisZ.clusterize(resolution);
40 
41  if (debug)
42  std::cout << " Found " << zClust.size() << " clusters in Z, "
43  << " slabs: " << std::endl;
44 
45  handles::const_iterator slabStart = first;
46  handles::const_iterator separ = first;
47 
48  for (unsigned int i = 0; i < zClust.size() - 1; ++i) {
49  float zSepar = (zClust[i] + zClust[i + 1]) / 2.f;
50  while ((*separ)->center().z() < zSepar)
51  ++separ;
52  if (debug) {
53  std::cout << " Slab at: " << zClust[i] << " elements: " << separ - slabStart << " unique volumes: ";
54  printUniqueNames(slabStart, separ);
55  }
56 
57  slabs.push_back(bSlab(slabStart, separ, debug));
58  slabStart = separ;
59  }
60  {
61  if (debug) {
62  std::cout << " Slab at: " << zClust.back() << " elements: " << last - separ << " unique volumes: ";
63  printUniqueNames(separ, last);
64  }
65  slabs.push_back(bSlab(separ, last, debug));
66  }
67 
68  // Check that all slabs have the same dphi.
69  std::vector<bSlab>::const_iterator i = slabs.begin();
70  Geom::Phi<float> phimax = (*i).maxPhi();
71  Geom::Phi<float> phimin = (*i).minPhi();
72  for (++i; i != slabs.end(); ++i) {
73  if (fabs(phimax - (*i).maxPhi()) > 0.001 || fabs(phimin - (*i).minPhi()) > 0.001) {
74  if (debug) {
75  std::cout << "*** WARNING: slabs in this rod have different dphi! minphi " << phimin;
76  std::cout << " != " << (*i).minPhi() << " or maxphi " << phimax << " != " << (*i).maxPhi() << std::endl;
77  }
78  }
79  }
80 }
81 
83  if (mrod == nullptr) {
84  std::vector<MagBSlab*> mSlabs;
85  for (std::vector<bSlab>::const_iterator slab = slabs.begin(); slab != slabs.end(); ++slab) {
86  mSlabs.push_back((*slab).buildMagBSlab());
87  }
88  mrod = new MagBRod(mSlabs, slabs.front().minPhi()); //FIXME
89  }
90  return mrod;
91 }
void printUniqueNames(handles::const_iterator begin, handles::const_iterator end, bool uniq=true)
Just for debugging...
MagBRod * buildMagBRod() const
Construct the MagBRod upon request.
Definition: bRod.cc:82
MagBRod * mrod
Definition: bRod.h:34
#define nullptr
handles volumes
Definition: bRod.h:33
std::vector< float > clusterize(float resolution)
double f[11][100]
#define end
Definition: vmac.h:39
#define debug
Definition: HDRShower.cc:19
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
#define begin
Definition: vmac.h:32
std::vector< bSlab > slabs
Definition: bRod.h:32