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 // Unordered map for saving sum of values (thr/ithr/vcasn) for avg calculation
152 std::map<short int, std::array<long int, 6>> mThresholds;
153 // Map including PixID for noisy pixels
154 std::map<short int, std::vector<int>> mNoisyPixID;
155 // Map including PixID for Inefficient pixels
156 std::map<short int, std::vector<int>> mIneffPixID;
157 // Map including PixID for Dead pixels
158 std::map<short int, std::vector<int>> mDeadPixID;
159 // Vector for the calculation of the most probable value
160 std::map<short int, std::array<int, 200>> mpvCounter;
161 // Tree to save threshold info in full threshold scan case
162 TFile* mRootOutfile = nullptr;
163 TTree* mThresholdTree = nullptr;
164 TTree* mScTree = nullptr;
165 TTree* mSlopeTree = nullptr;
166 short int vChipid[N_COL];
167 short int vRow[N_COL];
168 short int vThreshold[N_COL];
169 bool vSuccess[N_COL];
170 float vNoise[N_COL];
171 unsigned char vPoints[N_COL];
172 short int vMixData[N_COL];
173 float vSlope[N_COL];
174 float vIntercept[N_COL];
175 unsigned char vCharge[N_COL];
176 unsigned char vHits[N_COL];
177 short int mColStep = 8; // save s-curves to tree every mColStep pixels on 1 row
178 short int mRowStep = 1;
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 bool mFlagsRU[N_RU] = {0};
237 std::map<short int, std::map<short int, std::array<std::array<int, 500>, 500>>> mCdwCntRU; // RU --> row --> 2D hit map
238 short int mLoopVal[N_RU][N_ROW] = {{0}};
239 bool mActiveLinks[N_RU][3] = {{false}};
240 std::set<short int> mRuSet;
241 // Either "T" for threshold, "V" for VCASN, or "I" for ITHR
242 char mScanType = '\0';
243 short int mMin = -1, mMax = -1, mMin2 = 0, mMax2 = 0;
244 short int mStep = 1, mStep2 = 1;
245 short int mStrobeWindow = 5; // 5 means 5*25ns = 125 ns
246 short int mRowScan = 512; // number of scanned rows, used only to normalize % of success
247
248 // Get threshold method (fit == 1, derivative == 0, or hitcounting == 2)
249 char mFitType = -1;
250
251 // To tag type(noisy, dead, ineff) of pixel
252 std::string PixelType;
253 // Machine hostname
254 std::string mHostname;
255
256 // DCS config object
258 // DCS config object for pixel type
260 // DCS config object shipped only to QC to know when scan is done
261 o2::dcs::DCSconfigObject_t mChipDoneQc;
262
263 // CDW version
264 short int mCdwVersion = 0; // for now: v0, v1
265
266 // Flag to avoid that endOfStream and stop are both done
267 bool isEnded = false;
268
269 // Flag to tag single noisy pix in digital scan
270 bool mTagSinglePix = false;
271
272 // flag to set url for ccdb mgr
273 std::string mCcdbMgrUrl = "";
274 // Bool to check exact row when counting hits
275 bool mCheckExactRow = false;
276
277 // Chip mod selector and chip mod base for parallel chip access
278 int mChipModSel = 0;
279 int mChipModBase = 1;
280
281 // To set min and max ITHR and VCASN in the tuning scans
282 short int inMinVcasn = 30;
283 short int inMaxVcasn = 100;
284 short int inMinIthr = 25;
285 short int inMaxIthr = 100;
286
287 // Flag to enable most-probable value calculation
288 bool isMpv = false;
289
290 // parameters for manual mode: if run type is not among the listed one
291 bool isManualMode = false;
292 bool saveTree;
293 bool scaleNinj = false;
294 short int manualMin, manualMin2 = 0;
295 short int manualMax, manualMax2 = 0;
296 short int manualStep = 1, manualStep2 = 1;
297 std::string manualScanType;
298 short int manualStrobeWindow = 5;
299 short int manualRowScan = 512; // used only to normalize % of success in thr/ithr/vcasn scans
300
301 // for CRU_ITS data processing
302 bool isCRUITS = false;
303
304 // map to get confDB id
305 std::vector<int>* mConfDBmap;
306 short int mConfDBv;
307
308 // Parameters useful to dump s-scurves on disk + file
309 bool isDumpS = false; // dump or not dump
310 int maxDumpS = -1; // maximum number of s-curves to be dumped, default -1 = dump all
311 std::string chipDumpS = ""; // list of comma-separated O2 chipIDs to be dumped, default is empty = dump all
312 int dumpCounterS[24120] = {0}; // count dumps for every chip
313 bool isChipDB[24120] = {0}; // check whether a chip has been already added to DB entry
314 TFile* fileDumpS; // file where to store the s-curves on disk
315 std::vector<short int> chipDumpList; // vector of chips to dump
316
317 // Run stop requested flag for EoS operations
318 bool mRunStopRequested = false;
319
320 // Flag to calculate the slope in pulse shape 2d scans, y of the 1st point, y of the second point
321 bool doSlopeCalculation = false;
322 bool mCalculate2DParams = true;
323 int chargeA = 0;
324 int chargeB = 0;
325
326 // Variable to select from which MEB to consider the hits.
327 int mMeb = -1;
328
329 // Percentage cut for VCASN/ITHR scans
330 short int mPercentageCut = 25; // default, at least 1 good row equivalent
331
332 // For data replay only
333 short int isLocal = false;
334};
335
336// Create a processor spec
338
339} // namespace its
340} // namespace o2
341
342#endif
Utils and constants for calibration and related workflows.
random_device dev
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions false
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
std::vector< char > DCSconfigObject_t
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
return true
o2::framework::DataProcessorSpec getITSThresholdCalibratorSpec(const ITSCalibInpConf &inpConf)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...