Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:31

0001 #include "FWPFEcalRecHitRPProxyBuilder.h"
0002 
0003 //______________________________________________________________________________
0004 void FWPFEcalRecHitRPProxyBuilder::scaleProduct(TEveElementList *parent,
0005                                                 FWViewType::EType type,
0006                                                 const FWViewContext *vc) {
0007   typedef std::vector<FWPFRhoPhiRecHit *> rpRecHits;
0008   unsigned int index = 0;
0009 
0010   for (rpRecHits::iterator i = m_towers.begin(); i != m_towers.end(); ++i) {
0011     m_towers[index]->updateScale(vc);
0012     index++;
0013   }
0014 }
0015 
0016 //______________________________________________________________________________
0017 void FWPFEcalRecHitRPProxyBuilder::cleanLocal() {
0018   typedef std::vector<FWPFRhoPhiRecHit *> rpRecHits;
0019   for (rpRecHits::iterator i = m_towers.begin(); i != m_towers.end(); ++i)
0020     (*i)->clean();
0021 
0022   m_towers.clear();
0023 }
0024 
0025 //______________________________________________________________________________
0026 TEveVector FWPFEcalRecHitRPProxyBuilder::calculateCentre(const float *vertices) {
0027   TEveVector centre;
0028 
0029   for (unsigned int i = 0; i < 8; i++) {
0030     int j = i * 3;
0031     centre.fX += vertices[j];
0032     centre.fY += vertices[j + 1];  // Total x,y,z values
0033     centre.fZ += vertices[j + 2];
0034   }
0035 
0036   centre *= 1.0f / 8.0f;  // Actually calculate the centre point
0037 
0038   return centre;
0039 }
0040 
0041 //______________________________________________________________________________
0042 void FWPFEcalRecHitRPProxyBuilder::build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) {
0043   m_towers.clear();  // Bug fix required for when multiple RhoPhiPF views are active
0044   for (unsigned int index = 0; index < static_cast<unsigned int>(iItem->size()); ++index) {
0045     TEveCompound *itemHolder = createCompound();
0046     product->AddElement(itemHolder);
0047     const FWEventItem::ModelInfo &info = item()->modelInfo(index);
0048 
0049     if (info.displayProperties().isVisible()) {
0050       bool added = false;
0051       float E, et;
0052       float ecalR = FWPFGeom::caloR1();
0053       Double_t lPhi, rPhi;
0054       const EcalRecHit &iData = modelData(index);
0055       const float *vertices = item()->getGeom()->getCorners(iData.detid());
0056 
0057       TEveVector centre = calculateCentre(vertices);
0058       TEveVector lVec = TEveVector(vertices[0], vertices[1], 0);   // Bottom left corner of tower
0059       TEveVector rVec = TEveVector(vertices[9], vertices[10], 0);  // Bottom right corner of tower
0060 
0061       lPhi = lVec.Phi();
0062       rPhi = rVec.Phi();
0063       E = iData.energy();
0064       et = FWPFMaths::calculateEt(centre, E);
0065 
0066       for (unsigned int i = 0; i < m_towers.size(); i++) {  // Small range to catch rounding inaccuracies etc.
0067         Double_t phi = m_towers[i]->getlPhi();
0068         if ((lPhi == phi) || ((lPhi < phi + 0.0005) && (lPhi > phi - 0.0005))) {
0069           m_towers[i]->addChild(this, itemHolder, vc, E, et);
0070           context().voteMaxEtAndEnergy(et, E);
0071           added = true;
0072           break;
0073         }
0074       }
0075 
0076       if (!added) {
0077         rVec.fX = ecalR * cos(rPhi);
0078         rVec.fY = ecalR * sin(rPhi);
0079         lVec.fX = ecalR * cos(lPhi);
0080         lVec.fY = ecalR * sin(lPhi);
0081         std::vector<TEveVector> bCorners(2);
0082         bCorners[0] = lVec;
0083         bCorners[1] = rVec;
0084 
0085         FWPFRhoPhiRecHit *rh = new FWPFRhoPhiRecHit(this, itemHolder, vc, E, et, lPhi, rPhi, bCorners);
0086         context().voteMaxEtAndEnergy(et, E);
0087         m_towers.push_back(rh);
0088       }
0089     }
0090   }
0091 }
0092 
0093 //______________________________________________________________________________
0094 REGISTER_FWPROXYBUILDER(FWPFEcalRecHitRPProxyBuilder, EcalRecHit, "PF Ecal RecHit", FWViewType::kRhoPhiPFBit);