00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 const int DEBUG = 0;
00014
00015
00016
00017 #include "BDSGlobalConstants.hh"
00018
00019 #include "BDSEventAction.hh"
00020
00021 #include <ctime>
00022 #include <vector>
00023 #include <algorithm>
00024
00025 #include "G4Event.hh"
00026 #include "G4EventManager.hh"
00027 #include "G4Run.hh"
00028 #include "G4RunManager.hh"
00029 #include "G4StackManager.hh"
00030 #include "G4HCofThisEvent.hh"
00031 #include "G4VHitsCollection.hh"
00032 #include "G4TrajectoryContainer.hh"
00033 #include "G4Trajectory.hh"
00034 #include "G4VVisManager.hh"
00035 #include "G4SDManager.hh"
00036 #include "G4UImanager.hh"
00037 #include "G4ios.hh"
00038 #include "G4UnitsTable.hh"
00039 #include "Randomize.hh"
00040
00041 #include "G4FieldManager.hh"
00042 #include "G4ChordFinder.hh"
00043
00044 #include "BDSSampler.hh"
00045 #include "BDSSamplerHit.hh"
00046 #include "BDSEnergyCounterHit.hh"
00047
00048 #include "BDSLWCalorimeter.hh"
00049 #include "BDSLWCalorimeterHit.hh"
00050
00051 #include "BDSSynchrotronRadiation.hh"
00052
00053 #include "BDSAcceleratorComponent.hh"
00054
00055 #include "BDSOutput.hh"
00056
00057 #include "BDSRunManager.hh"
00058
00059
00060
00061
00062
00063
00064
00065 typedef std::map<G4String,int> LogVolCountMap;
00066 extern LogVolCountMap* LogVolCount;
00067
00068 typedef list<BDSEnergyCounterSD*> ECList;
00069 extern ECList* theECList;
00070
00071 extern G4double BDSeBremFireDist;
00072 extern G4double BDSeBremZMin,BDSeBremZMax;
00073
00074
00075 extern G4bool BDSeBremsFiredThisEvent;
00076 extern G4double BDSeBremFireDist;
00077
00078 G4double htot;
00079 G4int event_number;
00080 G4bool FireLaserCompton;
00081
00082
00083 extern BDSOutput bdsOutput;
00084 extern G4String outputFilename;
00085 extern G4bool isBatch;
00086
00087
00088 extern G4bool verbose;
00089 extern G4bool verboseStep;
00090 extern G4bool verboseEvent;
00091 extern G4int verboseEventNumber;
00092 extern G4bool isBatch;
00093
00094 extern int nptwiss;
00095
00096
00097
00098
00099 BDSEventAction::BDSEventAction()
00100 :SamplerCollID_plane(-1),SamplerCollID_cylin(-1),
00101 LWCalorimeterCollID(-1),drawFlag("all")
00102 {
00103 if(isBatch) printModulo=1000;
00104 else printModulo=1;
00105
00106 itsOutputFileNumber=1;
00107
00108 itsRecordSize=1024;
00109
00110 LastComp=NULL;
00111 }
00112
00113
00114
00115 BDSEventAction::~BDSEventAction()
00116 {
00117 }
00118
00119
00120
00121 void BDSEventAction::BeginOfEventAction(const G4Event* evt)
00122 {
00123 if(DEBUG) G4cout<<"BDSEventAction : processing begin of event action"<<G4endl;
00124
00125 event_number = evt->GetEventID();
00126 htot=0.;
00127
00128
00129
00130
00131
00132
00133 if(BDSGlobals->DoTwiss())
00134 {
00135 if(event_number==0) {
00136 if(!BDSGlobals->GetSynchRescale()) G4cout << "\n---> Calculating Twiss Parameters"<<G4endl;
00137 if(BDSGlobals->GetSynchRescale()) G4cout<<"\n---> Calculating Twiss Parameters and Rescaling magnets" <<G4endl;
00138 }
00139 }
00140 else
00141 {
00142 if ((event_number+1)%printModulo ==0)
00143 {
00144 G4cout << "\n---> Begin of event: " << event_number ;
00145
00146
00147
00148
00149
00150
00151
00152 G4cout << G4endl;
00153 }
00154 }
00155
00156 if(verboseEvent) G4cout<<"Begin of event: "<<event_number<<G4endl ;
00157
00158
00159 G4SDManager * SDman = G4SDManager::GetSDMpointer();
00160
00161
00162 {
00163
00164 SamplerCollID_plane = SDman->GetCollectionID("Sampler_plane");
00165 }
00166
00167
00168 {
00169
00170
00171 }
00172
00173
00174 {
00175
00176
00177 }
00178 FireLaserCompton=true;
00179
00180 if(DEBUG) G4cout<<"BDSEventAction : begin of event action done"<<G4endl;
00181 }
00182
00183
00184
00185 void BDSEventAction::EndOfEventAction(const G4Event* evt)
00186 {
00187 if(DEBUG) G4cout<<"BDSEventAction : processing end of event action"<<G4endl;
00188
00189 if(BDSGlobals->DoTwiss())
00190 {
00191 if(event_number==nptwiss-1)
00192 {
00193 G4cout << "\n---> Done" <<G4endl;
00194 G4EventManager::GetEventManager()->GetStackManager()->clear();
00195 }
00196 }
00197
00198
00199 if(verboseEvent || verboseEventNumber == event_number)
00200 G4cout<<"processing end of event"<<G4endl;
00201
00202 G4SDManager * SDman = G4SDManager::GetSDMpointer();
00203
00204 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
00205
00206 BDSSamplerHitsCollection* SampHC=NULL;
00207
00208 BDSEnergyCounterHitsCollection* BDSEnergyCounter_HC=NULL;
00209
00210 if(DEBUG) G4cout<<"BDSEventAction : storing hits"<<G4endl;
00211
00212
00213
00214
00215 if(DEBUG) G4cout<<"BDSEventAction : processing planar hits collection"<<G4endl;
00216
00217 if(SamplerCollID_plane>=0)
00218 SampHC = (BDSSamplerHitsCollection*)(HCE->GetHC(SamplerCollID_plane));
00219
00220 if(SampHC) bdsOutput.WriteHits(SampHC);
00221
00222
00223 SampHC=NULL;
00224
00225
00226
00227
00228 if(DEBUG) G4cout<<"BDSEventAction : processing cylinder hits collection"<<G4endl;
00229
00230 if(SamplerCollID_cylin>=0)
00231 SampHC = (BDSSamplerHitsCollection*)(HCE->GetHC(SamplerCollID_cylin));
00232
00233 if (SampHC) bdsOutput.WriteHits(SampHC);
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 if(DEBUG) G4cout<<"BDSEventAction : storing energy loss histograms"<<G4endl;
00252
00253 for(iEC=theECList->begin();iEC!=theECList->end();iEC++)
00254 {
00255 G4String name=(*iEC)->GetCollectionName(0);
00256
00257 G4int BDSEnergyCounter_ID= SDman->GetCollectionID(name);
00258
00259 if(BDSEnergyCounter_ID>=0)
00260 {
00261 BDSEnergyCounter_HC=
00262 (BDSEnergyCounterHitsCollection*)(HCE->GetHC(BDSEnergyCounter_ID));
00263
00264 if(BDSEnergyCounter_HC)
00265 bdsOutput.WriteEnergyLoss(BDSEnergyCounter_HC);
00266 }
00267 }
00268
00269
00270
00271
00272 int evntsPerNtuple = BDSGlobals->GetNumberOfEventsPerNtuple();
00273
00274 if(evntsPerNtuple>0)
00275 if ((event_number+1)% evntsPerNtuple == 0 &&
00276 event_number+1 != BDSGlobals->GetNumberToGenerate())
00277 {
00278 if(DEBUG) G4cout<<"writing to file "<<G4endl;
00279
00280
00281 bdsOutput.Commit(itsOutputFileNumber++);
00282 if(DEBUG) G4cout<<"done"<<G4endl;
00283 }
00284
00285
00286
00287
00288
00289 if(DEBUG) G4cout<<"BDSEventAction : storing trajectories"<<G4endl;
00290
00291 G4TrajectoryContainer* TrajCont=evt->GetTrajectoryContainer();
00292
00293 if(!TrajCont) return;
00294
00295 TrajectoryVector* TrajVec=TrajCont->GetVector();
00296 bdsOutput.WriteTrajectory(TrajVec);
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 if(!isBatch) evt->Draw();
00323
00324
00325 TrajectoryVector::iterator iT;
00326 if(TrajVec)
00327 {
00328 for(iT=TrajVec->begin();iT<TrajVec->end();iT++)
00329 {
00330 G4Trajectory* Traj=(G4Trajectory*)(*iT);
00331 delete Traj;
00332 TrajVec->erase(iT);
00333 iT--;
00334 }
00335 }
00336
00337 if(DEBUG) G4cout<<"BDSEventAction : end of event action done"<<G4endl;
00338 }
00339
00340