]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalClusterMaker.cxx
first running version
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalClusterMaker.cxx
1 // $Id$
2 //
3 // Cluster maker task.
4 //
5 // Author: C.Loizides
6
7 #include <TChain.h>
8 #include <TClonesArray.h>
9 #include "AliAODCaloCluster.h"
10 #include "AliAODEvent.h"
11 #include "AliAnalysisManager.h"
12 #include "AliEMCALRecoUtils.h"
13 #include "AliESDCaloCluster.h"
14 #include "AliESDEvent.h"
15 #include "AliEmcalClusterMaker.h"
16
17 ClassImp(AliEmcalClusterMaker)
18
19 //________________________________________________________________________
20 AliEmcalClusterMaker::AliEmcalClusterMaker() : 
21   AliAnalysisTaskEmcal("AliEmcalClusterMaker", kFALSE),
22   fOutCaloName(),
23   fRecoUtils(0),
24   fEsdMode(kTRUE),
25   fOutClusters(0)
26 {
27   // Default constructor.
28 }
29
30 //________________________________________________________________________
31 AliEmcalClusterMaker::AliEmcalClusterMaker(const char *name, Bool_t histo) : 
32   AliAnalysisTaskEmcal(name, histo),
33   fOutCaloName("EmcClusters"),
34   fRecoUtils(0),
35   fEsdMode(kTRUE),
36   fOutClusters(0)
37 {
38   // Standard constructor.
39   
40   SetMakeGeneralHistograms(histo);
41
42   fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex.";
43 }
44
45 //________________________________________________________________________
46 AliEmcalClusterMaker::~AliEmcalClusterMaker()
47 {
48   // Destructor
49 }
50
51 //________________________________________________________________________
52 void AliEmcalClusterMaker::UserCreateOutputObjects()
53 {
54   // Create my user objects.
55
56   AliAnalysisTaskEmcal::UserCreateOutputObjects();
57
58   if (fRecoUtils)
59     fRecoUtils->Print("");
60   //  PostData(1, fOutput);
61 }
62
63 //________________________________________________________________________
64 void AliEmcalClusterMaker::ExecOnce() 
65 {
66   // Initialize the analysis.
67
68   // Do base class initializations and if it fails -> bail out
69   AliAnalysisTaskEmcal::ExecOnce();
70   if (!fInitialized) 
71     return;
72
73   if (dynamic_cast<AliAODEvent*>(InputEvent())) 
74     fEsdMode = kFALSE;
75
76   if (fEsdMode) 
77     fOutClusters = new TClonesArray("AliESDCaloCluster");
78   else 
79     fOutClusters = new TClonesArray("AliAODCaloCluster");
80
81   fOutClusters->SetName(fOutCaloName);
82
83   // post output in event if not yet present
84   if (!(InputEvent()->FindListObject(fOutCaloName))) {
85     InputEvent()->AddObject(fOutClusters);
86   } else {
87     fInitialized = kFALSE;
88     AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fOutCaloName.Data()));
89     return;
90   }
91 }
92
93 //________________________________________________________________________
94 Bool_t AliEmcalClusterMaker::Run() 
95 {
96   // Run the hadronic correction
97
98   // delete output
99   fOutClusters->Delete();
100
101   // loop over clusters
102   Int_t clusCount = 0;
103   Int_t entries   = fCaloClusters->GetEntries();
104   for (Int_t i=0; i<entries; ++i) {
105     AliVCluster *clus = static_cast<AliVCluster*>(fCaloClusters->At(i));
106     if (!clus || !clus->IsEMCAL())
107       continue;
108     AliVCluster *oc = 0;
109     if (fEsdMode) {
110       AliESDCaloCluster *ec = dynamic_cast<AliESDCaloCluster*>(clus);
111       if (!ec) continue;
112       oc = new ((*fOutClusters)[clusCount]) AliESDCaloCluster(*ec);
113     } else { 
114       AliAODCaloCluster *ac = dynamic_cast<AliAODCaloCluster*>(clus);
115       if (!ac) continue;
116       oc = new ((*fOutClusters)[clusCount]) AliAODCaloCluster(*ac);
117     }
118     if (fRecoUtils) {
119       if (fRecoUtils->IsRejectExoticCluster()) {
120         if (fRecoUtils->IsExoticCluster(oc,fCaloCells))
121         continue;
122       }
123       if (fRecoUtils->GetNonLinearityFunction()!=AliEMCALRecoUtils::kNoCorrection) {
124         Double_t energy = fRecoUtils->CorrectClusterEnergyLinearity(oc);
125         oc->SetE(energy);
126       }
127     }
128     if (!AcceptCluster(oc))
129       continue;
130     clusCount++;
131   }
132   if ((clusCount>0) && (clusCount==fOutClusters->GetEntries()))
133     fOutClusters->RemoveAt(clusCount);
134   return kTRUE;
135 }