-
Notifications
You must be signed in to change notification settings - Fork 118
feat(analysis/offline):Added a filter for good events #1280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
e2e3218
29b7791
489f76d
f4b418b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,230 @@ | ||||||||||||||||||||||||||||||||||
| /****************************************************************************** | ||||||||||||||||||||||||||||||||||
| * Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH * | ||||||||||||||||||||||||||||||||||
| * Copyright (C) 2025 Members of R3B Collaboration * | ||||||||||||||||||||||||||||||||||
| * * | ||||||||||||||||||||||||||||||||||
| * This software is distributed under the terms of the * | ||||||||||||||||||||||||||||||||||
| * GNU General Public Licence (GPL) version 3, * | ||||||||||||||||||||||||||||||||||
| * copied verbatim in the file "LICENSE". * | ||||||||||||||||||||||||||||||||||
| * * | ||||||||||||||||||||||||||||||||||
| * In applying this license GSI does not waive the privileges and immunities * | ||||||||||||||||||||||||||||||||||
| * granted to it by virtue of its status as an Intergovernmental Organization * | ||||||||||||||||||||||||||||||||||
| * or submit itself to any jurisdiction. * | ||||||||||||||||||||||||||||||||||
| ******************************************************************************/ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| // ----- R3BEventFilter ----- | ||||||||||||||||||||||||||||||||||
| // ----- Created 05/10/25 by J.L. Rodriguez-Sanchez ----- | ||||||||||||||||||||||||||||||||||
| // ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||
| * This class selects which events should be stored in the ROOT file. | ||||||||||||||||||||||||||||||||||
| * It acts as a filter, deciding whether an event is kept or discarded. | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #include "FairRunOnline.h" | ||||||||||||||||||||||||||||||||||
| #include <FairLogger.h> | ||||||||||||||||||||||||||||||||||
| #include <FairRootManager.h> | ||||||||||||||||||||||||||||||||||
| #include <FairRunAna.h> | ||||||||||||||||||||||||||||||||||
| #include <FairRuntimeDb.h> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #include "R3BEventFilter.h" | ||||||||||||||||||||||||||||||||||
| #include "R3BEventHeader.h" | ||||||||||||||||||||||||||||||||||
| #include "R3BFrsData.h" | ||||||||||||||||||||||||||||||||||
| #include "R3BLogger.h" | ||||||||||||||||||||||||||||||||||
| #include "R3BTofdHitData.h" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #include <TClonesArray.h> | ||||||||||||||||||||||||||||||||||
| #include <TMath.h> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| R3BEventFilter::R3BEventFilter() | ||||||||||||||||||||||||||||||||||
| : R3BEventFilter("R3BEventFilter", 1) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| R3BEventFilter::R3BEventFilter(const TString& name, Int_t iVerbose) | ||||||||||||||||||||||||||||||||||
| : FairTask(name, iVerbose) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| void R3BEventFilter::SetParContainers() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| R3BLOG(info, ""); | ||||||||||||||||||||||||||||||||||
| // Reading IncomingIDPar from FairRuntimeDb | ||||||||||||||||||||||||||||||||||
| auto rtdb = FairRuntimeDb::instance(); | ||||||||||||||||||||||||||||||||||
| R3BLOG_IF(fatal, !rtdb, "FairRuntimeDb not found"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| void R3BEventFilter::SetParameter() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| //--- Parameter Containers --- | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| InitStatus R3BEventFilter::Init() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| R3BLOG(info, ""); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| auto mgr = FairRootManager::Instance(); | ||||||||||||||||||||||||||||||||||
| R3BLOG_IF(fatal, nullptr == mgr, "FairRootManager not found"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| fHeader = dynamic_cast<R3BEventHeader*>(mgr->GetObject("EventHeader.")); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| fTofdHit = dynamic_cast<TClonesArray*>(mgr->GetObject("TofdHit")); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| fFrsData = dynamic_cast<TClonesArray*>(mgr->GetObject("FrsData")); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (!fCutFrsId) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| auto tmp = std::make_unique<TCutG>("fCutFrsId", 5); | ||||||||||||||||||||||||||||||||||
| tmp->SetPoint(0, 0.5, 0.5); | ||||||||||||||||||||||||||||||||||
| tmp->SetPoint(1, 4., 0.5); | ||||||||||||||||||||||||||||||||||
| tmp->SetPoint(2, 4., 4.); | ||||||||||||||||||||||||||||||||||
| tmp->SetPoint(3, 0.5, 4.); | ||||||||||||||||||||||||||||||||||
| tmp->SetPoint(4, 0.5, 0.5); | ||||||||||||||||||||||||||||||||||
| fCutFrsId = std::move(tmp); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (fChargeLimits.empty()) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| R3BLOG(warn, "Charge limits not set."); | ||||||||||||||||||||||||||||||||||
| fUseTofd = false; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetParameter(); | ||||||||||||||||||||||||||||||||||
| return kSUCCESS; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| InitStatus R3BEventFilter::ReInit() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| SetParContainers(); | ||||||||||||||||||||||||||||||||||
| SetParameter(); | ||||||||||||||||||||||||||||||||||
| return kSUCCESS; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| inline bool CheckFireConditionsTwoPlanes(const std::vector<int>& v) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| bool planes13ok = false; | ||||||||||||||||||||||||||||||||||
| bool planes24ok = false; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ((v[0] == 1) && (v[2] == 1)) | ||||||||||||||||||||||||||||||||||
| planes13ok = true; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ((v[1] == 1) && (v[3] == 1)) | ||||||||||||||||||||||||||||||||||
| planes24ok = true; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (planes13ok || planes24ok) | ||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+118
to
+125
|
||||||||||||||||||||||||||||||||||
| if (planes13ok || planes24ok) | |
| return true; | |
| else | |
| return false; | |
| } | |
| inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v) | |
| { | |
| return planes13ok || planes24ok; | |
| } | |
| inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v) | |
| { | |
| inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v) | |
| { |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null pointer dereference. The fHeader pointer is used without null checking on line 141. If fHeader is nullptr, this will cause a crash. Add a null check for fHeader before accessing GetExpId().
| if (!fHeader) | |
| { | |
| R3BLOG(error, "R3BEventFilter: Event header not available, skipping event"); | |
| StoreEvent(false); | |
| return; | |
| } |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check after dynamic_cast. If the cast fails, frsdata will be nullptr and calling GetZ() or GetAq() on it will cause a crash. Add a null check after the dynamic_cast.
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "determinate" should be "determine".
| // Function to determinate the charge in terms of the limits | |
| // Function to determine the charge in terms of the limits |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda function isSelectedCharge accesses fChargeLimits[plane - 1] without validating that the index is within bounds. If plane is 0 or if fChargeLimits has fewer than 'plane' elements, this will cause undefined behavior. Add bounds checking before accessing the vector.
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check after dynamic_cast. If the cast fails, tofdhit will be nullptr and calling GetPlaneId() or GetChargeZ() on it will cause a crash. Add a null check after the dynamic_cast.
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential out-of-bounds access. The plane ID from GetPlaneId() is used to index into chargeSelected and fChargeLimits without validation. If plane is 0 or greater than 4, this will cause out-of-bounds access. Consider adding bounds checking to ensure plane is within the valid range (1-4) before using it as an array index.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /****************************************************************************** | ||
| * Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH * | ||
| * Copyright (C) 2025 Members of R3B Collaboration * | ||
| * * | ||
| * This software is distributed under the terms of the * | ||
| * GNU General Public Licence (GPL) version 3, * | ||
| * copied verbatim in the file "LICENSE". * | ||
| * * | ||
| * In applying this license GSI does not waive the privileges and immunities * | ||
| * granted to it by virtue of its status as an Intergovernmental Organization * | ||
| * or submit itself to any jurisdiction. * | ||
| ******************************************************************************/ | ||
|
|
||
| // ---------------------------------------------------------------- | ||
| // ----- R3BEventFilter ----- | ||
| // ----- Created 05/10/25 by J.L. Rodriguez-Sanchez ----- | ||
| // ---------------------------------------------------------------- | ||
|
|
||
| /* | ||
| * This class selects which events should be stored in the ROOT file. | ||
| * It acts as a filter, deciding whether an event is kept or discarded. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| // ROOT headers | ||
| #include <TCutG.h> | ||
| #include <TMath.h> | ||
| #include <TString.h> | ||
|
|
||
| // FAIR headers | ||
| #include <FairTask.h> | ||
|
|
||
| // R3B headers | ||
| #include "R3BEventHeader.h" | ||
| #include "R3BFrsData.h" | ||
|
|
||
| class TClonesArray; | ||
|
|
||
| class R3BEventFilter : public FairTask | ||
| { | ||
| public: | ||
| /** | ||
| * Default constructor. | ||
| * Creates an instance of the task with default parameters. | ||
| */ | ||
| R3BEventFilter(); | ||
|
|
||
| /** | ||
| * Standard constructor. | ||
| * Creates an instance of the task. | ||
| * @param name a name of the task. | ||
| * @param iVerbose a verbosity level. | ||
| */ | ||
| explicit R3BEventFilter(const TString& name, Int_t iVerbose = 1); | ||
|
|
||
| /** | ||
| * Destructor. | ||
| * Frees the memory used by the object. | ||
| */ | ||
| ~R3BEventFilter() = default; | ||
|
|
||
| /** | ||
| * Method for task initialization. | ||
| * This function is called by the framework before | ||
| * the event loop. | ||
| * @return Initialization status. kSUCCESS, kERROR or kFATAL. | ||
| */ | ||
| InitStatus Init() override; | ||
|
|
||
| InitStatus ReInit() override; | ||
| /** | ||
| * Method for event loop implementation. | ||
| * Is called by the framework every time a new event is read. | ||
| * @param option an execution option. | ||
| */ | ||
| void Exec(Option_t* option) override; | ||
|
|
||
| /** | ||
| * A method for finish of processing of an event. | ||
| * Is called by the framework for each event after executing | ||
| * the tasks. | ||
| */ | ||
| void FinishEvent() override; | ||
|
|
||
| void SetParContainers() override; | ||
|
|
||
| void SetTCutFrsId(const TCutG* cut) | ||
| { | ||
| if (cut) | ||
| { | ||
| fCutFrsId.reset(static_cast<TCutG*>(cut->Clone())); | ||
| fCutFrsId->SetName("fCutFrsId"); | ||
| } | ||
| else | ||
| { | ||
| fCutFrsId.reset(); | ||
| } | ||
| } | ||
| void SetChargeLimits(const std::vector<std::vector<double>>& vec) { fChargeLimits = vec; } | ||
| void SetTofd() { fUseTofd = true; } | ||
| void UseTwoPlanes() { fUseAllPlanes = false; } | ||
|
|
||
| private: | ||
| void SetParameter(); | ||
| void StoreEvent(bool valid = true); | ||
|
|
||
| R3BEventHeader* fHeader = nullptr; | ||
| TClonesArray* fTofdHit = nullptr; | ||
| TClonesArray* fFrsData = nullptr; | ||
|
|
||
| std::unique_ptr<TCutG> fCutFrsId; | ||
| std::vector<std::vector<double>> fChargeLimits; | ||
|
|
||
| bool fUseTofd = false; | ||
| bool fUseAllPlanes = true; | ||
|
|
||
| public: | ||
| ClassDefOverride(R3BEventFilter, 1); // NOLINT | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing bounds check. The function accesses v[0], v[1], v[2], and v[3] without verifying that the vector has at least 4 elements. Add a size check similar to CheckFireConditionsAllPlanes to prevent out-of-bounds access.