2 // ********************************************************************
 
    3 // * License and Disclaimer                                           *
 
    5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
 
    6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
 
    7 // * conditions of the Geant4 Software License,  included in the file *
 
    8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
 
    9 // * include a list of copyright holders.                             *
 
   11 // * Neither the authors of this software system, nor their employing *
 
   12 // * institutes,nor the agencies providing financial support for this *
 
   13 // * work  make  any representation or  warranty, express or implied, *
 
   14 // * regarding  this  software system or assume any liability for its *
 
   15 // * use.  Please see the license in the file  LICENSE  and URL above *
 
   16 // * for the full disclaimer and the limitation of liability.         *
 
   18 // * This  code  implementation is the result of  the  scientific and *
 
   19 // * technical work of the GEANT4 collaboration.                      *
 
   20 // * By using,  copying,  modifying or  distributing the software (or *
 
   21 // * any work based  on the software)  you  agree  to acknowledge its *
 
   22 // * use  in  resulting  scientific  publications,  and indicate your *
 
   23 // * acceptance of all terms of the Geant4 Software license.          *
 
   24 // ********************************************************************
 
   26 // $Id: G4THnManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
 
   28 // Author: Ivana Hrivnacova, 23/06/2015  (ivana@ipno.in2p3.fr)
 
   30 #include "G4AnalysisManagerState.hh"
 
   31 #include "G4HnManager.hh"
 
   32 #include "G4AnalysisUtilities.hh"
 
   36 //_____________________________________________________________________________
 
   38 G4THnManager<T>::G4THnManager(const G4AnalysisManagerState& state,
 
   39                               const G4String& hnType)
 
   45   fHnManager = std::make_shared<G4HnManager>(hnType, state);
 
   48 //_____________________________________________________________________________
 
   50 G4THnManager<T>::~G4THnManager()
 
   52   for ( auto t : fTVector ) {
 
   61 //_____________________________________________________________________________
 
   63 T*  G4THnManager<T>::GetTInFunction(G4int id, 
 
   64                                     G4String functionName, G4bool warn,
 
   65                                     G4bool onlyIfActive) const
 
   67   G4int index = id - fHnManager->GetFirstId();
 
   68   if ( index < 0 || index >= G4int(fTVector.size()) ) {
 
   70       G4String inFunction = "G4THnManager::";
 
   71       inFunction += functionName;
 
   72       G4ExceptionDescription description;
 
   73       description << "      " << "histogram " << id << " does not exist.";
 
   74       G4Exception(inFunction, "Analysis_W011", JustWarning, description);
 
   79   // Do not return histogram if inactive 
 
   80   if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) {
 
   84   return fTVector[index];
 
   87 //_____________________________________________________________________________
 
   89 G4int G4THnManager<T>::RegisterT(T* t, const G4String& name)
 
   91   G4int index = fTVector.size();
 
   92   fTVector.push_back(t);
 
   94   fHnManager->SetLockFirstId(true);
 
   95   fNameIdMap[name] = index + fHnManager->GetFirstId();
 
   96   return index + fHnManager->GetFirstId();
 
   99 //_____________________________________________________________________________
 
  100 template <typename T>
 
  101 G4int  G4THnManager<T>::GetTId(const G4String& name, G4bool warn) const
 
  103   auto it = fNameIdMap.find(name);
 
  104   if ( it ==  fNameIdMap.end() ) {  
 
  106       G4String inFunction = "G4THnManager::GetH1Id";
 
  107       G4ExceptionDescription description;
 
  108       description << "      " << "histogram " << name << " does not exist.";
 
  109       G4Exception(inFunction, "Analysis_W011", JustWarning, description);
 
  111     return G4Analysis::kInvalidId;         
 
  116 //_____________________________________________________________________________
 
  117 template <typename T>
 
  118 void G4THnManager<T>::AddTVector(const std::vector<T*>& tVector)
 
  121     if ( fState.GetVerboseL4() ) 
 
  122       fState.GetVerboseL4()->Message("merge", "all " + fHnManager->GetHnType(), "");
 
  124   // std::vector<tools::histo::h1d*>::const_iterator itw = h1Vector.begin();
 
  125   // std::vector<tools::histo::h1d*>::iterator it;
 
  126   // for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
 
  127   //   (*it)->add(*(*itw++));
 
  129   auto itw = tVector.begin();
 
  130   for ( auto t : fTVector ) {
 
  134     if ( fState.GetVerboseL1() ) 
 
  135       fState.GetVerboseL1()->Message("merge", "all " + fHnManager->GetHnType(), "");
 
  139 //_____________________________________________________________________________
 
  140 template <typename T>
 
  141 typename std::vector<T*>::iterator G4THnManager<T>::BeginT()
 
  143   return fTVector.begin(); 
 
  146 //_____________________________________________________________________________
 
  147 template <typename T>
 
  148 typename std::vector<T*>::iterator G4THnManager<T>::EndT()
 
  150   return fTVector.end(); 
 
  153 //_____________________________________________________________________________
 
  154 template <typename T>
 
  155 typename std::vector<T*>::const_iterator G4THnManager<T>::BeginConstT() const
 
  157   return fTVector.begin(); 
 
  160 //_____________________________________________________________________________
 
  161 template <typename T>
 
  162 typename std::vector<T*>::const_iterator G4THnManager<T>::EndConstT() const
 
  164   return fTVector.end(); 
 
  171 //_____________________________________________________________________________
 
  172 template <typename T>
 
  173 G4bool G4THnManager<T>::Reset()
 
  175 // Reset histograms and ntuple
 
  177   G4bool finalResult = true;
 
  179   for ( auto t : fTVector ) {
 
  180     G4bool result = t->reset();
 
  181     if ( ! result ) finalResult = false;
 
  187 //_____________________________________________________________________________
 
  188 template <typename T>
 
  189 G4bool G4THnManager<T>::IsEmpty() const
 
  191   return ! fTVector.size();