source: JEM-EUSO/esaf_cc_at_lal/packages/simulation/detector/G4Detector/optics/src/OptSteppingAction.cc @ 114

Last change on this file since 114 was 114, checked in by moretto, 11 years ago

actual version of ESAF at CCin2p3

File size: 7.3 KB
Line 
1#include "OptSteppingAction.hh"
2#include "OptUserStackingAction.hh"
3#include "Photon.hh"
4
5#include <G4SteppingManager.hh>
6#include <G4Track.hh>
7#include <G4Step.hh>
8#include <G4StepPoint.hh>
9#include <G4TrackStatus.hh>
10#include <G4VPhysicalVolume.hh>
11#include <G4ParticleDefinition.hh>
12#include <G4ParticleTypes.hh>
13#include <G4String.hh>
14#include <G4ProcessManager.hh>
15#include <G4ProcessVector.hh>
16#include <G4OpBoundaryProcess.hh>
17#include <G4TrackStatus.hh>
18#include <G4EventManager.hh>
19#include <G4Event.hh>
20#include <G4MaterialPropertiesTable.hh>
21#include <G4Box.hh>
22#include <G4IntersectionSolid.hh>
23#include <G4Tubs.hh>
24#include <TTree.h>
25#include <TVector3.h>
26#include <TObject.h>
27#include <TObjString.h>
28
29#include "SimuApplication.hh"
30#include "ConfigFileParser.hh"
31#include "EsafConfigurable.hh"
32#include "Config.hh"
33#include <iostream>
34#include "VirtualTelParm.hh"
35#include <G4GeometryTolerance.hh>
36
37using namespace std;
38using namespace NTraceLens;
39const char* oprocess[] ={ "Undefined", "FresnelRefraction", 
40                          "FresnelReflection", "TotalInternalReflection",
41                          "LambertianReflection", "LobeReflection",
42                          "SpikeReflection", "BackScattering",
43                          "Absorption", "Detection", "NotAtBoundary",
44                          "SameMaterial", "StepTooSmall", "NoRINDEX" };
45
46// Detector subsystem identifier
47enum EDetectorSystem {
48    keUndefined               = 0,
49    kNotInside                = 1,
50    kBaffle                   = 2,
51    kOptics                   = 3,
52    kFocalPlane               = 4,
53    kWalls                    = 5,
54    kEarth                    = 6,
55    kG4FocalSurface           = 7
56};
57
58OptSteppingAction::OptSteppingAction(OptUserStackingAction* stack) : fStepCounter(0), fMaxIterations(1000)
59{
60    //theStatus = Undefined;
61    fBoundary = NULL;
62    fProcessManager = NULL;
63    fProcessVector = NULL;
64    fStatus = 0;
65    fStacking = stack;
66    ConfigFileParser* conf = Config::Get()->GetCF("G4","G4Detector");
67    string det=conf->GetStr("G4Detector.DetectorType");
68    //double fGeomTolerance=G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
69    if (det.find("Tus")!=string::npos){
70        fTus=true;
71        cover=0; 
72    }
73    else {
74        fTus=false;
75        tel_param* telParm = VirtualTelParm::GetOpticalSystemParam();
76        r_cut = telParm->surface[1].r_cut;
77        r_wall = telParm->r_wall;
78       
79// virtual cover without baffle
80
81        G4Box* cbox = new G4Box("cbox",(r_wall+1.)*mm,r_wall*mm,3.5*m);//(r_cut+10.)
82        G4Tubs* ctub =new G4Tubs("ctub",0.,r_wall*mm,3.*m,0.*deg,360.*deg);
83        G4IntersectionSolid* intersec = new G4IntersectionSolid("cbox*ctub", cbox, ctub);
84       
85        cover = new G4DisplacedSolid ("cover",intersec,0,G4ThreeVector(0,0,2.5*m));
86       
87    }
88    SetSender("OptSteppingAction");
89
90}
91
92OptSteppingAction::~OptSteppingAction()
93{
94
95}
96
97void OptSteppingAction::UserSteppingAction(const G4Step * theStep)
98{
99    G4VPhysicalVolume* prevol=theStep->GetPreStepPoint()->GetPhysicalVolume();
100    G4VPhysicalVolume* postvol=theStep->GetPostStepPoint()->GetPhysicalVolume();
101    G4String PreStepVolume,PostStepVolume;
102    if(prevol){
103        PreStepVolume = prevol->GetName();
104    }
105    if(postvol){
106        PostStepVolume = postvol->GetName();
107    }
108   
109    G4StepPoint *PostStep = 0;
110    G4StepPoint *PreStep = 0;
111    G4ThreeVector pre_pos, pre_dir;
112    G4ThreeVector post_pos, post_dir;
113   
114    PreStep = theStep->GetPreStepPoint();
115    pre_pos = PreStep->GetPosition();
116    pre_dir = PreStep->GetMomentumDirection();
117    PostStep = theStep->GetPostStepPoint();
118    post_pos =  PostStep->GetPosition();
119    post_dir =  PostStep->GetMomentumDirection();
120
121   
122    fStepCounter++;
123    if ( fStepCounter>fMaxIterations ){
124        theStep->GetTrack()->SetTrackStatus(fStopAndKill);
125        MsgForm(EsafMsg::Warning,"This photon exceeded the maximum number of iterations (%i), killed.",fMaxIterations);
126    }
127
128    //find the boundary process only once
129    if( !fBoundary ){
130        fProcessManager = theStep->GetTrack()->GetDefinition()->GetProcessManager();
131        G4int nprocesses = fProcessManager->GetProcessListLength();
132        fProcessVector = fProcessManager->GetProcessList();
133
134        for(int i=0;i<nprocesses;i++){
135            if( (*fProcessVector)[i]->GetProcessName()=="OpBoundary" ){
136                fBoundary = (G4OpBoundaryProcess*)(*fProcessVector)[i];
137                break;
138            }
139        }
140    }
141
142    theStatus = Undefined;
143    if(fBoundary)theStatus = fBoundary->GetStatus();
144
145    double rho = post_pos.perp();
146    if(!fTus && (fabs(post_pos.y())>=r_cut || rho>=r_wall)){
147        if(cover->Inside (pre_pos)==kInside ){
148            theStep->GetTrack()->SetTrackStatus(fStopAndKill);
149            fStatus=-4;
150            double dist = cover->DistanceToOut (pre_pos, pre_dir);
151            // intersection with virtual wall
152           
153            if(dist!=kInfinity ){
154              //printf("dist %g\n",dist);
155                pre_pos+=pre_dir.unit()*dist;
156                PostStep->SetPosition(pre_pos);
157                PostStep->SetMomentumDirection(pre_dir);
158                post_pos=pre_pos;
159                post_dir=pre_dir;
160                double t = PostStep->GetLocalTime();
161                t+=dist/c_light;
162                PostStep->SetLocalTime(t);
163            }
164        }
165        else if(cover->Inside (pre_pos)==kSurface){
166           
167            //double newdist= cover->DistanceToIn (pre_pos, pre_dir);
168            //if(newdist==kInfinity ){
169              PostStep->SetPosition(pre_pos);
170              //printf("dist %g\n",newdist);
171            //}
172//          if(newdist!=kInfinity ){
173//              pre_pos-=pre_dir.unit()*newdist;
174                //pre_pos.z()=0.;
175//              PostStep->SetPosition(pre_pos);
176//              PostStep->SetMomentumDirection(pre_dir);
177//              post_pos=pre_pos;
178//              post_dir=pre_dir;
179//              double t = PostStep->GetLocalTime();
180//              t-=newdist/c_light;
181//              PostStep->SetLocalTime(t);
182//             
183//         
184//         
185//         
186//          }
187//         
188//     
189        }
190        else PostStep->SetPosition(pre_pos);
191       
192    }
193
194 
195    if ( PostStep && fStatus!=-4 && PostStep->GetStepStatus()==fPostStepDoItProc &&
196         theStep->GetTrack()->GetTrackStatus()==fStopAndKill ) fStatus=-3;
197
198    if(postvol){
199     
200        if ( PostStepVolume.contains("FresnelLens") || PreStepVolume.contains("FresnelLens")||
201            PreStepVolume.contains("mirror_phys") ||PostStepVolume.contains("mirror_phys") ){
202            if(fStatus==0) fStatus++;
203        }
204
205        if(PostStepVolume=="absorber"){
206           
207            theStep->GetTrack()->SetTrackStatus(fStopAndKill);
208            fStatus=(fStatus>0?-2:-1);
209            if(fStatus==-1||fStatus==-2)PostStep->SetPosition(pre_pos);
210        }
211    }
212
213   
214    if ( theStatus==Absorption || theStatus==Detection ){
215        fStatus=-3;
216       
217    }
218    G4TrackStatus TrackStatus = theStep->GetTrack()->GetTrackStatus();
219
220    if(TrackStatus==fStopAndKill){
221        fStepCounter=0;
222        int history;
223        if ( post_pos.z()<0 && post_dir.z()<0  ){
224            history=kEarth;
225            double dist = cover->DistanceToOut (pre_pos, pre_dir);
226        // intersection with virtual wall
227           
228            if(dist!=kInfinity && dist!=0){
229
230                pre_pos+=pre_dir.unit()*dist;
231                PostStep->SetPosition(pre_pos);
232                PostStep->SetMomentumDirection(pre_dir);
233                post_pos=pre_pos;
234                post_dir=pre_dir;
235                double t = PostStep->GetLocalTime();
236                t+=dist/c_light;
237                PostStep->SetLocalTime(t);
238            }
239         
240         }
241         else if ( fStatus==-2 ) history=kG4FocalSurface;
242         else if ( fStatus==-3) history=kOptics;
243         else if ( fStatus==-4) history=kWalls;
244         else history=keUndefined;
245
246         fStacking->SetTrackHistory(history);
247         fStatus=0;
248    }
249}
Note: See TracBrowser for help on using the repository browser.