]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/muon/AliAnalysisTaskSingleMu.cxx
Adding centrality selection and additional muon track cuts for PbPb (Xiaoming)
[u/mrichter/AliRoot.git] / PWG3 / muon / AliAnalysisTaskSingleMu.cxx
CommitLineData
aad6618e 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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
662e37fe 16//-----------------------------------------------------------------------------
17/// \class AliAnalysisTaskSingleMu
18/// Analysis task for single muons in the spectrometer.
9728bcfd 19/// The output is a list of histograms.
b201705a 20/// The macro class can run on AODs or ESDs.
21/// In the latter case a flag can be activated to produce a tree as output.
9728bcfd 22/// If Monte Carlo information is present, some basics checks are performed.
662e37fe 23///
24/// \author Diego Stocco
25//-----------------------------------------------------------------------------
26
aad6618e 27//----------------------------------------------------------------------------
28// Implementation of the single muon analysis class
662e37fe 29// An example of usage can be found in the macro RunSingleMuAnalysisFromAOD.C.
aad6618e 30//----------------------------------------------------------------------------
31
32#define AliAnalysisTaskSingleMu_cxx
33
34// ROOT includes
aad6618e 35#include "TROOT.h"
9728bcfd 36#include "TH1.h"
37#include "TH2.h"
38#include "TH3.h"
39#include "TAxis.h"
40#include "TList.h"
662e37fe 41#include "TCanvas.h"
9728bcfd 42#include "TMath.h"
b201705a 43#include "TTree.h"
44#include "TTimeStamp.h"
589e3f71 45#include "TMap.h"
46#include "TObjString.h"
55065f3f 47#include "TObjArray.h"
589e3f71 48#include "TIterator.h"
49#include "TParameter.h"
50#include "TMCProcess.h"
aad6618e 51
52// STEER includes
589e3f71 53#include "AliAODInputHandler.h"
aad6618e 54#include "AliAODEvent.h"
55#include "AliAODTrack.h"
56#include "AliAODVertex.h"
aad6618e 57
9728bcfd 58#include "AliMCParticle.h"
59#include "AliStack.h"
60
b201705a 61#include "AliESDInputHandler.h"
62#include "AliESDEvent.h"
63#include "AliESDMuonTrack.h"
9728bcfd 64
589e3f71 65#include "AliMultiplicity.h"
93d6def1 66#include "AliCentrality.h"
589e3f71 67
68// ANALYSIS includes
69#include "AliAnalysisManager.h"
9728bcfd 70#include "AliAnalysisTaskSE.h"
4ab8d5a6 71#include "AliAnalysisDataSlot.h"
72#include "AliAnalysisDataContainer.h"
589e3f71 73
74// CORRFW includes
75#include "AliCFManager.h"
76#include "AliCFContainer.h"
77#include "AliCFGridSparse.h"
78#include "AliCFTrackKineCuts.h"
79#include "AliCFParticleGenCuts.h"
80#include "AliCFEventRecCuts.h"
81
aad6618e 82#include "AliAnalysisTaskSingleMu.h"
83
662e37fe 84/// \cond CLASSIMP
85ClassImp(AliAnalysisTaskSingleMu) // Class implementation in ROOT context
86/// \endcond
aad6618e 87
9728bcfd 88
aad6618e 89//________________________________________________________________________
589e3f71 90AliAnalysisTaskSingleMu::AliAnalysisTaskSingleMu(const char *name, Int_t fillTreeScaleDown, Bool_t keepAll) :
9728bcfd 91 AliAnalysisTaskSE(name),
589e3f71 92 fFillTreeScaleDown(fillTreeScaleDown),
b201705a 93 fKeepAll(keepAll),
589e3f71 94 fkNvtxContribCut(1),
4ab8d5a6 95 fTriggerClasses(0x0),
589e3f71 96 fCFManager(0),
9728bcfd 97 fHistoList(0),
b201705a 98 fHistoListMC(0),
589e3f71 99 fHistoListQA(0),
b201705a 100 fTreeSingleMu(0),
b201705a 101 fVarFloat(0),
102 fVarInt(0),
103 fVarChar(0),
104 fVarUInt(0),
105 fVarFloatMC(0),
589e3f71 106 fVarIntMC(0),
93d6def1 107 fAuxObjects(new TMap()),
108 fDebugString("")
aad6618e 109{
110 //
111 /// Constructor.
112 //
589e3f71 113 if ( fFillTreeScaleDown <= 0 )
b201705a 114 fKeepAll = kFALSE;
115
589e3f71 116 DefineOutput(1, AliCFContainer::Class());
9728bcfd 117 DefineOutput(2, TList::Class());
589e3f71 118 DefineOutput(3, TList::Class());
119 DefineOutput(4, TList::Class());
120
121 if ( fFillTreeScaleDown > 0 )
122 DefineOutput(5, TTree::Class());
123
55065f3f 124 fAuxObjects->SetOwner();
b201705a 125
55065f3f 126 SetTriggerClasses();
aad6618e 127}
128
9728bcfd 129
130//________________________________________________________________________
131AliAnalysisTaskSingleMu::~AliAnalysisTaskSingleMu()
aad6618e 132{
133 //
9728bcfd 134 /// Destructor
aad6618e 135 //
589e3f71 136
4ab8d5a6 137 delete fTriggerClasses;
138 // For proof: do not delete output containers
139 if ( ! AliAnalysisManager::GetAnalysisManager()->IsProofMode() ) {
140 delete fCFManager->GetParticleContainer(); // The container is not deleted by framework
141 delete fCFManager;
142 delete fHistoList;
143 delete fHistoListMC;
144 delete fHistoListQA;
145 delete fTreeSingleMu;
146 }
b201705a 147 delete fVarFloat;
148 delete fVarInt;
149 delete [] fVarChar;
150 delete fVarUInt;
151 delete fVarFloatMC;
152 delete fVarIntMC;
55065f3f 153 delete fAuxObjects;
9728bcfd 154}
aad6618e 155
9728bcfd 156
157//___________________________________________________________________________
b201705a 158void AliAnalysisTaskSingleMu::NotifyRun()
9728bcfd 159{
160 //
161 /// Use the event handler information to correctly fill the analysis flags:
162 /// - check if Monte Carlo information is present
163 //
164
589e3f71 165 if ( fMCEvent ) {
9728bcfd 166 AliInfo("Monte Carlo information is present");
167 }
168 else {
169 AliInfo("No Monte Carlo information in run");
aad6618e 170 }
589e3f71 171}
172
173
174//___________________________________________________________________________
175void AliAnalysisTaskSingleMu::FinishTaskOutput()
176{
177 //
178 /// Perform histogram normalization after the last analyzed event
179 /// but before merging
180 //
181
589e3f71 182 // Set the correct run limits for the histograms
183 // vs run number to cope with the merging
4ab8d5a6 184 Int_t histoIndex = -1;
589e3f71 185 Int_t indexPerRun[2] = {kHistoNeventsPerRun, kHistoNmuonsPerRun};
186 for ( Int_t ihisto=0; ihisto<2; ihisto++) {
187 histoIndex = GetHistoIndex(indexPerRun[ihisto]);
188 TH2F* histo2D = (TH2F*)fHistoList->At(histoIndex);
189 Double_t minX = 1e10, maxX = -1e10;
190 for (Int_t ibin=1; ibin<=histo2D->GetXaxis()->GetNbins(); ibin++){
191 TString runNum = histo2D->GetXaxis()->GetBinLabel(ibin);
192 minX = TMath::Min(runNum.Atof()-0.5, minX);
193 maxX = TMath::Max(runNum.Atof()+0.5, maxX);
194 }
195 histo2D->GetXaxis()->SetLimits(minX, maxX);
196 AliInfo(Form("Histogram %s run limits (%f, %f)",histo2D->GetName(), minX, maxX));
197 }
aad6618e 198}
199
9728bcfd 200
aad6618e 201//___________________________________________________________________________
9728bcfd 202void AliAnalysisTaskSingleMu::UserCreateOutputObjects()
aad6618e 203{
204 //
205 /// Create output histograms
206 //
9728bcfd 207 AliInfo(Form(" CreateOutputObjects of task %s\n", GetName()));
aad6618e 208
9728bcfd 209 // initialize histogram lists
589e3f71 210 if ( ! fHistoList ) fHistoList = new TList();
211 if ( ! fHistoListMC ) fHistoListMC = new TList();
212 if ( ! fHistoListQA ) fHistoListQA = new TList();
b201705a 213
214 // Init variables
215 fVarFloat = new Float_t [kNvarFloat];
216 fVarInt = new Int_t [kNvarInt];
217 fVarChar = new Char_t *[kNvarChar];
218 fVarUInt = new UInt_t [kNvarUInt];
219 fVarFloatMC = new Float_t [kNvarFloatMC];
220 fVarIntMC = new Int_t [kNvarIntMC];
589e3f71 221
222 const Int_t charWidth[kNvarChar] = {255};
223 for(Int_t ivar=0; ivar<kNvarChar; ivar++){
224 fVarChar[ivar] = new Char_t [charWidth[ivar]];
225 }
226
9728bcfd 227 Int_t nPtBins = 60;
589e3f71 228 Double_t ptMin = 0., ptMax = 30.;
9728bcfd 229 TString ptName("Pt"), ptTitle("p_{t}"), ptUnits("GeV/c");
589e3f71 230
55065f3f 231 Int_t nRapidityBins = 25;
232 Double_t rapidityMin = -4.5, rapidityMax = -2.;
4ab8d5a6 233 //TString rapidityName("Rapidity"), rapidityTitle("y"), rapidityUnits("");
234 TString rapidityName("Eta"), rapidityTitle("#eta"), rapidityUnits("");
589e3f71 235
236 Int_t nPhiBins = 36;
237 Double_t phiMin = 0.; Double_t phiMax = 2*TMath::Pi();
238 TString phiName("Phi"), phiTitle("#phi"), phiUnits("rad");
9728bcfd 239
589e3f71 240 Int_t nDcaBins = 30;
241 Double_t dcaMin = 0., dcaMax = 300.;
9728bcfd 242 TString dcaName("DCA"), dcaTitle("DCA"), dcaUnits("cm");
662e37fe 243
589e3f71 244 Int_t nVzBins = 40;
245 Double_t vzMin = -20., vzMax = 20.;
9728bcfd 246 TString vzName("Vz"), vzTitle("Vz"), vzUnits("cm");
247
589e3f71 248 Int_t nThetaAbsEndBins = 4;
249 Double_t thetaAbsEndMin = -0.5, thetaAbsEndMax = 3.5;
250 TString thetaAbsEndName("ThetaAbsEnd"), thetaAbsEndTitle("#theta_{abs}"), thetaAbsEndUnits("a.u.");
251
252 Int_t nChargeBins = 2;
253 Double_t chargeMin = -2, chargeMax = 2.;
254 TString chargeName("Charge"), chargeTitle("charge"), chargeUnits("e");
255
256 Int_t nMatchTrigBins = 4;
257 Double_t matchTrigMin = -0.5, matchTrigMax = 3.5;
258 TString matchTrigName("MatchTrig"), matchTrigTitle("Trigger match"), matchTrigUnits("");
9728bcfd 259
55065f3f 260 Int_t nTrigClassBins = fTriggerClasses->GetEntries();
261 Double_t trigClassMin = 0.5, trigClassMax = (Double_t)nTrigClassBins + 0.5;
4ab8d5a6 262 TString trigClassName("TrigClass"), trigClassTitle("Fired trigger class"), trigClassUnits("");
589e3f71 263
264 Int_t nGoodVtxBins = 3;
265 Double_t goodVtxMin = -0.5, goodVtxMax = 2.5;
266 TString goodVtxName("GoodVtx"), goodVtxTitle("Vertex flags"), goodVtxUnits("");
267
268 Int_t nMotherTypeBins = kNtrackSources;
269 Double_t motherTypeMin = -0.5, motherTypeMax = (Double_t)kNtrackSources - 0.5;
270 TString motherType("MotherType"), motherTypeTitle("motherType"), motherTypeUnits("");
9728bcfd 271
93d6def1 272 Int_t nCentralityBins = 10;
273 Double_t centralityMin = 0., centralityMax = 100.;
274 TString centralityName("Centrality"), centralityTitle("centrality"), centralityUnits("%");
4ab8d5a6 275
9728bcfd 276 TString trigName[kNtrigCuts];
277 trigName[kNoMatchTrig] = "NoMatch";
278 trigName[kAllPtTrig] = "AllPt";
279 trigName[kLowPtTrig] = "LowPt";
280 trigName[kHighPtTrig] = "HighPt";
281
282 TString srcName[kNtrackSources];
283 srcName[kCharmMu] = "Charm";
284 srcName[kBeautyMu] = "Beauty";
285 srcName[kPrimaryMu] = "Decay";
286 srcName[kSecondaryMu] = "Secondary";
287 srcName[kRecoHadron] = "Hadrons";
93d6def1 288 srcName[kUnknownPart] = "Unidentified";
9728bcfd 289
290 TH1F* histo1D = 0x0;
291 TH2F* histo2D = 0x0;
292 TString histoName, histoTitle;
293 Int_t histoIndex = 0;
294
589e3f71 295 // Multi-dimensional histo
93d6def1 296 Int_t nbins[kNvars] = {nPtBins, nRapidityBins, nPhiBins, nDcaBins, nVzBins, nThetaAbsEndBins, nChargeBins, nMatchTrigBins, nTrigClassBins, nGoodVtxBins, nMotherTypeBins, nCentralityBins};
297 Double_t xmin[kNvars] = {ptMin, rapidityMin, phiMin, dcaMin, vzMin, thetaAbsEndMin, chargeMin, matchTrigMin, trigClassMin, goodVtxMin, motherTypeMin, centralityMin};
298 Double_t xmax[kNvars] = {ptMax, rapidityMax, phiMax, dcaMax, vzMax, thetaAbsEndMax, chargeMax, matchTrigMax, trigClassMax, goodVtxMax, motherTypeMax, centralityMax};
299 TString axisTitle[kNvars] = {ptTitle, rapidityTitle, phiTitle, dcaTitle, vzTitle, thetaAbsEndTitle, chargeTitle, matchTrigTitle, trigClassTitle, goodVtxTitle, motherTypeTitle, centralityTitle};
300 TString axisUnits[kNvars] = {ptUnits, rapidityUnits, phiUnits, dcaUnits, vzUnits, thetaAbsEndUnits, chargeUnits, matchTrigUnits, trigClassUnits, goodVtxUnits, motherTypeUnits, centralityUnits};
662e37fe 301
4ab8d5a6 302 //TString stepTitle[kNsteps] = {"reconstructed", "in acceptance", "generated", "in acceptance (MC)"};
303 TString stepTitle[kNsteps] = {"reconstructed", "generated"};
589e3f71 304
305 // Create CF container
4ab8d5a6 306
307 // The framework has problems if the name of the object
308 // and the one of container differ
309 // To be complaint, get the name from container and set it
310 TString containerName = GetOutputSlot(1)->GetContainer()->GetName();
311
312 AliCFContainer* container = new AliCFContainer(containerName.Data(),"container for tracks",kNsteps,kNvars,nbins);
589e3f71 313
314 for ( Int_t idim = 0; idim<kNvars; idim++){
315 histoTitle = Form("%s (%s)", axisTitle[idim].Data(), axisUnits[idim].Data());
316 histoTitle.ReplaceAll("()","");
317
318 container->SetVarTitle(idim, histoTitle.Data());
319 container->SetBinLimits(idim, xmin[idim], xmax[idim]);
9728bcfd 320 }
589e3f71 321
322 for (Int_t istep=0; istep<kNsteps; istep++){
323 container->SetStepTitle(istep, stepTitle[istep].Data());
324 AliCFGridSparse* gridSparse = container->GetGrid(istep);
325
326 SetAxisLabel(gridSparse->GetAxis(kHvarTrigClass));
327 TAxis* isGoodVtxAxis = gridSparse->GetAxis(kHvarIsGoodVtx);
328 isGoodVtxAxis->SetBinLabel(1,Form("No vertex (contrib<%i)",fkNvtxContribCut));
329 isGoodVtxAxis->SetBinLabel(2,"Good vertex");
330 isGoodVtxAxis->SetBinLabel(3,"Pileup");
331 TAxis* motherTypeAxis = gridSparse->GetAxis(kHvarMotherType);
332 for (Int_t ibin=0; ibin<kNtrackSources; ibin++){
333 motherTypeAxis->SetBinLabel(ibin+1,srcName[ibin]);
334 }
9728bcfd 335 }
589e3f71 336
337 // Create cuts
338
339 //Particle-Level cuts:
340 AliCFParticleGenCuts* mcGenCuts = new AliCFParticleGenCuts();
341 mcGenCuts->SetNameTitle("mcGenCuts","MC particle generation cuts");
342 mcGenCuts->SetRequirePdgCode(13,kTRUE);
343 mcGenCuts->SetQAOn(fHistoListQA);
344
4ab8d5a6 345 /*
589e3f71 346 // MC kinematic cuts
347 AliCFTrackKineCuts *mcAccCuts = new AliCFTrackKineCuts();
348 mcAccCuts->SetNameTitle("mcAccCuts","MC-level acceptance cuts");
349 mcAccCuts->SetEtaRange(-4.,-2.5);
589e3f71 350 mcAccCuts->SetQAOn(fHistoListQA);
351
589e3f71 352 // Rec-Level kinematic cuts
353 AliCFTrackKineCuts *recAccCuts = new AliCFTrackKineCuts();
354 recAccCuts->SetNameTitle("recAccCuts","Reco-level acceptance cuts");
355 recAccCuts->SetEtaRange(-4.,-2.5);
356 recAccCuts->SetQAOn(fHistoListQA);
4ab8d5a6 357 */
589e3f71 358
589e3f71 359 TObjArray* mcGenList = new TObjArray(0) ;
360 mcGenList->AddLast(mcGenCuts);
361
4ab8d5a6 362 /*
589e3f71 363 TObjArray* mcAccList = new TObjArray(0);
364 mcAccList->AddLast(mcAccCuts);
365
589e3f71 366 TObjArray* recAccList = new TObjArray(0);
367 recAccList->AddLast(recAccCuts);
4ab8d5a6 368 */
589e3f71 369
589e3f71 370 // Create CF manager
371 fCFManager = new AliCFManager() ;
372 fCFManager->SetParticleContainer(container);
373
374 // Add cuts
375 // Dummy event container
376 Int_t dummyBins[1] = {1};
377 AliCFContainer* evtContainer = new AliCFContainer("dummyContainer","dummy contaier for events",1,1,dummyBins);
378 fCFManager->SetEventContainer(evtContainer);
379 fCFManager->SetEventCutsList(0,0x0);
380
381 // Init empty cuts (avoid warnings in framework)
382 for (Int_t istep=0; istep<kNsteps; istep++) {
383 fCFManager->SetParticleCutsList(istep,0x0);
662e37fe 384 }
4ab8d5a6 385 //fCFManager->SetParticleCutsList(kStepAcceptance,recAccList);
589e3f71 386 fCFManager->SetParticleCutsList(kStepGeneratedMC,mcGenList);
4ab8d5a6 387 //fCFManager->SetParticleCutsList(kStepAcceptanceMC,mcAccList);
662e37fe 388
b201705a 389 // Summary histos
589e3f71 390 histoName = "histoNeventsPerTrig";
391 histoTitle = "Number of events per trigger class";
392 histo2D = new TH2F(histoName.Data(), histoTitle.Data(), nTrigClassBins, trigClassMin, trigClassMax, 5, 0.5, 5.5);
393 histo2D->GetXaxis()->SetTitle("Fired class");
394 SetAxisLabel(histo2D->GetXaxis());
395 histo2D->GetYaxis()->SetBinLabel(1, "All events");
396 histo2D->GetYaxis()->SetBinLabel(2, "Good vtx events");
397 histo2D->GetYaxis()->SetBinLabel(3, "Pileup events");
398 histo2D->GetYaxis()->SetBinLabel(4, "All vertices");
399 histo2D->GetYaxis()->SetBinLabel(5, "Pileup vertices");
400 histoIndex = GetHistoIndex(kHistoNeventsPerTrig);
401 fHistoList->AddAt(histo2D, histoIndex);
402
b201705a 403 histoName = "histoMuonMultiplicity";
404 histoTitle = "Muon track multiplicity";
589e3f71 405 histo2D = new TH2F(histoName.Data(), histoTitle.Data(), 15, -0.5, 15-0.5,
406 nTrigClassBins, trigClassMin, trigClassMax);
407 histo2D->GetXaxis()->SetTitle("# of muons");
408 SetAxisLabel(histo2D->GetYaxis());
409 histoIndex = GetHistoIndex(kHistoMuonMultiplicity);
410 fHistoList->AddAt(histo2D, histoIndex);
411
412 histoName = "histoEventVz";
413 histoTitle = "All events IP Vz distribution";
4ab8d5a6 414 histo2D = new TH2F(histoName.Data(), histoTitle.Data(), nTrigClassBins, trigClassMin, trigClassMax, nVzBins, vzMin, vzMax);
415 histo2D->GetXaxis()->SetTitle("Fired class");
416 SetAxisLabel(histo2D->GetXaxis());
589e3f71 417 histoTitle = Form("%s (%s)", vzTitle.Data(), vzUnits.Data());
4ab8d5a6 418 histo2D->GetYaxis()->SetTitle(histoTitle.Data());
589e3f71 419 histoIndex = GetHistoIndex(kHistoEventVz);
4ab8d5a6 420 fHistoList->AddAt(histo2D, histoIndex);
b201705a 421
589e3f71 422 Int_t hRunIndex[2] = {kHistoNeventsPerRun, kHistoNmuonsPerRun};
423 TString hRunName[2] = {"histoNeventsPerRun", "histoNmuonsPerRun"};
424 TString hRunTitle[2] = {"Number of events per run", "Number of muons per run"};
425 for ( Int_t ihisto=0; ihisto<2; ihisto++){
426 histoName = hRunName[ihisto];
427 histoTitle = hRunTitle[ihisto];
428 histo2D = new TH2F(histoName.Data(), histoTitle.Data(),
429 1, 0., 0.,
430 nTrigClassBins, trigClassMin, trigClassMax);
431 histo2D->GetXaxis()->SetTitle("Run number");
432 SetAxisLabel(histo2D->GetYaxis());
433 histo2D->Sumw2();
434 histoIndex = hRunIndex[ihisto];
435 fHistoList->AddAt(histo2D, histoIndex);
436 }
437
438 // MC histos summary
93d6def1 439 Int_t hCheckVzIndex[3] = {kHistoCheckVzMC, kHistoCheckVzHasVtxMC, kHistoCheckVzNoPileupMC};
440 TString hCheckVzName[3] = {"histoCheckVz", "histoCheckVzHasVtx", "histoCheckVzIsPileup"};
441 TString hCheckVzTitle[3] = {"", " w/ vertex contributors", "w/ pileup SPD"};
442
443 for ( Int_t ihisto=0; ihisto<3; ihisto++ ) {
444 histoName = hCheckVzName[ihisto];
445 histoTitle = Form("Check IP Vz distribution %s", hCheckVzTitle[ihisto].Data());
446
447 histo2D = new TH2F(histoName.Data(), histoTitle.Data(),
448 nVzBins, vzMin, vzMax,
449 nVzBins, vzMin, vzMax);
450 histoTitle = Form("%s (%s)", vzTitle.Data(), vzUnits.Data());
451 histo2D->GetXaxis()->SetTitle(histoTitle.Data());
452 histoTitle = Form("%s MC (%s)", vzTitle.Data(), vzUnits.Data());
453 histo2D->GetYaxis()->SetTitle(histoTitle.Data());
454 histoIndex = GetHistoIndex(hCheckVzIndex[ihisto]);
455 fHistoListMC->AddAt(histo2D, histoIndex);
456 }
589e3f71 457
9728bcfd 458 // MC histos
459 for (Int_t itrig=0; itrig < kNtrigCuts; itrig++) {
460 for (Int_t isrc = 0; isrc < kNtrackSources; isrc++) {
461 histoName = Form("%sResolution%sTrig%s", ptName.Data(), trigName[itrig].Data(), srcName[isrc].Data());
462 histoTitle = Form("%s resolution. Trigger: %s (%s)", ptTitle.Data(), trigName[itrig].Data(), srcName[isrc].Data());
463 histo1D = new TH1F(histoName.Data(), histoTitle.Data(), 100, -5., 5.);
464 histo1D->GetXaxis()->SetTitle(Form("%s^{reco} - %s^{MC} (%s)", ptTitle.Data(), ptTitle.Data(), ptUnits.Data()));
b201705a 465 histoIndex = GetHistoIndex(kHistoPtResolutionMC, itrig, isrc);
9728bcfd 466 fHistoListMC->AddAt(histo1D, histoIndex);
467 }
468 }
469
b201705a 470 // Trees
4ab8d5a6 471 if ( fFillTreeScaleDown > 0 ) {
b201705a 472 TString leavesFloat[kNvarFloat] = {"Px", "Py", "Pz", "Pt",
473 "PxAtDCA", "PyAtDCA", "PzAtDCA", "PtAtDCA",
474 "PxUncorrected", "PyUncorrected", "PzUncorrected", "PtUncorrected",
475 "XUncorrected", "YUncorrected", "ZUncorrected",
476 "XatDCA", "YatDCA", "DCA",
589e3f71 477 "Eta", "Rapidity", "Charge", "RAtAbsEnd",
93d6def1 478 "IPVx", "IPVy", "IPVz", "Centrality"};
589e3f71 479 TString leavesInt[kNvarInt] = {"MatchTrig", "IsMuon", "IsGhost", "LoCircuit", "PassPhysicsSelection", "NVtxContrib", "NspdTracklets", "IsPileupVertex"};
b201705a 480 TString leavesChar[kNvarChar] = {"FiredTrigClass"};
b201705a 481 TString leavesUInt[kNvarUInt] = {"BunchCrossNum", "OrbitNum", "PeriodNum", "RunNum"};
93d6def1 482 TString leavesFloatMC[kNvarFloatMC] = {"PxMC", "PyMC", "PzMC", "PtMC",
483 "EtaMC", "RapidityMC",
484 "VxMC", "VyMC", "VzMC",
485 "MotherPxMC", "MotherPyMC", "MotherPzMC",
486 "MotherEtaMC", "MotherRapidityMC",
487 "MotherVxMC", "MotherVyMC", "MotherVzMC",
488 "IPVxMC", "IPVyMC", "IPVzMC"};
489 TString leavesIntMC[kNvarIntMC] = {"Pdg", "MotherPdg", "MotherType"};
b201705a 490
4ab8d5a6 491 TString treeName = GetOutputSlot(5)->GetContainer()->GetName();
492 Bool_t hasMC = AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler();
493 TString treeTitle = ( hasMC ) ? "Single Mu" : "Single Mu MC";
b201705a 494
4ab8d5a6 495 OpenFile(5);
496 if ( ! fTreeSingleMu ) fTreeSingleMu = new TTree(treeName.Data(), treeTitle.Data());
b201705a 497
498 for(Int_t itree=0; itree<2; itree++){
589e3f71 499 TParameter<Int_t>* par1 = new TParameter<Int_t>("fillTreeScaleDown",fFillTreeScaleDown);
500 TParameter<Int_t>* par2 = new TParameter<Int_t>("keepAllEvents",fKeepAll);
4ab8d5a6 501 fTreeSingleMu->GetUserInfo()->Add(par1);
502 fTreeSingleMu->GetUserInfo()->Add(par2);
b201705a 503 for(Int_t ivar=0; ivar<kNvarFloat; ivar++){
4ab8d5a6 504 fTreeSingleMu->Branch(leavesFloat[ivar].Data(), &fVarFloat[ivar], Form("%s/F", leavesFloat[ivar].Data()));
b201705a 505 }
506 for(Int_t ivar=0; ivar<kNvarInt; ivar++){
4ab8d5a6 507 fTreeSingleMu->Branch(leavesInt[ivar].Data(), &fVarInt[ivar], Form("%s/I", leavesInt[ivar].Data()));
b201705a 508 }
509 for(Int_t ivar=0; ivar<kNvarChar; ivar++){
b201705a 510 TString addString = leavesChar[ivar] + "/C";
4ab8d5a6 511 fTreeSingleMu->Branch(leavesChar[ivar].Data(), fVarChar[ivar], addString.Data());
b201705a 512 }
513 for(Int_t ivar=0; ivar<kNvarUInt; ivar++){
4ab8d5a6 514 fTreeSingleMu->Branch(leavesUInt[ivar].Data(), &fVarUInt[ivar], Form("%s/i", leavesUInt[ivar].Data()));
b201705a 515 }
4ab8d5a6 516 if ( hasMC ){
b201705a 517 for(Int_t ivar=0; ivar<kNvarFloatMC; ivar++){
4ab8d5a6 518 fTreeSingleMu->Branch(leavesFloatMC[ivar].Data(), &fVarFloatMC[ivar], Form("%s/F", leavesFloatMC[ivar].Data()));
b201705a 519 }
520 for(Int_t ivar=0; ivar<kNvarIntMC; ivar++){
4ab8d5a6 521 fTreeSingleMu->Branch(leavesIntMC[ivar].Data(), &fVarIntMC[ivar], Form("%s/I", leavesIntMC[ivar].Data()));
b201705a 522 }
523 }
524 } // loop on trees
4ab8d5a6 525 PostData(5, fTreeSingleMu);
b201705a 526 } // fillNTuple
4ab8d5a6 527
55065f3f 528 PostData(1, fCFManager->GetParticleContainer());
529 PostData(2, fHistoList);
530 PostData(3, fHistoListQA);
4ab8d5a6 531 PostData(4, fHistoListMC);
532
aad6618e 533}
534
535//________________________________________________________________________
9728bcfd 536void AliAnalysisTaskSingleMu::UserExec(Option_t * /*option*/)
aad6618e 537{
538 //
539 /// Main loop
540 /// Called for each event
541 //
542
b201705a 543 AliESDEvent* esdEvent = 0x0;
9728bcfd 544 AliAODEvent* aodEvent = 0x0;
9728bcfd 545
b201705a 546 esdEvent = dynamic_cast<AliESDEvent*> (InputEvent());
547 if ( ! esdEvent ){
b201705a 548 aodEvent = dynamic_cast<AliAODEvent*> (InputEvent());
549 }
aad6618e 550
b201705a 551 if ( ! aodEvent && ! esdEvent ) {
552 AliError ("AOD or ESD event not found. Nothing done!");
aad6618e 553 return;
554 }
555
589e3f71 556 if ( ! fMCEvent && InputEvent()->GetEventType() != 7 ) return; // Run only on physics events!
557
589e3f71 558 Bool_t fillCurrentEventTree = ( fFillTreeScaleDown == 0 ) ? kFALSE : ( Entry() % fFillTreeScaleDown == 0 );
559
560 Reset(kFALSE);
561
562 // Global event info
563 TString firedTrigClasses = ( esdEvent ) ? esdEvent->GetFiredTriggerClasses() : aodEvent->GetFiredTriggerClasses();
4ab8d5a6 564 /*
589e3f71 565 if ( fMCEvent ) {
566 // Add the MB name (which is not there in simulation)
567 // CAVEAT: to be checked if we perform beam-gas simulations
4ab8d5a6 568 if ( ! firedTrigClasses.Contains("CINT") && ! firedTrigClasses.Contains("MB") ) {
569 TString trigName = ((TObjString*)fTriggerClasses->At(0))->GetString();
570 firedTrigClasses.Prepend(Form("%s ", trigName.Data()));
55065f3f 571 }
589e3f71 572 }
4ab8d5a6 573 */
55065f3f 574
93d6def1 575 Double_t centralityValue = InputEvent()->GetCentrality()->GetCentralityPercentile("V0M");
576 // Avoid filling overflow bin when centrality is exactly 100.
577 Double_t centralityForContainer = TMath::Min(centralityValue, 99.999);
578
589e3f71 579 fVarFloat[kVarIPVz] = ( esdEvent ) ? esdEvent->GetPrimaryVertex()->GetZ() : aodEvent->GetPrimaryVertex()->GetZ();
580 fVarInt[kVarNVtxContrib] = ( esdEvent ) ? esdEvent->GetPrimaryVertex()->GetNContributors() : aodEvent->GetPrimaryVertex()->GetNContributors();
581 fVarInt[kVarNspdTracklets] = ( esdEvent ) ? esdEvent->GetMultiplicity()->GetNumberOfTracklets() : aodEvent->GetTracklets()->GetNumberOfTracklets();
55065f3f 582 fVarInt[kVarIsPileup] = ( esdEvent ) ? esdEvent->IsPileupFromSPD(3,0.8) : aodEvent->IsPileupFromSPD(3,0.8); // REMEMBER TO CHECK
589e3f71 583
584 fVarUInt[kVarRunNumber] = ( esdEvent ) ? esdEvent->GetRunNumber() : aodEvent->GetRunNumber();
585
586 Int_t isGoodVtxBin = ( fVarInt[kVarNVtxContrib] >= fkNvtxContribCut );
93d6def1 587 if ( isGoodVtxBin && fVarInt[kVarIsPileup] > 0 )
589e3f71 588 isGoodVtxBin = 2;
589
590 if ( fillCurrentEventTree ){
4ab8d5a6 591 strncpy(fVarChar[kVarTrigMask], firedTrigClasses.Data(),255);
93d6def1 592 fVarFloat[kVarCentrality] = centralityValue;
b201705a 593
589e3f71 594 fVarInt[kVarPassPhysicsSelection] = ( esdEvent ) ? ((AliESDInputHandler*)AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler())->IsEventSelected() : ((AliAODInputHandler*)AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler())->IsEventSelected();
b201705a 595
596 // Small workaround: in MC the bunch ID are not properly set and the timestamp is in seconds
597 // So fill bunchCrossing with the read timestamp
598 // fill the orbit and period number with a timestamp created while reading the run
599 TTimeStamp ts;
589e3f71 600 fVarUInt[kVarBunchCrossNumber] = ( fMCEvent ) ? (UInt_t)Entry() : esdEvent->GetBunchCrossNumber();
601 fVarUInt[kVarOrbitNumber] = ( fMCEvent ) ? ts.GetNanoSec() : esdEvent->GetOrbitNumber();
602 fVarUInt[kVarPeriodNumber] = ( fMCEvent ) ? ts.GetTime() : esdEvent->GetPeriodNumber();
9728bcfd 603
589e3f71 604 fVarFloat[kVarIPVx] = ( esdEvent ) ? esdEvent->GetPrimaryVertex()->GetX() : aodEvent->GetPrimaryVertex()->GetX();
605 fVarFloat[kVarIPVy] = ( esdEvent ) ? esdEvent->GetPrimaryVertex()->GetY() : aodEvent->GetPrimaryVertex()->GetY();
606 }
aad6618e 607
93d6def1 608 firedTrigClasses.Append(" ANY");
609
aad6618e 610 // Object declaration
589e3f71 611 AliMCParticle* mcPart = 0x0;
612 AliVParticle* track = 0x0;
aad6618e 613
589e3f71 614 Double_t containerInput[kNvars];
615 Int_t histoIndex = -1;
b201705a 616
589e3f71 617 fCFManager->SetRecEventInfo(InputEvent());
b201705a 618
589e3f71 619 // Pure Monte Carlo part
620 if ( fMCEvent ) {
621 fCFManager->SetMCEventInfo (fMCEvent);
622 Int_t nMCtracks = fMCEvent->GetNumberOfTracks();
623 if ( nMCtracks > 0 ) {
93d6def1 624 fVarFloatMC[kVarIPVxMC] = fMCEvent->Stack()->Particle(0)->Vx();
625 fVarFloatMC[kVarIPVyMC] = fMCEvent->Stack()->Particle(0)->Vy();
626 fVarFloatMC[kVarIPVzMC] = fMCEvent->Stack()->Particle(0)->Vz();
627 containerInput[kHvarVz] = fVarFloatMC[kVarIPVzMC];
589e3f71 628 containerInput[kHvarIsGoodVtx] = 1;
93d6def1 629 containerInput[kHvarCentrality] = centralityForContainer;
589e3f71 630 histoIndex = GetHistoIndex(kHistoCheckVzMC);
93d6def1 631 ((TH2F*)fHistoListMC->At(histoIndex))->Fill(fVarFloat[kVarIPVz], fVarFloatMC[kVarIPVzMC]);
632 if ( isGoodVtxBin >= 1 ) {
633 histoIndex = GetHistoIndex(kHistoCheckVzHasVtxMC);
634 ((TH2F*)fHistoListMC->At(histoIndex))->Fill(fVarFloat[kVarIPVz], fVarFloatMC[kVarIPVzMC]);
635 }
636 if ( isGoodVtxBin == 1 ) {
637 histoIndex = GetHistoIndex(kHistoCheckVzNoPileupMC);
638 ((TH2F*)fHistoListMC->At(histoIndex))->Fill(fVarFloat[kVarIPVz], fVarFloatMC[kVarIPVzMC]);
639 }
589e3f71 640 }
641
642 for (Int_t ipart=0; ipart<nMCtracks; ipart++) {
643 mcPart = (AliMCParticle*)fMCEvent->GetTrack(ipart);
644
645 //check the MC-level cuts
646 if ( ! fCFManager->CheckParticleCuts(kStepGeneratedMC,mcPart) )
647 continue;
648
649 containerInput[kHvarPt] = mcPart->Pt();
4ab8d5a6 650 //containerInput[kHvarY] = mcPart->Y();
651 containerInput[kHvarEta] = mcPart->Eta();
589e3f71 652 containerInput[kHvarPhi] = mcPart->Phi();
653 containerInput[kHvarDCA] = TMath::Sqrt(mcPart->Xv()*mcPart->Xv() +
654 mcPart->Yv()*mcPart->Yv());
655 containerInput[kHvarThetaZones] = GetBinThetaAbsEnd(TMath::Pi()-mcPart->Theta(),kTRUE);
656 containerInput[kHvarCharge] = mcPart->Charge()/3.;
657 containerInput[kHvarMatchTrig] = 1.;
589e3f71 658 containerInput[kHvarMotherType] = (Double_t)RecoTrackMother(mcPart);
93d6def1 659 //containerInput[kHvarP] = mcPart->P();
589e3f71 660
55065f3f 661 for ( Int_t itrig=0; itrig<fTriggerClasses->GetEntries(); itrig++ ) {
662 TString trigName = ((TObjString*)fTriggerClasses->At(itrig))->GetString();
663 if ( ! firedTrigClasses.Contains(trigName.Data()) )
664 continue;
665 containerInput[kHvarTrigClass] = (Double_t)(itrig+1);
666 fCFManager->GetParticleContainer()->Fill(containerInput,kStepGeneratedMC);
4ab8d5a6 667 // if ( fCFManager->CheckParticleCuts(kStepAcceptanceMC,mcPart) ) fCFManager->GetParticleContainer()->Fill(containerInput,kStepAcceptanceMC);
55065f3f 668 } // loop on trigger classes
93d6def1 669 if ( fDebug >= 2 ) printf("AliAnalysisTaskSingleMu: Pure MC. %s. Set mother %i\n", fDebugString.Data(), (Int_t)containerInput[kHvarMotherType]);
589e3f71 670 } // loop on MC particles
671 } // is MC
672
673
674 Int_t trackLabel = -1;
b201705a 675 Bool_t isGhost = kFALSE;
676 Int_t nGhosts = 0, nMuons = 0;
677
589e3f71 678 Int_t nTracks = ( esdEvent ) ? esdEvent->GetNumberOfMuonTracks() : aodEvent->GetNTracks();
9728bcfd 679
680 for (Int_t itrack = 0; itrack < nTracks; itrack++) {
aad6618e 681
9728bcfd 682 // Get variables
b201705a 683 if ( esdEvent ){
589e3f71 684 // ESD only info
9728bcfd 685
b201705a 686 track = esdEvent->GetMuonTrack(itrack);
687 isGhost = ( ((AliESDMuonTrack*)track)->ContainTriggerData() && ! ((AliESDMuonTrack*)track)->ContainTrackerData() );
688
589e3f71 689 if ( fillCurrentEventTree ) {
690 if ( itrack > 0 ) Reset(kTRUE);
691 fVarFloat[kVarPxUncorrected] = ( isGhost ) ? -TMath::Tan(((AliESDMuonTrack*)track)->GetThetaXUncorrected()) : ((AliESDMuonTrack*)track)->PxUncorrected();
692 fVarFloat[kVarPyUncorrected] = ( isGhost ) ? -TMath::Tan(((AliESDMuonTrack*)track)->GetThetaYUncorrected()) : ((AliESDMuonTrack*)track)->PyUncorrected();
693 fVarFloat[kVarPzUncorrected] = ( isGhost ) ? -1 : ((AliESDMuonTrack*)track)->PzUncorrected();
694
695 fVarFloat[kVarPtUncorrected] =
696 TMath::Sqrt(fVarFloat[kVarPxUncorrected] * fVarFloat[kVarPxUncorrected] +
697 fVarFloat[kVarPyUncorrected] * fVarFloat[kVarPyUncorrected]);
b201705a 698
589e3f71 699 fVarFloat[kVarXUncorrected] = ((AliESDMuonTrack*)track)->GetNonBendingCoorUncorrected();
700 fVarFloat[kVarYUncorrected] = ((AliESDMuonTrack*)track)->GetBendingCoorUncorrected();
701 fVarFloat[kVarZUncorrected] = ((AliESDMuonTrack*)track)->GetZUncorrected();
b201705a 702
589e3f71 703 fVarInt[kVarLocalCircuit] = ((AliESDMuonTrack*)track)->LoCircuit();
704 }
705
706 if ( isGhost ) {
707 // If is ghost fill only a partial information
708 nGhosts++;
709 if ( fillCurrentEventTree ) {
710 fVarInt[kVarIsMuon] = 0;
711 fVarInt[kVarIsGhost] = nGhosts;
712 fVarInt[kVarMatchTrig] = ((AliESDMuonTrack*)track)->GetMatchTrigger();
4ab8d5a6 713 fTreeSingleMu->Fill();
589e3f71 714 }
b201705a 715 continue;
716 }
717 }
718 else {
719 track = aodEvent->GetTrack(itrack);
720 if ( ! ((AliAODTrack*)track)->IsMuonTrack() )
721 continue;
b201705a 722 }
9728bcfd 723
b201705a 724 // Information for tracks in tracker
725 nMuons++;
b201705a 726
727 fVarFloat[kVarPt] = track->Pt();
4ab8d5a6 728 //fVarFloat[kVarRapidity] = track->Y();
729 fVarFloat[kVarEta] = track->Eta();
b201705a 730 fVarFloat[kVarXatDCA] = (esdEvent ) ? ((AliESDMuonTrack*)track)->GetNonBendingCoorAtDCA() : ((AliAODTrack*)track)->XAtDCA();
731 fVarFloat[kVarYatDCA] = (esdEvent ) ? ((AliESDMuonTrack*)track)->GetBendingCoorAtDCA() : ((AliAODTrack*)track)->YAtDCA();
589e3f71 732 fVarFloat[kVarDCA] =
733 TMath::Sqrt( fVarFloat[kVarXatDCA] * fVarFloat[kVarXatDCA] +
734 fVarFloat[kVarYatDCA] * fVarFloat[kVarYatDCA] );
735 fVarFloat[kVarCharge] = (Float_t)track->Charge();
736 fVarFloat[kVarRAtAbsEnd] = (esdEvent ) ? ((AliESDMuonTrack*)track)->GetRAtAbsorberEnd() : ((AliAODTrack*)track)->GetRAtAbsorberEnd();
b201705a 737 fVarInt[kVarMatchTrig] = (esdEvent ) ? ((AliESDMuonTrack*)track)->GetMatchTrigger() : ((AliAODTrack*)track)->GetMatchTrigger();
738
589e3f71 739 if ( fillCurrentEventTree ){
740 fVarInt[kVarIsMuon] = nMuons;
741 fVarInt[kVarIsGhost] = 0;
4ab8d5a6 742 //fVarFloat[kVarEta] = track->Eta();
743 fVarFloat[kVarRapidity] = track->Y();
b201705a 744 fVarFloat[kVarPx] = track->Px();
745 fVarFloat[kVarPy] = track->Py();
746 fVarFloat[kVarPz] = track->Pz();
589e3f71 747 fVarFloat[kVarPxAtDCA] = ( esdEvent ) ? ((AliESDMuonTrack*)track)->PxAtDCA() : ((AliAODTrack*)track)->PxAtDCA();
748 fVarFloat[kVarPyAtDCA] = ( esdEvent ) ? ((AliESDMuonTrack*)track)->PyAtDCA() : ((AliAODTrack*)track)->PyAtDCA();
749 fVarFloat[kVarPzAtDCA] = ( esdEvent ) ? ((AliESDMuonTrack*)track)->PzAtDCA() : ((AliAODTrack*)track)->PzAtDCA();
b201705a 750 fVarFloat[kVarPtAtDCA] = TMath::Sqrt(fVarFloat[kVarPxAtDCA]*fVarFloat[kVarPxAtDCA] + fVarFloat[kVarPyAtDCA]*fVarFloat[kVarPyAtDCA]);
b201705a 751 }
9728bcfd 752
589e3f71 753 fVarIntMC[kVarMotherType] = kUnknownPart;
754
9728bcfd 755 // Monte Carlo part
589e3f71 756 if ( fMCEvent ) {
9728bcfd 757
589e3f71 758 trackLabel = track->GetLabel();
9728bcfd 759
93d6def1 760 if ( trackLabel >= 0 ) {
761 AliMCParticle* matchedMCTrack = (AliMCParticle*)fMCEvent->GetTrack(trackLabel);
589e3f71 762 fVarIntMC[kVarMotherType] = RecoTrackMother(matchedMCTrack);
763 fVarFloatMC[kVarPtMC] = matchedMCTrack->Pt();
764 FillTriggerHistos(kHistoPtResolutionMC, fVarInt[kVarMatchTrig], fVarIntMC[kVarMotherType], fVarFloat[kVarPt] - fVarFloatMC[kVarPtMC]);
765 if ( fillCurrentEventTree ){
766 fVarFloatMC[kVarPxMC] = matchedMCTrack->Px();
767 fVarFloatMC[kVarPyMC] = matchedMCTrack->Py();
768 fVarFloatMC[kVarPzMC] = matchedMCTrack->Pz();
769 fVarFloatMC[kVarEtaMC] = matchedMCTrack->Eta();
770 fVarFloatMC[kVarRapidityMC] = matchedMCTrack->Y();
771 fVarFloatMC[kVarVxMC] = matchedMCTrack->Xv();
772 fVarFloatMC[kVarVyMC] = matchedMCTrack->Yv();
773 fVarFloatMC[kVarVzMC] = matchedMCTrack->Zv();
774 fVarIntMC[kVarPdg] = matchedMCTrack->PdgCode();
93d6def1 775
776 Int_t imother = matchedMCTrack->GetMother();
777 if ( imother >= 0 ) {
778 AliMCParticle* motherTrack = (AliMCParticle*)fMCEvent->GetTrack(imother);
779 fVarFloatMC[kVarMotherPxMC] = motherTrack->Px();
780 fVarFloatMC[kVarMotherPyMC] = motherTrack->Py();
781 fVarFloatMC[kVarMotherPzMC] = motherTrack->Pz();
782 fVarFloatMC[kVarMotherEtaMC] = motherTrack->Eta();
783 fVarFloatMC[kVarMotherRapidityMC] = motherTrack->Y();
784 fVarFloatMC[kVarMotherVxMC] = motherTrack->Xv();
785 fVarFloatMC[kVarMotherVyMC] = motherTrack->Yv();
786 fVarFloatMC[kVarMotherVzMC] = motherTrack->Zv();
787 fVarIntMC[kVarMotherPdg] = motherTrack->PdgCode();
788 }
589e3f71 789 }
b201705a 790 }
93d6def1 791 if ( fDebug >= 1 ) printf("AliAnalysisTaskSingleMu: Reco track. %s. Set mother %i\n", fDebugString.Data(), fVarIntMC[kVarMotherType]);
589e3f71 792 } // if use MC
793
794 containerInput[kHvarPt] = fVarFloat[kVarPt];
4ab8d5a6 795 //containerInput[kHvarY] = fVarFloat[kVarRapidity];
796 containerInput[kHvarEta] = fVarFloat[kVarEta];
589e3f71 797 containerInput[kHvarPhi] = track->Phi();
798 containerInput[kHvarDCA] = fVarFloat[kVarDCA];
799 containerInput[kHvarVz] = fVarFloat[kVarIPVz];
800 containerInput[kHvarThetaZones] = GetBinThetaAbsEnd(fVarFloat[kVarRAtAbsEnd]);
801 containerInput[kHvarCharge] = fVarFloat[kVarCharge];
802 containerInput[kHvarMatchTrig] = (Double_t)fVarInt[kVarMatchTrig];
589e3f71 803 containerInput[kHvarIsGoodVtx] = (Double_t)isGoodVtxBin;
804 containerInput[kHvarMotherType] = (Double_t)fVarIntMC[kVarMotherType];
93d6def1 805 containerInput[kHvarCentrality] = centralityForContainer;
806 //containerInput[kHvarP] = track->P();
589e3f71 807
55065f3f 808 histoIndex = GetHistoIndex(kHistoNmuonsPerRun);
809 for ( Int_t itrig=0; itrig<fTriggerClasses->GetEntries(); itrig++ ) {
810 TString trigName = ((TObjString*)fTriggerClasses->At(itrig))->GetString();
811 if ( ! firedTrigClasses.Contains(trigName.Data()) )
812 continue;
813 containerInput[kHvarTrigClass] = (Double_t)(itrig+1);
814 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructed);
4ab8d5a6 815 // if ( fCFManager->CheckParticleCuts(kStepAcceptance,track) ) fCFManager->GetParticleContainer()->Fill(containerInput,kStepAcceptance);
55065f3f 816 ((TH2F*)fHistoList->At(histoIndex))->Fill(Form("%u",fVarUInt[kVarRunNumber]), containerInput[kHvarTrigClass], 1.);
817 } // loop on trigger classes
589e3f71 818
4ab8d5a6 819 if ( fillCurrentEventTree ) fTreeSingleMu->Fill();
9728bcfd 820 } // loop on tracks
b201705a 821
589e3f71 822 if ( fillCurrentEventTree && fKeepAll && ( ( nMuons + nGhosts ) == 0 ) ) {
b201705a 823 // Fill event also if there is not muon (when explicitely required)
4ab8d5a6 824 fTreeSingleMu->Fill();
b201705a 825 }
826
55065f3f 827 for ( Int_t itrig=0; itrig<fTriggerClasses->GetEntries(); itrig++ ) {
828 TString trigName = ((TObjString*)fTriggerClasses->At(itrig))->GetString();
829 if ( ! firedTrigClasses.Contains(trigName.Data()) )
830 continue;
831 Double_t trigClassBin = (Double_t)(itrig+1);
832 histoIndex = GetHistoIndex(kHistoNeventsPerTrig);
833 ((TH2F*)fHistoList->At(histoIndex))->Fill(trigClassBin, 1., 1.); // All events
834 ((TH2F*)fHistoList->At(histoIndex))->Fill(trigClassBin, 4., (Double_t)(fVarInt[kVarIsPileup]+1)); // All vertices
835 if ( isGoodVtxBin == 1 )
836 ((TH2F*)fHistoList->At(histoIndex))->Fill(trigClassBin, 2., 1.); // Good vtx events
837 else if ( isGoodVtxBin == 2 ) {
838 ((TH2F*)fHistoList->At(histoIndex))->Fill(trigClassBin, 3., 1.); // Pileup events
839 ((TH2F*)fHistoList->At(histoIndex))->Fill(trigClassBin, 5., 1.); // Pileup vertices
840 }
589e3f71 841
55065f3f 842 histoIndex = GetHistoIndex(kHistoMuonMultiplicity);
843 ((TH1F*)fHistoList->At(histoIndex))->Fill(nMuons, trigClassBin);
589e3f71 844
4ab8d5a6 845 if ( isGoodVtxBin == 1 ) {
55065f3f 846 histoIndex = GetHistoIndex(kHistoEventVz);
4ab8d5a6 847 ((TH2F*)fHistoList->At(histoIndex))->Fill(trigClassBin,fVarFloat[kVarIPVz]);
55065f3f 848 }
849
850 histoIndex = GetHistoIndex(kHistoNeventsPerRun);
851 ((TH2F*)fHistoList->At(histoIndex))->Fill(Form("%u",fVarUInt[kVarRunNumber]), trigClassBin, 1.);
852 } // loop on trigger classes
589e3f71 853
589e3f71 854
855 // Post final data. It will be written to a file with option "RECREATE"
856 PostData(1, fCFManager->GetParticleContainer());
857 PostData(2, fHistoList);
55065f3f 858 PostData(3, fHistoListQA);
4ab8d5a6 859 PostData(4, fHistoListMC);
589e3f71 860 if ( fFillTreeScaleDown > 0 )
4ab8d5a6 861 PostData(5, fTreeSingleMu);
aad6618e 862}
863
864//________________________________________________________________________
865void AliAnalysisTaskSingleMu::Terminate(Option_t *) {
866 //
867 /// Draw some histogram at the end.
868 //
589e3f71 869
870 AliCFContainer* container = dynamic_cast<AliCFContainer*> (GetOutputData(1));
871 if ( ! container ) {
872 AliError("Cannot find container in file");
873 return;
874 }
875
876 //Int_t histoIndex = -1;
877
878 if ( ! gROOT->IsBatch() ) {
4ab8d5a6 879 TString currName = GetName();
880 currName.Prepend("c1_");
881 TCanvas *c1_SingleMu = new TCanvas(currName.Data(),"Vz vs Pt",10,10,310,310);
93fd3322 882 c1_SingleMu->SetFillColor(10); c1_SingleMu->SetHighLightColor(10);
883 c1_SingleMu->SetLeftMargin(0.15); c1_SingleMu->SetBottomMargin(0.15);
93d6def1 884 TH2* histo = dynamic_cast<TH2*>(container->Project(kStepReconstructed,kHvarPt,kHvarVz));
4ab8d5a6 885 currName = GetName();
886 currName.Prepend("hPtVz_");
887 histo->SetName(currName.Data());
888 histo->Draw("COLZ");
aad6618e 889 }
589e3f71 890
aad6618e 891}
892
893//________________________________________________________________________
9728bcfd 894 void AliAnalysisTaskSingleMu::FillTriggerHistos(Int_t histoIndex, Int_t matchTrig, Int_t motherType,
895 Float_t var1, Float_t var2, Float_t var3)
aad6618e 896{
897 //
9728bcfd 898 /// Fill all histograms passing the trigger cuts
aad6618e 899 //
662e37fe 900
9728bcfd 901 Int_t nTrigs = TMath::Max(1, matchTrig);
902 TArrayI trigToFill(nTrigs);
903 trigToFill[0] = matchTrig;
904 for(Int_t itrig = 1; itrig < matchTrig; itrig++){
905 trigToFill[itrig] = itrig;
906 }
662e37fe 907
9728bcfd 908 TList* histoList = (motherType < 0 ) ? fHistoList : fHistoListMC;
909
910 TString className;
911 for(Int_t itrig = 0; itrig < nTrigs; itrig++){
912 Int_t currIndex = GetHistoIndex(histoIndex, trigToFill[itrig], motherType);
913 className = histoList->At(currIndex)->ClassName();
93d6def1 914 if ( fDebug >= 3 ) printf("AliAnalysisTaskSingleMu: matchTrig %i Fill %s\n", matchTrig, histoList->At(currIndex)->GetName());
9728bcfd 915 if (className.Contains("1"))
916 ((TH1F*)histoList->At(currIndex))->Fill(var1);
917 else if (className.Contains("2"))
918 ((TH2F*)histoList->At(currIndex))->Fill(var1, var2);
919 else if (className.Contains("3"))
920 ((TH3F*)histoList->At(currIndex))->Fill(var1, var2, var3);
921 else
922 AliWarning("Histogram not filled");
923 }
aad6618e 924}
925
aad6618e 926//________________________________________________________________________
589e3f71 927Int_t AliAnalysisTaskSingleMu::RecoTrackMother(AliMCParticle* mcParticle)
aad6618e 928{
929 //
9728bcfd 930 /// Find track mother from kinematics
aad6618e 931 //
932
589e3f71 933 Int_t recoPdg = mcParticle->PdgCode();
aad6618e 934
93d6def1 935 fDebugString = Form("History: %i", recoPdg);
936
9728bcfd 937 // Track is not a muon
589e3f71 938 if ( TMath::Abs(recoPdg) != 13 ) return kRecoHadron;
aad6618e 939
589e3f71 940 Int_t imother = mcParticle->GetMother();
aad6618e 941
93d6def1 942 //Int_t baseFlv[2] = {4,5};
943 //Int_t mType[2] = {kCharmMu, kBeautyMu};
944 Int_t den[3] = {100, 1000, 1};
aad6618e 945
93d6def1 946 //Bool_t isFirstMotherHF = kFALSE;
947 //Int_t step = 0;
948 Int_t motherType = kPrimaryMu;
589e3f71 949 while ( imother >= 0 ) {
950 TParticle* part = ((AliMCParticle*)fMCEvent->GetTrack(imother))->Particle();
662e37fe 951
93d6def1 952 fDebugString += Form(" <- %s (%s)", part->GetName(), TMCProcessName[part->GetUniqueID()]);
662e37fe 953
589e3f71 954 Int_t absPdg = TMath::Abs(part->GetPdgCode());
93d6def1 955 //step++;
956
957 if ( imother < fMCEvent->GetNumberOfPrimaries() ) {
958 /*
959 // Hadronic processes are not possible for "primary" =>
960 // either is decay or HF
961 if ( absPdg > 100 && absPdg < 400 ) {
962 // it is decay mu
963 motherType = kPrimaryMu;
964 break; // particle loop
965 }
966 else if ( step == 1 || isFirstMotherHF ){
967 // Check if it is HF muon
968 // avoid the case when the HF was not the first mother
969 // (the mu is produced by a decain chain => decay mu)
970 Bool_t foundHF = kFALSE;
971 for ( Int_t idec=0; idec<3; idec++ ) {
972 for ( Int_t ihf=0; ihf<2; ihf++ ) {
973 if ( ( absPdg/den[idec] ) != baseFlv[ihf] ) continue;
974 motherType = mType[ihf];
975 foundHF = kTRUE;
976 break;
977 } // loop on hf
978 if ( foundHF ) {
979 if ( step == 1 ) isFirstMotherHF = kTRUE;
980 break; // break loop on pdg code
981 // but continue the global loop to find higher mass HF
982 }
983 } // loop on pdg codes
984 if ( ! foundHF ) {
985 motherType = kPrimaryMu;
986 break;
987 }
988 else if ( absPdg < 10 ) {
989 // found HF quark: break particle loop
990 break;
991 }
992 } // potential HF code
993 */
994 for ( Int_t idec=0; idec<3; idec++ ) {
995 Int_t flv = absPdg/den[idec];
996 if ( flv > 0 && flv < 4 ) return kPrimaryMu;
997 else if ( flv == 0 || flv > 5 ) continue;
998 else {
999 motherType = ( flv == 4 ) ? kCharmMu : kBeautyMu;
1000 break; // break loop on pdg code
1001 // but continue the global loop to find higher mass HF
1002 }
1003 } // loop on pdg code
1004 if ( absPdg < 10 ) break; // particle loop
1005 } // is primary
1006 else {
1007 // If hadronic process => secondary
1008 if ( part->GetUniqueID() == kPHadronic ) {
1009 //motherType = kSecondaryMu;
1010 //break; // particle loop
1011 return kSecondaryMu;
1012 }
1013 } // is secondary
9728bcfd 1014
589e3f71 1015 imother = part->GetFirstMother();
9728bcfd 1016
93d6def1 1017 } // loop on mothers
1018
1019 return motherType;
589e3f71 1020}
662e37fe 1021
589e3f71 1022//________________________________________________________________________
1023Int_t AliAnalysisTaskSingleMu::GetHistoIndex(Int_t histoTypeIndex, Int_t trigIndex, Int_t srcIndex)
1024{
1025 //
1026 /// Get histogram index in the list
1027 //
1028
1029 if ( srcIndex < 0 ) {
1030 return histoTypeIndex;
9728bcfd 1031 }
589e3f71 1032
1033 return
1034 kNsummaryHistosMC +
1035 kNtrackSources * kNtrigCuts * histoTypeIndex +
1036 kNtrackSources * trigIndex +
1037 srcIndex;
9728bcfd 1038}
662e37fe 1039
9728bcfd 1040//________________________________________________________________________
589e3f71 1041Float_t AliAnalysisTaskSingleMu::GetBinThetaAbsEnd(Float_t RAtAbsEnd, Bool_t isTheta)
1042{
1043 //
1044 /// Get bin of theta at absorber end region
1045 //
1046 Float_t thetaDeg = ( isTheta ) ? RAtAbsEnd : TMath::ATan( RAtAbsEnd / 505. );
1047 thetaDeg *= TMath::RadToDeg();
1048 if ( thetaDeg < 2. )
1049 return 0.;
1050 else if ( thetaDeg < 3. )
1051 return 1.;
1052 else if ( thetaDeg < 9. )
1053 return 2.;
1054
1055 return 3.;
1056}
1057
b201705a 1058
1059//________________________________________________________________________
1060void AliAnalysisTaskSingleMu::Reset(Bool_t keepGlobal)
1061{
1062 //
1063 /// Reset variables
1064 //
1065 Int_t lastVarFloat = ( keepGlobal ) ? kVarIPVx : kNvarFloat;
1066 for(Int_t ivar=0; ivar<lastVarFloat; ivar++){
1067 fVarFloat[ivar] = 0.;
1068 }
1069 Int_t lastVarInt = ( keepGlobal ) ? kVarPassPhysicsSelection : kNvarInt;
1070 for(Int_t ivar=0; ivar<lastVarInt; ivar++){
589e3f71 1071 fVarInt[ivar] = 0;
b201705a 1072 }
589e3f71 1073 fVarInt[kVarMatchTrig] = -1;
b201705a 1074
1075 if ( ! keepGlobal ){
1076 for(Int_t ivar=0; ivar<kNvarChar; ivar++){
4ab8d5a6 1077 strncpy(fVarChar[ivar]," ",255);
b201705a 1078 }
1079 for(Int_t ivar=0; ivar<kNvarUInt; ivar++){
1080 fVarUInt[ivar] = 0;
1081 }
1082 }
589e3f71 1083 if ( fMCEvent ){
93d6def1 1084 lastVarFloat = ( keepGlobal ) ? kVarIPVxMC : kNvarFloatMC;
1085 for(Int_t ivar=0; ivar<lastVarFloat; ivar++){
b201705a 1086 fVarFloatMC[ivar] = 0.;
1087 }
1088 for(Int_t ivar=0; ivar<kNvarIntMC; ivar++){
93d6def1 1089 fVarIntMC[ivar] = 0;
b201705a 1090 }
93d6def1 1091 fVarIntMC[kVarMotherType] = -1;
1092 }
b201705a 1093}
589e3f71 1094
1095//________________________________________________________________________
55065f3f 1096void AliAnalysisTaskSingleMu::SetTriggerClasses(TString triggerClasses)
589e3f71 1097{
55065f3f 1098 /// Set trigger classes
1099 if ( fTriggerClasses )
1100 delete fTriggerClasses;
1101
1102 fTriggerClasses = triggerClasses.Tokenize(" ");
1103 fTriggerClasses->SetOwner();
589e3f71 1104
55065f3f 1105}
589e3f71 1106
1107//________________________________________________________________________
1108void AliAnalysisTaskSingleMu::SetAxisLabel(TAxis* axis)
1109{
1110 //
1111 /// Set the labels of trigger class axis
1112 //
55065f3f 1113 for ( Int_t itrig=0; itrig<fTriggerClasses->GetEntries(); itrig++ ) {
1114 TString trigName = ((TObjString*)fTriggerClasses->At(itrig))->GetString();
1115 axis->SetBinLabel(itrig+1,trigName.Data());
1116 }
1117 axis->SetTitle("Fired class");
589e3f71 1118}