Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InttCombinedRawDataConverter.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InttCombinedRawDataConverter.cc
2 #include "InttMapping.h"
3 
6 
8 #include <fun4all/SubsysReco.h>
9 
10 #include <phool/getClass.h>
11 #include <phool/phool.h>
12 
13 #include <TFile.h>
14 #include <TSystem.h>
15 #include <TTree.h>
16 
17 #include <cstdlib> // for exit
18 #include <iostream> // for operator<<, endl, bas...
19 #include <utility> // for pair
20 
21 class PHCompositeNode;
22 
24  : SubsysReco(name)
25 {
26  // Do nothing
27 }
28 
30 {
31  if (filename.empty())
32  {
33  std::cout << "InttCombinedRawDataConverter::SetOputputFile(std:: string const& filename)" << std::endl;
34  std::cout << "Argument \"filename\" is empty string" << std::endl;
35  std::cout << "No output was written" << std::endl;
36 
37  return 1;
38  }
39 
40  std::cout << "Will write to file:" << std::endl;
41  std::cout << "\t" << filename << std::endl;
42 
43  file = TFile::Open(filename.c_str(), "RECREATE");
44  if (tree)
45  {
46  tree->SetDirectory(file);
47  }
48 
49  return 0;
50 }
51 
53 {
54  if (!file)
55  {
56  std::cout << "InttCombinedRawDataConverter::WriteOputputFile()" << std::endl;
57  std::cout << "Member \"file\" is uninitialized" << std::endl;
58  std::cout << "Did you call SetOutputFile()?" << std::endl;
59  std::cout << "No output was written" << std::endl;
60  return 1;
61  }
62 
63  if (!tree)
64  {
65  std::cout << "InttCombinedRawDataConverter::WriteOputputFile()" << std::endl;
66  std::cout << "Member \"tree\" is uninitialized" << std::endl;
67  std::cout << "Did you call SetOutputFile()?" << std::endl;
68  std::cout << "No output was written" << std::endl;
69  return 1;
70  }
71 
72  file->cd();
73  tree->Write();
74  file->Write();
75  file->Close();
76  return 0;
77 }
78 
80 {
81  delete tree;
82  tree = new TTree("prdf_tree", "prdf_tree");
83  if (file)
84  {
85  tree->SetDirectory(file);
86  }
87 
88  tree->Branch("n_evt", &n_evt);
89  tree->Branch("num_hits", &num_hits);
90 
91  branches_i =
92  {
93  {"flx_svr", new std::vector<Int_t>()},
94  {"flx_chn", new std::vector<Int_t>()},
95  {"lyr", new std::vector<Int_t>()},
96  {"ldr", new std::vector<Int_t>()},
97  {"arm", new std::vector<Int_t>()},
98  {"chp", new std::vector<Int_t>()},
99  {"chn", new std::vector<Int_t>()},
100 
101  {"flx_bco", new std::vector<Int_t>()},
102  {"adc", new std::vector<Int_t>()},
103  {"amp", new std::vector<Int_t>()},
104  };
105 
106  branches_l =
107  {
108  {"gtm_bco", new std::vector<Long64_t>()},
109  };
110 
111  branches_d =
112  {
113  //{"g_x", new std::vector<Double_t>()},
114  //{"g_y", new std::vector<Double_t>()},
115  //{"g_z", new std::vector<Double_t>()},
116  };
117 
118  for (auto& itr : branches_i)
119  {
120  tree->Branch(itr.first.c_str(), &(itr.second));
121  }
122  for (auto& itr : branches_l)
123  {
124  tree->Branch(itr.first.c_str(), &(itr.second));
125  }
126  for (auto& itr : branches_d)
127  {
128  tree->Branch(itr.first.c_str(), &(itr.second));
129  }
130 
131  if (Verbosity() > 20)
132  {
133  std::cout << "int InttCombinedRawDataConverter::Init(PHCompositeNode* /*topNode*/)" << std::endl;
134  }
135  if (Verbosity() > 20)
136  {
137  std::cout << "\tDone";
138  }
139 
140  return 0;
141 }
142 
144 {
145  n_evt = 0;
146  for (auto& itr : branches_i)
147  {
148  itr.second->clear();
149  }
150  for (auto& itr : branches_l)
151  {
152  itr.second->clear();
153  }
154  for (auto& itr : branches_d)
155  {
156  itr.second->clear();
157  }
158 
159  if (Verbosity() > 20)
160  {
161  std::cout << "int InttCombinedRawDataConverter::InitRun(PHCompositeNode* /*topNode*/)" << std::endl;
162  }
163  if (Verbosity() > 20)
164  {
165  std::cout << "\tDone";
166  }
167 
169 }
170 
172 {
173  if (!tree)
174  {
176  }
177 
178  if (Verbosity() > 20)
179  {
180  std::cout << "int InttCombinedRawDataConverter::process_event(PHCompositeNode* topNode)" << std::endl;
181  }
182  if (Verbosity() > 20)
183  {
184  std::cout << "\t" << n_evt << std::endl;
185  }
186 
187  InttRawHitContainer* inttcont = findNode::getClass<InttRawHitContainer>(topNode, m_InttRawNodeName);
188  if (!inttcont)
189  {
190  std::cout << "int InttCombinedRawDataConverter::process_event(PHCompositeNode* topNode)" << std::endl;
191  std::cout << "\t" << PHWHERE << " could not find node " << m_InttRawNodeName << std::endl;
192  std::cout << "\tExiting" << std::endl;
193 
194  gSystem->Exit(1);
195  exit(1);
196  }
197 
198  for (auto& itr : branches_i)
199  {
200  itr.second->clear();
201  }
202  for (auto& itr : branches_l)
203  {
204  itr.second->clear();
205  }
206  for (auto& itr : branches_d)
207  {
208  itr.second->clear();
209  }
210 
213  std::map<std::tuple<int, int, int, int, int>, char> hits;
214  for (unsigned int i = 0; i < inttcont->get_nhits(); i++)
215  {
216  InttRawHit* intthit = inttcont->get_hit(i);
217 
218  InttNameSpace::RawFromHit(raw, intthit);
219  // raw.felix_server = InttNameSpace::FelixFromPacket(intthit->get_packetid());
220  // raw.felix_channel = intthit->get_fee();
221  // raw.chip = (intthit->get_chip_id() + 25) % 26;
222  // raw.channel = intthit->get_channel_id();
223  onl = InttNameSpace::ToOnline(raw);
224 
225  std::tuple<int, int, int, int, int> tpl;
226  std::get<0>(tpl) = onl.lyr;
227  std::get<1>(tpl) = onl.ldr;
228  std::get<2>(tpl) = onl.arm;
229  std::get<3>(tpl) = onl.chp;
230  std::get<4>(tpl) = onl.chn;
231 
232  if (hits.find(tpl) != hits.end())
233  {
234  continue;
235  }
236  hits[tpl] = 0;
237 
238  branches_i["flx_svr"]->push_back(raw.felix_server);
239  branches_i["flx_chn"]->push_back(raw.felix_channel);
240 
241  branches_i["lyr"]->push_back(onl.lyr);
242  branches_i["ldr"]->push_back(onl.ldr);
243  branches_i["arm"]->push_back(onl.arm);
244  branches_i["chp"]->push_back(onl.chp);
245  branches_i["chn"]->push_back(onl.chn);
246 
247  branches_i["flx_bco"]->push_back(intthit->get_FPHX_BCO());
248  branches_i["adc"]->push_back(intthit->get_adc());
249  branches_i["amp"]->push_back(intthit->get_amplitude());
250 
251  branches_l["gtm_bco"]->push_back(intthit->get_bco());
252  }
253 
254  num_hits = branches_l.begin()->second->size();
255  tree->Fill();
256  ++n_evt;
257 
259 }
260 
262 {
264 }