BmnRoot 26.10.0-18-g4e3414f9
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{
46 UShort_t slot;
50};
51
53{
54 TString name;
63 TClonesArray* branchArrayPtr[CHANNEL_COUNT_MAX];
66};
67
69{
70 public:
72 BmnTrigRaw2Digit(TString mappingFile, TString INLFile, TTree* digiTree = NULL);
73 // BmnTrigRaw2Digit(TString mappingFile, TString INLFile, FairRootManager* frm = NULL, bool saveOutput = true);
74 BmnTrigRaw2Digit(TString mappingFile, TString INLFile, std::function<void(TString, TClonesArray*)> BranchRegFun);
75
77 {
78 for (TClonesArray* ar : trigArrays)
79 delete ar;
80 // for (auto el : fMap)
81 // delete el;
82 fMap.clear();
83 for (auto& el : fPlacementMap) {
84 delete el.second;
85 }
86 fPlacementMap.clear();
87 }
88
89 vector<BmnTrigChannelData>* GetMap() { return &fMap; }
90 /** Raw T0 module map (from Sergeev txt) */
91 T0ChMap& T0Map() { return fT0Map; }
92 /** TRC bit map */
94 /** MSC map */
97 map<std::pair<uint32_t, uint16_t>, uint16_t>& GetScaler2IdxMap() { return scalers2index_map; }
98 map<uint16_t, uint16_t>& GetTrcIdx2ScalerIdxMap() { return trcIdx2scalerIdx; }
100 vector<string>& GetScalerIdx2NameMap() { return scalers_index2name_map; }
101
102 BmnStatus FillEvent(TClonesArray* tdc, unordered_map<UInt_t, Long64_t>& tsMap);
103 BmnStatus FillEvent(TClonesArray* tdc, TClonesArray* adc, unordered_map<UInt_t, Long64_t>& tsMap);
108
109 vector<TClonesArray*>* GetTrigArrays() { return &trigArrays; }
110
112 {
113 // if (fTrcSerial > 0)
114 // return fTrcSerial;
115 for (auto& itPl : fPlacementMap)
116 if (itPl.second->IsT0)
117 return itPl.second->CrateSerial;
118 return 0;
119 }
120
121 uint32_t GetTrcSerial() { return fTrcSerial; }
122
123 void SetSetup(BmnSetup stp) { fSetup = stp; }
124
125 private:
127 {
128 UShort_t h = serial >> 16;
129 UShort_t l = serial & 0x0000FFFF;
130 TString inlFileName = Form("%s-%04X-%04X.ini", boardName.Data(), h, l);
131 return inlFileName;
132 }
133
134 UInt_t ChanCntByName(TString channelCountStr)
135 {
136 // regex reBoardName("(\\D+)(\\d+)(.*)");
137 TPRegexp reBoardName("(\\D+)(\\d+)(.*)");
138 // string channelCountStr = name;
139 UInt_t channelCount = CHANNEL_COUNT_MAX;
140 if (reBoardName.MatchB(channelCountStr)) {
141 // if (regex_match(name, reBoardName)){
142 // channelCountStr = regex_replace(name, reBoardName, "$2");
143 reBoardName.Substitute(channelCountStr, "$2");
144 channelCount = strtoul(channelCountStr.Data(), nullptr, 10);
145 // channelCount = strtoul(channelCountStr.c_str(), nullptr, 10);
146 }
147 return channelCount;
148 }
149
150 void ProcessWave(vector<int16_t>& iValue, Bool_t& isNeg);
151
152 int16_t GetBaseline(vector<int16_t>& iValue);
153 int16_t GetBaselineByMap(vector<int16_t>& iValue);
154
155 map<PlMapKey, BmnTrigParameters*> fPlacementMap;
159 vector<BmnTrigChannelData> fMap;
162 vector<TClonesArray*> trigArrays;
163
164 static constexpr size_t ADC_RANGE = SHRT_MAX - SHRT_MIN + 1;
165 // std::array<uint16_t, ADC_RANGE> fWorkArray;
166 map<int16_t, uint16_t> fValsMap;
167 uint32_t fTrcSerial;
168
170 // map: <serial, channel> -> index in the list (inside spillHeader->ScalersVec(), and MSC matrix)
171 map<std::pair<uint32_t, uint16_t>, uint16_t> scalers2index_map;
172 map<uint16_t, uint16_t> trcIdx2scalerIdx;
173 // map: name -> index in the list
175 vector<string> scalers_index2name_map;
176
178};
179
180#endif /* BMNTRIGRAWTODIGIT_H */
bool Bool_t
unsigned short UShort_t
unsigned int UInt_t
double Double_t
#define ClassDef(name, id)
char * Form(const char *fmt,...)
BmnStatus
Define status code.
Definition BmnEnums.h:93
BmnSetup
Define experimental setup.
Definition BmnEnums.h:165
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
int16_t GetBaselineByMap(vector< int16_t > &iValue)
BmnStatus ReadINLFromFile(BmnTrigParameters *par)
static constexpr size_t ADC_RANGE
map< std::pair< uint32_t, uint16_t >, uint16_t > scalers2index_map
vector< BmnTrigChannelData > fMap
map< int16_t, uint16_t > fValsMap
Name2SerCh name2scaler_map
BmnTrigRaw2Digit(TString mappingFile, TString INLFile, std::function< void(TString, TClonesArray *)> BranchRegFun)
vector< string > & GetScalerIdx2NameMap()
vector< string > scalers_index2name_map
BmnStatus ReadChannelMap(TString mappingFile)
vector< TClonesArray * > * GetTrigArrays()
NameChMap & GetScalerName2IdxMap()
virtual ~BmnTrigRaw2Digit()
map< PlMapKey, BmnTrigParameters * > fPlacementMap
int16_t GetBaseline(vector< int16_t > &iValue)
BmnStatus FillEvent(TClonesArray *tdc, TClonesArray *adc, unordered_map< UInt_t, Long64_t > &tsMap)
BmnStatus ClearArrays()
NameChMap & GetTrcMap()
TRC bit map.
Name2SerCh & GetScalerMap()
MSC map.
map< uint16_t, uint16_t > trcIdx2scalerIdx
void ProcessWave(vector< int16_t > &iValue, Bool_t &isNeg)
void SetSetup(BmnSetup stp)
SerCh2Name & GetScaler2NameMap()
map< uint16_t, uint16_t > & GetTrcIdx2ScalerIdxMap()
SerCh2Name scalers2name_map
BmnTrigRaw2Digit(TString mappingFile, TString INLFile, TTree *digiTree=NULL)
map< std::pair< uint32_t, uint16_t >, uint16_t > & GetScaler2IdxMap()
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)
vector< BmnTrigChannelData > * GetMap()
vector< TClonesArray * > trigArrays
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
const UShort_t kNCHANNELS
Define enumerations used in tracking.
#define CHANNEL_COUNT_MAX
#define TDC_BIN_COUNT
TClonesArray * branchArrayPtr
Double_t INL[CHANNEL_COUNT_MAX][TDC_BIN_COUNT]
Bool_t NegativeMap[CHANNEL_COUNT_MAX]
TClonesArray * branchArrayPtr[CHANNEL_COUNT_MAX]
UShort_t ChannelMap[CHANNEL_COUNT_MAX]
Double_t t[CHANNEL_COUNT_MAX]