1 #include "ERBeamDetUnpack.h" 3 #include "TClonesArray.h" 5 #include "FairRootManager.h" 6 #include "FairLogger.h" 11 ERBeamDetUnpack::ERBeamDetUnpack(
const TString& detName)
13 mwpc_amplitude_station_to_time_channel_({{
"MWPC1", 0}, {
"MWPC2", 1}, {
"MWPC3", 2}, {
"MWPC4", 3}}),
14 mwpc_branch_names_({{
"MWPC1",
"BeamDetMWPCDigiX1"}, {
"MWPC2",
"BeamDetMWPCDigiY1"},
15 {
"MWPC3",
"BeamDetMWPCDigiX2"}, {
"MWPC4",
"BeamDetMWPCDigiY2"}})
18 void ERBeamDetUnpack::SetToFCalibration(
const float F3_A,
const float F3_B,
19 const float F5_A,
const float F5_B) {
20 F3_time_calibration_A = F3_A;
21 F3_time_calibration_B = F3_B;
22 F5_time_calibration_A = F5_A;
23 F5_time_calibration_B = F5_B;
26 void ERBeamDetUnpack::SetMWPCCalibration(
const float A,
const float B) {
27 MWPC_time_calibration_A = A;
28 MWPC_time_calibration_B = B;
31 void ERBeamDetUnpack::Register() {
32 if (!setup_configuration_)
33 LOG(FATAL) <<
"[ERBeamDetUnpack] Setup was not inited" << FairLogger::endl;
34 FairRootManager* ioman = FairRootManager::Instance();
36 LOG(FATAL) <<
"[ERBeamDetUnpack] No FairRootManager" << FairLogger::endl;
37 const std::map<TString, unsigned short> stList = setup_configuration_->GetStationList(detector_name_);
38 for (
auto itSt : stList){
39 if (itSt.first == TString(
"F3")){
40 digi_collections_[
"BeamDetToFDigi1"] =
new TClonesArray(
"ERDigi",1000);
41 ioman->Register(
"BeamDetToFDigi1",
"BeamDet", digi_collections_[
"BeamDetToFDigi1"], kTRUE);
43 if (itSt.first == TString(
"F5")){
44 digi_collections_[
"BeamDetToFDigi2"] =
new TClonesArray(
"ERDigi",1000);
45 ioman->Register(
"BeamDetToFDigi2",
"BeamDet", digi_collections_[
"BeamDetToFDigi2"], kTRUE);
47 for (
auto itMwpcStation : mwpc_amplitude_station_to_time_channel_){
48 TString bName = mwpc_branch_names_.at(itMwpcStation.first);
49 if (itSt.first == itMwpcStation.first){
50 digi_collections_[bName] =
new TClonesArray(
"ERDigi",1000);
51 ioman->Register(bName,
"BeamDet", digi_collections_[bName], kTRUE);
57 std::vector<TString> ERBeamDetUnpack::InputBranchNames()
const {
58 return {TString(
"F3"), TString(
"tF3"), TString(
"F5"), TString(
"tF5"),
59 TString(
"tMWPC"), TString(
"MWPC1"), TString(
"MWPC2"),
60 TString(
"MWPC3"), TString(
"MWPC4")};
63 void ERBeamDetUnpack::UnpackSignalFromStations() {
64 UnpackToFStation(
"F3",
"tF3", 1);
65 UnpackToFStation(
"F5",
"tF5", 2);
69 void ERBeamDetUnpack::UnpackToFStation(
const TString& amplitude_station,
70 const TString& time_station,
const ushort tof_number) {
71 ChannelToAmpTime channel_to_signals;
72 UnpackAmpTimeStation(signals_from_stations_[amplitude_station],
73 signals_from_stations_[time_station],
75 if (channel_to_signals.size() == 4) {
76 float time = 0., amplitude = 0.;
77 for (
const auto channel_to_amplitude_and_time : channel_to_signals) {
78 const auto amplitude_and_time = channel_to_amplitude_and_time.second;
79 amplitude += amplitude_and_time.first;
80 time += amplitude_and_time.second;
82 time = CalibrateToF(time * 0.25, tof_number);
83 AddToFDigi(amplitude, time, tof_number);
85 LOG(DEBUG) <<
"[ERBeamDetUnpack] Wrong PMT number in ToF number " << tof_number << FairLogger::endl;
89 float ERBeamDetUnpack::CalibrateToF(
const float time,
const ushort tof_number) {
90 if (tof_number == 1) {
91 return time * F3_time_calibration_A + F3_time_calibration_B;
92 }
else if (tof_number == 2) {
93 return time * F5_time_calibration_A + F5_time_calibration_B;
95 LOG(FATAL) <<
"[ERBeamDetUnpack] Unknown TOF number " << tof_number << FairLogger::endl;
99 void ERBeamDetUnpack::UnpackMWPCStations() {
100 ChannelToSignal channels_to_time_signals;
101 UnpackStation(signals_from_stations_[
"tMWPC"], channels_to_time_signals);
102 for (
const auto& amplitude_station_and_time_channel : mwpc_amplitude_station_to_time_channel_) {
103 const auto& amplitude_station = amplitude_station_and_time_channel.first;
104 const auto time_channel = amplitude_station_and_time_channel.second;
105 if (channels_to_time_signals.find(time_channel) == channels_to_time_signals.end()) {
106 LOG(DEBUG) <<
"[ERBeamDetUnpack] MWPC time signal not found for amplitude station " 107 << amplitude_station << FairLogger::endl;
110 ChannelToSignal channels_to_amplitude_signals;
111 UnpackStation(signals_from_stations_[amplitude_station], channels_to_amplitude_signals);
112 for (
const auto channel_and_signal_from_amplitude_station : channels_to_amplitude_signals) {
113 const auto channel = channel_and_signal_from_amplitude_station.first;
114 auto amplitude = channel_and_signal_from_amplitude_station.second;
115 float time = channels_to_time_signals[time_channel] * MWPC_time_calibration_A
116 + MWPC_time_calibration_B;
117 AddMWPCDigi(amplitude, time, amplitude_station,
118 GetChannelNumber(channel, &mwpc_channels_mapping_));
123 void ERBeamDetUnpack::AddToFDigi(
float edep,
float time, ushort tof_number) {
125 if(tof_number == 1) {
126 digi =
new((*digi_collections_[
"BeamDetToFDigi1"])[digi_collections_[
"BeamDetToFDigi1"]->GetEntriesFast()])
127 ERDigi(edep, time, tof_number);
129 if(tof_number == 2) {
130 digi =
new((*digi_collections_[
"BeamDetToFDigi2"])[digi_collections_[
"BeamDetToFDigi2"]->GetEntriesFast()])
131 ERDigi(edep, time, tof_number);
135 void ERBeamDetUnpack::AddMWPCDigi(
float edep,
float time, TString mwpcSt, Int_t wireNb) {
136 TString bName = mwpc_branch_names_.at(mwpcSt);
137 new((*digi_collections_[bName])[digi_collections_[bName]->GetEntriesFast()])
138 ERDigi(edep, time, wireNb+1);