36 #include <Riostream.h> 43 #include <TObjString.h> 44 #include <TObjArray.h> 46 #include <TGraphErrors.h> 91 for(Int_t i=0; i<8; i++) {
93 for(Int_t j=0; j<
fnClasses; j++) overflow[i][j] = 0;
96 AliErrorClass(
"Trigger counters not in the right order or decreasing!");
100 for(Int_t i=0; i<8; i++) {
117 for (Int_t i = 0; i < run.
fClassIndex.GetSize(); i++) {
132 if(&run ==
this)
return *
this;
133 ((TObject *)
this)->operator=(run);
139 for (Int_t i = 0; i < run.
fClassIndex.GetSize(); i++) {
155 if( gSystem->AccessPathName( filename.Data() ) ) {
156 AliErrorClass( Form(
"file (%s) not found", filename.Data() ) );
160 ifstream *file =
new ifstream ( filename.Data() );
162 AliErrorClass(Form(
"Error opening file (%s) !",filename.Data()));
171 Bool_t verflag = kFALSE;
172 Bool_t classflag = kFALSE;
175 while (strLine.ReadLine(*file)) {
176 if (strLine.BeginsWith(
"#"))
continue;
178 TObjArray *tokens = strLine.Tokenize(
" \t");
179 Int_t ntokens = tokens->GetEntriesFast();
183 AliErrorClass( Form(
"Error reading version number from (%s), line :%s",
184 filename.Data() , strLine.Data() ) );
189 Short_t version= ((TObjString*)tokens->At(0))->String().Atoi();
192 if(version > 2) run2=kTRUE;
200 if ( !((TObjString*)tokens->At(1))->String().IsDigit() ) {
201 AliErrorClass( Form(
"Error reading Run number from (%s)", filename.Data() ));
204 rScaler->
SetRunNumber( ((TObjString*)tokens->At(0))->String().Atoi() );
205 nclass = (UChar_t)((TObjString*)tokens->At(1))->String().Atoi();
208 if ( nclass != ntokens - 2 ) {
209 AliErrorClass( Form(
"Error reading number of classes from (%s)", filename.Data() ));
212 for (UChar_t i=0; i<nclass; ++i) {
213 rScaler->
SetClass( i, (Char_t)((TObjString*)tokens->At(2+i))->String().Atoi() );
228 if (ntokens != 4 && ntokens !=5) {
229 AliErrorClass( Form(
"Error reading timestamp from (%s): line (%s)",
230 filename.Data(), strLine.Data() ));
234 UInt_t orbit = strtoul(((TObjString*)tokens->At(0))->String(), NULL, 10);
235 UInt_t period = strtoul(((TObjString*)tokens->At(1))->String(), NULL, 10);
236 UInt_t seconds = strtoul(((TObjString*)tokens->At(2))->String(), NULL, 10);
237 UInt_t microSecs = strtoul(((TObjString*)tokens->At(3))->String(), NULL, 10);
241 UInt_t tgroup=strtoul(((TObjString*)tokens->At(4))->String(), NULL, 10);
242 rec->SetTimeGroup(tgroup);
244 rec->SetTimeStamp( orbit, period, seconds, microSecs );
246 for (Int_t i=0; i<nclass; ++i) {
247 strLine1.ReadLine(*file);
248 if (strLine1.BeginsWith(
"#"))
continue;
249 TObjArray *tokens1 = strLine1.Tokenize(
" \t");
250 Int_t ntokens1 = tokens1->GetEntriesFast();
252 Bool_t err = run2 || (ntokens1 !=6);
253 err = err && (!run2 || (ntokens1 != 8));
255 AliErrorClass( Form(
"Error reading scalers from (%s): line (%s): ntokens=%i",
256 filename.Data(), strLine1.Data(),ntokens1 ));
263 UInt_t lOCB = strtoul(((TObjString*)tokens1->At(0))->String(), NULL, 10);
264 UInt_t lOCA = strtoul(((TObjString*)tokens1->At(1))->String(), NULL, 10);
265 UInt_t l1CB = strtoul(((TObjString*)tokens1->At(2))->String(), NULL, 10);
266 UInt_t l1CA = strtoul(((TObjString*)tokens1->At(3))->String(), NULL, 10);
267 UInt_t l2CB = strtoul(((TObjString*)tokens1->At(4))->String(), NULL, 10);
268 UInt_t l2CA = strtoul(((TObjString*)tokens1->At(5))->String(), NULL, 10);
270 UInt_t lMCB = strtoul(((TObjString*)tokens1->At(6))->String(), NULL, 10);
271 UInt_t lMCA = strtoul(((TObjString*)tokens1->At(7))->String(), NULL, 10);
272 rec->AddTriggerScalers( rScaler->
GetClass(i),
274 l1CA, l2CB, l2CA, lMCB, lMCA );
276 rec->AddTriggerScalers( rScaler->
GetClass(i),
300 Int_t base, position=-1, last, result = 0;
308 while (last >= base) {
309 position = (base+last) / 2;
310 AliDebug(1, Form(
"position= %d base= %d last= %d ",position,base,last));
315 if (!op2 || result < 0)
321 if( (position == 0 && result < 0) || position >=
fScalersRecord.GetEntriesFast() )
324 return (result < 0 ) ? position-1 : position;
337 AliErrorClass(
"Position=0 not alowed as comparison with previous record not possible");
346 ULong64_t c1_64[8],c2_64[8];
347 ULong64_t
const max1 = 4294967296ul;
348 ULong64_t
const max2 = 1000000000ul;
353 AliError(
"Records time decreases.");
366 for(Int_t i=0;i<8;i++)ovflow[i]=0;
374 for(Int_t i=0;i<(nlevels);i++){
375 if ( c2[i] >= c1[i] )
continue;
377 else if ( c2[i] < c1[i] && (c1[i] - c2[i]) > max2) ovflow[i]++;
379 AliError(
"Decreasing count with time.");
380 AliError(Form(
"%d c2: %u c1[i] %u ",i,c2[i],c1[i]));
387 for(Int_t i=0;i<nlevels;i++){
388 c2_64[i]=c2[i]+max1*(overflow[i][ic]+ovflow[i]);
389 c1_64[i]=c1[i]+max1*overflow[i][ic];
391 for(Int_t i=0;i<(nlevels-1);i++){
392 if ((c2_64[i] - c1_64[i]) < (c2_64[i+1] - c1_64[i+1]) ) {
393 if ( ((c2_64[i+1] - c1_64[i+1]) - (c2_64[i] - c1_64[i])) < 16ull ) {
AliDebugClass(1,
"Trigger scaler Level[i+1] > Level[i]. Diff < 16!");}
395 ULong64_t delta= (c2_64[i+1] - c1_64[i+1]) - (c2_64[i] - c1_64[i]);
397 if ((i != 1) || (delta>512ull)){
399 AliWarning(Form(
"%llu %llu %llu %llu delta: %llu",c1_64[i],c1_64[i+1],c2_64[i],c2_64[i+1],delta));
408 for(Int_t i=0;i<8;i++)overflow[i][ic] += ovflow[i];
409 if(
fVersion>2){
for(Int_t i=0;i<6;i++){ c64[i]=c2[i+2]+max1*overflow[i+2][ic]; }}
410 else{
for(Int_t i=0;i<6;i++){ c64[i]=c2[i]+max1*overflow[i][ic]; }}
413 ULong64_t cLMB = c2[0]+max1*overflow[0][ic];
414 ULong64_t cLMA = c2[1]+max1*overflow[1][ic];
439 AliError(
"Scalers record array is empty");
453 for(Int_t i=0; i<6; i++)c64[i]=c1[i+2];
455 for(Int_t i=0; i<6; i++)c64[i]=c1[i];
467 for(Int_t i=0; i<8; i++) {
469 for(Int_t j=0; j<
fnClasses; j++) overflow[i][j] = 0;
477 AliErrorClass(
"Inconsistent scalers, they will not be provided.");
478 for(Int_t i=0; i<8; i++)
delete overflow[i];
482 for(Int_t i=0; i<8; i++)
delete[] overflow[i];
495 if ( position == -1 ) {
505 if(scalers1->GetEntriesFast() !=
fnClasses){
506 AliErrorClass(
"Internal error: #classes in RecordESD != fnClasses");
511 for ( Int_t ic=0; ic < (Int_t)
fnClasses; ++ic ){
518 ULong64_t max = 16777216ul;
522 ULong64_t base[6],c1[6],c2[6],cint[6];
529 for(Int_t i=0;i<6;i++){
530 Double_t slope=Double_t(c2[i]-c1[i])/Double_t(orbit2-orbit1);
531 cint[i]=ULong64_t(slope*(orbit-orbit1)) +c1[i] -base[i];
547 if ( position == -1 ) {
559 if(scalers1->GetEntriesFast() !=
fnClasses){
560 AliErrorClass(
"Internal error: #classes in RecordESD != fnClasses");
565 for ( Int_t ic=0; ic < (Int_t)
fnClasses; ++ic ){
570 ULong64_t c1[6],c2[6],cint[6];
573 for(Int_t i=0;i<6;i++){
579 UInt_t max = 16777216ul;
580 UInt_t orbit, period;
608 if(scalers1->GetEntriesFast() !=
fnClasses){
609 AliErrorClass(
"Internal error: #classes in RecordESD != fnClasses");
614 for ( Int_t ic=0; ic < (Int_t)
fnClasses; ++ic ){
619 ULong64_t c1[6],c2[6],cint[6];
622 for(Int_t i=0;i<6;i++){
628 UInt_t max = 16777216ul;
629 UInt_t orbit, period;
646 Bool_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)
649 if (nB!=0 && orbits!=0) {
650 Double_t pB = (Double_t)countsB/((ULong64_t)nB*orbits);
651 if (!bkgCorr || nAC==0 ) {
652 mu = -log(1-pB)/triggerEff;
653 errmu = TMath::Sqrt(pB/((1-pB)*nB*orbits) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff));
658 Double_t pAC = (Double_t)countsAC/((ULong64_t)nAC*orbits);
659 mu = ( log(1.-pAC) - log(1.-pB) )/triggerEff;
661 errmu = TMath::Sqrt(pB/((1.-pB)*nB*orbits) + pAC/((1.-pAC)*nAC*orbits) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff));
668 Bool_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)
672 Double_t pB = (Double_t)countsB/beamB;
673 if (!bkgCorr || nAC==0 || nB==0) {
674 mu = -log(1-pB)/triggerEff;
675 errmu = TMath::Sqrt(pB/((1-pB)*beamB) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff));
680 Double_t pAC = (Double_t)countsAC/((ULong64_t)nAC*beamB/(Double_t)nB);
681 mu = ( log(1-pAC) - log(1-pB) )/triggerEff;
683 errmu = TMath::Sqrt(pB/((1-pB)*beamB) + pAC/((1-pAC)*nAC*beamB/nB) + mu*mu*errorEff*errorEff/(triggerEff*triggerEff));
697 if (level ==
"l0b") {s1=scalers1->
GetLOCB(); s2=scalers2->
GetLOCB();}
698 else if (level ==
"l0a") {s1=scalers1->
GetLOCA(); s2=scalers2->
GetLOCA();}
699 else if (level ==
"l1b") {s1=scalers1->
GetL1CB(); s2=scalers2->
GetL1CB();}
700 else if (level ==
"l1a") {s1=scalers1->
GetL1CA(); s2=scalers2->
GetL1CA();}
701 else if (level ==
"l2b") {s1=scalers1->
GetL2CB(); s2=scalers2->
GetL2CB();}
702 else if (level ==
"l2a") {s1=scalers1->
GetL2CA(); s2=scalers2->
GetL2CA();}
716 UInt_t max = 16777216;
717 Double_t orbitSec = 89.1*1.e-6;
718 return ((period2 - period1)*max + (orbit2-orbit1))*orbitSec;
729 UInt_t max = 16777216;
730 return (period2 - period1)*max + (orbit2-orbit1);
735 if (level !=
"l0b" && level !=
"l0a" && level !=
"l1b" && level !=
"l1a" && level !=
"l2b" && level !=
"l2a")
return kFALSE;
737 ULong64_t scaler =
GetDeltaScaler(scalRec1, scalRec2, classIndex, level);
739 if (time==0.)
return kFALSE;
740 rate = (Double_t)scaler/time;
741 error = (Double_t)sqrt(scaler)/time;
747 if (level !=
"l0b" && level !=
"l0a" && level !=
"l1b" && level !=
"l1a" && level !=
"l2b" && level !=
"l2a")
return kFALSE;
752 if (TString(bcMask->GetName()).CompareTo(
"NONE")!=0){
755 if (nBC<1)
return kFALSE;
756 ULong64_t scaler =
GetDeltaScaler(scalRec1, scalRec2, classIndex, level);
758 if (time==0.)
return kFALSE;
759 rate = (Double_t)scaler/time/nBC;
760 error = (Double_t)sqrt(scaler)/time/nBC;
766 ULong64_t l0 =
GetDeltaScaler(scalRec1, scalRec2, classIndex,
"l0b");
767 ULong64_t l2 =
GetDeltaScaler(scalRec1, scalRec2, classIndex,
"l2a");
769 l2l0 = (Double_t)l2/l0;
770 error = (Double_t)sqrt(l2-l2*l2/l0)/l0;
786 cint1bNames.Add(
new TNamed(Form(
"%s-ABCE",className),NULL));
787 cint1bNames.Add(
new TNamed(Form(
"%s-B",className),NULL));
788 cint1acNames.Add(
new TNamed(Form(
"%s-AC",className),NULL));
789 cbeambNames.Add(
new TNamed(
"CBEAMB",NULL));
790 cbeambNames.Add(
new TNamed(
"CTRUE",NULL));
792 Int_t cint1bIndex=-1, cint1acIndex=-1, cbeambIndex=-1;
795 for (Int_t i=0; i<cfg->
GetClasses().GetEntriesFast(); i++ ) {
797 for (Int_t j=0; j<cint1bNames.GetEntriesFast(); j++ ) {
798 if (nameString.BeginsWith(cint1bNames.At(j)->GetName())) cint1bIndex = i;
800 for (Int_t j=0; j<cint1acNames.GetEntriesFast(); j++ ) {
801 if (nameString.BeginsWith(cint1acNames.At(j)->GetName())) cint1acIndex = i;
803 for (Int_t j=0; j<cbeambNames.GetEntriesFast(); j++ ) {
804 if (nameString.BeginsWith(cbeambNames.At(j)->GetName())) cbeambIndex = i;
809 ULong64_t cint1b = 0;
811 if (cint1bIndex!=-1) {
816 if (TString(cint1bBCMask->GetName()).CompareTo(
"NONE")!=0){
819 }
else return kFALSE;
820 ULong64_t cint1ac = 0;
822 if (cint1acIndex!=-1) {
827 if (TString(cint1acBCMask->GetName()).CompareTo(
"NONE")!=0){
831 ULong64_t cbeamb = 0;
832 if (cbeambIndex!=-1) cbeamb=
GetDeltaScaler(scalRec1, scalRec2, cbeambIndex,
"l0b");
835 if (bkgCorr && (nB==0 || nAC==0 ))
return kFALSE;
837 if (colBCsFromFillScheme) {
838 if (
CalculateMu(mu, errmu, cint1b, cint1ac, nB, nAC, orbits, bkgCorr, triggerEff, errorEff))
return kTRUE;
841 if (cint1b!=0 && cbeamb==0)
return kFALSE;
842 if (
CalculateMu(mu, errmu, cint1b, cint1ac, cbeamb, nB, nAC, bkgCorr, triggerEff, errorEff))
return kTRUE;
853 if (level !=
"l0b" && level !=
"l0a" && level !=
"l1b" && level !=
"l1a" && level !=
"l2b" && level !=
"l2a")
return 0;
865 if (level !=
"l0b" && level !=
"l0a" && level !=
"l1b" && level !=
"l1a" && level !=
"l2b" && level !=
"l2a")
return 0;
872 if (
GetScalerRate(rate, error, scalRec1, scalRec2, classIndex, level))
return kTRUE;
886 if (
GetClassL2L0(l2l0, error, scalRec1, scalRec2, classIndex))
return kTRUE;
894 if (classIndex == -1)
return 0;
898 if (level !=
"l0b" && level !=
"l0a" && level !=
"l1b" && level !=
"l1a" && level !=
"l2b" && level !=
"l2a")
return 0;
900 Double_t* time =
new Double_t[nent];
901 Double_t* etime =
new Double_t[nent];
902 Double_t* rate =
new Double_t[nent];
903 Double_t* erate =
new Double_t[nent];
904 for (Int_t i=0;i<nent-1;i++) {
910 TGraphErrors* graph =
new TGraphErrors(nent-1, time, rate, etime, erate);
917 if (classIndex == -1)
return 0;
922 Double_t* time =
new Double_t[nent];
923 Double_t* etime =
new Double_t[nent];
924 Double_t* ratio =
new Double_t[nent];
925 Double_t* eratio =
new Double_t[nent];
927 for (Int_t i=0;i<nent-1;i++) {
933 TGraphErrors* graph =
new TGraphErrors(nent-1, time, ratio, etime, eratio);
943 Double_t* time =
new Double_t[nent];
944 Double_t* etime =
new Double_t[nent];
945 Double_t* mu =
new Double_t[nent];
946 Double_t* emu =
new Double_t[nent];
948 for (Int_t i=0;i<nent-1;i++) {
955 else {mu[i]=-1.; emu[i]=0.;}
957 TGraphErrors* graph =
new TGraphErrors(nent-1, time, mu, etime, emu);
964 cout <<
"Trigger Scalers Record per Run: " << endl;
965 cout <<
" File version :" <<
fVersion << endl;
966 cout <<
" Run Number :" <<
fRunNumber << endl;
967 cout <<
" Number of Classes :" << (Int_t)
fnClasses << endl;
968 cout <<
" Classes ID:";
UChar_t GetClassIndex() const
void SetTimeStamp(const AliTimeStamp *stamp)
void SetNumClasses(UChar_t nclass)
virtual void Print(const Option_t *opt="") const
void SetLMCA(ULong64_t count)
virtual ~AliTriggerRunScalers()
static Bool_t 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=kTRUE, Double_t triggerEff=1., Double_t errorEff=0.)
void GetAllScalers(UInt_t *scalers) const
Bool_t GetClassL2L0ForRun(Double_t &l2l0, Double_t &error, Int_t classIndex)
AliTriggerBCMask * GetBCMask() const
void SetTimeGroup(const UInt_t group)
const TObjArray & GetClasses() const
Char_t GetClass(Int_t i) const
void SetClass(UChar_t i, UChar_t index)
const AliTriggerScalersESD * GetTriggerScalersForClass(const Int_t classindex) const
ULong64_t GetL1CB() const
static ULong64_t GetDeltaScaler(const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2, Int_t classIndex, TString level)
void SetLMCB(ULong64_t count)
const TObjArray * GetTriggerScalers() const
void AddTriggerScalers(AliTriggerScalersESD *scaler)
static UInt_t GetDeltaOrbits(const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2)
static Bool_t GetClassL2L0(Double_t &l2l0, Double_t &error, const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2, Int_t classIndex)
#define AliWarning(message)
AliTriggerScalersESD * GetScalersForEventClass(const AliTimeStamp *stamp, const Int_t classIndex) const
ULong64_t GetL2CA() const
const TObjArray * GetTriggerScalers() const
Int_t GetClassIndexFromName(const char *className) const
static AliTriggerRunScalers * ReadScalers(TString &filename)
#define AliErrorClass(message)
static Bool_t GetScalerRate(Double_t &rate, Double_t &error, const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2, Int_t classIndex, TString level)
#define AliDebugClass(logLevel, message)
ULong64_t GetDeltaScalerForRun(Int_t classIndex, TString level)
virtual Int_t Compare(const TObject *obj) const
static Double_t GetDeltaTime(const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2)
static Bool_t GetScalerRatePerBC(Double_t &rate, Double_t &error, const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2, AliTriggerConfiguration *cfg, Int_t classIndex, TString level)
static Bool_t GetMuFromClassScaler(Double_t &mu, Double_t &errmu, const char *className, const AliTriggerScalersRecordESD *scalRec1, const AliTriggerScalersRecordESD *scalRec2, AliTriggerConfiguration *cfg, Bool_t colBCsFromFillScheme=kTRUE, Bool_t bkgCorr=kTRUE, Double_t triggerEff=1., Double_t errorEff=0.)
UChar_t GetClassIndex() const
virtual Int_t Compare(const TObject *obj) const
ULong64_t GetL2CB() const
ULong_t GetRunNumber() const
const AliTriggerScalersRecordESD * GetScalersDeltaForRun() const
TObjArray fScalersRecordESD
Int_t CorrectScalersOverflow()
void SetRunNumber(ULong_t run)
void GetAllScalersM012(UInt_t *scalers) const
Int_t ConsistencyCheck(Int_t position, Bool_t correctOverflow, UInt_t **overflow)
void rec(const char *filename="raw.root")
ULong64_t GetLOCB() const
TGraphErrors * GetGraphScalerRate(const char *className, TString level, AliTriggerConfiguration *cfg)
#define StdoutToAliError(whatever)
TGraphErrors * GetGraphScalerL2L0Ratio(const char *className, AliTriggerConfiguration *cfg)
void AddTriggerScalers(AliTriggerScalersRecord *scal)
#define AliDebug(logLevel, message)
const AliTriggerScalersRecordESD * GetScalersDeltaForEvent(const AliTimeStamp *stamp) const
const AliTimeStamp * GetTimeStamp() const
void GetAllScalers(ULong64_t *scalers) const
Int_t FindNearestScalersRecord(const AliTimeStamp *stamp) const
AliTriggerClass * GetTriggerClass(Int_t classIndex) const
ULong64_t GetL1CA() const
#define AliError(message)
Bool_t GetScalerRateForRun(Double_t &rate, Double_t &error, Int_t classIndex, TString level)
AliTriggerRunScalers & operator=(const AliTriggerRunScalers &run)
ULong64_t GetLOCA() const
UShort_t GetNUnmaskedBCs() const
const AliTimeStamp * GetTimeStamp() const
const char * GetClassNameFromIndex(Int_t classIndex) const
void SetVersion(Short_t ver)
TGraphErrors * GetGraphMu(AliTriggerConfiguration *cfg, const char *className, Bool_t colBCsFromFillScheme=kTRUE, Bool_t bkgCorr=kTRUE, Double_t triggerEff=1., Double_t errorEff=0.)