Skip to content
Snippets Groups Projects
Commit 858a22a8 authored by Volker Friese's avatar Volker Friese
Browse files

Modified CbmBuildEventsIdeal to handle multiple MC inputs.

parent ce91d7fa
No related branches found
No related tags found
1 merge request!163Modified CbmBuildEventsIdeal to handle multiple MC inputs.
...@@ -32,53 +32,89 @@ CbmBuildEventsIdeal::~CbmBuildEventsIdeal() {} ...@@ -32,53 +32,89 @@ CbmBuildEventsIdeal::~CbmBuildEventsIdeal() {}
// =========================================================================== // ===========================================================================
// ===== Number if different pairs (input,event) in a match object =======
UInt_t CbmBuildEventsIdeal::EventsInMatch(const CbmMatch* match) {
// --- No or empty match object
if (match == nullptr) return 0;
if (!match->GetNofLinks()) return 0;
// --- Only one link
if (match->GetNofLinks() == 1) return 1;
// --- More than one link: check whether they are from different events
CbmMatch testMatch;
for (Int_t iLink = 0; iLink < match->GetNofLinks(); iLink++) {
Int_t input = match->GetLink(iLink).GetFile();
Int_t event = match->GetLink(iLink).GetEntry();
testMatch.AddLink(1., 0, event, input);
}
return testMatch.GetNofLinks();
}
// ===========================================================================
// ===== Task execution ================================================== // ===== Task execution ==================================================
void CbmBuildEventsIdeal::Exec(Option_t*) { void CbmBuildEventsIdeal::Exec(Option_t*) {
// --- Timer and counters
TStopwatch timer; TStopwatch timer;
timer.Start(); timer.Start();
std::map<Int_t, CbmEvent*> eventMap; Int_t nEvents = 0; // Number of created events
Int_t nEvents = 0; UInt_t nDigisTot = 0; // Total number of digis
UInt_t nDigisTot = 0; UInt_t nDigisNoise = 0; // Digis without link to MC event
UInt_t nDigisNoise = 0; UInt_t nDigisAmbig = 0; // Digis with links to multiple MC events
// Clear output array // --- Clear output array
fEvents->Delete(); fEvents->Delete();
// --- Bookkeeping: Map from (input number, event number) to event
map<pair<Int_t, Int_t>, CbmEvent*> eventMap;
// --- Loop over all detector systems
for (ECbmModuleId& system : fSystems) { for (ECbmModuleId& system : fSystems) {
// --- Skip system if no data branch or no match match present
if (!fDigiMan->IsPresent(system)) continue; if (!fDigiMan->IsPresent(system)) continue;
if (!fDigiMan->IsMatchPresent(system)) continue; if (!fDigiMan->IsMatchPresent(system)) continue;
// --- Loop over digis for the current system
Int_t nDigis = fDigiMan->GetNofDigis(system); Int_t nDigis = fDigiMan->GetNofDigis(system);
UInt_t nNoise = 0; UInt_t nNoise = 0;
LOG(info) << GetName() << ": System " UInt_t nAmbig = 0;
<< CbmModuleList::GetModuleNameCaps(system) << ", digis "
<< nDigis;
for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) { for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
// --- Get the MC input and event number through the match object
const CbmMatch* match = fDigiMan->GetMatch(system, iDigi); const CbmMatch* match = fDigiMan->GetMatch(system, iDigi);
assert(match); assert(match);
Int_t mcInput = -1;
Int_t mcEvent = -1;
if (match->GetNofLinks()) {
mcInput = match->GetMatchedLink().GetFile();
mcEvent = match->GetMatchedLink().GetEntry();
}
// This implementation uses only MC event number from // --- Empty match objects or negative event numbers signal noise
// the matched link, i.e. that with the largest weight. if (mcInput < 0 || mcEvent < 0) {
// Can be refined later on.
Int_t mcEventNr = match->GetMatchedLink().GetEntry();
// Ignore digis with missing event number (noise)
if (mcEventNr < 0) {
nNoise++; nNoise++;
continue; continue;
} }
// Get event pointer. If event is not yet present, create it. // --- Count occurrences of multiple MC events in match
CbmEvent* event = NULL; if (EventsInMatch(match) > 1) nAmbig++;
if (eventMap.find(mcEventNr) == eventMap.end()) {
event = new ((*fEvents)[nEvents]) CbmEvent(nEvents); // --- Get event pointer. If event is not yet present, create it.
eventMap[mcEventNr] = event; CbmEvent* event = nullptr;
auto it = eventMap.find(make_pair(mcInput, mcEvent));
if (it == eventMap.end()) {
assert(nEvents == fEvents->GetEntriesFast());
event = new ((*fEvents)[nEvents]) CbmEvent(nEvents);
eventMap[make_pair(mcInput, mcEvent)] = event;
nEvents++; nEvents++;
} else } else
event = eventMap.at(mcEventNr); event = it->second;
// Fill digi index into event // --- Fill digi index into event
switch (system) { switch (system) {
case ECbmModuleId::kMvd: case ECbmModuleId::kMvd:
event->AddData(ECbmDataType::kMvdDigi, iDigi); event->AddData(ECbmDataType::kMvdDigi, iDigi);
...@@ -105,25 +141,25 @@ void CbmBuildEventsIdeal::Exec(Option_t*) { ...@@ -105,25 +141,25 @@ void CbmBuildEventsIdeal::Exec(Option_t*) {
} //? detector } //? detector
} //# digis } //# digis
LOG(debug) << GetName() << ": Detector " LOG(info) << GetName() << ": Detector "
<< CbmModuleList::GetModuleNameCaps(system) << ", digis " << CbmModuleList::GetModuleNameCaps(system) << ", digis "
<< nDigis << ", noise " << nNoise; << nDigis << " (" << nAmbig << " ambiguous), noise " << nNoise;
nDigisTot += nDigis; nDigisTot += nDigis;
nDigisAmbig += nAmbig;
nDigisNoise += nNoise; nDigisNoise += nNoise;
} //# detectors } //# detector systems
timer.Stop(); timer.Stop();
assert(nEvents == fEvents->GetEntriesFast()); assert(nEvents == fEvents->GetEntriesFast());
// --- Execution log // --- Execution log
std::cout << std::endl; std::cout << std::endl;
LOG(info) << "+ " << setw(15) << GetName() << ": Time-slice " << setw(3) Double_t execTime = 1000. * timer.RealTime();
<< right << fNofEntries << ", events: " << setw(6) << nEvents LOG(info) << setw(20) << left << GetName() << "[" << fixed << setprecision(4)
<< ", digis: " << nDigisTot << ", noise: " << nDigisNoise << execTime << " ms] : TSlice " << right << fNofEntries
<< ". Exec time " << fixed << setprecision(6) << timer.RealTime() << ", events: " << nEvents << ", digis: " << nDigisTot << " ("
<< " s."; << nDigisAmbig << " ambiguous), noise: " << nDigisNoise;
// --- For debug: event info // --- For debug: event info
if (gLogger->IsLogNeeded(fair::Severity::debug)) { if (gLogger->IsLogNeeded(fair::Severity::debug)) {
......
/** @file CbmBuildEventsIdeal.h /** @file CbmBuildEventsIdeal.h
** @author Volker Friese <v.friese@gsi.de> ** @author Volker Friese <v.friese@gsi.de>
** @date 17.09.2016 ** @since 17.09.2016
** @date 15.^^.1010
**/ **/
#ifndef CBMBUILDEVENTSIDEAL_H_
#ifndef CBMBUILDEVENTSIDEAL_H
#define CBMBUILDEVENTSIDEAL_H 1 #define CBMBUILDEVENTSIDEAL_H 1
...@@ -12,41 +14,57 @@ ...@@ -12,41 +14,57 @@
class TClonesArray; class TClonesArray;
class CbmDigiManager; class CbmDigiManager;
class CbmMatch;
/** @class CbmStsBuildEventsIdeal /** @class CbmStsBuildEventsIdeal
** @brief Task class for associating digis to events ** @brief Task class for associating digis to events
** @author Volker Friese <v.friese@gsi.de> ** @author Volker Friese <v.friese@gsi.de>
** @since 17.09.2016 ** @since 17.09.2016
** @version 1.0 ** @date 15.11.2020
**
** The digi event builder creates objects of class CbmEvent and fills them
** with digi objects. For the association of the digis to the events, the
** MC-truth information in the digi match objects is employed. A digi
** is attributed to the event of its link with the largest weight.
** **
** The event association uses MC truth (CbmMatch of CbmDigi). ** The event builder operates within one time slice; splitting of events
** It operates within one time slice; splitting of events between ** between time slices is not treated.
** time slice is not treated.
**/ **/
class CbmBuildEventsIdeal : public FairTask { class CbmBuildEventsIdeal : public FairTask {
public: public:
/** Constructor **/ /** @brief Constructor **/
CbmBuildEventsIdeal(); CbmBuildEventsIdeal();
/** Destructor **/ /** @brief Copy constructor (disabled) **/
CbmBuildEventsIdeal(const CbmBuildEventsIdeal&) = delete;
/** @brief Destructor **/
virtual ~CbmBuildEventsIdeal(); virtual ~CbmBuildEventsIdeal();
/** Task execution **/ /** @brief Task execution **/
virtual void Exec(Option_t* opt); virtual void Exec(Option_t* opt);
/** @brief Assignment operator (disabled) **/
CbmBuildEventsIdeal& operator=(const CbmBuildEventsIdeal&) = delete;
private:
CbmDigiManager* fDigiMan = nullptr; //!
std::vector<ECbmModuleId> fSystems {};
TClonesArray* fEvents = nullptr; //! Output array (class CbmEvent)
Int_t fNofEntries = 0; // Number of processed time slices
/** Task initialisation **/ private: // methods
/** @brief Task initialisation **/
virtual InitStatus Init(); virtual InitStatus Init();
CbmBuildEventsIdeal(const CbmBuildEventsIdeal&) = delete;
CbmBuildEventsIdeal& operator=(const CbmBuildEventsIdeal&) = delete; /** @brief Number of different MC events in a match object **/
UInt_t EventsInMatch(const CbmMatch* match);
private: // members
CbmDigiManager* fDigiMan = nullptr; //!
std::vector<ECbmModuleId> fSystems {}; // List of detector systems
TClonesArray* fEvents = nullptr; //! Output array (class CbmEvent)
Int_t fNofEntries = 0; // Number of processed time slices
ClassDef(CbmBuildEventsIdeal, 3); ClassDef(CbmBuildEventsIdeal, 3);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment