CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Geometry/EcalCommonData/src/DDEcalPreshowerAlgo.cc

Go to the documentation of this file.
00001 #include "Geometry/EcalCommonData/interface/DDEcalPreshowerAlgo.h"
00002 
00003 #include <cmath>
00004 #include <algorithm>
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DetectorDescription/Base/interface/DDTypes.h"
00008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00009 #include "DetectorDescription/Core/interface/DDSolid.h"
00010 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00011 
00012 DDEcalPreshowerAlgo::DDEcalPreshowerAlgo() : DDAlgorithm() {
00013   LogDebug("EcalGeom") << "DDEcalPreshowerAlgo info: Creating an instance" ;
00014 
00015 }
00016 
00017 void DDEcalPreshowerAlgo::initialize(const DDNumericArguments & nArgs,
00018                                      const DDVectorArguments & vArgs,
00019                                      const DDMapArguments & mArgs,
00020                                      const DDStringArguments & sArgs,
00021                                      const DDStringVectorArguments & vsArgs)
00022 {
00023 
00024   LogDebug("EcalGeom") << "DDEcalPreshowerAlgo info: Initialize" ;
00025  
00026   asym_ladd_ = vArgs["ASYMETRIC_LADDER"];
00027   types_l5_ = vsArgs["TYPES_OF_LADD_L5"];
00028   types_l4_ = vsArgs["TYPES_OF_LADD_L4"];
00029   ladd_l5_map_ = vArgs["LADD_L5_MAP"];
00030   ladd_l4_map_ = vArgs["LADD_L4_MAP"];
00031   noLaddInCol_ = vArgs["NUMB_OF_LADD_IN_COL"];
00032   startOfFirstLadd_ = vArgs["START_OF_1ST_LADD"];
00033   typeOfLaddRow0 = vsArgs["TYPE_OF_LADD_1"];
00034   typeOfLaddRow1 = vsArgs["TYPE_OF_LADD_2"];
00035   typeOfLaddRow2 = vsArgs["TYPE_OF_LADD_3"];
00036   typeOfLaddRow3 = vsArgs["TYPE_OF_LADD_4"];
00037   thickLayers_ = vArgs["Layers"];
00038   thickness_ = double(nArgs["PRESH_Z_TOTAL"]);
00039   materials_ = vsArgs["LayMat"];
00040   layName_ = vsArgs["LayName"];
00041   rmaxVec = vArgs["R_MAX"]; // inner radii
00042   rminVec = vArgs["R_MIN"]; // outer radii
00043   waf_intra_col_sep = double(nArgs["waf_intra_col_sep"]);
00044   waf_inter_col_sep = double(nArgs["waf_inter_col_sep"]);
00045   waf_active = double(nArgs["waf_active"]);
00046   wedge_length = double(nArgs["wedge_length"]);
00047   wedge_offset = double(nArgs["wedge_offset"]);
00048   zwedge_ceramic_diff = double(nArgs["zwedge_ceramic_diff"]);
00049   ywedge_ceramic_diff = double(nArgs["ywedge_ceramic_diff"]);
00050   ceramic_length = double(nArgs["ceramic_length"]);
00051   wedge_angle = double(nArgs["wedge_angle"]);
00052   wedge_back_thick = double(nArgs["wedge_back_thick"]);
00053   ladder_thick = double(nArgs["ladder_thick"]);
00054   ladder_width = double(nArgs["ladder_width"]);
00055   micromodule_length = double(nArgs["micromodule_length"]);
00056   box_thick = double(nArgs["box_thick"]);
00057   abs1stx = vArgs["1ST_ABSX"];
00058   abs1sty = vArgs["1ST_ABSY"];
00059   abs2ndx = vArgs["2ND_ABSX"];
00060   abs2ndy = vArgs["2ND_ABSY"];
00061   ladPfx_ = vsArgs["LadPrefix"];
00062   LaddMaterial_ =  sArgs["LadderMaterial"];
00063   LdrFrnt_Length = double(nArgs["LdrFrnt_Length"]);
00064   LdrFrnt_Offset = double(nArgs["LdrFrnt_Offset"]);
00065   LdrBck_Length = double(nArgs["LdrBck_Length"]);
00066   LdrBck_Offset = double(nArgs["LdrBck_Offset"]);
00067   dee_separation = double(nArgs["dee_sep"]);
00068   In_rad_Abs_Al = double(nArgs["R_MIN_Abs_Al"]);
00069   In_rad_Abs_Pb = double(nArgs["R_MIN_Abs_Pb"]);
00070   rMax_Abs_Al_ = double(nArgs["R_MAX_Abs_Al"]);
00071   absAlX_X_ = double(nArgs["AbsAlX_X"]);
00072   absAlX_Y_ = double(nArgs["AbsAlX_Y"]);
00073   absAlX_subtr1_Xshift_ = double(nArgs["AbsAlX_subtr1_Xshift"]);
00074   absAlX_subtr1_Yshift_ = double(nArgs["AbsAlX_subtr1_Yshift"]); 
00075   absAlY_X_ = double(nArgs["AbsAlY_X"]);
00076   absAlY_Y_ = double(nArgs["AbsAlY_Y"]);
00077   absAlY_subtr1_Xshift_ = double(nArgs["AbsAlY_subtr1_Xshift"]);
00078   absAlY_subtr1_Yshift_ = double(nArgs["AbsAlY_subtr1_Yshift"]);
00079 
00080 }
00081 
00082 void DDEcalPreshowerAlgo::execute(DDCompactView& cpv)
00083 {
00084   LogDebug("EcalGeom") << "******** DDEcalPreshowerAlgo execute!";
00085 
00086   // creates all the tube-like layers of the preshower
00087   doLayers(cpv);
00088   // creates and places the ladders
00089   doLadders(cpv);  
00090   // places the slicon strips in active silicon wafers
00091   doSens(cpv);
00092   
00093 }
00094 
00095 void DDEcalPreshowerAlgo::doLayers(DDCompactView& cpv)
00096 {
00097 
00098   double zpos = -thickness_/2., sdx(0), sdy(0), bdx(0),bdy(0);;
00099 
00100   for(size_t i = 0; i<thickLayers_.size(); ++i) {
00101     
00102     int I = int(i)+1; // FOTRAN I (offset +1)
00103     
00104     double rIn(0), rOut(0), zHalf(0);
00105     
00106     // create the name
00107     DDName ddname(getLayName(i),"esalgo");   // namespace:name
00108 
00109     // cone dimensions
00110     rIn   = rminVec[i];
00111     rOut  = rmaxVec[i];
00112     zHalf = thickLayers_[i]/2.;
00113 
00114     // create a logical part representing a single layer in the preshower
00115     DDSolid solid = DDSolidFactory::tubs(ddname, zHalf, rIn, rOut, 0.,360.*deg);
00116 
00117     DDLogicalPart layer = DDLogicalPart(ddname,getMaterial(i),solid);
00118     
00119     // position the logical part w.r.t. the parent volume
00120     zpos += zHalf;
00121     
00122     // create a logical part representing a single layer in the preshower
00123     // skip layers with detectors, front and rear window 
00124     if (I==2 || I==28 || I==13 || I==23) {
00125       zpos += zHalf;
00126       continue;
00127     }
00128     
00129     if ( I==12 ) {
00130       zlead1_ = zpos + zHalf;
00131     }
00132     if ( I==22 ) {
00133       zlead2_ = zpos + zHalf;
00134     }
00135     
00136     if (I==10 || I==20) { // New lead shape
00137       
00138       int absz=0; double outalbx, outalby, shiftR, outalbx2, outalby2, shiftR2;
00139 
00140       absz = int(abs1stx.size()); 
00141       if ( I==20) absz = int(abs2ndx.size()); 
00142       int cutabsx=-1, cutabsy=-1;
00143 
00144       DDName dd_Alname_f(getLayName(i)+"LOutAl","esalgo");
00145       DDName dd_Alname_g(getLayName(i)+"LOutAl2","esalgo");
00146       DDName dd_Alname_h(getLayName(i)+"LOutAltmp","esalgo");
00147       DDName dd_Alname_i(getLayName(i)+"LOutAltmp2","esalgo");
00148       DDName dd_Alname_j(getLayName(i)+"LOutAltmp3","esalgo");
00149 
00150       DDSolid Out_Al = DDSolidFactory::tubs(dd_Alname_f,zHalf-0.1*mm,rMax_Abs_Al_-20*cm,rMax_Abs_Al_,0.,90.*deg); 
00151       outalbx = absAlX_X_; outalby = rMax_Abs_Al_+0.1*mm-absAlX_subtr1_Yshift_; shiftR = absAlX_subtr1_Yshift_;
00152       if ( I==20)  {  outalbx = absAlY_X_; outalby = rMax_Abs_Al_+0.1*mm-absAlY_subtr1_Yshift_; shiftR =  absAlY_subtr1_Xshift_; } 
00153 
00154       DDSolid OutAltmp = DDSolidFactory::box(dd_Alname_h,outalbx/2+0.1*mm,outalby/2+0.1*mm,zHalf);
00155       DDSolid Out_Altmp3 = DDSolidFactory::subtraction(dd_Alname_j,Out_Al,OutAltmp,DDTranslation(outalbx/2,outalby/2+shiftR,0),DDRotation());
00156 
00157       outalby2 = absAlX_Y_; outalbx2 = rMax_Abs_Al_+0.1*mm-absAlX_subtr1_Xshift_; shiftR2 = absAlX_subtr1_Xshift_;
00158      if ( I==20)  { outalby2 = absAlY_Y_; outalbx2 = rMax_Abs_Al_+0.1*mm-absAlY_subtr1_Xshift_; shiftR2 = absAlY_subtr1_Xshift_; }
00159       DDSolid OutAltmp2 = DDSolidFactory::box(dd_Alname_i,outalbx2/2+0.1*mm,outalby2/2+0.1*mm,zHalf);
00160       DDSolid Out_Al2 = DDSolidFactory::subtraction(dd_Alname_g,Out_Altmp3,OutAltmp2,DDTranslation(outalbx2/2+shiftR2,outalby2/2,0),DDRotation());
00161   
00162       for (int L=0; L<absz; ++L) {
00163         int K=L; 
00164         std::ostringstream  tmp_name_b, tmp_name_b2, tmp_FAl_name_c, tmp_FAl_name_d;
00165         tmp_name_b << getLayName(i) << "L" << K; 
00166         tmp_name_b2 << getLayName(i) << "Lb2" << K; 
00167 
00168      if(L==0) tmp_FAl_name_c << getLayName(i)<<"LOutAl2"; 
00169      if(L>0) tmp_FAl_name_c << getLayName(i) << "LtmpAl" << K-1; 
00170 
00171         tmp_FAl_name_d << getLayName(i) << "LtmpAl" << K; 
00172 
00173         DDName dd_tmp_name_b(tmp_name_b.str(),"esalgo");
00174         DDName dd_tmp_name_b2(tmp_name_b2.str(),"esalgo");
00175         DDName dd_FAl_name_c(tmp_FAl_name_c.str(),"esalgo");
00176         DDName dd_FAl_name_d(tmp_FAl_name_d.str(),"esalgo");
00177 
00178         if(L==0) bdx = std::abs(abs1stx[K])/2; 
00179         if(L>0) bdx = std::abs(abs1stx[K]-abs1stx[K-1])/2; 
00180         bdy=abs1sty[K];
00181         if(abs1stx[K] < rIn+30*cm) { bdy=abs1sty[K]/2 - 30*cm; cutabsx = K;}
00182         
00183         if(I==20) { if(L==0) bdx = std::abs(abs2ndx[K])/2; 
00184                 if(L>0) bdx = std::abs(abs2ndx[K]-abs2ndx[K-1])/2;
00185                 bdy=abs2ndy[K];}
00186         
00187         if((abs2ndx[K] < rIn+30*cm) && I==20) { bdy=abs2ndy[K]/2 - 30*cm; cutabsy = K;}
00188         
00189         DDSolid solid_b = DDSolidFactory::box(dd_tmp_name_b,bdx,bdy,zHalf);
00190         DDSolid solid_b2 = DDSolidFactory::box(dd_tmp_name_b2,bdx+0.1*mm,bdy+0.1*mm,zHalf);
00191         
00192         sdx = abs1stx[K]-bdx ; sdy = 0;
00193         if(abs1stx[K] < rIn+30*cm ) sdy = abs1sty[K]-bdy ; 
00194         
00195         if(I==20) {sdx = abs2ndx[K]-bdx ; sdy = 0;}
00196         if((abs2ndx[K] < rIn+30*cm) && I==20 ) sdy = abs2ndy[K]-bdy ;
00197                 
00198         DDLogicalPart layer = DDLogicalPart(dd_tmp_name_b,getMaterial(i),solid_b);
00199         
00200         cpv.position(layer, parent(), 1, DDTranslation(sdx,sdy, zpos), DDRotation());
00201         cpv.position(layer, parent(), 2, DDTranslation(-sdx,sdy, zpos), DDRotation());
00202          DDSolid solid_c = DDSolid(dd_FAl_name_c);  
00203          DDSolid solid_d = DDSolidFactory::subtraction(dd_FAl_name_d,solid_c,solid_b2,DDTranslation(sdx,sdy,0),DDRotation());
00204         if(((abs1stx[K] < rIn+30*cm) && I==10) || ((abs2ndx[K] < rIn+30*cm) && I==20) ) { 
00205           cpv.position(layer, parent(), 3, DDTranslation(sdx,-sdy, zpos), DDRotation());
00206           cpv.position(layer, parent(), 4, DDTranslation(-sdx,-sdy, zpos), DDRotation());
00207          DDSolid solid_c = DDSolid(dd_FAl_name_c);  
00208          DDSolid solid_d = DDSolidFactory::subtraction(dd_FAl_name_d,solid_c,solid_b2,DDTranslation(sdx,sdy,0),DDRotation());
00209         }               
00210 
00211 
00212       }  
00213       
00214 
00215 
00216       DDName dd_tmp_name_b(getLayName(i)+"Lcut","esalgo");
00217       DDName dd_tmp_name_c(getLayName(i)+"tmpb","esalgo");
00218       DDName dd_tmp_name_d(getLayName(i)+"LinPb","esalgo");
00219 
00220       DDName dd_tmp_name_e(getLayName(i)+"LinAl","esalgo");
00221       DDName dd_tmp_name_f(getLayName(i)+"LOutAl","esalgo");
00222 
00223       
00224       bdx = abs1stx[cutabsx]; bdy=2*30*cm;
00225       if(I==20) bdx = abs2ndx[cutabsy]; bdy=2*30*cm;
00226       
00227       DDSolid solidcut = DDSolidFactory::box(dd_tmp_name_b,bdx,bdy,zHalf);
00228 
00229       DDSolid iner = DDSolidFactory::tubs(dd_tmp_name_c,zHalf+0.1*mm,0,In_rad_Abs_Pb,0.,360.*deg); 
00230 
00231 
00232       DDSolid final = DDSolidFactory::subtraction(dd_tmp_name_d,solidcut,iner,DDTranslation(0,0,0),DDRotation());
00233 
00234       
00235       DDLogicalPart layer = DDLogicalPart(dd_tmp_name_d,getMaterial(i),final);
00236       cpv.position(layer, parent(), 1, DDTranslation(0,0, zpos), DDRotation());
00237 
00238       DDSolid iner_Al = DDSolidFactory::tubs(dd_tmp_name_e,zHalf,In_rad_Abs_Al,In_rad_Abs_Pb-0.01*mm,0.,360.*deg); 
00239       DDLogicalPart layerAl = DDLogicalPart(dd_tmp_name_e,getMaterial(i-1),iner_Al);
00240       cpv.position(layerAl, parent(), 1, DDTranslation(0,0, zpos), DDRotation());
00241   
00242         std::ostringstream  tmp_Alname_fin;
00243         tmp_Alname_fin << getLayName(i) << "LtmpAl" << absz-1; 
00244         DDName dd_Alname_fin(tmp_Alname_fin.str(),"esalgo");
00245 
00246       DDSolid Outer_Al = DDSolid(dd_Alname_fin);
00247 
00248       DDLogicalPart layerFinOutAl = DDLogicalPart(dd_tmp_name_f,getMaterial(i-1),Outer_Al);
00249 
00250      cpv.position(layerFinOutAl, parent(), 1, DDTranslation(0,0, zpos), DDRotation());
00251      cpv.position(layerFinOutAl, parent(), 2, DDTranslation(0,0, zpos), DDRotation("esalgo:RABS90"));
00252      cpv.position(layerFinOutAl, parent(), 3, DDTranslation(0,0, zpos), DDRotation("esalgo:RABS180B"));
00253      cpv.position(layerFinOutAl, parent(), 4, DDTranslation(0,0, zpos), DDRotation("esalgo:R180"));
00254   
00255 
00256     
00257     } else {
00258       
00259       cpv.position(layer, parent(), 1, DDTranslation(0.,0., zpos), DDRotation());
00260       
00261       LogDebug("SFGeom")<<" debug : tubs, Logical part: "<<DDLogicalPart(ddname,getMaterial(i),solid)<<"\n translation "<<DDTranslation(0.,0.,zpos)<<" rotation "<<DDRotation()<< "\n";
00262     } 
00263     
00264     zpos += zHalf; 
00265   }
00266   
00267 }
00268 
00269 void DDEcalPreshowerAlgo::doLadders(DDCompactView& cpv) {
00270   
00271   double xpos(0), ypos(0), zpos(0), sdx(0), sdy(0), sdz(0);
00272   double prev_length_(0), ladder_new_length_(0), ladd_shift_(0), ladder_length (0);
00273   int enb(0), swed_scopy_glob(0); double sdxe[50] = {0}, sdye[50] = {0}, sdze[50] = {0};
00274   double sdxe2[50] = {0}, sdye2[50] = {0}, sdze2[50] = {0}, sdxe3[50] = {0}, sdye3[50] = {0}, sdze3[50] = {0};
00275   
00276   for (int M=0; M<int(types_l5_.size() + types_l4_.size()); M++) {
00277     int scopy(0); double boxax(0), boxay(0), boxaz(0);
00278     int ladd_not_plain(0), ladd_subtr_no(0), ladd_upper(0), ladd_side(0);
00279     
00280     DDSolid solid_lfront = DDSolidFactory::trap(DDName("LDRFRNT","esalgo"),
00281                                                 LdrFrnt_Length/2,   // pDz
00282                                                 -wedge_angle,     // pTheta
00283                                                 0,              // pPhi
00284                                                 ladder_width/2, // pDy1
00285                                                 (ladder_thick)/2,  // pDx1
00286                                                 (ladder_thick)/2,   //     pDx2
00287                                                 0,              //pAlp1
00288                                                 ladder_width/2,   //pDy2
00289                                                 (ladder_thick-ceramic_length*sin(wedge_angle*2))/2,   // pDx3
00290                                                 (ladder_thick-ceramic_length*sin(wedge_angle*2))/2,   // pDx4
00291                                                 0 );
00292     
00293     
00294     DDSolid solid_lbck = DDSolidFactory::trap(DDName("LDRBCK","esalgo"),
00295                                               LdrBck_Length/2,   // pDz
00296                                               -wedge_angle,     // pTheta
00297                                               0,                // pPhi
00298                                               ladder_width/2,   // pDy1
00299                                               (box_thick/cos(wedge_angle*2)+0.02*mm)/2,  // pDx1
00300                                               (box_thick/cos(wedge_angle*2)+0.02*mm)/2,   //     pDx2
00301                                               0,                //pAlp1
00302                                               ladder_width/2,   //pDy2
00303                                               (ladder_thick-wedge_back_thick)/2,   // pDx3
00304                                               (ladder_thick-wedge_back_thick)/2,   // pDx4
00305                                               0 );
00306     
00307     DDSolid solid_lfhalf = DDSolidFactory::trap(DDName("LDRFHALF","esalgo"),
00308                                                 LdrFrnt_Length/2,   // pDz
00309                                                 -wedge_angle,     // pTheta
00310                                                 0,              // pPhi
00311                                                 (ladder_width/2)/2,     // pDy1
00312                                                 (ladder_thick)/2,  // pDx1
00313                                                 (ladder_thick)/2,   //     pDx2
00314                                                 0,              //pAlp1
00315                                                 (ladder_width/2)/2,   //pDy2
00316                                                 (ladder_thick-ceramic_length*sin(wedge_angle*2))/2,   // pDx3
00317                                                 (ladder_thick-ceramic_length*sin(wedge_angle*2))/2,   // pDx4
00318                                                 0 );
00319     
00320     DDSolid solid_lbhalf = DDSolidFactory::trap(DDName("LDRBHALF","esalgo"),
00321                                                 LdrBck_Length/2,   // pDz
00322                                                 -wedge_angle,     // pTheta
00323                                                 0,              // pPhi
00324                                                 (ladder_width/2)/2,     // pDy1
00325                                                 (box_thick/cos(wedge_angle*2)+0.02*mm)/2,  // pDx1
00326                                                 (box_thick/cos(wedge_angle*2)+0.02*mm)/2,   //     pDx2
00327                                                 0,              //pAlp1
00328                                                 (ladder_width/2)/2,   //pDy2
00329                                                 (ladder_thick-wedge_back_thick)/2,   // pDx3
00330                                                 (ladder_thick-wedge_back_thick)/2,   // pDx4
00331                                                 0 );
00332     
00333     DDSolid solid_lfhtrunc = DDSolidFactory::trap(DDName("LDRFHTR","esalgo"),
00334                                                   (LdrFrnt_Length-waf_active)/2,   // pDz
00335                                                   -wedge_angle,     // pTheta
00336                                                   0,            // pPhi
00337                                                   (ladder_width/2)/2,   // pDy1
00338                                                   (ladder_thick)/2,  // pDx1
00339                                                   (ladder_thick)/2,   //     pDx2
00340                                                   0,            //pAlp1
00341                                                   (ladder_width/2)/2,   //pDy2
00342                                                   (ladder_thick-(ceramic_length-waf_active)*sin(wedge_angle*2))/2,   // pDx3
00343                                                   (ladder_thick-(ceramic_length-waf_active)*sin(wedge_angle*2))/2,   // pDx4
00344                                                   0 );
00345 
00346 // Creation of ladders with 5 micromodules length
00347     
00348     if(M<int(types_l5_.size())) {
00349       
00350       
00351       for (int i=0; i<=1; i++) {
00352         for (int j=0; j<=3; j++) {
00353           if(ladd_l5_map_[(i+j*2+M*10)]!=1){
00354             ladd_not_plain=1; ladd_subtr_no++; if(j>1) ladd_upper=1; ladd_side=i;
00355           }
00356         }
00357       }
00358       
00359       DDName ddname(getLadPrefix(0)+types_l5_[M],"esalgo");
00360       ladder_length = micromodule_length + 4*waf_active + 0.1*mm;
00361       
00362       
00363       if(ladd_not_plain) {   
00364         //          enb++; 
00365         std::ostringstream tmp_name_5b, tmp_name_5c, tmp_name_5d;
00366         if(ladd_upper) {
00367           
00368           
00369         }//upper
00370         else {
00371           enb++; 
00372           std::ostringstream tmp_name_5b, tmp_name_5c, tmp_name_5d;
00373           DDName dd_tmp_name_5a(getLadPrefix(2),"esalgo");
00374           tmp_name_5b <<getLadPrefix(3)<< enb;
00375           DDName dd_tmp_name_5b(tmp_name_5b.str(),"esalgo");        
00376           tmp_name_5c <<getLadPrefix(4)<< enb;
00377           DDName dd_tmp_name_5c(tmp_name_5c.str(),"esalgo");        
00378           tmp_name_5d << getLadPrefix(5) << enb;
00379           DDName dd_tmp_name_5d(tmp_name_5d.str(),"esalgo");
00380           
00381           DDName dd_tmp_name_5e(getLadPrefix(6),"esalgo");
00382           
00383           boxay =  ladder_length-LdrFrnt_Length-LdrBck_Length; boxax = ladder_width; boxaz = ladder_thick;
00384           
00385           DDSolid solid_5a = DDSolidFactory::box(dd_tmp_name_5a,boxax/2,boxay/2,boxaz/2.);
00386           if(ladd_side==0) sdxe[enb] = ladder_width/4; sdye[enb]= -boxay/2 - LdrFrnt_Length/2; sdze[enb] = -ladder_thick/2. + LdrFrnt_Offset;
00387           if(ladd_side==1) sdxe[enb] = -ladder_width/4;
00388           
00389           DDSolid solid_5b = DDSolidFactory::unionSolid(dd_tmp_name_5b,solid_5a,solid_lfhalf,DDTranslation(sdxe[enb],sdye[enb],sdze[enb]),DDRotation("esalgo:RM1299"));
00390           
00391           if(ladd_side==0) sdxe2[enb] = -ladder_width/4; sdye2[enb]= -boxay/2 - LdrFrnt_Length/2 + waf_active/2;
00392           sdze2[enb] = -ladder_thick/2. + LdrFrnt_Offset + (waf_active*sin(wedge_angle*2))/4;
00393           if(ladd_side==1) sdxe2[enb] = ladder_width/4;
00394           
00395           DDSolid solid_5c = DDSolidFactory::unionSolid(dd_tmp_name_5c,solid_5b,solid_lfhtrunc,DDTranslation(sdxe2[enb],sdye2[enb],sdze2[enb]),DDRotation("esalgo:RM1299"));
00396           
00397           sdxe3[enb] = 0; sdye3[enb] = boxay/2 + LdrBck_Length/2; sdze3[enb] = -ladder_thick/2. + LdrBck_Offset;
00398           DDSolid solid = DDSolidFactory::unionSolid(ddname,solid_5c,solid_lbck,DDTranslation(sdxe3[enb],sdye3[enb],sdze3[enb]),DDRotation("esalgo:RM1299"));      
00399           
00400           DDLogicalPart ladder = DDLogicalPart(ddname,getLaddMaterial(),solid); 
00401           DDName ddname2(getLadPrefix(1)+types_l5_[M],"esalgo");      
00402           DDLogicalPart ladder2 = DDLogicalPart(ddname2,getLaddMaterial(),solid);  
00403           
00404         }
00405         
00406       } //end of not plain ladder shape
00407       else {
00408         
00409         
00410         
00411         DDName dd_tmp_name_5pa(getLadPrefix(2)+"5p","esalgo");
00412         DDName dd_tmp_name_5pb(getLadPrefix(3)+"5p","esalgo");
00413         
00414         boxay = ladder_length-LdrFrnt_Length-LdrBck_Length; boxax = ladder_width; boxaz = ladder_thick;
00415         
00416         DDSolid solid_5pa = DDSolidFactory::box(dd_tmp_name_5pa,boxax/2,boxay/2,boxaz/2.);
00417         sdx = 0; sdy= -boxay/2 - LdrFrnt_Length/2; sdz = -ladder_thick/2. + LdrFrnt_Offset;
00418         
00419         DDSolid solid_5pb = DDSolidFactory::unionSolid(dd_tmp_name_5pb,solid_5pa,solid_lfront,DDTranslation(sdx,sdy,sdz),DDRotation("esalgo:RM1299"));
00420         
00421         sdx = 0; sdy= boxay/2 + LdrBck_Length/2; sdz = -ladder_thick/2. + LdrBck_Offset;
00422         
00423         DDSolid solid = DDSolidFactory::unionSolid(ddname,solid_5pb,solid_lbck,DDTranslation(sdx,sdy,sdz),DDRotation("esalgo:RM1299"));
00424         
00425         DDLogicalPart ladder = DDLogicalPart(ddname,getLaddMaterial(),solid); 
00426         DDName ddname2(getLadPrefix(1)+types_l5_[M],"esalgo");      
00427         DDLogicalPart ladder2 = DDLogicalPart(ddname2,getLaddMaterial(),solid);  
00428         
00429       }
00430     }
00431 
00432 // Creation of ladders with 4 micromodules length
00433 
00434     if( M >= int(types_l5_.size()) ) {
00435       int d = M - types_l5_.size();
00436            
00437       for (int i=0; i<=1; i++) {
00438         for (int j=0; j<=3; j++) {
00439           if(ladd_l4_map_[(i+j*2+(M-types_l5_.size())*8)]!=1 ){
00440             ladd_not_plain=1; ladd_subtr_no++; if(j>1) ladd_upper=1; ladd_side=i;
00441           }
00442         }
00443       }
00444       
00445       DDName ddname(getLadPrefix(0)+types_l4_[d],"esalgo");      
00446       ladder_length = micromodule_length + 3*waf_active + 0.1*mm;      
00447       
00448       if(ladd_not_plain) {        
00449         std::ostringstream tmp_name_b, tmp_name_c, tmp_name_d;
00450         if(ladd_upper) {
00451           enb++; 
00452           
00453           DDName dd_tmp_name_a(getLadPrefix(7),"esalgo");
00454           tmp_name_b <<getLadPrefix(8)<< enb;
00455           DDName dd_tmp_name_b(tmp_name_b.str(),"esalgo");      
00456           tmp_name_c <<getLadPrefix(9)<< enb;
00457           DDName dd_tmp_name_c(tmp_name_c.str(),"esalgo");          
00458           tmp_name_d << getLadPrefix(10) << enb;
00459           DDName dd_tmp_name_d(tmp_name_d.str(),"esalgo");
00460           DDName dd_tmp_name_e(getLadPrefix(11),"esalgo");           
00461           
00462           boxay =  ladder_length-LdrFrnt_Length-LdrBck_Length; boxax = ladder_width; boxaz = ladder_thick;
00463           DDSolid solid_a = DDSolidFactory::box(dd_tmp_name_a,boxax/2,boxay/2,boxaz/2.);
00464           
00465           sdxe[enb] = 0; sdye[enb]= -boxay/2 - LdrFrnt_Length/2; sdze[enb] = -ladder_thick/2. + LdrFrnt_Offset;
00466           DDSolid solid_b = DDSolidFactory::unionSolid(dd_tmp_name_b,solid_a,solid_lfront,DDTranslation(sdxe[enb],sdye[enb],sdze[enb]),DDRotation("esalgo:RM1299"));
00467           
00468           if(ladd_side==0) sdxe2[enb] = ladder_width/4; sdye2[enb] = boxay/2 + LdrBck_Length/2; sdze2[enb] = -ladder_thick/2. + LdrBck_Offset;
00469           if(ladd_side==1) sdxe2[enb] = -ladder_width/4; 
00470           DDSolid solid = DDSolidFactory::unionSolid(ddname,solid_b,solid_lbhalf,DDTranslation(sdxe2[enb],sdye2[enb],sdze2[enb]),DDRotation("esalgo:RM1299"));      
00471           
00472           DDLogicalPart ladder = DDLogicalPart(ddname,getLaddMaterial(),solid);
00473           DDName ddname2(getLadPrefix(1)+types_l4_[d],"esalgo"); 
00474           DDLogicalPart ladder2 = DDLogicalPart(ddname2,getLaddMaterial(),solid);   
00475           
00476         }//upper
00477         else {
00478           if(ladd_subtr_no>1) {
00479             enb++; 
00480             
00481             DDName dd_tmp_name_a(getLadPrefix(7),"esalgo");
00482             tmp_name_b <<getLadPrefix(8)<< enb;
00483             DDName dd_tmp_name_b(tmp_name_b.str(),"esalgo");    
00484             tmp_name_c <<getLadPrefix(9)<< enb;
00485             DDName dd_tmp_name_c(tmp_name_c.str(),"esalgo");        
00486             tmp_name_d << getLadPrefix(10) << enb;
00487             DDName dd_tmp_name_d(tmp_name_d.str(),"esalgo");
00488             DDName dd_tmp_name_e(getLadPrefix(11),"esalgo");           
00489             
00490             boxay =  ladder_length-LdrFrnt_Length-LdrBck_Length; boxax = ladder_width; boxaz = ladder_thick;
00491 
00492             DDSolid solid_a = DDSolidFactory::box(dd_tmp_name_a,boxax/2,boxay/2,boxaz/2.);
00493             if(ladd_side==0) sdxe[enb] = ladder_width/4; sdye[enb]= -boxay/2 - LdrFrnt_Length/2; sdze[enb] = -ladder_thick/2. + LdrFrnt_Offset;
00494             if(ladd_side==1) sdxe[enb] = -ladder_width/4;
00495             
00496             DDSolid solid_b = DDSolidFactory::unionSolid(dd_tmp_name_b,solid_a,solid_lfhalf,DDTranslation(sdxe[enb],sdye[enb],sdze[enb]),DDRotation("esalgo:RM1299"));
00497             
00498             sdxe2[enb] = 0; sdye2[enb] = boxay/2 + LdrBck_Length/2; sdze2[enb] = -ladder_thick/2. + LdrBck_Offset;
00499             
00500             DDSolid solid = DDSolidFactory::unionSolid(ddname,solid_b,solid_lbck,DDTranslation(sdxe2[enb],sdye2[enb],sdze2[enb]),DDRotation("esalgo:RM1299"));      
00501             
00502             DDLogicalPart ladder = DDLogicalPart(ddname,getLaddMaterial(),solid);
00503             DDName ddname2(getLadPrefix(1)+types_l4_[d],"esalgo"); 
00504             DDLogicalPart ladder2 = DDLogicalPart(ddname2,getLaddMaterial(),solid);
00505           } else {
00506             enb++; 
00507             DDName dd_tmp_name_a(getLadPrefix(7),"esalgo");
00508             tmp_name_b <<getLadPrefix(8)<< enb;
00509             DDName dd_tmp_name_b(tmp_name_b.str(),"esalgo");    
00510             tmp_name_c <<getLadPrefix(9)<< enb;
00511             DDName dd_tmp_name_c(tmp_name_c.str(),"esalgo");        
00512             tmp_name_d << getLadPrefix(10) << enb;
00513             DDName dd_tmp_name_d(tmp_name_d.str(),"esalgo");
00514             DDName dd_tmp_name_e(getLadPrefix(11),"esalgo");           
00515             
00516             boxay =  ladder_length-LdrFrnt_Length-LdrBck_Length; boxax = ladder_width; boxaz = ladder_thick;
00517             DDSolid solid_a = DDSolidFactory::box(dd_tmp_name_a,boxax/2,boxay/2,boxaz/2.);
00518             if(ladd_side==0) sdxe[enb] = ladder_width/4; sdye[enb]= -boxay/2 - LdrFrnt_Length/2; sdze[enb] = -ladder_thick/2. + LdrFrnt_Offset;
00519             if(ladd_side==1) sdxe[enb] = -ladder_width/4;
00520             
00521             DDSolid solid_b = DDSolidFactory::unionSolid(dd_tmp_name_b,solid_a,solid_lfhalf,DDTranslation(sdxe[enb],sdye[enb],sdze[enb]),DDRotation("esalgo:RM1299"));
00522             
00523             if(ladd_side==0) sdxe2[enb] = -ladder_width/4; sdye2[enb]= -boxay/2 - LdrFrnt_Length/2 + waf_active/2;
00524             sdze2[enb] = -ladder_thick/2. + LdrFrnt_Offset + (waf_active*sin(wedge_angle*2))/4;
00525             if(ladd_side==1) sdxe2[enb] = ladder_width/4;
00526             
00527             DDSolid solid_c = DDSolidFactory::unionSolid(dd_tmp_name_c,solid_b,solid_lfhtrunc,DDTranslation(sdxe2[enb],sdye2[enb],sdze2[enb]),DDRotation("esalgo:RM1299"));
00528             
00529             sdxe3[enb] = 0; sdye3[enb] = boxay/2 + LdrBck_Length/2; sdze3[enb] = -ladder_thick/2. + LdrBck_Offset;
00530             DDSolid solid = DDSolidFactory::unionSolid(ddname,solid_c,solid_lbck,DDTranslation(sdxe3[enb],sdye3[enb],sdze3[enb]),DDRotation("esalgo:RM1299"));      
00531             
00532             DDLogicalPart ladder = DDLogicalPart(ddname,getLaddMaterial(),solid);
00533             DDName ddname2(getLadPrefix(1)+types_l4_[d],"esalgo"); 
00534             DDLogicalPart ladder2 = DDLogicalPart(ddname2,getLaddMaterial(),solid);
00535             
00536           }     
00537         }
00538         
00539       } //end of not plain ladder shape
00540       else {
00541         DDName dd_tmp_name_pa(getLadPrefix(2)+"p","esalgo");
00542         DDName dd_tmp_name_pb(getLadPrefix(3)+"p","esalgo");
00543         
00544         boxay = ladder_length-LdrFrnt_Length-LdrBck_Length; boxax = ladder_width; boxaz = ladder_thick;
00545         
00546         DDSolid solid_pa = DDSolidFactory::box(dd_tmp_name_pa,boxax/2,boxay/2,boxaz/2.);
00547         sdx = 0; sdy= -boxay/2 - LdrFrnt_Length/2; sdz = -ladder_thick/2. + LdrFrnt_Offset;
00548         
00549         DDSolid solid_pb = DDSolidFactory::unionSolid(dd_tmp_name_pb,solid_pa,solid_lfront,DDTranslation(sdx,sdy,sdz),DDRotation("esalgo:RM1299"));
00550         
00551         sdx = 0; sdy= boxay/2 + LdrBck_Length/2; sdz = -ladder_thick/2. + LdrBck_Offset;
00552         DDSolid solid = DDSolidFactory::unionSolid(ddname,solid_pb,solid_lbck,DDTranslation(sdx,sdy,sdz),DDRotation("esalgo:RM1299"));          
00553         DDLogicalPart ladder = DDLogicalPart(ddname,getLaddMaterial(),solid);
00554         DDName ddname2(getLadPrefix(1)+types_l4_[d],"esalgo"); 
00555         DDLogicalPart ladder2 = DDLogicalPart(ddname2,getLaddMaterial(),solid);
00556       }
00557     }
00558    
00559 // insert SWED, SFBX and SFBY into ladders
00560   swed_scopy_glob++;
00561     if(M<int(types_l5_.size())) {
00562       DDName ddname(getLadPrefix(0)+types_l5_[M],"esalgo");
00563       DDName ddname2(getLadPrefix(1)+types_l5_[M],"esalgo"); 
00564       for (int i=0; i<=1; i++) {
00565         for (int j=0; j<=4; j++) {
00566           xpos = (i*2-1)*waf_intra_col_sep/2.; ypos = -ladder_length/2. + 0.05*mm -(LdrFrnt_Length-LdrBck_Length)/2 + wedge_length/2. + j*waf_active;
00567           zpos = -ladder_thick/2. + 0.005*mm + wedge_offset;
00568           if(ladd_l5_map_[(i+j*2+M*10)]==1) {
00569             scopy ++;
00570             cpv.position(DDLogicalPart("esalgo:SWED"), ddname, scopy+1000*swed_scopy_glob, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1299"));
00571             cpv.position(DDLogicalPart("esalgo:SWED"), ddname2, scopy+1000*swed_scopy_glob+100, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1299"));
00572             
00573             ypos = ypos + ywedge_ceramic_diff; zpos = -ladder_thick/2. + 0.005*mm + zwedge_ceramic_diff;
00574             cpv.position(DDLogicalPart("esalgo:SFBX"), ddname, scopy+1000*swed_scopy_glob, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1298"));
00575             cpv.position(DDLogicalPart("esalgo:SFBY"), ddname2, scopy+1000*swed_scopy_glob, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1300A")); 
00576           }
00577         }
00578       }
00579     }
00580     else
00581       {
00582         int d = M - types_l5_.size();
00583         DDName ddname(getLadPrefix(0)+types_l4_[d],"esalgo"); 
00584         DDName ddname2(getLadPrefix(1)+types_l4_[d],"esalgo");  
00585         for (int i=0; i<=1; i++) {
00586           for (int j=0; j<=3; j++) {
00587             xpos = (i*2-1)*waf_intra_col_sep/2.; ypos = -ladder_length/2. + 0.05*mm - (LdrFrnt_Length-LdrBck_Length)/2 + wedge_length/2. + j*waf_active;
00588             zpos = -ladder_thick/2. + 0.005*mm + wedge_offset;
00589             if(ladd_l4_map_[(i+j*2+(M-types_l5_.size())*8)]==1) {
00590               scopy ++;
00591               cpv.position(DDLogicalPart("esalgo:SWED"), ddname, scopy+1000*swed_scopy_glob, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1299"));
00592               cpv.position(DDLogicalPart("esalgo:SWED"), ddname2, scopy+1000*swed_scopy_glob+100, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1299"));
00593 
00594               ypos = ypos + ywedge_ceramic_diff; zpos = -ladder_thick/2. + 0.005*mm + zwedge_ceramic_diff;
00595               cpv.position(DDLogicalPart("esalgo:SFBX"), ddname, scopy+1000*swed_scopy_glob, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1298"));
00596               cpv.position(DDLogicalPart("esalgo:SFBY"), ddname2, scopy+1000*swed_scopy_glob, DDTranslation(xpos,ypos,zpos), DDRotation("esalgo:RM1300A"));
00597             }
00598           }
00599         }
00600       }
00601   }
00602 
00603 // Positioning of ladders
00604 
00605   std::string type;
00606   int icopy[100] = {0};
00607 
00608   for(int I=-9; I<=9;++I) {
00609     prev_length_=0; int J=std::abs(I);
00610     for (int K=0; K<noLaddInCol_[J]; K++) {
00611       std::string type;
00612 
00613       ladder_new_length_ = micromodule_length + 3*waf_active;
00614       ladd_shift_ = 4*waf_active;
00615 
00616       if(K==0) type = typeOfLaddRow0[J]; 
00617       if(K==1) type = typeOfLaddRow1[J];
00618       if(K==2) type = typeOfLaddRow2[J];
00619       if(K==3) type = typeOfLaddRow3[J]; 
00620 
00621       for(int i=0;i<int(types_l5_.size());i++) if(type == types_l5_[i]) {
00622         ladder_new_length_ = micromodule_length + 4*waf_active;
00623         ladd_shift_ = 5*waf_active;}
00624       
00625       int j = 0;
00626       
00627       for(int t=0;t<int(types_l5_.size());t++) if(type == types_l5_[t]) {j = t; if(I<0 && asym_ladd_[t] == 1 ) {j = j + 1;  type = types_l5_[j];}} 
00628       for(int t=0;t<int(types_l4_.size());t++) if(type == types_l4_[t]) {j = t+types_l5_.size(); if(I<0 && asym_ladd_[(t+types_l5_.size())] == 1 ) {j = j + 1; type = types_l4_[j-types_l5_.size()];}}
00629       
00630       xpos = I*(2*waf_intra_col_sep + waf_inter_col_sep);
00631       if(I>0) xpos = xpos + dee_separation;
00632       if(I<0) xpos = xpos - dee_separation;
00633 
00634       int sz = 20;    
00635       ypos = (sz-int(startOfFirstLadd_[J]))*waf_active - ladder_new_length_/2. + (LdrFrnt_Length-LdrBck_Length)/2 + micromodule_length + 0.05*cm - prev_length_;
00636 
00637       prev_length_ += ladd_shift_;        
00638       
00639       zpos = zlead1_ + ladder_thick/2. + 0.01*mm;
00640       icopy[j] +=1;
00641       DDName ddname(getLadPrefix(0)+type,"esalgo"); 
00642       
00643       cpv.position(DDLogicalPart(ddname), DDName("SF","esalgo"), icopy[j], DDTranslation(xpos,ypos,zpos), DDRotation());
00644 
00645       DDName ddname2(getLadPrefix(1)+type,"esalgo"); 
00646       
00647       xpos = I*(2*waf_intra_col_sep + waf_inter_col_sep);
00648       
00649       cpv.position(DDLogicalPart(ddname2), DDName("SF","esalgo"), icopy[j], DDTranslation(ypos,-xpos,zpos-zlead1_+zlead2_), DDRotation("esalgo:R270"));
00650 
00651       int changed = 0;
00652       for(int t=0;t<int(types_l5_.size());t++) if(type == types_l5_[t]) {j = t; if(asym_ladd_[t] == 2 && !changed) { j = j - 1; changed = 1;} if(asym_ladd_[t] == 1 && !changed) { j = j + 1; changed = 1;}  type = types_l5_[j];} 
00653       for(int t=0;t<int(types_l4_.size());t++) if(type == types_l4_[t]) {j = t+types_l5_.size(); if(asym_ladd_[(t+types_l5_.size())] == 2 && !changed) { j = j - 1; changed = 1;} if(asym_ladd_[(t+types_l5_.size())] == 1 && !changed) { j = j + 1; changed = 1;} type = types_l4_[j-types_l5_.size()]; }
00654       
00655       icopy[j] +=1;
00656 
00657       if(I>0) xpos = xpos + dee_separation;
00658       if(I<0) xpos = xpos - dee_separation;
00659 
00660       DDName ddname3(getLadPrefix(0)+type,"esalgo");       
00661       cpv.position(DDLogicalPart(ddname3), DDName("SF","esalgo"), icopy[j], DDTranslation(xpos,-ypos,zpos), DDRotation("esalgo:R180"));
00662 
00663       DDName ddname4(getLadPrefix(1)+type,"esalgo"); 
00664 
00665       xpos = I*(2*waf_intra_col_sep + waf_inter_col_sep);
00666 
00667       cpv.position(DDLogicalPart(ddname4), DDName("SF","esalgo"), icopy[j], DDTranslation(-ypos,-xpos,zpos-zlead1_+zlead2_), DDRotation("esalgo:R090"));
00668 
00669     }
00670   } 
00671 }
00672 
00673 void DDEcalPreshowerAlgo::doSens(DDCompactView& cpv) {
00674   
00675   double xpos(0), ypos(0);
00676   for(size_t i = 0; i<32; ++i)
00677     {
00678       xpos = -waf_active/2. + i*waf_active/32. + waf_active/64.;
00679       cpv.position(DDLogicalPart("esalgo:SFSX"), DDName("SFWX","esalgo"), i+1, DDTranslation(xpos,0., 0.),DDRotation());
00680       
00681       LogDebug("SFGeom")<<" debug : SFSX, Logical part: "<<DDLogicalPart("esalgo:SFSX")<<"\n translation "<<DDTranslation(xpos,0.,0.)<<" rotation "<<DDRotation()<<" copy number= " <<i<<"\n";
00682       
00683       ypos = -waf_active/2. + i*waf_active/32. + waf_active/64.;
00684       cpv.position(DDLogicalPart("esalgo:SFSY"),DDName("SFWY","esalgo"), i+1, DDTranslation(0.,ypos, 0.), DDRotation());
00685       
00686       LogDebug("SFGeom")<<" debug : SFSY, Logical part: "<<DDLogicalPart("esalgo:SFSY")<<"\n translation "<<DDTranslation(0.,ypos,0.)<<" rotation "<<DDRotation()<< " copy number= " <<i<< "\n";
00687       
00688     }
00689 }