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 (auto const& e: caloRing.getEnergies()) {
69  s << e << "\t";
70  }
71  s << " => ring E = " << caloRing.totalE();
72  return s;
73 }
74 
75 std::ostream& pftools::operator<<(std::ostream& s,
76  const pftools::CaloWindow& caloWindow) {
77 
78  s << "CaloWindow at (" << caloWindow.baryEta() << ", "
79  << caloWindow.baryPhi() << "):\n";
80  double totalE(0.0);
81  for (std::map<unsigned, pftools::CaloRing>::const_iterator cit =
82  caloWindow.getRingDepositions().begin(); cit != caloWindow.getRingDepositions().end(); ++cit) {
83  unsigned ring = (*cit).first;
84  const CaloRing& cr = (*cit).second;
85  s << "Ring " << ring << ":\t" << cr << "\n";
86  totalE += cr.totalE();
87  }
88 
89  s << "\tTotal E = " << totalE << std::endl;
90  return s;
91 
92 }
93 
94 vector<double> CaloWindow::stream(double normalisation) const {
95  vector<double> stream;
96  for (map<unsigned, pftools::CaloRing>::const_iterator cit =
97  energies_.begin(); cit != energies_.end(); ++cit) {
98  CaloRing c = (*cit).second;
99  std::vector<double> ringE = c.getEnergies();
100  stream.insert(stream.end(), ringE.begin(), ringE.end());
101  }
102  if(normalisation != 1.0){
103  for(vector<double>::iterator i = stream.begin(); i != stream.end(); ++i) {
104  double& entry = *i;
105  entry /= normalisation;
106  }
107  }
108  return stream;
109 
110 }
111 
112 void CaloWindow::printEnergies(std::ostream& s, double range) {
113 
114  for (std::map<unsigned, pftools::CaloRing>::const_iterator cit =
115  energies_.begin(); cit != energies_.end(); ++cit) {
116  CaloRing c = (*cit).second;
117  c.printEnergies(s, range);
118  s << "\t";
119  }
120 
121 }
122 
124  baryEta_(0.0), baryPhi_(0.0), nRings_(1), deltaR_(0.1), nPanes_(1), axis_(0.0) {
125 
126 }
127 
128 CaloWindow::CaloWindow(double eta, double phi, unsigned nRings, double deltaR, unsigned nPanes, double axis) {
129 
130  init(eta, phi, nRings, deltaR, nPanes, axis);
131 }
132 
134  energies_.clear();
135 }
136 
137 void CaloWindow::init(double eta, double phi, unsigned nRings, double deltaR, unsigned nPanes, double axis) {
138  baryEta_ = eta;
139  baryPhi_ = phi;
140  nRings_ = nRings;
141  deltaR_ = deltaR;
142  nPanes_ = nPanes;
143  axis_ = axis;
144 
145  energies_.clear();
146  CaloRing c(1);
147  energies_[0] = c;
148  for (unsigned j(1); j < nRings_; ++j) {
149 
150  CaloRing r(nPanes);
151  energies_[j] = r;
152  }
153 }
154 
156 
157 }
158 
159 std::pair<unsigned, unsigned> CaloWindow::relativePosition(double eta,
160  double phi) const {
161  //How far is this hit from the barycentre in deltaR?
162  double dEta = eta - baryEta_;
163  double dPhi = deltaPhi(phi, baryPhi_);
164 
165  double dR = deltaR(eta, phi, baryEta_, baryPhi_);
166 
167  unsigned ring = static_cast<unsigned> (floor(dR / deltaR_));
168 
169  if (ring == 0) {
170  //LogDebug("CaloWindow") << "Relative position: adding to central ring\n";
171  return std::pair<unsigned, unsigned>(0, 0);
172  }
173 
174  if (ring >= nRings_) {
175  return std::pair<unsigned, unsigned>(ring, 0);
176  }
177 
178  double dTheta = 0;
179 
180  if (dEta > 0) {
181  if (dPhi > 0)
182  dTheta = TMath::ATan(dPhi / dEta);
183  else
184  dTheta = 2 * TMath::Pi() + TMath::ATan(dPhi / dEta);
185  } else {
186  if (dPhi > 0)
187  dTheta = TMath::Pi() + TMath::ATan(dPhi / dEta);
188  else
189  dTheta = TMath::Pi() + TMath::ATan(dPhi / dEta);
190  }
191  //Rotation. Rotate theta into axis of caloWindow
192  // and also by half a window pane.
193  //TODO: bug check!!
194  //double dThetaOrig(dTheta);
195  double paneOn2 = TMath::Pi() / (*energies_.find(ring)).second.getNPanes();
196  dTheta = dTheta - axis_ - paneOn2;
197  //Original theta between 0 and 2 Pi, but transform above might move us beyond this, so...
198  //double dThetaCopy(dTheta);
199  //std::cout << "dTheta " << dThetaOrig << ", axis " << axis_ << ", paneOn2 " << paneOn2 << ", thetaPrime " << dTheta << "\n";
200  if(dTheta > 2 *TMath::Pi()) {
201  //std::cout << "To infinity and beyond...\n";
202  while(dTheta > 2 * TMath::Pi()) {
203  dTheta -= 2 * TMath::Pi();
204  //std::cout << "dTheta1 " << dTheta << "\n";
205  }
206  }
207  else if (dTheta < 0) {
208  //std::cout << "To infinity and beyond 2... dTheta = " << dTheta << "\n";
209  while(dTheta < 0) {
210  dTheta += 2 * TMath::Pi();
211  //std::cout << "dTheta2 " << dTheta << "\n";
212  }
213  }
214 
215 // std::cout << "\tdTheta is " << dTheta << " rad \n";
216  unsigned division = static_cast<unsigned> (floor((*energies_.find(ring)).second.getNPanes() * dTheta
217  / (TMath::Pi() * 2)));
218  //LogDebug("CaloWindow") << "Ring is " << ring << ", pane is "
219  // << division << "\n";
220 
221  return std::pair<unsigned, unsigned>(ring, division);
222 
223 }
224 
225 bool CaloWindow::addHit(double eta, double phi, double energy) {
226 
227  std::pair<unsigned, unsigned> position = relativePosition(eta, phi);
228  if (position.first >= nRings_) {
229 /* double dEta = eta - baryEta_;
230  double dPhi = deltaPhi(phi, baryPhi_);
231  double dR = deltaR(eta, phi, baryEta_, baryPhi_);
232  LogDebug("CaloWindow")
233  << "Hit is outside my range - it would be in ring "
234  << position.first << ", with dR = " << dR << std::endl;*/
235  return false;
236  }
237 // std::cout << "Adding hit to ring " << position.first << " in position "
238 // << position.second << " with energy " << energy << "\n";
239 
240  CaloRing& c = energies_[position.first];
241  c.addEnergy(position.second, energy);
242 
243  return true;
244 }
245 std::map<unsigned, double> CaloWindow::getRingEnergySummations() const {
246  std::map<unsigned, double> answer;
247  for (std::map<unsigned, CaloRing>::const_iterator cit = energies_.begin(); cit
248  != energies_.end(); ++cit) {
249  std::pair<unsigned, CaloRing> pair = *cit;
250  answer[pair.first] = pair.second.totalE();
251  }
252 
253  return answer;
254 }
255 
257 
258  CaloWindow cw(0.0, 0.0, 3, 0.1, 4);
259  std::cout << cw << std::endl;
260  cw.addHit(0, 0.05, 1.0);
261  cw.addHit(0.22, 0.05, 2.0);
262  cw.addHit(0, 0.8, 4.0);
263  cw.addHit(0.2, 0, 1.0);
264  cw.addHit(0.15, 0.15, 2.0);
265  cw.addHit(0.0, 0.2, 3.0);
266  cw.addHit(-0.15, 0.15, 4.0);
267  cw.addHit(-0.2, 0, 5.0);
268  cw.addHit(-0.15, -0.15, 6.0);
269  cw.addHit(-0.0, -0.2, 7.0);
270  cw.addHit(0.15, -0.15, 8.0);
271 
272  std::cout << cw << std::endl;
273  std::cout << "bye bye" << std::endl;
274 
275 }
std::map< unsigned, CaloRing > energies_
Definition: CaloWindow.h:165
const double Pi
answer
Definition: submit.py:44
int i
Definition: DBlmapReader.cc:9
unsigned panes_
Definition: CaloWindow.h:87
double deltaR_
double baryPhi() const
Definition: CaloWindow.h:142
std::map< unsigned, double > getRingEnergySummations() const
Definition: CaloWindow.cc:245
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:112
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
bool addHit(double eta, double phi, double energy)
Definition: CaloWindow.cc:225
const reco::Candidate::LorentzVector & axis_
int j
Definition: DBlmapReader.cc:9
std::vector< double > stream(double normalisation=1.0) const
Definition: CaloWindow.cc:94
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::map< unsigned, CaloRing > const & getRingDepositions() const
Definition: CaloWindow.h:121
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:159
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:137
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
list entry
Definition: mps_splice.py:62
std::vector< double > const & getEnergies() const
Definition: CaloWindow.h:71
tuple cout
Definition: gather_cfg.py:145
std::ostream & operator<<(std::ostream &s, const Calibratable &calib_)
Definition: Calibratable.cc:6
virtual ~CaloWindow()
Definition: CaloWindow.cc:155
double baryEta() const
Definition: CaloWindow.h:141