[1316] | 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 | // FredTrackCheck.cc |
---|
| 28 | // |
---|
| 29 | // Implemenation of track hit checker |
---|
| 30 | // |
---|
| 31 | |
---|
| 32 | #include "FredTrackCheck.hh" |
---|
| 33 | |
---|
| 34 | // |
---|
| 35 | // Constructor |
---|
| 36 | // |
---|
| 37 | FredTrackCheck::FredTrackCheck() {;} |
---|
| 38 | |
---|
| 39 | // |
---|
| 40 | // Destructor |
---|
| 41 | // |
---|
| 42 | FredTrackCheck::~FredTrackCheck() |
---|
| 43 | { |
---|
| 44 | Clear(); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | // |
---|
| 49 | // AddInHit |
---|
| 50 | // |
---|
| 51 | // Associated a new "in" hit with the track |
---|
| 52 | // |
---|
| 53 | void FredTrackCheck::AddInHit( const G4Track *track ) |
---|
| 54 | { |
---|
| 55 | // |
---|
| 56 | // Do we already know about this track? |
---|
| 57 | // |
---|
| 58 | FredTrackData *trackData = 0; |
---|
| 59 | FredTrackData *target = new FredTrackData( track->GetTrackID() ); |
---|
| 60 | |
---|
| 61 | std::vector<FredTrackData*>::const_iterator i; |
---|
| 62 | for (i=hitList.begin(); i!=hitList.end(); ++i) { |
---|
| 63 | if (**i==*target) { |
---|
| 64 | trackData = *i; |
---|
| 65 | break; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | if (trackData) { |
---|
| 69 | |
---|
| 70 | // |
---|
| 71 | // Yup: increment appropriately |
---|
| 72 | // |
---|
| 73 | trackData->IncrementIn(); |
---|
| 74 | delete target; |
---|
| 75 | } |
---|
| 76 | else { |
---|
| 77 | // |
---|
| 78 | // Nope: make one |
---|
| 79 | // |
---|
| 80 | target->IncrementIn(); |
---|
| 81 | hitList.push_back( target ); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // |
---|
| 86 | // AddOutHit |
---|
| 87 | // |
---|
| 88 | // Associated a new "out" hit with the track |
---|
| 89 | // |
---|
| 90 | void FredTrackCheck::AddOutHit( const G4Track *track ) |
---|
| 91 | { |
---|
| 92 | // |
---|
| 93 | // Do we already know about this track? |
---|
| 94 | // |
---|
| 95 | FredTrackData *trackData = 0; |
---|
| 96 | FredTrackData *target = new FredTrackData( track->GetTrackID() ); |
---|
| 97 | |
---|
| 98 | std::vector<FredTrackData*>::const_iterator i; |
---|
| 99 | for (i=hitList.begin(); i!=hitList.end(); ++i) { |
---|
| 100 | if (**i==*target) { |
---|
| 101 | trackData = *i; |
---|
| 102 | break; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | if (trackData) { |
---|
| 106 | |
---|
| 107 | // |
---|
| 108 | // Yup: increment appropriately |
---|
| 109 | // |
---|
| 110 | trackData->IncrementOut(); |
---|
| 111 | delete target; |
---|
| 112 | } |
---|
| 113 | else { |
---|
| 114 | // |
---|
| 115 | // Nope: make one |
---|
| 116 | // |
---|
| 117 | target->IncrementOut(); |
---|
| 118 | hitList.push_back( target ); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | // |
---|
| 123 | // GetTrackStat |
---|
| 124 | // |
---|
| 125 | // Return statistics on specified track |
---|
| 126 | // |
---|
| 127 | void FredTrackCheck::GetTrackStat( const G4Track *track, G4int *nIn, G4int *nOut ) |
---|
| 128 | { |
---|
| 129 | GetTrackStatID( track->GetTrackID(), nIn, nOut ); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | // |
---|
| 133 | // GetTrackStatID |
---|
| 134 | // |
---|
| 135 | // Return statistics on specified track |
---|
| 136 | // |
---|
| 137 | void FredTrackCheck::GetTrackStatID( G4int trackID, G4int *nIn, G4int *nOut ) |
---|
| 138 | { |
---|
| 139 | FredTrackData *trackData = 0; |
---|
| 140 | FredTrackData target( trackID ); |
---|
| 141 | |
---|
| 142 | std::vector<FredTrackData*>::const_iterator i; |
---|
| 143 | for (i=hitList.begin(); i!=hitList.end(); ++i) { |
---|
| 144 | if (**i==target) { |
---|
| 145 | trackData = *i; |
---|
| 146 | break; |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | if (trackData) { |
---|
| 150 | *nIn = trackData->GetNIn(); |
---|
| 151 | *nOut = trackData->GetNOut(); |
---|
| 152 | } |
---|
| 153 | else { |
---|
| 154 | *nIn = 0; |
---|
| 155 | *nOut = 0; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | // |
---|
| 161 | // ClearAll |
---|
| 162 | // |
---|
| 163 | // Clear all track data |
---|
| 164 | // |
---|
| 165 | void FredTrackCheck::Clear() |
---|
| 166 | { |
---|
| 167 | FredTrackData* a = 0; |
---|
| 168 | std::vector<FredTrackData*>::iterator i; |
---|
| 169 | while (hitList.size()>0) |
---|
| 170 | { |
---|
| 171 | a = hitList.back(); |
---|
| 172 | hitList.pop_back(); |
---|
| 173 | for (i=hitList.begin(); i!=hitList.end(); i++) |
---|
| 174 | { |
---|
| 175 | if (*i==a) |
---|
| 176 | { |
---|
| 177 | hitList.erase(i); |
---|
| 178 | i--; |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | if ( a ) delete a; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|