CbmRoot
Loading...
Searching...
No Matches
CbmMCEventFilter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer], Florian Uhlig */
4
10#include "CbmMCEventFilter.h"
11
12#include <FairRootManager.h>
13#include <Logger.h>
14
15#include <cassert>
16#include <iostream>
17#include <sstream>
18
19using std::cout;
20using std::endl;
21
22
23// ----- Constructor -------------------------------------------------------
25 : FairTask("MCEventFilter")
26 , fData()
27 , fMinNofData()
28 , fNofEventsIn(0)
29 , fNofEventsOut(0)
30{
31}
32// --------------------------------------------------------------------------
33
34
35// ----- Get a data object by index -------------------------------------
36TObject* CbmMCEventFilter::GetData(ECbmDataType type, Int_t index) const
37{
38 if (index < 0 || index >= GetNofData(type)) return nullptr;
39 return fData.at(type)->UncheckedAt(index);
40}
41// --------------------------------------------------------------------------
42
43
44// ----- Execution ------------------------------------------------------
46{
47
49 Bool_t test = SelectEvent();
50 if (test) {
51 LOG(info) << GetName() << ": Current event " << fNofEventsIn << " selected for output";
53 } //? Event selected
54 else
55 LOG(info) << GetName() << ": Current event " << fNofEventsIn << " discarded for output";
56 FairMCApplication::Instance()->SetSaveCurrentEvent(test);
57}
58// --------------------------------------------------------------------------
59
60
61// ----- End-of-run action ----------------------------------------------
63{
64
65 cout << endl;
66 LOG(info) << GetName() << ": Number of input events " << fNofEventsIn;
67 LOG(info) << GetName() << ": Number of output events " << fNofEventsOut << " = "
68 << 100. * Double_t(fNofEventsOut) / Double_t(fNofEventsIn) << " %";
69 cout << endl;
70}
71// --------------------------------------------------------------------------
72
73
74// ----- Initialisation -------------------------------------------------
90// --------------------------------------------------------------------------
91
92
93// ----- Get a branch of MC data from FairRootManager -------------------
95{
96
97 FairRootManager* rm = FairRootManager::Instance();
98 assert(rm);
99
100 TString branchName = GetBranchName(type);
101 if (!branchName.IsNull()) {
102 fData[type] = dynamic_cast<TClonesArray*>(rm->GetObject(branchName));
103 if (fData.at(type)) { LOG(info) << GetName() << ": Add branch " << branchName; }
104 }
105}
106// --------------------------------------------------------------------------
107
108
109// ----- Get branch name of data type -----------------------------------
111{
112
113 TString name = "";
114 switch (type) {
115 case ECbmDataType::kMCTrack: name = "MCTrack"; break;
116 case ECbmDataType::kMvdPoint: name = "MvdPoint"; break;
117 case ECbmDataType::kStsPoint: name = "StsPoint"; break;
118 case ECbmDataType::kRichPoint: name = "RichPoint"; break;
119 case ECbmDataType::kMuchPoint: name = "MuchPoint"; break;
120 case ECbmDataType::kTrdPoint: name = "TrdPoint"; break;
121 case ECbmDataType::kTofPoint: name = "TofPoint"; break;
122 case ECbmDataType::kFsdPoint: name = "FsdPoint"; break;
123 case ECbmDataType::kPsdPoint: name = "PsdPoint"; break;
124 default: name = ""; break;
125 }
126
127 return name;
128}
129// --------------------------------------------------------------------------
130
131
132// ----- Event selector -------------------------------------------------
134{
135
136 LOG(info) << GetName() << ": " << Statistics();
137 Bool_t check = kTRUE;
138 for (auto cut : fMinNofData) {
139 if (GetNofData(cut.first) < cut.second) {
140 LOG(info) << GetName() << ": Cut on branch " << GetBranchName(cut.first) << " not passed (number of data "
141 << GetNofData(cut.first) << ", required " << cut.second << ")";
142 check = kFALSE;
143 break;
144 }
145 }
146
147 return check;
148}
149// --------------------------------------------------------------------------
150
151
152// ----- Statistics info -------------------------------------------------
154{
155
156 std::stringstream ss;
157 ss << "MCTracks " << GetNofData(ECbmDataType::kMCTrack) << ", Points: ";
158 if (fData.at(ECbmDataType::kMvdPoint)) ss << "MVD " << GetNofData(ECbmDataType::kMvdPoint) << " ";
159 if (fData.at(ECbmDataType::kStsPoint)) ss << "STS " << GetNofData(ECbmDataType::kStsPoint) << " ";
160 if (fData.at(ECbmDataType::kRichPoint)) ss << "RICH " << GetNofData(ECbmDataType::kRichPoint) << " ";
161 if (fData.at(ECbmDataType::kMuchPoint)) ss << "MUCH " << GetNofData(ECbmDataType::kMuchPoint) << " ";
162 if (fData.at(ECbmDataType::kTrdPoint)) ss << "TRD " << GetNofData(ECbmDataType::kTrdPoint) << " ";
163 if (fData.at(ECbmDataType::kTofPoint)) ss << "TOF " << GetNofData(ECbmDataType::kTofPoint) << " ";
164 if (fData.at(ECbmDataType::kFsdPoint)) ss << "FSD " << GetNofData(ECbmDataType::kFsdPoint) << " ";
165 if (fData.at(ECbmDataType::kPsdPoint)) ss << "PSD " << GetNofData(ECbmDataType::kPsdPoint) << " ";
166
167 return ss.str();
168}
169// --------------------------------------------------------------------------
170
171
ClassImp(CbmConverterManager)
ECbmDataType
Definition CbmDefs.h:90
Class deciding whether to store an MC event.
std::map< ECbmDataType, Int_t > fMinNofData
Data arrays.
Int_t fNofEventsOut
Counter: output events.
TString GetBranchName(ECbmDataType type) const
Get branch name from data type.
void GetBranch(ECbmDataType type)
Get a branch from FairRootManager.
std::string Statistics() const
Info on number of MC objects in the arrays.
TObject * GetData(ECbmDataType type, Int_t index) const
Get a data object by index.
virtual void Exec(Option_t *)
Execution.
Int_t fNofEventsIn
Counter: input events.
std::map< ECbmDataType, TClonesArray * > fData
virtual void Finish()
Finish (end of run)
Bool_t SelectEvent() const
Event selector method.
Int_t GetNofData(ECbmDataType type) const
Number of data in a branch.
virtual InitStatus Init()
Initialisation.