File indexing completed on 2025-08-06 08:13:55
0001 #pragma once
0002
0003 #include <utility>
0004 using namespace std;
0005 namespace InttQa
0006 {
0007
0008
0009
0010
0011 const int kFelix_num = 8;
0012 const int kFee_num = 14;
0013 const int kChip_num = 26;
0014 const int kChan_num = 128;
0015 const int kFirst_pid = 3001;
0016 const int kBco_max = 128;
0017
0018 const int kColors[10] = {
0019 kBlack, kRed, kBlue,
0020 kGreen+2, kMagenta+1, kYellow+1,
0021 kCyan+1, kOrange+1, kBlue+9,
0022 kGray + 2
0023 };
0024
0025
0026
0027
0028 template < class aaa >
0029 int GetColor( aaa num )
0030 {
0031 assert( 0 <= num && num < 10 );
0032 return InttQa::kColors[ num ];
0033 }
0034
0035
0036 template < class TH >
0037 void HistConfig( TH* hist, int index=0 )
0038 {
0039 hist->SetLineColor( InttQa::GetColor(index) );
0040 hist->SetFillColorAlpha( hist->GetLineColor(), 0.1 );
0041 }
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 template < typename TH >
0053 TPaletteAxis* DrawPaletteAxis( TH* hist,
0054 double xmin, double ymin,
0055 double xmax, double ymax,
0056 double label_size = 0.04 )
0057
0058 {
0059
0060 gPad->Update();
0061 TPaletteAxis *pal = (TPaletteAxis*)hist->GetListOfFunctions()->FindObject("palette");
0062 pal->GetAxis()->SetLabelSize( label_size );
0063 pal->GetAxis()->CenterTitle();
0064
0065 pal->SetX1NDC( xmin );
0066 pal->SetX2NDC( xmax );
0067
0068 pal->SetY1NDC( ymin );
0069 pal->SetY2NDC( ymax );
0070 pal->Draw();
0071
0072 return pal;
0073 }
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 template < typename TH >
0084 void DrawStats( TH* hist, double xmin, double ymin, double xmax, double ymax, int font = 4)
0085 {
0086
0087 gPad->Update();
0088 TPaveStats *st = (TPaveStats*)hist->FindObject("stats");
0089 if( st == nullptr )
0090 return;
0091
0092 st->SetTextColorAlpha( hist->GetLineColor(), 1.0 );
0093 st->SetLineColorAlpha( hist->GetLineColor(), 1.0 );
0094 st->SetFillStyle( 1001 );
0095 st->SetFillColor( 0 );
0096
0097 st->SetX1NDC( xmin );
0098 st->SetX2NDC( xmax );
0099 st->SetY1NDC( ymin );
0100 st->SetY2NDC( ymax );
0101
0102 st->Draw("same");
0103 }
0104
0105
0106 template < class TH >
0107 void HistsConfig( int hist_num, TH* hists )
0108 {
0109
0110 std::vector < int > bin_x_with_entry;
0111 std::vector < int > bin_y_contents;
0112 for( int i=0; i<hist_num; i++ )
0113 {
0114
0115 for( int j=1; j<hists[i]->GetNbinsX()+1; j++ )
0116 {
0117 if( hists[i]->GetBinContent( j ) != 0 )
0118 {
0119 bin_x_with_entry.push_back( j );
0120 bin_y_contents.push_back( hists[i]->GetBinContent( j ) );
0121
0122 }
0123 }
0124 }
0125
0126 int min_non_zero_x = *std::min_element( bin_x_with_entry.begin(), bin_x_with_entry.end() );
0127 if( min_non_zero_x > 1 )
0128 min_non_zero_x--;
0129
0130 int max_non_zero_x = *std::max_element( bin_x_with_entry.begin(), bin_x_with_entry.end() );
0131
0132 if( max_non_zero_x < hists[0]->GetNbinsX() )
0133 max_non_zero_x++;
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 hists[0]->GetXaxis()->SetRange( min_non_zero_x, max_non_zero_x );
0147
0148 int min_y = *std::min_element( bin_y_contents.begin(), bin_y_contents.end() );
0149 int max_y = *std::max_element( bin_y_contents.begin(), bin_y_contents.end() );
0150 if( gPad->GetLogy() == 0 )
0151 max_y *= 1.2;
0152 else
0153 max_y *= 2;
0154
0155 hists[0]->GetYaxis()->SetRangeUser( min_y, max_y );
0156 for( int i=0; i<hist_num; i++ )
0157 {
0158 InttQa::HistConfig( hists[i], i );
0159 }
0160
0161 std::cout << "X range: " << min_non_zero_x << "\t" << max_non_zero_x << std::endl;
0162 std::cout << "Y range: " << min_y << "\t" << max_y << std::endl;
0163 }
0164
0165 template < class T >
0166 std::pair < int, int > OptimizeRange( T* hist, int axis_param=0 )
0167 {
0168
0169
0170
0171
0172
0173
0174
0175 TAxis* axis = hist->GetXaxis();
0176 if( axis_param == 1 )
0177 axis = hist->GetYaxis();
0178 else if( axis_param == 2 )
0179 axis = hist->GetZaxis();
0180
0181 int bin_min = 0;
0182 int bin_max = axis->GetNbins();
0183 int bin_max_sweep = bin_max;
0184
0185
0186 for( int i=1; i<bin_max_sweep; i++ )
0187 {
0188
0189 auto content = hist->GetBinContent( i );
0190 if( content > 0 )
0191 {
0192 bin_min = i;
0193 break;
0194 }
0195 }
0196
0197
0198 for( int i=bin_max_sweep-1; i>0; i-- )
0199 {
0200 auto content = hist->GetBinContent( i );
0201 if( content > 0 )
0202 {
0203 bin_max = i;
0204 std::cout << std::setw(10) << i << "\t" << content << std::endl;
0205 break;
0206 }
0207 }
0208
0209 if( bin_max == axis->GetNbins() )
0210 bin_max = 1;
0211
0212 std::cout << "detemination... " << bin_max << std::endl;
0213 axis->SetRange( bin_min, bin_max );
0214 std::pair < int, int >rtn( bin_min, bin_max );
0215 return rtn;
0216 }
0217 }