PageRenderTime 36ms CodeModel.GetById 8ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/DetectorDescription/Parser/src/DDDividedCons.cc

https://github.com/aivanov-cern/cmssw
C++ | 323 lines | 260 code | 46 blank | 17 comment | 22 complexity | 2bf37b7ce7832c84cd52e880d5a090f2 MD5 | raw file
  1//
  2// ********************************************************************
  3// 25.04.04 - M. Case ddd-ize G4ParameterisationCons*
  4// ********************************************************************
  5
  6#include "DetectorDescription/Parser/src/DDDividedCons.h"
  7#include "DetectorDescription/Parser/src/DDXMLElement.h"
  8
  9#include "DetectorDescription/Core/interface/DDLogicalPart.h"
 10#include "DetectorDescription/Core/interface/DDName.h"
 11#include "DetectorDescription/Core/interface/DDAxes.h"
 12#include "DetectorDescription/Core/interface/DDSolid.h"
 13#include "DetectorDescription/Core/interface/DDMaterial.h"
 14
 15#include "DetectorDescription/Base/interface/DDdebug.h"
 16#include "DetectorDescription/Base/interface/DDRotationMatrix.h"
 17
 18#include "CLHEP/Units/GlobalSystemOfUnits.h"
 19
 20DDDividedConsRho::DDDividedConsRho( const DDDivision& div, DDCompactView* cpv )
 21  : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
 22{
 23  checkParametersValidity();
 24  setType( "DivisionConsRho" );
 25  DDCons msol = (DDCons)(div_.parent().solid());
 26
 27  if( msol.rInPlusZ() == 0. )
 28  {
 29    std::cout << "WARNING - DDDividedConsRho, rOutMinusZ = 0. "
 30	      << std::endl 
 31	      << "          Width is calculated as that of rOutMinusZ !"
 32	      << std::endl;
 33  } 
 34      
 35  if( divisionType_ == DivWIDTH )
 36  {
 37    compNDiv_ = calculateNDiv( msol.rOutMinusZ()
 38			       - msol.rInMinusZ(), div_.width(), div_.offset() );
 39  }
 40  else if( divisionType_ == DivNDIV )
 41  {
 42    DDCons msol = (DDCons)(div_.parent().solid());
 43    compWidth_ = calculateWidth( msol.rOutMinusZ() - msol.rInMinusZ()
 44				 , div_.nReplicas()
 45				 , div_.offset() );
 46  }
 47
 48  DCOUT_V( 'P', " DDDividedConsRho - no divisions " << compNDiv_ << " = " << div_.nReplicas()
 49	   << "\n Offset " << div_.offset()
 50	   << "\n Width " << compWidth_ << " = " << div_.width()
 51	   << "\n DivType " << divisionType_);  
 52}
 53
 54DDDividedConsRho::~DDDividedConsRho( void )
 55{}
 56
 57double
 58DDDividedConsRho::getMaxParameter( void ) const
 59{
 60  DDCons msol = (DDCons)(div_.parent().solid());
 61  return msol.rOutMinusZ() - msol.rInMinusZ();
 62
 63}
 64
 65DDRotation
 66DDDividedConsRho::makeDDRotation( const int copyNo ) const
 67{
 68  DDRotation myddrot; // sets to identity.
 69  DCOUT_V ('P', "DDDividedConsRho::makeDDRotation : " << myddrot);
 70  return myddrot;
 71}
 72
 73DDTranslation
 74DDDividedConsRho::makeDDTranslation( const int copyNo ) const
 75{
 76  //----- translation 
 77  DDTranslation translation;
 78  DCOUT_V ('P', " DDDividedConsRho " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
 79  return translation;
 80}
 81
 82DDLogicalPart
 83DDDividedConsRho::makeDDLogicalPart( const int copyNo ) const
 84{ 
 85  DDName solname(div_.parent().ddname().name() + "_DIVCHILD" 
 86		 + DDXMLElement::itostr(copyNo) 
 87		 , div_.parent().ddname().ns());
 88  DDSolid ddcons(solname);
 89  DDMaterial usemat(div_.parent().material());
 90  DDCons msol = (DDCons)(div_.parent().solid());
 91
 92  double pRMin1 = msol.rInMinusZ() + div_.offset() + compWidth_ * copyNo;
 93  double pRMax1 = msol.rInMinusZ() + div_.offset() + compWidth_ * (copyNo+1);
 94 
 95  //width at Z Plus
 96  //- double compWidth_Plus =
 97  //   compWidth_ * ( msol.rOutPlusZ()/ msol.rInPlusZ())
 98  //-         / ( msol.rOutMinusZ() - msol.rInMinusZ());
 99  double compWidth_Plus = calculateWidth( msol.rOutPlusZ()
100					  - msol.rInPlusZ(), compNDiv_, div_.offset() );
101  double pRMin2 = msol.rInPlusZ()
102		  + div_.offset() + compWidth_Plus * copyNo;
103  double pRMax2 = msol.rInPlusZ()
104		  + div_.offset() + compWidth_Plus * (copyNo+1);
105  double pDz = msol.zhalf();
106
107  double pSPhi = msol.phiFrom();
108  double pDPhi = msol.deltaPhi();
109
110  ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1
111				, pRMin2, pRMax2, pSPhi, pDPhi);      
112  
113  DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
114  DCOUT_V( 'P', " DDDividedConsRho::makeDDLogicalPart() lp:" << ddlp );
115  return ddlp;
116}
117
118//--------------------------------------------------------------------------
119//--------------------------------------------------------------------------
120DDDividedConsPhi::DDDividedConsPhi( const DDDivision& div, DDCompactView* cpv )
121  : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
122{
123  checkParametersValidity();
124  setType( "DivisionConsPhi" );
125  DDCons msol = (DDCons)(div_.parent().solid());
126
127  if( divisionType_ == DivWIDTH )
128  {
129    DDCons msol = (DDCons)(div_.parent().solid());
130    //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
131    if( msol.deltaPhi() == 360.*deg )
132    {
133      compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
134    }
135    else
136    {
137      compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
138    }
139  }
140  else if( divisionType_ == DivNDIV )
141  {
142    DDCons msol = (DDCons)(div_.parent().solid());
143    if( msol.deltaPhi() == 360.*deg )
144    {
145      compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
146    }
147    else
148    {
149      compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
150    }
151  }
152
153  DCOUT_V( 'P', " DDDividedConsPhi - no divisions " << compNDiv_ << " = " << div_.nReplicas()
154	   << "\n Offset " << div_.offset()
155	   << "\n Width " << compWidth_ << " = " << div_.width()
156	   << "\n DivType " << divisionType_); 
157}
158
159DDDividedConsPhi::~DDDividedConsPhi( void )
160{}
161
162double
163DDDividedConsPhi::getMaxParameter( void ) const
164{
165  DDCons msol = (DDCons)(div_.parent().solid());
166  return msol.deltaPhi();
167}
168
169DDRotation
170DDDividedConsPhi::makeDDRotation( const int copyNo ) const
171{
172  DDRotation myddrot; // sets to identity.
173  double posi = ( copyNo - 1 ) * compWidth_;
174  DDRotationMatrix* rotMat = changeRotMatrix( posi );
175  // how to name the rotation??
176  // i hate this crap :-)
177  DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr(copyNo)
178		   , div_.parent().ddname().ns());
179  myddrot = DDrot(ddrotname, rotMat);
180
181  DCOUT_V ('P', "DDDividedConsPhi::makeDDRotation : " << myddrot);
182  return myddrot;
183}
184
185DDTranslation
186DDDividedConsPhi::makeDDTranslation( const int copyNo ) const
187{
188  //----- translation 
189  DDTranslation translation;  
190  DCOUT_V( 'P', " DDDividedConsPhi " << "\n\t Position: " << translation
191	   << " - Width: " << compWidth_
192	   << " - Axis " << DDAxesNames::name(div_.axis()));
193  return translation;
194}
195
196DDLogicalPart
197DDDividedConsPhi::makeDDLogicalPart( const int copyNo ) const
198{ 
199  DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
200		 , div_.parent().ddname().ns());
201  DDSolid ddcons(solname);
202  DDMaterial usemat(div_.parent().material());
203  DDCons msol = (DDCons)(div_.parent().solid());
204
205  if (!ddcons.isDefined().second)
206  {
207    double pRMin1 = msol.rInMinusZ();
208    double pRMax1 = msol.rOutMinusZ();
209    double pRMin2 = msol.rInPlusZ();
210    double pRMax2 = msol.rOutPlusZ();
211    double pDz = msol.zhalf();
212	  
213    //- already rotated  double pSPhi = div_.offset() + copyNo*compWidth_;
214    double pSPhi = div_.offset() + msol.phiFrom();
215    double pDPhi = compWidth_;
216    ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1
217				  , pRMin2, pRMax2, pSPhi, pDPhi);      
218  }
219  
220  DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
221  DCOUT_V ('P', " DDDividedConsPhi::makeDDLogicalPart() lp:" << ddlp);
222  return ddlp;
223}
224
225DDDividedConsZ::DDDividedConsZ( const DDDivision& div, DDCompactView* cpv )
226  :  DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
227{
228  checkParametersValidity();
229
230  DDCons msol = (DDCons)(div_.parent().solid());
231  setType( "DivisionConsZ" );
232      
233  if( divisionType_ == DivWIDTH )
234  {
235    DDCons msol = (DDCons)(div_.parent().solid());
236    compNDiv_ = calculateNDiv( 2*msol.zhalf()
237			       , div_.width(), div_.offset() );
238  }
239  else if( divisionType_ == DivNDIV )
240  {
241    DDCons msol = (DDCons)(div_.parent().solid());
242    compWidth_ = calculateWidth( 2*msol.zhalf()
243				 , div_.nReplicas(), div_.offset() );
244  }
245
246  DCOUT_V( 'P', " DDDividedConsZ - no divisions " << compNDiv_ << " = " << div_.nReplicas()
247	   << "\n Offset " << div_.offset()
248	   << "\n Width " << compWidth_ << " = " << div_.width()
249	   << "\n DivType " << divisionType_ );
250}
251
252DDDividedConsZ::~DDDividedConsZ( void )
253{}
254
255double
256DDDividedConsZ::getMaxParameter( void ) const
257{
258  DDCons msol = (DDCons)(div_.parent().solid());
259  return 2*msol.zhalf();
260}
261
262DDRotation
263DDDividedConsZ::makeDDRotation( const int copyNo ) const
264{
265  DDRotation myddrot; // sets to identity.
266  DCOUT_V ('P', "DDDividedConsZ::makeDDRotation : " << myddrot);
267  return myddrot;
268}
269
270DDTranslation
271DDDividedConsZ::makeDDTranslation( const int copyNo ) const
272{
273  //----- translation 
274  DDTranslation translation;
275
276  DDCons motherCons = (DDCons)(div_.parent().solid());
277  double posi = - motherCons.zhalf() + div_.offset() 
278		+ compWidth_/2 + copyNo*compWidth_;
279  translation.SetZ(posi); 
280  
281  DCOUT_V ('P', " DDDividedConsZ " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
282  return translation;
283}
284
285DDLogicalPart
286DDDividedConsZ::makeDDLogicalPart( const int copyNo ) const
287{ 
288  DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo) 
289		 , div_.parent().ddname().ns());
290  DDSolid ddcons(solname);
291  DDMaterial usemat(div_.parent().material());
292  DDCons msol = (DDCons)(div_.parent().solid());
293
294  double mHalfLength = msol.zhalf();
295  double aRInner = (msol.rInPlusZ()
296		    - msol.rInMinusZ()) / (2*mHalfLength);
297  double bRInner = (msol.rInPlusZ()
298		    + msol.rInMinusZ()) / 2;
299  double aROuter = (msol.rOutPlusZ()
300		    - msol.rOutMinusZ()) / (2*mHalfLength);
301  double bROuter = (msol.rOutPlusZ()
302		    + msol.rOutMinusZ()) / 2;
303  double xMinusZ = -mHalfLength + div_.offset() + compWidth_*copyNo;
304  double xPlusZ  = -mHalfLength + div_.offset() + compWidth_*(copyNo+1);
305
306  double pDz = compWidth_ / 2.;
307  double pSPhi = msol.phiFrom();
308  double pDPhi = msol.deltaPhi();
309
310  ddcons = DDSolidFactory::cons(DDName(solname)
311				, pDz
312				, aRInner * xMinusZ + bRInner
313				, aROuter * xMinusZ + bROuter
314				, aRInner * xPlusZ + bRInner
315				, aROuter * xPlusZ + bROuter
316				, pSPhi
317				, pDPhi
318    );
319  
320  DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
321  DCOUT_V( 'P', " DDDividedConsZ::makeDDLogicalPart() lp:" << ddlp );
322  return ddlp;
323}