FairRoot/PandaRoot
PndDskFLGHitProducerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndDskFLGHitProducerIdeal source file -----
3 // ----- Created 23/04/10 by Yutie Liang -----
4 // ----- -----
5 // ----- -----
6 // -------------------------------------------------------------------------
7 #include <fstream>
8 #include <iostream>
9 #include <math.h>
10 #include "stdio.h"
11 
12 //#include "PndGeoDsk.h"
14 #include "FairRootManager.h"
15 #include "PndMCTrack.h"
16 #include "PndDskParticle.h"
17 #include "PndDskFLGHit.h"
18 #include "TVector3.h"
19 #include "TRandom.h"
20 #include "FairRunAna.h"
21 #include "FairRuntimeDb.h"
22 #include "FairBaseParSet.h"
23 #include "FairGeoVolume.h"
24 #include "TString.h"
25 #include "FairGeoTransform.h"
26 #include "FairGeoVector.h"
27 #include "FairGeoMedium.h"
28 #include "FairGeoNode.h"
29 #include "TFormula.h"
30 #include "TMath.h"
31 #include "TParticlePDG.h"
32 #include "TDatabasePDG.h"
33 #include "TPDGCode.h"
34 #include "TGeoManager.h"
35 
36 
37 using std::endl;
38 using std::cout;
39 
40 // ----- Default constructor -------------------------------------------
42 :PndPersistencyTask("PndDskFLGHitProducerIdeal")
43 {
44 
45  fGeo = new PndGeoDskFLG();
46 }
47 // -------------------------------------------------------------------------
48 
49 // ----- Standard constructor with verbosity level -------------------------------------------
50 
52  :PndPersistencyTask("PndDskFLGHitProducerIdeal")
53 {
54  fGeo = new PndGeoDskFLG();
55  fVerbose = verbose;
56 }
57 // -------------------------------------------------------------------------
58 
59 
60 // ----- Destructor ----------------------------------------------------
62 {
63 
64  if (fGeo) delete fGeo;
65 }
66 // -------------------------------------------------------------------------
67 
68 
69 // ----- Initialization -----------------------------------------------
70 // -------------------------------------------------------------------------
72 {
73  cout << " ---------- INITIALIZATION ------------" << endl;
74  nevents = 0;
75  // Get RootManager
76  FairRootManager* ioman = FairRootManager::Instance();
77  if ( ! ioman ) {
78  cout << "-E- PndDskFLGHitProducerIdeal::Init: "
79  << "RootManager not instantiated!" << endl;
80  return kFATAL;
81  }
82 
83  // Get input array
84  fDskParticleArray = (TClonesArray*) ioman->GetObject("DskParticle");
85  if ( ! fDskParticleArray ) {
86  cout << "-W- PndDskFLGHitProducerIdeal::Init: "
87  << "No DskBarPoint array!" << endl;
88  return kERROR;
89  }
90 
91  // Create and register output array
92  fHitArray = new TClonesArray("PndDskFLGHit");
93  ioman->Register("PndDskFLGHit","Dsk",fHitArray, GetPersistency());
94 
95  //initialize random for producing cherenkov photons
96  rand = new TRandom();
97 
98  //fVerbose = 2;
99  cout << "-I- PndDskFLGHitProducerIdeal: Intialization successfull" << endl;
100 
101  return kSUCCESS;
102 
103 }
104 
105 
106 // ----- Execution of Task ---------------------------------------------
107 // -------------------------------------------------------------------------
109 {
110  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
111  fHitArray->Clear();
112 
113 
114  PndDskParticle* pt=NULL;
115  nevents++;
116 
117  if (fVerbose > 1) {
118  cout << " ----------------- DSK Hit Producer --------------------" << endl;
119  cout <<" Number of input MC points in the plate: "<<fDskParticleArray->GetEntries()<<endl;
120  }
121 
122  // fNHits = 0;
123 
124  // Loop over PndDskPoints
125  for(Int_t j=0; j<fDskParticleArray->GetEntriesFast(); j++) {
126  if (fVerbose > 1) printf("\n\n=====> Event No. %d\n", nevents);
127 
128  pt = (PndDskParticle*)fDskParticleArray->At(j);
129 
130  Double_t Px= pt->GetPx();
131  Double_t Py= pt->GetPy();
132  Double_t Pz= pt->GetPz();
133  Double_t P = sqrt(Px*Px + Py*Py +Pz*Pz);
134  Double_t mass = pt->GetMass();
135  Double_t energy = TMath::Sqrt(P*P + mass*mass);
136 
137  Double_t beta;
138  if(energy != 0) {
139  beta = P/energy;
140  }
141  else {
142  beta = -1.;
143  if (fVerbose >1) cout << "Beta not calculated " << endl;
144  }
145 
147  if (fabs(1./(1.47*beta)) > 1. || P == 0. || energy == 0.){
148  thetaC = -1.;
149  }else{
150  thetaC = acos(1/(1.47*beta));
151  }
152 
153  if (thetaC != -1. && beta > 1/1.47){
154 
155  //collect that need to be stored
156  Int_t trackID = pt->GetTrackID();
157  Int_t detectorID = 0;
158  TVector3 position_store(pt->GetX(), pt->GetY(), pt->GetZ());
159  TVector3 momentum_store(Px, Py, Pz);
160  Double_t time = 0;
161  Double_t angIn = pt->GetAngIn();
162  Double_t thetaC_store = pt->GetThetaC();
163 
164  //generate Cherenkov photons in a cone
165 
166  int N_cherenko_photon = pt->GetNPhot();
167 
168  TVector3 Cone_Pos(pt->GetX()*10, pt->GetY()*10, pt->GetZ()*10);
169  TVector3 Cone_Axis(Px, Py, Pz);
170  TVector3 Cherenkov_photon(1,0,0); //initialize
171  Cherenkov_photon.SetTheta(Cone_Axis.Theta() + thetaC);
172  Cherenkov_photon.SetPhi(Cone_Axis.Phi());
173  for(int i_photon = 0; i_photon < N_cherenko_photon; i_photon++){
174  Double_t rot_angle = 2*(TMath::Pi())*rand->Rndm();
175  Cherenkov_photon.Rotate(rot_angle, Cone_Axis);
176 
177  //cout<<"Cone_Axis: "<<Cone_Axis.X()<<" "<<Cone_Axis.Y()<<" "<<Cone_Axis.Z()<<endl;
178  //cout<<"Cone_Pos: "<<Cone_Pos.X()<<" "<<Cone_Pos.Y()<<" "<<Cone_Pos.Z()<<endl;
179  //cout<<"photon_dir: "<<Cherenkov_photon.X()<<" "<<Cherenkov_photon.Y()<<" "<<Cherenkov_photon.Z()<<" theta: "<<Cherenkov_photon.Theta()<<" phi: "<<Cherenkov_photon.Phi()<<endl;
180  if(Cherenkov_photon.Theta()<0.8 || Cherenkov_photon.Z()<0) continue;
181 
182  f_light_guide = -99;
183  f_pixel = -99; //fixme
184  //Propagate(Cone_Pos, Cherenkov_photon);
185 
186  if(Cherenkov_photon.Theta()>fGeo->reflect_threshold()) fGeo->Propagate(Cone_Pos, Cherenkov_photon, f_light_guide, f_pixel);
187 
188  if(f_light_guide != -99)
189  AddHit(trackID,detectorID,position_store,momentum_store,time,
190  angIn,thetaC_store,Cherenkov_photon,f_light_guide,f_pixel);
191 
192  }
193 
194 
195  }
196  }
197 }
198 
199 
200 
201 
202 // ----- Add Hit to HitCollection --------------------------------------
203 PndDskFLGHit* PndDskFLGHitProducerIdeal::AddHit(Int_t trackID, Int_t detectorID,
204  TVector3 position_store, TVector3 momentum_store, Double_t time,
205  Double_t angIn, Double_t thetaC_store,
206  TVector3 Cherenkov_photon, Int_t light_guide, Int_t pixel)
207  {
208  TClonesArray& clref = *fHitArray;
209  Int_t size = clref.GetEntriesFast();
210  return new(clref[size]) PndDskFLGHit( trackID,detectorID,position_store,momentum_store,time,
211  angIn,thetaC_store,Cherenkov_photon,light_guide,pixel);
212 }
213 // -------------------------------------------------------------------------
214 
215 
216 // ----- Finish Task ---------------------------------------------------
218 {
219 
220  cout << "-I- PndDskFLGHitProducerIdeal: Finish" << endl;
221  }
222 // -------------------------------------------------------------------------
223 
224 
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Double_t GetAngIn() const
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
#define verbose
Double_t reflect_threshold()
Definition: PndGeoDskFLG.h:43
Double_t GetMass() const
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
virtual void Exec(Option_t *option)
Double_t
Int_t GetNPhot() const
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
PndDskFLGHit * AddHit(Int_t trackID, Int_t detectorID, TVector3 position_store, TVector3 momentum_store, Double_t time, Double_t angIn, Double_t thetaC_store, TVector3 Cherenkov_photon, Int_t light_guide, Int_t pixel)
GeV c P
ClassImp(PndAnaContFact)
void Propagate(TVector3 pos, TVector3 dir, Int_t &i_FLG, Int_t &i_Pixel)
Double_t GetThetaC() const
Double_t Pi
Double_t thetaC
Definition: plot_dirc.C:16
Double_t energy
Definition: plot_dirc.C:15