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() :
41 fEventNumberInFile(0),
48 fTriggerScalersDeltaEvent(),
49 fTriggerScalersDeltaRun(),
50 fTriggerInputsNames(kNTriggerInputs),
53 fIRInt2InteractionsMap(0),
54 fIRInt1InteractionsMap(0)
56 // default constructor
58 SetName("AliESDHeader");
59 for(Int_t i = 0; i<kNMaxIR ; i++) fIRArray[i] = 0;
60 fTriggerInputsNames.SetOwner(kTRUE);
63 AliESDHeader::~AliESDHeader()
66 for(Int_t i=0;i<kNMaxIR;i++)if(fIRArray[i])delete fIRArray[i];
69 fIRBufferArray.Delete();
73 AliESDHeader::AliESDHeader(const AliESDHeader &header) :
75 fTriggerMask(header.fTriggerMask),
76 fOrbitNumber(header.fOrbitNumber),
77 fTimeStamp(header.fTimeStamp),
78 fEventType(header.fEventType),
79 fEventSpecie(header.fEventSpecie),
80 fPeriodNumber(header.fPeriodNumber),
81 fEventNumberInFile(header.fEventNumberInFile),
82 fBunchCrossNumber(header.fBunchCrossNumber),
83 fTriggerCluster(header.fTriggerCluster),
84 fL0TriggerInputs(header.fL0TriggerInputs),
85 fL1TriggerInputs(header.fL1TriggerInputs),
86 fL2TriggerInputs(header.fL2TriggerInputs),
87 fTriggerScalers(header.fTriggerScalers),
88 fTriggerScalersDeltaEvent(header.fTriggerScalersDeltaEvent),
89 fTriggerScalersDeltaRun(header.fTriggerScalersDeltaRun),
90 fTriggerInputsNames(TObjArray(kNTriggerInputs)),
91 fCTPConfig(header.fCTPConfig),
93 fIRInt2InteractionsMap(header.fIRInt2InteractionsMap),
94 fIRInt1InteractionsMap(header.fIRInt1InteractionsMap)
97 for(Int_t i = 0; i<kNMaxIR ; i++) {
98 if(header.fIRArray[i])fIRArray[i] = new AliTriggerIR(*header.fIRArray[i]);
101 for(Int_t i = 0; i < kNTriggerInputs; i++) {
102 TNamed *str = (TNamed *)((header.fTriggerInputsNames).At(i));
103 if (str) fTriggerInputsNames.AddAt(new TNamed(*str),i);
106 for(Int_t i = 0; i < (header.fIRBufferArray).GetEntries(); ++i) {
107 AliTriggerIR *ir = (AliTriggerIR*)((header.fIRBufferArray).At(i));
108 if (ir) fIRBufferArray.Add(new AliTriggerIR(*ir));
112 AliESDHeader& AliESDHeader::operator=(const AliESDHeader &header)
114 // assigment operator
116 AliVHeader::operator=(header);
117 fTriggerMask = header.fTriggerMask;
118 fOrbitNumber = header.fOrbitNumber;
119 fTimeStamp = header.fTimeStamp;
120 fEventType = header.fEventType;
121 fEventSpecie = header.fEventSpecie;
122 fPeriodNumber = header.fPeriodNumber;
123 fEventNumberInFile = header.fEventNumberInFile;
124 fBunchCrossNumber = header.fBunchCrossNumber;
125 fTriggerCluster = header.fTriggerCluster;
126 fL0TriggerInputs = header.fL0TriggerInputs;
127 fL1TriggerInputs = header.fL1TriggerInputs;
128 fL2TriggerInputs = header.fL2TriggerInputs;
129 fTriggerScalers = header.fTriggerScalers;
130 fTriggerScalersDeltaEvent = header.fTriggerScalersDeltaEvent;
131 fTriggerScalersDeltaRun = header.fTriggerScalersDeltaRun;
132 fIRInt2InteractionsMap = header.fIRInt2InteractionsMap;
133 fIRInt1InteractionsMap = header.fIRInt1InteractionsMap;
136 fCTPConfig = header.fCTPConfig;
138 fTriggerInputsNames.Clear();
139 for(Int_t i = 0; i < kNTriggerInputs; i++) {
140 TNamed *str = (TNamed *)((header.fTriggerInputsNames).At(i));
141 if (str) fTriggerInputsNames.AddAt(new TNamed(*str),i);
143 for(Int_t i = 0; i<kNMaxIR ; i++) {
145 if(header.fIRArray[i])fIRArray[i] = new AliTriggerIR(*header.fIRArray[i]);
149 fIRBufferArray.Delete();
150 for(Int_t i = 0; i < (header.fIRBufferArray).GetEntries(); ++i) {
151 AliTriggerIR *ir = (AliTriggerIR*)((header.fIRBufferArray).At(i));
152 if (ir) fIRBufferArray.Add(new AliTriggerIR(*ir));
158 void AliESDHeader::Copy(TObject &obj) const
160 // this overwrites the virtual TOBject::Copy()
161 // to allow run time copying without casting
164 if(this==&obj)return;
165 AliESDHeader *robj = dynamic_cast<AliESDHeader*>(&obj);
166 if(!robj)return; // not an AliESDHeader
170 //______________________________________________________________________________
171 void AliESDHeader::Reset()
173 // reset all data members
180 fEventNumberInFile = 0;
181 fBunchCrossNumber = 0;
183 fL0TriggerInputs = 0;
184 fL1TriggerInputs = 0;
185 fL2TriggerInputs = 0;
186 fTriggerScalers.Reset();
187 fTriggerScalersDeltaEvent.Reset();
188 fTriggerScalersDeltaRun.Reset();
189 fTriggerInputsNames.Clear();
191 fIRInt2InteractionsMap.ResetAllBits();
192 fIRInt1InteractionsMap.ResetAllBits();
196 for(Int_t i=0;i<kNMaxIR;i++)if(fIRArray[i]){
201 fIRBufferArray.Delete();
203 //______________________________________________________________________________
204 Bool_t AliESDHeader::AddTriggerIR(const AliTriggerIR* ir)
206 // Add an IR object into the array
207 // of IRs in the ESD header
209 fIRBufferArray.Add(new AliTriggerIR(*ir));
213 //______________________________________________________________________________
214 void AliESDHeader::Print(const Option_t *) const
216 // Print some data members
217 printf("Event # %d in file Bunch crossing # %d Orbit # %d Trigger %lld \n",
218 GetEventNumberInFile(),
219 GetBunchCrossNumber(),
222 printf("List of the active trigger inputs: ");
223 for(Int_t i = 0; i < kNTriggerInputs; i++) {
224 TNamed *str = (TNamed *)((fTriggerInputsNames).At(i));
225 if (str) printf("%s ",str->GetName());
230 //______________________________________________________________________________
231 void AliESDHeader::SetActiveTriggerInputs(const char*name, Int_t index)
233 // Fill the active trigger inputs names
234 // into the corresponding fTriggerInputsNames (TObjArray of TNamed)
235 if (index >= kNTriggerInputs || index < 0) {
236 AliError(Form("Index (%d) is outside the allowed range (0,59)!",index));
240 fTriggerInputsNames.AddAt(new TNamed(name,NULL),index);
242 //______________________________________________________________________________
243 const char* AliESDHeader::GetTriggerInputName(Int_t index, Int_t trglevel) const
245 // Get the trigger input name
246 // at the specified position in the trigger mask and trigger level (0,1,2)
247 TNamed *trginput = 0;
248 if (trglevel == 0) trginput = (TNamed *)fTriggerInputsNames.At(index);
249 if (trglevel == 1) trginput = (TNamed *)fTriggerInputsNames.At(index+24);
250 if (trglevel == 2) trginput = (TNamed *)fTriggerInputsNames.At(index+48);
251 if (trginput) return trginput->GetName();
254 //______________________________________________________________________________
255 TString AliESDHeader::GetActiveTriggerInputs() const
257 // Returns the list with the names of the active trigger inputs
259 for(Int_t i = 0; i < kNTriggerInputs; i++) {
260 TNamed *str = (TNamed *)((fTriggerInputsNames).At(i));
263 trginputs += str->GetName();
270 //______________________________________________________________________________
271 TString AliESDHeader::GetFiredTriggerInputs() const
273 // Returns the list with the names of the fired trigger inputs
275 for(Int_t i = 0; i < kNTriggerInputs; i++) {
276 TNamed *str = (TNamed *)((fTriggerInputsNames.At(i)));
277 if (i < 24 && (fL0TriggerInputs & (1 << i))) {
280 trginputs += str->GetName();
284 if (i >= 24 && i < 48 && (fL1TriggerInputs & (1 << (i-24)))) {
287 trginputs += str->GetName();
291 if (i >= 48 && (fL2TriggerInputs & (1 << (i-48)))) {
294 trginputs += str->GetName();
302 //______________________________________________________________________________
303 Bool_t AliESDHeader::IsTriggerInputFired(const char *name) const
305 // Checks if the trigger input is fired
307 TNamed *trginput = (TNamed *)fTriggerInputsNames.FindObject(name);
308 if (!trginput) return kFALSE;
310 Int_t inputIndex = fTriggerInputsNames.IndexOf(trginput);
311 if (inputIndex < 0) return kFALSE;
313 if (fL0TriggerInputs & (1 << inputIndex)) return kTRUE;
314 else if (fL1TriggerInputs & (1 << (inputIndex-24))) return kTRUE;
315 else if (fL2TriggerInputs & (1 << (inputIndex-48))) return kTRUE;
318 //________________________________________________________________________________
319 Int_t AliESDHeader::GetTriggerIREntries(Int_t int1, Int_t int2, Float_t deltaTime) const
321 // returns number of IR-s within time window deltaTime
322 // all possible combinations of int1 and int2 int1 - zdc bit, int2 v0 bit
324 const AliTriggerIR *IR;
326 Int_t nIR = GetTriggerIREntries();
327 UInt_t orbit1 = GetOrbitNumber();
328 const Double_t ot=0.0889218; //orbit time msec
329 Float_t timediff; // time difference between orbits (msec)
334 for(Int_t i=0;i<nIR;i++){//1
337 UInt_t orbit2 = IR->GetOrbit();
338 timediff = (orbit2<=orbit1) ? (Float_t)((orbit1-orbit2))*ot :
339 (Float_t)((16777215-orbit1+orbit2))*ot;
340 if (timediff>deltaTime) continue; //timediff outside time window
341 if((int1&int2) == -1){ //ignore both bits, just count IR-s within time window
345 // now check if int1, int2 bits are set
346 UInt_t nw = IR->GetNWord();
347 Bool_t *bint1 = IR->GetInt1s();
348 Bool_t *bint2 = IR->GetInt2s();
353 for(UInt_t j=0;j<nw;j++){//2
354 if(bint1[j]) flag1=1; // at least one int1 set
355 if(bint2[j]) flag2=1; // at least one int2 set
356 //printf("IR %d, bint1 %d, bint2 %d\n",i,bint1[j],bint2[j]);
358 // checking combinations
361 if((flag1*int1*flag2*int2)==1){// int1=1 & int2=1
365 if(int1 == -1){// ignore int1
366 if(flag2&int2){// int2=1
370 else if (!flag2&!int2){ //int2=0
376 if(int2 ==-1){//ignore int2
377 if(flag1&int1){//int1=1
381 else if(!flag1&!int1){ //int1=0
387 if((flag1*int1)&!flag2&!int2){// int1=1, int2=0
392 if((int2*flag2)&!int1&!flag1){// int1=0, int2=1
403 //__________________________________________________________________________
404 TObjArray AliESDHeader::GetIRArray(Int_t int1, Int_t int2, Float_t deltaTime) const
407 // returns an array of IR-s within time window deltaTime
408 // all possible combinations of int1 and int2 int1 - zdc bit, int2 v0 bit
410 const AliTriggerIR *IR;
413 Int_t nIR = GetTriggerIREntries();
414 UInt_t orbit1 = GetOrbitNumber();
415 const Double_t ot=0.0889218; //orbit time msec
416 Float_t timediff; // time difference between orbits (msec)
419 for(Int_t i=0;i<nIR;i++){//1
422 UInt_t orbit2 = IR->GetOrbit();
423 timediff = (orbit2<=orbit1) ? (Float_t)((orbit1-orbit2))*ot :
424 (Float_t)((16777215-orbit1+orbit2))*ot;
425 if (timediff>deltaTime) continue; //timediff outside time window
426 if((int1&int2) == -1){ //ignore both bits, just count IR-s within time window
427 arr.Add((AliTriggerIR*)IR); //add this IR
430 // now check if int1, int2 bits are set
431 UInt_t nw = IR->GetNWord();
432 Bool_t *bint1 = IR->GetInt1s();
433 Bool_t *bint2 = IR->GetInt2s();
438 for(UInt_t j=0;j<nw;j++){//2
439 if(bint1[j]) flag1=1; // at least one int1 set
440 if(bint2[j]) flag2=1; // at least one int2 set
442 // checking combinations
444 if((flag1*int1*flag2*int2)==1){// int1=1 & int2=1
445 arr.Add((AliTriggerIR*)IR); //add this IR
448 if(int1 == -1){// ignore int1
449 if(flag2&int2){// int2=1
450 arr.Add((AliTriggerIR*)IR); //add this IR
453 else if (!flag2&!int2){ //int2=0
454 arr.Add((AliTriggerIR*)IR); //add this IR
458 if(int2 ==-1){//ignore int2
459 if(flag1&int1){//int1=1
460 arr.Add((AliTriggerIR*)IR); //add this IR
463 else if(!flag1&!int1){ //int1=0
464 arr.Add((AliTriggerIR*)IR); //add this IR
468 if ((flag1*int1)&!flag2&!int2){// int1=1, int2=0
469 arr.Add((AliTriggerIR*)IR); //add this IR
472 if ((int2*flag2)&!int1&!flag1){// int1=0, int2=1
473 arr.Add((AliTriggerIR*)IR); //add this IR
482 //__________________________________________________________________________
483 void AliESDHeader::SetIRInteractionMap() const
486 // Function to compute the map of interations
487 // within 0TVX (int2) or V0A&V0C (int1) and the Event Id
488 // Note, the zero value is excluded
490 const AliTriggerIR *ir[5] = {GetTriggerIR(0),GetTriggerIR(1),GetTriggerIR(2),GetTriggerIR(3),GetTriggerIR(4)};
492 Long64_t orb = (Long64_t)GetOrbitNumber();
493 Long64_t bc = (Long64_t)GetBunchCrossNumber();
495 Long64_t evId = orb*3564 + bc;
497 for(Int_t i = 0; i < 5; ++i) {
498 if (ir[i] == NULL || ir[i]->GetNWord() == 0) continue;
499 Long64_t irOrb = (Long64_t)ir[i]->GetOrbit();
500 Bool_t* int2 = ir[i]->GetInt2s();
501 Bool_t* int1 = ir[i]->GetInt1s();
502 UShort_t* bcs = ir[i]->GetBCs();
503 for(UInt_t nW = 0; nW < ir[i]->GetNWord(); ++nW) {
504 Long64_t intId = irOrb*3564 + (Long64_t)bcs[nW];
505 if (int2[nW] == kTRUE) {
506 Int_t item = (intId-evId);
507 Int_t bin = FindIRIntInteractionsBXMap(item);
509 fIRInt2InteractionsMap.SetBitNumber(bin,kTRUE);
512 if (int1[nW] == kTRUE) {
513 Int_t item = (intId-evId);
514 Int_t bin = FindIRIntInteractionsBXMap(item);
516 fIRInt1InteractionsMap.SetBitNumber(bin,kTRUE);
522 fIRInt2InteractionsMap.Compact();
523 fIRInt1InteractionsMap.Compact();
526 //__________________________________________________________________________
527 Int_t AliESDHeader::FindIRIntInteractionsBXMap(Int_t difference) const
530 // The mapping is of 181 bits, from -90 to +90
534 if(difference<-90 || difference>90) return bin;
535 else { bin = 90 + difference; }
540 //__________________________________________________________________________
541 Int_t AliESDHeader::GetIRInt2ClosestInteractionMap() const
544 // Calculation of the closest interaction
546 SetIRInteractionMap();
548 Int_t firstNegative=100;
549 for(Int_t item=-1; item>=-90; item--) {
550 Int_t bin = FindIRIntInteractionsBXMap(item);
551 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
553 firstNegative = item;
557 Int_t firstPositive=100;
558 for(Int_t item=1; item<=90; item++) {
559 Int_t bin = FindIRIntInteractionsBXMap(item);
560 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
562 firstPositive = item;
567 Int_t closest = firstPositive < TMath::Abs(firstNegative) ? firstPositive : TMath::Abs(firstNegative);
568 if(firstPositive==100 && firstNegative==100) closest=0;
572 //__________________________________________________________________________
573 Int_t AliESDHeader::GetIRInt1ClosestInteractionMap(Int_t gap) const
576 // Calculation of the closest interaction
577 // In case of VZERO (Int1) one has to introduce a gap
578 // in order to avoid false positivies from after-pulses
580 SetIRInteractionMap();
582 Int_t firstNegative=100;
583 for(Int_t item=-1; item>=-90; item--) {
584 Int_t bin = FindIRIntInteractionsBXMap(item);
585 Bool_t isFired = fIRInt1InteractionsMap.TestBitNumber(bin);
587 firstNegative = item;
591 Int_t firstPositive=100;
592 for(Int_t item=1+gap; item<=90; item++) {
593 Int_t bin = FindIRIntInteractionsBXMap(item);
594 Bool_t isFired = fIRInt1InteractionsMap.TestBitNumber(bin);
596 firstPositive = item;
601 Int_t closest = firstPositive < TMath::Abs(firstNegative) ? firstPositive : TMath::Abs(firstNegative);
602 if(firstPositive==100 && firstNegative==100) closest=0;
606 //__________________________________________________________________________
607 Int_t AliESDHeader::GetIRInt2LastInteractionMap() const
610 // Calculation of the last interaction
612 SetIRInteractionMap();
614 Int_t lastNegative=0;
615 for(Int_t item=-90; item<=-1; item++) {
616 Int_t bin = FindIRIntInteractionsBXMap(item);
617 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
623 Int_t lastPositive=0;
624 for(Int_t item=90; item>=1; item--) {
625 Int_t bin = FindIRIntInteractionsBXMap(item);
626 Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
633 Int_t last = lastPositive > TMath::Abs(lastNegative) ? lastPositive : TMath::Abs(lastNegative);