| [807] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 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. *
|
|---|
| 10 | // * *
|
|---|
| 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. *
|
|---|
| 17 | // * *
|
|---|
| 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 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //---------------------------------------------------------------------------
|
|---|
| 27 | //
|
|---|
| 28 | // ClassName: Histo - Generic histogram/ntuple manager class
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Author: V.Ivanchenko 30.10.03
|
|---|
| 32 | //
|
|---|
| 33 | //----------------------------------------------------------------------------
|
|---|
| 34 | //
|
|---|
| 35 |
|
|---|
| 36 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 37 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 38 |
|
|---|
| 39 | #include "Histo.hh"
|
|---|
| 40 |
|
|---|
| 41 | #ifdef G4ANALYSIS_USE
|
|---|
| 42 |
|
|---|
| 43 | #include "AIDA/AIDA.h"
|
|---|
| 44 | #include "HistoMessenger.hh"
|
|---|
| 45 |
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 49 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 50 |
|
|---|
| 51 | Histo::Histo()
|
|---|
| 52 | {
|
|---|
| 53 | verbose = 0;
|
|---|
| 54 | histName = "testem9";
|
|---|
| 55 | histType = "hbook";
|
|---|
| 56 | nHisto = 0;
|
|---|
| 57 | defaultAct = 1;
|
|---|
| 58 | tupleName = "tuple9";
|
|---|
| 59 | tupleId = "100";
|
|---|
| 60 | tupleList = "";
|
|---|
| 61 | ntup = 0;
|
|---|
| 62 | messenger = 0;
|
|---|
| 63 |
|
|---|
| 64 | #ifdef G4ANALYSIS_USE
|
|---|
| 65 | tree = 0;
|
|---|
| 66 | af = 0;
|
|---|
| 67 | messenger = new HistoMessenger(this);
|
|---|
| 68 | #endif
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 72 |
|
|---|
| 73 | Histo::~Histo()
|
|---|
| 74 | {
|
|---|
| 75 | #ifdef G4ANALYSIS_USE
|
|---|
| 76 | delete messenger;
|
|---|
| 77 | delete af;
|
|---|
| 78 | #endif
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 82 |
|
|---|
| 83 | void Histo::book()
|
|---|
| 84 | {
|
|---|
| 85 | #ifdef G4ANALYSIS_USE
|
|---|
| 86 | G4cout << "### Histo books " << nHisto << " histograms " << G4endl;
|
|---|
| 87 | // Creating the analysis factory
|
|---|
| 88 | if(!af) af = AIDA_createAnalysisFactory();
|
|---|
| 89 | // Creating the tree factory
|
|---|
| 90 | AIDA::ITreeFactory* tf = af->createTreeFactory();
|
|---|
| 91 |
|
|---|
| 92 | // Creating a tree mapped to a new hbook file.
|
|---|
| 93 |
|
|---|
| 94 | G4String nam = histName + "." + histType;
|
|---|
| 95 |
|
|---|
| 96 | tree = tf->create(nam,histType,false,true,"uncompress");
|
|---|
| 97 | delete tf;
|
|---|
| 98 | if(tree) {
|
|---|
| 99 | G4cout << "Tree store : " << tree->storeName() << G4endl;
|
|---|
| 100 | } else {
|
|---|
| 101 | G4cout << "ERROR: Tree store " << histName << " is not created!" << G4endl;
|
|---|
| 102 | return;
|
|---|
| 103 | }
|
|---|
| 104 | // Creating a histogram factory, whose histograms will be handled by the tree
|
|---|
| 105 | AIDA::IHistogramFactory* hf = af->createHistogramFactory( *tree );
|
|---|
| 106 |
|
|---|
| 107 | // Creating an 1-dimensional histograms in the root directory of the tree
|
|---|
| 108 | for(G4int i=0; i<nHisto; i++) {
|
|---|
| 109 | if(active[i])
|
|---|
| 110 | histo[i] = hf->createHistogram1D(ids[i], titles[i], bins[i], xmin[i], xmax[i]);
|
|---|
| 111 | }
|
|---|
| 112 | delete hf;
|
|---|
| 113 | // Creating a tuple factory, whose tuples will be handled by the tree
|
|---|
| 114 | if(tupleList != "") {
|
|---|
| 115 | AIDA::ITupleFactory* tpf = af->createTupleFactory( *tree );
|
|---|
| 116 | ntup = tpf->create(tupleId, tupleName, tupleList);
|
|---|
| 117 | delete tpf;
|
|---|
| 118 | }
|
|---|
| 119 | #endif
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 123 |
|
|---|
| 124 | void Histo::save()
|
|---|
| 125 | {
|
|---|
| 126 | #ifdef G4ANALYSIS_USE
|
|---|
| 127 | // Write histogram file
|
|---|
| 128 | if(tree) {
|
|---|
| 129 | tree->commit();
|
|---|
| 130 | G4cout << "Closing the tree..." << G4endl;
|
|---|
| 131 | tree->close();
|
|---|
| 132 | G4cout << "Histograms and Ntuples are saved" << G4endl;
|
|---|
| 133 | delete tree;
|
|---|
| 134 | tree = 0;
|
|---|
| 135 | }
|
|---|
| 136 | #endif
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 140 |
|
|---|
| 141 | void Histo::add1D(const G4String& id, const G4String& name, G4int nb,
|
|---|
| 142 | G4double x1, G4double x2, G4double u)
|
|---|
| 143 | {
|
|---|
| 144 | if(verbose > 0) {
|
|---|
| 145 | G4cout << "New histogram will be booked: #" << id << " <" << name
|
|---|
| 146 | << " " << nb << " " << x1 << " " << x2 << " " << u
|
|---|
| 147 | << G4endl;
|
|---|
| 148 | }
|
|---|
| 149 | nHisto++;
|
|---|
| 150 | x1 /= u;
|
|---|
| 151 | x2 /= u;
|
|---|
| 152 | active.push_back(defaultAct);
|
|---|
| 153 | bins.push_back(nb);
|
|---|
| 154 | xmin.push_back(x1);
|
|---|
| 155 | xmax.push_back(x2);
|
|---|
| 156 | unit.push_back(u);
|
|---|
| 157 | ids.push_back(id);
|
|---|
| 158 | titles.push_back(name);
|
|---|
| 159 | histo.push_back(0);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 163 |
|
|---|
| 164 | void Histo::setHisto1D(G4int i, G4int nb, G4double x1, G4double x2, G4double u)
|
|---|
| 165 | {
|
|---|
| 166 | if(i>=0 && i<nHisto) {
|
|---|
| 167 | if(verbose > 0) {
|
|---|
| 168 | G4cout << "Update histogram: #" << i
|
|---|
| 169 | << " " << nb << " " << x1 << " " << x2 << " " << u
|
|---|
| 170 | << G4endl;
|
|---|
| 171 | }
|
|---|
| 172 | bins[i] = nb;
|
|---|
| 173 | xmin[i] = x1;
|
|---|
| 174 | xmax[i] = x2;
|
|---|
| 175 | unit[i] = u;
|
|---|
| 176 | } else {
|
|---|
| 177 | G4cout << "Histo::setHisto1D: WARNING! wrong histogram index " << i << G4endl;
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 182 |
|
|---|
| 183 | void Histo::fill(G4int i, G4double x, G4double w)
|
|---|
| 184 | {
|
|---|
| 185 | if(verbose > 1) {
|
|---|
| 186 | G4cout << "fill histogram: #" << i << " at x= " << x
|
|---|
| 187 | << " weight= " << w
|
|---|
| 188 | << G4endl;
|
|---|
| 189 | }
|
|---|
| 190 | #ifdef G4ANALYSIS_USE
|
|---|
| 191 | if(!tree) return;
|
|---|
| 192 | if(i>=0 && i<nHisto) {
|
|---|
| 193 | if(active[i]) histo[i]->fill((x/unit[i]), w);
|
|---|
| 194 | } else {
|
|---|
| 195 | G4cout << "Histo::fill: WARNING! wrong histogram index " << i << G4endl;
|
|---|
| 196 | }
|
|---|
| 197 | #endif
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 201 |
|
|---|
| 202 | void Histo::scale(G4int i, G4double x)
|
|---|
| 203 | {
|
|---|
| 204 | if(verbose > 0) {
|
|---|
| 205 | G4cout << "Scale histogram: #" << i << " by factor " << x << G4endl;
|
|---|
| 206 | }
|
|---|
| 207 | #ifdef G4ANALYSIS_USE
|
|---|
| 208 | if(!tree) return;
|
|---|
| 209 | if(i>=0 && i<nHisto) {
|
|---|
| 210 | histo[i]->scale(x);
|
|---|
| 211 | } else {
|
|---|
| 212 | G4cout << "Histo::scale: WARNING! wrong histogram index " << i << G4endl;
|
|---|
| 213 | }
|
|---|
| 214 | #endif
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 218 |
|
|---|
| 219 | void Histo::addTuple(const G4String& w1, const G4String& w2, const G4String& w3)
|
|---|
| 220 | {
|
|---|
| 221 | tupleId = w1;
|
|---|
| 222 | tupleName = w2;
|
|---|
| 223 | tupleList = w3;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 227 |
|
|---|
| 228 | void Histo::fillTuple(const G4String& parname, G4double x)
|
|---|
| 229 | {
|
|---|
| 230 | if(verbose > 1) {
|
|---|
| 231 | G4cout << "fill tuple by parameter <" << parname << "> = " << x << G4endl;
|
|---|
| 232 | }
|
|---|
| 233 | #ifdef G4ANALYSIS_USE
|
|---|
| 234 | if(ntup) ntup->fill(ntup->findColumn(parname), (float)x);
|
|---|
| 235 | #endif
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 239 |
|
|---|
| 240 | void Histo::addRow()
|
|---|
| 241 | {
|
|---|
| 242 | #ifdef G4ANALYSIS_USE
|
|---|
| 243 | if(ntup) ntup->addRow();
|
|---|
| 244 | #endif
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 248 |
|
|---|
| 249 | void Histo::setFileName(const G4String& nam)
|
|---|
| 250 | {
|
|---|
| 251 | histName = nam;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 255 |
|
|---|
| 256 | void Histo::setFileType(const G4String& nam)
|
|---|
| 257 | {
|
|---|
| 258 | if(nam == "root" || nam == "hbook" || nam == "aida") histType = nam;
|
|---|
| 259 | else if(nam == "xml" || nam == "XML") histType = "aida";
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 263 |
|
|---|