Histo Class Reference

#include <Histo.hh>

Collaboration diagram for Histo:
Collaboration graph
[legend]

Public Member Functions

 Histo ()
 ~Histo ()
void Book ()
void Save ()
void Add1D (const G4String &, const G4String &, G4int nb, G4double x1, G4double x2, G4double u=1.)
void SetHisto1D (G4int, G4int, G4double, G4double, G4double)
void Activate (G4int, G4bool)
void Fill (G4int, G4double, G4double)
void ScaleH1 (G4int, G4double)
void AddTuple (const G4String &)
void AddTupleI (const G4String &)
void AddTupleF (const G4String &)
void AddTupleD (const G4String &)
void FillTupleI (G4int, G4int)
void FillTupleF (G4int, G4float)
void FillTupleD (G4int, G4double)
void AddRow ()
void SetFileName (const G4String &)
void SetFileType (const G4String &)
void SetVerbose (G4int val)
G4bool IsActive () const

Private Attributes

G4RootAnalysisManager * fManager
HistoMessengerfMessenger
G4String fHistName
G4String fHistType
G4String fTupleName
G4String fTupleTitle
G4int fNHisto
G4int fVerbose
G4bool fDefaultAct
G4bool fHistoActive
G4bool fNtupleActive
std::vector< G4int > fHisto
std::vector< G4int > fTupleI
std::vector< G4int > fTupleF
std::vector< G4int > fTupleD
std::vector< G4int > fBins
std::vector< G4bool > fActive
std::vector< G4double > fXmin
std::vector< G4double > fXmax
std::vector< G4double > fUnit
std::vector< G4String > fIds
std::vector< G4String > fTitles
std::vector< G4String > fNtupleI
std::vector< G4String > fNtupleF
std::vector< G4String > fNtupleD

Detailed Description

Definition at line 56 of file Histo.hh.


Constructor & Destructor Documentation

Histo::Histo (  ) 

Definition at line 51 of file Histo.cc.

References fDefaultAct, fHistName, fHistoActive, fHistType, fManager, fMessenger, fNHisto, fNtupleActive, fTupleName, fTupleTitle, and fVerbose.

00052 {
00053   fManager   = 0;
00054   fMessenger = new HistoMessenger(this);
00055  
00056   fHistName   = "test";
00057   fHistType   = "root";
00058   fTupleName  = "tuple";
00059   fTupleTitle = "test";
00060   fNHisto     = 0;
00061   fVerbose    = 0;
00062   fDefaultAct = true;
00063   fHistoActive= false;
00064   fNtupleActive= false;
00065 }

Histo::~Histo (  ) 

Definition at line 69 of file Histo.cc.

References fManager, and fMessenger.

00070 {
00071   delete fMessenger;
00072   delete fManager;
00073 }


Member Function Documentation

void Histo::Activate ( G4int  i,
G4bool  val 
)

Definition at line 197 of file Histo.cc.

References fActive, fHistoActive, fNHisto, and fVerbose.

00198 {
00199   if(fVerbose > 1) {
00200     G4cout << "Histo::Activate: Histogram: #" << i << "   "  
00201            << val << G4endl;   
00202   }
00203   if(i>=0 && i<fNHisto) { 
00204     fActive[i] = val; 
00205     if(val) { fHistoActive = true; }
00206   }
00207 }

void Histo::Add1D ( const G4String &  id,
const G4String &  name,
G4int  nb,
G4double  x1,
G4double  x2,
G4double  u = 1. 
)

Definition at line 153 of file Histo.cc.

References fActive, fBins, fDefaultAct, fHisto, fIds, fNHisto, fTitles, fUnit, fVerbose, fXmax, and fXmin.

Referenced by HistoManager::BeginOfRun().

00155 {
00156   if(fVerbose > 0) {
00157     G4cout << "Histo::Add1D: New histogram will be booked: #" << id << "  <" << name 
00158            << "  " << nb << "  " << x1 << "  " << x2 << "  " << u 
00159            << G4endl;
00160   }
00161   ++fNHisto;
00162   x1 /= u;
00163   x2 /= u;
00164   fActive.push_back(fDefaultAct);
00165   fBins.push_back(nb);
00166   fXmin.push_back(x1);
00167   fXmax.push_back(x2);
00168   fUnit.push_back(u);
00169   fIds.push_back(id);
00170   fTitles.push_back(name);
00171   fHisto.push_back(-1);
00172 }

Here is the caller graph for this function:

void Histo::AddRow (  ) 

Definition at line 328 of file Histo.cc.

References fManager, and fNtupleActive.

00329 {
00330   if(!fNtupleActive) { return; }
00331   fManager->AddNtupleRow();
00332 } 

void Histo::AddTuple ( const G4String &  w1  ) 

Definition at line 243 of file Histo.cc.

References fTupleTitle.

00244 {
00245   fTupleTitle = w1;
00246 }

void Histo::AddTupleD ( const G4String &  w1  ) 

Definition at line 268 of file Histo.cc.

References fNtupleActive, fNtupleD, and fTupleD.

00269 {
00270   fNtupleActive = true;
00271   fNtupleD.push_back(w1);
00272   fTupleD.push_back(-1);
00273 }

void Histo::AddTupleF ( const G4String &  w1  ) 

Definition at line 259 of file Histo.cc.

References fNtupleActive, fNtupleF, and fTupleF.

00260 {
00261   fNtupleActive = true;
00262   fNtupleF.push_back(w1);
00263   fTupleF.push_back(-1);
00264 }

void Histo::AddTupleI ( const G4String &  w1  ) 

Definition at line 250 of file Histo.cc.

References fNtupleActive, fNtupleI, and fTupleI.

00251 {
00252   fNtupleActive = true;
00253   fNtupleI.push_back(w1);
00254   fTupleI.push_back(-1);
00255 }

void Histo::Book (  ) 

Definition at line 77 of file Histo.cc.

References fActive, fBins, fHistName, fHisto, fHistoActive, fHistType, fIds, fManager, fNHisto, fNtupleActive, fNtupleD, fNtupleF, fNtupleI, fTitles, fTupleD, fTupleF, fTupleI, fTupleName, fTupleTitle, fVerbose, fXmax, and fXmin.

Referenced by HistoManager::BeginOfRun().

00078 {
00079   if(!(fHistoActive || fNtupleActive)) { return; }
00080 
00081   // Always creating analysis manager
00082   fManager = G4RootAnalysisManager::Instance(); 
00083 
00084   // Creating a tree mapped to a new hbook file.
00085   G4String nam = fHistName + "." + fHistType;
00086 
00087   // Open file histogram file
00088   if(!fManager->OpenFile(nam)) {
00089     G4cout << "Histo::Book: ERROR open file <" << nam << ">" << G4endl;
00090     fHistoActive = false;
00091     fNtupleActive = false;
00092     return; 
00093   }
00094   G4cout << "### Histo::Save: Opended file <" << nam << ">  for " 
00095          << fNHisto << " histograms " << G4endl;
00096 
00097   // Creating an 1-dimensional histograms in the root directory of the tree
00098   for(G4int i=0; i<fNHisto; ++i) {
00099     if(fActive[i]) {
00100       G4String ss = "h" + fIds[i];
00101       fHisto[i] = fManager->CreateH1(ss, fTitles[i], fBins[i], fXmin[i], fXmax[i]);
00102       if(fVerbose > 0) {
00103         G4cout << "Created histogram #" << i << "  id= " << fHisto[i]
00104                << "  "  << ss << "  " << fTitles[i] << G4endl;
00105       }
00106     }
00107   }
00108   // Creating a tuple factory, whose tuples will be handled by the tree
00109   if(fNtupleActive) {
00110     fManager->CreateNtuple(fTupleName,fTupleTitle); 
00111     G4int i;
00112     G4int n = fNtupleI.size();
00113     for(i=0; i<n; ++i) { 
00114       if(fTupleI[i] == -1) {  fTupleI[i] = fManager->CreateNtupleIColumn(fNtupleI[i]); }
00115     }
00116     n = fNtupleF.size();
00117     for(i=0; i<n; ++i) { 
00118       if(fTupleF[i] == -1) {  fTupleF[i] = fManager->CreateNtupleFColumn(fNtupleF[i]); }
00119     }
00120     n = fNtupleD.size();
00121     for(i=0; i<n; ++i) { 
00122       if(fTupleD[i] == -1) {  fTupleD[i] = fManager->CreateNtupleDColumn(fNtupleD[i]); }
00123     }
00124   }
00125 } 

Here is the caller graph for this function:

void Histo::Fill ( G4int  i,
G4double  x,
G4double  w 
)

Definition at line 211 of file Histo.cc.

References fActive, fHisto, fHistoActive, fManager, fNHisto, fUnit, and fVerbose.

Referenced by HistoManager::EndOfRun().

00212 {
00213   if(!fHistoActive) { return; }
00214   if(fVerbose > 1) {
00215     G4cout << "Histo::Fill: Histogram: #" << i << " at x= " << x 
00216            << "  weight= " << w
00217            << G4endl;   
00218   }
00219   if(i>=0 && i<fNHisto) {
00220     if(fActive[i]) { fManager->FillH1(fHisto[i], x/fUnit[i], w); }
00221   } else {
00222     G4cout << "Histo::Fill: WARNING! wrong histogram index " << i << G4endl;
00223   }
00224 }

Here is the caller graph for this function:

void Histo::FillTupleD ( G4int  i,
G4double  x 
)

Definition at line 311 of file Histo.cc.

References fManager, fNtupleActive, fNtupleD, fTupleD, and fVerbose.

00312 {
00313   if(!fNtupleActive) { return; }
00314   G4int n = fNtupleD.size();
00315   if(i >= 0 && i < n) {
00316     if(fVerbose > 1) {
00317       G4cout << "Histo::FillTupleD: i= " << i << "  id= " << fTupleD[i]
00318              << "   <" << fNtupleD[i] << "> = " << x << G4endl; 
00319     }
00320     fManager->FillNtupleDColumn(fTupleD[i], x); 
00321   } else {
00322     G4cout << "Histo::FillTupleD: WARNING! wrong ntuple index " << i << G4endl;
00323   }
00324 }

void Histo::FillTupleF ( G4int  i,
G4float  x 
)

Definition at line 294 of file Histo.cc.

References fManager, fNtupleActive, fNtupleF, fTupleF, and fVerbose.

00295 {
00296   if(!fNtupleActive) { return; }
00297   G4int n = fNtupleF.size();
00298   if(i >= 0 && i < n) {
00299     if(fVerbose > 1) {
00300       G4cout << "Histo::FillTupleF: i= " << i << "  id= " << fTupleF[i]
00301              << "   <" << fNtupleF[i] << "> = " << x << G4endl; 
00302     }
00303     fManager->FillNtupleFColumn(fTupleF[i], x); 
00304   } else {
00305     G4cout << "Histo::FillTupleF: WARNING! wrong ntuple index " << i << G4endl;
00306   }
00307 }

void Histo::FillTupleI ( G4int  i,
G4int  x 
)

Definition at line 277 of file Histo.cc.

References fManager, fNtupleActive, fNtupleI, fTupleI, and fVerbose.

00278 {
00279   if(!fNtupleActive) { return; }
00280   G4int n = fNtupleI.size();
00281   if(i >= 0 && i < n) {
00282     if(fVerbose > 1) {
00283       G4cout << "Histo::FillTupleI: i= " << i << "  id= " << fTupleI[i]
00284              << "   <" << fNtupleI[i] << "> = " << x << G4endl; 
00285     }
00286     fManager->FillNtupleIColumn(fTupleI[i], x); 
00287   } else {
00288     G4cout << "Histo::FillTupleI: WARNING! wrong ntuple index " << i << G4endl;
00289   }
00290 }

G4bool Histo::IsActive (  )  const [inline]

Definition at line 108 of file Histo.hh.

References fHistoActive.

00108 { return fHistoActive; };

void Histo::Save (  ) 

Definition at line 129 of file Histo.cc.

References fHistName, fHistoActive, fHistType, fManager, fNtupleActive, and fVerbose.

Referenced by HistoManager::EndOfRun().

00130 {
00131   if(!(fHistoActive || fNtupleActive)) { return; }
00132 
00133   // Creating a tree mapped to a new hbook file.
00134   G4String nam = fHistName + "." + fHistType;
00135 
00136   // Write histogram file
00137   if(!fManager->Write()) {
00138     G4cout   << "Histo::Save: FATAL ERROR writing ROOT file" << G4endl;
00139     exit(1);
00140   }
00141   if(fVerbose > 0) {
00142     G4cout << "### Histo::Save: Histograms and Ntuples are saved" << G4endl;
00143   }
00144   if(fManager->CloseFile() && fVerbose > 0) {
00145     G4cout << "                 File is closed" << G4endl;
00146   }
00147   delete G4RootAnalysisManager::Instance();
00148   fManager = 0;
00149 } 

Here is the caller graph for this function:

void Histo::ScaleH1 ( G4int  i,
G4double  x 
)

Definition at line 228 of file Histo.cc.

References fActive, fHisto, fHistoActive, fManager, fNHisto, and fVerbose.

00229 {
00230   if(!fHistoActive) { return; }
00231   if(fVerbose > 0) {
00232     G4cout << "Histo::Scale: Histogram: #" << i << " by factor " << x << G4endl;   
00233   }
00234   if(i>=0 && i<fNHisto) {
00235     if(fActive[i]) { fManager->GetH1(fHisto[i])->scale(x); }
00236   } else {
00237     G4cout << "Histo::Scale: WARNING! wrong histogram index " << i << G4endl;
00238   }
00239 }

void Histo::SetFileName ( const G4String &  nam  ) 

Definition at line 336 of file Histo.cc.

References fHistName, and fHistoActive.

Referenced by HistoMessenger::SetNewValue().

00337 {
00338   fHistName = nam;
00339   fHistoActive = true;
00340 }

Here is the caller graph for this function:

void Histo::SetFileType ( const G4String &  nam  ) 

Definition at line 344 of file Histo.cc.

References fHistType.

Referenced by HistoMessenger::SetNewValue().

00345 {
00346   if(nam == "root" || nam == "ROOT" )   { fHistType = "root"; }
00347   else if(nam == "xml" || nam == "XML") { fHistType = "xml"; }
00348   else if(nam == "ascii" || nam == "ASCII" || 
00349           nam == "Csv" || nam == "csv" || nam == "CSV") { fHistType = "ascii"; }
00350 }

Here is the caller graph for this function:

void Histo::SetHisto1D ( G4int  i,
G4int  nb,
G4double  x1,
G4double  x2,
G4double  u 
)

Definition at line 176 of file Histo.cc.

References fActive, fBins, fHistoActive, fNHisto, fUnit, fVerbose, fXmax, and fXmin.

Referenced by HistoManager::BeginOfRun(), and HistoMessenger::SetNewValue().

00177 {
00178   if(i>=0 && i<fNHisto) {
00179     if(fVerbose > 0) {
00180       G4cout << "Histo::SetHisto1D: #" << i  
00181              << "  " << nb << "  " << x1 << "  " << x2 << "  " << u 
00182              << G4endl;
00183     }
00184     fBins[i] = nb;
00185     fXmin[i] = x1;
00186     fXmax[i] = x2;
00187     fUnit[i] = u;
00188     fActive[i] = true;
00189     fHistoActive = true;
00190   } else {
00191     G4cout << "Histo::SetHisto1D: WARNING! wrong histogram index " << i << G4endl;
00192   }
00193 }

Here is the caller graph for this function:

void Histo::SetVerbose ( G4int  val  )  [inline]

Definition at line 106 of file Histo.hh.

References fVerbose.

Referenced by HistoManager::HistoManager(), and HistoManager::SetVerbose().

00106 { fVerbose = val; };

Here is the caller graph for this function:


Field Documentation

std::vector<G4bool> Histo::fActive [private]

Definition at line 130 of file Histo.hh.

Referenced by Activate(), Add1D(), Book(), Fill(), ScaleH1(), and SetHisto1D().

std::vector<G4int> Histo::fBins [private]

Definition at line 129 of file Histo.hh.

Referenced by Add1D(), Book(), and SetHisto1D().

G4bool Histo::fDefaultAct [private]

Definition at line 121 of file Histo.hh.

Referenced by Add1D(), and Histo().

G4String Histo::fHistName [private]

Definition at line 115 of file Histo.hh.

Referenced by Book(), Histo(), Save(), and SetFileName().

std::vector<G4int> Histo::fHisto [private]

Definition at line 125 of file Histo.hh.

Referenced by Add1D(), Book(), Fill(), and ScaleH1().

G4bool Histo::fHistoActive [private]

Definition at line 122 of file Histo.hh.

Referenced by Activate(), Book(), Fill(), Histo(), IsActive(), Save(), ScaleH1(), SetFileName(), and SetHisto1D().

G4String Histo::fHistType [private]

Definition at line 116 of file Histo.hh.

Referenced by Book(), Histo(), Save(), and SetFileType().

std::vector<G4String> Histo::fIds [private]

Definition at line 134 of file Histo.hh.

Referenced by Add1D(), and Book().

G4RootAnalysisManager* Histo::fManager [private]

Definition at line 108 of file Histo.hh.

Referenced by AddRow(), Book(), Fill(), FillTupleD(), FillTupleF(), FillTupleI(), Histo(), Save(), ScaleH1(), and ~Histo().

Definition at line 113 of file Histo.hh.

Referenced by Histo(), and ~Histo().

G4int Histo::fNHisto [private]

Definition at line 119 of file Histo.hh.

Referenced by Activate(), Add1D(), Book(), Fill(), Histo(), ScaleH1(), and SetHisto1D().

G4bool Histo::fNtupleActive [private]
std::vector<G4String> Histo::fNtupleD [private]

Definition at line 138 of file Histo.hh.

Referenced by AddTupleD(), Book(), and FillTupleD().

std::vector<G4String> Histo::fNtupleF [private]

Definition at line 137 of file Histo.hh.

Referenced by AddTupleF(), Book(), and FillTupleF().

std::vector<G4String> Histo::fNtupleI [private]

Definition at line 136 of file Histo.hh.

Referenced by AddTupleI(), Book(), and FillTupleI().

std::vector<G4String> Histo::fTitles [private]

Definition at line 135 of file Histo.hh.

Referenced by Add1D(), and Book().

std::vector<G4int> Histo::fTupleD [private]

Definition at line 128 of file Histo.hh.

Referenced by AddTupleD(), Book(), and FillTupleD().

std::vector<G4int> Histo::fTupleF [private]

Definition at line 127 of file Histo.hh.

Referenced by AddTupleF(), Book(), and FillTupleF().

std::vector<G4int> Histo::fTupleI [private]

Definition at line 126 of file Histo.hh.

Referenced by AddTupleI(), Book(), and FillTupleI().

G4String Histo::fTupleName [private]

Definition at line 117 of file Histo.hh.

Referenced by Book(), and Histo().

G4String Histo::fTupleTitle [private]

Definition at line 118 of file Histo.hh.

Referenced by AddTuple(), Book(), and Histo().

std::vector<G4double> Histo::fUnit [private]

Definition at line 133 of file Histo.hh.

Referenced by Add1D(), Fill(), and SetHisto1D().

G4int Histo::fVerbose [private]
std::vector<G4double> Histo::fXmax [private]

Definition at line 132 of file Histo.hh.

Referenced by Add1D(), Book(), and SetHisto1D().

std::vector<G4double> Histo::fXmin [private]

Definition at line 131 of file Histo.hh.

Referenced by Add1D(), Book(), and SetHisto1D().


The documentation for this class was generated from the following files:

Generated on 19 Feb 2017 for QwGeant4 by  doxygen 1.6.1