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