Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:40

0001 /** \file
0002  *
0003  *  $Date: 2008/04/10 16:36:41 $
0004  *  $Revision: 1.7 $
0005  *  \author Andre Sznajder - UERJ(Brazil)
0006  */
0007 
0008 #include <memory>
0009 
0010 #include "Alignment/MuonAlignment/interface/AlignableCSCEndcap.h"
0011 #include "CondFormats/Alignment/interface/Alignments.h"
0012 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 
0015 /// The constructor simply copies the vector of stations and computes the surface from them
0016 AlignableCSCEndcap::AlignableCSCEndcap(const std::vector<AlignableCSCStation*>& cscStations)
0017     : AlignableComposite(cscStations[0]->id(), align::AlignableCSCEndcap) {
0018   theCSCStations.insert(theCSCStations.end(), cscStations.begin(), cscStations.end());
0019 
0020   // maintain also list of components
0021   for (const auto& station : cscStations) {
0022     const auto mother = station->mother();
0023     this->addComponent(station);  // components will be deleted by dtor of AlignableComposite
0024     station->setMother(mother);   // restore previous behaviour where mother is not set
0025   }
0026 
0027   setSurface(computeSurface());
0028   compConstraintType_ = Alignable::CompConstraintType::POSITION_Z;
0029 }
0030 
0031 /// Return AlignableCSCEndcap station at given index
0032 AlignableCSCStation& AlignableCSCEndcap::station(int i) {
0033   if (i >= size())
0034     throw cms::Exception("LogicError") << "Station index (" << i << ") out of range";
0035 
0036   return *theCSCStations[i];
0037 }
0038 
0039 /// Returns surface corresponding to current position
0040 /// and orientation, as given by average on all components
0041 AlignableSurface AlignableCSCEndcap::computeSurface() {
0042   return AlignableSurface(computePosition(), computeOrientation());
0043 }
0044 
0045 /// Compute average z position from all components (x and y forced to 0)
0046 AlignableCSCEndcap::PositionType AlignableCSCEndcap::computePosition() {
0047   float zz = 0.;
0048 
0049   for (std::vector<AlignableCSCStation*>::iterator ilayer = theCSCStations.begin(); ilayer != theCSCStations.end();
0050        ilayer++)
0051     zz += (*ilayer)->globalPosition().z();
0052 
0053   zz /= static_cast<float>(theCSCStations.size());
0054 
0055   return PositionType(0.0, 0.0, zz);
0056 }
0057 
0058 /// Just initialize to default given by default constructor of a RotationType
0059 AlignableCSCEndcap::RotationType AlignableCSCEndcap::computeOrientation() { return RotationType(); }
0060 
0061 /// Output Half Barrel information
0062 std::ostream& operator<<(std::ostream& os, const AlignableCSCEndcap& b) {
0063   os << "This EndCap contains " << b.theCSCStations.size() << " CSC stations" << std::endl;
0064   os << "(phi, r, z) =  (" << b.globalPosition().phi() << "," << b.globalPosition().perp() << ","
0065      << b.globalPosition().z();
0066   os << "),  orientation:" << std::endl << b.globalRotation() << std::endl;
0067   return os;
0068 }
0069 
0070 /// Recursive printout of whole Half Barrel structure
0071 void AlignableCSCEndcap::dump(void) const {
0072   edm::LogInfo("AlignableDump") << (*this);
0073   for (std::vector<AlignableCSCStation*>::const_iterator iLayer = theCSCStations.begin();
0074        iLayer != theCSCStations.end();
0075        iLayer++)
0076     (*iLayer)->dump();
0077 }
0078 
0079 //__________________________________________________________________________________________________
0080 
0081 Alignments* AlignableCSCEndcap::alignments(void) const {
0082   Alignments* m_alignments = new Alignments();
0083 
0084   // Add components recursively
0085   for (const auto& i : this->components()) {
0086     std::unique_ptr<Alignments> tmpAlignments{i->alignments()};
0087     std::copy(tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(), std::back_inserter(m_alignments->m_align));
0088   }
0089 
0090   // sort by rawId
0091   std::sort(m_alignments->m_align.begin(), m_alignments->m_align.end());
0092 
0093   return m_alignments;
0094 }
0095 
0096 //__________________________________________________________________________________________________
0097 
0098 AlignmentErrorsExtended* AlignableCSCEndcap::alignmentErrors(void) const {
0099   AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
0100 
0101   // Add components recursively
0102   for (const auto& i : this->components()) {
0103     std::unique_ptr<AlignmentErrorsExtended> tmpAlignmentErrorsExtended{i->alignmentErrors()};
0104     std::copy(tmpAlignmentErrorsExtended->m_alignError.begin(),
0105               tmpAlignmentErrorsExtended->m_alignError.end(),
0106               std::back_inserter(m_alignmentErrors->m_alignError));
0107   }
0108 
0109   // sort by rawId
0110   std::sort(m_alignmentErrors->m_alignError.begin(), m_alignmentErrors->m_alignError.end());
0111 
0112   return m_alignmentErrors;
0113 }