1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include "AliMuonEventCuts.h"
19 #include "THashList.h"
20 #include "TObjArray.h"
21 #include "TObjString.h"
23 #include "TParameter.h"
30 #include "AliInputEventHandler.h"
31 #include "AliVEvent.h"
32 #include "AliESDEvent.h"
33 #include "AliAODEvent.h"
34 #include "AliVVertex.h"
35 #include "AliCentrality.h"
36 #include "AliTimeStamp.h"
38 #include "AliAnalysisMuonUtility.h"
41 ClassImp(AliMuonEventCuts) // Class implementation in ROOT context
45 //________________________________________________________________________
46 AliMuonEventCuts::AliMuonEventCuts() :
48 fPhysicsSelectionMask(0),
49 fVertexMinNContributors(0),
52 fDefaultTrigClassPatterns(""),
53 fSelectedTrigPattern(0x0),
54 fRejectedTrigPattern(0x0),
55 fSelectedTrigLevel(0x0),
56 fAllSelectedTrigClasses(0x0),
57 fCentralityClasses(0x0),
59 fSelectedTrigClassesInEvent(0x0)
64 //________________________________________________________________________
65 AliMuonEventCuts::AliMuonEventCuts(const char* name, const char* title ) :
66 AliAnalysisCuts(name, title),
67 fPhysicsSelectionMask(0),
68 fVertexMinNContributors(0),
71 fDefaultTrigClassPatterns(""),
72 fSelectedTrigPattern(new TObjArray()),
73 fRejectedTrigPattern(new TObjArray()),
74 fSelectedTrigLevel(new TObjArray()),
75 fAllSelectedTrigClasses(new THashList()),
76 fCentralityClasses(0x0),
78 fSelectedTrigClassesInEvent(new TObjArray())
81 SetDefaultParameters();
82 SetDefaultFilterMask();
83 SetDefaultTrigClassPatterns();
85 SetCentralityClasses();
86 fAllSelectedTrigClasses->SetOwner();
87 fSelectedTrigClassesInEvent->SetOwner();
90 //________________________________________________________________________
91 AliMuonEventCuts::AliMuonEventCuts(const AliMuonEventCuts& obj) :
93 fPhysicsSelectionMask(obj.fPhysicsSelectionMask),
94 fVertexMinNContributors(obj.fVertexMinNContributors),
95 fVertexVzMin(obj.fVertexVzMin),
96 fVertexVzMax(obj.fVertexVzMax),
97 fDefaultTrigClassPatterns(obj.fDefaultTrigClassPatterns),
98 fSelectedTrigPattern(obj.fSelectedTrigPattern),
99 fRejectedTrigPattern(obj.fRejectedTrigPattern),
100 fSelectedTrigLevel(obj.fSelectedTrigLevel),
101 fAllSelectedTrigClasses(obj.fAllSelectedTrigClasses),
102 fCentralityClasses(obj.fCentralityClasses),
103 fTimeStamp(obj.fTimeStamp),
104 fSelectedTrigClassesInEvent(obj.fSelectedTrigClassesInEvent)
110 //________________________________________________________________________
111 AliMuonEventCuts& AliMuonEventCuts::operator=(const AliMuonEventCuts& obj)
113 /// Assignment operator
114 if ( this != &obj ) {
115 AliAnalysisCuts::operator=(obj);
116 fPhysicsSelectionMask = obj.fPhysicsSelectionMask;
117 fVertexMinNContributors = obj.fVertexMinNContributors,
118 fVertexVzMin = obj.fVertexVzMin;
119 fVertexVzMax = obj.fVertexVzMax;
120 fDefaultTrigClassPatterns = obj.fDefaultTrigClassPatterns;
121 fSelectedTrigPattern = obj.fSelectedTrigPattern;
122 fRejectedTrigPattern = obj.fRejectedTrigPattern;
123 fSelectedTrigLevel = obj.fSelectedTrigLevel;
124 fAllSelectedTrigClasses = obj.fAllSelectedTrigClasses;
125 fCentralityClasses = obj.fCentralityClasses;
126 fTimeStamp = obj.fTimeStamp;
127 fSelectedTrigClassesInEvent = obj.fSelectedTrigClassesInEvent;
133 //________________________________________________________________________
134 AliMuonEventCuts::~AliMuonEventCuts()
137 delete fSelectedTrigPattern;
138 delete fRejectedTrigPattern;
139 delete fSelectedTrigLevel;
140 delete fAllSelectedTrigClasses;
141 delete fSelectedTrigClassesInEvent;
142 delete fCentralityClasses;
146 //________________________________________________________________________
147 Bool_t AliMuonEventCuts::IsSelected( TObject* obj )
149 /// Track is selected
150 UInt_t filterMask = GetFilterMask();
151 UInt_t selectionMask = GetSelectionMask(obj);
153 return ( ( selectionMask & filterMask ) == filterMask );
157 //________________________________________________________________________
158 UInt_t AliMuonEventCuts::GetSelectionMask( const TObject* obj )
160 /// Get selection mask
162 UInt_t selectionMask = 0;
164 const AliInputEventHandler* inputHandler = static_cast<const AliInputEventHandler*> ( obj );
166 if ( const_cast<AliInputEventHandler*>(inputHandler)->IsEventSelected() & fPhysicsSelectionMask ) selectionMask |= kPhysicsSelected;
168 const AliVEvent* event = inputHandler->GetEvent();
170 Double_t centrality = GetCentrality(event);
171 if ( centrality >= fCentralityClasses->GetXmin() && centrality <= fCentralityClasses->GetXmax() ) selectionMask |= kSelectedCentrality;
175 if ( fSelectedTrigClassesInEvent->GetEntries() > 0 ) selectionMask |= kSelectedTrig;
177 AliVVertex* vertex = AliAnalysisMuonUtility::GetVertexSPD(event);
178 if ( vertex->GetNContributors() >= GetVertexMinNContributors() &&
179 vertex->GetZ() >= GetVertexVzMin() && vertex->GetZ() <= GetVertexVzMax() ) selectionMask |= kGoodVertex;
181 AliDebug(1, Form("Selection mask 0x%x\n", selectionMask));
183 return selectionMask;
187 //________________________________________________________________________
188 Bool_t AliMuonEventCuts::IsSelected( TList* /* list */)
191 AliError("Function not implemented: Use IsSelected(TObject*)");
195 //________________________________________________________________________
196 Bool_t AliMuonEventCuts::UpdateEvent ( const AliVEvent* event )
198 /// Update the transient data member per event
200 AliTimeStamp currTimeStamp(event->GetOrbitNumber(), event->GetPeriodNumber(), event->GetBunchCrossNumber());
201 if ( fTimeStamp && fTimeStamp->Compare(&currTimeStamp) == 0 ) return kFALSE;
203 BuildTriggerClasses(AliAnalysisMuonUtility::GetFiredTriggerClasses(event));
206 fTimeStamp = new AliTimeStamp(currTimeStamp);
211 //________________________________________________________________________
212 void AliMuonEventCuts::SetDefaultTrigClassPatterns ()
214 /// Set the default patterns
215 /// (done in such a way to get all muon triggers)
216 fDefaultTrigClassPatterns = "CINT CMU CMBAC CPBI !-ACE- !-AC- !-E- !WU !EGA !EJE !PHS";
217 SetTrigClassPatterns(fDefaultTrigClassPatterns);
220 //________________________________________________________________________
221 void AliMuonEventCuts::SetTrigClassPatterns ( TString pattern )
223 /// Set trigger classes
225 /// Classes are filled dynamically according to the pattern
226 /// - if name contains ! (without spaces): reject it
227 /// - otherwise, keep it
229 /// SetTrigClassPatterns("CMBAC !ALLNOTRD")
230 /// keeps classes containing CMBAC, and not containing ALLNOTRD.
232 /// CAVEAT: if you use an fCFContainer and you want an axis to contain the trigger classes,
233 /// please be sure that each pattern matches only 1 trigger class, or triggers will be mixed up
234 /// when merging different chuncks.
236 fSelectedTrigPattern->SetOwner();
237 if ( fSelectedTrigPattern->GetEntries() > 0 ) fSelectedTrigPattern->Delete();
238 fRejectedTrigPattern->SetOwner();
239 if ( fRejectedTrigPattern->GetEntries() > 0 ) fRejectedTrigPattern->Delete();
241 pattern.ReplaceAll(" "," ");
242 pattern.ReplaceAll("! ","!");
244 TObjArray* fullList = pattern.Tokenize(" ");
246 for ( Int_t ipat=0; ipat<fullList->GetEntries(); ++ipat ) {
247 TString currPattern = fullList->At(ipat)->GetName();
248 if ( currPattern.Contains("!") ) {
249 currPattern.ReplaceAll("!","");
250 fRejectedTrigPattern->AddLast(new TObjString(currPattern));
252 else fSelectedTrigPattern->AddLast(new TObjString(currPattern));
258 //________________________________________________________________________
259 void AliMuonEventCuts::SetTrigClassLevels ( TString pattern )
261 /// Set trigger cut level associated to the trigger class
264 /// SetTrigClassLevels("MSL:Lpt MSH:Hpt MUL:LptLpt")
266 /// For the trigger classes defined in SetTrigClassPatterns
267 /// it check if they contains the keywords MSL or MSH
268 /// Hence, in the analysis, the function
269 /// TrackPtCutMatchTrigClass(track, "CPBIMSL") returns true if track match Lpt
270 /// TrackPtCutMatchTrigClass(track, "CPBIMSH") returns true if track match Hpt
271 /// TrackPtCutMatchTrigClass(track, "CMBAC") always returns true
273 fSelectedTrigLevel->SetOwner();
274 if ( fSelectedTrigLevel->GetEntries() > 0 ) fSelectedTrigLevel->Delete();
276 pattern.ReplaceAll(" "," ");
277 pattern.ReplaceAll(" :",":");
279 TObjArray* fullList = pattern.Tokenize(" ");
281 for ( Int_t ipat=0; ipat<fullList->GetEntries(); ++ipat ) {
282 TString currPattern = fullList->At(ipat)->GetName();
283 TObjArray* arr = currPattern.Tokenize(":");
284 TObjString* trigClassPattern = new TObjString(arr->At(0)->GetName());
285 TString selTrigLevel = arr->At(1)->GetName();
286 selTrigLevel.ToUpper();
287 UInt_t trigLevel = 0;
288 if ( selTrigLevel.Contains("LPT") ) {
290 if ( selTrigLevel.Contains("LPTLPT") ) trigLevel += 2<<offset;
292 else if ( selTrigLevel.Contains("HPT") ) {
294 if ( selTrigLevel.Contains("HPTHPT") ) trigLevel += 3<<offset;
296 trigClassPattern->SetUniqueID(trigLevel);
297 fSelectedTrigLevel->AddLast(trigClassPattern);
304 //________________________________________________________________________
305 TArrayI AliMuonEventCuts::GetTrigClassPtCutLevel ( const TString trigClassName ) const
307 /// Get trigger class pt cut level for tracking/trigger matching
308 TObject* obj = fAllSelectedTrigClasses->FindObject(trigClassName.Data());
310 AliWarning(Form("Class %s not in the list!", trigClassName.Data()));
314 TArrayI ptCutLevel(2);
316 ptCutLevel[0] = obj->GetUniqueID() & 0x3;
317 ptCutLevel[1] = ( obj->GetUniqueID() >> 2 ) & 0x3;
319 AliDebug(1,Form("Class %s ptCutLevel %i %i",trigClassName.Data(),ptCutLevel[0],ptCutLevel[1]));
325 //________________________________________________________________________
326 TObjArray* AliMuonEventCuts::GetSelectedTrigClassesInEvent( const AliVEvent* event )
328 /// Return the selected trigger classes in the current event
330 return fSelectedTrigClassesInEvent;
334 //________________________________________________________________________
335 void AliMuonEventCuts::BuildTriggerClasses ( const TString firedTrigClasses )
338 /// Return the list of trigger classes to be considered
339 /// for current event. Update the global list if necessary
342 delete fSelectedTrigClassesInEvent;
343 fSelectedTrigClassesInEvent = new TObjArray(0);
344 fSelectedTrigClassesInEvent->SetOwner();
346 TString firedTrigClassesAny = "ANY " + firedTrigClasses;
347 TObjArray* firedTrigClassesList = firedTrigClassesAny.Tokenize(" ");
349 UInt_t trigLevel = 0;
350 for ( Int_t itrig=0; itrig<firedTrigClassesList->GetEntries(); ++itrig ) {
351 TString trigName = ((TObjString*)firedTrigClassesList->At(itrig))->GetString();
353 TObject* foundTrig = fAllSelectedTrigClasses->FindObject(trigName.Data());
354 if ( foundTrig ) trigLevel = foundTrig->GetUniqueID();
356 Bool_t rejectTrig = kFALSE;
357 for ( Int_t ipat=0; ipat<fRejectedTrigPattern->GetEntries(); ++ipat ) {
358 if ( trigName.Contains(fRejectedTrigPattern->At(ipat)->GetName() ) ) {
362 } // loop on reject pattern
363 if ( rejectTrig ) continue;
366 for ( Int_t ipat=0; ipat<fSelectedTrigPattern->GetEntries(); ++ipat ) {
367 if ( trigName.Contains(fSelectedTrigPattern->At(ipat)->GetName() ) ) {
371 } // loop on keep pattern
372 if ( rejectTrig ) continue;
375 for ( Int_t ipat=0; ipat<fSelectedTrigLevel->GetEntries(); ++ipat ) {
376 if ( trigName.Contains(fSelectedTrigLevel->At(ipat)->GetName() ) ) {
377 trigLevel = fSelectedTrigLevel->At(ipat)->GetUniqueID();
380 } // loop on trig level patterns
382 TObjString* currTrig = new TObjString(trigName);
383 currTrig->SetUniqueID(trigLevel);
384 fSelectedTrigClassesInEvent->AddLast(currTrig);
386 if ( foundTrig ) continue;
387 TObjString* addTrig = new TObjString(trigName);
388 addTrig->SetUniqueID(trigLevel);
389 fAllSelectedTrigClasses->Add(addTrig);
390 TString trigLevelInfo = Form("trig level %i ", trigLevel & 0x3);
391 trigLevelInfo += ( trigLevel > 3 ) ? "di-muon" : "single-muon";
392 AliInfo(Form("Adding %s (%s) to considered trigger classes",trigName.Data(),trigLevelInfo.Data()));
393 } // loop on trigger classes
395 delete firedTrigClassesList;
398 //________________________________________________________________________
399 void AliMuonEventCuts::SetCentralityClasses(Int_t nCentralityBins, Double_t* centralityBins)
402 /// Set centrality classes
404 Double_t* bins = centralityBins;
405 Int_t nbins = nCentralityBins;
407 Double_t defaultCentralityBins[] = {-5., 0., 5., 10., 20., 30., 40., 50., 60., 70., 80., 100., 105.};
408 if ( ! centralityBins ) {
409 bins = defaultCentralityBins;
410 nbins = sizeof(defaultCentralityBins)/sizeof(defaultCentralityBins[0])-1;
413 TString centralityEstimator = "V0M";
414 if ( fCentralityClasses ) {
415 centralityEstimator = GetCentralityEstimator();
416 delete fCentralityClasses;
418 fCentralityClasses = new TAxis(nbins, bins);
419 TString currClass = "";
420 for ( Int_t ibin=1; ibin<=fCentralityClasses->GetNbins(); ++ibin ){
421 currClass = Form("%.0f_%.0f",fCentralityClasses->GetBinLowEdge(ibin),fCentralityClasses->GetBinUpEdge(ibin));
422 fCentralityClasses->SetBinLabel(ibin, currClass.Data());
425 SetCentralityEstimator(centralityEstimator);
428 //________________________________________________________________________
429 void AliMuonEventCuts::SetCentralityEstimator ( const TString centralityEstimator )
431 /// Set centrality estimator
432 fCentralityClasses->SetName(centralityEstimator.Data());
436 //________________________________________________________________________
437 TString AliMuonEventCuts::GetCentralityEstimator () const
439 /// Get centrality estimator
440 return fCentralityClasses->GetName();
443 //________________________________________________________________________
444 Double_t AliMuonEventCuts::GetCentrality ( const AliVEvent* event ) const
447 AliVEvent* evt = const_cast<AliVEvent*>(event);
448 return evt->GetCentrality()->GetCentralityPercentile(GetCentralityEstimator());
451 //________________________________________________________________________
452 void AliMuonEventCuts::SetDefaultParameters ()
454 /// Standard parameters for muon event
455 SetPhysicsSelectionMask(AliVEvent::kAny);
456 SetVertexMinNContributors(1);
461 //________________________________________________________________________
462 void AliMuonEventCuts::SetDefaultFilterMask ()
464 /// Standard cuts for muon event
465 SetFilterMask ( kPhysicsSelected | kSelectedTrig | kGoodVertex );
468 //________________________________________________________________________
469 void AliMuonEventCuts::Print(Option_t* option) const
474 TString sopt(option);
476 if ( sopt.IsNull() || sopt.Contains("*") || sopt.Contains("all") ) sopt = "mask param";
477 UInt_t filterMask = GetFilterMask();
478 if ( sopt.Contains("mask") ) {
479 printf(" *** Muon event filter mask: *** \n");
480 printf(" 0x%x\n", filterMask);
481 if ( filterMask & kPhysicsSelected ) printf(" Pass physics selection 0x%x\n", fPhysicsSelectionMask);
482 if ( filterMask & kSelectedCentrality ) printf( "%g < centrality < %g", fCentralityClasses->GetXmin(), fCentralityClasses->GetXmax() );
483 if ( filterMask & kSelectedTrig ) printf(" Has selected trigger classes\n");
484 if ( filterMask & kGoodVertex ) printf(" SPD vertex with %i contributors && %g < Vz < %g\n", GetVertexMinNContributors(), GetVertexVzMin(), GetVertexVzMax());
485 printf(" ******************** \n");