00001
00002
00003
00004
00005
00006
00007
00008 #include "myglobals.hh"
00009 #include "G4DigiManager.hh"
00010 #include "G4HCofThisEvent.hh"
00011 #include "G4Step.hh"
00012 #include "G4ThreeVector.hh"
00013 #include "G4SDManager.hh"
00014 #include "G4TransportationManager.hh"
00015 #include "G4FieldManager.hh"
00016 #include "G4MagneticField.hh"
00017 #include "G4UnitsTable.hh"
00018 #include "G4ios.hh"
00019 #include "G4RunManager.hh"
00020 #include "G4TrackStatus.hh"
00021
00022 #include "CLHEP/Geometry/Vector3D.h"
00023 #include "CLHEP/Geometry/Point3D.h"
00024
00025 #include "TVector3.h"
00026
00027 #include <iostream>
00028
00029 #include "MyString2Anything.hh"
00030 #include "MyRoot.hh"
00031 #include "MySD.hh"
00032
00033 #include "KillerSD.hh"
00034
00035 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00036 typedef HepGeom::Point3D<double> HepPoint3D;
00037 typedef HepGeom::Vector3D<double> HepVector3D;
00038 #endif
00039
00040 KillerSD::KillerSD(G4String name, MyVGeometryParameter* pointer)
00041 :MySD(name, pointer)
00042 {
00043 }
00044
00045 KillerSD::~KillerSD(){
00046 }
00047
00048
00049
00050 void KillerSD::Initialize(G4HCofThisEvent* HCE)
00051 {
00052 }
00053
00054
00055
00056 void KillerSD::SetBranch(){
00057 }
00058
00059
00060
00061 void KillerSD::ReadOutputCard(G4String filename){
00062 ReSet();
00063 std::ifstream fin_card(filename);
00064 if(!fin_card){
00065 std::cout<<"In KillerSD::ReadOutputCard, cannot open "<<filename<<"!!!"<<std::endl;
00066 G4Exception("KillerSD::ReadOutputCard()",
00067 "InvalidSetup", FatalException,
00068 "cannot find output card");
00069 }
00070 std::stringstream buf_card;
00071 G4String s_card;
00072 G4String volName = get_VolName();
00073 int n_filter_section_symbol = 0;
00074 G4String FILTERSECTIONNAME = volName + "_FILTERSECTION";
00075 while(getline(fin_card,s_card)){
00076 buf_card.str("");
00077 buf_card.clear();
00078 buf_card<<s_card;
00079
00080
00081 const char* c_card = s_card.c_str();
00082 int length = strlen(c_card);
00083 int offset = 0;
00084 for ( ; offset < length; offset++ ){
00085 if ( c_card[offset] != ' ' ) break;
00086 }
00087 if ( c_card[offset] == '#' || (c_card[offset] == '/' && c_card[offset+1] == '/') || length - offset == 0 ){
00088 continue;
00089 }
00090
00091 G4String name, unit;
00092 buf_card>>name;
00093
00094 if ( n_filter_section_symbol == 0 ){
00095 if ( name == FILTERSECTIONNAME ){
00096 n_filter_section_symbol++;
00097 }
00098 }
00099 else if ( n_filter_section_symbol == 1 ){
00100 if ( name == FILTERSECTIONNAME ){
00101 n_filter_section_symbol++;
00102 }
00103 else if( name == "Switch" ) Switch = true;
00104 else if( name == "neutralCut" ) neutralCut = true;
00105 else if( name == "maxn" ) buf_card>>maxn;
00106 else if( name == "WL" ){
00107 int pid = 0;
00108 buf_card>>pid;
00109 white_list.push_back(pid);
00110 }
00111 else if( name == "BL" ){
00112 int pid = 0;
00113 buf_card>>pid;
00114 black_list.push_back(pid);
00115 }
00116 else{
00117 G4double para;
00118 G4String unit;
00119 buf_card>>para>>unit;
00120 para *= MyString2Anything::get_U(unit);
00121 if( name == "minp" ) minp = para;
00122 else if( name == "mine" ) mine = para;
00123 else if ( name == "minedep" ) minedep = para;
00124 else if( name == "mint" ) mint = para;
00125 else if( name == "maxt" ) maxt = para;
00126 else if( name == "tres" ) tres = para;
00127 else{
00128 std::cout<<"In KillerSD::ReadOutputCard, unknown name: "<<name<<" in file "<<filename<<std::endl;
00129 std::cout<<"Will ignore this line!"<<std::endl;
00130 }
00131 }
00132 }
00133
00134 if ( n_filter_section_symbol > 1 ){
00135 break;
00136 }
00137 }
00138 buf_card.str("");
00139 buf_card.clear();
00140 if ( n_filter_section_symbol<= 1 ){
00141 std::cout<<"*****************WARNING********************"<<std::endl;
00142 std::cout<<"In KillerSD::ReadOutputCard, failed to find enough section seperators \""<<FILTERSECTIONNAME<<"\" for filter in file "<<filename<<std::endl;
00143 std::cout<<"Will use default settings."<<std::endl;
00144 std::cout<<"********************************************"<<std::endl;
00145 }
00146 fin_card.close();
00147 ShowOutCard();
00148 }
00149
00150
00151
00152 void KillerSD::ReSet(){
00153
00154 Switch = true;
00155 neutralCut = false;
00156 minp = 0;
00157 mine = 0;
00158 maxn = 0;
00159 mint = 0;
00160 maxt = 0;
00161 tres = 0;
00162 minedep = -1*MeV;
00163 white_list.clear();
00164 black_list.clear();
00165 }
00166
00167
00168
00169 void KillerSD::ShowOutCard(){
00170 std::cout<<"*************************Output settings for "<<get_VolName()<<"***************************"<<std::endl;
00171
00172 std::cout<<"Switch on? "<<(Switch?"yes":"no")<<std::endl;
00173 std::cout<<"neutralCut on? "<<(neutralCut?"yes":"no")<<std::endl;
00174 std::cout<<"minp = "<<minp/MeV<<"MeV"<<std::endl;
00175 std::cout<<"mine = "<<mine/MeV<<"MeV"<<std::endl;
00176 std::cout<<"maxn = "<<maxn<<std::endl;
00177 std::cout<<"mint = "<<mint/ns<<"ns"<<std::endl;
00178 std::cout<<"maxt = "<<maxt/ns<<"ns"<<std::endl;
00179 std::cout<<"tres = "<<tres/ns<<"ns"<<std::endl;
00180 std::cout<<"minedep = "<<minedep/MeV<<"MeV"<<std::endl;
00181 std::cout<<"white list: "<<std::endl;
00182 for ( int i = 0; i< white_list.size(); i++){
00183 std::cout <<" Only tracks with these following PDGCodes will be killed:"<<std::endl;
00184 std::cout<<" "<<i<<": "<<white_list[i]<<std::endl;
00185 }
00186 if ( white_list.size() == 0 ){
00187 std::cout <<" Empty! So all tracks will be killed!"<<std::endl;
00188 }
00189 std::cout<<"black list: "<<std::endl;
00190 for ( int i = 0; i< black_list.size(); i++){
00191 std::cout <<" Tracks with these following PDGCodes will NOT be killed:"<<std::endl;
00192 std::cout<<" "<<i<<": "<<black_list[i]<<std::endl;
00193 }
00194 std::cout<<"******************************************************************************"<<std::endl;
00195 }
00196
00197
00198
00199 G4bool KillerSD::ProcessHits(G4Step* aStep,G4TouchableHistory* touchableHistory)
00200 {
00201
00202
00203
00204
00205 G4Track* aTrack = aStep->GetTrack() ;
00206 G4int trackID= aTrack->GetTrackID();
00207 G4int charge = aTrack->GetDefinition()->GetPDGCharge();
00208 G4int pid = aTrack->GetDefinition()->GetPDGEncoding();
00209
00210
00211 G4StepPoint* prePoint = aStep->GetPreStepPoint() ;
00212 G4double total_e = prePoint->GetTotalEnergy();
00213 G4ThreeVector pointIn_mom = prePoint->GetMomentum();
00214 G4double pointIn_pa = pointIn_mom.mag();
00215 G4ThreeVector pointIn_pos = prePoint->GetPosition();
00216 G4double pointIn_time = prePoint->GetGlobalTime();
00217 G4StepPoint* postPoint = aStep->GetPostStepPoint() ;
00218 G4double pointOut_time = postPoint->GetGlobalTime();
00219 G4ThreeVector pointOut_mom = postPoint->GetMomentum();
00220 G4double pointOut_pa = pointOut_mom.mag();
00221 G4ThreeVector pointOut_pos = postPoint->GetPosition();
00222
00223
00224 const G4VTouchable *touchable = prePoint->GetTouchable();
00225 G4int ReplicaNo = touchable->GetVolume(0)->GetCopyNo();
00226 G4String VolName = touchable->GetVolume(0)->GetName();
00227
00228
00229 G4double edep = aStep->GetTotalEnergyDeposit();
00230 G4double stepL = aStep->GetStepLength();
00231
00232
00233
00234 if (!Switch) return false;
00235
00236
00237 if ( charge == 0 && neutralCut ) return false;
00238
00239
00240
00241
00242
00243 bool foundit = false;
00244 for (int i = 0; i<white_list.size(); i++){
00245 if (pid == white_list[i]) foundit=true;
00246 if (white_list[i]==0&&pid<1e7) foundit = true;
00247 if (white_list[i]==-1&&trackID==1) foundit = true;
00248 }
00249 if (!foundit&&white_list.size()) return false;
00250
00251 foundit = false;
00252 for (int i = 0; i<black_list.size(); i++){
00253 if (pid == black_list[i]) foundit=true;
00254 if (black_list[i]==0&&pid<1e7) foundit = true;
00255 if (black_list[i]==-1&&trackID==1) foundit = true;
00256 }
00257 if (foundit) return false;
00258
00259
00260 if ( minp && pointOut_pa < minp ) return false;
00261
00262 if (mine&&aTrack->GetTotalEnergy()<mine) return false;
00263
00264
00265 if(isnan(pointOut_time)){
00266 G4cout<<"KillerSD:error, pointOut_time is nan "<<G4endl;
00267 return false;
00268 }
00269 if ( pointOut_time < mint && mint ) return false;
00270 if ( pointOut_time > maxt && maxt ) return false;
00271
00272
00273 if( edep <= minedep ) return false;
00274
00275 aTrack->SetTrackStatus(fStopAndKill);
00276 return true;
00277 }
00278
00279
00280
00281 void KillerSD::EndOfEvent(G4HCofThisEvent*){
00282 if (verboseLevel>0) {
00283
00284
00285
00286
00287
00288
00289
00290 }
00291 }