1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-------------------------------------------------------------------------
17 // Implementation of Class AliESDHeader
20 // Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
21 //-------------------------------------------------------------------------
23 #include "AliESDHeader.h"
24 #include "AliTriggerScalersESD.h"
25 #include "AliTriggerScalersRecordESD.h"
26 #include "AliTriggerIR.h"
27 #include "AliTriggerConfiguration.h"
30 ClassImp(AliESDHeader)
32 //______________________________________________________________________________
33 AliESDHeader::AliESDHeader() :
36 fTriggerMaskNext50(0),
42 fEventNumberInFile(0),
49 fTriggerScalersDeltaEvent(),
50 fTriggerScalersDeltaRun(),
51 fTriggerInputsNames(kNTriggerInputs),
54 fIRInt2InteractionsMap(0),
55 fIRInt1InteractionsMap(0)
57 // default constructor
59 SetName("AliESDHeader");
60 for(Int_t i = 0; i<kNMaxIR ; i++) fIRArray[i] = 0;
61 fTriggerInputsNames.SetOwner(kTRUE);
62 for (Int_t itype=0; itype<3; itype++) fTPCNoiseFilterCounter[itype]=0;
65 AliESDHeader::~AliESDHeader()
68 for(Int_t i=0;i<kNMaxIR;i++)if(fIRArray[i])delete fIRArray[i];
71 fIRBufferArray.Delete();
75 AliESDHeader::AliESDHeader(const AliESDHeader &header) :
77 fTriggerMask(header.fTriggerMask),
78 fTriggerMaskNext50(header.fTriggerMaskNext50),
79 fOrbitNumber(header.fOrbitNumber),
80 fTimeStamp(header.fTimeStamp),
81 fEventType(header.fEventType),
82 fEventSpecie(header.fEventSpecie),
83 fPeriodNumber(header.fPeriodNumber),
84 fEventNumberInFile(header.fEventNumberInFile),
85 fBunchCrossNumber(header.fBunchCrossNumber),
86 fTriggerCluster(header.fTriggerCluster),
87 fL0TriggerInputs(header.fL0TriggerInputs),
88 fL1TriggerInputs(header.fL1TriggerInputs),
89 fL2TriggerInputs(header.fL2TriggerInputs),
90 fTriggerScalers(header.fTriggerScalers),
91 fTriggerScalersDeltaEvent(header.fTriggerScalersDeltaEvent),
92 fTriggerScalersDeltaRun(header.fTriggerScalersDeltaRun),
93 fTriggerInputsNames(TObjArray(kNTriggerInputs)),
94 fCTPConfig(header.fCTPConfig),
96 fIRInt2InteractionsMap(header.fIRInt2InteractionsMap),
97 fIRInt1InteractionsMap(header.fIRInt1InteractionsMap)
100 for(Int_t i = 0; i<kNMaxIR ; i++) {
101 if(header.fIRArray[i])fIRArray[i] = new AliTriggerIR(*header.fIRArray[i]);
104 for(Int_t i = 0; i < kNTriggerInputs; i++) {
105 TNamed *str = (TNamed *)((header.fTriggerInputsNames).At(i));
106 if (str) fTriggerInputsNames.AddAt(new TNamed(*str),i);
109 for(Int_t i = 0; i < (header.fIRBufferArray).GetEntries(); ++i) {
110 AliTriggerIR *ir = (AliTriggerIR*)((header.fIRBufferArray).At(i));
111 if (ir) fIRBufferArray.Add(new AliTriggerIR(*ir));
113 for (Int_t itype=0; itype<3; itype++) fTPCNoiseFilterCounter[itype]=header.fTPCNoiseFilterCounter[itype];
116 AliESDHeader& AliESDHeader::operator=(const AliESDHeader &header)
118 // assigment operator
120 AliVHeader::operator=(header);
121 fTriggerMask = header.fTriggerMask;
122 fTriggerMaskNext50 = header.fTriggerMaskNext50;
123 fOrbitNumber = header.fOrbitNumber;
124 fTimeStamp = header.fTimeStamp;
125 fEventType = header.fEventType;
126 fEventSpecie = header.fEventSpecie;
127 fPeriodNumber = header.fPeriodNumber;
128 fEventNumberInFile = header.fEventNumberInFile;
129 fBunchCrossNumber = header.fBunchCrossNumber;
130 fTriggerCluster = header.fTriggerCluster;
131 fL0TriggerInputs = header.fL0TriggerInputs;
132 fL1TriggerInputs = header.fL1TriggerInputs;
133 fL2TriggerInputs = header.fL2TriggerInputs;
134 fTriggerScalers = header.fTriggerScalers;
135 fTriggerScalersDeltaEvent = header.fTriggerScalersDeltaEvent;
136 fTriggerScalersDeltaRun = header.fTriggerScalersDeltaRun;
137 fIRInt2InteractionsMap = header.fIRInt2InteractionsMap;
138 fIRInt1InteractionsMap = header.fIRInt1InteractionsMap;
141 fCTPConfig = header.fCTPConfig;
143 fTriggerInputsNames.Clear();
144 for(Int_t i = 0; i < kNTriggerInputs; i++) {
145 TNamed *str = (TNamed *)((header.fTriggerInputsNames).At(i));
146 if (str) fTriggerInputsNames.AddAt(new TNamed(*str),i);
148 for(Int_t i = 0; i<kNMaxIR ; i++) {
150 if(header.fIRArray[i])fIRArray[i] = new AliTriggerIR(*header.fIRArray[i]);
154 fIRBufferArray.Delete();
155 for(Int_t i = 0; i < (header.fIRBufferArray).GetEntries(); ++i) {
156 AliTriggerIR *ir = (AliTriggerIR*)((header.fIRBufferArray).At(i));
157 if (ir) fIRBufferArray.Add(new AliTriggerIR(*ir));
159 for (Int_t itype=0; itype<3; itype++) fTPCNoiseFilterCounter[itype]=header.fTPCNoiseFilterCounter[itype];
164 void AliESDHeader::Copy(TObject &obj) const
166 // this overwrites the virtual TOBject::Copy()
167 // to allow run time copying without casting
170 if(this==&obj)return;
171 AliESDHeader *robj = dynamic_cast<AliESDHeader*>(&obj);
172 if(!robj)return; // not an AliESDHeader
176 //______________________________________________________________________________
177 void AliESDHeader::Reset()
179 // reset all data members
181 fTriggerMaskNext50 = 0;
187 fEventNumberInFile = 0;
188 fBunchCrossNumber = 0;
190 fL0TriggerInputs = 0;
191 fL1TriggerInputs = 0;
192 fL2TriggerInputs = 0;
193 fTriggerScalers.Reset();
194 fTriggerScalersDeltaEvent.Reset();
195 fTriggerScalersDeltaRun.Reset();
196 fTriggerInputsNames.Clear();
198 fIRInt2InteractionsMap.ResetAllBits();
199 fIRInt1InteractionsMap.ResetAllBits();
203 for(Int_t i=0;i<kNMaxIR;i++)if(fIRArray[i]){
207 for (Int_t itype=0; itype<3; itype++) fTPCNoiseFilterCounter[itype]=0;
208 fIRBufferArray.Delete();
210 //______________________________________________________________________________
211 Bool_t AliESDHeader::AddTriggerIR(const AliTriggerIR* ir)
213 // Add an IR object into the array
214 // of IRs in the ESD header
216 fIRBufferArray.Add(new AliTriggerIR(*ir));
220 //______________________________________________________________________________
221 void AliESDHeader::Print(const Option_t *) const
223 // Print some data members
224 printf("Event # %d in file Bunch crossing # %d Orbit # %d Trigger %lld %lld\n",
225 GetEventNumberInFile(),
226 GetBunchCrossNumber(),
229 GetTriggerMaskNext50());
230 printf("List of the active trigger inputs: ");
231 for(Int_t i = 0; i < kNTriggerInputs; i++) {
232 TNamed *str = (TNamed *)((fTriggerInputsNames).At(i));
233 if (str) printf("%i %s ",i,str->GetName());
238 //______________________________________________________________________________
239 void AliESDHeader::SetActiveTriggerInputs(const char*name, Int_t index)
241 // Fill the active trigger inputs names
242 // into the corresponding fTriggerInputsNames (TObjArray of TNamed)
243 if (index >= kNTriggerInputs || index < 0) {
244 AliError(Form("Index (%d) is outside the allowed range (0,59)!",index));
248 fTriggerInputsNames.AddAt(new TNamed(name,NULL),index);
250 //______________________________________________________________________________
251 const char* AliESDHeader::GetTriggerInputName(Int_t index, Int_t trglevel) const
253 // Get the trigger input name
254 // at the specified position in the trigger mask and trigger level (0,1,2)
255 TNamed *trginput = 0;
256 if (trglevel == 0) trginput = (TNamed *)fTriggerInputsNames.At(index);
257 if (trglevel == 1) trginput = (TNamed *)fTriggerInputsNames.At(index+24);
258 if (trglevel == 2) trginput = (TNamed *)fTriggerInputsNames.At(index+48);
259 if (trginput) return trginput->GetName();
262 //______________________________________________________________________________
263 TString AliESDHeader::GetActiveTriggerInputs() const
265 // Returns the list with the names of the active trigger inputs
267 for(Int_t i = 0; i < kNTriggerInputs; i++) {
268 TNamed *str = (TNamed *)((fTriggerInputsNames).At(i));
271 trginputs += str->GetName();
278 //______________________________________________________________________________
279 TString AliESDHeader::GetFiredTriggerInputs() const
281 // Returns the list with the names of the fired trigger inputs
283 for(Int_t i = 0; i < kNTriggerInputs; i++) {
284 TNamed *str = (TNamed *)((fTriggerInputsNames.At(i)));
285 if (i < 24 && (fL0TriggerInputs & (1ul << i))) {
288 trginputs += str->GetName();
292 if (i >= 24 && i < 48 && (fL1TriggerInputs & (1ul << (i-24)))) {
295 trginputs += str->GetName();
299 if (i >= 48 && (fL2TriggerInputs & (1u << (i-48)))) {
302 trginputs += str->GetName();
310 //______________________________________________________________________________
311 Bool_t AliESDHeader::IsTriggerInputFired(const char *name) const
313 // Checks if the trigger input is fired
315 TNamed *trginput = (TNamed *)fTriggerInputsNames.FindObject(name);
316 if (trginput == 0) return kFALSE;
318 Int_t inputIndex = fTriggerInputsNames.IndexOf(trginput);
319 if (inputIndex < 0) return kFALSE;
322 if (fL0TriggerInputs & (1lu << inputIndex)) return kTRUE;
323 } else if(inputIndex < 48){
324 if (fL1TriggerInputs & (1lu << (inputIndex-24))) return kTRUE;
325 } else if(inputIndex < 60){
326 if (fL2TriggerInputs & (1u << (inputIndex-48))) return kTRUE;
329 AliError(Form("Index (%d) is outside the allowed range (0,59)!",inputIndex));
334 //________________________________________________________________________________
335 Int_t AliESDHeader::GetTriggerIREntries(Int_t int1, Int_t int2, Float_t deltaTime) const
337 // returns number of IR-s within time window deltaTime
338 // all possible combinations of int1 and int2 int1 - zdc bit, int2 v0 bit
340 const AliTriggerIR *IR;
342 Int_t nIR = GetTriggerIREntries();
343 UInt_t orbit1 = GetOrbitNumber();
344 const Double_t ot=0.0889218; //orbit time msec
345 Float_t timediff; // time difference between orbits (msec)
350 for(Int_t i=0;i<nIR;i++){//1
353 UInt_t orbit2 = IR->GetOrbit();
354 timediff = (orbit2<=orbit1) ? (Float_t)((orbit1-orbit2))*ot :
355 (Float_t)((16777215-orbit1+orbit2))*ot;
356 if (timediff>deltaTime) continue; //timediff outside time window
357 if((int1&int2) == -1){ //ignore both bits, just count IR-s within time window
361 // now check if int1, int2 bits are set
362 UInt_t nw = IR->GetNWord();
363 Bool_t *bint1 = IR->GetInt1s();
364 Bool_t *bint2 = IR->GetInt2s();
369 for(UInt_t j=0;j<nw;j++){//2
370 if(bint1[j]) flag1=1; // at least one int1 set
371 if(bint2[j]) flag2=1; // at least one int2 set
372 //printf("IR %d, bint1 %d, bint2 %d\n",i,bint1[j],bint2[j]);
374 // checking combinations
377 if((flag1*int1*flag2*int2)==1){// int1=1 & int2=1
381 if(int1 == -1){// ignore int1
382 if(flag2&int2){// int2=1
386 else if (!flag2&!int2){ //int2=0
392 if(int2 ==-1){//ignore int2
393 if(flag1&int1){//int1=1
397 else if(!flag1&!int1){ //int1=0
403 if((flag1*int1)&!flag2&!int2){// int1=1, int2=0
408 if((int2*flag2)&!int1&!flag1){// int1=0, int2=1
419 //__________________________________________________________________________
420 TObjArray AliESDHeader::GetIRArray(Int_t int1, Int_t int2, Float_t deltaTime) const
423 // returns an array of IR-s within time window deltaTime
424 // all possible combinations of int1 and int2 int1 - zdc bit, int2 v0 bit
426 const AliTriggerIR *IR;
429 Int_t nIR = GetTriggerIREntries();
430 UInt_t orbit1 = GetOrbitNumber();
431 const Double_t ot=0.0889218; //orbit time msec
432 Float_t timediff; // time difference between orbits (msec)
435 for(Int_t i=0;i<nIR;i++){//1
438 UInt_t orbit2 = IR->GetOrbit();
439 timediff = (orbit2<=orbit1) ? (Float_t)((orbit1-orbit2))*ot :
440 (Float_t)((16777215-orbit1+orbit2))*ot;
441 if (timediff>deltaTime) continue; //timediff outside time window
442 if((int1&int2) == -1){ //ignore both bits, just count IR-s within time window
443 arr.Add((AliTriggerIR*)IR); //add this IR
446 // now check if int1, int2 bits are set
447 UInt_t nw = IR->GetNWord();
448 Bool_t *bint1 = IR->GetInt1s();
449 Bool_t *bint2 = IR->GetInt2s();
454 for(UInt_t j=0;j<nw;j++){//2
455 if(bint1[j]) flag1=1; // at least one int1 set
456 if(bint2[j]) flag2=1; // at least one int2 set
458 // checking combinations
460 if((flag1*int1*flag2*int2)==1){// int1=1 & int2=1
461 arr.Add((AliTriggerIR*)IR); //add this IR
464 if(int1 == -1){// ignore int1
465 if(flag2&int2){// int2=1
466 arr.Add((AliTriggerIR*)IR); //add this IR
469 else if (!flag2&!int2){ //int2=0
470 arr.Add((AliTriggerIR*)IR); //add this IR
474 if(int2 ==-1){//ignore int2
475 if(flag1&int1){//int1=1
476 arr.Add((AliTriggerIR*)IR); //add this IR
479 else if(!flag1&!int1){ //int1=0
480 arr.Add((AliTriggerIR*)IR); //add this IR
484 if ((flag1*int1)&!flag2&!int2){// int1=1, int2=0
485 arr.Add((AliTriggerIR*)IR); //add this IR
488 if ((int2*flag2)&!int1&!flag1){// int1=0, int2=1
489 arr.Add((AliTriggerIR*)IR); //add this IR
498 //__________________________________________________________________________
499 void AliESDHeader::SetIRInteractionMap() const
502 // Function to compute the map of interations
503 // within 0TVX (int2) or V0A&V0C (int1) and the Event Id
504 // Note, the zero value is excluded
506 const AliTriggerIR *ir[5] = {GetTriggerIR(0),GetTriggerIR(1),GetTriggerIR(2),GetTriggerIR(3),GetTriggerIR(4)};
508 Long64_t orb = (Long64_t)GetOrbitNumber();
509 Long64_t bc = (Long64_t)GetBunchCrossNumber();
511 Long64_t evId = orb*3564 + bc;
513 for(Int_t i = 0; i < 5; ++i) {
514 if (ir[i] == NULL || ir[i]->GetNWord() == 0) continue;
515 Long64_t irOrb = (Long64_t)ir[i]->GetOrbit();
516 Bool_t* int2 = ir[i]->GetInt2s();
517 Bool_t* int1 = ir[i]->GetInt1s();
518 UShort_t* bcs = ir[i]->GetBCs();
519 for(UInt_t nW = 0; nW < ir[i]->GetNWord(); ++nW) {
520 Long64_t intId = irOrb*3564 + (Long64_t)bcs[nW];
521 if (int2[nW] == kTRUE) {
522 Int_t item = (intId-evId);
523 Int_t bin = FindIRIntInteractionsBXMap(item);
525 fIRInt2InteractionsMap.SetBitNumber(bin,kTRUE);
528 if (int1[nW] == kTRUE) {
529 Int_t item = (intId-evId);
530 Int_t bin = FindIRIntInteractionsBXMap(item);
532 fIRInt1InteractionsMap.SetBitNumber(bin,kTRUE);
538 fIRInt2InteractionsMap.Compact();
539 fIRInt1InteractionsMap.Compact();
542 //__________________________________________________________________________
543 Int_t AliESDHeader::FindIRIntInteractionsBXMap(Int_t difference) const
546 // The mapping is of 181 bits, from -90 to +90
550 if(difference<-90 || difference>90) return bin;
551 else { bin = 90 + difference; }
556 //__________________________________________________________________________
557 Int_t AliESDHeader::GetIRInt2ClosestInteractionMap() const
560 // Calculation of the closest interaction
562 SetIRInteractionMap();
564 Int_t firstNegative=100;
565 for(Int_t item=-1; item>=-90; item--) {
566 Int_t bin = FindIRIntInteractionsBXMap(item);
567 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
569 firstNegative = item;
573 Int_t firstPositive=100;
574 for(Int_t item=1; item<=90; item++) {
575 Int_t bin = FindIRIntInteractionsBXMap(item);
576 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
578 firstPositive = item;
583 Int_t closest = firstPositive < TMath::Abs(firstNegative) ? firstPositive : TMath::Abs(firstNegative);
584 if(firstPositive==100 && firstNegative==100) closest=0;
588 //__________________________________________________________________________
589 Int_t AliESDHeader::GetIRInt1ClosestInteractionMap(Int_t gap) const
592 // Calculation of the closest interaction
593 // In case of VZERO (Int1) one has to introduce a gap
594 // in order to avoid false positivies from after-pulses
596 SetIRInteractionMap();
598 Int_t firstNegative=100;
599 for(Int_t item=-1; item>=-90; item--) {
600 Int_t bin = FindIRIntInteractionsBXMap(item);
601 Bool_t isFired = fIRInt1InteractionsMap.TestBitNumber(bin);
603 firstNegative = item;
607 Int_t firstPositive=100;
608 for(Int_t item=1+gap; item<=90; item++) {
609 Int_t bin = FindIRIntInteractionsBXMap(item);
610 Bool_t isFired = fIRInt1InteractionsMap.TestBitNumber(bin);
612 firstPositive = item;
617 Int_t closest = firstPositive < TMath::Abs(firstNegative) ? firstPositive : TMath::Abs(firstNegative);
618 if(firstPositive==100 && firstNegative==100) closest=0;
622 //__________________________________________________________________________
623 Int_t AliESDHeader::GetIRInt2LastInteractionMap() const
626 // Calculation of the last interaction
628 SetIRInteractionMap();
630 Int_t lastNegative=0;
631 for(Int_t item=-90; item<=-1; item++) {
632 Int_t bin = FindIRIntInteractionsBXMap(item);
633 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
639 Int_t lastPositive=0;
640 for(Int_t item=90; item>=1; item--) {
641 Int_t bin = FindIRIntInteractionsBXMap(item);
642 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
649 Int_t last = lastPositive > TMath::Abs(lastNegative) ? lastPositive : TMath::Abs(lastNegative);