GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
CalFileFromILL.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
6#include <vector>
7
8#include "TChannel.h"
9#include "TFipps.h"
10
11int main(int argc, char** argv)
12{
13 if(argc < 4) {
14 std::cerr << "Usage: " << argv[0] << " <LUT file> <cal file(s)> <cross talk file>" << std::endl;
15 return 1;
16 }
17
18 std::stringstream str;
19 std::string line;
20
21 TChannel* channel = nullptr;
22
23 int adc;
24 int detType;
25 int detNumber;
26 int cryNumber;
27 int globId;
28 int timeOffset;
29
30 //////////////////////////////////////// look up table ////////////////////////////////////////
31 std::ifstream lutFile(argv[1]);
32
33 while(std::getline(lutFile, line)) {
34 if(line.empty() || std::all_of(line.begin(), line.end(), [](char c) { return std::isspace(c); }) || line[0] == '#') continue;
35
36 str.clear();
37 str.str(line);
38
39 str >> adc >> detType >> detNumber >> cryNumber >> globId >> timeOffset; // ignoring rangemin, rangemax at the end of the line
40 //std::cout<<"line \""<<line<<"\" adc "<<adc<<", detType "<<detType<<", cryNumber "<<cryNumber<<", globId "<<globId<<", timeOffset "<<timeOffset<<std::endl;
41
42 // Detector Types:
43 // -- 0 -> NotUsed
44 // -- 1 -> FIPPS Ge
45 // -- 2 -> IFIN Ge
46 // -- 3 -> FIPPS AC
47 // -- 4 -> IFIN AC
48 // -- 5 -> Fission Tag
49 // -- 6 -> LaBr3
50 // -- 7 -> TAC
51 //
52 // In case of AC, CloverId -> Associated clover
53 //
54 // DetId: 0->3 for Ge
55 // 0 for IFIN AC
56 // 0->2 for FIPPS AC (Back, Front, Side)
57 // id for TAG, LaBr3, TAC
58
59 str.clear();
60 str.str(std::string());
61 //std::cout<<"cleared - "<<str.str()<<std::endl;
62 switch(detType) {
63 case 1: // FIPPS Ge
64 str << "FIG";
65 break;
66 case 2: // IFIN Ge
67 str << "IFG";
68 break;
69 case 3: // FIPPS BGO
70 str << "FIS";
71 break;
72 case 4: // IFIN BGO
73 str << "IFS";
74 break;
75 default:
76 std::cerr << "unknown detector type " << detType << std::endl;
77 continue;
78 }
79 //std::cout<<"system - "<<str.str()<<std::endl;
80 str << std::setfill('0') << std::setw(2) << detNumber + 1; // LUT starts counting at 0, cal file starts at 1
81 //std::cout<<"detector # - "<<str.str()<<std::endl;
82 if(detType == 1 || detType == 2) { // Ge detectors - set crystals as colors
83 str << TFipps::GetColorFromNumber(cryNumber);
84 } else {
85 str << std::setw(1) << cryNumber;
86 }
87 //std::cout<<"crystal - "<<str.str()<<std::endl;
88 str << "N00X";
89 //std::cout<<"final - "<<str.str()<<std::endl;
90 channel = new TChannel(str.str().c_str());
91 channel->SetAddress((adc / 16) * 0x40 + adc % 16);
92 channel->SetNumber(TPriorityValue<int>(globId + 1, EPriority::kForce));
95 TChannel::AddChannel(channel);
96 //channel->Print();
97 }
98
99 //////////////////////////////////////// energy calibration ////////////////////////////////////////
100 Float_t tmpFloat;
101 std::vector<Float_t> coefficients;
102 int minRange = 0;
103 int maxRange = 30000;
104 for(int i = 2; i < argc - 1; ++i) {
105 std::ifstream calFile(argv[i]);
106 //std::cout<<"Opened energy calibration file '"<<argv[i]<<"' for range "<<i-2<<std::endl;
107 while(std::getline(calFile, line)) {
108 // erase all trailing whitespace
109 line.erase(std::find_if(line.rbegin(), line.rend(), [](int ch) { return !std::isspace(ch); }).base(), line.end());
110
111 if(line.empty() || std::all_of(line.begin(), line.end(), [](char c) { return std::isspace(c); }) || line[0] == '#') continue;
112
113 str.clear();
114 str.str(line);
115 str >> globId;
116 channel = TChannel::GetChannelByNumber(globId + 1);
117 if(channel != nullptr) {
118 if(i == 2) {
119 channel->DestroyENGCal();
120 channel->ResizeENG(argc - 3); // -3 = program itself, LUT file, and cross talk file
121 //std::cout<<"resized ENG to "<<argc-3<<" - "<<channel->GetMnemonic()->GetName()<<std::endl;
122 }
123 //std::cout<<"Setting "<<i-2<<" energy coefficients for channel "<<globId+1<<" - "<<channel->GetMnemonic()->GetName()<<std::endl;
124 //std::cout<<"From line \""<<line<<"\": "<<std::endl;
125 while(str.good()) {
126 str >> tmpFloat;
127 coefficients.push_back(tmpFloat);
128 }
129 //for(auto val : coefficients) std::cout<<val<<"\t";
130 //std::cout<<std::endl;
131 // we only expect the last two columns to be the ranges if we have more than one cal-file
132 if(argc > 4) {
133 maxRange = coefficients.back();
134 coefficients.pop_back();
135 minRange = coefficients.back();
136 coefficients.pop_back();
137 }
138 channel->SetENGCoefficients(coefficients, i - 2);
139 coefficients.clear();
140 channel->Print();
141 //std::cout<<minRange<<"-"<<maxRange<<std::endl;
142 channel->SetENGRange(std::make_pair(minRange, maxRange), i - 2);
143 channel->Print();
144 } else {
145 std::cerr << "Failed to find detector ID " << globId + 1 << " in TChannel" << std::endl;
146 }
147 }
148 }
149
150 //////////////////////////////////////// cross talk ////////////////////////////////////////
151 std::ifstream xTalkFile(argv[argc - 1]);
152 detNumber = 1;
153 int col;
154 int row;
155 double val;
156 while(std::getline(xTalkFile, line)) {
157 if(line.empty() || std::all_of(line.begin(), line.end(), [](char c) { return std::isspace(c); }) || line[0] == '#') continue;
158
159 str.clear();
160 str.str(line);
161 str >> col >> row >> val;
162 //std::cout<<"from line \""<<line<<"\" got col "<<col<<", row "<<row<<", val "<<val<<std::endl;
163
164 // col = affected crystal, row = affecting crystal
165 if(row == 0) {
166 channel = TChannel::FindChannelByName(Form("FIG%02d%sN00X", detNumber, TFipps::GetColorFromNumber(col)));
167 if(channel == nullptr) {
168 channel = TChannel::FindChannelByName(Form("IFG%02d%sN00X", detNumber, TFipps::GetColorFromNumber(col)));
169 }
170 if(channel == nullptr) {
171 std::cerr << "Failed to find channel \"" << Form("FI/IFG%02d%sN00X", detNumber, TFipps::GetColorFromNumber(col)) << "\"" << std::endl;
172 std::cerr << "Got color " << TFipps::GetColorFromNumber(col) << " from number " << col << std::endl;
173 break;
174 }
175 channel->DestroyCTCal();
176
177 //std::cout<<"destroyed cross talk coefficients for channel "<<channel->GetMnemonic()->GetName()<<std::endl;
178 }
179 channel->AddCTCoefficient(val);
180 if(col == 3 && row == 3) ++detNumber;
181 }
182
183 //std::cout<<std::endl<<"done"<<std::endl<<std::endl;
184
186}
int main(int argc, char **argv)
void AddCTCoefficient(double temp)
Definition TChannel.h:214
static void WriteCalFile(const std::string &outfilename="")
Definition TChannel.cxx:992
void SetAddress(unsigned int tmpadd)
Definition TChannel.cxx:540
void SetTimeOffset(const TPriorityValue< Long64_t > &tmp)
Definition TChannel.h:154
void DestroyENGCal()
Definition TChannel.cxx:554
static TChannel * FindChannelByName(const char *ccName)
Definition TChannel.cxx:494
void Print(Option_t *opt="") const override
Definition TChannel.cxx:833
void ResizeENG(size_t size)
Definition TChannel.h:217
void SetNumber(const TPriorityValue< int > &tmp)
Definition TChannel.h:139
static TChannel * GetChannelByNumber(int temp_num)
Definition TChannel.cxx:482
void SetENGCoefficients(const std::vector< Float_t > &tmp, size_t range=0)
Definition TChannel.h:225
void DestroyCTCal()
Definition TChannel.cxx:587
static void AddChannel(TChannel *, Option_t *opt="")
Definition TChannel.cxx:285
void SetENGRange(const std::pair< double, double > &tmp, const size_t &range)
Definition TChannel.h:231
void SetDigitizerType(const TPriorityValue< std::string > &tmp)
static const char * GetColorFromNumber(int number)
Definition TFipps.cxx:578