CMS 3D CMS Logo

DDEcalEndcapAlgo.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 // Header files for endcap supercrystal geometry
7 #include <CLHEP/Geometry/Transform3D.h>
8 
9 #include <string>
10 #include <vector>
11 
12 using namespace std;
13 using namespace cms;
14 using namespace dd4hep;
15 using namespace cms_units::operators;
16 
17 using DDTranslation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
18 using DDRotation = ROOT::Math::Rotation3D;
19 
20 namespace {
21  struct Endcap {
22  string mat;
23  double zOff;
24 
25  string quaName;
26  string quaMat;
27 
28  string crysMat;
29  string wallMat;
30 
31  double crysLength;
32  double crysRear;
33  double crysFront;
34  double sCELength;
35  double sCERear;
36  double sCEFront;
37  double sCALength;
38  double sCARear;
39  double sCAFront;
40  double sCAWall;
41  double sCHLength;
42  double sCHSide;
43 
44  double nSCTypes;
45  vector<double> vecEESCProf;
46  double nColumns;
47  vector<double> vecEEShape;
48  double nSCCutaway;
49  vector<double> vecEESCCutaway;
50  double nSCquad;
51  vector<double> vecEESCCtrs;
52  double nCRSC;
53  vector<double> vecEECRCtrs;
54 
55  array<double, 3> cutParms;
56  string cutBoxName;
57 
58  string envName;
59  string alvName;
60  string intName;
61  string cryName;
62 
63  DDTranslation cryFCtr[5][5];
64  DDTranslation cryRCtr[5][5];
65  DDTranslation scrFCtr[10][10];
66  DDTranslation scrRCtr[10][10];
67 
68  double pFHalf;
69  double pFFifth;
70  double pF45;
71 
72  vector<double> vecEESCLims;
73 
74  double iLength;
75  double iXYOff;
76  double cryZOff;
77  double zFront;
78  };
79 
80  const Rotation3D& myrot(cms::DDNamespace& ns, const string& nam, const Rotation3D& r) {
81  ns.addRotation(nam, r);
82  return ns.rotation(ns.prepend(nam));
83  }
84 
85  string_view mynamespace(string_view input) {
86  string_view v = input;
87  auto trim_pos = v.find(':');
88  if (trim_pos != v.npos)
89  v.remove_suffix(v.size() - (trim_pos + 1));
90  return v;
91  }
92 } // namespace
93 
94 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
95  BenchmarkGrd counter("DDEcalEndcapAlgo");
96  cms::DDNamespace ns(ctxt, e, true);
98 
99  // TRICK!
100  string myns{mynamespace(args.parentName()).data(), mynamespace(args.parentName()).size()};
101 
102  Endcap ee;
103  ee.mat = args.str("EEMat");
104  ee.zOff = args.dble("EEzOff");
105 
106  ee.quaName = args.str("EEQuaName");
107  ee.quaMat = args.str("EEQuaMat");
108  ee.crysMat = args.str("EECrysMat");
109  ee.wallMat = args.str("EEWallMat");
110  ee.crysLength = args.dble("EECrysLength");
111  ee.crysRear = args.dble("EECrysRear");
112  ee.crysFront = args.dble("EECrysFront");
113  ee.sCELength = args.dble("EESCELength");
114  ee.sCERear = args.dble("EESCERear");
115  ee.sCEFront = args.dble("EESCEFront");
116  ee.sCALength = args.dble("EESCALength");
117  ee.sCARear = args.dble("EESCARear");
118  ee.sCAFront = args.dble("EESCAFront");
119  ee.sCAWall = args.dble("EESCAWall");
120  ee.sCHLength = args.dble("EESCHLength");
121  ee.sCHSide = args.dble("EESCHSide");
122  ee.nSCTypes = args.dble("EEnSCTypes");
123  ee.nColumns = args.dble("EEnColumns");
124  ee.nSCCutaway = args.dble("EEnSCCutaway");
125  ee.nSCquad = args.dble("EEnSCquad");
126  ee.nCRSC = args.dble("EEnCRSC");
127  ee.vecEESCProf = args.vecDble("EESCProf");
128  ee.vecEEShape = args.vecDble("EEShape");
129  ee.vecEESCCutaway = args.vecDble("EESCCutaway");
130  ee.vecEESCCtrs = args.vecDble("EESCCtrs");
131  ee.vecEECRCtrs = args.vecDble("EECRCtrs");
132 
133  ee.cutBoxName = args.str("EECutBoxName");
134 
135  ee.envName = args.str("EEEnvName");
136  ee.alvName = args.str("EEAlvName");
137  ee.intName = args.str("EEIntName");
138  ee.cryName = args.str("EECryName");
139 
140  ee.pFHalf = args.dble("EEPFHalf");
141  ee.pFFifth = args.dble("EEPFFifth");
142  ee.pF45 = args.dble("EEPF45");
143 
144  ee.vecEESCLims = args.vecDble("EESCLims");
145  ee.iLength = args.dble("EEiLength");
146  ee.iXYOff = args.dble("EEiXYOff");
147  ee.cryZOff = args.dble("EECryZOff");
148  ee.zFront = args.dble("EEzFront");
149 
150  // Position supercrystals in EE Quadrant
151 
152  //********************************* cutbox for trimming edge SCs
153  const double cutWid(ee.sCERear / sqrt(2.));
154  ee.cutParms[0] = cutWid;
155  ee.cutParms[1] = cutWid;
156  ee.cutParms[2] = ee.sCELength / sqrt(2.);
157  Solid eeCutBox = Box(ee.cutBoxName, ee.cutParms[0], ee.cutParms[1], ee.cutParms[2]);
158  //**************************************************************
159 
160  const double zFix(ee.zFront - 3172_mm); // fix for changing z offset
161 
162  //** fill supercrystal front and rear center positions from xml input
163  for (unsigned int iC(0); iC != (unsigned int)ee.nSCquad; ++iC) {
164  const unsigned int iOff(8 * iC);
165  const unsigned int ix((unsigned int)ee.vecEESCCtrs[iOff + 0]);
166  const unsigned int iy((unsigned int)ee.vecEESCCtrs[iOff + 1]);
167 
168  assert(ix > 0 && ix < 11 && iy > 0 && iy < 11);
169 
170  ee.scrFCtr[ix - 1][iy - 1] =
171  DDTranslation(ee.vecEESCCtrs[iOff + 2], ee.vecEESCCtrs[iOff + 4], ee.vecEESCCtrs[iOff + 6] + zFix);
172 
173  ee.scrRCtr[ix - 1][iy - 1] =
174  DDTranslation(ee.vecEESCCtrs[iOff + 3], ee.vecEESCCtrs[iOff + 5], ee.vecEESCCtrs[iOff + 7] + zFix);
175  }
176 
177  //** fill crystal front and rear center positions from xml input
178  for (unsigned int iC(0); iC != 25; ++iC) {
179  const unsigned int iOff(8 * iC);
180  const unsigned int ix((unsigned int)ee.vecEECRCtrs[iOff + 0]);
181  const unsigned int iy((unsigned int)ee.vecEECRCtrs[iOff + 1]);
182 
183  assert(ix > 0 && ix < 6 && iy > 0 && iy < 6);
184 
185  ee.cryFCtr[ix - 1][iy - 1] =
186  DDTranslation(ee.vecEECRCtrs[iOff + 2], ee.vecEECRCtrs[iOff + 4], ee.vecEECRCtrs[iOff + 6]);
187 
188  ee.cryRCtr[ix - 1][iy - 1] =
189  DDTranslation(ee.vecEECRCtrs[iOff + 3], ee.vecEECRCtrs[iOff + 5], ee.vecEECRCtrs[iOff + 7]);
190  }
191 
192  Solid eeCRSolid = Trap(ee.cryName,
193  0.5 * ee.crysLength,
194  atan((ee.crysRear - ee.crysFront) / (sqrt(2.) * ee.crysLength)),
195  45._deg,
196  0.5 * ee.crysFront,
197  0.5 * ee.crysFront,
198  0.5 * ee.crysFront,
199  0._deg,
200  0.5 * ee.crysRear,
201  0.5 * ee.crysRear,
202  0.5 * ee.crysRear,
203  0._deg);
204  Volume eeCRLog = Volume(ee.cryName, eeCRSolid, ns.material(ee.crysMat));
205 
206  for (unsigned int isc(0); isc < ee.nSCTypes; ++isc) {
207  unsigned int iSCType = isc + 1;
208  const string anum(std::to_string(iSCType));
209  const double eFront(0.5 * ee.sCEFront);
210  const double eRear(0.5 * ee.sCERear);
211  const double eAng(atan((ee.sCERear - ee.sCEFront) / (sqrt(2.) * ee.sCELength)));
212  const double ffived(45_deg);
213  const double zerod(0_deg);
214  string eeSCEnvName(1 == iSCType ? ee.envName + std::to_string(iSCType)
215  : (ee.envName + std::to_string(iSCType) + "Tmp"));
216  Solid eeSCEnv = ns.addSolidNS(
217  eeSCEnvName,
218  Trap(eeSCEnvName, 0.5 * ee.sCELength, eAng, ffived, eFront, eFront, eFront, zerod, eRear, eRear, eRear, zerod));
219 
220  const double aFront(0.5 * ee.sCAFront);
221  const double aRear(0.5 * ee.sCARear);
222  const double aAng(atan((ee.sCARear - ee.sCAFront) / (sqrt(2.) * ee.sCALength)));
223  string eeSCAlvName(
224  (1 == iSCType ? ee.alvName + std::to_string(iSCType) : (ee.alvName + std::to_string(iSCType) + "Tmp")));
225  Solid eeSCAlv = ns.addSolidNS(
226  eeSCAlvName,
227  Trap(eeSCAlvName, 0.5 * ee.sCALength, aAng, ffived, aFront, aFront, aFront, zerod, aRear, aRear, aRear, zerod));
228 
229  const double dwall(ee.sCAWall);
230  const double iFront(aFront - dwall);
231  const double iRear(iFront);
232  const double iLen(ee.iLength);
233  string eeSCIntName(1 == iSCType ? ee.intName + std::to_string(iSCType)
234  : (ee.intName + std::to_string(iSCType) + "Tmp"));
235  Solid eeSCInt = ns.addSolidNS(eeSCIntName,
236  Trap(eeSCIntName,
237  iLen / 2.,
238  atan((ee.sCARear - ee.sCAFront) / (sqrt(2.) * ee.sCALength)),
239  ffived,
240  iFront,
241  iFront,
242  iFront,
243  zerod,
244  iRear,
245  iRear,
246  iRear,
247  zerod));
248 
249  const double dz(-0.5 * (ee.sCELength - ee.sCALength));
250  const double dxy(0.5 * dz * (ee.sCERear - ee.sCEFront) / ee.sCELength);
251  const double zIOff(-(ee.sCALength - iLen) / 2.);
252  const double xyIOff(ee.iXYOff);
253 
254  Volume eeSCELog;
255  Volume eeSCALog;
256  Volume eeSCILog;
257 
258  if (1 == iSCType) { // standard SC in this block
259  eeSCELog = ns.addVolumeNS(Volume(myns + ee.envName + std::to_string(iSCType), eeSCEnv, ns.material(ee.mat)));
260  eeSCALog = Volume(ee.alvName + std::to_string(iSCType), eeSCAlv, ns.material(ee.wallMat));
261  eeSCILog = Volume(ee.intName + std::to_string(iSCType), eeSCInt, ns.material(ee.mat));
262  } else { // partial SCs this block: create subtraction volumes as appropriate
263  const double half(ee.cutParms[0] - ee.pFHalf * ee.crysRear);
264  const double fifth(ee.cutParms[0] + ee.pFFifth * ee.crysRear);
265  const double fac(ee.pF45);
266 
267  const double zmm(0_mm);
268 
269  DDTranslation cutTra(
270  2 == iSCType ? DDTranslation(zmm, half, zmm)
271  : (3 == iSCType ? DDTranslation(half, zmm, zmm)
272  : (4 == iSCType ? DDTranslation(zmm, -fifth, zmm)
273  : (5 == iSCType ? DDTranslation(-half * fac, -half * fac, zmm)
274  : DDTranslation(-fifth, zmm, zmm)))));
275 
276  const CLHEP::HepRotationZ cutm(ffived);
277 
278  Rotation3D cutRot(5 != iSCType ? Rotation3D()
279  : myrot(ns,
280  "EECry5Rot",
281  Rotation3D(cutm.xx(),
282  cutm.xy(),
283  cutm.xz(),
284  cutm.yx(),
285  cutm.yy(),
286  cutm.yz(),
287  cutm.zx(),
288  cutm.zy(),
289  cutm.zz())));
290 
291  Solid eeCutEnv = SubtractionSolid(ee.envName + std::to_string(iSCType),
292  ns.solid(ee.envName + std::to_string(iSCType) + "Tmp"),
293  eeCutBox,
294  Transform3D(cutRot, cutTra));
295 
296  const DDTranslation extra(dxy, dxy, dz);
297 
298  Solid eeCutAlv = SubtractionSolid(ee.alvName + std::to_string(iSCType),
299  ns.solid(ee.alvName + std::to_string(iSCType) + "Tmp"),
300  eeCutBox,
301  Transform3D(cutRot, cutTra - extra));
302 
303  const double mySign(iSCType < 4 ? +1. : -1.);
304 
305  const DDTranslation extraI(xyIOff + mySign * 2_mm, xyIOff + mySign * 2_mm, zIOff);
306 
307  Solid eeCutInt = SubtractionSolid(ee.intName + std::to_string(iSCType),
308  ns.solid(ee.intName + std::to_string(iSCType) + "Tmp"),
309  eeCutBox,
310  Transform3D(cutRot, cutTra - extraI));
311 
312  eeSCELog = ns.addVolumeNS(Volume(myns + ee.envName + std::to_string(iSCType), eeCutEnv, ns.material(ee.mat)));
313  eeSCALog = Volume(ee.alvName + std::to_string(iSCType), eeCutAlv, ns.material(ee.wallMat));
314  eeSCILog = Volume(ee.intName + std::to_string(iSCType), eeCutInt, ns.material(ee.mat));
315  }
316  eeSCELog.placeVolume(eeSCALog, iSCType * 100 + 1, Position(dxy, dxy, dz));
317  eeSCALog.placeVolume(eeSCILog, iSCType * 100 + 1, Position(xyIOff, xyIOff, zIOff));
318 
319  DDTranslation croffset(0., 0., 0.);
320 
321  // Position crystals within parent supercrystal interior volume
322  static const unsigned int ncol(5);
323 
324  if (iSCType > 0 && iSCType <= ee.nSCTypes) {
325  const unsigned int icoffset((iSCType - 1) * ncol - 1);
326 
327  // Loop over columns of SC
328  for (unsigned int icol(1); icol <= ncol; ++icol) {
329  // Get column limits for this SC type from xml input
330  const int ncrcol((int)ee.vecEESCProf[icoffset + icol]);
331 
332  const int imin(0 < ncrcol ? 1 : (0 > ncrcol ? ncol + ncrcol + 1 : 0));
333  const int imax(0 < ncrcol ? ncrcol : (0 > ncrcol ? ncol : 0));
334 
335  if (imax > 0) {
336  // Loop over crystals in this row
337  for (int irow(imin); irow <= imax; ++irow) {
338  // Create crystal as a DDEcalEndcapTrap object and calculate rotation and
339  // translation required to position it in the SC.
340  DDEcalEndcapTrap crystal(1, ee.crysFront, ee.crysRear, ee.crysLength);
341 
342  crystal.moveto(ee.cryFCtr[icol - 1][irow - 1], ee.cryRCtr[icol - 1][irow - 1]);
343 
344  string rname("EECrRoC" + std::to_string(icol) + "R" + std::to_string(irow));
345 
346  eeSCALog.placeVolume(
347  eeCRLog,
348  100 * iSCType + 10 * (icol - 1) + (irow - 1),
349  Transform3D(
350  myrot(ns, rname, crystal.rotation()),
351  Position(crystal.centrePos().x(), crystal.centrePos().y(), crystal.centrePos().z() - ee.cryZOff)));
352  }
353  }
354  }
355  }
356  }
357 
358  //** Loop over endcap columns
359  for (int icol = 1; icol <= int(ee.nColumns); icol++) {
360  //** Loop over SCs in column, using limits from xml input
361  for (int irow = int(ee.vecEEShape[2 * icol - 2]); irow <= int(ee.vecEEShape[2 * icol - 1]); ++irow) {
362  if (ee.vecEESCLims[0] <= icol && ee.vecEESCLims[1] >= icol && ee.vecEESCLims[2] <= irow &&
363  ee.vecEESCLims[3] >= irow) {
364  // Find SC type (complete or partial) for this location
365  unsigned int isctype = 1;
366 
367  for (unsigned int ii = 0; ii < (unsigned int)(ee.nSCCutaway); ++ii) {
368  if ((ee.vecEESCCutaway[3 * ii] == icol) && (ee.vecEESCCutaway[3 * ii + 1] == irow)) {
369  isctype = int(ee.vecEESCCutaway[3 * ii + 2]);
370  }
371  }
372 
373  // Create SC as a DDEcalEndcapTrap object and calculate rotation and
374  // translation required to position it in the endcap.
375  DDEcalEndcapTrap scrys(1, ee.sCEFront, ee.sCERear, ee.sCELength);
376  scrys.moveto(ee.scrFCtr[icol - 1][irow - 1], ee.scrRCtr[icol - 1][irow - 1]);
377  scrys.translate(DDTranslation(0., 0., -ee.zOff));
378 
379  string rname(ee.envName + std::to_string(isctype) + std::to_string(icol) + "R" + std::to_string(irow));
380  // Position SC in endcap
381  Volume quaLog = ns.volume(ee.quaName);
382  Volume childEnvLog = ns.volume(myns + ee.envName + std::to_string(isctype));
383  quaLog.placeVolume(childEnvLog,
384  100 * isctype + 10 * (icol - 1) + (irow - 1),
385  Transform3D(scrys.rotation(), scrys.centrePos()));
386  }
387  }
388  }
389 
390  return 1;
391 }
392 
393 DECLARE_DDCMS_DETELEMENT(DDCMS_ecal_DDEcalEndcapAlgo, algorithm)
DDEcalEndcapTrap::rotation
DDRotationMatrix rotation()
Definition: DDEcalEndcapTrap.h:35
writedatasetfile.args
args
Definition: writedatasetfile.py:18
cms_units::operators
Definition: CMSUnits.h:13
input
static const std::string input
Definition: EdmProvDump.cc:48
cms::DDNamespace::addRotation
void addRotation(const std::string &name, const dd4hep::Rotation3D &rot) const
Definition: DDNamespace.cc:120
reco::HaloData::Endcap
Endcap
Definition: HaloData.h:14
cms::DDNamespace::solid
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:240
DECLARE_DDCMS_DETELEMENT
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
cms::DDNamespace::material
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:116
cms::DDParsingContext
Definition: DDParsingContext.h:13
cms::DDNamespace
Definition: DDNamespace.h:16
cms::cuda::assert
assert(be >=bs)
findQualityFiles.v
v
Definition: findQualityFiles.py:179
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDEcalEndcapAlgo.cc:94
DDEcalEndcapTrap
Definition: DDEcalEndcapTrap.h:11
DDEcalEndcapTrap.h
DDTranslation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:60
PixelTestBeamValidation_cfi.Position
Position
Definition: PixelTestBeamValidation_cfi.py:75
cms::DDNamespace::rotation
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:125
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:47
rname
const G4String rname[NREG]
Definition: ParametrisedEMPhysics.cc:48
DDPlugins.h
createfilelist.int
int
Definition: createfilelist.py:10
cms::DDNamespace::addSolidNS
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:221
cms::DDAlgoArguments
Definition: DDAlgoArguments.h:28
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:17
BenchmarkGrd.h
cms::DDNamespace::addVolumeNS
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:145
alignCSCRings.r
r
Definition: alignCSCRings.py:93
align::Detector
Definition: StructureType.h:86
std
Definition: JetResolutionObject.h:76
PVValHelper::dxy
Definition: PVValidationHelpers.h:47
PVValHelper::dz
Definition: PVValidationHelpers.h:50
dd4hep
Definition: DDPlugins.h:8
BenchmarkGrd
Definition: BenchmarkGrd.h:9
DDEcalEndcapTrap::translate
void translate(const DDTranslation &trans)
Definition: DDEcalEndcapTrap.cc:118
DDRotation
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
CMSUnits.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
DDEcalEndcapTrap::centrePos
DDTranslation centrePos()
Definition: DDEcalEndcapTrap.cc:220
DDEcalEndcapTrap::moveto
void moveto(const DDTranslation &frontCentre, const DDTranslation &rearCentre)
Definition: DDEcalEndcapTrap.cc:132
cuy.ii
ii
Definition: cuy.py:590
cms::DDNamespace::volume
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:205
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
DDTranslation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDEcalEndcapAlgo.cc:17