FairRoot/PandaRoot
outdated/mpiTools/macros/emc/reco_analys.C
Go to the documentation of this file.
1 #include <iostream>
2 #include "TChain.h"
3 #include "TH1D.h"
4 #include "TH2D.h"
5 #include "TClonesArray.h"
6 #include "TLorentzVector.h"
7 #include "TFile.h"
8 #include "TNtuple.h"
9 #include "TGeoManager.h"
10 #include "PndMCTrack.h"
11 #include "PndEmcHit.h"
12 #include "PndEmcDigi.h"
13 #include "PndEmcCluster.h"
14 #include "PndEmcTwoCoordIndex.h"
15 //#include "PndEmcMapper.h"
16 #include "PndEmcWaveform.h"
17 
18 void reco_analys(Char_t InputSimFile[]="sim_emc.root",
19  Char_t OutputFile[]="output.root")
20 {
21  TFile *f=new TFile(InputSimFile);
22  TGeoManager *fGeoManager = (TGeoManager *) f->Get("FAIRGeom");
23 
24  TChain *c=new TChain("pndsim");
25 
26  c->Add(InputSimFile);
27 
28  TClonesArray* track_array=new TClonesArray("PndMCTrack");
29  c->SetBranchAddress("MCTrack",&track_array);
30 
31  TClonesArray* cluster_array=new TClonesArray("PndEmcCluster");
32  TClonesArray* wf_array=new TClonesArray("PndEmcWaveform");
33  c->SetBranchAddress("EmcCluster",&cluster_array);
34  c->SetBranchAddress("EmcWaveform",&wf_array);
35 
36  TClonesArray* digi_array=new TClonesArray("PndEmcDigi");
37  c->SetBranchAddress("EmcDigi",&digi_array);
38 
39  TClonesArray* hit_array=new TClonesArray("PndEmcHit");
40  c->SetBranchAddress("EmcHit",&hit_array);
41 
42  TFile *fs=new TFile(OutputFile,"recreate");
43  TNtuple *n = new TNtuple("myntup","My Ntuple","et:tht:pht:ec:thc:phc:nc:sc:edbar:edfw:edbw:eh:ecc:thd:phd");
44 
45  cout << "<I> Number of entries " << c->GetEntries() << endl;
46 
47  double cluster_energy,cluster_energy_check,digi_low,digi_high;
48  double cluster_theta, cluster_phi; //position of the cluster
49  Double_t tot_digi_energy_barrel,tot_digi_energy_fwendcap,tot_digi_energy_bwendcap;
50  Double_t tot_hit_energy;
51  Double_t theta_digi,phi_digi;
52  int ndigi;
53 
54 // PndEmcMapper *fEmcMap=PndEmcMapper::Instance(1);
55 
56  // Cluster energy
57  for (Int_t j=0; j< c->GetEntries(); j++)
58  {
59  if (0 == (j%1000))
60  {
61  printf(".%i.",j);fflush(stdout);
62  }
63  c->GetEntry(j);
64 
65  PndMCTrack *track=(PndMCTrack*)track_array->At(0);
66  TLorentzVector p4mom=track->Get4Momentum();
67 
68  /*
69  cout << endl << "<I> Event number is " << j << endl;
70  cout << "<I> The total energy of the incident particle in this event is " << p4mom.E() << "\t" << "GeV" << endl;
71  cout << "<I> The kinetic energy of the incident particle in this event is " << p4mom.E()-p4mom.M() << "\t" << "GeV" << endl;
72  cout << "<I> The mass of the incident particle in this event is " << p4mom.M() << "\t" << "GeV/c2" << endl;
73  cout << "<I> The momentum of the incident particle in this event is " << p4mom.P() << "\t" << "GeV/c" << endl;
74  cout << "<I> The polar angle of the incident particle in this event is " << (180./TMath::Pi())*p4mom.Theta() << "\t" << "Degrees" << endl;
75  cout << "<I> The azimuthal angle of the incident particle in this event is " << (180./TMath::Pi())*p4mom.Phi() << "\t" << "Degrees" << endl;
76  cout << "<I> Number of clusters found is " << cluster_array->GetEntriesFast() << endl;
77  */
78 
79  tot_digi_energy_barrel=0;
80  tot_digi_energy_fwendcap=0;
81  tot_digi_energy_bwendcap=0;
82  tot_hit_energy=0;
83  for (Int_t i=0; i<digi_array->GetEntriesFast(); i++)
84  {
85  PndEmcDigi *digi=(PndEmcDigi*)digi_array->At(i);
87  Int_t detid=digi->GetDetectorId()/100000000;
88  //cout << digi->GetDetectorId() << "/" << detid << endl;
89  if (detid==3)
90  {
91  tot_digi_energy_fwendcap+=digi_energy;
92  }
93  else if (detid==4)
94  {
95  tot_digi_energy_bwendcap+=digi_energy;
96  }
97  else
98  {
99  tot_digi_energy_barrel+=digi_energy;
100  }
101 
102  }
103  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
104  {
105  PndEmcHit *hit=(PndEmcHit*)hit_array->At(i);
107  tot_hit_energy+=hit_energy;
108  }
109 
110  if (cluster_array->GetEntriesFast()>0)
111  {
112  Int_t idWithHighestEnergy = 0;
113  Double_t highestEnergy = -1.;
114 
115  // First find the cluster with the highest energy
116 
117  for (Int_t i=0; i<cluster_array->GetEntriesFast(); i++)
118  {
119  PndEmcCluster *cluster=(PndEmcCluster*)cluster_array->At(i);
120  cluster_energy=cluster->energy();
121  if (cluster_energy>highestEnergy)
122  {
123  idWithHighestEnergy = i;
124  highestEnergy = cluster_energy;
125  }
126 
127  }
128 
129  // Lets analyze that cluster!
130 
131 
132 
133  PndEmcCluster *cluster=(PndEmcCluster*)cluster_array->At(idWithHighestEnergy);
134 /*
135  std::vector<PndEmcDigi*> digiList=cluster->DigiList();
136  ndigi=digiList.size();
137  ndigi=0;
138 
139  cluster_energy_check=0;
140  digi_low=digiList[0]->GetEnergy();
141  digi_high=digiList[0]->GetEnergy();
142  Int_t digi_high_id=0;
143  for (Int_t k=0; k<ndigi; k++)
144  {
145  cluster_energy_check+=digiList[k]->GetEnergy();
146 
147  if (digiList[k]->GetEnergy()<digi_low)
148  {
149  digi_low=digiList[k]->GetEnergy();
150  }
151  if (digiList[k]->GetEnergy()>digi_high)
152  {
153  digi_high=digiList[k]->GetEnergy();
154  digi_high_id=k;
155  }
156  }
157 
158  theta_digi=digiList[digi_high_id]->GetTheta();
159  phi_digi=digiList[digi_high_id]->GetPhi();
160 */
161  TVector3 cluster_pos=cluster->where();
162  cluster_theta=cluster_pos.Theta();
163  cluster_phi=cluster_pos.Phi();
164  cluster_energy=cluster->energy();
165 
166  /*
167  cout << "<I> E = " << cluster_energy << endl;
168  cout << "<I> Theta = " << cluster_theta*(180/TMath::Pi()) << endl;
169  cout << "<I> Phi = " << cluster_phi*(180/TMath::Pi()) << endl;
170  cout << "<I> Nr of crystals = " << ndigi << endl;
171  cout << "<I> Dets (Edep): ";
172  */
173 
174 
175  n->Fill((Float_t) p4mom.E()-p4mom.M(),
176  (Float_t) (180./TMath::Pi())*p4mom.Theta(),
177  (Float_t) (180./TMath::Pi())*p4mom.Phi(),
178  (Float_t) cluster_energy,
179  (Float_t) cluster_theta*(180/TMath::Pi()),
180  (Float_t) cluster_phi*(180/TMath::Pi()),
181  (Float_t) cluster_array->GetEntriesFast(),
182  (Float_t) ndigi,
183  (Float_t) tot_digi_energy_barrel,
184  (Float_t) tot_digi_energy_fwendcap,
185  (Float_t) tot_digi_energy_bwendcap,
186  (Float_t) tot_hit_energy,
187  (Float_t) cluster_energy_check,
188  (Float_t) theta_digi*(180/TMath::Pi()),
189  (Float_t) phi_digi*(180/TMath::Pi()));
190  }
191  }
192  fs->Write();
193  return;
194 }
195 
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
void reco_analys(Char_t InputSimFile[]="sim_emc.root", Char_t OutputFile[]="output.root")
TClonesArray * digi
TVector3 where() const
virtual Double_t GetEnergy() const
Definition: PndEmcDigi.cxx:296
represents the reconstructed hit of one emc crystal
Definition: PndEmcDigi.h:40
Int_t i
Definition: run_full.C:25
Int_t GetDetectorId() const
Definition: PndEmcDigi.h:97
TClonesArray * digi_array
int n
TLorentzVector Get4Momentum() const
Definition: PndMCTrack.cxx:102
TClonesArray * hit_array
Double_t cluster_theta
TClonesArray * cluster_array
Double_t
virtual Double_t GetEnergy() const
Definition: PndEmcHit.h:54
PndMCTrack * track
Definition: anaLmdCluster.C:89
Double_t cluster_energy
TFile * f
Definition: bump_analys.C:12
Double_t cluster_phi
a cluster (group of neighboring crystals) of hit emc crystals
Definition: PndEmcCluster.h:29
represents the deposited energy of one emc crystal from simulation
Definition: PndEmcHit.h:26
virtual Double_t energy() const
TClonesArray * track_array
Definition: plot_rk.C:34
PndSdsMCPoint * hit
Definition: anasim.C:70
TLorentzVector p4mom
Double_t Pi
double digi_energy
Definition: digi_analys.C:17
double hit_energy
Definition: digi_analys.C:17