CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Alignment/CommonAlignment/src/AlignableBuilder.cc

Go to the documentation of this file.
00001 #include "Alignment/CommonAlignment/interface/AlignableComposite.h"
00002 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
00003 
00004 #include "Alignment/CommonAlignment/interface/AlignableBuilder.h"
00005 
00006 
00007 //__________________________________________________________________________________________________
00008 AlignableBuilder::LevelInfo::LevelInfo( align::StructureType type,
00009                                         bool flat,
00010                                         unsigned int maxComponent ) :
00011   type_(type),
00012   flat_(flat),
00013   maxComponent_(maxComponent)
00014 {
00015 }
00016 
00017 //__________________________________________________________________________________________________
00018 AlignableBuilder::AlignableBuilder(align::StructureType moduleType, Counters& counters, const TrackerTopology* tTopo):
00019   theModuleType(moduleType),
00020   theCounters(counters),
00021   theTopology(tTopo)
00022 {
00023 }
00024 
00025 //__________________________________________________________________________________________________
00026 void AlignableBuilder::addLevelInfo(align::StructureType type,
00027                                     bool flat,
00028                                     unsigned int maxComponent)
00029 {
00030   theLevelInfos.push_back( LevelInfo(type, flat, maxComponent) );
00031 }
00032 
00033 //__________________________________________________________________________________________________
00034 void AlignableBuilder::buildAll( AlignSetup<align::Alignables>& setup ) const
00035 {
00036   build(0, theModuleType, setup); // build the first level above the modules
00037 
00038   for (unsigned int l = 1; l < theLevelInfos.size(); ++l) 
00039     build(l, theLevelInfos[l - 1].type_, setup);
00040 }
00041 
00042 //__________________________________________________________________________________________________
00043 unsigned int AlignableBuilder::maxComponent(unsigned int level) const
00044 {
00045   unsigned int max = 1;
00046 
00047   for (unsigned int l = level; l < theLevelInfos.size(); ++l)
00048   {
00049     max *= theLevelInfos[l].maxComponent_;
00050   }
00051 
00052   return max;
00053 }
00054 
00055 //__________________________________________________________________________________________________
00056 unsigned int AlignableBuilder::index( unsigned int level, align::ID id, const TrackerTopology* tTopo) const
00057 {
00058   const LevelInfo& info = theLevelInfos[level];
00059 
00060   if (theLevelInfos.size() - 1 > level)
00061   {
00062     return index(level + 1, id, tTopo) * info.maxComponent_ + theCounters.get(info.type_)(id, tTopo) - 1;
00063   }
00064 
00065   return theCounters.get(info.type_)(id, tTopo) - 1;
00066 }
00067 
00068 
00069 //__________________________________________________________________________________________________
00070 void AlignableBuilder::build( unsigned int level, align::StructureType dauType,
00071                               AlignSetup<align::Alignables>& setup ) const
00072 {
00073   const LevelInfo& momInfo = theLevelInfos[level];
00074 
00075   align::StructureType momType = momInfo.type_;
00076 
00077   const align::Alignables& daus = setup.find( AlignableObjectId::idToString(dauType) );
00078 
00079   unsigned int nDau = daus.size();
00080 
00081   align::Alignables& moms = setup.get( AlignableObjectId::idToString(momType) );
00082 
00083   moms.reserve(nDau);
00084 
00085   // In order not to depend on the order of the daughter list,
00086   // we define flags to indicate the existence of a mother;
00087   // 0 if it hasn't been created.
00088   // We use vector instead of map for speed.
00089   align::Alignables tempMoms(maxComponent(level), 0); // init all to 0
00090 
00091   for (unsigned int i = 0; i < nDau; ++i)
00092   {
00093     Alignable* dau = daus[i];
00094 
00095     Alignable*& mom = tempMoms[index( level, dau->id(), theTopology )];
00096 
00097     if (0 == mom)
00098     { 
00099       // create new mom with id and rot of 1st dau
00100       if ( momInfo.flat_ )
00101         mom = new AlignableComposite( dau->id(), momType, dau->globalRotation() );
00102       else
00103         mom = new AlignableComposite( dau->id(), momType, align::RotationType() );
00104 
00105       moms.push_back(mom);
00106     }
00107 
00108     mom->addComponent(dau);
00109   }
00110 }