11 #include "TObjString.h"
14 #include "TTreeReader.h"
15 #include "TTreeReaderValue.h"
16 #include "TTreeReaderArray.h"
21 #include <boost/format.hpp>
22 #include <boost/math/special_functions/sign.hpp>
24 R__LOAD_LIBRARY(libtpc.so)
32 const
string &
outfile = "TPCEventDisplay_25926_100frame_test",
33 const
string &indir = "./",
34 const
string &runName = "cosmics-00025926",
35 const
bool writeAllHits =
true){
38 TString* outputfilename=
new TString(
outfile+
".root");
39 TFile* outputfile=
new TFile(outputfilename->Data(),
"recreate");
40 TTree* hitTree=
new TTree(
"hitTree",
"x,y,z position and max ADC value for all samples passing cut");
41 double x_Pos, y_Pos, z_Pos, frameVal;
42 int adcMinusPedestal, sectorNum,
layer, side, phiElement, timeBin, pad;
43 hitTree->Branch(
"x_Pos",&x_Pos,
"x_Pos/D");
44 hitTree->Branch(
"y_Pos",&y_Pos,
"y_Pos/D");
45 hitTree->Branch(
"z_Pos",&z_Pos,
"z_Pos/D");
46 hitTree->Branch(
"frameVal",&frameVal,
"frameVal/D");
47 hitTree->Branch(
"adcMinusPedestal",&adcMinusPedestal,
"adcMinusPedestal/I");
48 hitTree->Branch(
"sectorNum",§orNum,
"sectorNum/I");
49 hitTree->Branch(
"layer",&layer,
"layer/I");
50 hitTree->Branch(
"side",&side,
"side/I");
51 hitTree->Branch(
"phiElement",&phiElement,
"phiElement/I");
52 hitTree->Branch(
"timeBin",&timeBin,
"timeBin/I");
53 hitTree->Branch(
"pad",&pad,
"pad/I");
55 std::ofstream outdata;
56 outdata.open((
outfile+
".json").c_str());
58 cerr <<
"ERROR: file could not be opened" << endl;
62 string runNumberString = runName;
63 size_t pos = runNumberString.find(
"000");
64 runNumberString.erase(runNumberString.begin(),runNumberString.begin()+pos+3);
66 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 \"runstats\": [ \n \"sPHENIX Time Projection Chamber\", \"2023-08-23, Run 25926 - All EBDCs, 100 frames\", \"Cosmics Data\"] \n },\n" << endl;
68 outdata <<
" \"META\": {\n \"HITS\": {\n \"INNERTRACKER\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 2,\n \"color\": 16777215\n } \n },\n" << endl;
69 outdata <<
" \"TRACKHITS\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 2,\n \"transparent\": 0.5,\n \"color\": 16777215\n } \n },\n" << endl;
70 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;
71 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;
72 outdata <<
" \"TRACKHITS\": [\n\n ";
74 bool firstClus =
true;
95 M.
setMapNames(
"AutoPad-R1-RevA.sch.ChannelMapping.csv",
"AutoPad-R2-RevA-Pads.sch.ChannelMapping.csv",
"AutoPad-R3-RevA.sch.ChannelMapping.csv");
97 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 float pads_per_sector[3] = {96, 128, 192};
134 for (
int q = 0; q < 24; q++)
137 cout <<
"Processing sector " << q << endl;
145 string fileName = indir+
"TPC_ebdc"+sectorNumber+
"_"+runName+
"-0000.prdf_test.root";
147 TFile *TPCFile = TFile::Open(fileName.c_str());
148 TTree *sampleTree = (TTree*)TPCFile->Get(
"SampleTree");
149 TTree *taggerTree = (TTree*)TPCFile->Get(
"TaggerTree");
151 Int_t nSamples, fee, Channel, frame, checksumError, taggerFrame;
154 UShort_t adcSamples[5000];
155 sampleTree->SetBranchAddress(
"nSamples",&nSamples);
156 sampleTree->SetBranchAddress(
"fee",&fee);
157 sampleTree->SetBranchAddress(
"adcSamples",&adcSamples);
158 sampleTree->SetBranchAddress(
"Channel",&Channel);
160 sampleTree->SetBranchAddress(
"frame",&frame);
161 sampleTree->SetBranchAddress(
"checksumError",&checksumError);
162 sampleTree->SetBranchAddress(
"xPos",&xPos);
163 sampleTree->SetBranchAddress(
"yPos",&yPos);
165 taggerTree->SetBranchAddress(
"bco",&BCO);
166 taggerTree->SetBranchAddress(
"frame",&taggerFrame);
168 double channelMean[26][256];
169 double channelSigma[26][256];
170 double channelSamples[26][256];
171 int nHitsChannel[26][256];
173 for(
int fee_no=0;fee_no<26;fee_no++)
175 for(
int channel_no=0;channel_no<256;channel_no++)
177 channelMean[fee_no][channel_no] = 0.;
178 channelSigma[fee_no][channel_no] = 0.;
179 channelSamples[fee_no][channel_no] = 0.;
180 nHitsChannel[fee_no][channel_no] = 0;
198 std::vector<int> frameValsToCheck;
200 for(
int i = 0;
i < taggerTree->GetEntries();
i++)
202 taggerTree->GetEntry(
i);
210 for(
int i = 0;
i < sampleTree->GetEntries();
i++)
212 sampleTree->GetEntry(
i);
213 if (checksumError == 0)
215 for(
int adc_sam_no=0;adc_sam_no<10;adc_sam_no++)
217 channelSamples[fee][Channel] += 1.;
218 channelMean[fee][Channel] += adcSamples[adc_sam_no];
219 channelSigma[fee][Channel] += pow(adcSamples[adc_sam_no],2);
224 for(
int fee_no=0;fee_no<26;fee_no++)
226 for(
int channel_no=0;channel_no<256;channel_no++)
228 double temp1 = channelMean[fee_no][channel_no]/channelSamples[fee_no][channel_no];
229 double temp2 = channelSigma[fee_no][channel_no]/channelSamples[fee_no][channel_no];
230 channelMean[fee_no][channel_no] = temp1;
231 channelSigma[fee_no][channel_no] = sqrt(temp2 - pow(temp1,2));
236 for(
int i = 0;
i < sampleTree->GetEntries();
i++)
238 sampleTree->GetEntry(
i);
240 bool recordHits =
false;
241 for (
auto & vals : frameValsToCheck)
243 if (frame < vals + 2 && frame > vals - 1)
250 if (checksumError == 0 && channelMean[fee][Channel] > 20. && channelMean[fee][Channel] < 200.)
252 for(
int adc_sam_no=0;adc_sam_no<nSamples;adc_sam_no++)
254 if ((adcSamples[adc_sam_no] - channelMean[fee][Channel] > channelSigma[fee][Channel]*4) && (adcSamples[adc_sam_no] - channelMean[fee][Channel] > adcCut))
256 nHitsChannel[fee][Channel] += 1;
263 for(
int i = 0;
i < sampleTree->GetEntries();
i++)
265 sampleTree->GetEntry(
i);
269 if (nHitsChannel[fee][Channel] > 50)
continue;
271 if (nSamples <= 1)
continue;
272 bool recordHits =
false;
273 for (
auto & vals : frameValsToCheck)
275 if (frame < vals + 2 && frame > vals - 1)
285 if (checksumError == 0 && channelMean[fee][Channel] > 20. && channelMean[fee][Channel] < 200.)
287 for(
int adc_sam_no=0;adc_sam_no<nSamples;adc_sam_no++)
289 if ((adcSamples[adc_sam_no] - channelMean[fee][Channel] > channelSigma[fee][Channel]*5) && (adcSamples[adc_sam_no] - channelMean[fee][Channel] > adcCut))
291 adcMinusPedestal = adcSamples[adc_sam_no] - channelMean[fee][Channel];
295 zPos = 105. - (105./230.)*((
double)adc_sam_no - 10.);
302 zPos = -105. + (105./230.)*((
double)adc_sam_no - 10.);
308 int feeM = FEE_map[fee];
309 if(mod_arr[fee]==2) feeM += 6;
310 else if(mod_arr[fee]==3) feeM += 14;
312 pad = M.
getPad(feeM, Channel) + (phiElement)*pads_per_sector[mod_arr[fee]-1];
317 double R = M.
getR(feeM, Channel);
318 double phi = (sectorNum<12? -M.
getPhi(feeM, Channel) : M.
getPhi(feeM, Channel) ) + (sectorNum - side*12. )* M_PI / 6. ;
329 timeBin = adc_sam_no;
334 if (firstClus) firstClus =
false;
344 spts << adcMinusPedestal;
356 outdata <<
"],\n \"JETS\": [\n ]\n }," << endl;
357 outdata <<
"\"TRACKS\": {" << endl;
358 outdata <<
"\""<<
"INNERTRACKER"<<
"\": [";
359 outdata <<
"]" << endl;
360 outdata <<
"}" << endl;
361 outdata <<
"}" << endl;
368 std::cout <<
"Done" << std::endl;