Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 08:13:24

0001 
0002 /*!
0003  * \file TpcDistortionCorrectionContainer.cc
0004  * \brief stores distortion correction histograms on the node tree
0005  * \author Hugo Pereira Da Costa <hugo.pereira-da-costa@cea.fr>
0006  */
0007 
0008 #include "TpcDistortionCorrectionContainer.h"
0009 
0010 #include <TFile.h>
0011 #include <TH1.h>
0012 #include <TObject.h>
0013 
0014 #include <iostream>
0015 #include <memory>
0016 
0017 //_______________________________________________________________
0018 void TpcDistortionCorrectionContainer::load_histograms( const std::string& source )
0019 {
0020   std::cout << "TpcDistortionCorrectionContainer::load_histograms - reading corrections from " << source << std::endl;
0021   auto *distortion_tfile = TFile::Open(source.c_str());
0022   if (!distortion_tfile)
0023   {
0024     std::cout << "TpcDistortionCorrectionContainer::load_histograms - cannot open " << source << std::endl;
0025     exit(1);
0026   }
0027 
0028   const std::array<const std::string, 2> extension = {{"_negz", "_posz"}};
0029   for (int j = 0; j < 2; ++j)
0030   {
0031     m_hDPint[j] = dynamic_cast<TH1*>(distortion_tfile->Get((std::string("hIntDistortionP")+extension[j]).c_str()));
0032     assert(m_hDPint[j]);
0033     m_hDRint[j] = dynamic_cast<TH1*>(distortion_tfile->Get((std::string("hIntDistortionR")+extension[j]).c_str()));
0034     assert(m_hDRint[j]);
0035     m_hDZint[j] = dynamic_cast<TH1*>(distortion_tfile->Get((std::string("hIntDistortionZ")+extension[j]).c_str()));
0036     assert(m_hDZint[j]);
0037   }
0038 }
0039 
0040 //_______________________________________________________________
0041 void TpcDistortionCorrectionContainer::save_histograms( const std::string& destination ) const
0042 {
0043   // save everything to root file
0044   std::cout << "TpcDistortionCorrectionContainer::save_histograms - writing histograms to " << destination << std::endl;
0045   std::unique_ptr<TFile> outputfile(TFile::Open(destination.c_str(), "RECREATE"));
0046   outputfile->cd();
0047 
0048   for (const auto& h_list : {m_hentries, m_hDRint, m_hDPint, m_hDZint})
0049   {
0050     for (const auto& h : h_list)
0051     {
0052       if (h)
0053       {
0054         h->Write(h->GetName());
0055       }
0056     }
0057   }
0058 
0059   // close TFile
0060   outputfile->Close();
0061 }