CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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   align::Alignables& halfBarrels = alignableLists_.find(subDet + "HalfBarrel");
00138 
00139   const std::string barrelName(subDet + "Barrel");
00140   align::Alignables &barrel = alignableLists_.get(barrelName);
00141   barrel.reserve(1);
00142   barrel.push_back(new AlignableComposite(halfBarrels[0]->id(),AlignableObjectId::stringToId(barrelName),
00143                                           RotationType()));
00144   barrel[0]->addComponent(halfBarrels[0]);
00145   barrel[0]->addComponent(halfBarrels[1]);
00146 }
00147 
00148 //__________________________________________________________________________________________________
00149 void AlignableTracker::buildTPB()
00150 {
00151   AlignableBuilder builder(align::TPBModule, tkCounters_ );
00152 
00153   builder.addLevelInfo(align::TPBLadder    , true, 22); // max 22 ladders per layer
00154   builder.addLevelInfo(align::TPBLayer     , false, 3); // 3 layers per half barrel
00155   builder.addLevelInfo(align::TPBHalfBarrel, false, 2); // 2 half barrels in TPB
00156   builder.buildAll( alignableLists_ );
00157 
00158   buildBarrel("TPB");
00159 }
00160 
00161 //__________________________________________________________________________________________________
00162 void AlignableTracker::buildTPE()
00163 {
00164   AlignableBuilder builder(align::TPEModule, tkCounters_);
00165 
00166   builder.addLevelInfo(align::TPEPanel       , true,  2); // 2 panels per blade
00167   builder.addLevelInfo(align::TPEBlade       , true, 12); // 12 blades per half disk
00168   builder.addLevelInfo(align::TPEHalfDisk    , false, 3); // max 3 disks per cylinder
00169   builder.addLevelInfo(align::TPEHalfCylinder, false, 2); // 2 HC per endcap
00170   builder.addLevelInfo(align::TPEEndcap      , false, 2); // 2 endcaps in TPE
00171   builder.buildAll( alignableLists_ );
00172 }
00173 
00174 //__________________________________________________________________________________________________
00175 void AlignableTracker::buildTIB()
00176 {
00177   AlignableBuilder builder(align::TIBModule, tkCounters_);
00178 
00179   builder.addLevelInfo(align::TIBString    , true, 28); // max 22 strings per surface
00180   builder.addLevelInfo(align::TIBSurface   , false, 2); // 2 surfaces per half shell
00181   builder.addLevelInfo(align::TIBHalfShell , false, 2); // 2 half shells per layer
00182   builder.addLevelInfo(align::TIBLayer     , false, 4); // 4 layers per half barrel
00183   builder.addLevelInfo(align::TIBHalfBarrel, false, 2); // 2 half barrels in TIB
00184   builder.buildAll( alignableLists_ );
00185 
00186   buildBarrel("TIB");
00187 }
00188 
00189 //__________________________________________________________________________________________________
00190 void AlignableTracker::buildTID()
00191 {
00192   AlignableBuilder builder(align::TIDModule, tkCounters_);
00193 
00194   builder.addLevelInfo(align::TIDSide  , false, 2); // 2 sides per ring
00195   builder.addLevelInfo(align::TIDRing  , false, 3); // 3 rings per disk
00196   builder.addLevelInfo(align::TIDDisk  , false, 3); // 3 disks per endcap
00197   builder.addLevelInfo(align::TIDEndcap, false, 2); // 2 endcaps in TID
00198   builder.buildAll( alignableLists_ );
00199 }
00200 
00201 //__________________________________________________________________________________________________
00202 void AlignableTracker::buildTOB()
00203 {
00204   AlignableBuilder builder(align::TOBModule, tkCounters_);
00205 
00206   builder.addLevelInfo(align::TOBRod       , true, 74); // max 74 rods per layer
00207   builder.addLevelInfo(align::TOBLayer     , false, 6); // 6 layers per half barrel
00208   builder.addLevelInfo(align::TOBHalfBarrel, false, 2); // 2 half barrels in TOB
00209   builder.buildAll( alignableLists_ );
00210 
00211   buildBarrel("TOB");
00212 }
00213 
00214 //__________________________________________________________________________________________________
00215 void AlignableTracker::buildTEC()
00216 {
00217   AlignableBuilder builder(align::TECModule, tkCounters_);
00218 
00219   builder.addLevelInfo(align::TECRing  , true,  7); // max 7 rings per petal
00220   builder.addLevelInfo(align::TECPetal , true,  8); // 8 petals per side
00221   builder.addLevelInfo(align::TECSide  , false, 2); // 2 sides per disk
00222   builder.addLevelInfo(align::TECDisk  , false, 9); // 9 disks per endcap
00223   builder.addLevelInfo(align::TECEndcap, false, 2); // 2 endcaps in TEC
00224   builder.buildAll( alignableLists_ );
00225 }
00226 
00227 //__________________________________________________________________________________________________
00228 void AlignableTracker::buildTRK()
00229 {
00230   // Build pixel, strip and full tracker 'by hand':
00231   
00232   // First create pixel:
00233   const align::Alignables &pixelBarrel = alignableLists_.find("TPBBarrel");
00234   const align::Alignables &pixelEndcap = alignableLists_.find("TPEEndcap");
00235   align::Alignables &pixel = alignableLists_.get("Pixel");
00236   pixel.reserve(1);
00237   pixel.push_back(new AlignableComposite(pixelBarrel[0]->id(), align::Pixel, RotationType()));
00238   pixel[0]->addComponent(pixelBarrel[0]);
00239   pixel[0]->addComponent(pixelEndcap[0]);
00240   pixel[0]->addComponent(pixelEndcap[1]);
00241 
00242   // Now create strip:
00243   const align::Alignables &innerBarrel = alignableLists_.find("TIBBarrel");
00244   const align::Alignables &outerBarrel = alignableLists_.find("TOBBarrel");
00245   const align::Alignables &innerEndcap = alignableLists_.find("TIDEndcap");
00246   const align::Alignables &outerEndcap = alignableLists_.find("TECEndcap");
00247   align::Alignables &strip = alignableLists_.get("Strip");
00248   strip.reserve(1);
00249   strip.push_back(new AlignableComposite(innerBarrel[0]->id(), align::Strip, RotationType()));
00250   strip[0]->addComponent(innerBarrel[0]);
00251   strip[0]->addComponent(innerEndcap[0]);
00252   strip[0]->addComponent(innerEndcap[1]);
00253   strip[0]->addComponent(outerBarrel[0]);
00254   strip[0]->addComponent(outerEndcap[0]);
00255   strip[0]->addComponent(outerEndcap[1]);
00256 
00257   // Finally add strip and pixel to tracker - that of course already exists:
00258   align::Alignables &tracker = alignableLists_.get("Tracker");
00259   tracker.reserve(1);
00260   tracker.push_back(this);
00261   this->addComponent(pixel[0]); // add to tracker
00262   this->addComponent(strip[0]); // add to tracker
00263 
00264 }
00265 
00266 
00267 //__________________________________________________________________________________________________
00268 align::Alignables AlignableTracker::merge( const Alignables& list1,
00269                                            const Alignables& list2 ) const
00270 {
00271   Alignables all = list1;
00272 
00273   all.insert( all.end(), list2.begin(), list2.end() );
00274 
00275   return all;
00276 }
00277 
00278 
00279 //__________________________________________________________________________________________________
00280 Alignments* AlignableTracker::alignments( void ) const
00281 {
00282 
00283   align::Alignables comp = this->components();
00284   Alignments* m_alignments = new Alignments();
00285   // Add components recursively
00286   for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00287     {
00288       Alignments* tmpAlignments = (*i)->alignments();
00289       std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(), 
00290                                  std::back_inserter(m_alignments->m_align) );
00291           delete tmpAlignments;
00292     }
00293 
00294   std::sort( m_alignments->m_align.begin(), m_alignments->m_align.end(), 
00295                          lessAlignmentDetId<AlignTransform>() );
00296 
00297   return m_alignments;
00298 
00299 }
00300 
00301 
00302 //__________________________________________________________________________________________________
00303 AlignmentErrors* AlignableTracker::alignmentErrors( void ) const
00304 {
00305 
00306   align::Alignables comp = this->components();
00307   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00308 
00309   // Add components recursively
00310   for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00311     {
00312           AlignmentErrors* tmpAlignmentErrors = (*i)->alignmentErrors();
00313       std::copy( tmpAlignmentErrors->m_alignError.begin(), tmpAlignmentErrors->m_alignError.end(), 
00314                                  std::back_inserter(m_alignmentErrors->m_alignError) );
00315           delete tmpAlignmentErrors;
00316     }
00317 
00318   std::sort( m_alignmentErrors->m_alignError.begin(), m_alignmentErrors->m_alignError.end(), 
00319                          lessAlignmentDetId<AlignTransformError>() );
00320 
00321   return m_alignmentErrors;
00322 
00323 }