EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrimSelector.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PrimSelector.cxx
1 //-----------------------------------------------------------
2 // File and Version Information:
3 // $Id$
4 //
5 // Description:
6 // Implementation of class PrimSelector
7 // see PrimSelector.hh for details
8 //
9 // Environment:
10 // Software developed for the PANDA Detector at FAIR.
11 //
12 // Author List:
13 // Sebastian Neubert TUM (original author)
14 //
15 //
16 //-----------------------------------------------------------
17 
18 // Panda Headers ----------------------
19 
20 // This Class' Header ------------------
21 #include "PrimSelector.h"
22 
23 // C/C++ Headers ----------------------
24 #include <vector>
25 #include <map>
26 #include <iostream>
27 
28 // Collaborating Class Headers --------
29 #include "FairRootManager.h"
30 #include "TClonesArray.h"
31 #include "TVector3.h"
32 #include "TLorentzVector.h"
33 #include "TGraph.h"
34 #include "TH1D.h"
35 #include "TFile.h"
36 #include "GFTrack.h"
37 #include "GFTrackCand.h"
38 #include "GFException.h"
39 #include "GFAbsTrackRep.h"
40 //#include "trackProximity.h"
41 
42 // Class Member definitions -----------
43 
44 using namespace::std;
45 
47  : FairTask("PrimSelector"), _persistence(kFALSE), _trackBranchName("TrackPreFit")
48 {
49 }
50 
52 {}
53 
54 
57 {
58  //Get ROOT Manager
60 
61  if(ioman==0)
62  {
63  Error("PrimSelector::Init","RootManager not instantiated!");
64  return kERROR;
65  }
66 
67  // Get input collection
68  _trackArray=(TClonesArray*) ioman->GetObject(_trackBranchName);
69 
70  if(_trackArray==0)
71  {
72  Error("PrimSelector::Init","Track-array not found!");
73  return kERROR;
74  }
75 
76  _pocaArray=new TClonesArray("TVector3");
77  ioman->Register("PrimPoca","PrimSelector",_pocaArray,_persistence);
78 
79  // missuse of TVector3 to store the charge....
80  _chargeArray=new TClonesArray("TVector3");
81  ioman->Register("PrimCharge","PrimSelector",_chargeArray,_persistence);
82 
83 
84 
85  _primArray=new TClonesArray("TLorentzVector");
86  ioman->Register("Mom","PrimSelector",_primArray,_persistence);
87 
88  fEventCounter=0;
89  fNFullEvents=0;
90  fNPhysTracks=0;
91  fNBkgTracks=0;
92 
93 
94  return kSUCCESS;
95 }
96 
97 void
98 PrimSelector::Exec(Option_t* opt)
99 {
100  std::cout << "PrimSelector::Exec" << std::endl;
101 
102  // Reset output Arrays
103  if(_pocaArray==0) Fatal("PrimSelector::Exec)","No pocaArray");
104  _pocaArray->Delete();
105  if(_chargeArray==0) Fatal("PrimSelector::Exec)","No chargeArray");
106  _chargeArray->Delete();
107  if(_primArray==0) Fatal("PrimSelector::Exec)","No primArray");
108  _primArray->Delete();
109  int ntrks=_trackArray->GetEntriesFast();
110 
111  map<unsigned int, int> trackIds;
112 
113  TVector3 IP(0,0,0);
114  for(int itrk=0;itrk<ntrks;++itrk){
115  GFTrack* trk=(GFTrack*)_trackArray->At(itrk);
116  if(trk->getMom().Mag()<0.1) continue;
117 
118  GFAbsTrackRep* rep = trk->getCardinalRep();
119  TVector3 poca, dirInPoca;
120  try {
121  rep->extrapolateToPoint(IP, poca, dirInPoca);
122  }
123  catch(GFException& ex) {
124  if(fVerbose)std::cout<<ex.what()<<std::endl;
125  //continue;
126  }
127 
128  // record mctruth info
129  if(trk->getCand().getMcTrackId()<10000){
130  ++fNPhysTracks;
131  trackIds[trk->getCand().getMcTrackId()]+=1;
132  }
133  else ++fNBkgTracks;
134 
135 
136 
137  new((*_chargeArray)[_chargeArray->GetEntriesFast()]) TVector3(trk->getCharge(),0,0);
138  // store positions to cut on in analysis
139  Int_t size=_pocaArray->GetEntriesFast();
140  new((*_pocaArray)[size]) TVector3(poca);
141 
142  // build 4-vector
143  TVector3 p3=rep->getMom();
144  TLorentzVector pion;
145  // make mass hypothesis here
146  pion.SetXYZM(p3.X(),p3.Y(),p3.Z(),0.13957018);
147 
148  Int_t size2=_primArray->GetEntriesFast();
149  new((*_primArray)[size2]) TLorentzVector(pion);
150 
151  } // end loop over tracks
152 
153  if(trackIds.size()>=fNExpectedTracks)++fNFullEvents;
154 
155  ++fEventCounter;
156 }
157 
158 
159 void
162  file->mkdir("PrimSelector");
163  file->cd("PrimSelector");
164  double singleTrackEff=(double)fNPhysTracks/double(fNExpectedTracks*fEventCounter);
165  double singleTrackPurity=1. - (double)fNBkgTracks/(double)(fNBkgTracks+fNPhysTracks);
166 
167  double fullEvtEff= (double)fNFullEvents/(double)fEventCounter;
168 
169  TH1D* h=new TH1D("hEffPrim","Prim: nbkg nphys nfullevents nevent",4,0,4);
170  h->Fill(0.5,fNBkgTracks);
171  h->Fill(1.5,fNPhysTracks);
172  h->Fill(2.5,fNFullEvents);
173  h->Fill(3.5,fEventCounter);
174  h->Write();
175 
176  std::cout << "PrimSelector::FinishTask \n"
177  << " SingleTrackEfficiency: " << singleTrackEff << std::endl
178  << " SingleTrackPurity: " << singleTrackPurity<< std::endl
179  << " FullEventEfficiency: " << fullEvtEff<< std::endl;
180 
181  TGraph* gresults=new TGraph(3);
182  gresults->SetName("hPrimMC");
183  gresults->SetTitle("Efficiency Statistics by PrimSelector");
184 
185  gresults->SetPoint(0,0,singleTrackEff);
186  gresults->SetPoint(1,1,singleTrackPurity);
187  gresults->SetPoint(2,2,fullEvtEff);
188 
189  gresults->Write();
190 }
191