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