1 #include "ERTelescopeUnpack.h" 5 #include "TClonesArray.h" 7 #include "FairRootManager.h" 8 #include "FairLogger.h" 10 #include "DetEventFull.h" 11 #include "DetEventStation.h" 12 #include "DetMessage.h" 14 #include "ERSupport.h" 18 ERTelescopeUnpack::ERTelescopeUnpack(TString detName):
21 ERTelescopeUnpack::~ERTelescopeUnpack(){
22 for (
auto itStation : fStations){
24 delete itStation.second;
28 void ERTelescopeUnpack::Register() {
29 if (fStations.size() == 0)
30 LOG(FATAL) <<
"No Stations in ERTelescopeUnpack !" << FairLogger::endl;
32 LOG(FATAL) <<
"Error in ERTelescopeUnpack setup checking !" << FairLogger::endl;
34 LOG(FATAL) <<
"Problem in ReadCalFiles!" << FairLogger::endl;
39 std::vector<TString> ERTelescopeUnpack::InputBranchNames()
const {
40 std::vector<TString> station_names;
41 for (
const auto& it_station : fStations) {
42 auto* station = it_station.second;
43 for (
const auto& station_name : {station->ampStName, station->timeStName,
44 station->ampStName2, station->timeStName2}) {
45 if (station_name !=
"") {
46 station_names.push_back(station_name);
53 void ERTelescopeUnpack::CreateDigisFromRawStations(
54 const TString& er_station,
const TString& er_branch_name,
55 const TString& amp_station,
const TString& time_station,
56 TMatrixD* amp_cal_table, TMatrixD* time_cal_table,
57 const ChannelMapping* channel_mapping,
bool skip_alone_channels) {
58 ChannelToAmpTime channel_to_signals;
59 UnpackAmpTimeStation(signals_from_stations_[amp_station],
60 signals_from_stations_[time_station],
63 for (
const auto it : channel_to_signals){
64 const auto raw_channel = it.first;
65 const auto raw_amp = it.second.first;
66 const auto raw_time = it.second.second;
67 const auto amp_and_time = ApplyCalibration(raw_channel, raw_amp, raw_time,
68 amp_cal_table, time_cal_table);
69 AddDigi(amp_and_time.first, amp_and_time.second,
70 GetChannelNumber(it.first, channel_mapping), er_branch_name);
74 void ERTelescopeUnpack::UnpackSignalFromStations() {
75 for (
auto itStation : fStations) {
76 LOG(DEBUG) << itStation.first <<
" unpacking ..." << FairLogger::endl;
77 const auto* station = itStation.second;
78 CreateDigisFromRawStations(itStation.first, station->bName, station->ampStName, station->timeStName,
79 station->ampCalTable, station->timeCalTable, itStation.second->channelsMapping1,
80 station->skipAloneChannels);
81 if (station->sideCount == 2) {
82 CreateDigisFromRawStations(itStation.first, station->bName2, station->ampStName2, station->timeStName2,
83 station->ampCalTable2, station->timeCalTable2, itStation.second->channelsMapping2,
84 station->skipAloneChannels);
89 void ERTelescopeUnpack::AddDigi(
float edep,
float time, ERChannel stripNb, TString digiBranchName)
91 new((*digi_collections_[digiBranchName])
92 [digi_collections_[digiBranchName]->GetEntriesFast()])
ERDigi(edep, time, stripNb);
95 TString ERTelescopeUnpack::FormBranchName(TString type, Int_t sideCount, TString stName,
96 TString XY, TString XYside) {
99 branch_name.Form(
"TelescopeDigi_%s_%s",detector_name_.Data(),stName.Data());
101 if (sideCount == 1) {
102 branch_name.Form(
"TelescopeDigi_%s_SingleSi_%s_%s",detector_name_.Data(),stName.Data(),
105 branch_name.Form(
"TelescopeDigi_%s_DoubleSi_%s_%s_%s",detector_name_.Data(), stName.Data(),
106 XY.Data(), XYside.Data());
112 void ERTelescopeUnpack::AddSingleSiStation(TString name, TString ampStName, TString timeStName,
113 TString ampCalFile, TString timeCalFile, TString XYside,
114 ChannelMapping* channelsMapping,
115 Bool_t skipAloneChannels){
116 ERTelescopeStation* st =
new ERTelescopeStation(
"Si", 1, ampStName, timeStName,
"",
"", ampCalFile, timeCalFile,
"",
"",
"", XYside,
117 channelsMapping,
nullptr, skipAloneChannels);
118 fStations[name] = st;
121 void ERTelescopeUnpack::AddDoubleSiStation(TString name, TString ampStName, TString timeStName,
122 TString ampStName2, TString timeStName2, TString ampCalFile, TString timeCalFile,
123 TString ampCalFile2, TString timeCalFile2, TString XY,
124 ChannelMapping* channelsMapping1,
125 ChannelMapping* channelsMapping2,
126 Bool_t skipAloneChannels){
128 ampCalFile2, timeCalFile2, XY,
"", channelsMapping1, channelsMapping2, skipAloneChannels);
129 fStations[name] = st;
132 void ERTelescopeUnpack::AddCsIStation(TString name,TString ampStName, TString timeStName, TString ampCalFile, TString timeCalFile,
133 ChannelMapping* channelsMapping , Bool_t skipAloneChannels){
134 ERTelescopeStation* st =
new ERTelescopeStation(
"CsI", -1, ampStName, timeStName,
"",
"", ampCalFile, timeCalFile,
"",
"",
"",
"",
135 channelsMapping,
nullptr, skipAloneChannels);
136 fStations[name] = st;
139 void ERTelescopeUnpack::FormAllBranches(){
140 FairRootManager* ioman = FairRootManager::Instance();
141 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
142 for (
auto itStation : fStations){
143 if( itStation.second->sideCount == 2){
144 if (itStation.second->XY ==
"XY"){
145 itStation.second->bName = FormBranchName(
"Si",2,itStation.first,
"XY",
"X");
146 itStation.second->bName2 = FormBranchName(
"Si",2,itStation.first,
"XY",
"Y");
149 itStation.second->bName = FormBranchName(
"Si",2,itStation.first,
"XY",
"Y");
150 itStation.second->bName2 = FormBranchName(
"Si",2,itStation.first,
"XY",
"X");
154 itStation.second->bName = FormBranchName(itStation.second->type,
155 itStation.second->sideCount,
157 itStation.second->XYside);
160 for (
auto itStation : fStations){
161 TString bName = itStation.second->bName;
162 if (itStation.second->type ==
"Si") {
163 digi_collections_[bName] =
new TClonesArray(
"ERDigi", 10);
164 ioman->Register(bName,detector_name_, digi_collections_[bName], kTRUE);
165 if (itStation.second->sideCount == 2){
166 TString bName2 = itStation.second->bName2;
167 digi_collections_[bName2] =
new TClonesArray(
"ERDigi", 10);
168 ioman->Register(bName2,detector_name_, digi_collections_[bName2], kTRUE);
171 if (itStation.second->type ==
"CsI") {
172 digi_collections_[bName] =
new TClonesArray(
"ERDigi", 10);
173 ioman->Register(bName,detector_name_, digi_collections_[bName], kTRUE);
178 void ERTelescopeUnpack::DumpStationsInfo(){
179 LOG(INFO) <<
"!!! Stations info: " << FairLogger::endl;
180 for (
auto itStation : fStations){
181 LOG(INFO) <<
"\t" << itStation.first << FairLogger::endl;
182 LOG(INFO) <<
"\t\ttype : " << itStation.second->type << FairLogger::endl <<
183 "\t\tsideCount : " << itStation.second->sideCount << FairLogger::endl <<
184 "\t\tampStName : " << itStation.second->ampStName << FairLogger::endl <<
185 "\t\ttimeStName : " << itStation.second->timeStName << FairLogger::endl <<
186 "\t\tampStName2 : " << itStation.second->ampStName2 << FairLogger::endl <<
187 "\t\ttimeStName2 : " << itStation.second->timeStName2 << FairLogger::endl <<
188 "\t\tXY : " << itStation.second->XY << FairLogger::endl <<
189 "\t\tXYside : " << itStation.second->XYside << FairLogger::endl <<
190 "\t\tbName : " << itStation.second->bName << FairLogger::endl <<
191 "\t\tbName2 : " << itStation.second->bName2 << FairLogger::endl;
192 if (itStation.second->ampCalTable){
193 LOG(INFO) <<
"\t\tampCalFile : " << itStation.second->ampCalFile << FairLogger::endl;
194 LOG(INFO) <<
"\t\tampCalTable : " << FairLogger::endl;
195 itStation.second->ampCalTable->Print();
197 if (itStation.second->timeCalTable){
198 LOG(INFO) <<
"\t\ttimeCalFile : " << itStation.second->timeCalFile << FairLogger::endl;
199 LOG(INFO) <<
"\t\ttimeCalTable : " << FairLogger::endl;
200 itStation.second->timeCalTable->Print();
202 if (itStation.second->ampCalTable2){
203 LOG(INFO) <<
"\t\tampCalFile2 : " << itStation.second->ampCalFile2 << FairLogger::endl;
204 LOG(INFO) <<
"\t\tampCalTable2 : " << FairLogger::endl;
205 itStation.second->ampCalTable2->Print();
207 if (itStation.second->timeCalTable2){
208 LOG(INFO) <<
"\t\ttimeCalFile2 : " << itStation.second->timeCalFile2 << FairLogger::endl;
209 LOG(INFO) <<
"\t\ttimeCalTable2 : " << FairLogger::endl;
210 itStation.second->timeCalTable2->Print();
215 ERTelescopeStation::ERTelescopeStation(TString _type, Int_t _sideCount, TString _ampStName, TString _timeStName,
216 TString _ampStName2, TString _timeStName2, TString _ampCalFile, TString _timeCalFile,
217 TString _ampCalFile2, TString _timeCalFile2, TString _XY, TString _XYside,
218 ChannelMapping* _channelsMapping1, ChannelMapping* _channelsMapping2,
219 Bool_t _skipAloneChannels):
221 sideCount(_sideCount),
222 ampStName(_ampStName),
223 timeStName(_timeStName),
224 ampStName2(_ampStName2),
225 timeStName2(_timeStName2),
226 ampCalFile(_ampCalFile),
227 timeCalFile(_timeCalFile),
228 ampCalFile2(_ampCalFile2),
229 timeCalFile2(_timeCalFile2),
234 channelsMapping1(_channelsMapping1),
235 channelsMapping2(_channelsMapping2),
236 skipAloneChannels(_skipAloneChannels)
240 Bool_t ERTelescopeUnpack::ReadCalFiles(){
241 for (
auto itStation : fStations){
243 if (itStation.second->ampCalFile !=
""){
244 itStation.second->ampCalTable = ReadCalFile(itStation.second->ampCalFile);
245 if (!itStation.second->ampCalTable)
249 if (itStation.second->timeCalFile !=
""){
250 itStation.second->timeCalTable = ReadCalFile(itStation.second->timeCalFile);
251 if (!itStation.second->timeCalTable)
255 if (itStation.second->sideCount == 2 && itStation.second->ampCalFile2 !=
""){
256 itStation.second->ampCalTable2 = ReadCalFile(itStation.second->ampCalFile2);
257 if (!itStation.second->ampCalTable2)
261 if (itStation.second->sideCount == 2 && itStation.second->timeCalFile2 !=
""){
262 itStation.second->timeCalTable2 = ReadCalFile(itStation.second->timeCalFile2);
263 if (!itStation.second->timeCalTable2)
271 std::pair<float, float> ERTelescopeUnpack::
272 ApplyCalibration(ERChannel channel, Signal amp, Signal time,
273 TMatrixD* ampCalTable, TMatrixD* timeCalTable) {
274 std::pair<float, float> amp_and_time = {
static_cast<float>(amp) , static_cast<float>(time)};
276 if (channel >= ampCalTable->GetNrows()){
277 LOG(FATAL) <<
"Channel " << channel <<
" not found in amplitude calibration table of detector " 278 << detector_name_ << FairLogger::endl;
280 amp_and_time.first = amp_and_time.first *
static_cast<float>((*ampCalTable)[channel][1]) + static_cast<float>((*ampCalTable)[channel][0]);
283 if (channel >= timeCalTable->GetNrows()){
284 LOG(FATAL) <<
"Channel " << channel <<
" not found in time calibration table of detector " 285 << detector_name_ << FairLogger::endl;
287 amp_and_time.second = amp_and_time.second *
static_cast<float>((*timeCalTable)[channel][1]) + static_cast<float>((*timeCalTable)[channel][0]);
292 Bool_t ERTelescopeUnpack::CheckSetup() {
293 const std::map<TString, unsigned short> stationsInConfig = setup_configuration_->GetStationList(detector_name_);
294 for (
auto itStation : fStations){
296 if (stationsInConfig.find(station->ampStName) == stationsInConfig.end()){
297 LOG(FATAL) <<
"Amplitude station " << station->ampStName <<
298 " of telescope " << detector_name_ <<
299 " not found in setup configuration file" << FairLogger::endl;
302 if (station->timeStName !=
""){
303 if (stationsInConfig.find(station->timeStName) == stationsInConfig.end()){
304 LOG(FATAL) <<
"Time station " << station->timeStName <<
305 " of telescope " << detector_name_ <<
306 " not found in setup configuration file" << FairLogger::endl;
310 if (station->sideCount == 2){
311 if (stationsInConfig.find(station->ampStName2) == stationsInConfig.end()){
312 LOG(FATAL) <<
"Amplitude station " << station->ampStName2 <<
313 " of telescope " << detector_name_ <<
314 " not found in setup configuration file" << FairLogger::endl;
317 if (station->timeStName2 !=
""){
318 if (stationsInConfig.find(station->timeStName2) == stationsInConfig.end()){
319 LOG(FATAL) <<
"Time station " << station->timeStName2 <<
320 " of telescope " << detector_name_ <<
321 " not found in setup configuration file" << FairLogger::endl;
327 for (
auto itConfSt : stationsInConfig){
328 TString stationName = itConfSt.first;
329 Bool_t found = kFALSE;
330 for (
auto itStation : fStations){
332 if (station->ampStName == stationName ||
333 station->timeStName == stationName ||
334 station->ampStName2 == stationName ||
335 station->timeStName2 == stationName)
336 LOG(WARNING) <<
"Station " << stationName <<
" in setup file, but not defined to unpack!" << FairLogger::FairLogger::endl;