er  dev
ERBeamDetUnpack.cxx
1 #include "ERBeamDetUnpack.h"
2 
3 #include "TClonesArray.h"
4 
5 #include "FairRootManager.h"
6 #include "FairLogger.h"
7 
8 #include "ERDigi.h"
9 
10 //--------------------------------------------------------------------------------------------------
11 ERBeamDetUnpack::ERBeamDetUnpack(const TString& detName)
12  : ERUnpack(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"}})
16 {}
17 //--------------------------------------------------------------------------------------------------
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;
24 }
25 //--------------------------------------------------------------------------------------------------
26 void ERBeamDetUnpack::SetMWPCCalibration(const float A, const float B) {
27  MWPC_time_calibration_A = A;
28  MWPC_time_calibration_B = B;
29 }
30 //--------------------------------------------------------------------------------------------------
31 void ERBeamDetUnpack::Register() {
32  if (!setup_configuration_)
33  LOG(FATAL) << "[ERBeamDetUnpack] Setup was not inited" << FairLogger::endl;
34  FairRootManager* ioman = FairRootManager::Instance();
35  if (!ioman)
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);
42  }
43  if (itSt.first == TString("F5")){
44  digi_collections_["BeamDetToFDigi2"] = new TClonesArray("ERDigi",1000);
45  ioman->Register("BeamDetToFDigi2", "BeamDet", digi_collections_["BeamDetToFDigi2"], kTRUE);
46  }
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);
52  }
53  }
54  }
55 }
56 //--------------------------------------------------------------------------------------------------
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")};
61 }
62 //--------------------------------------------------------------------------------------------------
63 void ERBeamDetUnpack::UnpackSignalFromStations() {
64  UnpackToFStation("F3", "tF3", 1);
65  UnpackToFStation("F5", "tF5", 2);
66  UnpackMWPCStations();
67 }
68 //--------------------------------------------------------------------------------------------------
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],
74  channel_to_signals);
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;
81  }
82  time = CalibrateToF(time * 0.25, tof_number);
83  AddToFDigi(amplitude, time, tof_number);
84  } else {
85  LOG(DEBUG) << "[ERBeamDetUnpack] Wrong PMT number in ToF number " << tof_number << FairLogger::endl;
86  }
87 }
88 //--------------------------------------------------------------------------------------------------
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;
94  } else {
95  LOG(FATAL) << "[ERBeamDetUnpack] Unknown TOF number " << tof_number << FairLogger::endl;
96  }
97 }
98 //--------------------------------------------------------------------------------------------------
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;
108  continue;
109  }
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_));
119  }
120  }
121 }
122 //--------------------------------------------------------------------------------------------------
123 void ERBeamDetUnpack::AddToFDigi(float edep, float time, ushort tof_number) {
124  ERDigi *digi;
125  if(tof_number == 1) {
126  digi = new((*digi_collections_["BeamDetToFDigi1"])[digi_collections_["BeamDetToFDigi1"]->GetEntriesFast()])
127  ERDigi(edep, time, tof_number);
128  }
129  if(tof_number == 2) {
130  digi = new((*digi_collections_["BeamDetToFDigi2"])[digi_collections_["BeamDetToFDigi2"]->GetEntriesFast()])
131  ERDigi(edep, time, tof_number);
132  }
133 }
134 //--------------------------------------------------------------------------------------------------
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);
139 }
140 //--------------------------------------------------------------------------------------------------
141 ClassImp(ERBeamDetUnpack)
Definition: ERDigi.h:15