45 : FairTask(name, iVerbose)
46 , fOutFileName(outFileName)
48 for (Int_t i = 0; i < 5; i++) {
55 TFile* curFile = gFile;
56 TDirectory* curDirectory = gDirectory;
67 gDirectory = curDirectory;
160 std::string prefix = std::string(GetName()) +
"::Exec: ";
163 LOG(warning) << prefix <<
"The task can not run! Some data is missing.";
168 LOG(error) << GetName() <<
" SuperEventAnalysis option currently doesn't work";
182 for (
unsigned int iP = 0; iP <
fTopoPerformance->GetTopoReconstructor()->GetParticles().
size(); iP++) {
184 if (p.NDaughters() != 1)
continue;
185 maxTrackId = std::max(maxTrackId, p.DaughterIds()[0]);
191 LOG(fatal) << prefix <<
"MC track array not found!";
195 LOG(fatal) << prefix <<
"MC event list not found!";
202 vector<int> mcToKFmcMap[nMCEvents];
204 for (
int iMCEvent = 0, mcIndexOffset = 0,
nMCTracks = 0; iMCEvent < nMCEvents;
205 iMCEvent++, mcIndexOffset +=
nMCTracks) {
209 mcToKFmcMap[iMCEvent].resize(
nMCTracks, -1);
211 for (Int_t iMC = 0; iMC <
nMCTracks; iMC++) {
213 CbmLink mcTrackLink = mcEventLink;
223 kfMCTrack.SetPx(cbmMCTrack->
GetPx());
224 kfMCTrack.SetPy(cbmMCTrack->
GetPy());
225 kfMCTrack.SetPz(cbmMCTrack->
GetPz());
229 if (pdg < 9999999 && ((TParticlePDG*) TDatabasePDG::Instance()->GetParticle(pdg))) {
230 q = TDatabasePDG::Instance()->GetParticle(pdg)->Charge() / 3.0;
232 else if (pdg == 1000010020) {
235 else if (pdg == -1000010020) {
238 else if (pdg == 1000010030) {
241 else if (pdg == -1000010030) {
244 else if (pdg == 1000020030) {
247 else if (pdg == -1000020030) {
250 else if (pdg == 1000020040) {
253 else if (pdg == -1000020040) {
260 Double_t p = cbmMCTrack->
GetP();
263 kfMCTrack.SetMotherId(cbmMCTrack->
GetMotherId() + mcIndexOffset);
266 kfMCTrack.SetMotherId(-iMCEvent - 1);
268 kfMCTrack.SetQP(q / p);
269 kfMCTrack.SetPDG(pdg);
270 kfMCTrack.SetNMCPoints(0);
272 mcToKFmcMap[iMCEvent][iMC] =
mcTracks.size();
282 if (ntrackMatches < maxTrackId + 1) {
283 LOG(fatal) << prefix <<
"Number of track matches " << ntrackMatches <<
" is lower than the max track index "
284 << maxTrackId <<
" + 1, something goes wrong!";
288 vector<int> trackMatch(ntrackMatches, -1);
290 for (
int iTr = 0; iTr < ntrackMatches; iTr++) {
297 Float_t bestWeight = 0.f;
298 Float_t totalWeight = 0.f;
299 Int_t mcTrackId = -1;
302 for (
int iLink = 0; iLink < stsTrackMatch->
GetNofLinks(); iLink++) {
307 link = stsTrackMatch->
GetLink(iLink);
309 if (eventIndex >= 0) {
310 mcTrackId = mcToKFmcMap[eventIndex][iMCTrack];
319 if (bestWeight / totalWeight < 0.7) {
328 if (TMath::Abs(
mcTracks[mcTrackId].PDG()) > 4000
329 && !(TMath::Abs(
mcTracks[mcTrackId].PDG()) == 1000010020
330 || TMath::Abs(
mcTracks[mcTrackId].PDG()) == 1000010030
331 || TMath::Abs(
mcTracks[mcTrackId].PDG()) == 1000020030
332 || TMath::Abs(
mcTracks[mcTrackId].PDG()) == 1000020040)) {
336 mcTracks[mcTrackId].SetReconstructed();
337 trackMatch[iTr] = mcTrackId;
346 vector<int> trackMatch(maxTrackId + 1, -1);
356 for (
int iT = 0; iT < 4; iT++) {
361 LOG(info) << prefix <<
"Topo reconstruction time"
365 LOG(info) << prefix <<
" Sort Tracks " <<
fTime[2] /
fNTimeSlices * 1.e3 <<
" ms";
366 LOG(info) << prefix <<
" KF Particle Finder " <<
fTime[3] /
fNTimeSlices * 1.e3 <<
" ms";
371 for (
unsigned int iP = 0; iP <
fTopoPerformance->GetTopoReconstructor()->GetParticles().
size(); iP++) {
372 new ((*fRecParticles)[iP]) KFParticle(
fTopoPerformance->GetTopoReconstructor()->GetParticles()[iP]);
377 for (
unsigned int iP = 0; iP <
fTopoPerformance->GetTopoReconstructor()->GetParticles().
size(); iP++) {
381 Short_t matchType = 0;
400 new ((*fMCParticles)[iP]) KFMCParticle(
fTopoPerformance->MCParticles()[iP]);
407 std::string prefix = std::string(GetName()) +
"::Finish: ";
413 Int_t ntrackMatches =
fTopoPerformance->GetTopoReconstructor()->GetParticles().size();
414 vector<int> trackMatch(ntrackMatches, -1);
423 for (
int iT = 0; iT < 4; iT++) {
427 LOG(info) << prefix <<
"Topo reconstruction time"
428 <<
" Real = " << std::setw(10) <<
fTime[4] * 1.e3 <<
" ms";
429 LOG(info) << prefix <<
" Init " <<
fTime[0] * 1.e3 <<
" ms";
430 LOG(info) << prefix <<
" PV Finder " <<
fTime[1] * 1.e3 <<
" ms";
431 LOG(info) << prefix <<
" Sort Tracks " <<
fTime[2] * 1.e3 <<
" ms";
432 LOG(info) << prefix <<
" KF Particle Finder " <<
fTime[3] * 1.e3 <<
" ms";
435 TDirectory* curr = gDirectory;
436 TFile* currentFile = gFile;
444 LOG(fatal) << prefix <<
"Decay to be analysed is not specified!";
458 std::fstream eff(
fEfffileName.Data(), std::fstream::out);
492 static const int nParameters = 7;
493 TString parameterName[nParameters] = {
"X",
"Y",
"Z",
"Px",
"Py",
"Pz",
"E"};
495 TH1F* histogram[nParameters * 2];
496 TF1* fit[nParameters * 2];
498 for (
int iParameter = 0; iParameter < nParameters; iParameter++) {
499 TString cloneResidualName = TString(
"hResidual") + parameterName[iParameter];
500 histogram[iParameter] =
503 new TF1(TString(
"fitResidual") + parameterName[iParameter],
"gaus", histogram[iParameter]->GetXaxis()->GetXmin(),
504 histogram[iParameter]->GetXaxis()->GetXmax());
505 fit[iParameter]->SetLineColor(kRed);
506 histogram[iParameter]->Fit(TString(
"fitResidual") + parameterName[iParameter],
"QN",
"",
507 histogram[iParameter]->GetXaxis()->GetXmin(),
508 histogram[iParameter]->GetXaxis()->GetXmax());
509 sigma[iParameter] = fit[iParameter]->GetParameter(2);
511 TString clonePullName = TString(
"hPull") + parameterName[iParameter];
512 histogram[iParameter + nParameters] =
514 fit[iParameter + nParameters] =
new TF1(TString(
"fitPull") + parameterName[iParameter],
"gaus",
515 histogram[iParameter + nParameters]->GetXaxis()->GetXmin(),
516 histogram[iParameter + nParameters]->GetXaxis()->GetXmax());
517 fit[iParameter + nParameters]->SetLineColor(kRed);
518 histogram[iParameter + nParameters]->Fit(TString(
"fitPull") + parameterName[iParameter],
"QN",
"",
519 histogram[iParameter + nParameters]->GetXaxis()->GetXmin(),
520 histogram[iParameter + nParameters]->GetXaxis()->GetXmax());
521 sigma[iParameter + nParameters] = fit[iParameter + nParameters]->GetParameter(2);
524 if (saveReferenceResults) {
525 TCanvas fitCanvas(
"fitCanvas",
"fitCanvas", 1600, 800);
526 fitCanvas.Divide(4, 4);
528 int padMap[nParameters * 2] = {1, 2, 3, 9, 10, 11, 12, 5, 6, 7, 13, 14, 15, 16};
529 for (
int iHisto = 0; iHisto < nParameters * 2; iHisto++) {
530 fitCanvas.cd(padMap[iHisto]);
531 histogram[iHisto]->Draw();
532 fit[iHisto]->Draw(
"same");
536 fitCanvas.SaveAs(canvasFile.Data());
539 for (
int iHisto = 0; iHisto < nParameters * 2; iHisto++) {
551 TString referenceFileName =
556 while (!gSystem->AccessPathName(qaFileName)) {
558 qaFileName += iQAFile;
559 qaFileName += TString(
".root");
563 TFile* curFile = gFile;
564 TDirectory* curDirectory = gDirectory;
565 TFile* qaFile =
new TFile(qaFileName.Data(),
"RECREATE");
568 TH1F* qaHisto =
new TH1F(qaHistoName.Data(), qaHistoName.Data(), 16, 0, 16);
570 TString binLabel[16] = {
"#sigma_{x}",
"#sigma_{y}",
"#sigma_{z}",
"#sigma_{p_{x}}",
571 "#sigma_{p_{y}}",
"#sigma_{p_{z}}",
"#sigma_{E}",
"P_{x}",
572 "P_{y}",
"P_{z}",
"P_{p_{x}}",
"P_{p_{y}}",
573 "P_{p_{z}}",
"P_{E}",
"#varepsilon_{4#pi}",
"#varepsilon_{KFP}"};
574 for (
int iBin = 0; iBin < 16; iBin++) {
575 qaHisto->GetXaxis()->SetBinLabel(iBin + 1, binLabel[iBin].Data());
578 for (
int iSigma = 0; iSigma < 14; iSigma++) {
579 qaHisto->SetBinContent(iSigma + 1, sigma[iSigma]);
588 TFile* referenceFile =
new TFile(referenceFileName.Data(),
"READ");
589 if (referenceFile->IsOpen()) {
590 TH1F* referenceHisto = referenceFile->Get<TH1F>(qaHistoName);
591 if (referenceHisto) {
593 for (
int iBin = 1; iBin <= 7; iBin++) {
595 fabs(referenceHisto->GetBinContent(iBin) - qaHisto->GetBinContent(iBin)) / referenceHisto->GetBinContent(iBin)
598 for (
int iBin = 8; iBin <= 14; iBin++) {
600 fabs(referenceHisto->GetBinContent(iBin) - qaHisto->GetBinContent(iBin)) / referenceHisto->GetBinContent(iBin)
603 for (
int iBin = 15; iBin <= 16; iBin++) {
605 fabs(referenceHisto->GetBinContent(iBin) - qaHisto->GetBinContent(iBin)) / referenceHisto->GetBinContent(iBin)
609 referenceFile->Close();
610 referenceFile->Delete();
613 LOG(error) <<
"Could not open file " << referenceFileName <<
" with reference histograms";
622 gDirectory = curDirectory;
ClassImp(CbmKFParticleFinderQa)
void WriteHistosCurFile(TObject *obj)
virtual InitStatus Init()
CbmKFParticleFinderQa(const char *name="CbmKFParticleFinderQa", Int_t iVerbose=0, const KFParticleTopoReconstructor *tr=nullptr, TString outFileName="CbmKFParticleFinderQa.root")
virtual void Exec(Option_t *opt)
CbmMCDataArray * fMCTrackArray
Array of CbmEvent objects.
KFTopoPerformance * fTopoPerformance
CbmMCEventList * fMcEventList
void FitDecayQAHistograms(float sigma[14], const bool saveReferenceResults=false) const
TClonesArray * fMatchParticles
TClonesArray * fTrackMatchArray
void SetMatchType(Short_t i)