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