CMS 3D CMS Logo

FWCaloDataHistProxyBuilder.cc
Go to the documentation of this file.
4 
7 
8 #include "Rtypes.h"
9 #include "TEveCaloData.h"
10 #include "TMath.h"
11 #include "TEveCalo.h"
12 #include "TH2F.h"
13 
14 FWCaloDataHistProxyBuilder::FWCaloDataHistProxyBuilder() : m_hist(nullptr), m_sliceSelector(nullptr) {}
16 
17 namespace {
18  double wrapPi(double val) {
19  using namespace TMath;
20 
21  if (val < -Pi()) {
22  return val += TwoPi();
23  }
24  if (val > Pi()) {
25  return val -= TwoPi();
26  }
27  return val;
28  }
29 } // namespace
30 
32 
34  if (nullptr != m_hist) {
35  m_hist->Reset();
36  }
38 }
39 
41  if (m_hist == nullptr) {
42  // add new slice
43  Bool_t status = TH1::AddDirectoryStatus();
44  TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
45  m_hist = new TH2F("caloHist", "caloHist", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -M_PI, M_PI);
46  TH1::AddDirectory(status);
47  TEveCaloDataHist* ch = static_cast<TEveCaloDataHist*>(m_caloData);
48  m_sliceIndex = ch->AddHistogram(m_hist);
49 
50  m_caloData->RefSliceInfo(m_sliceIndex)
51  .Setup(item()->name().c_str(),
52  0.,
53  item()->defaultDisplayProperties().color(),
54  item()->defaultDisplayProperties().transparency());
55 
56  // add new selector
58  if (m_caloData->GetUserData()) {
59  FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
60  assert(nullptr != base);
61  sel = dynamic_cast<FWFromTEveCaloDataSelector*>(base);
62  assert(nullptr != sel);
63  } else {
65  //make sure it is accessible via the base class
66  m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
67  }
69  sel->addSliceSelector(m_sliceIndex, m_sliceSelector);
70 
71  return true;
72  }
73  return false;
74 }
75 
76 void FWCaloDataHistProxyBuilder::addEntryToTEveCaloData(float eta, float phi, float Et, bool isSelected) {
77  using namespace TMath;
78  static float d = 2.5 * Pi() / 180;
79  // printf("comapre %f, %f \n", fw3dlego::xbins[80], fw3dlego::xbins[61] );
80 
82  if (Abs(eta) > fw3dlego::xbins[80]) {
83  m_hist->Fill(eta, wrapPi(phi - 3 * d), Et * 0.25);
84  m_hist->Fill(eta, wrapPi(phi - d), Et * 0.25);
85  m_hist->Fill(eta, wrapPi(phi + d), Et * 0.25);
86  m_hist->Fill(eta, wrapPi(phi + 3 * d), Et * 0.25);
87  } else if (Abs(eta) > fw3dlego::xbins[61]) {
88  m_hist->Fill(eta, wrapPi(phi - d), Et * 0.5);
89  m_hist->Fill(eta, wrapPi(phi + d), Et * 0.5);
90  } else {
91  m_hist->Fill(eta, phi, Et);
92  }
93  } else {
94  m_hist->Fill(eta, phi, Et);
95  }
96 
97  TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
98  if (isSelected) {
99  //NOTE: I tried calling TEveCalo::GetCellList but it always returned 0, probably because of threshold issues
100  // but looking at the TEveCaloHist::GetCellList code the CellId_t is just the histograms bin # and the slice
101  // printf("applyChangesToAllModels ...check selected \n");
102 
104  if (Abs(eta) > fw3dlego::xbins[80]) {
105  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi - 3 * d)), m_sliceIndex));
106  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi - d)), m_sliceIndex));
107  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi + d)), m_sliceIndex));
108  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi + 3 * d)), m_sliceIndex));
109  }
110  if (Abs(eta) > fw3dlego::xbins[60]) {
111  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi - d)), m_sliceIndex));
112  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi + d)), m_sliceIndex));
113  } else {
114  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, phi), m_sliceIndex));
115  }
116  } else {
117  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, phi), m_sliceIndex));
118  }
119  }
120 }
FWCaloDataHistProxyBuilder::FWCaloDataHistProxyBuilder
FWCaloDataHistProxyBuilder()
Definition: FWCaloDataHistProxyBuilder.cc:14
FWModelChangeManager.h
FWCaloDataHistProxyBuilder::assertCaloDataSlice
bool assertCaloDataSlice() override
Definition: FWCaloDataHistProxyBuilder.cc:40
fw3dlego::xbins
const double xbins[]
Definition: fw3dlego_xbins.cc:16
fireworks::Context
Definition: Context.h:41
TwoPi
const double TwoPi
Definition: CosmicMuonParameters.h:19
FWCaloDataHistProxyBuilder::instantiateSliceSelector
virtual FWHistSliceSelector * instantiateSliceSelector()=0
mps_update.status
status
Definition: mps_update.py:69
FWCaloDataProxyBuilderBase::itemBeingDestroyed
void itemBeingDestroyed(const FWEventItem *) override
Definition: FWCaloDataProxyBuilderBase.cc:106
cms::cuda::assert
assert(be >=bs)
fw3dlego::xbins_n
const int xbins_n
Definition: fw3dlego_xbins.cc:15
FWCaloDataProxyBuilderBase::m_sliceIndex
Int_t m_sliceIndex
Definition: FWCaloDataProxyBuilderBase.h:56
Abs
T Abs(T a)
Definition: MathUtil.h:49
FWCaloDataHistProxyBuilder::addEntryToTEveCaloData
void addEntryToTEveCaloData(float eta, float phi, float Et, bool isSelected)
Definition: FWCaloDataHistProxyBuilder.cc:76
PVValHelper::eta
Definition: PVValidationHelpers.h:69
FWCaloDataHistProxyBuilder::itemBeingDestroyed
void itemBeingDestroyed(const FWEventItem *) override
Definition: FWCaloDataHistProxyBuilder.cc:33
FWCaloDataHistProxyBuilder::setCaloData
void setCaloData(const fireworks::Context &) override
Definition: FWCaloDataHistProxyBuilder.cc:31
FWCaloDataProxyBuilderBase::m_caloData
TEveCaloData * m_caloData
Definition: FWCaloDataProxyBuilderBase.h:55
FWCaloDataHistProxyBuilder::m_hist
TH2F * m_hist
Definition: FWCaloDataHistProxyBuilder.h:22
PVValHelper::phi
Definition: PVValidationHelpers.h:68
FWHistSliceSelector::aggregatePhiCells
virtual bool aggregatePhiCells() const
Definition: FWHistSliceSelector.h:15
FWFromTEveCaloDataSelector
Definition: FWFromTEveCaloDataSelector.h:34
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
FWFromEveSelectorBase
Definition: FWFromEveSelectorBase.h:27
FWCaloDataHistProxyBuilder.h
FWEventItem.h
DDAxes::phi
FWCaloDataHistProxyBuilder::m_sliceSelector
FWHistSliceSelector * m_sliceSelector
Definition: FWCaloDataHistProxyBuilder.h:23
FWProxyBuilderBase::item
const FWEventItem * item() const
Definition: FWProxyBuilderBase.h:64
FWEventItem
Definition: FWEventItem.h:56
heppy_batch.val
val
Definition: heppy_batch.py:351
fireworks::Context::getCaloData
TEveCaloDataHist * getCaloData() const
Definition: Context.h:69
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWProxyBuilderBase::context
const fireworks::Context & context() const
Definition: FWProxyBuilderBase.cc:412
FWCaloDataHistProxyBuilder::~FWCaloDataHistProxyBuilder
~FWCaloDataHistProxyBuilder() override
Definition: FWCaloDataHistProxyBuilder.cc:15
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
ztail.d
d
Definition: ztail.py:151
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
fw3dlego_xbins.h
FWHistSliceSelector.h