CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/MagneticField/GeomBuilder/src/bRod.cc

Go to the documentation of this file.
00001 // #include "Utilities/Configuration/interface/Architecture.h"
00002 
00003 /*
00004  *  See header file for a description of this class.
00005  *
00006  *  $Date: 2008/04/23 13:59:30 $
00007  *  $Revision: 1.6 $
00008  *  \author N. Amapane - INFN Torino
00009  */
00010 
00011 #include "MagneticField/GeomBuilder/src/bRod.h"
00012 #include "Utilities/BinningTools/interface/ClusterizingHistogram.h"
00013 #include "MagneticField/Layers/interface/MagBRod.h"
00014 #include "MagneticField/Layers/interface/MagVerbosity.h"
00015 #include "Utilities/General/interface/precomputed_value_sort.h"
00016 
00017 using namespace SurfaceOrientation;
00018 
00019 MagGeoBuilderFromDDD::bRod::~bRod(){}
00020 
00021 //The ctor is in charge of finding slabs inside the rod.
00022 MagGeoBuilderFromDDD::bRod::bRod(handles::const_iterator begin,
00023                                         handles::const_iterator end) :
00024   volumes(begin,end),
00025   mrod(0)
00026 {
00027   precomputed_value_sort(volumes.begin(), volumes.end(), ExtractZ());
00028 
00029   // Clusterize in Z
00030   const float resolution = 5.; // cm
00031   float zmin = volumes.front()->center().z()-resolution;
00032   float zmax = volumes.back()->center().z()+resolution;
00033   ClusterizingHistogram  hisZ( int((zmax-zmin)/resolution) + 1, zmin, zmax);
00034 
00035   if (MagGeoBuilderFromDDD::debug) std::cout << "     Z slabs: " << zmin << " " << zmax << std::endl;
00036 
00037   handles::const_iterator first = volumes.begin();
00038   handles::const_iterator last = volumes.end();  
00039 
00040   for (handles::const_iterator i=first; i!=last; ++i){
00041     hisZ.fill((*i)->center().z());
00042   }
00043   std::vector<float> zClust = hisZ.clusterize(resolution);
00044 
00045   if (MagGeoBuilderFromDDD::debug) std::cout << "     Found " << zClust.size() << " clusters in Z, "
00046                   << " slabs: " << std::endl;
00047 
00048   handles::const_iterator slabStart = first;
00049   handles::const_iterator separ = first;
00050 
00051   for (unsigned int i=0; i<zClust.size() - 1; ++i) {
00052     float zSepar = (zClust[i] + zClust[i+1])/2.f;
00053     while ((*separ)->center().z() < zSepar) ++separ;
00054     if (MagGeoBuilderFromDDD::debug) {
00055       std::cout << "     Slab at: " << zClust[i]
00056            << " elements: " << separ-slabStart << " unique volumes: ";
00057       volumeHandle::printUniqueNames(slabStart, separ);
00058     }
00059     
00060     slabs.push_back(bSlab(slabStart, separ));
00061     slabStart = separ;
00062   }
00063   {
00064     if (MagGeoBuilderFromDDD::debug) {
00065       std::cout << "     Slab at: " << zClust.back() <<" elements: " << last-separ
00066            << " unique volumes: ";
00067       volumeHandle::printUniqueNames(separ,last);
00068     }
00069     slabs.push_back(bSlab(separ, last));
00070   }
00071 
00072   // Check that all slabs have the same dphi.
00073   std::vector<bSlab>::const_iterator i = slabs.begin();
00074   Geom::Phi<float> phimax = (*i).maxPhi();
00075   Geom::Phi<float> phimin = (*i).minPhi();
00076   for (++i; i!= slabs.end(); ++i) { 
00077     if(fabs(phimax - (*i).maxPhi()) > 0.001 ||
00078        fabs(phimin - (*i).minPhi()) > 0.001){
00079       if (MagGeoBuilderFromDDD::debug) std::cout << "*** WARNING: slabs in this rod have different dphi!" <<std::endl;
00080     }
00081   }
00082 }
00083 
00084 
00085 
00086 MagBRod* MagGeoBuilderFromDDD::bRod::buildMagBRod() const{
00087   if (mrod==0) {
00088     std::vector<MagBSlab*> mSlabs;
00089     for (std::vector<bSlab>::const_iterator slab = slabs.begin();
00090          slab!=slabs.end(); ++slab) {
00091       mSlabs.push_back((*slab).buildMagBSlab());
00092     }
00093     mrod = new MagBRod(mSlabs,slabs.front().minPhi()); //FIXME
00094   }
00095   return mrod;
00096 }