CMS 3D CMS Logo

MultipleScatteringX0Data.cc
Go to the documentation of this file.
4 
5 #include "TH2.h"
6 #include "TFile.h"
7 #include "TKey.h"
8 
9 #include <iostream>
10 #include <string>
11 #include <cmath>
12 
13 using namespace std;
14 
15 
17  : theData(nullptr)
18 {
19  string filename = fileName();
20  TFile theFile(filename.c_str(),"READ");
21  if (not theFile.IsZombie()) {
22  theData.reset(dynamic_cast<TH2F*> (theFile.GetKey("h100")->ReadObj()));
23  theData->SetDirectory(nullptr);
24  }
25  if (!theData) {
26  throw cms::Exception("Data not found")
27  << " ** MultipleScatteringX0Data ** file: "
28  << filename
29  <<" <-- no data found!!!";
30  }
31 }
32 
34 {
35 }
36 
38 {
39  string defName="RecoTracker/TkMSParametrization/data/MultipleScatteringX0Data.root";
40  edm::FileInPath f(defName);
41  return f.fullPath();
42 }
43 
45 {
46  if (theData) return theData->GetNbinsX();
47  else return 0;
48 }
49 
51 {
52  if (theData) return theData->GetXaxis()->GetXmin();
53  else return 0;
54 }
55 
57 {
58  if (theData) return theData->GetXaxis()->GetXmax();
59  else return 0;
60 }
61 
62 float MultipleScatteringX0Data::sumX0atEta(float eta, float r) const
63 {
64  if(!theData) return 0.;
65  eta = fabs(eta);
66 
67  int ieta = theData->GetXaxis()->FindBin(eta);
68  int irad = theData->GetYaxis()->FindBin(r);
69 
70  if (irad < theData->GetNbinsY()) {
71  return theData->GetBinContent(ieta,irad);
72  }
73  else {
74  float sumX0 = 0;
75  for(int ir = theData->GetNbinsY(); ir > 0; ir--) {
76  float val = theData->GetBinContent(ieta, ir);
77  if (val > sumX0) sumX0 = val;
78  }
79  return sumX0;
80  }
81 }
#define nullptr
float sumX0atEta(float eta, float r) const override
double f[11][100]
std::string fullPath() const
Definition: FileInPath.cc:197
std::unique_ptr< TH2F > theData