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