Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalTools.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CalTools.h
1 // ----------------------------------------------------------------------------
2 // 'CalTools.h'
3 // Derek Anderson
4 // 10.30.2023
5 //
6 // Collection of frequent calo. cluster-related methods utilized
7 // in the sPHENIX Cold QCD Energy-Energy Correlator analysis.
8 // ----------------------------------------------------------------------------
9 
10 #pragma once
11 
12 // c++ utilities
13 #include <limits>
14 #include <string>
15 #include <vector>
16 #include <cassert>
17 #include <optional>
18 // phool libraries
19 #include <phool/phool.h>
20 #include <phool/getClass.h>
21 #include <phool/PHIODataNode.h>
22 #include <phool/PHNodeIterator.h>
23 #include <phool/PHCompositeNode.h>
24 // CaloBase libraries
25 #include <calobase/RawCluster.h>
26 #include <calobase/RawClusterUtility.h>
27 #include <calobase/RawClusterContainer.h>
28 // analysis utilities
29 #include "Constants.h"
30 
31 // make common namespaces implicit
32 using namespace std;
33 using namespace findNode;
34 
35 
36 
37 namespace SColdQcdCorrelatorAnalysis {
38  namespace SCorrelatorUtilities {
39 
40  // ClustInfo definition ---------------------------------------------------
41 
42  struct ClustInfo {
43 
44  // data members
45  int system = numeric_limits<int>::max();
46  size_t nTwr = numeric_limits<size_t>::max();
47  double ene = numeric_limits<double>::max();
48  double rho = numeric_limits<double>::max();
49  double eta = numeric_limits<double>::max();
50  double phi = numeric_limits<double>::max();
51  double rx = numeric_limits<double>::max();
52  double ry = numeric_limits<double>::max();
53  double rz = numeric_limits<double>::max();
54 
55  void SetInfo(const RawCluster* clust, optional<int> sys = nullopt) {
56  if (sys.has_value()) {
57  system = sys.value();
58  }
59  nTwr = clust -> getNTowers();
60  ene = clust -> get_energy();
61  rho = clust -> get_r();
62  eta = numeric_limits<double>::max(); // FIXME add method to calculate eta
63  phi = clust -> get_phi();
64  rx = clust -> get_position().x();
65  ry = clust -> get_position().y();
66  rz = clust -> get_position().z();
67  return;
68  };
69 
70  void Reset() {
71  system = numeric_limits<int>::max();
72  nTwr = numeric_limits<int>::max();
73  ene = numeric_limits<double>::max();
74  rho = numeric_limits<double>::max();
75  eta = numeric_limits<double>::max();
76  phi = numeric_limits<double>::max();
77  rx = numeric_limits<double>::max();
78  ry = numeric_limits<double>::max();
79  rz = numeric_limits<double>::max();
80  return;
81  } // end 'Reset()'
82 
83  static vector<string> GetListOfMembers() {
84  vector<string> members = {
85  "sys",
86  "nTwr",
87  "ene",
88  "rho",
89  "eta",
90  "phi",
91  "rx",
92  "ry",
93  "rz"
94  };
95  return members;
96  } // end 'GetListOfMembers()'
97 
98  // overloaded < operator
99  friend bool operator<(const ClustInfo& lhs, const ClustInfo& rhs) {
100 
101  // note that some quantities aren't relevant for this comparison
102  const bool isLessThan = (
103  (lhs.nTwr < rhs.nTwr) &&
104  (lhs.ene < rhs.ene) &&
105  (lhs.rho < rhs.rho) &&
106  (lhs.eta < rhs.eta) &&
107  (lhs.phi < rhs.phi) &&
108  (lhs.rx < rhs.rx) &&
109  (lhs.ry < rhs.ry) &&
110  (lhs.rz < rhs.rz)
111  );
112  return isLessThan;
113 
114  } // end 'operator<(ClustInfo&, ClustInfo&)'
115 
116  // overloaded > operator
117  friend bool operator>(const ClustInfo& lhs, const ClustInfo& rhs) {
118 
119  // note that some quantities aren't relevant for this comparison
120  const bool isGreaterThan = (
121  (lhs.nTwr > rhs.nTwr) &&
122  (lhs.ene > rhs.ene) &&
123  (lhs.rho > rhs.rho) &&
124  (lhs.eta > rhs.eta) &&
125  (lhs.phi > rhs.phi) &&
126  (lhs.rx > rhs.rx) &&
127  (lhs.ry > rhs.ry) &&
128  (lhs.rz > rhs.rz)
129  );
130  return isGreaterThan;
131 
132  } // end 'operator>(ClustInfo&, ClustInfo&)'
133 
134  // overloaded, <=, >= operators
135  inline friend bool operator<=(const ClustInfo& lhs, const ClustInfo& rhs) {return !(lhs > rhs);}
136  inline friend bool operator>=(const ClustInfo& lhs, const ClustInfo& rhs) {return !(lhs < rhs);}
137 
138  // default ctor/dtor
139  ClustInfo() {};
141 
142  // ctor accepting RawClusters
143  ClustInfo(const RawCluster* clust, optional<int> sys = nullopt) {
144  SetInfo(clust, sys);
145  }
146 
147  }; // end ClustInfo def
148 
149 
150 
151  // cluster methods --------------------------------------------------------
152 
154 
155  // grab clusters
156  RawClusterContainer* clustStore = getClass<RawClusterContainer>(topNode, node.data());
157  if (!clustStore) {
158  cout << PHWHERE
159  << "PANIC: " << node << " node is missing!"
160  << endl;
161  assert(clustStore);
162  }
163  return clustStore;
164 
165  } // end 'GetClusterStore(PHCompositeNode*, string)'
166 
167 
168 
170 
171  // get store and return range of clusters
172  RawClusterContainer* clustStore = GetClusterStore(topNode, store);
173  return clustStore -> getClusters();
174 
175  } // end 'GetClusters(PHCompositeNode*, string)'
176 
177 
178 
179  bool IsInAcceptance(const ClustInfo& cluster, const ClustInfo& minimum, const ClustInfo& maximum) {
180 
181  return ((cluster >= minimum) && (cluster <= maximum));
182 
183  } // end 'IsInAcceptance(ClustInfo&, ClustInfo&, ClustInfo&)'
184 
185  } // end SCorrelatorUtilities namespace
186 } // end SColdQcdCorrealtorAnalysis namespace
187 
188 // end ------------------------------------------------------------------------
189