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