REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorSignalChannelActivityProcess.cxx
1 /*************************************************************************
2  * This file is part of the REST software framework. *
3  * *
4  * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5  * For more information see http://gifna.unizar.es/trex *
6  * *
7  * REST is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * REST is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have a copy of the GNU General Public License along with *
18  * REST in $REST_PATH/LICENSE. *
19  * If not, see http://www.gnu.org/licenses/. *
20  * For the list of contributors see $REST_PATH/CREDITS. *
21  *************************************************************************/
22 
79 #include "TRestDetectorSignalChannelActivityProcess.h"
80 
81 using namespace std;
82 
84 
89 
103  const char* configFilename) {
104  Initialize();
105 
106  if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
107 }
108 
113  delete fSignalEvent;
114 }
115 
120 
126  SetSectionName(this->ClassName());
127  SetLibraryVersion(LIBRARY_VERSION);
128 
129  fSignalEvent = new TRestDetectorSignalEvent();
130 }
131 
144 void TRestDetectorSignalChannelActivityProcess::LoadConfig(const string& configFilename, const string& name) {
145  if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
146 }
147 
156  fReadout = GetMetadata<TRestDetectorReadout>();
157 
158  RESTDebug << "TRestDetectorSignalChannelActivityProcess::InitProcess. Readout pointer : " << fReadout
159  << RESTendl;
160  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info && fReadout)
161  fReadout->PrintMetadata();
162 
163  if (!fReadOnly) {
164  fDaqChannelsHisto = new TH1D("daqChannelActivity", "daqChannelActivity", fDaqHistogramChannels,
165  fDaqStartChannel, fDaqEndChannel);
166  if (fReadout) {
167  fReadoutChannelsHisto =
168  new TH1D("rChannelActivity", "readoutChannelActivity", fReadoutHistogramChannels,
169  fReadoutStartChannel, fReadoutEndChannel);
170  fReadoutChannelsHisto_OneSignal =
171  new TH1D("rChannelActivity_1", "readoutChannelActivity", fReadoutHistogramChannels,
172  fReadoutStartChannel, fReadoutEndChannel);
173  fReadoutChannelsHisto_OneSignal_High =
174  new TH1D("rChannelActivity_1H", "readoutChannelActivity", fReadoutHistogramChannels,
175  fReadoutStartChannel, fReadoutEndChannel);
176  fReadoutChannelsHisto_TwoSignals =
177  new TH1D("rChannelActivity_2", "readoutChannelActivity", fReadoutHistogramChannels,
178  fReadoutStartChannel, fReadoutEndChannel);
179  fReadoutChannelsHisto_TwoSignals_High =
180  new TH1D("rChannelActivity_2H", "readoutChannelActivity", fReadoutHistogramChannels,
181  fReadoutStartChannel, fReadoutEndChannel);
182  fReadoutChannelsHisto_ThreeSignals =
183  new TH1D("rChannelActivity_3", "readoutChannelActivity", fReadoutHistogramChannels,
184  fReadoutStartChannel, fReadoutEndChannel);
185  fReadoutChannelsHisto_ThreeSignals_High =
186  new TH1D("rChannelActivity_3H", "readoutChannelActivity", fReadoutHistogramChannels,
187  fReadoutStartChannel, fReadoutEndChannel);
188  fReadoutChannelsHisto_MultiSignals =
189  new TH1D("rChannelActivity_M", "readoutChannelActivity", fReadoutHistogramChannels,
190  fReadoutStartChannel, fReadoutEndChannel);
191  fReadoutChannelsHisto_MultiSignals_High =
192  new TH1D("rChannelActivity_MH", "readoutChannelActivity", fReadoutHistogramChannels,
193  fReadoutStartChannel, fReadoutEndChannel);
194  }
195  }
196 }
197 
202  TString obsName;
203 
204  TRestDetectorSignalEvent* fInputSignalEvent = (TRestDetectorSignalEvent*)inputEvent;
205 
207 
208  fSignalEvent->SetID(fInputSignalEvent->GetID());
209  fSignalEvent->SetSubID(fInputSignalEvent->GetSubID());
210  fSignalEvent->SetTimeStamp(fInputSignalEvent->GetTimeStamp());
211  fSignalEvent->SetSubEventTag(fInputSignalEvent->GetSubEventTag());
212 
213  Int_t N = fInputSignalEvent->GetNumberOfSignals();
214  for (int sgnl = 0; sgnl < N; sgnl++) fSignalEvent->AddSignal(*fInputSignalEvent->GetSignal(sgnl));
216 
217  Int_t Nlow = 0;
218  Int_t Nhigh = 0;
219  for (int s = 0; s < fSignalEvent->GetNumberOfSignals(); s++) {
220  TRestDetectorSignal* sgnl = fSignalEvent->GetSignal(s);
221  if (sgnl->GetMaxValue() > fHighThreshold) Nhigh++;
222  if (sgnl->GetMaxValue() > fLowThreshold) Nlow++;
223  }
224 
225  for (int s = 0; s < fSignalEvent->GetNumberOfSignals(); s++) {
226  TRestDetectorSignal* sgnl = fSignalEvent->GetSignal(s);
227  // Adding signal to the channel activity histogram
228  if (!fReadOnly && fReadout) {
229  Int_t signalID = fSignalEvent->GetSignal(s)->GetID();
230 
231  Int_t p, m, readoutChannel;
232  fReadout->GetPlaneModuleChannel(signalID, p, m, readoutChannel);
233 
234  fReadoutChannelsHisto->Fill(readoutChannel);
235 
236  if (sgnl->GetMaxValue() > fLowThreshold) {
237  if (Nlow == 1) fReadoutChannelsHisto_OneSignal->Fill(readoutChannel);
238  if (Nlow == 2) fReadoutChannelsHisto_TwoSignals->Fill(readoutChannel);
239  if (Nlow == 3) fReadoutChannelsHisto_ThreeSignals->Fill(readoutChannel);
240  if (Nlow > 3 && Nlow < 10) fReadoutChannelsHisto_MultiSignals->Fill(readoutChannel);
241  }
242 
243  if (sgnl->GetMaxValue() > fHighThreshold) {
244  if (Nhigh == 1) fReadoutChannelsHisto_OneSignal_High->Fill(readoutChannel);
245  if (Nhigh == 2) fReadoutChannelsHisto_TwoSignals_High->Fill(readoutChannel);
246  if (Nhigh == 3) fReadoutChannelsHisto_ThreeSignals_High->Fill(readoutChannel);
247  if (Nhigh > 3 && Nhigh < 10) fReadoutChannelsHisto_MultiSignals_High->Fill(readoutChannel);
248  }
249  }
250 
251  if (!fReadOnly) {
252  Int_t daqChannel = fSignalEvent->GetSignal(s)->GetID();
253  fDaqChannelsHisto->Fill(daqChannel);
254  }
255  }
256 
257  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
258  fAnalysisTree->PrintObservables();
259 
260  return fSignalEvent;
261 }
262 
269  if (!fReadOnly) {
270  fDaqChannelsHisto->Write();
271  if (fReadout) {
272  fReadoutChannelsHisto->Write();
273 
274  fReadoutChannelsHisto_OneSignal->Write();
275  fReadoutChannelsHisto_TwoSignals->Write();
276  fReadoutChannelsHisto_ThreeSignals->Write();
277  fReadoutChannelsHisto_MultiSignals->Write();
278 
279  fReadoutChannelsHisto_OneSignal_High->Write();
280  fReadoutChannelsHisto_TwoSignals_High->Write();
281  fReadoutChannelsHisto_ThreeSignals_High->Write();
282  fReadoutChannelsHisto_MultiSignals_High->Write();
283  }
284  }
285 }
286 
292  fLowThreshold = StringToDouble(GetParameter("lowThreshold", "25"));
293  fHighThreshold = StringToDouble(GetParameter("highThreshold", "50"));
294 
295  fDaqHistogramChannels = StringToInteger(GetParameter("daqChannels", "300"));
296  fDaqStartChannel = StringToInteger(GetParameter("daqStartCh", "4320"));
297  fDaqEndChannel = StringToInteger(GetParameter("daqEndCh", "4620"));
298  fReadoutHistogramChannels = StringToInteger(GetParameter("readoutChannels", "128"));
299  fReadoutStartChannel = StringToInteger(GetParameter("readoutStartCh", "0"));
300  fReadoutEndChannel = StringToInteger(GetParameter("readoutEndCh", "128"));
301 }
A pure analysis process to generate histograms with detector channels activity.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
void Initialize() override
Function to initialize input/output event members and define the section name.
void InitFromConfigFile() override
Function to read input parameters from the RML TRestDetectorSignalChannelActivityProcess metadata sec...
void EndProcess() override
Function to include required actions after all events have been processed. In this process it will ta...
void InitProcess() override
Process initialization. The ROOT TH1 histograms are created here using the limits defined in the proc...
A base class for any REST event.
Definition: TRestEvent.h:38
@ REST_Info
+show most of the information for each steps
@ REST_Debug
+show the defined debug messages
Double_t StringToDouble(std::string in)
Gets a double from a string.
Int_t StringToInteger(std::string in)
Gets an integer from a string.