CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/FastSimulation/ForwardDetectors/plugins/AcceptanceTableHelper.cc

Go to the documentation of this file.
00001 /****************************************************************************
00002  * File AcceptanceTableHelper.cc
00003  *
00004  * Access to acceptance tables stored in root histograms
00005  *
00006  * Author: Dmitry Zaborov
00007  *
00008  * Version: $Id: AcceptanceTableHelper.cc,v 1.1 2008/11/25 17:34:15 beaudett Exp $
00009  ***************************************************************************/
00010 
00011 #include "FastSimulation/ForwardDetectors/plugins/AcceptanceTableHelper.h"
00012 
00013 #include <iostream>
00014 #include <math.h>
00015 
00018 void AcceptanceTableHelper::Init(TFile& f, const std::string basename)
00019 {
00020   // ... read table for low t
00021   TH3F *h = (TH3F*)f.Get(basename.c_str());
00022 
00023   if (h != NULL)
00024   {
00025     h_log10t_log10Xi_Phi = (TH3F*)h->Clone();
00026     std::cout << "Read ";
00027     h_log10t_log10Xi_Phi->SetDirectory(0); // secure it from deleting if the file is eventually closed
00028     h_log10t_log10Xi_Phi->Print();
00029   } else {
00030     std::cout << "Warning: could not get acceptance table " << basename << std::endl;
00031   }
00032   
00033   // ... read table for high t
00034   std::string name2 = basename+"_hight";
00035   h = (TH3F*)f.Get(name2.c_str());
00036 
00037   if (h != NULL)
00038   {
00039     h_t_log10Xi_Phi = (TH3F*)h->Clone();
00040     h_t_log10Xi_Phi->SetDirectory(0); // secure it from deleting if the file is eventually closed
00041     std::cout << "Read ";
00042     h_t_log10Xi_Phi->Print();
00043   } else {
00044     std::cout << "Warning: could not get acceptance table " << name2 << std::endl;
00045   }
00046 }
00047 
00050 float AcceptanceTableHelper::GetAcceptance(float t, float xi, float phi) {
00051 
00052   float log10t  = log10(-t);
00053   float log10Xi = log10(xi);
00054 
00055   float acc = 0;
00056 
00057   if ((h_log10t_log10Xi_Phi != NULL)                              // if table exists
00058        && (log10t < h_log10t_log10Xi_Phi->GetXaxis()->GetXmax())) // and t within table range
00059   {
00060   
00061     float log10tMin = h_log10t_log10Xi_Phi->GetXaxis()->GetXmin();
00062     if (log10t < log10tMin) log10t = log10tMin; // very small t should go to the lowest t bin
00063     
00064     acc = h_log10t_log10Xi_Phi->GetBinContent(h_log10t_log10Xi_Phi->FindBin(log10t, log10Xi, phi));
00065 
00066   } else if (h_t_log10Xi_Phi != NULL) { // if table exists for high t
00067 
00068      acc = h_t_log10Xi_Phi->GetBinContent(h_t_log10Xi_Phi->FindBin(-t, log10Xi, phi));
00069   }
00070   
00071   return acc;
00072 }