10 #include "AliAnalysisTask.h"
11 #include "AliAnalysisManager.h"
13 #include "AliESDEvent.h"
14 #include "AliESDInputHandler.h"
15 #include "AliESDVertex.h"
16 #include "AliESDMuonTrack.h"
18 #include "AliAnalysisTaskSingleMuESD.h"
20 // analysis task for single muon analysis of the ESD events
21 // Authors: Bogdan Vulpescu, Nicole Bastid, LPC Clermont-Ferrand
23 ClassImp(AliAnalysisTaskSingleMuESD)
25 //________________________________________________________________________
26 AliAnalysisTaskSingleMuESD::AliAnalysisTaskSingleMuESD(const char *name)
27 : AliAnalysisTask(name, ""),
41 // Define input and output slots here
42 // Input slot #0 works with a TChain
43 DefineInput(0, TChain::Class());
44 // Output slot #0 writes into a TNtuple container
45 DefineOutput(0, TNtuple::Class());
46 // Output slot #1 writes into a TH1F container
47 DefineOutput(1, TH1F::Class());
50 //________________________________________________________________________
51 void AliAnalysisTaskSingleMuESD::ConnectInputData(Option_t *)
53 // Connect ESD or AOD here
56 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
58 Printf("ERROR: Could not read chain from input slot 0");
60 // Disable all branches and enable only the needed ones
61 // The next two lines are different when data produced as AliESDEvent is read
62 tree->SetBranchStatus("*", kFALSE);
63 tree->SetBranchStatus("MuonTracks.*", kTRUE);
64 tree->SetBranchStatus("SPDVertex.*", kTRUE);
65 tree->SetBranchStatus("AliESDHeader.*", kTRUE);
67 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
70 Printf("ERROR: Could not get ESDInputHandler");
72 fESD = esdH->GetEvent();
76 //________________________________________________________________________
77 void AliAnalysisTaskSingleMuESD::CreateOutputObjects()
79 // Create output ntuple
81 fNtuple = new TNtuple("ntEsd1mu","ntEsd1mu","VtZ:Mult:TMask:Z:Pt:P:Eta:Theta:Phi:Zpos:Hits:Xi2:Eff:TrigMatch:TrigXi2");
82 // histogram with trigger classes
83 fTrigger = new TH1F("TriggerMask","L/H/USL/USH/LSL/LSH",6,0,6);
87 //________________________________________________________________________
88 void AliAnalysisTaskSingleMuESD::Exec(Option_t *)
91 // Called for each event
92 // Fill the ntuple with variables and the trigger histogram
94 Float_t ntvar[15], pt, p, eta, thetad, phid, charge, chi2, zcoor, chi2MatchTrig;
96 Int_t masksave = 0, hits, matchTrig;
98 Double_t fZVertex = 0;
99 Double_t fYVertex = 0;
100 Double_t fXVertex = 0;
101 Double_t fErXVertex = 0;
102 Double_t fErYVertex = 0;
105 Printf("ERROR: fESD not available");
110 // mask values: L/H/USL/USH/LSL/LSH
111 // Bit position Histogram bin Trigger class
112 // 1 (less) 1 ("L") MULow single low pt
113 // 2 2 ("H") MUHigh single high pt
114 // 3 3 ("USL") MULU unlike-sign low pt
115 // 4 4 ("USH") MUHU unlike-sign high pt
116 // 5 5 ("LSL") MULL like-sign low pt
117 // 6 (most) 6 ("LSH") MUHL like-sign high pt
119 mask = fESD->GetTriggerMask();
120 if (mask & fMaskTrig1MuL) {
124 if (mask & fMaskTrig1MuH) {
128 if (mask & fMaskTrigUSL) {
132 if (mask & fMaskTrigUSH) {
136 if (mask & fMaskTrigLSL) {
140 if (mask & fMaskTrigLSH) {
145 TString firedTC = fESD->GetFiredTriggerClasses();
146 if (firedTC.Contains("MULow")) {
150 if (firedTC.Contains("MUHigh")) {
154 if (firedTC.Contains("MULU")) {
158 if (firedTC.Contains("MUHU")) {
162 if (firedTC.Contains("MULL")) {
166 if (firedTC.Contains("MUHL")) {
172 // get the SPD reconstructed vertex (vertexer)
173 AliESDVertex* vertex = (AliESDVertex*) fESD->GetVertex();
174 if (vertex->GetNContributors()) {
175 fZVertex = vertex->GetZ();
176 fYVertex = vertex->GetY();
177 fXVertex = vertex->GetX();
178 fErXVertex = vertex->GetXRes();
179 fErYVertex = vertex->GetYRes();
182 Int_t nTracks = (Int_t)fESD->GetNumberOfMuonTracks() ;
183 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
185 AliESDMuonTrack* muonTrack = new AliESDMuonTrack(*(fESD->GetMuonTrack(iTrack)));
187 Printf("ERROR: Could not receive track %d", iTrack);
191 pt = muonTrack->Pt();
193 eta = muonTrack->Eta();
194 thetad = muonTrack->Theta()*180./TMath::Pi();
195 phid = muonTrack->Phi()*180./TMath::Pi();
196 charge = muonTrack->Charge();
197 hits = muonTrack->GetNHit();
198 chi2 = muonTrack->GetChi2() / (2.0 * hits - 5);
199 zcoor = muonTrack->GetZ();
200 matchTrig = muonTrack->GetMatchTrigger();
201 chi2MatchTrig = muonTrack->GetChi2MatchTrigger();
203 rEff[0] = rEff[1] = 0.0;
204 GetEffFitted(eta,pt,rEff);
219 ntvar[13] = matchTrig;
220 ntvar[14] = chi2MatchTrig;
222 fNtuple->Fill(ntvar);
228 PostData(0, fNtuple);
229 PostData(1, fTrigger);
233 //________________________________________________________________________
234 void AliAnalysisTaskSingleMuESD::Terminate(Option_t *)
239 //________________________________________________________________________
240 void AliAnalysisTaskSingleMuESD::GetEffFitted(Double_t eta, Double_t pt, Double_t rEff[2])
242 // tracking efficiency
245 Float_t etaMin = -4.;
246 Float_t etaBin = 0.1;
248 rEff[0]=1.;rEff[1]=0.;
250 // nbinEta = number of eta bins startig at etaMin = -4 and binning of 0.1 (etaBin)
251 Float_t p0[15] = {-0.9338,-0.9441,-0.9397,-0.9586,-0.9713,-0.9752,-0.9711,-0.9751,-0.9746,-0.9729,-0.9754,-0.9722,-0.9722,-0.971,-0.9709};
252 Float_t p1[15] = {-0.6383,-1.4729,-1.0109,-1.4316,-1.5926,-1.367,-1.1895,-1.2834,-1.3289,-1.5916,-1.4258,-1.0983,-1.0812,-0.7179, -0.4613};
254 Float_t etaInf, etaSup;
255 for (Int_t i = 1; i < nbinEta+1; i++){
256 etaInf = etaMin + (i-1)*etaBin;
257 etaSup = etaMin + i*etaBin;
258 if(eta > etaInf && eta <= etaSup) numBin = i-1;
261 if(numBin>=0 && pt >=1.) rEff[0] = p0[numBin] * TMath::TanH(p1[numBin]*pt);
266 //________________________________________________________________________
267 void AliAnalysisTaskSingleMuESD::SetTriggerType(const Char_t *trig)
269 // set the trigger masks according to the trigger type used in the
272 TString triggerType(trig);
274 if (!triggerType.CompareTo("MUON")) {
275 fMaskTrig1MuL = 1; // MULow
276 fMaskTrig1MuH = 2; // MUHigh
277 fMaskTrigUSL = 4; // MULU
278 fMaskTrigLSL = 16; // MULL
279 fMaskTrigUSH = 8; // MUHU
280 fMaskTrigLSH = 32; // MUHL
281 } else if (!triggerType.CompareTo("p-p")) {
282 fMaskTrig1MuL = 128; // MULow
283 fMaskTrig1MuH = 256; // MUHigh
284 fMaskTrigUSL = 65536; // MULU
285 fMaskTrigLSL = 131072; // MULL
286 fMaskTrigUSH = 262144; // MUHU
287 fMaskTrigLSH = 524288; // MUHL
289 // MUON trigger, values by default in the constructor
292 fTriggerType = kTRUE;