ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtDecoderSpecMATTask.cxx
Go to the documentation of this file.
1 #include "AtDecoderSpecMATTask.h"
2 
3 // FAIRROOT classes
4 #include <FairRootManager.h>
5 #include <FairRun.h>
6 #include <FairRunAna.h>
7 #include <FairRunOnline.h>
8 #include <FairRuntimeDb.h>
9 
10 constexpr auto cRED = "\033[1;31m";
11 constexpr auto cYELLOW = "\033[1;33m";
12 constexpr auto cNORMAL = "\033[0m";
13 constexpr auto cGREEN = "\033[1;32m";
14 
16 
18 {
19  fLogger = FairLogger::GetLogger();
20 
21  fDecoder = nullptr;
22  fDataNum = 0;
23  // fOpt = 0;
24 
25  fFPNPedestalRMS = -1;
26 
27  fExternalNumTbs = kFALSE;
28  fNumTbs = 512;
29 
30  // fUseGainCalibration = kFALSE;
31  // fGainCalibrationFile = "";
32  // fGainConstant = -9999;
33  // fGainLinear = -9999;
34  // fGainQuadratic = 0;
35 
36  fIsPersistence = kFALSE;
37 
38  fPar = nullptr;
39  fRawEventArray = new TClonesArray("AtRawEvent");
40  fRawEvent = nullptr;
41 
42  fIsSeparatedData = kFALSE;
43  fIsPseudoTopology = kFALSE;
44 
45  fInternalID = 1;
46  fEventID = 0; // For SpecMAT data events start from 1 not 0
47 
48  // fAuxChannels.clear();
49  fNumCobo = 4;
50 
51  for (Int_t i = 0; i < fNumCobo; i++) {
52  fIsCoboPadPlane[i] = kTRUE;
53  fIsPositive[i] = kTRUE;
54  }
55 
56  fMask = 0xF;
57 }
58 
60 {
61  fIsPersistence = value;
62 }
64 {
65  fNumTbs = numTbs;
66  fExternalNumTbs = kTRUE;
67 }
68 void AtDecoderSpecMATTask::AddData(TString filename, Int_t coboIdx)
69 {
70  LOG(debug) << "In task adding file " << filename << " to cobo " << coboIdx;
71  fDataList[coboIdx].push_back(filename);
72 }
74 {
75  fDataNum = value;
76 }
77 void AtDecoderSpecMATTask::SetFPNPedestal(Double_t pedestalRMS)
78 {
79  fFPNPedestalRMS = pedestalRMS;
80 }
82 {
83  for (Int_t i = 0; i < fNumCobo; i++) {
84  fIsPositive[i] = value[i];
85  }
86 }
87 // void AtDecoderSpecMATTask::SetUseGainCalibration(Bool_t value) {
88 // fUseGainCalibration = value; } void
89 // AtDecoderSpecMATTask::SetGainCalibrationData(TString filename) {
90 // fGainCalibrationFile = filename; } void
91 // AtDecoderSpecMATTask::SetGainReference(Double_t constant, Double_t linear,
92 // Double_t quadratic) { fGainConstant = constant; fGainLinear = linear;
93 // fGainQuadratic = quadratic; }
95 {
96  fIsSeparatedData = value;
97 }
98 void AtDecoderSpecMATTask::SetEventID(Long64_t eventid)
99 {
100  fEventID = eventid;
101 }
102 /* Old map style
103 void AtDecoderSpecMATTask::SetGeo(TString geofile)
104 {
105  fGeoFile = geofile;
106 }
107 void AtDecoderSpecMATTask::SetProtoMap(TString mapfile)
108 {
109  fProtoMapFile = mapfile;
110 }
111 void AtDecoderSpecMATTask::SetMapOpt(Int_t value)
112 {
113  fOpt = value;
114 }
115 void AtDecoderSpecMATTask::SetMap(Char_t const *map)
116 {
117  fMap = map;
118 }
119 void AtDecoderSpecMATTask::SetInhibitMaps(TString inimap, TString lowgmap, TString xtalkmap)
120 {
121  fIniMap = inimap;
122  fLowgMap = lowgmap;
123  fXtalkMap = xtalkmap;
124 }
125 
126 void AtDecoderSpecMATTask::SetAuxChannels(std::vector<Int_t> AuxCh)
127 {
128  fAuxChannels = AuxCh;
129 }
130 */
132 {
133  fIsPseudoTopology = value;
134 }
135 
137 {
138  fNumCobo = numCobo;
139 }
140 
142 {
143  for (Int_t i = 0; i < fNumCobo; i++) {
144  fIsCoboPadPlane[i] = IsPadPlane[i];
145  }
146 }
148 {
149  fMask = mask;
150 }
151 
153 {
154  return fEventIDLast;
155 }
156 
158 {
159  FairRootManager *ioMan = FairRootManager::Instance();
160  if (ioMan == 0) {
161  LOG(error) << "Cannot find RootManager!";
162 
163  return kERROR;
164  }
165 
166  fDecoder = std::make_unique<AtCoreSpecMAT>(fMap);
167  fDecoder->SetNumCobo(fNumCobo);
168  fDecoder->SetIsPadPlaneCobo(fIsCoboPadPlane);
169  fDecoder->SetPositivePolarity(fIsPositive);
170 
171  for (Int_t iFile = 0; iFile < fDataList[0].size(); iFile++)
172  fDecoder->AddData(fDataList[0].at(iFile));
173 
174  LOG(debug) << "After adding data filename is: " << fDecoder->GetFileName();
175 
176  if (fIsPseudoTopology)
177  fDecoder->SetPseudoTopologyFrame(fMask, kFALSE);
178 
179  fDecoder->SetData(fDataNum);
180 
181  LOG(debug) << "After setting data filename is: " << fDecoder->GetFileName();
182 
183  if (fExternalNumTbs)
184  fDecoder->SetNumTbs(fNumTbs);
185  else
186  fDecoder->SetNumTbs(fPar->GetNumTbs());
187 
188  if (fFPNPedestalRMS == -1)
189  // fFPNPedestalRMS = fPar -> GetFPNPedestalRMS();
190  fFPNPedestalRMS = 5;
191 
192  fDecoder->SetFPNPedestal(fFPNPedestalRMS);
193 
194  if (fMap == nullptr) {
195  LOG(error) << "SpecMAT Map was never set!";
196  return kERROR;
197  } else
198  fDecoder->SetMap(fMap);
199 
200  ioMan->Register("AtRawEvent", "AtTPC", fRawEventArray, fIsPersistence);
201  LOG(debug) << "At end of init filename is: " << fDecoder->GetFileName();
202  return kSUCCESS;
203 }
204 
206 {
207  FairRun *run = FairRun::Instance();
208  if (!run)
209  LOG(fatal) << "No analysis run!";
210 
211  FairRuntimeDb *db = run->GetRuntimeDb();
212  if (!db)
213  LOG(fatal) << "No runtime database!";
214 
215  fPar = (AtDigiPar *)db->getContainer("AtDigiPar");
216  if (!fPar)
217  LOG(fatal) << "Cannot find AtDigiPar!";
218 }
219 
220 void AtDecoderSpecMATTask::Exec(Option_t *opt)
221 {
222  fRawEventArray->Delete();
223  std::cout << "Start of SpecMAT decoder task for event " << fEventID + 1 << std::endl;
224  if (fRawEvent == nullptr)
225  fRawEvent = fDecoder->GetRawEvent(fEventID++);
226  fInternalID++;
227  // if (fInternalID % 100 == 0)
228  std::cout << " Event Number " << fEventID << " Internal ID : " << fInternalID
229  << " Number of Pads : " << fRawEvent->GetNumPads() << std::endl;
230 
231  new ((*fRawEventArray)[0]) AtRawEvent(*fRawEvent);
232 
233  fRawEvent = nullptr;
234 
235  LOG(debug) << "Finished unpacking event";
236 }
237 
239 {
240  fRawEventArray->Delete();
241 
242  fRawEvent = fDecoder->GetRawEvent(eventID);
243  fEventIDLast = fDecoder->GetEventID();
244 
245  if (fRawEvent == nullptr)
246  return 1;
247 
248  new ((*fRawEventArray)[0]) AtRawEvent(*fRawEvent);
249 
250  return 0;
251 }
252 
254 {
255  fRawEvent = fDecoder->GetRawEvent();
256 
257  if (fRawEvent == nullptr) {
258  LOG(info) << "End of file. Terminating FairRun.";
259  FairRootManager::Instance()->SetFinishRun();
260  }
261 }
AtDecoderSpecMATTask::AddData
void AddData(TString filename, Int_t coboIdx=0)
Adding raw data file to the list.
Definition: AtDecoderSpecMATTask.cxx:68
AtDecoderSpecMATTask::AtDecoderSpecMATTask
AtDecoderSpecMATTask()
Constructor.
Definition: AtDecoderSpecMATTask.cxx:17
AtDecoderSpecMATTask::ReadEvent
Int_t ReadEvent(Int_t eventID)
Read event for AtSource.
Definition: AtDecoderSpecMATTask.cxx:238
cRED
constexpr auto cRED
Definition: AtDecoderSpecMATTask.cxx:10
AtDecoderSpecMATTask.h
AtDecoderSpecMATTask::SetUseSeparatedData
void SetUseSeparatedData(Bool_t value=kTRUE)
Setting to use not merged data files.
Definition: AtDecoderSpecMATTask.cxx:94
cGREEN
constexpr auto cGREEN
Definition: AtDecoderSpecMATTask.cxx:13
AtDecoderSpecMATTask::SetParContainers
virtual void SetParContainers()
Definition: AtDecoderSpecMATTask.cxx:205
AtDecoderSpecMATTask::SetNumCobo
void SetNumCobo(Int_t numCobo)
Definition: AtDecoderSpecMATTask.cxx:136
AtDecoderSpecMATTask::Init
virtual InitStatus Init()
Definition: AtDecoderSpecMATTask.cxx:157
AtRawEvent
Definition: AtRawEvent.h:34
AtDecoderSpecMATTask::SetPTFMask
void SetPTFMask(Int_t mask)
Definition: AtDecoderSpecMATTask.cxx:147
AtDecoderSpecMATTask
Definition: AtDecoderSpecMATTask.h:23
AtDigiPar
Definition: AtDigiPar.h:14
AtDecoderSpecMATTask::SetEventID
void SetEventID(Long64_t eventid=-1)
Setting event id for STSource.
Definition: AtDecoderSpecMATTask.cxx:98
ClassImp
ClassImp(AtDecoderSpecMATTask)
AtDecoderSpecMATTask::SetData
void SetData(Int_t value)
Setting which data to be decoded.
Definition: AtDecoderSpecMATTask.cxx:73
cYELLOW
constexpr auto cYELLOW
Definition: AtDecoderSpecMATTask.cxx:11
AtDecoderSpecMATTask::SetPositivePolarity
void SetPositivePolarity(Bool_t *value)
Definition: AtDecoderSpecMATTask.cxx:81
AtDecoderSpecMATTask::FinishEvent
virtual void FinishEvent()
Finishing the event.
Definition: AtDecoderSpecMATTask.cxx:253
AtRawEvent::GetNumPads
Int_t GetNumPads() const
Definition: AtRawEvent.h:122
AtDecoderSpecMATTask::Exec
virtual void Exec(Option_t *opt)
Definition: AtDecoderSpecMATTask.cxx:220
AtDecoderSpecMATTask::SetPseudoTopologyFrame
void SetPseudoTopologyFrame(Bool_t value)
Definition: AtDecoderSpecMATTask.cxx:131
AtDecoderSpecMATTask::SetNumTbs
void SetNumTbs(Int_t numTbs)
Setting the number of time buckets used when taking data.
Definition: AtDecoderSpecMATTask.cxx:63
AtDecoderSpecMATTask::SetFPNPedestal
void SetFPNPedestal(Double_t rms)
Setting the FPN RMS value cut for pedestal region taking.
Definition: AtDecoderSpecMATTask.cxx:77
AtDecoderSpecMATTask::SetPersistence
void SetPersistence(Bool_t value=kTRUE)
If set, decoded raw data is written in ROOT file with AtRawEvent class.
Definition: AtDecoderSpecMATTask.cxx:59
AtDecoderSpecMATTask::GetEventID
Long64_t GetEventID()
Definition: AtDecoderSpecMATTask.cxx:152
AtDecoderSpecMATTask::SetIsCoboPadPlane
void SetIsCoboPadPlane(Bool_t *IsPadPlane)
Definition: AtDecoderSpecMATTask.cxx:141
cNORMAL
constexpr auto cNORMAL
Definition: AtDecoderSpecMATTask.cxx:12