Adding methods to calculate the number of trigger flags on each side and fill the...
[u/mrichter/AliRoot.git] / VZERO / AliVZEROTriggerSimulator.cxx
CommitLineData
a08520b8 1/**************************************************************************\r
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
3 * *\r
4 * Author: The ALICE Off-line Project. *\r
5 * Contributors are mentioned in the code where appropriate. *\r
6 * *\r
7 * Permission to use, copy, modify and distribute this software and its *\r
8 * documentation strictly for non-commercial purposes is hereby granted *\r
9 * without fee, provided that the above copyright notice appears in all *\r
10 * copies and that both the copyright notice and this permission notice *\r
11 * appear in the supporting documentation. The authors make no claims *\r
12 * about the suitability of this software for any purpose. It is *\r
13 * provided "as is" without express or implied warranty. *\r
14 **************************************************************************/\r
e370cdfe 15// \r
16// Class AliVZEROTriggerSimulator\r
17// ------------------------------\r
a08520b8 18// Simulate the VZERO Trigger response\r
19// Use FEE parameters stored in Database\r
20// Can work on real data or in simulation\r
e370cdfe 21//\r
22\r
23#include <TTree.h>\r
24#include <TClonesArray.h>\r
d0ff6548 25#include <TParameter.h>\r
a08520b8 26\r
27#include "AliLog.h"\r
28#include "AliCDBManager.h"\r
29#include "AliCDBEntry.h"\r
30#include "AliCDBStorage.h"\r
31#include "AliCDBId.h"\r
32#include "AliVZEROTriggerData.h"\r
33#include "AliVZEROLogicalSignal.h"\r
34#include "AliVZEROTriggerSimulator.h"\r
35#include "AliVZEROdigit.h"\r
d0ff6548 36#include "AliVZEROCalibData.h"\r
37#include "AliVZEROConst.h"\r
26918303 38#include "AliCTPTimeParams.h"\r
a08520b8 39\r
40ClassImp(AliVZEROTriggerSimulator)\r
41\r
a08520b8 42//_____________________________________________________________________________\r
43AliVZEROTriggerSimulator::AliVZEROTriggerSimulator(TTree * digitsTree, TClonesArray* digits) : \r
90c0f772 44TObject(),fTriggerData(NULL),fDigitsTree(digitsTree),fDigits(digits),fTriggerWord(0)\r
a08520b8 45{\r
e370cdfe 46 // constructor\r
90c0f772 47 fTriggerData = LoadTriggerData();\r
26918303 48 LoadClockOffset();\r
90c0f772 49 \r
a08520b8 50 for(int i=0;i<64;i++) {\r
51 fBBFlags[i] = fBGFlags[i] = kFALSE;\r
5978520a 52 fCharges[i] = 0.;\r
a08520b8 53 }\r
54 GenerateBBWindows();\r
55 GenerateBGWindows();\r
56 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
57 fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
58 fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
59 fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
60 fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0); \r
61 }\r
62}\r
63//_____________________________________________________________________________\r
64AliVZEROTriggerSimulator::AliVZEROTriggerSimulator() : \r
90c0f772 65TObject(),fTriggerData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)\r
a08520b8 66{\r
e370cdfe 67 // Default constructor\r
90c0f772 68 fTriggerData = LoadTriggerData();\r
26918303 69 LoadClockOffset();\r
90c0f772 70\r
a08520b8 71 for(int i=0;i<64;i++) {\r
72 fBBFlags[i] = fBGFlags[i] = kFALSE;\r
73 fCharges[i] = 0;\r
74 }\r
75 GenerateBBWindows();\r
76 GenerateBGWindows();\r
77 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
78 fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
79 fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
80 fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
81 fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0); \r
82 }\r
83}\r
84\r
85//_____________________________________________________________________________\r
86AliVZEROTriggerSimulator::~AliVZEROTriggerSimulator(){\r
e370cdfe 87// Destructor\r
63424920 88 for (Int_t i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
89 delete fBBGate[i];\r
90 delete fBGGate[i];\r
91 delete fBBLatch[i];\r
92 delete fBBReset[i];\r
93 delete fBGLatch[i];\r
94 delete fBGReset[i];\r
95 }\r
a08520b8 96}\r
97\r
98//_____________________________________________________________________________\r
99void AliVZEROTriggerSimulator::GenerateBBWindows() \r
100{\r
e370cdfe 101 // Generates the BB observation window\r
a08520b8 102 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
e370cdfe 103 AliVZEROLogicalSignal clk1BB(fTriggerData->GetClk1Win1(i),fTriggerData->GetDelayClk1Win1(i));\r
104 AliVZEROLogicalSignal clk2BB(fTriggerData->GetClk2Win1(i),fTriggerData->GetDelayClk2Win1(i));\r
105 fBBGate[i] = new AliVZEROLogicalSignal(clk1BB & clk2BB);\r
a08520b8 106 }\r
107}\r
108//_____________________________________________________________________________\r
109void AliVZEROTriggerSimulator::GenerateBGWindows() \r
110{\r
e370cdfe 111 // Generates the BG observation window\r
a08520b8 112 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
e370cdfe 113 AliVZEROLogicalSignal clk1BG(fTriggerData->GetClk1Win2(i),fTriggerData->GetDelayClk1Win2(i));\r
114 AliVZEROLogicalSignal clk2BG(fTriggerData->GetClk2Win2(i),fTriggerData->GetDelayClk2Win2(i));\r
115 fBGGate[i] = new AliVZEROLogicalSignal(clk1BG & clk2BG);\r
a08520b8 116 }\r
117}\r
118\r
119//_____________________________________________________________________________\r
120AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const \r
121{\r
122 // Gets Trigger object for VZERO set\r
00ff1707 123 AliDebug(1,"Loading Trigger parameters");\r
a08520b8 124 AliCDBManager *man = AliCDBManager::Instance();\r
125 \r
126 \r
127 AliCDBEntry *entry=0;\r
128 \r
129 entry = man->Get("VZERO/Trigger/Data");\r
130 if(!entry){\r
26918303 131 AliFatal("Load of trigger calibration data from default storage failed!");\r
132 return NULL;\r
a08520b8 133 }\r
134 \r
135 // Retrieval of data in directory VZERO/Calib/Trigger:\r
136 \r
137 AliVZEROTriggerData *triggerData = NULL;\r
138 \r
139 if (entry) triggerData = (AliVZEROTriggerData*) entry->GetObject();\r
140 if (!triggerData) AliError("No Trigger data from database !");\r
141 \r
142 return triggerData;\r
143}\r
144\r
26918303 145\r
146//_____________________________________________________________________________\r
147void AliVZEROTriggerSimulator::LoadClockOffset()\r
148{\r
149 // This method is used in order to\r
150 // retrieve the TDC clock offset including\r
151 // roll-over, trig count and CTP L0->L1 delay\r
152\r
153 AliCDBEntry *entry0 = AliCDBManager::Instance()->Get("VZERO/Calib/Data");\r
154 if (!entry0) {\r
155 AliFatal("V0 Calib object is not found in OCDB !");\r
156 return;\r
157 }\r
158 AliVZEROCalibData *calibdata = (AliVZEROCalibData*) entry0->GetObject();\r
159\r
160 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");\r
161 if (!entry) {\r
162 AliFatal("CTP timing parameters are not found in OCDB !");\r
163 return;\r
164 }\r
165 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();\r
166 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;\r
167\r
168 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");\r
169 if (!entry1) {\r
170 AliFatal("CTP time-alignment is not found in OCDB !");\r
171 return;\r
172 }\r
173 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();\r
174 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);\r
175\r
176 for(Int_t board = 0; board < AliVZEROTriggerData::kNCIUBoards; ++board) {\r
177 fClockOffset[board] = (((Float_t)calibdata->GetRollOver(board)-\r
178 (Float_t)calibdata->GetTriggerCountOffset(board))*25.0-\r
179 l1Delay+\r
180 kV0Offset);\r
181 AliDebug(1,Form("Board %d Offset %f",board,fClockOffset[board]));\r
182 }\r
183}\r
184\r
a08520b8 185//_____________________________________________________________________________\r
186void AliVZEROTriggerSimulator::Run() {\r
187 //AliInfo("Generating VZERO Triggers");\r
188 \r
189 // Loop over VZERO entries\r
190 Int_t nEntries = (Int_t)fDigitsTree->GetEntries();\r
191 for (Int_t ievt=0; ievt<nEntries; ievt++) {\r
192 fDigitsTree->GetEvent(ievt);\r
193 \r
194 Int_t nDigits = fDigits->GetEntriesFast();\r
195 \r
196 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {\r
197 AliVZEROdigit* digit = (AliVZEROdigit*)fDigits->At(iDigit);\r
198 \r
199 Int_t integrator = digit->Integrator();\r
200 Int_t pmNumber = digit->PMNumber();\r
d0ff6548 201 Int_t board = AliVZEROCalibData::GetBoardNumber(pmNumber);\r
202 Int_t channel = AliVZEROCalibData::GetFEEChannelNumber(pmNumber);\r
127e0d90 203 if (board < 0 || channel < 0) continue;\r
a08520b8 204 \r
205 if(fTriggerData->GetEnableCharge(board,channel)) {\r
d0ff6548 206 fCharges[pmNumber] = digit->ChargeADC(AliVZEROdigit::kNClocks/2);\r
e370cdfe 207 if(fTriggerData->GetPedestalSubtraction(board)) {\r
5978520a 208 if(fCharges[pmNumber]>=(Float_t) fTriggerData->GetPedestalCut(integrator,board,channel)){ \r
209 fCharges[pmNumber] -= (Float_t) fTriggerData->GetPedestal(integrator,board,channel);\r
a08520b8 210 } else {\r
5978520a 211 fCharges[pmNumber] = 0.;\r
a08520b8 212 }\r
e370cdfe 213 }\r
a08520b8 214 } else {\r
5978520a 215 fCharges[pmNumber] = 0.;\r
a08520b8 216 }\r
217 \r
d0ff6548 218 Float_t time = digit->Time();\r
26918303 219 time -= fClockOffset[board];\r
d0ff6548 220\r
221 AliDebug(10,Form(" Digit: %f %d %d %d %d %d %d %d %d",digit->Time(),\r
222 digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),\r
223 digit->ChargeADC(11),digit->ChargeADC(12),digit->ChargeADC(13),\r
224 digit->ChargeADC(14),digit->ChargeADC(15)));\r
b47d88ce 225 AliDebug(10,Form(" PM nb : %d ; TDC= %f(%f) Enable Time %d charge %d inCoin %d charge %f",\r
226 pmNumber,time,digit->Time(),\r
d0ff6548 227 fTriggerData->GetEnableTiming(board,channel),fTriggerData->GetEnableCharge(board,channel),\r
228 fBBGate[board]->IsInCoincidence(time),fCharges[pmNumber]));\r
a08520b8 229 fBBFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBBGate[board]->IsInCoincidence(time);\r
230 fBGFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBGGate[board]->IsInCoincidence(time);\r
231 \r
232 } // end of loop over digits\r
233 } // end of loop over events in digits tree\r
234 \r
235 Int_t nBBflagsV0A = 0;\r
236 Int_t nBBflagsV0C = 0;\r
237 Int_t nBGflagsV0A = 0;\r
238 Int_t nBGflagsV0C = 0;\r
5978520a 239 Float_t chargeV0A = 0.;\r
240 Float_t chargeV0C = 0.;\r
d0ff6548 241 Int_t aBBflagsV0A = 0;\r
242 Int_t aBBflagsV0C = 0;\r
243 Int_t aBGflagsV0A = 0;\r
244 Int_t aBGflagsV0C = 0;\r
a08520b8 245\r
246 for(int i=0;i<64;i++) {\r
247 if(i<32) {\r
248 nBBflagsV0C += fBBFlags[i]; \r
249 nBGflagsV0C += fBGFlags[i];\r
250 chargeV0C += fCharges[i];\r
d0ff6548 251 if (fBBFlags[i]) aBBflagsV0C |= (1 << i);\r
252 if (fBGFlags[i]) aBGflagsV0C |= (1 << i);\r
a08520b8 253 } else {\r
254 nBBflagsV0A += fBBFlags[i]; \r
255 nBGflagsV0A += fBGFlags[i];\r
256 chargeV0A += fCharges[i];\r
d0ff6548 257 if (fBBFlags[i]) aBBflagsV0A |= (1 << (i-32));\r
258 if (fBGFlags[i]) aBGflagsV0A |= (1 << (i-32));\r
a08520b8 259 }\r
260 //AliInfo(Form("Ch %d BB=%d BG=%d",i,fBBFlags[i],fBGFlags[i] )); \r
261 }\r
d0ff6548 262\r
263 // Store the BB and BG flags in the digits tree (user info)\r
264 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0A",aBBflagsV0A));\r
265 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0C",aBBflagsV0C));\r
266 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0A",aBGflagsV0A));\r
267 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0C",aBGflagsV0C));\r
a08520b8 268 \r
269 // BBA\r
270 if(nBBflagsV0A>=fTriggerData->GetBBAThreshold()) SetBBA();\r
271 \r
272 // BBC\r
273 if(nBBflagsV0C>=fTriggerData->GetBBCThreshold()) SetBBC();\r
274\r
275 // BBA_AND_BBC\r
276 if(GetBBA() && GetBBC()) SetBBAandBBC();\r
277 \r
278 // BBA_OR_BBC\r
279 if(GetBBA() || GetBBC()) SetBBAorBBC();\r
280\r
281 // BGA\r
282 if(nBGflagsV0A>=fTriggerData->GetBGAThreshold()) SetBGA();\r
283\r
284 // BGC\r
285 if(nBGflagsV0C>=fTriggerData->GetBGCThreshold()) SetBGC();\r
286 \r
287 // BGA_AND_BBC (Beam Gas from RB24 side)\r
288 if(nBBflagsV0C>=fTriggerData->GetBBCForBGThreshold() && GetBGA()) SetBGAandBBC();\r
289 \r
290 // BGC_AND_BBA (Beam Gas from RB26 side)\r
291 if(nBBflagsV0A>=fTriggerData->GetBBAForBGThreshold() && GetBGC()) SetBGCandBBA();\r
292\r
293 // CTA1_AND_CTC1 (Centrality trigger 1)\r
294 if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() && chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1andCTC1();\r
295\r
296 // CTA1_OR_CTC1 (Centrality trigger 1)\r
297 if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() || chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1orCTC1();\r
298 \r
299 // CTA2_AND_CTC2 (Centrality trigger 2)\r
300 if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() && chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2andCTC2();\r
301 \r
302 // CTA2_OR_CTC2 (Centrality trigger 2)\r
303 if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() || chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2orCTC2();\r
304 \r
305 // MTA_AND_MTC (Multiplicity Trigger)\r
306 if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
307 && (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
308 SetMTAandMTC();\r
309 \r
310 // MTA_OR_MTC (Multiplicity Trigger)\r
311 if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
312 || (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
313 SetMTAorMTC();\r
314 \r
315 // BGA_OR_BGC\r
316 if(GetBGA() || GetBGC()) SetBGAorBGC();\r
317 \r
318 // (BGA and BBC) or (BGC and BBA) (Beam Gas from one of the two sides)\r
319 if(GetBGAandBBC() || GetBGCandBBA()) SetBeamGas();\r
320\r
e370cdfe 321// AliInfo(Form("BB Flags : V0A = %d V0C = %d ",nBBflagsV0A, nBBflagsV0C )); \r
322// AliInfo(Form("BG Flags : V0A = %d V0C = %d ",nBGflagsV0A, nBGflagsV0C )); \r
323// AliInfo(Form("Charges : V0A = %d V0C = %d ",chargeV0A, chargeV0C )); \r
a08520b8 324 \r
325}\r
326\r
90c0f772 327\r
e370cdfe 328\r