]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TRD/info/AliTRDeventCuts.cxx
new event cut class by Markus for local event selection for TRD
[u/mrichter/AliRoot.git] / PWG1 / TRD / info / AliTRDeventCuts.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2008, 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 //                                                                        //
17 // Event cut class for the TRD Performance Train                          //
18 //                                                                        //
19 // Encapsulation of events cuts for usage with TRD performance train      //
20 // - reconstructed vertex                                                 //
21 // - vertex Z position                                                    //
22 // - vertex number of contributors                                        //
23 // - trigger selection list                                               //
24 //                                                                        //
25 // *) see constructor for default values                                  //
26 //                                                                        //
27 // author                                                                 //
28 // Markus Fasel <m.fasel@gsi.de>                                          //
29 //                                                                        //
30 ////////////////////////////////////////////////////////////////////////////
31
32
33 #include <TIterator.h>
34 #include <TMath.h>
35 #include <TObjArray.h>
36 #include <TObjString.h>
37 #include <TString.h>
38
39 #include "AliESDEvent.h"
40 #include "AliESDVertex.h"
41
42 #include "AliTRDeventCuts.h"
43
44 ClassImp(AliTRDeventCuts)
45
46 //______________________________________________________________
47 AliTRDeventCuts::AliTRDeventCuts(const Char_t *name):
48   TNamed(name, ""),
49   fTriggerNames(NULL),
50   fVertexN(1),
51   fVertexZ(15.)
52 {
53   //
54   // Default Constructor
55   //
56 }
57
58 //______________________________________________________________
59 AliTRDeventCuts::~AliTRDeventCuts()
60 {
61 // Destructor
62
63   if(fTriggerNames) fTriggerNames->Delete();
64   delete fTriggerNames;
65 }
66
67 //______________________________________________________________
68 Bool_t AliTRDeventCuts::IsSelected(AliESDEvent *ev, Bool_t col)
69 {
70 // Apply cuts
71
72   Bool_t select = kTRUE;
73   if(fTriggerNames){
74     Bool_t passTrigger = kFALSE; 
75     TString trgname = ev->GetFiredTriggerClasses();
76     TObjArray *triggers = trgname.Tokenize("");
77     TIterator *trgIter = triggers->MakeIterator(); 
78     TObjString *trg = NULL;
79     while((trg = dynamic_cast<TObjString *>(trgIter->Next())))
80       passTrigger = passTrigger || CheckTrigger(trg->String().Data());
81     delete triggers; delete trgIter;
82     select = select && passTrigger;
83   }
84   // select only physical events
85   select = select && (ev->GetEventType() == 7);
86
87   if(!col) return select;
88
89   const AliESDVertex *primVtx = ev->GetPrimaryVertex();
90   if(fVertexN > 0)
91     select = select && (primVtx && primVtx->GetNContributors() >= fVertexN);
92   if(fVertexZ >= 0.)
93     select = select && (primVtx && TMath::Abs(primVtx->GetZ()) <= fVertexZ);
94   return select;
95 }
96
97 //______________________________________________________________
98 void AliTRDeventCuts::AddTrigger(const Char_t *name)
99 {
100 // Add trigger name according to the logbook
101
102   if(!fTriggerNames) fTriggerNames = new TObjArray;
103   if(CheckTrigger(name)) return;
104   fTriggerNames->Add(new TObjString(name));
105 }
106
107 //______________________________________________________________
108 Bool_t AliTRDeventCuts::CheckTrigger(const Char_t *name)
109 {
110 // check if trigger with id "name" is on the accepted trigger list
111
112   TObjString *trg = NULL;
113   TIterator *it = fTriggerNames->MakeIterator();
114   Bool_t triggerExists = kFALSE;
115   while((trg = dynamic_cast<TObjString *>(it))){
116     if(!trg->String().CompareTo(name)) triggerExists = kTRUE;
117   }
118   delete it;
119   return triggerExists;
120 }