Missing code protection (Plamen)
[u/mrichter/AliRoot.git] / STEER / STEER / AliTriggerRunScalers.cxx
CommitLineData
e39e51f6 1/**************************************************************************
d7dd8a54 2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id: AliTriggerRunScalers.cxx 22322 2007-11-22 11:43:14Z cvetan $ */
17
18///////////////////////////////////////////////////////////////////////////////
19//
20// Class to define the ALICE Trigger Scalers Record per Run.
d07a9211 21// ReadScalers(): read the txt file (rXXXX.cnt) provided by CTP and creates array of records.
22// ConsistencyCheck(): checks if the last scaler added to record is consistent,
23// i.e. time increases and valued are not decreasing in time.
24//
d7dd8a54 25//
26//////////////////////////////////////////////////////////////////////////////
27
c180f65d 28#include <stdlib.h>
d7dd8a54 29#include <Riostream.h>
d07a9211 30
31//#include <TObject.h>
32//#include <TArrayC.h>
33//#include <TFile.h>
d7dd8a54 34#include <TClass.h>
d7dd8a54 35#include <TSystem.h>
36#include <TObjString.h>
37#include <TObjArray.h>
7f66b913 38#include <TMath.h>
39#include <TGraphErrors.h>
d7dd8a54 40
41#include "AliLog.h"
42#include "AliTimeStamp.h"
43#include "AliTriggerScalers.h"
6441c2a8 44#include "AliTriggerScalersESD.h"
d7dd8a54 45#include "AliTriggerScalersRecord.h"
6441c2a8 46#include "AliTriggerScalersRecordESD.h"
d7dd8a54 47#include "AliTriggerRunScalers.h"
7f66b913 48#include "AliTriggerConfiguration.h"
49#include "AliTriggerClass.h"
50#include "AliTriggerBCMask.h"
d7dd8a54 51
52ClassImp( AliTriggerRunScalers )
53
54//_____________________________________________________________________________
55AliTriggerRunScalers::AliTriggerRunScalers():
56 TObject(),
57 fVersion(0),
58 fRunNumber(0),
59 fnClasses(0),
60 fClassIndex(),
bf7443cc 61 fScalersRecord(),
62 fScalersRecordESD()
d7dd8a54 63{
64 // Default constructor
65}
7eaf72df 66//______________________________________________________________________________
67AliTriggerRunScalers::~AliTriggerRunScalers()
68{
69 // Destructor
70 fScalersRecord.SetOwner();
71 fScalersRecord.Delete();
72 fScalersRecordESD.SetOwner();
73 fScalersRecordESD.Delete();
74}
d7dd8a54 75//_____________________________________________________________________________
76void AliTriggerRunScalers::AddTriggerScalers( AliTriggerScalersRecord* scaler )
77{
d07a9211 78 // Add scaler and check consistency
e39e51f6 79 fScalersRecord.AddLast( scaler );
74135182 80 UInt_t* overflow[6];
81 for(Int_t i=0; i<6; i++) {
82 overflow[i] = new UInt_t[fnClasses];
83 for(Int_t j=0; j<fnClasses; j++) overflow[i][j] = 0;
84 }
85 if (AliTriggerRunScalers::ConsistencyCheck(fScalersRecord.GetEntriesFast()-1,kFALSE,overflow)){
a93ccff3 86 AliErrorClass("Trigger counters not in the right order or decreasing!");
87 // scaler->Print();
88 // fScalersRecord.Sort();
89 }
d7dd8a54 90}
bf7443cc 91//_____________________________________________________________________________
92
93AliTriggerRunScalers::AliTriggerRunScalers(const AliTriggerRunScalers &run) :
94 TObject(),
95 fVersion(run.fVersion),
96 fRunNumber(run.fRunNumber),
97 fnClasses(run.fnClasses),
98 fClassIndex(),
99 fScalersRecord(),
100 fScalersRecordESD()
101{
102// copy constructor
f379aa89 103 fClassIndex.Set(run.fClassIndex.GetSize());
bf7443cc 104for (Int_t i = 0; i < run.fClassIndex.GetSize(); i++) {
105 if (run.fClassIndex[i]) fClassIndex.AddAt(run.fClassIndex[i], i);
106 }
107for (Int_t i = 0; i < run.fScalersRecord.GetEntriesFast(); i++) {
108 if (run.fScalersRecord[i]) fScalersRecord.Add(run.fScalersRecord[i]->Clone());
109 }
110for (Int_t i = 0; i < run.fScalersRecordESD.GetEntriesFast(); i++) {
111 if (run.fScalersRecordESD[i]) fScalersRecordESD.Add(run.fScalersRecordESD[i]->Clone());
112 }
113
114}
115//_____________________________________________________________________________
116AliTriggerRunScalers &AliTriggerRunScalers::operator=(const AliTriggerRunScalers& run)
117{
118// assignment operator
119if(&run == this) return *this;
120((TObject *)this)->operator=(run);
121
122fVersion = run.fVersion;
123fRunNumber = run.fRunNumber;
124fnClasses = run.fnClasses;
d7dd8a54 125
bf7443cc 126for (Int_t i = 0; i < run.fClassIndex.GetSize(); i++) {
127 if (run.fClassIndex[i]) fClassIndex.AddAt(run.fClassIndex[i], i);
128 }
129for (Int_t i = 0; i < run.fScalersRecord.GetEntriesFast(); i++) {
130 if (run.fScalersRecord[i]) fScalersRecord.Add(run.fScalersRecord[i]->Clone());
131 }
132for (Int_t i = 0; i < run.fScalersRecordESD.GetEntriesFast(); i++) {
133 if (run.fScalersRecordESD[i]) fScalersRecordESD.Add(run.fScalersRecordESD[i]->Clone());
134 }
135return *this;
136}
d7dd8a54 137//_____________________________________________________________________________
138AliTriggerRunScalers* AliTriggerRunScalers::ReadScalers( TString & filename )
139{
d07a9211 140 // Read scalers from text file(.cnt) provided by CTP
141 // for given run and convert it to root format
d7dd8a54 142 if( gSystem->AccessPathName( filename.Data() ) ) {
143 AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
144 return NULL;
145 }
146
147 ifstream *file = new ifstream ( filename.Data() );
148 if (!*file) {
149 AliErrorClass(Form("Error opening file (%s) !\n",filename.Data()));
150 file->close();
151 delete file;
152 return NULL;
153 }
154
155 AliTriggerRunScalers* rScaler = new AliTriggerRunScalers();
156
157 TString strLine;
158 Bool_t verflag = kFALSE;
159 Bool_t classflag = kFALSE;
160 UChar_t nclass = 0;
161 while (strLine.ReadLine(*file)) {
162 if (strLine.BeginsWith("#")) continue;
163
164 TObjArray *tokens = strLine.Tokenize(" \t");
165 Int_t ntokens = tokens->GetEntriesFast();
166 // 1st line, version, it is one number,
167 if (!verflag) {
168 if (ntokens != 1) {
169 AliErrorClass( Form( "Error reading version number from (%s), line :%s\n",
170 filename.Data() , strLine.Data() ) );
171 return NULL;
172 }
173 // cout << "Version "<< ((TObjString*)tokens->At(0))->String().Atoi() << endl;
174 rScaler->SetVersion( ((TObjString*)tokens->At(0))->String().Atoi() );
175 verflag = kTRUE;
176 delete tokens;
177 continue;
178 }
179
180 // 2nd line, run number , number of classes, list of classes used in this partition
181
182 if (!classflag) {
183 if ( !((TObjString*)tokens->At(1))->String().IsDigit() ) {
184 AliErrorClass( Form( "Error reading Run number from (%s)\n", filename.Data() ));
185 }
186 // cout << "Run Number " << ((TObjString*)tokens->At(0))->String().Atoi() << endl;
187 rScaler->SetRunNumber( ((TObjString*)tokens->At(0))->String().Atoi() );
188 nclass = (UChar_t)((TObjString*)tokens->At(1))->String().Atoi();
189 // cout << "Number of classes " << nclass << endl;
190 rScaler->SetNumClasses( nclass );
191 if ( nclass != ntokens - 2 ) {
192 AliErrorClass( Form( "Error reading number of classes from (%s)\n", filename.Data() ));
193 }
194 for (UChar_t i=0; i<nclass; ++i) {
195 rScaler->SetClass( i, (Char_t)((TObjString*)tokens->At(2+i))->String().Atoi() );
196 }
197 classflag = kTRUE;
198 delete tokens;
199 continue;
200 }
201
202 // Records
203 // Each record consists of 1+(number of classes in partition) lines
204 // 1st line of record = time stamp (4 words)
205 // 1st word = ORBIT(24 bits)
206 // 2nd word = Period Counter (28 bit)
207 // 3rd word = seconds (32 bits) from epoch
208 // 4th word = microsecs (32 bits)
209 // other lines = 6 words of counters (L0 before,L0 after, ....)
210 if (ntokens != 4) {
211 AliErrorClass( Form( "Error reading timestamp from (%s): line (%s)",
212 filename.Data(), strLine.Data() ));
213 return NULL;
214 }
e39e51f6 215
216 UInt_t orbit = strtoul(((TObjString*)tokens->At(0))->String(), NULL, 10);
217 UInt_t period = strtoul(((TObjString*)tokens->At(1))->String(), NULL, 10);
218 UInt_t seconds = strtoul(((TObjString*)tokens->At(2))->String(), NULL, 10);
219 UInt_t microSecs = strtoul(((TObjString*)tokens->At(3))->String(), NULL, 10);
220
d7dd8a54 221 AliTriggerScalersRecord * rec = new AliTriggerScalersRecord();
222 rec->SetTimeStamp( orbit, period, seconds, microSecs );
d7dd8a54 223 TString strLine1;
224 for (Int_t i=0; i<nclass; ++i) {
225 strLine1.ReadLine(*file);
226 if (strLine1.BeginsWith("#")) continue;
227 TObjArray *tokens1 = strLine1.Tokenize(" \t");
228 Int_t ntokens1 = tokens1->GetEntriesFast();
229 if( ntokens1 != 6 ) {
29bdda4f 230 AliErrorClass( Form( "Error reading scalers from (%s): line (%s)",
231 filename.Data(), strLine1.Data() ));
232 delete rec;
233 return rScaler;
d7dd8a54 234 }
d5aaf775 235
236 UInt_t lOCB = strtoul(((TObjString*)tokens1->At(0))->String(), NULL, 10);
237 UInt_t lOCA = strtoul(((TObjString*)tokens1->At(1))->String(), NULL, 10);
238 UInt_t l1CB = strtoul(((TObjString*)tokens1->At(2))->String(), NULL, 10);
239 UInt_t l1CA = strtoul(((TObjString*)tokens1->At(3))->String(), NULL, 10);
240 UInt_t l2CB = strtoul(((TObjString*)tokens1->At(4))->String(), NULL, 10);
241 UInt_t l2CA = strtoul(((TObjString*)tokens1->At(5))->String(), NULL, 10);
e39e51f6 242
d7dd8a54 243 rScaler->GetClass(i);
244 rec->AddTriggerScalers( rScaler->GetClass(i),
d5aaf775 245 lOCB, lOCA, l1CB,
246 l1CA, l2CB, l2CA );
247
d7dd8a54 248 delete tokens1;
249 }
250 rScaler->AddTriggerScalers( rec );
251
252 delete tokens;
253 }
254 file->close();
255 delete file;
256
257 return rScaler;
258}
259
260//_____________________________________________________________________________
033d0f8e 261Int_t AliTriggerRunScalers::FindNearestScalersRecord( const AliTimeStamp *stamp ) const
d7dd8a54 262{
263 // Find Trigger scaler record with the closest timestamp <= "stamp"
264 // using a binary search.
265 // return the index in the array of records, if the timestamp
266 // is out of range return -1
267
268 Int_t base, position=-1, last, result = 0;
5dd39685 269 Int_t op2 = 0;
d7dd8a54 270
033d0f8e 271 //fScalersRecord.Sort();
d7dd8a54 272
273 base = 0;
274 last = fScalersRecord.GetEntriesFast();
275
276 while (last >= base) {
277 position = (base+last) / 2;
767e5649 278 AliDebug(1, Form("position= %d base= %d last= %d ",position,base,last));
d7dd8a54 279 AliTriggerScalersRecord* rec = (AliTriggerScalersRecord*)fScalersRecord.At(position);
5dd39685 280 if( rec && rec->GetTimeStamp()) op2 = 1;
281 if( op2 && (result = stamp->Compare(rec->GetTimeStamp())) == 0 )
0367cade 282 return position; // exact match
d7dd8a54 283 if (!op2 || result < 0)
284 last = position-1;
285 else
286 base = position+1;
5dd39685 287 op2 = 0;
d7dd8a54 288 }
289 if( (position == 0 && result < 0) || position >= fScalersRecord.GetEntriesFast() )
290 return -1; // out of range
291 else
292 return (result < 0 ) ? position-1 : position; // nearst < stamp
293}
e39e51f6 294//_____________________________________________________________________________
74135182 295Int_t AliTriggerRunScalers::ConsistencyCheck(Int_t position,Bool_t correctOverflow, UInt_t** overflow)
e39e51f6 296{
d07a9211 297 //Check if counters are consistent(increase). Example: lOCB(n) < lOCB(n+1) and lOCB > lOCA
6441c2a8 298 // scalers coding 0,1,2,3,4,5=0b,0a,1b,1a,2b,2a
47fde2cb 299 // returns:
300 // 1 = decresing time
301 // 2 = too big jump in scalers, looks like some readings are missing
302 // 3 = (level+1) > (level)
6441c2a8 303 if (position == 0){
a93ccff3 304 if(correctOverflow){
305 AliErrorClass("position=0\n");
306 return 1;
7f66b913 307 }else return 0; // to work correctly in AddScalers
a93ccff3 308 };
47fde2cb 309 UInt_t c2[6], c1[6];
6441c2a8 310 ULong64_t c64[6];
74135182 311 Bool_t increase[6];
312 for(Int_t i=0;i<6;i++){increase[i]=0;}
6441c2a8 313 ULong64_t const max1 = 4294967295ul; //32bit counters overflow after 4294967295
314 ULong64_t const max2 = 1000000000ul; //when counters overflow they seem to be decreasing. Assume decrease cannot be smaller than max2.
d07a9211 315
316 AliTriggerScalersRecord* scalers2 = (AliTriggerScalersRecord*)fScalersRecord.At(position);
317 AliTriggerScalersRecord* scalers1 = (AliTriggerScalersRecord*)fScalersRecord.At(position-1);
47fde2cb 318 if (scalers2->Compare((AliTriggerScalersRecord*)fScalersRecord.At(position-1)) == -1) return 1;
6441c2a8 319
320 AliTriggerScalersRecordESD* recESD = 0;
321 if(correctOverflow){
322 recESD = new AliTriggerScalersRecordESD();
268381f3 323 recESD->SetTimeStamp(scalers2->GetTimeStamp());
d07a9211 324 }
6441c2a8 325 for( Int_t ic=0; ic<fnClasses; ++ic ){
326 TObjArray* scalersArray2 = (TObjArray*)scalers2->GetTriggerScalers();
327 AliTriggerScalers* counters2 = (AliTriggerScalers*)scalersArray2->At(ic);
d9db8747 328 UChar_t iclass = counters2->GetClassIndex();
6441c2a8 329 counters2->GetAllScalers(c2);
330 TObjArray* scalersArray1 = (TObjArray*)scalers1->GetTriggerScalers();
331 AliTriggerScalers* counters1 = (AliTriggerScalers*)scalersArray1->At(ic);
332 counters1->GetAllScalers(c1);
a93ccff3 333 for(Int_t i=0;i<5;i++){
334 if ( c2[i] >= c1[i] ) increase[i]=1;
74135182 335 else if ( c2[i] < c1[i] && (c1[i] - c2[i]) > max2) overflow[i][ic]++;
6441c2a8 336 else return 2;
337 }
338 for(Int_t i=0;i<5;i++){
a93ccff3 339 if ((c2[i] - c1[i]) < (c2[i+1] - c1[i+1]) && increase[i] && increase[i+1] ) {
340 if ( ((c2[i+1] - c1[i+1]) - (c2[i] - c1[i])) < 16 ) {AliWarningClass("Trigger scaler Level[i+1] > Level[i]. Diff < 16!");}
341 else return 3; }
74135182 342 else if ( (max1 - c1[i]+c2[i]) < (c2[i+1] - c1[i+1]) && overflow[i][ic] && increase[i+1] ) {
a93ccff3 343 if ( ((c2[i+1] - c1[i+1]) - (max1 - c1[i]+c2[i])) < 16 ) {AliWarningClass("Trigger scaler Level[i+1] > Level[i]. Diff < 16!");}
344 else return 3; }
74135182 345 else if ( (c2[i] - c1[i]) < (max1 - c1[i+1] + c2[i+1]) && increase[i] && overflow[i+1][ic] ) {
a93ccff3 346 if ( ((max1 - c1[i+1] + c2[i+1]) - (c2[i] - c1[i])) < 16 ) {AliWarningClass("Trigger scaler Level[i+1] > Level[i]. Diff < 16!");}
347 else return 3; }
74135182 348 else if ( (max1 - c1[i] + c2[i] ) < (max1 - c1[i+1] + c2[i+1]) && overflow[i][ic] && overflow[i+1][ic] ) {
a93ccff3 349 if ( ((max1 - c1[i+1] + c2[i+1]) - (max1 - c1[i] + c2[i] )) < 16 ) {AliWarningClass("Trigger scaler Level[i+1] > Level[i]. Diff < 16!");}
350 else return 3; }
6441c2a8 351 }
a93ccff3 352 if(correctOverflow){
74135182 353 for(Int_t i=0;i<6;i++){ c64[i]=c2[i]+max1*overflow[i][ic]; }
d9db8747 354 AliTriggerScalersESD* s= new AliTriggerScalersESD(iclass,c64);
6441c2a8 355 recESD->AddTriggerScalers(s);
a93ccff3 356 }
357
6441c2a8 358 }
359 if(correctOverflow)fScalersRecordESD.AddLast(recESD);
360 return 0;
361}
362//____________________________________________________________________________
363Int_t AliTriggerRunScalers::CorrectScalersOverflow()
364{
365 // Run over fScalersRecord, check overflow using CheckConsistency methos
366 // and save corrected result in fScalersRecordESD.
ab26241b 367
368 // Temporary fix for the OCDB entries written with v4-16-Release
369 // where the wrong sorting was used
370 fScalersRecord.Sort();
6441c2a8 371 UInt_t c1[6];
372 ULong64_t c64[6];
373 AliTriggerScalersRecordESD* recESD = new AliTriggerScalersRecordESD();
374 // add 0
375 AliTriggerScalersRecord* scalers = (AliTriggerScalersRecord*)fScalersRecord.At(0);
7f66b913 376 recESD->SetTimeStamp(scalers->GetTimeStamp());
6441c2a8 377 for( Int_t ic=0; ic<fnClasses; ++ic ){
378 TObjArray* scalersArray = (TObjArray*)scalers->GetTriggerScalers();
379 AliTriggerScalers* counters = (AliTriggerScalers*)scalersArray->At(ic);
380 counters->GetAllScalers(c1);
d9db8747 381 UChar_t iclass = counters->GetClassIndex();
6441c2a8 382 for(Int_t i=0; i<6; i++)c64[i]=c1[i];
d9db8747 383 AliTriggerScalersESD* s= new AliTriggerScalersESD(iclass,c64);
6441c2a8 384 recESD->AddTriggerScalers(s);
385 }
386 fScalersRecordESD.AddLast(recESD);
74135182 387
388 UInt_t* overflow[6];
389 for(Int_t i=0; i<6; i++) {
390 overflow[i] = new UInt_t[fnClasses];
391 for(Int_t j=0; j<fnClasses; j++) overflow[i][j] = 0;
392 }
393
6441c2a8 394 for(Int_t i=1;i<fScalersRecord.GetEntriesFast(); i++){
74135182 395 if(ConsistencyCheck(i,kTRUE,overflow)){
a93ccff3 396 fScalersRecord.At(i)->Print();
397 fScalersRecord.At(i-1)->Print();
6441c2a8 398 fScalersRecordESD.SetOwner();
399 fScalersRecordESD.Delete();
400 AliErrorClass("Inconsistent scalers, they will not be provided.\n");
401 return 1;
402 }
403 }
404 if(fScalersRecordESD.GetEntriesFast() != fScalersRecord.GetEntriesFast()){
405 AliErrorClass("Internal error: #scalers ESD != #scalers \n");
406 return 1;
407 }
408 return 0;
409}
410//_____________________________________________________________________________
411AliTriggerScalersESD* AliTriggerRunScalers::GetScalersForEventClass(const AliTimeStamp* stamp,const Int_t classIndex) const
412{
413 // Find scalers for event for class in fScalersRecordESD
414 // Assumes that fScalerRecord = fScalerRecordESD
415 Int_t position = FindNearestScalersRecord(stamp);
416 if ( position == -1 ) {
417 AliErrorClass("Event AliTimeStamp out of range!");
418 return 0;
419 }
420 // check also position=max
421 AliTriggerScalersRecordESD* scalrec1 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(position);
422 AliTriggerScalersRecordESD* scalrec2 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(position+1);
423 TObjArray* scalers1 = (TObjArray*)scalrec1->GetTriggerScalers();
424 TObjArray* scalers2 = (TObjArray*)scalrec2->GetTriggerScalers();
0367cade 425
6441c2a8 426 if(scalers1->GetEntriesFast() != fnClasses){
427 AliErrorClass("Internal error: #classes in RecordESD != fnClasses\n");
428 return 0;
429 }
a93ccff3 430
6441c2a8 431 AliTriggerScalersESD *s1,*s2;
a93ccff3 432 for ( Int_t ic=0; ic < (Int_t)fnClasses; ++ic ){
433
6441c2a8 434 s1 = (AliTriggerScalersESD*)scalers1->At(ic);
435 s2 = (AliTriggerScalersESD*)scalers2->At(ic);
a93ccff3 436
6441c2a8 437 Bool_t classfound = (s1->GetClassIndex() == classIndex) && (s2->GetClassIndex() == classIndex);
438 if(classfound){
7f66b913 439 ULong64_t max = 16777216ul;
6441c2a8 440 AliTriggerScalersRecordESD* scalrec0 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(0);
441 TObjArray* scalers0 = (TObjArray*)scalrec0->GetTriggerScalers();
442 AliTriggerScalersESD *s0 = (AliTriggerScalersESD*)scalers0->At(ic);
443 ULong64_t base[6],c1[6],c2[6],cint[6];
444 ULong64_t orbit = max*(stamp->GetPeriod()) + stamp->GetOrbit();
445 s0->GetAllScalers(base);
446 s1->GetAllScalers(c1);
447 s2->GetAllScalers(c2);
448 ULong64_t orbit1 = max*(scalrec1->GetTimeStamp()->GetPeriod())+scalrec1->GetTimeStamp()->GetOrbit();
449 ULong64_t orbit2 = max*(scalrec2->GetTimeStamp()->GetPeriod())+scalrec2->GetTimeStamp()->GetOrbit();
450 for(Int_t i=0;i<6;i++){
451 Double_t slope=Double_t(c2[i]-c1[i])/Double_t(orbit2-orbit1);
452 cint[i]=ULong64_t(slope*(orbit-orbit1)) +c1[i] -base[i];
453 }
454 AliTriggerScalersESD* result = new AliTriggerScalersESD(classIndex,cint);
455 return result;
456 }
47fde2cb 457 }
6441c2a8 458 AliErrorClass(Form("Classindex %i not found.\n",classIndex));
47fde2cb 459 return 0;
e39e51f6 460}
7f66b913 461
462//_____________________________________________________________________________
463const AliTriggerScalersRecordESD* AliTriggerRunScalers::GetScalersDeltaForEvent(const AliTimeStamp* stamp) const
464{
465 // Find scalers for event for class in fScalersRecordESD
466 // Assumes that fScalerRecord = fScalerRecordESD
467 Int_t position = FindNearestScalersRecord(stamp);
468 if ( position == -1 ) {
469 AliErrorClass("Event AliTimeStamp out of range!");
470 return 0;
471 }
472 // check also position=max
eaf06408 473 if (fScalersRecordESD.GetEntriesFast()<2) return 0;
474
7f66b913 475 AliTriggerScalersRecordESD* scalrec1 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(position);
476 AliTriggerScalersRecordESD* scalrec2 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(position+1);
477 TObjArray* scalers1 = (TObjArray*)scalrec1->GetTriggerScalers();
478 TObjArray* scalers2 = (TObjArray*)scalrec2->GetTriggerScalers();
479
480 if(scalers1->GetEntriesFast() != fnClasses){
481 AliErrorClass("Internal error: #classes in RecordESD != fnClasses\n");
482 return 0;
483 }
484 AliTriggerScalersRecordESD *scalrec = new AliTriggerScalersRecordESD();
485 AliTriggerScalersESD *s1,*s2;
486 for ( Int_t ic=0; ic < (Int_t)fnClasses; ++ic ){
487
488 s1 = (AliTriggerScalersESD*)scalers1->At(ic);
489 s2 = (AliTriggerScalersESD*)scalers2->At(ic);
490
491 ULong64_t c1[6],c2[6],cint[6];
492 s1->GetAllScalers(c1);
493 s2->GetAllScalers(c2);
494 for(Int_t i=0;i<6;i++){
495 cint[i]=c2[i]-c1[i];
496 }
497 AliTriggerScalersESD* result = new AliTriggerScalersESD(s1->GetClassIndex(),cint);
498 scalrec->AddTriggerScalers(result);
499 }
500 UInt_t max = 16777216ul;
501 UInt_t orbit, period;
502
503 if (scalrec2->GetTimeStamp()->GetOrbit() > scalrec1->GetTimeStamp()->GetOrbit()) {
504 orbit = scalrec2->GetTimeStamp()->GetOrbit() - scalrec1->GetTimeStamp()->GetOrbit();
505 period = scalrec2->GetTimeStamp()->GetPeriod() - scalrec1->GetTimeStamp()->GetPeriod();
506 }
507 else {
508 orbit = max - (scalrec1->GetTimeStamp()->GetOrbit() - scalrec2->GetTimeStamp()->GetOrbit());
509 period = scalrec2->GetTimeStamp()->GetPeriod() - scalrec1->GetTimeStamp()->GetPeriod() - 1;
510 }
511
512 AliTimeStamp *timestamp = new AliTimeStamp(orbit, period, 0);
513 scalrec->SetTimeStamp(timestamp);
514 delete timestamp;
515 return scalrec;
516}
517//_____________________________________________________________________________
518const AliTriggerScalersRecordESD* AliTriggerRunScalers::GetScalersDeltaForRun() const
519{
520 // Find scalers for event for class in fScalersRecordESD
521 // Assumes that fScalerRecord = fScalerRecordESD
eaf06408 522 if (fScalersRecordESD.GetEntriesFast()<2) return 0;
523
7f66b913 524 AliTriggerScalersRecordESD* scalrec1 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(0);
525 AliTriggerScalersRecordESD* scalrec2 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(fScalersRecord.GetEntriesFast()-1);
526 TObjArray* scalers1 = (TObjArray*)scalrec1->GetTriggerScalers();
527 TObjArray* scalers2 = (TObjArray*)scalrec2->GetTriggerScalers();
528
529 if(scalers1->GetEntriesFast() != fnClasses){
530 AliErrorClass("Internal error: #classes in RecordESD != fnClasses\n");
531 return 0;
532 }
533 AliTriggerScalersESD *s1,*s2;
534 AliTriggerScalersRecordESD *scalrec = new AliTriggerScalersRecordESD();
535 for ( Int_t ic=0; ic < (Int_t)fnClasses; ++ic ){
536
537 s1 = (AliTriggerScalersESD*)scalers1->At(ic);
538 s2 = (AliTriggerScalersESD*)scalers2->At(ic);
539
540 ULong64_t c1[6],c2[6],cint[6];
541 s1->GetAllScalers(c1);
542 s2->GetAllScalers(c2);
543 for(Int_t i=0;i<6;i++){
544 cint[i]=c2[i]-c1[i];
545 }
546 AliTriggerScalersESD* result = new AliTriggerScalersESD(s1->GetClassIndex(),cint);
547 scalrec->AddTriggerScalers(result);
548 }
549 UInt_t max = 16777216ul;
550 UInt_t orbit, period;
551
552 if (scalrec2->GetTimeStamp()->GetOrbit() > scalrec1->GetTimeStamp()->GetOrbit()) {
553 orbit = scalrec2->GetTimeStamp()->GetOrbit() - scalrec1->GetTimeStamp()->GetOrbit();
554 period = scalrec2->GetTimeStamp()->GetPeriod() - scalrec1->GetTimeStamp()->GetPeriod();
555 }
556 else {
557 orbit = max - (scalrec1->GetTimeStamp()->GetOrbit() - scalrec2->GetTimeStamp()->GetOrbit());
558 period = scalrec2->GetTimeStamp()->GetPeriod() - scalrec1->GetTimeStamp()->GetPeriod() - 1;
559 }
560
561 AliTimeStamp *timestamp = new AliTimeStamp(orbit, period, 0);
562 scalrec->SetTimeStamp(timestamp);
563 delete timestamp;
564 return scalrec;
565}
566//_____________________________________________________________________________
eaf06408 567Bool_t AliTriggerRunScalers::CalculateMu(Double_t &mu, Double_t &errmu, ULong64_t countsB, ULong64_t countsAC, UShort_t nB, UShort_t nAC, UInt_t orbits, Bool_t bkgCorr, Double_t triggerEff, Double_t errorEff)
7f66b913 568{
569
570 if (nB!=0 && orbits!=0) {
eaf06408 571 Double_t pB = (Double_t)countsB/(nB*orbits); // probability for B trigger
572 if (!bkgCorr || nAC==0 ) {
573 mu = -log(1-pB)/triggerEff;
9e4f3acc 574 errmu = TMath::Sqrt(pB/((1-pB)*nB*orbits) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff)); //
eaf06408 575 return kTRUE;
576 }
7f66b913 577 else
578 {
eaf06408 579 Double_t pAC = (Double_t)countsAC/(nAC*orbits); // probability for AC trigger (background)
9e4f3acc 580 mu = ( log(1.-pAC) - log(1.-pB) )/triggerEff;
eaf06408 581 // error
9e4f3acc 582 errmu = TMath::Sqrt(pB/((1.-pB)*nB*orbits) + pAC/((1.-pAC)*nAC*orbits) /*- 2*TMath::Sqrt(pB*pAC/(nB*nAC*(1.-pB)*(1.-pAC)))/orbits*/ + mu*mu*errorEff*errorEff/(triggerEff*triggerEff)); // assume no correlation between B and AC rates, hence no cov term in error
eaf06408 583 return kTRUE;
7f66b913 584 }
585 }
eaf06408 586 return kFALSE;
7f66b913 587}
588//_____________________________________________________________________________
eaf06408 589Bool_t AliTriggerRunScalers::CalculateMu(Double_t &mu, Double_t &errmu, ULong64_t countsB, ULong64_t countsAC, ULong64_t beamB, UShort_t nB, UShort_t nAC, Bool_t bkgCorr, Double_t triggerEff, Double_t errorEff)
7f66b913 590{
591
592 if (beamB!=0) {
eaf06408 593 Double_t pB = (Double_t)countsB/beamB; // probability for B trigger
594 if (!bkgCorr || nAC==0 || nB==0) {
595 mu = -log(1-pB)/triggerEff;
9e4f3acc 596 errmu = TMath::Sqrt(pB/((1-pB)*beamB) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff)); //
eaf06408 597 return kTRUE;
598 }
599 else
7f66b913 600 {
eaf06408 601 Double_t pAC = (Double_t)countsAC/(nAC*beamB/nB); // probability for AC trigger (background)
602 mu = ( log(1-pAC) - log(1-pB) )/triggerEff;
603 // error
9e4f3acc 604 errmu = TMath::Sqrt(pB/((1-pB)*beamB) + pAC/((1-pAC)*nAC*beamB/nB) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff));
eaf06408 605 return kTRUE;
7f66b913 606 }
607 }
eaf06408 608 return kFALSE;
7f66b913 609}
610//_____________________________________________________________________________
eaf06408 611ULong64_t AliTriggerRunScalers::GetDeltaScaler(const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2, Int_t classIndex, TString level)
7f66b913 612{
7f66b913 613 const AliTriggerScalersESD* scalers1 = scalRec1->GetTriggerScalersForClass(classIndex);
614 const AliTriggerScalersESD* scalers2 = scalRec2->GetTriggerScalersForClass(classIndex);
2696a238 615 ULong64_t s1=0;
616 ULong64_t s2=0;
eaf06408 617
618 if (level == "l0b") {s1=scalers1->GetLOCB(); s2=scalers2->GetLOCB();}
619 else if (level == "l0a") {s1=scalers1->GetLOCA(); s2=scalers2->GetLOCA();}
620 else if (level == "l1b") {s1=scalers1->GetL1CB(); s2=scalers2->GetL1CB();}
621 else if (level == "l1a") {s1=scalers1->GetL1CA(); s2=scalers2->GetL1CA();}
622 else if (level == "l2b") {s1=scalers1->GetL2CB(); s2=scalers2->GetL2CB();}
623 else if (level == "l2a") {s1=scalers1->GetL2CA(); s2=scalers2->GetL2CA();}
624 else return 0;
625
7f66b913 626 return s2-s1;
627}
628//_____________________________________________________________________________
629Double_t AliTriggerRunScalers::GetDeltaTime(const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2)
630{
631 const AliTimeStamp* stamp1 = scalRec1->GetTimeStamp();
632 const AliTimeStamp* stamp2 = scalRec2->GetTimeStamp();
633 UInt_t orbit1 = stamp1->GetOrbit();
634 UInt_t orbit2 = stamp2->GetOrbit();
635 UInt_t period1 = stamp1->GetPeriod();
636 UInt_t period2 = stamp2->GetPeriod();
637 UInt_t max = 16777216; // The period counter increases when 24 bit orbit counter overflow
638 Double_t orbitSec = 89.1*1.e-6; // Length of 1 orbit in seconds
639 return ((period2 - period1)*max + (orbit2-orbit1))*orbitSec;
640}
641//_____________________________________________________________________________
642UInt_t AliTriggerRunScalers::GetDeltaOrbits(const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2)
643{
644 const AliTimeStamp* stamp1 = scalRec1->GetTimeStamp();
645 const AliTimeStamp* stamp2 = scalRec2->GetTimeStamp();
646 UInt_t orbit1 = stamp1->GetOrbit();
647 UInt_t orbit2 = stamp2->GetOrbit();
648 UInt_t period1 = stamp1->GetPeriod();
649 UInt_t period2 = stamp2->GetPeriod();
650 UInt_t max = 16777216; // The period counter increases when 24 bit orbit counter overflow
651 return (period2 - period1)*max + (orbit2-orbit1);
652}
653//_____________________________________________________________________________
eaf06408 654Bool_t AliTriggerRunScalers::GetScalerRate(Double_t &rate, Double_t &error, const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2, Int_t classIndex, TString level)
7f66b913 655{
eaf06408 656 if (level != "l0b" && level != "l0a" && level != "l1b" && level != "l1a" && level != "l2b" && level != "l2a") return kFALSE;
2696a238 657
7f66b913 658 ULong64_t scaler = GetDeltaScaler(scalRec1, scalRec2, classIndex, level);
659 Double_t time = GetDeltaTime(scalRec1, scalRec2 );
eaf06408 660 if (time==0.) return kFALSE;
661 rate = (Double_t)scaler/time;
662 error = (Double_t)sqrt(scaler)/time;
663 return kTRUE;
7f66b913 664}
665//_____________________________________________________________________________
eaf06408 666Bool_t AliTriggerRunScalers::GetScalerRatePerBC(Double_t &rate, Double_t &error, const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2, AliTriggerConfiguration* cfg, Int_t classIndex, TString level)
7f66b913 667{
eaf06408 668 if (level != "l0b" && level != "l0a" && level != "l1b" && level != "l1a" && level != "l2b" && level != "l2a") return kFALSE;
669 const AliTriggerClass* trgclass = cfg->GetTriggerClass(classIndex);
670 AliTriggerBCMask* bcMask = new AliTriggerBCMask();
671 if (trgclass) bcMask = (AliTriggerBCMask*)trgclass->GetBCMask();
672 Int_t nBC=0;
673 if (TString(bcMask->GetName()).CompareTo("NONE")!=0){
674 nBC = (UShort_t)bcMask->GetNUnmaskedBCs();
675 }
676 if (nBC<1) return kFALSE;
7f66b913 677 ULong64_t scaler = GetDeltaScaler(scalRec1, scalRec2, classIndex, level);
678 Double_t time = GetDeltaTime(scalRec1, scalRec2 );
eaf06408 679 if (time==0.) return kFALSE;
680 rate = (Double_t)scaler/time/nBC;
681 error = (Double_t)sqrt(scaler)/time/nBC;
682 return kTRUE;
7f66b913 683}
684//_____________________________________________________________________________
eaf06408 685Bool_t AliTriggerRunScalers::GetClassL2L0(Double_t &l2l0, Double_t &error, const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2, Int_t classIndex)
7f66b913 686{
eaf06408 687 ULong64_t l0 = GetDeltaScaler(scalRec1, scalRec2, classIndex, "l0b");
688 ULong64_t l2 = GetDeltaScaler(scalRec1, scalRec2, classIndex, "l2a");
689 if (l0!=0) {
690 l2l0 = (Double_t)l2/l0;
691 error = (Double_t)sqrt(l2-l2*l2/l0)/l0;
692 return kTRUE;
693 }
694 return kFALSE;
7f66b913 695}
696//_____________________________________________________________________________
eaf06408 697Bool_t AliTriggerRunScalers::GetMuFromClassScaler(Double_t &mu, Double_t &errmu, const char* className, const AliTriggerScalersRecordESD* scalRec1, const AliTriggerScalersRecordESD* scalRec2, AliTriggerConfiguration* cfg, Bool_t colBCsFromFillScheme, Bool_t bkgCorr, Double_t triggerEff, Double_t errorEff)
7f66b913 698{
eaf06408 699 // className = the first part of the class name. For example CINT1 for the class CINT1-B-NOPF-ALL
7f66b913 700 // colBCsFromFillScheme=kTRUE - use filling scheme and orbit counter
701 // colBCsFromFillScheme=kFALSE - use cbeamb scaler to get number of colliding BCs
702 // One can also switch background correction ON or OFF with bkgCorr
703 TObjArray cint1bNames;
7f66b913 704 TObjArray cint1acNames;
eaf06408 705 TObjArray cbeambNames;
7f66b913 706 //
eaf06408 707 cint1bNames.Add(new TNamed(Form("%s-ABCE",className),NULL));
708 cint1bNames.Add(new TNamed(Form("%s-B",className),NULL));
709 cint1acNames.Add(new TNamed(Form("%s-AC",className),NULL));
710 cbeambNames.Add(new TNamed("CBEAMB",NULL));
711 cbeambNames.Add(new TNamed("CTRUE",NULL));
7f66b913 712 //
eaf06408 713 Int_t cint1bIndex=-1, cint1acIndex=-1, cbeambIndex=-1;
714 TString nameString;
715 //
716 for (Int_t i=0; i<cfg->GetClasses().GetEntriesFast(); i++ ) {
717 nameString = cfg->GetClassNameFromIndex(i);
718 for (Int_t j=0; j<cint1bNames.GetEntriesFast(); j++ ) {
719 if (nameString.BeginsWith(cint1bNames.At(j)->GetName())) cint1bIndex = i;
720 }
721 for (Int_t j=0; j<cint1acNames.GetEntriesFast(); j++ ) {
722 if (nameString.BeginsWith(cint1acNames.At(j)->GetName())) cint1acIndex = i;
723 }
724 for (Int_t j=0; j<cbeambNames.GetEntriesFast(); j++ ) {
725 if (nameString.BeginsWith(cbeambNames.At(j)->GetName())) cbeambIndex = i;
726 }
727 nameString.Clear();
7f66b913 728 }
729 //
730 ULong64_t cint1b = 0;
731 UShort_t nB=0;
732 if (cint1bIndex!=-1) {
eaf06408 733 cint1b=GetDeltaScaler(scalRec1, scalRec2, cint1bIndex, "l0b");
7f66b913 734 const AliTriggerClass* cint1bClass = cfg->GetTriggerClass(cint1bIndex);
2696a238 735 AliTriggerBCMask* cint1bBCMask = new AliTriggerBCMask();
7f66b913 736 if (cint1bClass) cint1bBCMask = (AliTriggerBCMask*)cint1bClass->GetBCMask();
737 if (TString(cint1bBCMask->GetName()).CompareTo("NONE")!=0){
738 nB = (UShort_t)cint1bBCMask->GetNUnmaskedBCs();
739 }
740 } else return kFALSE;
741 ULong64_t cint1ac = 0;
742 UShort_t nAC=0;
743 if (cint1acIndex!=-1) {
eaf06408 744 cint1ac=GetDeltaScaler(scalRec1, scalRec2, cint1acIndex, "l0b");
7f66b913 745 AliTriggerClass* cint1acClass = cfg->GetTriggerClass(cint1acIndex);
2696a238 746 AliTriggerBCMask* cint1acBCMask = new AliTriggerBCMask();
7f66b913 747 if (cint1acClass) cint1acBCMask = (AliTriggerBCMask*)cint1acClass->GetBCMask();
748 if (TString(cint1acBCMask->GetName()).CompareTo("NONE")!=0){
749 nAC = (UShort_t)cint1acBCMask->GetNUnmaskedBCs();
750 }
751 }
7f66b913 752 ULong64_t cbeamb = 0;
eaf06408 753 if (cbeambIndex!=-1) cbeamb=GetDeltaScaler(scalRec1, scalRec2, cbeambIndex, "l0b");
7f66b913 754 UInt_t orbits = GetDeltaOrbits(scalRec1, scalRec2);
755 //
eaf06408 756 if (bkgCorr && (nB==0 || nAC==0 )) return kFALSE;
7f66b913 757 //
758 if (colBCsFromFillScheme) {
eaf06408 759 if (CalculateMu(mu, errmu, cint1b, cint1ac, nB, nAC, orbits, bkgCorr, triggerEff, errorEff)) return kTRUE;
7f66b913 760 }
761 else {
762 if (cint1b!=0 && cbeamb==0) return kFALSE;
eaf06408 763 if (CalculateMu(mu, errmu, cint1b, cint1ac, cbeamb, nB, nAC, bkgCorr, triggerEff, errorEff)) return kTRUE;
7f66b913 764 }
765 //
eaf06408 766 return kFALSE;
7f66b913 767}
768//_____________________________________________________________________________
eaf06408 769ULong64_t AliTriggerRunScalers::GetDeltaScalerForRun(Int_t classIndex, TString level)
7f66b913 770{
771 if (fScalersRecordESD.GetEntriesFast()==0) {
772 if (CorrectScalersOverflow()==1) return 0;
773 }
eaf06408 774 if (level != "l0b" && level != "l0a" && level != "l1b" && level != "l1a" && level != "l2b" && level != "l2a") return 0;
775
7f66b913 776 if (fScalersRecordESD.GetEntriesFast()>1) {
777 const AliTriggerScalersRecordESD* scalRec1 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(0);
778 const AliTriggerScalersRecordESD* scalRec2 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(fScalersRecordESD.GetEntriesFast()-1);
7f66b913 779 return GetDeltaScaler(scalRec1, scalRec2, classIndex, level);
780 }
781 return 0;
782}
783//_____________________________________________________________________________
eaf06408 784Bool_t AliTriggerRunScalers::GetScalerRateForRun(Double_t &rate, Double_t &error, Int_t classIndex, TString level)
7f66b913 785{
eaf06408 786 if (level != "l0b" && level != "l0a" && level != "l1b" && level != "l1a" && level != "l2b" && level != "l2a") return 0;
7f66b913 787 if (fScalersRecordESD.GetEntriesFast()==0) {
eaf06408 788 if (CorrectScalersOverflow()==1) return kFALSE;
7f66b913 789 }
790 if (fScalersRecordESD.GetEntriesFast()>=4) {
7f66b913 791 const AliTriggerScalersRecordESD* scalRec1 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(0);
792 const AliTriggerScalersRecordESD* scalRec2 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(fScalersRecordESD.GetEntriesFast()-1);
eaf06408 793 if (GetScalerRate(rate, error, scalRec1, scalRec2, classIndex, level)) return kTRUE;
7f66b913 794 }
eaf06408 795 return kFALSE;
7f66b913 796}
797//_____________________________________________________________________________
eaf06408 798Bool_t AliTriggerRunScalers::GetClassL2L0ForRun(Double_t &l2l0, Double_t &error, Int_t classIndex)
7f66b913 799{
800 if (fScalersRecordESD.GetEntriesFast()==0) {
eaf06408 801 if (CorrectScalersOverflow()==1) return kFALSE;
7f66b913 802 }
803 if (fScalersRecordESD.GetEntriesFast()>=4) {
804 const AliTriggerScalersRecordESD* scalRec1 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(0);
805 const AliTriggerScalersRecordESD* scalRec2 = (AliTriggerScalersRecordESD*)fScalersRecordESD.At(fScalersRecordESD.GetEntriesFast()-1); // Skip the first and last scaler readings for timing reasons
eaf06408 806
807 if ( GetClassL2L0(l2l0, error, scalRec1, scalRec2, classIndex)) return kTRUE;
7f66b913 808 }
eaf06408 809 return kFALSE;
7f66b913 810}
811//_____________________________________________________________________________
eaf06408 812TGraphErrors* AliTriggerRunScalers::GetGraphScalerRate(const char* className, TString level, AliTriggerConfiguration* cfg)
7f66b913 813{
814 Int_t classIndex = cfg->GetClassIndexFromName(className);
815 if (classIndex == -1) return 0;
816 if (fScalersRecordESD.GetEntriesFast()==0) {
817 if (CorrectScalersOverflow()==1) return 0;
818 }
eaf06408 819 if (level != "l0b" && level != "l0a" && level != "l1b" && level != "l1a" && level != "l2b" && level != "l2a") return 0;
7f66b913 820 Int_t nent = fScalersRecordESD.GetEntriesFast();
821 Double_t* time = new Double_t[nent];
822 Double_t* etime = new Double_t[nent];
823 Double_t* rate = new Double_t[nent];
824 Double_t* erate = new Double_t[nent];
825 for (Int_t i=0;i<nent-1;i++) {
826 if (i>0) time[i] = time[i-1]+GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i-1), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i))/2.+GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1))/2.;
827 else time[0] = GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(0), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(1))/2.;
828 etime[i] = GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1))/2.;
eaf06408 829 if (!GetScalerRate( rate[i], erate[i], (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1), classIndex, level)) {rate[i]=-1; erate[i]=0.;}
7f66b913 830 }
831 TGraphErrors* graph = new TGraphErrors(nent-1, time, rate, etime, erate);
832 return graph;
833}
834//_____________________________________________________________________________
835TGraphErrors* AliTriggerRunScalers::GetGraphScalerL2L0Ratio(const char* className, AliTriggerConfiguration* cfg)
836{
837 Int_t classIndex = cfg->GetClassIndexFromName(className);
4efa7500 838 if (classIndex == -1) return 0;
7f66b913 839 if (fScalersRecordESD.GetEntriesFast()==0) {
840 if (CorrectScalersOverflow()==1) return 0;
841 }
842 Int_t nent = fScalersRecordESD.GetEntriesFast();
843 Double_t* time = new Double_t[nent];
844 Double_t* etime = new Double_t[nent];
845 Double_t* ratio = new Double_t[nent];
846 Double_t* eratio = new Double_t[nent];
7f66b913 847
848 for (Int_t i=0;i<nent-1;i++) {
849 if (i>0) time[i] = time[i-1]+GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i-1), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i))/2.+GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1))/2.;
850 else time[0] = GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(0), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(1))/2.;
851 etime[i] = GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1))/2.;
eaf06408 852 if (!GetClassL2L0(ratio[i], eratio[i], (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1), classIndex)) {ratio[i]=-1; eratio[i]=0.;}
7f66b913 853 }
854 TGraphErrors* graph = new TGraphErrors(nent-1, time, ratio, etime, eratio);
855 return graph;
856}
857//_____________________________________________________________________________
eaf06408 858TGraphErrors* AliTriggerRunScalers::GetGraphMu(AliTriggerConfiguration* cfg, const char* className, Bool_t colBCsFromFillScheme, Bool_t bkgCorr, Double_t triggerEff, Double_t errorEff)
7f66b913 859{
860 if (fScalersRecordESD.GetEntriesFast()==0) {
861 if (CorrectScalersOverflow()==1) return 0;
862 }
863 Int_t nent = fScalersRecordESD.GetEntriesFast();
864 Double_t* time = new Double_t[nent];
865 Double_t* etime = new Double_t[nent];
866 Double_t* mu = new Double_t[nent];
867 Double_t* emu = new Double_t[nent];
868
869 for (Int_t i=0;i<nent-1;i++) {
870 Double_t m=0.;
871 Double_t err=0.;
872 if (i!=0) time[i] = time[i-1]+GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i-1), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i))/2.+GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1))/2.;
873 else time[0] = GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(0), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(1))/2.;
874 etime[i] = GetDeltaTime((AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1))/2.;
eaf06408 875 if (GetMuFromClassScaler( m,err, className, (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i), (AliTriggerScalersRecordESD*)fScalersRecordESD.At(i+1), cfg, colBCsFromFillScheme, bkgCorr, triggerEff, errorEff)!=kFALSE) {mu[i]=m; emu[i]=err;}
7f66b913 876 else {mu[i]=-1.; emu[i]=0.;}
877 }
878 TGraphErrors* graph = new TGraphErrors(nent-1, time, mu, etime, emu);
879 return graph;
880}
d7dd8a54 881//_____________________________________________________________________________
882void AliTriggerRunScalers::Print( const Option_t* ) const
883{
884 // Print
885 cout << "Trigger Scalers Record per Run: " << endl;
886 cout << " File version :" << fVersion << endl;
887 cout << " Run Number :" << fRunNumber << endl;
888 cout << " Number of Classes :" << (Int_t)fnClasses << endl;
889 cout << " Classes ID:";
890 for( Int_t i=0; i<fnClasses; ++i )
891 cout << " " << (Int_t)fClassIndex[i];
892 cout << endl;
893
894 for( Int_t i=0; i<fScalersRecord.GetEntriesFast(); ++i )
895 ((AliTriggerScalersRecord*)fScalersRecord.At(i))->Print();
896}
897