Skip to content

Commit ecd971c

Browse files
committed
Implementation of the Tprev/Tnext task.
1 parent b7d5932 commit ecd971c

File tree

6 files changed

+227
-12
lines changed

6 files changed

+227
-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
@@ -42,6 +42,7 @@ set(SRCS
4242
R3BTcutPar.cxx
4343
R3BTsplinePar.cxx
4444
R3BWhiterabbitPropagator.cxx
45+
R3BTprevTnext.cxx
4546
./pars/R3BMSOffsetPar.cxx
4647
./pars/R3BMSOffsetContFact.cxx
4748
./pars/R3BMSOffsetFinder.cxx)
@@ -62,6 +63,7 @@ set(HEADERS
6263
R3BTcutPar.h
6364
R3BTsplinePar.h
6465
R3BWhiterabbitPropagator.h
66+
R3BTprevTnext.h
6567
./pars/R3BMSOffsetPar.h
6668
./pars/R3BMSOffsetContFact.h
6769
./pars/R3BMSOffsetFinder.h)

r3bbase/R3BTprevTnext.cxx

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
constexpr auto ERROR_NO_MS = -30; // Assigned value for events where there is no MS
31+
constexpr auto INVALID_TPTN = -10; // Assigned value for invalid or nonexistent TPrev or TNext
32+
constexpr auto ERROR_MULTI_MS = -20; // Assigned value for events where there are multiple MS
33+
constexpr auto INVALID_EVENT = -40; // Assigned value for events where the MS was not correctly written
34+
constexpr auto FIRST_LAST_HIT = 0; // Assigned value for events where the first/last hit is the MS
35+
R3BTprevTnext::R3BTprevTnext()
36+
: R3BTprevTnext("R3B Tprev/Tnext", 1)
37+
{
38+
}
39+
40+
R3BTprevTnext::R3BTprevTnext(const TString& name, Int_t iVerbose)
41+
: FairTask(name, iVerbose)
42+
{
43+
}
44+
45+
InitStatus R3BTprevTnext::Init()
46+
{
47+
48+
FairRootManager* rootManager = FairRootManager::Instance();
49+
if (rootManager == nullptr)
50+
{
51+
LOG(error) << "FairRootManager not opened!";
52+
return kFATAL;
53+
}
54+
55+
FairRuntimeDb* rtdb = FairRuntimeDb::instance();
56+
if (rtdb == nullptr)
57+
{
58+
LOG(error) << "FairRuntimeDb not opened!";
59+
return kFATAL;
60+
}
61+
62+
fR3BEventHeader = dynamic_cast<R3BEventHeader*>(rootManager->GetObject("EventHeader."));
63+
if (fR3BEventHeader == nullptr)
64+
{
65+
LOG(error) << "R3BTprevTnext::Init() EventHeader. not found";
66+
return kFATAL;
67+
}
68+
69+
fSamplerMapped = dynamic_cast<TClonesArray*>(rootManager->GetObject("SamplerMapped"));
70+
if (fSamplerMapped == nullptr)
71+
{
72+
LOG(error) << "SamplerMapped not found or wrong type.";
73+
return kFATAL;
74+
}
75+
76+
fSamplerMSMapped = dynamic_cast<TClonesArray*>(rootManager->GetObject("SamplerMSMapped"));
77+
if (fSamplerMSMapped == nullptr)
78+
{
79+
LOG(error) << "SamplerMSMapped not found or wrong type.";
80+
return kFATAL;
81+
}
82+
83+
fMSOffsetPar = dynamic_cast<R3BMSOffsetPar*>(rtdb->getContainer("MSOffsetPar"));
84+
if (fMSOffsetPar == nullptr)
85+
{
86+
LOG(error) << "Could not find MSOffsetPar container!";
87+
return kFATAL;
88+
}
89+
90+
return kSUCCESS;
91+
}
92+
93+
void R3BTprevTnext::Exec(Option_t* /*opt*/)
94+
{
95+
Double_t fTprev = INVALID_TPTN; // Initialization with invalid values.
96+
Double_t fTnext = INVALID_TPTN;
97+
Int_t dMScounter = 0;
98+
const Int_t sampHits = fSamplerMapped->GetEntriesFast();
99+
const Int_t sampmsHits = fSamplerMSMapped->GetEntriesFast();
100+
const Double_t MSOffset = fMSOffsetPar->GetMSOffset();
101+
Double_t SAMPTime = 0;
102+
Double_t SAMPMSTime = 0;
103+
if (sampmsHits == 1 && sampHits > 0)
104+
{
105+
R3BSamplerMappedData* SAMPMapped = nullptr;
106+
R3BSamplerMappedData* SAMPMSMapped = nullptr;
107+
SAMPMSMapped = dynamic_cast<R3BSamplerMappedData*>(fSamplerMSMapped->At(0));
108+
SAMPMSTime = SAMPMSMapped->GetTime();
109+
for (Int_t i = 0; i < sampHits; ++i)
110+
{
111+
SAMPMapped = dynamic_cast<R3BSamplerMappedData*>(fSamplerMapped->At(i));
112+
SAMPTime = SAMPMapped->GetTime();
113+
auto tpn = SAMPTime - SAMPMSTime - MSOffset;
114+
if (tpn < -fDelta_clk)
115+
{
116+
fTprev = -CLOCK_PERIOD * tpn;
117+
}
118+
if (abs(tpn) <= fDelta_clk)
119+
{
120+
++dMScounter;
121+
}
122+
if (tpn > fDelta_clk)
123+
{
124+
fTnext = CLOCK_PERIOD * tpn;
125+
break;
126+
}
127+
}
128+
}
129+
else
130+
{
131+
fR3BEventHeader->SetTprev(INVALID_EVENT);
132+
fR3BEventHeader->SetTnext(INVALID_EVENT);
133+
return;
134+
}
135+
136+
if (dMScounter ==
137+
0) // This if statement checks if there is no Hit correspondent to the MSHit even after the first if statement
138+
{
139+
fTprev = ERROR_NO_MS;
140+
fTnext = ERROR_NO_MS;
141+
}
142+
if (dMScounter > 1)
143+
{
144+
fTprev = ERROR_MULTI_MS;
145+
fTnext = ERROR_MULTI_MS;
146+
}
147+
if (dMScounter == 1)
148+
{
149+
if (sampHits == 1)
150+
{
151+
fR3BEventHeader->SetTprev(fOne_hit);
152+
fR3BEventHeader->SetTnext(fOne_hit);
153+
return;
154+
}
155+
if (fTprev < 0 && fTnext > 0)
156+
{
157+
fTprev = FIRST_LAST_HIT;
158+
}
159+
if (fTprev > 0 && fTnext < 0)
160+
{
161+
fTnext = FIRST_LAST_HIT;
162+
}
163+
}
164+
fR3BEventHeader->SetTprev(fTprev);
165+
fR3BEventHeader->SetTnext(fTnext);
166+
}
167+
168+
ClassImp(R3BTprevTnext) // NOLINT

r3bbase/R3BTprevTnext.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
class TClonesArray;
20+
class R3BMSOffsetPar;
21+
class R3BEventHeader;
22+
class R3BSamplerMappedData;
23+
class R3BTprevTnext : public FairTask
24+
{
25+
public:
26+
/** Default constructor **/
27+
R3BTprevTnext();
28+
29+
/** Standard constructor **/
30+
explicit R3BTprevTnext(const TString& name, Int_t iVerbose = 1);
31+
32+
/** Virtual method Init **/
33+
InitStatus Init() override;
34+
35+
/** Virtual method Exec **/
36+
void Exec(Option_t* opt) override;
37+
38+
void SetOne_hit(Double_t One_hit_position) { fOne_hit = One_hit_position; }
39+
void SetDelta_clk(Double_t clock) { fDelta_clk = clock; }
40+
41+
private:
42+
R3BMSOffsetPar* fMSOffsetPar = nullptr;
43+
TClonesArray* fSamplerMapped = nullptr;
44+
TClonesArray* fSamplerMSMapped = nullptr;
45+
R3BEventHeader* fR3BEventHeader = nullptr; /**< Event header - input data. */
46+
Double_t fDelta_clk = 1.0;
47+
Double_t fOne_hit = 3e6;
48+
49+
ClassDefOverride(R3BTprevTnext, 1); // NOLINT
50+
};

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)