00001
00009
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011
00012 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
00013 #include "Geometry/DTGeometry/interface/DTChamber.h"
00014 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00015 #include <Geometry/DTGeometry/interface/DTLayer.h>
00016 #include "CondFormats/Alignment/interface/Alignments.h"
00017 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00018 #include "CondFormats/Alignment/interface/AlignmentSorter.h"
00019
00020
00021 #include "Alignment/MuonAlignment/interface/AlignableDTChamber.h"
00022 #include "Alignment/MuonAlignment/interface/AlignableCSCChamber.h"
00023 #include "Alignment/MuonAlignment/interface/AlignableDTStation.h"
00024 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00025 #include "Alignment/MuonAlignment/interface/AlignableCSCStation.h"
00026 #include "Alignment/MuonAlignment/interface/AlignableDTWheel.h"
00027 #include "Alignment/MuonAlignment/interface/AlignableDTBarrel.h"
00028 #include "Alignment/MuonAlignment/interface/AlignableCSCEndcap.h"
00029
00030
00031 AlignableMuon::AlignableMuon( const DTGeometry* dtGeometry , const CSCGeometry* cscGeometry )
00032 : AlignableComposite(0, align::AlignableMuon)
00033 {
00034
00035
00036 buildDTBarrel( dtGeometry );
00037
00038
00039 buildCSCEndcap( cscGeometry );
00040
00041
00042 recursiveSetMothers( this );
00043
00044
00045 theId = this->components()[0]->id();
00046
00047 edm::LogInfo("AlignableMuon") << "Constructing alignable muon objects DONE";
00048
00049
00050 }
00051
00052
00053 AlignableMuon::~AlignableMuon()
00054 {
00055
00056 for ( align::Alignables::iterator iter=theMuonComponents.begin();
00057 iter != theMuonComponents.end(); iter++){
00058 delete *iter;
00059 }
00060
00061
00062 }
00063
00064
00065
00066 void AlignableMuon::buildDTBarrel( const DTGeometry* pDT )
00067 {
00068
00069 LogDebug("Position") << "Constructing AlignableDTBarrel";
00070
00071
00072 std::vector<AlignableDTChamber*> tmpDTChambersInStation;
00073 std::vector<AlignableDTStation*> tmpDTStationsInWheel;
00074
00075
00076
00077 for( int iwh = -2 ; iwh < 3 ; iwh++ ){
00078
00079
00080 for( int ist = 1 ; ist < 5 ; ist++ ){
00081
00082
00083 std::vector<GeomDet*> theSLs;
00084 for( std::vector<DTChamber*>::const_iterator det = pDT->chambers().begin();
00085 det != pDT->chambers().end(); ++det ){
00086
00087 DTChamberId chamberId = (*det)->id();
00088
00089
00090 int wh = chamberId.wheel();
00091 int st = chamberId.station();
00092
00093
00094
00095 if ( iwh == wh && ist == st ){
00096
00097
00098 AlignableDTChamber* tmpDTChamber = new AlignableDTChamber( *det );
00099
00100
00101 tmpDTChambersInStation.push_back( tmpDTChamber );
00102
00103
00104 }
00105
00106
00107 }
00108
00109
00110 theDTChambers.insert( theDTChambers.end(), tmpDTChambersInStation.begin(),
00111 tmpDTChambersInStation.end() );
00112
00113
00114 AlignableDTStation* tmpDTStation = new AlignableDTStation( tmpDTChambersInStation );
00115
00116
00117 tmpDTStationsInWheel.push_back( tmpDTStation );
00118
00119
00120 tmpDTChambersInStation.clear();
00121
00122
00123 }
00124
00125
00126 theDTStations.insert( theDTStations.end(), tmpDTStationsInWheel.begin(),
00127 tmpDTStationsInWheel.end() );
00128
00129
00130 AlignableDTWheel* tmpWheel = new AlignableDTWheel( tmpDTStationsInWheel );
00131
00132
00133
00134 theDTWheels.push_back( tmpWheel );
00135
00136
00137 tmpDTStationsInWheel.clear();
00138
00139
00140
00141 }
00142
00143
00144 AlignableDTBarrel* tmpDTBarrel = new AlignableDTBarrel( theDTWheels );
00145
00146
00147 theDTBarrel.push_back( tmpDTBarrel );
00148
00149
00150 theMuonComponents.push_back( tmpDTBarrel );
00151
00152
00153 }
00154
00155
00156
00157
00158
00159
00160 void AlignableMuon::buildCSCEndcap( const CSCGeometry* pCSC )
00161 {
00162
00163 LogDebug("Position") << "Constructing AlignableCSCBarrel";
00164
00165
00166 std::vector<AlignableCSCStation*> tmpCSCStationsInEndcap;
00167
00168
00169 for( int iec = 1 ; iec < 3 ; iec++ ){
00170
00171
00172 std::vector<AlignableCSCRing*> tmpCSCRingsInStation;
00173
00174
00175 for( int ist = 1 ; ist < 5 ; ist++ ){
00176
00177
00178 std::vector<AlignableCSCChamber*> tmpCSCChambersInRing;
00179
00180
00181 for ( int iri = 1; iri < 5; iri++ ){
00182
00183
00184 std::vector<CSCChamber*> vc = pCSC->chambers();
00185 for( std::vector<CSCChamber*>::const_iterator det = vc.begin(); det != vc.end(); ++det ){
00186
00187
00188 CSCDetId cscId = (*det)->id();
00189
00190
00191 int ec = cscId.endcap();
00192 int st = cscId.station();
00193 int ri = cscId.ring();
00194
00195
00196
00197 if ( iec == ec && ist == st && iri == ri ) {
00198
00199
00200 AlignableCSCChamber* tmpCSCChamber = new AlignableCSCChamber( *det );
00201
00202
00203 tmpCSCChambersInRing.push_back( tmpCSCChamber );
00204
00205
00206 }
00207
00208
00209 }
00210
00211
00212 if (tmpCSCChambersInRing.size() > 0) {
00213
00214
00215 theCSCChambers.insert( theCSCChambers.end(), tmpCSCChambersInRing.begin(), tmpCSCChambersInRing.end() );
00216
00217
00218 AlignableCSCRing* tmpCSCRing = new AlignableCSCRing( tmpCSCChambersInRing );
00219
00220
00221 tmpCSCRingsInStation.push_back( tmpCSCRing );
00222
00223
00224 tmpCSCChambersInRing.clear();
00225
00226
00227 }
00228
00229
00230 }
00231
00232
00233 AlignableCSCStation* tmpCSCStation = new AlignableCSCStation( tmpCSCRingsInStation );
00234
00235
00236 theCSCRings.insert( theCSCRings.end(), tmpCSCRingsInStation.begin(), tmpCSCRingsInStation.end() );
00237
00238
00239 tmpCSCStationsInEndcap.push_back( tmpCSCStation );
00240
00241
00242 tmpCSCRingsInStation.clear();
00243
00244
00245 }
00246
00247
00248 AlignableCSCEndcap* tmpEndcap = new AlignableCSCEndcap( tmpCSCStationsInEndcap );
00249
00250
00251 theCSCStations.insert( theCSCStations.end(), tmpCSCStationsInEndcap.begin(), tmpCSCStationsInEndcap.end() );
00252
00253
00254 theCSCEndcaps.push_back( tmpEndcap );
00255
00256
00257 tmpCSCStationsInEndcap.clear();
00258
00259
00260 }
00261
00262
00263 theMuonComponents.insert( theMuonComponents.end(), theCSCEndcaps.begin(), theCSCEndcaps.end() );
00264
00265
00266 }
00267
00268
00269 align::Alignables AlignableMuon::DTLayers()
00270 {
00271 align::Alignables result;
00272
00273 align::Alignables chambers = DTChambers();
00274 for (align::Alignables::const_iterator chamberIter = chambers.begin(); chamberIter != chambers.end(); ++chamberIter) {
00275 align::Alignables superlayers = (*chamberIter)->components();
00276 for (align::Alignables::const_iterator superlayerIter = superlayers.begin(); superlayerIter != superlayers.end(); ++superlayerIter) {
00277 align::Alignables layers = (*superlayerIter)->components();
00278 for (align::Alignables::const_iterator layerIter = layers.begin(); layerIter != layers.end(); ++layerIter) {
00279 result.push_back(*layerIter);
00280 }
00281 }
00282 }
00283
00284 return result;
00285 }
00286
00287
00288 align::Alignables AlignableMuon::DTSuperLayers()
00289 {
00290 align::Alignables result;
00291
00292 align::Alignables chambers = DTChambers();
00293 for (align::Alignables::const_iterator chamberIter = chambers.begin(); chamberIter != chambers.end(); ++chamberIter) {
00294 align::Alignables superlayers = (*chamberIter)->components();
00295 for (align::Alignables::const_iterator superlayerIter = superlayers.begin(); superlayerIter != superlayers.end(); ++superlayerIter) {
00296 result.push_back(*superlayerIter);
00297 }
00298 }
00299
00300 return result;
00301 }
00302
00303
00304 align::Alignables AlignableMuon::DTChambers()
00305 {
00306 align::Alignables result;
00307 copy( theDTChambers.begin(), theDTChambers.end(), back_inserter(result) );
00308 return result;
00309 }
00310
00311
00312 align::Alignables AlignableMuon::DTStations()
00313 {
00314 align::Alignables result;
00315 copy( theDTStations.begin(), theDTStations.end(), back_inserter(result) );
00316 return result;
00317 }
00318
00319
00320
00321 align::Alignables AlignableMuon::DTWheels()
00322 {
00323 align::Alignables result;
00324 copy( theDTWheels.begin(), theDTWheels.end(), back_inserter(result) );
00325 return result;
00326 }
00327
00328
00329 align::Alignables AlignableMuon::DTBarrel()
00330 {
00331 align::Alignables result ;
00332 copy( theDTBarrel.begin(), theDTBarrel.end(), back_inserter(result) );
00333 return result;
00334 }
00335
00336
00337 align::Alignables AlignableMuon::CSCLayers()
00338 {
00339 align::Alignables result;
00340
00341 align::Alignables chambers = CSCChambers();
00342 for (align::Alignables::const_iterator chamberIter = chambers.begin(); chamberIter != chambers.end(); ++chamberIter) {
00343 align::Alignables layers = (*chamberIter)->components();
00344 for (align::Alignables::const_iterator layerIter = layers.begin(); layerIter != layers.end(); ++layerIter) {
00345 result.push_back(*layerIter);
00346 }
00347 }
00348
00349 return result;
00350 }
00351
00352
00353 align::Alignables AlignableMuon::CSCChambers()
00354 {
00355 align::Alignables result;
00356 copy( theCSCChambers.begin(), theCSCChambers.end(), back_inserter(result) );
00357 return result;
00358 }
00359
00360
00361 align::Alignables AlignableMuon::CSCRings()
00362 {
00363 align::Alignables result;
00364 copy( theCSCRings.begin(), theCSCRings.end(), back_inserter(result) );
00365 return result;
00366 }
00367
00368
00369 align::Alignables AlignableMuon::CSCStations()
00370 {
00371 align::Alignables result;
00372 copy( theCSCStations.begin(), theCSCStations.end(), back_inserter(result) );
00373 return result;
00374 }
00375
00376
00377 align::Alignables AlignableMuon::CSCEndcaps()
00378 {
00379 align::Alignables result;
00380 copy( theCSCEndcaps.begin(), theCSCEndcaps.end(), back_inserter(result) );
00381 return result;
00382 }
00383
00384
00385
00386 void AlignableMuon::recursiveSetMothers( Alignable* alignable )
00387 {
00388
00389 align::Alignables components = alignable->components();
00390 for ( align::Alignables::iterator iter = components.begin();
00391 iter != components.end(); iter++ )
00392 {
00393 (*iter)->setMother( alignable );
00394 recursiveSetMothers( *iter );
00395 }
00396
00397 }
00398
00399 Alignments* AlignableMuon::alignments( void ) const
00400 {
00401
00402 align::Alignables comp = this->components();
00403 Alignments* m_alignments = new Alignments();
00404
00405 for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00406 {
00407 Alignments* tmpAlignments = (*i)->alignments();
00408 std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(),
00409 std::back_inserter(m_alignments->m_align) );
00410 delete tmpAlignments;
00411 }
00412
00413 std::sort( m_alignments->m_align.begin(), m_alignments->m_align.end(),
00414 lessAlignmentDetId<AlignTransform>() );
00415
00416 return m_alignments;
00417
00418 }
00419
00420 AlignmentErrors* AlignableMuon::alignmentErrors( void ) const
00421 {
00422
00423 align::Alignables comp = this->components();
00424 AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00425
00426
00427 for ( align::Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00428 {
00429 AlignmentErrors* tmpAlignmentErrors = (*i)->alignmentErrors();
00430 std::copy( tmpAlignmentErrors->m_alignError.begin(), tmpAlignmentErrors->m_alignError.end(),
00431 std::back_inserter(m_alignmentErrors->m_alignError) );
00432 delete tmpAlignmentErrors;
00433 }
00434
00435 std::sort( m_alignmentErrors->m_alignError.begin(), m_alignmentErrors->m_alignError.end(),
00436 lessAlignmentDetId<AlignTransformError>() );
00437
00438 return m_alignmentErrors;
00439
00440 }
00441
00442 Alignments* AlignableMuon::dtAlignments( void )
00443 {
00444
00445 Alignments* tmpAlignments = this->DTBarrel().front()->alignments();
00446
00447 return tmpAlignments;
00448
00449 }
00450
00451 AlignmentErrors* AlignableMuon::dtAlignmentErrors( void )
00452 {
00453
00454 AlignmentErrors* tmpAlignmentErrors = this->DTBarrel().front()->alignmentErrors();
00455
00456 return tmpAlignmentErrors;
00457
00458 }
00459
00460 Alignments* AlignableMuon::cscAlignments( void )
00461 {
00462
00463
00464 Alignments* cscEndCap1 = this->CSCEndcaps().front()->alignments();
00465 Alignments* cscEndCap2 = this->CSCEndcaps().back()->alignments();
00466 Alignments* tmpAlignments = new Alignments();
00467
00468 std::copy( cscEndCap1->m_align.begin(), cscEndCap1->m_align.end(), back_inserter( tmpAlignments->m_align ) );
00469 std::copy( cscEndCap2->m_align.begin(), cscEndCap2->m_align.end(), back_inserter( tmpAlignments->m_align ) );
00470
00471 return tmpAlignments;
00472
00473 }
00474
00475 AlignmentErrors* AlignableMuon::cscAlignmentErrors( void )
00476 {
00477
00478
00479 AlignmentErrors* cscEndCap1Errors = this->CSCEndcaps().front()->alignmentErrors();
00480 AlignmentErrors* cscEndCap2Errors = this->CSCEndcaps().back()->alignmentErrors();
00481 AlignmentErrors* tmpAlignmentErrors = new AlignmentErrors();
00482
00483 std::copy(cscEndCap1Errors->m_alignError.begin(), cscEndCap1Errors->m_alignError.end(), back_inserter(tmpAlignmentErrors->m_alignError) );
00484 std::copy(cscEndCap2Errors->m_alignError.begin(), cscEndCap2Errors->m_alignError.end(), back_inserter(tmpAlignmentErrors->m_alignError) );
00485
00486 return tmpAlignmentErrors;
00487
00488 }