diff --git a/r3bbase/BaseLinkDef.h b/r3bbase/BaseLinkDef.h index c443d72e2..8f6215665 100644 --- a/r3bbase/BaseLinkDef.h +++ b/r3bbase/BaseLinkDef.h @@ -34,4 +34,5 @@ #pragma link C++ class R3BMSOffsetContFact+; #pragma link C++ class R3BMSOffsetPar+; #pragma link C++ class R3BMSOffsetFinder+; +#pragma link C++ class R3BTprevTnext+; #endif diff --git a/r3bbase/CMakeLists.txt b/r3bbase/CMakeLists.txt index 237326f84..a414bcceb 100644 --- a/r3bbase/CMakeLists.txt +++ b/r3bbase/CMakeLists.txt @@ -42,6 +42,7 @@ set(SRCS R3BTcutPar.cxx R3BTsplinePar.cxx R3BWhiterabbitPropagator.cxx + R3BTprevTnext.cxx ./pars/R3BMSOffsetPar.cxx ./pars/R3BMSOffsetContFact.cxx ./pars/R3BMSOffsetFinder.cxx) @@ -62,6 +63,7 @@ set(HEADERS R3BTcutPar.h R3BTsplinePar.h R3BWhiterabbitPropagator.h + R3BTprevTnext.h ./pars/R3BMSOffsetPar.h ./pars/R3BMSOffsetContFact.h ./pars/R3BMSOffsetFinder.h) diff --git a/r3bbase/R3BTprevTnext.cxx b/r3bbase/R3BTprevTnext.cxx new file mode 100644 index 000000000..6511cf258 --- /dev/null +++ b/r3bbase/R3BTprevTnext.cxx @@ -0,0 +1,157 @@ +/****************************************************************************** + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2019-2023 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. * + ******************************************************************************/ + +#include "R3BTprevTnext.h" +#include "FairLogger.h" +#include "FairRootManager.h" +#include "FairRunAna.h" +#include "FairRuntimeDb.h" +#include "R3BEventHeader.h" +#include "R3BMSOffsetPar.h" +#include "R3BSamplerMappedData.h" +#include "R3BShared.h" +#include "TClonesArray.h" +#include "TMath.h" +#include "TObjArray.h" +#include "TRandom.h" +#include +#include +constexpr auto CLOCK_PERIOD = 10; // ns +R3BTprevTnext::R3BTprevTnext() + : R3BTprevTnext("R3B Tprev/Tnext", 1) +{ +} + +R3BTprevTnext::R3BTprevTnext(const TString& name, Int_t iVerbose) + : FairTask(name, iVerbose) +{ +} + +InitStatus R3BTprevTnext::Init() +{ + + FairRootManager* rootManager = FairRootManager::Instance(); + if (rootManager == nullptr) + { + return kFATAL; + } + + FairRuntimeDb* rtdb = FairRuntimeDb::instance(); + if (rtdb == nullptr) + { + LOG(error) << "FairRuntimeDb not opened!"; + return kFATAL; + } + + fR3BEventHeader = dynamic_cast(rootManager->GetObject("EventHeader.")); + if (fR3BEventHeader == nullptr) + { + LOG(error) << "R3BTprevTnext::Init() EventHeader. not found"; + return kFATAL; + } + + fSamplerMapped = dynamic_cast(rootManager->GetObject("SamplerMapped")); + if (fSamplerMapped == nullptr) + { + return kFATAL; + } + + fSamplerMSMapped = dynamic_cast(rootManager->GetObject("SamplerMSMapped")); + if (fSamplerMSMapped == nullptr) + { + return kFATAL; + } + + fMSOffsetPar = dynamic_cast(rtdb->getContainer("MSOffsetPar")); + if (fMSOffsetPar == nullptr) + { + LOG(error) << "Could not find MSOffsetPar container!"; + return kFATAL; + } + + return kSUCCESS; +} + +void R3BTprevTnext::Exec(Option_t* /*opt*/) +{ + Double_t fTprev = -10.0; // Initialization with invalid values. + Double_t fTnext = -10.0; + Int_t dMScounter = 0; + const Int_t sampHits = fSamplerMapped->GetEntriesFast(); + const Int_t sampmsHits = fSamplerMSMapped->GetEntriesFast(); + const Double_t MSOffset = fMSOffsetPar->GetMSOffset(); + Double_t SAMPTime = 0; + Double_t SAMPMSTime = 0; + R3BSamplerMappedData* SAMPMapped = nullptr; + R3BSamplerMappedData* SAMPMSMapped = nullptr; + bool sawMS = false; + if (fR3BEventHeader->GetTpat() < fTpat && fR3BEventHeader->GetTrigger() == 1 && fR3BEventHeader->GetTpat() > 0) + { + if (sampmsHits == 1 && sampHits > 0) + { + SAMPMSMapped = dynamic_cast(fSamplerMSMapped->At(0)); + SAMPMSTime = SAMPMSMapped->GetTime(); + for (Int_t i = 0; i < sampHits; ++i) + { + SAMPMapped = dynamic_cast(fSamplerMapped->At(i)); + SAMPTime = SAMPMapped->GetTime(); + auto tpn = SAMPTime - SAMPMSTime - MSOffset; + if (tpn < -fDelta_clk) + { + fTprev = -CLOCK_PERIOD * tpn; + } + if (abs(tpn) <= 1) + { + sawMS = true; + ++dMScounter; + } + if (tpn > fDelta_clk) + { + fTnext = CLOCK_PERIOD * tpn; + break; + } + } + } + } + if (sawMS) + { + if (fTprev == -10.0) + { + fTprev = 43.1e9; // MS is the first hit + } + if (fTnext == -10.0) + { + fTnext = 43.1e9; // MS is the last hit + } + if (dMScounter > 1) + { + if (fTprev == 43.1e9) + { + fTprev = 0; // Tprev inside the fDelta_clk + } + if (fTnext == 43.1e9) + { + fTnext = 0; // Tnext inside the fDelta_clk + } + } + if (dMScounter == 1 && fTprev == 43.1e9 && fTnext == 43.1e9) + { + fTprev = -20.0; // Only one hit in the event + fTnext = -20.0; + } + } + fR3BEventHeader->SetTprev(fTprev); + fR3BEventHeader->SetTnext(fTnext); +} + +ClassImp(R3BTprevTnext) // NOLINT diff --git a/r3bbase/R3BTprevTnext.h b/r3bbase/R3BTprevTnext.h new file mode 100644 index 000000000..9a42d81bb --- /dev/null +++ b/r3bbase/R3BTprevTnext.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2019-2023 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. * + ******************************************************************************/ + +#pragma once + +#include "FairTask.h" +#include "R3BMSOffsetPar.h" + +constexpr Int_t Default_Tpat = 1024; +class TClonesArray; +class R3BMSOffsetPar; +class R3BEventHeader; +class R3BSamplerMappedData; +class R3BTprevTnext : public FairTask +{ + public: + /** Default constructor **/ + R3BTprevTnext(); + + /** Standard constructor **/ + explicit R3BTprevTnext(const TString& name, Int_t iVerbose = 1); + + /** Virtual method Init **/ + InitStatus Init() override; + + /** Virtual method Exec **/ + void Exec(Option_t* opt) override; + + void SetTpat(Int_t option) { fTpat = option; } + void SetDelta_clk(Double_t clock) { fDelta_clk = clock; } + + private: + R3BMSOffsetPar* fMSOffsetPar = nullptr; + TClonesArray* fSamplerMapped = nullptr; + TClonesArray* fSamplerMSMapped = nullptr; + R3BEventHeader* fR3BEventHeader = nullptr; /**< Event header - input data. */ + Int_t fTpat = Default_Tpat; + Double_t fDelta_clk = 1.0; + + ClassDefOverride(R3BTprevTnext, 1); // NOLINT +}; diff --git a/r3bbase/pars/R3BMSOffsetFinder.cxx b/r3bbase/pars/R3BMSOffsetFinder.cxx index 661abab8f..32daf004a 100644 --- a/r3bbase/pars/R3BMSOffsetFinder.cxx +++ b/r3bbase/pars/R3BMSOffsetFinder.cxx @@ -43,12 +43,6 @@ R3BMSOffsetFinder::R3BMSOffsetFinder() // R3BMSOffsetFinder: Standard Constructor -------------------------- R3BMSOffsetFinder::R3BMSOffsetFinder(const TString& name, Int_t iVerbose) : FairTask(name, iVerbose) - , fMSOffset(0.0) - , fMinStatistics(1) - , fMSOffsetPar(nullptr) - , fSamplerMapped(nullptr) - , fSamplerMSMapped(nullptr) - , fh_Offset_Finder(nullptr) { } diff --git a/r3bbase/pars/R3BMSOffsetFinder.h b/r3bbase/pars/R3BMSOffsetFinder.h index 4afec89a4..23445bdb2 100644 --- a/r3bbase/pars/R3BMSOffsetFinder.h +++ b/r3bbase/pars/R3BMSOffsetFinder.h @@ -69,16 +69,16 @@ class R3BMSOffsetFinder : public FairTask // NOLINT private: // Number of histograms, limits and bining - Double_t fMSOffset; + Double_t fMSOffset = 0.0; // Minimum statistics and parameters - Int_t fMinStatistics{}; + Int_t fMinStatistics = 1; - R3BMSOffsetPar* fMSOffsetPar; /**< Parameter container. >*/ - TClonesArray* fSamplerMapped; /**< Array with SAMP Mapped input data. >*/ - TClonesArray* fSamplerMSMapped; /**< Array with SAMPMS MApped input data. >*/ + R3BMSOffsetPar* fMSOffsetPar = nullptr; /**< Parameter container. >*/ + TClonesArray* fSamplerMapped = nullptr; /**< Array with SAMP Mapped input data. >*/ + TClonesArray* fSamplerMSMapped = nullptr; /**< Array with SAMPMS MApped input data. >*/ - TH1F* fh_Offset_Finder; + TH1F* fh_Offset_Finder = nullptr; public: ClassDefOverride(R3BMSOffsetFinder, 1); // NOLINT