00001
00003
00004
00006
00007 #include <cmath>
00008 #include <algorithm>
00009
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00012 #include "DetectorDescription/Core/interface/DDSolid.h"
00013 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
00014 #include "Geometry/EcalCommonData/interface/DDEcalEndcapAlgo.h"
00015 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00016
00017 #include <CLHEP/Geometry/Transform3D.h>
00018
00019
00020 #include "Geometry/EcalCommonData/interface/DDEcalEndcapTrap.h"
00021
00022
00023 namespace std{} using namespace std;
00024
00025 DDEcalEndcapAlgo::DDEcalEndcapAlgo() :
00026 m_idNameSpace ( "" ),
00027 m_EEMat ( "" ),
00028 m_EEzOff ( 0 ),
00029 m_EEQuaName ( "" ),
00030 m_EEQuaMat ( "" ),
00031 m_EECrysMat ( "" ),
00032 m_EEWallMat ( "" ),
00033 m_EECrysLength ( 0 ) ,
00034 m_EECrysRear ( 0 ) ,
00035 m_EECrysFront ( 0 ) ,
00036 m_EESCELength ( 0 ) ,
00037 m_EESCERear ( 0 ) ,
00038 m_EESCEFront ( 0 ) ,
00039 m_EESCALength ( 0 ) ,
00040 m_EESCARear ( 0 ) ,
00041 m_EESCAFront ( 0 ) ,
00042 m_EESCAWall ( 0 ) ,
00043 m_EESCHLength ( 0 ) ,
00044 m_EESCHSide ( 0 ) ,
00045 m_EEnSCTypes ( 0 ) ,
00046 m_vecEESCProf (),
00047 m_EEnColumns ( 0 ),
00048 m_vecEEShape (),
00049 m_EEnSCCutaway ( 0 ) ,
00050 m_vecEESCCutaway (),
00051 m_EEnSCquad ( 0 ) ,
00052 m_vecEESCCtrs(),
00053 m_EEnCRSC ( 0 ) ,
00054 m_vecEECRCtrs(),
00055 m_cutParms ( 0 ),
00056 m_cutBoxName ( "" ),
00057 m_envName ( "" ),
00058 m_alvName ( "" ),
00059 m_intName ( "" ),
00060 m_cryName ( "" ),
00061 m_PFhalf ( 0 ) ,
00062 m_PFfifth ( 0 ) ,
00063 m_PF45 ( 0 ) ,
00064 m_vecEESCLims (),
00065 m_iLength ( 0 ) ,
00066 m_iXYOff ( 0 ) ,
00067 m_cryZOff ( 0 ) ,
00068 m_zFront ( 0 )
00069 {
00070 edm::LogInfo("EcalGeom") << "DDEcalEndcapAlgo info: Creating an instance" ;
00071 }
00072
00073 DDEcalEndcapAlgo::~DDEcalEndcapAlgo() {}
00074
00075
00076
00077
00078 void DDEcalEndcapAlgo::initialize(const DDNumericArguments & nArgs,
00079 const DDVectorArguments & vArgs,
00080 const DDMapArguments & ,
00081 const DDStringArguments & sArgs,
00082 const DDStringVectorArguments & ) {
00083
00084
00085 m_idNameSpace = DDCurrentNamespace::ns();
00086
00087 m_idNameSpace = parent().name().ns();
00088
00089 m_EEMat = sArgs["EEMat" ] ;
00090 m_EEzOff = nArgs["EEzOff" ] ;
00091
00092 m_EEQuaName = sArgs["EEQuaName" ] ;
00093 m_EEQuaMat = sArgs["EEQuaMat" ] ;
00094 m_EECrysMat = sArgs["EECrysMat" ] ;
00095 m_EEWallMat = sArgs["EEWallMat" ] ;
00096 m_EECrysLength = nArgs["EECrysLength" ] ;
00097 m_EECrysRear = nArgs["EECrysRear" ] ;
00098 m_EECrysFront = nArgs["EECrysFront" ] ;
00099 m_EESCELength = nArgs["EESCELength" ] ;
00100 m_EESCERear = nArgs["EESCERear" ] ;
00101 m_EESCEFront = nArgs["EESCEFront" ] ;
00102 m_EESCALength = nArgs["EESCALength" ] ;
00103 m_EESCARear = nArgs["EESCARear" ] ;
00104 m_EESCAFront = nArgs["EESCAFront" ] ;
00105 m_EESCAWall = nArgs["EESCAWall" ] ;
00106 m_EESCHLength = nArgs["EESCHLength" ] ;
00107 m_EESCHSide = nArgs["EESCHSide" ] ;
00108 m_EEnSCTypes = nArgs["EEnSCTypes"];
00109 m_EEnColumns = nArgs["EEnColumns"];
00110 m_EEnSCCutaway = nArgs["EEnSCCutaway"];
00111 m_EEnSCquad = nArgs["EEnSCquad"];
00112 m_EEnCRSC = nArgs["EEnCRSC"];
00113 m_vecEESCProf = vArgs["EESCProf"];
00114 m_vecEEShape = vArgs["EEShape"];
00115 m_vecEESCCutaway = vArgs["EESCCutaway"];
00116 m_vecEESCCtrs = vArgs["EESCCtrs"];
00117 m_vecEECRCtrs = vArgs["EECRCtrs"];
00118
00119 m_cutBoxName = sArgs["EECutBoxName" ] ;
00120
00121 m_envName = sArgs["EEEnvName" ] ;
00122 m_alvName = sArgs["EEAlvName" ] ;
00123 m_intName = sArgs["EEIntName" ] ;
00124 m_cryName = sArgs["EECryName" ] ;
00125
00126 m_PFhalf = nArgs["EEPFHalf" ] ;
00127 m_PFfifth = nArgs["EEPFFifth" ] ;
00128 m_PF45 = nArgs["EEPF45" ] ;
00129
00130 m_vecEESCLims = vArgs["EESCLims"];
00131
00132 m_iLength = nArgs["EEiLength" ] ;
00133
00134 m_iXYOff = nArgs["EEiXYOff" ] ;
00135
00136 m_cryZOff = nArgs["EECryZOff"] ;
00137
00138 m_zFront = nArgs["EEzFront"] ;
00139
00140
00141 }
00142
00144
00146
00147
00148 DDRotation
00149 DDEcalEndcapAlgo::myrot( const std::string& s,
00150 const DDRotationMatrix& r ) const
00151 {
00152 return DDrot( ddname( m_idNameSpace + ":" + s ), new DDRotationMatrix( r ) ) ;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162 DDMaterial
00163 DDEcalEndcapAlgo::ddmat( const std::string& s ) const
00164 {
00165 return DDMaterial( ddname( s ) ) ;
00166 }
00167
00168 DDName
00169 DDEcalEndcapAlgo::ddname( const std::string& s ) const
00170 {
00171 const pair<std::string,std::string> temp ( DDSplit(s) ) ;
00172 if ( temp.second == "" ) {
00173 return DDName( temp.first,
00174 m_idNameSpace ) ;
00175 } else {
00176 return DDName( temp.first, temp.second );
00177 }
00178 }
00179
00180
00181
00182 void
00183 DDEcalEndcapAlgo::execute( DDCompactView& cpv )
00184 {
00185
00186
00187
00188
00189
00190
00191
00192 const double cutWid ( eeSCERear()/sqrt(2.) ) ;
00193 const DDSolid eeCutBox ( DDSolidFactory::box(
00194 cutBoxName(),
00195 cutWid,
00196 cutWid,
00197 eeSCELength()/sqrt(2.) ) ) ;
00198 m_cutParms = &eeCutBox.parameters() ;
00199
00200
00201 const double zFix ( m_zFront - 3172*mm ) ;
00202
00203
00204 for( unsigned int iC ( 0 ) ; iC != (unsigned int) eenSCquad() ; ++iC )
00205 {
00206 const unsigned int iOff ( 8*iC ) ;
00207 const unsigned int ix ( (unsigned int) eevecEESCCtrs()[ iOff + 0 ] ) ;
00208 const unsigned int iy ( (unsigned int) eevecEESCCtrs()[ iOff + 1 ] ) ;
00209
00210 assert( ix > 0 && ix < 11 && iy >0 && iy < 11 ) ;
00211
00212 m_scrFCtr[ ix - 1 ][ iy - 1 ] = DDTranslation( eevecEESCCtrs()[ iOff + 2 ] ,
00213 eevecEESCCtrs()[ iOff + 4 ] ,
00214 eevecEESCCtrs()[ iOff + 6 ] + zFix ) ;
00215
00216 m_scrRCtr[ ix - 1 ][ iy - 1 ] = DDTranslation( eevecEESCCtrs()[ iOff + 3 ] ,
00217 eevecEESCCtrs()[ iOff + 5 ] ,
00218 eevecEESCCtrs()[ iOff + 7 ] + zFix ) ;
00219 }
00220
00221
00222 for( unsigned int iC ( 0 ) ; iC != 25 ; ++iC )
00223 {
00224 const unsigned int iOff ( 8*iC ) ;
00225 const unsigned int ix ( (unsigned int) eevecEECRCtrs()[ iOff + 0 ] ) ;
00226 const unsigned int iy ( (unsigned int) eevecEECRCtrs()[ iOff + 1 ] ) ;
00227
00228 assert( ix > 0 && ix < 6 && iy >0 && iy < 6 ) ;
00229
00230 m_cryFCtr[ ix - 1 ][ iy - 1 ] = DDTranslation( eevecEECRCtrs()[ iOff + 2 ] ,
00231 eevecEECRCtrs()[ iOff + 4 ] ,
00232 eevecEECRCtrs()[ iOff + 6 ] ) ;
00233
00234 m_cryRCtr[ ix - 1 ][ iy - 1 ] = DDTranslation( eevecEECRCtrs()[ iOff + 3 ] ,
00235 eevecEECRCtrs()[ iOff + 5 ] ,
00236 eevecEECRCtrs()[ iOff + 7 ] ) ;
00237 }
00238
00239 EECreateCR() ;
00240
00241 for( unsigned int isc ( 0 ); isc<eenSCTypes() ; ++isc )
00242 {
00243 EECreateSC( isc+1, cpv );
00244 }
00245
00246 const std::vector<double>& colLimits ( eevecEEShape() );
00247
00248 for( int icol = 1; icol<=int(eenColumns()); icol++ )
00249 {
00250
00251 for( int irow = int(colLimits[2*icol-2]);
00252 irow <= int(colLimits[2*icol-1]) ; ++irow )
00253 {
00254 if( vecEESCLims()[0] <= icol &&
00255 vecEESCLims()[1] >= icol &&
00256 vecEESCLims()[2] <= irow &&
00257 vecEESCLims()[3] >= irow )
00258 {
00259
00260 const unsigned int isctype ( EEGetSCType( icol, irow ) );
00261
00262
00263
00264 DDEcalEndcapTrap scrys( 1, eeSCEFront(), eeSCERear(), eeSCELength() ) ;
00265
00266 scrys.moveto( scrFCtr( icol, irow ),
00267 scrRCtr( icol, irow ) );
00268 scrys.translate( DDTranslation( 0., 0., -eezOff() ) ) ;
00269
00270 DDName rname ( envName( isctype ).name()
00271 + int_to_string( icol ) + "R" + int_to_string( irow ) ) ;
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 cpv.position( envName( isctype ),
00283 eeQuaName(),
00284 100*isctype + 10*(icol-1) + (irow-1),
00285 scrys.centrePos(),
00286 myrot( rname.fullname(), scrys.rotation() ) ) ;
00287 }
00288 }
00289 }
00290 }
00291
00292
00293 void
00294 DDEcalEndcapAlgo::EECreateSC( const unsigned int iSCType ,
00295 DDCompactView& cpv )
00296 {
00297
00298 DDRotation noRot ;
00299
00300 DDLogicalPart eeSCELog;
00301 DDLogicalPart eeSCALog;
00302 DDLogicalPart eeSCILog;
00303
00304
00305
00306 const string anum ( int_to_string(iSCType) ) ;
00307
00308 const double eFront ( 0.5*eeSCEFront() ) ;
00309 const double eRear ( 0.5*eeSCERear() ) ;
00310 const double eAng ( atan((eeSCERear()-eeSCEFront())/(sqrt(2.)*eeSCELength())) ) ;
00311 const double ffived ( 45*deg ) ;
00312 const double zerod ( 0*deg ) ;
00313 DDSolid eeSCEnv ( DDSolidFactory::trap(
00314 ( 1 == iSCType ? envName( iSCType ) : addTmp( envName( iSCType ) ) ),
00315 0.5*eeSCELength(),
00316 eAng,
00317 ffived,
00318 eFront,
00319 eFront,
00320 eFront,
00321 zerod,
00322 eRear,
00323 eRear,
00324 eRear,
00325 zerod ) );
00326
00327 const double aFront ( 0.5*eeSCAFront() ) ;
00328 const double aRear ( 0.5*eeSCARear() ) ;
00329 const double aAng ( atan((eeSCARear()-eeSCAFront())/(sqrt(2.)*eeSCALength())) ) ;
00330 const DDSolid eeSCAlv ( DDSolidFactory::trap(
00331 ( 1== iSCType ? alvName( iSCType ) : addTmp( alvName( iSCType ) ) ),
00332 0.5*eeSCALength(),
00333 aAng,
00334 ffived,
00335 aFront,
00336 aFront,
00337 aFront,
00338 zerod,
00339 aRear,
00340 aRear,
00341 aRear,
00342 zerod ) );
00343
00344 const double dwall ( eeSCAWall() ) ;
00345 const double iFront ( aFront - dwall ) ;
00346 const double iRear ( iFront ) ;
00347 const double iLen ( iLength() ) ;
00348 const DDSolid eeSCInt ( DDSolidFactory::trap(
00349 ( 1==iSCType ? intName( iSCType ) : addTmp( intName( iSCType ) ) ),
00350 iLen/2.,
00351 atan((eeSCARear()-eeSCAFront())/(sqrt(2.)*eeSCALength())),
00352 ffived,
00353 iFront,
00354 iFront,
00355 iFront,
00356 zerod,
00357 iRear,
00358 iRear,
00359 iRear,
00360 zerod ) );
00361
00362 const double dz ( -0.5*( eeSCELength() - eeSCALength() ) ) ;
00363 const double dxy ( 0.5* dz * (eeSCERear() - eeSCEFront())/eeSCELength() ) ;
00364 const double zIOff ( -( eeSCALength() - iLen )/2. ) ;
00365 const double xyIOff ( iXYOff() ) ;
00366
00367 if( 1 == iSCType )
00368 {
00369 eeSCELog = DDLogicalPart( envName( iSCType ), eeMat(), eeSCEnv );
00370 eeSCALog = DDLogicalPart( alvName( iSCType ), eeWallMat(), eeSCAlv );
00371 eeSCILog = DDLogicalPart( intName( iSCType ), eeMat(), eeSCInt );
00372 }
00373 else
00374 {
00375 const double half ( (*m_cutParms)[0] - eePFHalf() *eeCrysRear() ) ;
00376 const double fifth ( (*m_cutParms)[0] + eePFFifth()*eeCrysRear() ) ;
00377 const double fac ( eePF45() ) ;
00378
00379 const double zmm ( 0*mm ) ;
00380
00381 DDTranslation cutTra ( 2 == iSCType ? DDTranslation( zmm, half, zmm ) :
00382 ( 3 == iSCType ? DDTranslation( half, zmm, zmm ) :
00383 ( 4 == iSCType ? DDTranslation( zmm, -fifth, zmm ) :
00384 ( 5 == iSCType ? DDTranslation( -half*fac, -half*fac, zmm ) :
00385 DDTranslation( -fifth, zmm, zmm ) ) ) ) ) ;
00386
00387 const CLHEP::HepRotationZ cutm ( ffived ) ;
00388
00389 DDRotation cutRot ( 5 != iSCType ? noRot : myrot( "EECry5Rot",
00390 DDRotationMatrix( cutm.xx(), cutm.xy(), cutm.xz(),
00391 cutm.yx(), cutm.yy(), cutm.yz(),
00392 cutm.zx(), cutm.zy(), cutm.zz() ) ) ) ;
00393
00394 DDSolid eeCutEnv ( DDSolidFactory::subtraction( envName( iSCType ),
00395 addTmp( envName( iSCType ) ),
00396 cutBoxName(),
00397 cutTra,
00398 cutRot ) ) ;
00399
00400 const DDTranslation extra ( dxy, dxy, dz ) ;
00401
00402 DDSolid eeCutAlv ( DDSolidFactory::subtraction( alvName( iSCType ),
00403 addTmp( alvName( iSCType ) ),
00404 cutBoxName(),
00405 cutTra - extra,
00406 cutRot ) ) ;
00407
00408 const double mySign ( iSCType < 4 ? +1. : -1. ) ;
00409
00410 const DDTranslation extraI ( xyIOff + mySign*2*mm,
00411 xyIOff + mySign*2*mm, zIOff ) ;
00412
00413 DDSolid eeCutInt ( DDSolidFactory::subtraction( intName( iSCType ),
00414 addTmp( intName( iSCType ) ),
00415 cutBoxName(),
00416 cutTra - extraI,
00417 cutRot ) ) ;
00418
00419 eeSCELog = DDLogicalPart( envName( iSCType ), eeMat() , eeCutEnv ) ;
00420 eeSCALog = DDLogicalPart( alvName( iSCType ), eeWallMat(), eeCutAlv ) ;
00421 eeSCILog = DDLogicalPart( intName( iSCType ), eeMat() , eeCutInt ) ;
00422 }
00423
00424
00425 cpv.position( eeSCALog, envName( iSCType ), iSCType*100 + 1, DDTranslation( dxy, dxy, dz ), noRot );
00426 cpv.position( eeSCILog, alvName( iSCType ), iSCType*100 + 1, DDTranslation( xyIOff, xyIOff, zIOff), noRot );
00427
00428 DDTranslation croffset( 0., 0., 0.) ;
00429 EEPositionCRs( alvName( iSCType ), croffset, iSCType, cpv ) ;
00430
00431 }
00432
00433 unsigned int
00434 DDEcalEndcapAlgo::EEGetSCType( const unsigned int iCol,
00435 const unsigned int iRow )
00436 {
00437 unsigned int iType = 1;
00438 for( unsigned int ii = 0; ii < (unsigned int)( eenSCCutaway() ) ; ++ii )
00439 {
00440 if( ( eevecEESCCutaway()[ 3*ii ] == iCol ) &&
00441 ( eevecEESCCutaway()[ 3*ii + 1 ] == iRow ) )
00442 {
00443 iType = int(eevecEESCCutaway()[3*ii+2]);
00444
00445
00446 }
00447 }
00448 return iType;
00449 }
00450
00451 void
00452 DDEcalEndcapAlgo::EECreateCR()
00453 {
00454
00455
00456
00457
00458 DDSolid EECRSolid (DDSolidFactory::trap(
00459 cryName(),
00460 0.5*eeCrysLength(),
00461 atan((eeCrysRear()-eeCrysFront())/(sqrt(2.)*eeCrysLength())),
00462 45.*deg,
00463 0.5*eeCrysFront(),0.5*eeCrysFront(),0.5*eeCrysFront(),0.*deg,
00464 0.5*eeCrysRear(), 0.5*eeCrysRear(), 0.5*eeCrysRear(),0.*deg ) );
00465
00466 DDLogicalPart part ( cryName(), eeCrysMat(), EECRSolid ) ;
00467 }
00468
00469 void
00470 DDEcalEndcapAlgo::EEPositionCRs( const DDName pName,
00471 const DDTranslation ,
00472 const int iSCType,
00473 DDCompactView& cpv )
00474 {
00475
00476
00477
00478
00479 static const unsigned int ncol ( 5 ) ;
00480
00481 if( iSCType > 0 &&
00482 iSCType <= eenSCTypes() )
00483 {
00484 const unsigned int icoffset ( ( iSCType - 1 )*ncol - 1 ) ;
00485
00486
00487 for( unsigned int icol ( 1 ); icol <= ncol ; ++icol )
00488 {
00489
00490 const int ncrcol ( (int) eevecEESCProf()[ icoffset + icol ] ) ;
00491
00492 const int imin ( 0 < ncrcol ? 1 : ( 0 > ncrcol ? ncol + ncrcol + 1 : 0 ) ) ;
00493 const int imax ( 0 < ncrcol ? ncrcol : ( 0 > ncrcol ? ncol : 0 ) ) ;
00494
00495 if( imax>0 )
00496 {
00497
00498 for( int irow ( imin ); irow <= imax ; ++irow )
00499 {
00500
00501
00502
00503
00504
00505 DDEcalEndcapTrap crystal( 1, eeCrysFront(), eeCrysRear(), eeCrysLength() ) ;
00506
00507 crystal.moveto( cryFCtr( icol, irow ) ,
00508 cryRCtr( icol, irow ) );
00509
00510 DDName rname ( "EECrRoC" + int_to_string( icol ) + "R" + int_to_string( irow ) ) ;
00511
00512 cpv.position( cryName(),
00513 pName,
00514 100*iSCType + 10*( icol - 1 ) + ( irow - 1 ),
00515 crystal.centrePos() - DDTranslation(0,0,m_cryZOff),
00516 myrot( rname.fullname(), crystal.rotation() ) ) ;
00517 }
00518 }
00519 }
00520 }
00521 }
00522