| 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 | // $Id: AnaEx01AnalysisManager.cc,v 1.18 2009/05/13 08:33:17 gbarrand Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Guy Barrand 14th Septembre 2000.
|
|---|
| 32 |
|
|---|
| 33 | #ifdef G4ANALYSIS_USE
|
|---|
| 34 |
|
|---|
| 35 | #include "G4ios.hh"
|
|---|
| 36 | #include "G4SDManager.hh"
|
|---|
| 37 | #include "G4Run.hh"
|
|---|
| 38 | #include "G4Event.hh"
|
|---|
| 39 | #include "G4HCofThisEvent.hh"
|
|---|
| 40 |
|
|---|
| 41 | #include <AIDA/IAnalysisFactory.h>
|
|---|
| 42 | #include <AIDA/ITreeFactory.h>
|
|---|
| 43 | #include <AIDA/ITupleFactory.h>
|
|---|
| 44 | #include <AIDA/IHistogramFactory.h>
|
|---|
| 45 | #include <AIDA/ITree.h>
|
|---|
| 46 | #include <AIDA/IHistogram1D.h>
|
|---|
| 47 | #include <AIDA/ITuple.h>
|
|---|
| 48 |
|
|---|
| 49 | #include "AnaEx01CalorHit.hh"
|
|---|
| 50 | #include "AnaEx01AnalysisManager.hh"
|
|---|
| 51 |
|
|---|
| 52 | AnaEx01AnalysisManager::AnaEx01AnalysisManager(AIDA::IAnalysisFactory* aAIDA)
|
|---|
| 53 | :fCalorimeterCollID(-1)
|
|---|
| 54 | ,fAIDA(aAIDA)
|
|---|
| 55 | ,fTree(0)
|
|---|
| 56 | ,fEAbs(0)
|
|---|
| 57 | ,fLAbs(0)
|
|---|
| 58 | ,fEGap(0)
|
|---|
| 59 | ,fLGap(0)
|
|---|
| 60 | ,fTuple(0)
|
|---|
| 61 | {
|
|---|
| 62 | // Could fail if no AIDA implementation found :
|
|---|
| 63 | if(!fAIDA) {
|
|---|
| 64 | G4cout << "AIDA analysis factory not found." << G4endl;
|
|---|
| 65 | return;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | AIDA::ITreeFactory* treeFactory = fAIDA->createTreeFactory();
|
|---|
| 69 | if(!treeFactory) return;
|
|---|
| 70 |
|
|---|
| 71 | // Create a tree-like container to handle histograms.
|
|---|
| 72 | // This tree is associated to a AnaEx01.<format> file.
|
|---|
| 73 |
|
|---|
| 74 | std::string h_name_EAbs("EAbs");
|
|---|
| 75 | std::string h_name_LAbs("LAbs");
|
|---|
| 76 | std::string h_name_EGap("EGap");
|
|---|
| 77 | std::string h_name_LGap("LGap");
|
|---|
| 78 | std::string t_name("AnaEx01");
|
|---|
| 79 |
|
|---|
| 80 | // File format :
|
|---|
| 81 | std::string format("xml");
|
|---|
| 82 | //std::string format("hbook");
|
|---|
| 83 | //std::string format("root");
|
|---|
| 84 |
|
|---|
| 85 | std::string file("AnaEx01");
|
|---|
| 86 | std::string ext;
|
|---|
| 87 | ext = "."+format;
|
|---|
| 88 |
|
|---|
| 89 | std::string opts;
|
|---|
| 90 | if(format=="hbook") {
|
|---|
| 91 | opts = "compress=no";
|
|---|
| 92 |
|
|---|
| 93 | h_name_EAbs = "1";
|
|---|
| 94 | h_name_LAbs = "2";
|
|---|
| 95 | h_name_EGap = "3";
|
|---|
| 96 | h_name_LGap = "4";
|
|---|
| 97 | t_name = "101";
|
|---|
| 98 |
|
|---|
| 99 | } else if(format=="root") {
|
|---|
| 100 | opts = "compress=yes";
|
|---|
| 101 |
|
|---|
| 102 | } else if(format=="xml") {
|
|---|
| 103 | ext = ".aida";
|
|---|
| 104 | opts = "compress=no";
|
|---|
| 105 |
|
|---|
| 106 | } else {
|
|---|
| 107 | G4cout << "storage format \"" << format << "\""
|
|---|
| 108 | << " not handled in this example."
|
|---|
| 109 | << G4endl;
|
|---|
| 110 | return;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | file += ext;
|
|---|
| 114 | fTree = treeFactory->create(file,format,false,true,opts);
|
|---|
| 115 |
|
|---|
| 116 | // Factories are not "managed" by an AIDA analysis system.
|
|---|
| 117 | // They must be deleted by the AIDA user code.
|
|---|
| 118 | delete treeFactory;
|
|---|
| 119 |
|
|---|
| 120 | if(!fTree) {
|
|---|
| 121 | G4cout << "can't create tree associated to file \"" << file << "\"."
|
|---|
| 122 | << G4endl;
|
|---|
| 123 | return;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | fTree->mkdir("histograms");
|
|---|
| 127 | fTree->cd("histograms");
|
|---|
| 128 |
|
|---|
| 129 | // Create an histo factory that will create histo in the tree :
|
|---|
| 130 | AIDA::IHistogramFactory* histoFactory =
|
|---|
| 131 | fAIDA->createHistogramFactory(*fTree);
|
|---|
| 132 | if(histoFactory) {
|
|---|
| 133 | fEAbs = histoFactory->createHistogram1D(h_name_EAbs,"EAbs",100,0,100);
|
|---|
| 134 | if(!fEAbs) G4cout << "can't create histo EAbs." << G4endl;
|
|---|
| 135 | fLAbs = histoFactory->createHistogram1D(h_name_LAbs,"LAbs",100,0,100);
|
|---|
| 136 | if(!fLAbs) G4cout << "can't create histo LAbs." << G4endl;
|
|---|
| 137 | fEGap = histoFactory->createHistogram1D(h_name_EGap,"EGap",100,0,10);
|
|---|
| 138 | if(!fEGap) G4cout << "can't create histo EGap." << G4endl;
|
|---|
| 139 | fLGap = histoFactory->createHistogram1D(h_name_LGap,"LGap",100,0,100);
|
|---|
| 140 | if(!fLGap) G4cout << "can't create histo LGap." << G4endl;
|
|---|
| 141 | delete histoFactory;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | fTree->cd("..");
|
|---|
| 145 | fTree->mkdir("tuples");
|
|---|
| 146 | fTree->cd("tuples");
|
|---|
| 147 |
|
|---|
| 148 | // Get a tuple factory :
|
|---|
| 149 | AIDA::ITupleFactory* tupleFactory = fAIDA->createTupleFactory(*fTree);
|
|---|
| 150 | if(tupleFactory) {
|
|---|
| 151 |
|
|---|
| 152 | // Create a tuple :
|
|---|
| 153 | fTuple = tupleFactory->create(t_name,"AnaEx01",
|
|---|
| 154 | "double EAbs,double LAbs,double EGap,double LGap");
|
|---|
| 155 | if(!fTuple) G4cout << "can't create tuple." << G4endl;
|
|---|
| 156 |
|
|---|
| 157 | delete tupleFactory;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | fTree->cd("..");
|
|---|
| 161 | }
|
|---|
| 162 | AnaEx01AnalysisManager::~AnaEx01AnalysisManager() {
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | void AnaEx01AnalysisManager::BeginOfRun(const G4Run* aRun){
|
|---|
| 166 | G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | void AnaEx01AnalysisManager::EndOfRun(const G4Run*){
|
|---|
| 170 | if(fTree) fTree->commit();
|
|---|
| 171 | if(fEAbs) {
|
|---|
| 172 | G4cout << "Histo : EAbs : mean " << fEAbs->mean() << " rms : " << fEAbs->rms() << G4endl;
|
|---|
| 173 | G4cout << "Histo : LAbs : mean " << fLAbs->mean() << " rms : " << fLAbs->rms() << G4endl;
|
|---|
| 174 | G4cout << "Histo : EGap : mean " << fEGap->mean() << " rms : " << fEGap->rms() << G4endl;
|
|---|
| 175 | G4cout << "Histo : LGap : mean " << fLGap->mean() << " rms : " << fLGap->rms() << G4endl;
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | void AnaEx01AnalysisManager::BeginOfEvent(const G4Event*){
|
|---|
| 180 | if(fCalorimeterCollID==-1) {
|
|---|
| 181 | G4SDManager* SDman = G4SDManager::GetSDMpointer();
|
|---|
| 182 | fCalorimeterCollID = SDman->GetCollectionID("CalCollection");
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | void AnaEx01AnalysisManager::EndOfEvent(const G4Event* aEvent){
|
|---|
| 187 | if(!fEAbs) return; // No histo booked !
|
|---|
| 188 | if(!fTuple) return; // No tuple booked !
|
|---|
| 189 |
|
|---|
| 190 | //G4int evtNb = aEvent->GetEventID();
|
|---|
| 191 |
|
|---|
| 192 | G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
|
|---|
| 193 | AnaEx01CalorHitsCollection* CHC =
|
|---|
| 194 | HCE ? (AnaEx01CalorHitsCollection*)(HCE->GetHC(fCalorimeterCollID)) : 0;
|
|---|
| 195 |
|
|---|
| 196 | if(CHC) {
|
|---|
| 197 | G4int n_hit = CHC->entries();
|
|---|
| 198 | for (G4int i=0;i<n_hit;i++) {
|
|---|
| 199 | G4double EAbs = (*CHC)[i]->GetEdepAbs();
|
|---|
| 200 | G4double LAbs = (*CHC)[i]->GetTrakAbs();
|
|---|
| 201 | G4double EGap = (*CHC)[i]->GetEdepGap();
|
|---|
| 202 | G4double LGap = (*CHC)[i]->GetTrakGap();
|
|---|
| 203 | fEAbs->fill(EAbs);
|
|---|
| 204 | fLAbs->fill(LAbs);
|
|---|
| 205 | fEGap->fill(EGap);
|
|---|
| 206 | fLGap->fill(LGap);
|
|---|
| 207 |
|
|---|
| 208 | fTuple->fill(0,EAbs);
|
|---|
| 209 | fTuple->fill(1,LAbs);
|
|---|
| 210 | fTuple->fill(2,EGap);
|
|---|
| 211 | fTuple->fill(3,LGap);
|
|---|
| 212 | fTuple->addRow();
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | }
|
|---|
| 217 | void AnaEx01AnalysisManager::Step(const G4Step*){}
|
|---|
| 218 |
|
|---|
| 219 | #endif
|
|---|