MdADCCalibration.cc
Go to the documentation of this file.
1 #include <utl/ErrorLogger.h>
2 #include <utl/UTMPoint.h>
3 #include <fwk/CentralConfig.h>
4 
5 #include <evt/Event.h>
6 #include <mevt/MEvent.h>
7 #include <mevt/Counter.h>
8 #include <mevt/Module.h>
9 #include <utl/Branch.h>
10 #include <utl/ConfigUtils.h>
11 
12 #include "MdADCCalibration.h"
13 
14 using namespace fwk;
15 using namespace utl;
16 using namespace MdADCCalibrationAG;
17 
18 namespace MdADCCalibrationAG {
19 
22 {
23  // Configuration reading
24  utl::Branch config = fwk::CentralConfig::GetInstance()->GetTopBranch("MdADCCalibration");
25 
26  LoadConfig(config, "useOfflineCalibration", fUseOfflineCalibration, 0);
27  LoadConfig(config, "useOnlineCalibration", fUseOnlineCalibration, 1);
28 
29  // Fill the fUseOfflineCalibration map from the configuration file
30  if (fUseOfflineCalibration) {
31  utl::Branch calibrationLG = config.GetChild("moduleOfflineCalibrationLG");
32  for (utl::Branch b = calibrationLG.GetFirstChild(); b; b = b.GetNextSibling()) {
33  utl::AttributeMap attibutes = b.GetAttributes();
34  const int counterId = det::VManager::FindComponent<unsigned int>("counterId", attibutes);
35  const int moduleId = det::VManager::FindComponent<unsigned int>("moduleId", attibutes);
36  const int globalModuleId = counterId*1000 + moduleId;
37  const double calibration = b.Get<double>();
38  fModuleOfflineCalibrationLG[globalModuleId] = calibration;
39  }
40 
41  utl::Branch calibrationHG = config.GetChild("moduleOfflineCalibrationHG");
42  for (utl::Branch b = calibrationHG.GetFirstChild(); b; b = b.GetNextSibling()) {
43  utl::AttributeMap attibutes = b.GetAttributes();
44  const int counterId = det::VManager::FindComponent<unsigned int>("counterId", attibutes);
45  const int moduleId = det::VManager::FindComponent<unsigned int>("moduleId", attibutes);
46  const int globalModuleId = counterId*1000 + moduleId;
47  const double calibration = b.Get<double>();
48  fModuleOfflineCalibrationHG[globalModuleId] = calibration;
49  }
50 
51  utl::Branch resolutionLG = config.GetChild("moduleOfflineResolutionLG");
52  for (utl::Branch b = resolutionLG.GetFirstChild(); b; b = b.GetNextSibling()) {
53  utl::AttributeMap attibutes = b.GetAttributes();
54  const int counterId = det::VManager::FindComponent<unsigned int>("counterId", attibutes);
55  const int moduleId = det::VManager::FindComponent<unsigned int>("moduleId", attibutes);
56  const int globalModuleId = counterId*1000 + moduleId;
57  const double resolution = b.Get<double>();
58  fModuleOfflineResolutionLG[globalModuleId] = resolution;
59  }
60 
61  utl::Branch resolutionHG = config.GetChild("moduleOfflineResolutionHG");
62  for (utl::Branch b = resolutionHG.GetFirstChild(); b; b = b.GetNextSibling()) {
63  utl::AttributeMap attibutes = b.GetAttributes();
64  const int counterId = det::VManager::FindComponent<unsigned int>("counterId", attibutes);
65  const int moduleId = det::VManager::FindComponent<unsigned int>("moduleId", attibutes);
66  const int globalModuleId = counterId*1000 + moduleId;
67  const double resolution = b.Get<double>();
68  fModuleOfflineResolutionHG[globalModuleId] = resolution;
69  }
70 
71  }
72  return eSuccess;
73 }
74 
76  MdADCCalibration::Run(evt::Event& event)
77  {
78 
79  if (!event.HasMEvent()) {
80  WARNING("\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
81  return eContinueLoop;
82  }
83 
84  INFO("Starting");
85  std::ostringstream os;
86 
87  mevt::MEvent& me = event.GetMEvent();
88 
89  for (mevt::MEvent::CounterIterator ic = me.CountersBegin(), ec = me.CountersEnd(); ic != ec; ++ic) {
90 
91  mevt::Counter& counter = *ic;
92  const int counterId = counter.GetId();
93 
94  if (counter.IsRejected()) {
95  os.str("");
96  os << "Skipping the rejected counter " << counterId << " .";
97  INFO(os);
98  continue;
99  }
100 
101  os.str("");
102  os << "Processing counter " << counterId;
103  INFO(os);
104 
105 
106  for (mevt::Counter::ModuleIterator im = counter.ModulesBegin(), em = counter.ModulesEnd(); im != em; ++im) {
107 
108  DEBUGLOG("Starting module loop");
109  mevt::Module& module = *im;
110  const int moduleId = module.GetId();
111 
112  os.str("");
113  os << "Processing module " << moduleId;
114  DEBUGLOG(os);
115 
116 
117  if (module.IsRejected()) {
118  os.str("");
119  os << "Module " << module.GetId() << " of counter " << counterId;
120  os << " discarded because flagged as: " << module.GetRejectionReason();
121  WARNING(os);
122  continue;
123  }
124 
125  // Load calibration into the event
126  LoadModuleCalibration(counter, module);
127 
128  } // end module loop
129  } // end counter loop
130  return eSuccess;
131 }
132 
133 
135 MdADCCalibration::Finish()
136 {
137  return eSuccess;
138 }
139 
140 
141 void MdADCCalibration::LoadModuleCalibration(mevt::Counter& counter, mevt::Module& module)
142 {
143 
144 
145  double calibrationA = 0.0;
146  double calibrationB = 0.0;
147  double resolutionA = 0.0;
148  double resolutionB = 0.0;
149 
150 
151  if(fUseOnlineCalibration)
152  {
153  GetOnlineCalibration(calibrationA, resolutionA, calibrationB, resolutionB, module);
154  }
155 
156  if (calibrationA == 0.0 && fUseOfflineCalibration)
157  {
158  GetOfflineCalibration(calibrationA, resolutionA, calibrationB, resolutionB, counter, module);
159 
160  }
161 
162  // Set results in event
163  mevt::ModuleRecData& mRecData = module.GetRecData();
164 
165  mRecData.SetMeanChargeMuonHG(calibrationB);
166  mRecData.SetStdDevChargeMuonHG(resolutionB);
167  mRecData.SetMeanChargeMuonLG(calibrationA);
168  mRecData.SetStdDevChargeMuonLG(resolutionA);
169 
170 
171 
172  std::ostringstream os;
173  os.str("");
174  os << "Mean charge muon ADC LG " << calibrationA << ", StdDev = " << resolutionA
175  << "Mean charge muon ADC HG " << calibrationB << ", StdDev = " << resolutionB;
176  INFO(os);
177 }
178 
179 void MdADCCalibration::GetOfflineCalibration(double& calibrationA, double& resolutionA, double& calibrationB, double& resolutionB, mevt::Counter& counter, mevt::Module& module)
180 {
181  std::ostringstream os;
182  const int globalModuleId = counter.GetId()*1000 + module.GetId();
183  if(fModuleOfflineCalibrationLG.find(globalModuleId) != fModuleOfflineCalibrationLG.end())
184  {
185  calibrationA = fModuleOfflineCalibrationLG[globalModuleId];
186  }else
187  {
188  calibrationA = fModuleOfflineCalibrationLG[0];
189  os.str("");
190  os << "Module " << module.GetId() << " of counter " << counter.GetId();
191  os << " uses global calibration";
192  WARNING(os);
193  }
194 
195  if(fModuleOfflineResolutionLG.find(globalModuleId) != fModuleOfflineResolutionLG.end())
196  {
197  resolutionA = fModuleOfflineResolutionLG[globalModuleId];
198  }else
199  {
200  resolutionA = fModuleOfflineResolutionLG[0];
201  }
202 
203  if(fModuleOfflineCalibrationHG.find(globalModuleId) != fModuleOfflineCalibrationHG.end())
204  {
205  calibrationB = fModuleOfflineCalibrationHG[globalModuleId];
206  }else
207  {
208  calibrationB = fModuleOfflineCalibrationHG[0];
209  }
210 
211  if(fModuleOfflineResolutionHG.find(globalModuleId) != fModuleOfflineResolutionHG.end())
212  {
213  resolutionB = fModuleOfflineResolutionHG[globalModuleId];
214  }else
215  {
216  resolutionB = fModuleOfflineResolutionHG[0];
217  }
218 }
219 
220 void MdADCCalibration::GetOnlineCalibration(double& calibrationA, double& resolutionA, double& calibrationB, double& resolutionB, mevt::Module& module)
221 {
222 
223  if(module.GetId()>0){
224  calibrationA = 0.0;
225  resolutionA = 0.0;
226  calibrationB = 0.0;
227  resolutionB = 0.0;
228  }
229 
230 
231  /*
232  * This method has to be implemented. The integration of the online calibration into CDAS is not yet ready, so I do not know what kind of data
233  * I will be receiving in this instance.
234  *
235  * The noise histogram has to be subtracted from the charge histogram to obtain the calibration histogram from which the mean value
236  * and StdDev give the calibration and resolution. There are 6 histograms in total, 3 for the low gain channel and 3 for the high gain channel
237  *
238  *
239  * You can check GAP_2019_046 to see how this is performed,
240  *
241  * */
242 
243  /*const int moduleId = module.GetId();
244  const vector<CalibrationData> dataCalib = module.GetCalibrationData()
245  if(dataCalib.size() > 0)
246  {
247  int nroBins = 1000;
248  double xminA = -1000;
249  double xmaxA = 3000;
250  double binSizeA = (xmaxA-xminA)/(double) nroBins;
251 
252  double xminB = -6000;
253  double xmaxB = 10000;
254  double binSizeB = (xmaxB-xminB)/(double) nroBins;
255 
256 
257  int histogramChargeA[nroBins];
258  int histogramChargeB[nroBins];
259  int histogramNoiseA[nroBins];
260  int histogramNoiseB[nroBins];
261  int histogramCalibrationA[nroBins];
262  int histogramCalibrationB[nroBins];
263 
264  for(calib_iterator calibIt = dataCalib.begin() ; calibIt != dataCalib.end() ; ++calibIt)
265  {
266 
267 
268  }
269  }
270 
271  */
272 
273 
274 }
275 
276 
277 
278 
279 } // end namespace
Module level reconstruction data. This class contains all data required by the muon reconstruction...
Definition: ModuleRecData.h:29
CounterConstIterator CountersBegin() const
Definition: MEvent.h:49
void SetMeanChargeMuonHG(const double charge)
bool HasMEvent() const
void SetStdDevChargeMuonHG(const double charge)
Counter level event data.
std::map< std::string, std::string > AttributeMap
Definition: Branch.h:24
std::string GetRejectionReason() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
int GetId() const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
void SetMeanChargeMuonLG(const double charge)
Class representing a document branch.
Definition: Branch.h:107
void SetStdDevChargeMuonLG(const double charge)
Module level event data.
Definition: MEvent/Module.h:41
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
InternalModuleCollection::ComponentIterator ModuleIterator
ModuleConstIterator ModulesBegin() const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
InternalCounterCollection::ComponentIterator CounterIterator
Definition: MEvent.h:31
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
ModuleRecData & GetRecData()
bool IsRejected() const
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
Definition: ConfigUtils.h:35
CounterConstIterator CountersEnd() const
Definition: MEvent.h:52
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
Root of the Muon event hierarchy.
Definition: MEvent.h:25
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.