3#include "CbmStsPoint.h"
7#define GCC_DIAGNOSTIC_AWARE 1
8#if GCC_DIAGNOSTIC_AWARE
9#pragma GCC diagnostic ignored "-Wunknown-pragmas"
99 fReco->Add(reco.Data());
110 if (!lambdaStore.
IsNull()) {
158 cout <<
"Recognized scenario 1" << endl;
171 cout <<
"Recognized scenario 2 (or 3)" << endl;
185 cout <<
"Recognized scenario 4" << endl;
205 TString eos_host =
"root://ncm.jinr.ru/";
206 TString digiDir =
"/eos/nica/bmn/exp/digi/";
209 TString dirList[2] = {
"4720-5186_BMN_Krypton",
"3590-4707_BMN_Argon"};
240 TTree* tree =
new TTree(
"bmndata",
"bmndata");
243 tree->
Branch(
"BmnParticleStore", &tmp);
245 for (
Int_t iEntry = 0; iEntry < store->GetEntriesFast(); iEntry++) {
267 map<UInt_t, TVector3> EventIdsVpMap;
285 omp_set_num_threads(nThreads);
292#pragma omp parallel for
293 for (
Int_t iLambda = low; iLambda < up; iLambda++) {
302 for (
auto it : EventIdsVpMap) {
314 map<UInt_t, pair<TVector3, TVector3>> GoodLambdaForEachVertex;
316 map<UInt_t, BmnParticlePair>
320 for (
auto it : EventIdsVpMap) {
321 UInt_t
id = it.first;
326 GoodLambdaForEachVertex[id] = make_pair(lambda, Vp);
329 embMonitorMap[id] = aPairToBeWritten;
337 auto itEmbInfoMap = embMonitorMap.find(
id);
338 if (itEmbInfoMap != embMonitorMap.end())
339 (*itEmbInfoMap).second = currentPair;
345 auto itr = GoodLambdaForEachVertex.find(
id);
346 if (itr != GoodLambdaForEachVertex.end())
347 (*itr).second.first = tmp;
359 TTree* tree =
new TTree(
"bmndata",
"bmndata");
362 for (
auto it : GoodLambdaForEachVertex) {
363 UInt_t
id = it.first;
368 fMon->SetStoreVertexEvent(par);
370 auto itEmbInfoMap = embMonitorMap.find(
id);
401 map<UInt_t, vector<BmnStripDigit>> digsFromLambdasGem;
402 map<UInt_t, vector<BmnStripDigit>> digsFromLambdasSilicon;
403 map<UInt_t, vector<BmnStripDigit>> digsFromLambdasCsc;
406 for (
auto it : GoodLambdaForEachVertex) {
408 Int_t lambda = par[0];
409 Int_t vertex = par[1];
410 Int_t event = par[2];
412 if (lambda == -1 || vertex == -1 || event == -1)
429 cout <<
"GEM# " << digsFromLambdasGem.size() <<
" SILICON# " << digsFromLambdasSilicon.size() <<
" CSC# "
430 << digsFromLambdasCsc.size() << endl;
434 TTree* tree =
new TTree(
"bmndata",
"bmndata");
437 tree->
Branch(
"BmnGemStripDigit", &digitsGem);
440 tree->
Branch(
"BmnSiliconDigit", &digitsSil);
442 for (
auto digs : digsFromLambdasGem) {
445 vector<BmnStripDigit> digitsInEvent = digs.second;
455 for (
auto digs : digsFromLambdasSilicon) {
458 vector<BmnStripDigit> digitsInEvent = digs.second;
474 TF1* scaleFuncGem =
normUtils->GetRescaleFunction(
"GEM");
475 TF1* scaleFuncSil =
normUtils->GetRescaleFunction(
"SILICON");
477 if (!scaleFuncGem || !scaleFuncSil) {
478 cout <<
"Something is wrong, exiting ..." << endl;
482 for (
auto& digs : digsFromLambdasGem) {
483 vector<BmnStripDigit>& digitsInEvent = digs.second;
486 digit.SetStripSignal(scaleFuncGem->
Eval(digit.GetStripSignal()));
489 for (
auto& digs : digsFromLambdasSilicon) {
490 vector<BmnStripDigit>& digitsInEvent = digs.second;
493 digit.SetStripSignal(scaleFuncSil->
Eval(digit.GetStripSignal()));
498 map<UInt_t, map<pair<Int_t, Int_t>,
Long_t>>
499 evIdGemChannelSerial;
500 map<UInt_t, map<pair<Int_t, Int_t>,
Long_t>>
501 evIdCscChannelSerial;
502 map<UInt_t, map<vector<Int_t>,
Long_t>>
503 evIdSiliconChannelSerial;
508 for (
auto it : digsFromLambdasGem) {
509 vector<BmnStripDigit> digits = it.second;
511 evIdGemChannelSerial[it.first] = tmpMap;
516 for (
auto it : digsFromLambdasSilicon) {
517 vector<BmnStripDigit> digits = it.second;
519 evIdSiliconChannelSerial[it.first] = tmpMap;
524 for (
auto it : digsFromLambdasCsc) {
525 vector<BmnStripDigit> digits = it.second;
527 evIdCscChannelSerial[it.first] = tmpMap;
537 rawRoot =
AddInfoToRawFile(digsFromLambdasGem, evIdGemChannelSerial, digsFromLambdasSilicon,
538 evIdSiliconChannelSerial, digsFromLambdasCsc, evIdCscChannelSerial);
552 if (ch.
Add(fileName.
Data()) == 0)
571 Int_t nHitsPerProton = 0;
572 Double_t Pprot = 0., TxProt = -1., TyProt = -1.;
591 if (track->
GetP() < 0.5)
594 const Int_t nStats = 10;
595 Int_t pointsOnGemsSiliconsAndCsc[nStats];
596 for (
Int_t iStat = 0; iStat < nStats; iStat++)
597 pointsOnGemsSiliconsAndCsc[iStat] = 0;
603 if (point->GetTrackID() != iTrack)
605 pointsOnGemsSiliconsAndCsc[point->
GetStation()]++;
612 if (point->GetTrackID() != iTrack)
621 if (point->GetTrackID() != iTrack)
623 pointsOnGemsSiliconsAndCsc[9]++;
634 for (
Int_t iStat = 0; iStat < 6; iStat++) {
635 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
638 if (pointCounter == 0)
639 isPrelimAccepted[0] =
kFALSE;
645 for (
Int_t iStat = 6; iStat < 9; iStat++) {
646 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
649 if (pointCounter == 0)
650 isPrelimAccepted[1] =
kFALSE;
656 for (
Int_t iStat = 9; iStat < nStats; iStat++) {
657 if (pointsOnGemsSiliconsAndCsc[iStat] != 0)
660 if (pointCounter == 0)
661 isPrelimAccepted[2] =
kFALSE;
665 (isPrelimAccepted[0] && isPrelimAccepted[1] && isPrelimAccepted[2]) ?
kTRUE :
kFALSE;
667 if (!doWeAcceptEvent)
672 for (
Int_t iStat = 0; iStat < nStats; iStat++) {
673 if (pointsOnGemsSiliconsAndCsc[iStat] == 2) {
674 isMultiplePointsOnZ =
kTRUE;
677 nHitsPerProton += pointsOnGemsSiliconsAndCsc[iStat];
679 if (isMultiplePointsOnZ || nHitsPerProton < 4 || nHitsPerProton > nStats)
682 Pprot = track->
GetP();
692 Int_t nHitsPerPion = 0;
693 Double_t Ppion = 0., TxPion = -1., TyPion = -1.;
712 if (track->
GetP() < 0.5)
715 const Int_t nStats = 9;
716 Int_t pointsOnGemsAndSilicon[nStats];
717 for (
Int_t iStat = 0; iStat < nStats; iStat++)
718 pointsOnGemsAndSilicon[iStat] = 0;
724 if (point->GetTrackID() != jTrack)
726 pointsOnGemsAndSilicon[point->
GetStation()]++;
733 if (point->GetTrackID() != jTrack)
746 for (
Int_t iStat = 0; iStat < 6; iStat++) {
747 if (pointsOnGemsAndSilicon[iStat] != 0)
750 if (pointCounter == 0)
751 isPrelimAccepted[0] =
kFALSE;
757 for (
Int_t iStat = 6; iStat < nStats; iStat++) {
758 if (pointsOnGemsAndSilicon[iStat] != 0)
761 if (pointCounter == 0)
762 isPrelimAccepted[1] =
kFALSE;
765 Bool_t doWeAcceptEvent = (isPrelimAccepted[0] && isPrelimAccepted[1]) ?
kTRUE :
kFALSE;
767 if (!doWeAcceptEvent)
772 for (
Int_t iStat = 0; iStat < nStats; iStat++) {
773 if (pointsOnGemsAndSilicon[iStat] == 2) {
774 isMultiplePointsOnZ =
kTRUE;
777 nHitsPerPion += pointsOnGemsAndSilicon[iStat];
779 if (isMultiplePointsOnZ || nHitsPerPion < 4 || nHitsPerPion > nStats)
782 Ppion = track->
GetP();
791 pairFromLambda.
SetTxPair(TxProt, TxPion);
792 pairFromLambda.
SetTyPair(TyProt, TyPion);
793 pairFromLambda.
SetNHitsPair(nHitsPerProton, nHitsPerPion);
823 std::map<DetectorId, bool> setup;
824 setup.insert(std::make_pair(
kBC, 0));
825 setup.insert(std::make_pair(
kSILICON, 1));
826 setup.insert(std::make_pair(
kGEM, 1));
844 map<UInt_t, TVector3> EventIdsVpMap;
846 fReco->GetEntry(iEntry);
859 return EventIdsVpMap;
868 vector<BmnStripDigit> digits;
889 Int_t idxPi = -1, idxProt = -1;
892 for (
Int_t iTrack = 0; iTrack <
fMCTracks->GetEntriesFast(); iTrack++) {
923 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
928 digits.push_back(*digi);
938 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
942 digits.push_back(*digi);
952 if (point->GetTrackID() != idxProt && point->GetTrackID() != idxPi)
956 digits.push_back(*digi);
966 map<Int_t, Int_t> digiToChannel;
967 map<pair<Int_t, Int_t>,
Long_t> digiChannelToSerial;
969 const Int_t nDigs = digits.size();
974 for (
Int_t iDigi = 0; iDigi < nDigs; iDigi++) {
977 digiToChannel[iDigi] =
fInfo->GemDigiToChannel(dig, serial[iDigi]);
981 for (
auto it : digiToChannel) {
987 Long_t value = (serial[it.first] == 0) ?
fInfo->GemDigiChannelToSerial(make_pair(digits[it.first], it.second))
989 digiChannelToSerial[make_pair(it.first, it.second)] = value;
992 return digiChannelToSerial;
997 map<pair<Int_t, Int_t>,
Long_t> digiChannelToSerial;
999 for (
size_t iDigi = 0; iDigi < digits.size(); iDigi++) {
1004 digiChannelToSerial[make_pair(iDigi,
fInfo->CscDigiToChannel(dig, serial))] = serial;
1007 return digiChannelToSerial;
1012 map<vector<Int_t>,
Long_t> digiChannelToSerial;
1014 for (
size_t iDigi = 0; iDigi < digits.size(); iDigi++) {
1017 Int_t chan = -1, sample = -1;
1021 fInfo->SiliconDigiToChannelSampleSerial(dig, chan, sample, serial);
1022 vector<Int_t> tmp{(int)iDigi, chan, sample};
1024 digiChannelToSerial[tmp] = serial;
1027 return digiChannelToSerial;
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)
1041 tmp +=
"_withLambdaEmbedded.root";
1052 t->
Branch(
"BmnEventHeader.", &header);
1053 t->
Branch(
"SYNC", &sync);
1054 t->
Branch(
"ADC32", &gemOrCsc);
1055 t->
Branch(
"ADC128", &silicon);
1069 if (iEntry % 1000 == 0)
1070 cout <<
"Embedding, event# " << iEntry << endl;
1080 header->SetRunId(fEventHeader->GetRunId());
1085 for (
Int_t iSync = 0; iSync <
fSync->GetEntriesFast(); iSync++) {
1096 auto itDigGem = digsGem.find(eventId);
1097 auto itDigSilicon = digsSilicon.find(eventId);
1098 auto itDigCsc = digsCsc.find(eventId);
1100 if (itDigGem == digsGem.end())
1101 isEventIdFoundInTheMap =
kFALSE;
1105 vector<BmnStripDigit> digitsGem;
1106 map<pair<Int_t, Int_t>,
Long_t> idxChanSerGem;
1109 vector<BmnStripDigit> digitsSilicon;
1110 map<vector<Int_t>,
Long_t> idxChanSampleSerSilicon;
1113 vector<BmnStripDigit> digitsCsc;
1114 map<pair<Int_t, Int_t>,
Long_t> idxChanSerCsc;
1116 if (isEventIdFoundInTheMap) {
1119 digitsGem = itDigGem->second;
1120 idxChanSerGem = evIdChannelSerialGem.find(eventId)->second;
1125 digitsSilicon = itDigSilicon->second;
1126 idxChanSampleSerSilicon = evIdChannelSerialSilicon.find(eventId)->second;
1131 digitsCsc = itDigCsc->second;
1132 idxChanSerCsc = evIdChannelSerialCsc.find(eventId)->second;
1138 for (
Int_t iAdc32 = 0; iAdc32 <
fADC32->GetEntriesFast(); iAdc32++) {
1147 for (
auto itCorr : idxChanSerGem) {
1148 Int_t channelTmp = itCorr.first.second;
1151 Long_t serialBuff = itCorr.second;
1153 if ((
Int_t)channel != channelBuff || serial != serialBuff)
1157 Int_t signal =
Int_t(digitsGem[itCorr.first.first].GetStripSignal());
1160 adc32->GetShortValue()[sample] += signal * 16;
1162 adc32->GetShortValue()[sample] +=
fSignal[0] * 16;
1170 for (
auto itCorr : idxChanSerCsc) {
1171 Int_t channelTmp = itCorr.first.second;
1174 Long_t serialBuff = itCorr.second;
1176 if ((
Int_t)channel != channelBuff || serial != serialBuff)
1180 Int_t signal =
Int_t(digitsCsc[itCorr.first.first].GetStripSignal() * 16.);
1183 adc32->GetShortValue()[sample] += signal;
1185 adc32->GetShortValue()[sample] +=
fSignal[2] * 16;
1198 for (
Int_t iAdc128 = 0; iAdc128 <
fADC128->GetEntriesFast(); iAdc128++) {
1205 for (
auto itCorr : idxChanSampleSerSilicon) {
1206 Int_t chan = itCorr.first[1];
1207 Long_t ser = itCorr.second;
1209 if ((
Int_t)channel != chan || serial != ser)
1212 Int_t idx = itCorr.first[0];
1213 Int_t signal =
Int_t(digitsSilicon[idx].GetStripSignal() * 16.);
1215 Int_t sample = itCorr.first[2];
1218 Int_t sign = (digitsSilicon[idx].GetStripLayer() == 0) ? +1 : -1;
1220 adc128->GetShortValue()[sample] += sign * signal;
1222 adc128->GetShortValue()[sample] += sign *
fSignal[1] * 16;
1230 adc128->GetShortValue(), adc128->
IsEmbedded());
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;
1259 for (
Int_t iTrack = 0; iTrack <
fMCTracks->GetEntriesFast(); iTrack++) {
1267 if (track->
GetPz() < 0.)
1277 TVector3 tmp(Tx * Pz, Ty * Pz, Pz);
1291 cout <<
"N_particles_store# " <<
fLambdaStore->GetEntriesFast() << endl;
1295 cout <<
"P = " << lambda->
GetP() <<
" Eta = " << lambda->
GetEta() <<
" Phi = " << lambda->
GetPhi() << endl;
1322 TString namePart = (pdg == 3122) ?
"lambda" : (pdg == 310) ?
"kaon" :
"unknown";
1325 TString macroName =
"SimulateLambdaPassing.C";
1328 TString gPathFull = gPathConfig +
"/macro/embedding/" + macroName;
1330 TString argList =
TString::Format(
"(%d, %d, %G, %G, %G, %G, %G, %G, %G, \"%s\")", pdg,
fNeventsToBeSimulated,
1348 else if (z > z1 && z < z2)
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
void SetAsEmbedded(Bool_t flag)
uint32_t GetSerial() const
uint16_t GetChannel() 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 SimulateLambdaPassing(Int_t, Double_t, TVector2, TVector3, Int_t, Int_t)
void SetUseRealSignals(Bool_t flag)
virtual ~BmnLambdaEmbedding()
SignalNormalizationUtils * normUtils
Bool_t doEmbeddingMonitor
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)
Bool_t doRawRootConvertion
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)
Int_t fNeventsToBeSimulated
void DoEmbeddingMonitor(Bool_t flag)
Bool_t doSimulateLambdaThroughSetup
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
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()
Class BmnStripDigit Base class for strip detector digits.
Long64_t GetTime_sec() const
Long64_t GetTime_ns() const
Long64_t GetEvent() const
Int_t GetMotherId() const
Int_t GetPdgCode() const
Accessors.
Double_t GetX() const
Accessors.
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
static TString Format(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
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)
UniRun.h Class for the table: run_.
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
Double_t Sqrt(Double_t x)
constexpr Double_t RadToDeg()