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