Skip to content

Commit

Permalink
Implementation of Parameter finder for Tprev/Tnext calculation
Browse files Browse the repository at this point in the history
Update of MSOffset classes
  • Loading branch information
leandrofloyd committed Sep 7, 2023
1 parent b0f85c9 commit cb819cb
Show file tree
Hide file tree
Showing 11 changed files with 551 additions and 34 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Labiche, Marc
Lagni, Andrea
Lihtar, Ivana
Loeher, Bastian
Milhomens da Fonseca, Leandro
Mozumdar, Nikhil
Panin, Valerii
Plag, Ralf
Expand Down
4 changes: 3 additions & 1 deletion r3bbase/BaseLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
#pragma link C++ class R3BTcutPar+;
#pragma link C++ class R3BTsplinePar+;
#pragma link C++ class R3BCoarseTimeStitch+;

#pragma link C++ class R3BMSOffsetContFact+;
#pragma link C++ class R3BMSOffsetPar+;
#pragma link C++ class R3BMSOffsetFinder+;
#endif
24 changes: 19 additions & 5 deletions r3bbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

set(SYSTEM_INCLUDE_DIRECTORIES ${SYSTEM_INCLUDE_DIRECTORIES} ${BASE_INCLUDE_DIRECTORIES})

set(INCLUDE_DIRECTORIES #put here all directories where header files are located
${R3BROOT_SOURCE_DIR}/r3bbase ${R3BROOT_SOURCE_DIR}/tcal ${R3BROOT_SOURCE_DIR}/r3bdata
${R3BROOT_SOURCE_DIR}/r3bdata/wrData ${Boost_INCLUDE_DIRS})
set(INCLUDE_DIRECTORIES
#put here all directories where header files are located
${R3BROOT_SOURCE_DIR}/r3bbase
${R3BROOT_SOURCE_DIR}/tcal
${R3BROOT_SOURCE_DIR}/r3bdata
${R3BROOT_SOURCE_DIR}/r3bdata/sampData
${R3BROOT_SOURCE_DIR}/r3bdata/wrData
${R3BROOT_SOURCE_DIR}/r3bbase/pars
)

include_directories(${INCLUDE_DIRECTORIES})
include_directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
Expand All @@ -39,7 +45,11 @@ set(SRCS
R3BModule.cxx
R3BTcutPar.cxx
R3BTsplinePar.cxx
R3BWhiterabbitPropagator.cxx)
R3BWhiterabbitPropagator.cxx
./pars/R3BMSOffsetPar.cxx
./pars/R3BMSOffsetContFact.cxx
./pars/R3BMSOffsetFinder.cxx
)

set(HEADERS
R3BCoarseTimeStitch.h
Expand All @@ -55,7 +65,11 @@ set(HEADERS
R3BShared.h
R3BTcutPar.h
R3BTsplinePar.h
R3BWhiterabbitPropagator.h)
R3BWhiterabbitPropagator.h
./pars/R3BMSOffsetPar.h
./pars/R3BMSOffsetContFact.h
./pars/R3BMSOffsetFinder.h
)

set(LINKDEF BaseLinkDef.h)

Expand Down
73 changes: 73 additions & 0 deletions r3bbase/pars/R3BMSOffsetContFact.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/******************************************************************************
* 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. *
******************************************************************************/

//
// R3BMSOffsetContFact
//
// Factory for the parameter containers in libR3BMSOffset
//

#include "R3BMSOffsetContFact.h"
#include "R3BMSOffsetPar.h"

#include "FairParAsciiFileIo.h"
#include "FairParRootFileIo.h"
#include "FairRuntimeDb.h"

#include "R3BLogger.h"

#include "TClass.h"

static const R3BMSOffsetContFact gR3BMSOffsetContFact;

R3BMSOffsetContFact::R3BMSOffsetContFact()
{
// Constructor (called when the library is loaded)
fName = "R3BMSOffsetContFact";
fTitle = "Factory for parameter containers in libR3BMSOffset";
setAllContainers();
FairRuntimeDb::instance()->addContFactory(this);
}

void R3BMSOffsetContFact::setAllContainers()
{
// Creates the Container objects with all accepted contexts and adds them to
// the list of containers for the STS library.

auto pOffset = std::make_unique<FairContainer>("MSOffsetPar", "MSOffsetPar Offset Parameters", "MSOffsetPar");
pOffset->addContext("MSOffsetPar");

containers->Add(pOffset.release());
}

FairParSet* R3BMSOffsetContFact::createContainer(FairContainer* cOffset)
{
// Trals the constructor of the corresponding parameter container.
// For an actual context, which is not an empty string and not the default context
// of this container, the name is concatinated with the context.

// const char* name = cOffset->GetName();
// R3BLOG(info, name);
// FairParSet* pOff = nullptr;
// if (strcmp(name, "MSOffsetPar") == 0)
const auto name = std::string_view{cOffset->GetName()};
R3BLOG(info, name);
FairParSet* pOff = nullptr;
if (name == "MSOffsetPar")
{
pOff = new R3BMSOffsetPar(cOffset->getConcatName().Data(), cOffset->GetTitle(), cOffset->getContext());
}
return pOff;
}

ClassImp(R3BMSOffsetContFact);
33 changes: 33 additions & 0 deletions r3bbase/pars/R3BMSOffsetContFact.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************
* 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 "FairContFact.h"

class FairContainer;

class R3BMSOffsetContFact : public FairContFact
{
private:
void setAllContainers();

public:
R3BMSOffsetContFact();
R3BMSOffsetContFact(const R3BMSOffsetContFact&) = delete;
R3BMSOffsetContFact(R3BMSOffsetContFact&&) = delete;
R3BMSOffsetContFact& operator=(const R3BMSOffsetContFact&) = delete;
R3BMSOffsetContFact& operator=(R3BMSOffsetContFact&&) = delete;
~R3BMSOffsetContFact() override = default;
FairParSet* createContainer(FairContainer* /*unused*/) override;
ClassDefOverride(R3BMSOffsetContFact, 0) // Factory for all MSOffset parameter containers
};
168 changes: 168 additions & 0 deletions r3bbase/pars/R3BMSOffsetFinder.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/******************************************************************************
* 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. *
******************************************************************************/

// ROOT headers
#include "R3BSamplerMappedData.h"
#include "R3BShared.h"
#include "TClonesArray.h"
#include "TF1.h"
#include "TH1F.h"
#include "TMath.h"
#include "TObjArray.h"
#include "TRandom.h"
#include "TVector3.h"
#include <cstdlib>
#include <iostream>
// Fair headers
#include "FairLogger.h"
#include "FairRootManager.h"
#include "FairRunAna.h"
#include "FairRuntimeDb.h"

// R3B headers
#include "R3BEventHeader.h"
#include "R3BMSOffsetFinder.h"
#include "R3BMSOffsetPar.h"

// R3BMSOffsetFinder: Default Constructor --------------------------
R3BMSOffsetFinder::R3BMSOffsetFinder()
: R3BMSOffsetFinder("R3B MS Offset Finder", 1)
{
}

// 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)
{
}

void R3BMSOffsetFinder::SetParContainers()
{
// Parameter Container
if (auto* rtdb = FairRuntimeDb::instance(); rtdb == nullptr)
{
LOG(error) << "FairRuntimeDb not opened!";
}
}

// ----- Public method Init --------------------------------------------
InitStatus R3BMSOffsetFinder::Init()
{

LOG(info) << "R3BMSOffsetFinder: Init";

FairRootManager* rootManager = FairRootManager::Instance();
if (rootManager == nullptr)
{
return kFATAL;
}

fSamplerMapped = dynamic_cast<TClonesArray*>(rootManager->GetObject("SamplerMapped"));
if (fSamplerMapped == nullptr)
{
return kFATAL;
}

fSamplerMSMapped = dynamic_cast<TClonesArray*>(rootManager->GetObject("SamplerMSMapped"));
if (fSamplerMSMapped == nullptr)
{
return kFATAL;
}

FairRuntimeDb* rtdb = FairRuntimeDb::instance();
if (rtdb == nullptr)
{
return kFATAL;
}

fMSOffsetPar = dynamic_cast<R3BMSOffsetPar*>(rtdb->getContainer("MSOffsetPar"));
if (fMSOffsetPar == nullptr)
{
LOG(error) << "R3BMSOffsetFinder::Init() Couldn't get handle on MSOffsetPar container";
return kFATAL;
}

fh_Offset_Finder = R3B::root_owned<TH1F>("MSOffsetFinderHisto", "MSOffsetFinderHisto", 2000.0, -1000.0, 1000.0);

return kSUCCESS;
}

// ----- Public method ReInit --------------------------------------------
InitStatus R3BMSOffsetFinder::ReInit()
{
SetParContainers();
return kSUCCESS;
}

// ----- Public method Exec --------------------------------------------
void R3BMSOffsetFinder::Exec(Option_t* /*opt*/)
{

const Int_t sampHits = fSamplerMapped->GetEntriesFast();
const Int_t sampmsHits = fSamplerMSMapped->GetEntriesFast();
if ((sampHits == 0) || (sampmsHits != 1))
{
return;
}
Double_t SAMPTime = 0;
R3BSamplerMappedData* SAMPMapped = nullptr;

R3BSamplerMappedData* SAMPMSMapped = dynamic_cast<R3BSamplerMappedData*>(fSamplerMSMapped->At(0));

Check warning on line 126 in r3bbase/pars/R3BMSOffsetFinder.cxx

View workflow job for this annotation

GitHub Actions / clang-tidy

use auto when initializing with a cast to avoid duplicating the type name [hicpp-use-auto,modernize-use-auto]
auto SAMPMSTime = SAMPMSMapped->GetTime();

for (Int_t i = 0; i < sampHits; i++)
{
SAMPMapped = dynamic_cast<R3BSamplerMappedData*>(fSamplerMapped->At(i));
SAMPTime = SAMPMapped->GetTime();

// Fill the histogram
fh_Offset_Finder->Fill(SAMPTime - SAMPMSTime);
}
}

// ---- Public method Reset --------------------------------------------------
void R3BMSOffsetFinder::Reset() {}

void R3BMSOffsetFinder::FinishEvent() {}

// ---- Public method Finish --------------------------------------------------
void R3BMSOffsetFinder::FinishTask() { SearchMSOffset(); }

//------------------

void R3BMSOffsetFinder::SearchMSOffset()
{

LOG(info) << "R3BMSOffsetFinder: Search MS Offset";
if (fh_Offset_Finder->GetEntries() >= fMinStatistics)
{
auto MSpos = fh_Offset_Finder->GetMaximumBin();
auto offset =
(fh_Offset_Finder->GetBinCenter(MSpos)) -
0.5; // The bin is unitary, so the Bin Center will always be X.5 (the center of a unitary bin). To fix that
// the -0.5 is added to the equation. The time here is in clock cycles, so thi -0.5 corrects that.
fMSOffsetPar->SetMSOffset(offset);
}

// Fill container:

fMSOffsetPar->setChanged();
}

ClassImp(R3BMSOffsetFinder)
Loading

0 comments on commit cb819cb

Please sign in to comment.