Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:43

0001 #include "DataFormats/Math/interface/angle_units.h"
0002 #include "DetectorDescription/Core/interface/DDSplit.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "DD4hep/DetFactoryHelper.h"
0007 
0008 //#define EDM_ML_DEBUG
0009 using namespace angle_units::operators;
0010 
0011 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0012   cms::DDNamespace ns(ctxt, e, true);
0013   cms::DDAlgoArguments args(ctxt, e);
0014   // Header section
0015   std::string parentName = DDSplit(args.parentName()).first;
0016   std::string cellMat = args.value<std::string>("CellMaterial");                        //Cell material
0017   double cellDx = args.value<double>("CellDx");                                         //Cell size (x)
0018   double cellDy = args.value<double>("CellDy");                                         //Cell size (y)
0019   double cellDz = args.value<double>("CellDz");                                         //Cell size (z)
0020   double startY = args.value<double>("StartY");                                         //Starting Y for Cell
0021   std::vector<std::string> childName = args.value<std::vector<std::string> >("Child");  //Children name
0022   std::vector<int> number = args.value<std::vector<int> >("Number");                    //Number of cells
0023   std::vector<int> size = args.value<std::vector<int> >("Size");                        //Number of children
0024   std::vector<int> type = args.value<std::vector<int> >("Type");                        //First child
0025 #ifdef EDM_ML_DEBUG
0026   edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: Cell material " << cellMat << "\tCell Size "
0027                                << cms::convert2mm(cellDx) << ", " << cms::convert2mm(cellDy) << ", "
0028                                << cms::convert2mm(cellDz) << "\tStarting Y " << cms::convert2mm(startY) << "\tChildren "
0029                                << childName[0] << ", " << childName[1]
0030                                << "\n                         Cell positioning done for " << number.size() << " times";
0031   for (unsigned int i = 0; i < number.size(); ++i)
0032     edm::LogVerbatim("HCalGeom") << "\t" << i << " Number of children " << size[i] << " occurence " << number[i]
0033                                  << " first child index " << type[i];
0034   edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo debug: Parent " << args.parentName() << " NameSpace " << ns.name();
0035 #endif
0036 
0037   dd4hep::Volume parent = ns.volume(args.parentName());
0038   dd4hep::Material matter = ns.material(cellMat);
0039 
0040   double ypos = startY;
0041   int box = 0;
0042   for (unsigned int i = 0; i < number.size(); i++) {
0043     double dx = cellDx * size[i];
0044     int indx = type[i];
0045     for (int j = 0; j < number[i]; j++) {
0046       box++;
0047       std::string name = parentName + std::to_string(box);
0048       dd4hep::Solid solid = dd4hep::Box(ns.prepend(name), dx, cellDy, cellDz);
0049 #ifdef EDM_ML_DEBUG
0050       edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << solid.name() << " Box made of " << cellMat << " of Size "
0051                                    << cms::convert2mm(dx) << ", " << cms::convert2mm(cellDy) << ", "
0052                                    << cms::convert2mm(cellDz);
0053 #endif
0054       dd4hep::Volume glog(solid.name(), solid, matter);
0055 
0056       parent.placeVolume(glog, box, dd4hep::Position(0.0, ypos, 0.0));
0057 #ifdef EDM_ML_DEBUG
0058       edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << solid.name() << " number " << box << " positioned in "
0059                                    << parent.name() << " at (0.0, " << cms::convert2mm(ypos)
0060                                    << ", 0.0) with no rotation";
0061 #endif
0062 
0063       double xpos = -dx + cellDx;
0064       ypos += 2 * cellDy;
0065       indx = 1 - indx;
0066       for (int k = 0; k < size[i]; ++k) {
0067         glog.placeVolume(ns.volume(childName[indx]), k + 1, dd4hep::Position(xpos, 0.0, 0.0));
0068 #ifdef EDM_ML_DEBUG
0069         edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << childName[indx] << " number " << (k + 1)
0070                                      << " positioned in " << glog.name() << " at (" << cms::convert2mm(xpos)
0071                                      << ", 0,0, 0.0) with no rotation";
0072 #endif
0073         xpos += 2 * cellDx;
0074       }
0075     }
0076   }
0077 #ifdef EDM_ML_DEBUG
0078   edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalForwardAlgo construction";
0079 #endif
0080   return cms::s_executed;
0081 }
0082 
0083 // first argument is the type from the xml file
0084 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalForwardAlgo, algorithm);