]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/AliAnaCaloTrigger.cxx
Updating for CMake
[u/mrichter/AliRoot.git] / PWG4 / AliAnaCaloTrigger.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 //_________________________________________________________________________
17 // An analysis task to check the trigger data in ESD
18 // Creates an ntuple for 2x2 and NxN triggers
19 // Each ntuple connects the maximum trigger amplitudes 
20 // and its positions with reconstructed clusters
21 //
22 //*-- Yves Schutz (CERN) & Gustavo Conesa Balbastre (INFN-LNF)
23 //////////////////////////////////////////////////////////////////////////////
24
25 #include <TChain.h>
26 #include <TFile.h> 
27 #include <TNtuple.h>
28 #include <TVector3.h> 
29
30 #include "AliAnaCaloTrigger.h" 
31 #include "AliAnalysisManager.h"
32 #include "AliESDEvent.h" 
33 #include "AliLog.h"
34 #include "AliESDCaloCluster.h"
35
36 //______________________________________________________________________________
37 AliAnaCaloTrigger::AliAnaCaloTrigger() :  
38   fChain(0),
39   fESD(0), 
40   fOutputContainer(0),
41   fCalorimeter("PHOS"),
42   fNtTrigger22(0), 
43   fNtTriggerNN(0)
44
45 {
46   // Default Constructor.
47
48 }
49
50 //______________________________________________________________________________
51 AliAnaCaloTrigger::AliAnaCaloTrigger(const char *name) : 
52   AliAnalysisTask(name,"AnaCaloTrigger"),  
53   fChain(0),
54   fESD(0), 
55   fOutputContainer(0),
56   fCalorimeter("PHOS"),
57   fNtTrigger22(0), 
58   fNtTriggerNN(0)
59
60 {
61   // Constructor.
62   // Input slot #0 works with an Ntuple
63   DefineInput(0, TChain::Class());
64   // Output slot #0 writes into a TH1 container
65   DefineOutput(0,  TObjArray::Class()) ; 
66 }
67 //____________________________________________________________________________
68 AliAnaCaloTrigger::AliAnaCaloTrigger(const AliAnaCaloTrigger & ct) : 
69   AliAnalysisTask(ct), fChain(ct.fChain), fESD(ct.fESD),
70   fOutputContainer(ct.fOutputContainer), fCalorimeter(ct. fCalorimeter),
71   fNtTrigger22(ct.fNtTrigger22), fNtTriggerNN(ct.fNtTriggerNN)
72 {
73
74   // cpy ctor
75   SetName (ct.GetName()) ; 
76   SetTitle(ct.GetTitle()) ;
77  
78 }
79
80 //_________________________________________________________________________
81 AliAnaCaloTrigger & AliAnaCaloTrigger::operator = (const AliAnaCaloTrigger & source)
82 {
83   // assignment operator
84   
85   if(&source == this) return *this;
86
87   fChain = source.fChain ; 
88   fESD = source.fESD ;
89   fOutputContainer = source.fOutputContainer ;
90   fCalorimeter = source. fCalorimeter ;
91   fNtTrigger22 = source.fNtTrigger22 ;
92   fNtTriggerNN = source.fNtTriggerNN ;
93
94   return *this;
95   
96 }
97
98 //______________________________________________________________________________
99 AliAnaCaloTrigger::~AliAnaCaloTrigger()
100 {
101   // dtor
102   //fOutputContainer->Clear() ; 
103   //delete fOutputContainer ;
104
105 }
106
107
108 //______________________________________________________________________________
109 void AliAnaCaloTrigger::ConnectInputData(const Option_t*)
110 {
111   // Initialisation of branch container and histograms 
112     
113   AliInfo(Form("*** Initialization of %s", GetName())) ; 
114   
115   // Get input data
116   fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
117   if (!fChain) {
118     AliError(Form("Input 0 for %s not found\n", GetName()));
119     return ;
120   }
121   
122   fESD = new AliESDEvent();
123   fESD->ReadFromTree(fChain);
124
125 }
126
127 //________________________________________________________________________
128
129 void AliAnaCaloTrigger::CreateOutputObjects()
130 {  
131
132   // Create the outputs containers
133   OpenFile(0) ;
134
135   // create histograms 
136   fNtTrigger22 = new TNtuple(fCalorimeter+"trigger22", "Trigger data 2x2 patch", "a22:a220:enMax:phEnMax:eta22:phi22:etaMax:phiMax:phEtaMax:phPhiMax");
137   fNtTriggerNN = new TNtuple(fCalorimeter+"triggerNN", "Trigger data NxN patch", "aNN:aNN0:enMax:phEnMax:etaNN:phiNN:etaMax:phiMax:phEtaMax:phPhiMax");
138   
139   // create output container
140   
141   fOutputContainer = new TObjArray(2) ; 
142   fOutputContainer->SetName(GetName()) ; 
143   
144   fOutputContainer->AddAt(fNtTrigger22,             0) ; 
145   fOutputContainer->AddAt(fNtTriggerNN,             1) ; 
146
147 }
148
149 //______________________________________________________________________________
150 void AliAnaCaloTrigger::Exec(Option_t *) 
151 {
152   // Processing of one event
153   
154   Long64_t entry = fChain->GetReadEntry() ;
155   
156   if (!fESD) {
157     AliError("fESD is not connected to the input!") ; 
158     return ; 
159   }
160   
161   if ( !((entry-1)%100) ) 
162     AliInfo(Form("%s ----> Processing event # %lld",  (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ; 
163   
164   // Get trigger information of fCalorimeter 
165   TArrayF * triggerAmplitudes = 0x0 ;
166   TArrayF * triggerPosition   = 0x0 ;
167   Int_t numberOfCaloClusters  =  fESD->GetNumberOfCaloClusters() ;
168
169   if(fCalorimeter == "PHOS"){
170     triggerAmplitudes      = fESD->GetPHOSTriggerAmplitudes();
171     triggerPosition        = fESD->GetPHOSTriggerPosition();
172   }
173   else if(fCalorimeter == "EMCAL"){
174     triggerAmplitudes    = fESD->GetEMCALTriggerAmplitudes();
175     triggerPosition      = fESD->GetEMCALTriggerPosition();
176   }
177
178   if( triggerAmplitudes && triggerPosition ){
179   // trigger amplitudes
180   const Float_t ka22    = static_cast<Float_t>(triggerAmplitudes->At(0)) ; 
181   const Float_t ka22O   = static_cast<Float_t>(triggerAmplitudes->At(1)) ; 
182   const Float_t kaNN    = static_cast<Float_t>(triggerAmplitudes->At(2)) ; 
183   const Float_t kaNNO   = static_cast<Float_t>(triggerAmplitudes->At(3)) ; 
184
185   // trigger position
186   const Float_t kx22  =  static_cast<Float_t>(triggerPosition->At(0)) ; 
187   const Float_t ky22  =  static_cast<Float_t>(triggerPosition->At(1)) ;
188   const Float_t kz22  =  static_cast<Float_t>(triggerPosition->At(2)) ;
189   const Float_t kxNN  =  static_cast<Float_t>(triggerPosition->At(3)) ; 
190   const Float_t kyNN  =  static_cast<Float_t>(triggerPosition->At(4)) ;
191   const Float_t kzNN  =  static_cast<Float_t>(triggerPosition->At(5)) ; 
192   
193   Float_t enMax       = 0. ;
194   Float_t phEnMax     = 0. ;
195   Float_t etaMax      = 0.5 ;
196   Float_t phiMax      = 0. ; 
197   Float_t phEtaMax    = 0.5 ;
198   Float_t phPhiMax    = 0. ; 
199   
200   TVector3 vpos22(kx22, ky22, kz22) ;
201   TVector3 vposNN(kxNN, kyNN, kzNN) ;
202   Float_t eta22 = vpos22.Eta() ; 
203   Float_t phi22 = vpos22.Phi() * TMath::RadToDeg() + 360. ; 
204   Float_t etaNN = vposNN.Eta() ; 
205   Float_t phiNN = vposNN.Phi() * TMath::RadToDeg() + 360. ; 
206
207   Int_t      icaloCluster ; 
208   
209   // loop over the Calorimeters Clusters
210   
211   for(icaloCluster = 0 ; icaloCluster < numberOfCaloClusters ; icaloCluster++) {
212     
213     AliESDCaloCluster * cluster = fESD->GetCaloCluster(icaloCluster) ;
214     
215     if (cluster && ( (fCalorimeter == "PHOS" && cluster->IsPHOS())  ||  
216                      (fCalorimeter == "EMCAL" && cluster->IsEMCAL()))) {
217           
218       Float_t cluEnergy = cluster->E() ; 
219       Float_t pos[3] ;
220       TVector3 vpos ;
221       
222       cluster->GetPosition( pos ) ;
223       
224       if ( cluEnergy > enMax) { 
225         enMax = cluEnergy ; 
226         vpos.SetXYZ(pos[0], pos[1], pos[2]) ; 
227         etaMax = vpos.Eta() ; 
228         phiMax = vpos.Phi() ; 
229       }
230
231       Double_t * pid = cluster->GetPid() ;
232       
233       if(pid[AliPID::kPhoton] > 0.9) {
234         if ( cluEnergy > phEnMax) { 
235           phEnMax = cluEnergy ; 
236           vpos.SetXYZ(pos[0], pos[1], pos[2]) ; 
237           phEtaMax = vpos.Eta() ; 
238           phPhiMax = vpos.Phi() ; 
239         }
240       }
241     }//if cluster
242     
243     fNtTrigger22->Fill(ka22, ka22O, enMax, phEnMax, eta22, phi22, etaMax, phiMax * TMath::RadToDeg() + 360., phEtaMax, phPhiMax * TMath::RadToDeg() + 360.);
244     fNtTriggerNN->Fill(kaNN, kaNNO, enMax, phEnMax, etaNN, phiNN, etaMax, phiMax * TMath::RadToDeg() + 360., phEtaMax, phPhiMax * TMath::RadToDeg() + 360.);
245   }//CaloCluster loop
246   
247   }//If trigger arrays filled
248   
249   PostData(0, fOutputContainer);
250   
251 }
252
253 //______________________________________________________________________________
254 void AliAnaCaloTrigger::Terminate(Option_t *)
255 {
256   // Processing when the event loop is ended
257
258 }