ERND.cxx

Elvira Gazeeva, 12/20/2017 12:09 PM

Download (8.78 KB)

 
1
// -------------------------------------------------------------------------
2
// -----                        ERND source file                   -----
3
// -----                  Created data  by developerName               -----
4
// -------------------------------------------------------------------------
5
#include "ERND.h"
6

    
7
#include "TClonesArray.h"
8
#include "TParticle.h"
9
#include "TVirtualMC.h"
10
#include "TString.h"
11

    
12
#include "FairRootManager.h"
13
#include "FairLogger.h"
14

    
15
// -----   Default constructor   -------------------------------------------
16
ERND::ERND() : 
17
  FairDetector("ERND", kTRUE),
18
   fNDPoints(NULL),
19
   fStep(0)
20
{
21
  LOG(INFO) << "  ERND::ERND()" << FairLogger::endl;
22
  ResetParameters();
23
  fNDPoints = new TClonesArray("ERNDPoint");
24
  flGeoPar = new TList();
25
  flGeoPar->SetName( GetName());
26
  fVerboseLevel = 1;
27
  fVersion = 1;
28
}
29
// -------------------------------------------------------------------------
30

    
31
// -----   Standard constructor   ------------------------------------------
32
ERND::ERND(const char* name, Bool_t active, Int_t verbose) 
33
  : FairDetector(name, active,verbose),
34
   fNDPoints(NULL)
35
  {
36
  ResetParameters();
37
  fNDPoints = new TClonesArray("ERNDPoint");
38
  flGeoPar = new TList();
39
  flGeoPar->SetName( GetName());
40
  fVersion = 1;
41
}
42

    
43
ERND::~ERND() {
44
  if (fNDPoints) {
45
    fNDPoints->Delete();
46
    delete fNDPoints;
47
  }
48
}
49

    
50
void ERND::Initialize()
51
{
52
  FairDetector::Initialize();
53
}
54

    
55

    
56
Bool_t ERND::ProcessHits(FairVolume* vol) {
57
  // Set constants for Birk's Law implentation
58
  /*
59
  static const Double_t dP = 1.032 ;
60
  static const Double_t BirkC1 =  0.013/dP;
61
  static const Double_t BirkC2 =  9.6e-6/(dP * dP);
62
  */
63
  //Birks constants from Craun, R. L.; Smith, D. L. NIM 80,2, p. 239, 1970
64
  static const Double_t dP = 0.97;
65
 // static const Double_t BirkC1 =  0.00856/dP;
66
  static const Double_t BirkC1 =  0.001/dP;
67
  static const Double_t BirkC2 =  4.99e-6/(dP * dP);
68

    
69

    
70
  static Int_t          eventID;           //!  event index
71
  static Int_t          trackID;           //!  track index
72
  static Int_t          mot0TrackID;       //!  0th mother track index
73
  static Int_t       pdg;              //!  pdg
74
  static TLorentzVector posIn, posOut;    //!  position
75
  static TLorentzVector momIn, momOut;    //!  momentum
76
  static Double32_t     time;              //!  time
77
  static Double32_t     length;            //!  length
78
  static Double32_t     eLoss;             //!  energy loss
79
  static Int_t          stilbenNr;
80
  static Double_t       lightYield;
81

    
82
  gMC->SetMaxStep(0.01);
83

    
84
  if ( gMC->IsTrackEntering() ) { // Return true if this is the first step of the track in the current volume
85
    eLoss  = 0.;
86
    lightYield = 0.;
87
    eventID = gMC->CurrentEvent();
88
    gMC->TrackPosition(posIn);
89
    gMC->TrackMomentum(momIn);
90
    trackID  = gMC->GetStack()->GetCurrentTrackNumber();
91
    time   = gMC->TrackTime() * 1.0e09;  // Return the current time of flight of the track being transported
92
    length = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
93
    mot0TrackID  = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
94
    pdg = gMC->TrackPid(); // GeV/c2
95
    gMC->CurrentVolOffID(3,stilbenNr); 
96
  }
97
  
98
  eLoss += gMC->Edep(); // GeV //Return the energy lost in the current step
99
  Double_t curLightYield = 0.;
100
  // Apply Birk's law ( Adapted from G3BIRK/Geant3)
101
  // Correction for all charge states
102
  if (gMC->TrackCharge()!=0) { // Return the charge of the track currently transported
103
    Double_t BirkC1Mod = 0;
104
    // Apply correction for higher charge states
105
      if (TMath::Abs(gMC->TrackCharge())>=2)
106
        BirkC1Mod=BirkC1*7.2/12.6;
107
      else
108
        BirkC1Mod=BirkC1;
109

    
110
    if (gMC->TrackStep()>0)
111
    {
112
      Double_t dedxcm=gMC->Edep()*1000./gMC->TrackStep(); //[MeV/cm]
113
      curLightYield=gMC->Edep()*1000./(1.+BirkC1Mod*dedxcm+BirkC2*dedxcm*dedxcm); //[MeV]
114
      curLightYield /= 1000.; //[GeV]
115
      lightYield+=curLightYield;
116
    }
117
  }
118

    
119
        if (gMC->IsTrackExiting()    || //Return true if this is the last step of the track in the current volume 
120
            gMC->IsTrackStop()       || //Return true if the track energy has fallen below the threshold
121
            gMC->IsTrackDisappeared()) 
122
        { 
123
    gMC->TrackPosition(posOut);
124
    gMC->TrackMomentum(momOut);
125
    
126
          if (eLoss > 0. && gMC->TrackCharge()!=0){
127
      AddPoint( eventID, trackID, mot0TrackID, pdg,
128
                TVector3(posIn.X(),   posIn.Y(),   posIn.Z()),
129
                TVector3(posOut.X(),  posOut.Y(),  posOut.Z()),
130
                TVector3(momIn.Px(),  momIn.Py(),  momIn.Pz()),
131
                TVector3(momOut.Px(), momOut.Py(), momOut.Pz()),
132
                time, length, eLoss, stilbenNr, lightYield);
133
    }
134
  }
135
  return kTRUE;
136
}
137

    
138
// -----   Public method EndOfEvent   -----------------------------------------
139
void ERND::BeginEvent() {
140
}
141

    
142

    
143
void ERND::EndOfEvent() {
144
  LOG(DEBUG) << "ND Points Count: " << fNDPoints->GetEntriesFast() << FairLogger::endl;
145
  Print();
146
  Reset();
147
}
148

    
149
// -----   Public method Register   -------------------------------------------
150
void ERND::Register() {
151
  FairRootManager* ioman = FairRootManager::Instance();
152
  if (!ioman)
153
        Fatal("Init", "IO manager is not set");        
154
  ioman->Register("NDPoint","ND", fNDPoints, kTRUE);
155
}
156
// ----------------------------------------------------------------------------
157

    
158
// -----   Public method GetCollection   --------------------------------------
159
TClonesArray* ERND::GetCollection(Int_t iColl) const {
160
  if (iColl == 0) 
161
    return fNDPoints;
162
  else 
163
    return NULL;
164
}
165
// ----------------------------------------------------------------------------
166

    
167
// -----   Public method Print   ----------------------------------------------
168
void ERND::Print(Option_t *option) const
169
{
170
  for (Int_t i_point = 0; i_point < fNDPoints->GetEntriesFast(); i_point++){
171
    ERNDPoint* point = (ERNDPoint*)fNDPoints->At(i_point);
172
    point->Print();
173
  }
174
}
175
// ----------------------------------------------------------------------------
176

    
177
// -----   Public method Reset   ----------------------------------------------
178
void ERND::Reset() {
179
  fNDPoints->Clear();
180
  ResetParameters();
181
}
182
// ----------------------------------------------------------------------------
183

    
184
// -----   Public method CopyClones   -----------------------------------------
185
void ERND::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
186
  LOG(DEBUG) << "   ERND::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)" 
187
            << FairLogger::endl;
188
  Int_t nEntries = cl1->GetEntriesFast();
189
  LOG(DEBUG) << "decector: " << nEntries << " entries to add" << FairLogger::endl;
190
  TClonesArray& clref = *cl2;
191
  ERNDPoint* oldpoint = NULL;
192
  for (Int_t i=0; i<nEntries; i++) {
193
  oldpoint = (ERNDPoint*) cl1->At(i);
194
   Int_t index = oldpoint->GetTrackID() + offset;
195
   oldpoint->SetTrackID(index);
196
   new (clref[cl2->GetEntriesFast()]) ERNDPoint(*oldpoint);
197
  }
198
  LOG(DEBUG) << "decector: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
199
}
200
// ----------------------------------------------------------------------------
201

    
202
// -----   Private method AddPoint   --------------------------------------------
203
ERNDPoint* ERND::AddPoint(Int_t eventID, Int_t trackID,
204
                                    Int_t mot0trackID,
205
                                    Int_t pdg,
206
                                    TVector3 posIn,
207
                                    TVector3 posOut, TVector3 momIn,
208
                                    TVector3 momOut, Double_t time,
209
                                    Double_t length, Double_t eLoss, Int_t stilbenNr, Float_t lightYield) {
210
  TClonesArray& clref = *fNDPoints;
211
  Int_t size = clref.GetEntriesFast();
212
  return new(clref[size]) ERNDPoint(eventID, trackID, mot0trackID, pdg,
213
                                          posIn, posOut, momIn, momOut, time, length, eLoss,stilbenNr,lightYield);
214
        
215
}
216
// ----------------------------------------------------------------------------
217

    
218
// -----   Public method ConstructGeometry   ----------------------------------
219
void ERND::ConstructGeometry() {
220
  TString fileName = GetGeometryFileName();
221
  if(fileName.EndsWith(".root")) {
222
    LOG(DEBUG) << "Constructing ERND geometry from ROOT file " << fileName.Data() << FairLogger::endl;
223
    ConstructRootGeometry();
224
  } else {
225
    LOG(DEBUG) << "Geometry file name is not set" << FairLogger::endl;
226
  }
227
  
228
}
229
// ----------------------------------------------------------------------------
230

    
231
// ----------------------------------------------------------------------------
232
Bool_t ERND::CheckIfSensitive(std::string name)
233
{
234
  TString volName = name;
235
  if(volName.Contains("crystal")) {
236
    return kTRUE;
237
  }
238

    
239
  return kFALSE;
240
}
241
// ----------------------------------------------------------------------------
242

    
243
// ----------------------------------------------------------------------------
244
void ERND::ResetParameters() {
245
};
246
// ----------------------------------------------------------------------------
247
ClassImp(ERND)