Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     Context
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Sep 30 14:57:12 EDT 2008
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "TH2.h"
0017 #include "TMath.h"
0018 #include "TEveTrackPropagator.h"
0019 #include "TEveCaloData.h"
0020 #include "Fireworks/Core/interface/fw3dlego_xbins.h"
0021 
0022 #include "Fireworks/Core/interface/Context.h"
0023 #include "Fireworks/Core/interface/FWMagField.h"
0024 #include "Fireworks/Core/interface/FWBeamSpot.h"
0025 #include "Fireworks/Core/interface/CmsShowCommon.h"
0026 
0027 #include <functional>
0028 
0029 using namespace fireworks;
0030 
0031 Context* Context::s_fwContext = nullptr;
0032 
0033 const float Context::s_caloTransEta = 1.479;
0034 const float Context::s_caloTransAngle = 2 * atan(exp(-s_caloTransEta));
0035 
0036 // simplified
0037 const float Context::s_caloZ = 290;
0038 const float Context::s_caloR = s_caloZ * tan(s_caloTransAngle);
0039 
0040 /*
0041 // barrel
0042 const float Context::s_caloR1 = 129;
0043 const float Context::s_caloZ1 = s_caloR1/tan(s_caloTransAngle);
0044 // endcap
0045 const float Context::s_caloZ2 = 315.4;
0046 const float Context::s_caloR2 = s_caloZ2*tan(s_caloTransAngle);
0047 */
0048 
0049 // calorimeter offset between TEveCalo and outlines (used by proxy builders)
0050 const float Context::s_caloOffR = 10;
0051 const float Context::s_caloOffZ = s_caloOffR / tan(s_caloTransAngle);
0052 
0053 //
0054 // constructors and destructor
0055 //
0056 Context::Context(FWModelChangeManager* iCM,
0057                  FWSelectionManager* iSM,
0058                  FWEventItemsManager* iEM,
0059                  FWColorManager* iColorM,
0060                  FWJobMetadataManager* iJMDM)
0061     : m_changeManager(iCM),
0062       m_selectionManager(iSM),
0063       m_eventItemsManager(iEM),
0064       m_colorManager(iColorM),
0065       m_metadataManager(iJMDM),
0066       m_geom(nullptr),
0067       m_propagator(nullptr),
0068       m_trackerPropagator(nullptr),
0069       m_muonPropagator(nullptr),
0070       m_magField(nullptr),
0071       m_beamSpot(nullptr),
0072       m_commonPrefs(nullptr),
0073       m_maxEt(1.f),
0074       m_maxEnergy(1.f),
0075       m_hidePFBuilders(false),
0076       m_caloData(nullptr),
0077       m_caloDataHF(nullptr) {
0078   if (iColorM)  // unit test
0079     m_commonPrefs = new CmsShowCommon(this);
0080 
0081   s_fwContext = this;
0082 }
0083 
0084 Context::~Context() { delete m_commonPrefs; }
0085 
0086 void Context::initEveElements() {
0087   m_magField = new FWMagField();
0088   m_beamSpot = new FWBeamSpot();
0089 
0090   float propagatorOffR = 5;
0091   float propagatorOffZ = propagatorOffR * caloZ1(false) / caloR1(false);
0092 
0093   // common propagator, helix stepper
0094   m_propagator = new TEveTrackPropagator();
0095   m_propagator->SetMagFieldObj(m_magField, false);
0096   m_propagator->SetMaxR(caloR2() - propagatorOffR);
0097   m_propagator->SetMaxZ(caloZ2() - propagatorOffZ);
0098   m_propagator->SetDelta(0.01);
0099   m_propagator->SetProjTrackBreaking(m_commonPrefs->getProjTrackBreaking());
0100   m_propagator->SetRnrPTBMarkers(m_commonPrefs->getRnrPTBMarkers());
0101   m_propagator->IncDenyDestroy();
0102   // tracker propagator
0103   m_trackerPropagator = new TEveTrackPropagator();
0104   m_trackerPropagator->SetStepper(TEveTrackPropagator::kRungeKutta);
0105   m_trackerPropagator->SetMagFieldObj(m_magField, false);
0106   m_trackerPropagator->SetDelta(0.01);
0107   m_trackerPropagator->SetMaxR(caloR1() - propagatorOffR);
0108   m_trackerPropagator->SetMaxZ(caloZ2() - propagatorOffZ);
0109   m_trackerPropagator->SetProjTrackBreaking(m_commonPrefs->getProjTrackBreaking());
0110   m_trackerPropagator->SetRnrPTBMarkers(m_commonPrefs->getRnrPTBMarkers());
0111   m_trackerPropagator->IncDenyDestroy();
0112   // muon propagator
0113   m_muonPropagator = new TEveTrackPropagator();
0114   m_muonPropagator->SetStepper(TEveTrackPropagator::kRungeKutta);
0115   m_muonPropagator->SetMagFieldObj(m_magField, false);
0116   m_muonPropagator->SetDelta(0.05);
0117   m_muonPropagator->SetMaxR(850.f);
0118   m_muonPropagator->SetMaxZ(1100.f);
0119   m_muonPropagator->SetProjTrackBreaking(m_commonPrefs->getProjTrackBreaking());
0120   m_muonPropagator->SetRnrPTBMarkers(m_commonPrefs->getRnrPTBMarkers());
0121   m_muonPropagator->IncDenyDestroy();
0122 
0123   // general calo data
0124   {
0125     m_caloData = new TEveCaloDataHist();
0126     m_caloData->IncDenyDestroy();
0127 
0128     // Phi range is always in the (-Pi, Pi) without a shift.
0129     // Set wrap to false for the optimisation on TEveCaloData::GetCellList().
0130     m_caloData->SetWrapTwoPi(false);
0131 
0132     Bool_t status = TH1::AddDirectoryStatus();
0133     TH1::AddDirectory(kFALSE);  //Keeps histogram from going into memory
0134     TH2F* dummy =
0135         new TH2F("background", "background", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -1 * TMath::Pi(), TMath::Pi());
0136 
0137     TH1::AddDirectory(status);
0138     Int_t sliceIndex = m_caloData->AddHistogram(dummy);
0139     (m_caloData)->RefSliceInfo(sliceIndex).Setup("background", 0., 0);
0140   }
0141   // HF calo data
0142   {
0143     m_caloDataHF = new TEveCaloDataVec(1);
0144     m_caloDataHF->IncDenyDestroy();
0145     m_caloDataHF->SetWrapTwoPi(false);
0146     m_caloDataHF->RefSliceInfo(0).Setup("bg", 0.3, kRed);
0147     m_caloDataHF->SetEtaBins(new TAxis(fw3dlego::xbins_hf_n - 1, fw3dlego::xbins_hf));
0148     Double_t off = 10 * TMath::DegToRad();
0149     m_caloDataHF->SetPhiBins(new TAxis(36, -TMath::Pi() - off, TMath::Pi() - off));
0150   }
0151 }
0152 
0153 void Context::deleteEveElements() {
0154   // AMT: delete of eve-elements disabled to prevent crash on exit.
0155   // A lot of eve objects use this elements (e.g. TEveCalo, TEveTrack ...)
0156   // If want to have explicit delete make sure order of destruction
0157   // is correct: this should be called after all scenes are destroyed.
0158 }
0159 
0160 CmsShowCommon* Context::commonPrefs() const { return m_commonPrefs; }
0161 
0162 void Context::voteMaxEtAndEnergy(float et, float energy) const {
0163   m_maxEt = TMath::Max(et, m_maxEt);
0164   m_maxEnergy = TMath::Max(energy, m_maxEnergy);
0165 }
0166 
0167 void Context::resetMaxEtAndEnergy() const {
0168   // should not be zero, problems with infinte bbox
0169 
0170   m_maxEnergy = 1.f;
0171   m_maxEt = 1.f;
0172 }
0173 
0174 float Context::getMaxEnergyInEvent(bool isEt) const { return isEt ? m_maxEt : m_maxEnergy; }
0175 
0176 //
0177 // static member functions
0178 //
0179 
0180 float Context::caloR1(bool offset) { return offset ? (s_caloR - offset) : s_caloR; }
0181 
0182 float Context::caloR2(bool offset) { return offset ? (s_caloR - offset) : s_caloR; }
0183 float Context::caloZ1(bool offset) { return offset ? (s_caloZ - offset) : s_caloZ; }
0184 
0185 float Context::caloZ2(bool offset) { return offset ? (s_caloZ - offset) : s_caloZ; }
0186 
0187 float Context::caloTransEta() { return s_caloTransEta; }
0188 
0189 float Context::caloTransAngle() { return s_caloTransAngle; }
0190 
0191 double Context::caloMaxEta() { return fw3dlego::xbins_hf[fw3dlego::xbins_hf_n - 1]; }
0192 
0193 Context* Context::getInstance() { return s_fwContext; }