Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWPFEcalRecHitLegoProxyBuilder.h"
0002 
0003 //______________________________________________________________________________
0004 void FWPFEcalRecHitLegoProxyBuilder::scaleProduct(TEveElementList *parent,
0005                                                   FWViewType::EType type,
0006                                                   const FWViewContext *vc) {
0007   FWViewEnergyScale *caloScale = vc->getEnergyScale();
0008   bool b = caloScale->getPlotEt();
0009   float maxVal = getMaxVal(b);
0010   typedef std::vector<FWPFLegoRecHit *> rh;
0011 
0012   // printf("FWPFEcalRecHitLegoProxyBuilder::scaleProduct >> scale %f \n", caloScale->getValToHeight());
0013   for (rh::iterator i = m_recHits.begin(); i != m_recHits.end(); ++i) {  // Tallest tower needs deciding still
0014     if ((*i)->isTallest() == false && (*i)->getEtEnergy(b) == maxVal)
0015       (*i)->setIsTallest(true);
0016 
0017     (*i)->updateScale(vc, getMaxValLog(caloScale->getPlotEt()));
0018   }
0019 }
0020 
0021 //______________________________________________________________________________
0022 void FWPFEcalRecHitLegoProxyBuilder::localModelChanges(const FWModelId &iId,
0023                                                        TEveElement *parent,
0024                                                        FWViewType::EType viewType,
0025                                                        const FWViewContext *vc) {
0026   for (TEveElement::List_i i = parent->BeginChildren(); i != parent->EndChildren(); ++i) {
0027     {
0028       TEveStraightLineSet *line = dynamic_cast<TEveStraightLineSet *>(*i);
0029       if (line) {
0030         line->SetMarkerColor(item()->modelInfo(iId.index()).displayProperties().color());
0031       }
0032     }
0033   }
0034 }
0035 
0036 //______________________________________________________________________________
0037 TEveVector FWPFEcalRecHitLegoProxyBuilder::calculateCentre(const std::vector<TEveVector> &corners) const {
0038   TEveVector centre;
0039 
0040   for (size_t i = 0; i < corners.size(); ++i) {
0041     centre.fX += corners[i].fX;
0042     centre.fY += corners[i].fY;  // Get total for x,y,z values
0043     centre.fZ += corners[i].fZ;
0044   }
0045   centre *= 1.f / 8.f;
0046 
0047   return centre;
0048 }
0049 
0050 //______________________________________________________________________________
0051 void FWPFEcalRecHitLegoProxyBuilder::build(const FWEventItem *iItem,
0052                                            TEveElementList *product,
0053                                            const FWViewContext *vc) {
0054   size_t itemSize = iItem->size();  //cache size
0055 
0056   for (size_t index = 0; index < itemSize; ++index) {
0057     TEveCompound *itemHolder = createCompound();
0058     product->AddElement(itemHolder);
0059 
0060     const EcalRecHit &iData = modelData(index);
0061     const float *corners = item()->getGeom()->getCorners(iData.detid());
0062     float energy, et;
0063     std::vector<TEveVector> etaphiCorners(8);
0064     TEveVector centre;
0065 
0066     if (corners == nullptr)
0067       continue;
0068 
0069     int k = 3;
0070     for (int i = 0; i < 4; ++i) {
0071       int j = k * 3;
0072       TEveVector cv = TEveVector(corners[j], corners[j + 1], corners[j + 2]);
0073       etaphiCorners[i].fX = cv.Eta();  // Conversion of rechit X/Y values for plotting in Eta/Phi
0074       etaphiCorners[i].fY = cv.Phi();
0075       etaphiCorners[i].fZ = 0.0;
0076 
0077       etaphiCorners[i + 4].fX =
0078           etaphiCorners[i].fX;  // Top can simply be plotted exactly over the top of the bottom face
0079       etaphiCorners[i + 4].fY = etaphiCorners[i].fY;
0080       etaphiCorners[i + 4].fZ = 0.001;
0081       // printf("%f %f %d \n",  etaphiCorners[i].fX, etaphiCorners[i].fY, i);
0082       --k;
0083     }
0084 
0085     centre = calculateCentre(etaphiCorners);
0086     energy = iData.energy();
0087     et = FWPFMaths::calculateEt(centre, energy);
0088     context().voteMaxEtAndEnergy(et, energy);
0089 
0090     if (energy > m_maxEnergy)
0091       m_maxEnergy = energy;
0092     if (energy > m_maxEt)
0093       m_maxEt = et;
0094 
0095     // Stop phi wrap
0096     float dPhi1 = etaphiCorners[2].fY - etaphiCorners[1].fY;
0097     float dPhi2 = etaphiCorners[3].fY - etaphiCorners[0].fY;
0098     float dPhi3 = etaphiCorners[1].fY - etaphiCorners[2].fY;
0099     float dPhi4 = etaphiCorners[0].fY - etaphiCorners[3].fY;
0100 
0101     if (dPhi1 > 1)
0102       etaphiCorners[2].fY = etaphiCorners[2].fY - (2 * TMath::Pi());
0103     if (dPhi2 > 1)
0104       etaphiCorners[3].fY = etaphiCorners[3].fY - (2 * TMath::Pi());
0105     if (dPhi3 > 1)
0106       etaphiCorners[2].fY = etaphiCorners[2].fY + (2 * TMath::Pi());
0107     if (dPhi4 > 1)
0108       etaphiCorners[3].fY = etaphiCorners[3].fY + (2 * TMath::Pi());
0109 
0110     FWPFLegoRecHit *recHit = new FWPFLegoRecHit(etaphiCorners, itemHolder, this, vc, energy, et);
0111     recHit->setSquareColor(item()->defaultDisplayProperties().color());
0112     m_recHits.push_back(recHit);
0113   }
0114 
0115   m_maxEnergyLog = log(m_maxEnergy);
0116   m_maxEtLog = log(m_maxEt);
0117 
0118   scaleProduct(product, FWViewType::kLegoPFECAL, vc);
0119 }
0120 
0121 //______________________________________________________________________________
0122 void FWPFEcalRecHitLegoProxyBuilder::cleanLocal() {
0123   for (std::vector<FWPFLegoRecHit *>::iterator i = m_recHits.begin(); i != m_recHits.end(); ++i)
0124     delete (*i);
0125 
0126   m_recHits.clear();
0127 }
0128 
0129 //______________________________________________________________________________
0130 REGISTER_FWPROXYBUILDER(FWPFEcalRecHitLegoProxyBuilder, EcalRecHit, "PF Ecal RecHit", FWViewType::kLegoPFECALBit);