FairRoot/PandaRoot
PndGemIdealHitProducer.cxx
Go to the documentation of this file.
1 // PndGemIdealHitProducer
3 // Filler of PndGemHit
5 
15 // Includes from GEM
16 #include "PndGemDigitize.h"
17 
18 // Includes from base
19 #include "FairRootManager.h"
20 #include "FairRunAna.h"
21 #include "FairRuntimeDb.h"
22 
23 // Includes from ROOT
24 #include "TClonesArray.h"
25 #include "TObjArray.h"
26 #include "TMath.h"
27 #include "TGeoManager.h"
28 #include "TGeoNode.h"
29 #include "TRandom.h"
30 
31 #include "PndDetectorList.h"
32 #include "PndGemIdealHitProducer.h"
33 
34 #include "PndGemMCPoint.h"
35 #include "PndGemHit.h"
36 #include "PndGemMCPoint.h"
37 #include "PndGemDigiPar.h"
38 #include "PndGemSensor.h"
39 #include "PndGemDigi.h"
40 
41 #include <iomanip>
42 
43 using std::cout;
44 using std::endl;
45 using std::flush;
46 using std::setw;
47 using std::setprecision;
48 
49 // ----- Default constructor -------------------------------------------
51  FairTask("Ideal GEM hit Producer") {
52  fDigiPar = NULL;
53 
54  fTNofEvents = 0;
55  fTNofPoints = 0;
56  fTNofHits = 0;
57 }
58 
59 // ----- Constructor ---------------------------------------------------
61  : FairTask(name, iVerbose) {
62  fDigiPar = NULL;
63 
64  fTNofEvents = 0;
65  fTNofPoints = 0;
66  fTNofHits = 0;
67 }
68 
69 
70 // ----- Destructor ----------------------------------------------------
72  if(fHitArray){
73  fHitArray->Delete();
74  delete fHitArray;
75  }
76  if ( fDigiPar) delete fDigiPar;
77 }
78 
79 // ----- Private method SetParContainers -------------------------------
81 
82  // Get run and runtime database
83  FairRunAna* run = FairRunAna::Instance();
84  if ( ! run ) Fatal("SetParContainers", "No analysis run");
85 
86  FairRuntimeDb* db = run->GetRuntimeDb();
87  if ( ! db ) Fatal("SetParContainers", "No runtime database");
88 
89  // Get GEM digitisation parameter container
90  fDigiPar = (PndGemDigiPar*)(db->getContainer("PndGemDetectors"));
91 
92 }
93 // -------------------------------------------------------------------------
94 
95 
96 // ----- Public method Init --------------------------------------------
98 
99  std::cout << " INITIALIZATION OF Ideal Gem Hit Producer***************" << std::endl;
100 
101  // Get RootManager
102  FairRootManager* ioman = FairRootManager::Instance();
103  if( !ioman ) {
104  std::cout << "-E- PndGemIdealHitProducer::Init: "
105  << "RootManager not instantiated!" << std::endl;
106  return kFATAL;
107  }
108 
109  // Get input array
110  fPointArray = (TClonesArray*) ioman->GetObject("GEMPoint");
111  if( !fPointArray ) {
112  std::cout << "-W- PndGemIdealHitProducer::Init: "
113  << "Array of GEMPoints not found!" << std::endl;
114  return kERROR;
115  }
116 
117  // Create and register output array
118  fHitArray = new TClonesArray("PndGemHit");
119 
120  ioman->Register("GEMHit","GEM ideal hit",fHitArray,kTRUE);
121 
122  std::cout << "-I- PndGemIdealHitProducer: Intialization successfull" << std::endl;
123  return kSUCCESS;
124 
125 }
126 
127 // ----- Public method Exec --------------------------------------------
129 
130  // Reset output array
131  if( !fHitArray ) Fatal("Exec", "No hit array");
132 
133  fTNofEvents++;
134 
136 
137  Int_t nofHits = 0;
138  fHitArray->Delete();
139  Double_t dr, dp;
140  Double_t radius, innerR;
141 
142  for ( Int_t iPoint = 0 ; iPoint < fPointArray->GetEntriesFast() ; iPoint++ ) {
143  PndGemMCPoint* currentPndGemMCPoint = (PndGemMCPoint*)fPointArray->At(iPoint);
144 
145  Double_t posIn[3] = {currentPndGemMCPoint->GetX(),
146  currentPndGemMCPoint->GetY(),
147  currentPndGemMCPoint->GetZ()};
148 
149  Int_t sensorId = currentPndGemMCPoint->GetSensorId();
150 
151  TString nodeName = fDigiPar->GetNodeName(sensorId);
152 
153  gGeoManager->cd(nodeName.Data());
154  TGeoNode* curNode = gGeoManager->GetCurrentNode();
155 
156  sensor = (PndGemSensor*)fDigiPar->GetSensor(sensorId);
157 
158  fTNofPoints++;
159 
160  Double_t locPosIn[4];
161 
162  curNode->MasterToLocal(posIn,locPosIn);
163 
164  radius = TMath::Sqrt(locPosIn[0]*locPosIn[0]+locPosIn[1]*locPosIn[1]);
165  innerR = sensor->GetInnerRadius();
166  if ( sensor->GetStripAngle(0) == 0. && sensor->GetStripAngle(1) == 90. ) {
167  dp = sensor->GetPitch(0)*radius/innerR/TMath::Sqrt(12.);
168  dr = sensor->GetPitch(1)/TMath::Sqrt(12.);
169  }
170 
171  if ( sensor->GetStripAngle(0) == -sensor->GetStripAngle(1) ) {
172  Double_t pitch = ( sensor->GetPitch(0)+sensor->GetPitch(1) ) / 2.;
173  dp = pitch*radius/innerR/TMath::Sqrt(12.);
174  Double_t cosAng = TMath::Cos(TMath::DegToRad()*sensor->GetStripAngle(0));
175  Double_t xh = - innerR*cosAng + TMath::Sqrt(innerR*innerR*cosAng*cosAng-innerR*innerR+radius*radius);
176  Double_t backAng = TMath::ACos((radius*radius+xh*xh-innerR*innerR)/(2.*radius*xh));
177  dr = dp / TMath::Tan(backAng);
178  }
179 
180  Double_t phiAValue = TMath::ATan(locPosIn[0]/locPosIn[1]);
181  if ( locPosIn[1] < 0 ) phiAValue += TMath::Pi();
182  else if ( locPosIn[0] < 0 ) phiAValue += 2.*TMath::Pi();
183 
184  Double_t rSmear, pSmear;
185 
186  gRandom->Rannor(rSmear,pSmear);
187  rSmear = radius + rSmear*dr;
188  pSmear = 0. + pSmear*dp;
189 
190  if ( rSmear < innerR || rSmear > sensor->GetOuterRadius() ) rSmear = radius;
191 
192  locPosIn[0] = rSmear*TMath::Sin(phiAValue) + pSmear*TMath::Cos(phiAValue);
193  locPosIn[1] = rSmear*TMath::Cos(phiAValue) - pSmear*TMath::Sin(phiAValue);
194 
195  TVector3 pos(locPosIn[0],locPosIn[1],sensor->GetZ0());
196 
197  Double_t sigma = dp;
198  if ( dr > sigma ) sigma = dr;
199  TVector3 dpos(sigma, sigma, sensor->GetD());
200 
201  new ((*fHitArray)[nofHits++]) PndGemHit(kGemHit,
202  pos, dpos,
203  -1, -1, dr, dp, iPoint);
204  fTNofHits++;
205  } // end of loop over Points
206 }
207 
208 // ----- Private method Finish -----------------------------------------
210  if ( fHitArray ) fHitArray->Delete();
211 
212  cout << "-------------------- " << fName.Data() << " : Summary ---------------" << endl;
213  cout << " Events: " << setw(10) << fTNofEvents << endl;
214  cout << " Points: " << setw(10) << fTNofPoints << " ( " << (Double_t)fTNofPoints/((Double_t)fTNofEvents) << " per event )" << endl;
215  cout << " Hits: " << setw(10) << fTNofHits << " ( " << (Double_t)fTNofHits /((Double_t)fTNofEvents) << " per event )" << endl;
216  cout << " --> ( " << (Double_t)fTNofHits /((Double_t)fTNofEvents)/((Double_t)fDigiPar->GetNSensors()) << " per sensor )" << endl;
217  cout << " --> ( " << (Double_t)fTNofHits /((Double_t)fTNofPoints ) << " per point )" << endl;
218  cout << "---------------------------------------------------------------------" << endl;
219 }
220 // -------------------------------------------------------------------------
221 
TVector3 pos
virtual void Exec(Option_t *opt)
Int_t run
Definition: autocutx.C:47
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double_t GetInnerRadius() const
Definition: PndGemSensor.h:102
static T Sin(const T &x)
Definition: PndCAMath.h:42
float Tan(float x)
Definition: PndCAMath.h:165
TGeoVolume * sensor
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
Digitization Parameter Class for GEM part.
Definition: PndGemDigiPar.h:31
TClonesArray * fHitArray
Output array of PndGemHits.
TGeoManager * gGeoManager
static T Cos(const T &x)
Definition: PndCAMath.h:43
Class for conversion points to hits.
PndGemSensor * GetSensor(Int_t stationNr, Int_t sensorNr)
Int_t GetSensorId() const
Definition: PndGemMCPoint.h:90
Double_t
TString GetNodeName(Int_t sensorId)
TClonesArray * fPointArray
Input array of PndGemMCPoints.
TString name
Int_t GetNSensors()
Definition: PndGemDigiPar.h:46
Double_t GetD() const
Definition: PndGemSensor.h:104
ClassImp(PndAnaContFact)
Int_t iVerbose
Double_t GetZ0() const
Definition: PndGemSensor.h:100
Double_t GetOuterRadius() const
Definition: PndGemSensor.h:103
Double_t GetPitch(Int_t index) const
Definition: PndGemSensor.h:106
Double_t Pi
Double_t GetStripAngle(Int_t index) const
Definition: PndGemSensor.h:105