| 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 | // Rich advanced example for Geant4
|
|---|
| 27 | // RichTbEventAction.cc for Rich of LHCb
|
|---|
| 28 | // History:
|
|---|
| 29 | // Created: Sajan Easo (Sajan.Easo@cern.ch)
|
|---|
| 30 | // Revision and changes: Patricia Mendez (Patricia.Mendez@cern.ch)
|
|---|
| 31 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 32 | #include "RichTbEventAction.hh"
|
|---|
| 33 | #include "G4Event.hh"
|
|---|
| 34 | #include "G4EventManager.hh"
|
|---|
| 35 | #include "G4TrajectoryContainer.hh"
|
|---|
| 36 | #include "G4Trajectory.hh"
|
|---|
| 37 | #include "G4HCofThisEvent.hh"
|
|---|
| 38 | #include "G4VHitsCollection.hh"
|
|---|
| 39 | #include "G4SDManager.hh"
|
|---|
| 40 | #include "G4VVisManager.hh"
|
|---|
| 41 | #include "G4UImanager.hh"
|
|---|
| 42 | #include "G4ios.hh"
|
|---|
| 43 | #include "RichTbSD.hh"
|
|---|
| 44 | #include "RichTbHit.hh"
|
|---|
| 45 | #include "RichTbRunConfig.hh"
|
|---|
| 46 | #include "RichTbAnalysisManager.hh"
|
|---|
| 47 | #include "RichTbIOData.hh"
|
|---|
| 48 |
|
|---|
| 49 | RichTbEventAction::RichTbEventAction()
|
|---|
| 50 | {
|
|---|
| 51 | RichTbCollID = -1;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | RichTbEventAction::RichTbEventAction(RichTbRunConfig* RConfig,
|
|---|
| 55 | G4VVisManager* RVisManager, RichTbIOData* RIOData)
|
|---|
| 56 | {
|
|---|
| 57 | RichTbCollID = -1;
|
|---|
| 58 | runConfiguration=RConfig;
|
|---|
| 59 |
|
|---|
| 60 | pVisManager=RVisManager;
|
|---|
| 61 | rTbIOData = RIOData;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | RichTbEventAction::~RichTbEventAction()
|
|---|
| 65 | {
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void RichTbEventAction::BeginOfEventAction(const G4Event* evt)
|
|---|
| 69 | {
|
|---|
| 70 |
|
|---|
| 71 | G4SDManager * SDman = G4SDManager::GetSDMpointer();
|
|---|
| 72 | if(RichTbCollID<0){
|
|---|
| 73 | RichTbCollID = SDman->GetCollectionID("RichTbHitsCollection");
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | #ifdef G4ANALYSIS_USE
|
|---|
| 77 | RichTbAnalysisManager * analysis = RichTbAnalysisManager::getInstance();
|
|---|
| 78 | analysis->BeginOfEventAnalysis(evt);
|
|---|
| 79 | #endif
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | void RichTbEventAction::EndOfEventAction(const G4Event* evt)
|
|---|
| 83 | {
|
|---|
| 84 | RichTbRunConfig* RConfig = runConfiguration;
|
|---|
| 85 |
|
|---|
| 86 | // first get the trajectories
|
|---|
| 87 | G4TrajectoryContainer* trajectoryContainer=evt->GetTrajectoryContainer();
|
|---|
| 88 | G4int n_trajectories=0;
|
|---|
| 89 |
|
|---|
| 90 | G4int totalhits = 0;
|
|---|
| 91 |
|
|---|
| 92 | if(trajectoryContainer){n_trajectories=trajectoryContainer->entries();
|
|---|
| 93 | G4cout << " " << n_trajectories
|
|---|
| 94 | << " Tracks are stored in Trajectorycontainer." << G4endl;
|
|---|
| 95 | }
|
|---|
| 96 | // Now get the hits
|
|---|
| 97 |
|
|---|
| 98 | if(RichTbCollID<0) return;
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
|
|---|
| 102 | RichTbHitsCollection* RHC = 0;
|
|---|
| 103 | G4int n_hit = 0;
|
|---|
| 104 |
|
|---|
| 105 | if(HCE)
|
|---|
| 106 | {
|
|---|
| 107 |
|
|---|
| 108 | RHC = (RichTbHitsCollection*)(HCE->GetHC(RichTbCollID));
|
|---|
| 109 |
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | if(RHC)
|
|---|
| 113 | {
|
|---|
| 114 | n_hit = RHC->entries();
|
|---|
| 115 | for(G4int i=0;i<n_hit;i++)
|
|---|
| 116 | {
|
|---|
| 117 | totalhits += i;
|
|---|
| 118 | }
|
|---|
| 119 | // G4cout << " " << n_hit
|
|---|
| 120 | // << " hits are stored in RichTbHitsCollection." << G4endl;
|
|---|
| 121 | }
|
|---|
| 122 | if(RConfig->getRichTbDrawTrajectory() > 0)
|
|---|
| 123 | {
|
|---|
| 124 | for (G4int i=0; i<n_trajectories; i++)
|
|---|
| 125 | {
|
|---|
| 126 | (*(evt->GetTrajectoryContainer()))[i]->DrawTrajectory();
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | //now for the hits.
|
|---|
| 131 |
|
|---|
| 132 | if(RHC)
|
|---|
| 133 | {
|
|---|
| 134 | G4int n_hith = RHC->entries();
|
|---|
| 135 | for (G4int ih=0; ih<n_hith; ih++ )
|
|---|
| 136 | {
|
|---|
| 137 | RichTbHit* aHit = (*RHC)[ih];
|
|---|
| 138 | aHit->DrawWithVisM(pVisManager);
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | //Now to Fill the Histograms
|
|---|
| 143 |
|
|---|
| 144 | #ifdef G4ANALYSIS_USE
|
|---|
| 145 | RichTbAnalysisManager * analysis = RichTbAnalysisManager::getInstance();
|
|---|
| 146 | analysis->EndOfEventAnalysis(evt);
|
|---|
| 147 | #endif
|
|---|
| 148 |
|
|---|
| 149 | // Now to write out the data
|
|---|
| 150 | if(RConfig -> DoWriteOutputFile() )
|
|---|
| 151 | {
|
|---|
| 152 | rTbIOData -> WriteOutEventHeaderData(evt);
|
|---|
| 153 | rTbIOData -> WriteOutHitData(evt);
|
|---|
| 154 | G4cout << ">>> End of Event Number " << evt->GetEventID() << G4endl;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|