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_BCO",
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\", \"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};
131 float pads_per_sector[3] = {96, 128, 192};
135 ULong64_t BCOVal =128434038131;
137 for (
int q = 0; q < 24; q++)
140 cout <<
"Processing sector " << q << endl;
148 string fileName = indir+
"TPC_ebdc"+sectorNumber+
"_"+runName+
"-0001.prdf_test.root";
150 TFile *TPCFile = TFile::Open(fileName.c_str());
151 TTree *sampleTree = (TTree*)TPCFile->Get(
"SampleTree");
152 TTree *taggerTree = (TTree*)TPCFile->Get(
"TaggerTree");
154 Int_t nSamples, fee, Channel, frame, packet, checksumError, taggerFrame;
157 UShort_t adcSamples[5000];
158 sampleTree->SetBranchAddress(
"nSamples",&nSamples);
159 sampleTree->SetBranchAddress(
"fee",&fee);
160 sampleTree->SetBranchAddress(
"adcSamples",&adcSamples);
161 sampleTree->SetBranchAddress(
"Channel",&Channel);
163 sampleTree->SetBranchAddress(
"frame",&frame);
164 sampleTree->SetBranchAddress(
"checksumError",&checksumError);
165 sampleTree->SetBranchAddress(
"xPos",&xPos);
166 sampleTree->SetBranchAddress(
"yPos",&yPos);
168 taggerTree->SetBranchAddress(
"bco",&BCO);
169 taggerTree->SetBranchAddress(
"packet",&packet);
170 taggerTree->SetBranchAddress(
"frame",&taggerFrame);
172 double channelMean[26][256];
173 double channelSigma[26][256];
174 double channelSamples[26][256];
175 int nHitsChannel[26][256];
177 for(
int fee_no=0;fee_no<26;fee_no++)
179 for(
int channel_no=0;channel_no<256;channel_no++)
181 channelMean[fee_no][channel_no] = 0.;
182 channelSigma[fee_no][channel_no] = 0.;
183 channelSamples[fee_no][channel_no] = 0.;
184 nHitsChannel[fee_no][channel_no] = 0;
202 std::vector<int> frameValsToCheck;
204 for(
int i = 0;
i < taggerTree->GetEntries();
i++)
206 taggerTree->GetEntry(
i);
207 if ((BCO < BCOVal + 5) && (BCO > BCOVal - 5))
210 cout <<
"Sector "<<q<<
" found packet = "<<packet<<
" taggerFrame = "<<taggerFrame<<
" with BCO = "<<BCO<<endl;
211 frameValsToCheck.push_back(taggerFrame);
215 for(
int i = 0;
i < sampleTree->GetEntries();
i++)
217 sampleTree->GetEntry(
i);
218 if (checksumError == 0)
220 for(
int adc_sam_no=0;adc_sam_no<10;adc_sam_no++)
222 channelSamples[fee][Channel] += 1.;
223 channelMean[fee][Channel] += adcSamples[adc_sam_no];
224 channelSigma[fee][Channel] += pow(adcSamples[adc_sam_no],2);
229 for(
int fee_no=0;fee_no<26;fee_no++)
231 for(
int channel_no=0;channel_no<256;channel_no++)
233 double temp1 = channelMean[fee_no][channel_no]/channelSamples[fee_no][channel_no];
234 double temp2 = channelSigma[fee_no][channel_no]/channelSamples[fee_no][channel_no];
235 channelMean[fee_no][channel_no] = temp1;
236 channelSigma[fee_no][channel_no] = sqrt(temp2 - pow(temp1,2));
241 for(
int i = 0;
i < sampleTree->GetEntries();
i++)
243 sampleTree->GetEntry(
i);
245 bool recordHits =
false;
246 for (
auto & vals : frameValsToCheck)
248 if (frame < vals + 2 && frame > vals - 1)
255 if (checksumError == 0 && channelMean[fee][Channel] > 20. && channelMean[fee][Channel] < 200.)
257 for(
int adc_sam_no=0;adc_sam_no<nSamples;adc_sam_no++)
259 if ((adcSamples[adc_sam_no] - channelMean[fee][Channel] > channelSigma[fee][Channel]*4) && (adcSamples[adc_sam_no] - channelMean[fee][Channel] > adcCut))
261 nHitsChannel[fee][Channel] += 1;
268 int sample_count = 0;
269 for(
int i = 0;
i < sampleTree->GetEntries();
i++)
271 sampleTree->GetEntry(
i);
275 if (nHitsChannel[fee][Channel] > 50)
continue;
277 if (nSamples <= 1)
continue;
278 bool recordHits =
false;
279 for (
auto & vals : frameValsToCheck)
281 if (frame < vals + 2 && frame > vals - 1)
287 if (!recordHits)
continue;
292 if (checksumError == 0 && channelMean[fee][Channel] > 20. && channelMean[fee][Channel] < 200.)
294 for(
int adc_sam_no=0;adc_sam_no<nSamples;adc_sam_no++)
296 if ((adcSamples[adc_sam_no] - channelMean[fee][Channel] > channelSigma[fee][Channel]*5) && (adcSamples[adc_sam_no] - channelMean[fee][Channel] > adcCut))
298 adcMinusPedestal = adcSamples[adc_sam_no] - channelMean[fee][Channel];
302 zPos = 105. - (105./230.)*((
double)adc_sam_no - 10.);
309 zPos = -105. + (105./230.)*((
double)adc_sam_no - 10.);
315 int feeM = FEE_map[fee];
316 if(mod_arr[fee]==2) feeM += 6;
317 else if(mod_arr[fee]==3) feeM += 14;
319 pad = M.
getPad(feeM, Channel) + (phiElement)*pads_per_sector[mod_arr[fee]-1];
324 double R = M.
getR(feeM, Channel);
325 double phi = (sectorNum<12? -M.
getPhi(feeM, Channel) : M.
getPhi(feeM, Channel) ) + (sectorNum - side*12. )* M_PI / 6. ;
336 timeBin = adc_sam_no;
341 if (firstClus) firstClus =
false;
351 spts << adcMinusPedestal;
363 cout <<
"sample_count = "<<sample_count<<endl;
367 outdata <<
"],\n \"JETS\": [\n ]\n }," << endl;
368 outdata <<
"\"TRACKS\": {" << endl;
369 outdata <<
"\""<<
"INNERTRACKER"<<
"\": [";
370 outdata <<
"]" << endl;
371 outdata <<
"}" << endl;
372 outdata <<
"}" << endl;
379 std::cout <<
"Done" << std::endl;