EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmRichTestHits.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmRichTestHits.cxx
1 
8 #include "CbmRichTestHits.h"
9 
10 #include "CbmGeoRichPar.h"
11 #include "CbmRichPoint.h"
12 #include "CbmRichHit.h"
13 
14 #include "FairTask.h"
15 #include "FairRootManager.h"
16 #include "CbmMCTrack.h"
17 #include "FairRunAna.h"
18 #include "FairRuntimeDb.h"
19 #include "FairBaseParSet.h"
20 #include "FairGeoVolume.h"
21 #include "FairGeoTransform.h"
22 #include "FairGeoVector.h"
23 #include "FairGeoMedium.h"
24 #include "FairGeoNode.h"
25 
26 #include "TClonesArray.h"
27 #include "TGraph.h"
28 #include "TVector3.h"
29 #include "TH2D.h"
30 #include "TH1D.h"
31 
32 #include <map>
33 #include <iostream>
34 
35 using std::cout;
36 using std::endl;
37 using std::map;
38 
40  FairTask("CbmRichTestHits"),
41  fRichHits(NULL),
42  fRichPoints(NULL),
43  fMcTracks(NULL),
44 
45  fNEvents(0),
46 
47  fh_Det1ev(NULL),
48  fh_Det1ev_zoom(NULL),
49  fh_Detall(NULL),
50  fh_Detall_zoom(NULL),
51  fh_n_vs_p(NULL),
52 
53  fh_Nhits(NULL),
54 
55  fh_Nall(NULL),
56  fh_Nel(NULL),
57  fh_Nelprim(NULL),
58  fh_Npi(NULL),
59  fh_Nk(NULL),
60  fh_Nhad(NULL),
61  fh_Nnoise(NULL),
62 
63  fSensNodes(NULL),
64  fPar(NULL),
65  fDetZ(0.)
66 {
67  fh_Det1ev = new TH2D("fh_Det1ev","points in detector plane (1 event)",170,-170,170,250,-250,250);
68  fh_Det1ev_zoom = new TH2D("fh_Det1ev_zoom","points in detector plane (1 event, zoom in)",100,10,60,100,60,110);
69  fh_Detall = new TH2D("fh_Detall","points in detector plane (all events)",170,-170,170,250,-250,250);
70  fh_Detall_zoom = new TH2D("fh_Detall_zoom","points in detector plane (all events, zoom in)",150,40,70,150,110,140);
71  fh_n_vs_p = new TH2D("fh_n_vs_p","Npoints versus momentum",150,0,15,70,0,70);
72 
73  fh_Nhits = new TH1D("fh_Nhits","Number of hits of e rings (STS>=6)",70,0,70);
74 
75  fh_Nall = new TH1D("fh_Nall","Number of all rings in RICH",150,0,150);
76  fh_Nel = new TH1D("fh_Nel","Number of electron rings in RICH",150,0,150);
77  fh_Nelprim = new TH1D("fh_Nelprim","Number of electron (STS>=6) rings in RICH",150,0,150);
78  fh_Npi = new TH1D("fh_Npi","Number of pi rings in RICH",150,0,150);
79  fh_Nk = new TH1D("fh_Nk","Number of K rings in RICH",150,0,150);
80  fh_Nhad = new TH1D("fh_Nhad","Number of hadrons crossing PMT plane",50,0,50);
81  fh_Nnoise = new TH1D("fh_Nnoise","Number of noise hits PMT plane",100,0,2000);
82 }
83 
85 {
86  // write histograms to a file
87  fh_Det1ev->Write();
88  fh_Det1ev_zoom->Write();
89  fh_Detall->Write();
90  fh_Detall_zoom->Write();
91  fh_n_vs_p->Write();
92 
93  fh_Nhits-> Write();
94 
95  fh_Nall->Write();
96  fh_Nel->Write();
97  fh_Nelprim->Write();
98  fh_Npi->Write();
99  fh_Nk->Write();
100  fh_Nhad->Write();
101  fh_Nnoise->Write();
102 }
103 
105 {
106  // Get Base Container
108  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
109  fPar=(CbmGeoRichPar*)(rtdb->getContainer("CbmGeoRichPar"));
110 }
111 
113 {
115 
116  // get detector position (z):
117  FairGeoNode *det= dynamic_cast<FairGeoNode*> (fSensNodes->FindObject("rich1d#1"));
118  if (! det) cout << " -I no RICH Geo Node found !!!!! " << endl;
119  FairGeoTransform* detTr=det->getLabTransform(); // detector position in labsystem
120  FairGeoVector detPosLab=detTr->getTranslation(); // ... in cm
121  FairGeoTransform detCen=det->getCenterPosition(); // center in Detector system
122  FairGeoVector detPosCen=detCen.getTranslation();
123  fDetZ = detPosLab.Z() + detPosCen.Z();
126  if (NULL == ioman) { Fatal("CbmRichTestHits::Init", "RootManager not instantised!");}
127 
128  fMcTracks = (TClonesArray*) ioman->GetObject("MCTrack");
129  if ( NULL == fMcTracks) { Fatal("CbmRichTestHits::Init", "No MCTrack array!");}
130 
131  fRichPoints = (TClonesArray*) ioman->GetObject("RichPoint");
132  if ( NULL == fRichPoints) { Fatal("CbmRichTestHits::Init", "No RichPoint array!");}
133 
134  fRichHits = (TClonesArray*) ioman->GetObject("RichHit");
135  if ( NULL == fRichHits) { Fatal("CbmRichTestHits::Init", "No RichHit array!");}
136 
137  return kSUCCESS;
138 }
139 
141  Option_t* option)
142 {
143  fNEvents++;
144 
145  TVector3 position;
146  TVector3 momentum;
147  TVector3 vertex;
148 
149  Int_t Nhad, Nring, Nel, Nel_prim, Npi, Nk, Nnoise;
150  Nhad = Nring = Nel = Nel_prim = Npi = Nk = Nnoise = 0;
151 
152  map<Int_t,Int_t> hitMap;
153 
154  Int_t nHits = fRichHits->GetEntriesFast();
155  Int_t nMCTracks = fMcTracks->GetEntriesFast();
156 
157  for(Int_t iHit=0; iHit<nHits; iHit++){
158  CbmRichHit* pHit= (CbmRichHit*) fRichHits->At(iHit);
159  if( NULL == pHit ) continue;
160 
161  pHit->Position(position);
162  fh_Detall->Fill(position.X(),position.Y());
163  fh_Detall_zoom->Fill(position.X(),position.Y());
164  if (fNEvents == 1) {
165  fh_Det1ev->Fill(position.X(),position.Y());
166  fh_Det1ev_zoom->Fill(position.X(),position.Y());
167  }
168 
169  // Noise hit
170  if ((pHit->GetRefId()) < 0) {
171  Nnoise++;
172  continue;
173  }
174  CbmRichPoint* pPoint = (CbmRichPoint*) fRichPoints->At(pHit->GetRefId());
175  CbmMCTrack* pTrack = (CbmMCTrack*)fMcTracks->At(pPoint->GetTrackID());
176  Int_t gcode = pTrack->GetPdgCode();
177  if (gcode != 50000050) Nhad++;
178  if (gcode == 50000050){
179  pTrack->GetStartVertex(vertex);
180  Int_t motherID = pTrack->GetMotherId();
181  if (motherID == -1) continue;
182 
183  pTrack = (CbmMCTrack*) fMcTracks->At(motherID);
184  hitMap[motherID]++;
185  } //select cherenkov photons
186  } // point loop
187 
188  for (Int_t iMCTrack=0; iMCTrack<nMCTracks; iMCTrack++) {
189  CbmMCTrack* pTrack = (CbmMCTrack*) fMcTracks->At(iMCTrack);
190  if ( NULL == pTrack ) continue;
191  Int_t Nhits = hitMap[iMCTrack];
192  if (Nhits){
193  Nring++;
194  pTrack->GetMomentum(momentum);
195  fh_n_vs_p->Fill(momentum.Mag(),Nhits);
196  Int_t gcode = pTrack->GetPdgCode();
197  if (TMath::Abs(gcode) == 11) {
198  Nel++;
199  if (pTrack->GetNPoints(kSTS) > 5) {
200  Nel_prim++;
201  fh_Nhits->Fill(Nhits);
202  }
203  } //electrons
204  if (TMath::Abs(gcode) == 211) Npi++;
205  if (TMath::Abs(gcode) == 321) Nk++;
206  } // tracks with points in Rich
207  } // track loop
208 
209  fh_Nall->Fill(Nring);
210  fh_Nel->Fill(Nel);
211  fh_Nelprim->Fill(Nel_prim);
212  fh_Npi->Fill(Npi);
213  fh_Nk->Fill(Nk);
214  fh_Nhad->Fill(Nhad);
215  fh_Nnoise->Fill(Nnoise);
216 
217  if (fVerbose){
218  cout << "--------------------------------------------------------------------------" << endl;
219  cout << "----------- Test Rich HitProducer -----------" << endl;
220  cout << endl;
221  cout << " Number of particles in RICH detector ----- event number " << fNEvents << endl;
222  cout << " hadrons in RICH (no Cherenkov photons) = " << Nhad << endl;
223  cout << " total rings = " << Nring << endl;
224  cout << " electrons = " << Nel << endl;
225  cout << " electrons (STS>=6) = " << Nel_prim << endl;
226  cout << " pions = " << Npi << endl;
227  cout << " Kaons = " << Nk << endl;
228  cout << endl;
229  cout << "--------------------------------------------------------------------------" << endl;
230  }
231 }
232 
234 {
235  fMcTracks->Clear();
236  fRichPoints->Clear();
237  fRichHits->Clear();
238 }
239 
241