BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnLambdaEmbedding.cxx
Go to the documentation of this file.
2
3#include "CbmStsPoint.h"
4#include "UniRun.h"
5
6// Defines GCC_DIAGNOSTIC_AWARE if GCC 4.7 or above
7#define GCC_DIAGNOSTIC_AWARE 1
8#if GCC_DIAGNOSTIC_AWARE
9#pragma GCC diagnostic ignored "-Wunknown-pragmas"
10#endif
11
13 : fInfo(nullptr)
14 , fSim(nullptr)
15 , fReco(nullptr)
16 , fLambdaSim(nullptr)
17 , fMCTracks(nullptr)
18 , fVertices(nullptr)
19 , fGemPoints(nullptr)
20 , fGemDigits(nullptr)
21 , fGemMatch(nullptr)
22 , fCscPoints(nullptr)
23 , fCscDigits(nullptr)
24 , fCscMatch(nullptr)
25 , fSiliconPoints(nullptr)
26 , fSiliconDigits(nullptr)
27 , fSiliconMatch(nullptr)
28 , fADC32(nullptr)
29 , fADC128(nullptr)
30 , fSync(nullptr)
31 , fLambdaStore(nullptr)
32 , fHeader(nullptr)
33 , fMon(nullptr)
34{
35 // Useful tools
36 fInfo = new BmnLambdaMisc(); // Initialize useful tools to work with mapping ...
37}
38
40 TString sim,
41 TString reco,
42 TString out,
43 Int_t nEvs,
44 TString lambdaStore)
45 : fInfo(nullptr)
46 , fSim(nullptr)
47 , fReco(nullptr)
48 , fLambdaSim(nullptr)
49 , fMCTracks(nullptr)
50 , fVertices(nullptr)
51 , fGemPoints(nullptr)
52 , fGemDigits(nullptr)
53 , fGemMatch(nullptr)
54 , fCscPoints(nullptr)
55 , fCscDigits(nullptr)
56 , fCscMatch(nullptr)
57 , fSiliconPoints(nullptr)
58 , fSiliconDigits(nullptr)
59 , fSiliconMatch(nullptr)
60 , fADC32(nullptr)
61 , fADC128(nullptr)
62 , fSync(nullptr)
63 , fLambdaStore(nullptr)
64 , fWrittenStores(nullptr)
65 , fHeader(nullptr)
66 , fMon(nullptr)
67 , normUtils(nullptr)
68 , fPdgDecParticle(3122)
69 , fPdgPostive(2212)
70 , fPdgNegative(-211)
71{
72 fDataFileName = raw;
73 fDigiFileName = out;
74 fStorePath = "outputDataStore";
75
76 // Initialize steering flags by default ...
85
89
90 fEvents = nEvs;
91
92 // Open simu file
93 fSim = new TChain("bmndata");
94 fSim->Add(sim.Data());
95 fSim->SetBranchAddress("MCTrack", &fMCTracks);
96
97 // Open dst file
98 fReco = new TChain("bmndata");
99 fReco->Add(reco.Data());
100 fReco->SetBranchAddress("BmnVertex", &fVertices);
101 fReco->SetBranchAddress("DstEventHeader.", &fHeader);
102
103 // Useful tools
104 fInfo = new BmnLambdaMisc(); // Initialize useful tools to work with mapping ...
105
106 fNstores = 10;
108 fStoreToProcess = -1;
109
110 if (!lambdaStore.IsNull()) {
112 for (Int_t iStore = 0; iStore < fNstores; iStore++)
113 fWrittenStores[iStore] = nullptr;
114
115 for (Int_t iStore = 0; iStore < fNstores; iStore++)
116 fWrittenStores[iStore] = new TClonesArray("BmnParticleStore");
117
118 TChain* ch = new TChain("bmndata");
119 ch->Add(lambdaStore.Data());
120
121 TClonesArray* tmp = nullptr;
122 ch->SetBranchAddress("BmnParticleStore", &tmp);
123
124 for (Int_t iStore = 0; iStore < fNstores; iStore++) {
125 ch->GetEntry(iStore);
126
127 fWrittenStores[iStore] = (TClonesArray*)(tmp->UncheckedAt(0))->Clone();
128 }
129
130 delete ch;
131 } else
132 fLambdaStore = new TClonesArray("BmnParticleStore");
133
134 fRunId = -1;
135 fFieldScale = -1.;
136
137 // Default cut values ...
138 fZmin = -3.;
139 fZmax = +3.;
140 fEtaMin = 0.;
141 fEtaMax = 100.;
142 fPhiMin = 0.;
143 fPhiMax = 360.;
144 fMomMin = 0.;
145 fNHitsProton = 4;
146 fNHitsPion = 4;
148
149 fSignal.push_back(1000);
150 fSignal.push_back(1500);
151 fSignal.push_back(1000);
152
153 // Resetting default values of flags depending on an user's scenario if recognized
154 // Scenario 1 (just selecting Lambdas ...)
155 if ((!out.Contains("digi") && !out.IsNull()) && raw.IsNull() && !sim.IsNull() && reco.IsNull()
156 && lambdaStore.IsNull())
157 {
158 cout << "Recognized scenario 1" << endl;
168 } // Scenario 2 (passing all stores (or selected one) in file to simulation ...)
169 else if (raw.IsNull() && sim.IsNull() && !reco.IsNull() && out.IsNull() && !lambdaStore.IsNull())
170 {
171 cout << "Recognized scenario 2 (or 3)" << endl;
180 }
181 // Scenario 4 (namely, embedding )
182 else if (!raw.IsNull() && (out.Contains("digi") && !out.IsNull()) && sim.IsNull() && !reco.IsNull()
183 && lambdaStore.IsNull())
184 {
185 cout << "Recognized scenario 4" << endl;
194 }
195}
196
198{
199 fFileNamePart = (fPdgDecParticle == 3122) ? "lambda" : (fPdgDecParticle == 310) ? "kaon" : "unknown";
200
201 // 0. Get a function from current dst to be used for rescaling ...
202 if (isUseRealSignal) {
203 TString digiFile = "";
204
205 TString eos_host = "root://ncm.jinr.ru/";
206 TString digiDir = "/eos/nica/bmn/exp/digi/";
207 TString run = "run7";
208 TString release = "20.02.0";
209 TString dirList[2] = {"4720-5186_BMN_Krypton", "3590-4707_BMN_Argon"};
210
211 fReco->GetEntry();
212
213 Int_t idx = (UniRun::GetRun(7, fHeader->GetRunId())->GetBeamParticle() == "Ar") ? 1
214 : (UniRun::GetRun(7, fHeader->GetRunId())->GetBeamParticle() == "Kr") ? 0
215 : -1;
216
217 TString command = TString::Format("xrdcp %s/%s/%s/%s/%s/bmn_run%d_digi.root %s", eos_host.Data(),
218 digiDir.Data(), run.Data(), release.Data(), dirList[idx].Data(),
219 fHeader->GetRunId(), gSystem->GetFromPipe("pwd").Data());
220
221 gSystem->Exec(command.Data());
222
223 TFile* file = new TFile(Form("bmn_run%d_digi.root", fHeader->GetRunId()));
224
225 if (file->IsOpen())
226 digiFile = file->GetName();
227
228 delete file;
229
230 if (!digiFile.IsNull())
231 normUtils = new SignalNormalizationUtils(digiFile, TString(fReco->GetFile()->GetName()));
232 }
233
234 // 1. Create a store with lambdas ...
235 if (doLambdaStore) {
236 if (!fDigiFileName.Contains("digi") && !fDigiFileName.IsNull()) {
238
239 TFile* f = new TFile(fDigiFileName.Data(), "recreate");
240 TTree* tree = new TTree("bmndata", "bmndata");
241
242 TClonesArray* tmp = new TClonesArray("BmnParticleStore");
243 tree->Branch("BmnParticleStore", &tmp);
244
245 for (Int_t iEntry = 0; iEntry < store->GetEntriesFast(); iEntry++) {
246 tmp->Delete();
247 TClonesArray* arr = (TClonesArray*)store->UncheckedAt(iEntry);
248
249 new ((*tmp)[tmp->GetEntriesFast()]) BmnParticleStore(*((BmnParticleStore*)arr));
250 tree->Fill();
251 }
252
253 tree->Write();
254
255 delete tmp;
256 delete tree;
257 delete f;
258
259 } else
261 }
262
265
266 // 2. Create list of eventId for reconstructed events where the primary vertex is assumed to be defined ...
267 map<UInt_t, TVector3> EventIdsVpMap;
269 EventIdsVpMap = ListOfEventsWithReconstructedVp();
270
271 // 3. Get information on mag. field in the run ...
273 if (fRunId != -1) {
274 Double_t map_current = 55.87;
275 UniRun* runInfo = UniRun::GetRun(7, fRunId);
276 if (runInfo)
277 fFieldScale = *runInfo->GetFieldVoltage() / map_current;
278 }
279 }
280
281 // 4. Loop over store with lambdas ...
282 // Int_t nThreads = 1;
283#if defined(_OPENMP)
284 nThreads = fNstores;
285 omp_set_num_threads(nThreads);
286#endif
287
289 Int_t low = (fStoreToProcess != -1) ? fStoreToProcess : 0;
290 Int_t up = (fStoreToProcess != -1) ? (fStoreToProcess + 1) : fNstores;
291
292#pragma omp parallel for
293 for (Int_t iLambda = low; iLambda < up; iLambda++) {
295 Double_t eta = lambda->GetEta();
296 Double_t phi = lambda->GetPhi();
297 Double_t p = lambda->GetP();
298 Double_t pdg = lambda->GetPdg();
299
300 Int_t iVertex = 0;
301
302 for (auto it : EventIdsVpMap) {
303 // Get reconstructed primary vertex ...
304 TVector3 Vp = it.second;
305
306 SimulateLambdaPassing(pdg, p, TVector2(eta, phi), Vp, iLambda, iVertex);
307
308 iVertex++;
309 }
310 }
311 }
312
313 // 5. Find at least one lambda to be reconstructed for a given Vp
314 map<UInt_t, pair<TVector3, TVector3>> GoodLambdaForEachVertex; // <evId ---> (<iLambda, iVertex, iEvent>, <Vp>)
315
316 map<UInt_t, BmnParticlePair>
317 embMonitorMap; // evId --> particlePair (see physics/particles/BmnParticlePair.h(*.cxx))
318
319 Int_t iVertex = 0;
320 for (auto it : EventIdsVpMap) {
321 UInt_t id = it.first;
322 TVector3 lambda(
323 -1, -1, -1); // <iLambda, iVertex, iEvent>, no appropriate any lambda found yet for current eventId ...
324 TVector3 Vp = it.second;
325
326 GoodLambdaForEachVertex[id] = make_pair(lambda, Vp); // Put info for a given eventId
327
328 BmnParticlePair aPairToBeWritten;
329 embMonitorMap[id] = aPairToBeWritten;
330
331 for (Int_t iLambda = 0; iLambda < fNstores; iLambda++) {
332 BmnParticlePair currentPair;
333
334 Int_t eve = FindReconstructableLambdaFromStore(iLambda, iVertex, currentPair);
335
336 // Put current pair into the embMonitorMap ...
337 auto itEmbInfoMap = embMonitorMap.find(id);
338 if (itEmbInfoMap != embMonitorMap.end())
339 (*itEmbInfoMap).second = currentPair;
340
341 if (eve != -1) {
342 TVector3 tmp = TVector3(iLambda, iVertex, eve);
343
344 // Trying to find id to be replaced ...
345 auto itr = GoodLambdaForEachVertex.find(id);
346 if (itr != GoodLambdaForEachVertex.end())
347 (*itr).second.first = tmp;
348
349 break;
350 }
351 }
352 iVertex++;
353 }
354
355 // 6. Monitor events with embedded lambdas ...
356 if (doEmbeddingMonitor) {
358 TFile* file = new TFile(Form("embedding_%d.root", fRunId), "recreate");
359 TTree* tree = new TTree("bmndata", "bmndata");
360
361 tree->Branch("EmbeddingMonitor.", &fMon);
362 for (auto it : GoodLambdaForEachVertex) {
363 UInt_t id = it.first;
364
365 TVector3 par = it.second.first;
366
367 fMon->SetId(id);
368 fMon->SetStoreVertexEvent(par);
369
370 auto itEmbInfoMap = embMonitorMap.find(id);
371 // if (itEmbInfoMap != embMonitorMap.end()) {
372 BmnParticlePair pair = (*itEmbInfoMap).second;
373
374 fMon->SetProtonP(pair.GetMomPart1());
375 fMon->SetPionP(pair.GetMomPart2());
376
377 fMon->SetTxProton(pair.GetTxPart1());
378 fMon->SetTxPion(pair.GetTxPart2());
379
380 fMon->SetTyProton(pair.GetTyPart1());
381 fMon->SetTyPion(pair.GetTyPart2());
382
383 fMon->SetNHitsProton(pair.GetNHitsPart1());
384 fMon->SetNHitsPion(pair.GetNHitsPart2());
385 // }
386
387 if ((Int_t)par[0] != -1 && (Int_t)par[1] != -1 && (Int_t)par[2] != -1)
388 fMon->IsEmbedded(kTRUE);
389
390 else
391 fMon->IsEmbedded(kFALSE);
392
393 tree->Fill();
394 }
395
396 tree->Write();
397 file->Close();
398 }
399
400 // 7. Create digi-arrays corresponding to a certain eventId ... <evId --> lambdaDigs>
401 map<UInt_t, vector<BmnStripDigit>> digsFromLambdasGem; // GEM
402 map<UInt_t, vector<BmnStripDigit>> digsFromLambdasSilicon; // SILICON
403 map<UInt_t, vector<BmnStripDigit>> digsFromLambdasCsc; // CSC
404
405 if (doEmbedding)
406 for (auto it : GoodLambdaForEachVertex) {
407 TVector3 par = it.second.first;
408 Int_t lambda = par[0];
409 Int_t vertex = par[1];
410 Int_t event = par[2];
411
412 if (lambda == -1 || vertex == -1 || event == -1)
413 continue;
414
415 if (isGemEmbedded)
416 digsFromLambdasGem[it.first] = GetDigitsFromLambda(
417 TString::Format("%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), lambda, vertex),
418 event, "GEM");
419 if (isSilEmbedded)
420 digsFromLambdasSilicon[it.first] = GetDigitsFromLambda(
421 TString::Format("%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), lambda, vertex),
422 event, "SILICON");
423 if (isCscEmbedded)
424 digsFromLambdasCsc[it.first] = GetDigitsFromLambda(
425 TString::Format("%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), lambda, vertex),
426 event, "CSC");
427 }
428
429 cout << "GEM# " << digsFromLambdasGem.size() << " SILICON# " << digsFromLambdasSilicon.size() << " CSC# "
430 << digsFromLambdasCsc.size() << endl;
431
432 // 7a. Collecting all MC-digits together ...
433 if (isUseRealSignal) {
434 TTree* tree = new TTree("bmndata", "bmndata");
435
436 TClonesArray* digitsGem = new TClonesArray("BmnGemStripDigit");
437 tree->Branch("BmnGemStripDigit", &digitsGem);
438
439 TClonesArray* digitsSil = new TClonesArray("BmnSiliconDigit");
440 tree->Branch("BmnSiliconDigit", &digitsSil);
441
442 for (auto digs : digsFromLambdasGem) {
443 digitsGem->Delete();
444
445 vector<BmnStripDigit> digitsInEvent = digs.second;
446
447 for (BmnStripDigit digit : digitsInEvent) {
448 BmnStripDigit* dig = &digit;
449
450 new ((*digitsGem)[digitsGem->GetEntriesFast()]) BmnStripDigit(dig);
451 }
452 tree->Fill();
453 }
454
455 for (auto digs : digsFromLambdasSilicon) {
456 digitsSil->Delete();
457
458 vector<BmnStripDigit> digitsInEvent = digs.second;
459
460 for (BmnStripDigit digit : digitsInEvent) {
461 BmnStripDigit* dig = &digit;
462
463 new ((*digitsSil)[digitsSil->GetEntriesFast()]) BmnStripDigit(dig);
464 }
465 tree->Fill();
466 }
467
468 normUtils->SetMcDataSet((TChain*)tree);
469 delete tree;
470 delete digitsGem;
471 delete digitsSil;
472
473 // Recalculating all signals according to the scal function got ...
474 TF1* scaleFuncGem = normUtils->GetRescaleFunction("GEM");
475 TF1* scaleFuncSil = normUtils->GetRescaleFunction("SILICON");
476
477 if (!scaleFuncGem || !scaleFuncSil) {
478 cout << "Something is wrong, exiting ..." << endl;
479 throw;
480 }
481
482 for (auto& digs : digsFromLambdasGem) {
483 vector<BmnStripDigit>& digitsInEvent = digs.second;
484
485 for (BmnStripDigit& digit : digitsInEvent)
486 digit.SetStripSignal(scaleFuncGem->Eval(digit.GetStripSignal()));
487 }
488
489 for (auto& digs : digsFromLambdasSilicon) {
490 vector<BmnStripDigit>& digitsInEvent = digs.second;
491
492 for (BmnStripDigit& digit : digitsInEvent)
493 digit.SetStripSignal(scaleFuncSil->Eval(digit.GetStripSignal()));
494 }
495 }
496
497 // 8. Make correspondence between evId and lambda digits with info on channel and serial ...
498 map<UInt_t, map<pair<Int_t, Int_t>, Long_t>>
499 evIdGemChannelSerial; // GEM --- <evId ---> <digi index + ch, serial>>
500 map<UInt_t, map<pair<Int_t, Int_t>, Long_t>>
501 evIdCscChannelSerial; // CSC --- <evId ---> <digi index + ch, serial>>
502 map<UInt_t, map<vector<Int_t>, Long_t>>
503 evIdSiliconChannelSerial; // SILICON --- <evId ---> <digi index + ch + sample, serial>>
504
505 if (doEmbedding) {
506 // GEM
507 if (isGemEmbedded)
508 for (auto it : digsFromLambdasGem) {
509 vector<BmnStripDigit> digits = it.second;
510 map<pair<Int_t, Int_t>, Long_t> tmpMap = GetGemChannelSerialFromDigi(digits);
511 evIdGemChannelSerial[it.first] = tmpMap;
512 }
513
514 // SILICON
515 if (isSilEmbedded)
516 for (auto it : digsFromLambdasSilicon) {
517 vector<BmnStripDigit> digits = it.second;
518 map<vector<Int_t>, Long_t> tmpMap = GetSiliconChannelSerialFromDigi(digits);
519 evIdSiliconChannelSerial[it.first] = tmpMap;
520 }
521
522 // CSC
523 if (isCscEmbedded)
524 for (auto it : digsFromLambdasCsc) {
525 vector<BmnStripDigit> digits = it.second;
526 map<pair<Int_t, Int_t>, Long_t> tmpMap = GetCscChannelSerialFromDigi(digits);
527 evIdCscChannelSerial[it.first] = tmpMap;
528 }
529 }
530
531 // 9. Do *.data --> *raw.root convertion for requested events ...
533
534 // 10. Loop over *raw.root to embed lambda digits ...
535 TString rawRoot = "";
536 if (doEmbedding)
537 rawRoot = AddInfoToRawFile(digsFromLambdasGem, evIdGemChannelSerial, digsFromLambdasSilicon,
538 evIdSiliconChannelSerial, digsFromLambdasCsc, evIdCscChannelSerial);
539
540 // 11. Start decoding ...
541 if (!rawRoot.IsNull() && doDecode)
543}
544
546 Int_t iVertex,
547 BmnParticlePair& pairFromLambda)
548{
549 TString fileName =
550 TString::Format("%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), iLambda, iVertex);
551 TChain ch("bmndata");
552 if (ch.Add(fileName.Data()) == 0)
553 return -1;
554
555 // Open lambda file
556 TClonesArray* tracks = nullptr;
557 TClonesArray* gemPoints = nullptr;
558 TClonesArray* siliconPoints = nullptr;
559 TClonesArray* cscPoints = nullptr;
560
561 ch.SetBranchAddress("MCTrack", &tracks);
562 ch.SetBranchAddress("StsPoint", &gemPoints);
563 ch.SetBranchAddress("SiliconPoint", &siliconPoints);
564 ch.SetBranchAddress("CSCPoint", &cscPoints);
565
566 for (Int_t iEv = 0; iEv < ch.GetEntries(); iEv++) {
567 ch.GetEntry(iEv);
568
569 // Loop over protons ...
570 // A proton we are looking for is single !
571 Int_t nHitsPerProton = 0;
572 Double_t Pprot = 0., TxProt = -1., TyProt = -1.;
573
574 for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++) {
575 CbmMCTrack* track = (CbmMCTrack*)tracks->UncheckedAt(iTrack);
576
577 // Skip primary tracks
578 if (track->GetMotherId() == -1)
579 continue;
580
581 // Skipping particles not been protons
582 if (track->GetPdgCode() != fPdgPostive)
583 continue;
584
585 Int_t id = track->GetMotherId();
586
587 // Get secondary protons and pions from lambda decay
588 if (((CbmMCTrack*)tracks->UncheckedAt(id))->GetPdgCode() != fPdgDecParticle)
589 continue;
590
591 if (track->GetP() < 0.5)
592 continue;
593
594 const Int_t nStats = 10; // 6 GEMs + 3 SILICONs + 1 CSC [<0 ... 5>, <6, 7, 8>, <9>]
595 Int_t pointsOnGemsSiliconsAndCsc[nStats];
596 for (Int_t iStat = 0; iStat < nStats; iStat++)
597 pointsOnGemsSiliconsAndCsc[iStat] = 0;
598
599 // Loop over gem points ...
600 if (isGemEmbedded)
601 for (Int_t iGem = 0; iGem < gemPoints->GetEntriesFast(); iGem++) {
602 CbmStsPoint* point = (CbmStsPoint*)gemPoints->UncheckedAt(iGem);
603 if (point->GetTrackID() != iTrack)
604 continue;
605 pointsOnGemsSiliconsAndCsc[point->GetStation()]++;
606 }
607
608 // Loop over silicon points ...
609 if (isSilEmbedded)
610 for (Int_t iSilicon = 0; iSilicon < siliconPoints->GetEntriesFast(); iSilicon++) {
611 FairMCPoint* point = (FairMCPoint*)siliconPoints->UncheckedAt(iSilicon);
612 if (point->GetTrackID() != iTrack)
613 continue;
614 pointsOnGemsSiliconsAndCsc[DefineSiliconStatByZpoint(point->GetZ())]++;
615 }
616
617 // Loop over csc points ...
618 if (isCscEmbedded)
619 for (Int_t iCsc = 0; iCsc < cscPoints->GetEntriesFast(); iCsc++) {
620 BmnCSCPoint* point = (BmnCSCPoint*)cscPoints->UncheckedAt(iCsc);
621 if (point->GetTrackID() != iTrack)
622 continue;
623 pointsOnGemsSiliconsAndCsc[9]++;
624 }
625
626 // Here we decide on a track whether being accepted or not according a list of detectors to be used when
627 // embedding MC-data ...
628 Bool_t isPrelimAccepted[3] = {kTRUE, kTRUE, kTRUE}; // GEM, SILICON, CSC ...
629 Int_t pointCounter;
630
631 // Checking GEMs ...
632 if (isGemEmbedded) {
633 pointCounter = 0;
634 for (Int_t iStat = 0; iStat < 6; iStat++) {
635 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
636 pointCounter++;
637 }
638 if (pointCounter == 0)
639 isPrelimAccepted[0] = kFALSE;
640 }
641
642 // Checking SILICONs ...
643 if (isSilEmbedded) {
644 pointCounter = 0;
645 for (Int_t iStat = 6; iStat < 9; iStat++) {
646 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
647 pointCounter++;
648 }
649 if (pointCounter == 0)
650 isPrelimAccepted[1] = kFALSE;
651 }
652
653 // Checking CSC ...
654 if (isCscEmbedded) {
655 pointCounter = 0;
656 for (Int_t iStat = 9; iStat < nStats; iStat++) {
657 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
658 pointCounter++;
659 }
660 if (pointCounter == 0)
661 isPrelimAccepted[2] = kFALSE;
662 }
663
664 Bool_t doWeAcceptEvent =
665 (isPrelimAccepted[0] && isPrelimAccepted[1] && isPrelimAccepted[2]) ? kTRUE : kFALSE;
666
667 if (!doWeAcceptEvent)
668 continue;
669
670 // Loop over statArray to avoid multiple Z ...
671 Bool_t isMultiplePointsOnZ = kFALSE;
672 for (Int_t iStat = 0; iStat < nStats; iStat++) {
673 if (pointsOnGemsSiliconsAndCsc[iStat] == 2) {
674 isMultiplePointsOnZ = kTRUE;
675 break;
676 } else
677 nHitsPerProton += pointsOnGemsSiliconsAndCsc[iStat];
678 }
679 if (isMultiplePointsOnZ || nHitsPerProton < 4 || nHitsPerProton > nStats)
680 continue;
681
682 Pprot = track->GetP();
683 TxProt = track->GetPx() / track->GetPz();
684 TyProt = track->GetPy() / track->GetPz();
685 }
686
687 // Skipping the next loop if not satisfied condition ...
688 if (nHitsPerProton < fNHitsProton || Abs(Pprot) < FLT_EPSILON)
689 continue;
690
691 // Loop over pions ...
692 Int_t nHitsPerPion = 0;
693 Double_t Ppion = 0., TxPion = -1., TyPion = -1.;
694
695 for (Int_t jTrack = 0; jTrack < tracks->GetEntriesFast(); jTrack++) {
696 CbmMCTrack* track = (CbmMCTrack*)tracks->UncheckedAt(jTrack);
697
698 // Skip primary tracks
699 if (track->GetMotherId() == -1)
700 continue;
701
702 // Skipping particles not been pions ...
703 if (track->GetPdgCode() != fPdgNegative)
704 continue;
705
706 Int_t id = track->GetMotherId();
707
708 // Get secondary protons and pions from lambda decay
709 if (((CbmMCTrack*)tracks->UncheckedAt(id))->GetPdgCode() != fPdgDecParticle)
710 continue;
711
712 if (track->GetP() < 0.5)
713 continue;
714
715 const Int_t nStats = 9; // 6 GEMs + 3 SILICONs [<0 ... 5>, <6, 7, 8>]
716 Int_t pointsOnGemsAndSilicon[nStats];
717 for (Int_t iStat = 0; iStat < nStats; iStat++)
718 pointsOnGemsAndSilicon[iStat] = 0;
719
720 // Loop over gem points ...
721 if (isGemEmbedded)
722 for (Int_t iGem = 0; iGem < gemPoints->GetEntriesFast(); iGem++) {
723 CbmStsPoint* point = (CbmStsPoint*)gemPoints->UncheckedAt(iGem);
724 if (point->GetTrackID() != jTrack)
725 continue;
726 pointsOnGemsAndSilicon[point->GetStation()]++;
727 }
728
729 // Loop over silicon points ...
730 if (isSilEmbedded)
731 for (Int_t iSilicon = 0; iSilicon < siliconPoints->GetEntriesFast(); iSilicon++) {
732 FairMCPoint* point = (FairMCPoint*)siliconPoints->UncheckedAt(iSilicon);
733 if (point->GetTrackID() != jTrack)
734 continue;
735 pointsOnGemsAndSilicon[DefineSiliconStatByZpoint(point->GetZ())]++;
736 }
737
738 // Here we decide on a track whether being accepted or not according a list of detectors to be used when
739 // embedding MC-data ...
740 Bool_t isPrelimAccepted[2] = {kTRUE, kTRUE}; // GEM, SILICON
741 Int_t pointCounter;
742
743 // Checking GEMs ...
744 if (isGemEmbedded) {
745 pointCounter = 0;
746 for (Int_t iStat = 0; iStat < 6; iStat++) {
747 if (pointsOnGemsAndSilicon[iStat] != 0)
748 pointCounter++;
749 }
750 if (pointCounter == 0)
751 isPrelimAccepted[0] = kFALSE;
752 }
753
754 // Checking SILICONs ...
755 if (isSilEmbedded) {
756 pointCounter = 0;
757 for (Int_t iStat = 6; iStat < nStats; iStat++) {
758 if (pointsOnGemsAndSilicon[iStat] != 0)
759 pointCounter++;
760 }
761 if (pointCounter == 0)
762 isPrelimAccepted[1] = kFALSE;
763 }
764
765 Bool_t doWeAcceptEvent = (isPrelimAccepted[0] && isPrelimAccepted[1]) ? kTRUE : kFALSE;
766
767 if (!doWeAcceptEvent)
768 continue;
769
770 // Loop over statArray to avoid multiple Z ...
771 Bool_t isMultiplePointsOnZ = kFALSE;
772 for (Int_t iStat = 0; iStat < nStats; iStat++) {
773 if (pointsOnGemsAndSilicon[iStat] == 2) {
774 isMultiplePointsOnZ = kTRUE;
775 break;
776 } else
777 nHitsPerPion += pointsOnGemsAndSilicon[iStat];
778 }
779 if (isMultiplePointsOnZ || nHitsPerPion < 4 || nHitsPerPion > nStats)
780 continue;
781
782 Ppion = track->GetP();
783 TxPion = track->GetPx() / track->GetPz();
784 TyPion = track->GetPy() / track->GetPz();
785 }
786
787 if (nHitsPerPion < fNHitsPion || Abs(Ppion) < FLT_EPSILON)
788 continue;
789
790 pairFromLambda.SetMomPair(Pprot, Ppion);
791 pairFromLambda.SetTxPair(TxProt, TxPion);
792 pairFromLambda.SetTyPair(TyProt, TyPion);
793 pairFromLambda.SetNHitsPair(nHitsPerProton, nHitsPerPion);
794
795 return iEv;
796 }
797 return -1;
798}
799
801{
802 BmnRawDataDecoder* decoder = new BmnRawDataDecoder(raw, "", fEvents);
803 decoder->SetPeriodId(7);
804 decoder->SetRunId(fRunId);
805
807 decoder->ConvertRawToRoot();
809
810 delete decoder;
811}
812
814{
815 BmnRawDataDecoder* rdd = new BmnRawDataDecoder("", "", fEvents);
816 BmnDecoder* decoder = rdd->GetDecoder();
817 decoder->SetPeriodId(7);
818 decoder->SetRunId(fRunId);
819 decoder->SetRawRootFile(raw);
821 decoder->SetBmnSetup(kBMNSETUP);
822
823 std::map<DetectorId, bool> setup; // flags to determine BM@N setup
824 setup.insert(std::make_pair(kBC, 0)); // TRIGGERS
825 setup.insert(std::make_pair(kSILICON, 1)); // SILICON
826 setup.insert(std::make_pair(kGEM, 1)); // GEM
827
828 decoder->SetDetectorSetup(setup);
829
830 decoder->SetMSCMapping("MSC_map_Run7.txt");
831 decoder->SetTrigPlaceMapping("Trig_PlaceMap_Run7.txt");
832 decoder->SetTrigChannelMapping("Trig_map_Run7.txt");
833 decoder->SetSiliconMapping("SILICON_map_run7.txt");
834 decoder->SetGemMapping("GEM_map_run7.txt");
835 decoder->SetCSCMapping("CSC_map_period7.txt");
836
837 decoder->DecodeDataToDigi();
838
839 delete decoder;
840}
841
843{
844 map<UInt_t, TVector3> EventIdsVpMap;
845 for (Int_t iEntry = 0; iEntry < fEvents; iEntry++) {
846 fReco->GetEntry(iEntry);
847
848 if (iEntry == 0)
849 fRunId = fHeader->GetRunId();
850
851 CbmVertex* vertex = (CbmVertex*)fVertices->UncheckedAt(0);
852
853 // Used cuts on primary vertex
854 if (vertex->GetZ() < fZmin || vertex->GetZ() > fZmax)
855 continue;
856
857 EventIdsVpMap[fHeader->GetEventId()] = TVector3(vertex->GetX(), vertex->GetY(), vertex->GetZ());
858 }
859 return EventIdsVpMap;
860}
861
862vector<BmnStripDigit> BmnLambdaEmbedding::GetDigitsFromLambda(TString lambdaEve, Int_t evNum, TString det)
863{
864 Bool_t isSilicon = (det.Contains("SILICON")) ? kTRUE : kFALSE;
865 Bool_t isGem = (det.Contains("GEM")) ? kTRUE : kFALSE;
866 Bool_t isCsc = (det.Contains("CSC")) ? kTRUE : kFALSE;
867
868 vector<BmnStripDigit> digits;
869
870 // Open file with simulated lambdas
871 fLambdaSim = new TChain("bmndata");
872 fLambdaSim->Add(lambdaEve.Data());
873 fLambdaSim->SetBranchAddress("MCTrack", &fMCTracks);
874
875 fLambdaSim->SetBranchAddress("SiliconPoint", &fSiliconPoints);
876 fLambdaSim->SetBranchAddress("BmnSiliconDigit", &fSiliconDigits);
877 fLambdaSim->SetBranchAddress("BmnSiliconDigitMatch", &fSiliconMatch);
878
879 fLambdaSim->SetBranchAddress("StsPoint", &fGemPoints);
880 fLambdaSim->SetBranchAddress("BmnGemStripDigit", &fGemDigits);
881 fLambdaSim->SetBranchAddress("BmnGemStripDigitMatch", &fGemMatch);
882
883 fLambdaSim->SetBranchAddress("CSCPoint", &fCscPoints);
884 fLambdaSim->SetBranchAddress("BmnCSCDigit", &fCscDigits);
885 fLambdaSim->SetBranchAddress("BmnCSCDigitMatch", &fCscMatch);
886
887 fLambdaSim->GetEntry(evNum);
888
889 Int_t idxPi = -1, idxProt = -1;
890
891 // Looking for protons and pions from lambda decay
892 for (Int_t iTrack = 0; iTrack < fMCTracks->GetEntriesFast(); iTrack++) {
893 CbmMCTrack* track = (CbmMCTrack*)fMCTracks->UncheckedAt(iTrack);
894
895 // Skip primary tracks
896 if (track->GetMotherId() == -1)
897 continue;
898
899 // Skip particles not been protons or pions
900 if (track->GetPdgCode() != fPdgPostive && track->GetPdgCode() != fPdgNegative)
901 continue;
902
903 Int_t pdg = track->GetPdgCode();
904 Int_t id = track->GetMotherId();
905
906 // Get secondary protons and pions from lambda decay
907 if (((CbmMCTrack*)fMCTracks->UncheckedAt(id))->GetPdgCode() != fPdgDecParticle)
908 continue;
909
910 if (pdg > 0)
911 idxProt = iTrack;
912 else
913 idxPi = iTrack;
914 }
915
916 // Loop over GEM-digits
917 if (isGem)
918 for (Int_t iDig = 0; iDig < fGemDigits->GetEntriesFast(); iDig++) {
919 BmnMatch* digiMatch = (BmnMatch*)fGemMatch->UncheckedAt(iDig);
920
921 Int_t idxPoint = digiMatch->GetMatchedLink().GetIndex();
922 FairMCPoint* point = (FairMCPoint*)fGemPoints->UncheckedAt(idxPoint);
923 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
924 continue;
925
926 BmnStripDigit* digi = (BmnStripDigit*)fGemDigits->UncheckedAt(iDig);
927 // digi->SetName((point->GetTrackID() == idxProt) ? "PROTON" : "PION");
928 digits.push_back(*digi);
929 }
930
931 // Loop over CSC-digits
932 if (isCsc)
933 for (Int_t iDig = 0; iDig < fCscDigits->GetEntriesFast(); iDig++) {
934 BmnMatch* digiMatch = (BmnMatch*)fCscMatch->UncheckedAt(iDig);
935
936 Int_t idxPoint = digiMatch->GetMatchedLink().GetIndex();
937 FairMCPoint* point = (FairMCPoint*)fCscPoints->UncheckedAt(idxPoint);
938 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
939 continue;
940
941 BmnStripDigit* digi = (BmnStripDigit*)fCscDigits->UncheckedAt(iDig);
942 digits.push_back(*digi);
943 }
944
945 // Loop over SILICON-digits
946 if (isSilicon)
947 for (Int_t iDig = 0; iDig < fSiliconDigits->GetEntriesFast(); iDig++) {
948 BmnMatch* digiMatch = (BmnMatch*)fSiliconMatch->UncheckedAt(iDig);
949
950 Int_t idxPoint = digiMatch->GetMatchedLink().GetIndex();
951 FairMCPoint* point = (FairMCPoint*)fSiliconPoints->UncheckedAt(idxPoint);
952 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
953 continue;
954
955 BmnStripDigit* digi = (BmnStripDigit*)fSiliconDigits->UncheckedAt(iDig);
956 digits.push_back(*digi);
957 }
958
959 delete fLambdaSim;
960
961 return digits;
962}
963
964map<pair<Int_t, Int_t>, Long_t> BmnLambdaEmbedding::GetGemChannelSerialFromDigi(vector<BmnStripDigit> digits)
965{
966 map<Int_t, Int_t> digiToChannel; // (digi index in vector ---> channel)
967 map<pair<Int_t, Int_t>, Long_t> digiChannelToSerial; // (digi index in vector + channel ---> serial)
968
969 const Int_t nDigs = digits.size();
970
971 // Fill digiToChannel map ...
972 Long_t serial[nDigs];
973
974 for (Int_t iDigi = 0; iDigi < nDigs; iDigi++) {
975 serial[iDigi] = 0x0;
976 BmnStripDigit* dig = &digits[iDigi];
977 digiToChannel[iDigi] = fInfo->GemDigiToChannel(dig, serial[iDigi]);
978 }
979
980 // Fill digiChannelToSerial map ...
981 for (auto it : digiToChannel) {
982
983 // Skip digits with no channel found ...
984 if (it.second == -1)
985 continue;
986
987 Long_t value = (serial[it.first] == 0) ? fInfo->GemDigiChannelToSerial(make_pair(digits[it.first], it.second))
988 : serial[it.first];
989 digiChannelToSerial[make_pair(it.first, it.second)] = value;
990 }
991
992 return digiChannelToSerial;
993}
994
995map<pair<Int_t, Int_t>, Long_t> BmnLambdaEmbedding::GetCscChannelSerialFromDigi(vector<BmnStripDigit> digits)
996{
997 map<pair<Int_t, Int_t>, Long_t> digiChannelToSerial; // (digi index in vector + channel ---> serial)
998
999 for (size_t iDigi = 0; iDigi < digits.size(); iDigi++) {
1000 BmnStripDigit* dig = &digits[iDigi];
1001
1002 Long_t serial = 0x0;
1003
1004 digiChannelToSerial[make_pair(iDigi, fInfo->CscDigiToChannel(dig, serial))] = serial;
1005 }
1006
1007 return digiChannelToSerial;
1008}
1009
1010map<vector<Int_t>, Long_t> BmnLambdaEmbedding::GetSiliconChannelSerialFromDigi(vector<BmnStripDigit> digits)
1011{
1012 map<vector<Int_t>, Long_t> digiChannelToSerial; // (digi index in vector + channel + sample ---> serial)
1013
1014 for (size_t iDigi = 0; iDigi < digits.size(); iDigi++) {
1015 BmnStripDigit* dig = &digits[iDigi];
1016
1017 Int_t chan = -1, sample = -1;
1018 Long_t serial = 0x0;
1019
1020 // Get channel, sample and serial information ...
1021 fInfo->SiliconDigiToChannelSampleSerial(dig, chan, sample, serial);
1022 vector<Int_t> tmp{(int)iDigi, chan, sample};
1023
1024 digiChannelToSerial[tmp] = serial;
1025 }
1026
1027 return digiChannelToSerial;
1028}
1029
1030TString BmnLambdaEmbedding::AddInfoToRawFile(map<UInt_t, vector<BmnStripDigit>> digsGem,
1031 map<UInt_t, map<pair<Int_t, Int_t>, Long_t>> evIdChannelSerialGem,
1032 map<UInt_t, vector<BmnStripDigit>> digsSilicon,
1033 map<UInt_t, map<vector<Int_t>, Long_t>> evIdChannelSerialSilicon,
1034 map<UInt_t, vector<BmnStripDigit>> digsCsc,
1035 map<UInt_t, map<pair<Int_t, Int_t>, Long_t>> evIdChannelSerialCsc)
1036{
1037
1038 // Create output file ...
1040 tmp = tmp.ReplaceAll(".root", "");
1041 tmp += "_withLambdaEmbedded.root";
1042
1043 TFile* f = new TFile(tmp.Data(), "recreate");
1044 TTree* t = new TTree("BMN_RAW", "BMN_RAW");
1045
1046 TClonesArray* gemOrCsc = new TClonesArray("BmnADCDigit");
1047 TClonesArray* silicon = new TClonesArray("BmnADCDigit");
1048 TClonesArray* sync = new TClonesArray("BmnSyncDigit");
1049
1050 BmnEventHeader* header = new BmnEventHeader();
1051
1052 t->Branch("BmnEventHeader.", &header);
1053 t->Branch("SYNC", &sync);
1054 t->Branch("ADC32", &gemOrCsc);
1055 t->Branch("ADC128", &silicon);
1056
1057 TChain* ch = new TChain("BMN_RAW");
1058 ch->Add(fRawRootFileName.Data());
1059
1060 BmnEventHeader* fEventHeader = nullptr;
1061
1062 ch->SetBranchAddress("ADC32", &fADC32);
1063 ch->SetBranchAddress("ADC128", &fADC128);
1064 ch->SetBranchAddress("SYNC", &fSync);
1065 ch->SetBranchAddress("BmnEventHeader.", &fEventHeader);
1066
1067 // Loop over existing *raw.root file ...
1068 for (Int_t iEntry = 0; iEntry < fEvents; iEntry++) {
1069 if (iEntry % 1000 == 0)
1070 cout << "Embedding, event# " << iEntry << endl;
1071 // Clear TClonesArrays from the previous event ...
1072 gemOrCsc->Delete();
1073 silicon->Delete();
1074 sync->Delete();
1075
1076 ch->GetEntry(iEntry);
1077
1078 UInt_t eventId = fEventHeader->GetEventId();
1079
1080 header->SetRunId(fEventHeader->GetRunId());
1081 header->SetEventId(eventId);
1082 header->SetEventType(fEventHeader->GetEventType());
1083
1084 // Get SYNC digits ....
1085 for (Int_t iSync = 0; iSync < fSync->GetEntriesFast(); iSync++) {
1086 BmnSyncDigit* dig = (BmnSyncDigit*)fSync->UncheckedAt(iSync);
1087
1088 new ((*sync)[sync->GetEntriesFast()])
1089 BmnSyncDigit(dig->GetSerial(), dig->GetEvent(), dig->GetTime_sec(), dig->GetTime_ns());
1090 }
1091
1092 // Looking for current eventId in the digi-map ...
1093 // EventId should be the same for three maps (digsGem, digsSilicon, digsCsc)
1094 Bool_t isEventIdFoundInTheMap = kTRUE;
1095
1096 auto itDigGem = digsGem.find(eventId);
1097 auto itDigSilicon = digsSilicon.find(eventId);
1098 auto itDigCsc = digsCsc.find(eventId);
1099
1100 if (itDigGem == digsGem.end())
1101 isEventIdFoundInTheMap = kFALSE;
1102
1103 // Array with digits for certain eventId
1104 // GEM
1105 vector<BmnStripDigit> digitsGem;
1106 map<pair<Int_t, Int_t>, Long_t> idxChanSerGem;
1107
1108 // SILICON
1109 vector<BmnStripDigit> digitsSilicon;
1110 map<vector<Int_t>, Long_t> idxChanSampleSerSilicon;
1111
1112 // CSC
1113 vector<BmnStripDigit> digitsCsc;
1114 map<pair<Int_t, Int_t>, Long_t> idxChanSerCsc;
1115
1116 if (isEventIdFoundInTheMap) {
1117 // GEM
1118 if (isGemEmbedded) {
1119 digitsGem = itDigGem->second;
1120 idxChanSerGem = evIdChannelSerialGem.find(eventId)->second;
1121 }
1122
1123 // SILICON
1124 if (isSilEmbedded) {
1125 digitsSilicon = itDigSilicon->second;
1126 idxChanSampleSerSilicon = evIdChannelSerialSilicon.find(eventId)->second;
1127 }
1128
1129 // CSC
1130 if (isCscEmbedded) {
1131 digitsCsc = itDigCsc->second;
1132 idxChanSerCsc = evIdChannelSerialCsc.find(eventId)->second;
1133 }
1134 }
1135
1136 // GEM and CSC
1138 for (Int_t iAdc32 = 0; iAdc32 < fADC32->GetEntriesFast(); iAdc32++) {
1139 BmnADCDigit* adc32 = (BmnADCDigit*)fADC32->UncheckedAt(iAdc32);
1140
1141 UInt_t channel = adc32->GetChannel(); // ---> (0 ... 63)
1142 UInt_t serial = adc32->GetSerial();
1143
1144 // GEM:
1145 // Looking for a pair <channel, serial> in the correspondence map ...
1146 if (isGemEmbedded)
1147 for (auto itCorr : idxChanSerGem) {
1148 Int_t channelTmp = itCorr.first.second; // ---> (0 ... 2047)
1149
1150 Int_t channelBuff = Int_t(channelTmp / 32);
1151 Long_t serialBuff = itCorr.second;
1152
1153 if ((Int_t)channel != channelBuff || serial != serialBuff)
1154 continue;
1155
1156 Int_t sample = Int_t(channelTmp % 32);
1157 Int_t signal = Int_t(digitsGem[itCorr.first.first].GetStripSignal());
1158
1159 if (isUseRealSignal)
1160 adc32->GetShortValue()[sample] += signal * 16;
1161 else
1162 adc32->GetShortValue()[sample] += fSignal[0] * 16;
1163
1164 adc32->SetAsEmbedded(kTRUE);
1165 }
1166
1167 // CSC:
1168 // Looking for a pair <channel, serial> in the correspondence map ...
1169 if (isCscEmbedded)
1170 for (auto itCorr : idxChanSerCsc) {
1171 Int_t channelTmp = itCorr.first.second; // ---> (0 ... 2047)
1172
1173 Int_t channelBuff = Int_t(channelTmp / 32);
1174 Long_t serialBuff = itCorr.second;
1175
1176 if ((Int_t)channel != channelBuff || serial != serialBuff)
1177 continue;
1178
1179 Int_t sample = Int_t(channelTmp % 32);
1180 Int_t signal = Int_t(digitsCsc[itCorr.first.first].GetStripSignal() * 16.);
1181
1182 if (isUseRealSignal)
1183 adc32->GetShortValue()[sample] += signal;
1184 else
1185 adc32->GetShortValue()[sample] += fSignal[2] * 16;
1186
1187 adc32->SetAsEmbedded(kTRUE);
1188 }
1189
1190 // Write ADC-digit to the output file ...
1191 new ((*gemOrCsc)[gemOrCsc->GetEntriesFast()])
1192 BmnADCDigit(adc32->GetSerial(), adc32->GetChannel(), adc32->GetNSamples(), adc32->GetShortValue(),
1193 adc32->IsEmbedded());
1194 }
1195
1196 // SILICON
1197 if (isSilEmbedded)
1198 for (Int_t iAdc128 = 0; iAdc128 < fADC128->GetEntriesFast(); iAdc128++) {
1199 BmnADCDigit* adc128 = (BmnADCDigit*)fADC128->UncheckedAt(iAdc128);
1200
1201 UInt_t channel = adc128->GetChannel();
1202 UInt_t serial = adc128->GetSerial();
1203
1204 // Looking for an entry with a given <channel, sample, serial> in the correspondence map ...
1205 for (auto itCorr : idxChanSampleSerSilicon) {
1206 Int_t chan = itCorr.first[1];
1207 Long_t ser = itCorr.second;
1208
1209 if ((Int_t)channel != chan || serial != ser)
1210 continue;
1211
1212 Int_t idx = itCorr.first[0];
1213 Int_t signal = Int_t(digitsSilicon[idx].GetStripSignal() * 16.);
1214
1215 Int_t sample = itCorr.first[2];
1216
1217 // x'-layer has a negative polarity!
1218 Int_t sign = (digitsSilicon[idx].GetStripLayer() == 0) ? +1 : -1;
1219 if (isUseRealSignal)
1220 adc128->GetShortValue()[sample] += sign * signal;
1221 else
1222 adc128->GetShortValue()[sample] += sign * fSignal[1] * 16;
1223
1224 adc128->SetAsEmbedded(kTRUE);
1225 }
1226
1227 // Write ADC-digit to the output file ...
1228 new ((*silicon)[silicon->GetEntriesFast()])
1229 BmnADCDigit(adc128->GetSerial(), adc128->GetChannel(), adc128->GetNSamples(),
1230 adc128->GetShortValue(), adc128->IsEmbedded());
1231 }
1232
1233 t->Fill();
1234 }
1235
1236 delete ch;
1237
1238 t->Write();
1239 f->Close();
1240
1241 return tmp;
1242}
1243
1244// Create store of possible primary lambdas to be used for embedding ...
1245
1247{
1248 cout << fNstores << endl;
1249 for (Int_t iEntry = 0; iEntry < fSim->GetEntries(); iEntry++) {
1250 fSim->GetEntry(iEntry);
1251 if (iEntry % 1000 == 0) {
1252 cout << "Event# " << iEntry << " processed" << endl;
1253 cout << "Size of store# " << fLambdaStore->GetEntriesFast() << endl;
1254 }
1255
1256 if (fLambdaStore->GetEntriesFast() == fNstores) // Maximum size of current store
1257 break;
1258
1259 for (Int_t iTrack = 0; iTrack < fMCTracks->GetEntriesFast(); iTrack++) {
1260 CbmMCTrack* track = (CbmMCTrack*)fMCTracks->UncheckedAt(iTrack);
1261
1262 // Get primary lambdas only ...
1263 if (track->GetPdgCode() != fPdgDecParticle || track->GetMotherId() != -1)
1264 continue;
1265
1266 // Get lambdas in forward direction ...
1267 if (track->GetPz() < 0.)
1268 continue;
1269
1270 Double_t p = track->GetP();
1271 Double_t Tx = track->GetPx() / track->GetPz();
1272 Double_t Ty = track->GetPy() / track->GetPz();
1273
1274 Double_t Pz = p / TMath::Sqrt(1 + Tx * Tx + Ty * Ty);
1275 Double_t eta = 0.5 * TMath::Log((p + Pz) / (p - Pz));
1276
1277 TVector3 tmp(Tx * Pz, Ty * Pz, Pz);
1278 Double_t phi = tmp.Phi() * TMath::RadToDeg() + 180.;
1279
1280 if (eta < fEtaMin || eta > fEtaMax || p < fMomMin || phi < fPhiMin || phi > fPhiMax)
1281 continue;
1282
1283 new ((*fLambdaStore)[fLambdaStore->GetEntriesFast()]) BmnParticleStore(fPdgDecParticle, p, Tx, Ty);
1284 }
1285 }
1286 return fLambdaStore;
1287}
1288
1290{
1291 cout << "N_particles_store# " << fLambdaStore->GetEntriesFast() << endl;
1292
1293 for (Int_t iLambda = 0; iLambda < fLambdaStore->GetEntriesFast(); iLambda++) {
1294 BmnParticleStore* lambda = (BmnParticleStore*)fLambdaStore->UncheckedAt(iLambda);
1295 cout << "P = " << lambda->GetP() << " Eta = " << lambda->GetEta() << " Phi = " << lambda->GetPhi() << endl;
1296 }
1297}
1298
1300{
1301 delete fSim;
1302 delete fReco;
1303
1304 delete fInfo;
1305
1306 if (fMon)
1307 delete fMon;
1308
1309 if (normUtils)
1310 delete normUtils;
1311}
1312
1314 Double_t P,
1315 TVector2 pos,
1316 TVector3 Vp,
1317 Int_t iLambda,
1318 Int_t iVertex)
1319{
1320 // Here there is a list of arguments to be passed to the macro below ...
1321
1322 TString namePart = (pdg == 3122) ? "lambda" : (pdg == 310) ? "kaon" : "unknown";
1323 TString outFile = TString::Format("%s/%s%d_vertex%d.root", fStorePath.Data(), namePart.Data(), iLambda, iVertex);
1324
1325 TString macroName = "SimulateLambdaPassing.C";
1326
1327 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
1328 TString gPathFull = gPathConfig + "/macro/embedding/" + macroName;
1329
1330 TString argList = TString::Format("(%d, %d, %G, %G, %G, %G, %G, %G, %G, \"%s\")", pdg, fNeventsToBeSimulated,
1331 fFieldScale, P, pos.X(), pos.Y(), Vp.X(), Vp.Y(), Vp.Z(), outFile.Data());
1332 TString exeCommand = TString::Format("root -b -q '%s%s'", gPathFull.Data(), argList.Data());
1333
1334 gSystem->Exec(exeCommand.Data());
1335}
1336
1338{
1339 // Boardings are valid for RUN7 only!!!
1340 const Double_t z1 = 14.;
1341 const Double_t z2 = 20.;
1342
1343 Int_t shift = 6; // nGems in RUN7
1344 Int_t tmp;
1345
1346 if (z < z1)
1347 tmp = 0;
1348 else if (z > z1 && z < z2)
1349 tmp = 1;
1350 else if (z > z2)
1351 tmp = 2;
1352 else
1353 return -1;
1354
1355 return shift + tmp;
1356}
bool Bool_t
int Int_t
long Long_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
@ kBC
@ kSILICON
@ kGEM
@ kBMNSETUP
Definition BmnEnums.h:166
void SetAsEmbedded(Bool_t flag)
Definition BmnADCDigit.h:57
uint32_t GetNSamples()
Definition BmnADCDigit.h:53
Bool_t IsEmbedded()
Definition BmnADCDigit.h:59
uint32_t GetSerial() const
Definition BmnADCDigit.h:49
uint16_t GetChannel() const
Definition BmnADCDigit.h:51
void SetBmnSetup(BmnSetup v)
Definition BmnDecoder.h:235
void SetRunId(UInt_t v)
Definition BmnDecoder.h:124
void SetRawRootFile(TString filename)
Definition BmnDecoder.h:270
void SetDetectorSetup(std::map< DetectorId, bool > setup)
Definition BmnDecoder.h:229
void SetDigiRootFile(TString filename)
Definition BmnDecoder.h:272
void SetMSCMapping(TString map)
Definition BmnDecoder.h:225
void SetPeriodId(UInt_t v)
Definition BmnDecoder.h:126
void SetTrigPlaceMapping(TString map)
Definition BmnDecoder.h:160
void SetGemMapping(TString map)
Definition BmnDecoder.h:174
BmnStatus DecodeDataToDigi()
void SetTrigChannelMapping(TString file)
Definition BmnDecoder.h:168
void SetCSCMapping(TString map)
Definition BmnDecoder.h:166
void SetSiliconMapping(TString map)
Definition BmnDecoder.h:162
void SetEventType(BmnEventType event_type)
Set the type for this event.
UInt_t GetEventId()
Get the event ID for this event.
BmnEventType GetEventType()
Get the type of this event.
void SetEventId(UInt_t event_id)
Set the event ID for this event.
DstEventHeader * fHeader
void SimulateLambdaPassing(Int_t, Double_t, TVector2, TVector3, Int_t, Int_t)
void SetUseRealSignals(Bool_t flag)
SignalNormalizationUtils * normUtils
TClonesArray * fSiliconMatch
void DoRawRootConvertion(Bool_t flag)
map< vector< Int_t >, Long_t > GetSiliconChannelSerialFromDigi(vector< BmnStripDigit >)
TClonesArray * fSiliconDigits
map< pair< Int_t, Int_t >, Long_t > GetCscChannelSerialFromDigi(vector< BmnStripDigit >)
BmnLambdaEmbeddingMonitor * fMon
void DoSimulateLambdaThroughSetup(Bool_t flag)
map< pair< Int_t, Int_t >, Long_t > GetGemChannelSerialFromDigi(vector< BmnStripDigit >)
TClonesArray * fCscPoints
map< UInt_t, TVector3 > ListOfEventsWithReconstructedVp()
vector< Short_t > fSignal
void DoDecode(Bool_t flag)
void DoLambdaStore(Bool_t flag)
TString AddInfoToRawFile(map< UInt_t, vector< BmnStripDigit > >, map< UInt_t, map< pair< Int_t, Int_t >, Long_t > >, map< UInt_t, vector< BmnStripDigit > >, map< UInt_t, map< vector< Int_t >, Long_t > >, map< UInt_t, vector< BmnStripDigit > >, map< UInt_t, map< pair< Int_t, Int_t >, Long_t > >)
void StartDecodingWithEmbeddedLambdas(TString)
TClonesArray * fCscDigits
vector< BmnStripDigit > GetDigitsFromLambda(TString, Int_t, TString)
void DoEmbeddingMonitor(Bool_t flag)
TClonesArray ** fWrittenStores
void DoRawRootFromBinaryData(TString)
TClonesArray * fSiliconPoints
TClonesArray * fGemPoints
TClonesArray * CreateLambdaStore()
Int_t DefineSiliconStatByZpoint(Double_t)
void DoListOfEventsWithReconstructedVertex(Bool_t flag)
Bool_t doListOfEventsWithReconstructedVertex
Int_t FindReconstructableLambdaFromStore(Int_t, Int_t, BmnParticlePair &)
void DoPrintStoreInfo(Bool_t flag)
void DoEmbedding(Bool_t flag)
TClonesArray * fGemDigits
TClonesArray * fLambdaStore
const BmnLink & GetMatchedLink() const
Definition BmnMatch.h:40
Int_t GetNHitsPart1(TString det="")
void SetTxPair(Double_t val1, Double_t val2)
Int_t GetNHitsPart2(TString det="")
Double_t GetMomPart1()
Double_t GetTxPart1()
Double_t GetTyPart1()
void SetNHitsPair(vector< Int_t > part1, vector< Int_t > part2)
void SetTyPair(Double_t val1, Double_t val2)
void SetMomPair(Double_t val1, Double_t val2)
Double_t GetTxPart2()
Double_t GetMomPart2()
Double_t GetTyPart2()
void SetPeriodId(UInt_t v)
BmnDecoder * GetDecoder() const
void SetRunId(UInt_t v)
Class BmnStripDigit Base class for strip detector digits.
UInt_t GetSerial() const
Long64_t GetTime_sec() const
Long64_t GetTime_ns() const
Long64_t GetEvent() const
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Double_t GetPy() const
Definition CbmMCTrack.h:59
Double_t GetPz() const
Definition CbmMCTrack.h:60
Double_t GetPx() const
Definition CbmMCTrack.h:58
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
Double_t GetP() const
Definition CbmMCTrack.h:68
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
Int_t GetStation() const
Definition CbmStsPoint.h:76
CbmVertex.h.
Definition CbmVertex.h:21
Double_t GetZ() const
Definition CbmVertex.h:60
Double_t GetX() const
Accessors.
Definition CbmVertex.h:58
Double_t GetY() const
Definition CbmVertex.h:59
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
void Delete(Option_t *option="") override
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
virtual Bool_t IsOpen() const
void Close(Option_t *option="") override
const char * GetName() const override
Int_t GetEntriesFast() const
TObject * UncheckedAt(Int_t i) const
friend friend class TClonesArray
const char * Data() const
Bool_t IsNull() const
static TString Format(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
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)
Double_t Y() const
Double_t X() const
Double_t Z() const
Double_t Phi() const
Double_t Y() const
Double_t X() const
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TString GetBeamParticle()
get beam particle of the current run
Definition UniRun.h:109
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:121
Double_t Log(Double_t x)
Double_t Sqrt(Double_t x)
Double_t Abs(Double_t d)
constexpr Double_t RadToDeg()