Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #define MipHist_cc
0002 #include "MipHist.hh"
0003 
0004 
0005 ////////////////////////////////////////////////////////////////////////
0006 // constructor                                                        //
0007 ////////////////////////////////////////////////////////////////////////
0008 MipHist::MipHist( string name, string title ) :
0009   name_( name ),
0010   title_( title )
0011 {
0012   this->Init();
0013 }
0014 
0015 ////////////////////////////////////////////////////////////////////////
0016 // private functions                                                  //
0017 ////////////////////////////////////////////////////////////////////////
0018 void MipHist::Init()
0019 {
0020   
0021   string name_raw = name_ + "_raw";
0022   hist_raw_ = new TH1D( name_raw.c_str(), title_.c_str(), bin_num_, xmin_, xmax_) ; // , "adc_in", cut, "",
0023   hist_raw_->SetLineWidth( 2 );
0024   HistSetting( hist_raw_ );
0025 
0026   string name_shc = name_ + "_shc";
0027   hist_shc_adc7_ = new TH1D( name_shc.c_str(), title_.c_str(), bin_num_, xmin_, xmax_) ; // , "adc_in", cut, "",
0028   hist_shc_adc7_->SetLineWidth( 2 );
0029   HistSetting( hist_shc_adc7_ );
0030 
0031   string name_dhc = name_ + "_dhc";
0032   hist_dhc_adc14_ = new TH1D( name_dhc.c_str(), title_.c_str(), bin_num_, xmin_, xmax_) ; // , "adc_in", cut, "",
0033   hist_dhc_adc14_->SetLineWidth( 2 );
0034   HistSetting( hist_dhc_adc14_ );
0035 
0036   f_ = new TF1( "f", "landau", xmin_, xmax_ );
0037   f_->SetLineStyle( 2 );
0038   
0039 }
0040 
0041 ////////////////////////////////////////////////////////////////////////
0042 // private functions                                                  //
0043 ////////////////////////////////////////////////////////////////////////
0044 void MipHist::Fill( TH1D* hist, int val )
0045 {
0046   hist->Fill( val );
0047 }
0048 
0049 void MipHist::ModifyAdc( TH1D* hist_ref, double power_factor )
0050 {
0051   cout << "MipHist::ModifyAdc, " << hist_ref->GetName() << endl;
0052   
0053   for( int i=1; i<hist_ref->GetNbinsX() + 1; i++ )
0054     {
0055       int content_raw = hist_raw_->GetBinContent( i );
0056 
0057       int content = hist_ref->GetBinContent(i);
0058       if( content == 0 )
0059     {
0060       continue;
0061     }
0062       
0063       int content_diff = content_raw - content;
0064       double content_modified = pow( modification_factor_, power_factor ) * content + content_diff;
0065       hist_->SetBinContent( i, content_modified ); // update if needed
0066       
0067       cout << i << " "
0068        << hist_->GetBinLowEdge( i ) << " "
0069        << content_raw << "\t"
0070        << content << "\t"
0071        << content_diff << "\t"
0072        << content_modified
0073        << endl;
0074     }
0075 
0076   // cout << "ModifyAdc" << endl;
0077   // cout << "Index of ADC: " << index_adc << endl;
0078   // cout << "#ADC: " << num_cluster_adc << endl;
0079   // cout << "#ADC (single-hit cluster): " << num_single_hit_cluster_adc << endl;
0080   // cout << "#ADC (multiple-hit cluster): " << num_multiple_hit_cluster_adc << endl;
0081   // cout << "Modified #ADC (single-hit cluster): " << num_modified_single_hit_cluster_adc << endl;
0082   // cout << "Moddified #ADC: " << num_modified_cluster_adc << endl;
0083 
0084 }
0085 
0086 ////////////////////////////////////////////////////////////////////////
0087 // public functions                                                   //
0088 ////////////////////////////////////////////////////////////////////////
0089 void MipHist::DrawLine( TF1* f )
0090 {
0091   TLine* line = new TLine();
0092   line->SetLineColor( f->GetLineColor() );
0093   line->SetLineStyle( f->GetLineStyle() );
0094 
0095   double mpv = f->GetParameter(1);
0096   line->DrawLine( mpv, 0, mpv, 1.3 );
0097 
0098 }
0099 
0100 void MipHist::Fill( int val )
0101 {
0102   this->Fill( hist_raw_, val );
0103 }
0104 
0105 void MipHist::FillAll( int val, bool is_single, bool is_double )
0106 {
0107   this->Fill( hist_raw_, val );
0108 
0109   if( is_single )
0110     this->Fill( hist_shc_adc7_, val );
0111   else if( is_double )
0112     this->Fill( hist_dhc_adc14_, val );
0113 }
0114 
0115 TF1* MipHist::GetNormalizedFunction( double top_val )
0116 {
0117   TF1* f = (TF1*)f_->Clone();
0118   f->SetParLimits( 0, 0, 250 );
0119   f->SetParLimits( 1, 70, 150 );
0120   f->SetParLimits( 2, 0, 100 );
0121   auto hist = this->GetNormalizedHist( top_val );
0122   hist->Fit( f, "0", "", 35, 600 );
0123 
0124   return f;
0125 }
0126 
0127 TH1D* MipHist::GetNormalizedHist( double top_val )
0128 {
0129   auto hist = (TH1D*)hist_->Clone();
0130   if( true )
0131     {
0132       hist->Scale( 1.0 / hist->GetEntries() );
0133     }
0134   else if( false )
0135     {
0136       double max_content = 0.0;
0137       for( int i=1; i<hist->GetNbinsX()+1; i++ )
0138     if( max_content < hist->GetBinContent(i) )
0139       max_content = hist->GetBinContent(i) ;
0140       
0141       hist->Scale( top_val / max_content );
0142       //      hist->Scale( 1. / max_content );
0143     }
0144   else if( false )
0145     {
0146       hist->Scale( 1. / hist->GetBinContent( 2 ) );
0147     }
0148   return hist;
0149 }
0150 
0151 void MipHist::ModifyAdc()
0152 {
0153   // init
0154   hist_ = (TH1D*)hist_raw_->Clone();
0155   hist_->SetName( name_.c_str() );
0156   hist_->SetFillColorAlpha( color_, alpha_ );
0157   hist_->SetLineColorAlpha( color_, 1 );
0158 
0159   if( does_adc7_correction_ == true )
0160     this->ModifyAdc( hist_shc_adc7_, 1.0 );
0161   
0162   if( does_adc14_correction_ == true )
0163     this->ModifyAdc( hist_dhc_adc14_, 2.0 );
0164 
0165   hist_->Fit( f_, "0" );
0166 }
0167 
0168 void MipHist::SetColorAlpha( int color, double alpha, bool does_all )
0169 {
0170   color_ = color;
0171   alpha_ = alpha;
0172   
0173   hist_raw_->SetFillColorAlpha( color_, alpha_ );
0174   hist_raw_->SetLineColorAlpha( color_, 1 );
0175 
0176   hist_shc_adc7_->SetFillColorAlpha( color_, alpha_ );
0177   hist_shc_adc7_->SetLineColorAlpha( color_, 1 );
0178 
0179   hist_dhc_adc14_->SetFillColorAlpha( color_, alpha_ );
0180   hist_dhc_adc14_->SetLineColorAlpha( color_, 1 );
0181 
0182   if( does_all )
0183     {
0184       hist_->SetFillColorAlpha( color_, alpha_ );
0185       hist_->SetLineColorAlpha( color_, 1 );
0186     }
0187   
0188   f_->SetLineColor( color_ );
0189 }
0190 
0191 void MipHist::Print()
0192 {
0193 
0194   cout << string( 50, '-' ) << endl;
0195   cout << tag_ << endl;
0196   cout << setw(3) << "bin" << " "
0197        << setw(4) << "DAC" << "  "
0198        << setw(8) << "Raw" << "  "
0199        << setw(8) << "Single7" << "  "
0200        << setw(8) << "Double14" << "  "
0201        << setw(8) << "Modified"
0202        << endl;
0203 
0204   // from underflow bin to overflow bin
0205   for( int i=0; i<hist_->GetNbinsX() + 2; i++ )
0206     {
0207       cout << setw(3) << i << " "
0208        << setw(4) << hist_->GetBinLowEdge( i ) << "  "
0209        << setw(8) << hist_raw_->GetBinContent(i) << "  "
0210        << setw(8) << hist_shc_adc7_->GetBinContent(i) << "  "
0211        << setw(8) << hist_dhc_adc14_->GetBinContent(i) << "  "
0212        << setw(8) << hist_->GetBinContent(i) << "  "
0213        << endl;
0214     }
0215   cout << endl;
0216 
0217 }