MollerAnalysis.cc
Go to the documentation of this file.00001
00002 #include "MollerAnalysis.hh"
00003 #include "MollerDetectorHit.hh"
00004 #include "RootAnalysis.hh"
00005
00006 #include "G4SystemOfUnits.hh"
00007 #include "G4ios.hh"
00008
00009 #include "G4RunManager.hh"
00010 #include "G4VPhysicalVolume.hh"
00011 #include "G4Event.hh"
00012 #include "G4Run.hh"
00013 #include "G4Track.hh"
00014 #include "G4Material.hh"
00015 #include "G4ClassificationOfNewTrack.hh"
00016 #include "G4TrackStatus.hh"
00017 #include "G4Step.hh"
00018 #include "G4Types.hh"
00019
00020 #include "G4HCofThisEvent.hh"
00021 #include "G4VHitsCollection.hh"
00022 #include "G4TrajectoryContainer.hh"
00023 #include "G4Trajectory.hh"
00024 #include "G4VVisManager.hh"
00025 #include "G4SDManager.hh"
00026 #include "G4UImanager.hh"
00027 #include "G4UIcommand.hh"
00028
00029 #include "MollerAnalysisMessenger.hh"
00030 #include "MollerDetectorConstruction.hh"
00031
00032 #include <time.h>
00033 #include <iostream>
00034
00035 #include "TROOT.h"
00036 #include "TNtuple.h"
00037 #include "TApplication.h"
00038 #include "TSystem.h"
00039
00040 using namespace std;
00041
00042 MollerAnalysis::MollerAnalysis()
00043 {
00044 if (gSystem) gSystem->ProcessEvents();
00045
00046 ev_num=0;
00047 partType=-1;
00048 splitProcess=-1;
00049 creatorProcess=-1;
00050 index=-1;
00051
00052
00053
00054
00055
00056 verboseLevel=0;
00057
00058 kineE0=0; kineE1=0; kineE2=0;
00059
00060 px0=0; py0=0; pz0=0;
00061 px1=0; py1=0; pz1=0;
00062 px2=0; py2=0; pz2=0;
00063
00064 theta0=0; theta1=0; theta2=0;
00065
00066 x0=0; y0=0; z0=0;
00067
00068 analysisMessenger = new MollerAnalysisMessenger(this);
00069
00070 }
00071 MollerAnalysis::MollerAnalysis(MollerDetectorConstruction* detector)
00072 :myDetector(detector)
00073 {
00074 if (gSystem) gSystem->ProcessEvents();
00075
00076 G4int NUM_COLS = myDetector->getNumColl();
00077
00078 NUM_DETS = NUM_COLS;
00079 G4cout<<G4endl<<G4endl<<"NUM_COLS = "<<NUM_COLS<<G4endl<<G4endl;
00080
00081 ev_num=0;
00082 partType=-1;
00083 splitProcess=-1;
00084 creatorProcess=-1;
00085 index=-1;
00086
00087
00088
00089
00090
00091 verboseLevel=0;
00092
00093 kineE0=0; kineE1=0; kineE2=0;
00094
00095 px0=0; py0=0; pz0=0;
00096 px1=0; py1=0; pz1=0;
00097 px2=0; py2=0; pz2=0;
00098
00099 theta0=0; theta1=0; theta2=0;
00100
00101 x0=0; y0=0; z0=0;
00102
00103 analysisMessenger = new MollerAnalysisMessenger(this);
00104
00105 }
00106
00107 MollerAnalysis::MollerAnalysis(const MollerAnalysis &right)
00108 : RootAnalysis()
00109 {
00110 if (gSystem) gSystem->ProcessEvents();
00111
00112 ev_num=right.ev_num;
00113 partType=right.partType;
00114 splitProcess=right.splitProcess;
00115 creatorProcess=right.creatorProcess;
00116 index=right.index;
00117
00118
00119
00120
00121
00122
00123 verboseLevel=right.verboseLevel;
00124
00125 kineE0=right.kineE0;
00126 kineE1=right.kineE1;
00127 kineE2=right.kineE2;
00128
00129 px0=right.px0;
00130 py0=right.py0;
00131 pz0=right.pz0;
00132
00133 px1=right.px1;
00134 py1=right.py1;
00135 pz1=right.pz1;
00136
00137 px2=right.px2;
00138 py2=right.py2;
00139 pz2=right.pz2;
00140
00141 theta0=right.theta0;
00142 theta1=right.theta1;
00143 theta2=right.theta2;
00144
00145 x0=right.x0;
00146 y0=right.y0;
00147 z0=right.z0;
00148
00149 }
00150
00151 const MollerAnalysis& MollerAnalysis::operator=(const MollerAnalysis &right)
00152 {
00153 if (gSystem) gSystem->ProcessEvents();
00154
00155 ev_num=right.ev_num;
00156 partType=right.partType;
00157 splitProcess=right.splitProcess;
00158 creatorProcess=right.creatorProcess;
00159 index=right.index;
00160
00161
00162
00163
00164
00165 verboseLevel=right.verboseLevel;
00166
00167 kineE0=right.kineE0;
00168 kineE1=right.kineE1;
00169 kineE2=right.kineE2;
00170
00171 px0=right.px0;
00172 py0=right.py0;
00173 pz0=right.pz0;
00174
00175 px1=right.px1;
00176 py1=right.py1;
00177 pz1=right.pz1;
00178
00179 px2=right.px2;
00180 py2=right.py2;
00181 pz2=right.pz2;
00182
00183 theta0=right.theta0;
00184 theta1=right.theta1;
00185 theta2=right.theta2;
00186
00187 x0=right.x0;
00188 y0=right.y0;
00189 z0=right.z0;
00190
00191 return *this;
00192
00193 }
00194
00195 MollerAnalysis::~MollerAnalysis()
00196 {
00197 delete analysisMessenger;
00198 }
00199 void MollerAnalysis::SetRootFileName(const G4String& nam)
00200 {
00201 rootfileName = nam;
00202 }
00203
00204
00205 void MollerAnalysis::BeginOfRunAction(const G4Run* )
00206 {
00207 if (gSystem) gSystem->ProcessEvents();
00208
00209 G4cout << "Run Action has been entered\n" << G4endl;
00210
00211 G4cout << "Root file name is "<<rootfileName << G4endl;
00212
00213
00214
00215
00216 G4String filenamechar=(rootfileName+".root");
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 hfile = new TFile(filenamechar,"RECREATE","Root/G4 analysis");
00242
00243
00244
00245 string myntuple_string;
00246 myntuple_string="ion:x:y:z:x0:y0:z0:kineE:px:py:pz:kineE0:px0:py0:pz0:kineE1:px1:py1:pz1:kineE2:px2:py2:pz2:type:volume:theta0:theta1:theta2:ev_num:process:event:creator:hit:kineE_org:theta_org:track:diffXS:totXS:rate";
00247
00248 char *string_ntup = new char[myntuple_string.length()+1];
00249 strncpy (string_ntup,myntuple_string.c_str(),myntuple_string.length()+1);
00250
00251 ntup = new TNtuple("geant","G4 Results",(char *)string_ntup);
00252
00253 G4cout << "Run Action has been completed\n" << G4endl;
00254 }
00255
00256 void MollerAnalysis::BeginOfEventAction(const G4Event *)
00257 {
00258 ev_num++;
00259 if (gSystem) gSystem->ProcessEvents();
00260
00261 G4SDManager * SDman = G4SDManager::GetSDMpointer();
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 if((int) hitsCollID.size()==0)
00275 {
00276 G4cout<<G4endl<<G4endl<<"Setting hitsCollID"<<G4endl<<G4endl;
00277
00278 for (int i=0; i<NUM_DETS; i++) {
00279 G4String colNam = "detector";
00280 colNam+=G4UIcommand::ConvertToString(i+1);
00281 colNam+="/hitsColl";
00282
00283 G4cout << colNam << G4endl;
00284
00285 hitsCollID.push_back (SDman->GetCollectionID(colNam));
00286 }
00287
00288 G4cout<<G4endl<<"Finished setting hitsCollID"<<G4endl<<G4endl;
00289
00290 }
00291
00292
00293 gRootAnalysis->SetProcess(1);
00294
00295
00296
00297
00298
00299 }
00300
00301
00302 void MollerAnalysis::UserSteppingAction(const G4Step *aStep)
00303 {
00304
00305
00306 G4Track* fTrack = aStep->GetTrack();
00307
00308
00309 if (fTrack->GetTrackStatus()!=fAlive) {
00310
00311 return;
00312 }
00313
00314 G4int tracking = 1;
00315
00316 G4StepPoint* thePrePoint = aStep->GetPreStepPoint();
00317 G4StepPoint* thePostPoint = aStep->GetPostStepPoint();
00318 G4VPhysicalVolume* thePrePV = thePrePoint->GetPhysicalVolume();
00319 G4Material* material = fTrack->GetMaterial();
00320
00321 const G4VProcess* originProcess = fTrack->GetCreatorProcess();
00322 const G4VProcess* stepProcess = thePostPoint->GetProcessDefinedStep();
00323
00324 G4String process;
00325 if (originProcess!=0) process = originProcess->GetProcessName();
00326 G4String process1;
00327 if (stepProcess!=0) process1 = stepProcess->GetProcessName();
00328
00329
00330 G4String volume = fTrack->GetVolume()->GetName();
00331 G4String particle = fTrack->GetDefinition()->GetParticleName();
00332
00333
00334 if (process=="eIoni") creatorProcess=0;
00335 else if (process=="conv") creatorProcess=1;
00336 else if (process=="Decay") creatorProcess=2;
00337 else if (process=="annihil") creatorProcess=3;
00338 else if (process=="eBrem") creatorProcess=4;
00339 else if (process=="phot") creatorProcess=5;
00340 else if (process=="compt") creatorProcess=6;
00341 else if (process=="Transportation") creatorProcess=7;
00342 else if (process=="msc") creatorProcess=8;
00343 else creatorProcess=9;
00344
00345
00346
00347 if ((particle == "e-")
00348 && (fTrack->GetVertexKineticEnergy()==11*GeV)
00349 && ((thePrePoint->GetKineticEnergy()-
00350 thePostPoint->GetKineticEnergy())>1.00*GeV)
00351 && (process1=="eIoni"))
00352 {
00353 if (kineE0==0 || kineE1==0) {
00354 kineE0 = thePrePoint->GetKineticEnergy();
00355 kineE1 = thePostPoint->GetKineticEnergy();
00356 px0 = thePrePoint->GetMomentumDirection().x();
00357 py0 = thePrePoint->GetMomentumDirection().y();
00358 pz0 = thePrePoint->GetMomentumDirection().z();
00359 px1 = thePostPoint->GetMomentumDirection().x();
00360 py1 = thePostPoint->GetMomentumDirection().y();
00361 pz1 = thePostPoint->GetMomentumDirection().z();
00362 theta0 = sqrt(px0*px0 + py0*py0);
00363 theta1 = sqrt(px1*px1 + py1*py1);
00364 x0 = thePostPoint->GetPosition().x();
00365 y0 = thePostPoint->GetPosition().y();
00366 z0 = thePostPoint->GetPosition().z();
00367 }
00368
00369 if (process1=="eIoni") splitProcess=0;
00370 else if (process1=="conv") splitProcess=1;
00371 else if (process1=="Decay") splitProcess=2;
00372 else if (process1=="annihil") splitProcess=3;
00373 else if (process1=="eBrem") splitProcess=4;
00374 else if (process1=="photo") splitProcess=5;
00375 else if (process1=="compton") splitProcess=6;
00376 else if (process1=="Transportation") splitProcess=7;
00377 else splitProcess=8;
00378 }
00379
00380 if (tracking) {
00381
00382 G4ThreeVector worldPos = fTrack->GetPosition();
00383 G4ThreeVector worldMomentum = fTrack->GetMomentumDirection();
00384 G4ThreeVector vertexMomentum = fTrack->GetVertexMomentumDirection();
00385
00386 G4double scat_ang = sqrt(vertexMomentum.x()*vertexMomentum.x() +
00387 vertexMomentum.y()*vertexMomentum.y());
00388
00389
00390
00391
00392
00393 G4double kineE = fTrack->GetKineticEnergy();
00394 G4double kineE0 = fTrack->GetVertexKineticEnergy();
00395
00396 G4bool ion = (process=="eIoni");
00397
00398 if (particle=="e-") partType=0;
00399 else if (particle=="e+") partType=1;
00400 else if (particle=="proton") partType=2;
00401 else if (particle=="antiproton") partType=3;
00402 else if (particle=="gamma") partType=4;
00403 else partType=5;
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 }
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 if((material->GetName()=="Tungsten")||(material->GetName()=="Pb")||(material->GetName()=="Copper")){
00463 if (kineE2 == 0 && process=="eIoni") {
00464 kineE2 = fTrack->GetVertexKineticEnergy();
00465 px2 = fTrack->GetVertexMomentumDirection().x();
00466 py2 = fTrack->GetVertexMomentumDirection().y();
00467 pz2 = fTrack->GetVertexMomentumDirection().z();
00468 theta2 = sqrt(px2*px2 + py2*py2);
00469 x0 = fTrack->GetVertexPosition().x();
00470 y0 = fTrack->GetVertexPosition().y();
00471 z0 = fTrack->GetVertexPosition().z();
00472
00473 }
00474
00475
00476 fTrack->SetTrackStatus(fKillTrackAndSecondaries);
00477 return;
00478 }
00479
00480 }
00481
00482
00483 void MollerAnalysis::EndOfEventAction(const G4Event *anEvent)
00484 {
00485
00486 if (gSystem) gSystem->ProcessEvents();
00487
00488 G4HCofThisEvent * HCE = anEvent->GetHCofThisEvent();
00489
00490 event = anEvent->GetEventID();
00491
00492 std::vector<MollerDetectorHitsCollection*> THC;
00493
00494
00495 if(HCE) {
00496 for (int i=0; i<NUM_DETS; i++) {
00497 THC.push_back ((MollerDetectorHitsCollection*)(HCE->GetHC(hitsCollID[i])));
00498 }
00499 }
00500 G4int checkTrack1=0;
00501 G4int checkTrack2=0;
00502
00503 for (int i=0; i<NUM_DETS; i++) {
00504
00505 if(THC[i]){
00506 int n_hit = THC[i]->entries();
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517 checkTrack1=0;
00518 checkTrack2=0;
00519 if (n_hit>0) {
00520
00521 for(int i1=0;i1<n_hit;i1++) {
00522 MollerDetectorHit* aHit = (*THC[i])[i1];
00523
00524
00525
00526
00527
00528
00529
00530 if ((aHit->GetTrackID()==1)&&(checkTrack1==0)) {
00531 if (aHit->GetType()==0) AddData(aHit);
00532 if (aHit->GetType()==4) AddData(aHit);
00533 checkTrack1++;
00534 } else if ((aHit->GetTrackID()==2)&&(checkTrack2==0)){
00535 if (aHit->GetType()==0) AddData(aHit);
00536 if (aHit->GetType()==4) AddData(aHit);
00537 checkTrack2++;
00538 }
00539
00540 }
00541
00542 }
00543 }
00544 }
00545
00546 gRootAnalysis->SetMomentum0(0,0,0,0);
00547 gRootAnalysis->SetMomentum1(0,0,0,0);
00548 gRootAnalysis->SetMomentum2(0,0,0,0);
00549 gRootAnalysis->SetProcess(0);
00550
00551 }
00552
00553
00554
00555 void MollerAnalysis::EndOfRunAction(const G4Run *)
00556 {
00557 if (gSystem) gSystem->ProcessEvents();
00558
00559 hfile->Write();
00560 hfile->Close();
00561
00562 }
00563
00564