11 #include "TObjString.h"
14 #include "TTreeReader.h"
15 #include "TTreeReaderValue.h"
16 #include "TTreeReaderArray.h"
24 void TPCPedestalCalibration(vector<string> inputFiles = {
"/sphenix/user/rosstom/test/testFiles/TPC_ebdc00_pedestal-00010131-0000.prdf_TPCRawDataTree.root"}){
25 for (
int fileNum = 0; fileNum < inputFiles.size(); fileNum++){
26 string sectorNum = inputFiles[fileNum];
27 size_t pos = sectorNum.find(
"ebdc");
28 sectorNum.erase(pos+6);
29 sectorNum.erase(sectorNum.begin(),sectorNum.begin()+pos+4);
31 if (sectorNum.substr(0,1) ==
"0")
33 sectorNum.erase(sectorNum.begin(),sectorNum.end()-1);
34 sector = std::stoi(sectorNum);
36 else sector = std::stoi(sectorNum);
38 Int_t 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_t 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 *pedestalInput = TFile::Open(inputFiles[fileNum].c_str());
42 TTreeReader myReader(
"SampleTree", pedestalInput);
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(
"pedestalCalibration_TPC_ebdc"+sectorNum+
".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(
"pedStd",&pedStd,
"pedStd/F");
63 outputTree->Branch(
"sector",§or,
"sector/I");
64 outputTree->Branch(
"fee",&fee,
"fee/I");
65 outputTree->Branch(
"chan",&chan,
"chan/I");
66 outputTree->Branch(
"module",&module,
"module/I");
67 outputTree->Branch(
"slot",&slot,
"slot/I");
69 Float_t ave_adc_fee_channel[26][256];
70 Float_t std_adc_fee_channel[26][256];
71 Float_t counts_adc_fee_channel[26][256];
72 Int_t alive_array_fee_channel[26][256];
73 for(
int fee_no=0;fee_no<26;fee_no++){
74 for(
int channel_no=0;channel_no<256;channel_no++)
76 ave_adc_fee_channel[fee_no][channel_no]=0.0;
77 std_adc_fee_channel[fee_no][channel_no]=0.0;
78 counts_adc_fee_channel[fee_no][channel_no]=0.0;
79 alive_array_fee_channel[fee_no][channel_no]=1;
83 while(myReader.Next())
87 alive_array_fee_channel[*fee_in][*Channel_in]=0;
92 for(
int adc_sam_no=0;adc_sam_no<*nSamples_in;adc_sam_no++)
94 if (adcSamples_in[adc_sam_no] == 0 || TMath::IsNaN(
float(adcSamples_in[adc_sam_no])))
96 alive_array_fee_channel[*fee_in][*Channel_in]=0;
101 for(
int adc_sam_no=0;adc_sam_no<*nSamples_in;adc_sam_no++){
102 ave_adc_fee_channel[*fee_in][*Channel_in]+=adcSamples_in[adc_sam_no];
103 std_adc_fee_channel[*fee_in][*Channel_in]+=pow(adcSamples_in[adc_sam_no],2);
104 counts_adc_fee_channel[*fee_in][*Channel_in]+=1.0;
109 for(
int fee_no=0;fee_no<26;fee_no++)
111 for(
int channel_no=0;channel_no<256;channel_no++)
113 if(counts_adc_fee_channel[fee_no][channel_no] != 0.0)
115 float temp1 = ave_adc_fee_channel[fee_no][channel_no]/counts_adc_fee_channel[fee_no][channel_no];
116 float temp2 = std_adc_fee_channel[fee_no][channel_no]/counts_adc_fee_channel[fee_no][channel_no];
117 ave_adc_fee_channel[fee_no][channel_no] = temp1;
118 std_adc_fee_channel[fee_no][channel_no] = temp2;
122 ave_adc_fee_channel[fee_no][channel_no] = 0.0;
123 std_adc_fee_channel[fee_no][channel_no] = 0.0;
124 alive_array_fee_channel[fee_no][channel_no]=0;
127 if(ave_adc_fee_channel[fee_no][channel_no] > 200 || ave_adc_fee_channel[fee_no][channel_no] < 10)
129 alive_array_fee_channel[fee_no][channel_no]=0;
132 pedMean=ave_adc_fee_channel[fee_no][channel_no];
133 pedStd=sqrt(std_adc_fee_channel[fee_no][channel_no] - pow(ave_adc_fee_channel[fee_no][channel_no],2));
134 isAlive=alive_array_fee_channel[fee_no][channel_no];
137 module=mod_arr[fee_no];
138 slot=slot_arr[fee_no];
145 pedestalInput->Close();