#include "TH1.h"
#include "TMath.h"
#include "AliESDHeader.h"
#include "AliESDRun.h"
#include "AliTRDeventInfo.h"
ClassImp(AliTRDeventInfo)
Int_t const AliTRDeventInfo::fgkMultBin[AliTRDeventInfo::kCentralityClasses-1] = {
700, 1400, 2100, 2800
};
Float_t const AliTRDeventInfo::fgkCentBin[AliTRDeventInfo::kCentralityClasses-1] = {
0.1, 0.2, 0.5, 0.8
};
AliTRDeventInfo::AliTRDeventInfo():
TObject()
,fHeader(NULL)
,fRun(NULL)
,fCentrality(-1)
,fMult(-1)
{
SetBit(kOwner, 0);
}
AliTRDeventInfo::AliTRDeventInfo(AliESDHeader *header, AliESDRun *run):
TObject()
,fHeader(header)
,fRun(run)
,fCentrality(-1)
,fMult(-1)
{
SetBit(kOwner, 0);
}
AliTRDeventInfo::AliTRDeventInfo(const AliTRDeventInfo &info):
TObject()
,fHeader(info.fHeader)
,fRun(info.fRun)
,fCentrality(info.fCentrality)
,fMult(info.fMult)
{
SetBit(kOwner, 0);
}
AliTRDeventInfo& AliTRDeventInfo::operator=(const AliTRDeventInfo& info){
if(this == &info) return *this;
fHeader = info.fHeader;
fRun = info.fRun;
fCentrality = info.fCentrality;
fMult = info.fMult;
SetBit(kOwner, 0);
return *this;
}
AliTRDeventInfo::~AliTRDeventInfo(){
Delete("");
}
void AliTRDeventInfo::Delete(const Option_t *){
if(IsOwner()){
if(fHeader) delete fHeader;
if(fRun) delete fRun;
};
fHeader = NULL;
fRun = NULL;
}
void AliTRDeventInfo::SetOwner()
{
SetBit(kOwner, 1);
fHeader = new AliESDHeader(*fHeader);
fRun = new AliESDRun(*fRun);
}
UShort_t AliTRDeventInfo::GetBunchFill() const
{
return fHeader->GetBunchCrossNumber();
}
Int_t AliTRDeventInfo::GetCentralityBin(Float_t cenPer)
{
for(Int_t icen(0); icen<kCentralityClasses-1; icen++){
if(cenPer<fgkCentBin[icen]) return icen;
}
return -1;
}
TString AliTRDeventInfo::GetFiredTriggerClasses()
{
return (fRun&&fHeader)?fRun->GetFiredTriggerClasses(fHeader->GetTriggerMask()):"";
}
Int_t AliTRDeventInfo::GetMultiplicityBin(Int_t n)
{
for(Int_t im(0); im<kCentralityClasses-1; im++){
if(n<fgkMultBin[im]) return kCentralityClasses-im-1;
}
return 0;
}
void AliTRDeventInfo::GetListOfIsolatedBunches(TH1D* hbc, Int_t bunchSpacing) {
Int_t nBunches(0);
Bool_t isIsolated[kLHCbunches]; memset(isIsolated, 0, kLHCbunches*sizeof(Bool_t));
for(Int_t bcBin(1); bcBin<=hbc->GetNbinsX(); bcBin++) {
Int_t bc(TMath::Nint(hbc->GetBinCenter(bcBin)));
if(bc<0 || bc>=kLHCbunches) continue;
Double_t entries(hbc->GetBinContent(bcBin));
if(entries<1.) continue;
Bool_t kFOUND(kTRUE);
for(Int_t ibc = TMath::Max(1,bcBin-bunchSpacing); ibc <= TMath::Min(Int_t(kLHCbunches), bcBin+bunchSpacing); ibc++) {
if(ibc==bcBin) continue;
if(hbc->GetBinContent(ibc)>0.) {
kFOUND = kFALSE;
break;
}
}
isIsolated[bc] = kFOUND;
if(kFOUND) nBunches++;
}
printf("Isolated bunches [%d] @ min bunch spacing [%d]:\n{", nBunches, bunchSpacing);
for(Int_t ibc(0); ibc<kLHCbunches; ++ibc) if(isIsolated[ibc]) printf("%4d, ", ibc);
printf("};\n");
}