FairRoot/PandaRoot
PndPidBremCorrector.cxx
Go to the documentation of this file.
1 //-----------------------
2 // This Class's Header --
3 //-----------------------
4 #include "PndPidBremCorrector.h"
5 
6 //---------------
7 // C++ Headers --
8 //---------------
9 #include <vector>
10 //#include <set>
11 //#include <map>
12 #include <iostream>
13 
14 // Path of file:
15 // ----- $pandaroot/pid/PidCorr
16 
17 //-------------------------------
18 // Collaborating Class Headers --
19 //-------------------------------
20 
21 #include "FairRootManager.h"
22 #include "FairRunAna.h"
23 #include "FairRuntimeDb.h"
24 #include "TClonesArray.h"
25 
26 #include "PndEmcBump.h"
27 #include "PndEmcCluster.h"
28 
29 #include "PndPidCandidate.h"
30 
32 
33 using std::cout;
34 using std::endl;
35 
37  fBumpArray(0), fClusterArray(0), fPhiBumpArray(0), fChargedCandidateArray(0), fNeutralCandidateArray(0), fBremCorrected4MomArray(0),fRecMomOfEle(0), fRecThetaOfEle(0), fRecPhiOfEle(0), fCharge(0), fSepPhotonE(0.), fMergPhotonE(0.), fEmcPhiBumpList(), fTrackBranchNamePidHypo(""), fPersistance(kTRUE)
38 {
39 
40 }
41 
43 {
44 
45 }
46 
48 
49  // Get RootManager
50  FairRootManager* ioman = FairRootManager::Instance();
51  if ( ! ioman ){
52  cout << "-E- PndPidBremCorrector::Init: "
53  << "RootManager not instantiated!" << endl;
54  return kFATAL;
55  }
56 
57 
58  fClusterArray = dynamic_cast<TClonesArray *> (ioman->GetObject("EmcCluster"));
59  if ( ! fClusterArray ) {
60  cout << "-W- PndEmcMakeBump::Init: "
61  << "No PndEmcCluster array!" << endl;
62  return kERROR;
63  }
64 
65  fPhiBumpArray = dynamic_cast<TClonesArray *> (ioman->GetObject("EmcPhiBump"));
66  if ( ! fPhiBumpArray ) {
67  cout << "-W- PndEmcMakePhiBump::Init: "
68  << "No PhiBumpArray array!" << endl;
69  return kERROR;
70  }
71 
72  fBumpArray = dynamic_cast<TClonesArray *> (ioman->GetObject("EmcBump"));
73  if ( ! fBumpArray ) {
74  cout << "-W- PndEmcMakeBump::Init: "
75  << "No PndEmcBump array!" << endl;
76  return kERROR;
77  }
78 
79  fChargedCandidateArray = dynamic_cast<TClonesArray *> (ioman->GetObject("PidChargedCand"+fTrackBranchNamePidHypo));
80  if ( ! fChargedCandidateArray ) {
81  cout << "-W- PndEmcMakeBump::Init: "
82  << "No PidChargedCand array!" << endl;
83  return kERROR;
84  }
85 
86 
87  fNeutralCandidateArray = dynamic_cast<TClonesArray *> (ioman->GetObject("PidNeutralCand"+fTrackBranchNamePidHypo));
88  if ( ! fNeutralCandidateArray ) {
89  cout << "-W- PndEmcMakeBump::Init: "
90  << "No PidNeutralCand array!" << endl;
91  return kERROR;
92  }
93 
94 
95  fBremCorrected4MomArray = new TClonesArray("PndPidBremCorrected4Mom");
96  ioman->Register("BremCorrected4Mom"+fTrackBranchNamePidHypo,"Pid",fBremCorrected4MomArray,fPersistance);
97 
98  return kSUCCESS;
99 
100 }
101 
103 {
104 
105  // Reset output array
106  if ( ! fBremCorrected4MomArray ) Fatal("Exec", "No BremCorrected4Mom Array");
107  fBremCorrected4MomArray->Delete();
108 
109  int nChargedCand = fChargedCandidateArray->GetEntriesFast();
110 
111  for (int iCand = 0; iCand<nChargedCand; ++iCand){
112 
113  PndPidCandidate* theChargedCand = (PndPidCandidate*) fChargedCandidateArray->At(iCand);
114  fRecMomOfEle = theChargedCand->GetMomentum().Mag();
115  fRecThetaOfEle = theChargedCand->GetMomentum().Theta()*TMath::RadToDeg();
116  fRecPhiOfEle = theChargedCand->GetMomentum().Phi()*TMath::RadToDeg();
117  fCharge = theChargedCand->GetCharge();
118 
119  TVector3 mom = theChargedCand->GetMomentum();
120  double ene = theChargedCand->GetEnergy();
121  TLorentzVector m4 = TLorentzVector(mom,ene);
122  //double mass = m4.M();
123  double mass = 0.000511; // Electron mass hypothesis (GeV)
124 
125  std::vector<int> sep_bumps, phi_bumps;
126  fSepPhotonE = GetSepPhotonE(theChargedCand, sep_bumps);
127  fMergPhotonE = GetMergPhotonE(theChargedCand, phi_bumps);
128  double energy_gamma = fSepPhotonE + fMergPhotonE;
129 
130  TVector3 momCorr = ((energy_gamma+fRecMomOfEle)/fRecMomOfEle) * mom;
131  double eneCorr = TMath::Hypot(mass, momCorr.Mag());
132 
134  bremCorr->SetMomentum(momCorr);
135  bremCorr->SetEnergy(eneCorr);
136  for (size_t i=0; i < sep_bumps.size(); ++i) bremCorr->AddToSepBumpList(sep_bumps[i]);
137  for (size_t i=0; i < phi_bumps.size(); ++i) bremCorr->AddToPhiBumpList(phi_bumps[i]);
138  bremCorr->SetPidCandIdx(iCand);
139 
140  }
141 
142 }
143 
145  TClonesArray& clref = *fBremCorrected4MomArray;
146  Int_t size = clref.GetEntriesFast();
147  return new(clref[size]) PndPidBremCorrected4Mom();
148 }
149 
150 double PndPidBremCorrector::GetSepPhotonE(PndPidCandidate *ChargedCand, std::vector<int>& sep_bumps){
151 
152  Float_t PhotonTotEnergySepWtd = 0;
153 
154  const int iTrkEmcIdx = ChargedCand->GetEmcIndex();
155  if (iTrkEmcIdx<0) return 0;
156 
157  const int nBump = fBumpArray->GetEntriesFast();
158  for(Int_t iBump = 0; iBump<nBump; ++iBump)
159  {
160  PndEmcBump *PhotonBump = (PndEmcBump *) fBumpArray->At(iBump);
161  const Float_t PhotonEnergySep = PhotonBump->GetEnergyCorrected();
162 
163  const Int_t iSepBump = PhotonBump->GetClusterIndex();
164  if ( iSepBump == iTrkEmcIdx ) continue;
165 
166  const Double_t PhotonThetaSep = PhotonBump->position().Theta()*TMath::RadToDeg();
167  const Double_t PhotonPhiSep = PhotonBump->position().Phi()*TMath::RadToDeg();
168 
169  const Bool_t fwd = fRecThetaOfEle <= 23.;
170  const Float_t Pt = fRecMomOfEle*TMath::Sin(fRecThetaOfEle/TMath::RadToDeg());
171  const Float_t DeltaPhiBarrel = TMath::ASin(0.12/Pt)*2.*TMath::RadToDeg();
172  const Float_t DeltaPhiForward = (0.6*2.0/Pt)*TMath::Tan(fRecThetaOfEle/57.3)*57.3;
173 
174  const Float_t RealDeltaPhi = fCharge<0?PhotonPhiSep-fRecPhiOfEle:fRecPhiOfEle-PhotonPhiSep;
175  const Float_t RealDeltaTheta = fCharge<0?PhotonThetaSep-fRecThetaOfEle:fRecThetaOfEle-PhotonThetaSep;
176 
177  const Float_t rad_calc = 100.*TMath::Sin(RealDeltaPhi*TMath::DegToRad()/2.)*2.0*Pt/0.3/2.0; // B=2T
178  const Float_t zed_calc = rad_calc/TMath::Tan(TMath::DegToRad()*fRecThetaOfEle);
179 
180  const Float_t wt = fwd ? 1.0/(1.+TMath::Exp((zed_calc-90.)/25.)) : 1.0/(1.+TMath::Exp((rad_calc-21.)/5.));
181  const Float_t ThetaCutUp = 2.;
182  const Float_t ThetaCutDown = -2.;
183  const Float_t PhiCutUp = fwd ? DeltaPhiForward : DeltaPhiBarrel;
184  const Float_t PhiCutDown = -1;
185 
186  const Bool_t PhiCut = RealDeltaPhi <= PhiCutUp && RealDeltaPhi >= PhiCutDown;
187  const Bool_t ThetaCut = RealDeltaTheta <= ThetaCutUp && RealDeltaTheta >= ThetaCutDown;
188 
189  if (PhiCut && ThetaCut) {
190  PhotonTotEnergySepWtd += wt*PhotonEnergySep;
191  sep_bumps.push_back(iSepBump);
192  }
193 
194  }//loop neutralcand
195 
196  if (PhotonTotEnergySepWtd < fRecMomOfEle/100.) PhotonTotEnergySepWtd = 0;
197 
198  return PhotonTotEnergySepWtd;
199 
200 }
201 
202 double PndPidBremCorrector::GetMergPhotonE(PndPidCandidate *ChargedCand, std::vector<int>& phi_bumps){
203 
204  Double_t PhotonTotEnergyMerg = 0.0;
205 
206  // no EMcal cluster associated with track ...
207  if (ChargedCand->GetEmcIndex() < 0) return 0.0;
208 
209  PndEmcBump *EleBump = (PndEmcBump *) fBumpArray->At(ChargedCand->GetEmcIndex());
210  Int_t EleRefCluster = EleBump->GetClusterIndex();
211 
212  if (EleRefCluster < 0) return 0.0;
213  GetEmcPhiBumpList(EleRefCluster);
214 
215  //Double_t EnergyCut = 0.15/TMath::Sin(fRecThetaOfEle*TMath::DegToRad()); //[R.K. 01/2017] unused variable
216  //Double_t EleEnergy = 0; //[R.K. 01/2017] unused variable
217 
218  int iMax = 0;
219  Float_t eMax = -1e9;
220  for (size_t ib = 0; ib < fEmcPhiBumpList.size(); ++ib) {
221  if( fEmcPhiBumpList[ib]->energy() > eMax) {
222  iMax = ib;
223  eMax = fEmcPhiBumpList[ib]->energy();
224  }
225  }
226  Int_t iS = fCharge<0?0:iMax+1;
227  Int_t iE = fCharge<0?iMax-1:fEmcPhiBumpList.size()-1;
228  for(Int_t r = iS; r<=iE; r++) {
229  PhotonTotEnergyMerg += fEmcPhiBumpList[r]->energy();
230  phi_bumps.push_back(r);
231  }
232 
233  if(PhotonTotEnergyMerg > fRecMomOfEle/100.) {
234  return PhotonTotEnergyMerg;
235  } else {
236  return 0.0;
237  }
238 
239 }
240 
242  fEmcPhiBumpList.clear();
243  int nPhiBump = fPhiBumpArray->GetEntriesFast();
244  for (int ipb=0; ipb<nPhiBump; ++ipb) {
245  PndEmcBump *phibump = (PndEmcBump*) fPhiBumpArray->At(ipb);
246  if ( phibump->GetClusterIndex() == iClust ) {
247  fEmcPhiBumpList.push_back(phibump);
248  }
249  }
250 }
static T ASin(const T &x)
Int_t GetCharge() const
TClonesArray * fNeutralCandidateArray
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
static T Sin(const T &x)
Definition: PndCAMath.h:42
float Tan(float x)
Definition: PndCAMath.h:165
Double_t GetEnergy() const
Double_t mom
Definition: plot_dirc.C:14
Int_t GetEmcIndex() const
TVector3 position() const
Double_t
TClonesArray * fChargedCandidateArray
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
TClonesArray * fClusterArray
Int_t GetClusterIndex()
Definition: PndEmcBump.h:54
void GetEmcPhiBumpList(int iClust)
TClonesArray * fPhiBumpArray
Double_t GetEnergyCorrected() const
TClonesArray * fBremCorrected4MomArray
PndPidBremCorrected4Mom * AddBremCorrected4Mom()
std::vector< PndEmcBump * > fEmcPhiBumpList
TVector3 GetMomentum() const
double GetMergPhotonE(PndPidCandidate *, std::vector< Int_t > &)
represents a reconstructed (splitted) emc cluster
Definition: PndEmcBump.h:34
double GetSepPhotonE(PndPidCandidate *, std::vector< Int_t > &)
TClonesArray * fBumpArray
Double_t energy
Definition: plot_dirc.C:15