Fixes for coverity
[u/mrichter/AliRoot.git] / ZDC / AliZDCTriggerProcessor.cxx
1 #include "AliZDCTriggerProcessor.h"
2 #include "AliCDBManager.h"
3 #include "AliCDBEntry.h"
4 #include "AliCDBMetaData.h"
5 #include "AliLog.h"
6 #include "AliZDCTriggerParameters.h"
7
8 /////////////////////////////////////////////////////////////////////
9 //                                                                 //
10 //        Class implementing ZDC  trigger processor.               //
11 //                                                                 //
12 /////////////////////////////////////////////////////////////////////
13
14 ClassImp(AliZDCTriggerProcessor)
15
16 //______________________________________________________________________________________________
17 AliZDCTriggerProcessor::AliZDCTriggerProcessor() :
18   fSignal(0x0),
19   fTriggerParam(0x0)
20 {
21   // default constructor
22 }
23
24 //______________________________________________________________________________________________
25 AliZDCTriggerProcessor::AliZDCTriggerProcessor(Float_t* signal) :
26   fSignal(signal),
27   fTriggerParam(GetTriggerParamFromOCDB())
28 {
29   // standard constructor I 
30   // gets the trigger parameters directly from OCDB
31 }
32
33 //______________________________________________________________________________________________
34 AliZDCTriggerProcessor::AliZDCTriggerProcessor(Float_t* signal, AliZDCTriggerParameters* ocdbParam) :
35   fSignal(signal),
36   fTriggerParam(ocdbParam)
37 {
38   // standard constructor II
39 }
40
41 //_____________________________________________________________________________
42 AliZDCTriggerProcessor &AliZDCTriggerProcessor::operator =(const AliZDCTriggerProcessor &trig)
43 {
44  // Equal operator.
45  this->~AliZDCTriggerProcessor();
46  new(this) AliZDCTriggerProcessor(trig);
47  return *this;  
48
49 }
50
51 //______________________________________________________________________________________________
52 AliZDCTriggerProcessor::AliZDCTriggerProcessor(const AliZDCTriggerProcessor& trigg) :
53   TObject(),
54   fSignal(trigg.fSignal),
55   fTriggerParam(trigg.fTriggerParam)
56 {
57   // copy constructor
58 }
59
60 //______________________________________________________________________________________________
61 AliZDCTriggerProcessor::~AliZDCTriggerProcessor()
62 {
63   // destructor
64 }
65
66 //______________________________________________________________________________________________
67 UInt_t AliZDCTriggerProcessor::ProcessEvent()
68 {
69   // process ZDC signals in order to determine the trigger output
70   UInt_t ctpInput = 0;
71   //
72   Bool_t mbTriggered = MBTrigger();
73   if(mbTriggered == kTRUE) ctpInput = 0x1;
74   Bool_t cenTriggered = CentralTrigger();
75   if(cenTriggered == kTRUE) ctpInput = 0x1 << 1;
76   Bool_t semicenTriggered = SemicentralTrigger();
77   if(semicenTriggered == kTRUE) ctpInput = 0x1 << 2;
78   Bool_t emdTriggered = EMDTrigger();
79   if(emdTriggered == kTRUE) ctpInput = 0x1 << 3;
80   
81   if((mbTriggered == kTRUE) || (cenTriggered == kTRUE) || 
82      (semicenTriggered == kTRUE) || (emdTriggered == kTRUE)){
83       return ctpInput;
84   }
85   else{
86     return 0;
87   }
88 }
89
90 //______________________________________________________________________________________________
91 Bool_t AliZDCTriggerProcessor::MBTrigger()
92 {
93   // is the processed event a MB A-A event?
94   Float_t mbTrheshold = 0.;
95   if(fTriggerParam) mbTrheshold = fTriggerParam->GetADCMBThreshold();
96   // check whether ZDC signal > mbTrheshold
97   if((fSignal[0]+fSignal[1]+fSignal[3]+fSignal[4]) > mbTrheshold)
98        return kTRUE;
99   else return kFALSE;
100   
101 }
102
103 //______________________________________________________________________________________________
104 Bool_t AliZDCTriggerProcessor::CentralTrigger()
105 {
106   // is the processed event a central A-A event?
107   
108   Float_t zemThr = 0;
109   Float_t centralWin[2] = {0,0};
110   if(fTriggerParam){
111     zemThr = fTriggerParam->GetADCZDCCentralityThr();
112     const Float_t* cWin = fTriggerParam->GetADCCentralWindow();
113     centralWin[0] = cWin[0];
114     centralWin[1] = cWin[1];
115   }
116   // 
117   if((fSignal[0]+fSignal[1]+fSignal[3]+fSignal[4]) > centralWin[0]
118      && 
119      (fSignal[0]+fSignal[1]+fSignal[3]+fSignal[4]) < centralWin[1]
120      &&
121      fSignal[2] > zemThr)
122         return kTRUE;
123   else return kFALSE;
124 }
125
126 //______________________________________________________________________________________________
127 Bool_t AliZDCTriggerProcessor::SemicentralTrigger()
128 {
129   // is the processed event a semicentral A-A event?
130   
131   Float_t zemThr = 0;  
132   Float_t semicentralWin[2] = {0,0};
133   if(fTriggerParam){
134     zemThr  =  fTriggerParam->GetADCZDCCentralityThr();
135     const Float_t* cWin =   fTriggerParam->GetADCSemicentralWindow();
136     semicentralWin[0] = cWin[0];
137     semicentralWin[1] = cWin[1];
138   }
139   //
140   if((fSignal[0]+fSignal[1]+fSignal[3]+fSignal[4]) > semicentralWin[0]
141      && 
142      (fSignal[0]+fSignal[1]+fSignal[3]+fSignal[4]) < semicentralWin[1]
143      &&
144      fSignal[2] > zemThr)
145         return kTRUE;
146   else return kFALSE;
147 }
148
149 //______________________________________________________________________________________________
150 Bool_t AliZDCTriggerProcessor::EMDTrigger()
151 {
152   // is the processed an EMD event?
153   
154   Float_t emdWin[4] = {0,0,0,0};
155   if(fTriggerParam){
156     const Float_t* eWin =   fTriggerParam->GetADCEMDWindow();
157     emdWin[0] = eWin[0];
158     emdWin[1] = eWin[1];
159     emdWin[2] = eWin[2];
160     emdWin[3] = eWin[3];
161   }
162   // check whether ZNA AND ZNC signals fall into the 
163   // 2 distinct windows defined for EMD trigger
164   if(fSignal[0] > emdWin[0] && fSignal[0] < emdWin[1]
165      &&
166      fSignal[3] > emdWin[2] && fSignal[3] < emdWin[3])
167         return kTRUE;
168   else return kFALSE;
169 }
170
171 //______________________________________________________________________________________________
172 AliZDCTriggerParameters* AliZDCTriggerProcessor::GetTriggerParamFromOCDB() const
173 {
174   // retrieving trigger parameter configuration form OCDB
175   AliZDCTriggerParameters *trigParam = 0x0;
176   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Trigger/");
177   if(!entry) AliFatal("No calibration data loaded!");  
178   else{
179     trigParam = dynamic_cast<AliZDCTriggerParameters*>  (entry->GetObject());
180     if(!trigParam)  AliFatal("Wrong calibration object in calibration  file!");
181   }
182
183   return trigParam;
184 }