FairRoot/PandaRoot
PndFtsHitProducerRealFast.cxx
Go to the documentation of this file.
1 // PndFtsHitProducerRealFast
3 //
4 // Class for digitalization for FTS
5 //
6 // authors: Pablo Genova - Pavia University
7 // Lia Lavezzi - Pavia University
8 //
9 // modified for forward tracking by Isabella Garzia - Ferrara Univertsity
11 
13 
14 #include "PndFtsHit.h"
15 #include "PndFtsHitInfo.h"
16 #include "PndFtsPoint.h"
17 #include "PndFtsSingleStraw.h"
18 #include "PndGeoFtsPar.h"
19 #include "PndFtsTube.h"
20 #include "PndFtsMapCreator.h"
21 #include "PndFtsSignalOverlap.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 FTS Hit Producer",0), fPointArray(0), fHitArray(0),
45  fVolumeArray(0), fHitInfoArray(0), fevtn(0), fFtsParameters(new PndGeoFtsPar()), fOverlap(kFALSE)
46 {
47  SetPersistency(kTRUE);
48 }
49 // -------------------------------------------------------------------------
50 
51 
52 
53 // ----- Destructor ----------------------------------------------------
55 // -------------------------------------------------------------------------
56 
57 
58 
59 // ----- Public method Init --------------------------------------------
61  fevtn=0;
62 
63  std::cout<<"#########################################################"<<std::endl;
64  std::cout<<"PndFtsHitProducerRealFast: Init()#######"<<std::endl;
65  std::cout<<"#########################################################"<<std::endl;
66 
67  // Get RootManager
68  FairRootManager* ioman = FairRootManager::Instance();
69  if ( ! ioman ) {
70  cout << "-E- PndFtsHitProducerRealFast-wintz::Init: "
71  << "RootManager not instantiated!" << endl;
72  return kFATAL;
73  }
74 
75  // Get input array
76  fPointArray = (TClonesArray*) ioman->GetObject("FTSPoint");
77  if ( ! fPointArray ) {
78  cout << "-W- PndFtsHitProducerRealFast::Init: "
79  << "No FTSPoint array!" << endl;
80  return kERROR;
81  }
82 
83  // Create and register output array: without fOverlap
84  //fHitArray = new TClonesArray("PndFtsHit");
85  //ioman->Register("FTSHit","FTS",fHitArray, fPersistence);
86 
88  if(!fOverlap){
89  fHitArray = new TClonesArray("PndFtsHit");
90  ioman->Register("FTSHit","FTS",fHitArray, GetPersistency());
91  }
92  else{
93  //if overlap on, save the overlapped hits in regular
94  //output TCA (FTSHit) and the "original" hits (non overlapped)
95  //in another TCA (FTSOriginalHit)
96  fOverlapHitArray = new TClonesArray("PndFtsHit");
97  ioman->Register("FTSHit","FTS",fOverlapHitArray, GetPersistency());
98  fHitArray = new TClonesArray("PndFtsHit");
99  ioman->Register("FTSOriginalHit","FTS",fHitArray, GetPersistency());
100  }
101 
102 
103 
104  // Create and register output array
105  fHitInfoArray = new TClonesArray("PndFtsHitInfo");
106  ioman->Register("FTSHitInfo", "FTS", fHitInfoArray, kFALSE);
107 
108  fVolumeArray = gGeoManager->GetListOfVolumes();
109 
110  cout << "-I- PndFTSHitProducerRealFast: INITIALIZATION SUCCESSFUL" << endl;
111 
112 
113  //CHECK added
115  fTubeArray = mapper->FillTubeArray();
116 
117  return kSUCCESS;
118 
119 }
120 // -------------------------------------------------------------------------
121 
123 
124  FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
125  fFtsParameters = (PndGeoFtsPar*) rtdb->getContainer("PndGeoFtsPar");
126 }
127 
128 
129 // ----- Public method Exec --------------------------------------------
131 
132  //std::cout<<"PndFtsHitProducer Exec ########"<<std::endl;
133  if(fVerbose && fevtn%50==0) cout << "Event Number "<<fevtn<<endl;
134  else if(fVerbose >= 3) cout << "Event Number "<<fevtn<<endl;
135 
136  fevtn++;
137 
138  // Reset output array
139  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
140 
141  fHitArray->Delete();
142  fHitInfoArray->Clear();
143  if(fOverlap) fOverlapHitArray->Delete();
144 
145  Int_t detID = 0; // detectorID
146  TVector3 pos, dpos; // position and error vectors
147 
148  // Declare some variables
149  PndFtsPoint* point = NULL;
150 
151  // Loop over FtsPoints
152  Int_t nPoints = fPointArray->GetEntriesFast();
153 
154  // cout << "------------ " << nPoints << endl;
155 
156  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
157  point = (PndFtsPoint*) fPointArray->At(iPoint);
158  if (point == NULL) continue;
159 
160  detID = point->GetDetectorID();
161 
162  // tubeID CHECK added
163  Int_t skew = 0;
164  Int_t tubeID = point->GetTubeID();
165  Int_t chamberID=point->GetChamberID();
166  Int_t layerID=point->GetLayerID();
167  PndFtsTube *tube = (PndFtsTube*) fTubeArray->At(tubeID);
168 
169  //if skewed tube: skew==1
170  if(layerID>=3 && layerID<=6){skew=1;} //skewed tudes fts1
171  if(layerID>=11 && layerID<=14){skew=1;} //skewed tudes fts2
172  if(layerID>=19 && layerID<=22){skew=1;} //skewed tudes fts3
173  if(layerID>=27 && layerID<=30){skew=1;} //skewed tudes fts4
174  if(layerID>=35 && layerID<=38){skew=1;} //skewed tudes fts5
175  if(layerID>=43 && layerID<=46){skew=1;} //skewed tudes fts6
176 
177 
178  double InOut[6];
179  memset(InOut, 0, sizeof(InOut));
180 
181  InOut[0] = point->GetXInLocal();
182  InOut[1] = point->GetYInLocal();
183  InOut[2] = point->GetZInLocal();
184  InOut[3] = point->GetXOutLocal();
185  InOut[4] = point->GetYOutLocal();
186  InOut[5] = point->GetZOutLocal();
187 
188  // single straw tube simulation -----------------------
189  PndFtsSingleStraw fts;
190 
191  //setting the single straw tube simulation constants
192  // 3 options currently available:
193  // TConst(tube radius (cm), gas pressure (bar), Ar%, CO2%)
194  // fts.TConst(0.4, 1, 0.9, 0.1);
195  //fts.TConst(0.5, 1, 0.9, 0.1);//1 bar
196  fts.TConst(0.5, 2, 0.8, 0.2); //2 bar
197 
198  // wire positioning->controllare bene
199  fts.PutWireXYZ(0., 0., -75., 0., 0., 75.);
200 
201  // get particle momentum
202  TVector3 momentum(point->GetPxOut(),point->GetPyOut(),point->GetPzOut()); // GeV/c
203 
204  Double_t GeV=1.;
205  // position in cm (already in cm); momentum in GeV (already in GeV); mass in GeV (already in GeV)
206 
207  // drift time calculation
208 
209  Double_t pulset =-1;
210  //pulset = fts.PartToTime(point->GetMass()/GeV, momentum.Mag()/GeV, InOut);
211 
212  // constant initialization
213  fts.TInit(point->GetMass()/GeV, momentum.Mag()/GeV, InOut);
214 
215  // true radius (cm)
216  Double_t true_rad = fts.TrueDist(InOut);
217 
218  // simulated radius (cm)
219  //Double_t radius = fts.TimnsToDiscm(pulset);
220  //if(radius < 0.) radius = 0.; // CHECK
221  //if(radius <0. ||radius==0.) radius =-999;
222 
223  // fast simulation
224  Double_t radius= fts.FastRec(true_rad,1) ; //,0) standard curve ,1) Juelich exp curve
225  //Juelich is at 2 bar pressure
226  // dE calculation
227  // double depCharge = fts.PartToADC();
228 
229  // dE calculation ------- check
230  // charge calculation
231  Double_t depcharge = fts.FastPartToADC(); // CHECK arbitrary units!
232  // dE/dx calculation postponed
233  //Double_t dedx = -999; //[R.K. 01/2017] unused variable?
234 
235 
236  Double_t closestDistanceError = GetError(radius);//calculates the error according to Juelich experimental curves
237  //cout<<"radius "<<radius<<" error "<<closestDistanceError<<endl;
238  //closestDistanceError = 0.0150; //150 microns check this point!
239  //closestDistanceError =TMath::Sqrt(2.)*radius/TMath::Sqrt(12);
240 
241  //TVector3 position(point->GetX(), point->GetY(), point->GetZ()); // use this for hits having same coordinates as MC points
242  TVector3 position = tube->GetPosition(); // use this for realistic hit production
243  pos.SetXYZ(position.X(), position.Y(), position.Z()); // <--- stt1
244 
245  // dpos.SetXYZ(innerStrawDiameter / 2., innerStrawDiameter / 2., GetLongitudinalResolution(position.Z()));
246  dpos.SetXYZ(0.5, 0.5, 3.); // per adesso (stessi che in Ideal:
247  // innerStrawDiameter/2 = 0.5,
248  // longitudinalResolution = 3.)
249 
250  // create hit
251  Double_t eventTime = FairRootManager::Instance()->GetEventTime();
252  Double_t flightTime = point->GetTime();
253  AddHit(detID, tubeID, chamberID, layerID, skew, iPoint, pos, dpos, pulset+flightTime+eventTime, radius, closestDistanceError, depcharge);
254  AddHitInfo(0, 0, point->GetTrackID(), iPoint, 0, kFALSE);
255 
256  }// Loop over MCPoints
257 
258  if(fOverlap){
261 
262  }
263 
264  // Event summary
265  //cout << "-I- PndSttHitProducerRealFast: " << nPoints << " FtsPoints, "
266  //<< nPoints << " Hits created." << endl;
267 
268 }
269 // -------------------------------------------------------------------------
271  TVector3 , TVector3 ) // localInPos localOutPos //[R.K.03/2017] unused variable(s)
272 {
273 
274 
275  //Double_t
276  //zPosInStrawFrame = (localOutPos.Z() - localInPos.Z()) / 2.; //[R.K. 01/2017] unused variable?
277  //FIXME We have dummy Error calculation
278  // zposError = gRandom->Gaus(0., GetLongitudinalResolution(zPosInStrawFrame));
279  zposError = gRandom->Gaus(0., 3.); // per adesso (stesso che in Ideal:
280  // longitudinalResolution = 3.)
281 
282  zpos += zposError;
283 }
284 
285 
286 
287 // ----- Private method AddHit --------------------------------------------
288 PndFtsHit* PndFtsHitProducerRealFast::AddHit(Int_t detID, Int_t tubeID, Int_t chamberID, Int_t layerID, Int_t skew, Int_t iPoint, TVector3& pos, TVector3& dpos, Double_t p, Double_t rsim, Double_t closestDistanceError, Double_t depcharge) {
289 
290 
291  // see PndFtsHit for hit description
292  TClonesArray& clref = *fHitArray;
293  Int_t size = clref.GetEntriesFast();
294 
295  PndFtsHit *hitnew = new(clref[size]) PndFtsHit(detID, tubeID, chamberID, layerID, skew, iPoint, pos, dpos, p, rsim, closestDistanceError, depcharge);
296  return hitnew;
297 
298 }
299 // ----
300 
301 // ----- Private method AddHitInfo --------------------------------------------
302 PndFtsHitInfo* PndFtsHitProducerRealFast::AddHitInfo(Int_t fileNumber, Int_t eventNumber, Int_t trackID, Int_t pointID, Int_t nMerged, Bool_t isFake){
303  // see PndFtsHitInfo for hit description
304 
305 
306  TClonesArray& clref = *fHitInfoArray;
307  Int_t size = clref.GetEntriesFast();
308  return new(clref[size]) PndFtsHitInfo(fileNumber, eventNumber, trackID, pointID, nMerged, isFake);
309 }
310 
311 
313 
314 
315  // data from julich
316  Double_t resmic=-1;
317  if(TrueDcm < 0.48){
318  resmic = 20. +1.48048e+02
319  -3.35951e+02*TrueDcm
320  -1.87575e+03*pow(TrueDcm,2)
321  +1.92910e+04*pow(TrueDcm,3)
322  -6.90036e+04*pow(TrueDcm,4)
323  +1.07960e+05*pow(TrueDcm,5)
324  -5.90064e+04*pow(TrueDcm,6) ;
325  }
326  else resmic=65.;
327 
328  return resmic*0.0001;
329 }
330 
331 
Double_t GetXOutLocal() const
Definition: PndFtsPoint.h:59
TVector3 pos
Int_t GetChamberID()
Definition: PndFtsPoint.h:89
Double_t GetPzOut() const
Definition: PndFtsPoint.h:54
Double_t p
Definition: anasim.C:58
int fVerbose
Definition: poormantracks.C:24
Bool_t OverlapSimultaneousSignals(TClonesArray *OverlapHitArray)
virtual void Exec(Option_t *opt)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Double_t GetZOutLocal() const
Definition: PndFtsPoint.h:61
PndFtsHitInfo * AddHitInfo(Int_t fileNumber, Int_t eventNumber, Int_t trackID, Int_t pointID, Int_t nMerged, Bool_t isFake)
Double_t GetPxOut() const
Definition: PndFtsPoint.h:52
void SetPersistency(Bool_t val=kTRUE)
void TInit(Double_t Mass, Double_t Momentum, Double_t InOut[])
Double_t GetYOutLocal() const
Definition: PndFtsPoint.h:60
TGeoManager * gGeoManager
Double_t GetYInLocal() const
Definition: PndFtsPoint.h:63
Double_t GetZInLocal() const
Definition: PndFtsPoint.h:64
double skew
PndFtsHit * AddHit(Int_t detID, Int_t tubeID, Int_t chamberID, Int_t layerID, Int_t skew, Int_t iPoint, TVector3 &pos, TVector3 &dpos, Double_t p, Double_t rsim, Double_t closestDistanceError, Double_t depcharge)
void TConst(Double_t Radius, Double_t pSTP, Double_t ArP, Double_t CO2P)
Int_t GetTubeID()
Definition: PndFtsPoint.h:86
Double_t TrueDist(Double_t Point[])
void FoldZPosWithResolution(Double_t &zpos, Double_t &zposError, TVector3 localInPos, TVector3 localOutPos)
Double_t
const Double_t zpos
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TVector3 GetPosition() const
Definition: PndFtsTube.cxx:68
void PutWireXYZ(Double_t w1, Double_t w2, Double_t w3, Double_t w4, Double_t w5, Double_t w6)
Double_t FastRec(Double_t TrueDcm, Int_t Flag)
ClassImp(PndAnaContFact)
TClonesArray * FillTubeArray()
this function will be used in PndFtsHitProducesRealFast
Double_t GetPyOut() const
Definition: PndFtsPoint.h:53
Double_t GetXInLocal() const
Definition: PndFtsPoint.h:62
Int_t GetLayerID()
Definition: PndFtsPoint.h:90
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72
Double_t GetMass() const
Definition: PndFtsPoint.h:70