Additional protection
[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
a08520b8 38\r
39ClassImp(AliVZEROTriggerSimulator)\r
40\r
a08520b8 41//_____________________________________________________________________________\r
42AliVZEROTriggerSimulator::AliVZEROTriggerSimulator(TTree * digitsTree, TClonesArray* digits) : \r
90c0f772 43TObject(),fTriggerData(NULL),fDigitsTree(digitsTree),fDigits(digits),fTriggerWord(0)\r
a08520b8 44{\r
e370cdfe 45 // constructor\r
90c0f772 46 fTriggerData = LoadTriggerData();\r
47 \r
a08520b8 48 for(int i=0;i<64;i++) {\r
49 fBBFlags[i] = fBGFlags[i] = kFALSE;\r
5978520a 50 fCharges[i] = 0.;\r
a08520b8 51 }\r
52 GenerateBBWindows();\r
53 GenerateBGWindows();\r
54 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
55 fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
56 fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
57 fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
58 fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0); \r
59 }\r
60}\r
61//_____________________________________________________________________________\r
62AliVZEROTriggerSimulator::AliVZEROTriggerSimulator() : \r
90c0f772 63TObject(),fTriggerData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)\r
a08520b8 64{\r
e370cdfe 65 // Default constructor\r
90c0f772 66 fTriggerData = LoadTriggerData();\r
67\r
a08520b8 68 for(int i=0;i<64;i++) {\r
69 fBBFlags[i] = fBGFlags[i] = kFALSE;\r
70 fCharges[i] = 0;\r
71 }\r
72 GenerateBBWindows();\r
73 GenerateBGWindows();\r
74 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
75 fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
76 fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
77 fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
78 fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0); \r
79 }\r
80}\r
81\r
82//_____________________________________________________________________________\r
83AliVZEROTriggerSimulator::~AliVZEROTriggerSimulator(){\r
e370cdfe 84// Destructor\r
a08520b8 85 if(fBBGate) delete [] fBBGate;\r
86 if(fBGGate) delete [] fBGGate;\r
87 if(fBBLatch) delete [] fBBLatch;\r
88 if(fBBReset) delete [] fBBReset;\r
89 if(fBGLatch) delete [] fBGLatch;\r
90 if(fBGReset) delete [] fBGReset;\r
91}\r
92\r
93//_____________________________________________________________________________\r
94void AliVZEROTriggerSimulator::GenerateBBWindows() \r
95{\r
e370cdfe 96 // Generates the BB observation window\r
a08520b8 97 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
e370cdfe 98 AliVZEROLogicalSignal clk1BB(fTriggerData->GetClk1Win1(i),fTriggerData->GetDelayClk1Win1(i));\r
99 AliVZEROLogicalSignal clk2BB(fTriggerData->GetClk2Win1(i),fTriggerData->GetDelayClk2Win1(i));\r
100 fBBGate[i] = new AliVZEROLogicalSignal(clk1BB & clk2BB);\r
a08520b8 101 }\r
102}\r
103//_____________________________________________________________________________\r
104void AliVZEROTriggerSimulator::GenerateBGWindows() \r
105{\r
e370cdfe 106 // Generates the BG observation window\r
a08520b8 107 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
e370cdfe 108 AliVZEROLogicalSignal clk1BG(fTriggerData->GetClk1Win2(i),fTriggerData->GetDelayClk1Win2(i));\r
109 AliVZEROLogicalSignal clk2BG(fTriggerData->GetClk2Win2(i),fTriggerData->GetDelayClk2Win2(i));\r
110 fBGGate[i] = new AliVZEROLogicalSignal(clk1BG & clk2BG);\r
a08520b8 111 }\r
112}\r
113\r
114//_____________________________________________________________________________\r
115AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const \r
116{\r
117 // Gets Trigger object for VZERO set\r
00ff1707 118 AliDebug(1,"Loading Trigger parameters");\r
a08520b8 119 AliCDBManager *man = AliCDBManager::Instance();\r
120 \r
121 \r
122 AliCDBEntry *entry=0;\r
123 \r
124 entry = man->Get("VZERO/Trigger/Data");\r
125 if(!entry){\r
126 AliWarning("Load of calibration data from default storage failed!");\r
127 AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");\r
128 \r
129 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");\r
130 entry = man->Get("VZERO/Trigger/Data",0);\r
131 }\r
132 \r
133 // Retrieval of data in directory VZERO/Calib/Trigger:\r
134 \r
135 AliVZEROTriggerData *triggerData = NULL;\r
136 \r
137 if (entry) triggerData = (AliVZEROTriggerData*) entry->GetObject();\r
138 if (!triggerData) AliError("No Trigger data from database !");\r
139 \r
140 return triggerData;\r
141}\r
142\r
143//_____________________________________________________________________________\r
144void AliVZEROTriggerSimulator::Run() {\r
145 //AliInfo("Generating VZERO Triggers");\r
146 \r
147 // Loop over VZERO entries\r
148 Int_t nEntries = (Int_t)fDigitsTree->GetEntries();\r
149 for (Int_t ievt=0; ievt<nEntries; ievt++) {\r
150 fDigitsTree->GetEvent(ievt);\r
151 \r
152 Int_t nDigits = fDigits->GetEntriesFast();\r
153 \r
154 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {\r
155 AliVZEROdigit* digit = (AliVZEROdigit*)fDigits->At(iDigit);\r
156 \r
157 Int_t integrator = digit->Integrator();\r
158 Int_t pmNumber = digit->PMNumber();\r
d0ff6548 159 Int_t board = AliVZEROCalibData::GetBoardNumber(pmNumber);\r
160 Int_t channel = AliVZEROCalibData::GetFEEChannelNumber(pmNumber);\r
a08520b8 161 \r
162 if(fTriggerData->GetEnableCharge(board,channel)) {\r
d0ff6548 163 fCharges[pmNumber] = digit->ChargeADC(AliVZEROdigit::kNClocks/2);\r
e370cdfe 164 if(fTriggerData->GetPedestalSubtraction(board)) {\r
5978520a 165 if(fCharges[pmNumber]>=(Float_t) fTriggerData->GetPedestalCut(integrator,board,channel)){ \r
166 fCharges[pmNumber] -= (Float_t) fTriggerData->GetPedestal(integrator,board,channel);\r
a08520b8 167 } else {\r
5978520a 168 fCharges[pmNumber] = 0.;\r
a08520b8 169 }\r
e370cdfe 170 }\r
a08520b8 171 } else {\r
5978520a 172 fCharges[pmNumber] = 0.;\r
a08520b8 173 }\r
174 \r
d0ff6548 175 Float_t time = digit->Time();\r
176 time -= kClockOffset;\r
177\r
178 AliDebug(10,Form(" Digit: %f %d %d %d %d %d %d %d %d",digit->Time(),\r
179 digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),\r
180 digit->ChargeADC(11),digit->ChargeADC(12),digit->ChargeADC(13),\r
181 digit->ChargeADC(14),digit->ChargeADC(15)));\r
b47d88ce 182 AliDebug(10,Form(" PM nb : %d ; TDC= %f(%f) Enable Time %d charge %d inCoin %d charge %f",\r
183 pmNumber,time,digit->Time(),\r
d0ff6548 184 fTriggerData->GetEnableTiming(board,channel),fTriggerData->GetEnableCharge(board,channel),\r
185 fBBGate[board]->IsInCoincidence(time),fCharges[pmNumber]));\r
a08520b8 186 fBBFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBBGate[board]->IsInCoincidence(time);\r
187 fBGFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBGGate[board]->IsInCoincidence(time);\r
188 \r
189 } // end of loop over digits\r
190 } // end of loop over events in digits tree\r
191 \r
192 Int_t nBBflagsV0A = 0;\r
193 Int_t nBBflagsV0C = 0;\r
194 Int_t nBGflagsV0A = 0;\r
195 Int_t nBGflagsV0C = 0;\r
5978520a 196 Float_t chargeV0A = 0.;\r
197 Float_t chargeV0C = 0.;\r
d0ff6548 198 Int_t aBBflagsV0A = 0;\r
199 Int_t aBBflagsV0C = 0;\r
200 Int_t aBGflagsV0A = 0;\r
201 Int_t aBGflagsV0C = 0;\r
a08520b8 202\r
203 for(int i=0;i<64;i++) {\r
204 if(i<32) {\r
205 nBBflagsV0C += fBBFlags[i]; \r
206 nBGflagsV0C += fBGFlags[i];\r
207 chargeV0C += fCharges[i];\r
d0ff6548 208 if (fBBFlags[i]) aBBflagsV0C |= (1 << i);\r
209 if (fBGFlags[i]) aBGflagsV0C |= (1 << i);\r
a08520b8 210 } else {\r
211 nBBflagsV0A += fBBFlags[i]; \r
212 nBGflagsV0A += fBGFlags[i];\r
213 chargeV0A += fCharges[i];\r
d0ff6548 214 if (fBBFlags[i]) aBBflagsV0A |= (1 << (i-32));\r
215 if (fBGFlags[i]) aBGflagsV0A |= (1 << (i-32));\r
a08520b8 216 }\r
217 //AliInfo(Form("Ch %d BB=%d BG=%d",i,fBBFlags[i],fBGFlags[i] )); \r
218 }\r
d0ff6548 219\r
220 // Store the BB and BG flags in the digits tree (user info)\r
221 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0A",aBBflagsV0A));\r
222 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0C",aBBflagsV0C));\r
223 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0A",aBGflagsV0A));\r
224 fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0C",aBGflagsV0C));\r
a08520b8 225 \r
226 // BBA\r
227 if(nBBflagsV0A>=fTriggerData->GetBBAThreshold()) SetBBA();\r
228 \r
229 // BBC\r
230 if(nBBflagsV0C>=fTriggerData->GetBBCThreshold()) SetBBC();\r
231\r
232 // BBA_AND_BBC\r
233 if(GetBBA() && GetBBC()) SetBBAandBBC();\r
234 \r
235 // BBA_OR_BBC\r
236 if(GetBBA() || GetBBC()) SetBBAorBBC();\r
237\r
238 // BGA\r
239 if(nBGflagsV0A>=fTriggerData->GetBGAThreshold()) SetBGA();\r
240\r
241 // BGC\r
242 if(nBGflagsV0C>=fTriggerData->GetBGCThreshold()) SetBGC();\r
243 \r
244 // BGA_AND_BBC (Beam Gas from RB24 side)\r
245 if(nBBflagsV0C>=fTriggerData->GetBBCForBGThreshold() && GetBGA()) SetBGAandBBC();\r
246 \r
247 // BGC_AND_BBA (Beam Gas from RB26 side)\r
248 if(nBBflagsV0A>=fTriggerData->GetBBAForBGThreshold() && GetBGC()) SetBGCandBBA();\r
249\r
250 // CTA1_AND_CTC1 (Centrality trigger 1)\r
251 if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() && chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1andCTC1();\r
252\r
253 // CTA1_OR_CTC1 (Centrality trigger 1)\r
254 if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() || chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1orCTC1();\r
255 \r
256 // CTA2_AND_CTC2 (Centrality trigger 2)\r
257 if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() && chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2andCTC2();\r
258 \r
259 // CTA2_OR_CTC2 (Centrality trigger 2)\r
260 if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() || chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2orCTC2();\r
261 \r
262 // MTA_AND_MTC (Multiplicity Trigger)\r
263 if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
264 && (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
265 SetMTAandMTC();\r
266 \r
267 // MTA_OR_MTC (Multiplicity Trigger)\r
268 if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
269 || (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
270 SetMTAorMTC();\r
271 \r
272 // BGA_OR_BGC\r
273 if(GetBGA() || GetBGC()) SetBGAorBGC();\r
274 \r
275 // (BGA and BBC) or (BGC and BBA) (Beam Gas from one of the two sides)\r
276 if(GetBGAandBBC() || GetBGCandBBA()) SetBeamGas();\r
277\r
e370cdfe 278// AliInfo(Form("BB Flags : V0A = %d V0C = %d ",nBBflagsV0A, nBBflagsV0C )); \r
279// AliInfo(Form("BG Flags : V0A = %d V0C = %d ",nBGflagsV0A, nBGflagsV0C )); \r
280// AliInfo(Form("Charges : V0A = %d V0C = %d ",chargeV0A, chargeV0C )); \r
a08520b8 281 \r
282}\r
283\r
90c0f772 284\r
e370cdfe 285\r