FairRoot/PandaRoot
PndDrcHitProducerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndDrcHitProducerIdeal source file -----
3 // ----- Created 11/10/06 by Annalisa Cecchi -----
4 // ----- -----
5 // ----- -----
6 // -------------------------------------------------------------------------
7 #include <fstream>
8 #include <iostream>
9 #include "stdio.h"
10 
11 #include "PndGeoDrc.h"
12 #include "PndDrcHitProducerIdeal.h"
13 #include "FairRootManager.h"
14 #include "PndMCTrack.h"
15 #include "PndDrcBarPoint.h"
16 #include "PndDrcHit.h"
17 #include "TVector3.h"
18 #include "TRandom.h"
19 #include "FairRunAna.h"
20 #include "FairRuntimeDb.h"
21 #include "FairBaseParSet.h"
22 #include "FairGeoVolume.h"
23 #include "TString.h"
24 #include "FairGeoTransform.h"
25 #include "FairGeoVector.h"
26 #include "FairGeoMedium.h"
27 #include "FairGeoNode.h"
28 #include "PndGeoDrcPar.h"
29 #include "TFormula.h"
30 #include "TMath.h"
31 #include "TGeoMatrix.h"
32 #include "TParticlePDG.h"
33 #include "TDatabasePDG.h"
34 #include "TPDGCode.h"
35 #include "TGeoManager.h"
36 
37 
38 using std::endl;
39 using std::cout;
40 
41 // ----- Default constructor -------------------------------------------
43  :PndPersistencyTask("PndDrcHitProducerIdeal"),fGeo(new PndGeoDrc())
44 {
45  fVerbose=0;
46 }
47 // -------------------------------------------------------------------------
48 
49 // ----- Standard constructor with verbosity level -------------------------------------------
50 
52  :PndPersistencyTask("PndDrcHitProducerIdeal"),fGeo(new PndGeoDrc())
53 {
55 }
56 // -------------------------------------------------------------------------
57 
58 
59 // ----- Destructor ----------------------------------------------------
61 {
62  if (fGeo) delete fGeo;
63 }
64 // -------------------------------------------------------------------------
65 
66 
67 // ----- Initialization -----------------------------------------------
68 // -------------------------------------------------------------------------
70 {
71  cout << " ---------- INITIALIZATION ------------" << endl;
72  nevents = 0;
73  // Get RootManager
74  FairRootManager* ioman = FairRootManager::Instance();
75  if ( ! ioman ) {
76  cout << "-E- PndDrcHitProducerIdeal::Init: "
77  << "RootManager not instantiated!" << endl;
78  return kFATAL;
79  }
80 
81  // Get input array
82  fBarPointArray = (TClonesArray*) ioman->GetObject("DrcBarPoint");
83  if ( ! fBarPointArray ) {
84  cout << "-W- PndDrcHitProducerIdeal::Init: "
85  << "No DrcBarPoint array!" << endl;
86  return kERROR;
87  }
88 
89  // Create and register output array
90  fHitArray = new TClonesArray("PndDrcHit");
91  ioman->Register("DrcHit","Drc",fHitArray, GetPersistency());
92 
93  cout << "-I- PndDrcHitProducerIdeal: Intialization successfull" << endl;
94 
95  return kSUCCESS;
96 
97 }
98 
99 
100 // ----- Execution of Task ---------------------------------------------
101 // -------------------------------------------------------------------------
102 void PndDrcHitProducerIdeal::Exec(Option_t*) // ion //[R.K.03/2017] unused variable(s)
103 {
104  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
105  fHitArray->Clear();
106 
107 
108  PndDrcBarPoint* pt=NULL;
109  nevents++;
110 
111  if (fVerbose > 0) {
112  cout << " ----------------- DRC Hit Producer --------------------" << endl;
113  cout <<" Number of input MC points in the bar: "<<fBarPointArray->GetEntries()<<endl;
114  }
115 
116  // fNHits = 0;
117 
118  // Loop over PndDrcPoints
119  for(Int_t j=0; j<fBarPointArray->GetEntriesFast(); j++) {
120  if (fVerbose > 1) printf("\n\n=====> Event No. %d\n", nevents);
121 
122  pt = (PndDrcBarPoint*)fBarPointArray->At(j);
123 
124  Double_t Px= pt->GetPx();
125  Double_t Py= pt->GetPy();
126  Double_t Pz= pt->GetPz();
127  Double_t P = sqrt(Px*Px + Py*Py +Pz*Pz);
128  Double_t mass = pt->GetMass();
129  Double_t energy = TMath::Sqrt(P*P + mass*mass);
130 
131  Double_t beta;
132  if(energy != 0) {
133  beta = P/energy;
134  }
135  else {
136  beta = -1.;
137  if (fVerbose >0) cout << "Beta not calculated " << endl;
138  }
139 
140  if (pt->GetThetaC() != -1. && beta > 1/1.47){
141  fDetectorID = pt->GetBoxId()*10 + pt->GetBarId();
142 
143  //TGeoNode *dircNode = (TGeoNode*)
144  gGeoManager->FindNode(pt->GetX(), pt->GetY(), pt->GetZ());
145  TGeoMatrix *dircMat = (TGeoMatrix*)gGeoManager->GetCurrentMatrix();
146  const Double_t *dircPos = dircMat->GetTranslation();
147  fPosHit.SetXYZ(dircPos[0], dircPos[1], dircPos[2]);
148 
149  Double_t fDPosXHit = 0.5; //mm
150  Double_t fDPosYHit = 0.5;
151  Double_t fDPosZHit = 0.;
152  fDPosHit.SetXYZ(fDPosXHit,fDPosYHit,fDPosZHit);
153 
154  fThetaC = gRandom->Gaus(pt->GetThetaC(),0.003);
155  fErrThetaC = 0.; //rad
156 
157  fRefIndex = j;
158 
159  // PndMCTrack* tr = NULL;
160 
162  fPosHit,
163  fDPosHit,
164  fThetaC,
165  fErrThetaC,
166  fRefIndex);
167  }
168  }
169 }
170 
171 
172 
173 
174 // ----- Add Hit to HitCollection --------------------------------------
176  Int_t , // sensorID //[R.K.03/2017] unused variable(s)
177  TVector3 posHit,
178  TVector3 dPosHit,
180  Double_t errThetaC,
181  Int_t index){
182  TClonesArray& clref = *fHitArray;
183  Int_t size = clref.GetEntriesFast();
184  return new(clref[size]) PndDrcHit(detID,
185  detID,
186  posHit,
187  dPosHit,
188  thetaC,
189  errThetaC,
190  index);
191 }
192 
193 // -------------------------------------------------------------------------
194 
195 
196 // ----- Finish Task ---------------------------------------------------
198 {
199 
200  cout << "-I- PndDrcHitProducerIdeal: Finish" << endl;
201  }
202 // -------------------------------------------------------------------------
203 
204 
Double_t GetMass() const
int fVerbose
Definition: poormantracks.C:24
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Int_t GetBarId() const
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
#define verbose
TGeoManager * gGeoManager
Double_t GetThetaC() const
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
PndDrcHit * AddHit(Int_t detID, Int_t sensorID, TVector3 posHit, TVector3 dPosHit, Double_t thetaC, Double_t errThetaC, Int_t index)
Int_t GetBoxId() const
Double_t
GeV c P
ClassImp(PndAnaContFact)
Double_t thetaC
Definition: plot_dirc.C:16
virtual void Exec(Option_t *option)
Double_t energy
Definition: plot_dirc.C:15