CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Fireworks/Core/src/Context.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     Context
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Sep 30 14:57:12 EDT 2008
00011 // $Id: Context.cc,v 1.35 2011/03/08 09:36:05 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "TH2.h"
00018 #include "TMath.h"
00019 #include "TEveTrackPropagator.h"
00020 #include "TEveCaloData.h"
00021 #include "Fireworks/Core/interface/fw3dlego_xbins.h"
00022 
00023 #include "Fireworks/Core/interface/Context.h"
00024 #include "Fireworks/Core/interface/FWMagField.h"
00025 #include "Fireworks/Core/interface/FWBeamSpot.h"
00026 #include "Fireworks/Core/interface/CmsShowCommon.h"
00027 
00028 using namespace fireworks;
00029 //
00030 // constants, enums and typedefs
00031 //
00032 
00033 //
00034 // static data member definitions
00035 //
00036 
00037 #include <boost/bind.hpp>
00038 const float Context::s_caloTransEta = 1.479; 
00039 const float Context::s_caloTransAngle = 2*atan(exp(-s_caloTransEta));
00040 
00041 // simplified
00042 const float Context::s_caloZ  = 290; 
00043 const float Context::s_caloR  = s_caloZ*tan(s_caloTransAngle);
00044 
00045 /*
00046 // barrel
00047 const float Context::s_caloR1 = 129;
00048 const float Context::s_caloZ1 = s_caloR1/tan(s_caloTransAngle);
00049 // endcap
00050 const float Context::s_caloZ2 = 315.4;
00051 const float Context::s_caloR2 = s_caloZ2*tan(s_caloTransAngle);
00052 */
00053 
00054 // calorimeter offset between TEveCalo and outlines (used by proxy builders)
00055 const float Context::s_caloOffR = 10;
00056 const float Context::s_caloOffZ = s_caloOffR/tan(s_caloTransAngle);
00057 
00058 
00059 //
00060 // constructors and destructor
00061 //
00062 Context::Context(FWModelChangeManager* iCM,
00063                  FWSelectionManager* iSM,
00064                  FWEventItemsManager* iEM,
00065                  FWColorManager* iColorM,
00066                  FWJobMetadataManager* iJMDM
00067                  ) :
00068   m_changeManager(iCM),
00069   m_selectionManager(iSM),
00070   m_eventItemsManager(iEM),
00071   m_colorManager(iColorM),
00072   m_metadataManager(iJMDM),
00073   m_geom(0),
00074   m_propagator(0),
00075   m_trackerPropagator(0),
00076   m_muonPropagator(0),
00077   m_magField(0),
00078   m_beamSpot(0),
00079   m_commonPrefs(0),
00080   m_maxEt(1.f),
00081   m_maxEnergy(1.f),
00082   m_caloData(0),
00083   m_caloDataHF(0)
00084 {
00085    if (iColorM) // unit test
00086      m_commonPrefs = new CmsShowCommon(this);
00087 }
00088 
00089 
00090 Context::~Context()
00091 {
00092    delete m_commonPrefs;
00093 }
00094 
00095 void
00096 Context::initEveElements()
00097 {
00098    m_magField = new FWMagField();
00099    m_beamSpot = new FWBeamSpot();
00100    
00101 
00102    float propagatorOffR = 5;
00103    float propagatorOffZ = propagatorOffR*caloZ1(false)/caloR1(false);
00104 
00105    // common propagator, helix stepper
00106    m_propagator = new TEveTrackPropagator();
00107    m_propagator->SetMagFieldObj(m_magField, false);
00108    m_propagator->SetMaxR(caloR2()-propagatorOffR);
00109    m_propagator->SetMaxZ(caloZ2()-propagatorOffZ);
00110    m_propagator->SetDelta(0.01);
00111    m_propagator->SetProjTrackBreaking(m_commonPrefs->getProjTrackBreaking());
00112    m_propagator->SetRnrPTBMarkers(m_commonPrefs->getRnrPTBMarkers());
00113    m_propagator->IncDenyDestroy();
00114    // tracker propagator
00115    m_trackerPropagator = new TEveTrackPropagator();
00116    m_trackerPropagator->SetStepper( TEveTrackPropagator::kRungeKutta );
00117    m_trackerPropagator->SetMagFieldObj(m_magField, false);
00118    m_trackerPropagator->SetDelta(0.01);
00119    m_trackerPropagator->SetMaxR(caloR1()-propagatorOffR);
00120    m_trackerPropagator->SetMaxZ(caloZ2()-propagatorOffZ);
00121    m_trackerPropagator->SetProjTrackBreaking(m_commonPrefs->getProjTrackBreaking());
00122    m_trackerPropagator->SetRnrPTBMarkers(m_commonPrefs->getRnrPTBMarkers());
00123    m_trackerPropagator->IncDenyDestroy();
00124    // muon propagator
00125    m_muonPropagator = new TEveTrackPropagator();
00126    m_muonPropagator->SetStepper( TEveTrackPropagator::kRungeKutta );
00127    m_muonPropagator->SetMagFieldObj(m_magField, false);
00128    m_muonPropagator->SetDelta(0.05);
00129    m_muonPropagator->SetMaxR(850.f);
00130    m_muonPropagator->SetMaxZ(1100.f);
00131    m_muonPropagator->SetProjTrackBreaking(m_commonPrefs->getProjTrackBreaking());
00132    m_muonPropagator->SetRnrPTBMarkers(m_commonPrefs->getRnrPTBMarkers());
00133    m_muonPropagator->IncDenyDestroy();
00134 
00135    // general calo data
00136    {
00137       m_caloData = new TEveCaloDataHist();
00138       m_caloData->IncDenyDestroy();
00139 
00140       // Phi range is always in the (-Pi, Pi) without a shift.
00141       // Set wrap to false for the optimisation on TEveCaloData::GetCellList().
00142       m_caloData->SetWrapTwoPi(false);
00143 
00144       Bool_t status = TH1::AddDirectoryStatus();
00145       TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
00146       TH2F* dummy = new TH2F("background",
00147                              "background",
00148                              fw3dlego::xbins_n - 1, fw3dlego::xbins,
00149                              72, -1*TMath::Pi(), TMath::Pi());
00150       
00151       TH1::AddDirectory(status);
00152       Int_t sliceIndex = m_caloData->AddHistogram(dummy);
00153       (m_caloData)->RefSliceInfo(sliceIndex).Setup("background", 0., 0);
00154    }
00155    // HF calo data
00156    {
00157       m_caloDataHF = new TEveCaloDataVec(1);
00158       m_caloDataHF->IncDenyDestroy();
00159       m_caloDataHF->SetWrapTwoPi(false);
00160       m_caloDataHF->RefSliceInfo(0).Setup("bg", 0.3, kRed);
00161       m_caloDataHF->SetEtaBins(new TAxis(fw3dlego::xbins_hf_n - 1, fw3dlego::xbins_hf));
00162       Double_t off = 10 * TMath::DegToRad();
00163       m_caloDataHF->SetPhiBins(new TAxis(36, -TMath::Pi() -off, TMath::Pi() -off));
00164    }
00165 }
00166 
00167 void
00168 Context::deleteEveElements()
00169 {
00170    // AMT: delete of eve-elements disabled to prevent crash on exit.
00171    // A lot of eve objects use this elements (e.g. TEveCalo, TEveTrack ...)
00172    // If want to have explicit delete make sure order of destruction
00173    // is correct: this should be called after all scenes are destroyed.
00174 }
00175 
00176 
00177 
00178 CmsShowCommon* 
00179 Context::commonPrefs() const
00180 {
00181    return m_commonPrefs;
00182 }
00183 
00184 void
00185 Context::voteMaxEtAndEnergy(float et, float energy) const
00186 {
00187    m_maxEt     = TMath::Max(et    , m_maxEt    );
00188    m_maxEnergy = TMath::Max(energy, m_maxEnergy);
00189 }
00190 
00191 void
00192 Context::resetMaxEtAndEnergy() const
00193 {
00194    // should not be zero, problems with infinte bbox 
00195 
00196    m_maxEnergy = 1.f;
00197    m_maxEt     = 1.f;
00198 }
00199 
00200 float
00201 Context::getMaxEnergyInEvent(bool isEt) const
00202 {
00203    return isEt ?  m_maxEt : m_maxEnergy;
00204 }
00205 
00206 //
00207 // static member functions
00208 //
00209 
00210 float Context::caloR1(bool offset)
00211 {
00212    return offset ? (s_caloR -offset) :s_caloR;
00213 }
00214 
00215 float Context::caloR2(bool offset)
00216 {
00217   
00218    return offset ? (s_caloR -offset) :s_caloR;
00219 }
00220 float Context::caloZ1(bool offset)
00221 {
00222    return offset ? (s_caloZ -offset) :s_caloZ;
00223 }
00224 
00225 float Context::caloZ2(bool offset)
00226 { 
00227    return offset ? (s_caloZ -offset) :s_caloZ;
00228 }
00229 
00230 float Context::caloTransEta()
00231 {
00232    return s_caloTransEta;
00233 }
00234 
00235 float Context::caloTransAngle()
00236 {
00237    return s_caloTransAngle;
00238 }
00239 
00240 double Context::caloMaxEta()
00241 {
00242    return fw3dlego::xbins_hf[fw3dlego::xbins_hf_n -1];
00243 }