FairRoot/PandaRoot
PndHypMSAnaTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndHypMSAnaTask source file -----
3 // ----- Created 18/07/08 by T.Stockmanns -----
4 // -------------------------------------------------------------------------
5 // libc includes
6 #include <iostream>
7 
8 // Root includes
9 #include "TROOT.h"
10 #include "TClonesArray.h"
11 #include "TVector3.h"
12 
13 
14 // framework includes
15 #include "FairRootManager.h"
16 #include "PndHypMSAnaTask.h"
17 #include "FairRunAna.h"
18 #include "FairRuntimeDb.h"
19 #include "FairHit.h"
20 #include "PndMCTrack.h"
21 // PndHyp includes
22 #include "PndHypPoint.h"
23 #include "FairTrackParH.h"
24 #include "FairTrackParP.h"
25 
26 #include "TDatabasePDG.h"
27 
28 #include <vector>
29 #include <map>
30 
31 
32 // ----- Default constructor -------------------------------------------
33 PndHypMSAnaTask::PndHypMSAnaTask() : FairTask("Geane Task for PANDA PndHyp"), fEventNr(0)
34 {
35  histo = new TH1F("h1","h1",3000,0,20);
36 }
37 // -------------------------------------------------------------------------
38 
39 
40 // ----- Destructor ----------------------------------------------------
42 {delete(histo);delete fGeoH;
43 }
44 
45 // ----- Public method Init --------------------------------------------
47 {
48  // Get RootManager
49  FairRootManager* ioman = FairRootManager::Instance();
50  if ( !ioman){
51  std::cout << "-E- PndHypMSAnaTask::Init: "<< "RootManager not instantiated!" << std::endl;
52  return kFATAL;
53  }
54 
55  // Get input arrays
56  fMCTracks = (TClonesArray*) ioman->GetObject("MCTrack");
57  if (!fMCTracks){
58  std::cout << "-W- PndHypMSAnaTask::Init: "<< "No MCTrack" << " array!" << std::endl;
59  return kERROR;
60  }
61 
62  fMCHits = (TClonesArray*) ioman->GetObject("HypPoint");
63  if ( !fMCHits) {
64  std::cout << "-W- PndHypMSAnaTask::Init: "<< "No MVDPoint"<<" array!" << std::endl;
65  return kERROR;
66  }
67 
68  /* fTrackParGeane = new TClonesArray("FairTrackParP");
69  ioman->Register("GeaneTrackPar","Geane", fTrackParGeane, kTRUE);
70 
71  fTrackParIni = new TClonesArray("FairTrackParP");
72  ioman->Register("GeaneTrackIni","Geane", fTrackParIni, kTRUE);
73 
74  fTrackParFinal = new TClonesArray("FairTrackParP");
75  ioman->Register("GeaneTrackFinal","Geane", fTrackParFinal, kTRUE);*/
76 
77  // fPro = new FairGeanePro();
79 
80  return kSUCCESS;
81 }
82 // -------------------------------------------------------------------------
84 {
85  // Get Base Container
86  //FairRunAna* ana = FairRunAna::Instance();
87  //FairRuntimeDb* rtdb=ana->GetRuntimeDb();
88 
89 }
90 
91 
92 // ----- Public method Exec --------------------------------------------
93 void PndHypMSAnaTask::Exec(Option_t*)
94 {
95  // mcHitMap.clear(); //Track -> MCHits
96  TVector3 vpi2;
97 
98 // fTrackParGeane->Delete();
99 // fTrackParIni->Delete();
100 // fTrackParFinal->Delete();
101 
103 
104  std::cout << "------------Event " << fEventNr << "-------------" << std::endl;
105  fEventNr++;
106  std::cout<<" size map "<<mcHitMap.size()<<std::endl;
107 
108  for (std::map<int, std::vector<int> >::const_iterator it = mcHitMap.begin();
109  it!= mcHitMap.end();
110  it++)
111  { //go through all tracks
112  PndMCTrack* myTrack = (PndMCTrack*)(fMCTracks->At(it->first));
113  std::vector<int> MChits = it->second;
114 
115  /* if(myTrack==0)
116  {
117  it++;
118  continue;
119  }
120  */
121 
122 
123  //if(myTrack->GetPdgCode()>1010000000||myTrack->GetPdgCode()>1020000000)
124  //std::cout<<" hypernuclei "<<std::endl;
125 
126  if (MChits.size() >=3){
127 
128  PndHypPoint* startPoint = (PndHypPoint*)(fMCHits->At(0));
129  std::cout<<" hits "<<MChits.size()<<(it->first)<<std::endl;
130  //std::cout << "StartPoint: " << *startPoint << std::endl;
131 
132  //PndMCTrack* mctruth=(PndMCTrack*)fMCTracks->At( startPoint->GetTrackID());
133  //if(mctruth==0)continue;
134  std::cout<<" pid "<<startPoint->GetTrackID()<<" "<<it->first<<std::endl;
135  Int_t MotherId, Motherpdg;
136  MotherId= myTrack->GetMotherID();
137 
138  if (MotherId==-1)Motherpdg = myTrack->GetPdgCode();
139  else {
140  PndMCTrack *mother =(PndMCTrack*)fMCTracks->At(MotherId);
141  Motherpdg = mother->GetPdgCode();
142  }
143  if((myTrack->GetPdgCode()==-211)&&( Motherpdg>1010000000&&
144  Motherpdg<1020050130) )
145  { //startPoint->MomentumIn(vpi2);//vpi2 = mctruth->GetMomentum();
146  std::cout<<" hits "<<MChits.size()<<" "<<Motherpdg<<std::endl;
147 
148  histo->Fill(MChits.size());//vpi2.Mag());
149  }
150 
151  /*
152  TVector3 StartPos(startPoint->GetPosition());
153  TVector3 StartPosErr(0.0, 0.0, 0.0);
154  TVector3 StartMom(startPoint->GetPx(), startPoint->GetPy(), startPoint->GetPz());
155  TVector3 StartMomErr(0.0, 0.0, 0.0);
156  TVector3 startO, startU, startV;
157 
158  fGeoH->GetOUVId(startPoint->GetDetName(), startO, startU, startV);
159  fPro->PropagateFromPlane(startU, startV);
160 
161  Int_t PDGCode = myTrack->GetPdgCode();
162  TDatabasePDG *fdbPDG= TDatabasePDG::Instance();
163  TParticlePDG *fParticle= fdbPDG->GetParticle(PDGCode);
164  Double_t fCharge= fParticle->Charge();
165 
166  TClonesArray& clref1 = *fTrackParIni;
167  Int_t size1 = clref1.GetEntriesFast();
168  FairTrackParP *fStart= new (clref1[size1]) FairTrackParP(StartPos, StartMom, StartPosErr, StartMomErr, fCharge, startO, startU, startV);
169 
170  for (int p = 1; p < MChits.size(); p++){ //go through all hits in track
171  PndHypPoint* myPoint = (PndHypPoint*)(fMCHits->At(MChits[p]));
172  std::cout << "PropagationPoint: " << *myPoint << std::endl;
173 
174  TVector3 StopPos(myPoint->GetPosition());
175  TVector3 StopPosErr(0.0, 0.0, 0.0);
176  TVector3 StopMom(myPoint->GetPx(), myPoint->GetPy(), myPoint->GetPz());
177  TVector3 StopMomErr(0.0, 0.0, 0.0);
178 
179  TVector3 o, u, v;
180  fGeoH->GetOUVId(myPoint->GetDetName(), o, u, v);
181 
182  TClonesArray& clref2 = *fTrackParFinal;
183  Int_t size2 = clref2.GetEntriesFast();
184  FairTrackParP *fStop= new (clref2[size2]) FairTrackParP(StopPos, StopMom, StopPosErr, StopMomErr, fCharge, o, u, v);
185 
186  TClonesArray& clref = *fTrackParGeane;
187  Int_t size = clref.GetEntriesFast();
188  FairTrackParP *fRes= new(clref[size]) FairTrackParP();
189 
190  std::cout << "Propagation Plane:" << std::endl;
191  std::cout << "o: " << o[0] << " " << o[1] << " " << o[2] << std::endl;
192  std::cout << "u: " << u[0] << " " << u[1] << " " << u[2] << std::endl;
193  std::cout << "v: " << v[0] << " " << v[1] << " " << v[2] << std::endl;
194 
195  TVector3 endPoint(myPoint->GetPosition());
196  //fPro->SetPoint(endPoint);
197  //fPro->PropagateToPCA(1);
198 
199  fPro->PropagateToPlane(o, u, v);
200  if(fCharge>0)fPro->Propagate(fStart, fRes, 211);
201  if(fCharge<0)fPro->Propagate(fStart, fRes, -211);
202 
203  std::cout << std::endl;
204  std::cout << "Propagation Points: " << std::endl;
205  std::cout << fRes->GetX() << " +/- " << fRes->GetDX() << std::endl;
206  std::cout << fRes->GetY() << " +/- " << fRes->GetDY() << std::endl;
207  std::cout << fRes->GetZ() << " +/- " << fRes->GetDZ() << std::endl;
208  std::cout << std::endl;
209 
210  TVector3 global(fRes->GetX(), fRes->GetY(), fRes->GetZ());
211  TVector3 local = fGeoH->MasterToLocalId(global, myPoint->GetDetName());
212 
213  std::cout << "Propagation Point local: " << std::endl;
214  std::cout << local[0] << " " << local[1] << " " << local[2] << std::endl;
215  std::cout << std::endl;
216  }
217  */
218  }
219  }
220  fMCTracks->Delete();
221  fMCHits->Delete();
222  Finish();
223 
224 
225 }
226 
228 { fMCTracks->Delete();
229  fMCHits->Delete();
230 }
231 
232 std::map<int, std::vector<int> > PndHypMSAnaTask::AssignHitsToTracks()
233 {
234  std::map<int, std::vector<int> > result;
235  for (int i = 0; i < fMCHits->GetEntriesFast(); i++){ //get all MC Hits
236  PndHypPoint* myPoint = (PndHypPoint*)(fMCHits->At(i)); //sort MCHits with Tracks
237  //if(myPoint->GetTrackID()>1000)continue;
238  TVector3 mom;
239  myPoint->Momentum(mom);
240 
241  // if(mom.Mag()>0.05){
242  //std::cout<<" hyp "<<myPoint->GetTrackID()<<std::endl;
243  //}
244 
245  PndMCTrack* myTrack = (PndMCTrack*)(fMCTracks->At(myPoint->GetTrackID()));
246  result[myPoint->GetTrackID()].push_back(i);
247  //}
248 
249  }
250  return result;
251  //result.clear();
252 }
253 
255  TFile* file = FairRootManager::Instance()->GetOutFile();
256  file->cd();
257  file->mkdir("Dedx_detid");
258  file->cd("Dedx_detid");
259 
260  histo->Write();
261  delete histo;
262  histo=NULL;
263 }
264 
265 
virtual void Exec(Option_t *opt)
Int_t Motherpdg
Int_t i
Definition: run_full.C:25
TFile * file
std::map< int, std::vector< int > > AssignHitsToTracks()
PndTransMap * map
Definition: sim_emc_apd.C:99
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
virtual void SetParContainers()
Class to access the naming information of the MVD.
virtual InitStatus Init()
Double_t mom
Definition: plot_dirc.C:14
TGeoManager * gGeoManager
TClonesArray * fMCTracks
PndHypGeoHandling * fGeoH
ClassImp(PndHypMSAnaTask)
std::map< int, std::vector< int > > mcHitMap
virtual void Finish()
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
TClonesArray * fMCHits
Int_t MotherId