made bugfix 25978 into a generic protection
[u/mrichter/AliRoot.git] / MUON / MUONReCalcGlobalTrigger.C
CommitLineData
c45527c1 1/// \ingroup macros
2/// \file MUONReCalcGlobalTrigger.C
3/// \brief Re-calculate regional/global trigger response from local response.
4///
5/// Basic usage is :
6///
7/// MUONReCalcGlobalTrigger("path_to_reconstruction_galice");
8///
9/// Starting from local responses the macro will re-calculate regional and
10/// global response and print-out the global trigger decision.
11/// It is used for comissioning data with cosmics where the global trigger
12/// was not written in the raw stream.
13/// The purpose is (for the future) to compare the re-calculated answer with
14/// the global trigger decision returned by the CTP.
15///
16/// \author Bogdan Vulpescu
17
18#if !defined(__CINT__) || defined(__MAKECINT__)
19
20#include "AliCDBManager.h"
21#include "AliMpCDB.h"
22#include "AliMUONCalibrationData.h"
23#include "AliMUONTriggerCrateStore.h"
24#include "AliMUONGlobalTriggerBoard.h"
25#include "AliMUONDataInterface.h"
26#include "AliMUONLocalTrigger.h"
27#include "AliMUONVTriggerStore.h"
28#include "AliMUONTriggerCrate.h"
29#include "AliMUONRegionalTriggerBoard.h"
30#include "AliMUONLocalTriggerBoard.h"
31#include "AliMUONVCalibParam.h"
32#include "AliMUONTriggerBoard.h"
33
34#include <TArrayS.h>
35#include <TIterator.h>
36#include <TObjArray.h>
37#include <TMath.h>
38
39#endif
40
41UShort_t locResp[235];
42
43AliMUONCalibrationData *calibData;
44AliMUONTriggerCrateStore *fCrates;
45AliMUONGlobalTriggerBoard *fGlobalTriggerBoard;
46
47Int_t debug;
48
49//___________________________________________________________________________
50void PrintPattBin(Short_t s) {
51 /// binary print-out of the strip patterns
52
53 printf(" ");
54 Int_t mask = 0;
55 for (Int_t i = 15; i >= 0; i--) {
56 mask = (Int_t)TMath::Power(2,i);
57 printf("%1d",(s & mask) >> i);
58 }
59 printf(" \n");
60
61}
62
63//___________________________________________________________________________
64void PrintGloBin(UShort_t s) {
65 /// binary print-out of global trigger decision
66
67 Int_t mask = 0;
68 for (Int_t i = 5; i >= 0; i--) {
69 mask = (Int_t)TMath::Power(2,i);
70 printf("%1d",(s & mask) >> i);
71 }
72 printf(" \n");
73
74}
75
76//___________________________________________________________________________
77Bool_t ReCalcGlobalTrigger() {
78 /// re-calculate regional/global decision from array of local triggers
79
80 Int_t loLpt, loHpt;
81 AliMUONTriggerCrate* cr;
82
83 // regional response
84
85 fCrates->FirstCrate();
86
87 Int_t irb(0);
88
89 while ( ( cr = fCrates->NextCrate() ) ) {
90
91 if (debug) printf("Crate nr = %2d \n",++irb);
92
93 TObjArray *boards = cr->Boards();
94
95 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
96 regb->Reset();
97
98 Int_t nrBoard = 0;
99
100 UShort_t regLocResp[16]; for (Int_t j=0; j<16; j++) regLocResp[j] = 0;
101
102 for (Int_t j = 1; j < boards->GetEntries(); j++) {
103
104 TObject *o = boards->At(j);
105
106 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
107
108 if (board->GetNumber() == 0) continue;
109
110 if (debug) {
111 printf("...Board nr = %2d : ",++nrBoard);
112 printf("%3d %s in slot %2d of crate %s \n",board->GetNumber(),board->GetName(),j,cr->GetName());
113 }
114
115 UShort_t response = locResp[board->GetNumber()];
116
117 if (debug) printf("......Response = %x \n",response);
118
119 if (response != 0) {
120 loLpt = response & 3;
121 loHpt = (response & 12) >> 2;
122 //printf("Response loLpt = %02b loHpt = %02b \n",loLpt,loHpt);
123 }
124
125 regLocResp[j-1] = response;
126
127 } // local board loop
128
129 AliMUONVCalibParam* regionalBoardMasks = calibData->RegionalTriggerBoardMasks(irb);
130 UShort_t rmask = static_cast<UShort_t>(regionalBoardMasks->ValueAsInt(0) & 0xFFFF);
131 regb->Mask(rmask);
132 regb->SetLocalResponse(regLocResp);
133 regb->Response();
134 //for (Int_t j=0; j<16; j++) printf("%3d ",regLocResp[j]);
135 //printf("Reg %2d Response %3d mask %4x\n",irb,regb->GetResponse(),rmask);
136
137 irb++;
138
139 } // crate loop
140
141 // global response
142
143 fGlobalTriggerBoard->Reset();
144
145 AliMUONVCalibParam* globalBoardMasks = calibData->GlobalTriggerBoardMasks();
146 for ( Int_t i = 0; i < globalBoardMasks->Size(); ++i ) {
147 UShort_t gmask = static_cast<UShort_t>(globalBoardMasks->ValueAsInt(i) & 0xFF);
148 fGlobalTriggerBoard->Mask(i,gmask);
149 }
150
151 fCrates->FirstCrate();
152
153 UShort_t regional[16];
154 irb = 0;
155
156 if ( !fCrates->NumberOfCrates() >= 16 ) {
157 printf("Something is wrong : too many crates %d",fCrates->NumberOfCrates());
158 return kFALSE;
159 }
160
161 while ( ( cr = fCrates->NextCrate() ) ) {
162 AliMUONTriggerBoard* rb =
163 static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
164 regional[irb] = rb->GetResponse();
165 ++irb;
166 }
167
168 fGlobalTriggerBoard->SetRegionalResponse(regional);
169 fGlobalTriggerBoard->Response();
170
171 if (fGlobalTriggerBoard->GetResponse() != 0) {
172 fGlobalTriggerBoard->Scan("");
173 printf("Global trigger response = ");
174 PrintGloBin(fGlobalTriggerBoard->GetResponse());
175 return kTRUE;
176 }
177
178 return kFALSE;
179
180}
181
182//___________________________________________________________________________
183void MUONReCalcGlobalTrigger(const char* input) {
184 /// create array of local triggers from the raw data, run the re-calculation
185 /// and print-out the results
186
187 debug = 0;
188
189 Int_t runNumber = 0;
190
191 AliCDBManager* man = AliCDBManager::Instance();
192 man->SetDefaultStorage("local://$ALICE_ROOT");
193 man->SetRun(runNumber);
194 AliMpCDB::LoadDDLStore();
195
196 calibData = new AliMUONCalibrationData(runNumber);
197
198 fCrates = new AliMUONTriggerCrateStore;
199 fCrates->ReadFromFile();
200 fGlobalTriggerBoard = new AliMUONGlobalTriggerBoard;
201
202 AliMUONDataInterface diRec(input);
203
204 printf("Number of events = %d \n",diRec.NumberOfEvents());
205 Int_t nEvents = diRec.NumberOfEvents();
206
207 AliMUONLocalTrigger* localTrig;
208 Int_t circ, loLpt, loHpt, lutLpt[2], lutHpt[2];
209 TArrayS xPattern[235];
210 TArrayS yPattern[235];
211
212 nEvents = 100;
213 for (Int_t ievent = 0; ievent < nEvents; ++ievent) {
214
215 for (Int_t i = 0; i < 234; i++) {
216 locResp[i] = 0;
217 }
218
219 AliMUONVTriggerStore* triggerStore = diRec.TriggerStore(ievent,"R");
220 TIter nextLocal(triggerStore->CreateLocalIterator());
221 while ( (localTrig = static_cast<AliMUONLocalTrigger*>( nextLocal() )) != NULL ) {
222 circ = localTrig->LoCircuit();
223
224 loLpt = localTrig->LoLpt();
225 loHpt = localTrig->LoHpt();
226
227 lutLpt[0] = loLpt & 1;
228 lutLpt[1] = (loLpt & 2) >> 1;
229 lutHpt[0] = loHpt & 1;
230 lutHpt[1] = (loHpt & 2) >> 1;
231
232 locResp[circ] = lutLpt[0] +
233 static_cast<int>(lutLpt[1]<<1) +
234 static_cast<int>(lutHpt[0]<<2) +
235 static_cast<int>(lutHpt[1]<<3);
236
237 localTrig->GetXPattern(xPattern[circ]);
238 localTrig->GetYPattern(yPattern[circ]);
239
240 if (debug) {
241 printf("Event %4d circ %3d loLpt %1d loHpt %1d resp %3d\n",ievent,circ,loLpt,loHpt,locResp[circ]);
242 }
243
244 } // local trigger loop
245
246 if (ReCalcGlobalTrigger()) {
247 printf("............ for event %5d \n",ievent);
248 for (Int_t ic = 1; ic <= 234; ic++) {
249 if (locResp[ic] != 0) {
250 UShort_t response = locResp[ic];
251 loLpt = response & 3;
252 loHpt = (response & 12) >> 2;
253 printf("............ in circuit %3d loLpt %1d loHpt %1d resp %3d\n",ic,loLpt,loHpt,response);
254
255 printf(" Pattern X:\n");
256 PrintPattBin(xPattern[ic].At(0));
257 PrintPattBin(xPattern[ic].At(1));
258 PrintPattBin(xPattern[ic].At(2));
259 PrintPattBin(xPattern[ic].At(3));
260 printf(" Pattern Y:\n");
261 PrintPattBin(yPattern[ic].At(0));
262 PrintPattBin(yPattern[ic].At(1));
263 PrintPattBin(yPattern[ic].At(2));
264 PrintPattBin(yPattern[ic].At(3));
265
266 }
267 }
268 printf("\n\n");
269 }
270
271 } // event loop
272
273}
274