00001 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00002
00003 #include "FWCore/Utilities/interface/Exception.h"
00004
00005
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
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() )
00026 {
00027
00028
00029
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();
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;
00058
00059 for (unsigned int i = 0; i < nDet; ++i) {
00060
00061 const unsigned int subdetId = dets[i]->geographicalId().subdetId();
00062 if (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) {
00063
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
00072 if (!aliUnits) {
00073 aliUnits = &alignableLists_.get(moduleName + "Unit");
00074 aliUnits->reserve(576);
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
00081
00082
00083
00084
00085 const SiStripDetId detId(dets[i]->geographicalId());
00086 if (!detId.glued()) {
00087 if (dets[i]->components().size()) {
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));
00094 const align::Alignables detUnits(alis.back()->components());
00095
00096 if (!aliUnits) {
00097 aliUnits = &alignableLists_.get(moduleName + "Unit");
00098 aliUnits->reserve(576);
00099 }
00100 aliUnits->insert(aliUnits->end(), detUnits.begin(), detUnits.end());
00101 } else {
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
00110 if (!aliUnits) {
00111 aliUnits = &alignableLists_.get(moduleName + "Unit");
00112 aliUnits->reserve(576);
00113 }
00114 aliUnits->push_back(alis.back());
00115 }
00116 }
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);
00154 builder.addLevelInfo(align::TPBLayer , false, 3);
00155 builder.addLevelInfo(align::TPBHalfBarrel, false, 2);
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);
00167 builder.addLevelInfo(align::TPEBlade , true, 12);
00168 builder.addLevelInfo(align::TPEHalfDisk , false, 3);
00169 builder.addLevelInfo(align::TPEHalfCylinder, false, 2);
00170 builder.addLevelInfo(align::TPEEndcap , false, 2);
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);
00180 builder.addLevelInfo(align::TIBSurface , false, 2);
00181 builder.addLevelInfo(align::TIBHalfShell , false, 2);
00182 builder.addLevelInfo(align::TIBLayer , false, 4);
00183 builder.addLevelInfo(align::TIBHalfBarrel, false, 2);
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);
00195 builder.addLevelInfo(align::TIDRing , false, 3);
00196 builder.addLevelInfo(align::TIDDisk , false, 3);
00197 builder.addLevelInfo(align::TIDEndcap, false, 2);
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);
00207 builder.addLevelInfo(align::TOBLayer , false, 6);
00208 builder.addLevelInfo(align::TOBHalfBarrel, false, 2);
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);
00220 builder.addLevelInfo(align::TECPetal , true, 8);
00221 builder.addLevelInfo(align::TECSide , false, 2);
00222 builder.addLevelInfo(align::TECDisk , false, 9);
00223 builder.addLevelInfo(align::TECEndcap, false, 2);
00224 builder.buildAll( alignableLists_ );
00225 }
00226
00227
00228 void AlignableTracker::buildTRK()
00229 {
00230
00231
00232
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
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
00258 align::Alignables &tracker = alignableLists_.get("Tracker");
00259 tracker.reserve(1);
00260 tracker.push_back(this);
00261 this->addComponent(pixel[0]);
00262 this->addComponent(strip[0]);
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
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
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 }