Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
caloTreeGen.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file caloTreeGen.cc
1 #include "caloTreeGen.h"
2 
4 
6 
7 //Fun4All
11 #include <phool/PHCompositeNode.h>
12 #include <phool/getClass.h>
13 #include <phool/phool.h>
14 #include <ffaobjects/EventHeader.h>
15 
16 //ROOT stuff
17 #include <TH1F.h>
18 #include <TH2F.h>
19 #include <TH3F.h>
20 #include <TFile.h>
21 #include <TLorentzVector.h>
22 #include <TTree.h>
23 
24 //For clusters and geometry
25 #include <calobase/RawCluster.h>
26 #include <calobase/RawClusterContainer.h>
27 #include <calobase/RawClusterUtility.h>
28 #include <calobase/RawTowerGeomContainer.h>
29 
30 //Tower stuff
31 #include <calobase/TowerInfoContainer.h>
32 #include <calobase/TowerInfo.h>
33 
34 //thingy
35 #include <CLHEP/Geometry/Point3D.h>
36 
37 
38 //____________________________________________________________________________..
40 SubsysReco(name)
41  ,T(nullptr)
42  ,Outfile(name)
43  ,doClusters(1)
44 ,totalCaloE(0)
45 ,doFineCluster(0)
46 {
47  std::cout << "caloTreeGen::caloTreeGen(const std::string &name) Calling ctor" << std::endl;
48 }
49 
50 //____________________________________________________________________________..
52 {
53  std::cout << "caloTreeGen::~caloTreeGen() Calling dtor" << std::endl;
54 }
55 
56 //____________________________________________________________________________..
58 {
59 
60  out = new TFile(Outfile.c_str(),"RECREATE");
61 
62 
63  T = new TTree("T","T");
64 
65  //emc
66  T -> Branch("emcTowE",&m_emcTowE);
67  T -> Branch("emcTowEta",&m_emcTowEta);
68  T -> Branch("emcTowPhi",&m_emcTowPhi);
69  T -> Branch("emcTiming",&m_emcTiming);
70  T -> Branch("emciEta",&m_emciEta);
71  T -> Branch("emciPhi",&m_emciPhi);
72 
73  T -> Branch("clusterEFull",&m_clusterE);
74  T -> Branch("clusterPhi",&m_clusterPhi);
75  T -> Branch("clusterEta", &m_clusterEta);
76  T -> Branch("clustrPt", &m_clusterPt);
77  T -> Branch("clusterChi", &m_clusterChi);
78  T -> Branch("clusterNtow",&m_clusterNtow);
79  T -> Branch("clusterTowMax",&m_clusterTowMax);
80  T -> Branch("clusterECore",&m_clusterECore);
81 
82  T -> Branch("totalCaloE",&totalCaloE);
83 
84  T -> Branch("clusTowPhi","vector<vector<int> >",&m_clusTowPhi);
85  T -> Branch("clusTowEta","vector<vector<int> >",&m_clusTowEta);
86  T -> Branch("clusTowE","vector<vector<float> >",&m_clusTowE);
87 
88  //so that the histos actually get written out
90  se -> Print("NODETREE");
91 
92  std::cout << "caloTreeGen::Init(PHCompositeNode *topNode) Initializing" << std::endl;
94 }
95 
96 //____________________________________________________________________________..
98 {
99  std::cout << "caloTreeGen::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
101 }
102 
103 //____________________________________________________________________________..
105 {
106 
107  //Information on clusters
108  RawClusterContainer *clusterContainer = findNode::getClass<RawClusterContainer>(topNode,"CLUSTERINFO_CEMC");
109  if(!clusterContainer && doClusters)
110  {
111  std::cout << PHWHERE << "caloTreeGen::process_event - Fatal Error - CLUSTER_CEMC node is missing. " << std::endl;
112  return 0;
113  }
114 
115  //tower information
116  TowerInfoContainer *emcTowerContainer;
117  emcTowerContainer = findNode::getClass<TowerInfoContainer>(topNode,"TOWERINFO_CALIB_CEMC");
118  if(!emcTowerContainer)
119  {
120  std::cout << PHWHERE << "caloTreeGen::process_event Could not find node TOWERS_CEMC" << std::endl;
122  }
123 
124 
125  //Tower geometry node for location information
126  RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
127  if (!towergeom && doClusters)
128  {
129  std::cout << PHWHERE << "caloTreeGen::process_event Could not find node TOWERGEOM_CEMC" << std::endl;
131  }
132 
133  float calib = 1.;
134 
135  //grab all the towers and fill their energies.
136  unsigned int tower_range = emcTowerContainer->size();
137  totalCaloE = 0;
138  for(unsigned int iter = 0; iter < tower_range; iter++)
139  {
140  unsigned int towerkey = emcTowerContainer->encode_key(iter);
141  unsigned int ieta = getCaloTowerEtaBin(towerkey);
142  unsigned int iphi = getCaloTowerPhiBin(towerkey);
143  m_emciEta.push_back(ieta);
144  m_emciPhi.push_back(iphi);
145 
146  double energy = emcTowerContainer -> get_tower_at_channel(iter) -> get_energy()/calib;
147  totalCaloE += energy;
148  double time = emcTowerContainer -> get_tower_at_channel(iter) -> get_time();
149 
150  if(doClusters)
151  {
152  double phi = towergeom -> get_phicenter(iphi);
153  double eta = towergeom -> get_etacenter(ieta);
154  m_emcTowPhi.push_back(phi);
155  m_emcTowEta.push_back(eta);
156  }
157  m_emcTowE.push_back(energy);
158  m_emcTiming.push_back(time);
159 
160  }
161 
162  if(doClusters)
163  {
164  RawClusterContainer::ConstRange clusterEnd = clusterContainer -> getClusters();
166  for(clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
167  {
168  RawCluster *recoCluster = clusterIter -> second;
169 
170  CLHEP::Hep3Vector vertex(0,0,0);
171  CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*recoCluster, vertex);
172  CLHEP::Hep3Vector E_vec_cluster_Full = RawClusterUtility::GetEVec(*recoCluster, vertex);
173 
174  float clusE = E_vec_cluster.mag();
175  float clus_eta = E_vec_cluster.pseudoRapidity();
176  float clus_phi = E_vec_cluster.phi();
177  float clus_pt = E_vec_cluster.perp();
178  float clus_chi = recoCluster -> get_chi2();
179  float nTowers = recoCluster ->getNTowers();
180  float maxTowerEnergy = getMaxTowerE(recoCluster,emcTowerContainer);
181 
182  m_clusterE.push_back(E_vec_cluster_Full.mag());
183  m_clusterECore.push_back(clusE);
184  m_clusterPhi.push_back(clus_phi);
185  m_clusterEta.push_back(clus_eta);
186  m_clusterPt.push_back(clus_pt);
187  m_clusterChi.push_back(clus_chi);
188  m_clusterNtow.push_back(nTowers);
189  m_clusterTowMax.push_back(maxTowerEnergy);
190  if(doFineCluster)
191  {
192  m_clusTowPhi.push_back(returnClusterTowPhi(recoCluster,emcTowerContainer));
193  m_clusTowEta.push_back(returnClusterTowEta(recoCluster,emcTowerContainer));
194  m_clusTowE.push_back(returnClusterTowE(recoCluster,emcTowerContainer));
195  }
196  }
197  }
198 
199  T -> Fill();
200 
202 }
203 
204 //____________________________________________________________________________..
206 {
207  m_clusterE.clear();
208  m_clusterPhi.clear();
209  m_clusterEta.clear();
210  m_clusterPt.clear();
211  m_clusterChi.clear();
212  m_clusterTowMax.clear();
213  m_clusterNtow.clear();
214  m_clusterECore.clear();
215 
216  m_emcTowPhi.clear();
217  m_emcTowEta.clear();
218  m_emcTowE.clear();
219  m_emcTiming.clear();
220  m_emciEta.clear();
221  m_emciPhi.clear();
222 
223  m_clusTowPhi.clear();
224  m_clusTowEta.clear();
225  m_clusTowE.clear();
226 
228 }
229 
230 //____________________________________________________________________________..
232 {
233  std::cout << "caloTreeGen::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
235 }
236 
237 //____________________________________________________________________________..
239 {
240  std::cout << "caloTreeGen::End(PHCompositeNode *topNode) This is the End..." << std::endl;
241 
242  out -> cd();
243  T -> Write();
244  out -> Close();
245  delete out;
246 
247  //hm -> dumpHistos(Outfile.c_str(), "UPDATE");
249 }
250 
251 //____________________________________________________________________________..
253 {
254  std::cout << "caloTreeGen::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
256 }
257 
258 //____________________________________________________________________________..
259 void caloTreeGen::Print(const std::string &what) const
260 {
261  std::cout << "caloTreeGen::Print(const std::string &what) const Printing info for " << what << std::endl;
262 }
263 // convert from calorimeter key to phi bin
264 //____________________________________________________________________________..
265 unsigned int caloTreeGen::getCaloTowerPhiBin(const unsigned int key)
266 {
267  unsigned int etabin = key >> 16U;
268  unsigned int phibin = key - (etabin << 16U);
269  return phibin;
270 }
271 
272 //____________________________________________________________________________..
273 // convert from calorimeter key to eta bin
274 unsigned int caloTreeGen::getCaloTowerEtaBin(const unsigned int key)
275 {
276  unsigned int etabin = key >> 16U;
277  return etabin;
278 }
279 //____________________________________________________________________________..
281 {
282  RawCluster::TowerConstRange towers = cluster -> get_towers();
284 
285  float maxEnergy = 0;
286  for(toweriter = towers.first; toweriter != towers.second; toweriter++)
287  {
288  float towE = toweriter -> second;
289 
290  if( towE > maxEnergy) maxEnergy = towE;
291  }
292  return maxEnergy;
293 }
294 //____________________________________________________________________________..
295 std::vector<int> caloTreeGen::returnClusterTowEta(RawCluster *cluster, TowerInfoContainer *towerContainer)
296 {
297  RawCluster::TowerConstRange towers = cluster -> get_towers();
299 
300  std::vector<int> towerIDsEta;
301  for(toweriter = towers.first; toweriter != towers.second; toweriter++) towerIDsEta.push_back(RawTowerDefs::decode_index1(toweriter -> first));
302 
303  return towerIDsEta;
304 }
305 //____________________________________________________________________________..
306 std::vector<int> caloTreeGen::returnClusterTowPhi(RawCluster *cluster, TowerInfoContainer *towerContainer)
307 {
308  RawCluster::TowerConstRange towers = cluster -> get_towers();
310 
311  std::vector<int> towerIDsPhi;
312  for(toweriter = towers.first; toweriter != towers.second; toweriter++) towerIDsPhi.push_back(RawTowerDefs::decode_index2(toweriter -> first));
313  return towerIDsPhi;
314 }
315 //____________________________________________________________________________..
316 std::vector<float> caloTreeGen::returnClusterTowE(RawCluster *cluster, TowerInfoContainer *towerContainer)
317 {
318  RawCluster::TowerConstRange towers = cluster -> get_towers();
320 
321  std::vector<float> towerE;
322  for(toweriter = towers.first; toweriter != towers.second; toweriter++) towerE.push_back(toweriter -> second);
323 
324  return towerE;
325 }