ROOT logo
////////////////////////////////////////////////////////////////////////////
//                                                                        //
//  Event info for TRD performance train                                  //
//                                                                        //
//  Authors:                                                              //
//    Markus Fasel <M.Fasel@gsi.de>                                       //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

#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/*, 3500*/
};
Float_t const AliTRDeventInfo::fgkCentBin[AliTRDeventInfo::kCentralityClasses-1] = {
  0.1, 0.2, 0.5, 0.8/*, 1.*/
};
//____________________________________________________________________
AliTRDeventInfo::AliTRDeventInfo():
  TObject()
  ,fHeader(NULL)
  ,fRun(NULL)
  ,fCentrality(-1)
  ,fMult(-1)
{
  //
  // Default Constructor
  // 
  SetBit(kOwner, 0);
}

//____________________________________________________________________
AliTRDeventInfo::AliTRDeventInfo(AliESDHeader *header, AliESDRun *run):
  TObject()
  ,fHeader(header)
  ,fRun(run)
  ,fCentrality(-1)
  ,fMult(-1)
{
  //
  // Constructor with Arguments
  //
  SetBit(kOwner, 0);
//  fHeader->Print();
/*  for(Int_t ilevel(0); ilevel<3; ilevel++){
    printf("L%d :: ", ilevel);
    Int_t itrig(0); TString tn;
    do{
      tn = fHeader->GetTriggerInputName(itrig++, ilevel);
      printf("%s ", tn.Data());
    } while(tn.CompareTo(""));
    printf("\n");
  }*/
}

//____________________________________________________________________
AliTRDeventInfo::AliTRDeventInfo(const AliTRDeventInfo &info):
  TObject()
  ,fHeader(info.fHeader)
  ,fRun(info.fRun)
  ,fCentrality(info.fCentrality)
  ,fMult(info.fMult)
{
  //
  // Copy Constructor
  // Flat Copy
  // 
  SetBit(kOwner, 0);
}

//____________________________________________________________________
AliTRDeventInfo& AliTRDeventInfo::operator=(const AliTRDeventInfo& info){
  //
  // Operator=
  // Flat Copy
  //
  if(this == &info) return *this;
  fHeader     = info.fHeader;
  fRun        = info.fRun;
  fCentrality = info.fCentrality;
  fMult       = info.fMult;
  SetBit(kOwner, 0);
  return *this;
}

//____________________________________________________________________
AliTRDeventInfo::~AliTRDeventInfo(){
  //
  // Destructor
  // Delete the entries if it is the Owner
  //
  Delete("");
}

//____________________________________________________________________
void AliTRDeventInfo::Delete(const Option_t *){
  //
  // Delete the Object
  // Delete the entries if it is the Owner
  // 
  if(IsOwner()){
    if(fHeader) delete fHeader;
    if(fRun) delete fRun;
  };
  fHeader = NULL;
  fRun = NULL;
}

//____________________________________________________________________
void AliTRDeventInfo::SetOwner()
{
  // Do deep copy
  
  SetBit(kOwner, 1);
  fHeader = new AliESDHeader(*fHeader);
  fRun = new AliESDRun(*fRun);
}

//____________________________________________________________________
UShort_t  AliTRDeventInfo::GetBunchFill() const
{
  // wrapper
  return fHeader->GetBunchCrossNumber();
}

//____________________________________________________________________
Int_t  AliTRDeventInfo::GetCentralityBin(Float_t cenPer)
{
// calculate centrality bin
  for(Int_t icen(0); icen<kCentralityClasses-1; icen++){
    if(cenPer<fgkCentBin[icen]) return icen;
  }
  return -1;
}

//____________________________________________________________________
TString  AliTRDeventInfo::GetFiredTriggerClasses()
{
// copy of similar function from AliESDEvent
  return (fRun&&fHeader)?fRun->GetFiredTriggerClasses(fHeader->GetTriggerMask()):"";
}

//____________________________________________________________________
Int_t  AliTRDeventInfo::GetMultiplicityBin(Int_t n)
{
// calculate centrality bin
  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) {
  //
  // Find the isolated bunch crossings
  //
  // from I.Arsene first implementation in AliTRDcheckESD

  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; // outside LHC range
    Double_t entries(hbc->GetBinContent(bcBin));
    if(entries<1.) continue;             // not filled
    
    // check isolation
    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++;
  }   // end loop over BC bins

  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");
}
 AliTRDeventInfo.cxx:1
 AliTRDeventInfo.cxx:2
 AliTRDeventInfo.cxx:3
 AliTRDeventInfo.cxx:4
 AliTRDeventInfo.cxx:5
 AliTRDeventInfo.cxx:6
 AliTRDeventInfo.cxx:7
 AliTRDeventInfo.cxx:8
 AliTRDeventInfo.cxx:9
 AliTRDeventInfo.cxx:10
 AliTRDeventInfo.cxx:11
 AliTRDeventInfo.cxx:12
 AliTRDeventInfo.cxx:13
 AliTRDeventInfo.cxx:14
 AliTRDeventInfo.cxx:15
 AliTRDeventInfo.cxx:16
 AliTRDeventInfo.cxx:17
 AliTRDeventInfo.cxx:18
 AliTRDeventInfo.cxx:19
 AliTRDeventInfo.cxx:20
 AliTRDeventInfo.cxx:21
 AliTRDeventInfo.cxx:22
 AliTRDeventInfo.cxx:23
 AliTRDeventInfo.cxx:24
 AliTRDeventInfo.cxx:25
 AliTRDeventInfo.cxx:26
 AliTRDeventInfo.cxx:27
 AliTRDeventInfo.cxx:28
 AliTRDeventInfo.cxx:29
 AliTRDeventInfo.cxx:30
 AliTRDeventInfo.cxx:31
 AliTRDeventInfo.cxx:32
 AliTRDeventInfo.cxx:33
 AliTRDeventInfo.cxx:34
 AliTRDeventInfo.cxx:35
 AliTRDeventInfo.cxx:36
 AliTRDeventInfo.cxx:37
 AliTRDeventInfo.cxx:38
 AliTRDeventInfo.cxx:39
 AliTRDeventInfo.cxx:40
 AliTRDeventInfo.cxx:41
 AliTRDeventInfo.cxx:42
 AliTRDeventInfo.cxx:43
 AliTRDeventInfo.cxx:44
 AliTRDeventInfo.cxx:45
 AliTRDeventInfo.cxx:46
 AliTRDeventInfo.cxx:47
 AliTRDeventInfo.cxx:48
 AliTRDeventInfo.cxx:49
 AliTRDeventInfo.cxx:50
 AliTRDeventInfo.cxx:51
 AliTRDeventInfo.cxx:52
 AliTRDeventInfo.cxx:53
 AliTRDeventInfo.cxx:54
 AliTRDeventInfo.cxx:55
 AliTRDeventInfo.cxx:56
 AliTRDeventInfo.cxx:57
 AliTRDeventInfo.cxx:58
 AliTRDeventInfo.cxx:59
 AliTRDeventInfo.cxx:60
 AliTRDeventInfo.cxx:61
 AliTRDeventInfo.cxx:62
 AliTRDeventInfo.cxx:63
 AliTRDeventInfo.cxx:64
 AliTRDeventInfo.cxx:65
 AliTRDeventInfo.cxx:66
 AliTRDeventInfo.cxx:67
 AliTRDeventInfo.cxx:68
 AliTRDeventInfo.cxx:69
 AliTRDeventInfo.cxx:70
 AliTRDeventInfo.cxx:71
 AliTRDeventInfo.cxx:72
 AliTRDeventInfo.cxx:73
 AliTRDeventInfo.cxx:74
 AliTRDeventInfo.cxx:75
 AliTRDeventInfo.cxx:76
 AliTRDeventInfo.cxx:77
 AliTRDeventInfo.cxx:78
 AliTRDeventInfo.cxx:79
 AliTRDeventInfo.cxx:80
 AliTRDeventInfo.cxx:81
 AliTRDeventInfo.cxx:82
 AliTRDeventInfo.cxx:83
 AliTRDeventInfo.cxx:84
 AliTRDeventInfo.cxx:85
 AliTRDeventInfo.cxx:86
 AliTRDeventInfo.cxx:87
 AliTRDeventInfo.cxx:88
 AliTRDeventInfo.cxx:89
 AliTRDeventInfo.cxx:90
 AliTRDeventInfo.cxx:91
 AliTRDeventInfo.cxx:92
 AliTRDeventInfo.cxx:93
 AliTRDeventInfo.cxx:94
 AliTRDeventInfo.cxx:95
 AliTRDeventInfo.cxx:96
 AliTRDeventInfo.cxx:97
 AliTRDeventInfo.cxx:98
 AliTRDeventInfo.cxx:99
 AliTRDeventInfo.cxx:100
 AliTRDeventInfo.cxx:101
 AliTRDeventInfo.cxx:102
 AliTRDeventInfo.cxx:103
 AliTRDeventInfo.cxx:104
 AliTRDeventInfo.cxx:105
 AliTRDeventInfo.cxx:106
 AliTRDeventInfo.cxx:107
 AliTRDeventInfo.cxx:108
 AliTRDeventInfo.cxx:109
 AliTRDeventInfo.cxx:110
 AliTRDeventInfo.cxx:111
 AliTRDeventInfo.cxx:112
 AliTRDeventInfo.cxx:113
 AliTRDeventInfo.cxx:114
 AliTRDeventInfo.cxx:115
 AliTRDeventInfo.cxx:116
 AliTRDeventInfo.cxx:117
 AliTRDeventInfo.cxx:118
 AliTRDeventInfo.cxx:119
 AliTRDeventInfo.cxx:120
 AliTRDeventInfo.cxx:121
 AliTRDeventInfo.cxx:122
 AliTRDeventInfo.cxx:123
 AliTRDeventInfo.cxx:124
 AliTRDeventInfo.cxx:125
 AliTRDeventInfo.cxx:126
 AliTRDeventInfo.cxx:127
 AliTRDeventInfo.cxx:128
 AliTRDeventInfo.cxx:129
 AliTRDeventInfo.cxx:130
 AliTRDeventInfo.cxx:131
 AliTRDeventInfo.cxx:132
 AliTRDeventInfo.cxx:133
 AliTRDeventInfo.cxx:134
 AliTRDeventInfo.cxx:135
 AliTRDeventInfo.cxx:136
 AliTRDeventInfo.cxx:137
 AliTRDeventInfo.cxx:138
 AliTRDeventInfo.cxx:139
 AliTRDeventInfo.cxx:140
 AliTRDeventInfo.cxx:141
 AliTRDeventInfo.cxx:142
 AliTRDeventInfo.cxx:143
 AliTRDeventInfo.cxx:144
 AliTRDeventInfo.cxx:145
 AliTRDeventInfo.cxx:146
 AliTRDeventInfo.cxx:147
 AliTRDeventInfo.cxx:148
 AliTRDeventInfo.cxx:149
 AliTRDeventInfo.cxx:150
 AliTRDeventInfo.cxx:151
 AliTRDeventInfo.cxx:152
 AliTRDeventInfo.cxx:153
 AliTRDeventInfo.cxx:154
 AliTRDeventInfo.cxx:155
 AliTRDeventInfo.cxx:156
 AliTRDeventInfo.cxx:157
 AliTRDeventInfo.cxx:158
 AliTRDeventInfo.cxx:159
 AliTRDeventInfo.cxx:160
 AliTRDeventInfo.cxx:161
 AliTRDeventInfo.cxx:162
 AliTRDeventInfo.cxx:163
 AliTRDeventInfo.cxx:164
 AliTRDeventInfo.cxx:165
 AliTRDeventInfo.cxx:166
 AliTRDeventInfo.cxx:167
 AliTRDeventInfo.cxx:168
 AliTRDeventInfo.cxx:169
 AliTRDeventInfo.cxx:170
 AliTRDeventInfo.cxx:171
 AliTRDeventInfo.cxx:172
 AliTRDeventInfo.cxx:173
 AliTRDeventInfo.cxx:174
 AliTRDeventInfo.cxx:175
 AliTRDeventInfo.cxx:176
 AliTRDeventInfo.cxx:177
 AliTRDeventInfo.cxx:178
 AliTRDeventInfo.cxx:179
 AliTRDeventInfo.cxx:180
 AliTRDeventInfo.cxx:181
 AliTRDeventInfo.cxx:182
 AliTRDeventInfo.cxx:183
 AliTRDeventInfo.cxx:184
 AliTRDeventInfo.cxx:185
 AliTRDeventInfo.cxx:186
 AliTRDeventInfo.cxx:187
 AliTRDeventInfo.cxx:188
 AliTRDeventInfo.cxx:189
 AliTRDeventInfo.cxx:190
 AliTRDeventInfo.cxx:191