CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Alignment/MuonAlignment/src/AlignableMuon.cc

Go to the documentation of this file.
00001 
00009 // Framework
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 
00012 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
00013 #include "Geometry/DTGeometry/interface/DTChamber.h" 
00014 #include "Geometry/CSCGeometry/interface/CSCGeometry.h" 
00015 #include <Geometry/DTGeometry/interface/DTLayer.h> 
00016 #include "CondFormats/Alignment/interface/Alignments.h" 
00017 #include "CondFormats/Alignment/interface/AlignmentErrors.h" 
00018 #include "CondFormats/Alignment/interface/AlignmentSorter.h" 
00019 
00020 // Muon  components
00021 #include "Alignment/MuonAlignment/interface/AlignableDTChamber.h"
00022 #include "Alignment/MuonAlignment/interface/AlignableCSCChamber.h"
00023 #include "Alignment/MuonAlignment/interface/AlignableDTStation.h"
00024 #include "Geometry/CommonDetUnit/interface/GeomDet.h" 
00025 #include "Alignment/MuonAlignment/interface/AlignableCSCStation.h"
00026 #include "Alignment/MuonAlignment/interface/AlignableDTWheel.h"
00027 #include "Alignment/MuonAlignment/interface/AlignableDTBarrel.h"
00028 #include "Alignment/MuonAlignment/interface/AlignableCSCEndcap.h"
00029 
00030 //--------------------------------------------------------------------------------------------------
00031 AlignableMuon::AlignableMuon( const DTGeometry* dtGeometry , const CSCGeometry* cscGeometry )
00032   : AlignableComposite(0, align::AlignableMuon) // cannot yet set id, use 0
00033 {
00034 
00035   // Build the muon barrel
00036   buildDTBarrel( dtGeometry );
00037 
00038   // Build the muon end caps
00039   buildCSCEndcap( cscGeometry );
00040 
00041   // Set links to mothers recursively
00042   recursiveSetMothers( this );
00043 
00044   // now can set id as for all composites: id of first component
00045   theId = this->components()[0]->id();
00046 
00047   edm::LogInfo("AlignableMuon") << "Constructing alignable muon objects DONE";
00048 
00049 
00050 }
00051 
00052 //--------------------------------------------------------------------------------------------------
00053 AlignableMuon::~AlignableMuon() 
00054 {
00055 
00056   for ( align::Alignables::iterator iter=theMuonComponents.begin();
00057                 iter != theMuonComponents.end(); iter++){
00058     delete *iter;
00059   }
00060       
00061 
00062 }
00063 
00064 
00065 //--------------------------------------------------------------------------------------------------
00066 void AlignableMuon::buildDTBarrel( const DTGeometry* pDT  )
00067 {
00068   
00069  LogDebug("Position") << "Constructing AlignableDTBarrel"; 
00070 
00071   // Temporary container for chambers in a given station and stations in a given wheel
00072   std::vector<AlignableDTChamber*>   tmpDTChambersInStation;
00073   std::vector<AlignableDTStation*>   tmpDTStationsInWheel;
00074 
00075 
00076   // Loop over wheels ( -2..2 )
00077   for( int iwh = -2 ; iwh < 3 ; iwh++ ){
00078 
00079     // Loop over stations ( 1..4 )
00080     for( int ist = 1 ; ist < 5 ; ist++ ){
00081   
00082       // Loop over geom DT Chambers
00083       std::vector<GeomDet*> theSLs;
00084       for( std::vector<DTChamber*>::const_iterator det = pDT->chambers().begin(); 
00085                    det != pDT->chambers().end(); ++det ){
00086         // Get the chamber ID
00087         DTChamberId chamberId = (*det)->id(); 
00088                 
00089         // Get wheel,station and sector of the chamber
00090         int wh = chamberId.wheel();
00091         int st = chamberId.station();
00092         //int se = chamberId.sector();
00093 
00094         // Select the chambers in a given wheel in a given station
00095         if ( iwh == wh && ist == st ){
00096 
00097           // Create the alignable DT chamber
00098           AlignableDTChamber* tmpDTChamber  = new AlignableDTChamber( *det );
00099  
00100           // Store the DT chambers in a given DT Station and Wheel
00101                   tmpDTChambersInStation.push_back( tmpDTChamber );
00102 
00103                   // End chamber selection
00104                 }
00105 
00106                 // End loop over chambers
00107       }  
00108           
00109       // Store the DT chambers 
00110       theDTChambers.insert( theDTChambers.end(), tmpDTChambersInStation.begin(),
00111                             tmpDTChambersInStation.end() );
00112 
00113       // Create the alignable DT station with chambers in a given station and wheel 
00114       AlignableDTStation* tmpDTStation  = new AlignableDTStation( tmpDTChambersInStation );
00115      
00116       // Store the DT stations in a given wheel  
00117       tmpDTStationsInWheel.push_back( tmpDTStation );
00118 
00119       // Clear the temporary vector of chambers in a station
00120       tmpDTChambersInStation.clear();
00121 
00122     // End loop over stations
00123     }
00124 
00125     // Store The DT stations
00126         theDTStations.insert( theDTStations.end(), tmpDTStationsInWheel.begin(),
00127                                                   tmpDTStationsInWheel.end() );
00128 
00129     // Create the alignable DT wheel
00130     AlignableDTWheel* tmpWheel  = new AlignableDTWheel( tmpDTStationsInWheel );
00131      
00132 
00133     // Store the DT wheels  
00134     theDTWheels.push_back( tmpWheel );
00135 
00136     // Clear temporary vector of stations in a wheel
00137     tmpDTStationsInWheel.clear();
00138 
00139 
00140   // End loop over wheels   
00141   }    
00142           
00143   // Create the alignable Muon Barrel
00144   AlignableDTBarrel* tmpDTBarrel  = new AlignableDTBarrel( theDTWheels );  
00145   
00146   // Store the barrel
00147   theDTBarrel.push_back( tmpDTBarrel );
00148 
00149   // Store the barrel in the muon 
00150   theMuonComponents.push_back( tmpDTBarrel );
00151 
00152 
00153 }
00154 
00155 
00156 
00157 //--------------------------------------------------------------------------------------------------
00158 
00159 
00160 void AlignableMuon::buildCSCEndcap( const CSCGeometry* pCSC  )
00161 {
00162   
00163  LogDebug("Position") << "Constructing AlignableCSCBarrel"; 
00164 
00165   // Temporary container for stations in a given endcap
00166   std::vector<AlignableCSCStation*>  tmpCSCStationsInEndcap;
00167 
00168   // Loop over endcaps ( 1..2 )
00169   for( int iec = 1 ; iec < 3 ; iec++ ){
00170 
00171     // Temporary container for rings in a given station
00172     std::vector<AlignableCSCRing*>   tmpCSCRingsInStation;
00173     
00174     // Loop over stations ( 1..4 )
00175     for( int ist = 1 ; ist < 5 ; ist++ ){
00176   
00177       // Temporary container for chambers in a given ring
00178       std::vector<AlignableCSCChamber*>  tmpCSCChambersInRing;
00179 
00180       // Loop over rings ( 1..4 )
00181       for ( int iri = 1; iri < 5; iri++ ){
00182          
00183          // Loop over geom CSC Chambers
00184          std::vector<CSCChamber*> vc = pCSC->chambers();
00185          for( std::vector<CSCChamber*>::const_iterator det = vc.begin();  det != vc.end(); ++det ){
00186 
00187             // Get the CSCDet ID
00188             CSCDetId cscId = (*det)->id();
00189 
00190             // Get chamber, station, ring, layer and endcap labels of the CSC chamber
00191             int ec = cscId.endcap();
00192             int st = cscId.station();
00193             int ri = cscId.ring();
00194             //int ch = cscId.chamber();
00195 
00196             // Select the chambers in a given endcap, station, and ring
00197             if ( iec == ec && ist == st && iri == ri ) {
00198 
00199                // Create the alignable CSC chamber 
00200                AlignableCSCChamber* tmpCSCChamber  = new AlignableCSCChamber( *det );
00201   
00202                // Store the alignable CSC chambers
00203                tmpCSCChambersInRing.push_back( tmpCSCChamber );    
00204 
00205                // End If chamber selection
00206             }
00207 
00208             // End loop over geom CSC chambers
00209          }
00210 
00211          // Not all stations have 4 rings: only add the rings that exist (have chambers associated with them)
00212          if (tmpCSCChambersInRing.size() > 0) {
00213 
00214             // Store the alignable CSC chambers
00215             theCSCChambers.insert(  theCSCChambers.end(), tmpCSCChambersInRing.begin(), tmpCSCChambersInRing.end() );    
00216 
00217             // Create the alignable CSC ring with chambers in a given ring
00218             AlignableCSCRing* tmpCSCRing  = new AlignableCSCRing( tmpCSCChambersInRing );
00219 
00220             // Store the CSC rings in a given station
00221             tmpCSCRingsInStation.push_back( tmpCSCRing );
00222 
00223             // Clear the temporary vector of chambers in ring
00224             tmpCSCChambersInRing.clear();
00225 
00226             // End if this ring exists
00227          }
00228 
00229          // End loop over rings
00230       }
00231 
00232       // Create the alignable CSC station with rings in a given station 
00233       AlignableCSCStation* tmpCSCStation  = new AlignableCSCStation( tmpCSCRingsInStation );
00234      
00235       // Store the alignable CSC rings
00236       theCSCRings.insert(  theCSCRings.end(), tmpCSCRingsInStation.begin(), tmpCSCRingsInStation.end() );
00237 
00238       // Store the CSC stations in a given endcap  
00239       tmpCSCStationsInEndcap.push_back( tmpCSCStation );
00240 
00241       // Clear the temporary vector of rings in station
00242       tmpCSCRingsInStation.clear();
00243 
00244     // End loop over stations
00245     }
00246 
00247     // Create the alignable CSC endcap 
00248     AlignableCSCEndcap* tmpEndcap  = new AlignableCSCEndcap( tmpCSCStationsInEndcap );
00249      
00250     // Store the alignable CSC stations 
00251     theCSCStations.insert(  theCSCStations.end(), tmpCSCStationsInEndcap.begin(), tmpCSCStationsInEndcap.end() );
00252 
00253     // Store the alignable CSC endcaps
00254     theCSCEndcaps.push_back( tmpEndcap );
00255 
00256     // Clear the temporary vector of stations in endcap
00257     tmpCSCStationsInEndcap.clear();
00258 
00259   // End loop over endcaps  
00260   }
00261 
00262   // Store the encaps in the muon components  
00263   theMuonComponents.insert(  theMuonComponents.end(), theCSCEndcaps.begin(), theCSCEndcaps.end() );    
00264 
00265     
00266 }
00267 
00268 //--------------------------------------------------------------------------------------------------
00269 align::Alignables AlignableMuon::DTLayers()
00270 {
00271   align::Alignables result;
00272 
00273   align::Alignables chambers = DTChambers();
00274   for (align::Alignables::const_iterator chamberIter = chambers.begin();  chamberIter != chambers.end();  ++chamberIter) {
00275      align::Alignables superlayers = (*chamberIter)->components();
00276      for (align::Alignables::const_iterator superlayerIter = superlayers.begin();  superlayerIter != superlayers.end();  ++superlayerIter) {
00277         align::Alignables layers = (*superlayerIter)->components();
00278         for (align::Alignables::const_iterator layerIter = layers.begin();  layerIter != layers.end();  ++layerIter) {
00279            result.push_back(*layerIter);
00280         }
00281      }
00282   }
00283 
00284   return result;
00285 }
00286 
00287 //--------------------------------------------------------------------------------------------------
00288 align::Alignables AlignableMuon::DTSuperLayers()
00289 {
00290   align::Alignables result;
00291 
00292   align::Alignables chambers = DTChambers();
00293   for (align::Alignables::const_iterator chamberIter = chambers.begin();  chamberIter != chambers.end();  ++chamberIter) {
00294      align::Alignables superlayers = (*chamberIter)->components();
00295      for (align::Alignables::const_iterator superlayerIter = superlayers.begin();  superlayerIter != superlayers.end();  ++superlayerIter) {
00296         result.push_back(*superlayerIter);
00297      }
00298   }
00299 
00300   return result;
00301 }
00302 
00303 //--------------------------------------------------------------------------------------------------
00304 align::Alignables AlignableMuon::DTChambers()
00305 {
00306   align::Alignables result;
00307   copy( theDTChambers.begin(), theDTChambers.end(), back_inserter(result) );
00308   return result;
00309 }
00310 
00311 //--------------------------------------------------------------------------------------------------
00312 align::Alignables AlignableMuon::DTStations()
00313 {
00314   align::Alignables result;
00315   copy( theDTStations.begin(), theDTStations.end(), back_inserter(result) );
00316   return result;
00317 }
00318 
00319 
00320 //--------------------------------------------------------------------------------------------------
00321 align::Alignables AlignableMuon::DTWheels()
00322 {
00323   align::Alignables result;
00324   copy( theDTWheels.begin(), theDTWheels.end(), back_inserter(result) );
00325   return result;
00326 }
00327 
00328 //--------------------------------------------------------------------------------------------------
00329 align::Alignables AlignableMuon::DTBarrel()
00330 {
00331   align::Alignables result ;
00332   copy( theDTBarrel.begin(), theDTBarrel.end(), back_inserter(result) );
00333   return result;
00334 }
00335 
00336 //--------------------------------------------------------------------------------------------------
00337 align::Alignables AlignableMuon::CSCLayers()
00338 {
00339   align::Alignables result;
00340 
00341   align::Alignables chambers = CSCChambers();
00342   for (align::Alignables::const_iterator chamberIter = chambers.begin();  chamberIter != chambers.end();  ++chamberIter) {
00343      align::Alignables layers = (*chamberIter)->components();
00344      for (align::Alignables::const_iterator layerIter = layers.begin();  layerIter != layers.end();  ++layerIter) {
00345         result.push_back(*layerIter);
00346      }
00347   }
00348 
00349   return result;
00350 }
00351 
00352 //--------------------------------------------------------------------------------------------------
00353 align::Alignables AlignableMuon::CSCChambers()
00354 {
00355   align::Alignables result;
00356   copy( theCSCChambers.begin(), theCSCChambers.end(), back_inserter(result) );
00357   return result;
00358 }
00359 
00360 //--------------------------------------------------------------------------------------------------
00361 align::Alignables AlignableMuon::CSCRings()
00362 {
00363   align::Alignables result;
00364   copy( theCSCRings.begin(), theCSCRings.end(), back_inserter(result) );
00365   return result;
00366 }
00367 
00368 //--------------------------------------------------------------------------------------------------
00369 align::Alignables AlignableMuon::CSCStations()
00370 {
00371   align::Alignables result;
00372   copy( theCSCStations.begin(), theCSCStations.end(), back_inserter(result) );
00373   return result;
00374 }
00375 
00376 //--------------------------------------------------------------------------------------------------
00377 align::Alignables AlignableMuon::CSCEndcaps()
00378 {
00379   align::Alignables result;
00380   copy( theCSCEndcaps.begin(), theCSCEndcaps.end(), back_inserter(result) );
00381   return result;
00382 }
00383 
00384 
00385 //__________________________________________________________________________________________________
00386 void AlignableMuon::recursiveSetMothers( Alignable* alignable )
00387 {
00388   
00389   align::Alignables components = alignable->components();
00390   for ( align::Alignables::iterator iter = components.begin();
00391                 iter != components.end(); iter++ )
00392         {
00393           (*iter)->setMother( alignable );
00394           recursiveSetMothers( *iter );
00395         }
00396 
00397 }
00398 //__________________________________________________________________________________________________
00399 Alignments* AlignableMuon::alignments( void ) const
00400 {
00401 
00402   align::Alignables comp = this->components();
00403   Alignments* m_alignments = new Alignments();
00404   // Add components recursively
00405   for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00406     {
00407       Alignments* tmpAlignments = (*i)->alignments();
00408       std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(), 
00409                                  std::back_inserter(m_alignments->m_align) );
00410           delete tmpAlignments;
00411     }
00412 
00413   std::sort( m_alignments->m_align.begin(), m_alignments->m_align.end(), 
00414                          lessAlignmentDetId<AlignTransform>() );
00415 
00416   return m_alignments;
00417 
00418 }
00419 //__________________________________________________________________________________________________
00420 AlignmentErrors* AlignableMuon::alignmentErrors( void ) const
00421 {
00422 
00423   align::Alignables comp = this->components();
00424   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00425 
00426   // Add components recursively
00427   for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00428     {
00429           AlignmentErrors* tmpAlignmentErrors = (*i)->alignmentErrors();
00430       std::copy( tmpAlignmentErrors->m_alignError.begin(), tmpAlignmentErrors->m_alignError.end(), 
00431                                  std::back_inserter(m_alignmentErrors->m_alignError) );
00432           delete tmpAlignmentErrors;
00433     }
00434 
00435   std::sort( m_alignmentErrors->m_alignError.begin(), m_alignmentErrors->m_alignError.end(), 
00436                          lessAlignmentDetId<AlignTransformError>() );
00437 
00438   return m_alignmentErrors;
00439 
00440 }
00441 //__________________________________________________________________________________________________
00442 Alignments* AlignableMuon::dtAlignments( void )
00443 {
00444   // Retrieve muon barrel alignments
00445   Alignments* tmpAlignments = this->DTBarrel().front()->alignments();
00446   
00447   return tmpAlignments;
00448 
00449 }
00450 //__________________________________________________________________________________________________
00451 AlignmentErrors* AlignableMuon::dtAlignmentErrors( void )
00452 {
00453   // Retrieve muon barrel alignment errors
00454   AlignmentErrors* tmpAlignmentErrors = this->DTBarrel().front()->alignmentErrors();
00455 
00456   return tmpAlignmentErrors;
00457   
00458 }
00459 //__________________________________________________________________________________________________
00460 Alignments* AlignableMuon::cscAlignments( void )
00461 {
00462 
00463   // Retrieve muon endcaps alignments
00464   Alignments* cscEndCap1    = this->CSCEndcaps().front()->alignments();
00465   Alignments* cscEndCap2    = this->CSCEndcaps().back()->alignments();
00466   Alignments* tmpAlignments = new Alignments();
00467 
00468   std::copy( cscEndCap1->m_align.begin(), cscEndCap1->m_align.end(), back_inserter( tmpAlignments->m_align ) );
00469   std::copy( cscEndCap2->m_align.begin(), cscEndCap2->m_align.end(), back_inserter( tmpAlignments->m_align ) );
00470   
00471   return tmpAlignments;
00472 
00473 }
00474 //__________________________________________________________________________________________________
00475 AlignmentErrors* AlignableMuon::cscAlignmentErrors( void )
00476 {
00477 
00478   // Retrieve muon endcaps alignment errors
00479    AlignmentErrors* cscEndCap1Errors = this->CSCEndcaps().front()->alignmentErrors();
00480    AlignmentErrors* cscEndCap2Errors = this->CSCEndcaps().back()->alignmentErrors();
00481    AlignmentErrors* tmpAlignmentErrors    = new AlignmentErrors();
00482 
00483   std::copy(cscEndCap1Errors->m_alignError.begin(), cscEndCap1Errors->m_alignError.end(), back_inserter(tmpAlignmentErrors->m_alignError) );
00484   std::copy(cscEndCap2Errors->m_alignError.begin(), cscEndCap2Errors->m_alignError.end(), back_inserter(tmpAlignmentErrors->m_alignError) );
00485   
00486   return tmpAlignmentErrors;
00487   
00488 }