add new mergeable classes for chamber status and trigger statistics
[u/mrichter/AliRoot.git] / PWGPP / 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 "AliLog.h"
40 #include "AliESDEvent.h"
41 #include "AliESDVertex.h"
42
43 #include "AliTRDeventInfo.h"
44 #include "AliTRDeventCuts.h"
45
46 ClassImp(AliTRDeventCuts)
47
48 //______________________________________________________________
49 AliTRDeventCuts::AliTRDeventCuts()
50   :TNamed("trdEventCuts", "")
51   ,fTriggerNames(NULL)
52   ,fBunches(NULL)
53   ,fEventType(7)
54   ,fVertexN(1)
55   ,fVertexZ(15.)
56 {
57   //
58   // Dummy Constructor
59   //
60   
61 }
62
63 //______________________________________________________________
64 AliTRDeventCuts::AliTRDeventCuts(const Char_t *name)
65   :TNamed(name, "")
66   ,fTriggerNames(NULL)
67   ,fBunches(NULL)
68   ,fEventType(7)
69   ,fVertexN(1)
70   ,fVertexZ(15.)
71 {
72   //
73   // Default Constructor
74   //
75 }
76
77 //______________________________________________________________
78 AliTRDeventCuts::AliTRDeventCuts(const AliTRDeventCuts &ref)
79   :TNamed((TNamed&)ref)
80   ,fTriggerNames(NULL)
81   ,fBunches(NULL)
82   ,fEventType(ref.fEventType)
83   ,fVertexN(ref.fVertexN)
84   ,fVertexZ(ref.fVertexZ)
85 {
86 // Copy constructor
87   if(ref.fTriggerNames){
88     for(Int_t it(0); it<ref.fTriggerNames->GetEntriesFast(); it++) AddTrigger(((TObjString*)(*ref.fTriggerNames)[it])->GetName());
89   }
90   if(ref.fBunches) SetBunchSelection(AliTRDeventInfo::kLHCbunches, ref.fBunches);
91 }
92
93 //______________________________________________________________
94 AliTRDeventCuts::~AliTRDeventCuts()
95 {
96 // Destructor
97
98   if(fTriggerNames) fTriggerNames->Delete();
99   delete fTriggerNames;
100   if(fBunches) delete [] fBunches;
101 }
102
103 //______________________________________________________________
104 Bool_t AliTRDeventCuts::IsSelected(AliESDEvent *ev, Bool_t col)
105 {
106 // Apply cuts
107
108   Bool_t select = kTRUE;
109   if(fTriggerNames){
110     Bool_t passTrigger = kFALSE; 
111     TString trgname = ev->GetFiredTriggerClasses();
112     TObjArray *triggers = trgname.Tokenize(" ");
113     TIterator *trgIter = triggers->MakeIterator(); 
114     TObjString *trg(NULL);
115     while((trg = dynamic_cast<TObjString *>(trgIter->Next())))
116       passTrigger = passTrigger || CheckTrigger(trg->String().Data());
117     triggers->Delete(); delete triggers; delete trgIter;
118     select = select && passTrigger;
119   }
120   if(!select){
121     AliDebug(1, Form("Reject Ev[%d] for trigger[%s]", ev->GetEventNumberInFile(), ev->GetFiredTriggerClasses().Data()));
122     return select;
123   }
124   // select only physical events
125   select = select && (ev->GetEventType() == fEventType);
126   if(!select){
127     AliDebug(1, Form("Reject Ev[%d] for EvType[%d]", ev->GetEventNumberInFile(), ev->GetEventType()));
128     return select;
129   }
130
131   if(!col) return select;
132
133   // vertex selection
134   const AliESDVertex *primVtx = ev->GetPrimaryVertex();
135   if(fVertexN > 0)
136     select = select && (primVtx && primVtx->GetNContributors() >= fVertexN);
137   if(fVertexZ >= 0.)
138     select = select && (primVtx && TMath::Abs(primVtx->GetZ()) <= fVertexZ);
139   if(!select){
140     AliDebug(1, Form("Reject Ev[%d] for Vertex[%p][%d %6.2f]", ev->GetEventNumberInFile(), (void*)primVtx, primVtx?primVtx->GetNContributors():0, primVtx?TMath::Abs(primVtx->GetZ()):0));
141     return select;
142   }
143
144   // bunch cross selection
145   if(fBunches){
146     Int_t evBC(ev->GetBunchCrossNumber()), ibc(0);
147     Bool_t kFOUND(kFALSE);
148     while(fBunches[ibc]>0){
149       if(evBC==fBunches[ibc]){
150         kFOUND = kTRUE;
151         break;
152       }
153       ibc++;
154     }
155     select = select && kFOUND;
156   }
157   if(!select){
158     AliDebug(1, Form("Reject Ev[%d] for BunchCross[%d]", ev->GetEventNumberInFile(), ev->GetBunchCrossNumber()));
159     return select;
160   }
161   return select;
162 }
163
164 //______________________________________________________________
165 void AliTRDeventCuts::AddTrigger(const Char_t *name)
166 {
167 // Add trigger name according to the logbook
168
169   if(!fTriggerNames) fTriggerNames = new TObjArray;
170   if(CheckTrigger(name)) return;
171   fTriggerNames->Add(new TObjString(name));
172 }
173
174 //______________________________________________________________
175 Bool_t AliTRDeventCuts::CheckTrigger(const Char_t *name)
176 {
177 // check if trigger with id "name" is on the accepted trigger list
178
179   if(!fTriggerNames) return kFALSE;
180   Bool_t kExists(kFALSE);
181   for(Int_t it(0); it<fTriggerNames->GetEntriesFast(); it++){
182     if(((TObjString*)(*fTriggerNames)[it])->String().CompareTo(name)==0){
183       kExists = kTRUE;
184       break;
185     }
186   }
187   return kExists;
188 }
189
190
191 //______________________________________________________________
192 void AliTRDeventCuts::Print(Option_t */*opt*/) const
193 {
194 // Print content of event cuts
195   printf("Event Type       : %2d\n", fEventType);
196   printf("Vertex  selection: N[%2d] Z[cm]=%6.2f\n", fVertexN, fVertexZ);
197   if(fTriggerNames){
198     printf("Trigger selection: ");
199     for(Int_t it(0); it<fTriggerNames->GetEntriesFast(); it++) printf("\"%s\" ", ((TObjString*)(*fTriggerNames)[it])->GetName());
200     printf("\n");
201   }
202   if(fBunches){
203     printf("Bunches selection: ");
204     for(Int_t ibc(0); ibc<AliTRDeventInfo::kLHCbunches; ibc++){
205       if(fBunches[ibc]<0) break;
206       printf("%4d ", fBunches[ibc]);
207     }
208     printf("\n");
209   }
210 }
211
212 //______________________________________________________________
213 void AliTRDeventCuts::SetBunchSelection(Int_t n, Int_t bunches[])
214 {
215 // Set Bunch selection for run
216   if(!fBunches) fBunches = new Int_t[AliTRDeventInfo::kLHCbunches];
217   for(Int_t ibc(0); ibc<AliTRDeventInfo::kLHCbunches; ibc++) fBunches[ibc] = ibc<n?bunches[ibc]:-1;
218 }
219