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 // $Id: FWCaloTowerProxyBuilder.cc,v 1.25 2011/02/23 11:34:52 amraktad Exp $
12 //
13 
14 // system includes
15 #include <math.h>
16 
17 // user includes
18 #include "TEveCaloData.h"
19 #include "TEveCalo.h"
20 #include "TH2F.h"
21 
25 
29 
31 
32 
33 
34 //
35 // constructors , dectructors
36 //
38 m_towers(0),
39 m_hist(0)
40 {
41 }
42 
44 {
45 }
46 
47 //
48 // member functions
49 //
50 
51 void
53 {
55 }
56 
57 
58 void
60  TEveElementList* el, const FWViewContext* ctx)
61 {
62  m_towers=0;
63  if (iItem)
64  {
65  iItem->get(m_towers);
66  FWCaloDataProxyBuilderBase::build(iItem, el, ctx);
67  }
68 }
69 
70 void
72 {
73 
74  if(0!=m_hist) {
75  m_hist->Reset();
76  }
78 }
79 
80 double
81 wrapPi(double val)
82 {
83  using namespace TMath;
84 
85  if (val< -Pi())
86  {
87  return val += TwoPi();
88  }
89  if (val> Pi())
90  {
91  return val -= TwoPi();
92  }
93  return val;
94 }
95 
96 void
98 {
99  static float d = 2.5*TMath::Pi()/180;
100  m_hist->Reset();
101 
102  if (m_towers)
103  {
104  TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
105 
106  if(item()->defaultDisplayProperties().isVisible()) {
107  // assert(item()->size() >= m_towers->size());
108  unsigned int index=0;
109  for(CaloTowerCollection::const_iterator tower = m_towers->begin(); tower != m_towers->end(); ++tower,++index) {
110  const FWEventItem::ModelInfo& info = item()->modelInfo(index);
111  if(info.displayProperties().isVisible()) {
112  if (tower->ietaAbs() > 39)
113  {
114  m_hist->Fill(tower->eta(),wrapPi(tower->phi() - 3*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() + d), getEt(*tower) *0.25);
117  m_hist->Fill(tower->eta(),wrapPi(tower->phi() + 3*d), getEt(*tower) *0.25);
118  }
119  else if (tower->ietaAbs() > 20)
120  {
121  m_hist->Fill(tower->eta(),wrapPi(tower->phi() - d), getEt(*tower) *0.5);
122  m_hist->Fill(tower->eta(),wrapPi(tower->phi() + d), getEt(*tower) *0.5);
123  }
124  else
125  {
126  m_hist->Fill(tower->eta(),tower->phi(), getEt(*tower));
127  }
128  }
129  if(info.isSelected()) {
130  //NOTE: I tried calling TEveCalo::GetCellList but it always returned 0, probably because of threshold issues
131  // but looking at the TEveCaloHist::GetCellList code the CellId_t is just the histograms bin # and the slice
132  // printf("applyChangesToAllModels ...check selected \n");
133 
134  if (tower->ietaAbs() > 39)
135  {
136  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -3*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() +d)) ,m_sliceIndex));
139  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +3*d)),m_sliceIndex));
140  }
141  else if (tower->ietaAbs() > 20)
142  {
143  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -d)), m_sliceIndex));
144  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +d)), m_sliceIndex));
145  }
146  else
147  {
148  selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(),tower->phi()),m_sliceIndex));
149  }
150  }
151  }
152  }
153  }
154 
155 }
156 
157 //______________________________________________________________________________
158 bool
160 {
161  if (m_hist == 0)
162  {
163  // add new slice
164  Bool_t status = TH1::AddDirectoryStatus();
165  TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
166  m_hist = new TH2F("caloHist",
167  "caloHist",
169  72, -M_PI, M_PI);
170  TH1::AddDirectory(status);
171  TEveCaloDataHist* ch = static_cast<TEveCaloDataHist*>(m_caloData);
172  m_sliceIndex = ch->AddHistogram(m_hist);
173 
174 
175 
176  m_caloData->RefSliceInfo(m_sliceIndex).Setup(item()->name().c_str(), 0.,
177  item()->defaultDisplayProperties().color(),
178  item()->defaultDisplayProperties().transparency());
179 
180  // add new selector
182  if (m_caloData->GetUserData())
183  {
184  FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
185  assert(0!=base);
186  sel = dynamic_cast<FWFromTEveCaloDataSelector*> (base);
187  assert(0!=sel);
188  }
189  else
190  {
192  //make sure it is accessible via the base class
193  m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
194  }
195 
197 
198  return true;
199  }
200  return false;
201 }
202 
206 
207 
208 
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
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:68
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:59
const double xbins[]
bool isSelected() const
Definition: FWEventItem.h:71
void get(const T *&oData) const
Definition: FWEventItem.h:85
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:81
const int xbins_n
const_iterator end() const
#define M_PI
Definition: BFit3D.cc:3
static const int kAllLegoBits
Definition: FWViewType.h:61
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