BmnRoot
Loading...
Searching...
No Matches
BmnMassSpectrumAnal.cxx
Go to the documentation of this file.
2
6
8 : fPeriod(7)
9 , fStartRun(3589)
10 , fFinishRun(4710)
11 , fBeam("Ar")
12 , fSignal(0.)
13 , fBackground(0.)
14 , xLow(1.07)
15 , xUp(1.22)
16 , fSignalBinMin(18)
17 , fSignalBinMax(26)
18 , fNFiles(0)
19{}
20
22 : fPeriod(7)
23 , fStartRun(3589)
24 , fFinishRun(4710)
25 , fBeam("Ar")
26 , fParticlePairCuts(new TClonesArray("BmnParticlePairCut"))
27 , hSpectra(nullptr)
28 , fSignal(0.)
29 , fBackground(0.)
30 , xLow(1.07)
31 , xUp(1.22)
32 , fSignalBinMin(18)
33 , fSignalBinMax(26)
34 , fNFiles(0)
35 , hSpectrumImproved(nullptr)
36 , isPtY(kFALSE)
37 , hSpectraPt(nullptr)
38 , hSpectraY(nullptr)
39 , nPtBins(0)
40 , nYBins(0)
41{
42 fTarget.resize(0);
43
44 // Composing input file list ...
45 TSystemDirectory dirFiles(dir.Data(), dir.Data());
46 TList* files = dirFiles.GetListOfFiles();
47
48 TSystemFile* file;
49 TIter next((TCollection*)files);
50
51 fInFiles.resize(0);
52
53 while ((file = (TSystemFile*)next())) {
54
55 TString fname = file->GetName();
56
57 if (!file->IsDirectory() && fname.EndsWith(".root"))
58 fInFiles.push_back(dir + (TString)file->GetName());
59 }
60}
61
63{
64 Double_t B = cut->B();
65 Double_t S = cut->S();
66
67 Double_t mass = cut->mass();
68 Double_t width = cut->width();
69
70 // Skipping resulted spectra wide and narrow signals ..
71 if (width > 0.005 || width < 0.002)
72 return kFALSE;
73
74 if (TMath::Abs(mass - 1.1157) > width)
75 return kFALSE;
76
77 // Skipping bad spectra with incorrect (not satisfying) values of B and S
78 if (S < fSignal || B < 0. || B > 10000.) // FIXME
79 return kFALSE;
80
81 return kTRUE;
82}
83
85{
86 vector<TString> list;
87
88 for (Int_t iFile = fStartRun; iFile < fFinishRun; iFile++) {
89 UniRun* pCurrentRun = UniRun::GetRun(fPeriod, iFile);
90
91 // Check presense of the current run in DB ...
92 if (!pCurrentRun)
93 continue;
94
95 if (pCurrentRun->GetBeamParticle() != fBeam)
96 continue;
97
98 TString targ = pCurrentRun->GetTargetParticle();
99
100 // Skipping runs w/o target ...
101 if (targ == "")
102 continue;
103
104 Bool_t isNeededTarget = kFALSE;
105
106 for (auto it : fTarget) {
107 if (it != targ)
108 continue;
109 else {
110 isNeededTarget = kTRUE;
111 break;
112 }
113 }
114
115 if (!isNeededTarget)
116 continue;
117
118 for (TString tmp : fInFiles) {
119 if (!tmp.Contains(Form("%d", iFile)))
120 continue;
121
122 list.push_back(tmp);
123 break;
124 }
125 }
126 return list;
127}
128
129void BmnMassSpectrumAnal::DoOptimization()
130{
131 vector<TString> selectedFiles = createFilelist();
132 cout << "nFiles# " << selectedFiles.size() << endl;
133
134 // Preparing spectrum histograms ...
135 hSpectra = new TH1F*[fParticlePairCuts->GetEntriesFast()];
136 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
137
138 BmnParticlePairCut* cut = (BmnParticlePairCut*)fParticlePairCuts->UncheckedAt(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();
143
144 Double_t path = cut->path();
145
146 Int_t nPos = cut->nHitsGemPos();
147 Int_t nNeg = cut->nHitsGemNeg();
148
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);
152 }
153
154 // Processing files ...
155 for (auto it = selectedFiles.begin(); it != selectedFiles.end(); it++) {
156 if (fNFiles && distance(selectedFiles.begin(), it) == fNFiles)
157 break;
158
159 ReadFile(*it);
160 }
161
162 // Setting cuts and B, T, mean (mass), sigma (width) ...
163 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
164
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.);
168
169 if (hSpectra[iCut]->GetEntries() < 250.) // FIXME!!!
170 continue;
171
172 if (iCut % 1000 == 0)
173 cout << "Fitting cut# " << iCut << endl;
174
175 fitSpectrum(hSpectra[iCut], mean, sigma, T, B);
176
177 BmnParticlePairCut* cut = (BmnParticlePairCut*)fParticlePairCuts->UncheckedAt(iCut);
178 cut->SetBackground(B.first);
179 cut->SetSignalAndBackground(T.first);
180
181 cut->SetMass(mean);
182 cut->SetWidth(sigma);
183 }
184
185 const Int_t nCuts = 1; // FIXME
186 TFile* fOut = new TFile(Form("h%s.root", fTarget.at(0).Data()), "recreate");
187
188 map<Double_t, Int_t> Smap; // S --> cut
189 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
190 BmnParticlePairCut* cut = (BmnParticlePairCut*)fParticlePairCuts->UncheckedAt(iCut);
191
192 if (!checkFit(cut))
193 continue;
194
195 Double_t S = cut->S();
196
197 Smap[S] = iCut;
198 }
199
200 // Getting highest signal values ...
201
202 vector<Int_t> cutsToBeImproved;
203
204 for (auto it = Smap.rbegin(); it != Smap.rend(); it++) {
205
206 if (distance(Smap.rbegin(), it) == nCuts)
207 break;
208
209 BmnParticlePairCut* cut = (BmnParticlePairCut*)fParticlePairCuts->UncheckedAt(it->second);
210
211 Double_t B = cut->B();
212 Double_t S = cut->S();
213
214 cutsToBeImproved.push_back(it->second);
215
216 hSpectra[it->second]->SetTitle(Form("S = %G, B = %G, S/B = %G", S, B, S / B));
217 hSpectra[it->second]->Write();
218 }
219
220 // Doing optimization over each cut consequently ...
221 for (auto it : cutsToBeImproved) {
222 BmnParticlePairCut* cut = (BmnParticlePairCut*)fParticlePairCuts->UncheckedAt(it);
223
224 // Improving dca12 ...
225 Double_t dca12Imp = ImproveCutValue(selectedFiles, cut, "dca12");
226 cout << "Improved dca12 = " << dca12Imp << endl;
227 cut->SetDca12(dca12Imp);
228
229 // Improving dca0 ...
230 Double_t dca0Imp = ImproveCutValue(selectedFiles, cut, "dca0");
231 cout << "Improved dca0 = " << dca0Imp << endl;
232 cut->SetDca0(dca0Imp);
233
234 // Improving dca1 ...
235 Double_t dca1Imp = ImproveCutValue(selectedFiles, cut, "dca1");
236 cout << "Improved dca1 = " << dca1Imp << endl;
237 cut->SetDca1(dca1Imp);
238
239 // Improving dca2 ...
240 Double_t dca2Imp = ImproveCutValue(selectedFiles, cut, "dca2");
241 cout << "Improved dca2 = " << dca2Imp << endl;
242 cut->SetDca2(dca2Imp);
243
244 // Improving path ...
245 Double_t path = ImproveCutValue(selectedFiles, cut, "path");
246 cout << "Improved path = " << path << endl;
247 cut->SetPath(path);
248 }
249
250 delete fOut;
251}
252
253Double_t BmnMassSpectrumAnal::ImproveCutValue(vector<TString> selectedFiles, BmnParticlePairCut* cut, TString cutName)
254{
255 Double_t step = 0.;
256 Int_t nSteps = 0;
257
258 if (cutName.Contains("dca")) {
259 step = .1;
260 nSteps = 5;
261 } else if (cutName.Contains("path")) {
262 step = 2.;
263 nSteps = 5;
264 }
265
266 TClonesArray* cutsImproved = new TClonesArray("BmnParticlePairCut");
267 vector<TH1F*> spectraImproved;
268
269 // Adding source cut to be used for adjustment ...
270 new ((*cutsImproved)[cutsImproved->GetEntriesFast()]) BmnParticlePairCut(*cut);
271
272 vector<Int_t> signs;
273
274 if (cutName.Contains("path"))
275 signs.push_back(+1);
276 else {
277 signs.push_back(+1);
278 signs.push_back(-1);
279 }
280
281 for (auto sign : signs)
282 for (Int_t iStep = 1; iStep < nSteps + 1; iStep++) {
283
284 // Creating new cut ...
285 BmnParticlePairCut* cutImp = new BmnParticlePairCut(*cut);
286
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")
294 cutImp->SetDca12(cutImp->dca12() + sign * iStep * step);
295 else if (cutName == "path")
296 cutImp->SetPath(cutImp->path() + sign * iStep * step);
297 else
298 Fatal("BmnMassSpectrumAnal::ImproveCutValue", "No correct cut name given!");
299
300 cutImp->SetOrigin("improved");
301
302 // Creating new spectrum ...
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();
308
309 Int_t nPos = cutImp->nHitsGemPos();
310 Int_t nNeg = cutImp->nHitsGemNeg();
311
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);
314
315 hSpectrumImproved = new TH1F(hName.Data(), "massSpectrum", 75, xLow, xUp);
316
317 for (auto it1 = selectedFiles.begin(); it1 != selectedFiles.end(); it1++) {
318 if (fNFiles && distance(selectedFiles.begin(), it1) == fNFiles)
319 break;
320
321 ReadFile(*it1, cutImp);
322 }
323
324 // Fitting obtained spectrum ...
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.);
328
329 fitSpectrum(hSpectrumImproved, mean, sigma, T, B);
330
331 cutImp->SetBackground(B.first);
332 cutImp->SetSignalAndBackground(T.first);
333 cutImp->SetMass(mean);
334 cutImp->SetWidth(sigma);
335
336 if (!checkFit(cutImp))
337 continue;
338
339 hSpectrumImproved->SetTitle(
340 Form("S = %G, B = %G, S/B = %G", T.first - B.first, B.first, (T.first - B.first) / B.first));
341 hSpectrumImproved->SetName((TString)hSpectrumImproved->GetName() + TString::Format(", improved"));
342
343 // Adding possibly adjusted cut and spectrum ...
344 new ((*cutsImproved)[cutsImproved->GetEntriesFast()]) BmnParticlePairCut(*cutImp);
345
346 spectraImproved.push_back((TH1F*)hSpectrumImproved->Clone());
347
348 delete hSpectrumImproved;
349 }
350
351 // No additional info added, thus skipping ...
352 if (cutsImproved->GetEntriesFast() == 1) {
353 if (cutName == "dca0")
354 return cut->dca0();
355 else if (cutName == "dca1")
356 return cut->dca1();
357 else if (cutName == "dca2")
358 return cut->dca2();
359 else if (cutName == "dca12")
360 return cut->dca12();
361 else if (cutName == "path")
362 return cut->path();
363
364 return 0.;
365 }
366
367 BmnParticlePairCut source;
368 vector<BmnParticlePairCut> improved;
369
370 for (Int_t iEntry = 0; iEntry < cutsImproved->GetEntriesFast(); iEntry++) {
371 BmnParticlePairCut* cut0 = (BmnParticlePairCut*)cutsImproved->UncheckedAt(iEntry);
372
373 if (cut0->origin().Contains("improved"))
374 improved.push_back(*cut0);
375 else
376 source = *cut0;
377 }
378
379 delete cutsImproved;
380
381 Double_t S0 = source.S();
382 Double_t B0 = source.B();
383
384 // Removing cuts increasing B or decreasing S significantly ...
385 for (auto it1 = improved.begin(); it1 != improved.end(); it1++) {
386
387 Double_t S1 = (*it1).S();
388 Double_t B1 = (*it1).B();
389
390 Double_t dS_S0 = (S1 - S0) / S0;
391 Double_t dB_B0 = (B1 - B0) / B0;
392
393 if (dB_B0 > 0. || dB_B0 > dS_S0)
394 improved.erase(it1--);
395 }
396
397 // If no one improved cut survived ...
398 if (!improved.size()) {
399 if (cutName == "dca0")
400 return cut->dca0();
401 else if (cutName == "dca1")
402 return cut->dca1();
403 else if (cutName == "dca2")
404 return cut->dca2();
405 else if (cutName == "dca12")
406 return cut->dca12();
407 else if (cutName == "path")
408 return cut->path();
409
410 return 0.;
411 }
412
413 // Getting improved cut that reduces signal as much as possible ...
414 map<Double_t, Double_t> signalCut;
415 for (BmnParticlePairCut it1 : improved) {
416 Double_t cVal = -1.;
417
418 if (cutName == "dca0")
419 cVal = it1.dca0();
420 else if (cutName == "dca1")
421 cVal = it1.dca1();
422 else if (cutName == "dca2")
423 cVal = it1.dca2();
424 else if (cutName == "dca12")
425 cVal = it1.dca12();
426 else if (cutName == "path")
427 cVal = it1.path();
428
429 signalCut[it1.S()] = cVal;
430 }
431
432 auto it1 = signalCut.rbegin();
433
434 TString hNamePart = TString::Format("%s %G", cutName.Data(), it1->second);
435
436 for (TH1F* h : spectraImproved) {
437 if (!((TString)h->GetName()).Contains(hNamePart.Data()))
438 continue;
439
440 cout << h->GetName() << endl;
441 gFile->cd();
442 h->Write();
443
444 break;
445 }
446
447 return it1->second;
448}
449
451 BmnParticlePairCut* cut0,
452 TClonesArray* triggEffInfo,
453 Double_t pathMin,
454 Double_t pathMax)
455{
456 TChain* out = new TChain("bmndata");
457 out->Add(f.Data());
458
459 if (!out->GetFile()) {
460 delete out;
461 return;
462 }
463
464 DstEventHeaderExtended* header = nullptr;
465 TClonesArray* particlePair = nullptr;
466
467 out->SetBranchAddress("ParticlePair", &particlePair);
468 out->SetBranchAddress("DstEventHeaderExtended.", &header);
469
470 if (!particlePair || !header)
471 return;
472
473 // Getting trigger info and its efficiency for certain multiplicity bin ...
475 out->GetEntry();
476 TString trigger = info->GetTrigger(header->GetRunId());
477
478 delete info;
479
480 // for (Int_t iEv = 0; iEv < 10000; iEv++) {
481 for (Int_t iEv = 0; iEv < out->GetEntries(); iEv++) {
482 out->GetEntry(iEv);
483
484 Int_t nVpTracks = header->nTracks();
485 Double_t Z = header->Vp().Z();
486
487 if (nVpTracks < 2 || TMath::Abs(Z) > 6.)
488 continue;
489
490 Double_t epsilon = 1.;
491
492 if (triggEffInfo) {
493 for (Int_t iEntry = 0; iEntry < triggEffInfo->GetEntriesFast(); iEntry++) {
494 TriggerEfficiency* eff = (TriggerEfficiency*)triggEffInfo->UncheckedAt(iEntry);
495
496 if (trigger != eff->trigger())
497 continue;
498
499 Int_t minMult = eff->multilplicity().first;
500 Int_t maxMult = eff->multilplicity().second;
501
502 if (nVpTracks >= minMult && nVpTracks < maxMult) {
503 epsilon = eff->efficiency();
504
505 break;
506 }
507 }
508 }
509
510 for (Int_t iPair = 0; iPair < particlePair->GetEntriesFast(); iPair++) {
511 BmnParticlePair* pair = (BmnParticlePair*)particlePair->UncheckedAt(iPair);
512
513 // V0 ...
514 Double_t v0z = pair->GetV0Z();
515
516 // Skipping so far reconstructed V0's ...
517 if (v0z < 0. || v0z > 50.)
518 continue;
519
520 // Geometry topology ...
521 Double_t DCA12 = pair->GetDCA12();
522 Double_t DCA1 = pair->GetDCA1();
523 Double_t DCA2 = pair->GetDCA2();
524 Double_t DCA0 = pair->GetDCA0();
525
526 Double_t PATH = pair->GetPath();
527
528 // Track length (GEM part of glob. track) ...
529 Int_t protonNGemHits = pair->GetNHitsPart1("GEM");
530 Int_t pionNGemHits = pair->GetNHitsPart2("GEM");
531
532 BmnParticlePairCut* cut = cut0;
533
534 if (!cut0)
535 for (Int_t iCut = 0; iCut < fParticlePairCuts->GetEntriesFast(); iCut++) {
536 cut = (BmnParticlePairCut*)fParticlePairCuts->UncheckedAt(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();
541
542 Double_t path = cut->path();
543
544 Int_t nPos = cut->nHitsGemPos();
545 Int_t nNeg = cut->nHitsGemNeg();
546
547 if (DCA0 > dca0 || DCA12 > dca12) // <=
548 continue;
549
550 if (DCA1 < dca1 || DCA2 < dca2 || PATH < path) // >=
551 continue;
552
553 if (protonNGemHits <= nPos || pionNGemHits <= nNeg) // >
554 continue;
555
556 hSpectra[iCut]->Fill(pair->GetInvMass());
557 }
558 else {
559 Double_t dca0 = cut->dca0();
560 Double_t dca1 = cut->dca1();
561 Double_t dca2 = cut->dca2();
562 Double_t dca12 = cut->dca12();
563
564 Double_t path = cut->path();
565
566 Int_t nPos = cut->nHitsGemPos();
567 Int_t nNeg = cut->nHitsGemNeg();
568
569 if (DCA0 > dca0 || DCA12 > dca12) // <=
570 continue;
571
572 if (DCA1 < dca1 || DCA2 < dca2) // >=
573 continue;
574
575 if (!fPathBins.size()) {
576 if (PATH < path) // >=
577 continue;
578 } else {
579 if (PATH < pathMin || PATH > pathMax)
580 continue;
581 }
582
583 if (protonNGemHits <= nPos || pionNGemHits <= nNeg) // >
584 continue;
585
587 hSpectrumImproved->Fill(pair->GetInvMass(), 1. / epsilon);
588
589 if (isPtY) {
590 // Kinematic topology ...
591 Double_t protonMom = pair->GetMomPart1();
592 Double_t pionMom = pair->GetMomPart2();
593
594 Double_t protonTx = pair->GetTxPart1();
595 Double_t pionTx = pair->GetTxPart2();
596
597 Double_t protonTy = pair->GetTyPart1();
598 Double_t pionTy = pair->GetTyPart2();
599
600 vector<Double_t> kinVec1{protonMom, protonTx, protonTy};
601 if (!isVectorOk(kinVec1))
602 continue;
603
604 vector<Double_t> kinVec2{pionMom, pionTx, pionTy};
605 if (!isVectorOk(kinVec2))
606 continue;
607
608 Double_t y = -1., pt = -1.;
609 GetPtY(kinVec1, kinVec2, pt, y);
610
611 Int_t binPt = FinBin(fPtBinMap, pt);
612 if (binPt != -1)
613 hSpectraPt[binPt]->Fill(pair->GetInvMass(), 1. / epsilon);
614
615 Int_t binY = FinBin(fYBinMap, y);
616 if (binY != -1)
617 hSpectraY[binY]->Fill(pair->GetInvMass(), 1. / epsilon);
618
619 // cout << epsilon << endl;
620 }
621 }
622 }
623 }
624
625 cout << "File " << f << " processed# " << endl;
626 delete out;
627}
628
630{
632
633 vector<Double_t> binErrorsAll;
634 vector<Double_t> binErrorsSignal;
635
636 // Saving bin errors for all bins ...
637 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
638 binErrorsAll.push_back(h->GetBinError(iBin));
639
640 // Saving bin errors for signal region ...
641 for (Int_t iBin = fSignalBinMin; iBin < fSignalBinMax + 1; iBin++)
642 binErrorsSignal.push_back(h->GetBinError(iBin));
643
644 // Setting zero errors for signal region ...
645 for (Int_t iBin = fSignalBinMin; iBin < fSignalBinMax + 1; iBin++)
646 h->SetBinError(iBin, 0.);
647
648 Double_t xmin = mA.xLow + 0.01;
649 Double_t xmax = mA.xUp;
650 Double_t n = 6;
651
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);
656
657 // Restoring all bin errors ...
658 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
659 h->SetBinError(iBin, binErrorsAll[iBin]);
660
661 if (!backRes.Get())
662 return nullptr;
663 else
664 return backRes;
665}
666
668 Double_t& mean,
669 Double_t& sigma,
670 pair<Double_t, Double_t>& T,
671 pair<Double_t, Double_t>& B)
672{
674
675 vector<Double_t> binErrorsAll;
676 vector<Double_t> binErrorsSignal;
677
678 // Saving bin errors for all bins ...
679 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
680 binErrorsAll.push_back(h->GetBinError(iBin));
681
682 // Saving bin errors for signal region ...
683 for (Int_t iBin = fSignalBinMin; iBin < fSignalBinMax + 1; iBin++)
684 binErrorsSignal.push_back(h->GetBinError(iBin));
685
686 // Setting zero errors for signal region ...
687 for (Int_t iBin = fSignalBinMin; iBin < fSignalBinMax + 1; iBin++)
688 h->SetBinError(iBin, 0.);
689
690 Double_t xmin = mA.xLow + 0.01;
691 Double_t xmax = mA.xUp;
692 Double_t n = 6;
693
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);
698
699 if (!backRes.Get())
700 return;
701
702 // Setting zero error for all range ...
703 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
704 h->SetBinError(iBin, 0.);
705
706 // Restoring errors for signal range ...
707 for (Int_t iBin = fSignalBinMin; iBin < fSignalBinMax + 1; iBin++)
708 h->SetBinError(iBin, binErrorsSignal[iBin - fSignalBinMin]);
709
710 TF1* fitSignal = new TF1("f2", signal, xmin, xmax, 3);
711
712 fitSignal->SetParameter(0, 2000.);
713 fitSignal->SetParameter(1, 1.1157); // FIXME!!!
714 fitSignal->SetParameter(2, 0.002);
715 fitSignal->SetNpx(500);
716
717 fitSignal->SetLineColor(kRed);
718 TFitResultPtr sigRes =
719 h->Fit(fitSignal, "SQR0+", "", h->GetBinCenter(fSignalBinMin), h->GetBinCenter(fSignalBinMax));
720
721 if (!sigRes.Get())
722 return;
723
724 // Restoring all bin errors ...
725 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
726 h->SetBinError(iBin, binErrorsAll[iBin]);
727
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));
741
742 TFitResultPtr res = h->Fit(fSpectrum, "SQR+", "", xmin, xmax);
743
744 if (!res.Get())
745 return;
746
747 mean = res->Parameter(8);
748 sigma = TMath::Abs(res->Parameter(9));
749
750 // Calculating T and B by fit ...
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);
753
754 // Calculating T and B by histogram ...
755 B.second = 0.;
756 T.second = 0.;
757
758 for (Int_t iBin = fSignalBinMin; iBin < fSignalBinMax + 1; iBin++) {
759 B.second += fitBackground->Eval(h->GetBinCenter(iBin));
760 T.second += h->GetBinContent(iBin);
761 }
762}
763
764Double_t BmnMassSpectrumAnal::background(Double_t* xx, Double_t* p)
765{
767 // mA.SetSpectrumRange(.452, .602);
768 Double_t fA = mA.xLow;
769 Double_t fB = mA.xUp;
770
771 vector<Double_t> fT;
772 fT.resize(6); // polynomial
773
774 Double_t x = (2.0 * xx[0] - fA - fB) / (fB - fA);
775 int order = fT.size();
776 if (order == 1)
777 return p[0];
778 if (order == 2)
779 return p[0] + x * p[1];
780 // build the polynomials
781 fT[0] = 1;
782 fT[1] = x;
783 for (Int_t i = 1; i < order; ++i) {
784 fT[i + 1] = 2 * x * fT[i] - fT[i - 1];
785 }
786 Double_t sum = p[0] * fT[0];
787 for (int i = 1; i <= order; ++i) {
788 sum += p[i] * fT[i];
789 }
790 return sum;
791}
792
793// Signal function ...
794
795Double_t BmnMassSpectrumAnal::signal(Double_t* xx, Double_t* p)
796{
797 Double_t arg = (xx[0] - p[1]) / p[2];
798 Double_t fitval = p[0] * TMath::Exp(-0.5 * arg * arg);
799 return fitval;
800}
801
802// Sum of background and peak function
803
804Double_t BmnMassSpectrumAnal::fitFunction(Double_t* x, Double_t* par)
805{
806 return background(x, &par[0]) + signal(x, &par[7]);
807}
808
809void BmnMassSpectrumAnal::GetPtY(vector<Double_t> vec1, vector<Double_t> vec2, Double_t& pt, Double_t& Y)
810{
811 // vec --> (p, Tx, Ty)
812
813 Double_t p1 = vec1.at(0);
814 Double_t Tx1 = vec1.at(1);
815 Double_t Ty1 = vec1.at(2);
816
817 Double_t p2 = vec2.at(0);
818 Double_t Tx2 = vec2.at(1);
819 Double_t Ty2 = vec2.at(2);
820
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));
823
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));
826
827 Double_t pz1 = p1 / TMath::Sqrt(1 + Tx1 * Tx1 + Ty1 * Ty1);
828 Double_t pz2 = p2 / TMath::Sqrt(1 + Tx2 * Tx2 + Ty2 * Ty2);
829
830 Double_t px = px1 + px2;
831 Double_t py = py1 + py2;
832 Double_t pz = pz1 + pz2;
833
834 Double_t p = TMath::Sqrt(px * px + py * py + pz * pz);
835
836 const Double_t m = 1.1157;
837 Double_t E = TMath::Sqrt(p * p + m * m);
838
839 pt = TMath::Sqrt(px * px + py * py);
840
841 Y = .5 * TMath::Log((E + pz) / (E - pz));
842}
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
float f
Definition P4_F32vec4.h:21
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 SetDca1(Double_t v)
void SetBackground(Double_t b)
void SetDca0(Double_t v)
void SetPath(Double_t v)
void SetDca12(Double_t v)
void SetWidth(Double_t w)
void SetDca2(Double_t v)
void SetMass(Double_t m)
Int_t GetNHitsPart1(TString det="")
Int_t GetNHitsPart2(TString det="")
Double_t GetMomPart1()
Double_t GetTxPart1()
Double_t GetTyPart1()
Double_t GetInvMass()
Double_t GetTxPart2()
Double_t GetMomPart2()
Double_t GetTyPart2()
pair< Int_t, Int_t > multilplicity()
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:177
TString GetBeamParticle()
get beam particle of the current run
Definition UniRun.h:113
TString GetTargetParticle()
get target particle of the current run
Definition UniRun.h:115