1 #include "ERNDUnpack.h" 8 #include "FairRootManager.h" 9 #include "FairLogger.h" 11 #include "DetEventFull.h" 12 #include "DetEventStation.h" 13 #include "DetMessage.h" 15 #include "ERDetectorList.h" 17 #include "ERSupport.h" 20 ERNDUnpack::ERNDUnpack(TString detName, TString ampStation, TString timeStation, TString tacStation,
21 TString ampCalFile, TString timeCalFile, TString tacCalFile,
22 ChannelMapping* channelsMapping ,
23 Bool_t skipAloneChannels) :
25 fAmpStation(ampStation),
26 fTimeStation(timeStation),
27 fTACStation(tacStation),
28 fChannelMapping(channelsMapping),
29 fSkipAloneChannels(skipAloneChannels)
32 fAmpCalTable = ReadCalFile(ampCalFile);
33 if (timeCalFile !=
"")
34 fTimeCalTable = ReadCalFile(timeCalFile);
36 fTACCalTable = ReadCalFile(tacCalFile);
39 void ERNDUnpack::Register() {
40 FairRootManager* ioman = FairRootManager::Instance();
41 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
42 digi_collections_[
"NDDigis"] =
new TClonesArray(
"ERNDDigi", 10);
43 ioman->Register(
"NDDigi",
"ND", digi_collections_[
"NDDigis"], kTRUE );
45 Fatal(
"Init",
"Error in ERNDUnpack setup checking !");
48 std::vector<TString> ERNDUnpack::InputBranchNames()
const {
49 return {fAmpStation, fTimeStation, fTACStation};
52 void ERNDUnpack::UnpackSignalFromStations() {
53 ChannelToAmpTimeTac channel_to_signals;
54 UnpackAmpTimeTACStation(signals_from_stations_[fAmpStation],
55 signals_from_stations_[fTimeStation],
56 signals_from_stations_[fTACStation],
59 for (
auto itValue : channel_to_signals) {
60 ERChannel channel = itValue.first;
62 std::tie(amp, time, tac) = itValue.second;
63 ApplyCalibrations(channel, amp , time, tac);
64 AddNDDigi(amp,time,tac, GetChannelNumber(channel, fChannelMapping));
68 void ERNDUnpack::ApplyCalibrations(
const ERChannel channel,
float& amp,
float& time,
float& tac) {
69 const auto applyCalibration = [
this, channel](
float& value,
const TMatrixD* table) {
72 if (channel >= table->GetNrows()){
73 LOG(FATAL) <<
"Channel " << channel <<
" not found in amplitude calibration table of detector " 74 << detector_name_ << FairLogger::endl;
76 value = value*(*table)[channel][1] + (*table)[channel][0];
78 applyCalibration(amp, fAmpCalTable);
79 applyCalibration(time, fTimeCalTable);
80 applyCalibration(tac, fTACCalTable);
83 void ERNDUnpack::AddNDDigi(
const float edep,
const float time,
const float tac,
84 const ERChannel channelNb) {
85 auto* digiCollection = digi_collections_[
"NDDigis"];
86 new((*digiCollection) [digiCollection->GetEntriesFast()])
87 ERNDDigi(channelNb, edep, -1. , time, -1. , tac);
90 Bool_t ERNDUnpack::CheckSetup() {
91 const auto stationsInConfig = setup_configuration_->GetStationList(detector_name_);
92 const auto stationInConfig = [stationsInConfig,
this](
const TString stationName,
94 if (stationsInConfig.find(stationName) == stationsInConfig.end()){
95 LOG(FATAL) << type <<
" station " << stationName <<
" of ND " << detector_name_
96 <<
" not found in setup configuration file" << FairLogger::endl;
101 if (!stationInConfig(fAmpStation,
"Amplitude"))
103 if (!stationInConfig(fTimeStation,
"Time"))
105 if (!stationInConfig(fTACStation,
"TAC"))