d12f0139c9d58535436e9c550401d50683fc1e7e
[u/mrichter/AliRoot.git] / PWG1 / TRD / info / AliTRDeventInfo.cxx
1 ////////////////////////////////////////////////////////////////////////////
2 //                                                                        //
3 //  Event info for TRD performance train                                  //
4 //                                                                        //
5 //  Authors:                                                              //
6 //    Markus Fasel <M.Fasel@gsi.de>                                       //
7 //                                                                        //
8 ////////////////////////////////////////////////////////////////////////////
9
10 #include "TH1.h"
11 #include "TMath.h"
12
13 #include "AliESDHeader.h"
14 #include "AliESDRun.h"
15
16 #include "AliTRDeventInfo.h"
17
18 ClassImp(AliTRDeventInfo)
19
20 //____________________________________________________________________
21 AliTRDeventInfo::AliTRDeventInfo():
22   TObject()
23   ,fHeader(0x0)
24   ,fRun(0x0)
25   ,fCentrality(-1)
26 {
27   //
28   // Default Constructor
29   // 
30   SetBit(kOwner, 0);
31 }
32
33 //____________________________________________________________________
34 AliTRDeventInfo::AliTRDeventInfo(AliESDHeader *header, AliESDRun *run):
35   TObject()
36   ,fHeader(header)
37   ,fRun(run)
38   ,fCentrality(-1)
39 {
40   //
41   // Constructor with Arguments
42   //
43   SetBit(kOwner, 0);
44 //  fHeader->Print();
45 /*  for(Int_t ilevel(0); ilevel<3; ilevel++){
46     printf("L%d :: ", ilevel);
47     Int_t itrig(0); TString tn;
48     do{
49       tn = fHeader->GetTriggerInputName(itrig++, ilevel);
50       printf("%s ", tn.Data());
51     } while(tn.CompareTo(""));
52     printf("\n");
53   }*/
54 }
55
56 //____________________________________________________________________
57 AliTRDeventInfo::AliTRDeventInfo(const AliTRDeventInfo &info):
58   TObject()
59   ,fHeader(info.fHeader)
60   ,fRun(info.fRun)
61   ,fCentrality(info.fCentrality)
62 {
63   //
64   // Copy Constructor
65   // Flat Copy
66   // 
67   SetBit(kOwner, 0);
68 }
69
70 //____________________________________________________________________
71 AliTRDeventInfo& AliTRDeventInfo::operator=(const AliTRDeventInfo& info){
72   //
73   // Operator=
74   // Flat Copy
75   //
76   this->fHeader = info.fHeader;
77   this->fRun = info.fRun;
78   fCentrality = info.fCentrality;
79   SetBit(kOwner, 0);
80   return *this;
81 }
82
83 //____________________________________________________________________
84 AliTRDeventInfo::~AliTRDeventInfo(){
85   //
86   // Destructor
87   // Delete the entries if it is the Owner
88   //
89   Delete("");
90 }
91
92 //____________________________________________________________________
93 void AliTRDeventInfo::Delete(const Option_t *){
94   //
95   // Delete the Object
96   // Delete the entries if it is the Owner
97   // 
98   if(IsOwner()){
99     if(fHeader) delete fHeader;
100     if(fRun) delete fRun;
101   };
102   fHeader = 0x0;
103   fRun = 0x0;
104 }
105
106 //____________________________________________________________________
107 void AliTRDeventInfo::SetOwner()
108 {
109   // Do deep copy
110   
111   SetBit(kOwner, 1);
112   fHeader = new AliESDHeader(*fHeader);
113   fRun = new AliESDRun(*fRun);
114 }
115
116 //____________________________________________________________________
117 void AliTRDeventInfo::GetListOfIsolatedBunches(TH1D* hbc, Int_t bunchSpacing) {
118   //
119   // Find the isolated bunch crossings
120   //
121   // from I.Arsene first implementation in AliTRDcheckESD
122
123   Int_t nBunches(0);
124   Bool_t isIsolated[kLHCbunches]; memset(isIsolated, 0, kLHCbunches*sizeof(Bool_t));
125   for(Int_t bcBin(1); bcBin<=hbc->GetNbinsX(); bcBin++) {
126     Int_t bc(TMath::Nint(hbc->GetBinCenter(bcBin)));
127     if(bc<0 || bc>kLHCbunches) continue; // outside LHC range
128     Double_t entries(hbc->GetBinContent(bcBin));
129     if(entries<1.) continue;             // not filled
130     
131     // check isolation
132     Bool_t kFOUND(kTRUE);
133     for(Int_t ibc = TMath::Max(1,bcBin-bunchSpacing); ibc <= TMath::Min(Int_t(kLHCbunches), bcBin+bunchSpacing); ibc++) {
134       if(ibc==bcBin) continue;
135       if(hbc->GetBinContent(ibc)>0.) {
136         kFOUND = kFALSE;
137         break;
138       }
139     }
140     isIsolated[bc] = kFOUND;
141     if(kFOUND) nBunches++;
142   }   // end loop over BC bins
143
144   printf("Isolated bunches [%d] @ min bunch spacing [%d]:\n{", nBunches, bunchSpacing);
145   for(Int_t ibc(0); ibc<kLHCbunches; ++ibc) if(isIsolated[ibc]) printf("%4d, ", ibc);
146   printf("};\n");
147 }