[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 | // Rich advanced example for Geant4 |
---|
| 27 | // RichTbAnalysisManager.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 "G4Timer.hh" |
---|
| 33 | #include "globals.hh" |
---|
| 34 | #include "fstream" |
---|
| 35 | #include <ctype.h> |
---|
| 36 | #include "G4ios.hh" |
---|
| 37 | #include "G4Run.hh" |
---|
| 38 | #include "G4Event.hh" |
---|
| 39 | #include "G4Track.hh" |
---|
| 40 | #include "G4VVisManager.hh" |
---|
| 41 | #include "G4TrajectoryContainer.hh" |
---|
| 42 | #include "G4Trajectory.hh" |
---|
| 43 | #include "G4SteppingManager.hh" |
---|
| 44 | |
---|
| 45 | #include "G4SDManager.hh" |
---|
| 46 | #include "G4HCofThisEvent.hh" |
---|
| 47 | #include "RichTbHit.hh" |
---|
| 48 | #include "RichTbRunConfig.hh" |
---|
| 49 | |
---|
| 50 | #include "RichTbAnalysisMessenger.hh" |
---|
| 51 | |
---|
| 52 | #ifdef G4ANALYSIS_USE |
---|
| 53 | #include "RichTbAnalysisManager.hh" |
---|
| 54 | #include "AIDA/AIDA.h" |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | RichTbAnalysisManager* RichTbAnalysisManager::instance = 0; |
---|
| 59 | |
---|
| 60 | RichTbAnalysisManager::RichTbAnalysisManager() |
---|
| 61 | :outputFileName("rich.his"), analysisFactory(0),tree(0),histogramFactory(0) |
---|
| 62 | { |
---|
| 63 | |
---|
| 64 | iTimer = new G4Timer; |
---|
| 65 | NumPhotBeforeAerogel=0; |
---|
| 66 | NumPhotBeforeMirror=0; |
---|
| 67 | NumPhotAfterMirror=0; |
---|
| 68 | NumPhotBeforeFilter=0; |
---|
| 69 | NumPhotAfterFilter=0; |
---|
| 70 | NumPhotAtHpd1Input=0; |
---|
| 71 | NumPhotAtHpd2Input=0; |
---|
| 72 | NumPhotAtHpd3Input=0; |
---|
| 73 | NumPhotAtHpd4Input=0; |
---|
| 74 | NumHitTotInHpd1=0; |
---|
| 75 | NumHitTotInHpd2=0; |
---|
| 76 | NumHitTotInHpd3=0; |
---|
| 77 | NumHitTotInHpd4=0; |
---|
| 78 | NumHitInSi=0; |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | analisysMessenger = new RichTbAnalysisMessenger(this); |
---|
| 82 | |
---|
| 83 | // Hooking an AIDA compliant analysis system. |
---|
| 84 | analysisFactory = AIDA_createAnalysisFactory(); |
---|
| 85 | if(analysisFactory) { |
---|
| 86 | |
---|
| 87 | AIDA::ITreeFactory* treeFactory = analysisFactory->createTreeFactory(); |
---|
| 88 | if(treeFactory) { |
---|
| 89 | |
---|
| 90 | tree = treeFactory->create(outputFileName,"hbook",false,true); |
---|
| 91 | |
---|
| 92 | delete treeFactory; // Will not delete the ITree. |
---|
| 93 | histogramFactory = analysisFactory->createHistogramFactory(*tree); |
---|
| 94 | |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | RichTbAnalysisManager::~RichTbAnalysisManager(){ |
---|
| 101 | |
---|
| 102 | delete histogramFactory; |
---|
| 103 | histogramFactory = 0; |
---|
| 104 | |
---|
| 105 | delete analysisFactory; |
---|
| 106 | analysisFactory = 0; |
---|
| 107 | |
---|
| 108 | delete instance; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | RichTbAnalysisManager* RichTbAnalysisManager::getInstance() |
---|
| 112 | { |
---|
| 113 | if(instance==0) {instance = new RichTbAnalysisManager;} |
---|
| 114 | return instance; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void RichTbAnalysisManager::book() |
---|
| 118 | { |
---|
| 119 | |
---|
| 120 | fhistoNrPhotG = histogramFactory->createHistogram1D("1","Number of Photon Hits per Track",120,0.,20.); |
---|
| 121 | fhistoNBeforeMirror = histogramFactory->createHistogram1D("2","Number of Photons before Mirror",100,0.,750.); |
---|
| 122 | fhistoWBeforeMirror = histogramFactory->createHistogram1D("3","WaveLength of Photons before Mirror",100,200.,800.); |
---|
| 123 | fhistoWAfterMirror = histogramFactory->createHistogram1D("4","WaveLength of Photons after Mirror",100,200.,800.); |
---|
| 124 | fhistoCkvProdSmall = histogramFactory->createHistogram1D("9","Cherekov Angle at roduction all angles",500,0.,0.5); |
---|
| 125 | fhistoEmisZ = histogramFactory->createHistogram1D("10","Z of the Photon Emission Point",120,0.,600.); |
---|
| 126 | fhistoCkvRadius = histogramFactory->createHistogram1D("5","Cherenkov Ring Radius",300,80.,220.); |
---|
| 127 | |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void RichTbAnalysisManager::finish() |
---|
| 131 | { |
---|
| 132 | if(tree){ |
---|
| 133 | |
---|
| 134 | tree->commit(); //Write histos and ntuples in file |
---|
| 135 | tree->close(); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | void RichTbAnalysisManager::BeginOfEventAnalysis(const G4Event*){ |
---|
| 142 | |
---|
| 143 | //RichCollId is already defined in LHCbRichSimEventAction.cc |
---|
| 144 | // Hence its extraction is not repeated here. |
---|
| 145 | iTimer->Start(); |
---|
| 146 | NumPhotBeforeAerogel=0; |
---|
| 147 | NumPhotBeforeMirror=0; |
---|
| 148 | NumPhotAfterMirror=0; |
---|
| 149 | NumPhotBeforeFilter=0; |
---|
| 150 | NumPhotAfterFilter=0; |
---|
| 151 | NumPhotAtHpd1Input=0; |
---|
| 152 | NumPhotAtHpd2Input=0; |
---|
| 153 | NumPhotAtHpd3Input=0; |
---|
| 154 | NumPhotAtHpd4Input=0; |
---|
| 155 | NumHitTotInHpd1=0; |
---|
| 156 | NumHitTotInHpd2=0; |
---|
| 157 | NumHitTotInHpd3=0; |
---|
| 158 | NumHitTotInHpd4=0; |
---|
| 159 | NumHitInSi=0; |
---|
| 160 | |
---|
| 161 | } |
---|
| 162 | void RichTbAnalysisManager::EndOfEventAnalysis(const G4Event* evt){ |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | iTimer->Stop(); |
---|
| 167 | // G4double TimeforThisEvent= iTimer->GetRealElapsed(); |
---|
| 168 | |
---|
| 169 | G4SDManager * SDman = G4SDManager::GetSDMpointer(); |
---|
| 170 | |
---|
| 171 | G4String colNam; |
---|
| 172 | G4int RichTbCollID = SDman->GetCollectionID(colNam="RichTbHitsCollection"); |
---|
| 173 | |
---|
| 174 | G4int RichTbc = RichTbCollID; |
---|
| 175 | G4int evtNb = evt->GetEventID(); |
---|
| 176 | |
---|
| 177 | if(RichTbc<0) return; |
---|
| 178 | G4HCofThisEvent * HCE = evt->GetHCofThisEvent(); |
---|
| 179 | RichTbHitsCollection* RHC = |
---|
| 180 | HCE ? (RichTbHitsCollection*)(HCE->GetHC(RichTbc)) : 0; |
---|
| 181 | if(RHC) |
---|
| 182 | { |
---|
| 183 | |
---|
| 184 | int n_hit = RHC->entries(); |
---|
| 185 | G4cout << " " << n_hit |
---|
| 186 | << " hits are stored in RichTbHitsCollection in event "<<evtNb<< G4endl; |
---|
| 187 | //fill the final number of hits in this event into a histogram |
---|
| 188 | |
---|
| 189 | fhistoNrPhotG->fill(n_hit*1.0); |
---|
| 190 | |
---|
| 191 | //To print and plot the number of hits per each HPD. |
---|
| 192 | |
---|
| 193 | for (G4int iha=0; iha<n_hit; iha++ ) { |
---|
| 194 | |
---|
| 195 | RichTbHit* aHit = (*RHC)[iha]; |
---|
| 196 | G4int CurHpdnum = aHit -> GetCurHpdNum(); |
---|
| 197 | if(CurHpdnum == 0 ) { |
---|
| 198 | NumHitTotInHpd1++; |
---|
| 199 | |
---|
| 200 | }else if (CurHpdnum == 1 ) { |
---|
| 201 | NumHitTotInHpd2++; |
---|
| 202 | |
---|
| 203 | }else if (CurHpdnum == 2 ) { |
---|
| 204 | NumHitTotInHpd3++; |
---|
| 205 | |
---|
| 206 | }else if (CurHpdnum == 3 ) { |
---|
| 207 | NumHitTotInHpd4++; |
---|
| 208 | |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | //fill the number of photons before mirror into a histogram |
---|
| 214 | |
---|
| 215 | fhistoNBeforeMirror->fill(NumPhotBeforeMirror); |
---|
| 216 | |
---|
| 217 | G4cout<<"NumPhot before mirror "<<NumPhotBeforeMirror<<G4endl; |
---|
| 218 | G4cout<<"NumPhot after mirror "<<NumPhotAfterMirror<<G4endl; |
---|
| 219 | G4cout<<"NumPhot incident on Hpd 1 2 3 4 = "<< NumPhotAtHpd1Input |
---|
| 220 | <<" "<< NumPhotAtHpd2Input<<" "<< NumPhotAtHpd3Input |
---|
| 221 | <<" "<< NumPhotAtHpd4Input<<G4endl; |
---|
| 222 | |
---|
| 223 | G4cout<<"Number of Si hits in Hpd 1 2 3 4 are "<<NumHitTotInHpd1 |
---|
| 224 | <<" "<<NumHitTotInHpd2<<" "<<NumHitTotInHpd3 |
---|
| 225 | <<" "<<NumHitTotInHpd4<<G4endl; |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | } |
---|
| 231 | //void RichTbAnalysisManager::StepAnalysis( |
---|
| 232 | // const G4SteppingManager* aSteppingManager ){ |
---|
| 233 | |
---|
| 234 | //} |
---|
| 235 | void RichTbAnalysisManager::setMeanHXCoord(G4double cx ) { |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | G4double hcurx = NumHXCoord+1.0; |
---|
| 239 | if(hcurx != 0.0 ) { |
---|
| 240 | G4double Mhx = MeanHXCoord * (NumHXCoord / hcurx) + cx/hcurx ; |
---|
| 241 | MeanHXCoord = Mhx; |
---|
| 242 | NumHXCoord = hcurx; |
---|
| 243 | |
---|
| 244 | }else { G4cout<< "Zero hcurx in setMeanHXCoord "<<G4endl; } |
---|
| 245 | } |
---|
| 246 | void RichTbAnalysisManager::setMeanHYCoord(G4double cy ) { |
---|
| 247 | |
---|
| 248 | G4double hcury = NumHYCoord+1.0; |
---|
| 249 | if(hcury != 0.0 ) { |
---|
| 250 | G4double Mhy = MeanHYCoord * (NumHYCoord / hcury) + cy/hcury ; |
---|
| 251 | MeanHYCoord = Mhy; |
---|
| 252 | NumHYCoord = hcury; |
---|
| 253 | }else { G4cout<< "Zero hcury in setMeanHYCoord "<<G4endl; } |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | void RichTbAnalysisManager::SetOutputFileName(G4String newName) |
---|
| 258 | { |
---|
| 259 | outputFileName = newName; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | #endif |
---|
| 270 | |
---|