8 #include "ERNXyterTreeSource.h" 10 #include "FairRootManager.h" 11 #include "cls_RootHit.h" 13 #include "ERNXyterCalibrator.h" 18 ERNXyterTreeSource::ERNXyterTreeSource() :
27 fNonLinGraphsFileName(
""),
30 for (Int_t i = 0; i < 64; i++) {
34 fPedestalsCorrection[0] = 25;
35 fPedestalsCorrection[1] = 19;
36 fPedestalsCorrection[2] = 23;
37 fPedestalsCorrection[3] = 21;
38 fPedestalsCorrection[4] = 21;
39 fPedestalsCorrection[5] = 19;
40 fPedestalsCorrection[6] = 27;
41 fPedestalsCorrection[7] = 25;
42 fPedestalsCorrection[8] = 23;
43 fPedestalsCorrection[9] = -3;
44 fPedestalsCorrection[10] = 27;
45 fPedestalsCorrection[11] = 23;
46 fPedestalsCorrection[12] = 1;
47 fPedestalsCorrection[13] = 1;
48 fPedestalsCorrection[14] = 3;
49 fPedestalsCorrection[15] = 23;
50 fPedestalsCorrection[16] = 27;
51 fPedestalsCorrection[17] = 19;
52 fPedestalsCorrection[18] = 25;
53 fPedestalsCorrection[19] = 17;
54 fPedestalsCorrection[20] = 19;
55 fPedestalsCorrection[21] = 29;
56 fPedestalsCorrection[22] = 15;
57 fPedestalsCorrection[23] = 21;
58 fPedestalsCorrection[24] = 19;
59 fPedestalsCorrection[25] = 25;
60 fPedestalsCorrection[26] = 1;
61 fPedestalsCorrection[27] = 21;
62 fPedestalsCorrection[28] = 21;
63 fPedestalsCorrection[29] = 19;
64 fPedestalsCorrection[30] = 17;
65 fPedestalsCorrection[31] = 3;
66 fPedestalsCorrection[32] = 17;
67 fPedestalsCorrection[33] = 21;
68 fPedestalsCorrection[34] = 21;
69 fPedestalsCorrection[35] = 25;
70 fPedestalsCorrection[36] = 21;
71 fPedestalsCorrection[37] = 23;
72 fPedestalsCorrection[38] = 15;
73 fPedestalsCorrection[39] = 23;
74 fPedestalsCorrection[40] = 15;
75 fPedestalsCorrection[41] = 19;
76 fPedestalsCorrection[42] = -1;
77 fPedestalsCorrection[43] = 15;
78 fPedestalsCorrection[44] = 15;
79 fPedestalsCorrection[45] = -3;
80 fPedestalsCorrection[46] = 19;
81 fPedestalsCorrection[47] = 11;
82 fPedestalsCorrection[48] = 23;
83 fPedestalsCorrection[49] = 19;
84 fPedestalsCorrection[50] = 19;
85 fPedestalsCorrection[51] = 15;
86 fPedestalsCorrection[52] = 19;
87 fPedestalsCorrection[53] = 3;
88 fPedestalsCorrection[54] = 21;
89 fPedestalsCorrection[55] = 25;
90 fPedestalsCorrection[56] = 27;
91 fPedestalsCorrection[57] = 17;
92 fPedestalsCorrection[58] = 19;
93 fPedestalsCorrection[59] = 17;
94 fPedestalsCorrection[60] = -3;
95 fPedestalsCorrection[61] = 17;
96 fPedestalsCorrection[62] = 13;
97 fPedestalsCorrection[63] = 21;
101 ERNXyterTreeSource::~ERNXyterTreeSource() {
105 Bool_t ERNXyterTreeSource::Init() {
109 Fatal(
"ERNXyterTreeSource::Init",
"No files for source ERNXyterTreeSource");
110 fFile =
new TFile(fPath);
111 if (!fFile->IsOpen()) {
112 Fatal(
"ERNXyterTreeSource::Init",
"Can`t open file for source ERNXyterTreeSource");
116 fTree = (TTree*)fFile->Get(fTreeName);
118 Fatal(
"ERNXyterTreeSource::Init",
"Can`t find tree in input file for source ERNXyterTreeSource");
121 fTree->SetBranchAddress(fBranchName.Data(),&fInEvent);
126 FairRootManager* ioman = FairRootManager::Instance();
129 ioman->Register(fBranchName.Data(),
"RawEvents", fInEvent, kTRUE);
130 ioman->Register(
"outBranch.",
"RawEvents", fOutEvent, kTRUE);
132 ImportCalParameters();
133 ImportNonLinGraphs();
138 Int_t ERNXyterTreeSource::ReadEvent(UInt_t) {
142 if ( !(fEvent%100000) ) {
143 std::cout <<
"####### EVENT " << fEvent <<
" #####" << std::endl;
146 if (fTree->GetEntriesFast() == fEvent+1) {
147 std::cout <<
"####### EVENT " << fEvent <<
" #####" << std::endl;
151 fTree->GetEntry(fEvent);
154 TClonesArray *rawHits = fInEvent->GetHits();
158 Float_t adcNonLin, adcNonLinCorr, adcCalibrated;
163 for (Int_t i = 0; i <= rawHits->GetLast(); i++) {
167 channel = rawHit->GetChannel();
168 adcVal = rawHit->GetAdcVal();
169 adcNonLin = ERNXyterCalibrator::Instance().GetCalibratedVal(channel, adcVal);
170 adcNonLinCorr = adcNonLin - fPedestalsCorrection[channel];
172 adcCalibrated = (adcNonLinCorr+calRandom.Uniform(-0.5, 0.5))/fCalPar[channel];
180 fOutEvent->AddHit(channel, adcVal, adcNonLin, adcNonLinCorr, adcCalibrated);
191 void ERNXyterTreeSource::Close() {
198 void ERNXyterTreeSource::Reset() {
206 void ERNXyterTreeSource::SetInFile(TString path, TString treeName, TString branchName){
208 fTreeName = treeName;
209 fBranchName = branchName;
210 cout <<
"Input file " << path <<
" with tree name " << fTreeName <<
" and branch name " <<
211 fBranchName <<
" added to source ERNXyterTreeSource" << endl;
214 void ERNXyterTreeSource::SetCalParameters(
const char* p_filename)
216 fCalParFileName = p_filename;
219 void ERNXyterTreeSource::SetNonLinGraphs(
const char* graph_filename) {
220 fNonLinGraphsFileName = graph_filename;
223 void ERNXyterTreeSource::ImportCalParameters() {
225 if (fCalParFileName.Length()==0) {
226 Warning(
"ERNXyterTreeSource::ImportCalParameters",
227 "File with 1e calibration parameters was not set.");
231 Info(
"ERNXyterTreeSource::ImportCalParameters",
232 "Importing calibration parameters from file %s corrected for %f.",
233 fCalParFileName.Data(), f1ePosCorrection);
235 std::ifstream infile(fCalParFileName.Data());
236 if (!infile.is_open()) {
237 Error(
"ERNXyterTreeSource::ImportCalParameters",
"File %s was not open.", fCalParFileName.Data());
244 for (
unsigned int i=0; i<64; i++) {
246 fCalPar[ch] = val/f1ePosCorrection;
252 void ERNXyterTreeSource::ImportNonLinGraphs() {
254 if (fNonLinGraphsFileName.Length()==0) {
255 Warning(
"ERNXyterTreeSource::ImportNonLinGraphs",
"File with graphs for non-linearity correction was not set.");
259 Info(
"ERNXyterTreeSource::ImportNonLinGraphs",
"Importing graphs for non-linearity correction from file %s.", fNonLinGraphsFileName.Data());
261 ERNXyterCalibrator::Instance().ImportGraphs(fNonLinGraphsFileName);
264 void ERNXyterTreeSource::PrintCalParameters() {
265 cout <<
"channel\tparameter" << endl;
266 for (Int_t i = 0; i<64; i++) {
267 cout << i <<
"\t" << fCalPar[i] << endl;