er  dev
ERmuSiMatcher.cxx
1 #include "ERmuSiMatcher.h"
2 
3 #include <iostream>
4 #include <map>
5 using namespace std;
6 
7 #include "FairRootManager.h"
8 #include "FairRunAna.h"
9 #include "FairRuntimeDb.h"
10 #include<iostream>
11 
12 #include "ERDetectorList.h"
13 
14 #include "ERMCTrack.h"
15 #include "ERmuSiPoint.h"
16 #include "ERmuSiHit.h"
17 #include "ERmuSiTrack.h"
18 #include "ERmuSiVertex.h"
19 // ----------------------------------------------------------------------------
21  : FairTask("ER muSi matching scheme"),
22  fTrueTracksNb(0),
23  fWrongTracksNb(0),
24  fMCTracksNb(0),
25  fShortMCTracksNb(0),
26  fNotFoundedVerteciesNb(0)
27 {
28 }
29 // ----------------------------------------------------------------------------
30 
31 // ----------------------------------------------------------------------------
33  : FairTask("ER muSi matching scheme ", verbose),
34  fTrueTracksNb(0),
35  fWrongTracksNb(0),
36  fMCTracksNb(0),
37  fShortMCTracksNb(0),
38  fNotFoundedVerteciesNb(0)
39 {
40 }
41 // ----------------------------------------------------------------------------
42 
43 // ----------------------------------------------------------------------------
45 {
46 }
47 // ----------------------------------------------------------------------------
48 
49 // ----------------------------------------------------------------------------
50 void ERmuSiMatcher::SetParContainers()
51 {
52  // Get run and runtime database
53  FairRunAna* run = FairRunAna::Instance();
54  if ( ! run ) Fatal("SetParContainers", "No analysis run");
55 
56  FairRuntimeDb* rtdb = run->GetRuntimeDb();
57  if ( ! rtdb ) Fatal("SetParContainers", "No runtime database");
58 }
59 // ----------------------------------------------------------------------------
60 
61 // ----------------------------------------------------------------------------
62 InitStatus ERmuSiMatcher::Init()
63 {
64  // Get input array
65  FairRootManager* ioman = FairRootManager::Instance();
66  if ( ! ioman ) Fatal("Init", "No FairRootManager");
67 
68  fMCTracks = (TClonesArray*) ioman->GetObject("MCTrack");
69  fmuSiPoints = (TClonesArray*) ioman->GetObject("muSiPoint");
70  fmuSiHits = (TClonesArray*) ioman->GetObject("muSiHit");
71  fmuSiTracks = (TClonesArray*) ioman->GetObject("muSiTrack");
72  fmuSiVertecies = (TClonesArray*) ioman->GetObject("muSiVertex");
73 
74  fHVertexDz = new TH1F("Vertex z quality", "Vertex z quality", 5000, 0., .5);
75  fHVertexDxy = new TH1F("Vertex xy quality", "Vertex xy quality", 5000, 0., .5);
76  return kSUCCESS;
77 }
78 // -------------------------------------------------------------------------
79 
80 // ----- Public method Exec --------------------------------------------
81 void ERmuSiMatcher::Exec(Option_t* opt)
82 {
83  std::cout << std::endl;
84  std::cout << "ERmuSiMatcher:" << std::endl;
85  Int_t trueTracks = 0;
86  Int_t wrongTracks = 0;
87  for(Int_t iTrack = 0; iTrack < fmuSiTracks->GetEntriesFast(); iTrack++){
88  ERmuSiTrack* track = (ERmuSiTrack*)fmuSiTracks->At(iTrack);
89  ERmuSiHit* hit0 = track->Hit(0);
90  ERmuSiHit* hit1 = track->Hit(1);
91  ERmuSiHit* hit2 = track->Hit(2);
92 
93  if (hit0->GetRefIndex() == -1 || hit1->GetRefIndex() == -1 || hit2->GetRefIndex() == -1){ //fakes
94  wrongTracks++;
95  continue;
96  }
97  ERmuSiPoint* point0 = (ERmuSiPoint*)fmuSiPoints->At(hit0->GetRefIndex());
98  ERmuSiPoint* point1 = (ERmuSiPoint*)fmuSiPoints->At(hit1->GetRefIndex());
99  ERmuSiPoint* point2 = (ERmuSiPoint*)fmuSiPoints->At(hit2->GetRefIndex());
100  if ((point0->GetTrackID() == point1->GetTrackID()) && (point1->GetTrackID() == point2->GetTrackID()))
101  trueTracks++;
102  else
103  wrongTracks++;
104  }
105 
106  map<Int_t,Int_t> pointsOnTracks;
107  for (Int_t iPoint = 0; iPoint < fmuSiPoints->GetEntriesFast(); iPoint++){
108  ERmuSiPoint* point = (ERmuSiPoint*)fmuSiPoints->At(iPoint);
109  pointsOnTracks[point->GetTrackID()]++;
110  }
111  Int_t shortMCTracks = 0;
112  for (map<Int_t,Int_t>::iterator it = pointsOnTracks.begin(); it != pointsOnTracks.end(); ++it){
113  if(it->second < 3)
114  shortMCTracks++;
115  }
116 
117  std::cout << "True tracks:" << trueTracks << std::endl;
118  std::cout << "Wrong tracks:" << wrongTracks << std::endl;
119  fTrueTracksNb += trueTracks;
120  fWrongTracksNb += wrongTracks;
121  fMCTracksNb += pointsOnTracks.size();
122  fShortMCTracksNb+= shortMCTracks;
123 
124  Int_t notFoundedVerteciesNb = 0;
125  //Выделяем mc вершины по массиву треков
126  vector<MCVertex> MCVertecies;
127  for (Int_t iTrack = 0; iTrack < fMCTracks->GetEntriesFast(); iTrack++){
128  ERMCTrack* mcTrack = (ERMCTrack*)fMCTracks->At(iTrack);
129  Bool_t addedToMC = kFALSE;
130  if (mcTrack->GetMotherId() == -1){
131  for(vector<MCVertex>::iterator it = MCVertecies.begin(); it!=MCVertecies.end(); it++){
132  if ( ((*it).x - mcTrack->GetStartX() < 0.01) &&
133  ((*it).y - mcTrack->GetStartY() < 0.01) &&
134  ((*it).y - mcTrack->GetStartY() < 0.01))
135  addedToMC = kTRUE;
136  }
137  if (!addedToMC)
138  MCVertecies.push_back(MCVertex(mcTrack->GetStartX(), mcTrack->GetStartY(), mcTrack->GetStartZ()));
139  }
140  }
141  //Смотрим какие вершины нашли
142  for(vector<MCVertex>::iterator it = MCVertecies.begin(); it!=MCVertecies.end(); it++){
143  MCVertex mcVertex = (*it);
144  Bool_t founded = kFALSE;
145  Float_t distFounded = 99999999.;
146  ERmuSiVertex* vertFounded;
147  for(Int_t iVert =0; iVert < fmuSiVertecies->GetEntriesFast(); iVert++ ){
148  ERmuSiVertex* vert = (ERmuSiVertex*)fmuSiVertecies->At(iVert);
149  Float_t dist = TMath::Sqrt((vert->X()-mcVertex.x)*(vert->X()-mcVertex.x) +
150  (vert->Y()-mcVertex.y)*(vert->Y()-mcVertex.y) +
151  (vert->Z()-mcVertex.z)*(vert->Z()-mcVertex.z));
152  if (dist < 1.){
153  founded = kTRUE;
154  if (dist < distFounded){ //выделяем наилучшую найденную вершину
155  distFounded = dist;
156  vertFounded = vert;
157  }
158  }
159  }
160  if (!founded){
161  notFoundedVerteciesNb++;
162  }else{
163  fHVertexDz->Fill(TMath::Abs(vertFounded->Z() - mcVertex.z));
164  fHVertexDxy->Fill(TMath::Sqrt((vertFounded->Y() - mcVertex.y)*(vertFounded->Y() - mcVertex.y)
165  +(vertFounded->X() - mcVertex.x)*(vertFounded->Z() - mcVertex.z)));
166  }
167  }
168 
169  std::cout << "Not founded primary vertecies:" << notFoundedVerteciesNb << std::endl;
170  fNotFoundedVerteciesNb += notFoundedVerteciesNb;
171 }
172 //----------------------------------------------------------------------------
173 
174 //----------------------------------------------------------------------------
176 {
177 }
178 // ----------------------------------------------------------------------------
179 
180 // ----------------------------------------------------------------------------
182 {
183  std::cout << std::endl;
184  std::cout << "========= ERmuSiMatcher : ================" << std::endl;
185 
186  std::cout << "MC tracks: " << fMCTracksNb << std::endl;
187  std::cout << "Short MC tracks: " << fShortMCTracksNb << std::endl;
188  std::cout << "True tracks: " << fTrueTracksNb << std::endl;
189  std::cout << "Wrong tracks: " << fWrongTracksNb << std::endl;
190  std::cout << "Eff. all: " << (Float_t)fTrueTracksNb/(Float_t)fMCTracksNb << std::endl;
191  std::cout << "Eff. long: " << (Float_t)fTrueTracksNb/(Float_t)(fMCTracksNb-fShortMCTracksNb)<< std::endl;
192  std::cout << "Not founded primary vertecies: " << fNotFoundedVerteciesNb << std::endl;
193 
194  fHVertexDz->Write();
195  fHVertexDxy->Write();
196 
197 }
198 // ----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
200 ClassImp(ERmuSiMatcher)
TClonesArray * fmuSiPoints
Definition: ERmuSiMatcher.h:45
virtual void Finish()
virtual void Exec(Option_t *opt)
virtual void Reset()
virtual InitStatus Init()