CbmRoot
CbmBuildEventsQA.cxx
Go to the documentation of this file.
1 
6 #include "CbmBuildEventsQA.h"
7 
8 #include "CbmEvent.h"
9 #include "CbmLink.h"
10 #include "CbmMatch.h"
11 #include "CbmStsDigi.h"
12 #include "FairLogger.h"
13 #include "FairRootManager.h"
14 #include "TClonesArray.h"
15 #include "TStopwatch.h"
16 #include <cassert>
17 #include <iomanip>
18 #include <iostream>
19 #include <map>
20 
21 using namespace std;
22 
23 
24 // ===== Constructor =====================================================
26  : FairTask("BuildEventsQA")
27  , fStsDigis(NULL)
28  , fStsDigiMatches(nullptr)
29  , fEvents(NULL)
30  , fNofEntries(0) {}
31 // ===========================================================================
32 
33 
34 // ===== Destructor ======================================================
36 // ===========================================================================
37 
38 
39 // ===== Task execution ==================================================
40 void CbmBuildEventsQA::Exec(Option_t*) {
41 
42  // --- Time and counters
43  TStopwatch timer;
44  timer.Start();
45  Int_t nMCEvents = 0;
46 
47  // --- Event loop
48  Int_t nEvents = fEvents->GetEntriesFast();
49  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
50  CbmEvent* event = (CbmEvent*) fEvents->At(iEvent);
51 
52  // --- Match event to MC
53  MatchEvent(event);
54  Int_t mcEventNr = event->GetMatch()->GetMatchedLink().GetEntry();
55  LOG(info) << GetName() << ": Event " << event->GetNumber()
56  << ", data objects : " << event->GetNofData()
57  << ", links: " << event->GetMatch()->GetNofLinks()
58  << ", matched MC event number " << mcEventNr;
59 
60  // --- Counters
61  Int_t nDigis = event->GetNofData(ECbmDataType::kStsDigi);
62  Int_t nDigiCorrect = 0;
63  Int_t nLinks = 0;
64  Int_t nLinksCorrect = 0;
65  nMCEvents += event->GetMatch()->GetNofLinks();
66 
67  // --- Loop over STS digis
68  for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
69  UInt_t index = event->GetIndex(ECbmDataType::kStsDigi, iDigi);
70  CbmStsDigi* digi = (CbmStsDigi*) fStsDigis->At(index);
71  CbmMatch* digiMatch = (CbmMatch*) fStsDigiMatches->At(index);
72  assert(digi);
73  assert(digiMatch);
74 
75  // --- Check MC event of digi match
76  if (digiMatch->GetMatchedLink().GetEntry() == mcEventNr) nDigiCorrect++;
77 
78  for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink++) {
79  Int_t entry = digiMatch->GetLink(iLink).GetEntry();
80  nLinks++;
81  if (entry == mcEventNr) nLinksCorrect++;
82  } //# links in digi
83 
84  } //# digis
85 
86 
87  // --- QA output
88  LOG(info) << GetName() << ": correct digis " << nDigiCorrect << " / "
89  << nDigis << " = "
90  << 100. * Double_t(nDigiCorrect) / Double_t(nDigis)
91  << " %, correct digi links " << nLinksCorrect << " / " << nLinks
92  << " = " << 100. * Double_t(nLinksCorrect) / Double_t(nLinks)
93  << " % ";
94 
95  } //# events
96 
97 
98  // Timer and counters
99  fNofEntries++;
100  timer.Stop();
101 
102  // --- Execution log
103  LOG(info) << "+ " << setw(20) << GetName() << ": Entry " << setw(6) << right
104  << fNofEntries << ", real time " << fixed << setprecision(6)
105  << timer.RealTime() << " s, events: " << fEvents->GetEntriesFast()
106  << ", MC events: " << nMCEvents;
107 }
108 // ===========================================================================
109 
110 
111 // ===== Task initialisation =============================================
113 
114  // --- Get FairRootManager instance
115  FairRootManager* ioman = FairRootManager::Instance();
116  assert(ioman);
117 
118  // --- Get input array (CbmEvent)
119  fEvents = (TClonesArray*) ioman->GetObject("Event");
120  assert(fEvents);
121 
122  // --- Get input array (CbmStsDigi)
123  fStsDigis = (TClonesArray*) ioman->GetObject("StsDigi");
124  assert(fStsDigis);
125 
126  return kSUCCESS;
127 }
128 // ===========================================================================
129 
130 
131 // ===== Match event =====================================================
133 
134  // TODO: This functionality should later be moved to the class
135  // CbmMatchRecoToMC
136 
137  // --- Get event match object. If present, will be cleared first. If not,
138  // --- it will be created.
139  CbmMatch* match = event->GetMatch();
140  if (!match) {
141  match = new CbmMatch();
142  event->SetMatch(match);
143  } //? event has no match
144 
145  // --- Loop over digis
146  for (Int_t iDigi = 0; iDigi < event->GetNofData(ECbmDataType::kStsDigi);
147  iDigi++) {
148  Int_t index = event->GetIndex(ECbmDataType::kStsDigi, iDigi);
149  CbmStsDigi* digi = (CbmStsDigi*) fStsDigis->At(index);
150  CbmMatch* digiMatch = (CbmMatch*) fStsDigiMatches->At(index);
151  assert(digi);
152  assert(digiMatch);
153 
154  // --- Update event match with digi links
155  // --- N.b.: The member "index" of CbmLink has here no meaning, since
156  // --- there is only one MC event per tree entry.
157  for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink++) {
158  Int_t file = digiMatch->GetLink(iLink).GetFile();
159  Int_t entry = digiMatch->GetLink(iLink).GetEntry();
160  Double_t weight = digiMatch->GetLink(iLink).GetWeight();
161  match->AddLink(weight, 0, entry, file);
162  } //# links in digi
163 
164  } //#digis
165 }
166 // ===========================================================================
167 
168 
CbmMatch::GetMatchedLink
const CbmLink & GetMatchedLink() const
Definition: CbmMatch.h:37
CbmMatch
Definition: CbmMatch.h:22
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
ECbmDataType::kStsDigi
@ kStsDigi
CbmMatch::GetNofLinks
Int_t GetNofLinks() const
Definition: CbmMatch.h:38
CbmBuildEventsQA::CbmBuildEventsQA
CbmBuildEventsQA()
Definition: CbmBuildEventsQA.cxx:25
CbmBuildEventsQA::fEvents
TClonesArray * fEvents
Input array (class CbmEvent)
Definition: CbmBuildEventsQA.h:40
CbmMatch.h
CbmBuildEventsQA::Exec
virtual void Exec(Option_t *opt)
Definition: CbmBuildEventsQA.cxx:40
CbmEvent.h
CbmStsDigi.h
CbmBuildEventsQA::fStsDigis
TClonesArray * fStsDigis
Input array (class CbmStsDigi)
Definition: CbmBuildEventsQA.h:38
CbmMatch::AddLink
void AddLink(const CbmLink &newLink)
Definition: CbmMatch.cxx:42
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStsDigi
Data class for a single-channel message in the STS.
Definition: CbmStsDigi.h:29
CbmBuildEventsQA::~CbmBuildEventsQA
virtual ~CbmBuildEventsQA()
Definition: CbmBuildEventsQA.cxx:35
CbmBuildEventsQA::MatchEvent
void MatchEvent(CbmEvent *event)
Definition: CbmBuildEventsQA.cxx:132
CbmBuildEventsQA::fStsDigiMatches
TClonesArray * fStsDigiMatches
Input array (class CbmMatch)
Definition: CbmBuildEventsQA.h:39
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmBuildEventsQA.h
CbmBuildEventsQA::fNofEntries
Int_t fNofEntries
Number of processed entries.
Definition: CbmBuildEventsQA.h:41
CbmBuildEventsQA::Init
virtual InitStatus Init()
Definition: CbmBuildEventsQA.cxx:112
CbmBuildEventsQA
Definition: CbmBuildEventsQA.h:24