Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** Implementation of the GEM Geometry Builder from GEM record stored in CondDB
0002  *
0003  *  \author M. Maggi - INFN Bari
0004  */
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "Geometry/GEMGeometryBuilder/src/GEMGeometryBuilderFromCondDB.h"
0007 #include "Geometry/GEMGeometry/interface/GEMEtaPartitionSpecs.h"
0008 
0009 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
0010 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
0011 #include "DataFormats/Math/interface/GeantUnits.h"
0012 
0013 #include <algorithm>
0014 
0015 using namespace geant_units::operators;
0016 
0017 GEMGeometryBuilderFromCondDB::GEMGeometryBuilderFromCondDB() {}
0018 
0019 GEMGeometryBuilderFromCondDB::~GEMGeometryBuilderFromCondDB() {}
0020 
0021 void GEMGeometryBuilderFromCondDB::build(GEMGeometry& theGeometry, const RecoIdealGeometry& rgeo) {
0022   const std::vector<DetId>& detids(rgeo.detIds());
0023   std::unordered_map<uint32_t, GEMSuperChamber*> superChambers;
0024   std::unordered_map<uint32_t, GEMChamber*> chambers;
0025   std::unordered_map<uint32_t, GEMEtaPartition*> partitions;
0026 
0027   for (unsigned int id = 0; id < detids.size(); ++id) {
0028     GEMDetId gemid(detids[id]);
0029     LogDebug("GEMGeometryBuilder") << "GEMGeometryBuilder adding " << gemid;
0030     if (gemid.roll() == 0) {
0031       if (gemid.layer() == 0) {
0032         GEMSuperChamber* gsc = buildSuperChamber(rgeo, id, gemid);
0033         superChambers.emplace(gemid.rawId(), gsc);
0034       } else {
0035         GEMChamber* gch = buildChamber(rgeo, id, gemid);
0036         chambers.emplace(gemid.rawId(), gch);
0037       }
0038     } else {
0039       GEMEtaPartition* gep = buildEtaPartition(rgeo, id, gemid);
0040       partitions.emplace(gemid.rawId(), gep);
0041     }
0042   }
0043 
0044   ////////////////////////////////////////////////////////////
0045   // TEMP - for backward compatability with old geometry
0046   // no superchambers or chambers in old geometry, using etpartitions
0047   if (superChambers.empty()) {
0048     for (unsigned int id = 0; id < detids.size(); ++id) {
0049       GEMDetId gemid(detids[id]);
0050       if (gemid.roll() == 1) {
0051         GEMChamber* gch = buildChamber(rgeo, id, gemid.chamberId());
0052         chambers.emplace(gemid.chamberId().rawId(), gch);
0053         if (gemid.layer() == 1) {
0054           GEMSuperChamber* gsc = buildSuperChamber(rgeo, id, gemid.superChamberId());
0055           superChambers.emplace(gemid.superChamberId().rawId(), gsc);
0056         }
0057       }
0058     }
0059   }
0060   ////////////////////////////////////////////////////////////
0061 
0062   // construct the regions, stations and rings.
0063   for (int re = -1; re <= 1; re = re + 2) {
0064     GEMRegion* region = new GEMRegion(re);
0065 
0066     for (int st = 0; st <= GEMDetId::maxStationId; ++st) {
0067       GEMStation* station = new GEMStation(re, st);
0068       std::string sign(re == -1 ? "-" : "");
0069       std::string name("GE" + sign + std::to_string(st) + "/1");
0070       station->setName(name);
0071 
0072       for (int ri = 1; ri <= 1; ++ri) {
0073         GEMRing* ring = new GEMRing(re, st, ri);
0074 
0075         for (auto sch : superChambers) {
0076           auto superChamber = sch.second;
0077           const GEMDetId scId(superChamber->id());
0078           if (scId.region() != re || scId.station() != st || scId.ring() != ri)
0079             continue;
0080           int ch = scId.chamber();
0081 
0082           for (int ly = 1; ly <= GEMDetId::maxLayerId; ++ly) {
0083             const GEMDetId chId(re, ri, st, ly, ch, 0);
0084             auto chamberIt = chambers.find(chId.rawId());
0085             if (chamberIt == chambers.end())
0086               continue;
0087             auto chamber = chamberIt->second;
0088 
0089             for (int roll = 1; roll <= GEMDetId::maxRollId; ++roll) {
0090               const GEMDetId rollId(re, ri, st, ly, ch, roll);
0091               auto gepIt = partitions.find(rollId.rawId());
0092               if (gepIt == partitions.end())
0093                 continue;
0094               auto gep = gepIt->second;
0095 
0096               chamber->add(gep);
0097               theGeometry.add(gep);
0098             }
0099 
0100             superChamber->add(chamber);
0101             theGeometry.add(chamber);
0102           }
0103 
0104           LogDebug("GEMGeometryBuilder") << "Adding super chamber " << scId << " to ring:";
0105           ring->add(superChamber);
0106           theGeometry.add(superChamber);
0107         }  // end superChambers
0108 
0109         if (ring->nSuperChambers()) {
0110           LogDebug("GEMGeometryBuilder") << "Adding ring " << ri << " to station "
0111                                          << "re " << re << " st " << st;
0112           station->add(ring);
0113           theGeometry.add(ring);
0114         } else {
0115           delete ring;
0116         }
0117       }  // end ring
0118 
0119       if (station->nRings()) {
0120         LogDebug("GEMGeometryBuilder") << "Adding station " << st << " to region " << re;
0121         region->add(station);
0122         theGeometry.add(station);
0123       } else {
0124         delete station;
0125       }
0126     }  // end station
0127 
0128     LogDebug("GEMGeometryBuilder") << "Adding region " << re << " to the geometry";
0129     theGeometry.add(region);
0130   }
0131 }
0132 
0133 GEMSuperChamber* GEMGeometryBuilderFromCondDB::buildSuperChamber(const RecoIdealGeometry& rgeo,
0134                                                                  unsigned int gid,
0135                                                                  GEMDetId detId) const {
0136   LogDebug("GEMGeometryBuilderFromCondDB") << "buildSuperChamber " << detId;
0137 
0138   RCPBoundPlane surf(boundPlane(rgeo, gid, detId));
0139 
0140   GEMSuperChamber* superChamber = new GEMSuperChamber(detId, surf);
0141   return superChamber;
0142 }
0143 
0144 GEMChamber* GEMGeometryBuilderFromCondDB::buildChamber(const RecoIdealGeometry& rgeo,
0145                                                        unsigned int gid,
0146                                                        GEMDetId detId) const {
0147   LogDebug("GEMGeometryBuilderFromCondDB") << "buildChamber " << detId;
0148 
0149   RCPBoundPlane surf(boundPlane(rgeo, gid, detId));
0150 
0151   GEMChamber* chamber = new GEMChamber(detId, surf);
0152   return chamber;
0153 }
0154 
0155 GEMEtaPartition* GEMGeometryBuilderFromCondDB::buildEtaPartition(const RecoIdealGeometry& rgeo,
0156                                                                  unsigned int gid,
0157                                                                  GEMDetId detId) const {
0158   std::vector<std::string>::const_iterator strStart = rgeo.strStart(gid);
0159   const std::string& name = *(strStart);
0160   LogDebug("GEMGeometryBuilderFromCondDB") << "buildEtaPartition " << name << " " << detId;
0161 
0162   std::vector<double>::const_iterator shapeStart = rgeo.shapeStart(gid);
0163   float be = convertMmToCm(*(shapeStart + 0));
0164   float te = convertMmToCm(*(shapeStart + 1));
0165   float ap = convertMmToCm(*(shapeStart + 2));
0166   float ti = convertMmToCm(*(shapeStart + 3));
0167   float nstrip = *(shapeStart + 4);
0168   float npad = *(shapeStart + 5);
0169   float dphi = (shapeStart + 6 < rgeo.shapeEnd(gid)) ? *(shapeStart + 6) : 0.17715;
0170 
0171   std::vector<float> pars;
0172   pars.emplace_back(be);
0173   pars.emplace_back(te);
0174   pars.emplace_back(ap);
0175   pars.emplace_back(nstrip);
0176   pars.emplace_back(npad);
0177   pars.emplace_back(dphi);
0178 
0179   RCPBoundPlane surf(boundPlane(rgeo, gid, detId));
0180   GEMEtaPartitionSpecs* e_p_specs = new GEMEtaPartitionSpecs(GeomDetEnumerators::GEM, name, pars);
0181 
0182   LogDebug("GEMGeometryBuilderFromCondDB") << "size " << be << " " << te << " " << ap << " " << ti;
0183   GEMEtaPartition* etaPartition = new GEMEtaPartition(detId, surf, e_p_specs);
0184   return etaPartition;
0185 }
0186 
0187 GEMGeometryBuilderFromCondDB::RCPBoundPlane GEMGeometryBuilderFromCondDB::boundPlane(const RecoIdealGeometry& rgeo,
0188                                                                                      unsigned int gid,
0189                                                                                      GEMDetId detId) const {
0190   std::vector<double>::const_iterator shapeStart = rgeo.shapeStart(gid);
0191   float be = convertMmToCm(*(shapeStart + 0));
0192   float te = convertMmToCm(*(shapeStart + 1));
0193   float ap = convertMmToCm(*(shapeStart + 2));
0194   float ti = convertMmToCm(*(shapeStart + 3));
0195   Bounds* bounds = new TrapezoidalPlaneBounds(be, te, ap, ti);
0196 
0197   std::vector<double>::const_iterator tranStart = rgeo.tranStart(gid);
0198   Surface::PositionType posResult(
0199       convertMmToCm(*(tranStart)), convertMmToCm(*(tranStart + 1)), convertMmToCm(*(tranStart + 2)));
0200 
0201   std::vector<double>::const_iterator rotStart = rgeo.rotStart(gid);
0202   Surface::RotationType rotResult(*(rotStart + 0),
0203                                   *(rotStart + 1),
0204                                   *(rotStart + 2),
0205                                   *(rotStart + 3),
0206                                   *(rotStart + 4),
0207                                   *(rotStart + 5),
0208                                   *(rotStart + 6),
0209                                   *(rotStart + 7),
0210                                   *(rotStart + 8));
0211 
0212   //Change of axes for the forward
0213   Basic3DVector<float> newX(1., 0., 0.);
0214   Basic3DVector<float> newY(0., 0., -1.);
0215   Basic3DVector<float> newZ(0., 1., 0.);
0216 
0217   rotResult.rotateAxes(newX, newY, newZ);
0218 
0219   return RCPBoundPlane(new BoundPlane(posResult, rotResult, bounds));
0220 }