2#include "CbmStsPoint.h"
6#define GCC_DIAGNOSTIC_AWARE 1
7#if GCC_DIAGNOSTIC_AWARE
8# pragma GCC diagnostic ignored "-Wunknown-pragmas"
24 fSiliconPoints(nullptr),
25 fSiliconDigits(nullptr),
26 fSiliconMatch(nullptr),
30 fLambdaStore(nullptr),
51 fSiliconPoints(nullptr),
52 fSiliconDigits(nullptr),
53 fSiliconMatch(nullptr),
57 fLambdaStore(nullptr),
58 fWrittenStores(nullptr),
62 fPdgDecParticle(3122),
68 fStorePath =
"outputDataStore";
71 doLambdaStore = kTRUE;
72 doListOfEventsWithReconstructedVertex = kTRUE;
73 doSimulateLambdaThroughSetup = kTRUE;
74 doRawRootConvertion = kTRUE;
77 doPrintStoreInfo = kFALSE;
78 doEmbeddingMonitor = kTRUE;
80 isGemEmbedded = kTRUE;
81 isSilEmbedded = kTRUE;
82 isCscEmbedded = kFALSE;
87 fSim =
new TChain(
"bmndata");
88 fSim->Add(sim.Data());
89 fSim->SetBranchAddress(
"MCTrack", &fMCTracks);
92 fReco =
new TChain(
"bmndata");
93 fReco->Add(reco.Data());
94 fReco->SetBranchAddress(
"BmnVertex", &fVertices);
95 fReco->SetBranchAddress(
"DstEventHeader.", &fHeader);
101 fNeventsToBeSimulated = 50;
102 fStoreToProcess = -1;
104 if (!lambdaStore.IsNull()) {
105 fWrittenStores =
new TClonesArray*[fNstores];
106 for (Int_t iStore = 0; iStore < fNstores; iStore++)
107 fWrittenStores[iStore] =
nullptr;
109 for (Int_t iStore = 0; iStore < fNstores; iStore++)
110 fWrittenStores[iStore] =
new TClonesArray(
"BmnParticleStore");
112 TChain* ch =
new TChain(
"bmndata");
113 ch->Add(lambdaStore.Data());
115 TClonesArray* tmp =
nullptr;
116 ch->SetBranchAddress(
"BmnParticleStore", &tmp);
118 for (Int_t iStore = 0; iStore < fNstores; iStore++) {
119 ch->GetEntry(iStore);
121 fWrittenStores[iStore] = (TClonesArray*) (tmp->UncheckedAt(0))->Clone();
126 fLambdaStore =
new TClonesArray(
"BmnParticleStore");
141 isUseRealSignal = kTRUE;
143 fSignal.push_back(1000);
144 fSignal.push_back(1500);
145 fSignal.push_back(1000);
149 if ((!out.Contains(
"digi") && !out.IsNull()) && raw.IsNull() && !sim.IsNull() && reco.IsNull() && lambdaStore.IsNull()) {
150 cout <<
"Recognized scenario 1" << endl;
161 else if (raw.IsNull() && sim.IsNull() && !reco.IsNull() && out.IsNull() && !lambdaStore.IsNull()) {
162 cout <<
"Recognized scenario 2 (or 3)" << endl;
173 else if (!raw.IsNull() && (out.Contains(
"digi") && !out.IsNull()) && sim.IsNull() && !reco.IsNull() && lambdaStore.IsNull()) {
174 cout <<
"Recognized scenario 4" << endl;
187 fFileNamePart = (fPdgDecParticle == 3122) ?
"lambda" : (fPdgDecParticle == 310) ?
"kaon" :
"unknown";
190 if (isUseRealSignal) {
191 TString digiFile =
"";
193 TString eos_host =
"root://ncm.jinr.ru/";
194 TString digiDir =
"/eos/nica/bmn/exp/digi/";
195 TString
run =
"run7";
196 TString release =
"20.02.0";
197 TString dirList[2] = {
"4720-5186_BMN_Krypton",
"3590-4707_BMN_Argon"};
204 TString command = TString::Format(
"xrdcp %s/%s/%s/%s/%s/bmn_run%d_digi.root %s",
205 eos_host.Data(), digiDir.Data(),
run.Data(), release.Data(), dirList[idx].Data(), fHeader->GetRunId(), gSystem->GetFromPipe(
"pwd").Data());
207 gSystem->Exec(command.Data());
209 TFile* file =
new TFile(Form(
"bmn_run%d_digi.root", fHeader->GetRunId()));
212 digiFile = file->GetName();
216 if (!digiFile.IsNull())
222 if (!fDigiFileName.Contains(
"digi") && !fDigiFileName.IsNull()) {
225 TFile*
f =
new TFile(fDigiFileName.Data(),
"recreate");
226 TTree* tree =
new TTree(
"bmndata",
"bmndata");
228 TClonesArray* tmp =
new TClonesArray(
"BmnParticleStore");
229 tree->Branch(
"BmnParticleStore", &tmp);
231 for (Int_t iEntry = 0; iEntry < store->GetEntriesFast(); iEntry++) {
233 TClonesArray* arr = (TClonesArray*) store->UncheckedAt(iEntry);
249 if (doPrintStoreInfo)
253 map <UInt_t, TVector3> EventIdsVpMap;
254 if (doListOfEventsWithReconstructedVertex)
255 EventIdsVpMap = ListOfEventsWithReconstructedVp();
258 if (doSimulateLambdaThroughSetup) {
260 Double_t map_current = 55.87;
271 omp_set_num_threads(nThreads);
274 if (doSimulateLambdaThroughSetup) {
275 Int_t low = (fStoreToProcess != -1) ? fStoreToProcess : 0;
276 Int_t up = (fStoreToProcess != -1) ? (fStoreToProcess + 1) : fNstores;
278#pragma omp parallel for
279 for (Int_t iLambda = low; iLambda < up; iLambda++) {
281 Double_t eta = lambda->
GetEta();
282 Double_t phi = lambda->
GetPhi();
283 Double_t p = lambda->
GetP();
284 Double_t pdg = lambda->
GetPdg();
288 for (
auto it : EventIdsVpMap) {
290 TVector3 Vp = it.second;
292 SimulateLambdaPassing(pdg, p, TVector2(eta, phi), Vp, iLambda, iVertex);
300 map <UInt_t, pair <TVector3, TVector3>> GoodLambdaForEachVertex;
302 map <UInt_t, BmnParticlePair> embMonitorMap;
305 for (
auto it : EventIdsVpMap) {
306 UInt_t
id = it.first;
307 TVector3 lambda(-1, -1, -1);
308 TVector3 Vp = it.second;
310 GoodLambdaForEachVertex[id] = make_pair(lambda, Vp);
313 embMonitorMap[id] = aPairToBeWritten;
315 for (Int_t iLambda = 0; iLambda < fNstores; iLambda++) {
318 Int_t eve = FindReconstructableLambdaFromStore(iLambda, iVertex, currentPair);
321 auto itEmbInfoMap = embMonitorMap.find(
id);
322 if (itEmbInfoMap != embMonitorMap.end())
323 (*itEmbInfoMap).second = currentPair;
326 TVector3 tmp = TVector3(iLambda, iVertex, eve);
329 auto itr = GoodLambdaForEachVertex.find(
id);
330 if (itr != GoodLambdaForEachVertex.end())
331 (*itr).second.first = tmp;
340 if (doEmbeddingMonitor) {
342 TFile* file =
new TFile(Form(
"embedding_%d.root", fRunId),
"recreate");
343 TTree* tree =
new TTree(
"bmndata",
"bmndata");
345 tree->Branch(
"EmbeddingMonitor.", &fMon);
346 for (
auto it : GoodLambdaForEachVertex) {
347 UInt_t
id = it.first;
349 TVector3 par = it.second.first;
354 auto itEmbInfoMap = embMonitorMap.find(
id);
371 if ((Int_t) par[0] != -1 && (Int_t) par[1] != -1 && (Int_t) par[2] != -1)
385 map <UInt_t, vector < BmnStripDigit>> digsFromLambdasGem;
386 map <UInt_t, vector < BmnStripDigit>> digsFromLambdasSilicon;
387 map <UInt_t, vector < BmnStripDigit>> digsFromLambdasCsc;
390 for (
auto it : GoodLambdaForEachVertex) {
391 TVector3 par = it.second.first;
392 Int_t lambda = par[0];
393 Int_t vertex = par[1];
394 Int_t
event = par[2];
396 if (lambda == -1 || vertex == -1 || event == -1)
400 digsFromLambdasGem[it.first] = GetDigitsFromLambda(TString::Format(
"%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), lambda, vertex), event,
"GEM");
402 digsFromLambdasSilicon[it.first] = GetDigitsFromLambda(TString::Format(
"%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), lambda, vertex), event,
"SILICON");
404 digsFromLambdasCsc[it.first] = GetDigitsFromLambda(TString::Format(
"%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), lambda, vertex), event,
"CSC");
407 cout <<
"GEM# " << digsFromLambdasGem.size() <<
" SILICON# " << digsFromLambdasSilicon.size() <<
" CSC# " << digsFromLambdasCsc.size() << endl;
410 if (isUseRealSignal) {
411 TTree* tree =
new TTree(
"bmndata",
"bmndata");
413 TClonesArray* digitsGem =
new TClonesArray(
"BmnGemStripDigit");
414 tree->Branch(
"BmnGemStripDigit", &digitsGem);
416 TClonesArray* digitsSil =
new TClonesArray(
"BmnSiliconDigit");
417 tree->Branch(
"BmnSiliconDigit", &digitsSil);
419 for (
auto digs : digsFromLambdasGem) {
422 vector <BmnStripDigit> digitsInEvent = digs.second;
427 new ((*digitsGem) [digitsGem->GetEntriesFast()])
BmnStripDigit(dig);
432 for (
auto digs : digsFromLambdasSilicon) {
435 vector <BmnStripDigit> digitsInEvent = digs.second;
440 new ((*digitsSil) [digitsSil->GetEntriesFast()])
BmnStripDigit(dig);
454 if (!scaleFuncGem || !scaleFuncSil) {
455 cout <<
"Something is wrong, exiting ..." << endl;
459 for (
auto& digs : digsFromLambdasGem) {
460 vector <BmnStripDigit> &digitsInEvent = digs.second;
463 digit.SetStripSignal(scaleFuncGem->Eval(digit.GetStripSignal()));
466 for (
auto& digs : digsFromLambdasSilicon) {
467 vector <BmnStripDigit> &digitsInEvent = digs.second;
470 digit.SetStripSignal(scaleFuncSil->Eval(digit.GetStripSignal()));
475 map <UInt_t, map < pair <Int_t, Int_t>, Long_t>> evIdGemChannelSerial;
476 map <UInt_t, map < pair <Int_t, Int_t>, Long_t>> evIdCscChannelSerial;
477 map <UInt_t, map < vector <Int_t>, Long_t>> evIdSiliconChannelSerial;
482 for (
auto it : digsFromLambdasGem) {
483 vector <BmnStripDigit> digits = it.second;
484 map <pair <Int_t, Int_t>, Long_t> tmpMap = GetGemChannelSerialFromDigi(digits);
485 evIdGemChannelSerial[it.first] = tmpMap;
490 for (
auto it : digsFromLambdasSilicon) {
491 vector <BmnStripDigit> digits = it.second;
492 map <vector <Int_t>, Long_t> tmpMap = GetSiliconChannelSerialFromDigi(digits);
493 evIdSiliconChannelSerial[it.first] = tmpMap;
498 for (
auto it : digsFromLambdasCsc) {
499 vector <BmnStripDigit> digits = it.second;
500 map <pair <Int_t, Int_t>, Long_t> tmpMap = GetCscChannelSerialFromDigi(digits);
501 evIdCscChannelSerial[it.first] = tmpMap;
506 DoRawRootFromBinaryData(fDataFileName);
509 TString rawRoot =
"";
511 rawRoot = AddInfoToRawFile(digsFromLambdasGem, evIdGemChannelSerial,
512 digsFromLambdasSilicon, evIdSiliconChannelSerial,
513 digsFromLambdasCsc, evIdCscChannelSerial);
516 if (!rawRoot.IsNull() && doDecode)
517 StartDecodingWithEmbeddedLambdas(rawRoot);
520Int_t BmnLambdaEmbedding::FindReconstructableLambdaFromStore(Int_t iLambda, Int_t iVertex,
BmnParticlePair& pairFromLambda) {
521 TString fileName = TString::Format(
"%s/%s%d_vertex%d.root", fStorePath.Data(), fFileNamePart.Data(), iLambda, iVertex);
522 TChain ch(
"bmndata");
523 if (ch.Add(fileName.Data()) == 0)
527 TClonesArray* tracks =
nullptr;
528 TClonesArray* gemPoints =
nullptr;
529 TClonesArray* siliconPoints =
nullptr;
530 TClonesArray* cscPoints =
nullptr;
532 ch.SetBranchAddress(
"MCTrack", &tracks);
533 ch.SetBranchAddress(
"StsPoint", &gemPoints);
534 ch.SetBranchAddress(
"SiliconPoint", &siliconPoints);
535 ch.SetBranchAddress(
"CSCPoint", &cscPoints);
537 for (Int_t iEv = 0; iEv < ch.GetEntries(); iEv++) {
542 Int_t nHitsPerProton = 0;
543 Double_t Pprot = 0., TxProt = -1., TyProt = -1.;
545 for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++) {
559 if (((
CbmMCTrack*) tracks->UncheckedAt(
id))->GetPdgCode() != fPdgDecParticle)
562 if (track->
GetP() < 0.5)
565 const Int_t nStats = 10;
566 Int_t pointsOnGemsSiliconsAndCsc[nStats];
567 for (Int_t iStat = 0; iStat < nStats; iStat++)
568 pointsOnGemsSiliconsAndCsc[iStat] = 0;
572 for (Int_t iGem = 0; iGem < gemPoints->GetEntriesFast(); iGem++) {
574 if (point->GetTrackID() != iTrack)
576 pointsOnGemsSiliconsAndCsc[point->
GetStation()]++;
581 for (Int_t iSilicon = 0; iSilicon < siliconPoints->GetEntriesFast(); iSilicon++) {
582 FairMCPoint* point = (FairMCPoint*) siliconPoints->UncheckedAt(iSilicon);
583 if (point->GetTrackID() != iTrack)
585 pointsOnGemsSiliconsAndCsc[DefineSiliconStatByZpoint(point->GetZ())]++;
590 for (Int_t iCsc = 0; iCsc < cscPoints->GetEntriesFast(); iCsc++) {
592 if (point->GetTrackID() != iTrack)
594 pointsOnGemsSiliconsAndCsc[9]++;
598 Bool_t isPrelimAccepted[3] = {kTRUE, kTRUE, kTRUE};
604 for (Int_t iStat = 0; iStat < 6; iStat++) {
605 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
608 if (pointCounter == 0)
609 isPrelimAccepted[0] = kFALSE;
615 for (Int_t iStat = 6; iStat < 9; iStat++) {
616 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
619 if (pointCounter == 0)
620 isPrelimAccepted[1] = kFALSE;
626 for (Int_t iStat = 9; iStat < nStats; iStat++) {
627 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
630 if (pointCounter == 0)
631 isPrelimAccepted[2] = kFALSE;
634 Bool_t doWeAcceptEvent = (isPrelimAccepted[0] && isPrelimAccepted[1] && isPrelimAccepted[2]) ? kTRUE : kFALSE;
636 if (!doWeAcceptEvent)
640 Bool_t isMultiplePointsOnZ = kFALSE;
641 for (Int_t iStat = 0; iStat < nStats; iStat++) {
642 if (pointsOnGemsSiliconsAndCsc[iStat] == 2) {
643 isMultiplePointsOnZ = kTRUE;
646 nHitsPerProton += pointsOnGemsSiliconsAndCsc[iStat];
648 if (isMultiplePointsOnZ || nHitsPerProton < 4 || nHitsPerProton > nStats)
651 Pprot = track->
GetP();
657 if (nHitsPerProton < fNHitsProton || Abs(Pprot) < FLT_EPSILON)
661 Int_t nHitsPerPion = 0;
662 Double_t Ppion = 0., TxPion = -1., TyPion = -1.;
664 for (Int_t jTrack = 0; jTrack < tracks->GetEntriesFast(); jTrack++) {
678 if (((
CbmMCTrack*) tracks->UncheckedAt(
id))->GetPdgCode() != fPdgDecParticle)
681 if (track->
GetP() < 0.5)
684 const Int_t nStats = 9;
685 Int_t pointsOnGemsAndSilicon[nStats];
686 for (Int_t iStat = 0; iStat < nStats; iStat++)
687 pointsOnGemsAndSilicon[iStat] = 0;
691 for (Int_t iGem = 0; iGem < gemPoints->GetEntriesFast(); iGem++) {
693 if (point->GetTrackID() != jTrack)
695 pointsOnGemsAndSilicon[point->
GetStation()]++;
700 for (Int_t iSilicon = 0; iSilicon < siliconPoints->GetEntriesFast(); iSilicon++) {
701 FairMCPoint* point = (FairMCPoint*) siliconPoints->UncheckedAt(iSilicon);
702 if (point->GetTrackID() != jTrack)
704 pointsOnGemsAndSilicon[DefineSiliconStatByZpoint(point->GetZ())]++;
708 Bool_t isPrelimAccepted[2] = {kTRUE, kTRUE};
714 for (Int_t iStat = 0; iStat < 6; iStat++) {
715 if (pointsOnGemsAndSilicon[iStat] != 0)
718 if (pointCounter == 0)
719 isPrelimAccepted[0] = kFALSE;
725 for (Int_t iStat = 6; iStat < nStats; iStat++) {
726 if (pointsOnGemsAndSilicon[iStat] != 0)
729 if (pointCounter == 0)
730 isPrelimAccepted[1] = kFALSE;
733 Bool_t doWeAcceptEvent = (isPrelimAccepted[0] && isPrelimAccepted[1]) ? kTRUE : kFALSE;
735 if (!doWeAcceptEvent)
739 Bool_t isMultiplePointsOnZ = kFALSE;
740 for (Int_t iStat = 0; iStat < nStats; iStat++) {
741 if (pointsOnGemsAndSilicon[iStat] == 2) {
742 isMultiplePointsOnZ = kTRUE;
745 nHitsPerPion += pointsOnGemsAndSilicon[iStat];
747 if (isMultiplePointsOnZ || nHitsPerPion < 4 || nHitsPerPion > nStats)
750 Ppion = track->
GetP();
755 if (nHitsPerPion < fNHitsPion || Abs(Ppion) < FLT_EPSILON)
759 pairFromLambda.
SetTxPair(TxProt, TxPion);
760 pairFromLambda.
SetTyPair(TyProt, TyPion);
761 pairFromLambda.
SetNHitsPair(nHitsPerProton, nHitsPerPion);
768void BmnLambdaEmbedding::DoRawRootFromBinaryData(TString raw) {
773 if (doRawRootConvertion)
780void BmnLambdaEmbedding::StartDecodingWithEmbeddedLambdas(TString raw) {
789 std::map<DetectorId, bool>
setup;
790 setup.insert(std::make_pair(
kBC, 0));
808map <UInt_t, TVector3> BmnLambdaEmbedding::ListOfEventsWithReconstructedVp() {
809 map <UInt_t, TVector3> EventIdsVpMap;
810 for (Int_t iEntry = 0; iEntry < fEvents; iEntry++) {
811 fReco->GetEntry(iEntry);
814 fRunId = fHeader->GetRunId();
819 if (vertex->
GetZ() < fZmin || vertex->
GetZ() > fZmax)
824 return EventIdsVpMap;
827vector <BmnStripDigit> BmnLambdaEmbedding::GetDigitsFromLambda(TString lambdaEve, Int_t evNum, TString det) {
828 Bool_t isSilicon = (det.Contains(
"SILICON")) ? kTRUE : kFALSE;
829 Bool_t isGem = (det.Contains(
"GEM")) ? kTRUE : kFALSE;
830 Bool_t isCsc = (det.Contains(
"CSC")) ? kTRUE : kFALSE;
832 vector <BmnStripDigit> digits;
835 fLambdaSim =
new TChain(
"bmndata");
836 fLambdaSim->Add(lambdaEve.Data());
837 fLambdaSim->SetBranchAddress(
"MCTrack", &fMCTracks);
839 fLambdaSim->SetBranchAddress(
"SiliconPoint", &fSiliconPoints);
840 fLambdaSim->SetBranchAddress(
"BmnSiliconDigit", &fSiliconDigits);
841 fLambdaSim->SetBranchAddress(
"BmnSiliconDigitMatch", &fSiliconMatch);
843 fLambdaSim->SetBranchAddress(
"StsPoint", &fGemPoints);
844 fLambdaSim->SetBranchAddress(
"BmnGemStripDigit", &fGemDigits);
845 fLambdaSim->SetBranchAddress(
"BmnGemStripDigitMatch", &fGemMatch);
847 fLambdaSim->SetBranchAddress(
"CSCPoint", &fCscPoints);
848 fLambdaSim->SetBranchAddress(
"BmnCSCDigit", &fCscDigits);
849 fLambdaSim->SetBranchAddress(
"BmnCSCDigitMatch", &fCscMatch);
851 fLambdaSim->GetEntry(evNum);
853 Int_t idxPi = -1, idxProt = -1;
856 for (Int_t iTrack = 0; iTrack < fMCTracks->GetEntriesFast(); iTrack++) {
871 if (((
CbmMCTrack*) fMCTracks->UncheckedAt(
id))->GetPdgCode() != fPdgDecParticle)
882 for (Int_t iDig = 0; iDig < fGemDigits->GetEntriesFast(); iDig++) {
886 FairMCPoint* point = (FairMCPoint*) fGemPoints->UncheckedAt(idxPoint);
887 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
892 digits.push_back(*digi);
897 for (Int_t iDig = 0; iDig < fCscDigits->GetEntriesFast(); iDig++) {
901 FairMCPoint* point = (FairMCPoint*) fCscPoints->UncheckedAt(idxPoint);
902 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
906 digits.push_back(*digi);
911 for (Int_t iDig = 0; iDig < fSiliconDigits->GetEntriesFast(); iDig++) {
915 FairMCPoint* point = (FairMCPoint*) fSiliconPoints->UncheckedAt(idxPoint);
916 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
920 digits.push_back(*digi);
928map <pair <Int_t, Int_t>, Long_t> BmnLambdaEmbedding::GetGemChannelSerialFromDigi(vector <BmnStripDigit> digits) {
929 map <Int_t, Int_t> digiToChannel;
930 map <pair <Int_t, Int_t>, Long_t> digiChannelToSerial;
932 const Int_t nDigs = digits.size();
935 Long_t serial[nDigs];
937 for (Int_t iDigi = 0; iDigi < nDigs; iDigi++) {
944 for (
auto it : digiToChannel) {
950 Long_t value = (serial[it.first] == 0) ? fInfo->
GemDigiChannelToSerial(make_pair(digits[it.first], it.second)) : serial[it.first];
951 digiChannelToSerial[make_pair(it.first, it.second)] = value;
954 return digiChannelToSerial;
957map <pair <Int_t, Int_t>, Long_t> BmnLambdaEmbedding::GetCscChannelSerialFromDigi(vector <BmnStripDigit> digits) {
958 map <pair <Int_t, Int_t>, Long_t> digiChannelToSerial;
960 for (
size_t iDigi = 0; iDigi < digits.size(); iDigi++) {
965 digiChannelToSerial[make_pair(iDigi, fInfo->
CscDigiToChannel(dig, serial))] = serial;
968 return digiChannelToSerial;
971map <vector <Int_t>, Long_t> BmnLambdaEmbedding::GetSiliconChannelSerialFromDigi(vector <BmnStripDigit> digits) {
972 map <vector <Int_t>, Long_t> digiChannelToSerial;
974 for (
size_t iDigi = 0; iDigi < digits.size(); iDigi++) {
977 Int_t chan = -1, sample = -1;
982 vector <Int_t> tmp{(
int)iDigi, chan, sample};
984 digiChannelToSerial[tmp] = serial;
987 return digiChannelToSerial;
990TString BmnLambdaEmbedding::AddInfoToRawFile(map <UInt_t, vector <BmnStripDigit>> digsGem, map <UInt_t, map <pair <Int_t, Int_t>, Long_t>> evIdChannelSerialGem,
991 map <UInt_t, vector < BmnStripDigit>> digsSilicon, map <UInt_t, map < vector <Int_t>, Long_t>> evIdChannelSerialSilicon,
992 map <UInt_t, vector <BmnStripDigit>> digsCsc, map <UInt_t, map <pair <Int_t, Int_t>, Long_t>> evIdChannelSerialCsc) {
995 TString tmp = fRawRootFileName;
996 tmp = tmp.ReplaceAll(
".root",
"");
997 tmp +=
"_withLambdaEmbedded.root";
999 TFile*
f =
new TFile(tmp.Data(),
"recreate");
1000 TTree* t =
new TTree(
"BMN_RAW",
"BMN_RAW");
1002 TClonesArray* gemOrCsc =
new TClonesArray(
"BmnADCDigit");
1003 TClonesArray* silicon =
new TClonesArray(
"BmnADCDigit");
1004 TClonesArray* sync =
new TClonesArray(
"BmnSyncDigit");
1008 t->Branch(
"BmnEventHeader.", &header);
1009 t->Branch(
"SYNC", &sync);
1010 t->Branch(
"ADC32", &gemOrCsc);
1011 t->Branch(
"ADC128", &silicon);
1013 TChain* ch =
new TChain(
"BMN_RAW");
1014 ch->Add(fRawRootFileName.Data());
1018 ch->SetBranchAddress(
"ADC32", &fADC32);
1019 ch->SetBranchAddress(
"ADC128", &fADC128);
1020 ch->SetBranchAddress(
"SYNC", &fSync);
1021 ch->SetBranchAddress(
"BmnEventHeader.", &fEventHeader);
1024 for (Int_t iEntry = 0; iEntry < fEvents; iEntry++) {
1025 if (iEntry % 1000 == 0)
1026 cout <<
"Embedding, event# " << iEntry << endl;
1032 ch->GetEntry(iEntry);
1036 header->SetRunId(fEventHeader->GetRunId());
1037 header->SetEventId(eventId);
1041 for (Int_t iSync = 0; iSync < fSync->GetEntriesFast(); iSync++) {
1049 Bool_t isEventIdFoundInTheMap = kTRUE;
1051 auto itDigGem = digsGem.find(eventId);
1052 auto itDigSilicon = digsSilicon.find(eventId);
1053 auto itDigCsc = digsCsc.find(eventId);
1055 if (itDigGem == digsGem.end())
1056 isEventIdFoundInTheMap = kFALSE;
1060 vector <BmnStripDigit> digitsGem;
1061 map <pair <Int_t, Int_t>, Long_t> idxChanSerGem;
1064 vector <BmnStripDigit> digitsSilicon;
1065 map <vector <Int_t>, Long_t> idxChanSampleSerSilicon;
1068 vector <BmnStripDigit> digitsCsc;
1069 map <pair <Int_t, Int_t>, Long_t> idxChanSerCsc;
1071 if (isEventIdFoundInTheMap) {
1073 if (isGemEmbedded) {
1074 digitsGem = itDigGem->second;
1075 idxChanSerGem = evIdChannelSerialGem.find(eventId)->second;
1079 if (isSilEmbedded) {
1080 digitsSilicon = itDigSilicon->second;
1081 idxChanSampleSerSilicon = evIdChannelSerialSilicon.find(eventId)->second;
1085 if (isCscEmbedded) {
1086 digitsCsc = itDigCsc->second;
1087 idxChanSerCsc = evIdChannelSerialCsc.find(eventId)->second;
1092 if (isGemEmbedded || isCscEmbedded)
1093 for (Int_t iAdc32 = 0; iAdc32 < fADC32->GetEntriesFast(); iAdc32++) {
1102 for (
auto itCorr : idxChanSerGem) {
1103 Int_t channelTmp = itCorr.first.second;
1105 Int_t channelBuff = Int_t(channelTmp / 32);
1106 Long_t serialBuff = itCorr.second;
1108 if ((Int_t)channel != channelBuff || serial != serialBuff)
1111 Int_t sample = Int_t(channelTmp % 32);
1112 Int_t signal = Int_t(digitsGem[itCorr.first.first].GetStripSignal());
1114 if (isUseRealSignal)
1125 for (
auto itCorr : idxChanSerCsc) {
1126 Int_t channelTmp = itCorr.first.second;
1128 Int_t channelBuff = Int_t(channelTmp / 32);
1129 Long_t serialBuff = itCorr.second;
1131 if ((Int_t)channel != channelBuff || serial != serialBuff)
1134 Int_t sample = Int_t(channelTmp % 32);
1135 Int_t signal = Int_t(digitsCsc[itCorr.first.first].GetStripSignal() * 16.);
1137 if (isUseRealSignal)
1151 for (Int_t iAdc128 = 0; iAdc128 < fADC128->GetEntriesFast(); iAdc128++) {
1158 for (
auto itCorr : idxChanSampleSerSilicon) {
1159 Int_t chan = itCorr.first[1];
1160 Long_t ser = itCorr.second;
1162 if ((Int_t)channel != chan || serial != ser)
1165 Int_t idx = itCorr.first[0];
1166 Int_t signal = Int_t(digitsSilicon[idx].GetStripSignal() * 16.);
1168 Int_t sample = itCorr.first[2];
1171 Int_t sign = (digitsSilicon[idx].GetStripLayer() == 0) ? +1 : -1;
1172 if (isUseRealSignal)
1198 cout << fNstores << endl;
1199 for (Int_t iEntry = 0; iEntry < fSim->GetEntries(); iEntry++) {
1200 fSim->GetEntry(iEntry);
1201 if (iEntry % 1000 == 0) {
1202 cout <<
"Event# " << iEntry <<
" processed" << endl;
1203 cout <<
"Size of store# " << fLambdaStore->GetEntriesFast() << endl;
1206 if (fLambdaStore->GetEntriesFast() == fNstores)
1209 for (Int_t iTrack = 0; iTrack < fMCTracks->GetEntriesFast(); iTrack++) {
1217 if (track->
GetPz() < 0.)
1220 Double_t p = track->
GetP();
1221 Double_t Tx = track->
GetPx() / track->
GetPz();
1222 Double_t Ty = track->
GetPy() / track->
GetPz();
1224 Double_t Pz = p / TMath::Sqrt(1 + Tx * Tx + Ty * Ty);
1225 Double_t eta = 0.5 * TMath::Log((p + Pz) / (p - Pz));
1227 TVector3 tmp(Tx * Pz, Ty * Pz, Pz);
1228 Double_t phi = tmp.Phi() * TMath::RadToDeg() + 180.;
1230 if (eta < fEtaMin || eta > fEtaMax || p < fMomMin || phi < fPhiMin || phi > fPhiMax)
1233 new ((*fLambdaStore)[fLambdaStore->GetEntriesFast()])
BmnParticleStore(fPdgDecParticle, p, Tx, Ty);
1236 return fLambdaStore;
1239void BmnLambdaEmbedding::PrintStoreInfo() {
1240 cout <<
"N_particles_store# " << fLambdaStore->GetEntriesFast() << endl;
1242 for (Int_t iLambda = 0; iLambda < fLambdaStore->GetEntriesFast(); iLambda++) {
1244 cout <<
"P = " << lambda->
GetP() <<
" Eta = " << lambda->
GetEta() <<
" Phi = " << lambda->
GetPhi() << endl;
1261void BmnLambdaEmbedding::SimulateLambdaPassing(Int_t pdg, Double_t P, TVector2 pos, TVector3 Vp, Int_t iLambda, Int_t iVertex) {
1264 TString namePart = (pdg == 3122) ?
"lambda" : (pdg == 310) ?
"kaon" :
"unknown";
1265 TString outFile = TString::Format(
"%s/%s%d_vertex%d.root", fStorePath.Data(), namePart.Data(), iLambda, iVertex);
1267 TString macroName =
"SimulateLambdaPassing.C";
1269 TString gPathConfig = gSystem->Getenv(
"VMCWORKDIR");
1270 TString gPathFull = gPathConfig +
"/macro/embedding/" + macroName;
1272 TString argList = TString::Format(
"(%d, %d, %G, %G, %G, %G, %G, %G, %G, \"%s\")", pdg, fNeventsToBeSimulated, fFieldScale, P, pos.X(), pos.Y(), Vp.X(), Vp.Y(), Vp.Z(), outFile.Data());
1273 TString exeCommand = TString::Format(
"root -b -q '%s%s'", gPathFull.Data(), argList.Data());
1275 gSystem->Exec(exeCommand.Data());
1278Int_t BmnLambdaEmbedding::DefineSiliconStatByZpoint(Double_t z) {
1280 const Double_t z1 = 14.;
1281 const Double_t z2 = 20.;
1288 else if (z > z1 && z < z2)
UInt_t GetNSamples() const
UShort_t GetChannel() const
void SetAsEmbedded(Bool_t flag)
Short_t * GetShortValue() const
void SetBmnSetup(BmnSetup v)
void SetRawRootFile(TString filename)
void SetDetectorSetup(std::map< DetectorId, bool > setup)
void SetDigiRootFile(TString filename)
void SetMSCMapping(TString map)
void SetPeriodId(UInt_t v)
void SetTrigPlaceMapping(TString map)
void SetGemMapping(TString map)
BmnStatus DecodeDataToDigi()
void SetTrigChannelMapping(TString file)
void SetCSCMapping(TString map)
void SetSiliconMapping(TString map)
void SetNHitsProton(Int_t nhits)
void IsEmbedded(Bool_t flag)
void SetTyPion(Double_t val)
void SetStoreVertexEvent(TVector3 info)
void SetProtonP(Double_t val)
void SetTxPion(Double_t val)
void SetNHitsPion(Int_t nhits)
void SetTxProton(Double_t val)
void SetTyProton(Double_t val)
void SetPionP(Double_t val)
void SetUseRealSignals(Bool_t flag)
virtual ~BmnLambdaEmbedding()
void DoRawRootConvertion(Bool_t flag)
void DoSimulateLambdaThroughSetup(Bool_t flag)
void DoDecode(Bool_t flag)
void DoLambdaStore(Bool_t flag)
void DoEmbeddingMonitor(Bool_t flag)
TClonesArray * CreateLambdaStore()
void DoListOfEventsWithReconstructedVertex(Bool_t flag)
void DoPrintStoreInfo(Bool_t flag)
void DoEmbedding(Bool_t flag)
Int_t GemDigiToChannel(BmnStripDigit *, Long_t &)
void SiliconDigiToChannelSampleSerial(BmnStripDigit *, Int_t &, Int_t &, Long_t &)
Int_t CscDigiToChannel(BmnStripDigit *, Long_t &)
Long_t GemDigiChannelToSerial(pair< BmnStripDigit, Int_t >)
const BmnLink & GetMatchedLink() const
Int_t GetNHitsPart1(TString det="")
void SetTxPair(Double_t val1, Double_t val2)
Int_t GetNHitsPart2(TString det="")
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)
TString GetRootFileName()
void SetPeriodId(UInt_t v)
BmnDecoder * GetDecoder() const
BmnStatus ConvertRawToRoot()
Long64_t GetTime_sec() const
Long64_t GetTime_ns() const
Long64_t GetEvent() const
Int_t GetMotherId() const
void SetMcDataSet(TChain *chainMC)
TF1 * GetRescaleFunction(TString det)
static UniRun * GetRun(int period_number, int run_number)
get run from the database
TString GetBeamParticle()
get beam particle of the current run
double * GetFieldVoltage()
get field voltage of the current run