GFlashShowerModel.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: GFlashShowerModel.cc 69796 2013-05-15 13:26:12Z gcosmo $
00027 //
00028 //
00029 // ------------------------------------------------------------
00030 // GEANT 4 class implementation
00031 //
00032 //      ---------------- GFlashShowerModel ----------------
00033 //
00034 // Authors: E.Barberio & Joanna Weng - 9.11.2004
00035 // ------------------------------------------------------------
00036 
00037 #include "G4Electron.hh"
00038 #include "G4Positron.hh"
00039 #include "G4NeutrinoE.hh"
00040 #include "G4NeutrinoMu.hh"
00041 #include "G4NeutrinoTau.hh"
00042 #include "G4AntiNeutrinoE.hh"
00043 #include "G4AntiNeutrinoMu.hh"
00044 #include "G4AntiNeutrinoTau.hh"
00045 #include "G4PionZero.hh"
00046 #include "G4VProcess.hh"
00047 #include "G4ios.hh"
00048 #include "G4LogicalVolume.hh"
00049 #include "geomdefs.hh"
00050 
00051 #include "GFlashShowerModel.hh"
00052 #include "GFlashHomoShowerParameterisation.hh"
00053 #include "GFlashSamplingShowerParameterisation.hh"
00054 #include "GFlashEnergySpot.hh"
00055 
00056 
00057 GFlashShowerModel::GFlashShowerModel(G4String modelName,
00058                                      G4Envelope* envelope)
00059   : G4VFastSimulationModel(modelName, envelope),
00060     PBound(0), Parameterisation(0), HMaker(0)
00061 {
00062   FlagParamType           = 0;
00063   FlagParticleContainment = 1;  
00064   StepInX0 = 0.1;
00065   Messenger       = new GFlashShowerModelMessenger(this);
00066 }
00067 
00068 GFlashShowerModel::GFlashShowerModel(G4String modelName)
00069   : G4VFastSimulationModel(modelName),
00070     PBound(0), Parameterisation(0), HMaker(0)
00071 {
00072   FlagParamType           =1;
00073   FlagParticleContainment = 1;  
00074   StepInX0 = 0.1; 
00075   Messenger       = new GFlashShowerModelMessenger(this); 
00076 }
00077 
00078 GFlashShowerModel::~GFlashShowerModel()
00079 {
00080   delete Messenger;
00081 }
00082 
00083 G4bool
00084 GFlashShowerModel::IsApplicable(const G4ParticleDefinition& particleType)
00085 { 
00086   return 
00087   &particleType == G4Electron::ElectronDefinition() ||
00088   &particleType == G4Positron::PositronDefinition(); 
00089 }
00090 
00091 /**********************************************************************/
00092 /* Checks whether conditions of fast parameterisation  are fullfilled */
00093 /**********************************************************************/
00094 
00095 G4bool GFlashShowerModel::ModelTrigger(const G4FastTrack & fastTrack )
00096 
00097 {
00098   G4bool select = false;
00099   if(FlagParamType != 0)                  
00100   {
00101     G4double  ParticleEnergy = fastTrack.GetPrimaryTrack()->GetKineticEnergy(); 
00102     G4ParticleDefinition &ParticleType =
00103       *(fastTrack.GetPrimaryTrack()->GetDefinition()); 
00104     if(ParticleEnergy > PBound->GetMinEneToParametrise(ParticleType) &&
00105        ParticleEnergy < PBound->GetMaxEneToParametrise(ParticleType) )
00106     {
00107       // check conditions depending on particle flavour
00108       // performance to be optimized @@@@@@@
00109       Parameterisation->GenerateLongitudinalProfile(ParticleEnergy);
00110       select     = CheckParticleDefAndContainment(fastTrack);  
00111       if (select) EnergyStop= PBound->GetEneToKill(ParticleType);
00112     }
00113   }
00114 
00115   return select; 
00116 }
00117 
00118 
00119 G4bool
00120 GFlashShowerModel::CheckParticleDefAndContainment(const G4FastTrack& fastTrack)
00121 {  
00122   G4bool filter=false;
00123   G4ParticleDefinition * ParticleType =
00124     fastTrack.GetPrimaryTrack()->GetDefinition(); 
00125   
00126   if(  ParticleType == G4Electron::ElectronDefinition() || 
00127     ParticleType == G4Positron::PositronDefinition() )
00128   {
00129     filter=true;
00130     if(FlagParticleContainment == 1)  
00131     {
00132       filter=CheckContainment(fastTrack); 
00133     }
00134   }
00135   return filter;  
00136 }
00137 
00138 G4bool GFlashShowerModel::CheckContainment(const G4FastTrack& fastTrack)
00139 {
00140   G4bool filter=false;
00141   // track informations
00142   G4ThreeVector DirectionShower=fastTrack.GetPrimaryTrackLocalDirection();
00143   G4ThreeVector InitialPositionShower=fastTrack.GetPrimaryTrackLocalPosition();
00144 
00145   G4ThreeVector OrthoShower, CrossShower; 
00146   // Returns orthogonal vector 
00147   OrthoShower = DirectionShower.orthogonal();
00148   // Shower in direction perpendicular to OrthoShower and DirectionShower
00149   CrossShower = DirectionShower.cross(OrthoShower);
00150   
00151   G4double  R     = Parameterisation->GetAveR90();
00152   G4double  Z     = Parameterisation->GetAveT90();
00153   G4int CosPhi[4] = {1,0,-1,0};
00154   G4int SinPhi[4] = {0,1,0,-1};
00155   
00156   G4ThreeVector Position;
00157   G4int NlateralInside=0;
00158   // pointer to solid we're in
00159   G4VSolid *SolidCalo = fastTrack.GetEnvelopeSolid();
00160   for(int i=0; i<4 ;i++)
00161   {
00162     // polar coordinates
00163     Position = InitialPositionShower       + 
00164     Z*DirectionShower           +
00165     R*CosPhi[i]*OrthoShower     +
00166     R*SinPhi[i]*CrossShower     ;
00167     
00168     if(SolidCalo->Inside(Position) != kOutside) 
00169       NlateralInside++;
00170   }
00171   
00172   // choose to parameterise or flag when all inetc...
00173   if(NlateralInside==4) filter=true;
00174   // std::cout << " points =   " <<NlateralInside << std::endl;
00175   return filter;
00176 }
00177 
00178 
00179 void
00180 GFlashShowerModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
00181 {
00182   // parametrise electrons
00183   if(fastTrack.GetPrimaryTrack()->GetDefinition()
00184      == G4Electron::ElectronDefinition() || 
00185      fastTrack.GetPrimaryTrack()->GetDefinition()
00186      == G4Positron::PositronDefinition() ) 
00187   ElectronDoIt(fastTrack,fastStep);
00188 }
00189 
00190 void
00191 GFlashShowerModel::ElectronDoIt(const G4FastTrack& fastTrack,
00192                                       G4FastStep&  fastStep)
00193 {
00194   // std::cout<<"--- ElectronDoit --- "<<std::endl;
00195   
00196   fastStep.KillPrimaryTrack();
00197   fastStep.SetPrimaryTrackPathLength(0.0);
00198   fastStep.SetTotalEnergyDeposited(fastTrack.GetPrimaryTrack()->
00199                                    GetKineticEnergy());
00200   
00201   //-----------------------------
00202   // Get track parameters 
00203   //-----------------------------  
00204   //E,vect{p} and t,vec(x)
00205   G4double Energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
00206   
00207   // axis of the shower, in global reference frame:
00208   G4ThreeVector DirectionShower =
00209     fastTrack.GetPrimaryTrack()->GetMomentumDirection();
00210   G4ThreeVector OrthoShower, CrossShower;
00211   OrthoShower = DirectionShower.orthogonal();
00212   CrossShower = DirectionShower.cross(OrthoShower);
00213   
00214   //--------------------------------
00216   //--------------------------------
00217   Parameterisation->GenerateLongitudinalProfile(Energy);
00218     // performance iteration @@@@@@@
00219   
00221   G4VSolid *SolidCalo = fastTrack.GetEnvelopeSolid();
00222   G4ThreeVector pos   = fastTrack.GetPrimaryTrackLocalPosition();
00223   G4ThreeVector dir   = fastTrack.GetPrimaryTrackLocalDirection();
00224   G4double Bound      = SolidCalo->DistanceToOut(pos,dir); 
00225   
00226   G4double Dz       = 0.00;     
00227   G4double ZEndStep = 0.00;
00228   
00229   G4double EnergyNow        = Energy;
00230   G4double EneIntegral      = 0.00;   
00231   G4double LastEneIntegral  = 0.00;   
00232   G4double DEne             = 0.00;
00233   
00234   G4double NspIntegral      = 0.00;   
00235   G4double LastNspIntegral  = 0.00;   
00236   G4double DNsp             = 0.00;
00237   
00238   // starting point of the shower:
00239   G4ThreeVector PositionShower  = fastTrack.GetPrimaryTrack()->GetPosition();
00240   G4ThreeVector NewPositionShower    = PositionShower;   
00241   G4double      StepLenght           = 0.00;
00242   
00243   G4int NSpotDeposited =0;
00244   
00245   //--------------------------
00247   //-------------------------
00248   
00249   do
00250   {  
00251     //determine step size=min(1Xo,next boundary)
00252     G4double stepLength = StepInX0*Parameterisation->GetX0();
00253     if(Bound < stepLength)
00254     { 
00255       Dz    = Bound;
00256       Bound = 0.00;
00257     }
00258     else
00259     { 
00260       Dz    = stepLength;
00261       Bound = Bound-Dz;
00262     }
00263     ZEndStep=ZEndStep+Dz;
00264     
00265     // Determine Energy Release in Step
00266     if(EnergyNow > EnergyStop)
00267     {
00268       LastEneIntegral  = EneIntegral;
00269       EneIntegral      = Parameterisation->IntegrateEneLongitudinal(ZEndStep);
00270       DEne             = std::min( EnergyNow,
00271                                    (EneIntegral-LastEneIntegral)*Energy);
00272       LastNspIntegral  = NspIntegral;
00273       NspIntegral      = Parameterisation->IntegrateNspLongitudinal(ZEndStep);
00274       DNsp             = std::max(1., std::floor( (NspIntegral-LastNspIntegral)
00275                                                  *Parameterisation->GetNspot() ));
00276     }
00277     // end of the shower
00278     else
00279     {    
00280       DEne = EnergyNow;
00281       DNsp = std::max(1., std::floor( (1.- NspIntegral)
00282                                      *Parameterisation->GetNspot() ));
00283     } 
00284     EnergyNow  = EnergyNow - DEne;
00285     
00286     // Apply sampling fluctuation - only in sampling calorimeters
00287     //
00288     GFlashSamplingShowerParameterisation* sp =
00289       dynamic_cast<GFlashSamplingShowerParameterisation*>(Parameterisation);
00290     if (sp)
00291     {
00292       G4double DEneSampling = sp->ApplySampling(DEne,Energy);
00293       DEne = DEneSampling;
00294     }
00295 
00296     //move particle in the middle of the step
00297     StepLenght        = StepLenght + Dz/2.00;  
00298     NewPositionShower = NewPositionShower + 
00299     StepLenght*DirectionShower;
00300     StepLenght        = Dz/2.00;
00301     
00302     //generate spots & hits:
00303     for (int i = 0; i < DNsp; i++)
00304     { 
00305       NSpotDeposited++;
00306       GFlashEnergySpot Spot;      
00307       
00308       //Spot energy: the same for all spots
00309       Spot.SetEnergy( DEne / DNsp );
00310       G4double PhiSpot = Parameterisation->GeneratePhi(); // phi of spot
00311       G4double RSpot   = Parameterisation                 // radius of spot
00312                          ->GenerateRadius(i,Energy,ZEndStep-Dz/2.);
00313 
00314       // check reference-> may be need to introduce rot matrix @@@
00315       // Position: equally spaced in z
00316       
00317       G4ThreeVector SpotPosition = NewPositionShower  +
00318             Dz/DNsp*DirectionShower*(i+1/2.-DNsp/2.)  +
00319             RSpot*std::cos(PhiSpot)*OrthoShower       +  
00320             RSpot*std::sin(PhiSpot)*CrossShower;      
00321       Spot.SetPosition(SpotPosition);
00322       
00323       //Generate Hits of this spot      
00324       HMaker->make(&Spot, &fastTrack);
00325     }
00326   }
00327   while(EnergyNow > 0.0 && Bound> 0.0);     
00328   
00329   //---------------
00331   //--------------- 
00332 }
00333 
00334 /*
00335 
00336 void
00337 GFlashShowerModel::GammaDoIt(const G4FastTrack& fastTrack,
00338                                    G4FastStep&  fastStep)
00339 { 
00340   
00341   if( fastTrack.GetPrimaryTrack()->GetKineticEnergy() > EnergyStop )
00342     return;
00343   
00344   //deposita in uno spot unico l'energia 
00345   //con andamento exp decrescente. 
00346   
00347   // Kill the particle to be parametrised
00348   fastStep.KillPrimaryTrack();
00349   fastStep.SetPrimaryTrackPathLength(0.0);
00350   fastStep.SetTotalEnergyDeposited(fastTrack.GetPrimaryTrack()
00351                                    ->GetKineticEnergy());
00352   // other settings????
00353   feSpotList.clear(); 
00354   
00355   //-----------------------------
00356   // Get track parameters 
00357   //-----------------------------
00358 
00359   // E,vect{p} and t,vec(x)
00360   G4double Energy = 
00361     fastTrack.GetPrimaryTrack()->GetKineticEnergy();
00362   // axis of the shower, in global reference frame:
00363   G4ThreeVector DirectionShower =
00364     fastTrack.GetPrimaryTrack()->GetMomentumDirection();
00365   // starting point of the shower:
00366   G4ThreeVector PositionShower =
00367     fastTrack.GetPrimaryTrack()->GetPosition();
00368   
00369   //G4double DEneSampling = Parameterisation->ApplySampling(Energy,Energy);
00370   //if(DEneSampling <= 0.00) DEneSampling=Energy;  
00371   
00372   if(Energy > 0.0)
00373   {
00374     G4double dist = Parameterisation->GenerateExponential(Energy);      
00375     
00376     GFlashEnergySpot Spot;
00377     Spot.SetEnergy( Energy );
00378     G4ThreeVector SpotPosition = PositionShower + dist*DirectionShower;  
00379     Spot.SetPosition(SpotPosition);
00380     
00381     // Record the Spot:
00382     feSpotList.push_back(Spot);
00383     
00384     //Generate Hits of this spot      
00385     HMaker->make(Spot);
00386   }
00387 }
00388 
00389 */

Generated on Mon May 27 17:50:29 2013 for Geant4 by  doxygen 1.4.7