11 #include "TObjString.h"
14 #include "TTreeReader.h"
15 #include "TTreeReaderValue.h"
16 #include "TTreeReaderArray.h"
19 gROOT->SetBatch(kTRUE);
20 std::ofstream outdata;
21 outdata.open(
"noisyChannels.txt");
23 cerr <<
"Error: file could not be opened" << endl;
26 for (
int q = 0; q < 24; q++){
31 string runNumber =
"beam-00026540";
33 string fileName =
"/sphenix/user/jamesj3j3/tpc/sPHENIXProjects/pedestal-run-26540/TPC_ebdc"+sectorNumber+
"_"+runNumber+
"-0000.prdf_TPCRawDataTree_skip100.root";
38 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};
39 int slot_arr[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};
41 TFile *truthInput = TFile::Open(fileName.c_str());
42 TTreeReader myReader(
"SampleTree", truthInput);
44 TTreeReaderValue<Int_t> nSamples_in(myReader,
"nSamples");
45 TTreeReaderValue<Int_t> fee_in(myReader,
"fee");
46 TTreeReaderArray<UShort_t> adcSamples_in(myReader,
"adcSamples");
47 TTreeReaderValue<Int_t> Channel_in(myReader,
"Channel");
50 TString* outputfilename=
new TString(
"/sphenix/user/jamesj3j3/tpc/sPHENIXProjects/pedestal-run-26540/outputfile_TPC_ebdc"+sectorNumber+
"_"+runNumber+
"_skip100.root");
51 TFile* outputfile=
new TFile(outputfilename->Data(),
"recreate");
52 TTree* outputTree=
new TTree(
"outputTree",
"outputTree");
60 outputTree->Branch(
"isAlive",&isAlive,
"isAlive/I");
61 outputTree->Branch(
"pedMean",&pedMean,
"pedMean/F");
62 outputTree->Branch(
"pedStdi",&pedStdi,
"pedStdi/F");
63 outputTree->Branch(
"chan",&chan,
"chan/I");
64 outputTree->Branch(
"fee",&fee,
"fee/I");
65 outputTree->Branch(
"module",&module,
"module/I");
66 outputTree->Branch(
"slot",&slot,
"slot/I");
70 string dChan =
"Dead Channels (Sector "+sectorNumber+
", Run "+runNumber+
");Channel Number + 256*FEE Number;Instances";
73 TH1F *dead_channel =
new TH1F(
"dead_channel",dChan.c_str(),256*26,-0.5,255.5+256*25);
76 std::vector<float> channels;
78 std::vector<float> std_data;
80 Float_t ave_adc_fee_channel[26][256];
81 Float_t std_adc_fee_channel[26][256];
82 Float_t counts_adc_fee_channel[26][256];
83 Int_t alive_array_fee_channel[26][256];
84 for(
int fee_no=0;fee_no<26;fee_no++){
85 for(
int channel_no=0;channel_no<256;channel_no++)
87 ave_adc_fee_channel[fee_no][channel_no]=0.0;
88 std_adc_fee_channel[fee_no][channel_no]=0.0;
89 counts_adc_fee_channel[fee_no][channel_no]=0.0;
90 alive_array_fee_channel[fee_no][channel_no]=1;
95 while(myReader.Next())
100 dead_channel->Fill(*Channel_in+ 256*(*fee_in));
101 alive_array_fee_channel[*fee_in][*Channel_in]=0;
106 for(
int adc_sam_no=0;adc_sam_no<*nSamples_in;adc_sam_no++){
108 if (adcSamples_in[adc_sam_no] == 0 || TMath::IsNaN(
float(adcSamples_in[adc_sam_no]))) {
109 dead_channel->Fill(*Channel_in+ 256*(*fee_in));dead=
true;
break;
110 alive_array_fee_channel[*fee_in][*Channel_in]=0;
113 if (dead) {
continue;}
115 for(
int adc_sam_no=0;adc_sam_no<*nSamples_in;adc_sam_no++){
116 ave_adc_fee_channel[*fee_in][*Channel_in]+=adcSamples_in[adc_sam_no];
117 std_adc_fee_channel[*fee_in][*Channel_in]+=pow(adcSamples_in[adc_sam_no],2);
118 counts_adc_fee_channel[*fee_in][*Channel_in]+=1.0;
123 for(
int fee_no=0;fee_no<26;fee_no++){
124 for(
int channel_no=0;channel_no<256;channel_no++){
125 if(counts_adc_fee_channel[fee_no][channel_no] != 0.0)
127 float temp1 = ave_adc_fee_channel[fee_no][channel_no]/counts_adc_fee_channel[fee_no][channel_no];
128 float temp2 = std_adc_fee_channel[fee_no][channel_no]/counts_adc_fee_channel[fee_no][channel_no];
129 ave_adc_fee_channel[fee_no][channel_no] = temp1;
130 std_adc_fee_channel[fee_no][channel_no] = temp2;
134 dead_channel->Fill(channel_no+ 256*(fee_no));
136 ave_adc_fee_channel[fee_no][channel_no] = 0.0;
137 std_adc_fee_channel[fee_no][channel_no] = 0.0;
138 alive_array_fee_channel[fee_no][channel_no]=0;
141 if(sqrt(std_adc_fee_channel[fee_no][channel_no] - pow(ave_adc_fee_channel[fee_no][channel_no],2)) > 4)
143 outdata <<
"Sector " << q <<
", FEE " << fee_no <<
", Channel " << channel_no << std::endl;
145 if(ave_adc_fee_channel[fee_no][channel_no] > 200)
147 dead_channel->Fill(channel_no+ 256*(fee_no));
148 std::cout <<
"(Large Pedestal pedestal>200) FEE: " << fee_no <<
", channel: " << channel_no <<
", " << ave_adc_fee_channel[fee_no][channel_no] << std::endl;
149 alive_array_fee_channel[fee_no][channel_no]=0;
151 else if(ave_adc_fee_channel[fee_no][channel_no] < 10)
153 dead_channel->Fill(channel_no+ 256*(fee_no));
154 std::cout <<
"(Small Pedestal pedestal<10) FEE: " << fee_no <<
", channel: " << channel_no <<
", " << ave_adc_fee_channel[fee_no][channel_no] << std::endl;
155 alive_array_fee_channel[fee_no][channel_no]=0;
157 channels.push_back(channel_no+256.*(fee_no));
158 pedestal.push_back(ave_adc_fee_channel[fee_no][channel_no]);
159 std_data.push_back(sqrt(std_adc_fee_channel[fee_no][channel_no] - pow(ave_adc_fee_channel[fee_no][channel_no],2)));
163 pedMean=ave_adc_fee_channel[fee_no][channel_no];
164 pedStdi=sqrt(std_adc_fee_channel[fee_no][channel_no] - pow(ave_adc_fee_channel[fee_no][channel_no],2));
165 isAlive=alive_array_fee_channel[fee_no][channel_no];
169 module=mod_arr[fee_no];
170 slot=slot_arr[fee_no];
181 TGraph *ave_adc =
new TGraph(256*26,channels.data(),pedestal.data());
182 TGraph *rms_adc =
new TGraph(256*26,channels.data(),std_data.data());
184 TCanvas *c1 =
new TCanvas(
"c1",
"c1",2000,1200);
187 auto tl =
new TLine();
tl->SetLineColor(kRed);
188 dead_channel->Draw();
189 for (
int k = 0;
k < 26;
k++)
191 tl->DrawLine(256*(
k+1),0,256*(
k+1),dead_channel->GetMaximum());
192 TLatex *
pt =
new TLatex(25+
k*256,dead_channel->GetMaximum()*5/6,
std::to_string(
k).c_str());
193 pt->SetTextSize(0.04);
203 ave_adc->SetTitle(
"Mean Pedestal Value;Channel Number + 256*FEE Number;Mean Pedestal ADC");
204 ave_adc->SetMarkerStyle(20);
205 ave_adc->SetMarkerColor(kBlue);
206 ave_adc->SetMarkerSize(0.25);
207 ave_adc->GetXaxis()->SetRangeUser(0,256*26);
208 ave_adc->GetYaxis()->SetRangeUser(0,150);
210 for (
int k = 0;
k < 26;
k++)
212 tl->DrawLine(256*(
k+1),0,256*(
k+1),150);
214 pt->SetTextSize(0.04);
226 rms_adc->SetTitle(
"Pedestal Standard Deviation;Channel Number + 256*FEE Number;Pedestal Standard Deviation");
227 rms_adc->SetMarkerStyle(20);
228 rms_adc->SetMarkerColor(kBlue);
229 rms_adc->SetMarkerSize(0.25);
230 rms_adc->GetXaxis()->SetRangeUser(0,256*26);
231 rms_adc->GetYaxis()->SetRangeUser(0,15);
233 for (
int k = 0;
k < 26;
k++)
235 tl->DrawLine(256*(
k+1),0,256*(
k+1),15);
237 pt->SetTextSize(0.04);
247 string saveName =
"images/S"+sectorNumber+
"-"+runNumber+
".png";
248 c1->SaveAs(saveName.c_str());