er  dev
ERBeamDet.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "TClonesArray.h"
10 #include "TParticle.h"
11 #include "TVirtualMC.h"
12 #include "TString.h"
13 
14 #include "FairRootManager.h"
15 #include "FairRun.h"
16 #include "FairRunSim.h"
17 #include "FairRuntimeDb.h"
18 #include "FairLogger.h"
19 
20 #include "ERBeamDet.h"
21 
22 //-------------------------------------------------------------------------------------------------
24  : ERDetector("ERBeamDet", kTRUE)
25 {
26  //Это нужно сделать для того, чтобы геометрия в симуляции автоматом писалась в файл runtime db
27  flGeoPar = new TList();
28  flGeoPar->SetName( GetName());
29  fVerboseLevel = 1;
30 }
31 //-------------------------------------------------------------------------------------------------
32 ERBeamDet::ERBeamDet(const char* name, Bool_t active, Int_t verbose)
33  : ERDetector(name, active, 1)
34 {
35  //Это нужно сделать для того, чтобы геометрия в симуляции автоматом писалась в файл runtime db
36  flGeoPar = new TList();
37  flGeoPar->SetName( GetName());
38  fVerboseLevel = verbose;
39 }
40 //-------------------------------------------------------------------------------------------------
42  for (auto* collection : {fToFPoints, fMWPCPoints, fTargetPoints}) {
43  if (collection) {
44  collection->Delete();
45  delete collection;
46  }
47  }
48 }
49 //-------------------------------------------------------------------------------------------------
51  FairDetector::Initialize();
52 }
53 //-------------------------------------------------------------------------------------------------
55  if (fVerboseLevel > 0)
56  Print();
57  Reset();
58 }
59 //-------------------------------------------------------------------------------------------------
61  FairRootManager* ioman = FairRootManager::Instance();
62  if (!ioman)
63  Fatal("Init", "IO manager is not set");
64  fToFPoints = new TClonesArray("ERBeamDetTOFPoint");
65  fMWPCPoints = new TClonesArray("ERBeamDetMWPCPoint");
66  if (fSensitiveTargetIsSet) {
67  fTargetPoints = new TClonesArray("ERBeamDetTargetPoint");
68  }
69  ioman->Register("BeamDetToFPoint","BeamDet", fToFPoints, kTRUE);
70  ioman->Register("BeamDetMWPCPoint","BeamDet", fMWPCPoints, kTRUE);
71  if (fSensitiveTargetIsSet) {
72  ioman->Register("BeamDetTargetPoint","BeamDet", fTargetPoints, kTRUE);
73  }
74 }
75 //-------------------------------------------------------------------------------------------------
76 TClonesArray* ERBeamDet::GetCollection(Int_t iColl) const {
77  if (iColl == 0)
78  return fToFPoints;
79  if (iColl == 0)
80  return fMWPCPoints;
81  if (fSensitiveTargetIsSet) {
82  if (iColl == 0)
83  return fTargetPoints;
84  }
85  return NULL;
86 }
87 //-------------------------------------------------------------------------------------------------
88 void ERBeamDet::Print(Option_t *option) const
89 {
90  if(fToFPoints->GetEntriesFast() > 0) {
91  for (Int_t iPoint = 0; iPoint < fToFPoints->GetEntriesFast(); iPoint++){
92  ERBeamDetTOFPoint* point = (ERBeamDetTOFPoint*)fToFPoints->At(iPoint);
93  point->Print();
94  }
95  }
96  if(fMWPCPoints->GetEntriesFast() > 0) {
97  for (Int_t iPoint = 0; iPoint < fMWPCPoints->GetEntriesFast(); iPoint++){
98  ERBeamDetMWPCPoint* point = (ERBeamDetMWPCPoint*)fMWPCPoints->At(iPoint);
99  point->Print();
100  }
101  }
102  if(fSensitiveTargetIsSet && fTargetPoints->GetEntriesFast() > 0) {
103  for (Int_t iPoint = 0; iPoint < fTargetPoints->GetEntriesFast(); iPoint++) {
105  point->Print();
106  }
107  }
108 }
109 //-------------------------------------------------------------------------------------------------
111  for (auto* collection : {fTargetPoints, fMWPCPoints, fToFPoints}) {
112  if (collection)
113  collection->Clear();
114  }
115 }
116 //-------------------------------------------------------------------------------------------------
117 void ERBeamDet::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
118  Int_t nEntries = cl1->GetEntriesFast();
119  LOG(FATAL) << "BeamDet: " << nEntries << " entries to add" << FairLogger::endl;
120  TClonesArray& clref = *cl2;
121  ERBeamDetTOFPoint* oldpoint = NULL;
122  for (Int_t i=0; i<nEntries; i++) {
123  oldpoint = (ERBeamDetTOFPoint*) cl1->At(i);
124  Int_t index = oldpoint->GetTrackID() + offset;
125  oldpoint->SetTrackID(index);
126  new (clref[cl2->GetEntriesFast()]) ERBeamDetTOFPoint(*oldpoint);
127  }
128  LOG(FATAL) << "BeamDet: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
129 }
130 //-------------------------------------------------------------------------------------------------
132  if (!fTargetPoints)
133  return nullptr;
134  TClonesArray& clref = *fTargetPoints;
135  Int_t size = clref.GetEntriesFast();
136  return new(clref[size]) ERBeamDetTargetPoint(fEventID, fTrackID, fMot0TrackID, fPID,
137  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
138  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
139  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
140  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
142 }
143 //-------------------------------------------------------------------------------------------------
145  TClonesArray& clref = *fMWPCPoints;
146  Int_t size = clref.GetEntriesFast();
147  return new(clref[size]) ERBeamDetMWPCPoint(fEventID, fTrackID, fMot0TrackID, fPID,
148  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
149  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
150  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
151  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
154 }
155 //-------------------------------------------------------------------------------------------------
157  TClonesArray& clref = *fToFPoints;
158  Int_t size = clref.GetEntriesFast();
159  return new(clref[size]) ERBeamDetTOFPoint(fEventID, fTrackID, fMot0TrackID, fPID,
160  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
161  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
162  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
163  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
165 }
166 //-------------------------------------------------------------------------------------------------
167 Bool_t ERBeamDet::CheckIfSensitive(std::string name) {
168  TString volName = name;
169  if(volName.Contains("gasStrip")) {
170  return kTRUE;
171  }
172  if(volName.Contains("plastic")) {
173  return kTRUE;
174  }
175  if(fSensitiveTargetIsSet && volName.Contains("targetBodyH2")) {
176  return kTRUE;
177  }
178  return kFALSE;
179 }
180 //-------------------------------------------------------------------------------------------------
182  fSetup->ConstructGeometry();
183  SetGeometryFileName("beamdet.temp.root");
184  ConstructRootGeometry();
185  fSensitiveTargetIsSet = fSetup->CheckIfTargetIsSet();
186 }
187 //-------------------------------------------------------------------------------------------------
188 Bool_t ERBeamDet::ProcessHits(FairVolume* vol) {
189  // Set constants for Birk's Law implentation
190  static const Double_t dP = 1.032 ;
191  static const Double_t BirkC1 = 0.013/dP;
192  static const Double_t BirkC2 = 9.6e-6/(dP * dP);
193 
194  if ( gMC->IsTrackEntering() ) { // Return true if this is the first step of the track in the current volume
195  fELoss = 0.;
196  fLightYield = 0;
197  fEventID = gMC->CurrentEvent();
198  gMC->TrackPosition(fPosIn);
199  gMC->TrackMomentum(fMomIn);
200  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
201  fTime = gMC->TrackTime() * 1.0e09; // Return the current time of flight of the track being transported
202  fLength = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
203  fMot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
204  fPID = gMC->TrackPid();
205  TString volName = gMC->CurrentVolName();
206  }
207  const Double_t stepEloss = gMC->Edep() * 1000; // [MeV] //Return the energy lost in the current step
208  fELoss += stepEloss;
209  Double_t stepLightYield = 0;
210  // Correction for all charge states
211  if (gMC->TrackCharge()!=0) { // Return the charge of the track currently transported
212  Double_t BirkC1Mod = 0;
213  // Apply correction for higher charge states
214  if (TMath::Abs(gMC->TrackCharge())>=2)
215  BirkC1Mod=BirkC1*7.2/12.6;
216  else
217  BirkC1Mod=BirkC1;
218 
219  if (gMC->TrackStep()>0) {
220  Double_t dedxcm = stepEloss / gMC->TrackStep(); //[MeV/cm]
221  stepLightYield= stepEloss / (1.+BirkC1Mod*dedxcm+BirkC2*dedxcm*dedxcm); //[MeV]
222  fLightYield += stepLightYield;
223  }
224  }
225  if (gMC->IsTrackExiting() || //Return true if this is the last step of the track in the current volume
226  gMC->IsTrackStop() || //Return true if the track energy has fallen below the threshold
227  gMC->IsTrackDisappeared())
228  {
229  gMC->TrackPosition(fPosOut);
230  gMC->TrackMomentum(fMomOut);
231  TString volName = gMC->CurrentVolName();
232  if (fELoss > 0.){
233  if(volName.Contains("plastic")) {
234  gMC->CurrentVolID(fToFNb);
235  AddTOFPoint();
236  if (fMot0TrackID != -1) {
237  gMC->StopTrack();
238  }
239  }
240  if(volName.Contains("gasStrip")) {
241  gMC->CurrentVolOffID(0, fMWPCWireNb);
242  gMC->CurrentVolOffID(1, fMWPCPlaneNb);
243  gMC->CurrentVolOffID(3, fMWPCNb);
244  AddMWPCPoint();
245  }
246  if (fSensitiveTargetIsSet) {
247  if(volName.Contains("targetBodyH2")) {
248  AddTargetPoint();
249  }
250  }
251  }
252  }
253  return kTRUE;
254 }
255 //-------------------------------------------------------------------------------------------------
256 ClassImp(ERBeamDet)
ERBeamDetTOFPoint * AddTOFPoint()
Adds a ERBeamDetToFPoint to the ToFPoints Collection.
Definition: ERBeamDet.cxx:156
Class for the MC transport of the BeamDet.
Definition: ERBeamDet.h:31
virtual ~ERBeamDet()
Destructor.
Definition: ERBeamDet.cxx:41
virtual Bool_t ProcessHits(FairVolume *vol=0)
Defines the action to be taken when a step is inside the active volume. Creates a ERBeamDetPoint and ...
Definition: ERBeamDet.cxx:188
ERBeamDet()
Default constructor.
Definition: ERBeamDet.cxx:23
TClonesArray * fTargetPoints
The TargetPoint collection.
Definition: ERBeamDet.h:97
virtual void Reset()
Clears the point collection. Virtual from FairDetector.
Definition: ERBeamDet.cxx:110
virtual TClonesArray * GetCollection(Int_t iColl) const
Accessor to the point collection . Abstract from FairDetector.
Definition: ERBeamDet.cxx:76
Int_t fEventID
event index
Definition: ERBeamDet.h:98
virtual void EndOfEvent()
If verbosity level is set, print point collection at the end of the event. Virtual from FairDetector...
Definition: ERBeamDet.cxx:54
TClonesArray * fMWPCPoints
The MWPCPoint collection.
Definition: ERBeamDet.h:96
virtual void Print(const Option_t *opt=0) const
ERBeamDetMWPCPoint * AddMWPCPoint()
Adds a ERBeamDetMWPCPoint to the MWPCPoints Collection.
Definition: ERBeamDet.cxx:144
ERBeamDetTargetPoint * AddTargetPoint()
Adds a ERBeamDetTargetPoint to the TargetPoints Collection.
Definition: ERBeamDet.cxx:131
TClonesArray * fToFPoints
The ToFPoint collection.
Definition: ERBeamDet.h:95
virtual void Initialize()
Initialize ERBeamDet data. Abstract from FairDetector.
Definition: ERBeamDet.cxx:50
Int_t fMWPCNb
MWPC station number.
Definition: ERBeamDet.h:111
virtual void Register()
Registers the point collection in the ROOT manager. Virtual from FairDetector.
Definition: ERBeamDet.cxx:60
virtual void ConstructGeometry()
Builds geometry and writes it to temporary file trough parameters from ERBeamDetSetup class object...
Definition: ERBeamDet.cxx:181
TLorentzVector fMomOut
point finish momentum
Definition: ERBeamDet.h:105
Int_t fMWPCWireNb
wire number in gas strip array
Definition: ERBeamDet.h:113
Double32_t fTime
point start time
Definition: ERBeamDet.h:106
Int_t fMot0TrackID
0th mother track index
Definition: ERDetector.h:145
TLorentzVector fMomIn
point start momentum
Definition: ERBeamDet.h:104
virtual void Print(const Option_t *opt=0) const
virtual Bool_t CheckIfSensitive(std::string name)
Check whether a volume is sensitive.
Definition: ERBeamDet.cxx:167
TLorentzVector fPosOut
point finish position
Definition: ERBeamDet.h:103
Double32_t fLightYield
light yield
Definition: ERBeamDet.h:109
virtual void Print(Option_t *option="") const
Screen output of hit collection. Virtual from TObject.
Definition: ERBeamDet.cxx:88
Double32_t fLength
length
Definition: ERBeamDet.h:107
TLorentzVector fPosIn
point start position
Definition: ERBeamDet.h:102
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Copies the hit collection with a given track index offset.
Definition: ERBeamDet.cxx:117
virtual void Print(const Option_t *opt=0) const
Int_t fToFNb
ToF plastic number.
Definition: ERBeamDet.h:110
The base class for detector simulation in er sim.
Definition: ERDetector.h:32
Double32_t fELoss
energy loss
Definition: ERDetector.h:157
Int_t fPID
particle PDG
Definition: ERBeamDet.h:101
Int_t fTrackID
track index
Definition: ERBeamDet.h:99
Int_t fMWPCPlaneNb
gas strip array number in MWPC station
Definition: ERBeamDet.h:112