SND@LHC Software
Loading...
Searching...
No Matches
ecalDigi.cxx
Go to the documentation of this file.
1#include "ecalDigi.h"
2
3#include "ecalStructure.h"
4
5#include "FairRootManager.h"
6
7#include "TRandom.h"
8#include "TSystem.h"
9#include "TMath.h"
10
11#include <iostream>
12#include <fstream>
13#include <list>
14
15using namespace std;
16
19 : FairTask(),
20 fPedestal(80),
21 fADCMax(16384),
22 fADCNoise(1.0e-3),
23 fADCChannel(1.0e-3),
24 fStr(NULL), fChannelMap()
25{
26 fChannelMap.clear();
27}
28
30ecalDigi::ecalDigi(const char* name, Int_t iVerbose)
31 : FairTask(name, iVerbose),
32 fPedestal(80),
33 fADCMax(16384),
34 fADCChannel(1.0e-3),
35 fADCNoise(1.0e-3),
36 fStr(NULL), fChannelMap()
37{
38 fChannelMap.clear();
39}
40
42void ecalDigi::LoadChannelMap(const char* filename)
43{
44 map<Int_t, Float_t> tmp;
45 TString fname=filename; gSystem->ExpandPathName(fname);
46 ifstream f(fname);
47 Int_t ch;
48 Int_t i=0;
49 Float_t adc;
50
51 tmp.clear();
52 for(;;)
53 {
54 f >> ch; if (f.eof()) break;
55 f >> adc; if (f.eof()) break;
56 tmp[ch]=adc;
57 i++;
58 }
59 if (fVerbose>999)
60 Info("LoadChannelMap", "%d records read", i);
61 f.close();
62 SetChannelMap(tmp);
63}
64
66InitStatus ecalDigi::Init()
67{
68 FairRootManager* manager=FairRootManager::Instance();
69 if (!manager)
70 {
71 Fatal("Init()", "Can't find IOManager.");
72 return kFATAL;
73 }
74
75 fStr=(ecalStructure*)manager->GetObject("EcalStructure");
76 if (!fStr)
77 {
78 Fatal("Init()", "Can't find calorimeter structure in the system.");
79 return kFATAL;
80 }
81
82 return kSUCCESS;
83}
84
86{
87 fStr=structure;
88}
89
91void ecalDigi::Exec(Option_t* option)
92{
93 ecalCell* cell;
94 list<ecalCell*> cells;
95 fStr->GetCells(cells);
96 list<ecalCell*>::const_iterator p=cells.begin();
97 Short_t adc;
98
99 for(;p!=cells.end();++p)
100 {
101 cell=(*p);
102 if (fChannelMap.empty())
103 adc=(Short_t)(gRandom->Gaus(cell->GetEnergy(), fADCNoise)/fADCChannel+fPedestal);
104 else
105 if (fChannelMap.find(cell->GetCellNumber())==fChannelMap.end())
106 {
107 Error("Exec", "Channel %d not found in map. Using default value!", cell->GetCellNumber());
108 //TODO: Should we insert Fatal here?
109 adc=(Short_t)(gRandom->Gaus(cell->GetEnergy(), fADCNoise)/fADCChannel+fPedestal);
110 }
111 else
112 {
113 adc=(Short_t)(gRandom->Gaus(cell->GetEnergy(), fADCNoise)/fChannelMap[cell->GetCellNumber()]+fPedestal);
114 }
115 if (adc>fADCMax) adc=fADCMax;
116 cell->SetEnergy(-1111);
117 cell->SetADC(adc);
118 }
119}
120
123{
124 ;
125}
128{
129 ;
130}
131
Int_t GetCellNumber() const
Definition ecalCell.h:40
void SetEnergy(Float_t energy)
Definition ecalCell.h:64
void SetADC(Short_t adc)
Definition ecalCell.h:65
Float_t GetEnergy() const
Definition ecalCell.h:42
ecalStructure * fStr
Definition ecalDigi.h:55
virtual void Finish()
Definition ecalDigi.cxx:122
void SetChannelMap(std::map< Int_t, Float_t > map)
Definition ecalDigi.h:37
virtual void Exec(Option_t *option)
Definition ecalDigi.cxx:91
Float_t fADCNoise
Definition ecalDigi.h:51
virtual InitStatus Init()
Definition ecalDigi.cxx:66
void InitPython(ecalStructure *structure)
Definition ecalDigi.cxx:85
Float_t fADCChannel
Definition ecalDigi.h:53
Short_t fPedestal
Definition ecalDigi.h:47
Short_t fADCMax
Definition ecalDigi.h:49
std::map< Int_t, Float_t > fChannelMap
Definition ecalDigi.h:58
virtual ~ecalDigi()
Definition ecalDigi.cxx:127
void LoadChannelMap(const char *filename)
Definition ecalDigi.cxx:42
void GetCells(std::list< ecalCell * > &cells) const
ClassImp(ecalContFact) ecalContFact