+//
+// Class AliRsnCutSet
+//
+// This is the front-end for cut management and checking.
+// It must be prepared by adding all required single cuts,
+// and then with a logical expression which combines all cuts
+// with the "AND", "OR" and "NOT" operators.
+//
+
#include "AliLog.h"
-#include "AliRsnCut.h"
#include "AliRsnExpression.h"
#include "AliRsnCutSet.h"
-ClassImp ( AliRsnCutSet )
-
-AliRsnCutSet::AliRsnCutSet()
- : TNamed(),fNumOfCuts ( 0 ),
- fCutScheme ( "" ),
- fCutSchemeIndexed ( "" ),
- fBoolValues ( 0 ),fIsScheme ( kFALSE )
+ClassImp(AliRsnCutSet)
+
+//_____________________________________________________________________________
+AliRsnCutSet::AliRsnCutSet(AliRsnCut::ETarget target) :
+ TNamed(),
+ fTarget(target),
+ fCuts(0),
+ fNumOfCuts(0),
+ fCutScheme(""),
+ fCutSchemeIndexed(""),
+ fBoolValues(0),
+ fIsScheme(kFALSE),
+ fExpression(0)
{
+//
+// Constructor without name (not recommended)
+//
+
fBoolValues = new Bool_t[1];
-// fExpression = new AliRsnExpression ( fCutSchemeIndexed );
- fExpression = 0;
- AliRsnExpression::sCutSet = this;
+ AliRsnExpression::fgCutSet = this;
}
-AliRsnCutSet::AliRsnCutSet ( TString name )
- : TNamed ( name,name ),fNumOfCuts ( 0 ),
- fCutScheme ( "" ),
- fCutSchemeIndexed ( "" ),
- fBoolValues ( 0 ),fIsScheme ( kFALSE )
+//_____________________________________________________________________________
+AliRsnCutSet::AliRsnCutSet(TString name, AliRsnCut::ETarget target) :
+ TNamed(name, name),
+ fTarget(target),
+ fCuts(0),
+ fNumOfCuts(0),
+ fCutScheme(""),
+ fCutSchemeIndexed(""),
+ fBoolValues(0),
+ fIsScheme(kFALSE),
+ fExpression(0)
{
+//
+// Constructor with argument name (recommended)
+//
+
fBoolValues = new Bool_t[1];
fExpression = 0;
- AliRsnExpression::sCutSet = this;
+ AliRsnExpression::fgCutSet = this;
}
-AliRsnCutSet::AliRsnCutSet ( const AliRsnCutSet & copy )
- : TNamed ( ( TNamed ) copy ),fCuts ( copy.fCuts ),fNumOfCuts ( copy.fNumOfCuts ),
- fCutScheme ( copy.fCutScheme ),
- fCutSchemeIndexed ( copy.fCutSchemeIndexed ),
- fIsScheme ( copy.fIsScheme ),
- fExpression ( copy.fExpression )
+//_____________________________________________________________________________
+AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
+ TNamed((TNamed) copy),
+ fTarget(copy.fTarget),
+ fCuts(copy.fCuts),
+ fNumOfCuts(copy.fNumOfCuts),
+ fCutScheme(copy.fCutScheme),
+ fCutSchemeIndexed(copy.fCutSchemeIndexed),
+ fBoolValues(0),
+ fIsScheme(copy.fIsScheme),
+ fExpression(copy.fExpression)
{
- AliRsnExpression::sCutSet = this;
+//
+// Copy constructor
+//
+
+ AliRsnExpression::fgCutSet = this;
}
+//_____________________________________________________________________________
AliRsnCutSet::~AliRsnCutSet()
{
+//
+// Destructor
+//
+
delete fExpression;
delete [] fBoolValues;
}
-void AliRsnCutSet::AddCut ( AliRsnCut * cut )
+//_____________________________________________________________________________
+void AliRsnCutSet::AddCut(AliRsnCut *cut)
{
- AliDebug ( AliLog::kDebug,"<-" );
- fCuts.Add ( cut );
+//
+// Add a new cut.
+// This must be done for all components of the final expression.
+// If the target of the cut does not match the target of this,
+// the cut is not added.
+//
+
+ if (!cut->IsTarget(fTarget))
+ {
+ AliError("Cut target does not match the cut-set target. Not added.");
+ return;
+ }
+
+ Int_t i;
+
+ AliDebug(AliLog::kDebug,"<-");
+ fCuts.Add(cut);
fNumOfCuts++;
- if ( fBoolValues )
- delete fBoolValues;
+
+ if (fBoolValues) delete [] fBoolValues;
+
fBoolValues = new Bool_t[fNumOfCuts];
- for ( Int_t i=0;i<fNumOfCuts ; i++ )
+ for (i = 0; i < fNumOfCuts; i++)
{
fBoolValues[i] = kTRUE;
}
- AliDebug ( AliLog::kDebug,Form ( "%d",fCuts.GetEntriesFast() ) );
- AliDebug ( AliLog::kDebug,"->" );
+ AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
+ AliDebug(AliLog::kDebug,"->");
}
-void AliRsnCutSet::ShowCuts ( )
+//_____________________________________________________________________________
+void AliRsnCutSet::ShowCuts() const
{
-// AliRsnCut *cut;
-// for ( Int_t i=0; i<fCuts.GetEntriesFast() ;i++ )
-// {
-// cut = ( AliRsnCut* ) fCuts.At ( i );
-// AliInfo ( Form ( "%s (\"%s\") [%.2f - %.2f]",cut->GetName(),cut->GetTitle(),cut->GetMin(),cut->GetMax() ) );
-// }
-}
-
-Bool_t AliRsnCutSet::IsSelected ( AliRsnCut::ECutSetType type, AliRsnDaughter *daughter )
-{
- if ( !fNumOfCuts )
- return kTRUE;
-
- Bool_t boolReturn = kTRUE;
+//
+// Prints all cuts
+//
AliRsnCut *cut;
- for ( Int_t i=0; i<fNumOfCuts ;i++ )
+
+ for (Int_t i = 0; i < fCuts.GetEntriesFast() ;i++)
{
- cut = ( AliRsnCut* ) fCuts.At ( i );
- fBoolValues[i] = cut->IsSelected ( type,daughter );
-// AliInfo(Form("%s %d",cut->GetName(),fBoolValues[i]));
+ cut = (AliRsnCut*)fCuts.At (i);
+ cut->Print();
}
-
- if ( fIsScheme )
- boolReturn = Passed();
-
- return boolReturn;
}
-Bool_t AliRsnCutSet::IsSelected ( AliRsnCut::ECutSetType type, AliRsnPairParticle * pair )
+//_____________________________________________________________________________
+Bool_t AliRsnCutSet::IsSelected(TObject *obj1, TObject *obj2)
{
- if ( !fNumOfCuts )
- return kTRUE;
+//
+// Checks an object according to the cut expression defined here.
+//
+
+ Int_t i;
+
+ if (!fNumOfCuts) return kTRUE;
Bool_t boolReturn = kTRUE;
AliRsnCut *cut;
- for ( Int_t i=0; i<fNumOfCuts ;i++ )
- {
- cut = ( AliRsnCut* ) fCuts.At ( i );
- fBoolValues[i] = cut->IsSelected (type,pair );
-// AliInfo(Form("%s %d",cut->GetName(),fBoolValues[i]));
+ for (i = 0; i < fNumOfCuts; i++) {
+ cut = (AliRsnCut*)fCuts.At(i);
+ fBoolValues[i] = cut->IsSelected(obj1, obj2);
}
- if ( fIsScheme )
- boolReturn = Passed();
-
+ if (fIsScheme) boolReturn = Passed();
return boolReturn;
}
-
-void AliRsnCutSet::SetCutScheme ( const TString & theValue )
+//_____________________________________________________________________________
+void AliRsnCutSet::SetCutScheme(const TString & theValue)
{
- AliDebug ( AliLog::kDebug,"<-" );
+//
+// Define the combination of cuts with logical operators
+// and using the names given to all defined cuts.
+//
+
+ AliDebug(AliLog::kDebug,"<-");
fCutScheme = theValue;
- SetCutSchemeIndexed ( theValue );
+ SetCutSchemeIndexed(theValue);
fIsScheme = kTRUE;
- AliDebug ( AliLog::kDebug,"->" );
+ AliDebug(AliLog::kDebug,"->");
}
-
-void AliRsnCutSet::SetCutSchemeIndexed ( TString theValue )
+//_____________________________________________________________________________
+void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
{
- AliDebug ( AliLog::kDebug,"<-" );
-// fCutSchemeIndexed = theValue;
+//
+// Internal method which indexes all cuts to organize their combo
+//
+
+ AliDebug(AliLog::kDebug,"<-");
+ theValue.Append(" ");
+ // fCutSchemeIndexed = theValue;
fCutSchemeIndexed = GetCutSchemeIndexed();
- AliDebug ( AliLog::kDebug,"->" );
+ AliDebug(AliLog::kDebug,"->");
}
-Int_t AliRsnCutSet::GetIndexByCutName ( TString s )
+//_____________________________________________________________________________
+Int_t AliRsnCutSet::GetIndexByCutName(TString s)
{
+//
+// Retrieve the cut index from its name
+//
+
+ Int_t i;
AliRsnCut *cut;
- for ( Int_t i=0 ;i< fCuts.GetEntriesFast() ;i++ )
- {
- cut = ( AliRsnCut* ) fCuts.At ( i );
-// if ( !cut->GetName().CompareTo ( s ) )
- if ( !s.CompareTo ( cut->GetName() ) )
- {
- return i;
- }
+
+ for (i = 0; i < fCuts.GetEntriesFast(); i++) {
+ cut = (AliRsnCut*) fCuts.At(i);
+ if (!s.CompareTo(cut->GetName())) return i;
}
return -1;
}
+//_____________________________________________________________________________
Bool_t AliRsnCutSet::Passed()
{
- AliRsnExpression::sCutSet = this;
- if ( !fExpression )
- {
- fExpression = new AliRsnExpression ( fCutSchemeIndexed );
- AliDebug ( AliLog::kDebug,"fExpression was created." );
+//
+// Combines the cuts according to expression
+// and gives a global response to the cut check
+//
+
+ AliRsnExpression::fgCutSet = this;
+ if (!fExpression) {
+ fExpression = new AliRsnExpression(fCutSchemeIndexed);
+ AliDebug(AliLog::kDebug,"fExpression was created.");
}
- return fExpression->Value ( *GetCuts() );
+
+ return fExpression->Value(*GetCuts());
}
+//_____________________________________________________________________________
Bool_t AliRsnCutSet::IsValidScheme()
{
- return ( ! ( ShowCutScheme().Contains ( "Error" ) ) );
+//
+// Validity check on cut expression specified by user
+//
+
+ return (!(ShowCutScheme().Contains("Error")));
}
+//_____________________________________________________________________________
TString AliRsnCutSet::ShowCutScheme()
{
+//
+// Utility method to check validity of expression
+//
return fExpression->Unparse();
}
-Int_t AliRsnCutSet::TestExpression ( TString opt )
+//_____________________________________________________________________________
+Int_t AliRsnCutSet::TestExpression(TString opt)
{
-// AliRsnCut *cut1 = new AliRsnCut ( "aaa","aaa" );
-// cut1->SetCutValues ( AliRsnCut::kEsdPt,0.0,1.0 );
-// AliRsnCut *cut2 = new AliRsnCut ( "bbb","bbb" );
-// cut2->SetCutValues ( AliRsnCut::kEsdPt,1.,2.0 );
-// AliRsnCut *cut3 = new AliRsnCut ( "ccc","ccc" );
-// cut3->SetCutValues ( AliRsnCut::kEsdPt,2.0,3.0 );
+
+// AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
+// cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
+// AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
+// cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
+// AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
+// cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
//
-// AliRsnCutSet* set = new AliRsnCutSet ( "setOne" );
-// set->AddCut ( cut1 );
-// set->AddCut ( cut2 );
-// set->AddCut ( cut3 );
+// AliRsnCutSet* set = new AliRsnCutSet ("setOne");
+// set->AddCut (cut1);
+// set->AddCut (cut2);
+// set->AddCut (cut3);
//
-// set->SetCutScheme ( "(aaa&!(ccc))&(bbb&!(ccc))" );
+// set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
//
// set->ShowCuts ();
+ AliDebug(1, opt.Data());
return 0;
}
+//_____________________________________________________________________________
void AliRsnCutSet::PrintSetInfo()
{
+//
+// Show data about the cut set
+//
+ Int_t i;
- AliInfo ( "========== Rsn Cut Set info ==============" );
- AliInfo ( Form ( "Sheme : %s",fCutScheme.Data() ) );
- AliInfo ( Form ( "Sheme : %s",fCutSchemeIndexed.Data() ) );
- AliInfo ( Form ( "Num of Cuts: %d", fCuts.GetEntriesFast() ) );
- AliInfo ( "====== Cuts ======" );
+ AliInfo("========== Rsn Cut Set info ==============");
+ AliInfo(Form("Scheme : %s",fCutScheme.Data()));
+ AliInfo(Form("Scheme : %s",fCutSchemeIndexed.Data()));
+ AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
+ AliInfo("====== Cuts ======");
AliRsnCut *cut;
- for ( Int_t i=0 ;i< fCuts.GetEntriesFast() ;i++ )
- {
- cut = ( AliRsnCut* ) fCuts.At ( i );
- if ( cut )
- AliInfo ( Form ( "%d %d",i,fBoolValues[i] ) );
-
+ for (i = 0; i < fCuts.GetEntriesFast(); i++) {
+ cut = (AliRsnCut*) fCuts.At(i);
+ if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
}
- AliInfo ( "========== END Rsn Cut Mgr info ==============" );
-
+ AliInfo("========== END Rsn Cut Mgr info ==============");
}
+//_____________________________________________________________________________
TString AliRsnCutSet::GetCutSchemeIndexed()
{
- AliDebug ( AliLog::kDebug,"<-" );
- TString str ( fCutScheme );
- AliDebug ( AliLog::kDebug,Form ( "Num of cuts %d",fCuts.GetEntriesFast() ) );
+//
+// Internal method to retrieve the list of cuts with their indexes
+// for evaluation of cut expression
+//
+
+ AliDebug(AliLog::kDebug,"<-");
+ Int_t i;
+ TString str(fCutScheme);
+ AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
AliRsnCut *cut;
- for ( Int_t i=0; i<fCuts.GetEntriesFast();i++ )
- {
- cut = ( AliRsnCut* ) fCuts.At ( i );
- str.ReplaceAll ( cut->GetName(),Form ( "%d",i ) );
+ for (i = 0; i < fCuts.GetEntriesFast(); i++) {
+ cut = (AliRsnCut*) fCuts.At(i);
+ str.ReplaceAll(cut->GetName(),Form("%d",i));
}
- AliDebug ( AliLog::kDebug,"->" );
+ AliDebug(AliLog::kDebug,"->");
return str;
}
+//_____________________________________________________________________________
+void AliRsnCutSet::SetEvent(AliRsnEvent *event)
+{
+//
+// Set the reference event to all contained cuts
+//
+
+ Int_t i;
+ AliRsnCut *cut;
+ for (i = 0; i < fCuts.GetEntriesFast(); i++) {
+ cut = (AliRsnCut*) fCuts.At(i);
+ if (cut) cut->SetEvent(event);
+ }
+}