Skip to content

Commit 45fb849

Browse files
committed
Added online for correlations between mwpc and tttx
Minor change Added histograms for multiplicity correlations
1 parent a313b2b commit 45fb849

3 files changed

Lines changed: 342 additions & 0 deletions

File tree

analysis/AnaLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#pragma link C++ class R3BCalifavsFootOnlineSpectra+;
4646
#pragma link C++ class R3BCalifavsTofDOnlineSpectra+;
4747
#pragma link C++ class R3BCalifavsSpiderOnlineSpectra+;
48+
#pragma link C++ class R3BMwpcvsTttxOnlineSpectra+;
4849
#pragma link C++ class R3BFibervsTofDOnlineSpectra+;
4950
#pragma link C++ class R3BFiberTrackingOnlineSpectra+;
5051
#pragma link C++ class R3BGeneralOnlineSpectra+;
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/******************************************************************************
2+
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2019-2024 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 "R3BMwpcvsTttxOnlineSpectra.h"
15+
#include "R3BEventHeader.h"
16+
#include "R3BLogger.h"
17+
#include "R3BMwpcHitData.h"
18+
#include "R3BShared.h"
19+
#include "R3BTttxHitData.h"
20+
21+
#include <FairLogger.h>
22+
#include <FairRootManager.h>
23+
#include <FairRunOnline.h>
24+
#include <FairRuntimeDb.h>
25+
26+
#include <TCanvas.h>
27+
#include <TFolder.h>
28+
#include <TH2F.h>
29+
#include <THttpServer.h>
30+
#include <TVector3.h>
31+
32+
#include <TClonesArray.h>
33+
#include <sstream>
34+
35+
R3BMwpcvsTttxOnlineSpectra::R3BMwpcvsTttxOnlineSpectra()
36+
: R3BMwpcvsTttxOnlineSpectra("R3BMwpcvsTttxOnlineSpectra", 1)
37+
{
38+
}
39+
40+
R3BMwpcvsTttxOnlineSpectra::R3BMwpcvsTttxOnlineSpectra(const TString& name, int iVerbose)
41+
: FairTask(name, iVerbose)
42+
{
43+
}
44+
45+
void R3BMwpcvsTttxOnlineSpectra::SetParContainers()
46+
{
47+
// Parameter Container
48+
// Reading amsStripCalPar from FairRuntimeDb
49+
FairRuntimeDb* rtdb = FairRuntimeDb::instance();
50+
R3BLOG_IF(fatal, !rtdb, "FairRuntimeDb not found");
51+
}
52+
53+
InitStatus R3BMwpcvsTttxOnlineSpectra::Init()
54+
{
55+
R3BLOG(info, "");
56+
FairRootManager* mgr = FairRootManager::Instance();
57+
R3BLOG_IF(fatal, mgr == nullptr, "FairRootManager not found");
58+
59+
fHeader = dynamic_cast<R3BEventHeader*>(mgr->GetObject("EventHeader."));
60+
R3BLOG_IF(fatal, fHeader == nullptr, "EventHeader. not found");
61+
62+
// get access to Hit data
63+
fHitItemsMw = dynamic_cast<TClonesArray*>(mgr->GetObject("Mwpc1HitData"));
64+
R3BLOG_IF(fatal, !fHitItemsMw, "Mwpc1HitData not found");
65+
66+
fHitItemsTttx = dynamic_cast<TClonesArray*>(mgr->GetObject("TttxHitData"));
67+
R3BLOG_IF(fatal, !fHitItemsTttx, "TttxHitData not found");
68+
69+
// Create histograms for detectors
70+
71+
cCMwTx = std::make_unique<TCanvas>("Mwpc_Tttx_Xcor", "Mwpc-X vs Tttx-X", 10, 10, 500, 500);
72+
cCMwTx->Divide(fNbHist, 1);
73+
fh2_xcor.resize(fNbHist);
74+
75+
cCMwTx_mul = std::make_unique<TCanvas>("Mwpc_Tttx_mulcor", "Mwpc vs Tttx multiplicities", 10, 10, 500, 500);
76+
cCMwTx_mul->Divide(fNbHist, 1);
77+
fh2_multcor.resize(fNbHist);
78+
79+
for (int i = 0; i < fNbHist; i++)
80+
{
81+
cCMwTx->cd(i + 1);
82+
std::stringstream ss1;
83+
ss1 << "fh2_Mwpc_Tttx_Xcor_" << i;
84+
fh2_xcor[i] = R3B::root_owned<TH2F>(ss1.str().c_str(), ss1.str().c_str(), 400, -100, 100, 67, -50, 50);
85+
fh2_xcor[i]->GetXaxis()->SetTitle("Mwpc-X [mm]");
86+
fh2_xcor[i]->GetYaxis()->SetTitle("Tttx-X [mm]");
87+
fh2_xcor[i]->GetYaxis()->SetTitleOffset(1.2);
88+
fh2_xcor[i]->GetXaxis()->CenterTitle(true);
89+
fh2_xcor[i]->GetYaxis()->CenterTitle(true);
90+
fh2_xcor[i]->Draw("COLZ");
91+
}
92+
93+
for (int i = 0; i < fNbHist; i++)
94+
{
95+
cCMwTx_mul->cd(i + 1);
96+
std::stringstream ss1;
97+
ss1 << "fh2_Mwpc_Tttx_mul_" << i;
98+
fh2_multcor[i] = R3B::root_owned<TH2F>(ss1.str().c_str(), ss1.str().c_str(), 10, 0, 10, 15, 0, 15);
99+
fh2_multcor[i]->GetXaxis()->SetTitle("Mwpc-mul");
100+
fh2_multcor[i]->GetYaxis()->SetTitle("Tttx-mul");
101+
fh2_multcor[i]->GetYaxis()->SetTitleOffset(1.2);
102+
fh2_multcor[i]->GetXaxis()->CenterTitle(true);
103+
fh2_multcor[i]->GetYaxis()->CenterTitle(true);
104+
fh2_multcor[i]->Draw("COLZ");
105+
}
106+
107+
// MAIN FOLDER-Mwpc-Tttx
108+
auto mainfol = new TFolder("Mwpc_vs_Tttx", "MWPC vs Tttx info");
109+
110+
if (fHitItemsMw && fHitItemsTttx)
111+
{
112+
mainfol->Add(cCMwTx_mul.get());
113+
mainfol->Add(cCMwTx.get());
114+
}
115+
116+
auto run = FairRunOnline::Instance();
117+
run->GetHttpServer()->Register("", this);
118+
119+
run->AddObject(mainfol);
120+
121+
// Register command to reset histograms
122+
run->GetHttpServer()->RegisterCommand("Reset_Mwpc_vs_Tttx", Form("/Objects/%s/->Reset_Histo()", GetName()));
123+
124+
return kSUCCESS;
125+
}
126+
127+
// ----- Public method ReInit ----------------------------------------------
128+
InitStatus R3BMwpcvsTttxOnlineSpectra::ReInit()
129+
{
130+
SetParContainers();
131+
// SetParameter();
132+
return kSUCCESS;
133+
}
134+
135+
void R3BMwpcvsTttxOnlineSpectra::Reset_Histo()
136+
{
137+
R3BLOG(info, "");
138+
for (const auto& hist : fh2_xcor)
139+
{
140+
hist->Reset();
141+
}
142+
for (const auto& hist : fh2_multcor)
143+
{
144+
hist->Reset();
145+
}
146+
}
147+
148+
void R3BMwpcvsTttxOnlineSpectra::Exec(Option_t* /*option*/)
149+
{
150+
if ((fTpat > 0) && (fHeader) && ((fHeader->GetTpat() & fTpat) != fTpat))
151+
return;
152+
153+
int nHitsMw = fHitItemsMw->GetEntriesFast();
154+
int nHitsTx = fHitItemsTttx->GetEntriesFast();
155+
156+
if (nHitsMw == 0 || nHitsTx == 0)
157+
return;
158+
159+
std::vector<TVector3> VMw;
160+
for (int ihit = 0; ihit < nHitsMw; ihit++)
161+
{
162+
auto hit = dynamic_cast<R3BMwpcHitData*>(fHitItemsMw->At(ihit));
163+
VMw.push_back(TVector3(hit->GetX(), hit->GetY(), 0));
164+
}
165+
166+
std::vector<int> mul_tttx(fNbHist, 0);
167+
for (int ihit = 0; ihit < nHitsTx; ihit++)
168+
{
169+
auto hit = dynamic_cast<R3BTttxHitData*>(fHitItemsTttx->At(ihit));
170+
auto idet = hit->GetDetID();
171+
auto posX = hit->GetX();
172+
if (idet < 0)
173+
continue;
174+
// Multiplicity per tttx detector: 0-all
175+
mul_tttx[idet]++;
176+
177+
for (const auto& vtemp : VMw)
178+
{
179+
if (abs(vtemp.X() - posX) < fMinDist)
180+
fh2_xcor[idet]->Fill(vtemp.X(), posX);
181+
}
182+
}
183+
184+
for (int ihist = 0; ihist < fNbHist; ihist++)
185+
{
186+
if (mul_tttx[ihist] > 0)
187+
fh2_multcor[ihist]->Fill(nHitsMw, mul_tttx[ihist]);
188+
}
189+
190+
fNEvents += 1;
191+
}
192+
193+
void R3BMwpcvsTttxOnlineSpectra::FinishEvent()
194+
{
195+
if (fHitItemsMw)
196+
{
197+
fHitItemsMw->Clear();
198+
}
199+
if (fHitItemsTttx)
200+
{
201+
fHitItemsTttx->Clear();
202+
}
203+
}
204+
205+
void R3BMwpcvsTttxOnlineSpectra::FinishTask()
206+
{
207+
// Write canvas for Hit data
208+
if (fHitItemsMw && fHitItemsTttx)
209+
{
210+
for (const auto& hist : fh2_xcor)
211+
{
212+
hist->Write();
213+
}
214+
for (const auto& hist : fh2_multcor)
215+
{
216+
hist->Write();
217+
}
218+
}
219+
}
220+
221+
ClassImp(R3BMwpcvsTttxOnlineSpectra)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/******************************************************************************
2+
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2019-2024 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+
// ------------------------------------------------------------
15+
// ----- R3BMwpcvsTttxOnlineSpectra -----
16+
// ----- Created 26/01/24 by J.L. Rodriguez-Sanchez -----
17+
// ------------------------------------------------------------
18+
19+
#pragma once
20+
21+
#include <FairTask.h>
22+
#include <TCanvas.h>
23+
#include <memory>
24+
#include <vector>
25+
26+
class TH2F;
27+
class TClonesArray;
28+
class R3BEventHeader;
29+
30+
constexpr const int8_t fNbHist = 3;
31+
32+
class R3BMwpcvsTttxOnlineSpectra : public FairTask
33+
{
34+
public:
35+
/**
36+
* Default constructor.
37+
* Creates an instance of the task with default parameters.
38+
*/
39+
R3BMwpcvsTttxOnlineSpectra();
40+
41+
/**
42+
* Standard constructor.
43+
* Creates an instance of the task.
44+
* @param name a name of the task.
45+
* @param iVerbose a verbosity level.
46+
*/
47+
explicit R3BMwpcvsTttxOnlineSpectra(const TString& name, int iVerbose = 1);
48+
49+
/**
50+
* Destructor.
51+
* Frees the memory used by the object.
52+
*/
53+
virtual ~R3BMwpcvsTttxOnlineSpectra() = default;
54+
55+
/** Virtual method SetParContainers **/
56+
void SetParContainers() override;
57+
58+
/**
59+
* Method for task initialization.
60+
* This function is called by the framework before
61+
* the event loop.
62+
* @return Initialization status. kSUCCESS, kERROR or kFATAL.
63+
*/
64+
InitStatus Init() override;
65+
66+
/** Virtual method ReInit **/
67+
InitStatus ReInit() override;
68+
69+
/**
70+
* Method for event loop implementation.
71+
* Is called by the framework every time a new event is read.
72+
* @param option an execution option.
73+
*/
74+
void Exec(Option_t* /*option*/) override;
75+
76+
/**
77+
* A method for finish of processing of an event.
78+
* Is called by the framework for each event after executing
79+
* the tasks.
80+
*/
81+
void FinishEvent() override;
82+
83+
/**
84+
* Method for finish of the task execution.
85+
* Is called by the framework after processing the event loop.
86+
*/
87+
void FinishTask() override;
88+
89+
/**
90+
* Method for setting the fTpat
91+
*/
92+
inline void SetTpat(int tpat) { fTpat = tpat; }
93+
94+
/**
95+
* Method for setting min difference in X (in mm) for MW-Tttx correlations
96+
*/
97+
inline void SetMinDist(double min) { fMinDist = min; }
98+
99+
/**
100+
* Method to reset histograms
101+
*/
102+
void Reset_Histo();
103+
104+
private:
105+
TClonesArray* fHitItemsMw = nullptr;
106+
TClonesArray* fHitItemsTttx = nullptr;
107+
R3BEventHeader* fHeader = nullptr;
108+
109+
int fNEvents = 0;
110+
int fTpat = 0;
111+
double fMinDist = 10.; // mm
112+
113+
std::vector<TH2F*> fh2_xcor;
114+
std::vector<TH2F*> fh2_multcor;
115+
std::unique_ptr<TCanvas> cCMwTx;
116+
std::unique_ptr<TCanvas> cCMwTx_mul;
117+
118+
public:
119+
ClassDefOverride(R3BMwpcvsTttxOnlineSpectra, 1)
120+
};

0 commit comments

Comments
 (0)