CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloWindow.cc
Go to the documentation of this file.
3 #include <TMath.h>
4 
5 using namespace pftools;
6 //using namespace edm;
7 using namespace std;
8 
9 //Let's do CaloRing first
11  panes_(1) {
12  myPanes_.push_back(0);
13 }
14 
15 CaloRing::CaloRing(unsigned nPanes) :
16  panes_(nPanes) {
17  for (unsigned j(0); j < nPanes; ++j)
18  myPanes_.push_back(0);
19 }
20 
21 double CaloRing::getEnergy(unsigned pane) const {
22  if (pane < panes_)
23  return myPanes_[pane];
24  else
25  return 0;
26 }
27 
28 bool CaloRing::setEnergy(unsigned pane, double energy) {
29  if (pane < panes_) {
30  myPanes_[pane] = energy;
31  return true;
32  }
33  return false;
34 }
35 
36 bool CaloRing::addEnergy(unsigned pane, double energy) {
37  if (pane < panes_) {
38  myPanes_[pane] += energy;
39  return true;
40  }
41  return false;
42 }
43 
44 double CaloRing::totalE() const {
45  double ans(0.0);
46  for (std::vector<double>::const_iterator cit = myPanes_.begin(); cit
47  != myPanes_.end(); ++cit) {
48  ans += *cit;
49  }
50  return ans;
51 }
52 
54  for (std::vector<double>::iterator cit = myPanes_.begin(); cit
55  != myPanes_.end(); ++cit)
56  *cit = 0.0;
57 
58 }
59 
60 void CaloRing::printEnergies(std::ostream& s, double range) {
61  for (std::vector<double>::iterator cit = myPanes_.begin(); cit
62  != myPanes_.end(); ++cit)
63  s << (*cit)/range << "\t";
64 }
65 
66 std::ostream& pftools::operator<<(std::ostream& s,
67  const pftools::CaloRing& caloRing) {
68  for (std::vector<double>::const_iterator it = caloRing.myPanes_.begin(); it
69  != caloRing.myPanes_.end(); ++it) {
70  s << *it << "\t";
71  }
72  s << " => ring E = " << caloRing.totalE();
73  return s;
74 }
75 
76 std::ostream& pftools::operator<<(std::ostream& s,
77  const pftools::CaloWindow& caloWindow) {
78 
79  s << "CaloWindow at (" << caloWindow.baryEta_ << ", "
80  << caloWindow.baryPhi_ << "):\n";
81  double totalE(0.0);
82  for (std::map<unsigned, pftools::CaloRing>::const_iterator cit =
83  caloWindow.energies_.begin(); cit != caloWindow.energies_.end(); ++cit) {
84  unsigned ring = (*cit).first;
85  const CaloRing& cr = (*cit).second;
86  s << "Ring " << ring << ":\t" << cr << "\n";
87  totalE += cr.totalE();
88  }
89 
90  s << "\tTotal E = " << totalE << std::endl;
91  return s;
92 
93 }
94 
95 vector<double> CaloWindow::stream(double normalisation) const {
96  vector<double> stream;
97  for (map<unsigned, pftools::CaloRing>::const_iterator cit =
98  energies_.begin(); cit != energies_.end(); ++cit) {
99  CaloRing c = (*cit).second;
100  std::vector<double> ringE = c.getEnergies();
101  stream.insert(stream.end(), ringE.begin(), ringE.end());
102  }
103  if(normalisation != 1.0){
104  for(vector<double>::iterator i = stream.begin(); i != stream.end(); ++i) {
105  double& entry = *i;
106  entry /= normalisation;
107  }
108  }
109  return stream;
110 
111 }
112 
113 void CaloWindow::printEnergies(std::ostream& s, double range) {
114 
115  for (std::map<unsigned, pftools::CaloRing>::const_iterator cit =
116  energies_.begin(); cit != energies_.end(); ++cit) {
117  CaloRing c = (*cit).second;
118  c.printEnergies(s, range);
119  s << "\t";
120  }
121 
122 }
123 
125  baryEta_(0.0), baryPhi_(0.0), nRings_(1), deltaR_(0.1), nPanes_(1), axis_(0.0) {
126 
127 }
128 
129 CaloWindow::CaloWindow(double eta, double phi, unsigned nRings, double deltaR, unsigned nPanes, double axis) {
130 
131  init(eta, phi, nRings, deltaR, nPanes, axis);
132 }
133 
135  energies_.clear();
136 }
137 
138 void CaloWindow::init(double eta, double phi, unsigned nRings, double deltaR, unsigned nPanes, double axis) {
139  baryEta_ = eta;
140  baryPhi_ = phi;
141  nRings_ = nRings;
142  deltaR_ = deltaR;
143  nPanes_ = nPanes;
144  axis_ = axis;
145 
146  energies_.clear();
147  CaloRing c(1);
148  energies_[0] = c;
149  for (unsigned j(1); j < nRings_; ++j) {
150 
151  CaloRing r(nPanes);
152  energies_[j] = r;
153  }
154 }
155 
157 
158 }
159 
160 std::pair<unsigned, unsigned> CaloWindow::relativePosition(double eta,
161  double phi) const {
162  //How far is this hit from the barycentre in deltaR?
163  double dEta = eta - baryEta_;
164  double dPhi = deltaPhi(phi, baryPhi_);
165 
166  double dR = deltaR(eta, phi, baryEta_, baryPhi_);
167 
168  unsigned ring = static_cast<unsigned> (floor(dR / deltaR_));
169 
170  if (ring == 0) {
171  //LogDebug("CaloWindow") << "Relative position: adding to central ring\n";
172  return std::pair<unsigned, unsigned>(0, 0);
173  }
174 
175  if (ring >= nRings_) {
176  return std::pair<unsigned, unsigned>(ring, 0);
177  }
178 
179  double dTheta = 0;
180 
181  if (dEta > 0) {
182  if (dPhi > 0)
183  dTheta = TMath::ATan(dPhi / dEta);
184  else
185  dTheta = 2 * TMath::Pi() + TMath::ATan(dPhi / dEta);
186  } else {
187  if (dPhi > 0)
188  dTheta = TMath::Pi() + TMath::ATan(dPhi / dEta);
189  else
190  dTheta = TMath::Pi() + TMath::ATan(dPhi / dEta);
191  }
192  //Rotation. Rotate theta into axis of caloWindow
193  // and also by half a window pane.
194  //TODO: bug check!!
195  //double dThetaOrig(dTheta);
196  double paneOn2 = TMath::Pi() / (*energies_.find(ring)).second.getNPanes();
197  dTheta = dTheta - axis_ - paneOn2;
198  //Original theta between 0 and 2 Pi, but transform above might move us beyond this, so...
199  //double dThetaCopy(dTheta);
200  //std::cout << "dTheta " << dThetaOrig << ", axis " << axis_ << ", paneOn2 " << paneOn2 << ", thetaPrime " << dTheta << "\n";
201  if(dTheta > 2 *TMath::Pi()) {
202  //std::cout << "To infinity and beyond...\n";
203  while(dTheta > 2 * TMath::Pi()) {
204  dTheta -= 2 * TMath::Pi();
205  //std::cout << "dTheta1 " << dTheta << "\n";
206  }
207  }
208  else if (dTheta < 0) {
209  //std::cout << "To infinity and beyond 2... dTheta = " << dTheta << "\n";
210  while(dTheta < 0) {
211  dTheta += 2 * TMath::Pi();
212  //std::cout << "dTheta2 " << dTheta << "\n";
213  }
214  }
215 
216 // std::cout << "\tdTheta is " << dTheta << " rad \n";
217  unsigned division = static_cast<unsigned> (floor((*energies_.find(ring)).second.getNPanes() * dTheta
218  / (TMath::Pi() * 2)));
219  //LogDebug("CaloWindow") << "Ring is " << ring << ", pane is "
220  // << division << "\n";
221 
222  return std::pair<unsigned, unsigned>(ring, division);
223 
224 }
225 
226 bool CaloWindow::addHit(double eta, double phi, double energy) {
227 
228  std::pair<unsigned, unsigned> position = relativePosition(eta, phi);
229  if (position.first >= nRings_) {
230 /* double dEta = eta - baryEta_;
231  double dPhi = deltaPhi(phi, baryPhi_);
232  double dR = deltaR(eta, phi, baryEta_, baryPhi_);
233  LogDebug("CaloWindow")
234  << "Hit is outside my range - it would be in ring "
235  << position.first << ", with dR = " << dR << std::endl;*/
236  return false;
237  }
238 // std::cout << "Adding hit to ring " << position.first << " in position "
239 // << position.second << " with energy " << energy << "\n";
240 
241  CaloRing& c = energies_[position.first];
242  c.addEnergy(position.second, energy);
243 
244  return true;
245 }
246 std::map<unsigned, double> CaloWindow::getRingEnergySummations() const {
247  std::map<unsigned, double> answer;
248  for (std::map<unsigned, CaloRing>::const_iterator cit = energies_.begin(); cit
249  != energies_.end(); ++cit) {
250  std::pair<unsigned, CaloRing> pair = *cit;
251  answer[pair.first] = pair.second.totalE();
252  }
253 
254  return answer;
255 }
256 
258 
259  CaloWindow cw(0.0, 0.0, 3, 0.1, 4);
260  std::cout << cw << std::endl;
261  cw.addHit(0, 0.05, 1.0);
262  cw.addHit(0.22, 0.05, 2.0);
263  cw.addHit(0, 0.8, 4.0);
264  cw.addHit(0.2, 0, 1.0);
265  cw.addHit(0.15, 0.15, 2.0);
266  cw.addHit(0.0, 0.2, 3.0);
267  cw.addHit(-0.15, 0.15, 4.0);
268  cw.addHit(-0.2, 0, 5.0);
269  cw.addHit(-0.15, -0.15, 6.0);
270  cw.addHit(-0.0, -0.2, 7.0);
271  cw.addHit(0.15, -0.15, 8.0);
272 
273  std::cout << cw << std::endl;
274  std::cout << "bye bye" << std::endl;
275 
276 }
std::map< unsigned, CaloRing > energies_
Definition: CaloWindow.h:163
const double Pi
answer
Definition: submit.py:44
int i
Definition: DBlmapReader.cc:9
unsigned panes_
Definition: CaloWindow.h:87
double deltaR_
std::map< unsigned, double > getRingEnergySummations() const
Definition: CaloWindow.cc:246
U second(std::pair< T, U > const &p)
double totalE() const
Definition: CaloWindow.cc:44
void printEnergies(std::ostream &s, double range=1.0)
Definition: CaloWindow.cc:113
std::vector< double > getEnergies() const
Definition: CaloWindow.h:71
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
bool addHit(double eta, double phi, double energy)
Definition: CaloWindow.cc:226
const reco::Candidate::LorentzVector & axis_
int j
Definition: DBlmapReader.cc:9
std::vector< double > stream(double normalisation=1.0) const
Definition: CaloWindow.cc:95
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
bool addEnergy(unsigned pane, double energy)
Definition: CaloWindow.cc:36
double getEnergy(unsigned pane) const
Definition: CaloWindow.cc:21
std::pair< unsigned, unsigned > relativePosition(double eta, double phi) const
Definition: CaloWindow.cc:160
bool setEnergy(unsigned pane, double energy)
Definition: CaloWindow.cc:28
void init(double eta, double phi, unsigned nRings, double deltaR, unsigned nPanes, double axis=0.0)
Definition: CaloWindow.cc:138
std::vector< double > myPanes_
Definition: CaloWindow.h:88
void printEnergies(std::ostream &s, double range=1.0)
Definition: CaloWindow.cc:60
static int position[264][3]
Definition: ReadPGInfo.cc:509
tuple cout
Definition: gather_cfg.py:121
std::ostream & operator<<(std::ostream &s, const Calibratable &calib_)
Definition: Calibratable.cc:6
virtual ~CaloWindow()
Definition: CaloWindow.cc:156