File indexing completed on 2024-04-06 12:22:29
0001
0002
0003
0004
0005
0006
0007 #include "bRod.h"
0008 #include "printUniqueNames.h"
0009 #include "Utilities/BinningTools/interface/ClusterizingHistogram.h"
0010 #include "MagneticField/Layers/interface/MagBRod.h"
0011 #include "Utilities/General/interface/precomputed_value_sort.h"
0012
0013 #include <iostream>
0014
0015 using namespace SurfaceOrientation;
0016 using namespace magneticfield;
0017
0018
0019 bRod::bRod(handles::const_iterator begin, handles::const_iterator end, bool debugVal)
0020 : volumes(begin, end), mrod(nullptr), debug(debugVal) {
0021 precomputed_value_sort(volumes.begin(), volumes.end(), ExtractZ());
0022
0023
0024 const float resolution = 5.;
0025 float zmin = volumes.front()->center().z() - resolution;
0026 float zmax = volumes.back()->center().z() + resolution;
0027 ClusterizingHistogram hisZ(int((zmax - zmin) / resolution) + 1, zmin, zmax);
0028
0029 if (debug)
0030 std::cout << " Z slabs: " << zmin << " " << zmax << std::endl;
0031
0032 handles::const_iterator first = volumes.begin();
0033 handles::const_iterator last = volumes.end();
0034
0035 for (handles::const_iterator i = first; i != last; ++i) {
0036 hisZ.fill((*i)->center().z());
0037 }
0038 std::vector<float> zClust = hisZ.clusterize(resolution);
0039
0040 if (debug)
0041 std::cout << " Found " << zClust.size() << " clusters in Z, "
0042 << " slabs: " << std::endl;
0043
0044 handles::const_iterator slabStart = first;
0045 handles::const_iterator separ = first;
0046
0047 for (unsigned int i = 0; i < zClust.size() - 1; ++i) {
0048 float zSepar = (zClust[i] + zClust[i + 1]) / 2.f;
0049 while ((*separ)->center().z() < zSepar)
0050 ++separ;
0051 if (debug) {
0052 std::cout << " Slab at: " << zClust[i] << " elements: " << separ - slabStart << " unique volumes: ";
0053 printUniqueNames(slabStart, separ);
0054 }
0055
0056 slabs.push_back(bSlab(slabStart, separ, debug));
0057 slabStart = separ;
0058 }
0059 {
0060 if (debug) {
0061 std::cout << " Slab at: " << zClust.back() << " elements: " << last - separ << " unique volumes: ";
0062 printUniqueNames(separ, last);
0063 }
0064 slabs.push_back(bSlab(separ, last, debug));
0065 }
0066
0067
0068 std::vector<bSlab>::const_iterator i = slabs.begin();
0069 Geom::Phi<float> phimax = (*i).maxPhi();
0070 Geom::Phi<float> phimin = (*i).minPhi();
0071 for (++i; i != slabs.end(); ++i) {
0072 if (fabs(phimax - (*i).maxPhi()) > 0.001 || fabs(phimin - (*i).minPhi()) > 0.001) {
0073 if (debug) {
0074 std::cout << "*** WARNING: slabs in this rod have different dphi! minphi " << phimin;
0075 std::cout << " != " << (*i).minPhi() << " or maxphi " << phimax << " != " << (*i).maxPhi() << std::endl;
0076 }
0077 }
0078 }
0079 }
0080
0081 MagBRod* bRod::buildMagBRod() const {
0082 if (mrod == nullptr) {
0083 std::vector<MagBSlab*> mSlabs;
0084 for (std::vector<bSlab>::const_iterator slab = slabs.begin(); slab != slabs.end(); ++slab) {
0085 mSlabs.push_back((*slab).buildMagBSlab());
0086 }
0087 mrod = new MagBRod(mSlabs, slabs.front().minPhi());
0088 }
0089 return mrod;
0090 }