Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:16

0001 /****************************************************************************
0002  * File AcceptanceTableHelper.cc
0003  *
0004  * Access to acceptance tables stored in root histograms
0005  *
0006  * Author: Dmitry Zaborov
0007  *
0008  * Version: $Id: AcceptanceTableHelper.cc,v 1.3 2007/12/31 10:02:46 elmer Exp $
0009  ***************************************************************************/
0010 
0011 #include "FastSimulation/ForwardDetectors/plugins/AcceptanceTableHelper.h"
0012 
0013 #include <iostream>
0014 #include <cmath>
0015 
0016 /** Read from root file <f> acceptance tables named <basename> and <basename>_hight */
0017 
0018 void AcceptanceTableHelper::Init(TFile& f, const std::string basename) {
0019   // ... read table for low t
0020   TH3F* h = (TH3F*)f.Get(basename.c_str());
0021 
0022   if (h != nullptr) {
0023     h_log10t_log10Xi_Phi = (TH3F*)h->Clone();
0024     std::cout << "Read ";
0025     h_log10t_log10Xi_Phi->SetDirectory(nullptr);  // secure it from deleting if the file is eventually closed
0026     h_log10t_log10Xi_Phi->Print();
0027   } else {
0028     std::cout << "Warning: could not get acceptance table " << basename << std::endl;
0029   }
0030 
0031   // ... read table for high t
0032   std::string name2 = basename + "_hight";
0033   h = (TH3F*)f.Get(name2.c_str());
0034 
0035   if (h != nullptr) {
0036     h_t_log10Xi_Phi = (TH3F*)h->Clone();
0037     h_t_log10Xi_Phi->SetDirectory(nullptr);  // secure it from deleting if the file is eventually closed
0038     std::cout << "Read ";
0039     h_t_log10Xi_Phi->Print();
0040   } else {
0041     std::cout << "Warning: could not get acceptance table " << name2 << std::endl;
0042   }
0043 }
0044 
0045 /** Return acceptance for given t, xi, phi */
0046 
0047 float AcceptanceTableHelper::GetAcceptance(float t, float xi, float phi) {
0048   float log10t = log10(-t);
0049   float log10Xi = log10(xi);
0050 
0051   float acc = 0;
0052 
0053   if ((h_log10t_log10Xi_Phi != nullptr)                           // if table exists
0054       && (log10t < h_log10t_log10Xi_Phi->GetXaxis()->GetXmax()))  // and t within table range
0055   {
0056     float log10tMin = h_log10t_log10Xi_Phi->GetXaxis()->GetXmin();
0057     if (log10t < log10tMin)
0058       log10t = log10tMin;  // very small t should go to the lowest t bin
0059 
0060     acc = h_log10t_log10Xi_Phi->GetBinContent(h_log10t_log10Xi_Phi->FindBin(log10t, log10Xi, phi));
0061 
0062   } else if (h_t_log10Xi_Phi != nullptr) {  // if table exists for high t
0063 
0064     acc = h_t_log10Xi_Phi->GetBinContent(h_t_log10Xi_Phi->FindBin(-t, log10Xi, phi));
0065   }
0066 
0067   return acc;
0068 }