CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
bSector.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  * $Date: 2007/03/09 14:38:23 $
7  * $Revision: 1.5 $
8  * \author N. Amapane - INFN Torino
9  */
10 
15 
17 
18 #include <algorithm>
19 
20 using namespace SurfaceOrientation;
21 using namespace std;
22 
23 
24 // Default ctor needed to have arrays.
26 
28 
29 // The ctor is in charge of finding rods inside the sector.
31  handles::const_iterator end) :
32  volumes(begin,end),
33  msector(0)
34 {
35  if (MagGeoBuilderFromDDD::debug) cout << " Sector at Phi " << volumes.front()->center().phi() << " "
36  << volumes.back()->center().phi() << endl;
37 
38  if (volumes.size() == 1) {
40  cout << " Rod at: 0 elements: " << end-begin
41  << " unique volumes: ";
43  }
44  rods.push_back(bRod(begin,end));
45  } else {
46  // Clusterize in phi. Use bin edge so that complete clusters can be
47  // easily found (not trivial using bin centers!)
48  // Unfortunately this makes the result more sensitive to the
49  // "resolution" parameter...
50  // To avoid +-pi boundary problems, take phi distance from min phi.
51  // Caveat of implicit conversions of Geom::Phi!!!
52 
53  // Sort volumes in DELTA phi - i.e. phi(j)-phi(i) > 0 if j>1.
54  precomputed_value_sort(volumes.begin(), volumes.end(),
55  ExtractPhiMax(), LessDPhi());
56 
57  const Geom::Phi<float> resolution(0.01); // rad
58  Geom::Phi<float> phi0 = volumes.front()->maxPhi();
59  float phiMin = -(float) resolution;
60  float phiMax = volumes.back()->maxPhi() - phi0 + resolution;
61 
62  ClusterizingHistogram hisPhi( int((phiMax-phiMin)/resolution) + 1,
63  phiMin, phiMax);
64 
65  handles::const_iterator first = volumes.begin();
66  handles::const_iterator last = volumes.end();
67 
68  for (handles::const_iterator i=first; i!=last; ++i){
69  hisPhi.fill((*i)->maxPhi()-phi0);
70  }
71  vector<float> phiClust = hisPhi.clusterize(resolution);
72 
73  if (MagGeoBuilderFromDDD::debug) cout << " Found " << phiClust.size() << " clusters in Phi, "
74  << " rods: " << endl;
75 
76  handles::const_iterator rodStart = first;
77  handles::const_iterator separ = first;
78 
79  float DZ = (*max_element(first,last,LessZ()))->maxZ() -
80  (*min_element(first,last,LessZ()))->minZ();
81 
82  float DZ1 = 0.;
83  for (unsigned int i=0; i<phiClust.size(); ++i) {
84  float phiSepar;
85  if (i<phiClust.size()-1) {
86  phiSepar = (phiClust[i] + phiClust[i+1])/2.f;
87  } else {
88  phiSepar = phiMax;
89  }
90  if (MagGeoBuilderFromDDD::debug) cout << " cluster " << i
91  << " phisepar " << phiSepar <<endl;
92  while (separ < last && (*separ)->maxPhi()-phi0 < phiSepar ) {
93  DZ1 += ((*separ)->maxZ() - (*separ)->minZ());
94  if (MagGeoBuilderFromDDD::debug) cout << " " << (*separ)->name << " "
95  << (*separ)->maxPhi()-phi0 << " "
96  << (*separ)->maxZ() << " " << (*separ)->minZ() << " "
97  << DZ1 << endl;
98  ++separ;
99  }
100 
101  // FIXME: print warning for small discrepancies. Tolerance (below)
102  // had to be increased since discrepancies sum to up to ~ 2 mm.
103  if (fabs(DZ-DZ1) > 0.001 && fabs(DZ-DZ1) < 0.5) {
104  if (MagGeoBuilderFromDDD::debug) cout << "*** WARNING: Z lenght mismatch by " << DZ-DZ1
105  << " " << DZ << " " << DZ1 << endl;
106 
107  }
108  if (fabs(DZ-DZ1) > 0.25 ) { // FIXME hardcoded tolerance
109  if (MagGeoBuilderFromDDD::debug) cout << " Incomplete, use also next cluster: "
110  << DZ << " " << DZ1 << " " << DZ-DZ1 << endl;
111  DZ1 = 0.;
112  continue;
113  } else if (DZ1>DZ+0.05) { // Wrong: went past max lenght // FIXME hardcoded tolerance
114  cout << " *** ERROR: bSector finding messed up." << endl;
115  volumeHandle::printUniqueNames(rodStart, separ);
116  DZ1 = 0.;
117  } else {
119  cout << " Rod at: " << phiClust[i] <<" elements: "
120  << separ-rodStart << " unique volumes: ";
121  volumeHandle::printUniqueNames(rodStart, separ);
122  }
123 
124  rods.push_back(bRod(rodStart, separ));
125  rodStart = separ;
126  DZ1 = 0.;
127  }
128  }
129 
130  if (MagGeoBuilderFromDDD::debug) cout << "-----------------------" << endl;
131 
132  }
133 }
134 
135 
137  if (msector==0) {
138  vector<MagBRod*> mRods;
139  for (vector<bRod>::const_iterator rod = rods.begin();
140  rod!=rods.end(); ++rod) {
141  mRods.push_back((*rod).buildMagBRod());
142  }
143  msector = new MagBSector(mRods, volumes.front()->minPhi()); //FIXME
144  }
145  return msector;
146 }
int i
Definition: DBlmapReader.cc:9
std::vector< bRod > rods
Definition: bSector.h:42
static void printUniqueNames(handles::const_iterator begin, handles::const_iterator end)
Just for debugging...
std::vector< float > clusterize(float resolution)
bSector()
Default ctor is needed to have arrays.
Definition: bSector.cc:25
double f[11][100]
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:94
MagBSector * buildMagBSector() const
Construct the MagBSector upon request.
Definition: bSector.cc:136
#define begin
Definition: vmac.h:31
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
tuple cout
Definition: gather_cfg.py:121