All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
ChargeInducer.cc
Go to the documentation of this file.
1 #include "ChargeInducer.h"
2 #include "SimDigital.h"
3 
4 #include <sstream>
5 
6 #include <marlin/VerbosityLevels.h>
7 
8 #include <TFile.h>
9 #include <TTree.h>
10 
12  : generator()
13 {
14 }
15 
17 {
18 }
19 void ChargeInducer::setSeed(unsigned int value)
20 {
21  generator.seed(value) ;
22 }
23 
24 
25 UniformPolya::UniformPolya(float _qbar , float _theta)
26  : ChargeInducer() ,
27  gammadist( std::gamma_distribution<float>( _qbar/_theta , _theta ) )
28 {
29 }
30 
32 {}
33 
35 {
36  return gammadist(generator) ;
37 }
38 
39 AsicPolya::AsicPolya(float _qbar , float _theta , std::string fileName)
40  : UniformPolya(_qbar , _theta) ,
41  polyaMap()
42 {
43  readFile(fileName) ;
44 }
45 
47 {
48 }
49 
50 
51 void AsicPolya::readFile(std::string fileName)
52 {
53  TFile* file = TFile::Open( fileName.c_str() , "READ") ;
54  if ( !file )
55  {
56  std::cerr << "ERROR : file " << fileName << " not found for AsicPolya::readFile" << std::endl ;
57  throw ;
58  }
59 
60  TTree* tree = dynamic_cast<TTree*>( file->Get("tree") ) ;
61  if ( !tree )
62  {
63  std::cerr << "ERROR : tree not present in file " << fileName << std::endl ;
64  throw ;
65  }
66 
67  int asicID ;
68  int layerID ;
69  float qbarAsic ;
70  float deltaAsic ;
71  std::vector<double>* position = NULL ;
72 
73  tree->SetBranchAddress("LayerID" , &layerID) ;
74  tree->SetBranchAddress("AsicID" , &asicID) ;
75  tree->SetBranchAddress("qbar" , &qbarAsic) ;
76  tree->SetBranchAddress("delta" , &deltaAsic) ;
77  tree->SetBranchAddress("Position" , &position) ;
78 
79  int iEntry = 0 ;
80  while ( tree->GetEntry(iEntry++) )
81  {
82  if ( qbarAsic <= 0 || deltaAsic <= 0 )
83  continue ;
84 
85  float alpha = qbarAsic/deltaAsic ;
86  float delta = deltaAsic ;
87 
88  std::gamma_distribution<float> localDist( alpha , delta ) ;
89 
90  int iAsic = static_cast<int>( (position->at(0)-10.408)/(8*10.408) ) ;
91  int jAsic = static_cast<int>( (position->at(1)-10.408)/(8*10.408) ) ;
92  int K = static_cast<int>( (position->at(2)-26.131)/26.131 + 0.5 ) ;
93 
94 
95  if ( asicID == -1 && layerID != -1 ) //global value for layer
96  polyaMap.insert( std::make_pair(AsicKey(K) , localDist) ) ;
97  else
98  polyaMap.insert( std::make_pair(AsicKey(K , iAsic , jAsic) , localDist) ) ;
99  }
100  file->Close() ;
101 }
102 
104 {
105  // int asicKey = (cellID.I()-1)/8 + ((cellID.J()-1)/8)*12 + cellID.K()*1000 ;
106  AsicKey asicKey(cellID->K() , (cellID->I()-1)/8 , (cellID->J()-1)/8) ;
107 
108  std::map<AsicKey, std::gamma_distribution<float> >::iterator it = polyaMap.find( asicKey ) ;
109 
110  if ( it == polyaMap.end() )
111  {
112  it = polyaMap.find( AsicKey( cellID->K() ) ) ; //else search for layer polya
113  if ( it == polyaMap.end() )
114  return gammadist(generator) ;
115  else
116  return it->second(generator) ;
117  }
118  else
119  return it->second(generator) ;
120 }
121 
virtual ~ChargeInducer()
std::gamma_distribution< float > gammadist
Definition: ChargeInducer.h:42
void readFile(std::string fileName)
virtual float getCharge(SimDigitalGeomCellId *cellID)
std::map< AsicKey, std::gamma_distribution< float > > polyaMap
Definition: ChargeInducer.h:58
std::mt19937 generator
Definition: ChargeInducer.h:29
UniformPolya(float _qbar, float _theta)
static const float K
void setSeed(unsigned int value)
virtual float getCharge(SimDigitalGeomCellId *cellID)
AsicPolya(float _qbar, float _theta, std::string fileName)