R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCheckMapping.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
16#include <FairRootManager.h>
17#include <TClonesArray.h>
18
19#include <iostream>
20#include <sstream>
21#include <stdlib.h>
22
23#define TIME_HVON_MAX 5
24#define PLANE_START 12
25#define PLANE_END 13
26
28 : FairTask("NeulandCheckMapping", 1)
29 , timestamp0(0)
30 , timestamp1(0)
31 , fMapped(NULL)
32 , fTrigger(-1)
33{
34}
35
36R3BNeulandCheckMapping::R3BNeulandCheckMapping(const char* name, Int_t iVerbose)
37 : FairTask(name, iVerbose)
38 , timestamp0(0)
39 , timestamp1(0)
40 , fMapped(NULL)
41 , fTrigger(-1)
42{
43}
44
46
48{
49 std::cout << "Init " << std::endl;
50
51 FairRootManager* rm = FairRootManager::Instance();
52 if (!rm)
53 {
54 return kFATAL;
55 }
56
57 header = (R3BEventHeader*)rm->GetObject("EventHeader.");
58
59 fMapped = (TClonesArray*)rm->GetObject("NeulandMappedData");
60 if (!fMapped)
61 {
62 return kFATAL;
63 }
64
65 h_countsok = new TH1F("countsok", "countsok", 1200, 0.5, 1200.5);
66
67 std::cout << "Setting all vtargets to -1...\n";
68 for (Int_t pln = 0; pln < fNofPlanes; pln++)
69 {
70 for (Int_t bar = 0; bar < fPaddlesPerPlane; bar++)
71 {
72 for (Int_t pmt = 0; pmt < 2; pmt++)
73 {
74
75 std::ostringstream oss;
76 oss << "nl:hv:p" << pln + 1 << "b" << bar + 1 << "t" << pmt + 1;
77
78 auto vmon = oss.str() + ":vmon";
79 auto vtarget = oss.str() + ":vtarget.A";
80
81 auto& entry = ca[pln][bar][pmt];
82 entry.group = epics.CreateGroup();
83
84 entry.vmon = entry.group->CreateChannel(vmon);
85 entry.vtarget = entry.group->CreateChannel(vtarget);
86
87 entry.vtarget->Set(-1);
88 entry.group->Commit();
89
90 cntOk[pln][bar][pmt] = 0;
91 }
92 }
93 }
94 std::cout << "Waiting for tubes to go down...\n";
95 for (Int_t pln = 0; pln < fNofPlanes; pln++)
96 {
97 for (Int_t bar = 0; bar < fPaddlesPerPlane; bar++)
98 {
99 for (Int_t pmt = 0; pmt < 2; pmt++)
100 {
101
102 auto& entrycheck = ca[pln][bar][pmt];
103
104 for (;;)
105 {
106 std::cout << "#";
107 entrycheck.group->Fetch();
108 if (entrycheck.vmon->Get() < 20.)
109 break;
110 sleep(1);
111 }
112 }
113 }
114 }
115 std::cout << "\nAll off! Enabling the first tube...\n";
116 iPlnHvOn = PLANE_START;
117 iBarHvOn = 0;
118 iPmtHvOn = 0;
119 auto& entryon = ca[iPlnHvOn][iBarHvOn][iPmtHvOn];
120 entryon.vtarget->Set(1050);
121 entryon.group->Commit();
122 for (;;)
123 {
124 entryon.group->Fetch();
125 if (fabs(entryon.vmon->Get() - entryon.vtarget->Get()) < 15.)
126 break;
127 sleep(1);
128 }
129 timestamp0.Set();
130 std::cout << "Done! Ready to rumble.\n";
131
132 finished = false;
133
134 return kSUCCESS;
135}
136
137void R3BNeulandCheckMapping::Exec(Option_t* option)
138{
139 if (finished)
140 FinishTask();
141
142 timestamp1.Set();
143
144 // test git ig, delete after test!
145
146 // std::cout << "Exec " << iPlnHvOn << " B " << iBarHvOn << " T " << iPmtHvOn << std::endl;
147
148 std::cout << "Exec ts0=" << timestamp0 << " ts1=" << timestamp1 << " diff=" << difftime(timestamp1, timestamp0)
149 << std::endl;
150
151 if (difftime(timestamp1, timestamp0) > TIME_HVON_MAX)
152 {
153
154 std::cout << "5 seconds? " << std::endl;
155
156 auto& entryoff = ca[iPlnHvOn][iBarHvOn][iPmtHvOn];
157 entryoff.vtarget->Set(-1);
158 entryoff.group->Commit();
159
160 for (;;)
161 {
162 std::cout << ".";
163 entryoff.group->Fetch();
164 if (entryoff.vmon->Get() < 20.)
165 break;
166 sleep(1);
167 }
168
169 iBarHvOn++;
170
171 if (iBarHvOn == fPaddlesPerPlane)
172 {
173 iBarHvOn = 0;
174 iPmtHvOn++;
175 if (iPmtHvOn == 2)
176 {
177 iPmtHvOn = 0;
178 iPlnHvOn++;
179 if (iPlnHvOn > PLANE_END)
180 {
181 finished = true;
182 iPlnHvOn = fNofPlanes - 1;
183 iBarHvOn = fPaddlesPerPlane - 1;
184 iPmtHvOn = 1;
185 std::cout << "ALL DONE!" << std::endl;
186 }
187 }
188 }
189
190 if (finished)
191 FinishTask();
192
193 std::cout << "Enabling " << iPlnHvOn << ':' << iBarHvOn << ':' << iPmtHvOn << "..." << std::flush;
194 auto& entryon = ca[iPlnHvOn][iBarHvOn][iPmtHvOn];
195 entryon.vtarget->Set(1050);
196 entryon.group->Commit();
197
198 for (;;)
199 {
200 std::cout << "$";
201 entryon.group->Fetch();
202 if (fabs(entryon.vmon->Get() - entryon.vtarget->Get()) < 15.)
203 break;
204 sleep(1);
205 }
206 std::cout << "Done!\n";
207
208 timestamp0.Set();
209 }
210
211 // std::cout << "not 5 seconds? " << std::endl;
212
213 if ((fTrigger >= 0) && (header) && (header->GetTrigger() != fTrigger))
214 return;
215
216 Int_t nHits = fMapped->GetEntries();
217
218 // nHits should be 1 * number of planes --- check here?
219
220 // Loop over mapped hits
221 for (Int_t i = 0; i < nHits; i++)
222 {
223
225
226 if (!hit)
227 continue; // should not happen
228
229 Int_t iPlane = hit->GetPlaneId();
230 Int_t iBar = hit->GetBarId();
231 Int_t iSide = -1 == hit->fCoarseTime1LE ? 2 : 1;
232
233 // check if there are signals in proper channel(s)
234 // std::cout << " CHECK!!!! xP " << iPlane << " B " << iBar << " T " << iSide << std::endl;
235 // std::cout << " HV !!!! xP " << iPlnHvOn << " B " << iBarHvOn << " T " << iPmtHvOn << std::endl;
236
237 if (iPlane - 1 == iPlnHvOn && iBar - 1 == iBarHvOn && iSide - 1 == iPmtHvOn)
238 {
239 // std::cout << " GOOD!!!! xP " << iPlane << " B " << iBar << " T " << iSide << std::endl;
240 cntOk[iPlnHvOn][iBarHvOn][iPmtHvOn]++;
241 }
242 else
243 {
244 // std::cout << " BAD!!!! xP " << iPlane << " B " << iBar << " T " << iSide << std::endl;
245 // std::cout << " HV !!!! xP " << iPlnHvOn << " B " << iBarHvOn << " T " << iPmtHvOn << std::endl;
246 // WriteBadMappedChannel();
247 }
248 }
249}
250
252
254{
255 // to do: cleanup resources
256 std::cout << " finish task " << std::endl;
257 for (Int_t pln = 0; pln < fNofPlanes; pln++)
258 {
259 for (Int_t bar = 0; bar < fPaddlesPerPlane; bar++)
260 {
261 for (Int_t pmt = 0; pmt < 2; pmt++)
262 {
263
264 h_countsok->SetBinContent(pln * 100 + bar * 2 + pmt + 1, cntOk[pln][bar][pmt]);
265 }
266 }
267 }
268 h_countsok->Write();
269}
#define PLANE_START
#define TIME_HVON_MAX
#define PLANE_END
virtual void Exec(Option_t *option)
Method for event loop implementation.
virtual void FinishTask()
Method for finish of the task execution.
virtual InitStatus Init()
Method for task initialization.
virtual void FinishEvent()
A method for finish of processing of an event.
virtual ~R3BNeulandCheckMapping()
Destructor.
R3BNeulandCheckMapping()
Default constructor.