Project
Loading...
Searching...
No Matches
ThresholdCalibratorSpec.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#ifndef O2_ITS_THRESHOLD_CALIBRATOR_
15#define O2_ITS_THRESHOLD_CALIBRATOR_
16
17#include <sys/stat.h>
18#include <filesystem>
19#include <string>
20#include <vector>
21#include <array>
22#include <set>
23#include <deque>
24
25#include <iostream>
26#include <fstream>
27#include <sstream>
28
29// Boost library for easy access of host name
30#include <boost/asio/ip/host_name.hpp>
31
34#include "Framework/Task.h"
39#include "Framework/Task.h"
42#include <fairmq/Device.h>
43
44#include <ITSMFTReconstruction/RawPixelDecoder.h> //o2::itsmft::RawPixelDecoder
47#include "CCDB/CcdbApi.h"
50
51// ROOT includes
52#include "TTree.h"
53#include "TH1F.h"
54#include "TF1.h"
55#include "TFile.h"
56
57using namespace o2::framework;
58using namespace o2::itsmft;
59
60namespace o2
61{
62namespace its
63{
64
65int nInj = 50;
66int nInjScaled = 50; // different from nInj only if mMeb > 0, in this case it is nInj/3.
67
68// List of the possible run types for reference
98
99// List of the possible fit types for reference
106
107// To work with parallel chip access
109 int chipModSel = 0;
110 int chipModBase = 1;
111};
112
114{
115 public:
117 ~ITSThresholdCalibrator() override;
118
121
122 void init(InitContext& ic) final;
123 void run(ProcessingContext& pc) final;
124 void endOfStream(EndOfStreamContext& ec) final;
125
126 void finalize();
127 void stop() final;
128 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
129
131 private:
132 void updateTimeDependentParams(ProcessingContext& pc);
133 // detector information
134 static constexpr short int N_COL = 1024; // number of columns in Alpide chip
135 static constexpr short int N_ROW = 512; // number of rows in Alpide chip
136
137 static const short int N_RU = o2::itsmft::ChipMappingITS::getNRUs();
138
139 // Number of scan points in a calibration scan
140 short int N_RANGE = 51;
141 // Number of scan points in case of 2D calibration
142 short int N_RANGE2 = 1;
143 // Min number of noisy pix in a dcol for bad dcol tagging
144 static constexpr short int N_PIX_DCOL = 50;
145
146 // The x-axis of the correct data fit chosen above
147 float* mX = nullptr;
148
149 // Hash tables to store the hit and threshold information per pixel
150 std::map<short int, std::map<int, std::vector<std::vector<std::vector<unsigned short int>>>>> mPixelHits;
151 std::map<short int, std::deque<short int>> mForbiddenRows;
152 // Unordered map for saving sum of values (thr/ithr/vcasn) for avg calculation
153 std::map<short int, std::array<long int, 6>> mThresholds;
154 // Map including PixID for noisy pixels
155 std::map<short int, std::vector<int>> mNoisyPixID;
156 // Map including PixID for Inefficient pixels
157 std::map<short int, std::vector<int>> mIneffPixID;
158 // Map including PixID for Dead pixels
159 std::map<short int, std::vector<int>> mDeadPixID;
160 // Vector for the calculation of the most probable value
161 std::map<short int, std::array<int, 200>> mpvCounter;
162 // Tree to save threshold info in full threshold scan case
163 TFile* mRootOutfile = nullptr;
164 TTree* mThresholdTree = nullptr;
165 TTree* mScTree = nullptr;
166 TTree* mSlopeTree = nullptr;
167 short int vChipid[N_COL];
168 short int vRow[N_COL];
169 short int vThreshold[N_COL];
170 bool vSuccess[N_COL];
171 float vNoise[N_COL];
172 unsigned char vPoints[N_COL];
173 short int vMixData[N_COL];
174 float vSlope[N_COL];
175 float vIntercept[N_COL];
176 unsigned char vCharge[N_COL];
177 unsigned char vHits[N_COL];
178 short int mColStep = 8; // save s-curves to tree every mColStep pixels on 1 row
179
180 // Initialize pointers for doing error function fits
181 TH1F* mFitHist = nullptr;
182 TF1* mFitFunction = nullptr;
183
184 // Some private helper functions
185 // Helper functions related to the running over data
186 void extractAndUpdate(const short int&, const short int&);
187 std::vector<float> calculatePulseParams(const short int&);
188 std::vector<float> calculatePulseParams2D(const short int&);
189 void extractThresholdRow(const short int&, const short int&);
190 void finalizeOutput();
191
192 void setRunType(const short int&);
193
194 // Helper functions related to threshold extraction
195 void initThresholdTree(bool recreate = true);
196 bool findUpperLower(std::vector<std::vector<unsigned short int>>, const short int&, short int&, short int&, bool, int);
197 bool findThreshold(const short int&, std::vector<std::vector<unsigned short int>>, const float*, short int&, float&, float&, int&, int);
198 bool findThresholdFit(const short int&, std::vector<std::vector<unsigned short int>>, const float*, const short int&, float&, float&, int&, int);
199 bool findThresholdDerivative(std::vector<std::vector<unsigned short int>>, const float*, const short int&, float&, float&, int&, int);
200 bool findThresholdHitcounting(std::vector<std::vector<unsigned short int>>, const float*, const short int&, float&, int);
201 void findAverage(const std::array<long int, 6>&, float&, float&, float&, float&);
202 void saveThreshold();
203
204 // Helper functions for writing to the database
205 void addDatabaseEntry(const short int&, const char*, std::vector<float>, bool);
206
207 // Utils
208 std::vector<short int> getIntegerVect(std::string&);
209 short int getRUID(short int chipID);
210 std::vector<short int> getChipListFromRu(short int, bool*);
211 short int getLinkID(short int, short int);
212 short int getNumberOfActiveLinks(bool*);
213
214 std::string mSelfName;
215 std::string mDictName;
216 std::string mNoiseName;
217
218 int mTFCounter = 0;
219 bool mVerboseOutput = false;
220 std::string mMetaType;
221 std::string mOutputDir;
222 std::string mMetafileDir = "/dev/null";
223 int mNThreads = 1;
224 o2::framework::DataTakingContext mDataTakingContext{};
225 o2::framework::TimingInfo mTimingInfo{};
226
227 // How many rows before starting new ROOT file
228 unsigned int mFileNumber = 0;
229 static constexpr unsigned int N_ROWS_PER_FILE = 150000;
230 unsigned int mRowCounter = 0;
231
232 short int mRunType = -1;
233 short int mRunTypeUp = -1;
234 short int mRunTypeRU[N_RU] = {0};
235 short int mRunTypeRUCopy[N_RU] = {0};
236 short int mCdwCntRU[N_RU][N_ROW] = {{0}};
237 short int mLoopVal[N_RU][N_ROW] = {{0}};
238 bool mActiveLinks[N_RU][3] = {{false}};
239 std::set<short int> mRuSet;
240 // Either "T" for threshold, "V" for VCASN, or "I" for ITHR
241 char mScanType = '\0';
242 short int mMin = -1, mMax = -1, mMin2 = 0, mMax2 = 0;
243 short int mStep = 1, mStep2 = 1;
244 short int mStrobeWindow = 5; // 5 means 5*25ns = 125 ns
245
246 // Get threshold method (fit == 1, derivative == 0, or hitcounting == 2)
247 char mFitType = -1;
248
249 // To tag type(noisy, dead, ineff) of pixel
250 std::string PixelType;
251 // Machine hostname
252 std::string mHostname;
253
254 // DCS config object
256 // DCS config object for pixel type
258 // DCS config object shipped only to QC to know when scan is done
259 o2::dcs::DCSconfigObject_t mChipDoneQc;
260
261 // CDW version
262 short int mCdwVersion = 0; // for now: v0, v1
263
264 // Flag to avoid that endOfStream and stop are both done
265 bool isEnded = false;
266
267 // Flag to tag single noisy pix in digital scan
268 bool mTagSinglePix = false;
269
270 // flag to set url for ccdb mgr
271 std::string mCcdbMgrUrl = "";
272 // Bool to check exact row when counting hits
273 bool mCheckExactRow = false;
274
275 // Chip mod selector and chip mod base for parallel chip access
276 int mChipModSel = 0;
277 int mChipModBase = 1;
278
279 // To set min and max ITHR and VCASN in the tuning scans
280 short int inMinVcasn = 30;
281 short int inMaxVcasn = 100;
282 short int inMinIthr = 25;
283 short int inMaxIthr = 100;
284
285 // Flag to enable most-probable value calculation
286 bool isMpv = false;
287
288 // parameters for manual mode: if run type is not among the listed one
289 bool isManualMode = false;
290 bool saveTree;
291 bool scaleNinj = false;
292 short int manualMin, manualMin2 = 0;
293 short int manualMax, manualMax2 = 0;
294 short int manualStep = 1, manualStep2 = 1;
295 std::string manualScanType;
296 short int manualStrobeWindow = 5;
297
298 // for CRU_ITS data processing
299 bool isCRUITS = false;
300
301 // map to get confDB id
302 std::vector<int>* mConfDBmap;
303 short int mConfDBv;
304
305 // Parameters useful to dump s-scurves on disk + file
306 bool isDumpS = false; // dump or not dump
307 int maxDumpS = -1; // maximum number of s-curves to be dumped, default -1 = dump all
308 std::string chipDumpS = ""; // list of comma-separated O2 chipIDs to be dumped, default is empty = dump all
309 int dumpCounterS[24120] = {0}; // count dumps for every chip
310 int countCdw[24120] = {0}; // count how many CDWs have been processed with the maximum charge injected: usefull for s-curve dump when hits do not arrive in order
311 TFile* fileDumpS; // file where to store the s-curves on disk
312 std::vector<short int> chipDumpList; // vector of chips to dump
313
314 // Run stop requested flag for EoS operations
315 bool mRunStopRequested = false;
316
317 // Flag to calculate the slope in pulse shape 2d scans, y of the 1st point, y of the second point
318 bool doSlopeCalculation = false;
319 bool mCalculate2DParams = true;
320 int chargeA = 0;
321 int chargeB = 0;
322
323 // Variable to select from which MEB to consider the hits.
324 int mMeb = -1;
325
326 // Percentage cut for VCASN/ITHR scans
327 short int mPercentageCut = 25; // default, at least 1 good row equivalent
328};
329
330// Create a processor spec
332
333} // namespace its
334} // namespace o2
335
336#endif
Utils and constants for calibration and related workflows.
random_device dev
Definition of the Alpide pixel reader for raw data processing.
void run(ProcessingContext &pc) final
void stop() final
This is invoked on stop.
void endOfStream(EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
GLenum array
Definition glcorearb.h:4274
std::vector< char > DCSconfigObject_t
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
o2::framework::DataProcessorSpec getITSThresholdCalibratorSpec(const ITSCalibInpConf &inpConf)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.