File indexing completed on 2025-08-06 08:14:00
0001 #define Analysis_cc
0002 #include "Analysis.hh"
0003
0004 Analysis::Analysis( string data_no_suffix, bool is_preliminary ) :
0005 is_preliminary_( is_preliminary )
0006 {
0007 this->Init( data_no_suffix );
0008 }
0009
0010 void Analysis::Init( string data_no_suffix )
0011 {
0012
0013 root_path_ = data_no_suffix + ".root";
0014 text_path_ = data_no_suffix + ".dat";
0015
0016 if( is_preliminary_ == true )
0017 output_ += "_preliminary.pdf";
0018 else
0019 output_ += "_internal.pdf";
0020
0021
0022 this->InitRoot();
0023
0024
0025 this->InitText();
0026
0027
0028 hist_fphx_bco_->Scale( 1.0 / event_num_ );
0029
0030 if( is_logy_ == true )
0031 {
0032 ymin_ = 0.1;
0033 ymax_ = 5e5;
0034 }
0035 else
0036 {
0037 ymin_ = 0.0;
0038 ymax_ = 600;
0039 }
0040
0041 return;
0042 }
0043
0044 void Analysis::InitRoot()
0045 {
0046
0047
0048
0049
0050
0051
0052 TFile* tf = new TFile( root_path_.c_str(), "READ" );
0053
0054 string title = ";Beam clock [BCO];Number of INTT hits";
0055
0056 hist_fphx_bco_raw_ = (TH1D*)tf->Get( "fphx_bco_raw" );
0057 hist_fphx_bco_raw_->SetTitle( title.c_str() );
0058
0059 hist_fphx_bco_ = (TH1D*)tf->Get( "fphx_bco" );
0060 this->ConfigureHist( hist_fphx_bco_ );
0061
0062 hist_fphx_bco_->SetLineColor( kBlue + 1 );
0063
0064
0065 TH1D* hist_offset = (TH1D*)tf->Get( "streaming_offset" );
0066 int the_position = 0;
0067 int largest = 0;
0068 for( int i=1; i<hist_offset->GetNbinsX()+1; i++ )
0069 {
0070 int content = hist_offset->GetBinContent( i );
0071 if( largest < content )
0072 {
0073 largest = content;
0074 the_position = i;
0075 }
0076
0077 }
0078
0079 streaming_offset_ = hist_offset->GetBinLowEdge( the_position );
0080 }
0081
0082 void Analysis::InitText()
0083 {
0084
0085
0086
0087
0088 ifstream ifs( text_path_.c_str() );
0089 if( ifs.fail() )
0090 {
0091 cerr << text_path_ << " is not found" << endl;
0092 return;
0093 }
0094
0095 string line;
0096 while( getline( ifs, line ) )
0097 {
0098 if( line[0] == '#' )
0099 continue;
0100
0101 Event* ev = new Event( line, streaming_offset_ );
0102 if( ev->GetInttGtmBco() == 396957258755 )
0103 {
0104
0105
0106
0107
0108
0109
0110
0111
0112 }
0113 events_.push_back( ev );
0114 }
0115
0116 ifs.close();
0117
0118 event_num_ = events_[ events_.size()-1 ]->GetEventNum();
0119 return;
0120 }
0121
0122
0123
0124
0125
0126 string Analysis::GetDate()
0127 {
0128 return "9/13/2024";
0129
0130 TDatime dt;
0131 int year = dt.GetYear();
0132 int month = dt.GetMonth();
0133 int day = dt.GetDay();
0134
0135
0136 std::stringstream ss;
0137 ss << month << "/" << day << "/" << year;
0138
0139 return ss.str();
0140 }
0141
0142 void Analysis::DrawWords( Event* event )
0143 {
0144
0145
0146
0147
0148 TLatex* tex = new TLatex();
0149
0150 double line_height = 0.05;
0151 double first_margin = 0.005;
0152 double pos_y = 1.0 - top_margin_ + first_margin;
0153
0154
0155 tex->DrawLatexNDC( 0.7, pos_y,
0156 string("#it{" + GetDate() + "}").c_str() );
0157
0158
0159 pos_y -= line_height - first_margin + 0.025;
0160 double pos_x = 0.2;
0161 if( is_preliminary_ == false )
0162 {
0163 tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Internal" );
0164 }
0165 else
0166 {
0167 tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" );
0168 }
0169
0170
0171 pos_y -= line_height;
0172 tex->DrawLatexNDC( pos_x, pos_y, "Run-24 #it{p+p} 200 GeV, Run 50889" );
0173
0174 pos_y -= line_height;
0175 tex->DrawLatexNDC( pos_x, pos_y, "INTT Streaming readout " );
0176
0177 pos_y -= line_height;
0178 stringstream ss;
0179 ss << "BCO " << event->GetInttGtmBco();
0180 tex->DrawLatexNDC( pos_x, pos_y, ss.str().c_str() );
0181
0182
0183
0184
0185
0186
0187
0188 }
0189
0190 TH1D* Analysis::GetShiftedHist( TH1D* hist_arg )
0191 {
0192 TH1D* hist = (TH1D*)hist_arg->Clone();
0193
0194 for( int i=1; i<hist->GetNbinsX()+1; i++ )
0195 {
0196 auto content = hist_arg->GetBinContent( i + shift_value_ );
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 if( (i + shift_value_ ) > hist->GetNbinsX() )
0210 content = hist_arg->GetBinContent( i + shift_value_ - hist->GetNbinsX() );
0211
0212 hist->SetBinContent( i, content );
0213 }
0214
0215 return hist;
0216 }
0217
0218 void Analysis::DrawGl1Timing( Event* event )
0219 {
0220 double timing = event->GetGl1Timing() + 0.5;
0221
0222 TLine* line = new TLine();
0223 line->SetLineColor( kAzure + 1 );
0224 line->SetLineWidth( 2 );
0225 line->SetLineStyle( 7 );
0226 line->DrawLine( timing, ymin_, timing, ymax_ );
0227 }
0228
0229
0230
0231
0232 void Analysis::Draw()
0233 {
0234
0235 SetsPhenixStyle();
0236
0237 TCanvas* c = new TCanvas( output_.c_str(), "title", 800, 800 );
0238
0239
0240 c->Print( ((string)c->GetName() + "[").c_str() );
0241
0242
0243
0244
0245 int counter = 0;
0246 for( auto& event : events_ )
0247 {
0248 counter++;
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261 int ignore_smaller_than = 7;
0262 bool condition = true
0263
0264
0265 && ( event->IsGl1Correspondings() == true )
0266
0267 && ( event->GetHitNumMachingGl1() > 30 )
0268 && ( event->GetFatPeakNum( ignore_smaller_than ) < 4 )
0269 && ( event->GetHitNumMaxEvent() / event->GetHitNumMachingGl1() < 3 )
0270 ;
0271
0272 condition = true
0273
0274
0275 && ( event->IsGl1Correspondings() == true )
0276
0277 && ( event->GetHitNumMachingGl1() > 30 )
0278 && ( event->GetFatPeakNum( ignore_smaller_than ) > 10 )
0279
0280 ;
0281
0282 if( event->GetInttGtmBco() == 396912729035 )
0283
0284 {
0285 cout << "The event!!!" << endl;
0286 condition = true;
0287 }
0288 else
0289 continue;
0290
0291
0292 if( !condition )
0293 continue;
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306 hist_fphx_bco_->GetYaxis()->SetRangeUser( ymin_, ymax_ );
0307 hist_fphx_bco_->Draw( "HISTE" );
0308 gPad->SetLogy( is_logy_ );
0309
0310 event->GetHist()->Draw( "same" );
0311 event->GetHistGl1Match()->Draw( "same" );
0312
0313 TLegend* leg = new TLegend( 0.2, 0.55, 0.35, 0.7);
0314 leg->AddEntry( hist_fphx_bco_, "#INTT hits (100k strobes average)", "l" );
0315 leg->AddEntry( event->GetHist(), "#INTT hits (Single strobe)", "l" );
0316 leg->AddEntry( event->GetHistGl1Match(), "#INTT hits (Matching trigger timing)", "l" );
0317 leg->SetTextSize( 0.04 );
0318
0319 this->DrawWords( event );
0320
0321 leg->Draw();
0322 c->Print( c->GetName() );
0323
0324 if( counter > process_num_ )
0325 break;
0326
0327 }
0328
0329 counter = 0;
0330 int counter_gl1_match = 0;
0331 for( auto& event : events_ )
0332 {
0333 counter++;
0334 counter_gl1_match += ( event->IsGl1Correspondings() ? 1 : 0 );
0335 }
0336
0337 cout << "GL1 matching ratio: "
0338 << counter_gl1_match << " / " << counter << " = "
0339 << double(counter_gl1_match) / counter
0340 << endl;
0341
0342 c->Print( ((string)c->GetName() + "]").c_str() );
0343 }