Another histos for lumi
[u/mrichter/AliRoot.git] / ITS / AliITSTriggerFOProcessor.cxx
CommitLineData
ad7f2bfa 1/////////////////////////////////////////////////////////////////////
2// Author: Henrik Tydesjo //
3// //
4// This class takes care of simulating the output from the pixel //
5// trigger system. //
6// The fast-or signals are given as input and they are processed //
7// to see which algorithm will give a signal to the central //
8// trigger system. To avoid doing the same operations many times, //
9// there is a method called PreprocessFOSignals, which should //
10// always be called for each event before the processing of //
11// each individual algorithm is done. //
12// //
13// As soon as a new algorithm has been implemented online, a //
14// corresponding method should be implemented here. Which method //
15// should be used for a given trigger label is taken care of in //
16// ProcessFOSignalsLabel method. //
17// //
18/////////////////////////////////////////////////////////////////////
19
20#include "AliITSTriggerFOProcessor.h"
21#include "AliITSTriggerConditions.h"
22#include <TError.h>
23
65e04d68 24/* $Id$ */
25
ad7f2bfa 26AliITSTriggerFOProcessor::AliITSTriggerFOProcessor() :
27 fFOInner(0), fFOOuter(0), fTriggerCond(NULL)
28{
29 // default constructor
30}
31//______________________________________________________________________
32AliITSTriggerFOProcessor::AliITSTriggerFOProcessor(AliITSTriggerConditions* ocdbCond) :
33 fFOInner(0), fFOOuter(0), fTriggerCond(ocdbCond)
34{
35 // constructor
36}
37//______________________________________________________________________
38AliITSTriggerFOProcessor::AliITSTriggerFOProcessor(const AliITSTriggerFOProcessor& handle):
39 fFOInner(handle.fFOInner), fFOOuter(handle.fFOOuter), fTriggerCond(handle.fTriggerCond)
40{
41 // copy constructor
42}
43//______________________________________________________________________
44AliITSTriggerFOProcessor::~AliITSTriggerFOProcessor() {
45 // destructor
46}
47//______________________________________________________________________
48AliITSTriggerFOProcessor& AliITSTriggerFOProcessor::operator=(const AliITSTriggerFOProcessor& handle) {
49 // assignment operator
50 if (this!=&handle) {
51 fFOInner = handle.fFOInner;
52 fFOOuter = handle.fFOOuter;
53 fTriggerCond = handle.fTriggerCond;
54 }
55 return *this;
56}
57//______________________________________________________________________
49c25a1d 58void AliITSTriggerFOProcessor::SetTriggerConditions(AliITSTriggerConditions* const ocdbCond) {
ad7f2bfa 59 // Method to give pointer to the OCDB conditions entry
60 fTriggerCond = ocdbCond;
61}
62//______________________________________________________________________
63UInt_t AliITSTriggerFOProcessor::GetNumOutputs() const {
64 // return number of outputs (algorithms) in use
65 if (fTriggerCond==NULL) {
66 Error("AliITSTriggerFOProcessor::GetNumOutputs","Trigger conditions entry not yet given.");
67 return 0;
68 }
69 return fTriggerCond->GetNumAlgo();
70}
71//______________________________________________________________________
72const Char_t* AliITSTriggerFOProcessor::GetOutputLabel(Short_t index) const {
73 // return the label of the index'th algorithm in use
74 if (fTriggerCond==NULL) {
75 Error("AliITSTriggerFOProcessor::GetOutputLabel","Trigger conditions entry not yet given.");
76 return "";
77 }
78 return fTriggerCond->GetAlgoLabelI(index);
79}
80//______________________________________________________________________
49c25a1d 81void AliITSTriggerFOProcessor::PreprocessFOSignals(AliITSFOSignalsSPD* const signals) {
ad7f2bfa 82 // Pre-process the fast-or signals to retrieve some data needed by most algorithms
83 if (fTriggerCond==NULL) {
84 Error("AliITSTriggerFOProcessor::PreprocessFOSignals","Trigger conditions entry not yet given.");
85 return;
86 }
87 fFOInner = 0;
88 fFOOuter = 0;
89
90 Int_t eq = -1;
91 Int_t hs = -1;
92 Int_t chip = -1;
93 while (signals->GetNextSignal(eq,hs,chip)) {
94 if (fTriggerCond->IsChipActive( (UInt_t)eq, (UInt_t)hs, (UInt_t)chip) ) {
95 if (hs<=1) fFOInner++;
96 else fFOOuter++;
97 }
98 }
99}
100//______________________________________________________________________
101Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsIndex(Short_t index, AliITSFOSignalsSPD* signals) {
102 // NB: For every event - Always call PreprocessFOSignals before calling this method
103 // Process index'th algorithm - returns true if output active
104 return ProcessFOSignalsLabel(GetOutputLabel(index), signals);
105}
106//______________________________________________________________________
107Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsLabel(const Char_t* label, AliITSFOSignalsSPD* signals) {
108 // NB: For every event - Always call PreprocessFOSignals before calling this method
109 // Process algorithm with label ... - returns true if output active
110 if (fTriggerCond==NULL) {
111 Error("AliITSTriggerFOProcessor::ProcessFOSignalsLabel","Trigger conditions entry not yet given.");
112 return kFALSE;
113 }
114
115 Short_t index = fTriggerCond->GetAlgoIndexL(label);
116 if (index<0) {
117 Error("AliITSTriggerFOProcessor::ProcessFOSignalsLabel", "No conditions for label '%s'.",label);
118 return kFALSE;
119 }
65e04d68 120
ad7f2bfa 121 if (strcmp(label, "0SMB") == 0) return ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter(index, signals);
fa774be6 122 else if (strcmp(label, "0SH1") == 0) return ProcessFOSignalsTHRInnerAndTHROuter(index, signals);
123 else if (strcmp(label, "0SH2") == 0) return ProcessFOSignalsTHRInnerAndTHROuter(index, signals);
124 else if (strcmp(label, "0SH3") == 0) return ProcessFOSignalsTHRInnerAndTHROuter(index, signals);
125 else if (strcmp(label, "0SH4") == 0) return ProcessFOSignalsTHRInnerAndTHROuter(index, signals);
126 else if (strcmp(label, "0SPF") == 0) return ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter(index, signals);
127 else if (strcmp(label, "0SX1") == 0) return ProcessFOSignalsInnerGTOuterPlusOffset(index, signals);
128 else if (strcmp(label, "0SX2") == 0) return ProcessFOSignalsOuterGTInnerPlusOffset(index, signals);
129 else if (strcmp(label, "0SBK") == 0) return ProcessFOSignalsTHRTotal(index, signals);
65e04d68 130 else if (strcmp(label, "0SCO") == 0) return ProcessFOSignalsCosmic(index, signals);
ad7f2bfa 131
132 else {
133 Error("AliITSTriggerFOProcessor::ProcessFOSignalsLabel", "Algorithm not yet implemented for label '%s'.",label);
134 return kFALSE;
135 }
136}
137//______________________________________________________________________
138Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter(Short_t index, AliITSFOSignalsSPD* /*signals*/) {
139 // NB: For every event - Always call PreprocessFOSignals before calling this method
140 // Process algorithm ' I+O > thr && I > thr && O > thr ' (index is needed to get the correct parameters from the ocdb object)
141 if (fTriggerCond==NULL) {
142 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter","Trigger conditions entry not yet given.");
143 return kFALSE;
144 }
145
146 // Get parameter values:
147 Int_t thIO = fTriggerCond->GetAlgoParamValueIN(index, "total_threshold");
148 if (thIO<0) {
149 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter","Parameter 'total_threshold' not defined");
150 return kFALSE;
151 }
152 Int_t thI = fTriggerCond->GetAlgoParamValueIN(index, "inner_threshold");
153 if (thI<0) {
154 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter","Parameter 'inner_threshold' not defined");
155 return kFALSE;
156 }
157 Int_t thO = fTriggerCond->GetAlgoParamValueIN(index, "outer_threshold");
158 if (thO<0) {
159 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotalAndTHRInnerAndTHROuter","Parameter 'outer_threshold' not defined");
160 return kFALSE;
161 }
162
163 // Evaluate:
164 return (fFOInner+fFOOuter >= thIO && fFOInner >= thI && fFOOuter >= thO);
165}
166//______________________________________________________________________
167Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsTHRInnerAndTHROuter(Short_t index, AliITSFOSignalsSPD* /*signals*/) {
168 // NB: For every event - Always call PreprocessFOSignals before calling this method
169 // Process algorithm ' I > thr && O > thr ' (index is needed to get the correct parameters from the ocdb object)
170 if (fTriggerCond==NULL) {
171 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRInnerAndTHROuter","Trigger conditions entry not yet given.");
172 return kFALSE;
173 }
174
175 // Get parameter values:
176 Int_t thI = fTriggerCond->GetAlgoParamValueIN(index, "inner_threshold");
177 if (thI<0) {
178 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRInnerAndTHROuter","Parameter 'inner_threshold' not defined");
179 return kFALSE;
180 }
181 Int_t thO = fTriggerCond->GetAlgoParamValueIN(index, "outer_threshold");
182 if (thO<0) {
183 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRInnerAndTHROuter","Parameter 'outer_threshold' not defined");
184 return kFALSE;
185 }
186
187 // Evaluate:
188 return (fFOInner >= thI && fFOOuter >= thO);
189}
190//______________________________________________________________________
191Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotal(Short_t index, AliITSFOSignalsSPD* /*signals*/) {
192 // NB: For every event - Always call PreprocessFOSignals before calling this method
193 // Process algorithm ' I+O > thr' (index is needed to get the correct parameters from the ocdb object)
194 if (fTriggerCond==NULL) {
195 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotal","Trigger conditions entry not yet given.");
196 return kFALSE;
197 }
198
199 // Get parameter values:
fa774be6 200 Int_t thIO = fTriggerCond->GetAlgoParamValueIN(index, "background_threshold_both");
ad7f2bfa 201 if (thIO<0) {
202 Error("AliITSTriggerFOProcessor::ProcessFOSignalsTHRTotal","Parameter 'total_threshold' not defined");
203 return kFALSE;
204 }
205
206 // Evaluate:
207 return (fFOInner + fFOOuter >= thIO);
208}
209//______________________________________________________________________
210Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsInnerGTOuterPlusOffset(Short_t index, AliITSFOSignalsSPD* /*signals*/) {
211 // NB: For every event - Always call PreprocessFOSignals before calling this method
212 // Process algorithm ' I > O+offset ' (index is needed to get the correct parameters from the ocdb object)
213 if (fTriggerCond==NULL) {
214 Error("AliITSTriggerFOProcessor::ProcessFOSignalsGTOuterPlusOffset","Trigger conditions entry not yet given.");
215 return kFALSE;
216 }
217
218 // Get parameter values:
fa774be6 219 Int_t offset = fTriggerCond->GetAlgoParamValueIN(index, "background_offset_inner");
ad7f2bfa 220 if (offset<0) {
221 Error("AliITSTriggerFOProcessor::ProcessFOSignalsInnerGTOuterPlusOffset","Parameter 'offset' not defined");
222 return kFALSE;
223 }
224
225 // Evaluate:
226 return (fFOInner >= fFOOuter + offset);
227}
228//______________________________________________________________________
229Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsOuterGTInnerPlusOffset(Short_t index, AliITSFOSignalsSPD* /*signals*/) {
230 // NB: For every event - Always call PreprocessFOSignals before calling this method
231 // Process algorithm ' O > I+offset ' (index is needed to get the correct parameters from the ocdb object)
232 if (fTriggerCond==NULL) {
233 Error("AliITSTriggerFOProcessor::ProcessFOSignalsGTOuterPlusOffset","Trigger conditions entry not yet given.");
234 return kFALSE;
235 }
236
237 // Get parameter values:
fa774be6 238 Int_t offset = fTriggerCond->GetAlgoParamValueIN(index, "background_offset_outer");
ad7f2bfa 239 if (offset<0) {
240 Error("AliITSTriggerFOProcessor::ProcessFOSignalsOuterGTInnerPlusOffset","Parameter 'offset' not defined");
241 return kFALSE;
242 }
243
244 // Evaluate:
245 return (fFOOuter >= fFOInner + offset);
246}
65e04d68 247//______________________________________________________________________
49c25a1d 248Bool_t AliITSTriggerFOProcessor::ProcessFOSignalsCosmic(Short_t index, AliITSFOSignalsSPD* const signals) {
65e04d68 249 // NB: For every event - Always call PreprocessFOSignals before calling this method
250 // Process algorithm 'cosmic' (index is needed to get the correct parameters from the ocdb object)
251 if (fTriggerCond==NULL) {
252 Error("AliITSTriggerFOProcessor::ProcessFOSignalsCosmic","Trigger conditions entry not yet given.");
253 return kFALSE;
254 }
255
256 // Get parameter values:
257 Int_t cosmicParam = fTriggerCond->GetAlgoParamValueIN(index, "cosmic_mode");
258 if (cosmicParam<0) {
259 Error("AliITSTriggerFOProcessor::ProcessFOSignalsCosmic","Parameter 'cosmic_mode' not defined");
260 return kFALSE;
261 }
262
263 // Evaluate:
264
265 UShort_t topOuter = 0;
266 UShort_t topInner = 0;
267 UShort_t bottomOuter = 0;
268 UShort_t bottomInner = 0;
269
270 Int_t eq = -1;
271 Int_t hs = -1;
272 Int_t chip = -1;
273 while (signals->GetNextSignal(eq,hs,chip)) {
274 if (fTriggerCond->IsChipActive( (UInt_t)eq, (UInt_t)hs, (UInt_t)chip) ) {
275 if (hs<=1) {
276 if (eq%10 < 5) topInner++;
277 else bottomInner++;
278 }
279 else {
280 if (eq%10 < 5) topOuter++;
281 else bottomOuter++;
282 }
283 }
284 }
285
286 // top outer & bottom outer
287 if (cosmicParam == 0) return (topOuter>0 && bottomOuter>0);
288 // inner & outer
289 if (cosmicParam == 1) return (fFOInner>0 && fFOOuter>0);
290 // double layer ( >=2 of top inner, top outer, bottom inner, bottom outer )
291 if (cosmicParam == 2) {
292 UShort_t nHalfLayers = 0;
293 if (topOuter>0) nHalfLayers++;
294 if (topInner>0) nHalfLayers++;
295 if (bottomOuter>0) nHalfLayers++;
296 if (bottomInner>0) nHalfLayers++;
297 return (nHalfLayers>=2);
298 }
299 // top outer & top inner & bottom outer & bottom inner
300 if (cosmicParam == 3) return (topOuter>0 && topInner>0 && bottomOuter>0 && bottomInner>0);
301 // top outer & bottom outer & inner
302 if (cosmicParam == 4) return (topOuter>0 && bottomOuter>0 && fFOInner>0);
303 // global or
304 if (cosmicParam == 5) return (fFOOuter>0 || fFOInner>0);
305
baffd773 306 Error("AliITSTriggerFOProcessor::ProcessFOSignalsCosmic","'cosmic_algorithm_parameter' = %d not defined",cosmicParam);
65e04d68 307 return kFALSE;
308}
ad7f2bfa 309