2 #if !defined(__CINT__) || defined(__MAKECINT__)
5 //#include <Riostream.h>
10 #include <TRefArray.h>
12 //AliRoot include files
13 #include "AliRunLoader.h"
15 #include "AliESDEvent.h"
16 #include "AliESDVertex.h"
17 #include "AliESDCaloCluster.h"
18 #include "AliESDCaloCells.h"
19 #include "AliESDCaloTrigger.h"
21 #include "AliEMCALGeometry.h"
25 //Change the bool depending on what information you want to print
26 // when all FALSE, prints minimum cluster information.
27 Bool_t kPrintKine = kFALSE; //Do not use for raw data.
28 Bool_t kPrintCaloCells = kFALSE;
29 Bool_t kPrintCaloTrigger = kFALSE;
30 Bool_t kPrintTrackMatches = kFALSE;
31 Bool_t kPrintClusterCells = kFALSE;
32 Bool_t kPrintClusterPID = kFALSE;
35 // Main method to read information stored in AliESDCaloClusters and AliESDCaloCells
37 // Init some example histograms
39 TH1F * hEta = (TH1F*) new TH1F("hEta","reco eta",1000, -0.71,0.71);
40 TH1F * hPhi = (TH1F*) new TH1F("hPhi","reco phi",130, 70,200);
41 TH1F * hE = (TH1F*) new TH1F("hE" ,"reco e",300, 0,30);
42 TH1F * hTime = (TH1F*) new TH1F("hTime" ,"reco time",1000, 0,1000);
43 hEta ->SetXTitle("#eta");
44 hPhi ->SetXTitle("#phi (deg)");
45 hE ->SetXTitle("E (GeV)");
46 hTime->SetXTitle("time (ns)");
49 TH1F * hMCEta = (TH1F*) new TH1F("hMCEta","MC eta",1000, -0.71,0.71);
50 TH1F * hMCPhi = (TH1F*) new TH1F("hMCPhi","MC phi",130, 70,200);
51 TH1F * hMCE = (TH1F*) new TH1F("hMCE" ,"MC e",300, 0,30);
52 hMCEta->SetXTitle("#eta");
53 hMCPhi->SetXTitle("#phi (deg)");
54 hMCE ->SetXTitle("E (GeV)");
57 TH1F * hDEta = (TH1F*) new TH1F("hDEta"," eta cluster - eta MC",500, -0.05,0.05);
58 TH1F * hDPhi = (TH1F*) new TH1F("hDPhi","phi cluster - phi MC",200, -20,20);
59 TH1F * hDE = (TH1F*) new TH1F("hDE" ,"e cluster - e MC",200, -10,10);
60 hDEta->SetXTitle("#eta_{reco}-#eta_{MC}");
61 hDPhi->SetXTitle("#phi_{reco}-#phi_{MC} (deg)");
62 hDE ->SetXTitle("E_{reco}-E_{MC} (GeV)");
64 //Open the ESD file, get the tree with events
65 TFile* f = new TFile("AliESDs.root");
66 TTree* esdTree = (TTree*)f->Get("esdTree");
67 AliESDEvent* esd = new AliESDEvent();
68 esd->ReadFromTree(esdTree);
70 //Init geometry and array that will contain the clusters
71 TRefArray* caloClusters = new TRefArray();
72 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance("EMCAL_FIRSTYEAR") ;
76 Int_t nEvt = esdTree->GetEntries();
77 for(Int_t iev = 0; iev < nEvt; iev++) {
78 cout << "<<<< Event: " << iev+1 << "/" << nEvt << " >>>>"<<endl;
79 esdTree->GetEvent(iev);
81 //Pass the geometry transformation matrix from ESDs to geometry
82 for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
83 //printf("matrix %d\n",mod);
84 if(esd->GetEMCALMatrix(mod)) {
85 //printf("EMCAL: mod %d, matrix %p\n",mod, esd->GetEMCALMatrix(mod));
86 //(esd->GetEMCALMatrix(mod))->Print("");
87 geom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
91 //In case you want to play with MC data, get stack
94 AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(), "read");
100 //get reconstructed vertex position
101 Double_t vertex_position[3];
102 esd->GetVertex()->GetXYZ(vertex_position);
104 //------------------------------------------------------
105 //Get Cells Array, all cells in event, print cells info
106 //------------------------------------------------------
107 AliVCaloCells &cells= *(esd->GetEMCALCells());
108 //AliESDCaloCells &cells= *(esd->GetEMCALCells());
111 Int_t nTotalCells = cells.GetNumberOfCells() ;
112 //Int_t type = cells.GetType();
113 for (Int_t icell= 0; icell < nTotalCells; icell++) {
114 cout<<"Cell : "<<icell<<"/"<<nTotalCells<<" ID: "<<cells.GetCellNumber(icell)<<" Amplitude: "<<cells.GetAmplitude(icell)<<" Time: "<<cells.GetTime(icell)*1e9<<endl;
118 //------------------------------------------------------
120 //------------------------------------------------------
122 if(kPrintCaloTrigger)
124 AliESDCaloTrigger& trg = *(esd->GetCaloTrigger("EMCAL"));
130 trg.GetPosition(posX, posY);
132 if (posX > -1 && posY > -1)
135 trg.GetL1TimeSum(ts);
137 cout << "Position: " << posX << " " << posY << " L1 amplitude: " << ts << endl;
142 //------------------------------------------------------
144 //------------------------------------------------------
146 //Get CaloClusters Array
147 caloClusters->Clear();
148 esd->GetEMCALClusters(caloClusters);
151 Int_t nclus = caloClusters->GetEntries();
152 for (Int_t icl = 0; icl < nclus; icl++) {
154 AliVCluster* clus = (AliVCluster*)caloClusters->At(icl);
155 //AliESDCluster* clus = (AliESDCluster*)caloClusters->At(icl);
156 Float_t energy = clus->E();
157 clus->GetPosition(pos);
158 TVector3 vpos(pos[0],pos[1],pos[2]);
160 //We can get a momentum TLorentzVector per cluster, corrected by the vertex position
162 //clus->GetMomentum(p,vertex_position);
164 Double_t cphi = vpos.Phi();
165 if(cphi < 0) cphi +=TMath::TwoPi();
166 Double_t ceta = vpos.Eta();
168 Int_t nMatched = clus->GetNTracksMatched();
169 Int_t trackIndex = clus->GetTrackMatchedIndex();
170 Int_t nLabels = clus->GetNLabels();
171 Int_t labelIndex = clus->GetLabel();
172 Int_t nCells = clus->GetNCells();
174 //Fill some histograms
176 hPhi->Fill(cphi*TMath::RadToDeg());
178 hTime->Fill(clus->GetTOF()*1e9);
180 //Print basic cluster information
181 cout << "Cluster: " << icl+1 << "/" << nclus << " Energy: " << energy << "; Phi: "
182 << cphi*TMath::RadToDeg() << "; Eta: " << ceta << "; NCells: " << nCells << " ;#Matches: " << nMatched
183 << "; Index: " << trackIndex << "; #Labels: " << nLabels << " Index: "
184 << labelIndex << "; Time "<<clus->GetTOF()*1e9<<" ns "<<endl;
187 if(stack && kPrintKine) {
188 if(labelIndex >= 0 && labelIndex < stack->GetNtrack()){
189 TParticle * particle = stack->Particle(labelIndex);
190 //Fill histograms with primary info
191 hMCEta->Fill(particle->Eta());
192 hMCPhi->Fill(particle->Phi()*TMath::RadToDeg());
193 hMCE ->Fill(particle->Energy());
194 hDEta ->Fill(ceta-particle->Eta());
195 hDPhi ->Fill(cphi*TMath::RadToDeg()-particle->Phi()*TMath::RadToDeg());
196 hDE ->Fill(energy-particle->Energy());
197 //Print primary values
198 cout<<" More contributing primary: "<<particle->GetName()<<"; with kinematics: "<<endl;
199 cout<<" \t Energy: "<<particle->Energy()<<"; Phi: "<<particle->Phi()*TMath::RadToDeg()<<"; Eta: "<<particle->Eta()<<endl;
200 for(Int_t i = 1; i < nLabels; i++){
201 //particle = stack->Particle((((AliESDCaloCluster*)clus)->GetLabelsArray())->At(i));
202 particle = stack->Particle((clus->GetLabels())[i]);
203 //or Int_t *labels = clus->GetLabels();
204 //particle = stack->Particle(labels[i]);
205 cout<<" Other contributing primary: "<<particle->GetName()<< "; Energy "<<particle->Energy()<<endl;
208 else if( labelIndex >= stack->GetNtrack()) cout <<"PROBLEM, label is too large : "<<labelIndex<<" >= particles in stack "<< stack->GetNtrack() <<endl;
209 else cout<<"Negative label!!! : "<<labelIndex<<endl;
213 if(kPrintTrackMatches && trackIndex >= 0) {
214 AliESDtrack* track = esd->GetTrack(trackIndex);
215 Double_t tphi = track->GetOuterParam()->Phi();
216 Double_t teta = track->GetOuterParam()->Eta();
217 Double_t tmom = track->GetOuterParam()->P();
218 cout << "\t Track Momentum: " << tmom << " phi: " << tphi << " eta: " << teta << endl;
220 Double_t deta = teta - ceta;
221 Double_t dphi = tphi - cphi;
222 if(dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
223 if(dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
224 Double_t dR = sqrt(dphi*dphi + deta*deta);
226 Double_t pOverE = tmom/energy;
228 if(dR < 0.02 && pOverE < 1.8 && nCells > 1) {
229 cout << "\n\t Excellent MATCH! dR = " << dR << " p/E = " << pOverE << " nCells = " << nCells << endl;
233 //Get PID weights and print them
234 if(kPrintClusterPID){
235 const Double_t *pid = clus->GetPID();
236 printf("PID weights: ph %0.2f, pi0 %0.2f, el %0.2f, conv el %0.2f, hadrons: pion %0.2f, kaon %0.2f, proton %0.2f , neutron %0.2f, kaon %0.2f \n",
237 pid[AliVCluster::kPhoton], pid[AliVCluster::kPi0],
238 pid[AliVCluster::kElectron], pid[AliVCluster::kEleCon],
239 pid[AliVCluster::kPion], pid[AliVCluster::kKaon], pid[AliVCluster::kProton],
240 pid[AliVCluster::kNeutron], pid[AliVCluster::kKaon0]);
243 //Get CaloCells of cluster and print their info, position.
244 if(kPrintClusterCells){
245 UShort_t * index = clus->GetCellsAbsId() ;
246 Double_t * fraction = clus->GetCellsAmplitudeFraction() ;
248 for(Int_t i = 0; i < nCells ; i++){
249 Int_t absId = index[i]; // or clus->GetCellNumber(i) ;
250 Double_t ampFract = fraction[i];
251 Float_t amp = cells.GetCellAmplitude(absId) ;
252 Double_t time = cells.GetCellTime(absId);
253 cout<<"\t Cluster Cell: AbsID : "<< absId << " == "<<clus->GetCellAbsId(i) <<"; Amplitude "<< amp << "; Fraction "<<ampFract<<"; Time " <<time*1e9<<endl;
262 geom->GetCellIndex(absId,iSupMod,iTower,iIphi,iIeta);
263 //Gives SuperModule and Tower numbers
264 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
265 iIphi, iIeta,iphi,ieta);
266 //Gives label of cell in eta-phi position per each supermodule
269 geom->EtaPhiFromIndex(absId,cellEta,cellPhi);
270 cout<< " SModule "<<iSupMod<<"; Tower "<<iTower <<"; Eta "<<iIeta
271 <<"; Phi "<<iIphi<<"; Index: Cell Eta "<<ieta<<"; Cell Phi "<<iphi
272 <<"; Global: Cell Eta "<<cellEta<<"; Cell Phi "<<cellPhi*TMath::RadToDeg()<<endl;
273 if(i==0) sm = iSupMod;
275 if(sm!=iSupMod) printf("******CLUSTER SHARED BY 2 SuperModules!!!!\n");
278 }// cluster cell loop
279 }// print cell clusters
284 //Write histograms in a file
285 TFile * fhisto = (TFile*) new TFile("histos.root","recreate");