Initialisation revisited
[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
15\r
16\r
17// Simulate the VZERO Trigger response\r
18// Use FEE parameters stored in Database\r
19// Can work on real data or in simulation\r
20#include "TTree.h"\r
21#include "TClonesArray.h"\r
22\r
23#include "AliLog.h"\r
24#include "AliCDBManager.h"\r
25#include "AliCDBEntry.h"\r
26#include "AliCDBStorage.h"\r
27#include "AliCDBId.h"\r
28#include "AliVZEROTriggerData.h"\r
29#include "AliVZEROLogicalSignal.h"\r
30#include "AliVZEROTriggerSimulator.h"\r
31#include "AliVZEROdigit.h"\r
32\r
33ClassImp(AliVZEROTriggerSimulator)\r
34\r
a08520b8 35//_____________________________________________________________________________\r
36AliVZEROTriggerSimulator::AliVZEROTriggerSimulator(TTree * digitsTree, TClonesArray* digits) : \r
90c0f772 37TObject(),fTriggerData(NULL),fDigitsTree(digitsTree),fDigits(digits),fTriggerWord(0)\r
a08520b8 38{\r
90c0f772 39 fTriggerData = LoadTriggerData();\r
40 \r
a08520b8 41 for(int i=0;i<64;i++) {\r
42 fBBFlags[i] = fBGFlags[i] = kFALSE;\r
43 fCharges[i] = 0;\r
44 }\r
45 GenerateBBWindows();\r
46 GenerateBGWindows();\r
47 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
48 fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
49 fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
50 fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
51 fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0); \r
52 }\r
53}\r
54//_____________________________________________________________________________\r
55AliVZEROTriggerSimulator::AliVZEROTriggerSimulator() : \r
90c0f772 56TObject(),fTriggerData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)\r
a08520b8 57{\r
90c0f772 58 fTriggerData = LoadTriggerData();\r
59\r
a08520b8 60 for(int i=0;i<64;i++) {\r
61 fBBFlags[i] = fBGFlags[i] = kFALSE;\r
62 fCharges[i] = 0;\r
63 }\r
64 GenerateBBWindows();\r
65 GenerateBGWindows();\r
66 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
67 fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
68 fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
69 fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
70 fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0); \r
71 }\r
72}\r
73\r
74//_____________________________________________________________________________\r
75AliVZEROTriggerSimulator::~AliVZEROTriggerSimulator(){\r
76 if(fBBGate) delete [] fBBGate;\r
77 if(fBGGate) delete [] fBGGate;\r
78 if(fBBLatch) delete [] fBBLatch;\r
79 if(fBBReset) delete [] fBBReset;\r
80 if(fBGLatch) delete [] fBGLatch;\r
81 if(fBGReset) delete [] fBGReset;\r
82}\r
83\r
84//_____________________________________________________________________________\r
85void AliVZEROTriggerSimulator::GenerateBBWindows() \r
86{\r
87 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
88 AliVZEROLogicalSignal Clk1BB(fTriggerData->GetClk1Win1(i),fTriggerData->GetDelayClk1Win1(i));\r
89 AliVZEROLogicalSignal Clk2BB(fTriggerData->GetClk2Win1(i),fTriggerData->GetDelayClk2Win1(i));\r
90 fBBGate[i] = new AliVZEROLogicalSignal(Clk1BB & Clk2BB);\r
91 }\r
92}\r
93//_____________________________________________________________________________\r
94void AliVZEROTriggerSimulator::GenerateBGWindows() \r
95{\r
96 for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
97 AliVZEROLogicalSignal Clk1BG(fTriggerData->GetClk1Win2(i),fTriggerData->GetDelayClk1Win2(i));\r
98 AliVZEROLogicalSignal Clk2BG(fTriggerData->GetClk2Win2(i),fTriggerData->GetDelayClk2Win2(i));\r
99 fBGGate[i] = new AliVZEROLogicalSignal(Clk1BG & Clk2BG);\r
100 }\r
101}\r
102\r
103//_____________________________________________________________________________\r
104AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const \r
105{\r
106 // Gets Trigger object for VZERO set\r
107 AliInfo("Loading Trigger parameters");\r
108 AliCDBManager *man = AliCDBManager::Instance();\r
109 \r
110 \r
111 AliCDBEntry *entry=0;\r
112 \r
113 entry = man->Get("VZERO/Trigger/Data");\r
114 if(!entry){\r
115 AliWarning("Load of calibration data from default storage failed!");\r
116 AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");\r
117 \r
118 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");\r
119 entry = man->Get("VZERO/Trigger/Data",0);\r
120 }\r
121 \r
122 // Retrieval of data in directory VZERO/Calib/Trigger:\r
123 \r
124 AliVZEROTriggerData *triggerData = NULL;\r
125 \r
126 if (entry) triggerData = (AliVZEROTriggerData*) entry->GetObject();\r
127 if (!triggerData) AliError("No Trigger data from database !");\r
128 \r
129 return triggerData;\r
130}\r
131\r
132//_____________________________________________________________________________\r
133void AliVZEROTriggerSimulator::Run() {\r
134 //AliInfo("Generating VZERO Triggers");\r
135 \r
136 // Loop over VZERO entries\r
137 Int_t nEntries = (Int_t)fDigitsTree->GetEntries();\r
138 for (Int_t ievt=0; ievt<nEntries; ievt++) {\r
139 fDigitsTree->GetEvent(ievt);\r
140 \r
141 Int_t nDigits = fDigits->GetEntriesFast();\r
142 \r
143 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {\r
144 AliVZEROdigit* digit = (AliVZEROdigit*)fDigits->At(iDigit);\r
145 \r
146 Int_t integrator = digit->Integrator();\r
147 Int_t pmNumber = digit->PMNumber();\r
148 Int_t board = pmNumber / 8;\r
149 Int_t channel = pmNumber % 8;\r
150 \r
151 if(fTriggerData->GetEnableCharge(board,channel)) {\r
152 fCharges[pmNumber] = digit->ADC();\r
153 if(fTriggerData->GetPedestalSubtraction(board)) \r
154 if(fCharges[pmNumber]>=fTriggerData->GetPedestalCut(integrator,board,channel)){ \r
155 fCharges[pmNumber] -= fTriggerData->GetPedestal(integrator,board,channel);\r
156 } else {\r
157 fCharges[pmNumber] = 0;\r
158 }\r
159 } else {\r
160 fCharges[pmNumber] = 0;\r
161 }\r
162 \r
163 Float_t time = (Float_t)digit->Time() / 10.; // digit->Time() in bin of 100 picoseconds. Divide by 10 to have it in nanoseconds\r
164 time += fTriggerData->GetDelayHit(board,channel);\r
165 \r
166 AliInfo(Form(" PM nb : %d ; ADC= %d ; TDC= %f Enable Time %d charge %d",pmNumber,digit->ADC(),time,fTriggerData->GetEnableTiming(board,channel),fTriggerData->GetEnableCharge(board,channel)));\r
167 fBBFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBBGate[board]->IsInCoincidence(time);\r
168 fBGFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBGGate[board]->IsInCoincidence(time);\r
169 \r
170 } // end of loop over digits\r
171 } // end of loop over events in digits tree\r
172 \r
173 Int_t nBBflagsV0A = 0;\r
174 Int_t nBBflagsV0C = 0;\r
175 Int_t nBGflagsV0A = 0;\r
176 Int_t nBGflagsV0C = 0;\r
177 Int_t chargeV0A = 0;\r
178 Int_t chargeV0C = 0;\r
179\r
180 for(int i=0;i<64;i++) {\r
181 if(i<32) {\r
182 nBBflagsV0C += fBBFlags[i]; \r
183 nBGflagsV0C += fBGFlags[i];\r
184 chargeV0C += fCharges[i];\r
185 } else {\r
186 nBBflagsV0A += fBBFlags[i]; \r
187 nBGflagsV0A += fBGFlags[i];\r
188 chargeV0A += fCharges[i];\r
189 }\r
190 //AliInfo(Form("Ch %d BB=%d BG=%d",i,fBBFlags[i],fBGFlags[i] )); \r
191 }\r
192 \r
193 // BBA\r
194 if(nBBflagsV0A>=fTriggerData->GetBBAThreshold()) SetBBA();\r
195 \r
196 // BBC\r
197 if(nBBflagsV0C>=fTriggerData->GetBBCThreshold()) SetBBC();\r
198\r
199 // BBA_AND_BBC\r
200 if(GetBBA() && GetBBC()) SetBBAandBBC();\r
201 \r
202 // BBA_OR_BBC\r
203 if(GetBBA() || GetBBC()) SetBBAorBBC();\r
204\r
205 // BGA\r
206 if(nBGflagsV0A>=fTriggerData->GetBGAThreshold()) SetBGA();\r
207\r
208 // BGC\r
209 if(nBGflagsV0C>=fTriggerData->GetBGCThreshold()) SetBGC();\r
210 \r
211 // BGA_AND_BBC (Beam Gas from RB24 side)\r
212 if(nBBflagsV0C>=fTriggerData->GetBBCForBGThreshold() && GetBGA()) SetBGAandBBC();\r
213 \r
214 // BGC_AND_BBA (Beam Gas from RB26 side)\r
215 if(nBBflagsV0A>=fTriggerData->GetBBAForBGThreshold() && GetBGC()) SetBGCandBBA();\r
216\r
217 // CTA1_AND_CTC1 (Centrality trigger 1)\r
218 if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() && chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1andCTC1();\r
219\r
220 // CTA1_OR_CTC1 (Centrality trigger 1)\r
221 if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() || chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1orCTC1();\r
222 \r
223 // CTA2_AND_CTC2 (Centrality trigger 2)\r
224 if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() && chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2andCTC2();\r
225 \r
226 // CTA2_OR_CTC2 (Centrality trigger 2)\r
227 if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() || chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2orCTC2();\r
228 \r
229 // MTA_AND_MTC (Multiplicity Trigger)\r
230 if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
231 && (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
232 SetMTAandMTC();\r
233 \r
234 // MTA_OR_MTC (Multiplicity Trigger)\r
235 if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
236 || (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
237 SetMTAorMTC();\r
238 \r
239 // BGA_OR_BGC\r
240 if(GetBGA() || GetBGC()) SetBGAorBGC();\r
241 \r
242 // (BGA and BBC) or (BGC and BBA) (Beam Gas from one of the two sides)\r
243 if(GetBGAandBBC() || GetBGCandBBA()) SetBeamGas();\r
244\r
245 AliInfo(Form("BB Flags : V0A = %d V0C = %d ",nBBflagsV0A, nBBflagsV0C )); \r
246 AliInfo(Form("BG Flags : V0A = %d V0C = %d ",nBGflagsV0A, nBGflagsV0C )); \r
247 AliInfo(Form("Charges : V0A = %d V0C = %d ",chargeV0A, chargeV0C )); \r
248 \r
249}\r
250\r
90c0f772 251\r