G4RootAnalysisManager.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 
00028 // Author: Ivana Hrivnacova, 15/06/2011  (ivana@ipno.in2p3.fr)
00029 
00030 #include "G4RootAnalysisManager.hh"
00031 #include "G4UnitsTable.hh"
00032 
00033 #include <iostream>
00034 
00035 G4RootAnalysisManager* G4RootAnalysisManager::fgInstance = 0;
00036 
00037 //_____________________________________________________________________________
00038 G4RootAnalysisManager* G4RootAnalysisManager::Instance()
00039 {
00040   if ( fgInstance == 0 ) {
00041     fgInstance = new G4RootAnalysisManager();
00042   }
00043   
00044   return fgInstance;
00045 }    
00046 
00047 //_____________________________________________________________________________
00048 G4RootAnalysisManager::G4RootAnalysisManager()
00049  : G4VAnalysisManager("Root"),
00050    fFile(0),
00051    fHistoDirectory(0),
00052    fNtupleDirectory(0),
00053    fH1Vector(),   
00054    fH2Vector(), 
00055    fH1NameIdMap(),  
00056    fH2NameIdMap(),  
00057    fNtuple(0),
00058    fNtupleBooking(0),
00059    fNtupleIColumnMap(),
00060    fNtupleFColumnMap(),
00061    fNtupleDColumnMap()
00062 {
00063   if ( fgInstance ) {
00064     G4ExceptionDescription description;
00065     description << "      " 
00066                 << "G4RootAnalysisManager already exists." 
00067                 << "Cannot create another instance.";
00068     G4Exception("G4RootAnalysisManager::G4RootAnalysisManager()",
00069                 "Analysis_F001", FatalException, description);
00070   }              
00071    
00072   fgInstance = this;
00073 }
00074 
00075 //_____________________________________________________________________________
00076 G4RootAnalysisManager::~G4RootAnalysisManager()
00077 {  
00078   std::vector<tools::histo::h1d*>::iterator it;
00079   for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
00080     delete (*it);
00081   }  
00082   
00083   std::vector<tools::histo::h2d*>::iterator it2;
00084   for (it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
00085     delete (*it2);
00086   }  
00087 
00088   delete fNtuple;
00089   delete fNtupleBooking;
00090   delete fFile;  
00091 
00092   fgInstance = 0;
00093 }
00094 
00095 // 
00096 // private methods
00097 //
00098 
00099 //_____________________________________________________________________________
00100 G4bool G4RootAnalysisManager::CreateHistoDirectory()
00101 {
00102   if ( fHistoDirectoryName == "" ) {
00103     // Do not create a new directory if its name is not set
00104     fHistoDirectory = &(fFile->dir());
00105     return true;
00106   }  
00107   
00108 #ifdef G4VERBOSE
00109   if ( fpVerboseL4 ) 
00110     fpVerboseL4->Message("create", "directory for histograms", fHistoDirectoryName);
00111 #endif
00112   
00113   fHistoDirectory = fFile->dir().mkdir(fHistoDirectoryName);
00114   if ( ! fHistoDirectory ) {
00115     G4ExceptionDescription description;
00116     description << "      " 
00117                 << "cannot create directory " << fHistoDirectoryName;
00118     G4Exception("G4RootAnalysisManager::CreateHistoDirectory()",
00119               "Analysis_W002", JustWarning, description);
00120     return false;       
00121   }       
00122 #ifdef G4VERBOSE
00123   else {
00124     if ( fpVerboseL2 ) 
00125       fpVerboseL2->Message("create", "directory for histograms", fHistoDirectoryName);
00126   }    
00127 #endif
00128   return true;
00129 }
00130 
00131 //_____________________________________________________________________________
00132 G4bool G4RootAnalysisManager::CreateNtupleDirectory()
00133 {
00134   if ( fNtupleDirectoryName == "" ) {
00135     // Do not create a new directory if its name is not set
00136     fNtupleDirectory = &(fFile->dir());
00137     return true;
00138   }  
00139   
00140 #ifdef G4VERBOSE
00141   if ( fpVerboseL4 ) 
00142     fpVerboseL4
00143       ->Message("create", "directory for ntuples", fNtupleDirectoryName);
00144 #endif
00145 
00146   fNtupleDirectory = fFile->dir().mkdir(fNtupleDirectoryName);
00147   if ( ! fNtupleDirectory ) {
00148     G4ExceptionDescription description;
00149     description << "      " 
00150                 << "cannot create directory " << fNtupleDirectoryName;
00151     G4Exception("G4RootAnalysisManager::CreateNtupleDirectory()",
00152                 "Analysis_W002", JustWarning, description);
00153     return false;       
00154   }       
00155 #ifdef G4VERBOSE
00156   else {
00157     if ( fpVerboseL2 ) 
00158       fpVerboseL2
00159         ->Message("create", "directory for ntuples", fNtupleDirectoryName);
00160   }    
00161 #endif
00162   return true;
00163 }
00164 
00165 //_____________________________________________________________________________
00166 void G4RootAnalysisManager::CreateNtupleFromBooking()
00167 {
00168 // Create ntuple from ntuple_booking.
00169 
00170   if ( fNtuple || (! fNtupleBooking) ) return;       
00171 
00172 #ifdef G4VERBOSE
00173   if ( fpVerboseL4 ) 
00174     fpVerboseL4->Message("create from booking", "ntuple", fNtupleBooking->m_name);
00175 #endif
00176   fNtuple = new tools::wroot::ntuple(*fNtupleDirectory, *fNtupleBooking);
00177   
00178   if ( fNtupleBooking->m_columns.size() ) {
00179     // store ntuple columns in local maps
00180     const std::vector<tools::ntuple_booking::col_t>& columns 
00181       = fNtupleBooking->m_columns;
00182     std::vector<tools::ntuple_booking::col_t>::const_iterator it;
00183     G4int index = 0;
00184     for ( it = columns.begin(); it!=columns.end(); ++it) {
00185       if ( (*it).second == tools::_cid(int(0) ) ) {
00186         G4cout << "adding int " << fNtuple->find_column<int>((*it).first) << G4endl;
00187         fNtupleIColumnMap[index++] = fNtuple->find_column<int>((*it).first);
00188       }
00189       else if( (*it).second == tools::_cid(float(0) ) ) {
00190         fNtupleFColumnMap[index++] = fNtuple->find_column<float>((*it).first);
00191       } 
00192       else if((*it).second== tools::_cid(double(0))) {
00193         fNtupleDColumnMap[index++] = fNtuple->find_column<double>((*it).first);
00194       }
00195       else {
00196         G4ExceptionDescription description;
00197         description << "      " 
00198                     << "Unsupported column type " << (*it).first;
00199         G4Exception("G4RootAnalysisManager::CreateNtupleFromBooking()",
00200                     "Analysis_W004", JustWarning, description);
00201       }
00202     }
00203   }
00204 }   
00205 
00206 //_____________________________________________________________________________
00207 tools::wroot::ntuple::column<int>*    
00208 G4RootAnalysisManager::GetNtupleIColumn(G4int id) const
00209 {
00210   std::map<G4int, tools::wroot::ntuple::column<int>* >::const_iterator it
00211     = fNtupleIColumnMap.find(id);
00212   if ( it == fNtupleIColumnMap.end() ) {
00213     G4ExceptionDescription description;
00214     description << "      " << "column " << id << " does not exist.";
00215     G4Exception("G4RootAnalysisManager::GetNtupleIColumn()",
00216                 "Analysis_W009", JustWarning, description);
00217     return 0;
00218   }
00219   
00220   return it->second;
00221 }  
00222     
00223 //_____________________________________________________________________________
00224 tools::wroot::ntuple::column<float>*  
00225 G4RootAnalysisManager::GetNtupleFColumn(G4int id) const
00226 {
00227   std::map<G4int, tools::wroot::ntuple::column<float>* >::const_iterator it
00228     = fNtupleFColumnMap.find(id);
00229   if ( it == fNtupleFColumnMap.end() ) {
00230     G4ExceptionDescription description;
00231     description << "      " << "column " << id << " does not exist.";
00232     G4Exception("G4RootAnalysisManager::GetNtupleFColumn()",
00233                 "Analysis_W009", JustWarning, description);
00234     return 0;
00235   }
00236   
00237   return it->second;
00238 }  
00239 
00240 
00241 //_____________________________________________________________________________
00242 tools::wroot::ntuple::column<double>* 
00243 G4RootAnalysisManager::GetNtupleDColumn(G4int id) const
00244 {
00245   std::map<G4int, tools::wroot::ntuple::column<double>* >::const_iterator it
00246     = fNtupleDColumnMap.find(id);
00247   if ( it == fNtupleDColumnMap.end() ) {
00248     G4ExceptionDescription description;
00249     description << "      " << "column " << id << " does not exist.";
00250     G4Exception("G4RootAnalysisManager::GetNtupleDColumn()",
00251                 "Analysis_W009", JustWarning, description);
00252     return 0;
00253   }
00254   
00255   return it->second;
00256 }  
00257  
00258 //_____________________________________________________________________________
00259 G4bool G4RootAnalysisManager::Reset()
00260 {
00261 // Reset histograms and ntuple
00262 
00263   G4bool finalResult = true;
00264 
00265   std::vector<tools::histo::h1d*>::iterator it;
00266   for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
00267     G4bool result = (*it)->reset();
00268     if ( ! result ) finalResult = false;
00269   }  
00270   
00271   std::vector<tools::histo::h2d*>::iterator it2;
00272   for (it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
00273     G4bool result = (*it2)->reset();
00274     if ( ! result ) finalResult = false;
00275   }  
00276   
00277   // ntuple is deleted automatically when file is closed
00278   //delete fNtuple;
00279   fNtuple = 0;
00280   
00281   return finalResult;
00282 }  
00283  
00284 //_____________________________________________________________________________
00285 void G4RootAnalysisManager::UpdateTitle(G4String& title, 
00286                                         const G4String& unitName, 
00287                                         const G4String& fcnName) const
00288 {
00289   if ( fcnName != "none" )  { title += " "; title += fcnName; title += "("; }
00290   if ( unitName != "none" ) { title += " ["; title += unitName; title += "]";}
00291   if ( fcnName != "none" )  { title += ")"; }
00292 }  
00293                                                           
00294 //
00295 // protected methods
00296 //
00297 
00298 //_____________________________________________________________________________
00299 G4bool G4RootAnalysisManager::WriteOnAscii(std::ofstream& output)
00300 {
00301 // Write selected objects on ASCII file
00302 // (Only H1 implemented by now)
00303 // According to the implementation by Michel Maire, originally in
00304 // extended examples.
00305 
00306   // h1 histograms
00307   for ( G4int i=0; i<G4int(fH1Vector.size()); ++i ) {
00308     G4int id = i + fFirstHistoId;
00309     G4HnInformation* info = GetH1Information(id); 
00310     // skip writing if activation is enabled and H1 is inactivated
00311     if ( ! info->fAscii ) continue; 
00312     tools::histo::h1d* h1 = fH1Vector[i];
00313 
00314 #ifdef G4VERBOSE
00315     if ( fpVerboseL3 ) 
00316       fpVerboseL3->Message("write on ascii", "h1d", info->fName);
00317 #endif
00318   
00319     output << "\n  1D histogram " << id << ": " << h1->title() 
00320            << "\n \n \t     X \t\t     Y" << G4endl;
00321     
00322     for (G4int j=0; j< G4int(h1->axis().bins()); ++j) {
00323        output << "  " << j << "\t" 
00324               << h1->axis().bin_center(j) << "\t"
00325               << h1->bin_height(i) << G4endl;
00326     } 
00327   }
00328   
00329   return true;
00330 }  
00331 
00332 //_____________________________________________________________________________
00333 tools::histo::h1d*  G4RootAnalysisManager::GetH1InFunction(G4int id, 
00334                                       G4String functionName, G4bool warn,
00335                                       G4bool onlyIfActive) const
00336 {
00337   G4int index = id - fFirstHistoId;
00338   if ( index < 0 || index >= G4int(fH1Vector.size()) ) {
00339     if ( warn) {
00340       G4String inFunction = "G4RootAnalysisManager::";
00341       inFunction += functionName;
00342       G4ExceptionDescription description;
00343       description << "      " << "histogram " << id << " does not exist.";
00344       G4Exception(inFunction, "Analysis_W007", JustWarning, description);
00345     }
00346     return 0;         
00347   }
00348   
00349   // Do not return histogram if inactive 
00350   if ( fActivation && onlyIfActive && ( ! GetActivation(kH1, id) ) ) {
00351     return 0; 
00352   }  
00353   
00354   return fH1Vector[index];
00355 }  
00356                                       
00357 //_____________________________________________________________________________
00358 tools::histo::h2d*  G4RootAnalysisManager::GetH2InFunction(G4int id, 
00359                                       G4String functionName, G4bool warn,
00360                                       G4bool onlyIfActive) const
00361 {                                      
00362   G4int index = id - fFirstHistoId;
00363   if ( index < 0 || index >= G4int(fH2Vector.size()) ) {
00364     if ( warn) {
00365       G4String inFunction = "G4RootAnalysisManager::";
00366       inFunction += functionName;
00367       G4ExceptionDescription description;
00368       description << "      " << "histogram " << id << " does not exist.";
00369       G4Exception(inFunction, "Analysis_W007", JustWarning, description);
00370     }
00371     return 0;         
00372   }
00373 
00374   // Do not return histogram if inactive 
00375   if ( fActivation  && onlyIfActive && ( ! GetActivation(kH2, id) ) ) {
00376     return 0; 
00377   }  
00378   
00379   return fH2Vector[index];
00380 }
00381   
00382 // 
00383 // public methods
00384 //
00385 
00386 //_____________________________________________________________________________
00387 G4bool G4RootAnalysisManager::OpenFile(const G4String& fileName)
00388 {
00389   // Keep file name
00390   fFileName =  fileName;
00391 
00392   // Add file extension .root if no extension is given
00393   G4String name(fileName);
00394   if ( name.find(".") == std::string::npos ) { 
00395     name.append(".");
00396     name.append(GetFileType());
00397   }  
00398   
00399 #ifdef G4VERBOSE
00400   if ( fpVerboseL4 ) 
00401     fpVerboseL4->Message("open", "analysis file", name);
00402 #endif
00403 
00404   // delete previous file if exists
00405   if ( fFile ) delete fFile;
00406   
00407   fFile = new tools::wroot::file(std::cout, name);
00408   if ( ! fFile->is_open() ) {
00409     G4ExceptionDescription description;
00410     description << "      " << "Cannot open file " << fileName;
00411     G4Exception("G4RootAnalysisManager::OpenFile()",
00412                 "Analysis_W001", JustWarning, description);
00413     return false;
00414   }
00415 
00416   // Create directories
00417   if ( ! CreateHistoDirectory() ) return false;
00418   if ( ! CreateNtupleDirectory() ) return false;
00419   
00420   // Create ntuple if it is booked
00421   if ( fNtupleBooking && ( ! fNtuple ) ) 
00422     CreateNtupleFromBooking();
00423   
00424   fLockFileName = true;
00425   fLockHistoDirectoryName = true;
00426   fLockNtupleDirectoryName = true;
00427 
00428 #ifdef G4VERBOSE
00429   if ( fpVerboseL1 ) 
00430     fpVerboseL1->Message("open", "analysis file", name);
00431 #endif
00432   
00433   return true;
00434 }  
00435   
00436 //_____________________________________________________________________________
00437 G4bool G4RootAnalysisManager::Write() 
00438 {
00439   // h1 histograms
00440   for ( G4int i=0; i<G4int(fH1Vector.size()); ++i ) {
00441     G4int id = i + fFirstHistoId;
00442     G4HnInformation* info = GetH1Information(id); 
00443     // skip writing if activation is enabled and H1 is inactivated
00444     if ( fActivation && ( ! info->fActivation ) ) continue; 
00445     tools::histo::h1d* h1 = fH1Vector[i];
00446 #ifdef G4VERBOSE
00447     if ( fpVerboseL3 ) 
00448       fpVerboseL3->Message("write", "h1d", info->fName);
00449 #endif
00450     G4bool result
00451       = to(*fHistoDirectory,*h1,info->fName);
00452     if ( ! result ) {
00453       G4ExceptionDescription description;
00454       description << "      " << "saving histogram " << info->fName << " failed";
00455       G4Exception("G4RootAnalysisManager::Write()",
00456                 "Analysis_W003", JustWarning, description);
00457       return false;       
00458     } 
00459   }
00460 
00461   // h2 histograms
00462   for ( G4int i=0; i<G4int(fH2Vector.size()); ++i ) {
00463     G4int id = i + fFirstHistoId;
00464     G4HnInformation* info = GetH2Information(id); 
00465     // skip writing if inactivated
00466     if ( fActivation && ( ! info->fActivation ) ) continue;
00467     tools::histo::h2d* h2 = fH2Vector[i];
00468 #ifdef G4VERBOSE
00469     if ( fpVerboseL3 ) 
00470       fpVerboseL3->Message("write", "h2d", info->fName);
00471 #endif
00472     G4bool result
00473       = to(*fHistoDirectory,*h2,info->fName);
00474     if ( ! result ) {
00475       G4ExceptionDescription description;
00476       description << "      " << "saving histogram " << info->fName << " failed";
00477       G4Exception("G4RootAnalysisManager::Write()",
00478                 "Analysis_W003", JustWarning, description);
00479       return false;       
00480     } 
00481   }
00482 
00483 #ifdef G4VERBOSE
00484   if ( fpVerboseL4 ) 
00485     fpVerboseL4->Message("write", "file", GetFullFileName());
00486 #endif
00487 
00488   unsigned int n;
00489   G4bool result = fFile->write(n);
00490 
00491 #ifdef G4VERBOSE
00492   if ( fpVerboseL1 ) 
00493     fpVerboseL1->Message("write", "file", GetFullFileName(), result);
00494 #endif
00495 
00496   // Write ASCII if activated
00497   if ( IsAscii() ) {
00498     G4bool result2 = WriteAscii();
00499     result = result && result2;
00500   }   
00501 
00502   return result;
00503 }
00504 
00505 //_____________________________________________________________________________
00506 G4bool G4RootAnalysisManager::CloseFile()
00507 {
00508   G4bool result = true;
00509 
00510 #ifdef G4VERBOSE
00511   if ( fpVerboseL4 ) 
00512     fpVerboseL4->Message("close", "file", GetFullFileName());
00513 #endif
00514 
00515   // reset data
00516   result = Reset();
00517   if ( ! result ) {
00518       G4ExceptionDescription description;
00519       description << "      " << "Resetting data failed";
00520       G4Exception("G4RootAnalysisManager::Write()",
00521                 "Analysis_W002", JustWarning, description);
00522       result = false;       
00523   } 
00524 
00525   // close file
00526   fFile->close();  
00527   fLockFileName = false;
00528 
00529 #ifdef G4VERBOSE
00530   if ( fpVerboseL1 ) 
00531     fpVerboseL1->Message("close", "file", GetFullFileName());
00532 #endif
00533 
00534   return result;
00535 } 
00536    
00537 //_____________________________________________________________________________
00538 G4int G4RootAnalysisManager::CreateH1(const G4String& name,  const G4String& title,
00539                                G4int nbins, G4double xmin, G4double xmax,
00540                                const G4String& unitName, const G4String& fcnName)
00541 {
00542 #ifdef G4VERBOSE
00543   if ( fpVerboseL4 ) 
00544     fpVerboseL4->Message("create", "H1", name);
00545 #endif
00546   G4int index = fH1Vector.size();
00547   G4double unit = GetUnitValue(unitName);
00548   G4Fcn fcn = GetFunction(fcnName);
00549   tools::histo::h1d* h1 
00550     = new tools::histo::h1d(title, nbins, fcn(xmin), fcn(xmax));
00551             // h1 objects are deleted in destructor and reset when 
00552             // closing a file.
00553 
00554   G4String axisTitle;
00555   UpdateTitle(axisTitle,unitName, fcnName);        
00556   h1->add_annotation(tools::histo::key_axis_x_title(), axisTitle);
00557 
00558   fH1Vector.push_back(h1);
00559   AddH1Information(name, unitName, fcnName, unit, fcn);
00560   
00561   fLockFirstHistoId = true;
00562 #ifdef G4VERBOSE
00563   if ( fpVerboseL2 ) 
00564     fpVerboseL2->Message("create", "H1", name);
00565 #endif
00566   fH1NameIdMap[name] = index + fFirstHistoId;
00567   return index + fFirstHistoId;
00568 }                                         
00569 
00570 //_____________________________________________________________________________
00571 G4int G4RootAnalysisManager::CreateH2(const G4String& name,  const G4String& title,
00572                                G4int nxbins, G4double xmin, G4double xmax,
00573                                G4int nybins, G4double ymin, G4double ymax,
00574                                const G4String& xunitName, const G4String& yunitName,
00575                                const G4String& xfcnName, const G4String& yfcnName)
00576                                
00577 {
00578 #ifdef G4VERBOSE
00579   if ( fpVerboseL4 ) 
00580     fpVerboseL4->Message("create", "H2", name);
00581 #endif
00582   G4int index = fH2Vector.size();
00583   G4double xunit = GetUnitValue(xunitName);
00584   G4double yunit = GetUnitValue(yunitName);
00585   G4Fcn xfcn = GetFunction(xfcnName);
00586   G4Fcn yfcn = GetFunction(yfcnName);
00587   tools::histo::h2d* h2 
00588     = new tools::histo::h2d(title, 
00589                             nxbins, xfcn(xmin), xfcn(xmax), 
00590                             nybins, yfcn(ymin), yfcn(ymax));
00591             // h2 objects are deleted in destructor and reset when 
00592             // closing a file.
00593 
00594   G4String xaxisTitle;
00595   G4String yaxisTitle;
00596   UpdateTitle(xaxisTitle, xunitName, xfcnName);        
00597   UpdateTitle(yaxisTitle, yunitName, yfcnName);        
00598   h2->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
00599   h2->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
00600              
00601   fH2Vector.push_back(h2);
00602   AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName, 
00603                    xunit, yunit, xfcn, yfcn);
00604   
00605   fLockFirstHistoId = true;
00606 #ifdef G4VERBOSE
00607   if ( fpVerboseL2 ) 
00608     fpVerboseL2->Message("create", "H2", name);
00609 #endif
00610   fH2NameIdMap[name] = index + fFirstHistoId;
00611   return index + fFirstHistoId;
00612 }                                         
00613 
00614 //_____________________________________________________________________________
00615 G4bool G4RootAnalysisManager::SetH1(G4int id,
00616                                 G4int nbins, G4double xmin, G4double xmax,
00617                                 const G4String& unitName, const G4String& fcnName)
00618 {                                
00619   tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1", false, false);
00620   if ( ! h1d ) return false;
00621 
00622   G4HnInformation* info = GetH1Information(id);
00623 #ifdef G4VERBOSE
00624   if ( fpVerboseL4 ) 
00625     fpVerboseL4->Message("configure", "H1", info->fName);
00626 #endif
00627 
00628   G4double unit = GetUnitValue(unitName);
00629   G4Fcn fcn = GetFunction(fcnName);
00630   h1d->configure(nbins, fcn(xmin), fcn(xmax));
00631   info->fXUnitName = unitName;
00632   info->fYUnitName = unitName;
00633   info->fXFcnName = fcnName;
00634   info->fYFcnName = fcnName;
00635   info->fXUnit = unit;
00636   info->fYUnit = unit;
00637   info->fXFcn = fcn;
00638   info->fYFcn = fcn;
00639   SetActivation(kH1, id, true); 
00640 
00641   G4String axisTitle;
00642   UpdateTitle(axisTitle,unitName, fcnName);        
00643   h1d->add_annotation(tools::histo::key_axis_x_title(), axisTitle);
00644   
00645   return true;
00646 }
00647   
00648 //_____________________________________________________________________________
00649 G4bool G4RootAnalysisManager::SetH2(G4int id,
00650                                 G4int nxbins, G4double xmin, G4double xmax, 
00651                                 G4int nybins, G4double ymin, G4double ymax,
00652                                 const G4String& xunitName, const G4String& yunitName,
00653                                 const G4String& xfcnName, const G4String& yfcnName)
00654 {                                
00655   tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
00656   if ( ! h2d ) return false;
00657 
00658   G4HnInformation* info = GetH2Information(id);
00659 #ifdef G4VERBOSE
00660   if ( fpVerboseL4 ) 
00661     fpVerboseL4->Message("configure", "H2", info->fName);
00662 #endif
00663 
00664   G4double xunit = GetUnitValue(xunitName);
00665   G4double yunit = GetUnitValue(yunitName);
00666   G4Fcn xfcn = GetFunction(xfcnName);
00667   G4Fcn yfcn = GetFunction(yfcnName);
00668   h2d->configure(nxbins, xfcn(xmin), xfcn(xmax), 
00669                  nybins, yfcn(ymin), yfcn(ymax));
00670 
00671   info->fXUnitName = xunitName;
00672   info->fYUnitName = yunitName;
00673   info->fXFcnName = xfcnName;
00674   info->fYFcnName = yfcnName;
00675   info->fXUnit = xunit;
00676   info->fYUnit = yunit;
00677   info->fXFcn = xfcn;
00678   info->fYFcn = yfcn;
00679   SetActivation(kH2, id, true); 
00680   
00681   G4String xaxisTitle;
00682   G4String yaxisTitle;
00683   UpdateTitle(xaxisTitle, xunitName, xfcnName);        
00684   UpdateTitle(yaxisTitle, yunitName, yfcnName);        
00685   h2d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
00686   h2d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
00687 
00688   return true;
00689 }
00690                                   
00691 //_____________________________________________________________________________
00692 G4bool G4RootAnalysisManager::ScaleH1(G4int id, G4double factor)
00693 {
00694   tools::histo::h1d* h1d = GetH1InFunction(id, "ScaleH1", false, false);
00695   if ( ! h1d ) return false;
00696 
00697   return h1d->scale(factor);
00698 }  
00699 
00700 //_____________________________________________________________________________
00701 G4bool G4RootAnalysisManager::ScaleH2(G4int id, G4double factor)
00702 {
00703   tools::histo::h2d* h2d = GetH2InFunction(id, "ScaleH2", false, false);
00704   if ( ! h2d ) return false;
00705 
00706   return h2d->scale(factor);
00707 }  
00708                            
00709 //_____________________________________________________________________________
00710 void G4RootAnalysisManager::CreateNtuple(const G4String& name, 
00711                                          const G4String& title)
00712 {
00713   if ( fNtupleBooking ) {
00714     G4ExceptionDescription description;
00715     description << "      " 
00716                 << "Ntuple already exists. "
00717                 << "(Only one ntuple is currently supported.)";
00718     G4Exception("G4RootAnalysisManager::CreateNtuple()",
00719                 "Analysis_W006", JustWarning, description);
00720     return;       
00721   }
00722 
00723   // Create a directory if file is open
00724   if ( fFile && ( ! fNtupleDirectory ) ) {
00725     if ( ! CreateNtupleDirectory() ) return;
00726   }
00727   
00728 #ifdef G4VERBOSE
00729   if ( fpVerboseL4 ) 
00730     fpVerboseL4->Message("create", "ntuple", name);
00731 #endif
00732 
00733   // Create ntuple booking
00734   fNtupleBooking = new tools::ntuple_booking();
00735   fNtupleBooking->m_name = name;
00736   fNtupleBooking->m_title = title;
00737            // ntuple booking object is deleted in destructor
00738 
00739   // Create ntuple if the file is open
00740   if ( fFile ) {
00741     fNtuple = new tools::wroot::ntuple(*fNtupleDirectory, name, title);
00742            // ntuple object is deleted automatically when closing a file
00743   }
00744 
00745 #ifdef G4VERBOSE
00746   if ( fpVerboseL2 ) 
00747     fpVerboseL2->Message("create", "ntuple", name);
00748 #endif
00749 }                                         
00750 
00751 //_____________________________________________________________________________
00752 G4int G4RootAnalysisManager::CreateNtupleIColumn(const G4String& name)
00753 {
00754 #ifdef G4VERBOSE
00755   if ( fpVerboseL4 ) 
00756     fpVerboseL4->Message("create", "ntuple I column", name);
00757 #endif
00758 
00759   if ( ! fNtupleBooking ) {
00760     G4ExceptionDescription description;
00761     description << "      " 
00762                 << "Ntuple has to be created first. ";
00763     G4Exception("G4RootAnalysisManager::CreateNtupleIColumn()",
00764                 "Analysis_W005", JustWarning, description);
00765     return -1;       
00766   }
00767 
00768   // Save column info in booking
00769   G4int index = fNtupleBooking->m_columns.size();
00770   fNtupleBooking->add_column<int>(name);  
00771  
00772   // Create column if ntuple already exists
00773   if ( fNtuple ) {
00774     tools::wroot::ntuple::column<int>* column 
00775       = fNtuple->create_column<int>(name);  
00776     fNtupleIColumnMap[index] = column;
00777   }  
00778 
00779   fLockFirstNtupleColumnId = true;
00780 
00781 #ifdef G4VERBOSE
00782   if ( fpVerboseL2 ) 
00783     fpVerboseL2->Message("create", "ntuple I column", name);
00784 #endif
00785 
00786   return index + fFirstNtupleColumnId;       
00787 }                                         
00788 
00789 //_____________________________________________________________________________
00790 G4int G4RootAnalysisManager::CreateNtupleFColumn(const G4String& name)
00791 {
00792 #ifdef G4VERBOSE
00793   if ( fpVerboseL4 ) 
00794     fpVerboseL4->Message("create", "ntuple F column", name);
00795 #endif
00796 
00797   if ( ! fNtupleBooking )  {
00798     G4ExceptionDescription description;
00799     description << "      " 
00800                 << "Ntuple has to be created first. ";
00801     G4Exception("G4RootAnalysisManager::CreateNtupleFColumn()",
00802                 "Analysis_W005", JustWarning, description);
00803     return -1;       
00804   }
00805 
00806   // Save column info in booking
00807   G4int index = fNtupleBooking->m_columns.size();
00808   fNtupleBooking->add_column<float>(name);  
00809  
00810   // Create column if ntuple already exists
00811   if ( fNtuple ) {
00812     tools::wroot::ntuple::column<float>* column 
00813       = fNtuple->create_column<float>(name);  
00814     fNtupleFColumnMap[index] = column;
00815   }  
00816 
00817   fLockFirstNtupleColumnId = true;
00818 
00819 #ifdef G4VERBOSE
00820   if ( fpVerboseL2 ) 
00821     fpVerboseL2->Message("create", "ntuple F column", name);
00822 #endif
00823 
00824   return index + fFirstNtupleColumnId;       
00825 }                                         
00826 
00827 
00828 //_____________________________________________________________________________
00829 G4int G4RootAnalysisManager::CreateNtupleDColumn(const G4String& name)   
00830 {
00831 #ifdef G4VERBOSE
00832   if ( fpVerboseL4 ) 
00833     fpVerboseL4->Message("create", "ntuple D column", name);
00834 #endif
00835 
00836   if ( ! fNtupleBooking ) {
00837     G4ExceptionDescription description;
00838     description << "      " 
00839                 << "Ntuple has to be created first. ";
00840     G4Exception("G4RootAnalysisManager::CreateNtupleDColumn()",
00841                 "Analysis_W005", JustWarning, description);
00842     return -1;       
00843   }
00844 
00845   // Save column info in booking
00846   G4int index = fNtupleBooking->m_columns.size();
00847   fNtupleBooking->add_column<double>(name);  
00848  
00849   // Create column if ntuple already exists
00850   if ( fNtuple ) {
00851     tools::wroot::ntuple::column<double>* column 
00852       = fNtuple->create_column<double>(name);  
00853     fNtupleDColumnMap[index] = column;
00854   }  
00855   
00856   fLockFirstNtupleColumnId = true;
00857 
00858 #ifdef G4VERBOSE
00859   if ( fpVerboseL2 ) 
00860     fpVerboseL2->Message("create", "ntuple D column", name);
00861 #endif
00862 
00863   return index + fFirstNtupleColumnId;       
00864 }                                         
00865 
00866 //_____________________________________________________________________________
00867 void G4RootAnalysisManager::FinishNtuple()
00868 { 
00869   // nothing to be done here
00870 }
00871    
00872 //_____________________________________________________________________________
00873 G4bool G4RootAnalysisManager::FillH1(G4int id, G4double value, G4double weight)
00874 {
00875   tools::histo::h1d* h1d = GetH1InFunction(id, "FillH1", true, false);
00876   if ( ! h1d ) return false;
00877 
00878   if ( fActivation && ( ! GetActivation(kH1, id) ) ) {
00879     //G4cout << "Skipping FillH1 for " << id << G4endl; 
00880     return false; 
00881   }  
00882 
00883   G4HnInformation* info = GetInformation(kH1, id);
00884   h1d->fill(info->fXFcn(value/info->fXUnit), weight);
00885 #ifdef G4VERBOSE
00886   if ( fpVerboseL4 ) {
00887     G4ExceptionDescription description;
00888     description << " id " << id << " value " << value;
00889     fpVerboseL4->Message("fill", "H1", description);
00890   }  
00891 #endif
00892   return true;
00893 }
00894 
00895 //_____________________________________________________________________________
00896 G4bool G4RootAnalysisManager::FillH2(G4int id, 
00897                                      G4double xvalue, G4double yvalue, 
00898                                      G4double weight)
00899 {
00900   tools::histo::h2d* h2d = GetH2InFunction(id, "FillH2", true, false);
00901   if ( ! h2d ) return false;
00902 
00903   if ( fActivation && ( ! GetActivation(kH2, id) ) ) return false; 
00904 
00905   G4HnInformation* info = GetInformation(kH2, id);
00906   h2d->fill(info->fXFcn(xvalue/info->fXUnit), 
00907             info->fYFcn(yvalue/info->fYUnit), weight);
00908 #ifdef G4VERBOSE
00909   if ( fpVerboseL4 ) {
00910     G4ExceptionDescription description;
00911     description << " id " << id 
00912                 << " xvalue " << xvalue << " yvalue " << yvalue;
00913     fpVerboseL4->Message("fill", "H2", description);
00914   }  
00915 #endif
00916   return true;
00917 }
00918 
00919 //_____________________________________________________________________________
00920 G4bool G4RootAnalysisManager::FillNtupleIColumn(G4int id, G4int value)
00921 {
00922   tools::wroot::ntuple::column<int>* column = GetNtupleIColumn(id);
00923   if ( ! column ) {
00924     G4ExceptionDescription description;
00925     description << "      " << "column " << id << " does not exist.";
00926     G4Exception("G4RootAnalysisManager::FillNtupleIColumn()",
00927                 "Analysis_W009", JustWarning, description);
00928     return false;
00929   }  
00930   
00931   column->fill(value);
00932 #ifdef G4VERBOSE
00933   if ( fpVerboseL4 ) {
00934     G4ExceptionDescription description;
00935     description << " id " << id << " value " << value;
00936     fpVerboseL4->Message("fill", "ntuple I column", description);
00937   }  
00938 #endif
00939   return true;       
00940 }                                         
00941 //_____________________________________________________________________________
00942 G4bool G4RootAnalysisManager::FillNtupleFColumn(G4int id, G4float value)
00943 {
00944   tools::wroot::ntuple::column<float>* column = GetNtupleFColumn(id);
00945   if ( ! column ) {
00946     G4ExceptionDescription description;
00947     description << "      " << "column " << id << " does not exist.";
00948     G4Exception("G4RootAnalysisManager::FillNtupleFColumn()",
00949                 "Analysis_W009", JustWarning, description);
00950     return false;
00951   }  
00952   
00953   column->fill(value);
00954 #ifdef G4VERBOSE
00955   if ( fpVerboseL4 ) {
00956     G4ExceptionDescription description;
00957     description << " id " << id << " value " << value;
00958     fpVerboseL4->Message("fill", "ntuple F column", description);
00959   }  
00960 #endif
00961   return true;       
00962 }                                         
00963 //_____________________________________________________________________________
00964 G4bool G4RootAnalysisManager::FillNtupleDColumn(G4int id, G4double value)
00965 {
00966   tools::wroot::ntuple::column<double>* column = GetNtupleDColumn(id);
00967   if ( ! column ) {
00968     G4ExceptionDescription description;
00969     description << "      " << "column " << id << " does not exist.";
00970     G4Exception("G4RootAnalysisManager::FillNtupleDColumn()",
00971                 "Analysis_W009", JustWarning, description);
00972     return false;
00973   }  
00974   
00975   column->fill(value);
00976 #ifdef G4VERBOSE
00977   if ( fpVerboseL4 ) {
00978     G4ExceptionDescription description;
00979     description << " id " << id << " value " << value;
00980     fpVerboseL4->Message("fill", "ntuple D column", description);
00981   }  
00982 #endif
00983   return true;       
00984 }                                         
00985 
00986 //_____________________________________________________________________________
00987 G4bool G4RootAnalysisManager::AddNtupleRow()
00988 { 
00989 #ifdef G4VERBOSE
00990   if ( fpVerboseL4 )
00991     fpVerboseL4->Message("add", "ntuple row", "");
00992 #endif
00993 
00994   if ( ! fNtuple ) {
00995     G4ExceptionDescription description;
00996     description << "      " << "ntuple does not exist. ";
00997     G4Exception("G4RootAnalysisManager::AddNtupleRow()",
00998                 "Analysis_W008", JustWarning, description);
00999     return false;
01000   }  
01001   
01002   G4bool result =fNtuple->add_row();
01003   if ( ! result ) {
01004     G4ExceptionDescription description;
01005     description << "      " << "adding row has failed.";
01006     G4Exception("G4RootAnalysisManager::AddNtupleRow()",
01007                 "Analysis_W004", JustWarning, description);
01008   }         
01009 #ifdef G4VERBOSE
01010   if ( fpVerboseL4 )
01011     fpVerboseL4->Message("add", "ntuple row", "", result);
01012 #endif
01013 
01014   return result;
01015 }
01016 
01017 //_____________________________________________________________________________
01018 tools::histo::h1d*  G4RootAnalysisManager::GetH1(G4int id, G4bool warn,
01019                                                  G4bool onlyIfActive) const 
01020 {
01021   return GetH1InFunction(id, "GetH1", warn, onlyIfActive);
01022 }
01023 
01024 //_____________________________________________________________________________
01025 tools::histo::h2d*  G4RootAnalysisManager::GetH2(G4int id, G4bool warn,
01026                                                  G4bool onlyIfActive) const 
01027 {
01028   return GetH2InFunction(id, "GetH2", warn, onlyIfActive);
01029 }
01030 
01031 //_____________________________________________________________________________
01032 G4int  G4RootAnalysisManager::GetH1Id(const G4String& name, G4bool warn) const
01033 {
01034   std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
01035   if ( it ==  fH1NameIdMap.end() ) {  
01036     if ( warn) {
01037       G4String inFunction = "G4RootAnalysisManager::GetH1Id";
01038       G4ExceptionDescription description;
01039       description << "      " << "histogram " << name << " does not exist.";
01040       G4Exception(inFunction, "Analysis_W007", JustWarning, description);
01041     }
01042     return -1;         
01043   }
01044   return it->second;
01045 }  
01046                                       
01047 //_____________________________________________________________________________
01048 G4int  G4RootAnalysisManager::GetH2Id(const G4String& name, G4bool warn) const
01049 {
01050   std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
01051   if ( it ==  fH2NameIdMap.end() ) {  
01052     if ( warn) {
01053       G4String inFunction = "G4RootAnalysisManager::GetH2Id";
01054       G4ExceptionDescription description;
01055       description << "      " << "histogram " << name << " does not exist.";
01056       G4Exception(inFunction, "Analysis_W007", JustWarning, description);
01057     }
01058     return -1;         
01059   }
01060   return it->second;
01061 }  
01062                                       
01063 //_____________________________________________________________________________
01064 tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple() const
01065 {
01066   return fNtuple;
01067 }  
01068 
01069 //_____________________________________________________________________________
01070 G4int G4RootAnalysisManager::GetH1Nbins(G4int id) const
01071 {
01072   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Nbins");
01073   if ( ! h1d ) return 0;
01074   
01075   return h1d->axis().bins();
01076 }  
01077 
01078 //_____________________________________________________________________________
01079 G4double G4RootAnalysisManager::GetH1Xmin(G4int id) const
01080 {
01081 // Returns xmin value with applied unit and histogram function
01082 
01083   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Xmin");
01084   if ( ! h1d ) return 0;
01085   
01086   G4HnInformation* info = GetInformation(kH1, id);
01087   return info->fXFcn(h1d->axis().lower_edge()*info->fXUnit);
01088 }  
01089 
01090 //_____________________________________________________________________________
01091 G4double G4RootAnalysisManager::GetH1Xmax(G4int id) const
01092 {
01093   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Xmax");
01094   if ( ! h1d ) return 0;
01095   
01096   G4HnInformation* info = GetInformation(kH1, id);
01097   return info->fXFcn(h1d->axis().upper_edge()*info->fXUnit);
01098 }  
01099 
01100 //_____________________________________________________________________________
01101 G4double G4RootAnalysisManager::GetH1Width(G4int id) const
01102 {
01103   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1XWidth", true, false);
01104   if ( ! h1d ) return 0;
01105   
01106   G4int nbins = h1d->axis().bins();
01107   if ( ! nbins ) {
01108     G4ExceptionDescription description;
01109     description << "    nbins = 0 (for h1 id = " << id << ").";
01110     G4Exception("G4RootAnalysisManager::GetH1Width",
01111                 "Analysis_W014", JustWarning, description);
01112     return 0;
01113   }              
01114   
01115   G4HnInformation* info = GetInformation(kH1, id);
01116   return ( info->fXFcn(h1d->axis().upper_edge()) 
01117            - info->fXFcn(h1d->axis().lower_edge()))*info->fXUnit/nbins;
01118 }  
01119 
01120 //_____________________________________________________________________________
01121 G4int G4RootAnalysisManager::GetH2Nxbins(G4int id) const
01122 {
01123   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NXbins");
01124   if ( ! h2d ) return 0;
01125   
01126   return h2d->axis_x().bins();
01127 }  
01128 
01129 //_____________________________________________________________________________
01130 G4double G4RootAnalysisManager::GetH2Xmin(G4int id) const
01131 {
01132 // Returns xmin value with applied unit and histogram function
01133 
01134   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmin");
01135   if ( ! h2d ) return 0;
01136   
01137   G4HnInformation* info = GetInformation(kH2, id);
01138   return info->fXFcn(h2d->axis_x().lower_edge()*info->fXUnit);
01139 }  
01140 
01141 //_____________________________________________________________________________
01142 G4double G4RootAnalysisManager::GetH2Xmax(G4int id) const
01143 {
01144   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmax");
01145   if ( ! h2d ) return 0;
01146   
01147   G4HnInformation* info = GetInformation(kH2, id);
01148   return info->fXFcn(h2d->axis_x().upper_edge()*info->fXUnit);
01149 }  
01150 
01151 //_____________________________________________________________________________
01152 G4double G4RootAnalysisManager::GetH2XWidth(G4int id) const
01153 {
01154   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XWidth", true, false);
01155   if ( ! h2d ) return 0;
01156   
01157   G4int nbins = h2d->axis_x().bins();
01158   if ( ! nbins ) {
01159     G4ExceptionDescription description;
01160     description << "    nbins = 0 (for h1 id = " << id << ").";
01161     G4Exception("G4RootAnalysisManager::GetH2Width",
01162                 "Analysis_W014", JustWarning, description);
01163     return 0;
01164   }              
01165   
01166   G4HnInformation* info = GetInformation(kH2, id);
01167   return ( info->fXFcn(h2d->axis_x().upper_edge()) 
01168            - info->fXFcn(h2d->axis_x().lower_edge()))*info->fXUnit/nbins;
01169 }  
01170 
01171 //_____________________________________________________________________________
01172 G4int G4RootAnalysisManager::GetH2Nybins(G4int id) const
01173 {
01174   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NYbins");
01175   if ( ! h2d ) return 0;
01176   
01177   return h2d->axis_y().bins();
01178 }  
01179 
01180 //_____________________________________________________________________________
01181 G4double G4RootAnalysisManager::GetH2Ymin(G4int id) const
01182 {
01183 // Returns xmin value with applied unit and histogram function
01184 
01185   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymin");
01186   if ( ! h2d ) return 0;
01187   
01188   G4HnInformation* info = GetInformation(kH2, id);
01189   return info->fYFcn(h2d->axis_y().lower_edge()*info->fYUnit);
01190 }  
01191 
01192 //_____________________________________________________________________________
01193 G4double G4RootAnalysisManager::GetH2Ymax(G4int id) const
01194 {
01195   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymax");
01196   if ( ! h2d ) return 0;
01197   
01198   G4HnInformation* info = GetInformation(kH2, id);
01199   return info->fYFcn(h2d->axis_y().upper_edge()*info->fYUnit);
01200 }  
01201 
01202 //_____________________________________________________________________________
01203 G4double G4RootAnalysisManager::GetH2YWidth(G4int id) const
01204 {
01205   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YWidth", true, false);
01206   if ( ! h2d ) return 0;
01207   
01208   G4int nbins = h2d->axis_y().bins();
01209   if ( ! nbins ) {
01210     G4ExceptionDescription description;
01211     description << "    nbins = 0 (for h1 id = " << id << ").";
01212     G4Exception("G4RootAnalysisManager::GetH2Width",
01213                 "Analysis_W014", JustWarning, description);
01214     return 0;
01215   }              
01216   
01217   G4HnInformation* info = GetInformation(kH2, id);
01218   return ( info->fYFcn(h2d->axis_y().upper_edge()) 
01219            - info->fYFcn(h2d->axis_y().lower_edge()))*info->fYUnit/nbins;
01220 }  
01221 
01222 //_____________________________________________________________________________
01223 G4bool G4RootAnalysisManager::SetH1Title(G4int id, const G4String& title)
01224 {
01225   tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1Title");
01226   if ( ! h1d ) return false;
01227   
01228   return h1d->set_title(title);
01229 }  
01230 
01231 //_____________________________________________________________________________
01232 G4bool G4RootAnalysisManager::SetH1XAxisTitle(G4int id, const G4String& title)
01233 {
01234   tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1XAxisTitle");
01235   if ( ! h1d ) return false;
01236   
01237   h1d->add_annotation(tools::histo::key_axis_x_title(), title);
01238   return true;
01239 }  
01240 
01241 //_____________________________________________________________________________
01242 G4bool G4RootAnalysisManager::SetH1YAxisTitle(G4int id, const G4String& title)
01243 {
01244   tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1YAxisTitle");
01245   if ( ! h1d ) return false;
01246   
01247   h1d->add_annotation(tools::histo::key_axis_y_title(), title);
01248   return true;
01249 }  
01250 
01251 //_____________________________________________________________________________
01252 G4bool G4RootAnalysisManager::SetH2Title(G4int id, const G4String& title)
01253 {
01254   tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2Title");
01255   if ( ! h2d ) return false;
01256   
01257   return h2d->set_title(title);
01258 }  
01259 
01260 //_____________________________________________________________________________
01261 G4bool G4RootAnalysisManager::SetH2XAxisTitle(G4int id, const G4String& title)
01262 {
01263   tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2XAxisTitle");
01264   if ( ! h2d ) return false;
01265   
01266   h2d->add_annotation(tools::histo::key_axis_x_title(), title);
01267   return true;
01268 }  
01269 
01270 //_____________________________________________________________________________
01271 G4bool G4RootAnalysisManager::SetH2YAxisTitle(G4int id, const G4String& title)
01272 {
01273   tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2YAxisTitle");
01274   if ( ! h2d ) return false;
01275   
01276   h2d->add_annotation(tools::histo::key_axis_x_title(), title);
01277   return true;  
01278 }  
01279 
01280 //_____________________________________________________________________________
01281 G4bool G4RootAnalysisManager::SetH2ZAxisTitle(G4int id, const G4String& title)
01282 {
01283   tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2ZAxisTitle");
01284   if ( ! h2d ) return false;
01285   
01286   h2d->add_annotation(tools::histo::key_axis_z_title(), title);
01287   return true;  
01288 }  
01289 
01290 //_____________________________________________________________________________
01291 G4String G4RootAnalysisManager::GetH1Title(G4int id) const
01292 {
01293   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Title");
01294   if ( ! h1d ) return "";
01295   
01296   return h1d->title();
01297 }  
01298 
01299 
01300 //_____________________________________________________________________________
01301 G4String G4RootAnalysisManager::GetH1XAxisTitle(G4int id) const 
01302 {
01303   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1XAxisTitle");
01304   if ( ! h1d ) return "";
01305   
01306   G4String title;
01307   G4bool result = h1d->annotation(tools::histo::key_axis_x_title(), title);
01308   if ( ! result ) {
01309     G4ExceptionDescription description;
01310     description << "    Failed to get x_axis title for h1 id = " << id << ").";
01311     G4Exception("G4RootAnalysisManager::GetH1XAxisTitle",
01312                 "Analysis_W014", JustWarning, description);
01313     return "";
01314   }
01315   
01316   return title;              
01317 }  
01318 
01319 //_____________________________________________________________________________
01320 G4String G4RootAnalysisManager::GetH1YAxisTitle(G4int id) const 
01321 {
01322   tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1YAxisTitle");
01323   if ( ! h1d ) return "";
01324   
01325   G4String title;
01326   G4bool result = h1d->annotation(tools::histo::key_axis_y_title(), title);
01327   if ( ! result ) {
01328     G4ExceptionDescription description;
01329     description << "    Failed to get y_axis title for h1 id = " << id << ").";
01330     G4Exception("G4RootAnalysisManager::GetH1YAxisTitle",
01331                 "Analysis_W014", JustWarning, description);
01332     return "";
01333   }
01334   
01335   return title;              
01336 }  
01337 
01338 //_____________________________________________________________________________
01339 G4String G4RootAnalysisManager::GetH2Title(G4int id) const
01340 {
01341   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Title");
01342   if ( ! h2d ) return "";
01343   
01344   return h2d->title();
01345 }  
01346 
01347 //_____________________________________________________________________________
01348 G4String G4RootAnalysisManager::GetH2XAxisTitle(G4int id) const 
01349 {
01350   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XAxisTitle");
01351   if ( ! h2d ) return "";
01352   
01353   G4String title;
01354   G4bool result = h2d->annotation(tools::histo::key_axis_x_title(), title);
01355   if ( ! result ) {
01356     G4ExceptionDescription description;
01357     description << "    Failed to get x_axis title for h2 id = " << id << ").";
01358     G4Exception("G4RootAnalysisManager::GetH2XAxisTitle",
01359                 "Analysis_W014", JustWarning, description);
01360     return "";
01361   }
01362   
01363   return title;              
01364 } 
01365 
01366 //_____________________________________________________________________________
01367 G4String G4RootAnalysisManager::GetH2YAxisTitle(G4int id) const 
01368 {
01369   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YAxisTitle");
01370   if ( ! h2d ) return "";
01371   
01372   G4String title;
01373   G4bool result = h2d->annotation(tools::histo::key_axis_y_title(), title);
01374   if ( ! result ) {
01375     G4ExceptionDescription description;
01376     description << "    Failed to get y_axis title for h2 id = " << id << ").";
01377     G4Exception("G4RootAnalysisManager::GetH2YAxisTitle",
01378                 "Analysis_W014", JustWarning, description);
01379     return "";
01380   }
01381   
01382   return title;              
01383 }  
01384 
01385 //_____________________________________________________________________________
01386 G4String G4RootAnalysisManager::GetH2ZAxisTitle(G4int id) const 
01387 {
01388   tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2ZAxisTitle");
01389   if ( ! h2d ) return "";
01390   
01391   G4String title;
01392   G4bool result = h2d->annotation(tools::histo::key_axis_z_title(), title);
01393   if ( ! result ) {
01394     G4ExceptionDescription description;
01395     description << "    Failed to get z_axis title for h2 id = " << id << ").";
01396     G4Exception("G4RootAnalysisManager::GetH2ZAxisTitle",
01397                 "Analysis_W014", JustWarning, description);
01398     return "";
01399   }
01400   
01401   return title;              
01402 }  

Generated on Mon May 27 17:49:44 2013 for Geant4 by  doxygen 1.4.7