26 , fParticlePairCuts(new TClonesArray(
"BmnParticlePairCut"))
35 , hSpectrumImproved(nullptr)
45 TSystemDirectory dirFiles(dir.Data(), dir.Data());
46 TList* files = dirFiles.GetListOfFiles();
49 TIter next((TCollection*)files);
53 while ((file = (TSystemFile*)next())) {
55 TString fname = file->GetName();
57 if (!file->IsDirectory() && fname.EndsWith(
".root"))
58 fInFiles.push_back(dir + (TString)file->GetName());
64 Double_t B = cut->
B();
65 Double_t S = cut->
S();
67 Double_t mass = cut->
mass();
68 Double_t width = cut->
width();
71 if (width > 0.005 || width < 0.002)
74 if (TMath::Abs(mass - 1.1157) > width)
78 if (S < fSignal || B < 0. || B > 10000.)
104 Bool_t isNeededTarget = kFALSE;
110 isNeededTarget = kTRUE;
119 if (!tmp.Contains(Form(
"%d", iFile)))
129void BmnMassSpectrumAnal::DoOptimization()
132 cout <<
"nFiles# " << selectedFiles.size() << endl;
135 hSpectra =
new TH1F*[fParticlePairCuts->GetEntriesFast()];
136 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
139 Double_t dca0 = cut->
dca0();
140 Double_t dca1 = cut->
dca1();
141 Double_t dca2 = cut->
dca2();
142 Double_t dca12 = cut->
dca12();
144 Double_t path = cut->
path();
149 TString hName = TString::Format(
"dca0 %G dca1 %G dca2 %G dca12 %G path %G nPos %d nNeg %d", dca0, dca1, dca2,
150 dca12, path, nPos, nNeg);
151 hSpectra[iCut] =
new TH1F(hName.Data(),
"massSpectrum", 75,
xLow,
xUp);
155 for (
auto it = selectedFiles.begin(); it != selectedFiles.end(); it++) {
163 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
165 Double_t mean = -1., sigma = -1.;
166 pair<Double_t, Double_t> T = make_pair(-1., -1.);
167 pair<Double_t, Double_t> B = make_pair(-1., -1.);
169 if (hSpectra[iCut]->GetEntries() < 250.)
172 if (iCut % 1000 == 0)
173 cout <<
"Fitting cut# " << iCut << endl;
185 const Int_t nCuts = 1;
186 TFile* fOut =
new TFile(Form(
"h%s.root",
fTarget.at(0).Data()),
"recreate");
188 map<Double_t, Int_t> Smap;
189 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
195 Double_t S = cut->
S();
202 vector<Int_t> cutsToBeImproved;
204 for (
auto it = Smap.rbegin(); it != Smap.rend(); it++) {
206 if (distance(Smap.rbegin(), it) == nCuts)
211 Double_t B = cut->
B();
212 Double_t S = cut->
S();
214 cutsToBeImproved.push_back(it->second);
216 hSpectra[it->second]->SetTitle(Form(
"S = %G, B = %G, S/B = %G", S, B, S / B));
217 hSpectra[it->second]->Write();
221 for (
auto it : cutsToBeImproved) {
225 Double_t dca12Imp = ImproveCutValue(selectedFiles, cut,
"dca12");
226 cout <<
"Improved dca12 = " << dca12Imp << endl;
230 Double_t dca0Imp = ImproveCutValue(selectedFiles, cut,
"dca0");
231 cout <<
"Improved dca0 = " << dca0Imp << endl;
235 Double_t dca1Imp = ImproveCutValue(selectedFiles, cut,
"dca1");
236 cout <<
"Improved dca1 = " << dca1Imp << endl;
240 Double_t dca2Imp = ImproveCutValue(selectedFiles, cut,
"dca2");
241 cout <<
"Improved dca2 = " << dca2Imp << endl;
245 Double_t path = ImproveCutValue(selectedFiles, cut,
"path");
246 cout <<
"Improved path = " << path << endl;
253Double_t BmnMassSpectrumAnal::ImproveCutValue(vector<TString> selectedFiles,
BmnParticlePairCut* cut, TString cutName)
258 if (cutName.Contains(
"dca")) {
261 }
else if (cutName.Contains(
"path")) {
266 TClonesArray* cutsImproved =
new TClonesArray(
"BmnParticlePairCut");
267 vector<TH1F*> spectraImproved;
274 if (cutName.Contains(
"path"))
281 for (
auto sign : signs)
282 for (Int_t iStep = 1; iStep < nSteps + 1; iStep++) {
287 if (cutName ==
"dca0")
288 cutImp->
SetDca0(cutImp->
dca0() + sign * iStep * step);
289 else if (cutName ==
"dca1")
290 cutImp->
SetDca1(cutImp->
dca1() + sign * iStep * step);
291 else if (cutName ==
"dca2")
292 cutImp->
SetDca2(cutImp->
dca2() + sign * iStep * step);
293 else if (cutName ==
"dca12")
295 else if (cutName ==
"path")
296 cutImp->
SetPath(cutImp->
path() + sign * iStep * step);
298 Fatal(
"BmnMassSpectrumAnal::ImproveCutValue",
"No correct cut name given!");
303 Double_t dca0 = cutImp->
dca0();
304 Double_t dca1 = cutImp->
dca1();
305 Double_t dca2 = cutImp->
dca2();
306 Double_t dca12 = cutImp->
dca12();
307 Double_t path = cutImp->
path();
312 TString hName = TString::Format(
"dca0 %G dca1 %G dca2 %G dca12 %G path %G nPos %d nNeg %d", dca0, dca1,
313 dca2, dca12, path, nPos, nNeg);
317 for (
auto it1 = selectedFiles.begin(); it1 != selectedFiles.end(); it1++) {
325 Double_t mean = -1., sigma = -1.;
326 pair<Double_t, Double_t> T = make_pair(-1., -1.);
327 pair<Double_t, Double_t> B = make_pair(-1., -1.);
340 Form(
"S = %G, B = %G, S/B = %G", T.first - B.first, B.first, (T.first - B.first) / B.first));
352 if (cutsImproved->GetEntriesFast() == 1) {
353 if (cutName ==
"dca0")
355 else if (cutName ==
"dca1")
357 else if (cutName ==
"dca2")
359 else if (cutName ==
"dca12")
361 else if (cutName ==
"path")
368 vector<BmnParticlePairCut> improved;
370 for (Int_t iEntry = 0; iEntry < cutsImproved->GetEntriesFast(); iEntry++) {
373 if (cut0->
origin().Contains(
"improved"))
374 improved.push_back(*cut0);
381 Double_t S0 = source.
S();
382 Double_t B0 = source.
B();
385 for (
auto it1 = improved.begin(); it1 != improved.end(); it1++) {
387 Double_t S1 = (*it1).S();
388 Double_t B1 = (*it1).B();
390 Double_t dS_S0 = (S1 - S0) / S0;
391 Double_t dB_B0 = (B1 - B0) / B0;
393 if (dB_B0 > 0. || dB_B0 > dS_S0)
394 improved.erase(it1--);
398 if (!improved.size()) {
399 if (cutName ==
"dca0")
401 else if (cutName ==
"dca1")
403 else if (cutName ==
"dca2")
405 else if (cutName ==
"dca12")
407 else if (cutName ==
"path")
414 map<Double_t, Double_t> signalCut;
418 if (cutName ==
"dca0")
420 else if (cutName ==
"dca1")
422 else if (cutName ==
"dca2")
424 else if (cutName ==
"dca12")
426 else if (cutName ==
"path")
429 signalCut[it1.S()] = cVal;
432 auto it1 = signalCut.rbegin();
434 TString hNamePart = TString::Format(
"%s %G", cutName.Data(), it1->second);
436 for (TH1F* h : spectraImproved) {
437 if (!((TString)h->GetName()).Contains(hNamePart.Data()))
440 cout << h->GetName() << endl;
452 TClonesArray* triggEffInfo,
456 TChain* out =
new TChain(
"bmndata");
459 if (!out->GetFile()) {
465 TClonesArray* particlePair =
nullptr;
467 out->SetBranchAddress(
"ParticlePair", &particlePair);
468 out->SetBranchAddress(
"DstEventHeaderExtended.", &header);
470 if (!particlePair || !header)
476 TString trigger = info->
GetTrigger(header->GetRunId());
481 for (Int_t iEv = 0; iEv < out->GetEntries(); iEv++) {
484 Int_t nVpTracks = header->nTracks();
485 Double_t Z = header->Vp().Z();
487 if (nVpTracks < 2 || TMath::Abs(Z) > 6.)
490 Double_t epsilon = 1.;
493 for (Int_t iEntry = 0; iEntry < triggEffInfo->GetEntriesFast(); iEntry++) {
502 if (nVpTracks >= minMult && nVpTracks < maxMult) {
510 for (Int_t iPair = 0; iPair < particlePair->GetEntriesFast(); iPair++) {
514 Double_t v0z = pair->
GetV0Z();
517 if (v0z < 0. || v0z > 50.)
522 Double_t DCA1 = pair->
GetDCA1();
523 Double_t DCA2 = pair->
GetDCA2();
524 Double_t DCA0 = pair->
GetDCA0();
526 Double_t PATH = pair->
GetPath();
535 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
537 Double_t dca0 = cut->
dca0();
538 Double_t dca1 = cut->
dca1();
539 Double_t dca2 = cut->
dca2();
540 Double_t dca12 = cut->
dca12();
542 Double_t path = cut->
path();
547 if (DCA0 > dca0 || DCA12 > dca12)
550 if (DCA1 < dca1 || DCA2 < dca2 || PATH < path)
553 if (protonNGemHits <= nPos || pionNGemHits <= nNeg)
559 Double_t dca0 = cut->
dca0();
560 Double_t dca1 = cut->
dca1();
561 Double_t dca2 = cut->
dca2();
562 Double_t dca12 = cut->
dca12();
564 Double_t path = cut->
path();
569 if (DCA0 > dca0 || DCA12 > dca12)
572 if (DCA1 < dca1 || DCA2 < dca2)
579 if (PATH < pathMin || PATH > pathMax)
583 if (protonNGemHits <= nPos || pionNGemHits <= nNeg)
600 vector<Double_t> kinVec1{protonMom, protonTx, protonTy};
601 if (!isVectorOk(kinVec1))
604 vector<Double_t> kinVec2{pionMom, pionTx, pionTy};
605 if (!isVectorOk(kinVec2))
608 Double_t y = -1., pt = -1.;
609 GetPtY(kinVec1, kinVec2, pt, y);
625 cout <<
"File " <<
f <<
" processed# " << endl;
633 vector<Double_t> binErrorsAll;
634 vector<Double_t> binErrorsSignal;
637 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
638 binErrorsAll.push_back(h->GetBinError(iBin));
642 binErrorsSignal.push_back(h->GetBinError(iBin));
646 h->SetBinError(iBin, 0.);
648 Double_t xmin = mA.
xLow + 0.01;
649 Double_t xmax = mA.
xUp;
652 TF1* fitBackground =
new TF1(
"f11",
background, xmin, xmax, n + 1);
653 fitBackground->SetLineColor(kBlue);
654 fitBackground->SetLineStyle(kDashed);
655 TFitResultPtr backRes = h->Fit(fitBackground,
"SQR+",
"", xmin, xmax);
658 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
659 h->SetBinError(iBin, binErrorsAll[iBin]);
670 pair<Double_t, Double_t>& T,
671 pair<Double_t, Double_t>& B)
675 vector<Double_t> binErrorsAll;
676 vector<Double_t> binErrorsSignal;
679 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
680 binErrorsAll.push_back(h->GetBinError(iBin));
684 binErrorsSignal.push_back(h->GetBinError(iBin));
688 h->SetBinError(iBin, 0.);
690 Double_t xmin = mA.
xLow + 0.01;
691 Double_t xmax = mA.
xUp;
694 TF1* fitBackground =
new TF1(
"f1",
background, xmin, xmax, n + 1);
695 fitBackground->SetLineColor(kBlue);
696 fitBackground->SetLineStyle(kDashed);
697 TFitResultPtr backRes = h->Fit(fitBackground,
"SQR+",
"", xmin, xmax);
703 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
704 h->SetBinError(iBin, 0.);
710 TF1* fitSignal =
new TF1(
"f2",
signal, xmin, xmax, 3);
712 fitSignal->SetParameter(0, 2000.);
713 fitSignal->SetParameter(1, 1.1157);
714 fitSignal->SetParameter(2, 0.002);
715 fitSignal->SetNpx(500);
717 fitSignal->SetLineColor(kRed);
718 TFitResultPtr sigRes =
725 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
726 h->SetBinError(iBin, binErrorsAll[iBin]);
728 TF1* fSpectrum =
new TF1(
"f",
fitFunction, xmin, xmax, 10);
729 fSpectrum->SetLineColor(kMagenta);
730 fSpectrum->SetNpx(500);
731 fSpectrum->SetParameter(0, backRes->Parameter(0));
732 fSpectrum->SetParameter(1, backRes->Parameter(1));
733 fSpectrum->SetParameter(2, backRes->Parameter(2));
734 fSpectrum->SetParameter(3, backRes->Parameter(3));
735 fSpectrum->SetParameter(4, backRes->Parameter(4));
736 fSpectrum->SetParameter(5, backRes->Parameter(5));
737 fSpectrum->SetParameter(6, backRes->Parameter(6));
738 fSpectrum->SetParameter(7, sigRes->Parameter(0));
739 fSpectrum->SetParameter(8, sigRes->Parameter(1));
740 fSpectrum->SetParameter(9, sigRes->Parameter(2));
742 TFitResultPtr res = h->Fit(fSpectrum,
"SQR+",
"", xmin, xmax);
747 mean = res->Parameter(8);
748 sigma = TMath::Abs(res->Parameter(9));
751 T.first = fSpectrum->Integral(mean - 3 * sigma, mean + 3 * sigma) / h->GetBinWidth(1);
752 B.first = fitBackground->Integral(mean - 3 * sigma, mean + 3 * sigma) / h->GetBinWidth(1);
759 B.second += fitBackground->Eval(h->GetBinCenter(iBin));
760 T.second += h->GetBinContent(iBin);
768 Double_t fA = mA.
xLow;
769 Double_t fB = mA.
xUp;
774 Double_t x = (2.0 * xx[0] - fA - fB) / (fB - fA);
775 int order = fT.size();
779 return p[0] + x * p[1];
783 for (Int_t
i = 1;
i < order; ++
i) {
784 fT[
i + 1] = 2 * x * fT[
i] - fT[
i - 1];
786 Double_t sum = p[0] * fT[0];
787 for (
int i = 1;
i <= order; ++
i) {
797 Double_t arg = (xx[0] - p[1]) / p[2];
798 Double_t fitval = p[0] * TMath::Exp(-0.5 * arg * arg);
813 Double_t p1 = vec1.at(0);
814 Double_t Tx1 = vec1.at(1);
815 Double_t Ty1 = vec1.at(2);
817 Double_t p2 = vec2.at(0);
818 Double_t Tx2 = vec2.at(1);
819 Double_t Ty2 = vec2.at(2);
821 Double_t px1 = Tx1 * (p1 / TMath::Sqrt(1 + Tx1 * Tx1 + Ty1 * Ty1));
822 Double_t px2 = Tx2 * (p2 / TMath::Sqrt(1 + Tx2 * Tx2 + Ty2 * Ty2));
824 Double_t py1 = Ty1 * (p1 / TMath::Sqrt(1 + Tx1 * Tx1 + Ty1 * Ty1));
825 Double_t py2 = Ty2 * (p2 / TMath::Sqrt(1 + Tx2 * Tx2 + Ty2 * Ty2));
827 Double_t pz1 = p1 / TMath::Sqrt(1 + Tx1 * Tx1 + Ty1 * Ty1);
828 Double_t pz2 = p2 / TMath::Sqrt(1 + Tx2 * Tx2 + Ty2 * Ty2);
830 Double_t px = px1 + px2;
831 Double_t py = py1 + py2;
832 Double_t pz = pz1 + pz2;
834 Double_t p = TMath::Sqrt(px * px + py * py + pz * pz);
836 const Double_t
m = 1.1157;
837 Double_t E = TMath::Sqrt(p * p +
m *
m);
839 pt = TMath::Sqrt(px * px + py * py);
841 Y = .5 * TMath::Log((E + pz) / (E - pz));
TString GetTrigger(Int_t)
map< Int_t, pair< Double_t, Double_t > > fPtBinMap
vector< TString > createFilelist()
static Double_t fitFunction(Double_t *, Double_t *)
map< Int_t, pair< Double_t, Double_t > > fYBinMap
vector< TString > fInFiles
void ReadFile(TString, BmnParticlePairCut *cut0=nullptr, TClonesArray *triggEffInfo=nullptr, Double_t pathMin=0., Double_t pathMax=0.)
Bool_t checkFit(BmnParticlePairCut *)
map< Int_t, pair< Double_t, Double_t > > fPathBins
TFitResultPtr fitSpectrum(TH1F *)
static Double_t signal(Double_t *, Double_t *)
vector< TString > fTarget
static Double_t background(Double_t *, Double_t *)
void GetPtY(vector< Double_t >, vector< Double_t >, Double_t &, Double_t &)
void SetOrigin(TString orig)
void SetSignalAndBackground(Double_t sb)
void SetBackground(Double_t b)
void SetDca12(Double_t v)
void SetWidth(Double_t w)
Int_t GetNHitsPart1(TString det="")
Int_t GetNHitsPart2(TString det="")
pair< Int_t, Int_t > multilplicity()
static UniRun * GetRun(int period_number, int run_number)
get run from the database
TString GetBeamParticle()
get beam particle of the current run
TString GetTargetParticle()
get target particle of the current run