| 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.16 2006/06/29 16:33:42 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 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.aida file.
|
|---|
| 73 | //std::string opts = "compress=yes";
|
|---|
| 74 | std::string opts = "compress=no";
|
|---|
| 75 | fTree = treeFactory->create("AnaEx01.aida","xml",false,true,opts);
|
|---|
| 76 | //std::string opts = "export=root";
|
|---|
| 77 | //fTree = treeFactory->create("AnaEx01.root","ROOT",false,true,opts);
|
|---|
| 78 |
|
|---|
| 79 | // Factories are not "managed" by an AIDA analysis system.
|
|---|
| 80 | // They must be deleted by the AIDA user code.
|
|---|
| 81 | delete treeFactory;
|
|---|
| 82 |
|
|---|
| 83 | if(!fTree) return;
|
|---|
| 84 |
|
|---|
| 85 | fTree->mkdir("histograms");
|
|---|
| 86 | fTree->cd("histograms");
|
|---|
| 87 |
|
|---|
| 88 | // Create an histo factory that will create histo in the tree :
|
|---|
| 89 | AIDA::IHistogramFactory* histoFactory =
|
|---|
| 90 | fAIDA->createHistogramFactory(*fTree);
|
|---|
| 91 | if(histoFactory) {
|
|---|
| 92 | fEAbs = histoFactory->createHistogram1D("EAbs",100,0,100);
|
|---|
| 93 | fLAbs = histoFactory->createHistogram1D("LAbs",100,0,100);
|
|---|
| 94 | fEGap = histoFactory->createHistogram1D("EGap",100,0,10);
|
|---|
| 95 | fLGap = histoFactory->createHistogram1D("LGap",100,0,100);
|
|---|
| 96 | delete histoFactory;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | fTree->cd("..");
|
|---|
| 100 | fTree->mkdir("tuples");
|
|---|
| 101 | fTree->cd("tuples");
|
|---|
| 102 |
|
|---|
| 103 | // Get a tuple factory :
|
|---|
| 104 | AIDA::ITupleFactory* tupleFactory = fAIDA->createTupleFactory(*fTree);
|
|---|
| 105 | if(tupleFactory) {
|
|---|
| 106 |
|
|---|
| 107 | // Create a tuple :
|
|---|
| 108 | fTuple = tupleFactory->create("AnaEx01","AnaEx01",
|
|---|
| 109 | "double EAbs,double LAbs,double EGap,double LGap");
|
|---|
| 110 |
|
|---|
| 111 | delete tupleFactory;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | }
|
|---|
| 115 | AnaEx01AnalysisManager::~AnaEx01AnalysisManager() {
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | void AnaEx01AnalysisManager::BeginOfRun(const G4Run* aRun){
|
|---|
| 119 | G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void AnaEx01AnalysisManager::EndOfRun(const G4Run*){
|
|---|
| 123 | if(fTree) fTree->commit();
|
|---|
| 124 | if(fEAbs) {
|
|---|
| 125 | G4cout << "Histo : EAbs : mean " << fEAbs->mean() << " rms : " << fEAbs->rms() << G4endl;
|
|---|
| 126 | G4cout << "Histo : LAbs : mean " << fLAbs->mean() << " rms : " << fLAbs->rms() << G4endl;
|
|---|
| 127 | G4cout << "Histo : EGap : mean " << fEGap->mean() << " rms : " << fEGap->rms() << G4endl;
|
|---|
| 128 | G4cout << "Histo : LGap : mean " << fLGap->mean() << " rms : " << fLGap->rms() << G4endl;
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | void AnaEx01AnalysisManager::BeginOfEvent(const G4Event*){
|
|---|
| 133 | if(fCalorimeterCollID==-1) {
|
|---|
| 134 | G4SDManager* SDman = G4SDManager::GetSDMpointer();
|
|---|
| 135 | fCalorimeterCollID = SDman->GetCollectionID("CalCollection");
|
|---|
| 136 | }
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | void AnaEx01AnalysisManager::EndOfEvent(const G4Event* aEvent){
|
|---|
| 140 | if(!fEAbs) return; // No histo booked !
|
|---|
| 141 | if(!fTuple) return; // No tuple booked !
|
|---|
| 142 |
|
|---|
| 143 | //G4int evtNb = aEvent->GetEventID();
|
|---|
| 144 |
|
|---|
| 145 | G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
|
|---|
| 146 | AnaEx01CalorHitsCollection* CHC =
|
|---|
| 147 | HCE ? (AnaEx01CalorHitsCollection*)(HCE->GetHC(fCalorimeterCollID)) : 0;
|
|---|
| 148 |
|
|---|
| 149 | if(CHC) {
|
|---|
| 150 | G4int n_hit = CHC->entries();
|
|---|
| 151 | for (G4int i=0;i<n_hit;i++) {
|
|---|
| 152 | G4double EAbs = (*CHC)[i]->GetEdepAbs();
|
|---|
| 153 | G4double LAbs = (*CHC)[i]->GetTrakAbs();
|
|---|
| 154 | G4double EGap = (*CHC)[i]->GetEdepGap();
|
|---|
| 155 | G4double LGap = (*CHC)[i]->GetTrakGap();
|
|---|
| 156 | fEAbs->fill(EAbs);
|
|---|
| 157 | fLAbs->fill(LAbs);
|
|---|
| 158 | fEGap->fill(EGap);
|
|---|
| 159 | fLGap->fill(LGap);
|
|---|
| 160 |
|
|---|
| 161 | fTuple->fill(0,EAbs);
|
|---|
| 162 | fTuple->fill(1,LAbs);
|
|---|
| 163 | fTuple->fill(2,EGap);
|
|---|
| 164 | fTuple->fill(3,LGap);
|
|---|
| 165 | fTuple->addRow();
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | }
|
|---|
| 170 | void AnaEx01AnalysisManager::Step(const G4Step*){}
|
|---|
| 171 |
|
|---|
| 172 | #endif
|
|---|