8#include "FairParamList.h"
22 : FairParGenericSet(name, title, context)
42 std::cout <<
"CbmMcbm2020TrdTshiftPar::printparams() " << &
fTimeshifts << std::endl;
44 std::cout <<
"ParSet has " << ntimeshifts <<
" timeshift changes stored" << std::endl;
46 for (
size_t ishiftblock = 0; ishiftblock < ntimeshifts; ishiftblock++) {
48 for (
size_t ichannel = 0; ichannel <
fgNchannels; ichannel++) {
49 if (ichannel % 6 == 0) std::cout << std::endl;
66 if (!l)
return kFALSE;
76 size_t itimeslice = 0;
77 for (
size_t ientry = 0; ientry < nentries; ientry++) {
93 ichannel = ientry - 1 - nthShift * (
fgNchannels + 1);
98 for (itimeslice = 0; itimeslice < static_cast<size_t>(std::abs(
fNtimeslices[0])); itimeslice++) {
106 auto newtspair = std::pair<size_t, std::vector<Int_t>>(itimeslice, itspair->second);
133 bool didChange =
true;
134 for (
size_t ievent = 1; ievent < static_cast<size_t>(std::abs(
fNtimeslices[0])); ievent++) {
135 tsidx = timeshiftHisto->GetXaxis()->GetBinLowEdge(ievent);
136 for (
size_t ichannel = 0; ichannel <
fgNchannels; ichannel++) {
137 tshift = (Int_t) timeshiftHisto->GetBinContent(ievent, ichannel);
151 eventId = tsidx / 10;
155 for (
size_t ichannel = 0; ichannel <
fgNchannels; ichannel++) {
181 TH1* histo =
nullptr;
192 std::string hpath =
"FillStation-RunInfo/FullTrd/RunId_wNEvents-RunInfo";
193 histo = mcbmanafile->Get<TH1>(hpath.data());
194 LOG_IF(fatal, !histo) <<
" CbmMcbm2020TrdTshiftPar::GetNEvents " << hpath.data() <<
" not found in the file"
196 double nevents = histo->GetBinContent(histo->GetMaximumBin());
204 THnSparse* hsparse =
nullptr;
212 std::string hpath =
"FillStation-TrdBmonDigi/FullTrd/"
213 "TsSourceTsIndex_DigiTrdChannel_DigiDtCorrSlice-TrdBmonDigi";
214 hsparse = mcbmanafile->Get<THnSparse>(hpath.data());
216 LOG_IF(fatal, !hsparse) <<
" CbmMcbm2020TrdTshiftPar::GetCalibHisto " << hpath.data() <<
" not found in the file"
222 auto tsaxis = hsparse->GetAxis(0);
223 tsaxis->SetRangeUser(0.0, (
double) nevents);
224 auto temphisto = hsparse->Projection(0, 1, 2);
225 auto histo = std::make_shared<TH3D>(*temphisto);
227 histo->SetName(
"calibbasehisto");
228 histo->SetTitle(
"calibbasehisto");
230 histo->GetXaxis()->SetUniqueID(hsparse->GetAxis(0)->GetUniqueID());
231 histo->GetYaxis()->SetUniqueID(hsparse->GetAxis(1)->GetUniqueID());
232 histo->GetZaxis()->SetUniqueID(hsparse->GetAxis(2)->GetUniqueID());
243 size_t nevents = calibbasehisto->GetNbinsX();
244 size_t firstTsIdx = calibbasehisto->GetXaxis()->GetBinLowEdge(calibbasehisto->GetXaxis()->GetFirst());
245 size_t lastTsIdx = calibbasehisto->GetXaxis()->GetBinUpEdge(calibbasehisto->GetXaxis()->GetLast());
248 size_t nchannels = calibbasehisto->GetNbinsY();
249 size_t firstChannel = calibbasehisto->GetYaxis()->GetBinLowEdge(calibbasehisto->GetYaxis()->GetFirst());
250 size_t lastChannel = calibbasehisto->GetYaxis()->GetBinUpEdge(calibbasehisto->GetYaxis()->GetLast());
252 std::shared_ptr<TH2I> calibhisto = std::make_shared<TH2I>(
"calibhisto",
"calibhisto", nevents, firstTsIdx, lastTsIdx,
253 nchannels, firstChannel, lastChannel);
256 for (
size_t itsidx = 1; itsidx < nevents; itsidx++) {
257 for (
size_t ichannel = 1; ichannel < nchannels; ichannel++) {
258 auto dominantshift =
GetDominantShift(calibbasehisto, itsidx, ichannel) < 255
260 : calibhisto->GetBinContent(itsidx - 1, ichannel);
261 if (itsidx - 1 == 0) dominantshift = 0;
262 calibhisto->SetBinContent(itsidx, ichannel, dominantshift);
271 auto hdomshift = calibbasehisto->ProjectionZ(
"domshift", itsidx, itsidx, ichannel, ichannel);
274 hdomshift->Scale(1. / hdomshift->Integral());
276 auto domshift = hdomshift->GetBinCenter(hdomshift->GetMaximumBin());
277 auto dominance = hdomshift->GetMaximum();
ClassImp(CbmConverterManager)
void putParams(FairParamList *)
std::map< size_t, std::vector< Int_t > > fmapTimeshifts
std::vector< Int_t > GetTimeshiftsVec(size_t tsidx)
Return the timeshift vector for a given Timeslice Index. Works only if getParams() was run before.
bool FillTimeshiftArray(std::shared_ptr< TFile > mcbmanafile)
Extract the timeshift values from a TAF output file that contains the required histograms and write t...
const std::vector< std::string > pararraynames
Names of the parameter arrays.
std::vector< Int_t > fvecCurrentTimeshifts
< Keys of the map are the tsIdx when a shift value for any channel changes, the vector contains the s...
std::shared_ptr< TH3 > GetCalibHisto(std::shared_ptr< TFile > mcbmanafile)
Extract the required base histogram from a mcbmana task output file.
TArrayI fTimeshifts
Array contains the timeshifts. Everytime a timeshift appears the tsIdx from the TS MetaData is follow...
Int_t GetDominantShift(std::shared_ptr< TH3 > calibbasehisto, size_t itsidx, size_t ichannel)
Extract the dominant shift value from the calibbase histogram. For a give tsIdx and channel.
virtual void printparams()
double GetNEvents(std::shared_ptr< TFile > mcbmanafile)
Extract the number of events from a mcbmana task output file, which has to contain the required histo...
Bool_t getParams(FairParamList *)
const size_t fgNchannels
Number of channels on the single Trd module used during mCbm2020.
bool GetTimeshifts(std::shared_ptr< TH2 > timeshiftHisto)
Extract the timeshift values from a histo containing the information and write them to fTimeshifts.
virtual ~CbmMcbm2020TrdTshiftPar()
TArrayI fNtimeslices
Number of timeslices in the given run. This is required to fill a complete fmapTimeshifts,...
const UInt_t fgMicroSliceLength
Length of a single microslice during mCbm 2020 data taking.
CbmMcbm2020TrdTshiftPar(const char *name="CbmMcbm2020TrdTshiftPar", const char *title="TRD timeshift unpacker parameters mCbm 2020", const char *context="Default")