CMS 3D CMS Logo

DDAHcalModuleAlgo.cc
Go to the documentation of this file.
1 // File: DDAHcalModuleAlgo.cc
3 // Description: Geometry factory class for HGCal (EE and HESil)
5 
6 #include <algorithm>
7 #include <cmath>
8 #include <string>
9 #include <vector>
10 
23 
24 //#define EDM_ML_DEBUG
25 
26 class DDAHcalModuleAlgo : public DDAlgorithm {
27 public:
28  // Constructor and Destructor
29  DDAHcalModuleAlgo(); // const std::string & name);
30 
31  void initialize(const DDNumericArguments& nArgs,
32  const DDVectorArguments& vArgs,
33  const DDMapArguments& mArgs,
34  const DDStringArguments& sArgs,
35  const DDStringVectorArguments& vsArgs) override;
36  void execute(DDCompactView& cpv) override;
37 
38 protected:
39  void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
41 
42 private:
43  static constexpr double tol_ = 0.00001;
44 
45  std::string tile_; // Scintillator tile
46  std::vector<std::string> materials_; // Materials
47  std::vector<std::string> names_; // Names
48  std::vector<double> thick_; // Thickness of the material
49  std::vector<int> copyNumber_; // Initial copy numbers
50  std::vector<int> layers_; // Number of layers in a section
51  std::vector<double> layerThick_; // Thickness of each section
52  std::vector<int> layerType_; // Type of the layer
53  std::vector<int> layerSense_; // Content of a layer (sensitive?)
54  std::vector<double> widths_; // Width (passive, active)
55  std::vector<double> heights_; // Heights (passive, active)
56  std::vector<int> tileN_; // # of tiles (along x, y)
57  std::vector<double> tileStep_; // Separation between tiles (x, y)
58  double zMinBlock_; // Starting z-value of the block
59  std::string idNameSpace_; // Namespace of this and ALL sub-parts
60 };
61 
63 #ifdef EDM_ML_DEBUG
64  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Creating an instance";
65 #endif
66 }
67 
69  const DDVectorArguments& vArgs,
70  const DDMapArguments&,
71  const DDStringArguments& sArgs,
72  const DDStringVectorArguments& vsArgs) {
73  tile_ = sArgs["TileName"];
74 #ifdef EDM_ML_DEBUG
75  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Tile " << tile_;
76 #endif
77  materials_ = vsArgs["MaterialNames"];
78  names_ = vsArgs["VolumeNames"];
79  thick_ = vArgs["Thickness"];
80  copyNumber_.resize(materials_.size(), 1);
81 #ifdef EDM_ML_DEBUG
82  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << materials_.size() << " types of volumes";
83  for (unsigned int i = 0; i < names_.size(); ++i)
84  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness " << thick_[i]
85  << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
86 #endif
87  layers_ = dbl_to_int(vArgs["Layers"]);
88  layerThick_ = vArgs["LayerThick"];
89 #ifdef EDM_ML_DEBUG
90  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layers_.size() << " blocks";
91  for (unsigned int i = 0; i < layers_.size(); ++i)
92  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " with " << layers_[i]
93  << " layers";
94 #endif
95  layerType_ = dbl_to_int(vArgs["LayerType"]);
96  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
97 #ifdef EDM_ML_DEBUG
98  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layerType_.size() << " layers";
99  for (unsigned int i = 0; i < layerType_.size(); ++i)
100  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
101  << layerSense_[i];
102 #endif
103  widths_ = vArgs["Widths"];
104  heights_ = vArgs["Heights"];
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << widths_.size() << " sizes for width "
107  << "and height:";
108  for (unsigned int i = 0; i < widths_.size(); ++i)
109  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << widths_[i] << ":" << heights_[i];
110 #endif
111  tileN_ = dbl_to_int(vArgs["TileN"]);
112  tileStep_ = vArgs["TileStep"];
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tileN_.size() << " tile positioning parameters";
115  for (unsigned int i = 0; i < tileN_.size(); ++i)
116  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << tileN_[i] << ":" << tileStep_[i];
117 #endif
118  zMinBlock_ = nArgs["zMinBlock"];
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << zMinBlock_ << " NameSpace " << idNameSpace_;
122 #endif
123 }
124 
126 // DDAHcalModuleAlgo methods...
128 
130 #ifdef EDM_ML_DEBUG
131  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDAHcalModuleAlgo...";
132 #endif
133  constructLayers(parent(), cpv);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HGCalGeom") << "<<== End of DDAHcalModuleAlgo construction";
136 #endif
137 }
138 
140 #ifdef EDM_ML_DEBUG
141  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: \t\tInside Layers";
142 #endif
143  double zi(zMinBlock_);
144  int laymin(0);
145  for (unsigned int i = 0; i < layers_.size(); i++) {
146  double zo = zi + layerThick_[i];
147  int laymax = laymin + layers_[i];
148  double zz = zi;
149  double thickTot(0);
150  for (int ly = laymin; ly < laymax; ++ly) {
151  int ii = layerType_[ly];
152  int copy = copyNumber_[ii];
153  zz += (0.5 * thick_[ii]);
154  thickTot += thick_[ii];
155 
156  std::string name = "HGCal" + names_[ii] + std::to_string(copy);
157 #ifdef EDM_ML_DEBUG
158  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii << " Front " << zi
159  << " Back " << zo << " superlayer thickness " << layerThick_[i];
160 #endif
162  DDMaterial matter(matName);
163  DDLogicalPart glog;
164  if (layerSense_[ly] == 0) {
165  DDSolid solid =
166  DDSolidFactory::box(DDName(name, idNameSpace_), 0.5 * widths_[0], 0.5 * heights_[0], 0.5 * thick_[ii]);
167  glog = DDLogicalPart(solid.ddname(), matter, solid);
168 #ifdef EDM_ML_DEBUG
169  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << matName
170  << " of dimensions " << 0.5 * widths_[0] << ", " << 0.5 * heights_[0] << ", "
171  << 0.5 * thick_[ii];
172 #endif
173  } else {
174  DDSolid solid =
175  DDSolidFactory::box(DDName(name, idNameSpace_), 0.5 * widths_[1], 0.5 * heights_[1], 0.5 * thick_[ii]);
176  glog = DDLogicalPart(solid.ddname(), matter, solid);
177 #ifdef EDM_ML_DEBUG
178  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << matName
179  << " of dimensions " << 0.5 * widths_[1] << ", " << 0.5 * heights_[1] << ", "
180  << 0.5 * thick_[ii];
181 #endif
182  positionSensitive(glog, cpv);
183  }
184  DDTranslation r1(0, 0, zz);
185  DDRotation rot;
186  cpv.position(glog, module, copy, r1, rot);
187  ++copyNumber_[ii];
188 #ifdef EDM_ML_DEBUG
189  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
190  << module.name() << " at " << r1 << " with " << rot;
191 #endif
192  zz += (0.5 * thick_[ii]);
193  } // End of loop over layers in a block
194  zi = zo;
195  laymin = laymax;
196  if (fabs(thickTot - layerThick_[i]) > tol_) {
197  if (thickTot > layerThick_[i]) {
198  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than thickness "
199  << thickTot << " of all its components **** ERROR ****\n";
200  } else {
201  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
202  << thickTot << " of the components\n";
203  }
204  }
205  } // End of loop over blocks
206 }
207 
209  int ncol = tileN_[0] / 2;
210  int nrow = tileN_[1] / 2;
211 #ifdef EDM_ML_DEBUG
212  int kount(0);
213  edm::LogVerbatim("HGCalGeom") << glog.ddname() << " Row " << nrow << " Column " << ncol;
214 #endif
215  for (int nr = -nrow; nr <= nrow; ++nr) {
216  int inr = (nr >= 0) ? nr : -nr;
217  double ypos = (nr >= 0) ? (inr - 0.5) * tileStep_[1] : -(inr - 0.5) * tileStep_[1];
218  for (int nc = -ncol; nc <= ncol; ++nc) {
219  int inc = (nc >= 0) ? nc : -nc;
220  double xpos = (nc >= 0) ? (inc - 0.5) * tileStep_[0] : -(inc - 0.5) * tileStep_[0];
221  if (nr != 0 && nc != 0) {
222  DDTranslation tran(xpos, ypos, 0.0);
224  int copy = inr * AHCalParameters::kColumn_ + inc;
225  if (nc < 0)
227  if (nr < 0)
230  cpv.position(name, glog.ddname(), copy, tran, rotation);
231 #ifdef EDM_ML_DEBUG
232  kount++;
233  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << name << " number " << copy << " positioned in "
234  << glog.ddname() << " at " << tran << " with " << rotation;
235 #endif
236  }
237  }
238  }
239 #ifdef EDM_ML_DEBUG
240  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << kount << " tiles for " << glog.ddname();
241 #endif
242 }
243 
244 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDAHcalModuleAlgo, "hgcal:DDAHcalModuleAlgo");
std::string idNameSpace_
std::vector< double > heights_
Log< level::Info, true > LogVerbatim
static constexpr int kSignRowColumn_
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
static constexpr double tol_
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
std::vector< double > layerThick_
std::vector< int > layers_
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
void execute(DDCompactView &cpv) override
static std::string & ns()
std::vector< std::string > materials_
Log< level::Error, false > LogError
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
static std::string to_string(const XMLCh *ch)
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
std::vector< int > layerType_
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::vector< double > tileStep_
static DDSolid box(const DDName &name, double xHalf, double yHalf, double zHalf)
Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf.
Definition: DDSolid.cc:547
ii
Definition: cuy.py:589
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
const N & name() const
Definition: DDBase.h:59
static constexpr int kRowColumn_
std::vector< double > widths_
std::vector< int > copyNumber_
const N & ddname() const
Definition: DDBase.h:61
std::vector< int > layerSense_
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::string > names_
Log< level::Warning, false > LogWarning
std::vector< int > tileN_
std::vector< double > thick_
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
static constexpr int kColumn_
Constants used.
void positionSensitive(DDLogicalPart &glog, DDCompactView &cpv)