]>
Commit | Line | Data |
---|---|---|
ac4edd2e | 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 | ||
16 | /* $Id: AliVAnalysisMuon.cxx 47782 2011-02-24 18:37:31Z martinez $ */ | |
17 | ||
18 | //----------------------------------------------------------------------------- | |
19 | /// \class AliVAnalysisMuon | |
20 | /// Base class with utilities for muon analysis | |
21 | /// | |
22 | /// \author Diego Stocco | |
23 | //----------------------------------------------------------------------------- | |
24 | ||
25 | #include "AliVAnalysisMuon.h" | |
26 | ||
27 | // ROOT includes | |
28 | #include "TROOT.h" | |
29 | #include "TH1.h" | |
30 | #include "TH2.h" | |
31 | #include "TAxis.h" | |
32 | #include "TCanvas.h" | |
33 | #include "TLegend.h" | |
34 | #include "TMath.h" | |
35 | #include "TObjString.h" | |
36 | #include "TObjArray.h" | |
37 | #include "THashList.h" | |
38 | #include "TStyle.h" | |
39 | //#include "TMCProcess.h" | |
40 | #include "TLorentzVector.h" | |
d30d0019 | 41 | #include "TRegexp.h" |
0a43bc7e | 42 | #include "TDatabasePDG.h" |
43 | #include "TParticlePDG.h" | |
ac4edd2e | 44 | |
45 | // STEER includes | |
46 | #include "AliInputEventHandler.h" | |
47 | #include "AliCentrality.h" | |
48 | ||
49 | #include "AliAODEvent.h" | |
50 | #include "AliAODTrack.h" | |
51 | #include "AliAODMCParticle.h" | |
52 | #include "AliMCEvent.h" | |
53 | #include "AliMCParticle.h" | |
54 | //#include "AliStack.h" | |
55 | #include "AliESDEvent.h" | |
56 | #include "AliESDMuonTrack.h" | |
c6e0141f | 57 | #include "AliCounterCollection.h" |
12e33589 | 58 | #include "AliVVertex.h" |
ac4edd2e | 59 | |
60 | // ANALYSIS includes | |
61 | #include "AliAnalysisManager.h" | |
62 | #include "AliAnalysisTaskSE.h" | |
63 | #include "AliAnalysisDataSlot.h" | |
64 | #include "AliAnalysisDataContainer.h" | |
65 | ||
66 | // CORRFW includes | |
67 | #include "AliCFGridSparse.h" | |
68 | ||
69 | // PWG3 includes | |
ac4edd2e | 70 | #include "AliMergeableCollection.h" |
ebba9ef0 | 71 | #include "AliMuonEventCuts.h" |
c6e0141f | 72 | #include "AliMuonTrackCuts.h" |
73 | #include "AliMuonPairCuts.h" | |
ebba9ef0 | 74 | #include "AliAnalysisMuonUtility.h" |
ac4edd2e | 75 | |
76 | /// \cond CLASSIMP | |
77 | ClassImp(AliVAnalysisMuon) // Class implementation in ROOT context | |
78 | /// \endcond | |
79 | ||
80 | ||
81 | //________________________________________________________________________ | |
82 | AliVAnalysisMuon::AliVAnalysisMuon() : | |
83 | AliAnalysisTaskSE(), | |
ebba9ef0 | 84 | fMuonEventCuts(0x0), |
c6e0141f | 85 | fMuonTrackCuts(0x0), |
86 | fMuonPairCuts(0x0), | |
ac4edd2e | 87 | fESDEvent(0x0), |
88 | fAODEvent(0x0), | |
89 | fTerminateOptions(0x0), | |
90 | fChargeKeys(0x0), | |
91 | fSrcKeys(0x0), | |
92 | fPhysSelKeys(0x0), | |
dba277b7 | 93 | fWeights(0x0), |
ac4edd2e | 94 | fEventCounters(0x0), |
95 | fMergeableCollection(0x0), | |
96 | fOutputList(0x0), | |
ac4edd2e | 97 | fOutputPrototypeList(0x0) |
98 | { | |
99 | /// Default ctor. | |
100 | } | |
101 | ||
102 | //________________________________________________________________________ | |
103 | AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonTrackCuts& trackCuts, const AliMuonPairCuts& pairCuts) : | |
104 | AliAnalysisTaskSE(name), | |
ebba9ef0 | 105 | fMuonEventCuts(new AliMuonEventCuts("stdEventCuts","stdEventCuts")), |
c6e0141f | 106 | fMuonTrackCuts(new AliMuonTrackCuts(trackCuts)), |
107 | fMuonPairCuts(new AliMuonPairCuts(pairCuts)), | |
ac4edd2e | 108 | fESDEvent(0x0), |
109 | fAODEvent(0x0), | |
110 | fTerminateOptions(0x0), | |
111 | fChargeKeys(0x0), | |
112 | fSrcKeys(0x0), | |
113 | fPhysSelKeys(0x0), | |
dba277b7 | 114 | fWeights(new THashList()), |
ac4edd2e | 115 | fEventCounters(0x0), |
116 | fMergeableCollection(0x0), | |
117 | fOutputList(0x0), | |
ac4edd2e | 118 | fOutputPrototypeList(0x0) |
119 | { | |
120 | // | |
121 | /// Constructor. | |
122 | // | |
8396b417 | 123 | |
ac4edd2e | 124 | InitKeys(); |
ebba9ef0 | 125 | SetTrigClassPatterns(""); |
8396b417 | 126 | SetCentralityClasses(); |
dba277b7 | 127 | fWeights->SetOwner(); |
ac4edd2e | 128 | |
129 | DefineOutput(1, TObjArray::Class()); | |
130 | } | |
131 | ||
132 | //________________________________________________________________________ | |
133 | AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonTrackCuts& trackCuts) : | |
134 | AliAnalysisTaskSE(name), | |
ebba9ef0 | 135 | fMuonEventCuts(new AliMuonEventCuts("stdEventCuts","stdEventCuts")), |
c6e0141f | 136 | fMuonTrackCuts(new AliMuonTrackCuts(trackCuts)), |
137 | fMuonPairCuts(0x0), | |
ac4edd2e | 138 | fESDEvent(0x0), |
139 | fAODEvent(0x0), | |
140 | fTerminateOptions(0x0), | |
141 | fChargeKeys(0x0), | |
142 | fSrcKeys(0x0), | |
143 | fPhysSelKeys(0x0), | |
dba277b7 | 144 | fWeights(new THashList()), |
ac4edd2e | 145 | fEventCounters(0x0), |
146 | fMergeableCollection(0x0), | |
147 | fOutputList(0x0), | |
ac4edd2e | 148 | fOutputPrototypeList(0x0) |
149 | { | |
150 | // | |
151 | /// Constructor. | |
152 | // | |
8396b417 | 153 | |
ac4edd2e | 154 | InitKeys(); |
ebba9ef0 | 155 | SetTrigClassPatterns(""); |
8396b417 | 156 | SetCentralityClasses(); |
dba277b7 | 157 | fWeights->SetOwner(); |
8396b417 | 158 | |
ac4edd2e | 159 | DefineOutput(1, TObjArray::Class()); |
160 | } | |
161 | ||
162 | ||
163 | //________________________________________________________________________ | |
164 | AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonPairCuts& pairCuts) : | |
165 | AliAnalysisTaskSE(name), | |
ebba9ef0 | 166 | fMuonEventCuts(new AliMuonEventCuts("stdEventCuts","stdEventCuts")), |
c6e0141f | 167 | fMuonTrackCuts(0x0), |
168 | fMuonPairCuts(new AliMuonPairCuts(pairCuts)), | |
ac4edd2e | 169 | fESDEvent(0x0), |
170 | fAODEvent(0x0), | |
171 | fTerminateOptions(0x0), | |
172 | fChargeKeys(0x0), | |
173 | fSrcKeys(0x0), | |
174 | fPhysSelKeys(0x0), | |
dba277b7 | 175 | fWeights(new THashList()), |
ac4edd2e | 176 | fEventCounters(0x0), |
177 | fMergeableCollection(0x0), | |
178 | fOutputList(0x0), | |
ac4edd2e | 179 | fOutputPrototypeList(0x0) |
180 | { | |
181 | // | |
182 | /// Constructor. | |
183 | // | |
184 | InitKeys(); | |
ebba9ef0 | 185 | SetTrigClassPatterns(""); |
8396b417 | 186 | SetCentralityClasses(); |
dba277b7 | 187 | fWeights->SetOwner(); |
8396b417 | 188 | |
ac4edd2e | 189 | DefineOutput(1, TObjArray::Class()); |
190 | } | |
191 | ||
192 | ||
193 | //________________________________________________________________________ | |
194 | AliVAnalysisMuon::~AliVAnalysisMuon() | |
195 | { | |
196 | // | |
197 | /// Destructor | |
198 | // | |
199 | ||
ebba9ef0 | 200 | delete fMuonEventCuts; |
c6e0141f | 201 | delete fMuonTrackCuts; |
202 | delete fMuonPairCuts; | |
ac4edd2e | 203 | delete fTerminateOptions; |
204 | delete fChargeKeys; | |
205 | delete fSrcKeys; | |
206 | delete fPhysSelKeys; | |
dba277b7 | 207 | delete fWeights; |
ac4edd2e | 208 | delete fOutputPrototypeList; |
209 | ||
210 | ||
211 | // For proof: do not delete output containers | |
212 | if ( ! AliAnalysisManager::GetAnalysisManager() || ! AliAnalysisManager::GetAnalysisManager()->IsProofMode() ) { | |
213 | delete fOutputList; | |
214 | } | |
215 | } | |
216 | ||
217 | //___________________________________________________________________________ | |
218 | void AliVAnalysisMuon::FinishTaskOutput() | |
219 | { | |
220 | // | |
221 | /// Remove empty histograms to reduce the number of histos to be merged | |
222 | // | |
8396b417 | 223 | |
ac4edd2e | 224 | |
225 | fMergeableCollection->PruneEmptyObjects(); | |
8396b417 | 226 | |
ac4edd2e | 227 | // Add stat. info from physics selection |
228 | // (usefull when running on AODs) | |
229 | if ( fInputHandler ) { | |
230 | for ( Int_t istat=0; istat<2; istat++ ) { | |
231 | TString statType = ( istat == 0 ) ? "ALL" : "BIN0"; | |
232 | TH2* hStat = dynamic_cast<TH2*>(fInputHandler->GetStatistics(statType.Data())); | |
233 | if ( hStat ) { | |
ac2e110b | 234 | TString objectName = Form("%s_%s", hStat->GetName(), GetName()); |
ac4edd2e | 235 | TH2* cloneStat = static_cast<TH2*>(hStat->Clone(objectName.Data())); |
236 | cloneStat->SetDirectory(0); | |
237 | fOutputList->Add(cloneStat); | |
238 | } | |
239 | else { | |
240 | AliWarning("Stat histogram not available"); | |
241 | break; | |
242 | } | |
243 | } // loop on stat type | |
244 | } | |
245 | } | |
246 | ||
247 | ||
248 | //___________________________________________________________________________ | |
249 | void AliVAnalysisMuon::NotifyRun() | |
250 | { | |
251 | /// Set run number for cuts | |
68e9b988 | 252 | if ( fMuonTrackCuts ) fMuonTrackCuts->SetRun(fInputHandler); |
253 | if ( fMuonPairCuts ) fMuonPairCuts->SetRun(fInputHandler); | |
ac4edd2e | 254 | } |
255 | ||
256 | //___________________________________________________________________________ | |
257 | void AliVAnalysisMuon::UserCreateOutputObjects() | |
258 | { | |
259 | // | |
260 | /// Create output objects | |
261 | // | |
262 | AliInfo(Form(" CreateOutputObjects of task %s\n", GetName())); | |
8396b417 | 263 | |
ac4edd2e | 264 | fOutputList = new TObjArray(); |
265 | fOutputList->SetOwner(); | |
266 | ||
ac4edd2e | 267 | fEventCounters = new AliCounterCollection("eventCounters"); |
268 | ||
ebba9ef0 | 269 | if ( ! GetCentralityClasses() ) SetCentralityClasses(); |
ac4edd2e | 270 | TString centralityClasses = ""; |
ebba9ef0 | 271 | for ( Int_t icent=1; icent<=GetCentralityClasses()->GetNbins(); ++icent ) { |
ac4edd2e | 272 | if ( ! centralityClasses.IsNull() ) centralityClasses += "/"; |
ebba9ef0 | 273 | centralityClasses += GetCentralityClasses()->GetBinLabel(icent); |
ac4edd2e | 274 | } |
275 | fEventCounters->AddRubric("selected", "yes/no"); | |
276 | fEventCounters->AddRubric("trigger", 100); | |
277 | fEventCounters->AddRubric("centrality", centralityClasses); | |
ac2e110b | 278 | fEventCounters->AddRubric("run", 10000); |
ac4edd2e | 279 | fEventCounters->Init(); |
8396b417 | 280 | fOutputList->Add(fEventCounters); |
ac4edd2e | 281 | |
282 | fMergeableCollection = new AliMergeableCollection("outputObjects"); | |
8396b417 | 283 | fOutputList->Add(fMergeableCollection); |
ac4edd2e | 284 | |
285 | PostData(1, fOutputList); | |
8396b417 | 286 | |
ebba9ef0 | 287 | fMuonEventCuts->Print(); |
288 | ||
8396b417 | 289 | MyUserCreateOutputObjects(); |
ac4edd2e | 290 | } |
291 | ||
292 | ||
293 | //________________________________________________________________________ | |
294 | void AliVAnalysisMuon::UserExec(Option_t * /*option*/) | |
295 | { | |
296 | // | |
297 | /// Main loop | |
298 | /// Called for each event | |
299 | // | |
300 | ||
301 | fAODEvent = dynamic_cast<AliAODEvent*> (InputEvent()); | |
302 | if ( ! fAODEvent ) | |
303 | fESDEvent = dynamic_cast<AliESDEvent*> (InputEvent()); | |
304 | ||
305 | if ( ! fAODEvent && ! fESDEvent ) { | |
306 | AliError ("AOD or ESD event not found. Nothing done!"); | |
307 | return; | |
308 | } | |
ebba9ef0 | 309 | |
310 | if ( ! fMuonEventCuts->IsSelected(fInputHandler) ) return; | |
ac4edd2e | 311 | |
8396b417 | 312 | Int_t physSel = ( fInputHandler->IsEventSelected() & AliVEvent::kAny ) ? kPhysSelPass : kPhysSelReject; |
ac4edd2e | 313 | |
314 | // | |
315 | // Global event info | |
316 | // | |
72ebcde7 | 317 | const TObjArray* selectTrigClasses = fMuonEventCuts->GetSelectedTrigClassesInEvent(InputEvent()); |
ac4edd2e | 318 | |
ebba9ef0 | 319 | Double_t centrality = fMuonEventCuts->GetCentrality(InputEvent()); |
320 | Int_t centralityBin = GetCentralityClasses()->FindBin(centrality); | |
321 | TString centralityBinLabel = GetCentralityClasses()->GetBinLabel(centralityBin); | |
ac4edd2e | 322 | |
8396b417 | 323 | TString selKey = ( physSel == kPhysSelPass ) ? "yes" : "no"; |
ac4edd2e | 324 | for ( Int_t itrig=0; itrig<selectTrigClasses->GetEntries(); ++itrig ) { |
325 | TString trigName = selectTrigClasses->At(itrig)->GetName(); | |
ac2e110b | 326 | fEventCounters->Count(Form("trigger:%s/selected:%s/centrality:%s/run:%i", trigName.Data(), selKey.Data(), centralityBinLabel.Data(),fCurrentRunNumber)); |
ac4edd2e | 327 | } |
328 | ||
ebba9ef0 | 329 | ProcessEvent(fPhysSelKeys->At(physSel)->GetName(), *selectTrigClasses, centralityBinLabel); |
ac4edd2e | 330 | |
331 | // Post final data. It will be written to a file with option "RECREATE" | |
332 | PostData(1, fOutputList); | |
333 | } | |
334 | ||
335 | //________________________________________________________________________ | |
336 | void AliVAnalysisMuon::Terminate(Option_t *) | |
337 | { | |
338 | // | |
339 | /// Draw some histogram at the end. | |
340 | // | |
341 | ||
df1e3f7a | 342 | if ( ! fTerminateOptions ) SetTerminateOptions(); |
343 | ||
ac4edd2e | 344 | if ( gROOT->IsBatch() ) return; |
8396b417 | 345 | |
ac4edd2e | 346 | fOutputList = dynamic_cast<TObjArray*>(GetOutputData(1)); |
347 | if ( ! fOutputList ) return; | |
348 | fEventCounters = static_cast<AliCounterCollection*>(fOutputList->FindObject("eventCounters")); | |
349 | fMergeableCollection = static_cast<AliMergeableCollection*>(fOutputList->FindObject("outputObjects")); | |
350 | ||
ac4edd2e | 351 | if ( ! fMergeableCollection ) return; |
df1e3f7a | 352 | AliInfo(Form("Mergeable collection size %g MB", fMergeableCollection->EstimateSize()/1024.0/1024.0)); |
ac4edd2e | 353 | if ( fTerminateOptions->At(3) ) { |
354 | TString sopt = fTerminateOptions->At(3)->GetName(); | |
355 | if ( sopt.Contains("verbose") ) fMergeableCollection->Print("*"); | |
356 | } | |
d30d0019 | 357 | SetCentralityClassesFromOutput(); |
ac4edd2e | 358 | } |
359 | ||
360 | ||
ac4edd2e | 361 | //________________________________________________________________________ |
0a43bc7e | 362 | Int_t AliVAnalysisMuon::GetParticleType ( AliVParticle* track, Bool_t forceReachFirstAncestor ) |
ac4edd2e | 363 | { |
364 | // | |
365 | /// Get particle type from mathced MC track | |
366 | // | |
367 | ||
368 | Int_t trackSrc = kUnidentified; | |
369 | Int_t trackLabel = track->GetLabel(); | |
370 | if ( trackLabel >= 0 ) { | |
ac2e110b | 371 | AliVParticle* matchedMCTrack = MCEvent()->GetTrack(trackLabel); |
0a43bc7e | 372 | if ( matchedMCTrack ) trackSrc = RecoTrackMother(matchedMCTrack,forceReachFirstAncestor); |
ac4edd2e | 373 | } // track has MC label |
374 | return trackSrc; | |
375 | } | |
376 | ||
377 | ||
378 | //________________________________________________________________________ | |
0a43bc7e | 379 | Int_t AliVAnalysisMuon::RecoTrackMother ( AliVParticle* mcParticle, Bool_t forceReachFirstAncestor ) |
ac4edd2e | 380 | { |
381 | // | |
382 | /// Find track mother from kinematics | |
0a43bc7e | 383 | /// The flag forceReachFirstAncestor affects the heavy flavor chains. |
384 | /// For example the case D -> K -> mu is seen as: | |
385 | /// - kDecayMu if forceReachFirstAncestor = kFALSE | |
386 | /// - kCharmMu if forceReachFirstAncestor = kTRUE | |
ac4edd2e | 387 | // |
388 | ||
389 | Int_t recoPdg = mcParticle->PdgCode(); | |
390 | ||
391 | // Track is not a muon | |
392 | if ( TMath::Abs(recoPdg) != 13 ) return kRecoHadron; | |
393 | ||
ebba9ef0 | 394 | Int_t imother = AliAnalysisMuonUtility::GetMotherIndex(mcParticle); |
ac4edd2e | 395 | |
0a43bc7e | 396 | //Int_t den[3] = {100, 1000, 1}; |
397 | Int_t den[2] = {100, 1000}; | |
398 | ||
ac4edd2e | 399 | |
400 | Int_t motherType = kDecayMu; | |
401 | while ( imother >= 0 ) { | |
ac2e110b | 402 | AliVParticle* part = MCEvent()->GetTrack(imother); |
0a43bc7e | 403 | TParticlePDG* partPdg = TDatabasePDG::Instance()->GetParticle(part->PdgCode()); |
ac4edd2e | 404 | //if ( ! part ) return motherType; |
405 | ||
406 | Int_t absPdg = TMath::Abs(part->PdgCode()); | |
407 | ||
ebba9ef0 | 408 | Bool_t isPrimary = AliAnalysisMuonUtility::IsPrimary(part, MCEvent()); |
ac4edd2e | 409 | |
410 | if ( isPrimary ) { | |
c6e0141f | 411 | if ( absPdg == 24 ) return kWbosonMu; |
412 | ||
0a43bc7e | 413 | if ( absPdg < 10 ) break; // particle loop |
414 | ||
415 | // Check heavy flavours | |
416 | for ( Int_t idec=0; idec<2; idec++ ) { | |
ac4edd2e | 417 | Int_t flv = (absPdg%100000)/den[idec]; |
0a43bc7e | 418 | if ( flv > 0 && flv < 4 ) { |
419 | if ( ! forceReachFirstAncestor ) return kDecayMu; | |
420 | } | |
ac4edd2e | 421 | else if ( flv == 0 || flv > 5 ) continue; |
0a43bc7e | 422 | // if ( flv < 4 || flv > 5 ) continue; |
ac4edd2e | 423 | else { |
0a43bc7e | 424 | if ( den[idec] == 100 && partPdg && ! partPdg->AntiParticle() ) motherType = kQuarkoniumMu; |
ac4edd2e | 425 | else if ( flv == 4 ) motherType = kCharmMu; |
426 | else motherType = kBeautyMu; | |
427 | break; // break loop on pdg code | |
428 | // but continue the global loop to find higher mass HF | |
429 | } | |
430 | } // loop on pdg code | |
0a43bc7e | 431 | //if ( absPdg < 10 ) break; // particle loop |
ac4edd2e | 432 | } // is primary |
433 | else { | |
434 | if ( part->Zv() < -90. ) { | |
435 | // If hadronic process => secondary | |
436 | //if ( part->GetUniqueID() == kPHadronic ) { | |
437 | return kSecondaryMu; | |
438 | //} | |
439 | } | |
440 | } // is secondary | |
441 | ||
ebba9ef0 | 442 | imother = AliAnalysisMuonUtility::GetMotherIndex(part); |
ac4edd2e | 443 | |
444 | } // loop on mothers | |
445 | ||
446 | return motherType; | |
447 | } | |
448 | ||
12e33589 | 449 | |
ac4edd2e | 450 | //________________________________________________________________________ |
8396b417 | 451 | Bool_t AliVAnalysisMuon::AddObjectToCollection(TObject* object, Int_t index) |
ac4edd2e | 452 | { |
453 | // | |
8396b417 | 454 | /// Add object to collection |
ac4edd2e | 455 | // |
456 | ||
457 | if ( ! fOutputPrototypeList ) { | |
458 | fOutputPrototypeList = new TObjArray(); | |
459 | fOutputPrototypeList->SetOwner(); | |
460 | } | |
8396b417 | 461 | if ( fOutputPrototypeList->FindObject(object->GetName() ) ) { |
462 | AliWarning(Form("Object with name %s already in the list", object->GetName())); | |
463 | return kFALSE; | |
464 | } | |
465 | if ( index < 0 ) fOutputPrototypeList->Add(object); | |
466 | else fOutputPrototypeList->AddAtAndExpand(object, index); | |
467 | ||
468 | return kTRUE; | |
ac4edd2e | 469 | } |
470 | ||
471 | //________________________________________________________________________ | |
472 | TObject* AliVAnalysisMuon::GetMergeableObject(TString physSel, TString trigClassName, TString centrality, TString objectName) | |
473 | { | |
474 | // | |
475 | /// Get mergeable object | |
476 | /// (create collection if necessary) | |
477 | // | |
478 | ||
479 | TString identifier = Form("/%s/%s/%s/", physSel.Data(), trigClassName.Data(), centrality.Data()); | |
480 | ||
481 | TObject* obj = fMergeableCollection->GetObject(identifier.Data(), objectName.Data()); | |
482 | if ( ! obj ) { | |
483 | CreateMergeableObjects(physSel, trigClassName, centrality); | |
484 | obj = fMergeableCollection->GetObject(identifier.Data(), objectName.Data()); | |
485 | AliInfo(Form("Mergeable object collection size %g MB", fMergeableCollection->EstimateSize()/1024.0/1024.0)); | |
486 | } | |
487 | return obj; | |
488 | } | |
489 | ||
490 | //________________________________________________________________________ | |
8396b417 | 491 | TObject* AliVAnalysisMuon::GetSum(TString physSel, TString trigClassNames, TString centrality, TString objectPattern) |
ac4edd2e | 492 | { |
493 | // | |
494 | /// Sum objects | |
495 | /// - physSel, trigClassNames must be in the form: key1,key2 | |
496 | /// - centrality must be in the form minValue_maxValue | |
d30d0019 | 497 | /// - objectPattern must be in the form match1,match2 |
ebba9ef0 | 498 | /// meaning that the object name must contain match1 or match2 |
d30d0019 | 499 | /// wildcard * is allowed |
ac4edd2e | 500 | |
8396b417 | 501 | if ( ! fMergeableCollection ) return 0x0; |
502 | ||
ac4edd2e | 503 | // Get centrality range |
504 | Int_t firstCentrality = 1; | |
ebba9ef0 | 505 | Int_t lastCentrality = GetCentralityClasses()->GetNbins(); |
ac4edd2e | 506 | |
507 | TObjArray* centralityRange = centrality.Tokenize("_"); | |
508 | Float_t range[2] = {0., 100.}; | |
509 | if ( centralityRange->GetEntries() >= 2 ) { | |
510 | for ( Int_t irange=0; irange<2; ++irange ) { | |
511 | range[irange] = ((TObjString*)centralityRange->At(irange))->GetString().Atof(); | |
512 | } | |
ebba9ef0 | 513 | firstCentrality = GetCentralityClasses()->FindBin(range[0]+0.0001); |
514 | lastCentrality = GetCentralityClasses()->FindBin(range[1]-0.0001); | |
ac4edd2e | 515 | } |
516 | delete centralityRange; | |
517 | ||
518 | TString sumCentralityString = ""; | |
519 | for ( Int_t icent=firstCentrality; icent<=lastCentrality; ++icent ) { | |
520 | if ( ! sumCentralityString.IsNull() ) sumCentralityString += ","; | |
ebba9ef0 | 521 | sumCentralityString += GetCentralityClasses()->GetBinLabel(icent); |
ac4edd2e | 522 | } |
523 | ||
d30d0019 | 524 | // objectPattern.ReplaceAll(" ",""); |
525 | // TObjArray* objPatternList = objectPattern.Tokenize("&"); | |
526 | // TObjArray objPatternMatrix(objPatternList->GetEntries()); | |
527 | // objPatternMatrix.SetOwner(); | |
528 | // for ( Int_t ikey=0; ikey<objPatternList->GetEntries(); ikey++ ) { | |
529 | // TObjArray* subKeyList = ((TObjString*)objPatternList->At(ikey))->GetString().Tokenize(","); | |
530 | // objPatternMatrix.AddAt(subKeyList, ikey); | |
531 | // } | |
532 | // delete objPatternList; | |
8396b417 | 533 | |
534 | ||
535 | TObjArray objectNameInCollection; | |
536 | objectNameInCollection.SetOwner(); | |
537 | TObjArray* physSelList = physSel.Tokenize(","); | |
538 | TObjArray* trigClassList = trigClassNames.Tokenize(","); | |
539 | TObjArray* centralityList = sumCentralityString.Tokenize(","); | |
540 | for ( Int_t isel=0; isel<physSelList->GetEntries(); isel++ ) { | |
541 | for ( Int_t itrig = 0; itrig<trigClassList->GetEntries(); itrig++ ) { | |
542 | for ( Int_t icent=0; icent<centralityList->GetEntries(); icent++ ) { | |
543 | TString currId = Form("/%s/%s/%s/", physSelList->At(isel)->GetName(), trigClassList->At(itrig)->GetName(),centralityList->At(icent)->GetName()); | |
544 | TList* objNameList = fMergeableCollection->CreateListOfObjectNames(currId.Data()); | |
545 | for ( Int_t iobj=0; iobj<objNameList->GetEntries(); iobj++ ) { | |
546 | TString objName = objNameList->At(iobj)->GetName(); | |
547 | if ( ! objectNameInCollection.FindObject(objName.Data()) ) objectNameInCollection.Add(new TObjString(objName.Data())); | |
548 | } | |
549 | delete objNameList; | |
550 | } | |
551 | } | |
552 | } | |
553 | delete physSelList; | |
554 | delete trigClassList; | |
555 | delete centralityList; | |
d30d0019 | 556 | |
557 | TObjArray* objPatternList = objectPattern.Tokenize(","); | |
ac4edd2e | 558 | |
559 | TString matchingObjectNames = ""; | |
8396b417 | 560 | for ( Int_t iobj=0; iobj<objectNameInCollection.GetEntries(); iobj++ ) { |
561 | TString objName = objectNameInCollection.At(iobj)->GetName(); | |
d30d0019 | 562 | for ( Int_t ipat=0; ipat<objPatternList->GetEntries(); ipat++ ) { |
563 | TString currPattern = ((TObjString*)objPatternList->At(ipat))->GetString(); | |
564 | if ( currPattern.Contains("*") ) { | |
565 | if ( ! objName.Contains(TRegexp(currPattern.Data(),kTRUE)) ) continue; | |
ac4edd2e | 566 | } |
d30d0019 | 567 | else if ( objName != currPattern ) continue; |
568 | ||
569 | if ( ! matchingObjectNames.IsNull() ) matchingObjectNames.Append(","); | |
570 | matchingObjectNames += objName; | |
ac4edd2e | 571 | } |
ac4edd2e | 572 | } |
d30d0019 | 573 | delete objPatternList; |
574 | ||
575 | // for ( Int_t iobj=0; iobj<objectNameInCollection.GetEntries(); iobj++ ) { | |
576 | // TString objName = objectNameInCollection.At(iobj)->GetName(); | |
577 | // Bool_t matchAnd = kTRUE; | |
578 | // for ( Int_t ikey=0; ikey<objPatternMatrix.GetEntries(); ikey++ ) { | |
579 | // TObjArray* subKeyList = (TObjArray*)objPatternMatrix.At(ikey); | |
580 | // Bool_t matchOr = kFALSE; | |
581 | // for ( Int_t isub=0; isub<subKeyList->GetEntries(); isub++ ) { | |
582 | // TString subKeyString = ((TObjString*)subKeyList->At(isub))->GetString(); | |
583 | // if ( subKeyString.Contains("*") ) { | |
584 | // if ( objName.Contains(TRegexp(subKeyString.Data())) ) { | |
585 | // matchOr = kTRUE; | |
586 | // break; | |
587 | // } | |
588 | // } | |
589 | // else if ( objName == subKeyString ) { | |
590 | // matchOr = kTRUE; | |
591 | // break; | |
592 | // } | |
593 | // } | |
594 | // if ( ! matchOr ) { | |
595 | // matchAnd = kFALSE; | |
596 | // break; | |
597 | // } | |
598 | // } | |
599 | // if ( ! matchAnd ) continue; | |
600 | // if ( ! matchingObjectNames.IsNull() ) matchingObjectNames.Append(","); | |
601 | // matchingObjectNames += objName; | |
602 | // } | |
ac4edd2e | 603 | |
604 | TString idPattern = Form("/%s/%s/%s/%s", physSel.Data(), trigClassNames.Data(), sumCentralityString.Data(), matchingObjectNames.Data()); | |
605 | idPattern.ReplaceAll(" ",""); | |
606 | ||
8396b417 | 607 | AliDebug(1,Form("Sum pattern %s", idPattern.Data())); |
608 | ||
ac4edd2e | 609 | return fMergeableCollection->GetSum(idPattern.Data()); |
ac4edd2e | 610 | } |
611 | ||
612 | //___________________________________________________________________________ | |
613 | void AliVAnalysisMuon::CreateMergeableObjects(TString physSel, TString trigClassName, TString centrality) | |
614 | { | |
615 | TObject* obj = 0x0; | |
616 | TString objectName = ""; | |
617 | TString identifier = Form("/%s/%s/%s/", physSel.Data(), trigClassName.Data(), centrality.Data()); | |
618 | for ( Int_t iobj=0; iobj<fOutputPrototypeList->GetEntries(); ++iobj ) { | |
619 | objectName = fOutputPrototypeList->At(iobj)->GetName(); | |
620 | obj = fOutputPrototypeList->At(iobj)->Clone(objectName.Data()); | |
621 | fMergeableCollection->Adopt(identifier, obj); | |
622 | } // loop on histos | |
623 | } | |
624 | ||
625 | ||
626 | //_______________________________________________________________________ | |
627 | Bool_t AliVAnalysisMuon::SetSparseRange(AliCFGridSparse* gridSparse, | |
628 | Int_t ivar, TString labelName, | |
629 | Double_t varMin, Double_t varMax, | |
630 | TString option) | |
631 | { | |
632 | // | |
633 | /// Set range in a smart way. | |
634 | /// Allows to select a bin from the label. | |
635 | /// Check the bin limits. | |
636 | // | |
637 | ||
dba277b7 | 638 | // Keep for backward compatibility |
ac4edd2e | 639 | |
dba277b7 | 640 | return AliAnalysisMuonUtility::SetSparseRange(gridSparse,ivar,labelName,varMin, varMax,option); |
ac4edd2e | 641 | } |
642 | ||
643 | //________________________________________________________________________ | |
ebba9ef0 | 644 | TString AliVAnalysisMuon::GetDefaultTrigClassPatterns() const |
ac4edd2e | 645 | { |
ebba9ef0 | 646 | /// Get default trigger class patterns |
647 | return fMuonEventCuts->GetDefaultTrigClassPatterns(); | |
ac4edd2e | 648 | } |
649 | ||
e7f23491 | 650 | //________________________________________________________________________ |
ebba9ef0 | 651 | void AliVAnalysisMuon::SetTrigClassPatterns(const TString pattern) |
e7f23491 | 652 | { |
ebba9ef0 | 653 | /// Set trigger classes |
654 | TString currPattern = pattern; | |
655 | if ( currPattern.IsNull() ) { | |
656 | currPattern = GetDefaultTrigClassPatterns(); | |
dba277b7 | 657 | currPattern.Append(",!CMUP*"); // by default do not account for UltraPeripheral events |
57142b8e | 658 | } |
ebba9ef0 | 659 | fMuonEventCuts->SetTrigClassPatterns(currPattern); |
e7f23491 | 660 | } |
661 | ||
ebba9ef0 | 662 | //________________________________________________________________________ |
663 | TList* AliVAnalysisMuon::GetAllSelectedTrigClasses() const | |
664 | { | |
665 | /// Get trigger classes | |
666 | return fMuonEventCuts->GetAllSelectedTrigClasses(); | |
667 | } | |
e7f23491 | 668 | |
ac4edd2e | 669 | //________________________________________________________________________ |
670 | void AliVAnalysisMuon::SetCentralityClasses(Int_t nCentralityBins, Double_t* centralityBins) | |
671 | { | |
672 | // | |
673 | /// Set centrality classes | |
674 | // | |
ebba9ef0 | 675 | fMuonEventCuts->SetCentralityClasses(nCentralityBins, centralityBins); |
676 | } | |
ac4edd2e | 677 | |
ebba9ef0 | 678 | //________________________________________________________________________ |
679 | TAxis* AliVAnalysisMuon::GetCentralityClasses() const | |
680 | { | |
681 | // | |
682 | /// Set centrality classes | |
683 | // | |
684 | return fMuonEventCuts->GetCentralityClasses(); | |
ac4edd2e | 685 | } |
686 | ||
d30d0019 | 687 | //________________________________________________________________________ |
688 | Bool_t AliVAnalysisMuon::SetCentralityClassesFromOutput() | |
689 | { | |
690 | // | |
691 | /// Get axis of centrality classes from output key | |
692 | // | |
693 | if ( ! fMergeableCollection ) return kFALSE; | |
694 | TList* centrKeyList = fMergeableCollection->CreateListOfKeys(2); | |
695 | TObjArray centrLimitsList; | |
696 | centrLimitsList.SetOwner(); | |
697 | if ( ! centrKeyList ) return kFALSE; | |
698 | for ( Int_t ikey=0; ikey<centrKeyList->GetEntries(); ikey++ ) { | |
699 | TString centr = static_cast<TObjString*>(centrKeyList->At(ikey))->GetString(); | |
700 | TObjArray* array = centr.Tokenize("_"); | |
701 | for ( Int_t ilim=0; ilim<array->GetEntries(); ilim++ ) { | |
702 | TString currLim = static_cast<TObjString*>(array->At(ilim))->GetString(); | |
703 | if ( ! centrLimitsList.FindObject(currLim.Data()) ) centrLimitsList.Add(new TObjString(currLim)); | |
704 | } | |
705 | delete array; | |
706 | } | |
707 | delete centrKeyList; | |
708 | ||
709 | // Get unsorted array | |
710 | TArrayD bins(centrLimitsList.GetEntries()); | |
711 | for ( Int_t ibin=0; ibin<centrLimitsList.GetEntries(); ibin++ ) { | |
712 | bins[ibin] = static_cast<TObjString*>(centrLimitsList.At(ibin))->GetString().Atof(); | |
713 | } | |
714 | ||
715 | // Sort it | |
716 | Int_t index[bins.GetSize()]; | |
717 | TMath::Sort(bins.GetSize(),bins.GetArray(),index, kFALSE); | |
718 | ||
719 | TArrayD sortedBins(bins.GetSize()); | |
720 | for ( Int_t ibin=0; ibin<centrLimitsList.GetEntries(); ibin++ ) { | |
721 | sortedBins[ibin] = bins[index[ibin]]; | |
722 | } | |
723 | ||
724 | SetCentralityClasses(sortedBins.GetSize()-1, sortedBins.GetArray()); | |
725 | return kTRUE; | |
726 | } | |
727 | ||
ac4edd2e | 728 | //________________________________________________________________________ |
729 | void AliVAnalysisMuon::SetTerminateOptions(TString physSel, TString trigClass, TString centralityRange, TString furtherOpts) | |
730 | { | |
731 | // | |
732 | /// Set terminate options | |
733 | // | |
734 | if ( ! fTerminateOptions ) { | |
735 | fTerminateOptions = new TObjArray(4); | |
736 | fTerminateOptions->SetOwner(); | |
737 | } | |
738 | fTerminateOptions->AddAt(new TObjString(physSel), 0); | |
739 | fTerminateOptions->AddAt(new TObjString(trigClass), 1); | |
740 | fTerminateOptions->AddAt(new TObjString(centralityRange),2); | |
741 | fTerminateOptions->AddLast(new TObjString(furtherOpts)); | |
742 | } | |
743 | ||
744 | //________________________________________________________________________ | |
745 | void AliVAnalysisMuon::InitKeys() | |
746 | { | |
dba277b7 | 747 | // |
748 | /// Init keys | |
749 | // | |
ac4edd2e | 750 | TString chargeKeys = "MuMinus MuPlus"; |
751 | fChargeKeys = chargeKeys.Tokenize(" "); | |
752 | ||
c6e0141f | 753 | TString srcKeys = "CharmMu BeautyMu QuarkoniumMu WbosonMu DecayMu SecondaryMu Hadron Unidentified"; |
ac4edd2e | 754 | fSrcKeys = srcKeys.Tokenize(" "); |
755 | ||
756 | TString physSelKeys = "PhysSelPass PhysSelReject"; | |
757 | fPhysSelKeys = physSelKeys.Tokenize(" "); | |
758 | } | |
dba277b7 | 759 | |
760 | ||
761 | //________________________________________________________________________ | |
762 | void AliVAnalysisMuon::SetWeight ( TObject* wgtObj ) | |
763 | { | |
764 | /// Set weight | |
765 | if ( fWeights->FindObject(wgtObj->GetName()) ) { | |
766 | AliWarning(Form("Weight object %s is already in the list",wgtObj->GetName())); | |
767 | return; | |
768 | } | |
769 | fWeights->Add(wgtObj); | |
770 | } | |
771 | ||
772 | //________________________________________________________________________ | |
773 | TObject* AliVAnalysisMuon::GetWeight ( const Char_t* wgtName ) | |
774 | { | |
775 | /// Get weight | |
776 | return fWeights->FindObject(wgtName); | |
777 | } | |
778 | ||
779 |