|
| 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) |
0 commit comments