R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandDigitizerCalData.cxx
Go to the documentation of this file.
1//
2// /******************************************************************************
3// * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
4// * Copyright (C) 2019-2024 Members of R3B Collaboration *
5// * *
6// * This software is distributed under the terms of the *
7// * GNU General Public Licence (GPL) version 3, *
8// * copied verbatim in the file "LICENSE". *
9// * *
10// * In applying this license GSI does not waive the privileges and immunities *
11// * granted to it by virtue of its status as an Intergovernmental Organization *
12// * or submit itself to any jurisdiction. *
13// ******************************************************************************/
14//
15// #include "R3BNeulandDigitizerCalData.h"
16// #include "FairLogger.h"
17// #include "FairRootManager.h"
18// #include "FairRunAna.h"
19// #include "FairRuntimeDb.h"
20// #include "TGeoManager.h"
21// #include "TGeoNode.h"
22// #include "TH1F.h"
23// #include "TH2F.h"
24// #include "TMath.h"
25// #include "TString.h"
26// #include <R3BShared.h>
27// #include <TFile.h>
28// #include <iostream>
29// #include <range/v3/view.hpp>
30// #include <stdexcept>
31// #include <utility>
32//
33// R3BNeulandDigitizerCalTask::R3BNeulandDigitizerCalTask(TString input, TString output)
34// : R3BNeulandDigitizerCalTask(Digitizing::CreateEngine(UsePaddle<NeulandPaddle>(), UseChannel<TacquilaChannel>()),
35// std::move(input),
36// std::move(output))
37// {
38// }
39//
40// R3BNeulandDigitizerCalTask::R3BNeulandDigitizerCalTask(std::unique_ptr<Digitizing::DigitizingEngineInterface> engine,
41// TString input,
42// TString output)
43// : FairTask("R3BNeulandDigitizerCalData")
44// , fPoints(std::move(input))
45// , fHits(std::move(output))
46// , fDigitizingEngine(std::move(engine))
47// {
48// }
49//
50// void R3BNeulandDigitizerCalTask::SetEngine(std::unique_ptr<Digitizing::DigitizingEngineInterface> engine)
51// {
52// fDigitizingEngine = std::move(engine);
53// }
54//
55// void R3BNeulandDigitizerCalTask::SetParContainers()
56// {
57// FairRunAna* run = FairRunAna::Instance();
58// if (run == nullptr)
59// {
60// LOG(fatal) << "R3BNeulandDigitizerCalData::SetParContainers: No analysis run";
61// }
62//
63// FairRuntimeDb* rtdb = run->GetRuntimeDb();
64// if (rtdb == nullptr)
65// {
66// LOG(fatal) << "R3BNeulandDigitizerCalData::SetParContainers: No runtime database";
67// }
68//
69// fNeulandGeoPar = dynamic_cast<R3BNeulandGeoPar*>(rtdb->getContainer("R3BNeulandGeoPar"));
70// if (fNeulandGeoPar == nullptr)
71// {
72// LOG(fatal) << "R3BNeulandDigitizerCalData::SetParContainers: No R3BNeulandGeoPar";
73// }
74//
75// fDigitizingEngine->Init();
76// }
77//
78// InitStatus R3BNeulandDigitizerCalTask::Init()
79// {
80// fPoints.Init();
81// fHits.Init();
82//
83// // Initialize control histograms
84// auto const PaddleMulSize = 3000;
85// hMultOne = R3B::root_owned<TH1I>(
86// "MultiplicityOne", "Paddle multiplicity: only one PMT per paddle", PaddleMulSize, 0, PaddleMulSize);
87// hMultTwo = R3B::root_owned<TH1I>(
88// "MultiplicityTwo", "Paddle multiplicity: both PMTs of a paddle", PaddleMulSize, 0, PaddleMulSize);
89// auto const timeBinSize = 200;
90// hRLTimeToTrig = R3B::root_owned<TH1F>("hRLTimeToTrig", "R/Ltime-triggerTime", timeBinSize, -100., 100.);
91//
92// return kSUCCESS;
93// }
94//
95// void R3BNeulandDigitizerCalTask::Exec(Option_t* /*option*/)
96// {
97// fHits.Reset();
98// const auto GeVToMeVFac = 1000.;
99//
100// // Look at each Land Point, if it deposited energy in the scintillator, store it with reference to the bar
101// for (const auto& point : fPoints.Retrieve())
102// {
103//
104// LOG(debug) << " input: eloss " << point->GetEnergyLoss() << std::endl;
105// if (point->GetEnergyLoss() > 0.)
106// {
107// const Int_t paddleID = point->GetPaddle();
108//
109// // Convert position of point to paddle-coordinates, including any rotation or translation
110// const TVector3 position = point->GetPosition();
111// const TVector3 converted_position = fNeulandGeoPar->ConvertToLocalCoordinates(position, paddleID);
112// LOG(debug2) << "NeulandDigitizer: Point in paddle " << paddleID
113// << " with global position XYZ: " << position.X() << " " << position.Y() << " " <<
114// position.Z();
115// LOG(debug2) << "NeulandDigitizer: Converted to local position XYZ: " << converted_position.X() << " "
116// << converted_position.Y() << " " << converted_position.Z();
117//
118// // Within the paddle frame, the relevant distance of the light from the pmt is always given by the
119// // X-Coordinate
120// const Double_t dist = converted_position.X();
121// fDigitizingEngine->DepositLight(paddleID, point->GetTime(), point->GetLightYield() * GeVToMeVFac, dist);
122// } // eloss
123// } // points
124// const auto paddles = fDigitizingEngine->ExtractPaddles();
125//
126// // Create CalHits
127// for (const auto& [paddleID, paddle] : paddles)
128// {
129// if (!paddle->HasFired())
130// {
131// continue;
132// }
133//
134// auto& left_channel = paddle->GetLeftChannelRef();
135// auto& right_channel = paddle->GetRightChannelRef();
136//
137// auto left_channel_signals = left_channel.GetCalSignals();
138// auto right_channel_signals = right_channel.GetCalSignals();
139//
140// // LOG(error)<< " Sum pmt_peak_: "<<
141// // std::accumulate(right_channel.pmt_peaks_.begin(),right_channel.pmt_peaks_.end(),0)<<std::endl;
142// for (const auto& [left, right] : ranges::zip_view(left_channel_signals, right_channel_signals))
143// {
144//
145// auto cal_data = R3B::Neuland::SimCalData{ paddleID, left.tot, right.tot, left.tle, right.tle };
146//
147// if (fHitFilters.IsValid(cal_data))
148// {
149// fHits.Insert(std::move(cal_data));
150// LOG(debug) << "Adding cal with id = " << paddleID << " left tot " << left.tot << " right tot "
151// << right.tot << std::endl;
152// }
153// } // loop over all hits for each paddle
154// } // loop over paddles
155//
156// LOG(debug) << "R3BNeulandDigitizerCalData: produced " << fHits.Size() << " hits";
157// }
158//
159// void R3BNeulandDigitizerCalTask::Finish()
160// {
161// TDirectory* tmp = gDirectory;
162// FairRootManager::Instance()->GetOutFile()->cd();
163//
164// gDirectory->mkdir("R3BNeulandDigitizerCalData");
165// gDirectory->cd("R3BNeulandDigitizerCalData");
166//
167// hMultOne->Write();
168// hMultTwo->Write();
169//
170// gDirectory = tmp;
171// }
172//
173// ClassImp(R3BNeulandDigitizerCalTask); // NOLINT