[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 | #ifdef G4ANALYSIS_USE |
---|
| 27 | |
---|
| 28 | #include <AIDA/AIDA.h> |
---|
| 29 | |
---|
| 30 | #include "exGPSAnalysisManager.hh" |
---|
| 31 | #include "exGPSAnalysisMessenger.hh" |
---|
| 32 | |
---|
| 33 | #include "G4UnitsTable.hh" |
---|
| 34 | |
---|
| 35 | exGPSAnalysisManager* exGPSAnalysisManager::instance = 0; |
---|
| 36 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 37 | |
---|
| 38 | exGPSAnalysisManager::exGPSAnalysisManager(): |
---|
[1230] | 39 | fileName("exgps.aida"),fileType("xml"),analysisFactory(0), tree(0),plotter(0), |
---|
| 40 | minpos(-10.),maxpos(10),mineng(0.),maxeng(1000.), |
---|
| 41 | enerHisto(0),posiXY(0),posiXZ(0),posiYZ(0),anglCTP(0),anglTP(0),tuple(0) |
---|
[807] | 42 | { |
---|
| 43 | // Define the messenger and the analysis system |
---|
| 44 | analysisMessenger = new exGPSAnalysisMessenger(this); |
---|
| 45 | |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 49 | |
---|
| 50 | exGPSAnalysisManager::~exGPSAnalysisManager() { |
---|
| 51 | |
---|
| 52 | delete analysisMessenger; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 59 | |
---|
| 60 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 61 | // |
---|
| 62 | exGPSAnalysisManager* exGPSAnalysisManager::getInstance () |
---|
| 63 | { |
---|
| 64 | if (instance == 0) instance = new exGPSAnalysisManager(); |
---|
| 65 | return instance; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 69 | |
---|
| 70 | void exGPSAnalysisManager::dispose() |
---|
| 71 | { |
---|
| 72 | if (instance != 0) |
---|
| 73 | { |
---|
| 74 | delete instance; |
---|
| 75 | instance = 0; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 80 | |
---|
| 81 | void exGPSAnalysisManager::Fill(G4String pname, G4double e, |
---|
| 82 | G4double x, G4double y, G4double z, |
---|
| 83 | G4double t, G4double p, G4double w) |
---|
| 84 | { |
---|
[1230] | 85 | if(enerHisto) { |
---|
| 86 | enerHisto->fill(e/MeV,w); |
---|
| 87 | posiXY->fill(x/cm,y/cm,w); |
---|
| 88 | posiXZ->fill(x/cm,z/cm,w); |
---|
| 89 | posiYZ->fill(y/cm,z/cm,w); |
---|
| 90 | anglCTP->fill(p/deg,std::cos(t),w); |
---|
| 91 | anglTP->fill(p/deg,t/deg,w); |
---|
| 92 | } |
---|
[807] | 93 | |
---|
| 94 | if (plotter) plotter->refresh(); |
---|
| 95 | |
---|
| 96 | // Fill the tuple |
---|
| 97 | |
---|
| 98 | if (tuple) { |
---|
| 99 | tuple->fill(0,pname); |
---|
| 100 | tuple->fill(1,e/MeV); |
---|
| 101 | tuple->fill(2,x/cm); |
---|
| 102 | tuple->fill(3,y/cm); |
---|
| 103 | tuple->fill(4,z/cm); |
---|
| 104 | tuple->fill(5,t/deg); |
---|
| 105 | tuple->fill(6,p/deg); |
---|
| 106 | tuple->fill(7,w); |
---|
| 107 | |
---|
| 108 | tuple->addRow(); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 113 | /* |
---|
| 114 | This member reset the histograms and it is called at the begin |
---|
| 115 | of each run; here we put the inizialization so that the histograms have |
---|
| 116 | always the right dimensions depending from the detector geometry |
---|
| 117 | */ |
---|
| 118 | void exGPSAnalysisManager::BeginOfRun() |
---|
| 119 | { |
---|
[1230] | 120 | tree = 0; |
---|
| 121 | plotter = 0; |
---|
[807] | 122 | |
---|
[1230] | 123 | enerHisto =0; |
---|
| 124 | posiXY = posiXZ = posiYZ = anglCTP =anglTP = 0; |
---|
| 125 | tuple = 0; |
---|
| 126 | |
---|
[807] | 127 | // Hooking an AIDA compliant analysis system. |
---|
| 128 | analysisFactory = AIDA_createAnalysisFactory(); |
---|
[1230] | 129 | if(!analysisFactory) //Have to check that, it can fail. |
---|
| 130 | { |
---|
| 131 | G4cout << "exGPSAnalysisManager::BeginOfRun: can't get AIDA." << G4endl; |
---|
| 132 | return; |
---|
| 133 | } |
---|
| 134 | AIDA::ITreeFactory* treeFactory = analysisFactory->createTreeFactory(); |
---|
| 135 | if(treeFactory) |
---|
| 136 | { |
---|
[807] | 137 | tree = treeFactory->create(fileName,fileType,false,true,"compress=yes"); |
---|
[1230] | 138 | if(!tree) //Have to check that, it can fail. |
---|
| 139 | { |
---|
| 140 | G4cout << "exGPSAnalysisManager::BeginOfRun:" |
---|
| 141 | << " can't create the AIDA::ITree : " << fileName << G4endl; |
---|
| 142 | return; |
---|
| 143 | } |
---|
| 144 | |
---|
[807] | 145 | delete treeFactory; // Will not delete the ITree. |
---|
| 146 | } |
---|
[1230] | 147 | |
---|
| 148 | AIDA::IHistogramFactory* hFactory = analysisFactory->createHistogramFactory(*tree); |
---|
[807] | 149 | if (hFactory) |
---|
| 150 | { |
---|
| 151 | // Create the energy histogram |
---|
| 152 | enerHisto = hFactory->createHistogram1D("Source Energy Spectrum",100,mineng,maxeng); |
---|
| 153 | |
---|
| 154 | // Create some 2d histos |
---|
| 155 | posiXY = hFactory->createHistogram2D("Source X-Y distribution",100,minpos/cm,maxpos/cm |
---|
| 156 | ,100,minpos/cm,maxpos/cm); |
---|
| 157 | posiXZ = hFactory->createHistogram2D("Source X-Z distribution",100,minpos/cm,maxpos/cm |
---|
| 158 | ,100,minpos/cm,maxpos/cm); |
---|
| 159 | posiYZ = hFactory->createHistogram2D("Source Y-Z distribution",100,minpos/cm,maxpos/cm |
---|
| 160 | ,100,minpos/cm,maxpos/cm); |
---|
| 161 | anglCTP = hFactory->createHistogram2D("Source phi-std::cos(theta) distribution",360,0,360 |
---|
| 162 | , 100, -1, 1); |
---|
| 163 | anglTP = hFactory->createHistogram2D("Source phi-theta distribution",360,0,360 |
---|
| 164 | ,180,0,180); |
---|
[1230] | 165 | delete hFactory; |
---|
[807] | 166 | } |
---|
| 167 | |
---|
| 168 | // Create a Tuple |
---|
| 169 | |
---|
[1230] | 170 | AIDA::ITupleFactory* tFactory = analysisFactory->createTupleFactory(*tree); |
---|
[807] | 171 | if (tFactory) |
---|
| 172 | { |
---|
[1230] | 173 | tuple = tFactory->create("MyTuple","MyTuple","string Pname, double Energy, X, Y, Z, Theta, Phi, Weight",""); |
---|
| 174 | delete tFactory; |
---|
[807] | 175 | } |
---|
[1230] | 176 | |
---|
| 177 | AIDA::IPlotterFactory* pf = analysisFactory->createPlotterFactory(0,0); |
---|
| 178 | if(pf) |
---|
| 179 | { |
---|
| 180 | plotter = pf->create(); |
---|
| 181 | if (plotter) |
---|
| 182 | { |
---|
| 183 | plotter->createRegions(2,3); |
---|
| 184 | if(enerHisto) plotter->region(0)->plot(*enerHisto); |
---|
| 185 | if(posiXY) plotter->region(1)->plot(*posiXY); |
---|
| 186 | if(posiXZ) plotter->region(2)->plot(*posiXZ); |
---|
| 187 | if(posiYZ) plotter->region(3)->plot(*posiYZ); |
---|
| 188 | if(anglCTP) plotter->region(4)->plot(*anglCTP); |
---|
| 189 | if(anglTP) plotter->region(5)->plot(*anglTP); |
---|
| 190 | plotter->show(); |
---|
| 191 | } |
---|
| 192 | delete pf; |
---|
| 193 | } |
---|
[807] | 194 | } |
---|
| 195 | |
---|
| 196 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 197 | |
---|
| 198 | /* |
---|
| 199 | This member is called at the end of each run |
---|
| 200 | */ |
---|
| 201 | void exGPSAnalysisManager::EndOfRun() |
---|
| 202 | { |
---|
| 203 | if (analysisFactory) |
---|
| 204 | { |
---|
| 205 | if (!tree->commit()) G4cout << "Commit failed: no AIDA file produced!" << G4endl; |
---|
| 206 | delete tree; |
---|
[1230] | 207 | tree = 0; |
---|
[807] | 208 | // G4cout << "Warning: Geant4 will NOT continue unless you close the JAS-AIDA window." << G4endl; |
---|
[1230] | 209 | |
---|
| 210 | delete plotter; |
---|
| 211 | plotter = 0; |
---|
| 212 | |
---|
| 213 | delete analysisFactory; //cleanup all AIDA related things. |
---|
| 214 | analysisFactory = 0; |
---|
| 215 | |
---|
| 216 | enerHisto = 0; |
---|
| 217 | posiXY = posiXZ = posiYZ = anglCTP =anglTP = 0; |
---|
| 218 | tuple = 0; |
---|
| 219 | |
---|
[807] | 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | #endif // G4ANALYSIS_USE |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | |
---|