]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/CaloCalib/AliAnalysisTaskCaloFilter.cxx
Fix to reduce the number of events that are wrongly identified as pile-up (GM Innocen...
[u/mrichter/AliRoot.git] / PWG4 / CaloCalib / AliAnalysisTaskCaloFilter.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: AliAnalysisTaskCaloFilter.cxx $ */
17
18 //////////////////////////////////////////////////////////
19 // Filter the ESDCaloClusters and ESDCaloCells of EMCAL,
20 // PHOS or both, creating the corresponing AODCaloClusters
21 // and AODCaloCells.
22 // Keep also the AODHeader information and the vertex.
23 // Needed for calorimeter calibration.
24 // Copy of AliAnalysisTaskESDfilter.
25 // Author: Gustavo Conesa Balbastre (INFN - Frascati)
26 //////////////////////////////////////////////////////////
27
28 #include "AliAnalysisTaskCaloFilter.h"
29 #include "AliESDEvent.h"
30 #include "AliAODEvent.h"
31 #include "AliESDCaloCluster.h"
32 #include "AliESDCaloCells.h"
33 #include "AliLog.h"
34
35 ClassImp(AliAnalysisTaskCaloFilter)
36   
37 ////////////////////////////////////////////////////////////////////////
38
39 AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter():
40   AliAnalysisTaskSE(),
41   fCalorimeter("EMCAL PHOS")
42 {
43   // Default constructor
44 }
45
46 //__________________________________________________
47 AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter(const char* name):
48   AliAnalysisTaskSE(name),
49   fCalorimeter("EMCAL PHOS")
50 {
51   // Constructor
52 }
53
54 //__________________________________________________
55 void AliAnalysisTaskCaloFilter::CreateAODFromAOD()
56 {
57
58   // Copy AOD header, vertex, CaloClusters and CaloCells to output AOD
59   
60   AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
61   
62   // set arrays and pointers
63   Float_t posF[3];
64   Double_t pos[3];
65   
66   Double_t covVtx[6];
67   
68   for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
69   
70   // Update the header
71    AliAODHeader* headerin = aod->GetHeader();
72   AliAODHeader* header = AODEvent()->GetHeader();
73   header->SetRunNumber(headerin->GetRunNumber());
74   header->SetBunchCrossNumber(headerin->GetBunchCrossNumber());
75   header->SetOrbitNumber(headerin->GetOrbitNumber());
76   header->SetPeriodNumber(headerin->GetPeriodNumber());
77   header->SetEventType(headerin->GetEventType());
78   header->SetMuonMagFieldScale(headerin->GetMuonMagFieldScale()); // FIXME
79   header->SetCentrality(headerin->GetCentrality());        // FIXME
80   
81   
82   header->SetTriggerMask(headerin->GetTriggerMask()); 
83   header->SetTriggerCluster(headerin->GetTriggerCluster());
84   header->SetMagneticField(headerin->GetMagneticField());
85   header->SetZDCN1Energy(headerin->GetZDCN1Energy());
86   header->SetZDCP1Energy(headerin->GetZDCP1Energy());
87   header->SetZDCN2Energy(headerin->GetZDCN2Energy());
88   header->SetZDCP2Energy(headerin->GetZDCP2Energy());
89   header->SetZDCEMEnergy(headerin->GetZDCEMEnergy(0),headerin->GetZDCEMEnergy(1));
90   Float_t diamxy[2]={aod->GetDiamondX(),aod->GetDiamondY()};
91   Float_t diamcov[3]; aod->GetDiamondCovXY(diamcov);
92   header->SetDiamond(diamxy,diamcov);
93   //
94   //
95   Int_t nVertices = 1 ;/* = prim. vtx*/;
96   Int_t nCaloClus = aod->GetNCaloClusters();
97   
98   AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
99   
100   // Access to the AOD container of vertices
101   TClonesArray &vertices = *(AODEvent()->GetVertices());
102   Int_t jVertices=0;
103   
104   // Add primary vertex. The primary tracks will be defined
105   // after the loops on the composite objects (V0, cascades, kinks)
106   const AliAODVertex *vtx = aod->GetPrimaryVertex();
107   
108   vtx->GetXYZ(pos); // position
109   vtx->GetCovMatrix(covVtx); //covariance matrix
110   
111   AliAODVertex * primary = new(vertices[jVertices++])
112     AliAODVertex(pos, covVtx, vtx->GetChi2perNDF(), NULL, -1, AliAODVertex::kPrimary);
113   primary->SetName(vtx->GetName());
114   primary->SetTitle(vtx->GetTitle());
115   
116   // Access to the AOD container of clusters
117   TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
118   Int_t jClusters=0;
119   
120   for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {
121     
122     AliAODCaloCluster * cluster = aod->GetCaloCluster(iClust);
123     
124     //Check which calorimeter information we want to keep.
125     if     (fCalorimeter.Contains("PHOS")  && !fCalorimeter.Contains("EMCAL") && cluster->IsEMCALCluster()) continue ;
126     else if(fCalorimeter.Contains("EMCAL") && !fCalorimeter.Contains("PHOS")  && cluster->IsPHOSCluster())  continue ;
127     
128     Int_t id       = cluster->GetID();
129     Float_t energy = cluster->E();
130     cluster->GetPosition(posF);
131     Char_t ttype   = cluster->GetType(); 
132     
133     
134     AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) 
135       AliAODCaloCluster(id,
136                         0,
137                         0x0,
138                         energy,
139                         posF,
140                         NULL,
141                         ttype);
142     
143     caloCluster->SetCaloCluster(cluster->GetDistToBadChannel(),
144                                 cluster->GetDispersion(),
145                                 cluster->GetM20(), cluster->GetM02(),
146                                 cluster->GetEmcCpvDistance(),  
147                                 cluster->GetNExMax(),cluster->GetTOF()) ;
148     
149     caloCluster->SetPIDFromESD(cluster->PID());
150     caloCluster->SetNCells(cluster->GetNCells());
151     caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
152     caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
153     
154   } 
155   caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters      
156   // end of loop on calo clusters
157   
158   // fill EMCAL cell info
159   if (fCalorimeter.Contains("EMCAL") && aod->GetEMCALCells()) { // protection against missing ESD information
160     AliAODCaloCells &aodinEMcells = *(aod->GetEMCALCells());
161     Int_t nEMcell = aodinEMcells.GetNumberOfCells() ;
162     
163     AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
164     aodEMcells.CreateContainer(nEMcell);
165     aodEMcells.SetType(AliAODCaloCells::kEMCAL);
166     for (Int_t iCell = 0; iCell < nEMcell; iCell++) {      
167       aodEMcells.SetCell(iCell,aodinEMcells.GetCellNumber(iCell),aodinEMcells.GetAmplitude(iCell));
168     }
169     aodEMcells.Sort();
170   }
171   
172   // fill PHOS cell info
173   if (fCalorimeter.Contains("PHOS") && aod->GetPHOSCells()) { // protection against missing ESD information
174     AliAODCaloCells &aodinPHcells = *(aod->GetPHOSCells());
175     Int_t nPHcell = aodinPHcells.GetNumberOfCells() ;
176     
177     AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
178     aodPHcells.CreateContainer(nPHcell);
179     aodPHcells.SetType(AliAODCaloCells::kPHOS);
180     for (Int_t iCell = 0; iCell < nPHcell; iCell++) {      
181       aodPHcells.SetCell(iCell,aodinPHcells.GetCellNumber(iCell),aodinPHcells.GetAmplitude(iCell));
182     }
183     aodPHcells.Sort();
184   }
185   
186   
187   return;
188 }
189
190 //__________________________________________________
191 void AliAnalysisTaskCaloFilter::CreateAODFromESD()
192 {
193
194   // Copy ESD header, vertex, CaloClusters and CaloCells to output AOD
195   
196   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
197   
198   // set arrays and pointers
199   Float_t posF[3];
200   Double_t pos[3];
201   
202   Double_t covVtx[6];
203   
204   for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
205   
206   // Update the header
207   
208   AliAODHeader* header = AODEvent()->GetHeader();
209   header->SetRunNumber(esd->GetRunNumber());
210   header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
211   header->SetOrbitNumber(esd->GetOrbitNumber());
212   header->SetPeriodNumber(esd->GetPeriodNumber());
213   header->SetEventType(esd->GetEventType());
214   header->SetMuonMagFieldScale(-999.); // FIXME
215   header->SetCentrality(-999.);        // FIXME
216   
217   
218   header->SetTriggerMask(esd->GetTriggerMask()); 
219   header->SetTriggerCluster(esd->GetTriggerCluster());
220   header->SetMagneticField(esd->GetMagneticField());
221   header->SetZDCN1Energy(esd->GetZDCN1Energy());
222   header->SetZDCP1Energy(esd->GetZDCP1Energy());
223   header->SetZDCN2Energy(esd->GetZDCN2Energy());
224   header->SetZDCP2Energy(esd->GetZDCP2Energy());
225   header->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
226   Float_t diamxy[2]={esd->GetDiamondX(),esd->GetDiamondY()};
227   Float_t diamcov[3]; esd->GetDiamondCovXY(diamcov);
228   header->SetDiamond(diamxy,diamcov);
229   //
230   //
231   Int_t nVertices = 1 ;/* = prim. vtx*/;
232   Int_t nCaloClus = esd->GetNumberOfCaloClusters();
233   
234   AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
235   
236   // Access to the AOD container of vertices
237   TClonesArray &vertices = *(AODEvent()->GetVertices());
238   Int_t jVertices=0;
239   
240   // Add primary vertex. The primary tracks will be defined
241   // after the loops on the composite objects (V0, cascades, kinks)
242   const AliESDVertex *vtx = esd->GetPrimaryVertex();
243   
244   vtx->GetXYZ(pos); // position
245   vtx->GetCovMatrix(covVtx); //covariance matrix
246   
247   AliAODVertex * primary = new(vertices[jVertices++])
248     AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
249   primary->SetName(vtx->GetName());
250   primary->SetTitle(vtx->GetTitle());
251   
252   // Access to the AOD container of clusters
253   TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
254   Int_t jClusters=0;
255   
256   for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {
257     
258     AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
259     
260     //Check which calorimeter information we want to keep.
261     if     (fCalorimeter.Contains("PHOS")  && !fCalorimeter.Contains("EMCAL") && cluster->IsEMCAL()) continue ;
262     else if(fCalorimeter.Contains("EMCAL") && !fCalorimeter.Contains("PHOS")  && cluster->IsPHOS())  continue ;
263     
264     Int_t id       = cluster->GetID();
265     Float_t energy = cluster->E();
266     cluster->GetPosition(posF);
267     Char_t ttype   = AliAODCluster::kUndef; 
268     
269     if (cluster->GetClusterType() == AliESDCaloCluster::kPHOSCluster) {
270       ttype=AliAODCluster::kPHOSNeutral;
271     } 
272     else if (cluster->GetClusterType() == AliESDCaloCluster::kEMCALClusterv1) {
273       ttype = AliAODCluster::kEMCALClusterv1;
274     }
275     
276     
277     AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) 
278       AliAODCaloCluster(id,
279                         0,
280                         0x0,
281                         energy,
282                         posF,
283                         NULL,
284                         ttype);
285     
286     caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
287                                 cluster->GetClusterDisp(),
288                                 cluster->GetM20(), cluster->GetM02(),
289                                 cluster->GetEmcCpvDistance(),  
290                                 cluster->GetNExMax(),cluster->GetTOF()) ;
291     
292     caloCluster->SetPIDFromESD(cluster->GetPid());
293     caloCluster->SetNCells(cluster->GetNCells());
294     caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
295     caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
296     
297   } 
298   caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters      
299   // end of loop on calo clusters
300   
301   // fill EMCAL cell info
302   if (fCalorimeter.Contains("EMCAL") && esd->GetEMCALCells()) { // protection against missing ESD information
303     AliESDCaloCells &esdEMcells = *(esd->GetEMCALCells());
304     Int_t nEMcell = esdEMcells.GetNumberOfCells() ;
305     
306     AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
307     aodEMcells.CreateContainer(nEMcell);
308     aodEMcells.SetType(AliAODCaloCells::kEMCAL);
309     for (Int_t iCell = 0; iCell < nEMcell; iCell++) {      
310       aodEMcells.SetCell(iCell,esdEMcells.GetCellNumber(iCell),esdEMcells.GetAmplitude(iCell));
311     }
312     aodEMcells.Sort();
313   }
314   
315   // fill PHOS cell info
316   if (fCalorimeter.Contains("PHOS") && esd->GetPHOSCells()) { // protection against missing ESD information
317     AliESDCaloCells &esdPHcells = *(esd->GetPHOSCells());
318     Int_t nPHcell = esdPHcells.GetNumberOfCells() ;
319     
320     AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
321     aodPHcells.CreateContainer(nPHcell);
322     aodPHcells.SetType(AliAODCaloCells::kPHOS);
323     for (Int_t iCell = 0; iCell < nPHcell; iCell++) {      
324       aodPHcells.SetCell(iCell,esdPHcells.GetCellNumber(iCell),esdPHcells.GetAmplitude(iCell));
325     }
326     aodPHcells.Sort();
327   }
328   
329   
330   return;
331 }
332
333 //__________________________________________________
334 void AliAnalysisTaskCaloFilter::Init()
335 {
336   // Initialization
337   if (fDebug > 1) AliInfo("Init() \n");
338   
339 }
340
341 //__________________________________________________
342 void AliAnalysisTaskCaloFilter::UserCreateOutputObjects()
343 {
344   // Create the output container
345 }
346
347 //__________________________________________________
348 void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
349 {
350   // Execute analysis for current event
351   //
352   
353   Long64_t ientry = Entry();
354   if (fDebug > 0)  printf("CaloFilter: Analysing event # %5d\n", (Int_t) ientry);
355
356   const char * dataevent =InputEvent()->GetName();
357   if(!strcmp(dataevent,"AliAODEvent"))   CreateAODFromAOD();  
358   
359   else if(!strcmp(dataevent,"AliESDEvent"))  CreateAODFromESD();
360   else {
361     AliFatal(Form("Unknown event type %s, ABORT",dataevent));
362     
363   }
364
365 }
366
367 //__________________________________________________
368 void AliAnalysisTaskCaloFilter::Terminate(Option_t */*option*/)
369 {
370   // Terminate analysis
371   //
372     if (fDebug > 1) printf("AnalysisCaloFilter: Terminate() \n");
373 }
374