BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnTrigRaw2Digit.h
Go to the documentation of this file.
1#ifndef BMNTRIGRAWTODIGIT_H
2#define BMNTRIGRAWTODIGIT_H
3// C++
4#include <fstream>
5#include <iostream>
6#include <map>
7#include <regex>
8#include <sstream>
9#include <unordered_map>
10#include <vector>
11// ROOT
12#include <TCanvas.h>
13#include <TClonesArray.h>
14#include <TH1I.h>
15#include <TMath.h>
16#include <TPRegexp.h>
17#include <TString.h>
18#include <TTree.h>
19// BmnRoot
20#include "BmnAliases.h"
21#include "BmnEnums.h"
22
23#define CHANNEL_COUNT_MAX 72u
24#define TDC72_CHANNEL_COUNT 72u
25#define TQDC16_CHANNEL_COUNT 16u
26#define TDC_BIN_COUNT 1024
27#define HPTIMEBIN 0.02344
28#define INVHPTIMEBIN 42.6666
29#define ADC_CLOCK_TQDC16VS 8.0 // nano seconds
30#define ADC_CLOCK 12.0
31#define ADC_CLOCK_OLD 12.5
32#define TDC_CLOCK 24.0
33#define TDC_CLOCK_OLD 25.0
34const UShort_t kNCHANNELS = 8; // number of channels in one HPTDC
35
36using std::map;
37using std::string;
38using std::unordered_map;
39using std::vector;
40
42{
43 public:
54
68 BmnTrigRaw2Digit(uint32_t period, TString mappingFile, TString INLFile, TTree* digiTree = NULL);
69 // BmnTrigRaw2Digit(TString mappingFile, TString INLFile, FairRootManager* frm = NULL, bool saveOutput = true);
70 BmnTrigRaw2Digit(uint32_t period,
71 TString mappingFile,
72 TString INLFile,
73 std::function<void(TString, TClonesArray*)> BranchRegFun);
74
76 {
77 for (TClonesArray* ar : trigArrays)
78 delete ar;
79 }
80
81 vector<BmnTrigChannelData>* GetMap() { return &fChannelVec; }
82 /** Raw T0 module map (from Sergeev txt) */
83 T0ChMap& T0Map() { return fT0Map; }
84 /** TRC bit map */
86 /** MSC map */
89 map<std::pair<uint32_t, uint16_t>, uint16_t>& GetScaler2IdxMap() { return scalers2index_map; }
90 map<uint16_t, uint16_t>& GetTrcIdx2ScalerIdxMap() { return trcIdx2scalerIdx; }
92 vector<string>& GetScalerIdx2NameMap() { return scalers_index2name_map; }
93
94 BmnStatus FillEvent(TClonesArray* tdc, unordered_map<UInt_t, Long64_t>& tsMap);
95 BmnStatus FillEvent(TClonesArray* tdc, TClonesArray* adc, unordered_map<UInt_t, Long64_t>& tsMap);
96 BmnStatus ReadINLFromFile(BmnTrigParameters* par);
97 BmnStatus ReadChannelMap(TString mappingFile);
100
101 vector<TClonesArray*>* GetTrigArrays() { return &trigArrays; }
102
104 {
105 // if (fTrcSerial > 0)
106 // return fTrcSerial;
107 for (auto& itPl : fPlacementVec)
108 if (itPl.IsT0)
109 return itPl.CrateSerial;
110 return 0;
111 }
112
113 uint32_t GetTrcSerial() { return fTrcSerial; }
114
115 void SetSetup(BmnSetup stp) { fSetup = stp; }
116
117 private:
119 {
120 uint32_t BoardSerial;
121 uint32_t CrateSerial;
122 uint8_t Slot;
123 bool IsT0;
124 };
125
126 void AssignMaps();
127
129 {
130 UShort_t h = serial >> 16;
131 UShort_t l = serial & 0x0000FFFF;
132 TString inlFileName = Form("%s-%04X-%04X.ini", boardName.Data(), h, l);
133 return inlFileName;
134 }
135
136 UInt_t ChanCntByName(TString channelCountStr)
137 {
138 // regex reBoardName("(\\D+)(\\d+)(.*)");
139 TPRegexp reBoardName("(\\D+)(\\d+)(.*)");
140 // string channelCountStr = name;
141 UInt_t channelCount = CHANNEL_COUNT_MAX;
142 if (reBoardName.MatchB(channelCountStr)) {
143 // if (regex_match(name, reBoardName)){
144 // channelCountStr = regex_replace(name, reBoardName, "$2");
145 reBoardName.Substitute(channelCountStr, "$2");
146 channelCount = strtoul(channelCountStr.Data(), nullptr, 10);
147 // channelCount = strtoul(channelCountStr.c_str(), nullptr, 10);
148 }
149 return channelCount;
150 }
151
152 void ProcessWave(vector<int16_t>& iValue, Bool_t& isNeg);
153
154 int16_t GetBaseline(vector<int16_t>& iValue);
155 int16_t GetBaselineByMap(vector<int16_t>& iValue);
156
157 uint32_t fPeriodId;
159
160 vector<PlacementLine> fPlacementVec; //!
161 unordered_map<uint32_t, BmnTrigParameters> fTrigBoardMap; //!
162
166 vector<BmnTrigChannelData> fChannelVec; //!
168 vector<TClonesArray*> trigArrays;
169
170 static constexpr size_t ADC_RANGE = SHRT_MAX - SHRT_MIN + 1;
171 // std::array<uint16_t, ADC_RANGE> fWorkArray;
172 unordered_map<int16_t, uint16_t> fValsMap;
173 uint32_t fTrcSerial;
174
176 // map: <serial, channel> -> index in the list (inside spillHeader->ScalersVec(), and MSC matrix)
177 map<std::pair<uint32_t, uint16_t>, uint16_t> scalers2index_map;
178 map<uint16_t, uint16_t> trcIdx2scalerIdx;
179 // map: name -> index in the list
182
184};
185
186#endif /* BMNTRIGRAWTODIGIT_H */
std::unordered_map< std::string, std::pair< uint32_t, uint16_t > > Name2SerCh
Definition BmnAliases.h:9
std::map< std::pair< uint32_t, uint16_t >, std::string > SerCh2Name
Definition BmnAliases.h:10
std::map< T0MapKey, uint16_t > T0ChMap
Definition BmnAliases.h:6
std::unordered_map< std::string, uint16_t > NameChMap
Definition BmnAliases.h:7
Define enumerations used in tracking.
BmnStatus
Define status code.
Definition BmnEnums.h:93
BmnSetup
Define experimental setup.
Definition BmnEnums.h:165
const UShort_t kNCHANNELS
#define CHANNEL_COUNT_MAX
#define TDC_BIN_COUNT
bool Bool_t
unsigned short UShort_t
unsigned int UInt_t
double Double_t
#define ClassDef(name, id)
char * Form(const char *fmt,...)
int16_t GetBaselineByMap(vector< int16_t > &iValue)
BmnStatus ReadINLFromFile(BmnTrigParameters *par)
Name2SerCh name2scaler_map
map< std::pair< uint32_t, uint16_t >, uint16_t > scalers2index_map
vector< string > & GetScalerIdx2NameMap()
BmnStatus ReadChannelMap(TString mappingFile)
vector< TClonesArray * > * GetTrigArrays()
NameChMap & GetScalerName2IdxMap()
virtual ~BmnTrigRaw2Digit()
int16_t GetBaseline(vector< int16_t > &iValue)
unordered_map< uint32_t, BmnTrigParameters > fTrigBoardMap
vector< BmnTrigChannelData > fChannelVec
vector< PlacementLine > fPlacementVec
NameChMap & GetTrcMap()
TRC bit map.
Name2SerCh & GetScalerMap()
MSC map.
void ProcessWave(vector< int16_t > &iValue, Bool_t &isNeg)
map< uint16_t, uint16_t > trcIdx2scalerIdx
void SetSetup(BmnSetup stp)
SerCh2Name & GetScaler2NameMap()
vector< string > scalers_index2name_map
map< uint16_t, uint16_t > & GetTrcIdx2ScalerIdxMap()
unordered_map< int16_t, uint16_t > fValsMap
SerCh2Name scalers2name_map
map< std::pair< uint32_t, uint16_t >, uint16_t > & GetScaler2IdxMap()
vector< TClonesArray * > trigArrays
NameChMap scalers_name2index_map
UInt_t ChanCntByName(TString channelCountStr)
T0ChMap & T0Map()
Raw T0 module map (from Sergeev txt).
TString Serial2FileName(TString boardName, UInt_t serial)
BmnStatus FillEvent(TClonesArray *tdc, unordered_map< UInt_t, Long64_t > &tsMap)
BmnStatus ReadPlacementMap(TString mappingFile)
BmnTrigRaw2Digit(uint32_t period, TString mappingFile, TString INLFile, TTree *digiTree=NULL)
vector< BmnTrigChannelData > * GetMap()
static constexpr size_t ADC_RANGE
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
const char * Data() const
Double_t t[CHANNEL_COUNT_MAX]
Double_t INL[CHANNEL_COUNT_MAX][TDC_BIN_COUNT]
TClonesArray * branchArrayPtr[CHANNEL_COUNT_MAX]
bool NegativeMap[CHANNEL_COUNT_MAX]
UShort_t ChannelMap[CHANNEL_COUNT_MAX]