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