CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/TrackerAlignment/src/AlignableTracker.cc

Go to the documentation of this file.
00001 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00002 
00003 #include "FWCore/Utilities/interface/Exception.h"
00004  
00005 // Geometry
00006 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00007 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00008 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00009 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00010 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00011 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00012 
00013 // Alignment
00014 #include "Alignment/CommonAlignment/interface/AlignableBuilder.h"
00015 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
00016 #include "Alignment/TrackerAlignment/interface/AlignableSiStripDet.h"
00017 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
00018 
00019 #include "CondFormats/Alignment/interface/Alignments.h"
00020 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00021 #include "CondFormats/Alignment/interface/AlignmentSorter.h"
00022 
00023 //__________________________________________________________________________________________________
00024 AlignableTracker::AlignableTracker( const TrackerGeometry* tkGeom ):
00025   AlignableComposite( 0, align::Tracker, RotationType() ) // id not yet known
00026 {
00027 
00028   // Get levels from geometry
00029   // for strip we create also <TIB/TID/TOB/TEC>ModuleUnit list for 1D components of 2D layers
00030   detsToAlignables(tkGeom->detsPXB(), "TPBModule");
00031   detsToAlignables(tkGeom->detsPXF(), "TPEModule");
00032   detsToAlignables(tkGeom->detsTIB(), "TIBModule");
00033   detsToAlignables(tkGeom->detsTID(), "TIDModule");
00034   detsToAlignables(tkGeom->detsTOB(), "TOBModule");
00035   detsToAlignables(tkGeom->detsTEC(), "TECModule");
00036 
00037   buildTPB();
00038   buildTPE();
00039   buildTIB();
00040   buildTID();
00041   buildTOB();
00042   buildTEC();
00043   buildTRK();
00044 
00045   theId = this->components()[0]->id(); // as all composites: id of first component
00046 }
00047 
00048 
00049 //__________________________________________________________________________________________________
00050 void AlignableTracker::detsToAlignables( const TrackingGeometry::DetContainer& dets,
00051                                          const std::string& moduleName )
00052 {
00053   unsigned int nDet = dets.size();
00054 
00055   align::Alignables& alis = alignableLists_.get(moduleName);
00056   alis.reserve(nDet);
00057   align::Alignables *aliUnits = 0;// If we need also units, they will be at moduleName + "Unit".
00058 
00059   for (unsigned int i = 0; i < nDet; ++i) {
00060    
00061     const unsigned int subdetId = dets[i]->geographicalId().subdetId();//don't check det()==Tracker
00062     if (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) {
00063       // Treat all pixel dets in same way with one AlignableDetUnit.
00064       const GeomDetUnit *detUnit = dynamic_cast<const GeomDetUnit*>(dets[i]);
00065       if (!detUnit) {
00066         throw cms::Exception("BadHierarchy") 
00067           << "[AlignableTracker] Pixel GeomDet (subdetector " << subdetId << ") not GeomDetUnit.\n";
00068       }
00069       alis.push_back(new AlignableDetUnit(detUnit));
00070 
00071       // Add pixel modules to list of units since they are in fact units
00072       if (!aliUnits) {
00073         aliUnits = &alignableLists_.get(moduleName + "Unit");
00074         aliUnits->reserve(576); // ugly hardcode to save some memory due to vector doubling
00075       }
00076       aliUnits->push_back(alis.back());
00077     
00078     } else if (subdetId == SiStripDetId::TIB || subdetId == SiStripDetId::TID
00079                || subdetId == SiStripDetId::TOB || subdetId == SiStripDetId::TEC) {
00080       // In strip we have:
00081       // 1) 'Pure' 1D-modules like TOB layers 3-6 (not glued): AlignableDetUnit
00082       // 2) Composite 2D-modules like TOB layers 1&2 (not glued): AlignableDet
00083       // 3) The two 1D-components of case 2 (glued): AlignableDetUnit that is constructed
00084       //      inside AlignableDet-constructor of 'mother', only need to add to alignableLists_
00085       const SiStripDetId detId(dets[i]->geographicalId());
00086       if (!detId.glued()) { // 2D- or 'pure' 1D-module
00087         if (dets[i]->components().size()) { // 2D-module
00088           const GluedGeomDet *gluedDet = dynamic_cast<GluedGeomDet*>(dets[i]);
00089           if (!gluedDet) {
00090             throw cms::Exception("LogicError") 
00091               << "[AlignableTracker]" << "dynamic_cast<GluedGeomDet*> failed.\n";
00092           }
00093           alis.push_back(new AlignableSiStripDet(gluedDet)); // components constructed within
00094           const align::Alignables detUnits(alis.back()->components());
00095           // Ensure pointer existence and make list available via moduleName appended with "Unit"
00096           if (!aliUnits) {
00097             aliUnits = &alignableLists_.get(moduleName + "Unit");
00098             aliUnits->reserve(576); // ugly hardcode to save some memory due to vector doubling
00099           }
00100           aliUnits->insert(aliUnits->end(), detUnits.begin(), detUnits.end()); // only 2...
00101         } else { // no components: pure 1D-module
00102           const GeomDetUnit *detUnit = dynamic_cast<const GeomDetUnit*>(dets[i]);
00103           if (!detUnit) {
00104             throw cms::Exception("BadHierarchy") 
00105               << "[AlignableTracker] pure 1D GeomDet (subdetector " << subdetId << ") not GeomDetUnit.\n";
00106           }
00107           alis.push_back(new AlignableDetUnit(detUnit));
00108 
00109           // Add pure 1D-modules to list of units since they are in fact units
00110           if (!aliUnits) {
00111             aliUnits = &alignableLists_.get(moduleName + "Unit");
00112             aliUnits->reserve(576); // ugly hardcode to save some memory due to vector doubling
00113           }
00114           aliUnits->push_back(alis.back());
00115         }
00116       } // no else: glued components of AlignableDet constructed within AlignableDet, see above
00117     } else {
00118       throw cms::Exception("LogicError") 
00119         << "[AlignableTracker] GeomDet of unknown subdetector.";
00120     }
00121   }
00122 
00123   LogDebug("Alignment") << "@SUB=AlignableTracker"
00124                         << alis.size() << " AlignableDet(Unit)s for " << moduleName;
00125   if (aliUnits) {
00126     LogDebug("Alignment") << "@SUB=AlignableTracker"
00127                           << aliUnits->size() << " AlignableDetUnits for " 
00128                           << moduleName + "Unit (capacity = " << aliUnits->capacity() << ").";
00129   }
00130   
00131 }
00132 
00133 
00134 //__________________________________________________________________________________________________
00135 void AlignableTracker::buildBarrel(const std::string& subDet)
00136 {
00137   AlignableObjectId objId;
00138 
00139   align::Alignables& halfBarrels = alignableLists_.find(subDet + "HalfBarrel");
00140 
00141   const std::string barrelName(subDet + "Barrel");
00142   align::Alignables &barrel = alignableLists_.get(barrelName);
00143   barrel.reserve(1);
00144   barrel.push_back(new AlignableComposite(halfBarrels[0]->id(), objId.nameToType(barrelName),
00145                                           RotationType()));
00146   barrel[0]->addComponent(halfBarrels[0]);
00147   barrel[0]->addComponent(halfBarrels[1]);
00148 }
00149 
00150 //__________________________________________________________________________________________________
00151 void AlignableTracker::buildTPB()
00152 {
00153   AlignableBuilder builder(align::TPBModule, tkCounters_ );
00154 
00155   builder.addLevelInfo(align::TPBLadder    , true, 22); // max 22 ladders per layer
00156   builder.addLevelInfo(align::TPBLayer     , false, 3); // 3 layers per half barrel
00157   builder.addLevelInfo(align::TPBHalfBarrel, false, 2); // 2 half barrels in TPB
00158   builder.buildAll( alignableLists_ );
00159 
00160   buildBarrel("TPB");
00161 }
00162 
00163 //__________________________________________________________________________________________________
00164 void AlignableTracker::buildTPE()
00165 {
00166   AlignableBuilder builder(align::TPEModule, tkCounters_);
00167 
00168   builder.addLevelInfo(align::TPEPanel       , true,  2); // 2 panels per blade
00169   builder.addLevelInfo(align::TPEBlade       , true, 12); // 12 blades per half disk
00170   builder.addLevelInfo(align::TPEHalfDisk    , false, 3); // max 3 disks per cylinder
00171   builder.addLevelInfo(align::TPEHalfCylinder, false, 2); // 2 HC per endcap
00172   builder.addLevelInfo(align::TPEEndcap      , false, 2); // 2 endcaps in TPE
00173   builder.buildAll( alignableLists_ );
00174 }
00175 
00176 //__________________________________________________________________________________________________
00177 void AlignableTracker::buildTIB()
00178 {
00179   AlignableBuilder builder(align::TIBModule, tkCounters_);
00180 
00181   builder.addLevelInfo(align::TIBString    , true, 28); // max 22 strings per surface
00182   builder.addLevelInfo(align::TIBSurface   , false, 2); // 2 surfaces per half shell
00183   builder.addLevelInfo(align::TIBHalfShell , false, 2); // 2 half shells per layer
00184   builder.addLevelInfo(align::TIBLayer     , false, 4); // 4 layers per half barrel
00185   builder.addLevelInfo(align::TIBHalfBarrel, false, 2); // 2 half barrels in TIB
00186   builder.buildAll( alignableLists_ );
00187 
00188   buildBarrel("TIB");
00189 }
00190 
00191 //__________________________________________________________________________________________________
00192 void AlignableTracker::buildTID()
00193 {
00194   AlignableBuilder builder(align::TIDModule, tkCounters_);
00195 
00196   builder.addLevelInfo(align::TIDSide  , false, 2); // 2 sides per ring
00197   builder.addLevelInfo(align::TIDRing  , false, 3); // 3 rings per disk
00198   builder.addLevelInfo(align::TIDDisk  , false, 3); // 3 disks per endcap
00199   builder.addLevelInfo(align::TIDEndcap, false, 2); // 2 endcaps in TID
00200   builder.buildAll( alignableLists_ );
00201 }
00202 
00203 //__________________________________________________________________________________________________
00204 void AlignableTracker::buildTOB()
00205 {
00206   AlignableBuilder builder(align::TOBModule, tkCounters_);
00207 
00208   builder.addLevelInfo(align::TOBRod       , true, 74); // max 74 rods per layer
00209   builder.addLevelInfo(align::TOBLayer     , false, 6); // 6 layers per half barrel
00210   builder.addLevelInfo(align::TOBHalfBarrel, false, 2); // 2 half barrels in TOB
00211   builder.buildAll( alignableLists_ );
00212 
00213   buildBarrel("TOB");
00214 }
00215 
00216 //__________________________________________________________________________________________________
00217 void AlignableTracker::buildTEC()
00218 {
00219   AlignableBuilder builder(align::TECModule, tkCounters_);
00220 
00221   builder.addLevelInfo(align::TECRing  , true,  7); // max 7 rings per petal
00222   builder.addLevelInfo(align::TECPetal , true,  8); // 8 petals per side
00223   builder.addLevelInfo(align::TECSide  , false, 2); // 2 sides per disk
00224   builder.addLevelInfo(align::TECDisk  , false, 9); // 9 disks per endcap
00225   builder.addLevelInfo(align::TECEndcap, false, 2); // 2 endcaps in TEC
00226   builder.buildAll( alignableLists_ );
00227 }
00228 
00229 //__________________________________________________________________________________________________
00230 void AlignableTracker::buildTRK()
00231 {
00232   // Build pixel, strip and full tracker 'by hand':
00233   
00234   // First create pixel:
00235   const align::Alignables &pixelBarrel = alignableLists_.find("TPBBarrel");
00236   const align::Alignables &pixelEndcap = alignableLists_.find("TPEEndcap");
00237   align::Alignables &pixel = alignableLists_.get("Pixel");
00238   pixel.reserve(1);
00239   pixel.push_back(new AlignableComposite(pixelBarrel[0]->id(), align::Pixel, RotationType()));
00240   pixel[0]->addComponent(pixelBarrel[0]);
00241   pixel[0]->addComponent(pixelEndcap[0]);
00242   pixel[0]->addComponent(pixelEndcap[1]);
00243 
00244   // Now create strip:
00245   const align::Alignables &innerBarrel = alignableLists_.find("TIBBarrel");
00246   const align::Alignables &outerBarrel = alignableLists_.find("TOBBarrel");
00247   const align::Alignables &innerEndcap = alignableLists_.find("TIDEndcap");
00248   const align::Alignables &outerEndcap = alignableLists_.find("TECEndcap");
00249   align::Alignables &strip = alignableLists_.get("Strip");
00250   strip.reserve(1);
00251   strip.push_back(new AlignableComposite(innerBarrel[0]->id(), align::Strip, RotationType()));
00252   strip[0]->addComponent(innerBarrel[0]);
00253   strip[0]->addComponent(innerEndcap[0]);
00254   strip[0]->addComponent(innerEndcap[1]);
00255   strip[0]->addComponent(outerBarrel[0]);
00256   strip[0]->addComponent(outerEndcap[0]);
00257   strip[0]->addComponent(outerEndcap[1]);
00258 
00259   // Finally add strip and pixel to tracker - that of course already exists:
00260   align::Alignables &tracker = alignableLists_.get("Tracker");
00261   tracker.reserve(1);
00262   tracker.push_back(this);
00263   this->addComponent(pixel[0]); // add to tracker
00264   this->addComponent(strip[0]); // add to tracker
00265 
00266 }
00267 
00268 
00269 //__________________________________________________________________________________________________
00270 align::Alignables AlignableTracker::merge( const Alignables& list1,
00271                                            const Alignables& list2 ) const
00272 {
00273   Alignables all = list1;
00274 
00275   all.insert( all.end(), list2.begin(), list2.end() );
00276 
00277   return all;
00278 }
00279 
00280 
00281 //__________________________________________________________________________________________________
00282 Alignments* AlignableTracker::alignments( void ) const
00283 {
00284 
00285   align::Alignables comp = this->components();
00286   Alignments* m_alignments = new Alignments();
00287   // Add components recursively
00288   for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00289     {
00290       Alignments* tmpAlignments = (*i)->alignments();
00291       std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(), 
00292                                  std::back_inserter(m_alignments->m_align) );
00293           delete tmpAlignments;
00294     }
00295 
00296   std::sort( m_alignments->m_align.begin(), m_alignments->m_align.end(), 
00297                          lessAlignmentDetId<AlignTransform>() );
00298 
00299   return m_alignments;
00300 
00301 }
00302 
00303 
00304 //__________________________________________________________________________________________________
00305 AlignmentErrors* AlignableTracker::alignmentErrors( void ) const
00306 {
00307 
00308   align::Alignables comp = this->components();
00309   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00310 
00311   // Add components recursively
00312   for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00313     {
00314           AlignmentErrors* tmpAlignmentErrors = (*i)->alignmentErrors();
00315       std::copy( tmpAlignmentErrors->m_alignError.begin(), tmpAlignmentErrors->m_alignError.end(), 
00316                                  std::back_inserter(m_alignmentErrors->m_alignError) );
00317           delete tmpAlignmentErrors;
00318     }
00319 
00320   std::sort( m_alignmentErrors->m_alignError.begin(), m_alignmentErrors->m_alignError.end(), 
00321                          lessAlignmentDetId<AlignTransformError>() );
00322 
00323   return m_alignmentErrors;
00324 
00325 }