CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
KKCorrectionFactors Class Reference

#include <KKCorrectionFactors.h>

Public Member Functions

float getScale (float genEnergy, float genEta, float simEnergy) const
 
 KKCorrectionFactors (const edm::ParameterSet &pset)
 
 ~KKCorrectionFactors ()
 

Private Attributes

TH3F * h3_
 
bool interpolate3D_
 

Detailed Description

Definition at line 27 of file KKCorrectionFactors.h.

Constructor & Destructor Documentation

KKCorrectionFactors::KKCorrectionFactors ( const edm::ParameterSet pset)

Definition at line 3 of file KKCorrectionFactors.cc.

References Exception, edm::ParameterSet::exists(), MillePedeFileConverter_cfg::fileName, edm::ParameterSet::getUntrackedParameter(), h3_, interpolate3D_, haddnano::obj, and AlCaHLTBitMon_QueryRunRegistry::string.

4 {
5 
6  interpolate3D_ = pset.exists("interpolate3D") && pset.getUntrackedParameter<bool>("interpolate3D");
7 
8  // Get the filename and histogram name
10  std::string histogramName = pset.getUntrackedParameter<std::string>("histogramName");
11 
12  // Read histo
13  edm::FileInPath myDataFile( fileName );
14  TFile * myFile = TFile::Open( myDataFile.fullPath().c_str() );
15 
16  gROOT->cd(); // create histogram in memory
17  auto obj = myFile->Get( histogramName.c_str() );
18 
19  // Check if histogram exists in file
20  if(!obj) {
21  throw cms::Exception( "FileReadError" )
22  << "Histogram \"" << histogramName
23  << "\" not found in file \"" << fileName
24  << "\".\n";
25  }
26  h3_ = new TH3F( *((TH3F*)obj) );
27 
28  delete myFile;
29 
30 }
T getUntrackedParameter(std::string const &, T const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
KKCorrectionFactors::~KKCorrectionFactors ( )
inline

Definition at line 34 of file KKCorrectionFactors.h.

References getScale(), and h3_.

34 { delete h3_; };

Member Function Documentation

float KKCorrectionFactors::getScale ( float  genEnergy,
float  genEta,
float  simEnergy 
) const

Definition at line 33 of file KKCorrectionFactors.cc.

References h3_, interpolate3D_, alignCSCRings::r, and Scenarios_cff::scale.

Referenced by ~KKCorrectionFactors().

34 {
35 
36  float r = simE / genE;
37  float scale = 1.;
38 
39  if( interpolate3D_
40  // TH3::Interpolate can only interpolate inside the bondaries of the histogram
41  && genE > h3_->GetXaxis()->GetXmin()
42  && genE < h3_->GetXaxis()->GetXmax()
43  && genEta > h3_->GetYaxis()->GetXmin()
44  && genEta < h3_->GetYaxis()->GetXmax()
45  && r < h3_->GetZaxis()->GetXmax()
46  && r > h3_->GetZaxis()->GetXmax() ) {
47 
48  scale = h3_->Interpolate( genE, genEta, r );
49 
50  } else { // interpolation in r is mandatory
51 
52  int binE = h3_->GetXaxis()->FindFixBin( genE );
53  int binEta = h3_->GetYaxis()->FindFixBin( genEta );
54 
55  // find the two bins which are closest to the actual value
56  auto binWidthR = h3_->GetZaxis()->GetBinWidth(0);
57  int binRup = h3_->GetZaxis()->FindFixBin( r + binWidthR/2. );
58  int binRdn = h3_->GetZaxis()->FindFixBin( r - binWidthR/2. );
59 
60  auto scaleUp = h3_->GetBinContent( binE, binEta, binRup );
61  auto scaleDn = h3_->GetBinContent( binE, binEta, binRdn );
62 
63  // make a linear extrapolation between neighbour bins if they are not zero
64  auto Rdn = h3_->GetZaxis()->GetBinCenter( binRdn );
65  scale = scaleDn + (scaleUp-scaleDn) * ( r - Rdn ) / binWidthR;
66 
67  }
68  return scale;
69 
70 }

Member Data Documentation

TH3F* KKCorrectionFactors::h3_
private

Definition at line 40 of file KKCorrectionFactors.h.

Referenced by getScale(), KKCorrectionFactors(), and ~KKCorrectionFactors().

bool KKCorrectionFactors::interpolate3D_
private

Definition at line 41 of file KKCorrectionFactors.h.

Referenced by getScale(), and KKCorrectionFactors().