File indexing completed on 2025-08-05 08:15:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __CINT__
0010 #include <algorithm>
0011 #include <cmath>
0012 #include "TCanvas.h"
0013 #include "TApplication.h"
0014 #include "TH1D.h"
0015 #include "TH1F.h"
0016 #include "TH2D.h"
0017 #include "TH2F.h"
0018 #include "TH3D.h"
0019 #include "TH3F.h"
0020 #include "TString.h"
0021 #include "TStyle.h"
0022 #include "TFile.h"
0023 #include "TGraphPolar.h"
0024 #include "TGraphPolargram.h"
0025 #include "TAxis.h"
0026 #include "TLatex.h"
0027 #include "TLegend.h"
0028 #include "TApplication.h"
0029 #include "TCanvas.h"
0030 #include "TMath.h"
0031 #include "TVirtualFitter.h"
0032 #include "Math/MinimizerOptions.h"
0033 #include "TFitResultPtr.h"
0034 #include "TFitResult.h"
0035 #include "TF1.h"
0036 #include "TPaveLabel.h"
0037 #include <string.h>
0038 #include <vector>
0039 #include <iostream>
0040 #include <RtypesCore.h>
0041 #endif
0042
0043 using namespace std;
0044
0045 void Locate(Int_t id, Bool_t is_ASIDE, Double_t *rbin, Double_t *thbin);
0046
0047
0048 void Noise_ModuleDisplay(){
0049
0050
0051
0052 bool skip_empty_fees = false;
0053
0054 std::vector<pair<int,int>> vec;
0055
0056 char name[100];
0057 int run_num;
0058
0059 cout << "Input run number: ";
0060 cin >> run_num;
0061
0062 const TString filename3( Form( "./pedestal-%d-outfile.root",run_num,run_num) );
0063
0064
0065
0066
0067 TFile *infile3 = TFile::Open(filename3);
0068
0069
0070 if(!infile3) return;
0071
0072 TNtuple * liveTntuple ;
0073 liveTntuple = (TNtuple*) infile3->Get("h_Alive");
0074
0075 TNtuple * totTntuple ;
0076 totTntuple = (TNtuple*) infile3->Get("h_AliveTot");
0077
0078 TH3F * dm2 = new TH3F("dm2","TPC map",26, -0.5, 25.5, 24, -0.5, 23.5, 3, 0.5, 3.5 );
0079 liveTntuple->Draw("module_id:sec_id:fee_id>>dm2","","");
0080
0081 TH3F * h_AlivePedestalNoise = new TH3F("h_AlivePedestalNoise","TPC Alive Pedestal Noise of Std. Dev,",26, -0.5, 25.5, 24, -0.5, 23.5, 3, 0.5, 3.5 );
0082 liveTntuple->Draw("module_id:sec_id:fee_id>>h_AlivePedestalNoise","pedStdi * (pedStdi < 20)","");
0083
0084 TH3F * tot = new TH3F("tot"," TPC Tot Map", 26, -0.5, 25.5, 24, -0.5, 23.5, 3, 0.5, 3.5 );
0085 totTntuple->Draw("module_id:sec_id:fee_id>>tot","","");
0086
0087
0088 dm2->Print();
0089 tot->Print();
0090
0091
0092 std::vector<Float_t> sub_arrA;
0093 std::vector<Float_t> sub_arrC;
0094
0095 Float_t frac[dm2->GetNbinsX()][dm2->GetNbinsY()];
0096 std::vector<Float_t> module_std_dev;
0097
0098 for (Int_t i = 0; i < dm2->GetNbinsY(); i++) {
0099
0100
0101
0102 for (Int_t j = 0; j < dm2->GetNbinsZ(); j++) {
0103
0104 Float_t num=0;
0105 Float_t denom=0;
0106 Float_t sum_noise=0;
0107
0108 for (Int_t k = 0; k < dm2->GetNbinsX(); k++) {
0109
0110 Float_t FEE_noise_sum = 0.0;
0111
0112 if(h_AlivePedestalNoise->GetBinContent(k+1,i+1,j+1) > 0.0){
0113 if( skip_empty_fees){
0114 if( dm2->GetBinContent(k+1,i+1,j+1) >= 1){
0115 num+=dm2->GetBinContent(k+1,i+1,j+1);
0116 denom+=tot->GetBinContent(k+1,i+1,j+1);
0117 sum_noise+=h_AlivePedestalNoise->GetBinContent(k+1,i+1,j+1);
0118 }
0119 }
0120 else {
0121 num+=dm2->GetBinContent(k+1,i+1,j+1);
0122 denom+=tot->GetBinContent(k+1,i+1,j+1);
0123 sum_noise+=h_AlivePedestalNoise->GetBinContent(k+1,i+1,j+1);
0124 }
0125 }
0126 FEE_noise_sum = h_AlivePedestalNoise->GetBinContent(k+1,i+1,j+1);
0127 std::cout << "Sec ID = " << i+1 << ", Module ID = " << j+1 << ", FEE ID = " << k+1 << ", Std. Dev. sum = " << FEE_noise_sum << std::endl;
0128 }
0129
0130 Float_t frac_val= ( num / denom) * 100.0;
0131 Float_t noise_value = sum_noise/num;
0132
0133 frac[i+1][j+1] = frac_val;
0134 std::cout << "Sec ID = " << i+1 << ", Module ID = " << j+1 << ", Live fraction = " << frac_val << "%" << std::endl;
0135 std::cout << "Sec ID = " << i+1 << ", Module ID = " << j+1 << ", Avg. Std. Dev. = " << noise_value << std::endl;
0136 if (i < 12) {
0137 sub_arrC.push_back(noise_value);
0138
0139
0140 }else {
0141 sub_arrA.push_back(noise_value);
0142
0143
0144 }
0145 }
0146 }
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 gStyle->SetOptStat(0);
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203 const Int_t N_rBins = 4;
0204 const Int_t N_thBins = 12;
0205
0206 Double_t rBin_edges[N_rBins + 1] = {0.0, 0.256, 0.504, 0.752, 1.00};
0207
0208 TGraphPolargram* polardummy1 = new TGraphPolargram("polardummy1",0,1,0,2.*TMath::Pi());
0209 polardummy1->SetToGrad();
0210 polardummy1->SetNdivPolar(N_thBins);
0211 polardummy1->SetLineColor(0);
0212 polardummy1->SetRadialLabelSize(0);
0213
0214 TGraphPolargram* polardummy2 = new TGraphPolargram("polardummy2",0,1,0,2.*TMath::Pi());
0215 polardummy2->SetToGrad();
0216 polardummy2->SetNdivPolar( N_thBins);
0217 polardummy2->SetLineColor(0);
0218 polardummy2->SetRadialLabelSize(0);
0219
0220 for(Int_t i = 0 ; i < 12 ; i++){
0221 char labelstr1[128];
0222 char labelstr2[128];
0223 if(i<=9){
0224 sprintf(labelstr2,"C0%d",i);
0225
0226 if(i<=6){
0227 sprintf(labelstr1,"A%d",18-i);
0228 }
0229 else if(i>6){
0230 sprintf(labelstr1,"A%d",30-i);
0231 }
0232
0233 }
0234 else {
0235 sprintf(labelstr2,"C%d",i);
0236 sprintf(labelstr1,"A%d",30-i);
0237 }
0238 polardummy1->SetPolarLabel(i,labelstr1);
0239 polardummy2->SetPolarLabel(i,labelstr2);
0240 }
0241
0242 TH2D* ErrASide = new TH2D( "ASide" , "ADC Counts North Side" , N_thBins, -TMath::Pi()/12. , 23.*TMath::Pi()/12. , N_rBins , rBin_edges );
0243
0244 TH2D* ErrCSide = new TH2D( "CSide" , "ADC Counts South Side" , N_thBins, -TMath::Pi()/12. , 23.*TMath::Pi()/12. , N_rBins , rBin_edges );
0245
0246
0247 Double_t r, theta;
0248 Int_t trip_count_total = 0;
0249 Bool_t is_ASIDE = true;
0250
0251 for (Int_t i = 0; i < 36; i++) {
0252 if(sub_arrA[i] > 0.0){
0253 Locate(i + 1, true, &r, &theta);
0254 ErrASide->Fill(theta, r, sub_arrA[i]);
0255
0256 }
0257 }
0258
0259 for (Int_t i = 0; i < 36; i++) {
0260 if(sub_arrC[i] > 0.0){
0261 Locate(i + 1,false, &r, &theta);
0262 ErrCSide->Fill(theta, r, sub_arrC[i]);
0263
0264 }
0265 }
0266
0267 sprintf(name, "%d-Noise Std. Dev. in ADC (North Side)",run_num);
0268 TH2D* dummy_his1 = new TH2D("dummy1", name, 100, -1.5, 1.5, 100, -1.5, 1.5);
0269
0270 sprintf(name, "%d-Noise Std. Dev. in ADC (South Side)",run_num);
0271 TH2D* dummy_his2 = new TH2D("dummy2", name, 100, -1.5, 1.5, 100, -1.5, 1.5);
0272
0273
0274 TPaveLabel* A00 = new TPaveLabel( 1.046586,-0.1938999,1.407997,0.2144871, "18" );
0275 TPaveLabel* A01 = new TPaveLabel( 0.962076,0.4382608,1.323487,0.8466479 , "17" );
0276 TPaveLabel* A02 = new TPaveLabel( 0.4801947,0.8802139,0.8416056,1.288601 , "16" );
0277 TPaveLabel* A03 = new TPaveLabel( -0.1823921,1.011681,0.1790189,1.425662, "15" );
0278 TPaveLabel* A04 = new TPaveLabel( -0.8449788,0.8690253,-0.4835679,1.288601 , "14" );
0279 TPaveLabel* A05 = new TPaveLabel( -1.30879,0.441058,-0.9473786,0.8550394 , "13" );
0280 TPaveLabel* A06 = new TPaveLabel( -1.411009,-0.2050886,-1.049598,0.2144871, "12" );
0281 TPaveLabel* A07 = new TPaveLabel( -1.302585,-0.7757116,-0.9471979,-0.3561359 , "23" );
0282 TPaveLabel* A08 = new TPaveLabel( -0.8449788,-1.309971,-0.4835679,-0.8848013 , "22" );
0283 TPaveLabel* A09 = new TPaveLabel( -0.1823921,-1.426557,0.1790189,-1.006982 , "21" );
0284 TPaveLabel* A10 = new TPaveLabel( 0.4801947,-1.309076,0.8416056,-0.8839062 , "20" );
0285 TPaveLabel* A11 = new TPaveLabel( 0.9622567,-0.7785088,1.323668,-0.3533387 , "19" );
0286
0287 TPaveLabel* C00 = new TPaveLabel( 1.046586,-0.1938999,1.407997,0.2144871, "00" );
0288 TPaveLabel* C01 = new TPaveLabel( 0.962076,0.4382608,1.323487,0.8466479 , "01" );
0289 TPaveLabel* C02 = new TPaveLabel( 0.4801947,0.8802139,0.8416056,1.288601 , "02" );
0290 TPaveLabel* C03 = new TPaveLabel( -0.1823921,1.011681,0.1790189,1.425662, "03" );
0291 TPaveLabel* C04 = new TPaveLabel( -0.8449788,0.8690253,-0.4835679,1.288601 , "04" );
0292 TPaveLabel* C05 = new TPaveLabel( -1.30879,0.441058,-0.9473786,0.8550394 , "05" );
0293 TPaveLabel* C06 = new TPaveLabel( -1.411009,-0.2050886,-1.049598,0.2144871, "06" );
0294 TPaveLabel* C07 = new TPaveLabel( -1.302585,-0.7757116,-0.9471979,-0.3561359 , "07" );
0295 TPaveLabel* C08 = new TPaveLabel( -0.8449788,-1.309971,-0.4835679,-0.8848013 , "08" );
0296 TPaveLabel* C09 = new TPaveLabel( -0.1823921,-1.426557,0.1790189,-1.006982 , "09" );
0297 TPaveLabel* C10 = new TPaveLabel( 0.4801947,-1.309076,0.8416056,-0.8839062 , "10" );
0298 TPaveLabel* C11 = new TPaveLabel( 0.9622567,-0.7785088,1.323668,-0.3533387 , "11" );
0299
0300 A00->SetFillColor(0);
0301 A01->SetFillColor(0);
0302 A02->SetFillColor(0);
0303 A03->SetFillColor(0);
0304 A04->SetFillColor(0);
0305 A05->SetFillColor(0);
0306 A06->SetFillColor(0);
0307 A07->SetFillColor(0);
0308 A08->SetFillColor(0);
0309 A09->SetFillColor(0);
0310 A10->SetFillColor(0);
0311 A11->SetFillColor(0);
0312
0313 C00->SetFillColor(0);
0314 C01->SetFillColor(0);
0315 C02->SetFillColor(0);
0316 C03->SetFillColor(0);
0317 C04->SetFillColor(0);
0318 C05->SetFillColor(0);
0319 C06->SetFillColor(0);
0320 C07->SetFillColor(0);
0321 C08->SetFillColor(0);
0322 C09->SetFillColor(0);
0323 C10->SetFillColor(0);
0324 C11->SetFillColor(0);
0325
0326 gStyle->SetPalette(kBird);
0327
0328 TCanvas *Error_Viz = new TCanvas("Error_Viz", "Error_Viz", 1248, 598);
0329 Error_Viz->Divide(2,1);
0330 Error_Viz->cd(1);
0331 dummy_his1->Draw("");
0332
0333 ErrCSide->Draw("colpolzsame0");
0334 C00->Draw("same");
0335 C01->Draw("same");
0336 C02->Draw("same");
0337 C03->Draw("same");
0338 C04->Draw("same");
0339 C05->Draw("same");
0340 C06->Draw("same");
0341 C07->Draw("same");
0342 C08->Draw("same");
0343 C09->Draw("same");
0344 C10->Draw("same");
0345 C11->Draw("same");
0346 Error_Viz->cd(2);
0347 dummy_his2->Draw("");
0348
0349 ErrASide->Draw("colpolzsame0");
0350 A00->Draw("same");
0351 A01->Draw("same");
0352 A02->Draw("same");
0353 A03->Draw("same");
0354 A04->Draw("same");
0355 A05->Draw("same");
0356 A06->Draw("same");
0357 A07->Draw("same");
0358 A08->Draw("same");
0359 A09->Draw("same");
0360 A10->Draw("same");
0361 A11->Draw("same");
0362
0363 ErrCSide->SetMaximum(4);
0364 ErrASide->SetMaximum(4);
0365
0366 ErrCSide->SetMinimum(0);
0367 ErrASide->SetMinimum(0);
0368
0369
0370
0371
0372 Double_t Maxval = TMath::Max(ErrASide->GetBinContent(ErrASide->GetMaximumBin()),ErrCSide->GetBinContent(ErrCSide->GetMaximumBin()));
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387 TFile *outf = new TFile("Trip_Histos.root","RECREATE");
0388 Error_Viz->Write();
0389
0390
0391
0392
0393
0394 sprintf(name,"/sphenix/user/llegnosky/run_%d/run_%d_Noise.png",run_num,run_num);
0395 Error_Viz->Print(name);
0396
0397 outf->Write();
0398 }
0399
0400 void Locate(Int_t id, Bool_t is_ASIDE, Double_t *rbin, Double_t *thbin) {
0401
0402 Double_t ASIDE_angle_bins[12] = { 0.1*2.*TMath::Pi()/12 , 1.1*2.*TMath::Pi()/12 , 2.1*2.*TMath::Pi()/12 , 3.1*2.*TMath::Pi()/12 , 4.1*2.*TMath::Pi()/12 , 5.1*2.*TMath::Pi()/12 , 6.1*2.*TMath::Pi()/12 , 7.1*2.*TMath::Pi()/12 , 8.1*2.*TMath::Pi()/12 , 9.1*2.*TMath::Pi()/12 , 10.1*2.*TMath::Pi()/12 , 11.1*2.*TMath::Pi()/12 };
0403
0404
0405
0406 Double_t CSIDE_angle_bins[12] = { 6.1*2.*TMath::Pi()/12 , 5.1*2.*TMath::Pi()/12 , 4.1*2.*TMath::Pi()/12 , 3.1*2.*TMath::Pi()/12 , 2.1*2.*TMath::Pi()/12 , 1.1*2.*TMath::Pi()/12 , 0.1*2.*TMath::Pi()/12 , 11.1*2.*TMath::Pi()/12 , 10.1*2.*TMath::Pi()/12 , 9.1*2.*TMath::Pi()/12 , 8.1*2.*TMath::Pi()/12 , 7.1*2.*TMath::Pi()/12 };
0407
0408
0409
0410 Int_t modid3 = id % 3;
0411
0412 switch(modid3) {
0413 case 1:
0414 *rbin = 0.4;
0415 break;
0416 case 2:
0417 *rbin = 0.6;
0418 break;
0419 case 0:
0420 *rbin = 0.8;
0421 break;
0422 }
0423
0424
0425 if( is_ASIDE ){
0426 *thbin = CSIDE_angle_bins[TMath::FloorNint((id-1)/3)];
0427 }
0428 else{
0429 *thbin = ASIDE_angle_bins[TMath::FloorNint((id-1)/3)];
0430 }
0431
0432 }