]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muon/AliMuonEventCuts.cxx
Added recoil option for shapes
[u/mrichter/AliRoot.git] / PWG / muon / AliMuonEventCuts.cxx
CommitLineData
f8b94231 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16#include "AliMuonEventCuts.h"
17
18#include "TMath.h"
57142b8e 19#include "TFormula.h"
f8b94231 20#include "THashList.h"
f8b94231 21#include "TObjArray.h"
22#include "TObjString.h"
23#include "TFile.h"
24#include "TParameter.h"
25#include "TKey.h"
26#include "TSystem.h"
27#include "TAxis.h"
28#include "TArrayI.h"
dba277b7 29#include "TRegexp.h"
30#include "TPRegexp.h"
f8b94231 31
32#include "AliLog.h"
33#include "AliInputEventHandler.h"
34#include "AliVEvent.h"
35#include "AliESDEvent.h"
36#include "AliAODEvent.h"
37#include "AliVVertex.h"
38#include "AliCentrality.h"
d0809f42 39#include "AliAnalysisUtils.h"
f8b94231 40
41#include "AliAnalysisMuonUtility.h"
f8b94231 42
43/// \cond CLASSIMP
44ClassImp(AliMuonEventCuts) // Class implementation in ROOT context
45/// \endcond
46
47
48//________________________________________________________________________
49AliMuonEventCuts::AliMuonEventCuts() :
50 AliAnalysisCuts(),
f8b94231 51 fPhysicsSelectionMask(0),
68e9b988 52 fVertexMinNContributors(0),
53 fVertexVzMin(0.),
54 fVertexVzMax(0.),
d0809f42 55 fCheckMask(0),
f8b94231 56 fSelectedTrigPattern(0x0),
57 fRejectedTrigPattern(0x0),
58 fSelectedTrigLevel(0x0),
57142b8e 59 fSelectedTrigCombination(0x0),
60 fTrigInputsMap(0x0),
f8b94231 61 fAllSelectedTrigClasses(0x0),
62 fCentralityClasses(0x0),
d0809f42 63 fAnalysisUtils(0x0),
4e2a9c02 64 fEventTriggerMask(0),
f8b94231 65 fSelectedTrigClassesInEvent(0x0)
66{
67 /// Default ctor.
f8b94231 68}
69
70//________________________________________________________________________
71AliMuonEventCuts::AliMuonEventCuts(const char* name, const char* title ) :
72AliAnalysisCuts(name, title),
68e9b988 73 fPhysicsSelectionMask(0),
74 fVertexMinNContributors(0),
75 fVertexVzMin(0.),
76 fVertexVzMax(0.),
d0809f42 77 fCheckMask(0xFFFF),
f8b94231 78 fSelectedTrigPattern(new TObjArray()),
79 fRejectedTrigPattern(new TObjArray()),
80 fSelectedTrigLevel(new TObjArray()),
57142b8e 81 fSelectedTrigCombination(new TObjArray()),
82 fTrigInputsMap(new THashList()),
f8b94231 83 fAllSelectedTrigClasses(new THashList()),
84 fCentralityClasses(0x0),
d0809f42 85 fAnalysisUtils(0x0),
4e2a9c02 86 fEventTriggerMask(0),
f8b94231 87 fSelectedTrigClassesInEvent(new TObjArray())
88{
89 /// Constructor
f8b94231 90 SetDefaultParameters();
91 SetDefaultFilterMask();
92 SetDefaultTrigClassPatterns();
93 SetTrigClassLevels();
94 SetCentralityClasses();
d0809f42 95 fAnalysisUtils = new AliAnalysisUtils();
f8b94231 96 fAllSelectedTrigClasses->SetOwner();
97 fSelectedTrigClassesInEvent->SetOwner();
98}
99
100//________________________________________________________________________
101AliMuonEventCuts::AliMuonEventCuts(const AliMuonEventCuts& obj) :
102 AliAnalysisCuts(obj),
f8b94231 103 fPhysicsSelectionMask(obj.fPhysicsSelectionMask),
68e9b988 104 fVertexMinNContributors(obj.fVertexMinNContributors),
105 fVertexVzMin(obj.fVertexVzMin),
106 fVertexVzMax(obj.fVertexVzMax),
d0809f42 107 fCheckMask(obj.fCheckMask),
f8b94231 108 fSelectedTrigPattern(obj.fSelectedTrigPattern),
109 fRejectedTrigPattern(obj.fRejectedTrigPattern),
110 fSelectedTrigLevel(obj.fSelectedTrigLevel),
57142b8e 111 fSelectedTrigCombination(obj.fSelectedTrigCombination),
112 fTrigInputsMap(obj.fTrigInputsMap),
f8b94231 113 fAllSelectedTrigClasses(obj.fAllSelectedTrigClasses),
114 fCentralityClasses(obj.fCentralityClasses),
d0809f42 115 fAnalysisUtils(obj.fAnalysisUtils),
4e2a9c02 116 fEventTriggerMask(obj.fEventTriggerMask),
f8b94231 117 fSelectedTrigClassesInEvent(obj.fSelectedTrigClassesInEvent)
118{
119 /// Copy constructor
120}
121
122
123//________________________________________________________________________
124AliMuonEventCuts& AliMuonEventCuts::operator=(const AliMuonEventCuts& obj)
125{
126 /// Assignment operator
127 if ( this != &obj ) {
128 AliAnalysisCuts::operator=(obj);
f8b94231 129 fPhysicsSelectionMask = obj.fPhysicsSelectionMask;
68e9b988 130 fVertexMinNContributors = obj.fVertexMinNContributors,
131 fVertexVzMin = obj.fVertexVzMin;
132 fVertexVzMax = obj.fVertexVzMax;
d0809f42 133 fCheckMask = obj.fCheckMask;
f8b94231 134 fSelectedTrigPattern = obj.fSelectedTrigPattern;
135 fRejectedTrigPattern = obj.fRejectedTrigPattern;
136 fSelectedTrigLevel = obj.fSelectedTrigLevel;
57142b8e 137 fSelectedTrigCombination = obj.fSelectedTrigCombination;
138 fTrigInputsMap = obj.fTrigInputsMap;
f8b94231 139 fAllSelectedTrigClasses = obj.fAllSelectedTrigClasses;
140 fCentralityClasses = obj.fCentralityClasses;
d0809f42 141 fAnalysisUtils = obj.fAnalysisUtils;
4e2a9c02 142 fEventTriggerMask = obj.fEventTriggerMask;
f8b94231 143 fSelectedTrigClassesInEvent = obj.fSelectedTrigClassesInEvent;
144 }
145 return *this;
146}
147
148
149//________________________________________________________________________
150AliMuonEventCuts::~AliMuonEventCuts()
151{
152 /// Destructor
153 delete fSelectedTrigPattern;
154 delete fRejectedTrigPattern;
155 delete fSelectedTrigLevel;
57142b8e 156 delete fSelectedTrigCombination;
157 delete fTrigInputsMap;
f8b94231 158 delete fAllSelectedTrigClasses;
159 delete fSelectedTrigClassesInEvent;
160 delete fCentralityClasses;
d0809f42 161 delete fAnalysisUtils;
f8b94231 162}
163
f8b94231 164//________________________________________________________________________
165Bool_t AliMuonEventCuts::IsSelected( TObject* obj )
166{
167 /// Track is selected
168 UInt_t filterMask = GetFilterMask();
169 UInt_t selectionMask = GetSelectionMask(obj);
170
57142b8e 171 AliDebug(1, Form("Is event selected %i mask 0x%x", ( selectionMask & filterMask ) == filterMask, selectionMask ));
172
f8b94231 173 return ( ( selectionMask & filterMask ) == filterMask );
174}
175
176
177//________________________________________________________________________
178UInt_t AliMuonEventCuts::GetSelectionMask( const TObject* obj )
179{
180 /// Get selection mask
181
182 UInt_t selectionMask = 0;
183
d0809f42 184 UInt_t checkMask = fCheckMask | GetFilterMask();
185
f8b94231 186 const AliInputEventHandler* inputHandler = static_cast<const AliInputEventHandler*> ( obj );
187
d0809f42 188 if ( checkMask & kPhysicsSelected ) {
189 if ( const_cast<AliInputEventHandler*>(inputHandler)->IsEventSelected() & fPhysicsSelectionMask ) selectionMask |= kPhysicsSelected;
190 }
f8b94231 191
192 const AliVEvent* event = inputHandler->GetEvent();
193
194 Double_t centrality = GetCentrality(event);
195 if ( centrality >= fCentralityClasses->GetXmin() && centrality <= fCentralityClasses->GetXmax() ) selectionMask |= kSelectedCentrality;
196
197 UpdateEvent(event);
198
199 if ( fSelectedTrigClassesInEvent->GetEntries() > 0 ) selectionMask |= kSelectedTrig;
200
d0809f42 201 if ( checkMask & kGoodVertex ) {
202 AliVVertex* vertex = AliAnalysisMuonUtility::GetVertexSPD(event);
203 if ( vertex->GetNContributors() >= GetVertexMinNContributors() &&
f8b94231 204 vertex->GetZ() >= GetVertexVzMin() && vertex->GetZ() <= GetVertexVzMax() ) selectionMask |= kGoodVertex;
d0809f42 205 }
f8b94231 206
d0809f42 207 if ( checkMask & kNoPileup ) {
208 if ( ! fAnalysisUtils->IsPileUpEvent(const_cast<AliVEvent*>(event)) ) selectionMask |= kNoPileup;
209 // // Uncomment to use settings for pPb
210 // if ( fRejectPileup ) {
211 // Int_t nTracklets = ( event.IsA() == AliESDEvent::Class() ) ? static_cast<AliESDEvent*>(event)->GetMultiplicity()->GetNumberOfTracklets() : static_cast<AliAODEvent*>(event)->GetTracklets()->GetNumberOfTracklets();
212 // Int_t nContrib = ( nTracklets < 40 ) ? 3 : 5;
213 // Double_t dist = 0.8;
214 // Bool_t isPielup = ( event.IsA() == AliESDEvent::Class() ) ? static_cast<AliESDEvent*>(event)->IsPileupFromSPD(nContrib,dist) : static_cast<AliAODEvent*>(event)->IsPileupFromSPD(nContrib,dist);
215 // if ( isPielup ) return;
216 // }
217 }
f8b94231 218
d0809f42 219 AliDebug(1, Form("Selection mask 0x%x\n", selectionMask));
f8b94231 220 return selectionMask;
221}
222
223
224//________________________________________________________________________
225Bool_t AliMuonEventCuts::IsSelected( TList* /* list */)
226{
227 /// Not implemented
228 AliError("Function not implemented: Use IsSelected(TObject*)");
229 return kFALSE;
230}
231
232//________________________________________________________________________
233Bool_t AliMuonEventCuts::UpdateEvent ( const AliVEvent* event )
234{
235 /// Update the transient data member per event
236
4e2a9c02 237 if ( fSelectedTrigClassesInEvent && ( fEventTriggerMask == event->GetTriggerMask() ) ) return kFALSE;
f8b94231 238
57142b8e 239 BuildTriggerClasses(AliAnalysisMuonUtility::GetFiredTriggerClasses(event), AliAnalysisMuonUtility::GetL0TriggerInputs(event), AliAnalysisMuonUtility::GetL1TriggerInputs(event), AliAnalysisMuonUtility::GetL2TriggerInputs(event));
f8b94231 240
4e2a9c02 241 fEventTriggerMask = event->GetTriggerMask();
f8b94231 242
243 return kTRUE;
244}
245
db0b061d 246//________________________________________________________________________
247TString AliMuonEventCuts::GetDefaultTrigClassPatterns () const
248{
249 /// Get the default patterns
250 /// (done in such a way to get all muon triggers)
251 return "CM*,C0M*,CINT*,CPBI*,CCENT*,CV*,!*ABCE*,!*-ACE-*,!*-AC-*,!*-E-*,!*WU*,!*EGA*,!*EJE*,!*PHS*";
252}
253
254//________________________________________________________________________
255TString AliMuonEventCuts::GetDefaultTrigInputsMap () const
256{
257 /// Get the default trigger inputs
258 ///
259
260 TString trigInputsMap = "0VBA:0,";
261 trigInputsMap += "0VBC:1,";
262 trigInputsMap += "0SMB:2,";
263 trigInputsMap += "0TVX:3,";
264 trigInputsMap += "0VGC:4,";
265 trigInputsMap += "0VGA:5,";
266 trigInputsMap += "0SH1:6,";
267 trigInputsMap += "0SH2:7,";
268 trigInputsMap += "0HPT:8,";
269 trigInputsMap += "0AMU:9,";
270 trigInputsMap += "0OB0:10,";
271 trigInputsMap += "0ASL:11,";
272 trigInputsMap += "0MSL:12,";
273 trigInputsMap += "0MSH:13,";
274 trigInputsMap += "0MUL:14,";
275 trigInputsMap += "0MLL:15,";
276 trigInputsMap += "0EMC:16,";
277 trigInputsMap += "0PH0:17,";
278 trigInputsMap += "0HWU:18,";
279 trigInputsMap += "0LSR:19,";
280 trigInputsMap += "0T0A:20,";
281 trigInputsMap += "0BPA:21,";
282 trigInputsMap += "0BPC:22,";
283 trigInputsMap += "0T0C:23,";
284
285 trigInputsMap += "1EJE:0,";
286 trigInputsMap += "1EGA:1,";
287 trigInputsMap += "1EJ2:2,";
288 trigInputsMap += "1EG2:3,";
289 trigInputsMap += "1PHL:4,";
290 trigInputsMap += "1PHM:5,";
291 trigInputsMap += "1PHH:6,";
292 trigInputsMap += "1HCO:8,";
293 trigInputsMap += "1HJT:9,";
294 trigInputsMap += "1HSE:10,";
295 trigInputsMap += "1DUM:11,";
296 trigInputsMap += "1HQU:12,";
297 trigInputsMap += "1H14:13,";
298 trigInputsMap += "1ZMD:14,";
299 trigInputsMap += "1ZMB:16,";
300 trigInputsMap += "1ZED:17,";
301 trigInputsMap += "1ZAC:18,";
302 trigInputsMap += "1EJE:19";
303
304 return trigInputsMap;
305}
306
f8b94231 307//________________________________________________________________________
308void AliMuonEventCuts::SetDefaultTrigClassPatterns ()
309{
310 /// Set the default patterns
311 /// (done in such a way to get all muon triggers)
db0b061d 312 SetTrigClassPatterns(GetDefaultTrigClassPatterns(),GetDefaultTrigInputsMap());
f8b94231 313}
314
dba277b7 315
f8b94231 316//________________________________________________________________________
db0b061d 317void AliMuonEventCuts::SetTrigClassPatterns ( TString trigPattern, TString trigInputsMap )
f8b94231 318{
319 /// Set trigger classes
320 ///
dba277b7 321 /// 1) specify trigger class pattern and reject pattern (wildcard * accepted)
322 /// Classes will be filled dynamycally according to the pattern
f8b94231 323 /// - if name contains ! (without spaces): reject it
dba277b7 324 /// - otherwise keep it
325 /// e.g. CMBAC*,!*ALLNOTRD*
326 /// keeps classes beginning with CMBAC, and not containing ALLNOTRD.
327 ///
328 /// CAVEATs:
329 /// a ) if a wildcard is not specified, exact match is required
330 /// b ) if you use an fCFContainer and you want an axis to contain the trigger classes,
331 /// please be sure that each pattern matches only 1 trigger class, or triggers will be mixed up
332 /// when merging different chuncks.
f8b94231 333 ///
dba277b7 334 ///
335 /// 2) specify a combination of triggers
336 /// combined through a logical AND "&" or a logical OR "|" (wildcard * NOT accepted)
337 /// It is also possible to ask for a trigger class containing a specific trigger input:
338 /// e.g. CMSL7-B-NOPF-MUON&0MSH,CMSL7-B-NOPF-MUON,CMSL7-B-NOPF-MUON|CMSL8-B-NOPF-MUON
339 /// will give the events with:
340 /// - the single low trigger class fired and containing a single high trigger input
341 /// - the single low trigger class fired
342 /// - the single low trigger class 7 or 8 fired
343 /// By default, when specific trigger combinations are provided, the most general case
344 /// based on trigger pattern is disabled...but it can be activated with the disableTrigPattern flag
345 ///
346 /// example:
347 /// SetTrigClassPatterns("CINT7*,!*-ACE-*,CMSL7-B-NOPF-MUON,CMSL7-B-NOPF-MUON&0MSH")
f8b94231 348
dba277b7 349
350 fSelectedTrigCombination->SetOwner();
351 if ( fSelectedTrigCombination->GetEntries() > 0 ) fSelectedTrigCombination->Delete();
f8b94231 352 fSelectedTrigPattern->SetOwner();
353 if ( fSelectedTrigPattern->GetEntries() > 0 ) fSelectedTrigPattern->Delete();
354 fRejectedTrigPattern->SetOwner();
355 if ( fRejectedTrigPattern->GetEntries() > 0 ) fRejectedTrigPattern->Delete();
db0b061d 356
357 SetTrigInputsMap(trigInputsMap);
358
dba277b7 359 TString badSyntax = "", duplicated = "";
360 TString listName[4] = {"L0","L1","L2","trigClass"};
f8b94231 361
dba277b7 362 TString pattern(trigPattern);
363 pattern.ReplaceAll(" ","");
57142b8e 364 TObjArray* fullList = pattern.Tokenize(",");
dba277b7 365 TIter next(fullList);
366 TObjString* objString = 0x0;
367
368 TObjArray combinationList;
369 // First search for patterns
370 while ( ( objString = static_cast<TObjString*>(next()) ) ) {
371 TString currPattern = objString->String();
372 Bool_t isCombination = ( currPattern.Contains("&") || currPattern.Contains("|") );
bafaa7dc 373 Bool_t isSingleTrigger = ( ! isCombination && ! currPattern.BeginsWith("0") && ! currPattern.BeginsWith("1") && ! currPattern.BeginsWith("2") );
374 Bool_t isMatchPattern = ( currPattern.Contains("*") || isSingleTrigger );
dba277b7 375 Bool_t isRejectPattern = kFALSE;
db0b061d 376 if ( isMatchPattern && currPattern.Contains("!") ) {
f8b94231 377 currPattern.ReplaceAll("!","");
dba277b7 378 isRejectPattern = kTRUE;
379 }
380 if ( isCombination && ( isMatchPattern || isRejectPattern ) ) {
381 badSyntax += Form(" %s;", currPattern.Data());
382 continue;
383 }
384 if ( isRejectPattern ) {
f8b94231 385 fRejectedTrigPattern->AddLast(new TObjString(currPattern));
bafaa7dc 386 AliDebug(1,Form("Adding %s to reject pattern",currPattern.Data()));
dba277b7 387 }
388 else if ( isMatchPattern ) {
389 fSelectedTrigPattern->AddLast(new TObjString(currPattern));
bafaa7dc 390 AliDebug(1,Form("Adding %s to match pattern",currPattern.Data()));
f8b94231 391 }
dba277b7 392 else combinationList.Add(objString);
f8b94231 393 }
394
dba277b7 395 // Then check for combinations
396 TIter nextCombo(&combinationList);
397 while ( ( objString = static_cast<TObjString*>(nextCombo()) ) ) {
398 TString currPattern = objString->String();
399
400 TString tn (currPattern);
db0b061d 401 Bool_t hasAND = kFALSE, hasOR = kFALSE, hasNOT = kFALSE;
dba277b7 402 if ( tn.Contains("&") ) {
403 tn.ReplaceAll("&",":");
782b4332 404 hasAND = kTRUE;
dba277b7 405 }
406 if ( tn.Contains("|") ) {
407 tn.ReplaceAll("|",":");
782b4332 408 hasOR = kTRUE;
dba277b7 409 }
db0b061d 410 if ( tn.Contains("!") ) {
411 tn.ReplaceAll("!","");
412 hasNOT = kTRUE;
413 }
dba277b7 414 if ( tn.Contains("(") || tn.Contains(")") ) {
415 tn.ReplaceAll("(","");
416 tn.ReplaceAll(")","");
417 }
418
db0b061d 419 if ( ! hasAND && ! hasOR && ! hasNOT ) {
dba277b7 420 if ( CheckTriggerClassPattern(currPattern) ) {
421 duplicated += Form("%s ", currPattern.Data());
422 continue;
423 }
424 }
425
426 TObjArray* trigCombo = new TObjArray();
427 trigCombo->SetOwner();
428 trigCombo->SetName(currPattern.Data());
429
782b4332 430 UInt_t uniqueID = kComboSimple;
db0b061d 431 if ( ( hasAND && hasOR ) || hasNOT ) uniqueID = kComboFormula;
782b4332 432 else if ( hasAND ) uniqueID = kComboAND;
433 else if ( hasOR ) uniqueID = kComboOR;
dba277b7 434
782b4332 435 trigCombo->SetUniqueID(uniqueID);
dba277b7 436
437 TObjArray* arr = tn.Tokenize(":");
438
439 TIter nextA(arr);
440 TObjString* an = 0x0;
441 while ( ( an = static_cast<TObjString*>(nextA()) ) )
442 {
443 Int_t listIdx = 3;
444 if ( an->String().BeginsWith("0") ) listIdx = 0;
445 else if ( an->String().BeginsWith("1") ) listIdx = 1;
446 else if ( an->String().BeginsWith("2") ) listIdx = 2;
447
448 TObjArray* currList = static_cast<TObjArray*>(trigCombo->FindObject(listName[listIdx].Data()));
449 if ( ! currList ) {
450 currList = new TObjArray();
451 currList->SetOwner();
452 currList->SetName(listName[listIdx].Data());
453 currList->SetUniqueID(listIdx);
454 trigCombo->AddAt(currList,listIdx);
455 }
456 TObjString* currStr = new TObjString(an->String());
457
458 if ( listIdx < 3 ) {
459 // that's an input
460 TObject* trigInput = fTrigInputsMap->FindObject(an->String().Data());
461 if ( trigInput ) currStr->SetUniqueID(trigInput->GetUniqueID());
462 else {
463 AliError(Form("Uknown input %s in formula %s", an->String().Data(), currPattern.Data()));
464 delete trigCombo;
465 trigCombo = 0x0;
466 break;
467 }
468 }
469 currList->AddLast(currStr);
470 }
471 delete arr;
472 if ( trigCombo) {
473 fSelectedTrigCombination->AddLast(trigCombo);
bafaa7dc 474 AliDebug(1,Form("Adding %s to trigger combination (type %u)",currPattern.Data(),trigCombo->GetUniqueID()));
dba277b7 475 }
476 }
f8b94231 477 delete fullList;
dba277b7 478
479 if ( ! duplicated.IsNull() )
480 AliWarning(Form("Triggers %s already accounted in patterns",duplicated.Data()));
481 if ( ! badSyntax.IsNull() )
482 AliWarning(Form("%s : illegal expressions. Must be in the form:\n pattern* => keep class if it contains pattern\n !pattern* => reject class if it contains pattern\n class&input = keep class if it satisfies the expression (exact matching required)",badSyntax.Data()));
f8b94231 483}
484
dba277b7 485
f8b94231 486//________________________________________________________________________
487void AliMuonEventCuts::SetTrigClassLevels ( TString pattern )
488{
489 /// Set trigger cut level associated to the trigger class
490 ///
491 /// example:
57142b8e 492 /// SetTrigClassLevels("MSL:Lpt,MSH:Hpt,MUL:LptLpt")
f8b94231 493 ///
494 /// For the trigger classes defined in SetTrigClassPatterns
495 /// it check if they contains the keywords MSL or MSH
496 /// Hence, in the analysis, the function
497 /// TrackPtCutMatchTrigClass(track, "CPBIMSL") returns true if track match Lpt
498 /// TrackPtCutMatchTrigClass(track, "CPBIMSH") returns true if track match Hpt
499 /// TrackPtCutMatchTrigClass(track, "CMBAC") always returns true
500
501 fSelectedTrigLevel->SetOwner();
502 if ( fSelectedTrigLevel->GetEntries() > 0 ) fSelectedTrigLevel->Delete();
503
57142b8e 504 pattern.ReplaceAll(" ","");
f8b94231 505
57142b8e 506 TObjArray* fullList = pattern.Tokenize(",");
f8b94231 507 UInt_t offset = 2;
508 for ( Int_t ipat=0; ipat<fullList->GetEntries(); ++ipat ) {
509 TString currPattern = fullList->At(ipat)->GetName();
510 TObjArray* arr = currPattern.Tokenize(":");
511 TObjString* trigClassPattern = new TObjString(arr->At(0)->GetName());
512 TString selTrigLevel = arr->At(1)->GetName();
513 selTrigLevel.ToUpper();
514 UInt_t trigLevel = 0;
515 if ( selTrigLevel.Contains("LPT") ) {
516 trigLevel = 2;
517 if ( selTrigLevel.Contains("LPTLPT") ) trigLevel += 2<<offset;
518 }
519 else if ( selTrigLevel.Contains("HPT") ) {
520 trigLevel = 3;
521 if ( selTrigLevel.Contains("HPTHPT") ) trigLevel += 3<<offset;
522 }
523 trigClassPattern->SetUniqueID(trigLevel);
524 fSelectedTrigLevel->AddLast(trigClassPattern);
525 delete arr;
526 }
527
528 delete fullList;
529}
530
5376e016
CP
531//________________________________________________________________________
532UInt_t AliMuonEventCuts::GetTriggerInputBitMaskFromInputName(const char* inputName) const
533{
534 // Get trigger input bit from its name
535
536 if (!fTrigInputsMap)
537 {
538 AliError("No Inputs Map available");
539 return TMath::Limits<UInt_t>::Max();
540 }
541
542 TObjString* s = static_cast<TObjString*>(fTrigInputsMap->FindObject(inputName));
543 if (!s)
544 {
545 AliError(Form("Did not find input %s",inputName));
546 return TMath::Limits<UInt_t>::Max();
547 }
548 return s->GetUniqueID();
549}
550
f8b94231 551//________________________________________________________________________
34e8fe1d 552TArrayI AliMuonEventCuts::GetTrigClassPtCutLevel ( TString trigClassName ) const
f8b94231 553{
554 /// Get trigger class pt cut level for tracking/trigger matching
57142b8e 555 ///
556 /// CAVEAT: this functionality fully works with trigger class names,
557 /// but it can have a problem to extract the correct information in
558 /// combinations of trigger classes/inputs. In this case it provides:
559 /// - the highest pt level among classes/inputs combined through a logical AND "&"
560 /// - the lowest pt level among classes/inputs combined through a logical OR "|"
561 /// The first should be fine, but the second could not be the proper matching.
f8b94231 562 TObject* obj = fAllSelectedTrigClasses->FindObject(trigClassName.Data());
563 if ( ! obj ) {
564 AliWarning(Form("Class %s not in the list!", trigClassName.Data()));
565 return -1;
566 }
567
568 TArrayI ptCutLevel(2);
569 ptCutLevel.Reset();
570 ptCutLevel[0] = obj->GetUniqueID() & 0x3;
571 ptCutLevel[1] = ( obj->GetUniqueID() >> 2 ) & 0x3;
572
782b4332 573 AliDebug(3,Form("Class %s ptCutLevel %i %i",trigClassName.Data(),ptCutLevel[0],ptCutLevel[1]));
f8b94231 574
575 return ptCutLevel;
576}
577
57142b8e 578
579//________________________________________________________________________
580void AliMuonEventCuts::SetTrigInputsMap ( TString trigInputsMap )
581{
582 /// Set trigger input mask
583 /// The inputs must be in the form:
584 /// input1:ID1,input2:ID2,...
585 /// CAVEAT: the input ID is ID_aliceLogbook - 1
586 /// since this is the ID in the OCDB
587
588 fTrigInputsMap->SetOwner();
589 if ( fTrigInputsMap->GetEntries() > 0 ) fTrigInputsMap->Delete();
db0b061d 590
591 if ( trigInputsMap.IsNull() ) {
592 AliWarning("Trigger input map not specified: using default");
593 trigInputsMap = GetDefaultTrigInputsMap();
594 }
595
57142b8e 596 trigInputsMap.ReplaceAll(" ","");
db0b061d 597
57142b8e 598 TObjArray* fullList = trigInputsMap.Tokenize(",");
599 for ( Int_t ipat=0; ipat<fullList->GetEntries(); ++ipat ) {
600 TString currPattern = fullList->At(ipat)->GetName();
601 TObjArray* arr = currPattern.Tokenize(":");
602 TObjString* trigInput = new TObjString(arr->At(0)->GetName());
603 UInt_t trigID = (UInt_t)static_cast<TObjString*>(arr->At(1))->GetString().Atoi();
604 trigInput->SetUniqueID(1<<trigID);
605 fTrigInputsMap->Add(trigInput);
606 delete arr;
607 }
608 delete fullList;
609}
610
5376e016
CP
611//________________________________________________________________________
612const TObjArray*
613AliMuonEventCuts::GetSelectedTrigClassesInEvent(const TString& firedTriggerClasses,
614 UInt_t l0Inputs, UInt_t l1Inputs,
615 UInt_t l2Inputs)
616{
617 /// Return the selected trigger classes in the fired trigger classes
618 /// give also the L0,L1,L2 input bit masks
619
620 BuildTriggerClasses(firedTriggerClasses,l0Inputs,l1Inputs,l2Inputs);
621
622 return fSelectedTrigClassesInEvent;
623}
624
f8b94231 625//________________________________________________________________________
72ebcde7 626const TObjArray* AliMuonEventCuts::GetSelectedTrigClassesInEvent( const AliVEvent* event )
f8b94231 627{
628 /// Return the selected trigger classes in the current event
629 UpdateEvent(event);
630 return fSelectedTrigClassesInEvent;
631}
632
633
634//________________________________________________________________________
34e8fe1d 635void AliMuonEventCuts::BuildTriggerClasses ( TString firedTrigClasses,
57142b8e 636 UInt_t l0Inputs, UInt_t l1Inputs, UInt_t l2Inputs )
f8b94231 637{
638 //
639 /// Return the list of trigger classes to be considered
640 /// for current event. Update the global list if necessary
641 //
642
a3f27e84 643 AliDebug(2,Form("Fired classes: %s Inputs 0x%x 0x%x 0x%x",firedTrigClasses.Data(),l0Inputs,l1Inputs,l2Inputs));
644
4e2a9c02 645 if ( fSelectedTrigClassesInEvent) fSelectedTrigClassesInEvent->Delete();
646 else {
647 fSelectedTrigClassesInEvent = new TObjArray(0);
648 fSelectedTrigClassesInEvent->SetOwner();
649 }
650
f8b94231 651
652 TString firedTrigClassesAny = "ANY " + firedTrigClasses;
f8b94231 653
57142b8e 654 if ( fSelectedTrigPattern->GetEntries() > 0 ) {
655 TObjArray* firedTrigClassesList = firedTrigClassesAny.Tokenize(" ");
656
657 for ( Int_t itrig=0; itrig<firedTrigClassesList->GetEntries(); ++itrig ) {
658 TString trigName = ((TObjString*)firedTrigClassesList->At(itrig))->GetString();
659
660 TObjString* foundTrig = static_cast<TObjString*>(fAllSelectedTrigClasses->FindObject(trigName.Data()));
661 if ( ! foundTrig ) {
662 if ( ! CheckTriggerClassPattern(trigName) ) continue;
663 }
f8b94231 664
57142b8e 665 AddToEventSelectedClass ( trigName, foundTrig );
666 } // loop on trigger classes
667
668 delete firedTrigClassesList;
669 }
670
671 for ( Int_t icomb=0; icomb<fSelectedTrigCombination->GetEntries(); icomb++ ) {
a3f27e84 672 TObjArray* currComb = static_cast<TObjArray*>(fSelectedTrigCombination->At(icomb));
57142b8e 673 if ( CheckTriggerClassCombination(currComb, firedTrigClassesAny, l0Inputs, l1Inputs, l2Inputs) ) {
a3f27e84 674 TObjString* foundTrig = static_cast<TObjString*>(fAllSelectedTrigClasses->FindObject(currComb->GetName()));
782b4332 675 AddToEventSelectedClass ( currComb->GetName(), foundTrig, currComb->GetUniqueID() );
57142b8e 676 }
677 }
678}
679
680//_____________________________________________________________________________
681Bool_t
682AliMuonEventCuts::CheckTriggerClassPattern ( const TString& toCheck ) const
683{
684 // Check if the "toCheck" class matches the user pattern
685
686 for ( Int_t ipat=0; ipat<fRejectedTrigPattern->GetEntries(); ++ipat ) {
dba277b7 687 if ( toCheck.Contains(TRegexp(fRejectedTrigPattern->At(ipat)->GetName(),kTRUE) ) ) return kFALSE;
57142b8e 688 } // loop on reject pattern
689
690 for ( Int_t ipat=0; ipat<fSelectedTrigPattern->GetEntries(); ++ipat ) {
dba277b7 691 if ( toCheck.Contains(TRegexp(fSelectedTrigPattern->At(ipat)->GetName(),kTRUE) ) ) return kTRUE;
57142b8e 692 } // loop on keep pattern
693
694 return kFALSE;
695}
696
697
698//_____________________________________________________________________________
699Bool_t
a3f27e84 700AliMuonEventCuts::CheckTriggerClassCombination ( const TObjArray* combo,
57142b8e 701 const TString& firedTriggerClasses,
702 UInt_t l0Inputs, UInt_t l1Inputs, UInt_t l2Inputs ) const
703{
704 // Check if the "toCheck" class (or logical combination of classes and L0 inputs)
705 // are within the "firedTriggerClasses"
706
707 Bool_t ok(kFALSE);
708
a3f27e84 709 TString comp(combo->GetName());
57142b8e 710 UInt_t trigInputs[3] = {l0Inputs, l1Inputs, l2Inputs};
711
a3f27e84 712 Bool_t exitLoop = kFALSE;
713
714 TIter nextObj(combo);
715 TObjArray* currList = 0x0;
716 while ( ( currList = static_cast<TObjArray*>(nextObj()) ) ) {
717 Int_t listIdx = currList->GetUniqueID();
718 TIter nextA(currList);
719 TObjString* an = 0x0;
57142b8e 720 while ( ( an = static_cast<TObjString*>(nextA()) ) )
721 {
a3f27e84 722 if ( listIdx < 3 ) {
723 UInt_t bit = an->GetUniqueID();
782b4332 724 ok = ( (trigInputs[listIdx] & bit) == bit );
a3f27e84 725 }
726 else {
dba277b7 727 TPRegexp re(Form("(^|[ ])%s([ ]|$)",an->String().Data()));
782b4332 728 ok = firedTriggerClasses.Contains(re);
57142b8e 729 }
782b4332 730 if ( combo->GetUniqueID() == kComboFormula ) comp.ReplaceAll(an->String().Data(),Form("%d",ok));
731 else if ( ( combo->GetUniqueID() == kComboAND && ! ok ) || ( combo->GetUniqueID() == kComboOR && ok ) ) {
a3f27e84 732 exitLoop = kTRUE;
733 break;
57142b8e 734 }
f8b94231 735 }
a3f27e84 736 if ( exitLoop ) break;
737 }
738
782b4332 739 if ( combo->GetUniqueID() == kComboFormula ) {
57142b8e 740 TFormula formula("TriggerClassFormulaCheck", comp.Data());
782b4332 741 if ( formula.Compile() > 0 ) {
742 AliError(Form("Could not evaluate formula %s",comp.Data()));
743 ok = kFALSE;
744 }
57142b8e 745 else ok = formula.Eval(0);
746 }
57142b8e 747
a3f27e84 748 AliDebug(2,Form("tname %s => %d comp=%s inputs 0x%x 0x%x 0x%x",combo->GetName(),ok,comp.Data(),l0Inputs, l1Inputs, l2Inputs));
57142b8e 749
750 return ok;
751}
752
753//_____________________________________________________________________________
754void
34e8fe1d 755AliMuonEventCuts::AddToEventSelectedClass ( const TString& toCheck, const TObjString* foundTrig, UInt_t comboType )
57142b8e 756{
757 /// Add current trigger to the selected class for the event
758
759 // Compute the trigger pt cut level of the current class
760 UInt_t trigLevel = 0;
761 if ( foundTrig ) trigLevel = foundTrig->GetUniqueID();
762 else {
763 // The assigned trigger pt cut level is:
764 // - the correct one if "toCheck" is a single trigger class
765 // - the highest pt cut among the matching ones in case "toCheck" is a trigger class/input
766 // combined through (at least one) logical AND "&"
767 // - the lowest pt cut among the macthing ones in case "toCheck" is a trigger class/input
768 // combined through (only) logical OR "|"
769 // This may lead to errors in case of complex combinations of trigger/inputs
db0b061d 770
771 // First eliminate trigger classes which are negated in combinations
772 TString checkStr(toCheck);
773 while ( checkStr.Contains("!") ) {
774 Int_t startNot = checkStr.Index("!");
775 Int_t endNot = startNot;
776 Int_t npars = 0;
777 for ( endNot = startNot; endNot<checkStr.Length(); endNot++ ) {
778 if ( checkStr[endNot] == '(' ) npars++;
779 else if ( checkStr[endNot] == ')' ) npars--;
780
781 if ( npars == 0 ) {
782 if ( checkStr[endNot] == '&' || checkStr[endNot] == '|' ) break;
783 }
784 }
785 checkStr.Remove(startNot,endNot-startNot);
786 }
787
788 // Then check if they match the Lpt or Hpt
782b4332 789 Bool_t isFirst = kTRUE;
57142b8e 790 for ( Int_t ipat=0; ipat<fSelectedTrigLevel->GetEntries(); ++ipat ) {
db0b061d 791 if ( checkStr.Contains(fSelectedTrigLevel->At(ipat)->GetName() ) ) {
57142b8e 792 UInt_t currLevel = fSelectedTrigLevel->At(ipat)->GetUniqueID();
782b4332 793 if ( comboType == kComboAND ) trigLevel = TMath::Max(trigLevel, currLevel);
794 else if ( comboType == kComboOR || comboType == kComboFormula ) {
795 if ( isFirst ) {
796 trigLevel = currLevel;
797 isFirst = kFALSE;
798 }
799 else trigLevel = TMath::Min(trigLevel, currLevel);
800 }
57142b8e 801 else {
802 trigLevel = currLevel;
803 break;
804 }
805 }
806 } // loop on trig level patterns
807 }
808
809 TObjString* currTrig = new TObjString(toCheck);
810 currTrig->SetUniqueID(trigLevel);
811 fSelectedTrigClassesInEvent->AddLast(currTrig);
812
813 if ( foundTrig ) return;
814 TObjString* addTrig = new TObjString(toCheck);
815 addTrig->SetUniqueID(trigLevel);
816 fAllSelectedTrigClasses->Add(addTrig);
817 TString trigLevelInfo = Form("trig level %i ", trigLevel & 0x3);
818 trigLevelInfo += ( trigLevel > 3 ) ? "di-muon" : "single-muon";
819 AliInfo(Form("Adding %s (%s) to considered trigger classes",toCheck.Data(),trigLevelInfo.Data()));
f8b94231 820}
821
822//________________________________________________________________________
823void AliMuonEventCuts::SetCentralityClasses(Int_t nCentralityBins, Double_t* centralityBins)
824{
825 //
826 /// Set centrality classes
827 //
828 Double_t* bins = centralityBins;
829 Int_t nbins = nCentralityBins;
830
57142b8e 831 Double_t defaultCentralityBins[] = {-5., 0., 5., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 105.};
f8b94231 832 if ( ! centralityBins ) {
833 bins = defaultCentralityBins;
834 nbins = sizeof(defaultCentralityBins)/sizeof(defaultCentralityBins[0])-1;
835 }
836
837 TString centralityEstimator = "V0M";
838 if ( fCentralityClasses ) {
839 centralityEstimator = GetCentralityEstimator();
840 delete fCentralityClasses;
841 }
842 fCentralityClasses = new TAxis(nbins, bins);
843 TString currClass = "";
844 for ( Int_t ibin=1; ibin<=fCentralityClasses->GetNbins(); ++ibin ){
845 currClass = Form("%.0f_%.0f",fCentralityClasses->GetBinLowEdge(ibin),fCentralityClasses->GetBinUpEdge(ibin));
846 fCentralityClasses->SetBinLabel(ibin, currClass.Data());
847 }
848
849 SetCentralityEstimator(centralityEstimator);
850}
851
852//________________________________________________________________________
34e8fe1d 853void AliMuonEventCuts::SetCentralityEstimator ( TString centralityEstimator )
f8b94231 854{
855 /// Set centrality estimator
856 fCentralityClasses->SetName(centralityEstimator.Data());
857}
858
859
860//________________________________________________________________________
861TString AliMuonEventCuts::GetCentralityEstimator () const
862{
863 /// Get centrality estimator
864 return fCentralityClasses->GetName();
865}
866
867//________________________________________________________________________
868Double_t AliMuonEventCuts::GetCentrality ( const AliVEvent* event ) const
869{
870 /// Get centrality
871 AliVEvent* evt = const_cast<AliVEvent*>(event);
872 return evt->GetCentrality()->GetCentralityPercentile(GetCentralityEstimator());
873}
874
875//________________________________________________________________________
876void AliMuonEventCuts::SetDefaultParameters ()
877{
878 /// Standard parameters for muon event
879 SetPhysicsSelectionMask(AliVEvent::kAny);
880 SetVertexMinNContributors(1);
881 SetVertexVzLimits();
882}
883
884
885//________________________________________________________________________
886void AliMuonEventCuts::SetDefaultFilterMask ()
887{
888 /// Standard cuts for muon event
889 SetFilterMask ( kPhysicsSelected | kSelectedTrig | kGoodVertex );
890}
891
892//________________________________________________________________________
893void AliMuonEventCuts::Print(Option_t* option) const
894{
895 //
896 /// Print info
897 //
898 TString sopt(option);
899 sopt.ToLower();
900 if ( sopt.IsNull() || sopt.Contains("*") || sopt.Contains("all") ) sopt = "mask param";
901 UInt_t filterMask = GetFilterMask();
902 if ( sopt.Contains("mask") ) {
903 printf(" *** Muon event filter mask: *** \n");
904 printf(" 0x%x\n", filterMask);
905 if ( filterMask & kPhysicsSelected ) printf(" Pass physics selection 0x%x\n", fPhysicsSelectionMask);
f0c7fd19 906 if ( filterMask & kSelectedCentrality ) printf( "%g < centrality (%s) < %g\n", fCentralityClasses->GetXmin(), GetCentralityEstimator().Data(), fCentralityClasses->GetXmax() );
d0809f42 907 if ( filterMask & kSelectedTrig ) printf(" Has selected trigger classes\n");
908 if ( filterMask & kGoodVertex ) printf(" SPD vertex with %i contributors && %g < Vz < %g\n", GetVertexMinNContributors(), GetVertexVzMin(), GetVertexVzMax());
909 if ( filterMask & kNoPileup ) printf(" Reject pileup with SPD\n");
f8b94231 910 printf(" ******************** \n");
911 }
f0c7fd19 912 if ( sopt.Contains("param") ) {
913 printf(" *** Muon event parameters: *** \n");
914 printf(" Centrality estimator: %s\n", GetCentralityEstimator().Data());
915 printf(" ******************** \n");
916 }
f8b94231 917}