test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloBox.cc
Go to the documentation of this file.
1 /*
2  * CaloBox.cc
3  *
4  * Created on: 11-May-2009
5  * Author: jamie
6  */
7 
9 
10 #include <iostream>
11 #include <cmath>
12 using namespace pftools;
13 using namespace std;
14 
15 CaloBox::CaloBox(double centerEta, double centerPhi, double dEta, double dPhi,
16  unsigned nEta, unsigned nPhi) :
17  centerEta_(centerEta), centerPhi_(centerPhi), dEta_(dEta), dPhi_(dPhi),
18  nEta_(nEta), nPhi_(nPhi) {
19  if (nEta_ % 2 != 1) {
20  cout << __PRETTY_FUNCTION__
21  << ": should use odd numbers for nEta and nPhi as CaloBox won't be symmetric otherwise!\n";
22  etaPosBound_ = (nEta / 2);
23  etaNegBound_ = -1 * static_cast<int> ((nEta / 2) + 1);
24 
25  } else {
26  etaPosBound_ = (nEta - 1) / 2;
27  etaNegBound_ = -1 * static_cast<int> ((nEta - 1) / 2);
28  }
29 
30  if (nPhi_ % 2 != 1) {
31  cout << __PRETTY_FUNCTION__
32  << ": should use odd numbers for nEta and nPhi as CaloBox won't be symmetric otherwise!\n";
33 
34  phiPosBound_ = (nPhi / 2);
35  phiNegBound_ = -1 * static_cast<int> ((nPhi / 2) + 1);
36  } else {
37  phiPosBound_ = (nPhi - 1) / 2;
38  phiNegBound_ = -1 * static_cast<int> ((nPhi - 1) / 2);
39  }
40 
41  reset();
42 
43  //cout << "CaloBox with n+ " << etaPosBound_ << ", n- " << etaNegBound_
44  // << ", p+ " << phiPosBound_ << ", p-" << phiNegBound_ << "\n";
45 
46 }
47 
49  for (int r = phiPosBound_; r >= phiNegBound_; --r) {
50  for (int c = etaNegBound_; c <= etaPosBound_; ++c) {
51  std::pair<int, int> pos(c, r);
52  energies_[pos] = 0.0;
53  }
54  }
55 }
56 
58 
59 }
60 
61 bool CaloBox::fill(double eta, double phi, double energy) {
62  int etaDiv = static_cast<int>(floor((eta - centerEta_ + dEta_ / 2.0) / dEta_));
63  int phiDiv = static_cast<int>(floor((phi - centerPhi_ + dPhi_ / 2.0) / dPhi_));
64  //cout << "Testing for " << etaDiv << ", " << phiDiv << "\n";
65 
66  if (etaDiv >= 0 && etaDiv > etaPosBound_)
67  return false;
68  if (etaDiv < 0 && etaDiv < etaNegBound_)
69  return false;
70  if (phiDiv >= 0 && phiDiv > phiPosBound_)
71  return false;
72  if (phiDiv < 0 && phiDiv < phiNegBound_)
73  return false;
74 
75  pair<int, int> key(etaDiv, phiDiv);
76 
77  energies_[key] += energy;
78  return true;
79 
80 }
81 
82 std::ostream& CaloBox::dump(std::ostream& stream, double norm, string rowDelim) const {
83 
84  for (int r = phiPosBound_; r >= phiNegBound_; --r) {
85  for (int c = etaNegBound_; c <= etaPosBound_; ++c) {
86  pair<int, int> pos(c, r);
87  double energy = energies_.find(pos)->second/norm;
88  stream << energy << "\t";
89  }
90  stream << rowDelim;
91  }
92 //
93 // for (map<pair<int, int> , double>::const iterator i = energies_.begin(); i
94 // != energies_.end(); ++i) {
95 // pair<int, int> loc = i->first;
96 // double en = i->second;
97 // stream << loc.first << ", " << loc.second << ": " << en << "\n";
98 // }
99 
100  return stream;
101 }
102 
104 
105  CaloBox cb(0.0, 0.0, 1.0, 1.0, 5, 5);
106 
107  unsigned count(0);
108  bool ok(false);
109 
110  ok = cb.fill(2, 1, 10);
111  if (!ok)
112  cout << "Box fill failed! Count = " << count << "\n";
113  ++count;
114 
115  ok = cb.fill(-1, 2, 20);
116  if (!ok)
117  cout << "Box fill failed! Count = " << count << "\n";
118  ++count;
119 
120  ok = cb.fill(-2, 5, 10);
121  if (!ok)
122  cout << "Box fill failed! Count = " << count << "\n";
123  ++count;
124 
125  ok = cb.fill(0.1, 1.3, 10);
126  if (!ok)
127  cout << "Box fill failed! Count = " << count << "\n";
128  ++count;
129 
130  ok = cb.fill(-1.4, 1.6, 10);
131  if (!ok)
132  cout << "Box fill failed! Count = " << count << "\n";
133  ++count;
134 
135  cout << cb;
136 
137 }
138 
139 std::ostream& pftools::operator<<(std::ostream& stream, const CaloBox& cb) {
140  stream << "CaloBox at " << cb.centerEta_ << ", " << cb.centerPhi_ << ":\n";
141  cb.dump(stream, 1.0, "\n");
142  return stream;
143 }
144 
bool fill(double eta, double phi, double energy)
Definition: CaloBox.cc:61
void reset()
Definition: CaloBox.cc:48
int etaNegBound_
Definition: CaloBox.h:35
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
double centerEta_
Definition: CaloBox.h:27
int phiPosBound_
Definition: CaloBox.h:36
int etaPosBound_
Definition: CaloBox.h:34
double dEta_
Definition: CaloBox.h:29
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
virtual ~CaloBox()
Definition: CaloBox.cc:57
unsigned nPhi_
Definition: CaloBox.h:32
std::map< std::pair< int, int >, double > energies_
Definition: CaloBox.h:48
int phiNegBound_
Definition: CaloBox.h:37
double centerPhi_
Definition: CaloBox.h:28
std::ostream & dump(std::ostream &stream, double norm=1.0, std::string rowDelim="\n") const
Definition: CaloBox.cc:82
tuple cout
Definition: gather_cfg.py:145
std::ostream & operator<<(std::ostream &s, const Calibratable &calib_)
Definition: Calibratable.cc:6
double dPhi_
Definition: CaloBox.h:30
unsigned nEta_
Definition: CaloBox.h:31