/** @file CbmMCEventFilter.cxx ** @author Volker Friese ** @since 07.08.2019 **/ #include "CbmMCEventFilter.h" #include #include #include #include "FairLogger.h" using std::cout; using std::endl; // ----- Constructor ------------------------------------------------------- CbmMCEventFilter::CbmMCEventFilter() : FairTask("MCEventFilter"), fData(kPsdPoint, nullptr), fMinNofData(), fNofEventsIn(0), fNofEventsOut(0) { } // -------------------------------------------------------------------------- // ----- Get a data object by index ------------------------------------- TObject* CbmMCEventFilter::GetData(ECbmDataType type, Int_t index) const { if ( index < 0 || index >= GetNofData(type)) return nullptr; return fData[type]->UncheckedAt(index); } // -------------------------------------------------------------------------- // ----- Execution ------------------------------------------------------ void CbmMCEventFilter::Exec(Option_t*) { fNofEventsIn++; Bool_t test = SelectEvent(); if ( test ) { LOG(INFO) << GetName() << ": Current event " << fNofEventsIn << " selected for output"; fNofEventsOut++; } //? Event selected else LOG(INFO) << GetName() << ": Current event " << fNofEventsIn << " discarded for output"; FairMCApplication::Instance()->SetSaveCurrentEvent(test); } // -------------------------------------------------------------------------- // ----- End-of-run action ---------------------------------------------- void CbmMCEventFilter::Finish() { cout << endl; LOG(INFO) << GetName() << ": Number of input events " << fNofEventsIn; LOG(INFO) << GetName() << ": Number of output events " << fNofEventsOut << " = " << 100. * Double_t(fNofEventsOut) / Double_t(fNofEventsIn) << " %"; cout << endl; } // -------------------------------------------------------------------------- // ----- Initialisation ------------------------------------------------- InitStatus CbmMCEventFilter::Init() { GetBranch(kMCTrack); GetBranch(kMvdPoint); GetBranch(kStsPoint); GetBranch(kRichPoint); GetBranch(kMuchPoint); GetBranch(kTrdPoint); GetBranch(kTofPoint); GetBranch(kPsdPoint); return kSUCCESS; } // -------------------------------------------------------------------------- // ----- Get a branch of MC data from FairRootManager ------------------- void CbmMCEventFilter::GetBranch(ECbmDataType type) { FairRootManager* rm = FairRootManager::Instance(); assert(rm); TString branchName = GetBranchName(type); if ( ! branchName.IsNull() ) { if ( type >= fData.size() ) fData.resize(type + 1); fData.at(type) = dynamic_cast(rm->GetObject(branchName)); if ( fData.at(type) ) LOG(INFO) << GetName() << ": Add branch " << branchName; } } // -------------------------------------------------------------------------- // ----- Get branch name of data type ----------------------------------- TString CbmMCEventFilter::GetBranchName(ECbmDataType type) const { TString name = ""; switch (type) { case kMCTrack: name = "MCTrack"; break; case kMvdPoint: name = "MvdPoint"; break; case kStsPoint: name = "StsPoint"; break; case kRichPoint: name = "RichPoint"; break; case kMuchPoint: name = "MuchPoint"; break; case kTrdPoint: name = "TrdPoint"; break; case kTofPoint: name = "TofPoint"; break; case kPsdPoint: name = "PsdPoint"; break; default: name = ""; break; } return name; } // -------------------------------------------------------------------------- // ----- Event selector ------------------------------------------------- Bool_t CbmMCEventFilter::SelectEvent() const { LOG(INFO) << GetName() << ": " << Statistics(); Bool_t check = kTRUE; for (auto cut : fMinNofData) { if ( GetNofData(cut.first) < cut.second ) { LOG(INFO) << GetName() << ": Cut on branch " << GetBranchName(cut.first) << " not passed (number of data " << GetNofData(cut.first) << ", required " << cut.second << ")"; check = kFALSE; break; } } return check; } // -------------------------------------------------------------------------- // ----- Statistics info ------------------------------------------------- std::string CbmMCEventFilter::Statistics() const { std::stringstream ss; ss << "MCTracks " << GetNofData(kMCTrack) << ", Points: "; if ( fData[kMvdPoint] ) ss << "MVD " << GetNofData(kMvdPoint) << " "; if ( fData[kStsPoint] ) ss << "STS " << GetNofData(kStsPoint) << " "; if ( fData[kRichPoint] ) ss << "RICH " << GetNofData(kRichPoint) << " "; if ( fData[kMuchPoint] ) ss << "MUCH " << GetNofData(kMuchPoint) << " "; if ( fData[kTrdPoint] ) ss << "TRD " << GetNofData(kTrdPoint) << " "; if ( fData[kTofPoint] ) ss << "TOF " << GetNofData(kTofPoint) << " "; if ( fData[kPsdPoint] ) ss << "PSD " << GetNofData(kPsdPoint) << " "; return ss.str(); } // -------------------------------------------------------------------------- ClassImp(CbmMCEventFilter)