Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
exrdmHisto Class Reference

#include <exrdmHisto.hh>

Public Member Functions

 exrdmHisto ()
 
 ~exrdmHisto ()
 
void Book ()
 
void Save ()
 
void Add1D (const G4String &, const G4String &, G4int nb=100, G4double x1=0., G4double x2=1., G4double u=1.)
 
void SetHisto1D (G4int, G4int, G4double, G4double, G4double)
 
void FillHisto (G4int, G4double, G4double)
 
void ScaleHisto (G4int, G4double)
 
void AddTuple (const G4String &, const G4String &, const G4String &)
 
void FillTuple (G4int, const G4String &, G4double)
 
void FillTuple (G4int, G4int, G4double)
 
void FillTuple (G4int, const G4String &, G4String &)
 
void FillTuple (G4int, const G4String &, G4bool)
 
void AddRow (G4int)
 
void SetFileName (const G4String &)
 
const G4StringGetFileName () const
 
void SetFileType (const G4String &)
 
const G4StringFileType () const
 

Detailed Description

Definition at line 66 of file exrdmHisto.hh.

Constructor & Destructor Documentation

exrdmHisto::exrdmHisto ( )

Definition at line 55 of file exrdmHisto.cc.

56 :fHistName("exrdm"), fHistType("root"),
57  fNHisto(0), fNTuple(0), fVerbose(0),
58  fDefaultAct(1)
59 {
60 #ifdef G4ANALYSIS_USE
61  fAida = 0;
62  fTree = 0;
63 #endif
64 
65 #ifdef G4ANALYSIS_USE_ROOT
66  fROOThisto.clear();
67  fROOTntup.clear();
68  fRarray.clear();
69  fRcol.clear();
70 #endif
71 
72  fActive.clear();
73  fBins.clear();
74  fXmin.clear();
75  fXmax.clear();
76  fUnit.clear();
77  fIds.clear();
78  fTitles.clear();
79  fTupleName.clear();
80  fTupleId.clear();
81  fTupleList.clear();
82  fTupleListROOT.clear();
83 
84  fMessenger = new exrdmHistoMessenger(this);
85 }
exrdmHisto::~exrdmHisto ( )

Definition at line 89 of file exrdmHisto.cc.

90 {
91 #ifdef G4ANALYSIS_USE
92  fHisto.clear();
93  fNtup.clear();
94 #endif
95 #ifdef G4ANALYSIS_USE_ROOT
96  //FIXME : G.Barrand : the below is crashy.
97  // In principle the TH are deleted
98  // when doing the TFile::Close !
99  // In fact the fHfileROOT should
100  // be deleted in Save(). And I am pretty
101  // sure that the TApplication is not needed.
102  //
103  // removed by F.Lei
104  // for(G4int i=0; i<fNHisto; i++) {
105  // if(fROOThisto[i]) delete fROOThisto[i];
106  // }
107 #endif
108  delete fMessenger;
109 }

Member Function Documentation

void exrdmHisto::Add1D ( const G4String id,
const G4String name,
G4int  nb = 100,
G4double  x1 = 0.,
G4double  x2 = 1.,
G4double  u = 1. 
)

Definition at line 226 of file exrdmHisto.cc.

References G4cout, and G4endl.

Referenced by exrdmAnalysisManager::BookHisto().

228 {
229  if(fVerbose > 0) {
230  G4cout << "New histogram will be booked: #" << id << " <" << name
231  << " " << nb << " " << x1 << " " << x2 << " " << u
232  << G4endl;
233  }
234  fNHisto++;
235  x1 /= u;
236  x2 /= u;
237  fActive.push_back(fDefaultAct);
238  fBins.push_back(nb);
239  fXmin.push_back(x1);
240  fXmax.push_back(x2);
241  fUnit.push_back(u);
242  fIds.push_back(id);
243  fTitles.push_back(name);
244 #ifdef G4ANALYSIS_USE
245  fHisto.push_back(0);
246 #endif
247 #ifdef G4ANALYSIS_USE_ROOT
248  fROOThisto.push_back(0);
249 #endif
250 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::AddRow ( G4int  i)

Definition at line 419 of file exrdmHisto.cc.

References G4cout, and G4endl.

Referenced by exrdmAnalysisManager::AddDecayProduct(), exrdmAnalysisManager::AddEnergy(), exrdmAnalysisManager::AddIsotope(), and exrdmAnalysisManager::AddParticle().

420 {
421  if(fVerbose > 1) G4cout << "Added a raw #" << i << " to tuple" << G4endl;
422 #ifdef G4ANALYSIS_USE
423  if(fNtup[i]) fNtup[i]->addRow();
424 #endif
425 
426 #ifdef G4ANALYSIS_USE_ROOT
427  float *ar=new float[fRcol[i]];
428  for (G4int j=0; j < fRcol[i]; j++) {
429 // G4cout << i << " " << fRarray[i][j] << G4endl;
430  ar[j] = fRarray[i][j];
431  }
432  if(fROOTntup[i]) fROOTntup[i]->Fill(ar);
433  delete ar;
434 #endif
435 
436 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::AddTuple ( const G4String w1,
const G4String w2,
const G4String  
)

Definition at line 333 of file exrdmHisto.cc.

References G4String::contains(), and G4String::remove().

Referenced by exrdmAnalysisManager::BookHisto().

338 {
339  //G4cout << w1 << " " << w2 << " " << w3 << G4endl;
340  fNTuple++;
341  fTupleId.push_back(w1);
342  fTupleName.push_back(w2) ;
343 #ifdef G4ANALYSIS_USE
344  fTupleList.push_back(w3);
345  fNtup.push_back(0);
346 #endif
347 
348 #ifdef G4ANALYSIS_USE_ROOT
349  std::vector<float> ar;
350  ar.clear();
351  for (size_t i = 0; i < 20; i++) ar.push_back(0.);
352  fRarray.push_back(ar);
353  // convert AIDA header to ROOT header for ntuple
354  G4Tokenizer next(w3);
355  G4String token = next();
356  G4String ROOTList1 = "" ;
357  G4int col = 0;
358  while ( token != "") {
359  token = next();
360  if (token == ",") token = next();
361  if (token.contains(",")) token.remove(token.size()-1);
362  ROOTList1 = ROOTList1 + token + G4String(":");
363  col++;
364  }
365  G4String ROOTList = ROOTList1.substr(0,ROOTList1.length()-2);
366 // G4cout << ROOTList << G4endl;
367  fTupleListROOT.push_back(ROOTList);
368  fROOTntup.push_back(0);
369  fRcol.push_back(col-1);
370 #endif
371 }
G4String & remove(str_size)
int G4int
Definition: G4Types.hh:78
G4bool contains(const std::string &) const
void exrdmHisto::Book ( )

Definition at line 113 of file exrdmHisto.cc.

References G4cout, G4endl, and gammaraytel::hf.

Referenced by exrdmAnalysisManager::BeginOfRun().

114 {
115 #ifdef G4ANALYSIS_USE
116  G4cout << "### exrdmHisto books " << fNHisto << " histograms " << G4endl;
117  // Creating the analysis factory
118  fAida = AIDA_createAnalysisFactory();
119  if(!fAida) {
120  G4cout << "ERROR: can't get AIDA." << G4endl;
121  return;
122  }
123  // Creating the fTree factory
124  {AIDA::ITreeFactory* tf = fAida->createTreeFactory();
125  // Creating a fTree mapped to a new fAida file.
126  G4String fileName = fHistName + "." + fHistType;
127  if (fHistType == "root") fileName = fHistName + "_aida." + fHistType;
128  fTree = tf->create(fileName,fHistType,false,true,"");
129  delete tf;
130  if(!fTree) {
131  G4cout << "ERROR: Tree store " << fHistName << " is not created!" << G4endl;
132  return;
133  }
134  G4cout << "Tree store : " << fTree->storeName() << G4endl;}
135  // Creating a histogram factory, whose histograms will be handled by the fTree
136  {AIDA::IHistogramFactory* hf = fAida->createHistogramFactory(*fTree);
137  // Creating an 1-dimensional histograms in the root directory of the fTree
138  for(G4int i=0; i<fNHisto; i++) {
139  if(fActive[i]) {
140  if(fVerbose>1)
141  G4cout<<"Book: histogram "<< i << " id= " << fIds[i] <<G4endl;
142  G4String tit = fIds[i];
143  if(fHistType == "root") tit = "h" + fIds[i];
144  fHisto[i] = hf->createHistogram1D(tit, fTitles[i], fBins[i], fXmin[i],
145  fXmax[i]);
146  }
147  }
148  delete hf;
149  G4cout << "AIDA histograms are booked" << G4endl;}
150 
151  // Creating a tuple factory, whose tuples will be handled by the fTree
152  {AIDA::ITupleFactory* tpf = fAida->createTupleFactory( *fTree );
153  G4cout << "AIDA will Book " << fNTuple << " ntuples" << G4endl;
154  for(G4int i=0; i<fNTuple; i++) {
155  if(fTupleList[i] != "") {
156  G4cout << "Creating Ntuple: " << fTupleName[i] <<":" <<fTupleList[i]
157  << G4endl;
158  fNtup[i] = tpf->create(fTupleId[i], fTupleName[i], fTupleList[i],"");
159  }
160  }
161  delete tpf;
162  G4cout << "AIDA ntuples are booked" << G4endl;}
163 #endif
164 
165 #ifdef G4ANALYSIS_USE_ROOT
166 // new TApplication("App", ((int *)0), ((char **)0));
167  G4String fileNameROOT = fHistName + G4String(".root");
168  fHfileROOT = new TFile(fileNameROOT.c_str() ,"RECREATE","ROOT file for exRDM");
169  G4cout << "Root file: " << fileNameROOT << G4endl;
170  // Creating an 1-dimensional histograms in the root directory of the fTree
171  for(G4int i=0; i<fNHisto; i++) {
172  if(fActive[i]) {
173  G4String id = G4String("h")+fIds[i];
174  fROOThisto[i] = new TH1D(id, fTitles[i], fBins[i], fXmin[i], fXmax[i]);
175  G4cout << "ROOT Histo " << fIds[i] << " " << fTitles[i] << " booked "
176  << G4endl;
177  }
178  }
179  // Now the ntuples
180  for(G4int i=0; i<fNTuple; i++) {
181  if(fTupleListROOT[i] != "") {
182  G4String id = G4String("t")+fTupleId[i];
183  G4cout << "Creating Ntuple "<<fTupleId[i] << " in ROOT file: "
184  << fTupleName[i] << G4endl;
185  fROOTntup[i] = new TNtuple(id, fTupleName[i], fTupleListROOT[i]);
186  G4cout << "ROOT Ntuple " << id << " " << fTupleName[i] <<" "
187  << fTupleListROOT[i]<< " booked " << G4endl;
188  }
189  }
190 #endif
191 
192 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
tuple hf
Definition: gammaraytel.py:8
const G4String & exrdmHisto::FileType ( ) const

Definition at line 461 of file exrdmHisto.cc.

462 {
463  return fHistType;
464 }
void exrdmHisto::FillHisto ( G4int  i,
G4double  x,
G4double  w 
)

Definition at line 274 of file exrdmHisto.cc.

References G4cout, and G4endl.

Referenced by exrdmAnalysisManager::AddParticle(), and exrdmAnalysisManager::EndOfEvent().

275 {
276  if(fVerbose > 1) {
277  G4cout << "fill histogram: #" << i << " at x= " << x
278  << " weight= " << w
279  << G4endl;
280  }
281 #ifdef G4ANALYSIS_USE
282  if(i>=0 && i<fNHisto) {
283  fHisto[i]->fill(x/fUnit[i], w);
284  } else {
285  G4cout << "exrdmHisto::fill: WARNING! wrong AIDA histogram index "
286  << i << G4endl;
287  }
288 #endif
289 #ifdef G4ANALYSIS_USE_ROOT
290  if(i>=0 && i<fNHisto) {
291  fROOThisto[i]->Fill(x/fUnit[i],w);
292  } else {
293  G4cout << "exrdmHisto::fill: WARNING! wrong ROOT histogram index "
294  << i << G4endl;
295  }
296 #endif
297 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::FillTuple ( G4int  i,
const G4String parname,
G4double  x 
)

Definition at line 375 of file exrdmHisto.cc.

References G4cout, and G4endl.

Referenced by exrdmAnalysisManager::AddDecayProduct(), exrdmAnalysisManager::AddEnergy(), exrdmAnalysisManager::AddIsotope(), and exrdmAnalysisManager::AddParticle().

376 {
377  if(fVerbose > 1)
378  G4cout << "fill tuple # " << i
379  <<" with parameter <" << parname << "> = " << x << G4endl;
380 #ifdef G4ANALYSIS_USE
381  if(fNtup[i]) fNtup[i]->fill(fNtup[i]->findColumn(parname), x);
382 #endif
383 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::FillTuple ( G4int  i,
G4int  col,
G4double  x 
)

Definition at line 387 of file exrdmHisto.cc.

References G4cout, and G4endl.

388 {
389  if(fVerbose > 1) {
390  G4cout << "fill tuple # " << i
391  <<" in column < " << col << "> = " << x << G4endl;
392  }
393 #ifdef G4ANALYSIS_USE
394  if(fNtup[i]) fNtup[i]->fill(col,double(x));
395 #endif
396 
397 #ifdef G4ANALYSIS_USE_ROOT
398  if(fROOTntup[i]) (fRarray[i])[col] = float(x);
399 #endif
400 
401 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::FillTuple ( G4int  i,
const G4String parname,
G4String x 
)

Definition at line 405 of file exrdmHisto.cc.

References G4cout, and G4endl.

406 {
407  if(fVerbose > 1) {
408  G4cout << "fill tuple # " << i
409  <<" with parameter <" << parname << "> = " << x << G4endl;
410  }
411 #ifdef G4ANALYSIS_USE
412  if(fNtup[i]) fNtup[i]->fill(fNtup[i]->findColumn(parname), x);
413 #endif
414 
415 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::FillTuple ( G4int  ,
const G4String ,
G4bool   
)
const G4String & exrdmHisto::GetFileName ( ) const

Definition at line 447 of file exrdmHisto.cc.

Referenced by exrdmAnalysisManager::EndOfRun().

448 {
449  return fHistName;
450 }
void exrdmHisto::Save ( )

Definition at line 196 of file exrdmHisto.cc.

References G4cout, and G4endl.

Referenced by exrdmAnalysisManager::EndOfRun().

197 {
198 #ifdef G4ANALYSIS_USE
199  // Write histogram file
200  fTree->commit();
201  G4cout << "Closing the AIDA fTree..." << G4endl;
202  fTree->close();
203  G4cout << "Histograms and Ntuples are saved" << G4endl;
204  delete fTree;
205  fTree = 0;
206  delete fAida;
207  fAida = 0;
208  {for(G4int i=0; i<fNHisto; i++) fHisto[i] = 0;}
209  {for(G4int i=0; i<fNTuple; i++) fNtup[i] = 0;}
210 #endif
211 #ifdef G4ANALYSIS_USE_ROOT
212  G4cout << "ROOT: files writing..." << G4endl;
213  fHfileROOT->Write();
214  G4cout << "ROOT: files closing..." << G4endl;
215  fHfileROOT->Close();
216  //
217  // F.Lei added following Guy's suggestion!
218  delete fHfileROOT;
219 
220 #endif
221 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::ScaleHisto ( G4int  i,
G4double  x 
)

Definition at line 301 of file exrdmHisto.cc.

References G4cout, and G4endl.

302 {
303  if(fVerbose > 0) {
304  G4cout << "Scale histogram: #" << i << " by factor " << x << G4endl;
305  }
306 #ifdef G4ANALYSIS_USE
307  if(i>=0 && i<fNHisto) {
308  fHisto[i]->scale(x);
309  G4cout << "exrdmHisto::scale: WARNING! wrong AIDA histogram index "
310  << i << G4endl;
311  }
312 #endif
313 #ifdef G4ANALYSIS_USE_ROOT
314  if(i>=0 && i<fNHisto) {
315  fROOThisto[i]->Scale(x);
316  } else {
317  G4cout << "exrdmHisto::scale: WARNING! wrong ROOT histogram index "
318  << i << G4endl;
319  }
320 #endif
321 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void exrdmHisto::SetFileName ( const G4String nam)

Definition at line 440 of file exrdmHisto.cc.

Referenced by exrdmHistoMessenger::SetNewValue().

441 {
442  fHistName = nam;
443 }
void exrdmHisto::SetFileType ( const G4String nam)

Definition at line 454 of file exrdmHisto.cc.

Referenced by exrdmHistoMessenger::SetNewValue().

455 {
456  fHistType = nam;
457 }
void exrdmHisto::SetHisto1D ( G4int  i,
G4int  nb,
G4double  x1,
G4double  x2,
G4double  u 
)

Definition at line 254 of file exrdmHisto.cc.

References G4cout, and G4endl.

Referenced by exrdmHistoMessenger::SetNewValue().

255 {
256  if(i>=0 && i<fNHisto) {
257  if(fVerbose > 0) {
258  G4cout << "Update histogram: #" << i
259  << " " << nb << " " << x1 << " " << x2 << " " << u
260  << G4endl;
261  }
262  fBins[i] = nb;
263  fXmin[i] = x1;
264  fXmax[i] = x2;
265  fUnit[i] = u;
266  } else {
267  G4cout << "exrdmHisto::setexrdmHisto1D: WARNING! wrong histogram index "
268  << i << G4endl;
269  }
270 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

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