diff --git a/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx b/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx index a9f8a9e8bfe2363d67f663138f2c05708a22e3d1..daf829d509afdd7125f37c97b1235383a8cdf7b1 100644 --- a/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx +++ b/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx @@ -645,6 +645,9 @@ const CbmPsdDigi* CbmAlgoBuildRawEvents::GetDigi(UInt_t uDigi) //---------------------------------------------------------------------- void CbmAlgoBuildRawEvents::CreateHistograms() { + outFolder = new TFolder("AlgoBuildRawEventsHist", " AlgoBuildRawEvents Histos"); + outFolder->Clear(); + fhEventTime = new TH1F("hEventTime", "seed time of the events; Seed time [s]; Events", 1000, 0, 0.001); fhEventTime->SetCanExtend(TH1::kAllAxes); @@ -681,10 +684,17 @@ void CbmAlgoBuildRawEvents::CreateHistograms() AddHistoToVector(fhEventDt, "evtbuild"); AddHistoToVector(fhEventSize, "evtbuild"); AddHistoToVector(fhNbDigiPerEvtTime, "evtbuild"); + outFolder->Add(fhEventTime); + outFolder->Add(fhEventDt); + outFolder->Add(fhEventSize); + outFolder->Add(fhNbDigiPerEvtTime); for (std::vector<TH2*>::iterator itHist = fvhNbDigiPerEvtTimeDet.begin(); itHist != fvhNbDigiPerEvtTimeDet.end(); ++itHist) { - if (nullptr != (*itHist)) { AddHistoToVector((*itHist), "evtbuild"); } + if (nullptr != (*itHist)) { + AddHistoToVector((*itHist), "evtbuild"); + outFolder->Add((*itHist)); + } } } diff --git a/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.h b/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.h index 7fc6cd8cde463c39f29c5c2993e74a7b517e294c..93276186101638af11d2c03e91b20f59f1b03bfc 100644 --- a/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.h +++ b/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.h @@ -198,6 +198,9 @@ public: fTimeSliceMetaDataArray = TimeSliceMetaDataArray; } + // Output folder for histograms + TFolder* GetOutFolder() { return outFolder; } + /// Data output access std::vector<CbmEvent*>& GetEventVector() { return fEventVector; } void ClearEventVector(); @@ -228,6 +231,8 @@ private: void UpdateTimeWinBoundariesExtrema(); void UpdateWidestTimeWinRange(); + TFolder* outFolder; // oputput folder to store histograms + /// Constants static constexpr Double_t kdDefaultTimeWinBeg = -100.0; static constexpr Double_t kdDefaultTimeWinEnd = 100.0; diff --git a/reco/eventbuilder/digis/CbmBuildEventsQA.cxx b/reco/eventbuilder/digis/CbmBuildEventsQA.cxx index 8f0e87f41fc871f56b6a8e1311f1ebb50a708149..84c87f37c4af7400502be085d157efb8c0035758 100644 --- a/reco/eventbuilder/digis/CbmBuildEventsQA.cxx +++ b/reco/eventbuilder/digis/CbmBuildEventsQA.cxx @@ -270,13 +270,6 @@ void CbmBuildEventsQA::MatchEvent(CbmEvent* event) void CbmBuildEventsQA::Finish() { //output histograms - fhCorrectDigiRatioAll->DrawCopy("colz", ""); - fhFoundDigiRatioAll->DrawCopy("colz", ""); - for (ECbmModuleId& system : fSystems) { - fhMapSystemsCorrectDigi[system]->DrawCopy("colz", ""); - fhMapSystemsFoundDigi[system]->DrawCopy("colz", ""); - } - if (!FairRootManager::Instance() || !FairRootManager::Instance()->GetSink()) { LOG(error) << "No sink found"; return; diff --git a/reco/eventbuilder/digis/CbmTaskBuildRawEvents.cxx b/reco/eventbuilder/digis/CbmTaskBuildRawEvents.cxx index 83e9db5f5c3900464e3babbff95d73e33f245e17..ce0640c01126f5f6133f1d1fea8ac664bb828388 100644 --- a/reco/eventbuilder/digis/CbmTaskBuildRawEvents.cxx +++ b/reco/eventbuilder/digis/CbmTaskBuildRawEvents.cxx @@ -382,33 +382,44 @@ void CbmTaskBuildRawEvents::FillOutput() void CbmTaskBuildRawEvents::SaveHistos() { - /// Obtain vector of pointers on each histo from the algo (+ optionally desired folder) - std::vector<std::pair<TNamed*, std::string>> vHistos = fpAlgo->GetHistoVector(); - - /// (Re-)Create ROOT file to store the histos - TDirectory* oldDir = NULL; - TFile* histoFile = NULL; - /// Store current directory position to allow restore later - oldDir = gDirectory; - /// open separate histo file in recreate mode - histoFile = new TFile(fsOutFileName, "RECREATE"); - histoFile->cd(); - - /// Save all plots and create folders if needed - for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) { - /// Make sure we end up in chosen folder - const TString sFolder = vHistos[uHisto].second.data(); - if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder); - gDirectory->cd(sFolder); - - /// Write plot - vHistos[uHisto].first->Write(); - histoFile->cd(); + if (fbWriteHistosToFairSink) { + if (!FairRootManager::Instance() || !FairRootManager::Instance()->GetSink()) { + LOG(error) << "No sink found"; + return; + } + FairSink* sink = FairRootManager::Instance()->GetSink(); + sink->WriteObject(fpAlgo->GetOutFolder(), nullptr); } + else { + + /// Obtain vector of pointers on each histo from the algo (+ optionally desired folder) + std::vector<std::pair<TNamed*, std::string>> vHistos = fpAlgo->GetHistoVector(); + + /// (Re-)Create ROOT file to store the histos + TDirectory* oldDir = NULL; + TFile* histoFile = NULL; + /// Store current directory position to allow restore later + oldDir = gDirectory; + /// open separate histo file in recreate mode + histoFile = new TFile(fsOutFileName, "RECREATE"); + histoFile->cd(); + + /// Save all plots and create folders if needed + for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) { + /// Make sure we end up in chosen folder + const TString sFolder = vHistos[uHisto].second.data(); + if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder); + gDirectory->cd(sFolder); - /// Restore original directory position - oldDir->cd(); - histoFile->Close(); + /// Write plot + vHistos[uHisto].first->Write(); + histoFile->cd(); + } + + /// Restore original directory position + oldDir->cd(); + histoFile->Close(); + } } diff --git a/reco/eventbuilder/digis/CbmTaskBuildRawEvents.h b/reco/eventbuilder/digis/CbmTaskBuildRawEvents.h index c896aa3a8e581faf5c412d4f07fd25562c0d94ab..aa683472f5fb9d970f96f99c5ebb14c3fb8d839f 100644 --- a/reco/eventbuilder/digis/CbmTaskBuildRawEvents.h +++ b/reco/eventbuilder/digis/CbmTaskBuildRawEvents.h @@ -67,6 +67,7 @@ public: /** Setters **/ void SetOutFilename(TString sNameIn) { fsOutFileName = sNameIn; } + void SetWriteHistosToFairSink(Bool_t var) { fbWriteHistosToFairSink = var; } void SetFillHistos(Bool_t bFlag = kTRUE) { @@ -148,7 +149,8 @@ private: TClonesArray* fEvents = nullptr; //! output container of CbmEvents - Bool_t fbFillHistos {kTRUE}; //! Switch ON/OFF filling of histograms + Bool_t fbFillHistos {kTRUE}; //! Switch ON/OFF filling of histograms + Bool_t fbWriteHistosToFairSink {kTRUE}; //! Write histos to FairRootManager instead of separate file /** Name of the histogram output file **/ TString fsOutFileName {"data/HistosEvtWin.root"};