File indexing completed on 2024-04-06 12:22:30
0001
0002
0003
0004
0005
0006
0007 #include "eSector.h"
0008 #include "printUniqueNames.h"
0009 #include "Utilities/BinningTools/interface/ClusterizingHistogram.h"
0010 #include "MagneticField/Layers/interface/MagESector.h"
0011 #include "Utilities/General/interface/precomputed_value_sort.h"
0012
0013 #include <algorithm>
0014 #include <iostream>
0015
0016 using namespace SurfaceOrientation;
0017 using namespace std;
0018 using namespace magneticfield;
0019
0020
0021 eSector::eSector(handles::const_iterator begin, handles::const_iterator end, bool debugFlag)
0022 : theVolumes(begin, end), msector(nullptr), debug(debugFlag) {
0023
0024
0025 precomputed_value_sort(theVolumes.begin(), theVolumes.end(), ExtractZ());
0026
0027
0028 const float resolution = 1.;
0029 float zmin = theVolumes.front()->center().z() - resolution;
0030 float zmax = theVolumes.back()->center().z() + resolution;
0031 ClusterizingHistogram hisZ(int((zmax - zmin) / resolution) + 1, zmin, zmax);
0032
0033 if (debug)
0034 cout << " Z layers: " << zmin << " " << zmax << endl;
0035
0036 handles::const_iterator first = theVolumes.begin();
0037 handles::const_iterator last = theVolumes.end();
0038
0039 for (handles::const_iterator i = first; i != last; ++i) {
0040 hisZ.fill((*i)->center().z());
0041 }
0042 vector<float> zClust = hisZ.clusterize(resolution);
0043
0044 if (debug)
0045 cout << " Found " << zClust.size() << " clusters in Z, "
0046 << " layers: " << endl;
0047
0048 handles::const_iterator layStart = first;
0049 handles::const_iterator separ = first;
0050
0051 for (unsigned int i = 0; i < zClust.size() - 1; ++i) {
0052 float zSepar = (zClust[i] + zClust[i + 1]) / 2.f;
0053 while ((*separ)->center().z() < zSepar)
0054 ++separ;
0055 if (debug) {
0056 cout << " Layer at: " << zClust[i] << " elements: " << separ - layStart << " unique volumes: ";
0057 printUniqueNames(layStart, separ);
0058 }
0059
0060 layers.push_back(eLayer(layStart, separ));
0061 layStart = separ;
0062 }
0063 {
0064 if (debug) {
0065 cout << " Layer at: " << zClust.back() << " elements: " << last - separ << " unique volumes: ";
0066 printUniqueNames(separ, last);
0067 }
0068 layers.push_back(eLayer(separ, last));
0069 }
0070
0071
0072 }
0073
0074 MagESector* eSector::buildMagESector() const {
0075 if (msector == nullptr) {
0076 vector<MagELayer*> mLayers;
0077 for (vector<eLayer>::const_iterator lay = layers.begin(); lay != layers.end(); ++lay) {
0078 mLayers.push_back((*lay).buildMagELayer());
0079 }
0080 msector = new MagESector(mLayers, theVolumes.front()->minPhi());
0081 }
0082 return msector;
0083 }