FairRoot/PandaRoot
PndGemMatchHits.cxx
Go to the documentation of this file.
1 //* $Id: */
2 
3 // -------------------------------------------------------------------------
4 // ----- PndGemMatchHits source file -----
5 // ----- Created 12/02/2009 by R. Karabowicz -----
6 // -------------------------------------------------------------------------
7 
8 // Includes from GEM
9 #include "PndGemMatchHits.h"
10 
11 // Includes from base
12 #include "FairRootManager.h"
13 #include "FairRunAna.h"
14 #include "FairRuntimeDb.h"
15 
16 // Includes from ROOT
17 #include "TClonesArray.h"
18 #include "TObjArray.h"
19 #include "TMath.h"
20 #include "TGeoManager.h"
21 #include "TGeoNode.h"
22 
23 #include "PndGemHit.h"
24 #include "PndGemMCPoint.h"
25 #include "PndGemDigiPar.h"
26 #include "PndGemSensor.h"
27 
28 #include <iostream>
29 #include <iomanip>
30 #include <map>
31 
32 using std::cout;
33 using std::cerr;
34 using std::endl;
35 using std::pair;
36 using std::setw;
37 using std::left;
38 using std::right;
39 using std::fixed;
40 using std::setprecision;
41 using std::map;
42 
43 
44 
45 // ----- Default constructor ------------------------------------------
46 PndGemMatchHits::PndGemMatchHits() : FairTask("GEM MatchHits", 1) {
47  fDigiPar = NULL;
48  fPoints = NULL;
49  fHits = NULL;
50  Reset();
51 }
52 // -------------------------------------------------------------------------
53 
54 
55 
56 // ----- Standard constructor ------------------------------------------
58  : FairTask("GEM MatchHitsr", iVerbose) {
59  fDigiPar = NULL;
60  fPoints = NULL;
61  fHits = NULL;
62  Reset();
63 }
64 // -------------------------------------------------------------------------
65 
66 
67 
68 // ----- Constructor with name -----------------------------------------
70  : FairTask(name, iVerbose) {
71  fDigiPar = NULL;
72  fPoints = NULL;
73  fHits = NULL;
74  Reset();
75 }
76 // -------------------------------------------------------------------------
77 
78 
79 
80 // ----- Destructor ----------------------------------------------------
82  if ( fDigiPar) delete fDigiPar;
83  Reset();
84 }
85 // -------------------------------------------------------------------------
86 
87 // ----- Public method Exec --------------------------------------------
88 void PndGemMatchHits::Exec(Option_t*) {
89  Int_t nofPoints = fPoints->GetEntriesFast();
90  Int_t nofHits = fHits->GetEntriesFast();
91 
92  if ( fVerbose )
93  cout << "PndGemMatchHits::Exec() with " << nofPoints << " points and " << nofHits << " hits." << endl;
94 
95  Int_t nHits = 0;
96  Int_t nMatchedHits = 0;
97  Int_t nFakeHits = 0;
98  Int_t nMultiHits = 0;
99 
100  vector<Double_t> pointZ;
101  vector<Double_t> pointR;
102  vector<Double_t> pointP;
103  for ( Int_t iPoint = 0 ; iPoint < nofPoints ; iPoint++ ) {
104  PndGemMCPoint* currentPndGemMCPoint = (PndGemMCPoint*)fPoints->At(iPoint);
105 
106  Double_t pointX = currentPndGemMCPoint->GetX();
107  Double_t pointY = currentPndGemMCPoint->GetY();
108 
109  if ( fVerbose > 1 )
110  cout << " .... " << pointX << " " << pointY << " " << currentPndGemMCPoint->GetZ() << endl;
111 
112  Double_t phiAValue = TMath::ATan(pointX/pointY);
113  if ( pointY < 0 ) phiAValue += TMath::Pi();
114  else if ( pointX < 0 ) phiAValue += 2.*TMath::Pi();
115 
116  pointZ.push_back(currentPndGemMCPoint->GetZ());
117  pointR.push_back(TMath::Sqrt(pointX*pointX+pointY*pointY));
118  pointP.push_back(phiAValue);
119 
120  if ( fVerbose > 1 )
121  cout << "point " << iPoint << ", sensor Id = " << currentPndGemMCPoint->GetSensorId() << " (" << pointZ[pointZ.size()-1] << "," << pointR[pointR.size()-1] << "," << pointP[pointP.size()-1] << ")" << endl;
122  }
123 
124  for ( Int_t iHit = 0 ; iHit < nofHits ; iHit++ ) {
125  PndGemHit* currentPndGemHit = (PndGemHit*)fHits->At(iHit);
126 
127  Double_t hitX = currentPndGemHit->GetX();
128  Double_t hitY = currentPndGemHit->GetY();
129  Double_t hitZ = currentPndGemHit->GetZ();
130 
131  if ( fVerbose > 1 )
132  cout << " .... " << hitX << " " << hitY << " " << currentPndGemHit->GetZ() << endl;
133 
134  Double_t hitP = TMath::ATan(hitX/hitY);
135  if ( hitY < 0 ) hitP += TMath::Pi();
136  else if ( hitX < 0 ) hitP += 2.*TMath::Pi();
137  Double_t hitR = TMath::Sqrt(hitX*hitX+hitY*hitY);
138 
139  if ( fVerbose > 1 ) {
140  cout << "-------------------------------------------" << endl;
141  cout << "hit " << iHit << " (" << hitZ << "," << hitR << "," << hitP << ")" << endl;
142  }
143 
144  Int_t matchPoint = -1;
145  Double_t closestDistance = 1000.;
146  Bool_t multiHit = kFALSE;
147  for ( size_t iPoint = 0 ; iPoint < pointZ.size() ; iPoint++ ) {
148  // if ( fVerbose > 1 )
149  if ( TMath::Abs(pointZ[iPoint]-hitZ) > currentPndGemHit->GetDz() ) { /*cout << "FAILED Z" << endl;*/ continue; }
150  if ( TMath::Abs(pointR[iPoint]-hitR) > currentPndGemHit->GetDr()*TMath::Sqrt(3.) ) { /*cout << "FAILED R" << endl;*/ continue; }
151 
152  if ( hitP < 1.0 && pointP[iPoint] > 5.5 ) hitP += 2.*TMath::Pi();
153  if ( hitP > 5.5 && pointP[iPoint] < 1.0 ) hitP -= 2.*TMath::Pi();
154 
155  if ( TMath::Abs(TMath::Tan(pointP[iPoint]-hitP)) > currentPndGemHit->GetDp()*TMath::Sqrt(3.)/hitR ) { /*cout << "FAILED PHI" << endl;*/ continue; }
156  if ( fVerbose > 1 ) {
157  cout << "matched with " << " (" << pointZ[iPoint] << "," << pointR[iPoint] << "," << pointP[iPoint] << ") " << endl;
158  cout << "DP = " << currentPndGemHit->GetDp() << " after transf. = " << currentPndGemHit->GetDp()*TMath::Sqrt(3.)/hitR << " while p_p = " << pointP[iPoint] << " " << " h_p = " << hitP << endl;
159  cout << "PASSED WITH POINT " << iPoint << endl;
160  }
161  Double_t distance = TMath::Sqrt((pointR[iPoint]-hitR)*(pointR[iPoint]-hitR)/currentPndGemHit->GetDr()/currentPndGemHit->GetDr()+
162  (pointP[iPoint]-hitP)*(pointP[iPoint]-hitP)/currentPndGemHit->GetDp()/currentPndGemHit->GetDp());
163  if ( matchPoint != -1 ) multiHit = kTRUE;
164  if ( distance > closestDistance ) continue;
165  closestDistance = distance;
166  matchPoint = iPoint;
167  }
168  currentPndGemHit->SetRefIndex(matchPoint);
169  if ( matchPoint != -1 ) {
170  PndGemMCPoint* matchp = (PndGemMCPoint*)fPoints->At(matchPoint);
171  currentPndGemHit->SetBotIndex(matchp->GetTrackID());
172  }
173  else {
174  currentPndGemHit->SetBotIndex(-1);
175  }
176 
177  nHits++;
178  if ( matchPoint != -1 ) nMatchedHits++;
179  else nFakeHits++;
180  if ( multiHit ) nMultiHits++;
181  }
182 
183  fNHits += nHits;
184  fNMatchedHits += nMatchedHits;
185  fNFakeHits += nFakeHits;
186  fNMultiHits += nMultiHits;
187 
188  if ( fVerbose ) {
189  cout << "************PndGemMatchHits**************" << endl;
190  cout << " Number of all hits " << nHits << endl;
191  cout << " Number of matched hits " << nMatchedHits << " -> " << 100.*(Double_t)nMatchedHits/(Double_t)nHits << endl;
192  cout << " Number of fake hits " << nFakeHits << " -> " << 100.*(Double_t)nFakeHits/(Double_t)nHits << endl;
193  cout << " Number of multi hits " << nMultiHits << " -> " << 100.*(Double_t)nMultiHits/(Double_t)nHits << endl;
194  cout << "*****************************************" << endl;
195  }
196 
197 }
198 // -------------------------------------------------------------------------
199 
200 
201 
202 // ----- Private method SetParContainers -------------------------------
204 
205  // Get run and runtime database
206  FairRunAna* run = FairRunAna::Instance();
207  if ( ! run ) Fatal("SetParContainers", "No analysis run");
208 
209  FairRuntimeDb* db = run->GetRuntimeDb();
210  if ( ! db ) Fatal("SetParContainers", "No runtime database");
211 
212  // Get GEM digitisation parameter container
213  fDigiPar = (PndGemDigiPar*)(db->getContainer("PndGemDetectors"));
214 
215 }
216 // -------------------------------------------------------------------------
217 
218 
219 
220 // ----- Private method Init -------------------------------------------
221 InitStatus PndGemMatchHits::Init() {
222 
223  // Get input array
224  FairRootManager* ioman = FairRootManager::Instance();
225  if ( ! ioman ) Fatal("Init", "No FairRootManager");
226  fPoints = (TClonesArray*) ioman->GetObject("GEMPoint");
227 
228  fHits = (TClonesArray*) ioman->GetObject("GEMHit");
229 
230  return kSUCCESS;
231 
232 }
233 // -------------------------------------------------------------------------
234 
235 
236 
237 // ----- Private method ReInit -----------------------------------------
239 
240  return kSUCCESS;
241 
242 }
243 // -------------------------------------------------------------------------
244 
245 
246 
247 // ----- Private method Reset ------------------------------------------
250 }
251 // -------------------------------------------------------------------------
252 
253 // ----- Private method Finish -----------------------------------------
255  cout << "************PndGemMatchHits summary**************" << endl;
256  cout << " Number of all hits " << fNHits << endl;
257  cout << " Number of matched hits " << fNMatchedHits << " -> " << 100.*(Double_t)fNMatchedHits/(Double_t)fNHits << endl;
258  cout << " Number of fake hits " << fNFakeHits << " -> " << 100.*(Double_t)fNFakeHits/(Double_t)fNHits << endl;
259  cout << " Number of multi hits " << fNMultiHits << " -> " << 100.*(Double_t)fNMultiHits/(Double_t)fNHits << endl;
260  cout << "*************************************************" << endl;
261 }
262 // -------------------------------------------------------------------------
263 
264 
266 
int fVerbose
Definition: poormantracks.C:24
virtual InitStatus ReInit()
Int_t run
Definition: autocutx.C:47
PndTransMap * map
Definition: sim_emc_apd.C:99
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
float Tan(float x)
Definition: PndCAMath.h:165
Digitization Parameter Class for GEM part.
Definition: PndGemDigiPar.h:31
virtual InitStatus Init()
PndGemDigiPar * fDigiPar
void SetBotIndex(Int_t id)
Definition: PndGemHit.h:65
static T Abs(const T &x)
Definition: PndCAMath.h:39
Int_t GetSensorId() const
Definition: PndGemMCPoint.h:90
int nHits
Definition: RiemannTest.C:16
Double_t
Double_t GetDp() const
Definition: PndGemHit.h:76
TString name
virtual void Finish()
ClassImp(PndAnaContFact)
Int_t iVerbose
virtual void Exec(Option_t *opt)
virtual void SetParContainers()
Double_t GetDr() const
Definition: PndGemHit.h:75
Double_t Pi
TClonesArray * fHits
TClonesArray * fPoints
virtual ~PndGemMatchHits()