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 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);
00156 builder.addLevelInfo(align::TPBLayer , false, 3);
00157 builder.addLevelInfo(align::TPBHalfBarrel, false, 2);
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);
00169 builder.addLevelInfo(align::TPEBlade , true, 12);
00170 builder.addLevelInfo(align::TPEHalfDisk , false, 3);
00171 builder.addLevelInfo(align::TPEHalfCylinder, false, 2);
00172 builder.addLevelInfo(align::TPEEndcap , false, 2);
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);
00182 builder.addLevelInfo(align::TIBSurface , false, 2);
00183 builder.addLevelInfo(align::TIBHalfShell , false, 2);
00184 builder.addLevelInfo(align::TIBLayer , false, 4);
00185 builder.addLevelInfo(align::TIBHalfBarrel, false, 2);
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);
00197 builder.addLevelInfo(align::TIDRing , false, 3);
00198 builder.addLevelInfo(align::TIDDisk , false, 3);
00199 builder.addLevelInfo(align::TIDEndcap, false, 2);
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);
00209 builder.addLevelInfo(align::TOBLayer , false, 6);
00210 builder.addLevelInfo(align::TOBHalfBarrel, false, 2);
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);
00222 builder.addLevelInfo(align::TECPetal , true, 8);
00223 builder.addLevelInfo(align::TECSide , false, 2);
00224 builder.addLevelInfo(align::TECDisk , false, 9);
00225 builder.addLevelInfo(align::TECEndcap, false, 2);
00226 builder.buildAll( alignableLists_ );
00227 }
00228
00229
00230 void AlignableTracker::buildTRK()
00231 {
00232
00233
00234
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
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
00260 align::Alignables &tracker = alignableLists_.get("Tracker");
00261 tracker.reserve(1);
00262 tracker.push_back(this);
00263 this->addComponent(pixel[0]);
00264 this->addComponent(strip[0]);
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
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
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 }