BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
digitConvertor.C
Go to the documentation of this file.
1//-------------------------------------------------------------------------------------
2#if !defined(__CLING__) || defined(__MAKECLING__)
3// ROOT includes
4#include "Riosfwd.h"
5#include "TBrowser.h"
6#include "TChain.h"
7#include "TClonesArray.h"
8#include "TFile.h"
9#include "TGeoBBox.h"
10#include "TGeoManager.h"
11#include "TGeoNavigator.h"
12#include "TGeoVolume.h"
13#include "TList.h"
14#include "TNamed.h"
15#include "TObject.h"
16#include "TROOT.h"
17#include "TStopwatch.h"
18#include "TString.h"
19#include "TSystem.h"
20#include "TVector3.h"
21
22// Fair includes
23#include "FairGeoInterface.h"
24#include "FairGeoLoader.h"
25#include "FairGeoNode.h"
26#include "FairGeoRootBuilder.h"
27
28// BMN includes
29#include "BmnTDCDigit.h"
30#include "BmnTOF1Point.h"
31#include "BmnTOF1TDC.h"
32#include "BmnTof1Digit.h"
33#include "BmnTof1GeoUtils.h"
34#include "TClonesArray.h"
35#include "UniDetectorParameter.h"
36#include "UniRun.h"
37#include "UniSearchCondition.h"
38
39#include <assert.h>
40#include <iomanip>
41#include <iostream>
42#include <string.h>
43//////#include <tuple>
44
45using namespace std;
46#endif
47
48// #include "../db_structures.h"
49//------------------------------------------------------------------------------------------------------------------------
50bool ParseGeoFile(BmnTof1GeoUtils*, const char* geoFlnm);
51bool LoadGeoSetup(int runPeriod);
53//------------------------------------------------------------------------------------------------------------------------
54// before run:
55// $ export TOF1inFlnm=bmn_run0014.root
56//------------------------------------------------------------------------------------------------------------------------
58{
59 char* inFlnm = getenv("TOF1inFlnm");
60 char* outFlnm = getenv("TOF1outFlnm");
61 assert(inFlnm != nullptr);
62
63 TString outFile, inFile(inFlnm);
64 if (nullptr != outFlnm)
65 outFile = outFlnm;
66 else {
67 outFile = "tof1digit_";
68 outFile += inFile;
69 }
70
71 // Load geometry from the Geometry Database
72 bool geoLoadOK = LoadGeoSetup(6);
73 assert(geoLoadOK);
74
75 // Parsing the loaded geometry
76 BmnTof1GeoUtils* pGeoUtils = new BmnTof1GeoUtils;
77 bool geoParseOK = ParseGeometry(pGeoUtils);
78 assert(geoParseOK);
79
80 // Create TDCs
81 // BmnTof1TDC(int serial, size_t tdcType, size_t nChannels, double inlWidth, size_t inlBins)
82 // BmnTof1TDC tdc1(0xFFE9DA91, 0x12, 72, 25., 1024);
83 // BmnTof1TDC tdc2(0x076CCF62, 0x12, 72, 25., 1024);
84 // BmnTof1TDC tdc3(0x076CAD53, 0x12, 72, 25., 1024);
85 // BmnTof1TDC tdc4(0xFFE9F5CB, 0x12, 72, 25., 1024);
86
87 BmnTof1TDC tdc1(0xFFE9DA91, 0x12, 72, 25., 1024);
88 BmnTof1TDC tdc2(0x076CCF62, 0x12, 72, 25., 1024);
89 BmnTof1TDC tdc3(0x076CAD53, 0x12, 72, 25., 1024);
90 BmnTof1TDC tdc4(0xFFE9F5CB, 0x12, 72, 25., 1024);
91
92 // Set unique TDC name id
93 tdc2.SetNameTitle("TDC_N2", "blablabla2222");
94 tdc1.SetNameTitle("TDC_N1", "blablabla2222");
95 tdc3.SetNameTitle("TDC_N3", "blablabla2222");
96 tdc4.SetNameTitle("TDC_N4", "blablabla2222");
97 // BmnTof1TDC::setNameTitle(0x168fdca, "tdcN1", "blablabla");
98
99 // Load DB parameters
101
102 BmnTof1TDC::dump();
103
104 // Setup configure
105 BmnTof1Configure config(3); // 0x168fdca, 0x1692190, 0x46f3326, 0x46f3872
106 config.Reset();
107
108 // +Y
109 // LEFT RIGHT
110 // UP
111 // kDetSlote_1 kDetSlote_2
112 // -----------------
113 // | |
114 // | |
115 // -----------------
116 // kDetSlote_3 kDetSlote_4
117 // -X 0 +X -->
118 // DOWN
119 // -Y
120
121 // Connect detectors with TDC (detID, detSlote, tdcSerial, tdcSlote)
122 // detector# 1
123 config.AddConnection(0, slote_D1, "TDC_N1", slote_T3);
124 config.AddConnection(0, slote_D2, "TDC_N1", slote_T2);
125 config.AddConnection(0, slote_D3, "TDC_N1", slote_T1);
126 config.AddConnection(0, slote_D4, "TDC_N2", slote_T3);
127
128 // detector# 2
129 config.AddConnection(1, slote_D2, "TDC_N2", slote_T2);
130 config.AddConnection(1, slote_D1, "TDC_N2", slote_T1);
131 config.AddConnection(1, slote_D4, "TDC_N3", slote_T3);
132 config.AddConnection(1, slote_D3, "TDC_N3", slote_T2);
133
134 // detector# 3
135 config.AddConnection(2, slote_D1, "TDC_N3", slote_T1);
136 config.AddConnection(2, slote_D2, "TDC_N4", slote_T3);
137 config.AddConnection(2, slote_D3, "TDC_N4", slote_T2);
138 config.AddConnection(2, slote_D4, "TDC_N4", slote_T1);
139
140 // Install TDC to CRATE (TDC_serial, CRATE_serial, CRATE_slote)
141 // config.InstallTDC(0xFFE9DA91, 0x1690454, 4);
142 // config.InstallTDC(0x076CCF62, 0x1690454, 5);
143 // config.InstallTDC(0x076CAD53, 0x1690454, 6);
144 // config.InstallTDC(0xFFE9F5CB, 0x1690454, 7);
145
146 config.InstallTDC(0xFFE9DA91, 0x1690454, 4);
147 config.InstallTDC(0x076CCF62, 0x1690454, 5);
148 config.InstallTDC(0x076CAD53, 0x1690454, 6);
149 config.InstallTDC(0xFFE9F5CB, 0x1690454, 7);
150
151 config.Status();
152
153 // config.RemoveConnection(0x46f3872, slote_T2);
154 // config.AddConnection(2, slote_D3, 0x46f3872, slote_T2);
155 // config.RemoveConnection(1, slote_D3);
156 // config.Status();
157
158 BmnTof1TDCMapping tofMapping(&config);
159
160 // ------------------------------------------------------------------------ processing BmnTDCDigit --->
161 // BmnTof1Digit Open output file
162 TFile file(outFile.Data(), "RECREATE");
163 if (file.IsZombie()) {
164 cerr << "\n\t --->ERROR: opening output file:\"" << outFile.Data() << "\"" << endl;
165 exit(-1);
166 }
167
168 TClonesArray* aTofDigits = new TClonesArray("BmnTof1Digit");
169 TTree* treeOut = new TTree("cbmsim", "only Tof1Digits now");
170 treeOut->Branch("bmn_tof400", &aTofDigits);
171
172 // Open input file
173 TChain* treeIn = new TChain("BMN_RAW");
174 treeIn->Add(inFile.Data());
175
176 Int_t nEntries = treeIn->GetEntries();
177 cout << "\n input file entries: " << nEntries;
178
179 // Activate branches
180 TClonesArray* aTofTDCdigit = NULL;
181 treeIn->SetBranchAddress("TDC", &aTofTDCdigit); //"bmn_tof400"
182 assert(nullptr != aTofTDCdigit);
183
184 BmnTDCDigit* pTDCdigit;
185 const BmnTof1Digit* pTofDigit;
186 BmnTof1DigitConvertor convertor;
187
188 size_t tdcSerial, NtofDigits = 0;
189 int detID, stripID, stripSideID;
190 int crateSerial, crateSlote, tdcChannel, tdcType, tdcLeading, tdcValue;
191 UChar_t tChannel, tHpId;
192
193 // nEntries = 100;
194 for (Int_t event = 0; event < nEntries; event++) {
195 treeIn->GetEntry(event);
196
197 convertor.Reset();
198
199 int Ndigits = aTofTDCdigit->GetEntries();
200 for (int digit = 0; digit < Ndigits; digit++) // cycle by TDCdigits
201 {
202 pTDCdigit = (BmnTDCDigit*)aTofTDCdigit->UncheckedAt(digit);
203
204 crateSerial = pTDCdigit->GetSerial();
205 crateSlote = pTDCdigit->GetSlot();
206 tChannel = pTDCdigit->GetChannel();
207 tHpId = pTDCdigit->GetHptdcId();
208 tdcType = pTDCdigit->GetType();
209 tdcLeading = pTDCdigit->GetLeading();
210 tdcValue = pTDCdigit->GetValue();
211
212 // cout<<"\nTDCdigit serial:"<<hex<<showbase<<crateSerial<<dec<<", slote:"<<crateSlote<<" "<<tdcType;
213
214 if (config.GetTDCserial(crateSerial, crateSlote, tdcSerial)) // TDCserial found == TOF1 tdc
215 {
216 tdcChannel = BmnTof1TDC::GetChannel(tChannel, tHpId);
217
218 // cout<<"\nTDCdigit serial:"<<hex<<showbase<<crateSerial<<dec<<", slote:"<<crateSlote<<",
219 // channel:"<<tdcChannel
220 // <<", type:"<<tdcType<<", leading:"<<tdcLeading<<", value:"<<tdcValue;
221
222 convertor.AddSample(tdcSerial, tdcChannel);
223
224 if (BmnTof1TDC::CheckTdcType(tdcSerial, tdcType)) // FIXME: maybe naxren nenado
225 if (tofMapping.Convert(tdcSerial, tdcChannel, &pTofDigit)) // Tof strip found
226 {
227 convertor.AddDigit(pTDCdigit, BmnTof1TDC::GetTDCChannel(tdcSerial, tdcChannel), pTofDigit);
228 }
229 }
230
231 } // cycle by TDCdigits
232
233 convertor.CalcCorrelationMatrix();
234
235 size_t entries = convertor.Convert(aTofDigits);
236 NtofDigits += entries;
237 cout << "\n event# " << event << ", TDC digits: " << Ndigits << " Tof1 digits = " << entries;
238
239 // save BmnTof1Digits to file
240 treeOut->Fill();
241 }
242
243 file.cd();
244 treeOut->Write();
245 file.Close();
246
247 cout << "\n$TOF1inFlnm = " << inFile.Data() << ", $TOF1outFlnm = " << outFile.Data()
248 << ", NtofDigits = " << NtofDigits << ", nEntries=" << nEntries << endl;
249 cout << "\nTask finished OK." << endl;
250}
251//-------------------------------------------------------------------------------------
252//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
253//-------------------------------------------------------------------------------------
254//-------------------------------------------------------------------------------------
256{
257 TObjArray arrayConditions;
260 arrayConditions.Add((TObject*)searchCondition);
261
262 TObjArray* pParameterValueArray = UniDetectorParameter::Search(arrayConditions);
263
264 // clean memory for conditions after search
265 for (int i = 0; i < arrayConditions.GetEntriesFast(); i++)
266 delete (UniSearchCondition*)arrayConditions[i];
267 arrayConditions.Clear();
268
269 size_t Nloaded = 0;
270 TString parName, inlParamName("inl");
271 int* DcSerial;
272 int* DcChannel;
273
274 for (int i = 0; i < pParameterValueArray->GetEntriesFast(); i++) {
275 UniDetectorParameter* pParameterValue = (UniDetectorParameter*)pParameterValueArray->At(i);
276
277 parName = pParameterValue->GetParameterName();
278 DcSerial = pParameterValue->GetDcSerial();
279 DcChannel = pParameterValue->GetChannel();
280
281 // inl TDC loading
282 if (parName == inlParamName) {
283 double* doublePtr;
284 int counter;
285 pParameterValue->GetDoubleArray(doublePtr, counter);
286
287 Nloaded += BmnTof1TDC::LoadInl(DcSerial, DcChannel, doublePtr, counter);
288 }
289 }
290
291 cout << " Parameters loaded = " << Nloaded << endl;
292
293 // clean memory after work
294 for (int i = 0; i < pParameterValueArray->GetEntriesFast(); i++)
295 delete (UniRun*)pParameterValueArray->At(i);
296 delete pParameterValueArray;
297}
298//-------------------------------------------------------------------------------------
299bool LoadGeoSetup(int runPeriod)
300{
301 GeoSetup gSetup;
302 string setupTag = gSetup.GetLastApprovedSetupTag(TString::Format("run%d", runPeriod).Data());
303 int res_code = gSetup.LoadSetupToGeoManager(setupTag);
304 if (res_code != 0) {
305 cerr << "\n ---> [LoadGeoSetup] Error: Can't load geometry '" << setupTag << "' from the Geometry Database."
306 << endl;
307 return false;
308 }
309
310 return true;
311}
312//-------------------------------------------------------------------------------------
314{
315 if (gGeoManager == nullptr) {
316 cerr << "\n ---> [ParseGeometry] Error: TGeoManager is not loaded." << endl;
317 return false;
318 }
319
320 parser->ParseTGeoManager(false, nullptr, true);
321
322 return true;
323}
324//-------------------------------------------------------------------------------------
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned char UChar_t
R__EXTERN TGeoManager * gGeoManager
UInt_t GetValue() const
Definition BmnTDCDigit.h:32
UInt_t GetSerial() const
Definition BmnTDCDigit.h:22
UChar_t GetHptdcId() const
Definition BmnTDCDigit.h:34
UChar_t GetSlot() const
Definition BmnTDCDigit.h:26
UChar_t GetChannel() const
Definition BmnTDCDigit.h:30
UChar_t GetType() const
Definition BmnTDCDigit.h:24
Bool_t GetLeading() const
Definition BmnTDCDigit.h:28
Int_t ParseTGeoManager(bool useMCinput, bool forced=false, Int_t verbose=0)
GeoSetup class.
Definition GeoSetup.h:40
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
Definition GeoSetup.cxx:512
string GetLastApprovedSetupTag(string_view tag_prefix)
Get tag for the last approved setup corresponding to the pattern.
Definition GeoSetup.cxx:122
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Bool_t cd() override
void Close(Option_t *option="") override
Int_t GetEntriesFast() const
void Clear(Option_t *option="") override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
void Add(TObject *obj) override
R__ALWAYS_INLINE Bool_t IsZombie() const
const char * Data() const
static TString Format(const char *fmt,...)
virtual Int_t Fill()
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
TString GetParameterName()
get parameter name of the current parameter value
static TObjArray * Search(UniSearchCondition &search_condition)
get parameters' values corresponding to the specified single condition and set owner for search_condi...
UniRun.h Class for the table: run_.
Definition UniRun.h:21
void LoadTofDBParameters()
bool LoadGeoSetup(int runPeriod)
bool ParseGeometry(BmnTof1GeoUtils *parser)
bool ParseGeoFile(BmnTof1GeoUtils *, const char *geoFlnm)
void digitConvertor()
Definition json.hpp:4446