FairRoot/PandaRoot
PndRichHitProducer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndRichHitProducer source file -----
3 // ----- Created 11/06/08 by S.Spataro -----
4 // -------------------------------------------------------------------------
5 
6 #include <PndPersistencyTask.h>
7 #include "PndRichHitProducer.h"
8 
9 #include "PndRichDigi.h"
10 #include "PndRichHit.h"
11 #include "PndRichPDHit.h"
12 #include "PndRichPDPoint.h"
13 #include "PndRichBarPoint.h"
14 
15 #include "FairRootManager.h"
16 #include "FairDetector.h"
17 #include "FairRun.h"
18 #include "FairRuntimeDb.h"
19 #include "FairEventHeader.h"
20 
22 
23 #include "TClonesArray.h"
24 #include "TGeoManager.h"
25 #include "TGeoVolume.h"
26 #include "TGeoNode.h"
27 #include "TGeoMatrix.h"
28 #include "TVector3.h"
29 #include "TRandom.h"
30 
31 #include <iostream>
32 #include <iomanip>
33 
34 using std::cout;
35 using std::endl;
36 
37 // ----- Default constructor -------------------------------------------
39  PndPersistencyTask("Rich Hit Producer") {
40  fPosResolution = -1.;
41  fGeoVersion = 313;
42  fPhDetNoise = kFALSE;
43  fNumRand = 0;
44  SetPersistency(kTRUE);
45  fTimeOrderedDigi = kFALSE;
46  fPreviousEventTime = -1;
47 }
48 // -------------------------------------------------------------------------
49 
50 // ----- Destructor ----------------------------------------------------
52 // -------------------------------------------------------------------------
53 
54 
55 
56 // ----- Public method Init --------------------------------------------
58 
59  cout << "-I- PndRichHitProducer::Init: "
60  << "INITIALIZATION *********************" << endl;
61 
62  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
63  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
64 
65  fGeo = new PndRichGeo();
67  cout << "-I- PndRichHitProducer::Init: "
68  << "fGeoVersion = " << fGeoVersion << endl;
69 
70  cout << "-I- PndRichHitProducer::Init: ";
71  if (fPhDetNoise)
72  cout << "Photodetector noise is switched on! " << endl;
73  else
74  cout << "Photodetector noise is switched off! " << endl;
75 
76  // Get RootManager
77  FairRootManager* ioman = FairRootManager::Instance();
78  if ( ! ioman ) {
79  cout << "-E- PndRichHitProducer::Init: "
80  << "RootManager not instantiated!" << endl;
81  return kFATAL;
82  }
83 
84  // Get input array
85  fPDPointArray = (TClonesArray*) ioman->GetObject("RichPDPoint");
86  if ( ! fPDPointArray ) {
87  cout << "-W- PndRichHitProducer::Init: "
88  << "No RichPDPoint array!" << endl;
89  return kERROR;
90  }
91 
92  fBarPointArray = (TClonesArray*) ioman->GetObject("RichBarPoint");
93  if ( ! fBarPointArray ) {
94  cout << "-W- PndRichHitProducer::Init: "
95  << "No RichBarPoint array!" << endl;
96  return kERROR;
97  }
98 
99  // Create and register output array
100  fDataBuffer = new PndRichHitWriteoutBuffer("RichDigi", "PndRich", GetPersistency());
101  fDataBuffer = (PndRichHitWriteoutBuffer*)ioman->RegisterWriteoutBuffer("RichDigi", fDataBuffer);
102  fDataBuffer->ActivateBuffering(fTimeOrderedDigi);
103 
104  fHitArray = new TClonesArray("PndRichHit");
105  ioman->Register("RichHit","PndRich",fHitArray,kTRUE);
106 
107  if (fPosResolution>0.)
108  cout << "-I- PndRichHitProducer::Init: "
109  << "Hit Position smearing: " << fPosResolution << " [cm]" << endl;
110 
111  cout << "-I- PndRichHitProducer: Intialization successfull" << endl;
112 
114 
115 /* for(UInt_t i=0;i<1e5;i++)
116  {
117  Double_t xl = 2*gRandom->Uniform()*(fGeo->phDetSizeX() + fGeo->phDetGapX());
118  Double_t yl = 2*gRandom->Uniform()*(fGeo->phDetSizeY() + fGeo->phDetGapY());
119  TVector3 posg = fGeo->PhDetPositionGlobal(TVector3(xl,yl,0.0));
120  TVector3 pos = fGeo->PositionDiscretization(posg);
121  TVector3 posl = pos.Z() ? fGeo->PhDetPositionLocal(pos) : TVector3(0,0,0);
122  std::cout << "PndRichGeo: " <<
123 // format("%15.6 %15.6 %15.6 %15.6 %15.6\n") % xl % yl % posl.X() % posl.Y() % pos.Z();
124  std::setprecision(8) << xl << " " << yl <<
125  " " << posl.X() << " " << posl.Y() << " " << pos.Z() << std::endl;
126  }
127 */
128 /* Double_t xmax = (fGeo->phDetSizeX() + fGeo->phDetGapX())*2;// *fGeo->phDetNumX();
129  Double_t ymax = (fGeo->phDetSizeY() + fGeo->phDetGapY())*2;// *fGeo->phDetNumY();
130  for(Double_t x=-xmax;x<xmax;x+=0.1)
131  {
132  for(Double_t y=-ymax;y<ymax;y+=0.1)
133  {
134  TVector3 pos = fGeo->PhDetPositionGlobal(TVector3(x,y,0));
135  Int_t ix = fGeo->IndexX(pos);
136  Int_t iy = fGeo->IndexY(pos);
137  TVector3 posl = fGeo->PhDetPositionLocal(fGeo->PixelPosition(ix,iy));
138  std::cout << "PndRichGeo: " <<
139  std::setprecision(8) << ix << " " << iy << " " << x << " " << y <<
140  " " << posl.X() << " " << posl.Y() << " " << pos.Z() << std::endl;
141  }
142  }*/
143  return kSUCCESS;
144 
145 }
146 // -------------------------------------------------------------------------
147 
148 
149 
150 // ----- Public method Exec --------------------------------------------
151 void PndRichHitProducer::Exec(Option_t* ) {
152 
153  fEventTime = FairRootManager::Instance()->GetEventTime();
154  std::cout << "FairRootManager::Instance()->GetEventTime() = " << fEventTime << " " << fPreviousEventTime << " " << fGeo->sensorsPerDevice() << std::endl;
155 
156  // Reset output array
157  //if ( ! fPDHitArray ) Fatal("Exec", "No HitArray");
158 
159  //if (!fTimeOrderedDigi) fPDHitArray->Clear();
160 
161  //pixels of PhDet
162  UInt_t iXmax = fGeo->phDetNPixelMaxX();
163  UInt_t iYmax = fGeo->phDetNPixelMaxY();
164 /* UInt_t map[iXmax][iYmax];
165  for (UInt_t ix=0; ix<iXmax; ix++)
166  for (UInt_t iy=0; iy<iYmax; iy++)
167  map[ix][iy] = 0;
168  */
169  // Loop over RichPDpoints
170  Int_t nPoints = fPDPointArray->GetEntriesFast();
171  PndRichPDPoint *point = 0;
172  TVector3 pos, mom;
174 // Double_t k = 2*3.1415927*197.3269602e-9;
175 
176  for (Int_t iPoint=0; iPoint<nPoints; iPoint++) {
177  point = (PndRichPDPoint*) fPDPointArray->At(iPoint);
178  point->Momentum(mom);
179 // if ( gRandom->Uniform() < fGeo->phDetQEff(k/mom.Mag()) ) {
180  point->Position(pos);
181  TVector3 posd = fGeo->PositionDiscretization(pos);
182  if (posd.Z())
183  {
184  Double_t t = gRandom->Gaus(point->GetTime(),0.5); //ns
185 /* if (fPhDetNoise) { // add noise
186  std::vector<Double_t> tn = PhDetNoise();
187  for (UInt_t i=0; i<tn.size(); i++)
188  if (t-tn.at(i)<720&&t>tn.at(i)) t = tn.at(i);
189  }*/
190  AddDigi(point->GetDetectorID(), fGeo->sensorIndex(), posd, sig, iPoint, t );
191 // UInt_t ix = fGeo->IndexX(posd);
192 // UInt_t iy = fGeo->IndexY(posd);
193 // if ( ix<iXmax && iy<iYmax )
194 // map[ix][iy] = 1;
195  }
196 // }
197  } // Loop over MCPoints
198  if (fPhDetNoise) {
199 /* for (UInt_t ix=0; ix<iXmax; ix++)
200  for (UInt_t iy=0; iy<iYmax; iy++)
201  if (!map[ix][iy]) {
202  std::vector<Double_t> tn = PhDetNoise();
203  if (tn.size()&&tn.back()>-50) {
204  pos = fGeo->PixelPosition(ix,iy);
205  AddDigi(0, fGeo->sensorIndex(), pos, sig, 0, tn.back() );
206  }
207  }*/
208  Int_t kcell = 8/fGeo->sensorsPerDevice(); // in one direction
209  Double_t fnoise = 1e3*1e-9*kcell*kcell; //GHz(=1/ns) per pixel
211  Int_t nn = gRandom->Poisson(iXmax*iYmax*fnoise*dt); //number of fired pixels
212  std::cout << "nn = " << nn << " " << iXmax << " " << iYmax << " " << kcell << std::endl;
213  for (Int_t i=0; i<nn; i++)
214  {
215  Int_t gind = gRandom->Integer(iXmax*iYmax);
216  Int_t ix = gind%iXmax;
217  Int_t iy = gind/iXmax;
218  pos = fGeo->PixelPosition(ix,iy);
219  Double_t t = (fTimeOrderedDigi?0:25)-dt*gRandom->Uniform();
220  AddDigi(0, fGeo->sensorIndex(), pos, sig, 0, t );
221  }
222  }
223 
224 // if (!fTimeOrderedDigi)
225  {
226  fHitArray->Clear();
227 
228  // Loop over RichBarPoints
229  Int_t nBarPoints = fBarPointArray->GetEntriesFast();
230  PndRichBarPoint *hit = 0;
231 
232  Int_t detID=-999; //[R.K.Jan/2017] Variable was not initialized!
233  Int_t sensorId=-999; //[R.K.Jan/2017] Variable was not initialized!
234  //, index; //[R.K. 01/2017] unused variable?
235  TVector3 dpos(0., 0., 0.);
236  // thetaC containe value of beta
237  Double_t thetaC, errThetaC;
238  dbpoint pnt;
239  for (Int_t iBarPoint=0; iBarPoint<nBarPoints; iBarPoint++) {
240  hit = (PndRichBarPoint*) fBarPointArray->At(iBarPoint);
241  hit->Position(pos);
242  hit->Momentum(mom);
243 
244  pnt.mass = hit->GetMass();
245  pnt.beta = mom.Mag()/sqrt(mom.Mag()*mom.Mag()+pnt.mass*pnt.mass);
246  pnt.x = pos.X();
247  pnt.y = pos.Y();
248  pnt.theta = mom.Theta();
249  pnt.phi = mom.Phi();
250 
251  if ( gRandom->Uniform() < fRichResolution->Efficiency(pnt) ) { // efficiency of reconstruction
252  errThetaC = fRichResolution->Sigma(pnt); // sigma of beta
253  thetaC = gRandom->Gaus( hit->GetThetaC(), errThetaC );
254  AddHit(detID, sensorId, pos, dpos, thetaC, errThetaC, iBarPoint);
255  }
256  } // Loop over MCPoints
257  }
258  fPreviousEventTime = FairRootManager::Instance()->GetEventTime();
259 }
260 // -------------------------------------------------------------------------
261 
262 std::vector<Double_t> PndRichHitProducer::PhDetNoise()
263 {
264  std::vector<Double_t> tn;
265  Double_t td = 720; //ns
266  Double_t fn = 0.25e5; //Hz
267  Double_t ts = -2000;//start time of noise simulation, in ns
268  Double_t tstop = 50;
269  Double_t t = 0;
270  while(ts<tstop) {
271  t += gRandom->Exp(1e9/fn-td);
272  fNumRand++;
273  if (t>td) {
274  ts += t;
275  t = 0;
276  if (ts<tstop) tn.push_back(ts);
277  }
278  }
279  return tn;
280 }
281 
282 // ----- Private method AddHit --------------------------------------------
283 void PndRichHitProducer::AddXPDHit(Int_t detID, Int_t sensorId,
284  TVector3& pos, TVector3& dpos,
285  Int_t index, Double_t time ){
286  if (fTimeOrderedDigi) AddDigi(detID,sensorId,pos,dpos,index,time);
287  else AddPDHit(detID,sensorId,pos,dpos,index,time);
288  //AddDigi(detID,sensorId,pos,dpos,index,time);
289 }
290 
291 PndRichDigi* PndRichHitProducer::AddDigi(Int_t detID, Int_t sensorId,
292  TVector3& pos, TVector3& dpos,
293  Int_t index, Double_t time ){
294  Double_t EventTime = FairRootManager::Instance()->GetEventTime();
295  fDeadTime = 100; // ns;
296 
297  Double_t timeThreshold=-999; //[R.K.Jan/2017] Variable was not initialized!
298  PndRichDigi *hitnew = new PndRichDigi(index,detID, sensorId, pos, dpos, time+EventTime, timeThreshold, EventTime+time);
299  if (fTimeOrderedDigi){
300  hitnew->ResetLinks();
301  FairEventHeader* evtHeader = (FairEventHeader*)FairRootManager::Instance()->GetObject("EventHeader.");
302  hitnew->AddLink(FairLink(evtHeader->GetInputFileId(), evtHeader->GetMCEntryNumber(), "RichPDPoint", index));
303  hitnew->AddLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), "EventHeader.", -1));
305  if (point) hitnew->AddLinks(*(point->GetPointerToLinks()));
306  }
307  fDataBuffer->FillNewData(hitnew, EventTime+time, EventTime+time+fDeadTime);
308  return hitnew;
309 }
310 // ----
311 
312 PndRichPDHit* PndRichHitProducer::AddPDHit(Int_t detID, Int_t sensorId,
313  TVector3& pos, TVector3& dpos,
314  Int_t index, Double_t time ){
315  // It fills the PndRichPDHit category
316 
317  Double_t timeThreshold=-999; //[R.K.Jan/2017] Variable was not initialized!
318  TClonesArray& clref = *fPDHitArray;
319  Int_t size = clref.GetEntriesFast();
320  return new(clref[size]) PndRichPDHit(index, detID, sensorId, pos, dpos, time, timeThreshold);
321 }
322 // ----
323 
324 
325 // ----- Private method AddHit --------------------------------------------
326 PndRichHit* PndRichHitProducer::AddHit(Int_t detID, Int_t sensorId,
327  TVector3& pos, TVector3& dpos,
328  Double_t thetaC, Double_t errThetaC,
329  Int_t index){
330 
331  TClonesArray& clref = *fHitArray;
332  Int_t size = clref.GetEntriesFast();
333  return new(clref[size]) PndRichHit(detID, sensorId, pos, dpos, thetaC, errThetaC, index);
334 }
335 // ----
336 
338 {
339 }
340 
342 {
343 }
344 
TVector3 pos
virtual InitStatus Init()
Double_t x
Definition: PndRichCalDb.h:25
TClonesArray * fHitArray
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
TVector3 PositionDiscretization(TVector3 pos, bool cell=true)
Definition: PndRichGeo.cxx:557
TClonesArray * pnt
void SetPersistency(Bool_t val=kTRUE)
UInt_t sensorsPerDevice()
Definition: PndRichGeo.h:216
virtual void Exec(Option_t *opt)
PndRichDigi * AddDigi(Int_t detID, Int_t sensorId, TVector3 &pos, TVector3 &dpos, Int_t index, Double_t time)
Double_t mom
Definition: plot_dirc.C:14
UInt_t phDetNPixelMaxY()
Definition: PndRichGeo.h:192
Double_t GetMass() const
void AddXPDHit(Int_t detID, Int_t sensorId, TVector3 &pos, TVector3 &dpos, Int_t index, Double_t time)
UInt_t phDetNPixelMaxX()
Definition: PndRichGeo.h:189
std::vector< Double_t > PhDetNoise()
Double_t
PndRichHit * AddHit(Int_t detID, Int_t sensorId, TVector3 &pos, TVector3 &dpos, Double_t thetaC, Double_t errThetaC, Int_t index)
TClonesArray * fPDHitArray
Double_t mass
Definition: PndRichCalDb.h:23
void init(size_t ver=0)
Definition: PndRichGeo.cxx:82
UInt_t sensorIndex()
Definition: PndRichGeo.h:186
PndRichPDHit * AddPDHit(Int_t detID, Int_t sensorId, TVector3 &pos, TVector3 &dpos, Int_t index, Double_t time)
Double_t GetThetaC() const
PndRichHitWriteoutBuffer * fDataBuffer
TClonesArray * fPDPointArray
ClassImp(PndAnaContFact)
Double_t theta
Definition: PndRichCalDb.h:27
TTree * t
Definition: bump_analys.C:13
Double_t phi
Definition: PndRichCalDb.h:28
PndSdsMCPoint * hit
Definition: anasim.C:70
Double_t Sigma(dbpoint pnt)
PndPidEmcAssociatorTask * ts
PndRichResolution * fRichResolution
Double_t Efficiency(dbpoint pnt)
Double_t beta
Definition: PndRichCalDb.h:24
Double_t thetaC
Definition: plot_dirc.C:16
Double_t y
Definition: PndRichCalDb.h:26
TClonesArray * fBarPointArray
TVector3 PixelPosition(UInt_t ix, UInt_t iy)
Definition: PndRichGeo.cxx:681
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72