FairRoot/PandaRoot
PndFtsHitProducerRealFull.cxx
Go to the documentation of this file.
1 // PndFtsHitProducerRealFull
3 //
4 // Class for digitalization for FTS
5 //
6 // authors: Pablo Genova - Pavia University
7 // Lia Lavezzi - Pavia University
8 //
9 // modified for FTS by Isabella Garzia
11 
13 
14 #include "PndFtsHit.h"
15 #include "PndFtsHitInfo.h"
16 #include "PndFtsPoint.h"
17 #include "PndFtsSingleStraw.h"
18 #include "PndFtsMapCreator.h"
19 #include "PndFtsTube.h"
20 
22 
23 #include "FairRootManager.h"
24 #include "FairRunAna.h"
25 #include "FairRuntimeDb.h"
26 #include "FairEventHeader.h"
27 
28 #include "TGeoManager.h"
29 #include "TVector3.h"
30 #include "TRandom.h"
31 #include "TClonesArray.h"
32 
33 #include <iostream>
34 
35 using std::cout;
36 using std::endl;
37 
38 // ----- Default constructor -------------------------------------------
40  PndPersistencyTask("Real FTS Hit Producer",0), fPointArray(0), //fHitArray(0),
41  fHitInfoArray(0), fFtsParameters(new PndGeoFtsPar()), fTimeOrderedDigi(kFALSE)
42 {
43  SetPersistency(kTRUE);
44 }
45 // -------------------------------------------------------------------------
46 
47 
48 
49 // ----- Destructor ----------------------------------------------------
51 // -------------------------------------------------------------------------
52 
53 
54 
55 // ----- Public method Init --------------------------------------------
57 
58  // Get RootManager
59  FairRootManager* ioman = FairRootManager::Instance();
60  if ( ! ioman ) {
61  cout << "-E- PndFtsHitProducerRealFull::Init: "
62  << "RootManager not instantiated!" << endl;
63  return kFATAL;
64  }
65 
66  // Get input array
67  fPointArray = dynamic_cast<TClonesArray*> (ioman->GetObject("FTSPoint"));
68  if ( ! fPointArray ) {
69  cout << "-W- PndFtsHitProducerRealFull::Init: "
70  << "No FTSPoint array!" << endl;
71  return kERROR;
72  }
73 
74  // Create and register output array
75 // fHitArray = new TClonesArray("PndFtsHit");
76 // ioman->Register("FTSHit","FTS",fHitArray, fPersistence);
77 
78  fDataBuffer = new PndFtsHitWriteoutBuffer("FTSHit", "FTS", GetPersistency());
79  fDataBuffer = (PndFtsHitWriteoutBuffer*)ioman->RegisterWriteoutBuffer("FTSHit", fDataBuffer);
80  fDataBuffer->ActivateBuffering(fTimeOrderedDigi);
81 
82  // Create and register output array
83  fHitInfoArray = new TClonesArray("PndFtsHitInfo");
84  ioman->Register("FTSHitInfo", "FTS", fHitInfoArray, kFALSE);
85 
86  // CHECK added
88  fTubeArray = mapper->FillTubeArray();
89 
90  cout << "-I- PndFtsHitProducerRealFull: Intialization successfull" << endl;
91 
92  return kSUCCESS;
93 
94 }
95 // -------------------------------------------------------------------------
96 
97 // CHECK added
99  FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
100  fFtsParameters = (PndGeoFtsPar*) rtdb->getContainer("PndGeoFtsPar");
101 }
102 
103 // ----- Public method Exec --------------------------------------------
105 
106  // Int_t evtn=0;
107  // PndFtsPoint *ptemp =(PndFtsPoint*) fPointArray->At(0);
108  // if(ptemp !=NULL) {
109  // evtn=ptemp->GetEventID();
110  // if(evtn%50==0)cout << "Event Number "<<evtn<<endl;
111  // }
112 
113  // Reset output array
114  //if ( ! fHitArray ) Fatal("Exec", "No HitArray");
115 
116  //fHitArray->Delete();
117  fHitInfoArray->Clear();
118 
119  Int_t detID = 0; // detectorID
120  TVector3 pos, dpos; // position and error vectors
121 
122  // Declare some variables
123  PndFtsPoint* point = NULL;
124 
125  // Loop over FtsPoints
126  Int_t nPoints = fPointArray->GetEntriesFast();
127  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
128  point = (PndFtsPoint*) fPointArray->At(iPoint);
129  if (point == NULL) continue;
130 
131  detID = point->GetDetectorID();
132 
133  // tubeID CHECK added
134  Int_t skew=0;
135  Int_t layerID = point->GetLayerID();
136  Int_t tubeID = point->GetTubeID();
137  Int_t chamberID = point->GetChamberID();
138  PndFtsTube *tube = (PndFtsTube*) fTubeArray->At(tubeID);
139 
140  //if skewed tube: skew==1
141  if(layerID>=3 && layerID<=6){skew=1;} //skewed tudes fts1
142  if(layerID>=11 && layerID<=14){skew=1;} //skewed tudes fts2
143  if(layerID>=19 && layerID<=22){skew=1;} //skewed tudes fts3
144  if(layerID>=27 && layerID<=30){skew=1;} //skewed tudes fts4
145  if(layerID>=35 && layerID<=38){skew=1;} //skewed tudes fts5
146  if(layerID>=43 && layerID<=46){skew=1;} //skewed tudes fts6
147 
148  double InOut[6];
149  memset(InOut, 0, sizeof(InOut));
150 
151  InOut[0] = point->GetXInLocal();
152  InOut[1] = point->GetYInLocal();
153  InOut[2] = point->GetZInLocal();
154  InOut[3] = point->GetXOutLocal();
155  InOut[4] = point->GetYOutLocal();
156  InOut[5] = point->GetZOutLocal();
157 
158  // single straw tube simulation -----------------------
159  PndFtsSingleStraw fts;
160 
161  //setting the single straw tube simulation constants
162  // 3 options currently available:
163  // TConst(tube radius (cm), gas pressure (bar), Ar%, CO2%)
164  // fts.TConst(0.4, 1, 0.9, 0.1);
165  // fts.TConst(0.5, 1, 0.9, 0.1);
166  fts.TConst(0.5, 2, 0.8, 0.2);
167 
168  // wire positioning
169  fts.PutWireXYZ(0., 0., -75., 0., 0., 75.);
170 
171  // get particle momentum
172  TVector3 momentum(point->GetPxOut(),point->GetPyOut(),point->GetPzOut()); // GeV/c
173 
174  Double_t GeV=1.;
175  // position in cm (already in cm); momentum in GeV (already in GeV); mass in GeV (already in GeV)
176 
177  // drift time calculation
178  Double_t pulset = fts.PartToTime(point->GetMass()/GeV, momentum.Mag()/GeV, InOut);
179 
180  // simulated radius (cm)
181  double radius = fts.TimnsToDiscm(pulset);
182  if(radius < 0.) radius = 0.; // CHECK
183 
184  // true radius (cm)
185  //double true_rad = fts.TrueDist(InOut); //[R.K. 03/2017] unused variable?
186 
187  // dE calculation
188  double depCharge = fts.PartToADC();
189 
190  // dE/dx calculation
191  //double dedx = -999; //[R.K. 01/2017] unused variable?
192 
193  // fts: detID, pos, dpos, index come from --------------
194  // fts (FairHit):
195  Double_t closestDistanceError = 0.0150; // per adesso (stessa che in Ideal:
196  // radialResolution = 0.0150)
197 
198  TVector3 position = tube->GetPosition();
199 
200  // ----------------
201  // TVector3 posInLocal(point->GetXInLocal(), point->GetYInLocal(), point->GetZInLocal());
202  // TVector3 posOutLocal(point->GetXOutLocal(), point->GetYOutLocal(), point->GetZOutLocal());
203  // Double_t zpos = position.Z() + ((posOutLocal.Z() + posInLocal.Z()) / 2.);
204  // Double_t zposError;
205  // FoldZPosWithResolution(zpos, zposError, posInLocal, posOutLocal);
206  // pos.SetXYZ(position.X(), position.Y(), zpos); // <--- stt2
207  // ----------------
208 
209  pos.SetXYZ(position.X(), position.Y(), position.Z()); // <--- stt1
210 
211  // dpos.SetXYZ(innerStrawDiameter / 2., innerStrawDiameter / 2., GetLongitudinalResolution(position.Z()));
212  dpos.SetXYZ(0.5, 0.5, 3.); // per adesso (stessi che in Ideal:
213  // innerStrawDiameter/2 = 0.5,
214  // longitudinalResolution = 3.)
215 
216 
217  // create hit
218  AddHit(detID, tubeID, chamberID, layerID, skew, iPoint, pos, dpos, pulset, radius, closestDistanceError, depCharge, point->GetTime());
219 
220  AddHitInfo(0, 0, point->GetTrackID(), iPoint, 0, kFALSE);
221 
222  }// Loop over MCPoints
223 
224  // Event summary
225  cout << "-I- PndFtsHitProducerRealFull: " << nPoints << " FtsPoints, "
226  << nPoints << " Hits created." << endl;
227 
228 }
229 // -------------------------------------------------------------------------
231  TVector3 , TVector3 ) // localInPos localOutPos //[R.K.03/2017] unused variable(s)
232 {
233  //Double_t
234  //zPosInStrawFrame = (localOutPos.Z() - localInPos.Z()) / 2.; //[R.K. 01/2017] unused variable?
235 
236  // zposError = gRandom->Gaus(0., GetLongitudinalResolution(zPosInStrawFrame));
237  zposError = gRandom->Gaus(0., 3.); // per adesso (stesso che in Ideal:
238  // longitudinalResolution = 3.)
239 
240  zpos += zposError;
241 }
242 
243 
244 
245 // ----- Private method AddHit --------------------------------------------
246 PndFtsHit* PndFtsHitProducerRealFull::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, Double_t timeOfFlight)
247 {
248  // see PndFtsHit for hit description
249 
250  Double_t EventTime = FairRootManager::Instance()->GetEventTime();
251 
252  PndFtsHit *hitnew = new PndFtsHit(detID, tubeID, chamberID, layerID, skew, iPoint, pos, dpos, p+EventTime+timeOfFlight, rsim, closestDistanceError, depcharge);
253  if (fTimeOrderedDigi){
254  hitnew->ResetLinks();
255  FairEventHeader* evtHeader = (FairEventHeader*)FairRootManager::Instance()->GetObject("EventHeader.");
256  hitnew->AddLink(FairLink(evtHeader->GetInputFileId(), evtHeader->GetMCEntryNumber(), "FTSPoint", iPoint));
257  hitnew->AddLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), "EventHeader.", -1));
258  }
259  fDataBuffer->FillNewData(hitnew, p+EventTime+timeOfFlight, timeOfFlight+EventTime);
260  return hitnew;
261 
262 }
263 // ----
264 
265 // ----- Private method AddHitInfo --------------------------------------------
266 PndFtsHitInfo* PndFtsHitProducerRealFull::AddHitInfo(Int_t fileNumber, Int_t eventNumber, Int_t trackID, Int_t pointID, Int_t nMerged, Bool_t isFake){
267  // see PndSttHitInfo for hit description
268  TClonesArray& clref = *fHitInfoArray;
269  Int_t size = clref.GetEntriesFast();
270  return new(clref[size]) PndFtsHitInfo(fileNumber, eventNumber, trackID, pointID, nMerged, isFake);
271 }
272 
273 
274 
275 
276 
277 
Double_t GetXOutLocal() const
Definition: PndFtsPoint.h:59
TVector3 pos
PndFtsHitWriteoutBuffer * fDataBuffer
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, Double_t timeOfFlight)
Int_t GetChamberID()
Definition: PndFtsPoint.h:89
Double_t GetPzOut() const
Definition: PndFtsPoint.h:54
Double_t GetZOutLocal() const
Definition: PndFtsPoint.h:61
Double_t GetPxOut() const
Definition: PndFtsPoint.h:52
void SetPersistency(Bool_t val=kTRUE)
Double_t GetYOutLocal() const
Definition: PndFtsPoint.h:60
virtual void Exec(Option_t *opt)
Double_t GetYInLocal() const
Definition: PndFtsPoint.h:63
Double_t p
Definition: anasim.C:58
Double_t TimnsToDiscm(Double_t time)
Double_t GetZInLocal() const
Definition: PndFtsPoint.h:64
double skew
void TConst(Double_t Radius, Double_t pSTP, Double_t ArP, Double_t CO2P)
Int_t GetTubeID()
Definition: PndFtsPoint.h:86
Double_t
const Double_t zpos
TClonesArray * point
Definition: anaLmdDigi.C:29
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TVector3 GetPosition() const
Definition: PndFtsTube.cxx:68
Double_t PartToTime(Double_t Mass, Double_t Momentum, Double_t InOut[])
void PutWireXYZ(Double_t w1, Double_t w2, Double_t w3, Double_t w4, Double_t w5, Double_t w6)
void FoldZPosWithResolution(Double_t &zpos, Double_t &zposError, TVector3 localInPos, TVector3 localOutPos)
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
PndFtsHitInfo * AddHitInfo(Int_t fileNumber, Int_t eventNumber, Int_t trackID, Int_t pointID, Int_t nMerged, Bool_t isFake)
Double_t GetMass() const
Definition: PndFtsPoint.h:70