Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcRawDataTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcRawDataTree.cc
1 
2 #include "TpcRawDataTree.h"
3 
6 #include <phool/PHIODataNode.h> // for PHIODataNode
7 #include <phool/PHNodeIterator.h> // for PHNodeIterator
8 #include <phool/PHObject.h> // for PHObject
9 #include <phool/getClass.h>
10 #include <phool/phool.h>
11 
12 #include <Event/Event.h>
13 #include <Event/EventTypes.h>
14 #include <Event/packet.h>
15 
16 #include <TFile.h>
17 #include <TTree.h>
18 #include <TH1F.h>
19 #include <TH2F.h>
20 
21 #include <cassert>
22 #include <iostream>
23 #include <memory>
24 
25 //____________________________________________________________________________..
27  : SubsysReco("TpcRawDataTree")
28  , m_fname(name)
29 {
30  // reserve memory for max ADC samples
31  m_adcSamples.resize(1024, 0);
32  M.setMapNames("AutoPad-R1-RevA.sch.ChannelMapping.csv", "AutoPad-R2-RevA-Pads.sch.ChannelMapping.csv", "AutoPad-R3-RevA.sch.ChannelMapping.csv");
33 }
34 
35 //____________________________________________________________________________..
37 {
39  size_t pos = sectorNum.find("TPC_ebdc");
40  sectorNum.erase(sectorNum.begin(),sectorNum.begin()+pos+8);
41  sectorNum.erase(sectorNum.begin()+2,sectorNum.end());
42  if(sectorNum.at(0) == '0') sectorNum.erase(sectorNum.begin(),sectorNum.begin()+1);
43  if(stoi(sectorNum) > 11) side = 1;
44 
45  m_file = TFile::Open(m_fname.c_str(), "recreate");
46  assert(m_file->IsOpen());
47 
48  m_PacketTree = new TTree("PacketTree", "Each entry is one packet");
49 
50  m_PacketTree->Branch("packet", &m_packet, "packet/I");
51  m_PacketTree->Branch("frame", &m_frame, "frame/I");
52  m_PacketTree->Branch("nWaveormInFrame", &m_nWaveormInFrame, "nWaveormInFrame/I");
53  m_PacketTree->Branch("nTaggerInFrame", &m_nTaggerInFrame, "nTaggerInFrame/I");
54  m_PacketTree->Branch("maxFEECount", &m_maxFEECount, "maxFEECount/I");
55 
56  m_SampleTree = new TTree("SampleTree", "Each entry is one waveform");
57 
58  m_SampleTree->Branch("packet", &m_packet, "packet/I");
59  m_SampleTree->Branch("frame", &m_frame, "frame/I");
60  m_SampleTree->Branch("nWaveormInFrame", &m_nWaveormInFrame, "nWaveormInFrame/I");
61  m_SampleTree->Branch("maxFEECount", &m_maxFEECount, "maxFEECount/I");
62  m_SampleTree->Branch("nSamples", &m_nSamples, "nSamples/I");
63  m_SampleTree->Branch("adcSamples", &m_adcSamples[0], "adcSamples[nSamples]/s");
64  m_SampleTree->Branch("fee", &m_fee, "fee/I");
65  m_SampleTree->Branch("sampaAddress", &m_sampaAddress, "sampaAddress/I");
66  m_SampleTree->Branch("sampaChannel", &m_sampaChannel, "sampaChannel/I");
67  m_SampleTree->Branch("Channel", &m_Channel, "Channel/I");
68  m_SampleTree->Branch("BCO", &m_BCO, "BCO/I");
69  m_SampleTree->Branch("checksum", &m_checksum, "checksum/I");
70  m_SampleTree->Branch("checksumError", &m_checksumError, "checksumError/I");
71 
72  m_TaggerTree = new TTree("TaggerTree", "Each entry is one tagger for level 1 trigger or endat tag");
73 
74  m_TaggerTree->Branch("packet", &m_packet, "packet/I");
75  m_TaggerTree->Branch("frame", &m_frame, "frame/I");
76  m_TaggerTree->Branch("tagger_type", &m_tagger_type, "tagger_type/s");
77  m_TaggerTree->Branch("is_endat", &m_is_endat, "is_endat/b");
78  m_TaggerTree->Branch("is_lvl1", &m_is_lvl1, "is_lvl1/b");
79  m_TaggerTree->Branch("bco", &m_bco, "bco/l");
80  m_TaggerTree->Branch("lvl1_count", &m_lvl1_count, "lvl1_count/i");
81  m_TaggerTree->Branch("endat_count", &m_endat_count, "endat_count/i");
82  m_TaggerTree->Branch("last_bco", &m_last_bco, "last_bco/l");
83  m_TaggerTree->Branch("modebits", &m_modebits, "modebits/b");
84 
85  R1_hist = new TH1F("R1_hist","R1_hist",1024,-0.5,1023.5);
86  R2_hist = new TH1F("R2_hist","R2_hist",1024,-0.5,1023.5);
87  R3_hist = new TH1F("R3_hist","R3_hist",1024,-0.5,1023.5);
88 
89  R1_time = new TH2F("R1_time","R1_time",360,-0.5,359.5,1024,-0.5,1023.5);
90  R2_time = new TH2F("R2_time","R2_time",360,-0.5,359.5,1024,-0.5,1023.5);
91  R3_time = new TH2F("R3_time","R3_time",360,-0.5,359.5,1024,-0.5,1023.5);
92 
93  TotalFEE = new TH1F("TotalFEE", "Total FEE", 26, -0.5, 25.5);
94  TotalFEEsampa = new TH1F("TotalFEEsampa", "Total FEE + sampa", 26*8, -0.5, 25*8-.5);
95  TotalFRAME = new TH1F("TotalFRAME", "Total FRAME", 21, -0.5, 20.5);
96 
97  checksumError_fee = new TH1F("FEEWithError", "FEE with Error", 26, -0.5, 25.5);
98  checksumError_feesampa = new TH1F("FEEsampaWithError", "FEE*8+sampa with Error", 26*8, -0.5, 25*8-.5);
99  checksumError_frame = new TH1F("FRAMEWithError", "FRAME with Error", 21, -0.5, 20.5);
100 
101  if (m_includeXYPos)
102  {
103  m_SampleTree->Branch("xPos", &m_xPos, "xPos/d");
104  m_SampleTree->Branch("yPos", &m_yPos, "yPos/d");
105  }
106 
108 }
109 
110 //____________________________________________________________________________..
112 {
113  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
114  if (_event == nullptr)
115  {
116  std::cout << "TpcRawDataTree::Process_Event Event not found" << std::endl;
117  return -1;
118  }
119  if (_event->getEvtType() >= 8)
120  {
122  }
123 
124  m_frame = _event->getEvtSequence();
125 
126  for (int packet : m_packets)
127  {
128  if (Verbosity())
129  {
130  std::cout << __PRETTY_FUNCTION__ << " : decoding packet " << packet << std::endl;
131  }
132 
133  m_packet = packet;
134 
135  std::unique_ptr<Packet> p(_event->getPacket(m_packet));
136  if (!p)
137  {
138  if (Verbosity())
139  {
140  std::cout << __PRETTY_FUNCTION__ << " : missing packet " << packet << std::endl;
141  }
142 
143  continue;
144  }
145 
146  m_nWaveormInFrame = p->iValue(0, "NR_WF");
147  m_nTaggerInFrame = p->lValue(0, "N_TAGGER");
148  m_maxFEECount = p->iValue(0, "MAX_FEECOUNT");
149 
150  for (int t = 0; t < m_nTaggerInFrame; t++)
151  {
152  /*uint16_t*/ m_tagger_type = (uint16_t) (p->lValue(t, "TAGGER_TYPE"));
153  /*uint8_t*/ m_is_endat = (uint8_t) (p->lValue(t, "IS_ENDAT"));
154  /*uint8_t*/ m_is_lvl1 = (uint8_t) (p->lValue(t, "IS_LEVEL1_TRIGGER"));
155  /*uint64_t*/ m_bco = (uint64_t) (p->lValue(t, "BCO"));
156  /*uint32_t*/ m_lvl1_count = (uint32_t) (p->lValue(t, "LEVEL1_COUNT"));
157  /*uint32_t*/ m_endat_count = (uint32_t) (p->lValue(t, "ENDAT_COUNT"));
158  /*uint64_t*/ m_last_bco = (uint64_t) (p->lValue(t, "LAST_BCO"));
159  /*uint8_t*/ m_modebits = (uint8_t) (p->lValue(t, "MODEBITS"));
160 
161  m_TaggerTree->Fill();
162  }
163 
164  for (int wf = 0; wf < m_nWaveormInFrame; wf++)
165  {
166  m_BCO = p->iValue(wf, "BCO");
167  m_nSamples = p->iValue(wf, "SAMPLES");
168  m_fee = p->iValue(wf, "FEE");
169 
170  m_sampaAddress = p->iValue(wf, "SAMPAADDRESS");
171  m_sampaChannel = p->iValue(wf, "SAMPACHANNEL");
172  m_Channel = p->iValue(wf, "CHANNEL");
173  m_checksum = p->iValue(wf, "CHECKSUM");
174  m_checksumError = p->iValue(wf, "CHECKSUMERROR");
175 
176  TH1F *fillHist;
177  TH2F *fillHist2D;
178 
179  if(m_fee == 2 ||
180  m_fee == 4 ||
181  m_fee == 3 ||
182  m_fee == 13 ||
183  m_fee == 17 ||
184  m_fee == 16){ fillHist=R1_hist; fillHist2D=R1_time;}
185  else if(m_fee == 11 ||
186  m_fee == 12 ||
187  m_fee == 19 ||
188  m_fee == 18 ||
189  m_fee == 01 ||
190  m_fee == 00 ||
191  m_fee == 16 ||
192  m_fee == 15){ fillHist=R2_hist; fillHist2D=R2_time;}
193  else{ fillHist=R3_hist; fillHist2D=R3_time;}
194 
195 
196  assert(m_nSamples < (int) m_adcSamples.size()); // no need for movements in memory allocation
197  for (int s = 0; s < m_nSamples; s++)
198  {
199  m_adcSamples[s] = p->iValue(wf, s);
200  if(m_checksumError==0){
201  fillHist->Fill(m_adcSamples[s]);
202  fillHist2D->Fill(s,m_adcSamples[s]);
203  }
204  else {
205  checksumError_fee->Fill(m_fee);
208  }
209  TotalFEE->Fill(m_fee);
210  TotalFEEsampa->Fill((m_fee*8. + m_sampaAddress));
211  TotalFRAME->Fill(m_frame);
212  }
213  if(m_includeXYPos)
214  {
215  int feeM = FEE_map[m_fee];
216  if(FEE_R[m_fee]==2) feeM += 6;
217  if(FEE_R[m_fee]==3) feeM += 14;
218  int layer = M.getLayer(feeM, m_Channel);
219  if(layer!=0)
220  {
221  double R = M.getR(feeM, m_Channel);
222  double phi = M.getPhi(feeM, m_Channel) + (stod(sectorNum) - side*12. )* M_PI / 6. ;
223  R /= 10.; //convert mm to cm
224 
225  m_xPos = R*cos(phi);
226  m_yPos = R*sin(phi);
227  }
228  else
229  {
230  m_xPos = 0.;
231  m_yPos = 0.;
232  }
233  }
234  m_SampleTree->Fill();
235  }
236 
237  m_PacketTree->Fill();
238  } // for (int packet : m_packets)
239 
241 }
242 
243 //____________________________________________________________________________..
245 {
246  checksumError_fee->Divide(TotalFEE);
249 
250  TotalFEE->SetDirectory(0);
251  TotalFEEsampa->SetDirectory(0);
252  TotalFRAME->SetDirectory(0);
253 
254  m_file->Write();
255 
256  std::cout << __PRETTY_FUNCTION__ << " : completed saving to " << m_file->GetName() << std::endl;
257  m_file->ls();
258 
259  m_file->Close();
260 
262 }