CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
12 
13 #include <iostream>
14 
15 using namespace SurfaceOrientation;
16 using namespace magneticfield;
17 
18 //The ctor is in charge of finding slabs inside the rod.
19 bRod::bRod(handles::const_iterator begin, handles::const_iterator end, bool debugVal)
20  : volumes(begin, end), mrod(nullptr), debug(debugVal) {
22 
23  // Clusterize in Z
24  const float resolution = 5.; // cm
25  float zmin = volumes.front()->center().z() - resolution;
26  float zmax = volumes.back()->center().z() + resolution;
27  ClusterizingHistogram hisZ(int((zmax - zmin) / resolution) + 1, zmin, zmax);
28 
29  if (debug)
30  std::cout << " Z slabs: " << zmin << " " << zmax << std::endl;
31 
32  handles::const_iterator first = volumes.begin();
33  handles::const_iterator last = volumes.end();
34 
35  for (handles::const_iterator i = first; i != last; ++i) {
36  hisZ.fill((*i)->center().z());
37  }
38  std::vector<float> zClust = hisZ.clusterize(resolution);
39 
40  if (debug)
41  std::cout << " Found " << zClust.size() << " clusters in Z, "
42  << " slabs: " << std::endl;
43 
44  handles::const_iterator slabStart = first;
45  handles::const_iterator separ = first;
46 
47  for (unsigned int i = 0; i < zClust.size() - 1; ++i) {
48  float zSepar = (zClust[i] + zClust[i + 1]) / 2.f;
49  while ((*separ)->center().z() < zSepar)
50  ++separ;
51  if (debug) {
52  std::cout << " Slab at: " << zClust[i] << " elements: " << separ - slabStart << " unique volumes: ";
53  printUniqueNames(slabStart, separ);
54  }
55 
56  slabs.push_back(bSlab(slabStart, separ, debug));
57  slabStart = separ;
58  }
59  {
60  if (debug) {
61  std::cout << " Slab at: " << zClust.back() << " elements: " << last - separ << " unique volumes: ";
62  printUniqueNames(separ, last);
63  }
64  slabs.push_back(bSlab(separ, last, debug));
65  }
66 
67  // Check that all slabs have the same dphi.
68  std::vector<bSlab>::const_iterator i = slabs.begin();
69  Geom::Phi<float> phimax = (*i).maxPhi();
70  Geom::Phi<float> phimin = (*i).minPhi();
71  for (++i; i != slabs.end(); ++i) {
72  if (fabs(phimax - (*i).maxPhi()) > 0.001 || fabs(phimin - (*i).minPhi()) > 0.001) {
73  if (debug) {
74  std::cout << "*** WARNING: slabs in this rod have different dphi! minphi " << phimin;
75  std::cout << " != " << (*i).minPhi() << " or maxphi " << phimax << " != " << (*i).maxPhi() << std::endl;
76  }
77  }
78  }
79 }
80 
82  if (mrod == nullptr) {
83  std::vector<MagBSlab*> mSlabs;
84  for (std::vector<bSlab>::const_iterator slab = slabs.begin(); slab != slabs.end(); ++slab) {
85  mSlabs.push_back((*slab).buildMagBSlab());
86  }
87  mrod = new MagBRod(mSlabs, slabs.front().minPhi()); //FIXME
88  }
89  return mrod;
90 }
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:81
MagBRod * mrod
Definition: bRod.h:34
handles volumes
Definition: bRod.h:33
std::vector< float > clusterize(float resolution)
#define debug
Definition: HDRShower.cc:19
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
string end
Definition: dataset.py:937
tuple cout
Definition: gather_cfg.py:144
tuple last
Definition: dqmdumpme.py:56
std::vector< bSlab > slabs
Definition: bRod.h:32