Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:43

0001 #include "ForwardDiskSectorBuilderFromWedges.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
0005 
0006 using namespace std;
0007 
0008 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
0009 BoundDiskSector* ForwardDiskSectorBuilderFromWedges::operator()(const vector<const TECWedge*>& wedges) const {
0010   // check first that all wedges are about at the same phi and z !
0011   float phiStart = wedges.front()->position().phi();
0012   float zStart = wedges.front()->position().z();
0013   float wphimin, wphimax;
0014   for (vector<const TECWedge*>::const_iterator i = wedges.begin(); i != wedges.end(); i++) {
0015     float zdiff = (**i).surface().position().z() - zStart;
0016     if (std::abs(zdiff) > 5.)
0017       edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges: Trying to build "
0018                                    << "Petal from Wedges at different z ! Delta Z = " << zdiff;
0019     float wphi = (**i).surface().position().phi();
0020     if (Geom::phiLess(phiStart, wphi)) {
0021       wphimin = phiStart;
0022       wphimax = wphi;
0023     } else {
0024       wphimin = wphi;
0025       wphimax = phiStart;
0026     }
0027     float phidiff = wphimax - wphimin;
0028     if (phidiff < 0.)
0029       phidiff += 2. * Geom::pi();
0030     if (phidiff > 0.3)
0031       edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges: Trying to build "
0032                                    << "Petal from Wedges at different phi ! Delta phi = " << phidiff;
0033   }
0034 
0035   auto bo = computeBounds(wedges);
0036 
0037   Surface::PositionType pos(bo.second.x(), bo.second.y(), bo.second.z());
0038   Surface::RotationType rot = computeRotation(wedges, pos);
0039   return new BoundDiskSector(pos, rot, bo.first);
0040 }
0041 
0042 pair<DiskSectorBounds*, GlobalVector> ForwardDiskSectorBuilderFromWedges::computeBounds(
0043     const vector<const TECWedge*>& wedges) const {
0044   // compute maximum and minimum radius and phi
0045   float rmin((**(wedges.begin())).specificSurface().innerRadius());
0046   float rmax(rmin);
0047   float zmin((**(wedges.begin())).surface().position().z());
0048   float zmax(zmin);
0049   float phimin((**(wedges.begin())).surface().position().phi());
0050   float phimax(phimin);
0051 
0052   for (vector<const TECWedge*>::const_iterator iw = wedges.begin(); iw != wedges.end(); iw++) {
0053     // edm::LogInfo(TkDetLayers) << "---------------------------------------------" ;
0054     // edm::LogInfo(TkDetLayers) <<   " Builder: Position of wedge     :" << (**iw).position() ;
0055     float ri = (**iw).specificSurface().innerRadius();
0056     float ro = (**iw).specificSurface().outerRadius();
0057     float zmi = (**iw).surface().position().z() - (**iw).specificSurface().bounds().thickness() / 2.;
0058     float zma = (**iw).surface().position().z() + (**iw).specificSurface().bounds().thickness() / 2.;
0059     float phi1 = (**iw).surface().position().phi() - (**iw).specificSurface().phiHalfExtension();
0060     float phi2 = (**iw).surface().position().phi() + (**iw).specificSurface().phiHalfExtension();
0061     rmin = min(rmin, ri);
0062     rmax = max(rmax, ro);
0063     zmin = min(zmin, zmi);
0064     zmax = max(zmax, zma);
0065     if (Geom::phiLess(phi1, phimin))
0066       phimin = phi1;
0067     if (Geom::phiLess(phimax, phi2))
0068       phimax = phi2;
0069   }
0070 
0071   if (!Geom::phiLess(phimin, phimax))
0072     edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges : "
0073                                  << "Something went wrong with Phi Sorting !";
0074   float zPos = (zmax + zmin) / 2.;
0075   float phiWin = phimax - phimin;
0076   float phiPos = (phimax + phimin) / 2.;
0077   float rmed = (rmin + rmax) / 2.;
0078   if (phiWin < 0.) {
0079     if ((phimin < Geom::pi() / 2.) || (phimax > -Geom::pi() / 2.)) {
0080       edm::LogError("TkDetLayers") << " Debug: something strange going on, please check ";
0081     }
0082     // edm::LogInfo(TkDetLayers) << " Petal at pi: phi " << phimin << " " << phimax << " " << phiWin
0083     //   << " " << 2.*Geom::pi()+phiWin << " " ;
0084     phiWin += 2. * Geom::pi();
0085     phiPos += Geom::pi();
0086   }
0087 
0088   GlobalVector pos(rmed * cos(phiPos), rmed * sin(phiPos), zPos);
0089   return make_pair(new DiskSectorBounds(rmin, rmax, zmin - zPos, zmax - zPos, phiWin), pos);
0090 }
0091 
0092 Surface::RotationType ForwardDiskSectorBuilderFromWedges::computeRotation(const vector<const TECWedge*>& wedges,
0093                                                                           Surface::PositionType pos) const {
0094   GlobalVector yAxis = (GlobalVector(pos.x(), pos.y(), 0.)).unit();
0095 
0096   GlobalVector zAxis(0., 0., 1.);
0097   GlobalVector xAxis = yAxis.cross(zAxis);
0098 
0099   return Surface::RotationType(xAxis, yAxis);
0100 }