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