Skip to content

Commit ec2433c

Browse files
committed
Implementation of the Tprev/Tnext task.
1 parent 92eef56 commit ec2433c

File tree

6 files changed

+217
-12
lines changed

6 files changed

+217
-12
lines changed

r3bbase/BaseLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
#pragma link C++ class R3BMSOffsetContFact+;
3535
#pragma link C++ class R3BMSOffsetPar+;
3636
#pragma link C++ class R3BMSOffsetFinder+;
37+
#pragma link C++ class R3BTprevTnext+;
3738
#endif

r3bbase/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(SRCS
4646
R3BTcutPar.cxx
4747
R3BTsplinePar.cxx
4848
R3BWhiterabbitPropagator.cxx
49+
R3BTprevTnext.cxx
4950
./pars/R3BMSOffsetPar.cxx
5051
./pars/R3BMSOffsetContFact.cxx
5152
./pars/R3BMSOffsetFinder.cxx
@@ -66,6 +67,7 @@ set(HEADERS
6667
R3BTcutPar.h
6768
R3BTsplinePar.h
6869
R3BWhiterabbitPropagator.h
70+
R3BTprevTnext.h
6971
./pars/R3BMSOffsetPar.h
7072
./pars/R3BMSOffsetContFact.h
7173
./pars/R3BMSOffsetFinder.h

r3bbase/R3BTprevTnext.cxx

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/******************************************************************************
2+
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2019-2023 Members of R3B Collaboration *
4+
* *
5+
* This software is distributed under the terms of the *
6+
* GNU General Public Licence (GPL) version 3, *
7+
* copied verbatim in the file "LICENSE". *
8+
* *
9+
* In applying this license GSI does not waive the privileges and immunities *
10+
* granted to it by virtue of its status as an Intergovernmental Organization *
11+
* or submit itself to any jurisdiction. *
12+
******************************************************************************/
13+
14+
#include "R3BTprevTnext.h"
15+
#include "FairLogger.h"
16+
#include "FairRootManager.h"
17+
#include "FairRunAna.h"
18+
#include "FairRuntimeDb.h"
19+
#include "R3BEventHeader.h"
20+
#include "R3BMSOffsetPar.h"
21+
#include "R3BSamplerMappedData.h"
22+
#include "R3BShared.h"
23+
#include "TClonesArray.h"
24+
#include "TMath.h"
25+
#include "TObjArray.h"
26+
#include "TRandom.h"
27+
#include <cstdlib>
28+
#include <iostream>
29+
constexpr auto clock_period = 10; // ns
30+
R3BTprevTnext::R3BTprevTnext()
31+
: R3BTprevTnext("R3B Tprev/Tnext", 1)
32+
{
33+
}
34+
35+
R3BTprevTnext::R3BTprevTnext(const TString& name, Int_t iVerbose)
36+
: FairTask(name, iVerbose)
37+
{
38+
}
39+
40+
InitStatus R3BTprevTnext::Init()
41+
{
42+
43+
FairRootManager* rootManager = FairRootManager::Instance();
44+
if (rootManager == nullptr)
45+
{
46+
return kFATAL;
47+
}
48+
49+
FairRuntimeDb* rtdb = FairRuntimeDb::instance();
50+
if (rtdb == nullptr)
51+
{
52+
LOG(error) << "FairRuntimeDb not opened!";
53+
return kFATAL;
54+
}
55+
56+
fR3BEventHeader = dynamic_cast<R3BEventHeader*>(rootManager->GetObject("EventHeader."));
57+
if (fR3BEventHeader == nullptr)
58+
{
59+
LOG(error) << "R3BTprevTnext::Init() EventHeader. not found";
60+
return kFATAL;
61+
}
62+
63+
fSamplerMapped = dynamic_cast<TClonesArray*>(rootManager->GetObject("SamplerMapped"));
64+
if (fSamplerMapped == nullptr)
65+
{
66+
return kFATAL;
67+
}
68+
69+
fSamplerMSMapped = dynamic_cast<TClonesArray*>(rootManager->GetObject("SamplerMSMapped"));
70+
if (fSamplerMSMapped == nullptr)
71+
{
72+
return kFATAL;
73+
}
74+
75+
fMSOffsetPar = dynamic_cast<R3BMSOffsetPar*>(rtdb->getContainer("MSOffsetPar"));
76+
if (fMSOffsetPar == nullptr)
77+
{
78+
LOG(error) << "Could not find MSOffsetPar container!";
79+
return kFATAL;
80+
}
81+
82+
return kSUCCESS;
83+
}
84+
85+
void R3BTprevTnext::Exec(Option_t* /*opt*/)
86+
{
87+
Double_t fTprev = -10.0; // Initialization with invalid values.
88+
Double_t fTnext = -10.0;
89+
Int_t dMScounter = 0;
90+
const Int_t sampHits = fSamplerMapped->GetEntriesFast();
91+
const Int_t sampmsHits = fSamplerMSMapped->GetEntriesFast();
92+
const Double_t MSOffset = fMSOffsetPar->GetMSOffset();
93+
Double_t SAMPTime = 0;
94+
Double_t SAMPMSTime = 0;
95+
R3BSamplerMappedData* SAMPMapped = nullptr;
96+
R3BSamplerMappedData* SAMPMSMapped = nullptr;
97+
bool sawMS = false;
98+
if (fR3BEventHeader->GetTpat() < fTpat && fR3BEventHeader->GetTrigger() == 1 && fR3BEventHeader->GetTpat() > 0)
99+
{
100+
if (sampmsHits == 1 && sampHits > 0)
101+
{
102+
SAMPMSMapped = dynamic_cast<R3BSamplerMappedData*>(fSamplerMSMapped->At(0));
103+
SAMPMSTime = SAMPMSMapped->GetTime();
104+
for (Int_t i = 0; i < sampHits; ++i)
105+
{
106+
SAMPMapped = dynamic_cast<R3BSamplerMappedData*>(fSamplerMapped->At(i));
107+
SAMPTime = SAMPMapped->GetTime();
108+
auto tpn = SAMPTime - SAMPMSTime - MSOffset;
109+
if (tpn < -delta_clk)
110+
{
111+
fTprev = -clock_period * tpn;
112+
}
113+
if (abs(tpn) <= 1)
114+
{
115+
sawMS = true;
116+
++dMScounter;
117+
}
118+
if (tpn > delta_clk)
119+
{
120+
fTnext = clock_period * tpn;
121+
break;
122+
}
123+
}
124+
}
125+
}
126+
if (sawMS)
127+
{
128+
if (fTprev == -10.0)
129+
{
130+
fTprev = 43.1e9; // MS is the first hit
131+
}
132+
if (fTnext == -10.0)
133+
{
134+
fTnext = 43.1e9; // MS is the last hit
135+
}
136+
if (dMScounter > 1)
137+
{
138+
if (fTprev == 43.1e9)
139+
{
140+
fTprev = 0; // Tprev inside the delta_clk
141+
}
142+
if (fTnext == 43.1e9)
143+
{
144+
fTnext = 0; // Tnext inside the delta_clk
145+
}
146+
}
147+
if (dMScounter == 1 && fTprev == 43.1e9 && fTnext == 43.1e9)
148+
{
149+
fTprev = -20.0; // Only one hit in the event
150+
fTnext = -20.0;
151+
}
152+
}
153+
fR3BEventHeader->SetTprev(fTprev);
154+
fR3BEventHeader->SetTnext(fTnext);
155+
}
156+
157+
ClassImp(R3BTprevTnext) // NOLINT

r3bbase/R3BTprevTnext.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/******************************************************************************
2+
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2019-2023 Members of R3B Collaboration *
4+
* *
5+
* This software is distributed under the terms of the *
6+
* GNU General Public Licence (GPL) version 3, *
7+
* copied verbatim in the file "LICENSE". *
8+
* *
9+
* In applying this license GSI does not waive the privileges and immunities *
10+
* granted to it by virtue of its status as an Intergovernmental Organization *
11+
* or submit itself to any jurisdiction. *
12+
******************************************************************************/
13+
14+
#pragma once
15+
16+
#include "FairTask.h"
17+
#include "R3BMSOffsetPar.h"
18+
19+
constexpr Int_t Default_Tpat = 1024;
20+
class TClonesArray;
21+
class R3BMSOffsetPar;
22+
class R3BEventHeader;
23+
class R3BSamplerMappedData;
24+
class R3BTprevTnext : public FairTask
25+
{
26+
public:
27+
/** Default constructor **/
28+
R3BTprevTnext();
29+
30+
/** Standard constructor **/
31+
explicit R3BTprevTnext(const TString& name, Int_t iVerbose = 1);
32+
33+
/** Virtual method Init **/
34+
InitStatus Init() override;
35+
36+
/** Virtual method Exec **/
37+
void Exec(Option_t* opt) override;
38+
39+
void SetTpat(Int_t option) { fTpat = option; }
40+
void SetDelta_clk(Double_t clock) { delta_clk = clock; }
41+
42+
private:
43+
R3BMSOffsetPar* fMSOffsetPar = nullptr;
44+
TClonesArray* fSamplerMapped = nullptr;
45+
TClonesArray* fSamplerMSMapped = nullptr;
46+
R3BEventHeader* fR3BEventHeader = nullptr; /**< Event header - input data. */
47+
Int_t fTpat = Default_Tpat;
48+
Double_t delta_clk = 1.0;
49+
50+
ClassDefOverride(R3BTprevTnext, 1); // NOLINT
51+
};

r3bbase/pars/R3BMSOffsetFinder.cxx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ R3BMSOffsetFinder::R3BMSOffsetFinder()
4343
// R3BMSOffsetFinder: Standard Constructor --------------------------
4444
R3BMSOffsetFinder::R3BMSOffsetFinder(const TString& name, Int_t iVerbose)
4545
: FairTask(name, iVerbose)
46-
, fMSOffset(0.0)
47-
, fMinStatistics(1)
48-
, fMSOffsetPar(nullptr)
49-
, fSamplerMapped(nullptr)
50-
, fSamplerMSMapped(nullptr)
51-
, fh_Offset_Finder(nullptr)
5246
{
5347
}
5448

r3bbase/pars/R3BMSOffsetFinder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ class R3BMSOffsetFinder : public FairTask // NOLINT
6969

7070
private:
7171
// Number of histograms, limits and bining
72-
Double_t fMSOffset;
72+
Double_t fMSOffset = 0.0;
7373

7474
// Minimum statistics and parameters
75-
Int_t fMinStatistics{};
75+
Int_t fMinStatistics = 1;
7676

77-
R3BMSOffsetPar* fMSOffsetPar; /**< Parameter container. >*/
78-
TClonesArray* fSamplerMapped; /**< Array with SAMP Mapped input data. >*/
79-
TClonesArray* fSamplerMSMapped; /**< Array with SAMPMS MApped input data. >*/
77+
R3BMSOffsetPar* fMSOffsetPar = nullptr; /**< Parameter container. >*/
78+
TClonesArray* fSamplerMapped = nullptr; /**< Array with SAMP Mapped input data. >*/
79+
TClonesArray* fSamplerMSMapped = nullptr; /**< Array with SAMPMS MApped input data. >*/
8080

81-
TH1F* fh_Offset_Finder;
81+
TH1F* fh_Offset_Finder = nullptr;
8282

8383
public:
8484
ClassDefOverride(R3BMSOffsetFinder, 1); // NOLINT

0 commit comments

Comments
 (0)