Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:14:01

0001 #include <sPhenixStyle.C>
0002 
0003 template < class T >
0004 void HistSetting( T* hist )
0005 {
0006   hist->GetXaxis()->CenterTitle();
0007   hist->GetYaxis()->CenterTitle();
0008   
0009   hist->GetYaxis()->SetTitleOffset( 1.7 )  ;
0010 }
0011 
0012 string GetDate()
0013 {
0014   return "9/13/2024";
0015   
0016   TDatime dt;
0017   int year  = dt.GetYear();
0018   int month = dt.GetMonth();
0019   int day   = dt.GetDay();
0020 
0021   // format: mm/dd/yyyy
0022   std::stringstream ss;
0023   ss << month << "/" << day << "/" << year;
0024 
0025   return ss.str();
0026 }
0027 
0028 void DrawWords( int run, bool is_preliminary )
0029 {
0030 
0031   ///////////////////////////////////////////////////////////////////////////////
0032   // Writting words in the canvas                                              //
0033   ///////////////////////////////////////////////////////////////////////////////
0034   TLatex* tex = new TLatex();
0035 
0036   double top_margin = 0.05;
0037   double line_height = 0.05;
0038   double first_margin = 0.005;  
0039   double pos_y = 1.0 - top_margin + first_margin;// - line_height;
0040 
0041   // Date
0042   tex->DrawLatexNDC( 0.7, pos_y,
0043              string("#it{" + GetDate() + "}").c_str() );
0044 
0045   // sPHENIX Internal or sPHENIX Prelimnary
0046   pos_y -= line_height - first_margin + 0.025;
0047   double pos_x = 0.5;
0048   if( is_preliminary == false )
0049     {
0050       tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Internal" );
0051     }
0052   else
0053     {
0054 
0055       pos_x = 0.5;
0056       tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" );
0057     }
0058 
0059   // p+p 200 GeV
0060   pos_y -= line_height;
0061   tex->DrawLatexNDC( pos_x, pos_y, "Run-24 #it{p+p} 200 GeV" );
0062 
0063   pos_y -= line_height;
0064   tex->DrawLatexNDC( pos_x, pos_y, ( string("Run ") + to_string(run)).c_str() );
0065 
0066   pos_y -= line_height;
0067   tex->DrawLatexNDC( pos_x, pos_y, "INTT Triggered mode" );
0068 }
0069 
0070 int GetPeakPosition( TH1D* hist )
0071 {
0072   int bin = 0;
0073   int content = 0;
0074   for( int i=1; i<hist->GetNbinsX()+1; i++ )
0075     {
0076     if( content < hist->GetBinContent( i ) )
0077       {
0078     content = hist->GetBinContent( i ) ;
0079     bin = i;
0080       }
0081     }
0082 
0083   return bin;
0084 }
0085 
0086 int GetRisingEdge( TH1D* hist )
0087 {
0088   int peak_position = GetPeakPosition( hist );
0089   int content_max = hist->GetBinContent( peak_position );
0090 
0091   for( int i=peak_position; i>0; i-- )
0092     {
0093       if( hist->GetBinContent( i ) < content_max * 1e-3 )
0094     {
0095       return i;
0096     }      
0097     }
0098 
0099   return 0;
0100 }
0101 
0102 TH1D* GetShiftedHist( TH1D* hist )
0103 {
0104   int edge_position = GetRisingEdge( hist ) ;
0105   auto hist_rtn = (TH1D*)hist->Clone();
0106   for( int i=1; i<hist->GetNbinsX()+1; i++ )
0107     {
0108       int position = i + edge_position;
0109       if ( position > hist->GetNbinsX() )
0110     position -= hist->GetNbinsX();
0111   
0112       hist_rtn->SetBinContent( i , hist->GetBinContent( position ) );
0113      
0114     }
0115   
0116     return hist_rtn;
0117 }
0118 
0119 int trigger_timing( int run = 50377, bool is_preliminary = false )
0120 {
0121 
0122   SetsPhenixStyle();
0123 
0124   string output = string("results/trigger_timing_run") + to_string( run );
0125   if( is_preliminary == true )
0126     output += "_preliminary.pdf";
0127   else
0128     output += "_internal.pdf";
0129   
0130   TCanvas* c = new TCanvas( output.c_str(), "title", 800, 800 );
0131   // c->SetTopMargin( top_margin_ );
0132   // c->SetRightMargin( right_margin_ );
0133 
0134   string data = string( "results/InttTriggerTiming_run000" ) + to_string( run ) + ".root";
0135   TFile* tf = new TFile( data.c_str(), "READ" );
0136   TH1D* hist_raw = (TH1D*)tf->Get( "bco_diff" );
0137   
0138   auto hist = GetShiftedHist( hist_raw );
0139   hist->SetTitle( ";Crossing relative to GTM [BCO];Counts" );
0140   //hist->SetLineColor( kRed );
0141   hist->SetFillColorAlpha( hist->GetLineColor(), 0.1 );
0142   HistSetting( hist );
0143   //hist->GetXaxis()->SetRangeUser( -1, 128 );
0144   hist->GetXaxis()->SetRangeUser( 0, 128 );
0145   hist->Draw();
0146 
0147   hist_raw->SetLineColor( kGray );
0148   //hist_raw->Draw( "same" );
0149   DrawWords( run, is_preliminary );
0150   
0151   c->Print( c->GetName() );
0152   return 0;
0153 }