11 #include "TObjString.h"
14 #include "TTreeReader.h"
15 #include "TTreeReaderValue.h"
16 #include "TTreeReaderArray.h"
19 #include <boost/format.hpp>
20 #include <boost/math/special_functions/sign.hpp>
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)
35 myReader =
new TTreeReader(R1);
37 else if (mod_arr[inFee] == 2)
39 myReader =
new TTreeReader(R2);
41 else if (mod_arr[inFee] == 3)
43 myReader =
new TTreeReader(R3);
45 TTreeReaderValue<Float_t> FEE(*myReader,
"FEE");
46 TTreeReaderValue<Int_t> FEE_Chan(*myReader,
"FEE_Chan");
49 TTreeReaderValue<Double_t>
phi(*myReader,
"phi");
52 TTreeReaderValue<Double_t> PadR(*myReader,
"PadR");
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;
59 while(myReader->Next())
61 if (slot[inFee]-1 == *FEE && channel == *FEE_Chan)
63 double x = (*PadR/10)*std::cos(*phi+phiOffset);
64 double y = (*PadR/10)*std::sin(*phi+phiOffset);
66 pos.SetX(x); pos.SetY(y);
71 pos.SetX(0); pos.SetY(0);
77 const string &
outfile =
"/sphenix/user/rosstom/test/TPCEventDisplay_10684",
78 const string &indir =
"/sphenix/user/rosstom/test/testFiles/",
79 const string &runName =
"beam-00010684",
80 const bool writeAllHits =
true){
83 TString* outputfilename=
new TString(
outfile+
".root");
84 TFile* outputfile=
new TFile(outputfilename->Data(),
"recreate");
85 TTree* hitTree=
new TTree(
"hitTree",
"x,y,z position and max ADC value for all samples passing cut");
86 double x_Pos, y_Pos, z_Pos;
88 hitTree->Branch(
"x_Pos",&x_Pos,
"x_Pos/D");
89 hitTree->Branch(
"y_Pos",&y_Pos,
"y_Pos/D");
90 hitTree->Branch(
"z_Pos",&z_Pos,
"z_Pos/D");
91 hitTree->Branch(
"max_adc",&max_adc,
"max_adc/I");
93 std::ofstream outdata;
94 outdata.open((
outfile+
".json").c_str());
96 cerr <<
"ERROR: file could not be opened" << endl;
100 string runNumberString = runName;
101 size_t pos = runNumberString.find(
"000");
102 runNumberString.erase(runNumberString.begin(),runNumberString.begin()+pos+3);
104 outdata <<
"{\n \"EVENT\": {\n \"runid\":" << runNumberString <<
", \n \"evtid\": 1, \n \"time\": 0, \n \"timeStr\": \"2023-05-30, 15:23:30 EST\", \n \"type\": \"Cosmics\", \n \"s_nn\": 0, \n \"B\": 0.0,\n \"pv\": [0,0,0] \n },\n" << endl;
106 outdata <<
" \"META\": {\n \"HITS\": {\n \"INNERTRACKER\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 5,\n \"color\": 16777215\n } \n },\n" << endl;
107 outdata <<
" \"TRACKHITS\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 5,\n \"transparent\": 0.5,\n \"color\": 16777215\n } \n },\n" << endl;
108 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;
109 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;
110 outdata <<
" \"TRACKHITS\": [\n\n ";
112 TTree *
R1 =
new TTree(
"R1",
"TPC Sector Mapping for R1");
113 TTree *
R2 =
new TTree(
"R2",
"TPC Sector Mapping for R1");
114 TTree *
R3 =
new TTree(
"R3",
"TPC Sector Mapping for R1");
116 R1->ReadFile(
"/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R1-RevA.sch.ChannelMapping.csv",
117 "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",
',');
118 R2->ReadFile(
"/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R2-RevA-Pads.sch.ChannelMapping.csv",
119 "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",
',');
120 R3->ReadFile(
"/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R3-RevA.sch.ChannelMapping.csv",
121 "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",
',');
123 bool firstClus =
true;
127 for (
int q = 0; q < 24; q++)
129 cout <<
"Processing sector " << q << endl;
135 string fileName = indir+
"TPC_ebdc"+sectorNumber+
"_"+runName+
"-0005.prdf_TPCRawDataTree.root";
137 TFile *TPCFile = TFile::Open(fileName.c_str());
138 TTreeReader myReader(
"SampleTree", TPCFile);
140 TTreeReaderValue<Int_t> nSamples(myReader,
"nSamples");
141 TTreeReaderValue<Int_t> fee(myReader,
"fee");
142 TTreeReaderArray<UShort_t> adcSamples(myReader,
"adcSamples");
143 TTreeReaderValue<Int_t> Channel(myReader,
"Channel");
144 TTreeReaderValue<Int_t>
BCO(myReader,
"BCO");
145 TTreeReaderValue<Int_t> frame(myReader,
"frame");
146 TTreeReaderValue<Int_t> checksumError(myReader,
"checksumError");
148 while(myReader.Next())
152 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};
154 if (*nSamples <= 1)
continue;
158 if (writeAllHits && *checksumError == 0)
160 for(
int adc_sam_no=0;adc_sam_no<*nSamples;adc_sam_no++)
162 if (adcSamples[adc_sam_no] - adcSamples[0] > adcCut)
164 max_adc = adcSamples[adc_sam_no];
168 zPos = 105. - 0.4*(
double)adc_sam_no;
173 zPos = -105. + 0.4*(
double)adc_sam_no;
179 if (binXY.X() == 0 || binXY.Y() == 0)
continue;
189 if (firstClus) firstClus =
false;
210 for(
int adc_sam_no=0;adc_sam_no<*nSamples;adc_sam_no++)
214 adcMax = adcSamples[adc_sam_no];
215 adcMaxPos = adc_sam_no;
219 if (adcSamples[adc_sam_no] > adcMax)
221 adcMax = adcSamples[adc_sam_no];
222 adcMaxPos = adc_sam_no;
232 zPos = 105. - 0.4*(
double)adcMaxPos;
233 if (zPos < 0. || zPos > 105.)
continue;
237 zPos = -105. + 0.4*(
double)adcMaxPos;
238 if (zPos > 0. || zPos < -105.)
continue;
243 if (binXY.X() == 0 || binXY.Y() == 0)
continue;
253 if (firstClus) firstClus =
false;
273 outdata <<
"],\n \"JETS\": [\n ]\n }," << endl;
274 outdata <<
"\"TRACKS\": {" << endl;
275 outdata <<
"\""<<
"INNERTRACKER"<<
"\": [";
276 outdata <<
"]" << endl;
277 outdata <<
"}" << endl;
278 outdata <<
"}" << endl;