Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:22:50

0001 #include "Phase2EndcapRingBuilder.h"
0002 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 using namespace edm;
0006 using namespace std;
0007 
0008 Phase2EndcapRing* Phase2EndcapRingBuilder::build(const GeometricDet* aPhase2EndcapRing,
0009                                                  const TrackerGeometry* theGeomDetGeometry,
0010                                                  const bool useBrothers) {
0011   vector<const GeometricDet*> allGeometricDets = aPhase2EndcapRing->components();
0012   vector<const GeometricDet*> compGeometricDets;
0013   LogDebug("TkDetLayers") << "Phase2EndcapRingBuilder with #Modules: " << allGeometricDets.size() << std::endl;
0014 
0015   vector<const GeomDet*> frontGeomDets;
0016   vector<const GeomDet*> backGeomDets;
0017   double meanZ = 0;
0018 
0019   if (!useBrothers) {
0020     //---- to evaluate meanZ
0021     for (vector<const GeometricDet*>::const_iterator compGeometricDets = allGeometricDets.begin();
0022          compGeometricDets != allGeometricDets.end();
0023          compGeometricDets++) {
0024       LogTrace("TkDetLayers") << " compGeometricDets->positionBounds().perp() "
0025                               << (*compGeometricDets)->positionBounds().z() << std::endl;
0026       meanZ = meanZ + (*compGeometricDets)->positionBounds().z();
0027     }
0028     meanZ = meanZ / allGeometricDets.size();
0029     LogDebug("TkDetLayers") << " meanZ " << meanZ << std::endl;
0030 
0031     for (vector<const GeometricDet*>::const_iterator compGeometricDets = allGeometricDets.begin();
0032          compGeometricDets != allGeometricDets.end();
0033          compGeometricDets++) {
0034       const GeomDet* theGeomDet = theGeomDetGeometry->idToDet((*compGeometricDets)->geographicalId());
0035 
0036       if (fabs((*compGeometricDets)->positionBounds().z()) < fabs(meanZ))
0037         frontGeomDets.push_back(theGeomDet);
0038 
0039       if (fabs((*compGeometricDets)->positionBounds().z()) > fabs(meanZ))
0040         backGeomDets.push_back(theGeomDet);
0041 
0042       if (fabs((*compGeometricDets)->positionBounds().z()) == fabs(meanZ))
0043         throw DetLayerException("Not possible to assiciate this GeometricDet in front or back");
0044     }
0045 
0046     LogDebug("TkDetLayers") << "frontGeomDets.size(): " << frontGeomDets.size();
0047     LogDebug("TkDetLayers") << "backGeomDets.size(): " << backGeomDets.size();
0048 
0049     return new Phase2EndcapRing(frontGeomDets, backGeomDets);
0050 
0051   } else {
0052     vector<const GeomDet*> frontGeomDetBrothers;
0053     vector<const GeomDet*> backGeomDetBrothers;
0054     vector<const GeometricDet*> compGeometricDets;
0055 
0056     //---- to evaluate meanZ
0057     double meanZ = 0;
0058     double meanZBrothers = 0;
0059     for (vector<const GeometricDet*>::const_iterator it = allGeometricDets.begin(); it != allGeometricDets.end();
0060          it++) {
0061       compGeometricDets = (*it)->components();
0062       if (compGeometricDets.size() != 2) {
0063         throw DetLayerException("Phase2OTEndcapRing is considered as a stack but does not have two components");
0064       } else {
0065         LogTrace("TkDetLayers") << " compGeometricDets[0]->positionBounds().perp() "
0066                                 << compGeometricDets[0]->positionBounds().z() << std::endl;
0067         LogTrace("TkDetLayers") << " compGeometricDets[1]->positionBounds().perp() "
0068                                 << compGeometricDets[1]->positionBounds().z() << std::endl;
0069         meanZ = meanZ + compGeometricDets[0]->positionBounds().z();
0070         meanZBrothers = meanZBrothers + compGeometricDets[1]->positionBounds().z();
0071       }
0072     }
0073     meanZ = meanZ / allGeometricDets.size();
0074     meanZBrothers = meanZBrothers / allGeometricDets.size();
0075     LogDebug("TkDetLayers") << " meanZ Lower " << meanZ << std::endl;
0076     LogDebug("TkDetLayers") << " meanZ Upper " << meanZBrothers << std::endl;
0077 
0078     for (vector<const GeometricDet*>::const_iterator it = allGeometricDets.begin(); it != allGeometricDets.end();
0079          it++) {
0080       compGeometricDets = (*it)->components();
0081       const GeomDet* theGeomDet = theGeomDetGeometry->idToDet(compGeometricDets[0]->geographicalId());
0082 
0083       if (fabs(compGeometricDets[0]->positionBounds().z()) < fabs(meanZ))
0084         frontGeomDets.push_back(theGeomDet);
0085 
0086       if (fabs(compGeometricDets[0]->positionBounds().z()) > fabs(meanZ))
0087         backGeomDets.push_back(theGeomDet);
0088 
0089       const GeomDet* theGeomDetBrother = theGeomDetGeometry->idToDet(compGeometricDets[1]->geographicalId());
0090 
0091       if (fabs(compGeometricDets[1]->positionBounds().z()) < fabs(meanZBrothers))
0092         frontGeomDetBrothers.push_back(theGeomDetBrother);
0093 
0094       if (fabs(compGeometricDets[1]->positionBounds().z()) > fabs(meanZBrothers))
0095         backGeomDetBrothers.push_back(theGeomDetBrother);
0096 
0097       if (fabs(compGeometricDets[0]->positionBounds().z()) == fabs(meanZ) ||
0098           fabs(compGeometricDets[1]->positionBounds().z()) == fabs(meanZBrothers))
0099         throw DetLayerException("Not possible to assiciate components of this GeometricDet in front or back");
0100     }
0101 
0102     LogDebug("TkDetLayers") << "frontGeomDets.size(): " << frontGeomDets.size();
0103     LogDebug("TkDetLayers") << "backGeomDets.size(): " << backGeomDets.size();
0104     LogDebug("TkDetLayers") << "frontGeomDetsBro.size(): " << frontGeomDetBrothers.size();
0105     LogDebug("TkDetLayers") << "backGeomDetsBro.size(): " << backGeomDetBrothers.size();
0106 
0107     return new Phase2EndcapRing(frontGeomDets, backGeomDets, frontGeomDetBrothers, backGeomDetBrothers);
0108   }
0109   return new Phase2EndcapRing(frontGeomDets, backGeomDets);
0110 }