PartCorr split in 2 Base and Dep; coding violations corrected; PHOS geometry can...
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliCaloTrackESDReader.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16 /* $Id:  $ */
17
18 //_________________________________________________________________________
19 // Class for reading data (ESDs) in order to do prompt gamma 
20 // or other particle identification and correlations
21 //
22 //
23 //*-- Author: Gustavo Conesa (LNF-INFN) 
24 //////////////////////////////////////////////////////////////////////////////
25
26
27 // --- ROOT system ---
28 //#include "Riostream.h"
29
30 //---- ANALYSIS system ----
31 #include "AliCaloTrackESDReader.h" 
32 #include "AliESDEvent.h"
33 #include "AliESDVertex.h"
34 #include "AliESDCaloCluster.h"
35 #include "AliAODCaloCluster.h"
36 #include "AliAODTrack.h"
37 #include "AliAODEvent.h"
38 #include "AliMCEvent.h"
39 #include "AliLog.h"
40
41 ClassImp(AliCaloTrackESDReader)
42
43 //____________________________________________________________________________
44 AliCaloTrackESDReader::AliCaloTrackESDReader() : 
45 AliCaloTrackReader()
46 {
47         //Default Ctor
48         
49         //Initialize parameters
50         fDataType=kESD;
51         
52 }
53
54 //____________________________________________________________________________
55 AliCaloTrackESDReader::AliCaloTrackESDReader(const AliCaloTrackESDReader & g) :   
56 AliCaloTrackReader(g)
57 {
58         // cpy ctor
59 }
60
61 //_________________________________________________________________________
62 //AliCaloTrackESDReader & AliCaloTrackESDReader::operator = (const AliCaloTrackESDReader & source)
63 //{
64 //      // assignment operator
65 //      
66 //      if(&source == this) return *this;
67 //      
68 //      return *this;
69 //      
70 //}
71
72 //____________________________________________________________________________
73 void AliCaloTrackESDReader::FillInputCTS() {
74         //Return array with CTS tracks
75         
76         fAODCTS = new TClonesArray("AliAODTrack",0);
77         
78         Int_t nTracks   = fESD->GetNumberOfTracks() ;
79         Int_t naod = 0;
80         Double_t pos[3];
81         Double_t p[3];
82         Double_t covTr[21];
83         Double_t pid[10];
84         for (Int_t itrack =  0; itrack <  nTracks; itrack++) {////////////// track loop
85                 AliESDtrack * track = fESD->GetTrack(itrack) ; // retrieve track from esd
86                 
87                 //We want tracks fitted in the detectors:
88                 ULong_t status=AliESDtrack::kTPCrefit;
89                 status|=AliESDtrack::kITSrefit;
90                 
91                 if ( (track->GetStatus() & status) == status) {//Check if the bits we want are set
92                         
93                         track->GetPxPyPz(p) ;
94                         TLorentzVector momentum(p[0],p[1],p[2],0);
95                         
96                         if(fCTSPtMin < momentum.Pt() &&fFidutialCut->IsInFidutialCut(momentum,"CTS")){
97                                 
98                                 if(fDebug > 3 && momentum.Pt() > 0.2)printf("FillInputCTS():: Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
99                                                                                                                         momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
100                                 
101                                 track->GetXYZ(pos);
102                                 track->GetCovarianceXYZPxPyPz(covTr);
103                                 track->GetESDpid(pid);
104                                 
105                                 Float_t impactXY, impactZ;
106                                 
107                                 track->GetImpactParameters(impactXY,impactZ);
108                                 
109                                 if (impactXY<3) {
110                                         // track inside the beam pipe
111                                         
112                                         AliAODTrack *aodTrack = new((*fAODCTS)[naod++]) 
113                                         AliAODTrack(track->GetID(), track->GetLabel(), p, kTRUE, pos, kFALSE,covTr, (Short_t)track->GetSign(), track->GetITSClusterMap(), 
114                                                                 pid,
115                                                                 0x0,//primary,
116                                                                 kTRUE, // check if this is right
117                                                                 kTRUE, // check if this is right
118                                                                 AliAODTrack::kPrimary, 
119                                                                 0);
120                                         
121                                         aodTrack->SetFlags(track->GetStatus());
122                                         aodTrack->ConvertAliPIDtoAODPID();
123                                 }
124                                 else continue;   // outside the beam pipe: orphan track 
125                         }//Pt and Fidutial cut passed. 
126                 }// track status
127         }// track loop
128         if(fDebug > 1) printf("FillInputCTS():: aod entries %d\n", fAODCTS->GetEntriesFast());
129 }
130
131 //____________________________________________________________________________
132 void AliCaloTrackESDReader::FillInputEMCAL() {
133         //Return array with EMCAL clusters in aod format
134         
135         fAODEMCAL = new TClonesArray("AliAODCaloCluster",0);
136         
137         TRefArray * caloClusters = new TRefArray();
138         fESD->GetEMCALClusters(caloClusters);
139         
140         //Get vertex for momentum calculation  
141         Double_t v[3] ; //vertex ;
142         GetVertex(v);
143         
144         //Loop to select clusters in fidutial cut and fill container with aodClusters
145         Int_t naod = 0;
146         Float_t pos[3] ;
147         //   Double_t * pid = new Double_t[AliPID::kSPECIESN];
148         
149         for (Int_t iclus =  0; iclus <  caloClusters->GetEntriesFast(); iclus++) {
150                 AliESDCaloCluster * clus = (AliESDCaloCluster *) caloClusters->At(iclus) ;
151                 TLorentzVector momentum ;
152                 clus->GetMomentum(momentum, v);      
153                 if(fDebug > 3 && momentum.E() > 0.1)printf("FillInputEMCAL():: all clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
154                                                                                                    momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta()); 
155                 if(fEMCALPtMin < momentum.Pt() && fFidutialCut->IsInFidutialCut(momentum,"EMCAL")){
156                         
157                         if(fDebug > 2 && momentum.E() > 0.2)printf("FillInputEMCAL():: Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
158                                                                                                            momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
159                         //       pid=clus->GetPid();      
160                         clus->GetPosition(pos) ;
161                         //       printf("Reader PID ESD: ph %0.2f, pi0 %0.2f, el %0.2f, conv el %0.2f,pi %0.2f, k %0.2f, p %0.2f, k0 %0.2f, n %0.2f, mu %0.2f \n",
162                         //           pid[AliPID::kPhoton],pid[AliPID::kPi0],
163                         //           pid[AliPID::kElectron],pid[AliPID::kEleCon],pid[AliPID::kPion],
164                         //           pid[AliPID::kKaon],pid[AliPID::kProton], pid[AliPID::kKaon0],
165                         //           pid[AliPID::kNeutron], pid[AliPID::kMuon]);
166                         Int_t id = clus->GetID();
167                         Int_t nLabel = clus->GetNLabels();
168                         Int_t *labels=0x0;
169                         if(clus->GetLabels()) labels =  (clus->GetLabels())->GetArray();
170                         
171                         Float_t energy = clus->E();
172                         Char_t ttype= AliAODCluster::kEMCALClusterv1;
173                         AliAODCaloCluster *caloCluster = new((*fAODEMCAL)[naod++]) 
174                         AliAODCaloCluster(id,nLabel,labels,energy, pos, NULL,ttype,0);
175                         
176                         caloCluster->SetPIDFromESD(clus->GetPid());
177                         caloCluster->SetCaloCluster(clus->GetDistanceToBadChannel(), clus->GetClusterDisp(), 
178                                                                                 clus->GetM20(), clus->GetM02(),   
179                                                                                 clus->GetEmcCpvDistance(),  clus->GetNExMax(), clus->GetTOF()) ;
180                                                                                 
181                                                                                         
182                         if(fDebug > 3 && momentum.E() > 0.2)
183                                 printf("FillInputEMCAL():: Selected clusters Distance BC %2.2f, dispersion %2.2f, M20 %f, M02 %3.2f, NexMax %d, TOF %e\n",
184                                                 clus->GetDistanceToBadChannel(), clus->GetClusterDisp(),clus->GetM20(), clus->GetM02(),
185                                                 clus->GetNExMax(), clus->GetTOF());
186                                                                                 
187                         caloCluster->SetNCells(clus->GetNCells());
188                         caloCluster->SetCellsAbsId(clus->GetCellsAbsId());
189                         caloCluster->SetCellsAmplitudeFraction(clus->GetCellsAmplitudeFraction());
190                         
191                         TArrayI* matchedT =     clus->GetTracksMatched();
192                         if (matchedT && clus->GetTrackMatched() > 0) {  
193                                 for (Int_t im = 0; im < matchedT->GetSize(); im++) {
194                                         caloCluster->AddTrackMatched((fESD->GetTrack(im)));
195                                 }
196                         }
197                         
198                 }//Pt and Fidutial cut passed.
199         }//esd cluster loop
200         
201         if(fDebug > 1) printf("FillInputEMCAL():: aod entries %d\n", fAODEMCAL->GetEntriesFast());
202         
203 }
204
205 //____________________________________________________________________________
206 void AliCaloTrackESDReader::FillInputPHOS() {
207         //Return array with PHOS clusters in aod format
208         fAODPHOS = new TClonesArray("AliAODCaloCluster",0);
209         
210         TRefArray * caloClusters = new TRefArray();
211         fESD->GetPHOSClusters(caloClusters);
212         
213         //Get vertex for momentum calculation  
214         Double_t v[3] ; //vertex ;
215         GetVertex(v);
216         
217         //Loop to select clusters in fidutial cut and fill container with aodClusters
218         Int_t naod = 0;
219         Float_t pos[3] ;
220         Double_t * pid = new Double_t[AliPID::kSPECIESN];
221         
222         for (Int_t iclus =  0; iclus <  caloClusters->GetEntriesFast(); iclus++) {
223                 AliESDCaloCluster * clus = (AliESDCaloCluster *) caloClusters->At(iclus) ;
224                 TLorentzVector momentum ;
225                 clus->GetMomentum(momentum, v);      
226                 if(fDebug > 3 && momentum.E() > 0.1)printf("FillInputPHOS():: all clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
227                                                                                                    momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
228                 if(fPHOSPtMin < momentum.Pt() && fFidutialCut->IsInFidutialCut(momentum,"PHOS")){
229                         
230                         if(fDebug > 2 && momentum.E() > 0.1)printf("FillInputPHOS():: Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
231                                                                                                            momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
232                         
233                         pid=clus->GetPid();      
234                         // printf("Reader PID ESD: ph %0.2f, pi0 %0.2f, el %0.2f, conv el %0.2f,pi %0.2f, k %0.2f, p %0.2f, k0 %0.2f, n %0.2f, mu %0.2f \n",
235                         //       pid[AliPID::kPhoton],pid[AliPID::kPi0],
236                         //       pid[AliPID::kElectron],pid[AliPID::kEleCon],pid[AliPID::kPion],
237                         //       pid[AliPID::kKaon],pid[AliPID::kProton], pid[AliPID::kKaon0],
238                         //       pid[AliPID::kNeutron], pid[AliPID::kMuon]);
239                         
240                         clus->GetPosition(pos) ;
241                         Int_t id = clus->GetID();
242                         Int_t nLabel = clus->GetNLabels();
243                         Int_t *labels=0x0;
244                         if(clus->GetLabels()) labels =  (clus->GetLabels())->GetArray();
245                         Float_t energy = clus->E();
246                         
247                         //Phos cluster type
248                         Char_t ttype= AliAODCluster::kPHOSNeutral;
249                         Float_t wNeutral = pid[AliPID::kNeutron]+ pid[AliPID::kKaon0]+pid[AliPID::kPhoton]+pid[AliPID::kPi0];
250                         Float_t wCharged = pid[AliPID::kMuon] + pid[AliPID::kElectron] + pid[AliPID::kEleCon]+ 
251                         pid[AliPID::kProton]+pid[AliPID::kKaon]+pid[AliPID::kPion];
252                         if( wCharged > wNeutral)  ttype= AliAODCluster::kPHOSCharged;
253                         
254                         AliAODCaloCluster *caloCluster = new((*fAODPHOS)[naod++]) 
255                         AliAODCaloCluster(id,nLabel,labels,energy, pos, NULL, ttype, 0);
256                         caloCluster->SetPIDFromESD(clus->GetPid());   
257                         caloCluster->SetCaloCluster(clus->GetDistanceToBadChannel(), clus->GetClusterDisp(), 
258                                                                                 clus->GetM20(), clus->GetM02(),  
259                                                                                 clus->GetEmcCpvDistance(),  clus->GetNExMax()) ;
260                                                                                 
261                         if(fDebug > 3 && momentum.E() > 0.2)
262                                 printf("FillInputPHOS():: Selected clusters Distance BC %2.2f, dispersion %2.2f, M20 %f, M02 %3.2f, EmcCpvDist %3.3f, NexMax %d, TOF %e\n",
263                                                 clus->GetDistanceToBadChannel(), clus->GetClusterDisp(),clus->GetM20(), clus->GetM02(),
264                                                 clus->GetEmcCpvDistance(),  clus->GetNExMax(), clus->GetTOF());
265
266                         caloCluster->SetNCells(clus->GetNCells());
267                         caloCluster->SetCellsAbsId(clus->GetCellsAbsId());
268                         caloCluster->SetCellsAmplitudeFraction(clus->GetCellsAmplitudeFraction());
269                         TArrayI* matchedT =     clus->GetTracksMatched();
270                         if (matchedT) { 
271                                 for (Int_t im = 0; im < matchedT->GetSize(); im++) {
272                                         caloCluster->AddTrackMatched((fESD->GetTrack(im)));
273                                 }
274                         }
275                         
276                 }//Pt and Fidutial cut passed.
277         }//esd cluster loop
278         if(fDebug > 1) printf("FillInputPHOS():: aod entries %d\n", fAODPHOS->GetEntriesFast());
279         
280         
281 }
282
283 //____________________________________________________________________________
284 void AliCaloTrackESDReader::FillInputEMCALCells() {
285         //Return array with EMCAL cells in esd format
286         
287         fEMCALCells = (TNamed*) fESD->GetEMCALCells(); 
288         
289 }
290
291 //____________________________________________________________________________
292 void AliCaloTrackESDReader::FillInputPHOSCells() {
293         //Return array with PHOS cells in esd format
294         
295         fPHOSCells = (TNamed*) fESD->GetPHOSCells(); 
296         
297 }
298
299 //____________________________________________________________________________
300 void AliCaloTrackESDReader::GetVertex(Double_t  v[3]) const {
301         //Return vertex position
302         
303         fESD->GetVertex()->GetXYZ(v) ;
304         
305 }
306
307
308 //____________________________________________________________________________
309 void AliCaloTrackESDReader::SetInputEvent(TObject* esd, TObject* aod, TObject* mc) {
310         // Connect the data pointers
311         
312         if(strcmp(esd->GetName(),"AliESDEvent"))
313                 AliFatal(Form("Wrong reader, here only ESDs. Input name: %s != AliESDEvent \n",esd->GetName()));
314         
315         SetESD((AliESDEvent*) esd);
316         SetAOD ((AliAODEvent*) aod);
317         SetMC((AliMCEvent*) mc);
318         
319 }