TACTICScorer.cc 4.51 KB
Newer Older
1 2
//#define USE_Garfield //only use if compiled with Garfield

Warren's avatar
Warren committed
3 4
#include "TACTICScorer.hh"
#include "G4UnitsTable.hh"
Warren's avatar
Warren committed
5
#include "G4RunManager.hh"
6
#include "TACTIC.hh"
7 8 9 10 11

#ifdef USE_Garfield
#include "GARFDRIFT.h"
#endif

12 13
double excess;

Warren's avatar
Warren committed
14 15
using namespace TACTICScorer;

16
Gas_Scorer::Gas_Scorer(G4String name,G4int Level,G4double ScorerLength,G4int NumberOfSegments, G4int depth, G4double p0, G4double p1, G4double p2, G4double p3) //what do level and depth do?       
Warren's avatar
Warren committed
17 18 19 20 21 22 23 24
:G4VPrimitiveScorer(name, depth),HCID(-1){
  m_ScorerLength = ScorerLength;
  m_NumberOfSegments = NumberOfSegments;
  m_SegmentLength = m_ScorerLength / m_NumberOfSegments;
  m_Level = Level;
  m_Position = G4ThreeVector(-1000,-1000,-1000);
  m_SegmentNumber = -1;
  m_Index = -1;
25 26 27 28
  m_p0 = p0;
  m_p1 = p1;
  m_p2 = p2;
  m_p3 = p3;
Warren's avatar
Warren committed
29 30 31 32 33 34
}

Gas_Scorer::~Gas_Scorer(){}

G4bool Gas_Scorer::ProcessHits(G4Step* aStep, G4TouchableHistory*){

35
  G4double* Infos = new G4double[15];
36
  //bool first_step = true;
Warren's avatar
Warren committed
37
  m_Position  = aStep->GetPreStepPoint()->GetPosition();
38

Warren's avatar
Warren committed
39
  Infos[0] = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
Warren's avatar
Warren committed
40

Warren's avatar
Warren committed
41 42 43
  Infos[1] = aStep->GetTrack()->GetTrackID();

  Infos[2] = aStep->GetTrack()->GetParticleDefinition()->GetAtomicNumber();;
44
  
Warren's avatar
Warren committed
45 46 47
  Infos[3] = aStep->GetPreStepPoint()->GetGlobalTime();
  Infos[4] = aStep->GetPreStepPoint()->GetKineticEnergy();
  Infos[5] = aStep->GetTotalEnergyDeposit() - aStep->GetNonIonizingEnergyDeposit();
Warren's avatar
Warren committed
48 49

  m_SegmentNumber = (int)((m_Position.z() + m_ScorerLength / 2.) / m_SegmentLength ) + 1; //Pad number 
Warren's avatar
Warren committed
50
  Infos[6] = m_SegmentNumber;
51
  //prepad = Infos[6]; 
Warren's avatar
Warren committed
52 53 54 55
  Infos[7] = m_Position.z();
  Infos[8] = pow(pow(m_Position.x(),2) + pow(m_Position.y(),2),0.5); //R
  Infos[9] = aStep->GetTrack()->GetVertexPosition()[2];
  Infos[10] = aStep->GetTrack()->GetVertexKineticEnergy();
Warren's avatar
Warren committed
56
  G4ThreeVector p_vec = aStep->GetTrack()->GetVertexMomentumDirection();
Warren's avatar
Warren committed
57 58
  Infos[11] = acos(p_vec[2]/pow(pow(p_vec[0],2)+pow(p_vec[1],2)+pow(p_vec[2],2),0.5))/deg; //angle relative to z axis (theta);   
  Infos[12] = aStep->GetTrack()->GetTrackLength();
59
  Infos[13] = m_p0 + m_p1*Infos[8] + m_p2*Infos[8]*Infos[8] + m_p3*Infos[8]*Infos[8]*Infos[8];
Warren's avatar
Warren committed
60
  
61 62 63 64
  //Infos[14] = excess;
  
  G4ThreeVector delta_Position = aStep->GetDeltaPosition();

Warren's avatar
Warren committed
65 66
  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_Level);
  m_Index = m_DetectorNumber * 1e3 + m_SegmentNumber * 1e6;
67
  
Warren's avatar
Warren committed
68
  if(isnan(Infos[10])) {
69 70 71
    aStep->GetTrack()->SetTrackStatus(fStopAndKill);
    return 0;
  }
72 73 74

  if(aStep->IsFirstStepInVolume() == true) excess = 0.;
  
Warren's avatar
Warren committed
75 76
  map<G4int, G4double**>::iterator it;
  it= EvtMap->GetMap()->find(m_Index);
77
  if(it!=EvtMap->GetMap()->end()){
Warren's avatar
Warren committed
78
    G4double* dummy = *(it->second);
79
    if(Infos[1]==dummy[1]) Infos[5]+=dummy[5]; //accumulate ionisation energy deposit to get total accross pad
80 81 82
    delete dummy;
  }
    
83 84
#ifdef USE_Garfield

85 86 87 88 89 90 91 92
  Infos[14] = GARFDRIFT(((aStep->GetTotalEnergyDeposit() - aStep->GetNonIonizingEnergyDeposit())/eV+excess), Infos[3], m_Position/cm, delta_Position/cm, Infos[8]/cm, Infos[6], Infos[2], m_ScorerLength/cm, m_SegmentLength/cm, Infos[0], (aStep->GetTotalEnergyDeposit() - aStep->GetNonIonizingEnergyDeposit())/eV)*eV;
  /*  
  file.open("excess_test.dat",std::ios::app);
  file << Infos[6] << "\t"  << "\t" <<  aStep->IsFirstStepInVolume() << "\t" << excess  << "\t" << Infos[14]/eV << "\t" << (int)((((aStep->GetTotalEnergyDeposit() - aStep->GetNonIonizingEnergyDeposit())/eV+excess) / 41.1)*0.01) << "\t" <<  Infos[8] <<  endl;
  file.close();
  */
  excess = Infos[14]/eV;
 
93
#endif
94

Warren's avatar
Warren committed
95
  EvtMap->set(m_Index, Infos);
96

Warren's avatar
Warren committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  return TRUE;

}

void Gas_Scorer::Initialize(G4HCofThisEvent* HCE){
    EvtMap = new NPS::HitsMap<G4double*>(GetMultiFunctionalDetector()->GetName(), GetName());
    if (HCID < 0) {
        HCID = GetCollectionID(0);
    }
    HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
}

void Gas_Scorer::EndOfEvent(G4HCofThisEvent*){}

void Gas_Scorer::clear(){
    std::map<G4int, G4double**>::iterator    MapIterator;
    for (MapIterator = EvtMap->GetMap()->begin() ; MapIterator != EvtMap->GetMap()->end() ; MapIterator++){
        delete *(MapIterator->second);
    }

    EvtMap->clear();
}


void Gas_Scorer::DrawAll(){}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......                                                                              

void Gas_Scorer::PrintAll(){
    G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl ;
    G4cout << " PrimitiveScorer " << GetName() << G4endl               ;
    G4cout << " Number of entries " << EvtMap->entries() << G4endl     ;
}