]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/CaloTasks/AliAnalysisTaskCaloFilter.cxx
updates from Fengchu
[u/mrichter/AliRoot.git] / PWGGA / CaloTasks / AliAnalysisTaskCaloFilter.cxx
CommitLineData
7a4cf423 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
7a4cf423 16//////////////////////////////////////////////////////////
17// Filter the ESDCaloClusters and ESDCaloCells of EMCAL,
18// PHOS or both, creating the corresponing AODCaloClusters
19// and AODCaloCells.
20// Keep also the AODHeader information and the vertex.
ea00d1fa 21// Keep tracks, v0s, VZERO if requested
22// Select events containing a cluster or track avobe a given threshold
7a4cf423 23// Copy of AliAnalysisTaskESDfilter.
24// Author: Gustavo Conesa Balbastre (INFN - Frascati)
25//////////////////////////////////////////////////////////
26
44cf05d7 27//Root
28#include "TGeoManager.h"
5994e71f 29#include "TFile.h"
5994e71f 30#include "TROOT.h"
31#include "TInterpreter.h"
44cf05d7 32
33//STEER
7a4cf423 34#include "AliESDEvent.h"
35#include "AliAODEvent.h"
7a4cf423 36#include "AliLog.h"
247abff4 37#include "AliVCluster.h"
38#include "AliVCaloCells.h"
247abff4 39#include "AliVEventHandler.h"
eee2ea01 40#include "AliAODHandler.h"
247abff4 41#include "AliAnalysisManager.h"
42#include "AliInputEventHandler.h"
44cf05d7 43
44//EMCAL
45#include "AliEMCALRecoUtils.h"
46#include "AliEMCALGeometry.h"
47
48#include "AliAnalysisTaskCaloFilter.h"
7a4cf423 49
50ClassImp(AliAnalysisTaskCaloFilter)
e4de0408 51
7a4cf423 52////////////////////////////////////////////////////////////////////////
53
54AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter():
ea00d1fa 55AliAnalysisTaskSE("CaloFilterTask"),
56fCaloFilter(0), fEventSelection(),
c9318292 57fAcceptAllMBEvent(kFALSE),fMBTriggerMask(AliVEvent::kMB),
58fCorrect(kFALSE),
ea00d1fa 59fEMCALGeo(0x0), fEMCALGeoName("EMCAL_COMPLETE12SMV1"),
e4de0408 60fEMCALRecoUtils(new AliEMCALRecoUtils),
61fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
62fGeoMatrixSet(kFALSE),
ea00d1fa 63fConfigName(""), fFillAODFile(kTRUE),
eee2ea01 64fFillMCParticles(kFALSE),
ea00d1fa 65fFillTracks(kFALSE), fFillHybridTracks(kFALSE),
66fFillAllVertices(kFALSE), fFillv0s(kFALSE),
67fFillVZERO(kFALSE),
68fEMCALEnergyCut(0.), fEMCALNcellsCut (0),
69fPHOSEnergyCut(0.), fPHOSNcellsCut (0),
70fTrackPtCut(-1),
71fVzCut(100.), fEvent(0x0),
72fESDEvent(0x0), fAODEvent(0x0)
7a4cf423 73{
74 // Default constructor
e4de0408 75
ea00d1fa 76 fEventSelection[0] = kFALSE;
77 fEventSelection[1] = kFALSE;
78 fEventSelection[2] = kFALSE;
79
e3990982 80 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
3b13c34c 81 //for(Int_t i = 0; i < 5 ; i++) fPHOSMatrix[i] = 0 ;
5994e71f 82
7a4cf423 83}
84
85//__________________________________________________
86AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter(const char* name):
ea00d1fa 87AliAnalysisTaskSE(name),
88fCaloFilter(0), fEventSelection(),
c9318292 89fAcceptAllMBEvent(kFALSE),fMBTriggerMask(AliVEvent::kMB),
90fCorrect(kFALSE),
ea00d1fa 91fEMCALGeo(0x0), fEMCALGeoName("EMCAL_COMPLETE12SMV1"),
e4de0408 92fEMCALRecoUtils(new AliEMCALRecoUtils),
93fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
94fGeoMatrixSet(kFALSE),
ea00d1fa 95fConfigName(""), fFillAODFile(kTRUE),
eee2ea01 96fFillMCParticles(kFALSE),
ea00d1fa 97fFillTracks(kFALSE), fFillHybridTracks(kFALSE),
98fFillAllVertices(kFALSE), fFillv0s(kFALSE),
99fFillVZERO(kFALSE),
100fEMCALEnergyCut(0.), fEMCALNcellsCut(0),
101fPHOSEnergyCut(0.), fPHOSNcellsCut(0),
102fTrackPtCut(-1),
103fVzCut(100.), fEvent(0x0),
104fESDEvent(0x0), fAODEvent(0x0)
7a4cf423 105{
106 // Constructor
e4de0408 107
ea00d1fa 108 fEventSelection[0] = kFALSE;
109 fEventSelection[1] = kFALSE;
110 fEventSelection[2] = kFALSE;
111
e3990982 112 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
3b13c34c 113 //for(Int_t i = 0; i < 5 ; i++) fPHOSMatrix[i] = 0 ;
e4de0408 114
7a4cf423 115}
116
117//__________________________________________________
247abff4 118AliAnalysisTaskCaloFilter::~AliAnalysisTaskCaloFilter()
7a4cf423 119{
247abff4 120 //Destructor.
121
44cf05d7 122 if(fEMCALGeo) delete fEMCALGeo;
123 if(fEMCALRecoUtils) delete fEMCALRecoUtils;
5994e71f 124
247abff4 125}
126
ea00d1fa 127//_____________________________________________
128Bool_t AliAnalysisTaskCaloFilter::AcceptEvent()
247abff4 129{
ea00d1fa 130 // Define conditions to accept the event to be filtered
e4de0408 131
f80aea56 132 if(!AcceptEventVertex()) return kFALSE;
133
ea00d1fa 134 Bool_t eventSel = kFALSE;
e4de0408 135
c9318292 136 Bool_t isMB = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & fMBTriggerMask);
e4de0408 137
ea00d1fa 138 if ( isMB && fAcceptAllMBEvent ) eventSel = kTRUE; // accept any MB event
e4de0408 139
ea00d1fa 140 else if( fEventSelection[0] && AcceptEventEMCAL() ) eventSel = kTRUE; // accept event depending on EMCAL activity
e4de0408 141
ea00d1fa 142 else if( fEventSelection[1] && AcceptEventPHOS () ) eventSel = kTRUE; // accept event depending on PHOS activity
e4de0408 143
ea00d1fa 144 else if( fEventSelection[2] && AcceptEventTrack() ) eventSel = kTRUE; // accept event depending on Track activity
e4de0408 145
ea00d1fa 146 return eventSel ;
e4de0408 147
148}
149
e4de0408 150//__________________________________________________
151Bool_t AliAnalysisTaskCaloFilter::AcceptEventEMCAL()
152{
ea00d1fa 153 // Accept event given there is a EMCAL cluster with enough energy, and not noisy, exotic
154
155 if(fCaloFilter==kPHOS) return kTRUE; // accept
e4de0408 156
ea00d1fa 157 if(fEMCALEnergyCut <= 0) return kTRUE; // accept
e4de0408 158
159 Int_t nCluster = InputEvent() -> GetNumberOfCaloClusters();
160 AliVCaloCells * caloCell = InputEvent() -> GetEMCALCells();
161 Int_t bc = InputEvent() -> GetBunchCrossNumber();
162
163 for(Int_t icalo = 0; icalo < nCluster; icalo++)
164 {
ea00d1fa 165 AliVCluster *clus = (AliVCluster*) (InputEvent()->GetCaloCluster(icalo));
e4de0408 166
ea00d1fa 167 if( ( clus->IsEMCAL() ) && ( clus->GetNCells() > fEMCALNcellsCut ) && ( clus->E() > fEMCALEnergyCut ) &&
e4de0408 168 fEMCALRecoUtils->IsGoodCluster(clus,fEMCALGeo,caloCell,bc))
169 {
170
ea00d1fa 171 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventEMCAL() - Accept : E %2.2f > %2.2f, nCells %d > %d \n",
172 clus->E(), fEMCALEnergyCut, clus->GetNCells(), fEMCALNcellsCut);
e4de0408 173
174 return kTRUE;
175 }
44cf05d7 176
e4de0408 177 }// loop
44cf05d7 178
ea00d1fa 179 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventEMCAL() - Reject \n");
180
e4de0408 181 return kFALSE;
44cf05d7 182
e4de0408 183}
184
ea00d1fa 185//_________________________________________________
186Bool_t AliAnalysisTaskCaloFilter::AcceptEventPHOS()
187{
188 // Accept event given there is a PHOS cluster with enough energy and not noisy/exotic
3a58eee6 189
ea00d1fa 190 if(fCaloFilter==kEMCAL) return kTRUE; // accept
7a4cf423 191
ea00d1fa 192 if(fPHOSEnergyCut <= 0) return kTRUE; // accept
193
194 Int_t nCluster = InputEvent() -> GetNumberOfCaloClusters();
195
196 for(Int_t icalo = 0; icalo < nCluster; icalo++)
197 {
198 AliVCluster *clus = (AliVCluster*) (InputEvent()->GetCaloCluster(icalo));
e4de0408 199
ea00d1fa 200 if( ( clus->IsPHOS() ) && ( clus->GetNCells() > fPHOSNcellsCut ) && ( clus->E() > fPHOSEnergyCut ))
e4de0408 201 {
e4de0408 202
ea00d1fa 203 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventPHOS() - Accept : E %2.2f > %2.2f, nCells %d > %d \n",
204 clus->E(), fPHOSEnergyCut, clus->GetNCells(), fPHOSNcellsCut);
e4de0408 205
ea00d1fa 206 return kTRUE;
e4de0408 207 }
208
ea00d1fa 209 }// loop
210
211 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventPHOS() - Reject \n");
212
213 return kFALSE;
214
215}
e4de0408 216
ea00d1fa 217//__________________________________________________
218Bool_t AliAnalysisTaskCaloFilter::AcceptEventTrack()
e4de0408 219{
ea00d1fa 220 // Accept event if there is a track avobe a certain pT
e4de0408 221
ea00d1fa 222 if(fTrackPtCut <= 0) return kTRUE; // accept
e4de0408 223
ea00d1fa 224 Double_t pTrack[3] = {0,0,0};
e4de0408 225
ea00d1fa 226 for (Int_t nTrack = 0; nTrack < fEvent->GetNumberOfTracks(); ++nTrack)
e4de0408 227 {
ea00d1fa 228 AliVTrack *track = (AliVTrack*) fEvent->GetTrack(nTrack);
e4de0408 229
ea00d1fa 230 // Select only hybrid tracks?
231 if(fAODEvent && fFillHybridTracks && !((AliAODTrack*)track)->IsHybridGlobalConstrainedGlobal()) continue;
e4de0408 232
ea00d1fa 233 track->GetPxPyPz(pTrack) ;
e4de0408 234
ea00d1fa 235 TLorentzVector momentum(pTrack[0],pTrack[1],pTrack[2],0);
e4de0408 236
ea00d1fa 237 if(momentum.Pt() > fTrackPtCut)
e4de0408 238 {
ea00d1fa 239 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventTrack() - Accept : pT %2.2f > %2.2f \n",
240 momentum.Pt(), fTrackPtCut);
241
242 return kTRUE;
e4de0408 243 }
244
ea00d1fa 245 }
e4de0408 246
ea00d1fa 247 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventTrack() - Reject \n");
e4de0408 248
ea00d1fa 249 return kFALSE;
250
251}
e4de0408 252
ea00d1fa 253//___________________________________________________
254Bool_t AliAnalysisTaskCaloFilter::AcceptEventVertex()
e4de0408 255{
ea00d1fa 256 // Accept event with good vertex
e4de0408 257
ea00d1fa 258 Double_t v[3];
259 InputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
247abff4 260
f80aea56 261
ea00d1fa 262 if(TMath::Abs(v[2]) > fVzCut)
e4de0408 263 {
f80aea56 264 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::AcceptEventVertex() - Vz Reject : vz %2.2f > %2.2f\n",v[2],fVzCut);
265
ea00d1fa 266 return kFALSE ;
e4de0408 267 }
268
ea00d1fa 269 return CheckForPrimaryVertex();
270}
271
272//_______________________________________________________
273Bool_t AliAnalysisTaskCaloFilter::CheckForPrimaryVertex()
274{
275 //Check if the vertex was well reconstructed, copy from v0Reader of conversion group
276 //It only works for ESDs
a8088a22 277
ea00d1fa 278 // AODs
279 if(!fESDEvent)
e4de0408 280 {
ea00d1fa 281 // Check that the vertex is not (0,0,0)
282 Double_t v[3];
283 InputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
284
285 if(TMath::Abs(v[2]) < 1e-6 &&
286 TMath::Abs(v[1]) < 1e-6 &&
287 TMath::Abs(v[0]) < 1e-6 )
8ebce41d 288 {
f80aea56 289 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::CheckForPrimaryVertex() - Reject v(0,0,0) \n");
ea00d1fa 290
291 return kFALSE ;
292 }
e4de0408 293
ea00d1fa 294 return kTRUE;
e4de0408 295 }
296
ea00d1fa 297 // ESDs
298 if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors() > 0)
299 {
300 return kTRUE;
301 }
e4de0408 302
ea00d1fa 303 if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors() < 1)
e4de0408 304 {
ea00d1fa 305 // SPD vertex
306 if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors() > 0)
8ebce41d 307 {
ea00d1fa 308 //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
309 return kTRUE;
8ebce41d 310
ea00d1fa 311 }
312 if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors() < 1)
313 {
314 // cout<<"bad vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
f80aea56 315 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::CheckForPrimaryVertex() - Reject, GetPrimaryVertexSPD()->GetNContributors() < 1 \n");
316
ea00d1fa 317 return kFALSE;
318 }
e4de0408 319 }
7a4cf423 320
f80aea56 321 if (fDebug > 0) printf("AliAnalysisTaskCaloFilter::CheckForPrimaryVertex() - Reject, GetPrimaryVertexTracks()->GetNContributors() > 1 \n");
a8088a22 322
ea00d1fa 323 return kFALSE;
7a4cf423 324
e4de0408 325}
326
327//__________________________________________________
328void AliAnalysisTaskCaloFilter::CorrectionsInEMCAL()
329{
f2ccb5b8 330 //If EMCAL, and requested, correct energy, position ...
e4de0408 331
f2ccb5b8 332 //Need to do this in a separate loop before filling the ESDs because of the track matching recalculations
e4de0408 333
334 if(fCorrect && (fCaloFilter==kEMCAL || fCaloFilter==kBoth) )
335 {
336 if(!fGeoMatrixSet)
337 {
338 if(fLoadEMCALMatrices)
339 {
c0b85449 340 printf("AliAnalysisTaskCaloFilter::UserExec() - Load user defined EMCAL geometry matrices\n");
3b13c34c 341 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
342 if(fEMCALMatrix[mod]){
343 if(DebugLevel() > 1)
344 fEMCALMatrix[mod]->Print();
345 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod) ;
346 }
347 fGeoMatrixSet=kTRUE;
348 }//SM loop
349 }//Load matrices
e4de0408 350 else if(!gGeoManager)
351 {
3b13c34c 352 printf("AliAnalysisTaskCaloFilter::UserExec() - Get geo matrices from data\n");
353 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
e4de0408 354 if(!strcmp(InputEvent()->GetName(),"AliAODEvent"))
355 {
3b13c34c 356 if(DebugLevel() > 1)
357 printf("AliAnalysisTaskCaloFilter Use ideal geometry, values geometry matrix not kept in AODs.\n");
358 }//AOD
e4de0408 359 else
360 {
3b13c34c 361 if(DebugLevel() > 1) printf("AliAnalysisTaskCaloFilter Load Misaligned matrices. \n");
e4de0408 362 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent()) ;
363 if(!esd)
364 {
3b13c34c 365 printf("AliAnalysisTaskCaloFilter::UserExec() - This event does not contain ESDs?");
366 return;
367 }
e4de0408 368 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
369 {
3b13c34c 370 //if(DebugLevel() > 1)
371 esd->GetEMCALMatrix(mod)->Print();
372 if(esd->GetEMCALMatrix(mod)) fEMCALGeo->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
373 }
374 fGeoMatrixSet=kTRUE;
375 }//ESD
376 }//Load matrices from Data
e4de0408 377
3b13c34c 378 }//first event
379
f2ccb5b8 380 //Cluster Loop
e4de0408 381 Int_t nCaloClus = InputEvent()->GetNumberOfCaloClusters();
382
383 for (Int_t iClust=0; iClust<nCaloClus; ++iClust)
384 {
385 AliVCluster * cluster = InputEvent()->GetCaloCluster(iClust);
f2ccb5b8 386
f2ccb5b8 387 if(cluster->IsPHOS()) continue ;
e4de0408 388
247abff4 389 Float_t position[]={0,0,0};
390 if(DebugLevel() > 2)
391 printf("Check cluster %d for bad channels and close to border\n",cluster->GetID());
392 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;
e4de0408 393
247abff4 394 if(DebugLevel() > 2)
395 {
3b13c34c 396 printf("Filter, before : i %d, E %f, dispersion %f, m02 %f, m20 %f, distToBad %f\n",iClust,cluster->E(),
397 cluster->GetDispersion(),cluster->GetM02(),cluster->GetM20(), cluster->GetDistanceToBadChannel());
247abff4 398 cluster->GetPosition(position);
399 printf("Filter, before : i %d, x %f, y %f, z %f\n",cluster->GetID(), position[0], position[1], position[2]);
400 }
f2ccb5b8 401
3b13c34c 402 //Recalculate distance to bad channels, if new list of bad channels provided
e4de0408 403 fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, InputEvent()->GetEMCALCells(), cluster);
404
405 if(fEMCALRecoUtils->IsRecalibrationOn())
406 {
407 fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, cluster, InputEvent()->GetEMCALCells());
408 fEMCALRecoUtils->RecalculateClusterShowerShapeParameters(fEMCALGeo, InputEvent()->GetEMCALCells(),cluster);
5ef94e1b 409 fEMCALRecoUtils->RecalculateClusterPID(cluster);
5ef94e1b 410 }
e4de0408 411
412 fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, InputEvent()->GetEMCALCells(),cluster);
f2ccb5b8 413
247abff4 414 if(DebugLevel() > 2)
415 {
3b13c34c 416 printf("Filter, after : i %d, E %f, dispersion %f, m02 %f, m20 %f, distToBad %f\n",cluster->GetID(),cluster->E(),
417 cluster->GetDispersion(),cluster->GetM02(),cluster->GetM20(), cluster->GetDistanceToBadChannel());
247abff4 418 cluster->GetPosition(position);
419 printf("Filter, after : i %d, x %f, y %f, z %f\n",cluster->GetID(), position[0], position[1], position[2]);
420 }
421
44907916 422 cluster->SetE(fEMCALRecoUtils->CorrectClusterEnergyLinearity(cluster));
423
f2ccb5b8 424 }
e4de0408 425
f2ccb5b8 426 //Recalculate track-matching
e4de0408 427 fEMCALRecoUtils->FindMatches(InputEvent(),0,fEMCALGeo);
f2ccb5b8 428
429 } // corrections in EMCAL
7a4cf423 430}
431
ea00d1fa 432//________________________________________________
433void AliAnalysisTaskCaloFilter::FillAODCaloCells()
434{
435 // Fill EMCAL/PHOS cell info
436
437 // EMCAL
438 if ((fCaloFilter==kBoth || fCaloFilter==kEMCAL) && fEvent->GetEMCALCells())
439 { // protection against missing ESD information
440 AliVCaloCells &eventEMcells = *(fEvent->GetEMCALCells());
441 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
442
443 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
444 aodEMcells.CreateContainer(nEMcell);
445 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
446 Double_t calibFactor = 1.;
447 for (Int_t iCell = 0; iCell < nEMcell; iCell++)
448 {
449 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
450 fEMCALGeo->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
451 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
452
453 if(fCorrect && fEMCALRecoUtils->IsRecalibrationOn())
454 {
455 calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
456 }
457
458 if(!fEMCALRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
459 { //Channel is not declared as bad
460 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor,
461 eventEMcells.GetTime(iCell),eventEMcells.GetMCLabel(iCell),eventEMcells.GetEFraction(iCell));
462 //printf("GOOD channel\n");
463 }
464 else
465 {
466 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0,-1,-1,0);
467 //printf("BAD channel\n");
468 }
469 }
470 aodEMcells.Sort();
471 }
472
473 // PHOS
474 if ((fCaloFilter==kBoth || fCaloFilter==kPHOS) && fEvent->GetPHOSCells())
475 { // protection against missing ESD information
476 AliVCaloCells &eventPHcells = *(fEvent->GetPHOSCells());
477 Int_t nPHcell = eventPHcells.GetNumberOfCells() ;
478
479 AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
480 aodPHcells.CreateContainer(nPHcell);
481 aodPHcells.SetType(AliVCaloCells::kPHOSCell);
482
483 for (Int_t iCell = 0; iCell < nPHcell; iCell++)
484 {
485 aodPHcells.SetCell(iCell,eventPHcells.GetCellNumber(iCell),eventPHcells.GetAmplitude(iCell),
486 eventPHcells.GetTime(iCell),eventPHcells.GetMCLabel(iCell),eventPHcells.GetEFraction(iCell));
487 }
488
489 aodPHcells.Sort();
490 }
491}
492
493
494//___________________________________________________
495void AliAnalysisTaskCaloFilter::FillAODCaloClusters()
e4de0408 496{
ea00d1fa 497 // Fill the AOD with caloclusters
44cf05d7 498
ea00d1fa 499 // Access to the AOD container of clusters
31364cb2 500
ea00d1fa 501 TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
502 Int_t jClusters=0;
503 Float_t posF[3] ;
504
505 Int_t nCaloClus = fEvent->GetNumberOfCaloClusters();
506 for (Int_t iClust=0; iClust<nCaloClus; ++iClust)
e4de0408 507 {
e4de0408 508
ea00d1fa 509 AliVCluster * cluster = fEvent->GetCaloCluster(iClust);
e4de0408 510
ea00d1fa 511 //Check which calorimeter information we want to keep.
512
513 if(fCaloFilter!=kBoth)
514 {
515 if (fCaloFilter==kPHOS && cluster->IsEMCAL()) continue ;
516 else if(fCaloFilter==kEMCAL && cluster->IsPHOS()) continue ;
517 }
518
519 // Get original residuals, in case of previous recalculation, reset them
520 Float_t dR = cluster->GetTrackDx();
521 Float_t dZ = cluster->GetTrackDz();
522
523 if(DebugLevel() > 2)
524 printf("Original residuals : dZ %f, dR %f\n ",dZ, dR);
525
526 //--------------------------------------------------------------
527 //If EMCAL and corrections done, get the new matching parameters, do not copy noisy clusters
528 if(cluster->IsEMCAL() && fCorrect)
529 {
530 if(DebugLevel() > 2)
531 printf("Check cluster %d for bad channels and close to border\n",cluster->GetID());
532
533 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;
534
535 if(fEMCALRecoUtils->IsExoticCluster(cluster, InputEvent()->GetEMCALCells(),InputEvent()->GetBunchCrossNumber())) continue;
536
537 fEMCALRecoUtils->GetMatchedResiduals(cluster->GetID(),dR,dZ);
538 cluster->SetTrackDistance(dR,dZ);
539 }
540
541 if(DebugLevel() > 2)
542 {
543 if(cluster->IsEMCAL()) printf("EMCAL Track-Cluster Residuals : dZ %f, dR %f\n ",dZ, dR);
544 if(cluster->IsPHOS()) printf("PHOS Track-Cluster Residuals : dZ %f, dR %f\n ",dZ, dR);
545 }
546
547 //--------------------------------------------------------------
548
549 //Now fill AODs
550
551 Int_t id = cluster->GetID();
552 Float_t energy = cluster->E();
553 cluster->GetPosition(posF);
554
555 AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++])
556 AliAODCaloCluster(id,
557 cluster->GetNLabels(),
558 cluster->GetLabels(),
559 energy,
560 posF,
561 NULL,
562 cluster->GetType());
563
564 caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
565 cluster->GetDispersion(),
566 cluster->GetM20(), cluster->GetM02(),
567 -1,
568 cluster->GetNExMax(),cluster->GetTOF()) ;
569
570 caloCluster->SetPIDFromESD(cluster->GetPID());
571 caloCluster->SetNCells(cluster->GetNCells());
572 caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
573 caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
574 caloCluster->SetTrackDistance(dR, dZ);
575
576 if(DebugLevel() > 2)
577 {
578 printf("Filter, aod : i %d, E %f, dispersion %f, m02 %f, m20 %f\n",caloCluster->GetID(),caloCluster->E(),
579 caloCluster->GetDispersion(),caloCluster->GetM02(),caloCluster->GetM20());
580 caloCluster->GetPosition(posF);
581 printf("Filter, aod : i %d, x %f, y %f, z %f\n",caloCluster->GetID(), posF[0], posF[1], posF[2]);
582 }
583
584 //Matched tracks, just to know if there was any match, the track pointer is useless if tracks not stored
585 if(TMath::Abs(dR) < 990 && TMath::Abs(dZ) < 990)
586 { //Default value in PHOS 999, in EMCAL 1024, why?
587 caloCluster->AddTrackMatched(new AliAODTrack);
588 }
589 // TO DO, in case Tracks available, think how to put the matched track in AOD
e4de0408 590 }
591
ea00d1fa 592 caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots
593
594}
595
596//__________________________________________________
597void AliAnalysisTaskCaloFilter::FillAODCaloTrigger()
598{
599 // AOD CaloTrigger copy
600
6dd84062 601 AliAODCaloTrigger* triggerEM = AODEvent()->GetCaloTrigger("EMCAL");
602 AliAODCaloTrigger* triggerPH = AODEvent()->GetCaloTrigger("PHOS");
603
604 AliAODCaloTrigger* inTriggerEM = fAODEvent ->GetCaloTrigger("EMCAL");
605 AliAODCaloTrigger* inTriggerPH = fAODEvent ->GetCaloTrigger("PHOS");
ea00d1fa 606
607 // Copy from AODs
608 if(fAODEvent)
e4de0408 609 {
6dd84062 610 if(inTriggerPH && (fCaloFilter==kBoth || fCaloFilter==kPHOS)) *triggerPH = *inTriggerPH;
ea00d1fa 611
6dd84062 612 if(inTriggerEM && (fCaloFilter==kBoth || fCaloFilter==kEMCAL)) *triggerEM = *inTriggerEM;
ea00d1fa 613
614 return;
44cf05d7 615 }
616
ea00d1fa 617}
618
619//______________________________________________
620void AliAnalysisTaskCaloFilter::FillAODHeader()
621{
622 // AOD header copy
623
624 AliAODHeader* header = AODEvent()->GetHeader();
625
626 // Copy from AODs
627 if(fAODEvent)
e4de0408 628 {
ea00d1fa 629 *header = *(fAODEvent->GetHeader());
630 return;
631 }
632
633 if(!fESDEvent) return;
634
635 // Copy from ESDs
636
637 header->SetRunNumber(fEvent->GetRunNumber());
638
639 TTree* tree = fInputHandler->GetTree();
640 if (tree)
641 {
642 TFile* file = tree->GetCurrentFile();
643 if (file) header->SetESDFileName(file->GetName());
644 }
645
646 header->SetBunchCrossNumber(fEvent->GetBunchCrossNumber());
647 header->SetOrbitNumber(fEvent->GetOrbitNumber());
648 header->SetPeriodNumber(fEvent->GetPeriodNumber());
649 header->SetEventType(fEvent->GetEventType());
650
651 //Centrality
652 if(fEvent->GetCentrality())
653 {
654 header->SetCentrality(new AliCentrality(*(fEvent->GetCentrality())));
655 }
656 else
657 {
658 header->SetCentrality(0);
659 }
660
661 //Trigger
662 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
663 header->SetFiredTriggerClasses(fESDEvent->GetFiredTriggerClasses());
664 header->SetTriggerMask(fEvent->GetTriggerMask());
665 header->SetTriggerCluster(fEvent->GetTriggerCluster());
666 header->SetL0TriggerInputs(fESDEvent->GetHeader()->GetL0TriggerInputs());
667 header->SetL1TriggerInputs(fESDEvent->GetHeader()->GetL1TriggerInputs());
668 header->SetL2TriggerInputs(fESDEvent->GetHeader()->GetL2TriggerInputs());
669
670 header->SetMagneticField(fEvent->GetMagneticField());
671 //header->SetMuonMagFieldScale(fESDEvent->GetCurrentDip()/6000.);
672
673 header->SetZDCN1Energy(fEvent->GetZDCN1Energy());
674 header->SetZDCP1Energy(fEvent->GetZDCP1Energy());
675 header->SetZDCN2Energy(fEvent->GetZDCN2Energy());
676 header->SetZDCP2Energy(fEvent->GetZDCP2Energy());
677 header->SetZDCEMEnergy(fEvent->GetZDCEMEnergy(0),fEvent->GetZDCEMEnergy(1));
678
679 Float_t diamxy[2]={fEvent->GetDiamondX(),fEvent->GetDiamondY()};
680 Float_t diamcov[3];
681 fEvent->GetDiamondCovXY(diamcov);
682 header->SetDiamond(diamxy,diamcov);
683 header->SetDiamondZ(fESDEvent->GetDiamondZ(),fESDEvent->GetSigma2DiamondZ());
684
685}
686
eee2ea01 687
688//__________________________________________________
689void AliAnalysisTaskCaloFilter::FillAODMCParticles()
690{
691 // Copy MC particles
692
693 if(!fFillMCParticles) return;
694
695 TClonesArray* inMCParticles = (TClonesArray*) (fAODEvent ->FindListObject("mcparticles"));
696 TClonesArray* ouMCParticles = (TClonesArray*) ( AODEvent()->FindListObject("mcparticles"));
697
698 if( inMCParticles && ouMCParticles ) new (ouMCParticles) TClonesArray(*inMCParticles);
699
700}
701
ea00d1fa 702//_____________________________________________
703void AliAnalysisTaskCaloFilter::FillAODTracks()
704{
705 // AOD track copy
706
707 if(!fFillTracks) return;
708
709 AliAODTrack* aodTrack(0x0);
710
711 Double_t pos[3] = { 0. };
712 Double_t covTr[21]= { 0. };
713 Double_t pid[10] = { 0. };
714 Double_t p[3] = { 0. };
715
716 // Copy from AODs
717 if(fAODEvent)
718 {
719 //TClonesArray* inTracks = fAODEvent ->GetTracks();
720 TClonesArray* ouTracks = AODEvent()->GetTracks();
721 //new (ouTracks) TClonesArray(*inTracks);
722
723 //printf("N tracks %d\n",fAODEvent->GetNumberOfTracks());
724 Int_t nCopyTrack = 0;
725 for (Int_t nTrack = 0; nTrack < fAODEvent->GetNumberOfTracks(); ++nTrack)
e4de0408 726 {
ea00d1fa 727 AliAODTrack *track = fAODEvent->GetTrack(nTrack);
44cf05d7 728
ea00d1fa 729 // Select only hybrid tracks?
730 if(fFillHybridTracks && !track->IsHybridGlobalConstrainedGlobal()) continue;
731
732 // Remove PID object to save space
733 //track->SetDetPID(0x0);
734
735 //new((*ouTracks)[nCopyTrack++]) AliAODTrack(*track);
736
737 track->GetPxPyPz(p);
738 Bool_t isDCA = track->GetPosition(pos);
739 track->GetCovMatrix(covTr);
740 track->GetPID(pid);
741
742 AliAODVertex* primVertex = (AliAODVertex*) AODEvent()->GetVertices()->At(0); // primary vertex, copied previously!!!
743
744 aodTrack = new((*ouTracks)[nCopyTrack++]) AliAODTrack(
745 track->GetID(),
746 track->GetLabel(),
747 p,
748 kTRUE,
749 pos,
750 isDCA,
751 covTr,
752 track->Charge(),
753 track->GetITSClusterMap(),
754 pid,
755 primVertex,
756 track->GetUsedForVtxFit(),
757 track->GetUsedForPrimVtxFit(),
758 (AliAODTrack::AODTrk_t) track->GetType(),
759 track->GetFilterMap(),
760 track->Chi2perNDF());
761
762
763 aodTrack->SetIsHybridGlobalConstrainedGlobal(track->IsHybridGlobalConstrainedGlobal());
764 aodTrack->SetIsHybridTPCConstrainedGlobal (track->IsHybridTPCConstrainedGlobal());
765 aodTrack->SetIsGlobalConstrained (track->IsGlobalConstrained());
766 aodTrack->SetIsTPCConstrained (track->IsTPCConstrained());
767
768 aodTrack->SetTPCFitMap (track->GetTPCFitMap());
769 aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());
770 aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());
771
772 aodTrack->SetChi2MatchTrigger(track->GetChi2MatchTrigger());
773
774 // set the DCA values to the AOD track
775
776 aodTrack->SetPxPyPzAtDCA(track->PxAtDCA(),track->PyAtDCA(),track->PzAtDCA());
777 aodTrack->SetXYAtDCA (track->XAtDCA() ,track->YAtDCA());
778
779 aodTrack->SetFlags (track->GetFlags());
780 aodTrack->SetTPCPointsF (track->GetTPCNclsF());
781
782 // Calo
783
784 if(track->IsEMCAL()) aodTrack->SetEMCALcluster(track->GetEMCALcluster());
785 if(track->IsPHOS()) aodTrack->SetPHOScluster (track->GetPHOScluster());
786 aodTrack->SetTrackPhiEtaOnEMCal( track->GetTrackPhiOnEMCal(), track->GetTrackPhiOnEMCal() );
787
788 }
789
790 //printf("Final N tracks %d\n",nCopyTrack);
791
792 return;
793 }
794
795}
796
797//_________________________________________
798void AliAnalysisTaskCaloFilter::FillAODv0s()
799{
800 // Copy v0s (use if you know what you do, use quite a lot of memory)
801
802 if(!fFillv0s) return;
803
804 // Copy from AODs
805 if(fAODEvent)
806 {
807 TClonesArray* inv0 = fAODEvent ->GetV0s();
808 TClonesArray* ouv0 = AODEvent()->GetV0s();
809
810 //new (ouv0s) TClonesArray(*inv0s);
811
812 Int_t allv0s = inv0->GetEntriesFast();
813
814 for (Int_t nv0s = 0; nv0s < allv0s; ++nv0s)
e4de0408 815 {
ea00d1fa 816 AliAODv0 *v0 = (AliAODv0*)inv0->At(nv0s);
817
818 new((*ouv0)[nv0s]) AliAODv0(*v0);
819 }
820
821 return;
822 }
823
824}
825
826//____________________________________________
827void AliAnalysisTaskCaloFilter::FillAODVZERO()
828{
829 // Copy VZERO
830
831 if(!fFillVZERO) return;
832
833 AliAODVZERO* vzeroData = AODEvent()->GetVZEROData();
834
835 if(fESDEvent) *vzeroData = *(fESDEvent->GetVZEROData());
836 else *vzeroData = *(fAODEvent->GetVZEROData());
837
838}
839
840//_______________________________________________
841void AliAnalysisTaskCaloFilter::FillAODVertices()
842{
843 // Copy vertices
844
845 // set arrays and pointers
846 Double_t pos[3] ;
847 Double_t covVtx[6];
848 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
849
850 // Copy from AODs
851 if(fAODEvent)
852 {
853 TClonesArray* inVertices = fAODEvent ->GetVertices();
854 TClonesArray* ouVertices = AODEvent()->GetVertices();
855
856 //new (ouVertices) TClonesArray(*inVertices);
857
858 //Keep only the first 3 vertices if not requested
859 Int_t allVertices = inVertices->GetEntriesFast();
860
861 //printf("n Vertices %d\n",allVertices);
862
863 if(!fFillAllVertices)
864 {
865 if(allVertices > 3) allVertices = 3;
44cf05d7 866 }
ea00d1fa 867
868 //printf("Final n Vertices %d\n",allVertices);
869
870 for (Int_t nVertices = 0; nVertices < allVertices; ++nVertices)
871 {
872 AliAODVertex *vertex = (AliAODVertex*)inVertices->At(nVertices);
873
874 new((*ouVertices)[nVertices]) AliAODVertex(*vertex);
875 }
876
877 return;
44cf05d7 878 }
ea00d1fa 879
880 if(!fESDEvent) return;
881
882 // Copy from ESDs
883
884 // Access to the AOD container of vertices
885 Int_t jVertices=0;
886 TClonesArray &vertices = *(AODEvent()->GetVertices());
887
888 // Add primary vertex. The primary tracks will be defined
889 // after the loops on the composite objects (v0, cascades, kinks)
890 fEvent ->GetPrimaryVertex()->GetXYZ(pos);
891 fESDEvent->GetPrimaryVertex()->GetCovMatrix(covVtx);
892 Float_t chi = fESDEvent->GetPrimaryVertex()->GetChi2toNDF();
893
894 AliAODVertex * primary = new(vertices[jVertices++])
895 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
896 primary->SetName(fEvent->GetPrimaryVertex()->GetName());
897 primary->SetTitle(fEvent->GetPrimaryVertex()->GetTitle());
e4de0408 898
44cf05d7 899}
900
ea00d1fa 901//____________________________________
902void AliAnalysisTaskCaloFilter::Init()
903{
904 //Init analysis with configuration macro if available
905
906 if(gROOT->LoadMacro(fConfigName) >=0)
907 {
908 printf("Configure analysis with %s\n",fConfigName.Data());
909
910 AliAnalysisTaskCaloFilter *filter = (AliAnalysisTaskCaloFilter*)gInterpreter->ProcessLine("ConfigCaloFilter()");
911
912 fEMCALGeoName = filter->fEMCALGeoName;
913 fLoadEMCALMatrices = filter->fLoadEMCALMatrices;
914 fFillAODFile = filter->fFillAODFile;
915 fFillTracks = filter->fFillTracks;
916 fFillHybridTracks = filter->fFillHybridTracks;
917 fFillv0s = filter->fFillv0s;
918 fFillVZERO = filter->fFillVZERO;
919 fFillAllVertices = filter->fFillAllVertices;
920 fEMCALRecoUtils = filter->fEMCALRecoUtils;
921 fConfigName = filter->fConfigName;
922 fCaloFilter = filter->fCaloFilter;
923 fEventSelection[0] = filter->fEventSelection[0];
924 fEventSelection[1] = filter->fEventSelection[1];
925 fEventSelection[2] = filter->fEventSelection[2];
926 fAcceptAllMBEvent = filter->fAcceptAllMBEvent;
6dd84062 927 fMBTriggerMask = filter->fMBTriggerMask;
ea00d1fa 928 fCorrect = filter->fCorrect;
929 fEMCALEnergyCut = filter->fEMCALEnergyCut;
930 fEMCALNcellsCut = filter->fEMCALNcellsCut;
931 fPHOSEnergyCut = filter->fPHOSEnergyCut;
932 fPHOSNcellsCut = filter->fPHOSNcellsCut;
933 fTrackPtCut = filter->fTrackPtCut;
934 fVzCut = filter->fVzCut;
935
936 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = filter->fEMCALMatrix[i] ;
937 }
938}
939
e4de0408 940//_________________________________________
941void AliAnalysisTaskCaloFilter::PrintInfo()
942{
5ef94e1b 943 //Print settings
e4de0408 944
2ec3a257 945 printf("AnalysisCaloFilter::PrintInfo() \n");
ea00d1fa 946
5ef94e1b 947 printf("\t Not only filter, correct Clusters? %d\n",fCorrect);
948 printf("\t Calorimeter Filtering Option ? %d\n",fCaloFilter);
ea00d1fa 949
3b13c34c 950 //printf("\t Use handmade geo matrices? EMCAL %d, PHOS %d\n",fLoadEMCALMatrices, fLoadPHOSMatrices);
951 printf("\t Use handmade geo matrices? EMCAL %d, PHOS 0\n",fLoadEMCALMatrices);
ea00d1fa 952
953 printf("\t Fill: AOD file? %d Tracks? %d; all Vertex? %d; v0s? %d; VZERO ? %d\n",
954 fFillAODFile,fFillTracks,fFillAllVertices, fFillv0s, fFillVZERO);
955
c9318292 956 printf("\t Event Selection based : EMCAL? %d, PHOS? %d Tracks? %d - Accept all MB with mask %d? %d\n",
957 fEventSelection[0],fEventSelection[1],fEventSelection[2],fMBTriggerMask, fAcceptAllMBEvent);
ea00d1fa 958
959 printf("\t \t EMCAL E > %2.2f, EMCAL nCells >= %d, PHOS E > %2.2f, PHOS nCells >= %d, Track pT > %2.2f, |vz| < %2.2f\n",
960 fEMCALEnergyCut,fEMCALNcellsCut,fPHOSEnergyCut,fPHOSNcellsCut, fTrackPtCut,fVzCut);
961}
962
963//_______________________________________________________
964void AliAnalysisTaskCaloFilter::UserCreateOutputObjects()
965{
966 // Init geometry
967
968 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
969
eee2ea01 970 if(fFillMCParticles)
971 {
972 TClonesArray * aodMCParticles = new TClonesArray("AliAODMCParticle",500);
973 aodMCParticles->SetName("mcparticles");
974 ((AliAODHandler*)AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler())->AddBranch("TClonesArray", &aodMCParticles);
975 }
976
ea00d1fa 977}
978
979//____________________________________________________________
980void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
981{
982 // Execute analysis for current event
983 // Copy input ESD or AOD header, vertex, CaloClusters and CaloCells to output AOD
984
985 if (fDebug > 0)
986 printf("CaloFilter: Analysing event # %d\n", (Int_t)Entry());
987
988 fEvent = InputEvent();
989 fAODEvent = dynamic_cast<AliAODEvent*> (fEvent);
990 fESDEvent = dynamic_cast<AliESDEvent*> (fEvent);
991
992 if(!fEvent)
993 {
994 printf("AliAnalysisTaskCaloFilter::UserExec - This event does not contain Input?");
995 return;
996 }
997
998 // printf("Start processing : %s\n",fAODEvent->GetFiredTriggerClasses().Data());
999
1000 // Select the event
1001
1002 if(!AcceptEvent()) return ;
1003
1004 //Magic line to write events to file
1005
1006 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
1007
1008 // Reset output AOD
1009
1010 Int_t nVertices = 0;
1011 if(fFillv0s) nVertices = fEvent->GetNumberOfV0s();
1012 Int_t nCaloClus = fEvent->GetNumberOfCaloClusters();
1013 Int_t nTracks = fEvent->GetNumberOfTracks();
1014
1015 AODEvent()->ResetStd(nTracks, nVertices, 0, 0, 0, nCaloClus, 0, 0);
1016
1017 // Copy
1018
1019 FillAODHeader();
1020
1021 //
1022 FillAODv0s();
1023
1024 //
1025 FillAODVertices(); // Do it before the track filtering to have the reference to the vertex
1026
1027 //
1028 FillAODVZERO();
1029
1030 //
1031 FillAODTracks();
1032
1033 //
1034 CorrectionsInEMCAL();
1035
1036 //
1037 FillAODCaloClusters();
1038
1039 //
1040 FillAODCaloCells();
1041
1042 //
1043 FillAODCaloTrigger();
1044
eee2ea01 1045 //
1046 FillAODMCParticles();
1047
ea00d1fa 1048 //printf("Filtered event, end processing : %s\n",fAODEvent->GetFiredTriggerClasses().Data());
1049
7a4cf423 1050}
1051