CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/MagneticField/GeomBuilder/src/eSector.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: 2007/03/09 14:38:23 $
00007  *  $Revision: 1.5 $
00008  *  \author N. Amapane - INFN Torino
00009  */
00010 
00011 #include "MagneticField/GeomBuilder/src/eSector.h"
00012 #include "Utilities/BinningTools/interface/ClusterizingHistogram.h"
00013 #include "MagneticField/Layers/interface/MagESector.h"
00014 #include "MagneticField/Layers/interface/MagVerbosity.h"
00015 
00016 #include <algorithm>
00017 #include "Utilities/General/interface/precomputed_value_sort.h"
00018 
00019 using namespace SurfaceOrientation;
00020 using namespace std;
00021 
00022 // The ctor is in charge of finding layers inside the sector.
00023 MagGeoBuilderFromDDD::eSector::eSector(handles::const_iterator begin,
00024                                        handles::const_iterator end) :
00025   theVolumes(begin,end),
00026   msector(0)
00027 {
00028   //FIXME!!!
00029   //precomputed_value_sort(theVolumes.begin(), theVolumes.end(), ExtractAbsZ());
00030   precomputed_value_sort(theVolumes.begin(), theVolumes.end(), ExtractZ());
00031   
00032 
00033   // Clusterize in Z
00034   const float resolution = 1.; // cm //FIXME ??
00035   float zmin = theVolumes.front()->center().z()-resolution;
00036   float zmax = theVolumes.back()->center().z()+resolution;
00037   ClusterizingHistogram  hisZ( int((zmax-zmin)/resolution) + 1, zmin, zmax);
00038 
00039   if (MagGeoBuilderFromDDD::debug) cout << "     Z layers: " << zmin << " " << zmax << endl;
00040 
00041   handles::const_iterator first = theVolumes.begin();
00042   handles::const_iterator last = theVolumes.end();  
00043 
00044   for (handles::const_iterator i=first; i!=last; ++i){
00045     hisZ.fill((*i)->center().z());
00046   }
00047   vector<float> zClust = hisZ.clusterize(resolution);
00048 
00049   if (MagGeoBuilderFromDDD::debug) cout << "     Found " << zClust.size() << " clusters in Z, "
00050                   << " layers: " << endl;
00051 
00052   handles::const_iterator layStart = first;
00053   handles::const_iterator separ = first;
00054 
00055   for (unsigned int i=0; i<zClust.size() - 1; ++i) {
00056     float zSepar = (zClust[i] + zClust[i+1])/2.f;
00057     while ((*separ)->center().z() < zSepar) ++separ;
00058     if (MagGeoBuilderFromDDD::debug) {
00059       cout << "     Layer at: " << zClust[i]
00060            << " elements: " << separ-layStart << " unique volumes: ";
00061       volumeHandle::printUniqueNames(layStart, separ);
00062     }
00063     
00064     layers.push_back(eLayer(layStart, separ));
00065     layStart = separ;
00066   }
00067   {
00068     if (MagGeoBuilderFromDDD::debug) {
00069       cout << "     Layer at: " << zClust.back() <<" elements: " << last-separ
00070            << " unique volumes: ";
00071       volumeHandle::printUniqueNames(separ,last);
00072     }
00073     layers.push_back(eLayer(separ, last));
00074   }
00075 
00076   // FIXME: Check that all layers have the same dz?. 
00077   
00078 }
00079 
00080 
00081 MagGeoBuilderFromDDD::eSector::~eSector(){}
00082 
00083 
00084 MagESector* MagGeoBuilderFromDDD::eSector::buildMagESector() const{
00085   if (msector==0) {
00086     vector<MagELayer*> mLayers;
00087     for (vector<eLayer>::const_iterator lay = layers.begin();
00088          lay!=layers.end(); ++lay) {
00089       mLayers.push_back((*lay).buildMagELayer());
00090     }
00091     msector = new MagESector(mLayers, theVolumes.front()->minPhi()); //FIXME
00092   }
00093   return msector;
00094 }