CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWCaloTowerProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calo
4 // Class : FWCaloTowerProxyBuilderBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Dec 3 11:28:28 EST 2008
11 //
12 
13 // system includes
14 #include <math.h>
15 
16 // user includes
17 #include "TEveCaloData.h"
18 #include "TEveCalo.h"
19 #include "TH2F.h"
20 
24 
28 
30 
31 
32 
33 //
34 // constructors , dectructors
35 //
37 m_towers(0),
38 m_hist(0)
39 {
40 }
41 
43 {
44 }
45 
46 //
47 // member functions
48 //
49 
50 void
52 {
54 }
55 
56 
57 void
59  TEveElementList* el, const FWViewContext* ctx)
60 {
61  m_towers=0;
62  if (iItem)
63  {
64  iItem->get(m_towers);
65  FWCaloDataProxyBuilderBase::build(iItem, el, ctx);
66  }
67 }
68 
69 void
71 {
72 
73  if(0!=m_hist) {
74  m_hist->Reset();
75  }
77 }
78 
79 double
80 wrapPi(double val)
81 {
82  using namespace TMath;
83 
84  if (val< -Pi())
85  {
86  return val += TwoPi();
87  }
88  if (val> Pi())
89  {
90  return val -= TwoPi();
91  }
92  return val;
93 }
94 
95 void
97 {
98  static float d = 2.5*TMath::Pi()/180;
99  m_hist->Reset();
100 
101  if (m_towers)
102  {
103  TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
104 
105  if(item()->defaultDisplayProperties().isVisible()) {
106  // assert(item()->size() >= m_towers->size());
107  unsigned int index=0;
108  for(CaloTowerCollection::const_iterator tower = m_towers->begin(); tower != m_towers->end(); ++tower,++index) {
109  const FWEventItem::ModelInfo& info = item()->modelInfo(index);
110  if(info.displayProperties().isVisible()) {
111  if (tower->ietaAbs() > 39)
112  {
113  m_hist->Fill(tower->eta(),wrapPi(tower->phi() - 3*d), getEt(*tower) *0.25);
114  m_hist->Fill(tower->eta(),wrapPi(tower->phi() - d), getEt(*tower) *0.25);
115  m_hist->Fill(tower->eta(),wrapPi(tower->phi() + d), getEt(*tower) *0.25);
116  m_hist->Fill(tower->eta(),wrapPi(tower->phi() + 3*d), getEt(*tower) *0.25);
117  }
118  else if (tower->ietaAbs() > 20)
119  {
120  m_hist->Fill(tower->eta(),wrapPi(tower->phi() - d), getEt(*tower) *0.5);
121  m_hist->Fill(tower->eta(),wrapPi(tower->phi() + d), getEt(*tower) *0.5);
122  }
123  else
124  {
125  m_hist->Fill(tower->eta(),tower->phi(), getEt(*tower));
126  }
127  }
128  if(info.isSelected()) {
129  //NOTE: I tried calling TEveCalo::GetCellList but it always returned 0, probably because of threshold issues
130  // but looking at the TEveCaloHist::GetCellList code the CellId_t is just the histograms bin # and the slice
131  // printf("applyChangesToAllModels ...check selected \n");
132 
133  if (tower->ietaAbs() > 39)
134  {
135  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -3*d)),m_sliceIndex));
136  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -d)) ,m_sliceIndex));
137  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +d)) ,m_sliceIndex));
138  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +3*d)),m_sliceIndex));
139  }
140  else if (tower->ietaAbs() > 20)
141  {
142  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -d)), m_sliceIndex));
143  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +d)), m_sliceIndex));
144  }
145  else
146  {
147  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(),tower->phi()),m_sliceIndex));
148  }
149  }
150  }
151  }
152  }
153 
154 }
155 
156 //______________________________________________________________________________
157 bool
159 {
160  if (m_hist == 0)
161  {
162  // add new slice
163  Bool_t status = TH1::AddDirectoryStatus();
164  TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
165  m_hist = new TH2F("caloHist",
166  "caloHist",
168  72, -M_PI, M_PI);
169  TH1::AddDirectory(status);
170  TEveCaloDataHist* ch = static_cast<TEveCaloDataHist*>(m_caloData);
171  m_sliceIndex = ch->AddHistogram(m_hist);
172 
173 
174 
175  m_caloData->RefSliceInfo(m_sliceIndex).Setup(item()->name().c_str(), 0.,
176  item()->defaultDisplayProperties().color(),
177  item()->defaultDisplayProperties().transparency());
178 
179  // add new selector
181  if (m_caloData->GetUserData())
182  {
183  FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
184  assert(0!=base);
185  sel = dynamic_cast<FWFromTEveCaloDataSelector*> (base);
186  assert(0!=sel);
187  }
188  else
189  {
191  //make sure it is accessible via the base class
192  m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
193  }
194 
196 
197  return true;
198  }
199  return false;
200 }
201 
205 
206 
207 
tuple base
Main Program
Definition: newFWLiteAna.py:92
const double TwoPi
const double Pi
virtual void setCaloData(const fireworks::Context &)
const fireworks::Context & context() const
static const TGPicture * info(bool iBackgroundIsBlack)
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:67
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:58
const double xbins[]
bool isSelected() const
Definition: FWEventItem.h:70
void get(const T *&oData) const
Definition: FWEventItem.h:84
std::vector< CaloTower >::const_iterator const_iterator
void addSliceSelector(int iSlice, FWFromSliceSelector *)
const FWEventItem * item() const
const CaloTowerCollection * m_towers
virtual void itemBeingDestroyed(const FWEventItem *)
TEveCaloDataHist * getCaloData() const
Definition: Context.h:80
#define M_PI
const int xbins_n
const_iterator end() const
static const int kAllLegoBits
Definition: FWViewType.h:60
virtual double getEt(const CaloTower &) const =0
double wrapPi(double val)
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535
tuple status
Definition: ntuplemaker.py:245
virtual void itemBeingDestroyed(const FWEventItem *)
const_iterator begin() const