diff --git a/AtData/AtDataLinkDef.h b/AtData/AtDataLinkDef.h index b1cc7f9da..e272dfd40 100644 --- a/AtData/AtDataLinkDef.h +++ b/AtData/AtDataLinkDef.h @@ -31,6 +31,7 @@ #pragma link C++ class AtFittedTrack + ; #pragma link C++ class AtFissionEvent + ; #pragma link C++ class AtGenericTrace + ; +#pragma link C++ class AtICEvent + ; #pragma link C++ class AtPatterns::AtPattern + ; #pragma link C++ class AtPatterns::AtPatternLine + ; diff --git a/AtData/AtICEvent.cxx b/AtData/AtICEvent.cxx new file mode 100644 index 000000000..5e593667b --- /dev/null +++ b/AtData/AtICEvent.cxx @@ -0,0 +1,17 @@ +#include "AtICEvent.h" + +ClassImp(AtICEvent) + + AtICEvent::AtICEvent() + : AtBaseEvent("AtICEvent") +{ +} + +void AtICEvent::Clear(Option_t *opt) +{ + AtBaseEvent::Clear(opt); + + fRawADC = -1.; + fADC = -1.; + fIsPedestalSubtracted = kFALSE; +} diff --git a/AtData/AtICEvent.h b/AtData/AtICEvent.h new file mode 100644 index 000000000..34c8169b3 --- /dev/null +++ b/AtData/AtICEvent.h @@ -0,0 +1,41 @@ +#ifndef AtICEVENT_H +#define AtICEVENT_H + +#include "AtBaseEvent.h" + +#include + +#include +#include +#include +#include +class TBuffer; +class TClass; +class TMemberInspector; + +class AtICEvent : public AtBaseEvent { +private: + Double_t fRawADC = -1.; + Double_t fADC = -1.; + Bool_t fIsPedestalSubtracted = kFALSE; + +public: + AtICEvent(); + AtICEvent(const AtICEvent &) = default; + AtICEvent &operator=(const AtICEvent &) = default; + virtual ~AtICEvent() = default; + + void Clear(Option_t *opt = nullptr) override; + + void SetRawADC(Double_t value) { fRawADC = value; } + void SetADC(Double_t value) { fADC = value; } + void SetPedestalSubtracted(Bool_t val = kTRUE) { fIsPedestalSubtracted = val; } + + Double_t GetRawADC() const { return fRawADC; } + Double_t GetADC() const { return fADC; } + Bool_t IsPedestalSubtracted() const { return fIsPedestalSubtracted; } + + ClassDefOverride(AtICEvent, 1); +}; + +#endif diff --git a/AtData/CMakeLists.txt b/AtData/CMakeLists.txt index 445cb359f..177bc9977 100644 --- a/AtData/CMakeLists.txt +++ b/AtData/CMakeLists.txt @@ -37,6 +37,7 @@ set(SRCS AtTrackingEvent.cxx AtPatternEvent.cxx AtGenericTrace.cxx + AtICEvent.cxx AtProtoQuadrant.cxx AtTrack.cxx diff --git a/AtReconstruction/AtICTask.cxx b/AtReconstruction/AtICTask.cxx new file mode 100644 index 000000000..6f17f9f57 --- /dev/null +++ b/AtReconstruction/AtICTask.cxx @@ -0,0 +1,111 @@ +#include "AtICTask.h" + +#include "AtAuxPad.h" +#include "AtICEvent.h" +#include "AtPad.h" +#include "AtRawEvent.h" + +#include +#include // for FairRootManager + +#include +#include // for TObject + +#include +#include +#include +#include +#include // for move + +constexpr auto cRED = "\033[1;31m"; +constexpr auto cYELLOW = "\033[1;33m"; +constexpr auto cNORMAL = "\033[0m"; +constexpr auto cGREEN = "\033[1;32m"; + +AtICTask::AtICTask() + : fInputBranchName("AtRawEvent"), fOutputBranchName("AtICEvent"), fICEventArray(TClonesArray("AtICEvent", 1)), + fIsPersistence(kFALSE) +{ +} + +void AtICTask::SetPersistence(Bool_t value) +{ + fIsPersistence = value; +} + +void AtICTask::SetInputBranch(TString branchName) +{ + fInputBranchName = branchName; +} + +void AtICTask::SetOutputBranch(TString branchName) +{ + fOutputBranchName = branchName; +} + +InitStatus AtICTask::Init() +{ + FairRootManager *ioMan = FairRootManager::Instance(); + if (ioMan == nullptr) { + LOG(error) << "Cannot find RootManager!"; + return kERROR; + } + + fRawEventArray = dynamic_cast(ioMan->GetObject(fInputBranchName)); + if (fRawEventArray == nullptr) { + LOG(error) << "Cannot find AtRawEvent array in branch " << fInputBranchName << "!"; + return kERROR; + } + + ioMan->Register(fOutputBranchName, "AtTPC", &fICEventArray, fIsPersistence); + + return kSUCCESS; +} + +void AtICTask::Exec(Option_t *opt) +{ + if (fRawEventArray->GetEntriesFast() == 0) { + LOG(debug) << "Skipping IC analysis because raw event array is empty"; + return; + } + + fICEventArray.Clear("C"); + + auto *rawEvent = dynamic_cast(fRawEventArray->At(0)); + if (!rawEvent || !rawEvent->IsGood()) + return; + + auto *ICEvent = dynamic_cast(fICEventArray.ConstructedAt(0)); + + if (!rawEvent->IsGood()) { + LOG(debug) << "Event " << rawEvent->GetEventID() << " is not good, skipping IC analysis"; + return; + } + + LOG(debug) << " --------------------> Staring IC analysis on event Number: " << rawEvent->GetEventID() << " with " + << rawEvent->GetNumPads() << " valid pads"; + + // Get the AtAuxPads that contain the IC data and get the trace integrals. + const auto &traces = rawEvent->GetGenTraces(); + int i_channel = -1; + for (auto &traceEntry : traces) { + i_channel++; + if (i_channel == 1) { + const auto &trace_rawADC = traceEntry->GetRawADC(); + auto maxIt = std::max_element(trace_rawADC.begin() + 20, trace_rawADC.end() - 12); + + ICEvent->SetRawADC(*maxIt); + + double baseline = std::accumulate(trace_rawADC.begin(), trace_rawADC.begin() + 20, 0.0) / 20.0; + if (baseline <= 0.) { + LOG(debug) << " ---> IC analysis : error baseline"; + return; + } + + ICEvent->SetPedestalSubtracted(kTRUE); + ICEvent->SetADC(*maxIt - baseline); + } + } + + LOG(debug) << "Finished running IC analysis"; +} diff --git a/AtReconstruction/AtICTask.h b/AtReconstruction/AtICTask.h new file mode 100644 index 000000000..2374796cd --- /dev/null +++ b/AtReconstruction/AtICTask.h @@ -0,0 +1,38 @@ +#ifndef AtICTASK_H +#define AtICTASK_H + +#include "AtPSA.h" + +#include + +#include // for THashConsistencyHolder, Bool_t, ClassDef, Opti... +#include +#include + +#include +class TBuffer; +class TClass; +class TMemberInspector; + +class AtICTask : public FairTask { +private: + TString fInputBranchName; + TString fOutputBranchName; + + TClonesArray *fRawEventArray{nullptr}; + TClonesArray fICEventArray; + + Bool_t fIsPersistence{false}; + +public: + AtICTask(); + ~AtICTask() = default; + + void SetPersistence(Bool_t value); + void SetInputBranch(TString branchName); + void SetOutputBranch(TString branchName); + virtual InitStatus Init(); + virtual void Exec(Option_t *opt); +}; + +#endif diff --git a/AtReconstruction/AtReconstructionLinkDef.h b/AtReconstruction/AtReconstructionLinkDef.h index 1526e0531..658c72c43 100755 --- a/AtReconstruction/AtReconstructionLinkDef.h +++ b/AtReconstruction/AtReconstructionLinkDef.h @@ -75,5 +75,6 @@ #pragma link C++ class AtCopyTreeTask + ; #pragma link C++ class AtLinkDAQTask + ; #pragma link C++ class AtCopyAuxTreeTask + ; +#pragma link C++ class AtICTask + ; #endif diff --git a/AtReconstruction/CMakeLists.txt b/AtReconstruction/CMakeLists.txt index a4bc5296b..7cb335ac8 100755 --- a/AtReconstruction/CMakeLists.txt +++ b/AtReconstruction/CMakeLists.txt @@ -78,6 +78,7 @@ set(SRCS AtHDF5WriteTask.cxx AtMacroTask.cxx AtCopyAuxTreeTask.cxx + AtICTask.cxx AtPatternRecognition/AtPRA.cxx AtPatternRecognition/AtSampleConsensus.cxx