FairRoot/PandaRoot
PndSttHitProducerRealFast.cxx
Go to the documentation of this file.
1 // PndSttHitProducerRealFast
3 //
4 // Class for digitalization for STT1
5 //
6 // authors: Pablo Genova - Pavia University
7 // Lia Lavezzi - Pavia University
8 //
10 
12 
13 #include "PndSttHit.h"
14 #include "PndSttHitInfo.h"
15 #include "PndSttPoint.h"
16 #include "PndSttSingleStraw.h"
17 #include "PndGeoSttPar.h"
18 #include "PndSttTube.h"
19 #include "PndSttMapCreator.h"
20 #include "PndSttSignalOverlap.h"
21 #include "PndSttTubeMap.h"
22 
23 #include "FairRootManager.h"
24 #include "FairRunAna.h"
25 #include "FairRuntimeDb.h"
26 #include "FairGeoNode.h"
27 #include "FairGeoTransform.h"
28 #include "FairGeoRotation.h"
29 #include "FairGeoVector.h"
30 
31 #include "TGeoManager.h"
32 #include "TClonesArray.h"
33 #include "TVector3.h"
34 #include "TRandom.h"
35 #include <iostream>
36 #include <cmath>
37 
38 using std::cout;
39 using std::endl;
40 using std::sqrt;
41 
42 // ----- Default constructor -------------------------------------------
44  PndPersistencyTask("Ideal STT Hit Producer",0), fSeparate(kFALSE), fSttParameters(NULL), fGeoType(-1) {
45  SetPersistency(kTRUE);
46  fOverlap = kFALSE;
47 }
48 // -------------------------------------------------------------------------
49 
50 
51 // ----- Destructor ----------------------------------------------------
53 // -------------------------------------------------------------------------
54 
55 
56 
57 // ----- Public method Init --------------------------------------------
59  fevtn=0;
60 
61  // Get RootManager
62  FairRootManager* ioman = FairRootManager::Instance();
63  if ( ! ioman ) {
64  cout << "-E- PndSttHitProducerRealFast-wintz::Init: "
65  << "RootManager not instantiated!" << endl;
66  return kFATAL;
67  }
68 
70 
71  // Get input array
72  fPointArray = (TClonesArray*) ioman->GetObject("STTPoint");
73  if ( ! fPointArray ) {
74  cout << "-W- PndSttHitProducerRealFast::Init: "
75  << "No STTPoint array!" << endl;
76  return kERROR;
77  }
78 
79  // Create and register output array
80  if(!fOverlap) {
81  if(fSeparate == kTRUE) {
82  fSttParalHitArray = new TClonesArray("PndSttHit");
83  ioman->Register("STTParalHit","STT", fSttParalHitArray, GetPersistency());
84  fSttSkewHitArray = new TClonesArray("PndSttHit");
85  ioman->Register("STTSkewHit","STT", fSttSkewHitArray, GetPersistency());
86  }
87  else {
88  // if there is no overlap save in output the regular hits
89  fHitArray = new TClonesArray("PndSttHit");
90  ioman->Register("STTHit","STT",fHitArray, GetPersistency());
91  }
92  }
93  else {
94 
95  // otherwise, with overlap on, save the overlapped hits in
96  // regular output TCA (STTHit) and the "original", non overlapped
97  // hits in another TCA (STTOriginalHit)
98  if(fSeparate == kTRUE) {
99  fSttParalOverlapHitArray = new TClonesArray("PndSttHit");
100  ioman->Register("STTParalHit","STT", fSttParalOverlapHitArray, GetPersistency());
101  fSttSkewOverlapHitArray = new TClonesArray("PndSttHit");
102  ioman->Register("STTSkewHit","STT", fSttSkewOverlapHitArray, GetPersistency());
103  fSttParalHitArray = new TClonesArray("PndSttHit");
104  ioman->Register("STTParalOriginalHit","STT", fSttParalHitArray, GetPersistency());
105  fSttSkewHitArray = new TClonesArray("PndSttHit");
106  ioman->Register("STTSkewOriginalHit","STT", fSttSkewHitArray, GetPersistency());
107  }
108  else {
109  fOverlapHitArray = new TClonesArray("PndSttHit");
110  ioman->Register("STTHit","STT",fOverlapHitArray, GetPersistency());
111  fHitArray = new TClonesArray("PndSttHit");
112  ioman->Register("STTOriginalHit","STT",fHitArray, GetPersistency());
113  }
114 
115  }
116 
117  // Create and register output array
118  fHitInfoArray = new TClonesArray("PndSttHitInfo");
119  ioman->Register("STTHitInfo", "STT", fHitInfoArray, kFALSE);
120 
121  fVolumeArray = gGeoManager->GetListOfVolumes();
122 
123  //cout << "-I- PndSttHitProducerRealFast: Intialization successfull" << endl;
124 
125  // CHECK added
126  if (fGeoType == 1){
128  fTubeArray = mapper.FillTubeArray();
129  }
130 
131  cout << "-I- PndSttHitProducerRealFast: Intialization successfull" << endl;
132 
133  return kSUCCESS;
134 
135 }
136 // -------------------------------------------------------------------------
137 
139  FairRuntimeDb* rtdb = FairRun::Instance()->GetRuntimeDb();
140  fSttParameters = (PndGeoSttPar*) rtdb->getContainer("PndGeoSttPar");
141 }
142 
143 
144 // ----- Public method Exec --------------------------------------------
146 
147  if(fVerbose && fevtn%50==0) cout << "Event Number "<<fevtn<<endl;
148  else if(fVerbose >= 3) cout << "Event Number "<<fevtn<<endl;
149 
150  fevtn++;
151 
152  if(fSeparate == kTRUE) {
153  fSttParalHitArray->Delete();
154  fSttSkewHitArray->Delete();
155  }
156  else {
157  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
158  fHitArray->Delete();
159  }
160  if(fOverlap) {
161  if(fSeparate == kTRUE) {
162  fSttParalOverlapHitArray->Delete();
163  fSttSkewOverlapHitArray->Delete();
164  }
165  else {
166  fOverlapHitArray->Delete();
167  }
168  }
169  fHitInfoArray->Clear();
170 
171  Int_t detID = 0; // detectorID
172  TVector3 pos, dpos; // position and error vectors
173 
174  // Declare some variables
175  PndSttPoint* point = NULL;
176 
177 
178  // Loop over SttPoints
179  Int_t nPoints = fPointArray->GetEntriesFast();
180 
181  // cout << "------------ " << nPoints << endl;
182 
183  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
184  point = (PndSttPoint*) fPointArray->At(iPoint);
185  if (point == NULL) continue;
186 
187  detID = point->GetDetectorID();
188 
189  // tubeID CHECK added
190  Int_t tubeID = point->GetTubeID();
191  PndSttTube *tube = nullptr;
192 
193  if (fGeoType == 1)
194  tube = (PndSttTube*) fTubeArray->At(tubeID);
195  else if (fGeoType == 2){
196  tube = PndSttTubeMap::Instance()->GetTube(tubeID);
197  }
198  if (tube == nullptr){
199  std::cout << "-E- PndSttHitProducerRealFast Nullptr of TubeID: " << tubeID << std::endl;
200  }
201 
202  double InOut[6];
203  memset(InOut, 0, sizeof(InOut));
204 
205  InOut[0] = point->GetXInLocal();
206  InOut[1] = point->GetYInLocal();
207  InOut[2] = point->GetZInLocal();
208  InOut[3] = point->GetXOutLocal();
209  InOut[4] = point->GetYOutLocal();
210  InOut[5] = point->GetZOutLocal();
211 
212  // single straw tube simulation -----------------------
213  PndSttSingleStraw stt;
214 
215  // setting the single straw tube simulation constants
216  // 3 options currently available:
217  // TConst(tube radius (cm), gas pressure (bar), Ar%, CO2%)
218  // stt.TConst(0.4, 1, 0.9, 0.1);
219  // stt.TConst(0.5, 1, 0.9, 0.1); // 1 bar
220  // stt.TConst(0.5, 2, 0.8, 0.2); // 2 bar
221  stt.TConst(0.5, 2, 0.9, 0.1); // 2 bar
222 
223  // wire positioning
224  stt.PutWireXYZ(0., 0., -75., 0., 0., 75.);
225 
226  // get particle momentum
227  TVector3 momentum(point->GetPxOut(),point->GetPyOut(),point->GetPzOut()); // GeV/c
228 
229  Double_t GeV=1.;
230  // position in cm (already in cm); momentum in GeV (already in GeV); mass in GeV (already in GeV)
231 
232  // drift time calculation
233 
234  Double_t pulset =-1;
235  //pulset = stt.PartToTime(point->GetMass()/GeV, momentum.Mag()/GeV, InOut);
236 
237  // constant initialization
238  stt.TInit(point->GetMass()/GeV, momentum.Mag()/GeV, InOut);
239 
240  // true radius (cm)
241  Double_t true_rad = stt.TrueDist(InOut);
242 
243  // simulated radius (cm)
244  //Double_t radius = stt.TimnsToDiscm(pulset);
245  //if(radius < 0.) radius = 0.; // CHECK
246  //if(radius <0. ||radius==0.) radius =-999;
247 
248  // fast simulation
249  Int_t flag = 2; // 0) standard curve, from simulation
250  // 1) Juelich exp curve from COSY-TOF (old) (2 bar, 80/20)
251  // 2) Juelich exp curve from COSY-TOF (Feb 2011) (1.25 bar, 80/20)
252  // 3) Juelich exp curve from prototype (Apr 2010)(2 bar, 90/10)
253 
254  Double_t radius= stt.FastRec(true_rad, flag);
255 
256  // dE calculation
257  // double depCharge = stt.PartToADC();
258  // dE calculation ------- check
259  // charge calculation
260  Double_t depcharge = stt.FastPartToADC(); // CHECK arbitrary units!
261  // dE/dx calculation postponed
262  //Double_t dedx = -999; //[R.K. 01/2017] unused variable?
263 
264  // error calculation according to the curve chosen by flag
265  Double_t closestDistanceError = GetError(radius, flag);
266 
267  //cout<<"radius "<<radius<<" error "<<closestDistanceError<<endl;
268  //closestDistanceError = 0.0150; //150 microns check this point!
269  //closestDistanceError =TMath::Sqrt(2.)*radius/TMath::Sqrt(12);
270  TVector3 position = tube->GetPosition(); // CHECK added
271 
272  pos.SetXYZ(position.X(), position.Y(), position.Z());
273 
274  // dpos.SetXYZ(innerStrawDiameter / 2., innerStrawDiameter / 2., GetLongitudinalResolution(position.Z()));
275  dpos.SetXYZ(1./TMath::Sqrt(12), 1./TMath::Sqrt(12), 150./TMath::Sqrt(12)); // CHECK will be changed in future
276 
277  // cout << "r: " << radius << " err: " << closestDistanceError << endl;
278  //cout<<" radius "<<radius<<endl;
279 
280 
281  AddHitInfo(0, 0, point->GetTrackID(), iPoint, 0, kFALSE);
282 
283  // create hit
284  if(fSeparate == kTRUE) {
285  if(tube->IsParallel()) AddHit(fSttParalHitArray, detID, tubeID, iPoint, pos, dpos, pulset, radius, closestDistanceError, depcharge);
286  else AddHit(fSttSkewHitArray, detID, tubeID, iPoint, pos, dpos, pulset, radius, closestDistanceError, depcharge);
287  }
288  else AddHit(detID, tubeID, iPoint, pos, dpos, pulset, radius, closestDistanceError, depcharge);
289 
290 
291  }// Loop over MCPoints
292 
293  if(fOverlap) {
294 
295  if(fSeparate == kTRUE) {
300  }
301  else {
304  // cout << "OVERLAP " << overlap << endl;
305  }
306  }
307 
308  // Event summary
309  // cout << "-I- PndSttHitProducerRealFast: " << nPoints << " SttPoints, "
310  // << nPoints << " Hits created." << endl;
311 }
312 // -------------------------------------------------------------------------
313 
315  TVector3 , TVector3 ) // localInPos ,localOutPos //[R.K.03/2017] unused variable(s)
316 {
317  //Double_t
318  //zPosInStrawFrame = (localOutPos.Z() - localInPos.Z()) / 2.; //[R.K. 01/2017] unused variable?
319 
320  // zposError = gRandom->Gaus(0., GetLongitudinalResolution(zPosInStrawFrame));
321  zposError = gRandom->Gaus(0., 3.); // per adesso (stesso che in Ideal:
322  // longitudinalResolution = 3.)
323 
324  zpos += zposError;
325 }
326 
327 
328 
329 // ----- Private method AddHit --------------------------------------------
330 PndSttHit* PndSttHitProducerRealFast::AddHit(Int_t detID, Int_t tubeID, Int_t iPoint, TVector3& pos, TVector3& dpos, Double_t p, Double_t rsim, Double_t closestDistanceError, Double_t depcharge) {
331  // see PndSttHit for hit description
332  TClonesArray& clref = *fHitArray;
333  Int_t size = clref.GetEntriesFast();
334 
335  PndSttHit *hitnew = new(clref[size]) PndSttHit(detID, tubeID, iPoint, pos, dpos, p, rsim, closestDistanceError, depcharge);
336  return hitnew;
337 
338 }
339 // ----
340 
341 // ----- Private method AddHit --------------------------------------------
342 PndSttHit* PndSttHitProducerRealFast::AddHit(TClonesArray *hitarray, Int_t detID, Int_t tubeID, Int_t iPoint, TVector3& pos, TVector3& dpos, Double_t p, Double_t rsim, Double_t closestDistanceError, Double_t depcharge) {
343  // see PndSttHit for hit description
344  TClonesArray& clref = *hitarray;
345  Int_t size = clref.GetEntriesFast();
346 
347  PndSttHit *hitnew = new(clref[size]) PndSttHit(detID, tubeID, iPoint, pos, dpos, p, rsim, closestDistanceError, depcharge);
348  return hitnew;
349 
350 }
351 // ----
352 
353 
354 
355 // ----- Private method AddHitInfo --------------------------------------------
356 PndSttHitInfo* PndSttHitProducerRealFast::AddHitInfo(Int_t fileNumber, Int_t eventNumber, Int_t trackID, Int_t pointID, Int_t nMerged, Bool_t isFake){
357  // see PndSttHitInfo for hit description
358  TClonesArray& clref = *fHitInfoArray;
359  Int_t size = clref.GetEntriesFast();
360  return new(clref[size]) PndSttHitInfo(fileNumber, eventNumber, trackID, pointID, nMerged, isFake);
361 }
362 // -------------------------------------------------------------------------
363 
364 // --------- Get Error on radius -------------------------------------------
366 
367  Double_t resmic=-1;
368 
369  // TrueDcm in cm
370 
371  // simulation res curve used
372  if (rescurve==0) {
373  // if(TrueDcm < 0.48){
374  resmic = +1.06966e+02
375  -4.03073e+03 *TrueDcm
376  +1.60851e+05 *pow(TrueDcm,2)
377  -2.87722e+06 *pow(TrueDcm,3)
378  +2.67581e+07 *pow(TrueDcm,4)
379  -1.43397e+08 *pow(TrueDcm,5)
380  +4.61046e+08 *pow(TrueDcm,6)
381  -8.79170e+08 *pow(TrueDcm,7)
382  +9.17095e+08 *pow(TrueDcm,8)
383  -4.03253e+08 *pow(TrueDcm,9);
384  // }
385  // else resmic=30.;
386  }
387 
388  // Juelich exp curve from COSY-TOF (old) used
389  else if (rescurve==1) {
390  // if (TrueDcm < 0.48) {
391  resmic = +1.48048e+02
392  -3.35951e+02*TrueDcm
393  -1.87575e+03*pow(TrueDcm,2)
394  +1.92910e+04*pow(TrueDcm,3)
395  -6.90036e+04*pow(TrueDcm,4)
396  +1.07960e+05*pow(TrueDcm,5)
397  -5.90064e+04*pow(TrueDcm,6);
398  // }
399  // else resmic=65.;
400  }
401 
402  // Juelich exp curve from COSY-TOF (Feb 2011) used
403  else if (rescurve==2) {
404  // data from COSY-TOF (Feb 2011)
405  // the parametrization comes from mm vs mm:
406  // => TrueDcm must be in mm
407  TrueDcm *= 10.; // cm -> mm
408  // and resmic will be given in mm ...
409 
410  // old parametriz
411  // resmic = +0.02152
412  // +0.6764*TrueDcm
413  // -1.008*pow(TrueDcm,2)
414  // +0.7421*pow(TrueDcm,3)
415  // -0.3036*pow(TrueDcm,4)
416  // +0.06955*pow(TrueDcm,5)
417  // -0.008327*pow(TrueDcm,6)
418  // +0.0004049*pow(TrueDcm,7);
419 
420  // pol5 parametriz
421  resmic = 0.188119
422  + 0.00211993 * TrueDcm
423  + 0.00336004 * pow(TrueDcm, 2)
424  - 0.0103979 * pow(TrueDcm, 3)
425  + 0.0033461 * pow(TrueDcm, 4)
426  -0.000315764 * pow(TrueDcm, 5);
427 
428  // convert resmic to micron and TrueDcm to cm
429  resmic *= 1000.;
430  TrueDcm *= 0.1;
431  }
432 
433  // Juelich exp curve from prototype (Apr 2010) used
434  else if (rescurve==3) {
435  // TrueDcm needed in mm --> error in mm
436  resmic = 4.521331e-01
437  -2.087216e-01 *10.*TrueDcm
438  +4.911102e-02 *pow(10.*TrueDcm,2)
439  -3.934728e-03 *pow(10.*TrueDcm,3);
440  resmic = resmic*1000.; // error in micron
441  }
442 
443  // resmic in micron
444  return resmic*0.0001; // --> resmic in cm
445 }
446 // -------------------------------------------------------------------------
447 
448 
TVector3 pos
Double_t p
Definition: anasim.C:58
int fVerbose
Definition: poormantracks.C:24
Double_t GetYOutLocal() const
Definition: PndSttPoint.h:47
Int_t GetTubeID()
Definition: PndSttPoint.h:77
void PutWireXYZ(Double_t w1, Double_t w2, Double_t w3, Double_t w4, Double_t w5, Double_t w6)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double_t GetZInLocal() const
Definition: PndSttPoint.h:51
Double_t GetXInLocal() const
Definition: PndSttPoint.h:49
void SetPersistency(Bool_t val=kTRUE)
Double_t TrueDist(Double_t Point[])
Double_t GetPzOut() const
Definition: PndSttPoint.h:60
PndSttTube * GetTube(int tubeId)
Definition: PndSttTubeMap.h:22
TGeoManager * gGeoManager
Int_t GetGeometryType()
Definition: PndGeoSttPar.h:28
void FoldZPosWithResolution(Double_t &zpos, Double_t &zposError, TVector3 localInPos, TVector3 localOutPos)
Double_t GetPxOut() const
Definition: PndSttPoint.h:58
Double_t GetError(Double_t, Int_t)
Double_t GetYInLocal() const
Definition: PndSttPoint.h:50
Double_t GetZOutLocal() const
Definition: PndSttPoint.h:48
Double_t GetXOutLocal() const
Definition: PndSttPoint.h:46
static PndSttTubeMap * Instance()
virtual void Exec(Option_t *opt)
Double_t
const Double_t zpos
TVector3 GetPosition()
Definition: PndSttTube.cxx:87
Bool_t OverlapSimultaneousSignals(TClonesArray *OverlapHitArray)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TClonesArray * FillTubeArray()
PndSttHitInfo * AddHitInfo(Int_t fileNumber, Int_t eventNumber, Int_t trackID, Int_t pointID, Int_t nMerged, Bool_t isFake)
Double_t GetMass() const
Definition: PndSttPoint.h:62
void TInit(Double_t Mass, Double_t Momentum, Double_t InOut[])
Double_t GetPyOut() const
Definition: PndSttPoint.h:59
Double_t FastRec(Double_t TrueDcm, Int_t Flag)
ClassImp(PndAnaContFact)
void TConst(Double_t Radius, Double_t pSTP, Double_t ArP, Double_t CO2P)
PndSttHit * AddHit(Int_t detID, Int_t tubeID, Int_t iPoint, TVector3 &pos, TVector3 &dpos, Double_t p, Double_t rsim, Double_t closestDistanceError, Double_t depcharge)
bool IsParallel()
Definition: PndSttTube.h:66
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72