Added loop for extraction of clusters really attached to its track.
[u/mrichter/AliRoot.git] / ANALYSIS / AliTriggerAnalysis.cxx
CommitLineData
70fdd197 1/* $Id: AliTriggerAnalysis.cxx 35782 2009-10-22 11:54:31Z jgrosseo $ */
ff8c4f30 2
7a11141c 3/**************************************************************************
4 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Author: The ALICE Off-line Project. *
7 * Contributors are mentioned in the code where appropriate. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18//-------------------------------------------------------------------------
70fdd197 19// Implementation of Class AliTriggerAnalysis
20// This class provides function to check if events have been triggered based on the data in the ESD
21// The trigger bits, trigger class inputs and only the data (offline trigger) can be used
7a11141c 22// Origin: Jan Fiete Grosse-Oetringhaus, CERN
23//-------------------------------------------------------------------------
24
70fdd197 25#include <Riostream.h>
907972ff 26#include <TH1F.h>
90dc86e9 27#include <TH2F.h>
907972ff 28#include <TList.h>
29#include <TIterator.h>
c01a136b 30#include "TParameter.h"
31#include <TMap.h>
733f0542 32#include <TRandom.h>
907972ff 33
70fdd197 34#include <AliTriggerAnalysis.h>
ff8c4f30 35
36#include <AliLog.h>
8d5a14d6 37#include <AliAnalysisManager.h>
ff8c4f30 38
39#include <AliESDEvent.h>
40
41#include <AliMultiplicity.h>
42#include <AliESDVZERO.h>
c8d3e441 43#include <AliESDZDC.h>
7a11141c 44#include <AliESDFMD.h>
225667ea 45#include <AliESDVertex.h>
449618cd 46#include <AliESDtrackCuts.h>
b68d0b5e 47#include <AliDAQ.h>
48#include <AliESDTrdTrack.h>
ff8c4f30 49
70fdd197 50ClassImp(AliTriggerAnalysis)
ff8c4f30 51
70fdd197 52AliTriggerAnalysis::AliTriggerAnalysis() :
90dc86e9 53 fSPDGFOThreshold(2),
733f0542 54 fSPDGFOEfficiency(0),
61899827 55 fV0TimeOffset(0),
97fa3cbc 56 fV0AdcThr(0),
57 fV0HwAdcThr(2.5),
58 fV0HwWinLow(61.5),
59 fV0HwWinHigh(86.5),
7c55ebd9 60 fZDCCutRefSum(-568.5),
61 fZDCCutRefDelta(-2.1),
62 fZDCCutSigmaSum(3.25),
63 fZDCCutSigmaDelta(2.25),
d6305a15 64 fZDCCutRefSumCorr(-65.5),
65 fZDCCutRefDeltaCorr(-2.1),
66 fZDCCutSigmaSumCorr(6.0),
67 fZDCCutSigmaDeltaCorr(1.2),
b68d0b5e 68 fZDCCutZNATimeCorrMin(0.0),
69 fZDCCutZNATimeCorrMax(2.0),
70 fZDCCutZNCTimeCorrMin(0.0),
71 fZDCCutZNCTimeCorrMax(5.0),
1ea7a921 72 fASPDCvsTCut(65),
73 fBSPDCvsTCut(4),
b68d0b5e 74 fTRDptHSE(3.),
75 fTRDpidHSE(144),
76 fTRDptHQU(2.),
77 fTRDpidHQU(164.),
78 fTRDptHEE(3.),
79 fTRDpidHEE(144),
80 fTRDminSectorHEE(6),
81 fTRDmaxSectorHEE(8),
82 fTRDptHJT(3.),
83 fTRDnHJT(3),
4011b280 84 fDoFMD(kTRUE),
90dc86e9 85 fFMDLowCut(0.2),
86 fFMDHitCut(0.5),
90dc86e9 87 fHistBitsSPD(0),
c2fff146 88 fHistFiredBitsSPD(0),
1ea7a921 89 fHistSPDClsVsTrk(0),
907972ff 90 fHistV0A(0),
61899827 91 fHistV0C(0),
907972ff 92 fHistZDC(0),
ce08cb1f 93 fHistTDCZDC(0),
102cfd12 94 fHistTimeZDC(0),
fcb18b05 95 fHistTimeCorrZDC(0),
907972ff 96 fHistFMDA(0),
97 fHistFMDC(0),
98 fHistFMDSingle(0),
c01a136b 99 fHistFMDSum(0),
559b5ed7 100 fHistT0(0),
a2ce3799 101 fTriggerClasses(0),
449618cd 102 fMC(kFALSE),
52f3b98d 103 fEsdTrackCuts(0),
104 fTPCOnly(kFALSE)
ff8c4f30 105{
61899827 106 // constructor
107}
108
109AliTriggerAnalysis::~AliTriggerAnalysis()
110{
111 // destructor
112
113 if (fHistBitsSPD)
114 {
115 delete fHistBitsSPD;
116 fHistBitsSPD = 0;
117 }
118
119 if (fHistFiredBitsSPD)
120 {
121 delete fHistFiredBitsSPD;
122 fHistFiredBitsSPD = 0;
123 }
124
1ea7a921 125 if (fHistSPDClsVsTrk)
126 {
127 delete fHistSPDClsVsTrk;
128 fHistSPDClsVsTrk = 0;
129 }
130
61899827 131 if (fHistV0A)
132 {
133 delete fHistV0A;
134 fHistV0A = 0;
135 }
136
137 if (fHistV0C)
138 {
139 delete fHistV0C;
140 fHistV0C = 0;
141 }
142
143 if (fHistZDC)
144 {
145 delete fHistZDC;
146 fHistZDC = 0;
147 }
ce08cb1f 148 if (fHistTDCZDC)
149 {
102cfd12 150 delete fHistTDCZDC;
151 fHistTDCZDC = 0;
152 }
153 if (fHistTimeZDC)
154 {
155 delete fHistTimeZDC;
156 fHistTimeZDC = 0;
ce08cb1f 157 }
fcb18b05 158 if (fHistTimeCorrZDC)
159 {
160 delete fHistTimeCorrZDC;
161 fHistTimeCorrZDC = 0;
162 }
61899827 163
164 if (fHistFMDA)
165 {
166 delete fHistFMDA;
167 fHistFMDA = 0;
168 }
169
170 if (fHistFMDC)
171 {
172 delete fHistFMDC;
173 fHistFMDC = 0;
174 }
175
176 if (fHistFMDSingle)
177 {
178 delete fHistFMDSingle;
179 fHistFMDSingle = 0;
180 }
181
182 if (fHistFMDSum)
183 {
184 delete fHistFMDSum;
185 fHistFMDSum = 0;
186 }
187
559b5ed7 188 if (fHistT0)
189 {
190 delete fHistT0;
191 fHistT0 = 0;
192 }
193
61899827 194 if (fTriggerClasses)
195 {
35fb1e58 196 fTriggerClasses->DeleteAll();
61899827 197 delete fTriggerClasses;
198 fTriggerClasses = 0;
199 }
449618cd 200
201 if (fEsdTrackCuts){
202 delete fEsdTrackCuts;
203 fEsdTrackCuts =0;
204 }
ff8c4f30 205}
206
891c67bd 207void AliTriggerAnalysis::EnableHistograms(Bool_t isLowFlux)
907972ff 208{
891c67bd 209 // creates the monitoring histograms (dynamical range of histograms can be adapted for pp and pPb via isLowFlux flag)
907972ff 210
296dd262 211 // do not add this hists to the directory
212 Bool_t oldStatus = TH1::AddDirectoryStatus();
213 TH1::AddDirectory(kFALSE);
891c67bd 214 //
215 Int_t nBins = isLowFlux ? 600 : 1202;
216 fHistBitsSPD = new TH2F("fHistBitsSPD", "SPD GFO;number of fired chips (offline);number of fired chips (hardware)", nBins, -1.5, -1.5 + nBins, nBins, -1.5, -1.5+nBins);
217 //
c01a136b 218 fHistFiredBitsSPD = new TH1F("fHistFiredBitsSPD", "SPD GFO Hardware;chip number;events", 1200, -0.5, 1199.5);
891c67bd 219 //
220 Int_t nBinsX = isLowFlux ? 100 : 300;
221 Int_t nBinsY = isLowFlux ? 500 : 1000;
222 Float_t xMax = isLowFlux ? 400 : 2999.5;
223 Float_t yMax = isLowFlux ? 4000 : 9999.5;
224 fHistSPDClsVsTrk = new TH2F("fHistSPDClsVsTrk", "SPD Clusters vs Tracklets", nBinsX, -0.5, xMax, nBinsY, -0.5, yMax);
225 //
988dd3a4 226 fHistV0A = new TH1F("fHistV0A", "V0A;leading time (ns);events", 400, -100, 100);
227 fHistV0C = new TH1F("fHistV0C", "V0C;leading time (ns);events", 400, -100, 100);
907972ff 228 fHistZDC = new TH1F("fHistZDC", "ZDC;trigger bits;events", 8, -1.5, 6.5);
ce08cb1f 229 fHistTDCZDC = new TH1F("fHistTDCZDC", "ZDC;TDC bits;events", 32, -0.5, 32-0.5);
102cfd12 230 fHistTimeZDC = new TH2F("fHistTimeZDC", "ZDC;TDC timing A+C vs C-A; events", 120,-30,30,120,-600,-540);
8195aa81 231 fHistTimeCorrZDC = new TH2F("fHistTimeCorrZDC", "ZDC;Corrected TDC timing A+C vs C-A; events", 120,-30,30,260,-100,30);
907972ff 232
233 // TODO check limits
234 fHistFMDA = new TH1F("fHistFMDA", "FMDA;combinations above threshold;events", 102, -1.5, 100.5);
235 fHistFMDC = new TH1F("fHistFMDC", "FMDC;combinations above threshold;events", 102, -1.5, 100.5);
236 fHistFMDSingle = new TH1F("fHistFMDSingle", "FMD single;multiplicity value;counts", 1000, 0, 10);
237 fHistFMDSum = new TH1F("fHistFMDSum", "FMD sum;multiplicity value;counts", 1000, 0, 10);
559b5ed7 238 fHistT0 = new TH1F("fHistT0", "T0;time (ns);events", 100, -25, 25);
c01a136b 239
240 fTriggerClasses = new TMap;
61899827 241 fTriggerClasses->SetOwner();
296dd262 242
243 TH1::AddDirectory(oldStatus);
907972ff 244}
245
70fdd197 246//____________________________________________________________________
247const char* AliTriggerAnalysis::GetTriggerName(Trigger trigger)
248{
249 // returns the name of the requested trigger
250 // the returned string will only be valid until the next call to this function [not thread-safe]
251
252 static TString str;
253
254 UInt_t triggerNoFlags = (UInt_t) trigger % (UInt_t) kStartOfFlags;
255
256 switch (triggerNoFlags)
257 {
258 case kAcceptAll : str = "ACCEPT ALL (bypass!)"; break;
259 case kMB1 : str = "MB1"; break;
260 case kMB2 : str = "MB2"; break;
261 case kMB3 : str = "MB3"; break;
262 case kSPDGFO : str = "SPD GFO"; break;
c2fff146 263 case kSPDGFOBits : str = "SPD GFO Bits"; break;
7c55ebd9 264 case kSPDGFOL0 : str = "SPD GFO L0 (first layer)"; break;
265 case kSPDGFOL1 : str = "SPD GFO L1 (second layer)"; break;
1ea7a921 266 case kSPDClsVsTrkBG : str = "Cluster vs Tracklets"; break;
61899827 267 case kV0A : str = "V0 A BB"; break;
268 case kV0C : str = "V0 C BB"; break;
733f0542 269 case kV0OR : str = "V0 OR BB"; break;
270 case kV0AND : str = "V0 AND BB"; break;
61899827 271 case kV0ABG : str = "V0 A BG"; break;
272 case kV0CBG : str = "V0 C BG"; break;
70fdd197 273 case kZDC : str = "ZDC"; break;
274 case kZDCA : str = "ZDC A"; break;
275 case kZDCC : str = "ZDC C"; break;
0d12ffff 276 case kZNA : str = "ZN A"; break;
277 case kZNC : str = "ZN C"; break;
278 case kZNABG : str = "ZN A BG"; break;
279 case kZNCBG : str = "ZN C BG"; break;
70fdd197 280 case kFMDA : str = "FMD A"; break;
281 case kFMDC : str = "FMD C"; break;
282 case kFPANY : str = "SPD GFO | V0 | ZDC | FMD"; break;
733f0542 283 case kNSD1 : str = "NSD1"; break;
97fa3cbc 284 case kMB1Prime: str = "MB1prime"; break;
7c55ebd9 285 case kZDCTDCA : str = "ZDC TDC A"; break;
286 case kZDCTDCC : str = "ZDC TDC C"; break;
287 case kZDCTime : str = "ZDC Time Cut"; break;
889c27e3 288 case kCentral : str = "V0 Central"; break;
289 case kSemiCentral : str = "V0 Semi-central"; break;
8d5a14d6 290 case kEMCAL : str = "EMCAL"; break;
b68d0b5e 291 case kTRDHCO : str = "TRD cosmics"; break;
292 case kTRDHJT : str = "TRD Jet"; break;
293 case kTRDHSE : str = "TRD Single Electron"; break;
294 case kTRDHQU : str = "TRD Quarkonia"; break;
295 case kTRDHEE : str = "TRD Dielectron"; break;
70fdd197 296 default: str = ""; break;
297 }
298
299 if (trigger & kOfflineFlag)
300 str += " OFFLINE";
301
225667ea 302 if (trigger & kOneParticle)
303 str += " OneParticle";
304
449618cd 305 if (trigger & kOneTrack)
306 str += " OneTrack";
307
70fdd197 308 return str;
309}
310
61899827 311Bool_t AliTriggerAnalysis::IsTriggerFired(const AliESDEvent* aEsd, Trigger trigger)
70fdd197 312{
313 // checks if an event has been triggered
314
315 if (trigger & kOfflineFlag)
316 return IsOfflineTriggerFired(aEsd, trigger);
317
318 return IsTriggerBitFired(aEsd, trigger);
319}
320
321Bool_t AliTriggerAnalysis::IsTriggerBitFired(const AliESDEvent* aEsd, Trigger trigger) const
322{
323 // checks if an event is fired using the trigger bits
324
325 return IsTriggerBitFired(aEsd->GetTriggerMask(), trigger);
326}
327
328Bool_t AliTriggerAnalysis::IsTriggerBitFired(ULong64_t triggerMask, Trigger trigger) const
329{
330 // checks if an event is fired using the trigger bits
331 //
332 // this function needs the branch TriggerMask in the ESD
333
334 // definitions from p-p.cfg
335 ULong64_t spdFO = (1 << 14);
336 ULong64_t v0left = (1 << 10);
337 ULong64_t v0right = (1 << 11);
338
339 switch (trigger)
340 {
341 case kAcceptAll:
342 {
343 return kTRUE;
344 break;
345 }
346 case kMB1:
347 {
348 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
349 return kTRUE;
350 break;
351 }
352 case kMB2:
353 {
354 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
355 return kTRUE;
356 break;
357 }
358 case kMB3:
359 {
360 if (triggerMask & spdFO && (triggerMask & v0left) && (triggerMask & v0right))
361 return kTRUE;
362 break;
363 }
364 case kSPDGFO:
365 {
366 if (triggerMask & spdFO)
367 return kTRUE;
368 break;
369 }
370 default:
371 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
372 break;
373 }
374
375 return kFALSE;
376}
377
378Bool_t AliTriggerAnalysis::IsTriggerBitFired(const AliESDEvent* aEsd, ULong64_t tclass) const
379{
380 // Checks if corresponding bit in mask is on
381
382 ULong64_t trigmask = aEsd->GetTriggerMask();
383 return (trigmask & (1ull << (tclass-1)));
384}
7c55ebd9 385
386Int_t AliTriggerAnalysis::EvaluateTrigger(const AliESDEvent* aEsd, Trigger trigger)
387{
388 // evaluates a given trigger "offline"
389 // trigger combinations are not supported, for that see IsOfflineTriggerFired
390
391 UInt_t triggerNoFlags = (UInt_t) trigger % (UInt_t) kStartOfFlags;
392 Bool_t offline = kFALSE;
393 if (trigger & kOfflineFlag)
394 offline = kTRUE;
395
396 Int_t decision = 0;
397 switch (triggerNoFlags)
398 {
399 case kSPDGFO:
400 {
401 decision = SPDFiredChips(aEsd, (offline) ? 0 : 1);
402 break;
403 }
404 case kSPDGFOL0:
405 {
406 decision = SPDFiredChips(aEsd, (offline) ? 0 : 1, kFALSE, 1);
407 break;
408 }
409 case kSPDGFOL1:
410 {
411 decision = SPDFiredChips(aEsd, (offline) ? 0 : 1, kFALSE, 2);
412 break;
1ea7a921 413 }
414 case kSPDClsVsTrkBG:
415 {
416 if(!offline)
417 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
418 decision = IsSPDClusterVsTrackletBG(aEsd);
419 break;
7c55ebd9 420 }
421 case kV0A:
422 {
423 if (V0Trigger(aEsd, kASide, !offline) == kV0BB)
424 decision = 1;
425 break;
426 }
427 case kV0C:
428 {
429 if (V0Trigger(aEsd, kCSide, !offline) == kV0BB)
430 decision = 1;
431 break;
432 }
433 case kV0ABG:
434 {
435 if (V0Trigger(aEsd, kASide, !offline) == kV0BG)
436 decision = 1;
437 break;
438 }
439 case kV0CBG:
440 {
441 if (V0Trigger(aEsd, kCSide, !offline) == kV0BG)
442 decision = 1;
443 break;
444 }
559b5ed7 445 case kT0:
446 {
447 if (T0Trigger(aEsd, !offline) == kT0BB)
448 decision = 1;
449 break;
450 }
451 case kT0BG:
452 {
453 if (!offline)
454 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
455 if (T0Trigger(aEsd, !offline) == kT0DecBG)
456 decision = 1;
457 break;
458 }
459 case kT0Pileup:
460 {
461 if (!offline)
462 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
463 if (T0Trigger(aEsd, !offline) == kT0DecPileup)
464 decision = 1;
465 break;
466 }
7c55ebd9 467 case kZDCA:
468 {
469 if (!offline)
470 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
471 if (ZDCTrigger(aEsd, kASide))
472 decision = 1;
473 break;
474 }
475 case kZDCC:
476 {
477 if (!offline)
478 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
479 if (ZDCTrigger(aEsd, kCSide))
480 decision = 1;
481 break;
482 }
483 case kZDCTDCA:
484 {
485 if (!offline)
486 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
487 if (ZDCTDCTrigger(aEsd, kASide))
488 decision = 1;
489 break;
490 }
491 case kZDCTDCC:
492 {
493 if (!offline)
494 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
495 if (ZDCTDCTrigger(aEsd, kCSide))
496 decision = 1;
497 break;
498 }
499 case kZDCTime:
500 {
501 if (!offline)
502 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
503 if (ZDCTimeTrigger(aEsd))
504 decision = 1;
505 break;
506 }
0d12ffff 507 case kZNA:
508 {
509 if (!offline)
510 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
511 if (ZDCTDCTrigger(aEsd,kASide,kTRUE,kFALSE,kFALSE))
512 decision = 1;
513 break;
514 }
515 case kZNC:
516 {
517 if (!offline)
518 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
519 if (ZDCTDCTrigger(aEsd,kCSide,kTRUE,kFALSE,kFALSE))
520 decision = 1;
521 break;
522 }
523 case kZNABG:
524 {
525 if (!offline)
526 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
527 if (ZDCTimeBGTrigger(aEsd,kASide))
528 decision = 1;
529 break;
530 }
531 case kZNCBG:
532 {
533 if (!offline)
534 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
535 if (ZDCTimeBGTrigger(aEsd,kCSide))
536 decision = 1;
537 break;
538 }
7c55ebd9 539 case kFMDA:
540 {
541 if (!offline)
542 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
543 if (FMDTrigger(aEsd, kASide))
544 decision = 1;
545 break;
546 }
547 case kFMDC:
548 {
549 if (!offline)
550 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
551 if (FMDTrigger(aEsd, kCSide))
552 decision = 1;
553 break;
554 }
555 case kCTPV0A:
556 {
557 if (offline)
558 AliFatal(Form("Offline trigger not available for trigger %d", triggerNoFlags));
559 if (IsL0InputFired(aEsd, 2))
560 decision = 1;
561 break;
562 }
563 case kCTPV0C:
564 {
565 if (offline)
566 AliFatal(Form("Offline trigger not available for trigger %d", triggerNoFlags));
567 if (IsL0InputFired(aEsd, 3))
568 decision = 1;
569 break;
570 }
571 case kTPCLaserWarmUp:
572 {
573 if (!offline)
574 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
575 return IsLaserWarmUpTPCEvent(aEsd);
576 }
b68d0b5e 577 case kTPCHVdip:
578 {
579 if (!offline)
580 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
581 return IsHVdipTPCEvent(aEsd);
582 }
625e557d 583 case kIncompleteEvent:
584 {
585 if (!offline)
586 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
587 return IsIncompleteEvent(aEsd);
588 }
889c27e3 589 case kCentral:
590 {
591 if (offline)
592 AliFatal(Form("Offline trigger not available for trigger %d - use centrality selection", triggerNoFlags));
593 if (aEsd->GetVZEROData()) {
594 if (aEsd->GetVZEROData()->TestBit(AliESDVZERO::kTriggerChargeBitsFilled)) {
595 if (aEsd->GetVZEROData()->GetTriggerBits() & (1<<AliESDVZERO::kCTA2andCTC2))
596 decision = kTRUE;
597 }
598 else
599 AliWarning("V0 centrality trigger bits were not filled!");
600 }
601 break;
602 }
603 case kSemiCentral:
604 {
605 if (offline)
606 AliFatal(Form("Offline trigger not available for trigger %d - use centrality selection", triggerNoFlags));
607 if (aEsd->GetVZEROData()) {
608 if (aEsd->GetVZEROData()->TestBit(AliESDVZERO::kTriggerChargeBitsFilled)) {
609 if (aEsd->GetVZEROData()->GetTriggerBits() & (1<<AliESDVZERO::kCTA1andCTC1))
610 decision = kTRUE;
611 }
612 else
613 AliWarning("V0 centrality trigger bits were not filled!");
614 }
615 break;
616 }
8d5a14d6 617 case kEMCAL:
618 {
619 if(!offline)
620 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
621 if (EMCALCellsTrigger(aEsd))
622 decision = kTRUE;
623 break;
624 }
b68d0b5e 625 case kTRDHCO:
626 {
627 if(!offline)
628 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
629 if(TRDTrigger(aEsd,kTRDHCO))
630 decision = kTRUE;
631 break;
632 }
633 case kTRDHJT:
634 {
635 if(!offline)
636 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
637 if(TRDTrigger(aEsd,kTRDHJT))
638 decision = kTRUE;
639 break;
640 }
641 case kTRDHSE:
642 {
643 if(!offline)
644 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
645 if(TRDTrigger(aEsd,kTRDHSE))
646 decision = kTRUE;
647 break;
648 }
649 case kTRDHQU:
650 {
651 if(!offline)
652 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
653 if(TRDTrigger(aEsd,kTRDHQU))
654 decision = kTRUE;
655 break;
656 }
657 case kTRDHEE:
658 {
659 if(!offline)
660 AliFatal(Form("Online trigger not available for trigger %d", triggerNoFlags));
661 if(TRDTrigger(aEsd,kTRDHEE))
662 decision = kTRUE;
663 break;
664 }
7c55ebd9 665 default:
666 {
667 AliFatal(Form("Trigger type %d not implemented", triggerNoFlags));
668 }
669 }
670
671 return decision;
672}
673
674Bool_t AliTriggerAnalysis::IsLaserWarmUpTPCEvent(const AliESDEvent* esd)
675{
676 //
677 // This function flags noisy TPC events which can happen during laser warm-up.
678 //
679
680 Int_t trackCounter = 0;
681 for (Int_t i=0; i<esd->GetNumberOfTracks(); ++i)
682 {
683 AliESDtrack *track = esd->GetTrack(i);
684 if (!track)
685 continue;
686
687 if (track->GetTPCNcls() < 30) continue;
7c55ebd9 688 if (TMath::Abs(track->Eta()) > 0.005) continue;
689 if (track->Pt() < 4) continue;
690 if (track->GetKinkIndex(0) > 0) continue;
691
692 UInt_t status = track->GetStatus();
9eb74f86 693 if ((status&AliESDtrack::kITSrefit)==AliESDtrack::kITSrefit) continue; // explicitly ask for tracks without ITS refit
694 if ((status&AliESDtrack::kTPCrefit)!=AliESDtrack::kTPCrefit) continue;
7c55ebd9 695
696 if (track->GetTPCsignal() > 10) continue; // explicitly ask for tracks without dE/dx
697
7c55ebd9 698 trackCounter++;
699 }
700 if (trackCounter > 15)
701 return kTRUE;
702 return kFALSE;
703}
70fdd197 704
b68d0b5e 705Bool_t AliTriggerAnalysis::IsHVdipTPCEvent(const AliESDEvent* esd) {
706 //
707 // This function flags events in which the TPC chamber HV is not at its nominal value
708 //
0f944a55 709 if (fMC) return kFALSE; // there are no dip events in MC
b68d0b5e 710 if (!esd->IsDetectorOn(AliDAQ::kTPC)) return kTRUE;
711 return kFALSE;
712
713}
714
625e557d 715Bool_t AliTriggerAnalysis::IsIncompleteEvent(const AliESDEvent* esd)
716{
717 //
718 // Check whether the event is incomplete
719 // (due to DAQ-HLT issues, it could be only part of the event was saved)
720 //
5cd1876a 721 if (fMC) return kFALSE; // there are no incomplete events on MC
625e557d 722 if ((esd->GetEventType() == 7) &&
723 (esd->GetDAQDetectorPattern() & (1<<4)) &&
724 !(esd->GetDAQAttributes() & (1<<7))) return kTRUE;
725
726 return kFALSE;
727}
728
b68d0b5e 729
61899827 730Bool_t AliTriggerAnalysis::IsOfflineTriggerFired(const AliESDEvent* aEsd, Trigger trigger)
ff8c4f30 731{
732 // checks if an event has been triggered "offline"
733
70fdd197 734 UInt_t triggerNoFlags = (UInt_t) trigger % (UInt_t) kStartOfFlags;
ff8c4f30 735
225667ea 736 Bool_t decision = kFALSE;
ff8c4f30 737 switch (triggerNoFlags)
738 {
70fdd197 739 case kAcceptAll:
ff8c4f30 740 {
225667ea 741 decision = kTRUE;
ff8c4f30 742 break;
743 }
70fdd197 744 case kMB1:
ff8c4f30 745 {
97fa3cbc 746 if (SPDGFOTrigger(aEsd, 0) || V0Trigger(aEsd, kASide, kFALSE) == kV0BB || V0Trigger(aEsd, kCSide, kFALSE) == kV0BB)
225667ea 747 decision = kTRUE;
ff8c4f30 748 break;
749 }
70fdd197 750 case kMB2:
ff8c4f30 751 {
97fa3cbc 752 if (SPDGFOTrigger(aEsd, 0) && (V0Trigger(aEsd, kASide, kFALSE) == kV0BB || V0Trigger(aEsd, kCSide, kFALSE) == kV0BB))
225667ea 753 decision = kTRUE;
ff8c4f30 754 break;
755 }
70fdd197 756 case kMB3:
ff8c4f30 757 {
97fa3cbc 758 if (SPDGFOTrigger(aEsd, 0) && V0Trigger(aEsd, kASide, kFALSE) == kV0BB && V0Trigger(aEsd, kCSide, kFALSE) == kV0BB)
225667ea 759 decision = kTRUE;
ff8c4f30 760 break;
761 }
70fdd197 762 case kSPDGFO:
ff8c4f30 763 {
c2fff146 764 if (SPDGFOTrigger(aEsd, 0))
225667ea 765 decision = kTRUE;
c2fff146 766 break;
767 }
768 case kSPDGFOBits:
769 {
770 if (SPDGFOTrigger(aEsd, 1))
225667ea 771 decision = kTRUE;
ff8c4f30 772 break;
773 }
70fdd197 774 case kV0A:
ff8c4f30 775 {
97fa3cbc 776 if (V0Trigger(aEsd, kASide, kFALSE) == kV0BB)
225667ea 777 decision = kTRUE;
ff8c4f30 778 break;
779 }
70fdd197 780 case kV0C:
ff8c4f30 781 {
97fa3cbc 782 if (V0Trigger(aEsd, kCSide, kFALSE) == kV0BB)
225667ea 783 decision = kTRUE;
ff8c4f30 784 break;
785 }
733f0542 786 case kV0OR:
787 {
97fa3cbc 788 if (V0Trigger(aEsd, kASide, kFALSE) == kV0BB || V0Trigger(aEsd, kCSide, kFALSE) == kV0BB)
225667ea 789 decision = kTRUE;
733f0542 790 break;
791 }
792 case kV0AND:
793 {
97fa3cbc 794 if (V0Trigger(aEsd, kASide, kFALSE) == kV0BB && V0Trigger(aEsd, kCSide, kFALSE) == kV0BB)
225667ea 795 decision = kTRUE;
733f0542 796 break;
797 }
61899827 798 case kV0ABG:
799 {
97fa3cbc 800 if (V0Trigger(aEsd, kASide, kFALSE) == kV0BG)
225667ea 801 decision = kTRUE;
61899827 802 break;
803 }
804 case kV0CBG:
805 {
97fa3cbc 806 if (V0Trigger(aEsd, kCSide, kFALSE) == kV0BG)
225667ea 807 decision = kTRUE;
61899827 808 break;
809 }
70fdd197 810 case kZDC:
c8d3e441 811 {
812 if (ZDCTrigger(aEsd, kASide) || ZDCTrigger(aEsd, kCentralBarrel) || ZDCTrigger(aEsd, kCSide))
225667ea 813 decision = kTRUE;
c8d3e441 814 break;
815 }
70fdd197 816 case kZDCA:
ff8c4f30 817 {
818 if (ZDCTrigger(aEsd, kASide))
225667ea 819 decision = kTRUE;
ff8c4f30 820 break;
821 }
70fdd197 822 case kZDCC:
ff8c4f30 823 {
824 if (ZDCTrigger(aEsd, kCSide))
225667ea 825 decision = kTRUE;
ff8c4f30 826 break;
827 }
0d12ffff 828 case kZNA:
829 {
830 if (ZDCTDCTrigger(aEsd,kASide,kTRUE,kFALSE,kFALSE))
831 decision = kTRUE;
832 break;
833 }
834 case kZNC:
835 {
836 if (ZDCTDCTrigger(aEsd,kCSide,kTRUE,kFALSE,kFALSE))
837 decision = kTRUE;
838 break;
839 }
840 case kZNABG:
841 {
842 if (ZDCTimeBGTrigger(aEsd,kASide))
843 decision = kTRUE;
844 break;
845 }
846 case kZNCBG:
847 {
848 if (ZDCTimeBGTrigger(aEsd,kCSide))
849 decision = kTRUE;
850 break;
851 }
70fdd197 852 case kFMDA:
7a11141c 853 {
854 if (FMDTrigger(aEsd, kASide))
225667ea 855 decision = kTRUE;
7a11141c 856 break;
857 }
70fdd197 858 case kFMDC:
7a11141c 859 {
860 if (FMDTrigger(aEsd, kCSide))
225667ea 861 decision = kTRUE;
7a11141c 862 break;
863 }
70fdd197 864 case kFPANY:
ff8c4f30 865 {
97fa3cbc 866 if (SPDGFOTrigger(aEsd, 0) || V0Trigger(aEsd, kASide, kFALSE) == kV0BB || V0Trigger(aEsd, kCSide, kFALSE) == kV0BB || ZDCTrigger(aEsd, kASide) || ZDCTrigger(aEsd, kCentralBarrel) || ZDCTrigger(aEsd, kCSide) || FMDTrigger(aEsd, kASide) || FMDTrigger(aEsd, kCSide))
225667ea 867 decision = kTRUE;
ff8c4f30 868 break;
869 }
733f0542 870 case kNSD1:
871 {
97fa3cbc 872 if (SPDFiredChips(aEsd, 0) >= 5 || (V0Trigger(aEsd, kASide, kFALSE) == kV0BB && V0Trigger(aEsd, kCSide, kFALSE) == kV0BB))
225667ea 873 decision = kTRUE;
733f0542 874 break;
875 }
97fa3cbc 876 case kMB1Prime:
877 {
878 Int_t count = 0;
879 if (SPDGFOTrigger(aEsd, 0))
880 count++;
881 if (V0Trigger(aEsd, kASide, kFALSE) == kV0BB)
882 count++;
883 if (V0Trigger(aEsd, kCSide, kFALSE) == kV0BB)
884 count++;
885
886 if (count >= 2)
225667ea 887 decision = kTRUE;
97fa3cbc 888
889 break;
890 }
8d5a14d6 891 case kEMCAL:
ff8c4f30 892 {
8d5a14d6 893 if (EMCALCellsTrigger(aEsd))
894 decision = kTRUE;
895 break;
b68d0b5e 896 }
897 case kTRDHCO:
898 {
899 if(TRDTrigger(aEsd,kTRDHCO))
900 decision = kTRUE;
901 break;
902 }
903 case kTRDHJT:
904 {
905 if(TRDTrigger(aEsd,kTRDHJT))
906 decision = kTRUE;
907 break;
908 }
909 case kTRDHSE:
910 {
911 if(TRDTrigger(aEsd,kTRDHSE))
912 decision = kTRUE;
913 break;
914 }
915 case kTRDHQU:
916 {
917 if(TRDTrigger(aEsd,kTRDHQU))
918 decision = kTRUE;
919 break;
920 }
921 case kTRDHEE:
922 {
923 if(TRDTrigger(aEsd,kTRDHEE))
924 decision = kTRUE;
925 break;
8d5a14d6 926 }
927 default:
928 {
ff8c4f30 929 AliFatal(Form("Trigger type %d not implemented", triggerNoFlags));
930 }
931 }
932
225667ea 933 // hadron-level requirement
934 if (decision && (trigger & kOneParticle))
935 {
936 decision = kFALSE;
937
938 const AliESDVertex* vertex = aEsd->GetPrimaryVertexSPD();
939 const AliMultiplicity* mult = aEsd->GetMultiplicity();
ff8c4f30 940
225667ea 941 if (mult && vertex && vertex->GetNContributors() > 0 && (!vertex->IsFromVertexerZ() || vertex->GetDispersion() < 0.02) && TMath::Abs(vertex->GetZv()) < 5.5)
942 {
943 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
944 {
945 if (TMath::Abs(mult->GetEta(i)) < 1)
946 {
947 decision = kTRUE;
948 break;
949 }
950 }
951 }
952 }
953
449618cd 954 // hadron level definition for TPC tracks
955
956 if (decision && (trigger & kOneTrack))
957 {
958 decision = kFALSE;
b256fde9 959 const AliESDVertex* vertex =0x0;
960 vertex = aEsd->GetPrimaryVertexTracks();
961 if (!vertex || vertex->GetNContributors() <= 0)
962 {
963 vertex = aEsd->GetPrimaryVertexSPD();
964 }
449618cd 965 Float_t ptmin, ptmax;
966 fEsdTrackCuts->GetPtRange(ptmin,ptmax);
967 AliDebug(3, Form("ptmin = %f, ptmax = %f\n",ptmin, ptmax));
968
969 if (vertex && vertex->GetNContributors() > 0 && (!vertex->IsFromVertexerZ() || vertex->GetDispersion() < 0.02) && TMath::Abs(vertex->GetZv()) < 10.) {
970 AliDebug(3,Form("Check on the vertex passed\n"));
971 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); ++i){
52f3b98d 972 if (fTPCOnly == kFALSE){
973 if (fEsdTrackCuts->AcceptTrack(aEsd->GetTrack(i))){
974 AliDebug(2, Form("pt of track = %f --> check passed\n",aEsd->GetTrack(i)->Pt()));
975 decision = kTRUE;
976 break;
977 }
978 }
979 else {
980 // TPC only tracks
981 AliESDtrack *tpcTrack = fEsdTrackCuts->GetTPCOnlyTrack((AliESDEvent*)aEsd, i);
982 if (!tpcTrack){
983 AliDebug(3,Form("track %d is NOT a TPC track",i));
984 continue;
985 }
986 else{
987 AliDebug(3,Form("track %d IS a TPC track",i));
988 if (!(fEsdTrackCuts->AcceptTrack(tpcTrack))) {
989 AliDebug(2, Form("TPC track %d NOT ACCEPTED, pt = %f, eta = %f",i,tpcTrack->Pt(), tpcTrack->Eta()));
990 delete tpcTrack; tpcTrack = 0x0;
991 continue;
992 } // end if the TPC track is not accepted
993 else{
994 AliDebug(2, Form("TPC track %d ACCEPTED, pt = %f, eta = %f",i,tpcTrack->Pt(), tpcTrack->Eta()));
995 decision = kTRUE;
996 delete tpcTrack; tpcTrack = 0x0;
997 break;
998 } // end if the TPC track is accepted
999 } // end if it is a TPC track
1000 } // end if you are looking at TPC only tracks
1001 } // end loop on tracks
1002 } // end check on vertex
449618cd 1003 else{
1004 AliDebug(4,Form("Check on the vertex not passed\n"));
1005 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); ++i){
1006 if (fEsdTrackCuts->AcceptTrack(aEsd->GetTrack(i))){
1007 AliDebug(4,Form("pt of track = %f --> check would be passed if the vertex was ok\n",aEsd->GetTrack(i)->Pt()));
1008 break;
1009 }
1010 }
1011 }
1012 if (!decision) AliDebug(3,("Check for kOneTrack NOT passed\n"));
1013 }
1014
225667ea 1015 return decision;
1016}
70fdd197 1017
1018Bool_t AliTriggerAnalysis::IsTriggerClassFired(const AliESDEvent* aEsd, const Char_t* tclass) const
1019{
1020 // tclass is logical function of inputs, e.g. 01 && 02 || 03 && 11 && 21
1021 // = L0 inp 1 && L0 inp 2 || L0 inp 3 && L1 inp 1 && L2 inp 1
1022 // NO brackets in logical function !
1023 // Spaces between operators and inputs.
1024 // Not all logical functions are available in CTP=
1025 // =any function of first 4 inputs; 'AND' of other inputs, check not done
1026 // This method will be replaced/complemened by similar one
1027 // which works withh class and inputs names as in CTP cfg file
1028
1029 TString TClass(tclass);
1030 TObjArray* tcltokens = TClass.Tokenize(" ");
1031 Char_t level=((TObjString*)tcltokens->At(0))->String()[0];
1032 UInt_t input=atoi((((TObjString*)tcltokens->At(0))->String()).Remove(0));
1033 Bool_t tcl = IsInputFired(aEsd,level,input);
1034
1035 for (Int_t i=1;i<tcltokens->GetEntriesFast();i=i+2) {
1036 level=((TObjString*)tcltokens->At(i+1))->String()[0];
1037 input=atoi((((TObjString*)tcltokens->At(i+1))->String()).Remove(0));
1038 Bool_t inpnext = IsInputFired(aEsd,level,input);
1039 Char_t op =((TObjString*)tcltokens->At(i))->String()[0];
1040 if (op == '&') tcl=tcl && inpnext;
1041 else if (op == '|') tcl =tcl || inpnext;
1042 else {
1043 AliError(Form("Syntax error in %s", tclass));
8dec6e35 1044 delete tcltokens;
1045 tcltokens = 0;
1046 // tcltokens->Delete();
70fdd197 1047 return kFALSE;
1048 }
1049 }
8dec6e35 1050 delete tcltokens;
1051 tcltokens = 0;
1052 // tcltokens->Delete();
70fdd197 1053 return tcl;
1054}
1055
1056Bool_t AliTriggerAnalysis::IsInputFired(const AliESDEvent* aEsd, Char_t level, UInt_t input) const
1057{
1058 // Checks trigger input of any level
1059
1060 switch (level)
1061 {
1062 case '0': return IsL0InputFired(aEsd,input);
1063 case '1': return IsL1InputFired(aEsd,input);
1064 case '2': return IsL2InputFired(aEsd,input);
1065 default:
1066 AliError(Form("Wrong level %i",level));
1067 return kFALSE;
1068 }
1069}
1070
1071Bool_t AliTriggerAnalysis::IsL0InputFired(const AliESDEvent* aEsd, UInt_t input) const
1072{
1073 // Checks if corresponding bit in mask is on
1074
1075 UInt_t inpmask = aEsd->GetHeader()->GetL0TriggerInputs();
1076 return (inpmask & (1<<(input-1)));
1077}
1078
1079Bool_t AliTriggerAnalysis::IsL1InputFired(const AliESDEvent* aEsd, UInt_t input) const
1080{
1081 // Checks if corresponding bit in mask is on
1082
1083 UInt_t inpmask = aEsd->GetHeader()->GetL1TriggerInputs();
1084 return (inpmask & (1<<(input-1)));
1085}
1086
1087Bool_t AliTriggerAnalysis::IsL2InputFired(const AliESDEvent* aEsd, UInt_t input) const
1088{
1089 // Checks if corresponding bit in mask is on
1090
1091 UInt_t inpmask = aEsd->GetHeader()->GetL2TriggerInputs();
1092 return (inpmask & (1<<(input-1)));
1093}
1094
1095void AliTriggerAnalysis::FillHistograms(const AliESDEvent* aEsd)
ff8c4f30 1096{
907972ff 1097 // fills the histograms with the info from the ESD
1098
c2fff146 1099 fHistBitsSPD->Fill(SPDFiredChips(aEsd, 0), SPDFiredChips(aEsd, 1, kTRUE));
907972ff 1100
97fa3cbc 1101 V0Trigger(aEsd, kASide, kFALSE, kTRUE);
1102 V0Trigger(aEsd, kCSide, kFALSE, kTRUE);
559b5ed7 1103 T0Trigger(aEsd, kFALSE, kTRUE);
ce08cb1f 1104 ZDCTDCTrigger(aEsd,kASide,kFALSE,kFALSE,kTRUE);
102cfd12 1105 ZDCTimeTrigger(aEsd,kTRUE);
1ea7a921 1106 IsSPDClusterVsTrackletBG(aEsd, kTRUE);
ce08cb1f 1107
907972ff 1108 AliESDZDC* zdcData = aEsd->GetESDZDC();
1109 if (zdcData)
1110 {
1111 UInt_t quality = zdcData->GetESDQuality();
1112
1113 // from Nora's presentation, general first physics meeting 16.10.09
1114 static UInt_t zpc = 0x20;
1115 static UInt_t znc = 0x10;
1116 static UInt_t zem1 = 0x08;
1117 static UInt_t zem2 = 0x04;
1118 static UInt_t zpa = 0x02;
1119 static UInt_t zna = 0x01;
1120
15695e03 1121 fHistZDC->Fill(1, (quality & zna) ? 1 : 0);
1122 fHistZDC->Fill(2, (quality & zpa) ? 1 : 0);
1123 fHistZDC->Fill(3, (quality & zem2) ? 1 : 0);
1124 fHistZDC->Fill(4, (quality & zem1) ? 1 : 0);
1125 fHistZDC->Fill(5, (quality & znc) ? 1 : 0);
1126 fHistZDC->Fill(6, (quality & zpc) ? 1 : 0);
907972ff 1127 }
1128 else
1129 {
1130 fHistZDC->Fill(-1);
1131 AliError("AliESDZDC not available");
1132 }
1133
4011b280 1134 if (fDoFMD) {
1135 fHistFMDA->Fill(FMDHitCombinations(aEsd, kASide, kTRUE));
1136 fHistFMDC->Fill(FMDHitCombinations(aEsd, kCSide, kTRUE));
1137 }
907972ff 1138}
c01a136b 1139
1140void AliTriggerAnalysis::FillTriggerClasses(const AliESDEvent* aEsd)
1141{
1142 // fills trigger classes map
1143
1144 TParameter<Long64_t>* count = dynamic_cast<TParameter<Long64_t>*> (fTriggerClasses->GetValue(aEsd->GetFiredTriggerClasses().Data()));
1145 if (!count)
1146 {
1147 count = new TParameter<Long64_t>(aEsd->GetFiredTriggerClasses(), 0);
1148 fTriggerClasses->Add(new TObjString(aEsd->GetFiredTriggerClasses().Data()), count);
1149 }
1150 count->SetVal(count->GetVal() + 1);
c01a136b 1151}
907972ff 1152
85c71ba7 1153Int_t AliTriggerAnalysis::SSDClusters(const AliESDEvent* aEsd)
1154{
1155 // returns the number of clusters in the SSD
1156 const AliMultiplicity* mult = aEsd->GetMultiplicity();
1157 Int_t clusters = mult->GetNumberOfITSClusters(4)+mult->GetNumberOfITSClusters(5);
1158 return clusters;
1159}
1160
1161
29533987 1162Int_t AliTriggerAnalysis::SPDFiredChips(const AliESDEvent* aEsd, Int_t origin, Bool_t fillHists, Int_t layer)
907972ff 1163{
1164 // returns the number of fired chips in the SPD
90dc86e9 1165 //
1166 // origin = 0 --> aEsd->GetMultiplicity()->GetNumberOfFiredChips() (filled from clusters)
1167 // origin = 1 --> aEsd->GetMultiplicity()->TestFastOrFiredChips() (from hardware bits)
29533987 1168 // layer = 0 --> both layers
1169 // layer = 1 --> inner
1170 // layer = 2 --> outer
ff8c4f30 1171
ff8c4f30 1172 const AliMultiplicity* mult = aEsd->GetMultiplicity();
1173 if (!mult)
1174 {
1175 AliError("AliMultiplicity not available");
907972ff 1176 return -1;
ff8c4f30 1177 }
90dc86e9 1178
29533987 1179 if (origin == 0){
1180 if (layer == 0)
1181 return mult->GetNumberOfFiredChips(0) + mult->GetNumberOfFiredChips(1);
1182
1183 return mult->GetNumberOfFiredChips(layer-1);
1184 }
90dc86e9 1185
1186 if (origin == 1)
1187 {
1188 Int_t nChips = 0;
29533987 1189 Int_t firstChip = 0;
1190 Int_t lastChip = 1200;
1191 if(layer == 1)
1192 lastChip = 400;
1193 if(layer == 2)
1194 firstChip = 400;
1195
8dec6e35 1196 for (Int_t i=firstChip; i<lastChip; i++)
733f0542 1197 {
90dc86e9 1198 if (mult->TestFastOrFiredChips(i) == kTRUE)
c2fff146 1199 {
733f0542 1200 // efficiency simulation (if enabled)
1201 if (fSPDGFOEfficiency)
1202 {
1203 if (gRandom->Uniform() > fSPDGFOEfficiency->GetBinContent(i+1))
1204 continue;
1205 }
1206
90dc86e9 1207 nChips++;
61899827 1208 if (fillHists)
c2fff146 1209 fHistFiredBitsSPD->Fill(i);
1210 }
733f0542 1211 }
90dc86e9 1212 return nChips;
1213 }
1214
1215 return -1;
907972ff 1216}
1217
61899827 1218Bool_t AliTriggerAnalysis::SPDGFOTrigger(const AliESDEvent* aEsd, Int_t origin)
907972ff 1219{
1220 // Returns if the SPD gave a global Fast OR trigger
1221
c2fff146 1222 Int_t firedChips = SPDFiredChips(aEsd, origin);
ff8c4f30 1223
1224 if (firedChips >= fSPDGFOThreshold)
1225 return kTRUE;
1226 return kFALSE;
1227}
1228
1ea7a921 1229Bool_t AliTriggerAnalysis::IsSPDClusterVsTrackletBG(const AliESDEvent* aEsd, Bool_t fillHists){
1230 //rejects BG based on the cluster vs tracklet correlation
1231 // returns true if the event is BG
1232 const AliMultiplicity* mult = aEsd->GetMultiplicity();
1233 if (!mult){
1234 AliFatal("No multiplicity object"); // TODO: Should this be fatal?
1235 }
1236 Int_t ntracklet = mult->GetNumberOfTracklets();
1237
1238 Int_t spdClusters = 0;
1239 for(Int_t ilayer = 0; ilayer < 2; ilayer++){
1240 spdClusters += mult->GetNumberOfITSClusters(ilayer);
1241 }
1242
1243 if(fillHists) {
1244 fHistSPDClsVsTrk->Fill(ntracklet,spdClusters);
1245 }
1246
1247 Bool_t isCvsTOk = kFALSE;
1248 Float_t limit = Float_t(fASPDCvsTCut) + Float_t(ntracklet) * fBSPDCvsTCut;
1249 if (spdClusters > limit) isCvsTOk = kTRUE;
1250 else isCvsTOk = kFALSE ;
1251
1252 return isCvsTOk;
1253
1254}
1255
1256
97fa3cbc 1257AliTriggerAnalysis::V0Decision AliTriggerAnalysis::V0Trigger(const AliESDEvent* aEsd, AliceSide side, Bool_t online, Bool_t fillHists)
ff8c4f30 1258{
c01a136b 1259 // Returns the V0 trigger decision in V0A | V0C
1260 //
733f0542 1261 // Returns kV0Fake if the calculated average time is in a window where neither BB nor BG is expected.
1262 // The rate of such triggers can be used to estimate the background. Note that the rate has to be
1263 // rescaled with the size of the windows (numerical values see below in the code)
1264 //
97fa3cbc 1265 // argument 'online' is used as a switch between online and offline trigger algorithms
1266 //
733f0542 1267 // Based on an algorithm by Cvetan Cheshkov
b85bbd53 1268
c01a136b 1269 AliESDVZERO* esdV0 = aEsd->GetVZEROData();
1270 if (!esdV0)
ff8c4f30 1271 {
1272 AliError("AliESDVZERO not available");
c01a136b 1273 return kV0Invalid;
ff8c4f30 1274 }
b85bbd53 1275 AliDebug(2,Form("In V0Trigger: %f %f",esdV0->GetV0ATime(),esdV0->GetV0CTime()));
97fa3cbc 1276
b85bbd53 1277 Int_t begin = -1;
1278 Int_t end = -1;
1279
1280 if (side == kASide)
1281 {
1282 begin = 32;
1283 end = 64;
1284 }
1285 else if (side == kCSide)
1286 {
1287 begin = 0;
1288 end = 32;
1289 }
1290 else
1291 return kV0Invalid;
1292
1293 if (esdV0->TestBit(AliESDVZERO::kDecisionFilled)) {
988dd3a4 1294 if (online) {
b85bbd53 1295 if (esdV0->TestBit(AliESDVZERO::kOnlineBitsFilled)) {
1296 for (Int_t i = begin; i < end; ++i) {
1297 if (esdV0->GetBBFlag(i)) return kV0BB;
1298 }
1299 for (Int_t i = begin; i < end; ++i) {
1300 if (esdV0->GetBGFlag(i)) return kV0BG;
1301 }
1302 return kV0Empty;
1303 }
1304 else {
1305 AliWarning("V0 online trigger analysis is not yet available!");
1306 return kV0BB;
1307 }
988dd3a4 1308 }
1309 else {
1310
1311 if (fillHists) {
1312 if (side == kASide && fHistV0A)
1313 fHistV0A->Fill(esdV0->GetV0ATime());
1314 if (side == kCSide && fHistV0C)
1315 fHistV0C->Fill(esdV0->GetV0CTime());
1316 }
1317
1318 if (side == kASide) return (V0Decision)esdV0->GetV0ADecision();
1319 else if (side == kCSide) return (V0Decision)esdV0->GetV0CDecision();
1320 else return kV0Invalid;
1321 }
1322 }
1323
c01a136b 1324 Float_t time = 0;
bcd135ec 1325 Float_t weight = 0;
97fa3cbc 1326 if (fMC)
1327 {
1328 Int_t runRange;
1329 if (aEsd->GetRunNumber() <= 104803) runRange = 0;
1330 else if (aEsd->GetRunNumber() <= 104876) runRange = 1;
1331 else runRange = 2;
1332
1333 Float_t factors[3][64] = {
1334 // runs: 104792-104803
1335 {4.6,5.9,6.3,6.0,4.7,5.9,4.9,5.4,4.8,4.1,4.9,4.6,4.5,5.5,5.1,5.8,4.3,4.0,4.0,3.3,3.1,2.9,3.0,5.6,3.3,4.9,3.9,5.3,4.1,4.4,3.9,5.5,5.7,9.5,5.1,5.3,6.6,7.1,8.9,4.4,4.1,5.9,9.0,4.5,4.1,6.0,4.7,7.1,4.2,4.7,3.9,6.3,5.9,4.8,4.7,4.5,4.7,5.4,5.8,5.0,5.1,5.9,5.3,3.6},
1336 // runs: 104841-104876
1337 {4.6,4.8,4.9,4.8,4.3,4.9,4.4,4.5,4.6,5.0,4.7,4.6,4.7,4.6,4.6,5.5,4.7,4.5,4.7,5.0,6.5,7.6,5.3,4.9,5.5,4.8,4.6,4.9,4.5,4.5,4.6,4.9,5.7,9.8,4.9,5.2,7.1,7.1,8.1,4.4,4.0,6.0,8.3,4.6,4.2,5.6,4.6,6.4,4.4,4.7,4.5,6.5,6.0,4.7,4.5,4.4,4.8,5.5,5.9,5.3,5.0,5.7,5.1,3.6},
1338 // runs: 104890-92
1339 {4.7,5.2,4.8,5.0,4.4,5.0,4.4,4.6,4.6,4.5,4.4,4.6,4.5,4.6,4.8,5.5,4.8,4.5,4.4,4.3,5.4,7.7,5.6,5.0,5.4,4.3,4.5,4.8,4.5,4.5,4.6,5.3,5.7,9.6,4.9,5.4,6.1,7.2,8.6,4.4,4.0,5.4,8.8,4.4,4.2,5.8,4.7,6.7,4.3,4.7,4.0,6.1,6.0,4.9,4.8,4.6,4.7,5.2,5.7,5.0,5.0,5.8,5.3,3.6}
1340 };
1341 Float_t dA = 77.4 - 11.0;
1342 Float_t dC = 77.4 - 2.9;
1343 // Time misalignment
1344 Float_t timeShift[64] = {0.477957 , 0.0889999 , 0.757669 , 0.205439 , 0.239666 , -0.183705 , 0.442873 , -0.281366 , 0.260976 , 0.788995 , 0.974758 , 0.548532 , 0.495023 , 0.868472 , 0.661167 , 0.358307 , 0.221243 , 0.530179 , 1.26696 , 1.33082 , 1.27086 , 1.77133 , 1.10253 , 0.634806 , 2.14838 , 1.50212 , 1.59253 , 1.66122 , 1.16957 , 1.52056 , 1.47791 , 1.81905 , -1.94123 , -1.29124 , -2.16045 , -1.78939 , -3.11111 , -1.87178 , -1.57671 , -1.70311 , -1.81208 , -1.94475 , -2.53058 , -1.7042 , -2.08109 , -1.84416 , -0.61073 , -1.77145 , 0.16999 , -0.0585339 , 0.00401133 , 0.397726 , 0.851111 , 0.264187 , 0.59573 , -0.158263 , 0.584362 , 1.20835 , 0.927573 , 1.13895 , 0.64648 , 2.18747 , 1.68909 , 0.451194};
1345 Float_t dA2 = 2.8, dC2 = 3.3;
1346
1347 if (online) {
1348 for (Int_t i = begin; i < end; ++i) {
1349 Float_t tempAdc = esdV0->GetAdc(i)/factors[runRange][i];
1350 Float_t tempTime = (i >= 32) ? esdV0->GetTime(i)+dA+timeShift[i]+dA2 : esdV0->GetTime(i)+dC+timeShift[i]+dC2;
1351 if (esdV0->GetTime(i) >= 1e-6 &&
1352 tempTime > fV0HwWinLow && tempTime < fV0HwWinHigh &&
1353 tempAdc > fV0HwAdcThr)
1354 return kV0BB;
1355 }
1356 return kV0Empty;
1357 }
1358 else {
1359 for (Int_t i = begin; i < end; ++i) {
1360 Float_t tempAdc = esdV0->GetAdc(i)/factors[runRange][i];
1361 Float_t tempTime = (i >= 32) ? esdV0->GetTime(i)+dA : esdV0->GetTime(i)+dC;
1362 Float_t tempRawTime = (i >= 32) ? esdV0->GetTime(i)+dA+timeShift[i]+dA2 : esdV0->GetTime(i)+dC+timeShift[i]+dC2;
1363 if (esdV0->GetTime(i) >= 1e-6 &&
1364 tempRawTime < 125.0 &&
1365 tempAdc > fV0AdcThr) {
1366 weight += 1.0;
1367 time += tempTime;
1368 }
1369 }
1370 }
1371 }
1372 else {
8b16e464 1373 if (online) {
1374 for (Int_t i = begin; i < end; ++i) {
1375 if (esdV0->GetTime(i) >= 1e-6 &&
1376 esdV0->GetTime(i) > fV0HwWinLow && esdV0->GetTime(i) < fV0HwWinHigh &&
1377 esdV0->GetAdc(i) > fV0HwAdcThr)
1378 return kV0BB;
1379 }
1380 return kV0Empty;
1381 }
1382 else {
1383 for (Int_t i = begin; i < end; ++i) {
1384 if (esdV0->GetTime(i) > 1e-6 && esdV0->GetAdc(i) > fV0AdcThr) {
2078f478 1385 Float_t correctedTime = V0CorrectLeadingTime(i, esdV0->GetTime(i), esdV0->GetAdc(i),aEsd->GetRunNumber());
8b16e464 1386 Float_t timeWeight = V0LeadingTimeWeight(esdV0->GetAdc(i));
1387 time += correctedTime*timeWeight;
97fa3cbc 1388
8b16e464 1389 weight += timeWeight;
1390 }
97fa3cbc 1391 }
c01a136b 1392 }
1393 }
907972ff 1394
bcd135ec 1395 if (weight > 0)
1396 time /= weight;
90a4610a 1397 time += fV0TimeOffset;
c01a136b 1398
1399 if (fillHists)
1400 {
1401 if (side == kASide && fHistV0A)
1402 fHistV0A->Fill(time);
1403 if (side == kCSide && fHistV0C)
1404 fHistV0C->Fill(time);
1405 }
907972ff 1406
c01a136b 1407 if (side == kASide)
1408 {
6dc2503d 1409 if (time > 68 && time < 100)
c01a136b 1410 return kV0BB;
bcd135ec 1411 if (time > 54 && time < 57.5)
c01a136b 1412 return kV0BG;
6dc2503d 1413 if (time > 57.5 && time < 68)
733f0542 1414 return kV0Fake;
c01a136b 1415 }
907972ff 1416
c01a136b 1417 if (side == kCSide)
1418 {
6dc2503d 1419 if (time > 75.5 && time < 100)
c01a136b 1420 return kV0BB;
bcd135ec 1421 if (time > 69.5 && time < 73)
c01a136b 1422 return kV0BG;
733f0542 1423 if (time > 55 && time < 69.5)
1424 return kV0Fake;
c01a136b 1425 }
1426
1427 return kV0Empty;
1428}
1429
2078f478 1430Float_t AliTriggerAnalysis::V0CorrectLeadingTime(Int_t i, Float_t time, Float_t adc, Int_t runNumber) const
c01a136b 1431{
1432 // Correct for slewing and align the channels
1433 //
bcd135ec 1434 // Authors: Cvetan Cheshkov / Raphael Tieulent
c01a136b 1435
1436 if (time == 0) return 0;
1437
bcd135ec 1438 // Time alignment
1439 Float_t timeShift[64] = {0.477957 , 0.0889999 , 0.757669 , 0.205439 , 0.239666 , -0.183705 , 0.442873 , -0.281366 , 0.260976 , 0.788995 , 0.974758 , 0.548532 , 0.495023 , 0.868472 , 0.661167 , 0.358307 , 0.221243 , 0.530179 , 1.26696 , 1.33082 , 1.27086 , 1.77133 , 1.10253 , 0.634806 , 2.14838 , 1.50212 , 1.59253 , 1.66122 , 1.16957 , 1.52056 , 1.47791 , 1.81905 , -1.94123 , -1.29124 , -2.16045 , -1.78939 , -3.11111 , -1.87178 , -1.57671 , -1.70311 , -1.81208 , -1.94475 , -2.53058 , -1.7042 , -2.08109 , -1.84416 , -0.61073 , -1.77145 , 0.16999 , -0.0585339 , 0.00401133 , 0.397726 , 0.851111 , 0.264187 , 0.59573 , -0.158263 , 0.584362 , 1.20835 , 0.927573 , 1.13895 , 0.64648 , 2.18747 , 1.68909 , 0.451194};
1440
2078f478 1441 if(runNumber < 106031)
1442 time -= timeShift[i];
c01a136b 1443
1444 // Slewing correction
1445 if (adc == 0) return time;
1446
bcd135ec 1447 Float_t p1 = 1.57345e1;
1448 Float_t p2 =-4.25603e-1;
1449
2078f478 1450 if(runNumber >= 106031) adc *= (2.5/4.0);
bcd135ec 1451 return (time - p1*TMath::Power(adc,p2));
1452}
1453
1454Float_t AliTriggerAnalysis::V0LeadingTimeWeight(Float_t adc) const
1455{
1456 if (adc < 1e-6) return 0;
1457
1458 Float_t p1 = 40.211;
1459 Float_t p2 =-4.25603e-1;
1460 Float_t p3 = 0.5646;
1461
1462 return 1./(p1*p1*TMath::Power(adc,2.*(p2-1.))+p3*p3);
ff8c4f30 1463}
1464
ce08cb1f 1465
1466Bool_t AliTriggerAnalysis::ZDCTDCTrigger(const AliESDEvent* aEsd, AliceSide side, Bool_t useZN, Bool_t useZP, Bool_t fillHists) const
1467{
1468 // Returns if ZDC triggered, based on TDC information
1469
1470 AliESDZDC *esdZDC = aEsd->GetESDZDC();
1471
6a7f284a 1472 Bool_t zdcNA = kFALSE;
1473 Bool_t zdcNC = kFALSE;
1474 Bool_t zdcPA = kFALSE;
1475 Bool_t zdcPC = kFALSE;
1476
1477 if (fMC) {
1478 // If it's MC, we use the energy
1479 Double_t minEnergy = 0;
1480 Double_t zNCEnergy = esdZDC->GetZDCN1Energy();
1481 Double_t zPCEnergy = esdZDC->GetZDCP1Energy();
1482 Double_t zNAEnergy = esdZDC->GetZDCN2Energy();
1483 Double_t zPAEnergy = esdZDC->GetZDCP2Energy();
1484 zdcNA = (zNAEnergy>minEnergy);
1485 zdcNC = (zNCEnergy>minEnergy);
1486 zdcPA = (zPAEnergy>minEnergy);
1487 zdcPC = (zPCEnergy>minEnergy);
1488
1489 }
1490 else {
1491
1492 Bool_t tdc[32] = {kFALSE};
1493 for(Int_t itdc=0; itdc<32; itdc++){
1494 for(Int_t i=0; i<4; i++){
102cfd12 1495 if (esdZDC->GetZDCTDCData(itdc, i) != 0){
6a7f284a 1496 tdc[itdc] = kTRUE;
1497 }
ce08cb1f 1498 }
6a7f284a 1499 if(fillHists && tdc[itdc]) {
1500 fHistTDCZDC->Fill(itdc);
1501 }
ce08cb1f 1502 }
6a7f284a 1503 zdcNA = tdc[12];
1504 zdcNC = tdc[10];
1505 zdcPA = tdc[13];
1506 zdcPC = tdc[11];
ce08cb1f 1507 }
ce08cb1f 1508
1509 if (side == kASide) return ((useZP&&zdcPA) || (useZN&&zdcNA));
1510 if (side == kCSide) return ((useZP&&zdcPC) || (useZN&&zdcNC));
1511 return kFALSE;
1512}
1513
102cfd12 1514Bool_t AliTriggerAnalysis::ZDCTimeTrigger(const AliESDEvent *aEsd, Bool_t fillHists) const
1515{
1516 // This method implements a selection
1517 // based on the timing in both sides of zdcN
1518 // It can be used in order to eliminate
1519 // parasitic collisions
1520 Bool_t zdcAccept = kFALSE;
102cfd12 1521 AliESDZDC *esdZDC = aEsd->GetESDZDC();
1522
869f9767 1523 if(fMC) {
1524 UInt_t esdFlag = esdZDC->GetESDQuality();
1525
1526 Bool_t znaFired=kFALSE, zpaFired=kFALSE;
1527 Bool_t zem1Fired=kFALSE, zem2Fired=kFALSE;
1528 Bool_t zncFired=kFALSE, zpcFired=kFALSE;
1529 //
1530 // **** Trigger patterns
1531 if((esdFlag & 0x00000001) == 0x00000001) znaFired=kTRUE;
1532 if((esdFlag & 0x00000002) == 0x00000002) zpaFired=kTRUE;
1533 if((esdFlag & 0x00000004) == 0x00000004) zem1Fired=kTRUE;
1534 if((esdFlag & 0x00000008) == 0x00000008) zem2Fired=kTRUE;
1535 if((esdFlag & 0x00000010) == 0x00000010) zncFired=kTRUE;
1536 if((esdFlag & 0x00000020) == 0x00000020) zpcFired=kTRUE;
1537 zdcAccept = (znaFired | zncFired);
1538 }
1539 else {
869f9767 1540 for(Int_t i = 0; i < 4; ++i) {
1541 if (esdZDC->GetZDCTDCData(10,i) != 0) {
1542 Float_t tdcC = 0.025*(esdZDC->GetZDCTDCData(10,i)-esdZDC->GetZDCTDCData(14,i));
fcb18b05 1543 Float_t tdcCcorr = esdZDC->GetZDCTDCCorrected(10,i);
869f9767 1544 for(Int_t j = 0; j < 4; ++j) {
1545 if (esdZDC->GetZDCTDCData(12,j) != 0) {
1546 Float_t tdcA = 0.025*(esdZDC->GetZDCTDCData(12,j)-esdZDC->GetZDCTDCData(14,j));
7c55ebd9 1547
fcb18b05 1548 Float_t tdcAcorr = esdZDC->GetZDCTDCCorrected(12,j);
1549 if(fillHists) {
1550 fHistTimeZDC->Fill(tdcC-tdcA,tdcC+tdcA);
1551 fHistTimeCorrZDC->Fill(tdcCcorr-tdcAcorr,tdcCcorr+tdcAcorr);
1552 }
1553 if (esdZDC->TestBit(AliESDZDC::kCorrectedTDCFilled)) {
d6305a15 1554 if (((tdcCcorr-tdcAcorr-fZDCCutRefDeltaCorr)*(tdcCcorr-tdcAcorr-fZDCCutRefDeltaCorr)/(fZDCCutSigmaDeltaCorr*fZDCCutSigmaDeltaCorr) +
1555 (tdcCcorr+tdcAcorr-fZDCCutRefSumCorr)*(tdcCcorr+tdcAcorr-fZDCCutRefSumCorr)/(fZDCCutSigmaSumCorr*fZDCCutSigmaSumCorr))< 1.0)
fcb18b05 1556 zdcAccept = kTRUE;
1557 }
1558 else {
7c55ebd9 1559 if (((tdcC-tdcA-fZDCCutRefDelta)*(tdcC-tdcA-fZDCCutRefDelta)/(fZDCCutSigmaDelta*fZDCCutSigmaDelta) +
1560 (tdcC+tdcA-fZDCCutRefSum)*(tdcC+tdcA-fZDCCutRefSum)/(fZDCCutSigmaSum*fZDCCutSigmaSum))< 1.0)
fcb18b05 1561 zdcAccept = kTRUE;
1562 }
869f9767 1563 }
102cfd12 1564 }
1565 }
1566 }
1567 }
102cfd12 1568 return zdcAccept;
1569}
1570
0d12ffff 1571Bool_t AliTriggerAnalysis::ZDCTimeBGTrigger(const AliESDEvent *aEsd, AliceSide side) const
1572{
1573 // This method implements a selection
1574 // based on the timing in of zdcN
37c099e8 1575 // It can be used in order to flag background
1576 // ** So far only implemented for the 2012 pA run **
1577
1578 if(fMC) return kFALSE;
0d12ffff 1579
1580 AliESDZDC *zdcData = aEsd->GetESDZDC();
1581 Bool_t zna = kFALSE;
1582 Bool_t znc = kFALSE;
b68d0b5e 1583 Bool_t znabadhit = kFALSE;
1584 Bool_t zncbadhit = kFALSE;
0d12ffff 1585
1586 Float_t tdcC=999, tdcCcorr=999, tdcA=999, tdcAcorr=999;
1587 for(Int_t i = 0; i < 4; ++i) {
1588 if (zdcData->GetZDCTDCData(10,i) != 0) {
1589 znc = kTRUE;
1590 tdcC = 0.025*(zdcData->GetZDCTDCData(10,i)-zdcData->GetZDCTDCData(14,i));
1591 tdcCcorr = zdcData->GetZDCTDCCorrected(10,i);
b68d0b5e 1592 if((TMath::Abs(tdcCcorr)<fZDCCutZNCTimeCorrMax) && (TMath::Abs(tdcCcorr)>fZDCCutZNCTimeCorrMin)) zncbadhit = kTRUE;
0d12ffff 1593 }
1594 }
1595 for(Int_t j = 0; j < 4; ++j) {
1596 if (zdcData->GetZDCTDCData(12,j) != 0) {
1597 zna = kTRUE;
1598 tdcA = 0.025*(zdcData->GetZDCTDCData(12,j)-zdcData->GetZDCTDCData(14,j));
1599 tdcAcorr = zdcData->GetZDCTDCCorrected(12,j);
b68d0b5e 1600 if((TMath::Abs(tdcAcorr)<fZDCCutZNATimeCorrMax) && (TMath::Abs(tdcAcorr)>fZDCCutZNATimeCorrMin)) znabadhit = kTRUE;
0d12ffff 1601 }
1602 }
1603
1604 const Int_t runNumber = aEsd->GetRunNumber();
22bb9681 1605 if(runNumber<188124 || (runNumber>188374 && runNumber<194713)){ // FIXME: end of pA-run is not known
5ec5f893 1606 AliDebug(3,Form(" ZN BG time cut not implemented for run %d",runNumber));
0d12ffff 1607 return kFALSE;
1608 }
1609
b68d0b5e 1610 Bool_t znabg = (zna && znabadhit);
1611 Bool_t zncbg = (znc && zncbadhit);
0d12ffff 1612
1613 // Printf("Checking ZN background (time) for run %d, A = %d, time=%2.2f, C = %d, time=%2.2f",runNumber,(Int_t)zna,tdcAcorr,(Int_t)znc,tdcCcorr);
1614 // Printf("Checking ZN background (time) for run %d, A-BG = %d, C-BG = %d",runNumber,(Int_t)znabg,(Int_t)zncbg);
1615
1616 if (side == kASide) return znabg;
1617 if (side == kCSide) return zncbg;
1618 return kFALSE;
1619}
1620
70fdd197 1621Bool_t AliTriggerAnalysis::ZDCTrigger(const AliESDEvent* aEsd, AliceSide side) const
ff8c4f30 1622{
1623 // Returns if ZDC triggered
1624
c8d3e441 1625 AliESDZDC* zdcData = aEsd->GetESDZDC();
1626 if (!zdcData)
1627 {
1628 AliError("AliESDZDC not available");
1629 return kFALSE;
1630 }
1631
1632 UInt_t quality = zdcData->GetESDQuality();
1633
1634 // from Nora's presentation, general first physics meeting 16.10.09
1635 static UInt_t zpc = 0x20;
1636 static UInt_t znc = 0x10;
1637 static UInt_t zem1 = 0x08;
1638 static UInt_t zem2 = 0x04;
1639 static UInt_t zpa = 0x02;
1640 static UInt_t zna = 0x01;
1641
1642 if (side == kASide && ((quality & zpa) || (quality & zna)))
1643 return kTRUE;
1644 if (side == kCentralBarrel && ((quality & zem1) || (quality & zem2)))
1645 return kTRUE;
1646 if (side == kCSide && ((quality & zpc) || (quality & znc)))
1647 return kTRUE;
ff8c4f30 1648
1649 return kFALSE;
1650}
1651
61899827 1652Int_t AliTriggerAnalysis::FMDHitCombinations(const AliESDEvent* aEsd, AliceSide side, Bool_t fillHists)
ff8c4f30 1653{
907972ff 1654 // returns number of hit combinations agove threshold
7a11141c 1655 //
1656 // Authors: FMD team, Hans Dalsgaard (code merged from FMD/AliFMDOfflineTrigger)
ff8c4f30 1657
4011b280 1658 if (!fDoFMD)
1659 return -1;
1660
7a11141c 1661 // Workaround for AliESDEvent::GetFMDData is not const!
1662 const AliESDFMD* fmdData = (const_cast<AliESDEvent*>(aEsd))->GetFMDData();
1663 if (!fmdData)
1664 {
1665 AliError("AliESDFMD not available");
907972ff 1666 return -1;
7a11141c 1667 }
1668
1669 Int_t detFrom = (side == kASide) ? 1 : 3;
1670 Int_t detTo = (side == kASide) ? 2 : 3;
1671
907972ff 1672 Int_t triggers = 0;
7a11141c 1673 Float_t totalMult = 0;
1674 for (UShort_t det=detFrom;det<=detTo;det++) {
1675 Int_t nRings = (det == 1 ? 1 : 2);
1676 for (UShort_t ir = 0; ir < nRings; ir++) {
1677 Char_t ring = (ir == 0 ? 'I' : 'O');
1678 UShort_t nsec = (ir == 0 ? 20 : 40);
1679 UShort_t nstr = (ir == 0 ? 512 : 256);
039db886 1680 for (UShort_t sec =0; sec < nsec; sec++) {
1681 for (UShort_t strip = 0; strip < nstr; strip++) {
1682 Float_t mult = fmdData->Multiplicity(det,ring,sec,strip);
1683 if (mult == AliESDFMD::kInvalidMult) continue;
1684
61899827 1685 if (fillHists)
907972ff 1686 fHistFMDSingle->Fill(mult);
1687
039db886 1688 if (mult > fFMDLowCut)
1689 totalMult = totalMult + mult;
1690 else
907972ff 1691 {
1692 if (totalMult > fFMDHitCut)
1693 triggers++;
1694
61899827 1695 if (fillHists)
907972ff 1696 fHistFMDSum->Fill(totalMult);
1697
1698 totalMult = 0;
1699 }
039db886 1700 }
7a11141c 1701 }
1702 }
1703 }
907972ff 1704
1705 return triggers;
1706}
1707
61899827 1708Bool_t AliTriggerAnalysis::FMDTrigger(const AliESDEvent* aEsd, AliceSide side)
907972ff 1709{
1710 // Returns if the FMD triggered
1711 //
1712 // Authors: FMD team, Hans Dalsgaard (code merged from FMD/AliFMDOfflineTrigger)
1713
1714 Int_t triggers = FMDHitCombinations(aEsd, side, kFALSE);
1715
1716 if (triggers > 0)
1717 return kTRUE;
1718
ff8c4f30 1719 return kFALSE;
1720}
907972ff 1721
70fdd197 1722Long64_t AliTriggerAnalysis::Merge(TCollection* list)
907972ff 1723{
1724 // Merge a list of AliMultiplicityCorrection objects with this (needed for
1725 // PROOF).
1726 // Returns the number of merged objects (including this).
1727
1728 if (!list)
1729 return 0;
1730
1731 if (list->IsEmpty())
1732 return 1;
1733
1734 TIterator* iter = list->MakeIterator();
1735 TObject* obj;
1736
1737 // collections of all histograms
559b5ed7 1738 const Int_t nHists = 14;
907972ff 1739 TList collections[nHists];
1740
1741 Int_t count = 0;
1742 while ((obj = iter->Next())) {
1743
70fdd197 1744 AliTriggerAnalysis* entry = dynamic_cast<AliTriggerAnalysis*> (obj);
907972ff 1745 if (entry == 0)
1746 continue;
1747
c01a136b 1748 Int_t n = 0;
1749 collections[n++].Add(entry->fHistV0A);
1750 collections[n++].Add(entry->fHistV0C);
1751 collections[n++].Add(entry->fHistZDC);
ce08cb1f 1752 collections[n++].Add(entry->fHistTDCZDC);
102cfd12 1753 collections[n++].Add(entry->fHistTimeZDC);
fcb18b05 1754 collections[n++].Add(entry->fHistTimeCorrZDC);
c01a136b 1755 collections[n++].Add(entry->fHistFMDA);
1756 collections[n++].Add(entry->fHistFMDC);
1757 collections[n++].Add(entry->fHistFMDSingle);
1758 collections[n++].Add(entry->fHistFMDSum);
1759 collections[n++].Add(entry->fHistBitsSPD);
1760 collections[n++].Add(entry->fHistFiredBitsSPD);
1ea7a921 1761 collections[n++].Add(entry->fHistSPDClsVsTrk);
559b5ed7 1762 collections[n++].Add(entry->fHistT0);
c01a136b 1763
1764 // merge fTriggerClasses
1765 TIterator* iter2 = entry->fTriggerClasses->MakeIterator();
73dc876a 1766 TObjString* obj2 = 0;
1767 while ((obj2 = dynamic_cast<TObjString*> (iter2->Next())))
c01a136b 1768 {
c2a5a2b9 1769 TParameter<Long64_t>* param2 = static_cast<TParameter<Long64_t>*> (entry->fTriggerClasses->GetValue(obj2));
c01a136b 1770
73dc876a 1771 TParameter<Long64_t>* param1 = dynamic_cast<TParameter<Long64_t>*> (fTriggerClasses->GetValue(obj2));
c01a136b 1772 if (param1)
1773 {
1774 param1->SetVal(param1->GetVal() + param2->GetVal());
1775 }
1776 else
1777 {
1778 param1 = dynamic_cast<TParameter<Long64_t>*> (param2->Clone());
73dc876a 1779 fTriggerClasses->Add(new TObjString(obj2->String()), param1);
c01a136b 1780 }
1781 }
1782
1783 delete iter2;
1784
907972ff 1785 count++;
1786 }
1787
c01a136b 1788 Int_t n = 0;
1789 fHistV0A->Merge(&collections[n++]);
1790 fHistV0C->Merge(&collections[n++]);
1791 fHistZDC->Merge(&collections[n++]);
ce08cb1f 1792 fHistTDCZDC->Merge(&collections[n++]);
92b1d068 1793 if (fHistTimeZDC)
1794 fHistTimeZDC->Merge(&collections[n++]);
1795 else
1796 n++;
fcb18b05 1797 if (fHistTimeCorrZDC)
1798 fHistTimeCorrZDC->Merge(&collections[n++]);
1799 else
1800 n++;
c01a136b 1801 fHistFMDA->Merge(&collections[n++]);
1802 fHistFMDC->Merge(&collections[n++]);
1803 fHistFMDSingle->Merge(&collections[n++]);
1804 fHistFMDSum->Merge(&collections[n++]);
1805 fHistBitsSPD->Merge(&collections[n++]);
1806 fHistFiredBitsSPD->Merge(&collections[n++]);
1ea7a921 1807 fHistSPDClsVsTrk->Merge(&collections[n++]);
559b5ed7 1808 fHistT0->Merge(&collections[n++]);
907972ff 1809 delete iter;
1810
1811 return count+1;
1812}
1813
61899827 1814void AliTriggerAnalysis::SaveHistograms() const
907972ff 1815{
1816 // write histograms to current directory
1817
c01a136b 1818 if (!fHistBitsSPD)
907972ff 1819 return;
1820
d988bfb0 1821 if (fHistBitsSPD) {
1822 fHistBitsSPD->Write();
891c67bd 1823 //fHistBitsSPD->ProjectionX();
1824 //fHistBitsSPD->ProjectionY();
d988bfb0 1825 }
1826 else Printf("Cannot save fHistBitsSPD");
1827 if (fHistFiredBitsSPD) fHistFiredBitsSPD->Write();
1828 else Printf("Cannot save fHistFiredBitsSPD");
1829 if (fHistV0A) fHistV0A->Write();
1830 else Printf("Cannot save fHistV0A");
1831 if (fHistV0C) fHistV0C->Write();
1832 else Printf("Cannot save fHistV0C");
1833 if (fHistZDC) fHistZDC->Write();
1834 else Printf("Cannot save fHistZDC");
1835 if (fHistTDCZDC) fHistTDCZDC->Write();
1836 else Printf("Cannot save fHistTDCZDC");
1837 if (fHistTimeZDC) fHistTimeZDC->Write();
1838 else Printf("Cannot save fHistTimeZDC");
fcb18b05 1839 if (fHistTimeCorrZDC) fHistTimeCorrZDC->Write();
1840 else Printf("Cannot save fHistTimeCorrZDC");
d988bfb0 1841 if (fHistFMDA) fHistFMDA->Write();
1842 else Printf("Cannot save fHistFMDA");
1843 if (fHistFMDC) fHistFMDC->Write();
1844 else Printf("Cannot save fHistFMDC");
1845 if (fHistFMDSingle) fHistFMDSingle->Write();
1846 else Printf("Cannot save fHistFMDSingle");
1847 if (fHistFMDSum) fHistFMDSum->Write();
1848 else Printf("Cannot save fHistFMDSum");
1849 if (fSPDGFOEfficiency) fSPDGFOEfficiency->Write("fSPDGFOEfficiency");
1ea7a921 1850 if (fHistSPDClsVsTrk) fHistSPDClsVsTrk->Write("fHistSPDClsVsTrk");
559b5ed7 1851 if (fHistT0) fHistT0->Write("fHistT0");
1852
8dec6e35 1853 // else Printf("Cannot save fSPDGFOEfficiency");
733f0542 1854
c01a136b 1855 fTriggerClasses->Write("fTriggerClasses", TObject::kSingleKey);
1856}
1857
1858void AliTriggerAnalysis::PrintTriggerClasses() const
1859{
1860 // print trigger classes
1861
1862 Printf("Trigger Classes:");
1863
35fb1e58 1864 Printf("Event count for trigger combinations:");
1865
1866 TMap singleTrigger;
1867 singleTrigger.SetOwner();
1868
c01a136b 1869 TIterator* iter = fTriggerClasses->MakeIterator();
1870 TObjString* obj = 0;
1871 while ((obj = dynamic_cast<TObjString*> (iter->Next())))
1872 {
35fb1e58 1873 TParameter<Long64_t>* param = static_cast<TParameter<Long64_t>*> (fTriggerClasses->GetValue(obj));
1874
e8b839ab 1875 Printf(" %s: %ld triggers", obj->String().Data(), (Long_t)param->GetVal());
c01a136b 1876
35fb1e58 1877 TObjArray* tokens = obj->String().Tokenize(" ");
1878 for (Int_t i=0; i<tokens->GetEntries(); i++)
1879 {
1880 TParameter<Long64_t>* count = dynamic_cast<TParameter<Long64_t>*> (singleTrigger.GetValue(((TObjString*) tokens->At(i))->String().Data()));
1881 if (!count)
1882 {
1883 count = new TParameter<Long64_t>(((TObjString*) tokens->At(i))->String().Data(), 0);
1884 singleTrigger.Add(new TObjString(((TObjString*) tokens->At(i))->String().Data()), count);
1885 }
1886 count->SetVal(count->GetVal() + param->GetVal());
1887 }
1888
1889 delete tokens;
c01a136b 1890 }
35fb1e58 1891 delete iter;
1892
1893 Printf("Event count for single trigger:");
1894
1895 iter = singleTrigger.MakeIterator();
1896 while ((obj = dynamic_cast<TObjString*> (iter->Next())))
1897 {
1898 TParameter<Long64_t>* param = static_cast<TParameter<Long64_t>*> (singleTrigger.GetValue(obj));
1899
e8b839ab 1900 Printf(" %s: %ld triggers", obj->String().Data(), (Long_t)param->GetVal());
35fb1e58 1901 }
1902 delete iter;
1903
1904 singleTrigger.DeleteAll();
907972ff 1905}
7c55ebd9 1906
1907
559b5ed7 1908//----------------------------------------------------------------------------------------------------
1909AliTriggerAnalysis::T0Decision AliTriggerAnalysis::T0Trigger(const AliESDEvent* aEsd, Bool_t online, Bool_t fillHists)
1910{
1911 // Returns the T0 TVDC trigger decision
1912 //
1913 // argument 'online' is used as a switch between online and offline trigger algorithms
1914 // in online mode return 0TVX
1915 // in offline mode in addition check pile-up and background :
1916 // pile-up readed from ESD: check if TVDC (0TVX module name) has more 1 hit;
1917 // backgroud flag readed from ESD : check in given time interval OrA and OrC were correct but TVDC not
1918 //
1919 // Based on an algorithm by Alla Maevskaya
1920
1921 const AliESDTZERO* esdT0 = aEsd->GetESDTZERO();
1922 if (!esdT0)
1923 {
1924 AliError("AliESDTZERO not available");
1925 return kT0Invalid;
1926 }
1927 //???? AliDebug(2,Form("In T0Trigger: %f %f",esdV0->GetV0ATime(),esdV0->GetV0CTime()));
1928 Float_t tvdc[5] ;
1929 for (Int_t ii=0; ii<5; ii++)
1930 tvdc[ii] = esdT0->GetTVDC(ii);
68ed9ebd 1931 // Int_t trig=esdT0->GetT0Trig();
559b5ed7 1932 // cout<<" T0 trig "<<trig<<endl;
1933
1934 if(fillHists) fHistT0->Fill(tvdc[0]);
1935
1936 if (online) {
f56ee636 1937 if(aEsd->GetHeader()->GetFiredTriggerInputs().Contains("0TVX") ) return kT0BB;
559b5ed7 1938 }
1939 else {
1940
559b5ed7 1941 if (esdT0->GetPileupFlag()) return kT0DecPileup;
1942 if (esdT0->GetBackgroundFlag()) return kT0DecBG;
7d9295b3 1943 if (tvdc[0]>-5 && tvdc[0]<5 && tvdc[0] != 0) return kT0BB;
559b5ed7 1944 }
1945
1946 if (fMC)
7b00906b 1947 if( esdT0->GetT0zVertex()>-12.3 && esdT0->GetT0zVertex() < 10.3) return kT0BB;
559b5ed7 1948
1949 return kT0Empty;
1950}
8d5a14d6 1951
1952//----------------------------------------------------------------------------------------------------
1953Bool_t AliTriggerAnalysis::EMCALCellsTrigger(const AliESDEvent *aEsd)
1954{
1955 //
1956 // Returns the EMCAL trigger decision
1957 // so far only implemented for LHC11a data
1958 // see http://alisoft.cern.ch/viewvc/trunk/PWGGA/EMCALTasks/AliEmcalPhysicsSelection.cxx?view=markup&root=AliRoot Revision 56136
1959 //
1960
1961 Bool_t isFired = kTRUE;
1962 const Int_t runNumber = aEsd->GetRunNumber();
1963
1964 /*
1965 // Load EMCAL branches from the manager
1966 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
1967 am->LoadBranch("EMCALCells.");
1968 am->LoadBranch("CaloClusters");
1969 */
1970
1971 // Get EMCAL cells
1972 AliVCaloCells *cells = aEsd->GetEMCALCells();
1973 const Short_t nCells = cells->GetNumberOfCells();
1974
1975 // count cells above threshold per sm
1976 Int_t nCellCount[10] = {0,0,0,0,0,0,0,0,0,0};
1977 for(Int_t iCell=0; iCell<nCells; ++iCell) {
1978 Short_t cellId = cells->GetCellNumber(iCell);
1979 Double_t cellE = cells->GetCellAmplitude(cellId);
1980 Int_t sm = cellId / (24*48);
1981 if (cellE>0.1)
1982 ++nCellCount[sm];
1983 }
1984
1985 // Trigger decision for LHC11a
1986 Bool_t isLedEvent = kFALSE;
1987 if ((runNumber>=144871) && (runNumber<=146860)) {
1988 if (nCellCount[4] > 100)
1989 isLedEvent = kTRUE;
1990 else {
1991 if ((runNumber>=146858) && (runNumber<=146860)) {
1992 if (nCellCount[3]>=35)
1993 isLedEvent = kTRUE;
1994 }
1995 }
1996 }
1997
1998 if (isLedEvent) {
1999 isFired = kFALSE;
2000 }
2001
2002 return isFired;
2003}
b68d0b5e 2004
2005//__________________________________________________________________________________________
2006Bool_t AliTriggerAnalysis::TRDTrigger(const AliESDEvent *esd, Trigger trigger)
2007{
2008 // evaluate the TRD trigger conditions,
2009 // so far HCO, HSE, HQU, HJT, HEE
2010
2011 Bool_t isFired = kFALSE;
2012
2013 if(trigger!=kTRDHCO && trigger!=kTRDHJT && trigger!=kTRDHSE && trigger!=kTRDHQU && trigger!=kTRDHEE) {
2014 AliWarning("Beware you are erroneously trying to use this function (wrong trigger)");
2015 return isFired;
2016 }
2017
2018 if (!esd) {
2019 AliErrorClass("ESD event pointer is null");
2020 return isFired;
2021 }
2022
2023 Int_t nTrdTracks = esd->GetNumberOfTrdTracks();
2024
2025 if (nTrdTracks > 0 && (trigger==kTRDHCO) ) {
2026 isFired = kTRUE;
2027 return isFired;
2028 }
2029
2030 if(trigger!=kTRDHJT) {
2031 for (Int_t iTrack = 0; iTrack < nTrdTracks; ++iTrack) {
2032
2033 AliESDTrdTrack *trdTrack = esd->GetTrdTrack(iTrack);
2034 if (!trdTrack) continue;
33561da5 2035
b68d0b5e 2036 // for the electron triggers we only consider matched tracks
2037 if(trigger==kTRDHQU)
2038 if ( (TMath::Abs(trdTrack->Pt()) > fTRDptHQU) && (trdTrack->GetPID() > fTRDpidHQU) ) {
2039 isFired = kTRUE;
2040 return isFired;
2041 }
2042
2043 if(trigger==kTRDHSE)
2044 if ( (TMath::Abs(trdTrack->Pt()) > fTRDptHSE) && (trdTrack->GetPID() > fTRDpidHSE) ) {
2045 isFired = kTRUE;
2046 return isFired;
2047 }
2048
2049 if(trigger==kTRDHEE)
2050 if ( (trdTrack->GetSector() >= fTRDminSectorHEE) && (trdTrack->GetSector() <= fTRDmaxSectorHEE) &&
2051 (TMath::Abs(trdTrack->Pt()) > fTRDptHSE) && (trdTrack->GetPID() > fTRDpidHSE) ) {
2052 isFired = kTRUE;
2053 return isFired;
2054 }
2055
2056 }
2057 } else if(trigger==kTRDHJT) {
2058
2059 Int_t nTracks[90] = { 0 }; // stack-wise counted number of tracks above pt threshold
2060
2061 for (Int_t iTrack = 0; iTrack < nTrdTracks; ++iTrack) {
2062
2063 AliESDTrdTrack *trdTrack = esd->GetTrdTrack(iTrack);
2064 if (!trdTrack) continue;
2065
2066 Int_t globalStack = 5*trdTrack->GetSector() + trdTrack->GetStack();
2067
2068 // stack-wise counting of tracks above pt threshold for jet trigger
2069 if (TMath::Abs(trdTrack->GetPt()) >= fTRDptHJT) {
2070 ++nTracks[globalStack];
2071 }
2072 }
2073
2074 // check if HJT condition is fulfilled in any stack
2075 for (Int_t iStack = 0; iStack < 90; iStack++) {
2076 if (nTracks[iStack] >= fTRDnHJT) {
2077 isFired = kTRUE;
2078 break;
2079 }
2080 }
2081
2082 }
2083
2084 return isFired;
2085}