Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:20:55

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTIDRingAlgo.cc
0003 // Description: Position n copies of detectors in alternate positions and
0004 //              also associated ICC's
0005 // Em 17Sep07: Cool inserts moved to DDTIDModulePosAlgo.h
0006 ///////////////////////////////////////////////////////////////////////////////
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0010 #include "DetectorDescription/Core/interface/DDSplit.h"
0011 #include "DetectorDescription/Core/interface/DDTypes.h"
0012 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0013 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0014 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0015 #include <CLHEP/Units/SystemOfUnits.h>
0016 
0017 #include <string>
0018 #include <vector>
0019 
0020 using namespace std;
0021 
0022 class DDTIDRingAlgo : public DDAlgorithm {
0023 public:
0024   //Constructor and Destructor
0025   DDTIDRingAlgo();
0026   ~DDTIDRingAlgo() override;
0027 
0028   void initialize(const DDNumericArguments& nArgs,
0029                   const DDVectorArguments& vArgs,
0030                   const DDMapArguments& mArgs,
0031                   const DDStringArguments& sArgs,
0032                   const DDStringVectorArguments& vsArgs) override;
0033 
0034   void execute(DDCompactView& cpv) override;
0035 
0036 private:
0037   string idNameSpace;         //Namespace of this & ALL subparts
0038   vector<string> moduleName;  //Name of the module
0039   string iccName;             //Name of the ICC
0040 
0041   int number;              //Number of copies
0042   double startAngle;       //Phi offset
0043   double rModule;          //Location of module in R
0044   vector<double> zModule;  //                   in Z
0045   double rICC;             //Location of ICC    in R
0046   double sICC;             //Shift of ICC       per to R
0047   vector<double> zICC;     //                   in Z
0048 };
0049 
0050 DDTIDRingAlgo::DDTIDRingAlgo() { LogDebug("TIDGeom") << "DDTIDRingAlgo info: Creating an instance"; }
0051 
0052 DDTIDRingAlgo::~DDTIDRingAlgo() {}
0053 
0054 void DDTIDRingAlgo::initialize(const DDNumericArguments& nArgs,
0055                                const DDVectorArguments& vArgs,
0056                                const DDMapArguments&,
0057                                const DDStringArguments& sArgs,
0058                                const DDStringVectorArguments& vsArgs) {
0059   idNameSpace = DDCurrentNamespace::ns();
0060   moduleName = vsArgs["ModuleName"];
0061   iccName = sArgs["ICCName"];
0062   DDName parentName = parent().name();
0063   LogDebug("TIDGeom") << "DDTIDRingAlgo debug: Parent " << parentName << "\tModule " << moduleName[0] << ", "
0064                       << moduleName[1] << "\tICC " << iccName << "\tNameSpace " << idNameSpace;
0065 
0066   number = int(nArgs["Number"]);
0067   startAngle = nArgs["StartAngle"];
0068   rModule = nArgs["ModuleR"];
0069   zModule = vArgs["ModuleZ"];
0070   rICC = nArgs["ICCR"];
0071   sICC = nArgs["ICCShift"];
0072   zICC = vArgs["ICCZ"];
0073 
0074   LogDebug("TIDGeom") << "DDTIDRingAlgo debug: Parameters for positioning--"
0075                       << " StartAngle " << startAngle / CLHEP::deg << " Copy Numbers " << number << " Modules at R "
0076                       << rModule << " Z " << zModule[0] << ", " << zModule[1] << " ICCs at R " << rICC << " Z "
0077                       << zICC[0] << ", " << zICC[1];
0078 }
0079 
0080 void DDTIDRingAlgo::execute(DDCompactView& cpv) {
0081   double theta = 90. * CLHEP::deg;
0082   double phiy = 0. * CLHEP::deg;
0083   double dphi = CLHEP::twopi / number;
0084 
0085   DDName mother = parent().name();
0086   DDName module;
0087   DDName icc(DDSplit(iccName).first, DDSplit(iccName).second);
0088 
0089   //Loop over modules
0090   for (int i = 0; i < number; i++) {
0091     //First the module
0092     double phiz = startAngle + i * dphi;
0093     double xpos = rModule * cos(phiz);
0094     double ypos = rModule * sin(phiz);
0095     double zpos, thetay, phix;
0096     if (i % 2 == 0) {
0097       phix = phiz + 90. * CLHEP::deg;
0098       thetay = 0 * CLHEP::deg;
0099       zpos = zModule[0];
0100       module = DDName(DDSplit(moduleName[0]).first, DDSplit(moduleName[0]).second);
0101     } else {
0102       phix = phiz - 90. * CLHEP::deg;
0103       thetay = 180 * CLHEP::deg;
0104       zpos = zModule[1];
0105       module = DDName(DDSplit(moduleName[1]).first, DDSplit(moduleName[1]).second);
0106     }
0107 
0108     // stereo face inside toward structure, rphi face outside
0109     phix = phix - 180. * CLHEP::deg;
0110     thetay = thetay + 180. * CLHEP::deg;
0111     //
0112 
0113     DDTranslation trmod(xpos, ypos, zpos);
0114     double phideg = phiz / CLHEP::deg;
0115     DDRotation rotation;
0116     string rotstr = mother.name() + to_string(phideg * 10.);
0117     rotation = DDRotation(DDName(rotstr, idNameSpace));
0118     if (!rotation) {
0119       LogDebug("TIDGeom") << "DDTIDRingAlgo test: Creating a new rotation " << rotstr << "\t" << theta / CLHEP::deg
0120                           << ", " << phix / CLHEP::deg << ", " << thetay / CLHEP::deg << ", " << phiy / CLHEP::deg
0121                           << ", " << theta / CLHEP::deg << ", " << phiz / CLHEP::deg;
0122       rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, thetay, phiy, theta, phiz);
0123     }
0124 
0125     cpv.position(module, mother, i + 1, trmod, rotation);
0126     LogDebug("TIDGeom") << "DDTIDRingAlgo test: " << module << " number " << i + 1 << " positioned in " << mother
0127                         << " at " << trmod << " with " << rotation;
0128 
0129     //Now the ICC
0130     if (i % 2 == 0) {
0131       zpos = zICC[0];
0132       xpos = rICC * cos(phiz) + sICC * sin(phiz);
0133       ypos = rICC * sin(phiz) - sICC * cos(phiz);
0134     } else {
0135       zpos = zICC[1];
0136       xpos = rICC * cos(phiz) - sICC * sin(phiz);
0137       ypos = rICC * sin(phiz) + sICC * cos(phiz);
0138     }
0139     DDTranslation tricc(xpos, ypos, zpos);
0140     cpv.position(icc, mother, i + 1, tricc, rotation);
0141     LogDebug("TIDGeom") << "DDTIDRingAlgo test: " << icc << " number " << i + 1 << " positioned in " << mother << " at "
0142                         << tricc << " with " << rotation;
0143   }
0144 }
0145 
0146 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTIDRingAlgo, "track:DDTIDRingAlgo");