CbmRoot
CbmMCEventFilter.cxx
Go to the documentation of this file.
1 
6 #include "CbmMCEventFilter.h"
7 
8 #include "FairLogger.h"
9 #include <cassert>
10 #include <iostream>
11 #include <sstream>
12 
13 using std::cout;
14 using std::endl;
15 
16 
17 // ----- Constructor -------------------------------------------------------
19  : FairTask("MCEventFilter")
20  , fData()
21  , fMinNofData()
22  , fNofEventsIn(0)
23  , fNofEventsOut(0) {}
24 // --------------------------------------------------------------------------
25 
26 
27 // ----- Get a data object by index -------------------------------------
28 TObject* CbmMCEventFilter::GetData(ECbmDataType type, Int_t index) const {
29  if (index < 0 || index >= GetNofData(type)) return nullptr;
30  return fData.at(type)->UncheckedAt(index);
31 }
32 // --------------------------------------------------------------------------
33 
34 
35 // ----- Execution ------------------------------------------------------
36 void CbmMCEventFilter::Exec(Option_t*) {
37 
38  fNofEventsIn++;
39  Bool_t test = SelectEvent();
40  if (test) {
41  LOG(INFO) << GetName() << ": Current event " << fNofEventsIn
42  << " selected for output";
43  fNofEventsOut++;
44  } //? Event selected
45  else
46  LOG(INFO) << GetName() << ": Current event " << fNofEventsIn
47  << " discarded for output";
48  FairMCApplication::Instance()->SetSaveCurrentEvent(test);
49 }
50 // --------------------------------------------------------------------------
51 
52 
53 // ----- End-of-run action ----------------------------------------------
55 
56  cout << endl;
57  LOG(INFO) << GetName() << ": Number of input events " << fNofEventsIn;
58  LOG(INFO) << GetName() << ": Number of output events " << fNofEventsOut
59  << " = " << 100. * Double_t(fNofEventsOut) / Double_t(fNofEventsIn)
60  << " %";
61  cout << endl;
62 }
63 // --------------------------------------------------------------------------
64 
65 
66 // ----- Initialisation -------------------------------------------------
67 InitStatus CbmMCEventFilter::Init() {
68 
77 
78  return kSUCCESS;
79 }
80 // --------------------------------------------------------------------------
81 
82 
83 // ----- Get a branch of MC data from FairRootManager -------------------
85 
86  FairRootManager* rm = FairRootManager::Instance();
87  assert(rm);
88 
89  TString branchName = GetBranchName(type);
90  if (!branchName.IsNull()) {
91  fData[type] = dynamic_cast<TClonesArray*>(rm->GetObject(branchName));
92  if (fData.at(type)) {
93  LOG(INFO) << GetName() << ": Add branch " << branchName;
94  }
95  }
96 }
97 // --------------------------------------------------------------------------
98 
99 
100 // ----- Get branch name of data type -----------------------------------
102 
103  TString name = "";
104  switch (type) {
105  case ECbmDataType::kMCTrack: name = "MCTrack"; break;
106  case ECbmDataType::kMvdPoint: name = "MvdPoint"; break;
107  case ECbmDataType::kStsPoint: name = "StsPoint"; break;
108  case ECbmDataType::kRichPoint: name = "RichPoint"; break;
109  case ECbmDataType::kMuchPoint: name = "MuchPoint"; break;
110  case ECbmDataType::kTrdPoint: name = "TrdPoint"; break;
111  case ECbmDataType::kTofPoint: name = "TofPoint"; break;
112  case ECbmDataType::kPsdPoint: name = "PsdPoint"; break;
113  default: name = ""; break;
114  }
115 
116  return name;
117 }
118 // --------------------------------------------------------------------------
119 
120 
121 // ----- Event selector -------------------------------------------------
123 
124  LOG(INFO) << GetName() << ": " << Statistics();
125  Bool_t check = kTRUE;
126  for (auto cut : fMinNofData) {
127  if (GetNofData(cut.first) < cut.second) {
128  LOG(INFO) << GetName() << ": Cut on branch " << GetBranchName(cut.first)
129  << " not passed (number of data " << GetNofData(cut.first)
130  << ", required " << cut.second << ")";
131  check = kFALSE;
132  break;
133  }
134  }
135 
136  return check;
137 }
138 // --------------------------------------------------------------------------
139 
140 
141 // ----- Statistics info -------------------------------------------------
142 std::string CbmMCEventFilter::Statistics() const {
143 
144  std::stringstream ss;
145  ss << "MCTracks " << GetNofData(ECbmDataType::kMCTrack) << ", Points: ";
147  ss << "MVD " << GetNofData(ECbmDataType::kMvdPoint) << " ";
149  ss << "STS " << GetNofData(ECbmDataType::kStsPoint) << " ";
151  ss << "RICH " << GetNofData(ECbmDataType::kRichPoint) << " ";
153  ss << "MUCH " << GetNofData(ECbmDataType::kMuchPoint) << " ";
155  ss << "TRD " << GetNofData(ECbmDataType::kTrdPoint) << " ";
157  ss << "TOF " << GetNofData(ECbmDataType::kTofPoint) << " ";
159  ss << "PSD " << GetNofData(ECbmDataType::kPsdPoint) << " ";
160 
161  return ss.str();
162 }
163 // --------------------------------------------------------------------------
164 
165 
CbmMCEventFilter
Class deciding whether to store an MC event.
Definition: CbmMCEventFilter.h:34
CbmMCEventFilter::Init
virtual InitStatus Init()
Initialisation.
Definition: CbmMCEventFilter.cxx:67
ECbmDataType::kMvdPoint
@ kMvdPoint
CbmMCEventFilter::GetBranch
void GetBranch(ECbmDataType type)
Get a branch from FairRootManager.
Definition: CbmMCEventFilter.cxx:84
ECbmDataType::kTofPoint
@ kTofPoint
CbmMCEventFilter::GetNofData
Int_t GetNofData(ECbmDataType type) const
Number of data in a branch.
Definition: CbmMCEventFilter.h:75
CbmMCEventFilter::fNofEventsOut
Int_t fNofEventsOut
Counter: output events.
Definition: CbmMCEventFilter.h:91
CbmMCEventFilter::CbmMCEventFilter
CbmMCEventFilter()
Definition: CbmMCEventFilter.cxx:18
ECbmDataType::kMCTrack
@ kMCTrack
CbmMCEventFilter::GetData
TObject * GetData(ECbmDataType type, Int_t index) const
Get a data object by index.
Definition: CbmMCEventFilter.cxx:28
ECbmDataType::kPsdPoint
@ kPsdPoint
ECbmDataType::kTrdPoint
@ kTrdPoint
CbmMCEventFilter::GetBranchName
TString GetBranchName(ECbmDataType type) const
Get branch name from data type.
Definition: CbmMCEventFilter.cxx:101
ECbmDataType
ECbmDataType
Definition: CbmDefs.h:76
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMCEventFilter::Exec
virtual void Exec(Option_t *)
Execution.
Definition: CbmMCEventFilter.cxx:36
CbmMCEventFilter::SelectEvent
Bool_t SelectEvent() const
Event selector method.
Definition: CbmMCEventFilter.cxx:122
CbmMCEventFilter::Statistics
std::string Statistics() const
Info on number of MC objects in the arrays.
Definition: CbmMCEventFilter.cxx:142
CbmMCEventFilter.h
CbmMCEventFilter::Finish
virtual void Finish()
Finish (end of run)
Definition: CbmMCEventFilter.cxx:54
CbmMCEventFilter::fData
std::map< ECbmDataType, TClonesArray * > fData
Definition: CbmMCEventFilter.h:87
ECbmDataType::kMuchPoint
@ kMuchPoint
ECbmDataType::kRichPoint
@ kRichPoint
CbmMCEventFilter::fNofEventsIn
Int_t fNofEventsIn
Counter: input events.
Definition: CbmMCEventFilter.h:90
CbmMCEventFilter::fMinNofData
std::map< ECbmDataType, Int_t > fMinNofData
Data arrays.
Definition: CbmMCEventFilter.h:89
ECbmDataType::kStsPoint
@ kStsPoint