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