Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TPCEventDisplay.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TPCEventDisplay.C
1 #include <cstdlib>
2 #include <iostream>
3 #include <map>
4 #include <string>
5 #include <vector>
6 
7 #include "TChain.h"
8 #include "TFile.h"
9 #include "TTree.h"
10 #include "TString.h"
11 #include "TObjString.h"
12 #include "TSystem.h"
13 #include "TROOT.h"
14 #include "TTreeReader.h"
15 #include "TTreeReaderValue.h"
16 #include "TTreeReaderArray.h"
17 #include "TVector3.h"
18 
19 #include <boost/format.hpp>
20 #include <boost/math/special_functions/sign.hpp>
21 
22 /*************************************************************/
23 /* TPC Raw Data Event Display */
24 /* Thomas Marshall,Aditya Dash */
25 /* rosstom@ucla.edu,aditya55@physics.ucla.edu */
26 /*************************************************************/
27 
28 TVector3 getBinPosition(int sector, int inFee, int channel, double zPos, TTree* R1, TTree* R2, TTree* R3)
29 {
30  int mod_arr[26] = {2,2,1,1,1,3,3,3,3,3,3,2,2,1,2,2,1,1,2,2,3,3,3,3,3,3};
31  float slot[26] = {5,6,1,3,2,12,10,11,9,8,7,1,2,4,8,7,6,5,4,3,1,3,2,4,6,5};
32  TTreeReader* myReader;
33  if (mod_arr[inFee] == 1)
34  {
35  myReader = new TTreeReader(R1);
36  }
37  else if (mod_arr[inFee] == 2)
38  {
39  myReader = new TTreeReader(R2);
40  }
41  else if (mod_arr[inFee] == 3)
42  {
43  myReader = new TTreeReader(R3);
44  }
45  TTreeReaderValue<Float_t> FEE(*myReader, "FEE");
46  TTreeReaderValue<Int_t> FEE_Chan(*myReader, "FEE_Chan");
47  //TTreeReaderValue<Double_t> x(myReader, "x");
48  //TTreeReaderValue<Double_t> y(myReader, "y");
49  TTreeReaderValue<Double_t> phi(*myReader, "phi");
50  //TTreeReaderValue<Double_t> PadX(myReader, "PadX");
51  //TTreeReaderValue<Double_t> PadY(myReader, "PadY");
52  TTreeReaderValue<Double_t> PadR(*myReader, "PadR");
53  //TTreeReaderValue<Double_t> PadPhi(myReader, "PadPhi");
54 
55  double phiOffset;
56  if (sector < 12) phiOffset = 2*M_PI*((double)sector/12.) - 2*M_PI*(1./12.)/2;
57  else phiOffset = 2*M_PI*(((double)sector-12.)/12.) - 2*M_PI*(1./12.)/2;
58 
59  while(myReader->Next())
60  {
61  if (slot[inFee]-1 == *FEE && channel == *FEE_Chan)
62  {
63  double x = (*PadR/10)*std::cos(*phi+phiOffset);
64  double y = (*PadR/10)*std::sin(*phi+phiOffset);
65  TVector3 pos;
66  pos.SetX(x); pos.SetY(y); pos.SetZ(zPos);
67  return pos;
68  }
69  }
70  TVector3 pos;
71  pos.SetX(0); pos.SetY(0); pos.SetZ(0);
72  return pos;
73 }
74 
75 
76 void TPCEventDisplay(const float adcCut = 85.,
77  const string &outfile = "/sphenix/user/rosstom/test/TPCEventDisplay_10169.json",
78  const string &indir = "/sphenix/user/rosstom/test/testFiles/",
79  const string &runName = "pedestal-00010169"){
80 
81  std::ofstream outdata;
82  outdata.open(outfile.c_str());
83  if( !outdata ) { // file couldn't be opened
84  cerr << "ERROR: file could not be opened" << endl;
85  exit(1);
86  }
87 
88  outdata << "{\n \"EVENT\": {\n \"runid\": 1, \n \"evtid\": 1, \n \"time\": 0, \n \"type\": \"Collision\", \n \"s_nn\": 0, \n \"B\": 3.0,\n \"pv\": [0,0,0] \n },\n" << endl;
89 
90  outdata << " \"META\": {\n \"HITS\": {\n \"INNERTRACKER\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 5,\n \"color\": 16777215\n } \n },\n" << endl;
91  outdata << " \"TRACKHITS\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 5,\n \"transparent\": 0.5,\n \"color\": 16777215\n } \n },\n" << endl;
92  outdata << " \"JETS\": {\n \"type\": \"JET\",\n \"options\": {\n \"rmin\": 0,\n \"rmax\": 78,\n \"emin\": 0,\n \"emax\": 30,\n \"color\": 16777215,\n \"transparent\": 0.5 \n }\n }\n }\n }\n," << endl;
93  outdata << " \"HITS\": {\n \"CEMC\":[{\"eta\": 0, \"phi\": 0, \"e\": 0}\n ],\n \"HCALIN\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n ],\n \"HCALOUT\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n \n ],\n\n" << endl;
94  outdata << " \"TRACKHITS\": [\n\n ";
95 
96  TTree *R1 = new TTree("R1","TPC Sector Mapping for R1");
97  TTree *R2 = new TTree("R2","TPC Sector Mapping for R1");
98  TTree *R3 = new TTree("R3","TPC Sector Mapping for R1");
99 
100  R1->ReadFile("/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R1-RevA.sch.ChannelMapping.csv",
101  "Entry/I:Radius/I:Pad/I:U/I:G/I:Pin/C:PinColID/I:PinRowID/I:PadName/C:FEE/F:FEE_Connector/C:FEE_Chan/I:phi/D:x/D:y/D:PadX/D:PadY/D:PadR/D:PadPhi/D",',');
102  R2->ReadFile("/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R2-RevA-Pads.sch.ChannelMapping.csv",
103  "Entry/I:Radius/I:Pad/I:U/I:G/I:Pin/C:PinColID/I:PinRowID/I:PadName/C:FEE/F:FEE_Connector/C:FEE_Chan/I:phi/D:x/D:y/D:PadX/D:PadY/D:PadR/D:PadPhi/D",',');
104  R3->ReadFile("/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R3-RevA.sch.ChannelMapping.csv",
105  "Entry/I:Radius/I:Pad/I:U/I:G/I:Pin/C:PinColID/I:PinRowID/I:PadName/C:FEE/F:FEE_Connector/C:FEE_Chan/I:phi/D:x/D:y/D:PadX/D:PadY/D:PadR/D:PadPhi/D",',');
106 
107  bool firstClus = true;
108 
109  for (int q = 0; q < 24; q++)
110  {
111  cout << "Processing sector " << q << endl;
112 
113  string sectorNumber;
114  if (q < 10) sectorNumber = "0"+std::to_string(q);
115  else sectorNumber = std::to_string(q);
116 
117  string fileName = indir+"TPC_ebdc"+sectorNumber+"_"+runName+"-0000.prdf_TPCRawDataTree.root";
118 
119  TFile *TPCFile = TFile::Open(fileName.c_str());
120  TTreeReader myReader("SampleTree", TPCFile);
121 
122  TTreeReaderValue<Int_t> nSamples(myReader, "nSamples");
123  TTreeReaderValue<Int_t> fee(myReader, "fee");
124  TTreeReaderArray<UShort_t> adcSamples(myReader, "adcSamples");
125  TTreeReaderValue<Int_t> Channel(myReader, "Channel");
126 
127  while(myReader.Next())
128  {
129  int mod_arr[26]={2,2,1,1,1,3,3,3,3,3,3,2,2,1,2,2,1,1,2,2,3,3,3,3,3,3};
130 
131  if (*nSamples <= 1) continue;
132 
133  float adcMax = 0;
134  float adcMaxPos = 0;
135  for(int adc_sam_no=0;adc_sam_no<*nSamples;adc_sam_no++)
136  {
137  if (adc_sam_no == 0)
138  {
139  adcMax = adcSamples[adc_sam_no];
140  adcMaxPos = adc_sam_no;
141  }
142  else
143  {
144  if (adcSamples[adc_sam_no] > adcMax)
145  {
146  adcMax = adcSamples[adc_sam_no];
147  adcMaxPos = adc_sam_no;
148  }
149  }
150  }
151  if (adcMax > adcCut)
152  {
153  double zPos;
154  if (q < 12)
155  {
156  zPos = 105. - (adcMaxPos/((double)*nSamples-1.))*105.;
157  }
158  else
159  {
160  zPos = -105. + (adcMaxPos/((double)*nSamples-1.))*105.;
161  }
162  TVector3 binXYZ = getBinPosition(q,*fee,*Channel,zPos,R1,R2,R3);
163 
164  TVector3 zeroVec;
165  zeroVec.SetX(0);zeroVec.SetY(0);zeroVec.SetZ(0);
166  if (binXYZ == zeroVec) continue;
167 
168  stringstream spts;
169 
170  if (firstClus) firstClus = false;
171  else spts << ",";
172 
173  spts << "{ \"x\": ";
174  spts << binXYZ.x();
175  spts << ", \"y\": ";
176  spts << binXYZ.y();
177  spts << ", \"z\": ";
178  spts << binXYZ.z();
179  spts << ", \"e\": ";
180  spts << adcMax;
181  spts << "}";
182 
183  outdata << (boost::format("%1%") % spts.str());
184  spts.clear();
185  spts.str("");
186  }
187  }
188  }
189  outdata << "],\n \"JETS\": [\n ]\n }," << endl;
190  outdata << "\"TRACKS\": {" << endl;
191  outdata <<"\""<<"INNERTRACKER"<<"\": [";
192  outdata << "]" << endl;
193  outdata << "}" << endl;
194  outdata << "}" << endl;
195 
196  outdata.close();
197 }