From 05ff8f1b34ea5d7b8292b67298052ba994a89261 Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Thu, 15 May 2025 23:14:05 +0200 Subject: [PATCH 1/2] feat(analysis/online);Added new online class to check the correlations between mwpc0 and foot Minor change Minor change --- analysis/AnaLinkDef.h | 1 + .../online/R3BMwpcvsFootOnlineSpectra.cxx | 239 ++++++++++++++++++ analysis/online/R3BMwpcvsFootOnlineSpectra.h | 117 +++++++++ 3 files changed, 357 insertions(+) create mode 100644 analysis/online/R3BMwpcvsFootOnlineSpectra.cxx create mode 100644 analysis/online/R3BMwpcvsFootOnlineSpectra.h diff --git a/analysis/AnaLinkDef.h b/analysis/AnaLinkDef.h index e68b30844..38d78c0dc 100644 --- a/analysis/AnaLinkDef.h +++ b/analysis/AnaLinkDef.h @@ -46,6 +46,7 @@ #pragma link C++ class R3BCalifavsTofDOnlineSpectra+; #pragma link C++ class R3BCalifavsSpiderOnlineSpectra+; #pragma link C++ class R3BMwpcvsTttxOnlineSpectra+; +#pragma link C++ class R3BMwpcvsFootOnlineSpectra+; #pragma link C++ class R3BFibervsTofDOnlineSpectra+; #pragma link C++ class R3BFiberTrackingOnlineSpectra+; #pragma link C++ class R3BGeneralOnlineSpectra+; diff --git a/analysis/online/R3BMwpcvsFootOnlineSpectra.cxx b/analysis/online/R3BMwpcvsFootOnlineSpectra.cxx new file mode 100644 index 000000000..cac3b812d --- /dev/null +++ b/analysis/online/R3BMwpcvsFootOnlineSpectra.cxx @@ -0,0 +1,239 @@ +/****************************************************************************** + * Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2025 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 "R3BMwpcvsFootOnlineSpectra.h" +#include "R3BEventHeader.h" +#include "R3BFootHitData.h" +#include "R3BLogger.h" +#include "R3BMwpcHitData.h" +#include "R3BShared.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +R3BMwpcvsFootOnlineSpectra::R3BMwpcvsFootOnlineSpectra() + : R3BMwpcvsFootOnlineSpectra("R3BMwpcvsFootOnlineSpectra", 1) +{ +} + +R3BMwpcvsFootOnlineSpectra::R3BMwpcvsFootOnlineSpectra(const TString& name, int iVerbose) + : FairTask(name, iVerbose) +{ +} + +void R3BMwpcvsFootOnlineSpectra::SetParContainers() +{ + // Parameter Container + // Reading amsStripCalPar from FairRuntimeDb + FairRuntimeDb* rtdb = FairRuntimeDb::instance(); + R3BLOG_IF(fatal, !rtdb, "FairRuntimeDb not found"); +} + +InitStatus R3BMwpcvsFootOnlineSpectra::Init() +{ + R3BLOG(info, ""); + FairRootManager* mgr = FairRootManager::Instance(); + R3BLOG_IF(fatal, mgr == nullptr, "FairRootManager not found"); + + fHeader = dynamic_cast(mgr->GetObject("EventHeader.")); + R3BLOG_IF(fatal, fHeader == nullptr, "EventHeader. not found"); + + // get access to Hit data + fHitItemsMw = dynamic_cast(mgr->GetObject("Mwpc0HitData")); + R3BLOG_IF(fatal, !fHitItemsMw, "Mwpc0HitData not found"); + + fHitItemsFoot = dynamic_cast(mgr->GetObject("FootHitData")); + R3BLOG_IF(fatal, !fHitItemsFoot, "FootHitData not found"); + + // Create histograms for detectors + cCMwF = std::make_unique("Mwpc_vs_Foot", "Mwpc vs Foot correlations", 10, 10, 500, 500); + cCMwF->Divide(2, 3); + + std::vector hist_names; + hist_names.push_back("fh2_MwpcX_Foot1X"); + hist_names.push_back("fh2_MwpcX_Foot3X"); + hist_names.push_back("fh2_MwpcY_Foot2Y"); + hist_names.push_back("fh2_MwpcY_Foot4Y"); + hist_names.push_back("fh2_MwpcX_Foot2Y"); + hist_names.push_back("fh2_MwpcY_Foot1X"); + + std::vector hist_titles; + hist_titles.push_back("MwpcX vs Foot1X"); + hist_titles.push_back("MwpcX vs Foot3X"); + hist_titles.push_back("MwpcY vs Foot2Y"); + hist_titles.push_back("MwpcY vs Foot4Y"); + hist_titles.push_back("MwpcX vs Foot2Y"); + hist_titles.push_back("MwpcY vs Foot1X"); + + std::vector hist_xaxis_titles; + hist_xaxis_titles.push_back("Foot1X [mm]"); + hist_xaxis_titles.push_back("Foot3X [mm]"); + hist_xaxis_titles.push_back("Foot2Y [mm]"); + hist_xaxis_titles.push_back("Foot4Y [mm]"); + hist_xaxis_titles.push_back("MwpcX [mm]"); + hist_xaxis_titles.push_back("Foot1X [mm]"); + + std::vector hist_yaxis_titles; + hist_yaxis_titles.push_back("MwpcX [mm]"); + hist_yaxis_titles.push_back("MwpcX [mm]"); + hist_yaxis_titles.push_back("MwpcY [mm]"); + hist_yaxis_titles.push_back("MwpcY [mm]"); + hist_yaxis_titles.push_back("Foot2Y [mm]"); + hist_yaxis_titles.push_back("MwpcY [mm]"); + + fh2_cor.resize(hist_names.size()); + fNbHist = hist_names.size(); + for (size_t i = 0; i < hist_names.size(); i++) + { + cCMwF->cd(i + 1); + gPad->SetLogz(); + std::stringstream ss1; + ss1 << "fh2_Mwpc_Tttx_Xcor_" << i; + fh2_cor[i] = R3B::root_owned(hist_names[i].c_str(), hist_titles[i].c_str(), 400, -100, 100, 67, -50, 50); + fh2_cor[i]->GetXaxis()->SetTitle(hist_xaxis_titles[i].c_str()); + fh2_cor[i]->GetYaxis()->SetTitle(hist_yaxis_titles[i].c_str()); + fh2_cor[i]->GetYaxis()->SetTitleOffset(1.2); + fh2_cor[i]->GetXaxis()->CenterTitle(true); + fh2_cor[i]->GetYaxis()->CenterTitle(true); + fh2_cor[i]->Draw("COLZ"); + } + + // MAIN FOLDER-Mwpc-Foot + auto mainfol = new TFolder("Mwpc_vs_Foot", "MWPC vs Foot info"); + + if (fHitItemsMw && fHitItemsFoot) + { + mainfol->Add(cCMwF.get()); + } + + auto run = FairRunOnline::Instance(); + run->GetHttpServer()->Register("", this); + + run->AddObject(mainfol); + + // Register command to reset histograms + run->GetHttpServer()->RegisterCommand("Reset_Mwpc_vs_Foot", Form("/Objects/%s/->Reset_Histo()", GetName())); + + return kSUCCESS; +} + +// ----- Public method ReInit ---------------------------------------------- +InitStatus R3BMwpcvsFootOnlineSpectra::ReInit() +{ + SetParContainers(); + // SetParameter(); + return kSUCCESS; +} + +void R3BMwpcvsFootOnlineSpectra::Reset_Histo() +{ + R3BLOG(info, ""); + for (const auto& hist : fh2_cor) + { + hist->Reset(); + } +} + +void R3BMwpcvsFootOnlineSpectra::Exec(Option_t* /*option*/) +{ + if ((fTpat > 0) && (fHeader) && ((fHeader->GetTpat() & fTpat) != fTpat)) + return; + + int nHitsMw = fHitItemsMw->GetEntriesFast(); + int nHitsFo = fHitItemsFoot->GetEntriesFast(); + + if (nHitsMw == 0 || nHitsFo == 0) + return; + + std::vector VMw; + for (size_t ihit = 0; ihit < nHitsMw; ihit++) + { + auto hit = dynamic_cast(fHitItemsMw->At(ihit)); + VMw.push_back(TVector3(hit->GetX(), hit->GetY(), 0)); + } + + for (size_t ihit = 0; ihit < nHitsFo; ihit++) + { + auto hit = dynamic_cast(fHitItemsFoot->At(ihit)); + auto idet = hit->GetDetId() - 1; + auto pos = hit->GetPos(); + if (idet < 0) + continue; + + if (idet == 0 || idet == 2) // Foot detectors in X + for (const auto& vtemp : VMw) + { + auto index = idet == 0 ? 0 : 1; + if (abs(vtemp.X() - pos) < fMinDist) + fh2_cor[index]->Fill(pos, vtemp.X()); + } + else if (idet == 1 || idet == 3) // Foot detectors in Y + for (const auto& vtemp : VMw) + { + auto index = idet == 1 ? 2 : 3; + if (abs(vtemp.Y() - pos) < fMinDist) + fh2_cor[index]->Fill(pos, vtemp.Y()); + } + + if (idet == 1) // Foot detector in Y closer to MW + for (const auto& vtemp : VMw) + { + fh2_cor[fNbHist - 2]->Fill(vtemp.X(), pos); + } + + if (idet == 0) // Foot detector in X closer to MW + for (const auto& vtemp : VMw) + { + fh2_cor[fNbHist - 1]->Fill(pos, vtemp.Y()); + } + } + fNEvents++; +} + +void R3BMwpcvsFootOnlineSpectra::FinishEvent() +{ + if (fHitItemsMw) + { + fHitItemsMw->Clear(); + } + if (fHitItemsFoot) + { + fHitItemsFoot->Clear(); + } +} + +void R3BMwpcvsFootOnlineSpectra::FinishTask() +{ + // Write canvas for Hit data + if (fHitItemsMw && fHitItemsFoot) + { + for (const auto& hist : fh2_cor) + { + hist->Write(); + } + } +} + +ClassImp(R3BMwpcvsFootOnlineSpectra) diff --git a/analysis/online/R3BMwpcvsFootOnlineSpectra.h b/analysis/online/R3BMwpcvsFootOnlineSpectra.h new file mode 100644 index 000000000..52e80a8f1 --- /dev/null +++ b/analysis/online/R3BMwpcvsFootOnlineSpectra.h @@ -0,0 +1,117 @@ +/****************************************************************************** + * Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2025 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. * + ******************************************************************************/ + +// ------------------------------------------------------------ +// ----- R3BMwpcvsFootOnlineSpectra ----- +// ----- Created 15/05/25 by J.L. Rodriguez-Sanchez ----- +// ------------------------------------------------------------ + +#pragma once + +#include +#include +#include +#include + +class TH2F; +class TClonesArray; +class R3BEventHeader; + +class R3BMwpcvsFootOnlineSpectra : public FairTask +{ + public: + /** + * Default constructor. + * Creates an instance of the task with default parameters. + */ + R3BMwpcvsFootOnlineSpectra(); + + /** + * Standard constructor. + * Creates an instance of the task. + * @param name a name of the task. + * @param iVerbose a verbosity level. + */ + explicit R3BMwpcvsFootOnlineSpectra(const TString& name, int iVerbose = 1); + + /** + * Destructor. + * Frees the memory used by the object. + */ + virtual ~R3BMwpcvsFootOnlineSpectra() = default; + + /** Virtual method SetParContainers **/ + void SetParContainers() override; + + /** + * Method for task initialization. + * This function is called by the framework before + * the event loop. + * @return Initialization status. kSUCCESS, kERROR or kFATAL. + */ + InitStatus Init() override; + + /** Virtual method ReInit **/ + InitStatus ReInit() override; + + /** + * Method for event loop implementation. + * Is called by the framework every time a new event is read. + * @param option an execution option. + */ + void Exec(Option_t* /*option*/) override; + + /** + * A method for finish of processing of an event. + * Is called by the framework for each event after executing + * the tasks. + */ + void FinishEvent() override; + + /** + * Method for finish of the task execution. + * Is called by the framework after processing the event loop. + */ + void FinishTask() override; + + /** + * Method for setting the fTpat + */ + inline void SetTpat(int tpat) { fTpat = tpat; } + + /** + * Method for setting min difference in X (in mm) for MW-Foot correlations + */ + inline void SetMinDist(double min) { fMinDist = min; } + + /** + * Method to reset histograms + */ + void Reset_Histo(); + + private: + TClonesArray* fHitItemsMw = nullptr; + TClonesArray* fHitItemsFoot = nullptr; + R3BEventHeader* fHeader = nullptr; + + unsigned long long fNEvents = 0; + int fTpat = 0; + double fMinDist = 20.; // mm + int8_t fNbHist = 6; + + std::vector fh2_cor; + std::unique_ptr cCMwF; + + public: + ClassDefOverride(R3BMwpcvsFootOnlineSpectra, 1); +}; From 598f8e1ba3a0af5a1eb7e7e878327d4f7863be9d Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sat, 17 May 2025 19:33:40 +0200 Subject: [PATCH 2/2] feat(r3bdata/footData):Added Z-charge variable for foot hit data --- r3bdata/footData/R3BFootHitData.cxx | 5 ++++- r3bdata/footData/R3BFootHitData.h | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/r3bdata/footData/R3BFootHitData.cxx b/r3bdata/footData/R3BFootHitData.cxx index 806c2688f..32dd5d719 100644 --- a/r3bdata/footData/R3BFootHitData.cxx +++ b/r3bdata/footData/R3BFootHitData.cxx @@ -24,7 +24,8 @@ R3BFootHitData::R3BFootHitData(uint8_t detid, TVector3 master, double energy, uint16_t mulstrip, - double eta) + double eta, + double zcharge) : fDetId(detid) , fNbHit(nbhit) , fPos(pos) @@ -34,6 +35,7 @@ R3BFootHitData::R3BFootHitData(uint8_t detid, , fEnergy(energy) , fMulStrip(mulstrip) , fEta(eta) + , fZCharge(zcharge) { } @@ -48,6 +50,7 @@ R3BFootHitData::R3BFootHitData(const R3BFootHitData& right) , fEnergy(right.fEnergy) , fMulStrip(right.fMulStrip) , fEta(right.fEta) + , fZCharge(right.fZCharge) { } diff --git a/r3bdata/footData/R3BFootHitData.h b/r3bdata/footData/R3BFootHitData.h index 3fd5f319d..91d304530 100644 --- a/r3bdata/footData/R3BFootHitData.h +++ b/r3bdata/footData/R3BFootHitData.h @@ -12,8 +12,8 @@ ******************************************************************************/ // ------------------------------------------------------------------ -// ----- R3BFootHitData header file ----- -// ----- Created 16/07/21 by J.L. Rodriguez-Sanchez ----- +// ----- R3BFootHitData header file ----- +// ----- Created 16/07/21 by J.L. Rodriguez-Sanchez ----- // ------------------------------------------------------------------ #pragma once @@ -32,11 +32,12 @@ class R3BFootHitData : public TObject *@param fDetId Detector unique identifier *@param fNbHit Number of hits *@param fMulStrip Number of strips with signals - *@param fPos Position in mm, local coordinate (detector frame) + *@param fPos Position in mm, local coordinate (detector frame) *@param fTheta Master: Angle theta [rad] (lab frame) *@param fPhi Master: Angle Phi [rad] (lab frame) *@param fEnergy Total energy deposited by the hit ([GeV] in sim) *@param fEta Difference between the integer part of the cluster position and the cluster position + *@param fZCharge Ion atomic charge **/ explicit R3BFootHitData(uint8_t detid, uint16_t nbhit, @@ -44,7 +45,8 @@ class R3BFootHitData : public TObject TVector3 master, double energy, uint16_t mulstrip = 0, - double eta = 0); + double eta = 0, + double zcharge = 0); /** Copy constructor **/ R3BFootHitData(const R3BFootHitData&); @@ -64,6 +66,7 @@ class R3BFootHitData : public TObject [[nodiscard]] inline const TVector3 GetPosLab() const { return fmaster; } [[nodiscard]] inline const double& GetEnergy() const { return fEnergy; } [[nodiscard]] inline const double& GetEta() const { return fEta; } + [[nodiscard]] inline const double& GetZCharge() const { return fZCharge; } protected: uint8_t fDetId = 0; @@ -75,7 +78,8 @@ class R3BFootHitData : public TObject double fEnergy = std::nan(""); uint16_t fMulStrip = 0; double fEta = 0; + double fZCharge = std::nan(""); public: - ClassDefOverride(R3BFootHitData, 1) + ClassDefOverride(R3BFootHitData, 2); // NOLINT };