Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:29

0001 // -*- C++ -*-
0002 //
0003 // Package:     Calo
0004 // Class  :     FWTauProxyBuilderBase
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Alja Mrak-Tadel
0010 //         Created:  Thu Oct 21 20:40:28 CEST 2010
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "TGeoTube.h"
0017 #include "TEveJetCone.h"
0018 #include "TEveGeoNode.h"
0019 #include "TEveGeoShape.h"
0020 #include "TEveScalableStraightLineSet.h"
0021 #include "TEveTrack.h"
0022 
0023 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0024 #include "Fireworks/Calo/interface/FWTauProxyBuilderBase.h"
0025 #include "Fireworks/Calo/interface/makeEveJetCone.h"
0026 #include "Fireworks/Core/interface/Context.h"
0027 #include "Fireworks/Calo/interface/thetaBins.h"
0028 #include "Fireworks/Core/interface/BuilderUtils.h"
0029 #include "Fireworks/Core/interface/FWEventItem.h"
0030 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0031 #include "Fireworks/Core/interface/FWEventItem.h"
0032 #include "Fireworks/Core/interface/FWBeamSpot.h"
0033 
0034 #include "Fireworks/Tracks/interface/TrackUtils.h"
0035 
0036 #include "DataFormats/TauReco/interface/BaseTau.h"
0037 #include "DataFormats/TrackReco/interface/Track.h"
0038 
0039 static const std::string kTauApexBeamSpot("Place Apex In BeamSpot");
0040 FWTauProxyBuilderBase::FWTauProxyBuilderBase() : m_minTheta(0), m_maxTheta(0) {}
0041 
0042 FWTauProxyBuilderBase::~FWTauProxyBuilderBase() {}
0043 
0044 void FWTauProxyBuilderBase::setItem(const FWEventItem* iItem) {
0045   FWProxyBuilderBase::setItem(iItem);
0046   if (iItem) {
0047     iItem->getConfig()->assertParam(kTauApexBeamSpot, false);
0048   }
0049 }
0050 
0051 void FWTauProxyBuilderBase::buildBaseTau(const reco::BaseTau& iTau,
0052                                          const reco::Jet* iJet,
0053                                          TEveElement* comp,
0054                                          FWViewType::EType type,
0055                                          const FWViewContext* vc) {
0056   // track
0057   addLeadTrack(iTau, comp);
0058   addConstituentTracks(iTau, comp);
0059 
0060   // projected markers
0061   if (FWViewType::isProjected(type)) {
0062     double phi = iTau.phi();
0063     double theta = iTau.theta();
0064     double size = 1;
0065 
0066     bool barrel = (theta < context().caloTransAngle() || theta > (TMath::Pi() - context().caloTransAngle()));
0067     float ecalR = barrel ? context().caloR1() : context().caloR2();
0068     float ecalZ = barrel ? context().caloZ1() : context().caloZ2();
0069 
0070     TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet("energy");
0071 
0072     if (type == FWViewType::kRhoZ) {
0073       double r(0);
0074       (theta < context().caloTransAngle() || M_PI - theta < context().caloTransAngle()) ? r = ecalZ / fabs(cos(theta))
0075                                                                                         : r = ecalR / sin(theta);
0076 
0077       fireworks::addRhoZEnergyProjection(this, comp, ecalR, ecalZ, m_minTheta - 0.003, m_maxTheta + 0.003, phi);
0078 
0079       marker->SetScaleCenter(0., (phi > 0 ? r * fabs(sin(theta)) : -r * fabs(sin(theta))), r * cos(theta));
0080       marker->AddLine(0.,
0081                       (phi > 0 ? r * fabs(sin(theta)) : -r * fabs(sin(theta))),
0082                       r * cos(theta),
0083                       0.,
0084                       (phi > 0 ? (r + size) * fabs(sin(theta)) : -(r + size) * fabs(sin(theta))),
0085                       (r + size) * cos(theta));
0086 
0087     } else {
0088       std::pair<double, double> phiRange = fireworks::getPhiRange(m_phis, phi);
0089       double min_phi = phiRange.first - M_PI / 36 / 2;
0090       double max_phi = phiRange.second + M_PI / 36 / 2;
0091       TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
0092       TGeoBBox* sc_box = new TGeoTubeSeg(ecalR - 1, ecalR + 1, 1, min_phi * 180 / M_PI, max_phi * 180 / M_PI);
0093       TEveGeoShape* shape = fireworks::getShape("spread", sc_box, item()->defaultDisplayProperties().color());
0094       shape->SetPickable(kTRUE);
0095       setupAddElement(shape, comp);
0096 
0097       marker->SetScaleCenter(ecalR * cos(phi), ecalR * sin(phi), 0);
0098       marker->AddLine(ecalR * cos(phi), ecalR * sin(phi), 0, (ecalR + size) * cos(phi), (ecalR + size) * sin(phi), 0);
0099     }
0100     marker->SetLineWidth(4);
0101     FWViewEnergyScale* caloScale = vc->getEnergyScale();
0102     marker->SetScale(caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? iTau.et() : iTau.energy()));
0103     setupAddElement(marker, comp);
0104 
0105     context().voteMaxEtAndEnergy(iTau.et(), iTau.energy());
0106   } else if (iJet) {
0107     // jet
0108     TEveJetCone* cone = fireworks::makeEveJetCone(*iJet, context());
0109     if (item()->getConfig()->value<bool>(kTauApexBeamSpot)) {
0110       FWBeamSpot* bs = context().getBeamSpot();
0111       cone->SetApex(TEveVector(bs->x0(), bs->y0(), bs->z0()));
0112     }
0113     const FWDisplayProperties& dp = item()->defaultDisplayProperties();
0114     cone->SetFillColor(dp.color());
0115     cone->SetLineColor(dp.color());
0116     setupAddElement(cone, comp);
0117     cone->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5));
0118   }
0119 }
0120 
0121 // Tracks which passed quality cuts and are inside a tracker signal cone around leading Track
0122 void FWTauProxyBuilderBase::addConstituentTracks(const reco::BaseTau& tau, class TEveElement* product) {
0123   for (reco::TrackRefVector::iterator i = tau.signalTracks().begin(), iEnd = tau.signalTracks().end(); i != iEnd; ++i) {
0124     TEveTrack* track(nullptr);
0125     if (i->isAvailable()) {
0126       track = fireworks::prepareTrack(**i, context().getTrackPropagator());
0127       track->MakeTrack();
0128       setupAddElement(track, product);
0129     }
0130   }
0131 }
0132 
0133 // Leading Track
0134 void FWTauProxyBuilderBase::addLeadTrack(const reco::BaseTau& tau, class TEveElement* product) {
0135   const reco::TrackRef leadTrack = tau.leadTrack();
0136   if (!leadTrack)
0137     return;
0138 
0139   TEveTrack* track = fireworks::prepareTrack(*leadTrack, context().getTrackPropagator());
0140   if (track) {
0141     track->MakeTrack();
0142     setupAddElement(track, product);
0143   }
0144 }
0145 
0146 void FWTauProxyBuilderBase::localModelChanges(const FWModelId& iId,
0147                                               TEveElement* iCompound,
0148                                               FWViewType::EType viewType,
0149                                               const FWViewContext* vc) {
0150   if (FWViewType::isProjected(viewType))
0151     increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
0152 }
0153 
0154 void FWTauProxyBuilderBase::scaleProduct(TEveElementList* product,
0155                                          FWViewType::EType viewType,
0156                                          const FWViewContext* vc) {
0157   int idx = 0;
0158   for (auto& c : product->RefChildren()) {
0159     // check the compound has more than one element (the first one is jet)
0160     for (auto& compChld : c->RefChildren()) {
0161       TEveScalableStraightLineSet* lineSet = dynamic_cast<TEveScalableStraightLineSet*>(compChld);
0162       if (lineSet) {
0163         // compund index in the product is an index of model data in the collection
0164         const void* modelData = item()->modelData(idx);
0165         const reco::BaseTau* ptr = (const reco::BaseTau*)(modelData);
0166         float value = vc->getEnergyScale()->getPlotEt() ? ptr->et() : ptr->energy();
0167         lineSet->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value);
0168         for (TEveProjectable::ProjList_i j = lineSet->BeginProjecteds(); j != lineSet->EndProjecteds(); ++j) {
0169           (*j)->UpdateProjection();
0170         }
0171       }
0172     }
0173     idx++;
0174   }
0175 }
0176 
0177 void FWTauProxyBuilderBase::cleanLocal() {}