FairRoot/PandaRoot
PndFsmMdtPid.cxx
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // File and Version Information:
3 // $Id: PndFsmMdtPid.cxx $
4 //
5 // Description:
6 // Class PndFsmMdtPid
7 //
8 // Implementation of the MDT for the FastSim
9 //
10 // This software was developed for the PANDA collaboration. If you
11 // use all or part of it, please give an appropriate acknowledgement.
12 //
13 // Author List:
14 // Ralf Kliemt Original Author
15 //
16 // Copyright Information:
17 // Copyright (C) 2014 GSI
18 //
19 //------------------------------------------------------------------------
20 
21 //-----------------------
22 // This Class's Header --
23 //-----------------------
24 #include "PndFsmMdtPid.h"
25 
26 //-------------
27 // C Headers --
28 //-------------
29 
30 //---------------
31 // C++ Headers --
32 //---------------
33 #include <math.h>
34 #include <iostream>
35 
36 using std::cout;
37 using std::endl;
38 using std::ostream;
39 using std::string;
40 
41 //-------------------------------
42 // Collaborating Class Headers --
43 //-------------------------------
44 
45 #include "ArgList.h"
46 #include "PndFsmResponse.h"
47 #include "PndFsmTrack.h"
48 #include "TH3F.h"
49 #include "TH1D.h"
50 #include "TFile.h"
51 
52 //-----------------------------------------------------------------------
53 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
54 //-----------------------------------------------------------------------
55 
56 //----------------
57 // Constructors --
58 //----------------
59 
61 {
63 
64  _thtMin=_thtMin*M_PI/180.0;
65  _thtMax=_thtMax*M_PI/180.0;
67  //print(std::cout);
68 }
69 
71 {
73  //set default parameter values and parses a parameter list
74  //i.e. std::list<std::string> of the form
75  //"a=1" "b=2" "c=3"
76  parseParameterList(par);
77 
78  _thtMin=_thtMin*M_PI/180.0;
79  _thtMax=_thtMax*M_PI/180.0;
81  //print(std::cout);
82 }
83 
84 //--------------
85 // Destructor --
86 //--------------
87 
89 {
90 }
91 
92 //--------------
93 // Operations --
94 //--------------
95 
98 {
99  PndFsmResponse *result=new PndFsmResponse();
100 
101  result->setDetector(this);
102  bool wasDetected=detected(t);
103  result->setDetected(wasDetected);
104 
105  if (wasDetected)
106  {
107  if (_useFlat) // just use very simple likelihoods for muons and pions
108  {
109  result->setLHElectron(0.);
110  result->setLHMuon( 1-_misId );
111  result->setLHPion( _misId );
112  result->setLHKaon( 0. );
113  result->setLHProton( 0. );
114  }
115  else // use sophisticated methode with histogram lookup likelihoods
116  {
117  int type = t->pdt();
118  double p = t->p4().Vect().Mag();
119  double tht = t->p4().Theta()*57.296;
120  double charge = t->charge();
121 
122  // convert pdg code in type: 0=e+-, 1=mu+-, 2=pi+-, 3=K+-, 4=p, 5=p-bar
123  int idx;
124  if (abs(type)==11) idx=0;
125  else if (abs(type)==13) idx=1;
126  else if (abs(type)==211) idx=2;
127  else if (abs(type)==321) idx=3;
128  else if (type==2212) idx=4;
129  else idx=5;
130 
131  // histogram max p = 8.0
132  if (p>7.99) p=7.99;
133 
134  // get the bin corresponding to p
135  int currbinT = _mdtPidPdf[0]->GetYaxis()->FindBin(tht);
136  int currbinP = _mdtPidPdf[0]->GetZaxis()->FindBin(p);
137 
138  // get the slice containing the pdf emcecal(p) for true particle type
139  TH1D *hpdf = _mdtPidPdf[idx]->ProjectionX("_tmppdf",currbinT, currbinT, currbinP, currbinP);
140 
141  // get a random emcecal value from the true distribution
142  // if distribution is empty, choose 0
143  double xsig = 0.;
144  if (hpdf->Integral()>0) xsig = hpdf->GetRandom();
145 
146  // store the value in the response object
147  result->setMuoIron(xsig);
148 
149  // find the bin corresponding to the value
150  int xsigbin = hpdf->FindBin(xsig);
151 
152  // get the probability values for the different particle types for this emcecal value; sum needed for normalization
153  double P[6], Psum=0.;
154 
155  // sum up e ... K
156  for (int k=0;k<6;++k)
157  {
158  P[k] = _mdtPidPdf[k]->GetBinContent(xsigbin,currbinT,currbinP);
159  if (k<4) Psum += P[k];
160  }
161  // add P_p or P_pbar depending on charge of particle
162  if (charge>0) Psum+=P[4];
163  else Psum+=P[5];
164 
165  if (Psum<=0.) Psum=1.;
166 
167  result->setLHElectron(P[0]/Psum);
168  result->setLHMuon(P[1]/Psum);
169  result->setLHPion(P[2]/Psum);
170  result->setLHKaon(P[3]/Psum);
171  if (charge>0) result->setLHProton(P[4]/Psum);
172  else result->setLHProton(P[5]/Psum);
173 
174  }
175  }
176 
177  return result;
178 }
179 
180 bool
182 {
183  double theta = t->p4().Theta();
184  double p=t->p4().Vect().Mag();
185  double charge=t->charge();
186  int type=abs(t->pdt());
187 
188  if (_useFlat) return ( charge!=0.0 && theta>=_thtMin && theta<=_thtMax && p>_pmin && ((type==13 && _rand->Rndm()<=_efficiency) || (type==211 && _rand->Rndm()<=_misId)) );
189 
190  return ( charge!=0.0 && theta>=_thtMin && theta<=_thtMax && p>_pmin );
191 }
192 
193 void
195 {
196  o <<"Parameters for detector <"<<detName()<<">"<<endl;
197  o <<" _thtMin = "<<_thtMin<<endl;
198  o <<" _thtMax = "<<_thtMax<<endl;
199  o <<" _pmin = "<<_pmin<<endl;
200  o <<" _misId = "<<_misId<<endl;
201  o <<" _efficiency = "<<_efficiency<<endl;
202 }
203 
204 void
206 {
207  _detName = "MdtPid";
208  _thtMin = 5.;
209  _thtMax = 160.;
210  _pmin = 1.0;
211  _misId = 0.01;
212  _efficiency = 1.0;
213  _parFileName = "$VMCWORKDIR/fastsim/MdtPidPdf3D.root";
214  _useFlat = false;
215 }
216 
217 bool
218 PndFsmMdtPid::setParameter(std::string &name, double value)
219 {
220  // *****************
221  // include here all parameters which should be settable via tcl
222  // *****************
223 
224  bool knownName=true;
225 
226  if (name == "thtMin")
227  _thtMin=value;
228  else
229  if (name == "thtMax")
230  _thtMax=value;
231  else
232  if (name == "pmin")
233  _pmin=value;
234  else
235  if (name == "misId")
236  _misId=value;
237  else
238  if (name == "efficiency")
239  _efficiency=value;
240  else
241  knownName=false;
242 
243  return knownName;
244 }
245 
247 {
248 
249  TFile *f=new TFile(_parFileName.c_str());
250 
251  for (int i=0;i<6;i++)
252  {
253  _mdtPidPdf[i]=0;
254  }
255 
256  if (f->IsZombie())
257  {
258  cout <<" -W- (PndFsmMdtPid::readParameters) - file "<<_parFileName.c_str()
259  <<" doesn't exist. Using simple likelihood."<<endl;
260  _useFlat = true;
261  }
262  else
263  {
264  _mdtPidPdf[0]=(TH3F*)f->Get("hpdf_e");
265  _mdtPidPdf[1]=(TH3F*)f->Get("hpdf_mu");
266  _mdtPidPdf[2]=(TH3F*)f->Get("hpdf_pi");
267  _mdtPidPdf[3]=(TH3F*)f->Get("hpdf_k");
268  _mdtPidPdf[4]=(TH3F*)f->Get("hpdf_p");
269  _mdtPidPdf[5]=(TH3F*)f->Get("hpdf_pb");
270 
271  cout << _mdtPidPdf[0]<<endl;
272 
273  for (int i=0;i<6;i++) _mdtPidPdf[i]->SetDirectory(0);
274 
275  f->Close();
276  }
277  delete f;
278 
279  return true;
280 }
void print(std::ostream &o)
Double_t p
Definition: anasim.C:58
std::string _parFileName
Definition: PndFsmMdtPid.h:84
double _efficiency
Definition: PndFsmAbsDet.h:93
void setLHElectron(double val)
Int_t i
Definition: run_full.C:25
void setLHProton(double val)
bool readParameters()
std::list< std::string > ArgList
Definition: ArgList.h:7
void setLHMuon(double val)
Double_t par[3]
double charge()
Definition: PndFsmTrack.h:75
void initParameters()
void parseParameterList(ArgList &par)
virtual PndFsmResponse * respond(PndFsmTrack *t)
bool detected(PndFsmTrack *t) const
TRandom3 * _rand
Definition: PndFsmAbsDet.h:94
void setMuoIron(double val)
int idx[MAX]
Definition: autocutx.C:38
TLorentzVector p4()
Definition: PndFsmTrack.h:72
basic_ostream< char, char_traits< char > > ostream
void setDetector(PndFsmAbsDet *detector)
const std::string & detName()
Definition: PndFsmAbsDet.h:74
double _thtMin
Definition: PndFsmMdtPid.h:77
TString tht(TString pts, TString exts="px py pz")
Definition: invexp.C:168
TFile * f
Definition: bump_analys.C:12
virtual ~PndFsmMdtPid()
double _thtMax
Definition: PndFsmMdtPid.h:78
void setLHKaon(double val)
TString name
double _misId
Definition: PndFsmMdtPid.h:80
bool setParameter(std::string &name, double value)
TH3F * _mdtPidPdf[6]
Definition: PndFsmMdtPid.h:75
GeV c P
std::string _detName
Definition: PndFsmAbsDet.h:92
void setDetected(bool isdet)
TTree * t
Definition: bump_analys.C:13
double _pmin
Definition: PndFsmMdtPid.h:79
void setLHPion(double val)