All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
EfficiencyManager.cc
Go to the documentation of this file.
1 #include "EfficiencyManager.h"
2 #include "SimDigital.h"
3 
4 #include <marlin/VerbosityLevels.h>
5 
6 #include <TFile.h>
7 #include <TTree.h>
8 
10 {
11 }
13 {
14 }
15 
17  : EfficiencyManager() ,
18  value(val)
19 {
20 }
22 {
23 }
24 
26 {
27  return value ;
28 }
29 
30 AsicEfficiency::AsicEfficiency(std::string fileName , float globalVal)
31  : UniformEfficiency(globalVal) ,
32  effMap()
33 {
34  readFile(fileName) ;
35 }
36 
38 {
39 }
40 
41 void AsicEfficiency::readFile(std::string fileName)
42 {
43  TFile* file = TFile::Open( fileName.c_str() , "READ") ;
44  if ( !file )
45  {
46  std::cerr << "ERROR : file " << fileName << " not found for AsicEfficiency::readFile" << std::endl ;
47  throw ;
48  }
49 
50  TTree* tree = dynamic_cast<TTree*>( file->Get("tree") ) ;
51  if ( !tree )
52  {
53  std::cerr << "ERROR : tree not present in file " << fileName << std::endl ;
54  throw ;
55  }
56 
57  int padID ;
58  int asicID ;
59  int layerID ;
60  std::vector<double>* efficiencies = NULL ;
61  std::vector<double>* position = NULL ;
62 
63  tree->SetBranchAddress("LayerID" , &layerID) ;
64  tree->SetBranchAddress("AsicID" , &asicID) ;
65  tree->SetBranchAddress("PadID" , &padID) ;
66  tree->SetBranchAddress("Efficiencies" , &efficiencies) ;
67  tree->SetBranchAddress("Position" , &position) ;
68 
69  int iEntry = 0 ;
70  while ( tree->GetEntry(iEntry++) )
71  {
72  if ( padID != -1 )
73  continue ;
74 
75  int iAsic = static_cast<int>( (position->at(0)-10.408)/(8*10.408) ) ;
76  int jAsic = static_cast<int>( (position->at(1)-10.408)/(8*10.408) ) ;
77  int K = static_cast<int>( (position->at(2)-26.131)/26.131 + 0.5 ) ;
78 
79 
80  if ( asicID == -1 && layerID != -1 ) //global value for layer
81  effMap.insert( std::make_pair(AsicKey(K) , efficiencies->at(0)) ) ;
82  else
83  effMap.insert( std::make_pair(AsicKey(K , iAsic , jAsic) , efficiencies->at(0)) ) ;
84  }
85 
86  file->Close() ;
87 }
88 
90 {
91  AsicKey asicKey(cellID->K() , (cellID->I()-1)/8 , (cellID->J()-1)/8) ;
92 
93  std::map<AsicKey,float>::const_iterator it = effMap.find( asicKey ) ;
94 
95  if ( it == effMap.end() )
96  {
97  it = effMap.find( AsicKey( cellID->K() ) ) ; //else search for layer mul
98  if ( it == effMap.end() )
99  return value ;
100  else
101  return it->second ;
102  }
103  else
104  return it->second ;
105 }
void readFile(std::string fileName)
virtual ~EfficiencyManager()
virtual float getEfficiency(SimDigitalGeomCellId *cellID)
AsicEfficiency(std::string fileName, float globalVal=1.0)
UniformEfficiency(float val=1.0)
virtual float getEfficiency(SimDigitalGeomCellId *cellID)
static const float K
virtual ~UniformEfficiency()
virtual ~AsicEfficiency()
std::map< AsicKey, float > effMap