CMS 3D CMS Logo

eSector.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 "eSector.h"
8 #include "printUniqueNames.h"
12 
13 #include <algorithm>
14 #include <iostream>
15 
16 using namespace SurfaceOrientation;
17 using namespace std;
18 using namespace magneticfield;
19 
20 // The ctor is in charge of finding layers inside the sector.
21 eSector::eSector(handles::const_iterator begin, handles::const_iterator end, bool debugFlag)
22  : theVolumes(begin, end), msector(nullptr), debug(debugFlag) {
23  //FIXME!!!
24  //precomputed_value_sort(theVolumes.begin(), theVolumes.end(), ExtractAbsZ());
26 
27  // Clusterize in Z
28  const float resolution = 1.; // cm //FIXME ??
29  float zmin = theVolumes.front()->center().z() - resolution;
30  float zmax = theVolumes.back()->center().z() + resolution;
31  ClusterizingHistogram hisZ(int((zmax - zmin) / resolution) + 1, zmin, zmax);
32 
33  if (debug)
34  cout << " Z layers: " << zmin << " " << zmax << endl;
35 
36  handles::const_iterator first = theVolumes.begin();
37  handles::const_iterator last = theVolumes.end();
38 
39  for (handles::const_iterator i = first; i != last; ++i) {
40  hisZ.fill((*i)->center().z());
41  }
42  vector<float> zClust = hisZ.clusterize(resolution);
43 
44  if (debug)
45  cout << " Found " << zClust.size() << " clusters in Z, "
46  << " layers: " << endl;
47 
48  handles::const_iterator layStart = first;
49  handles::const_iterator separ = first;
50 
51  for (unsigned int i = 0; i < zClust.size() - 1; ++i) {
52  float zSepar = (zClust[i] + zClust[i + 1]) / 2.f;
53  while ((*separ)->center().z() < zSepar)
54  ++separ;
55  if (debug) {
56  cout << " Layer at: " << zClust[i] << " elements: " << separ - layStart << " unique volumes: ";
57  printUniqueNames(layStart, separ);
58  }
59 
60  layers.push_back(eLayer(layStart, separ));
61  layStart = separ;
62  }
63  {
64  if (debug) {
65  cout << " Layer at: " << zClust.back() << " elements: " << last - separ << " unique volumes: ";
66  printUniqueNames(separ, last);
67  }
68  layers.push_back(eLayer(separ, last));
69  }
70 
71  // FIXME: Check that all layers have the same dz?.
72 }
73 
75  if (msector == nullptr) {
76  vector<MagELayer*> mLayers;
77  for (vector<eLayer>::const_iterator lay = layers.begin(); lay != layers.end(); ++lay) {
78  mLayers.push_back((*lay).buildMagELayer());
79  }
80  msector = new MagESector(mLayers, theVolumes.front()->minPhi()); //FIXME
81  }
82  return msector;
83 }
void printUniqueNames(handles::const_iterator begin, handles::const_iterator end, bool uniq=true)
Just for debugging...
std::vector< float > clusterize(float resolution)
double f[11][100]
MagESector * buildMagESector() const
Construct the MagESector upon request.
Definition: eSector.cc:74
#define debug
Definition: HDRShower.cc:19
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
const bool debug
Definition: eSector.h:34
std::vector< eLayer > layers
Definition: eSector.h:31
MagESector * msector
Definition: eSector.h:33