]>
Commit | Line | Data |
---|---|---|
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" | |
b1d66c10 | 29 | #include "AliMUONTriggerCrateConfig.h" |
30 | #include "AliMUONGlobalCrateConfig.h" | |
c45527c1 | 31 | #include "AliMUONRegionalTriggerBoard.h" |
b1d66c10 | 32 | #include "AliMUONRegionalTriggerConfig.h" |
c45527c1 | 33 | #include "AliMUONLocalTriggerBoard.h" |
34 | #include "AliMUONVCalibParam.h" | |
35 | #include "AliMUONTriggerBoard.h" | |
36 | ||
37 | #include <TArrayS.h> | |
c45527c1 | 38 | #include <TObjArray.h> |
39 | #include <TMath.h> | |
40 | ||
41 | #endif | |
42 | ||
43 | UShort_t locResp[235]; | |
44 | ||
45 | AliMUONCalibrationData *calibData; | |
46 | AliMUONTriggerCrateStore *fCrates; | |
47 | AliMUONGlobalTriggerBoard *fGlobalTriggerBoard; | |
b1d66c10 | 48 | AliMUONRegionalTriggerConfig* regionalConfig; |
49 | AliMUONGlobalCrateConfig * globalConfig; | |
50 | ||
51 | TIterator *cratesIterator; | |
c45527c1 | 52 | |
53 | Int_t debug; | |
54 | ||
55 | //___________________________________________________________________________ | |
56 | void PrintPattBin(Short_t s) { | |
57 | /// binary print-out of the strip patterns | |
58 | ||
59 | printf(" "); | |
60 | Int_t mask = 0; | |
61 | for (Int_t i = 15; i >= 0; i--) { | |
62 | mask = (Int_t)TMath::Power(2,i); | |
63 | printf("%1d",(s & mask) >> i); | |
64 | } | |
65 | printf(" \n"); | |
66 | ||
67 | } | |
68 | ||
69 | //___________________________________________________________________________ | |
70 | void PrintGloBin(UShort_t s) { | |
71 | /// binary print-out of global trigger decision | |
72 | ||
73 | Int_t mask = 0; | |
74 | for (Int_t i = 5; i >= 0; i--) { | |
75 | mask = (Int_t)TMath::Power(2,i); | |
76 | printf("%1d",(s & mask) >> i); | |
77 | } | |
78 | printf(" \n"); | |
79 | ||
80 | } | |
81 | ||
82 | //___________________________________________________________________________ | |
b1d66c10 | 83 | Bool_t ReCalcGlobalTrigger(TIter *nextCrates) { |
c45527c1 | 84 | /// re-calculate regional/global decision from array of local triggers |
85 | ||
86 | Int_t loLpt, loHpt; | |
87 | AliMUONTriggerCrate* cr; | |
88 | ||
89 | // regional response | |
90 | ||
b1d66c10 | 91 | nextCrates->Reset(); |
c45527c1 | 92 | |
93 | Int_t irb(0); | |
94 | ||
b1d66c10 | 95 | while ( ( cr = static_cast<AliMUONTriggerCrate*>(nextCrates->Next()) ) ) { |
c45527c1 | 96 | |
97 | if (debug) printf("Crate nr = %2d \n",++irb); | |
98 | ||
99 | TObjArray *boards = cr->Boards(); | |
100 | ||
101 | AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0); | |
102 | regb->Reset(); | |
103 | ||
104 | Int_t nrBoard = 0; | |
105 | ||
106 | UShort_t regLocResp[16]; for (Int_t j=0; j<16; j++) regLocResp[j] = 0; | |
107 | ||
108 | for (Int_t j = 1; j < boards->GetEntries(); j++) { | |
109 | ||
110 | TObject *o = boards->At(j); | |
111 | ||
112 | AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o; | |
113 | ||
114 | if (board->GetNumber() == 0) continue; | |
115 | ||
116 | if (debug) { | |
117 | printf("...Board nr = %2d : ",++nrBoard); | |
118 | printf("%3d %s in slot %2d of crate %s \n",board->GetNumber(),board->GetName(),j,cr->GetName()); | |
119 | } | |
120 | ||
121 | UShort_t response = locResp[board->GetNumber()]; | |
122 | ||
123 | if (debug) printf("......Response = %x \n",response); | |
124 | ||
125 | if (response != 0) { | |
126 | loLpt = response & 3; | |
127 | loHpt = (response & 12) >> 2; | |
128 | //printf("Response loLpt = %02b loHpt = %02b \n",loLpt,loHpt); | |
129 | } | |
130 | ||
131 | regLocResp[j-1] = response; | |
132 | ||
133 | } // local board loop | |
134 | ||
b1d66c10 | 135 | AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName()); |
136 | UShort_t rmask= crateConfig->GetMask(); | |
c45527c1 | 137 | regb->Mask(rmask); |
138 | regb->SetLocalResponse(regLocResp); | |
139 | regb->Response(); | |
140 | //for (Int_t j=0; j<16; j++) printf("%3d ",regLocResp[j]); | |
141 | //printf("Reg %2d Response %3d mask %4x\n",irb,regb->GetResponse(),rmask); | |
142 | ||
143 | irb++; | |
144 | ||
145 | } // crate loop | |
146 | ||
147 | // global response | |
148 | ||
149 | fGlobalTriggerBoard->Reset(); | |
150 | ||
b1d66c10 | 151 | if (!globalConfig) |
152 | printf("No valid trigger crate configuration in CDB\n"); | |
153 | ||
37a0914e | 154 | UInt_t gmask = 0; |
155 | ||
156 | for (Int_t i = 0; i < 4; i++) { | |
157 | gmask = globalConfig->GetGlobalMask(i); | |
158 | fGlobalTriggerBoard->Mask(i,gmask); | |
159 | } | |
b1d66c10 | 160 | |
b1d66c10 | 161 | nextCrates->Reset(); |
c45527c1 | 162 | |
163 | UShort_t regional[16]; | |
164 | irb = 0; | |
165 | ||
166 | if ( !fCrates->NumberOfCrates() >= 16 ) { | |
167 | printf("Something is wrong : too many crates %d",fCrates->NumberOfCrates()); | |
168 | return kFALSE; | |
169 | } | |
170 | ||
37a0914e | 171 | for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side |
172 | { | |
173 | for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side. | |
174 | { | |
175 | cr = fCrates->Crate(iSide, iReg); | |
176 | ||
177 | AliMUONTriggerBoard* rb = | |
178 | static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0)); | |
179 | regional[irb] = rb->GetResponse(); | |
180 | ++irb; | |
181 | } | |
c45527c1 | 182 | } |
183 | ||
184 | fGlobalTriggerBoard->SetRegionalResponse(regional); | |
185 | fGlobalTriggerBoard->Response(); | |
186 | ||
187 | if (fGlobalTriggerBoard->GetResponse() != 0) { | |
188 | fGlobalTriggerBoard->Scan(""); | |
189 | printf("Global trigger response = "); | |
190 | PrintGloBin(fGlobalTriggerBoard->GetResponse()); | |
191 | return kTRUE; | |
192 | } | |
193 | ||
194 | return kFALSE; | |
195 | ||
196 | } | |
197 | ||
198 | //___________________________________________________________________________ | |
199 | void MUONReCalcGlobalTrigger(const char* input) { | |
200 | /// create array of local triggers from the raw data, run the re-calculation | |
201 | /// and print-out the results | |
202 | ||
203 | debug = 0; | |
204 | ||
205 | Int_t runNumber = 0; | |
206 | ||
207 | AliCDBManager* man = AliCDBManager::Instance(); | |
162637e4 | 208 | man->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); |
c45527c1 | 209 | man->SetRun(runNumber); |
210 | AliMpCDB::LoadDDLStore(); | |
211 | ||
212 | calibData = new AliMUONCalibrationData(runNumber); | |
213 | ||
b1d66c10 | 214 | regionalConfig = calibData->RegionalTriggerConfig(); |
215 | globalConfig = calibData->GlobalTriggerCrateConfig(); | |
216 | ||
c45527c1 | 217 | fCrates = new AliMUONTriggerCrateStore; |
b1d66c10 | 218 | fCrates->ReadFromFile(calibData); |
219 | cratesIterator = fCrates->CreateCrateIterator(); | |
c45527c1 | 220 | fGlobalTriggerBoard = new AliMUONGlobalTriggerBoard; |
b1d66c10 | 221 | |
222 | TIter nextCrates(cratesIterator); | |
c45527c1 | 223 | |
224 | AliMUONDataInterface diRec(input); | |
225 | ||
226 | printf("Number of events = %d \n",diRec.NumberOfEvents()); | |
227 | Int_t nEvents = diRec.NumberOfEvents(); | |
228 | ||
229 | AliMUONLocalTrigger* localTrig; | |
230 | Int_t circ, loLpt, loHpt, lutLpt[2], lutHpt[2]; | |
231 | TArrayS xPattern[235]; | |
232 | TArrayS yPattern[235]; | |
233 | ||
c45527c1 | 234 | for (Int_t ievent = 0; ievent < nEvents; ++ievent) { |
235 | ||
236 | for (Int_t i = 0; i < 234; i++) { | |
237 | locResp[i] = 0; | |
238 | } | |
239 | ||
240 | AliMUONVTriggerStore* triggerStore = diRec.TriggerStore(ievent,"R"); | |
241 | TIter nextLocal(triggerStore->CreateLocalIterator()); | |
b1d66c10 | 242 | while ( (localTrig = static_cast<AliMUONLocalTrigger*>( nextLocal() )) ) { |
243 | ||
244 | if (localTrig->IsNull()) continue; | |
245 | ||
c45527c1 | 246 | circ = localTrig->LoCircuit(); |
247 | ||
248 | loLpt = localTrig->LoLpt(); | |
249 | loHpt = localTrig->LoHpt(); | |
250 | ||
251 | lutLpt[0] = loLpt & 1; | |
252 | lutLpt[1] = (loLpt & 2) >> 1; | |
253 | lutHpt[0] = loHpt & 1; | |
254 | lutHpt[1] = (loHpt & 2) >> 1; | |
255 | ||
256 | locResp[circ] = lutLpt[0] + | |
257 | static_cast<int>(lutLpt[1]<<1) + | |
258 | static_cast<int>(lutHpt[0]<<2) + | |
259 | static_cast<int>(lutHpt[1]<<3); | |
260 | ||
261 | localTrig->GetXPattern(xPattern[circ]); | |
262 | localTrig->GetYPattern(yPattern[circ]); | |
263 | ||
264 | if (debug) { | |
265 | printf("Event %4d circ %3d loLpt %1d loHpt %1d resp %3d\n",ievent,circ,loLpt,loHpt,locResp[circ]); | |
266 | } | |
267 | ||
268 | } // local trigger loop | |
269 | ||
b1d66c10 | 270 | if (ReCalcGlobalTrigger(&nextCrates)) { |
c45527c1 | 271 | printf("............ for event %5d \n",ievent); |
272 | for (Int_t ic = 1; ic <= 234; ic++) { | |
273 | if (locResp[ic] != 0) { | |
274 | UShort_t response = locResp[ic]; | |
275 | loLpt = response & 3; | |
276 | loHpt = (response & 12) >> 2; | |
277 | printf("............ in circuit %3d loLpt %1d loHpt %1d resp %3d\n",ic,loLpt,loHpt,response); | |
278 | ||
279 | printf(" Pattern X:\n"); | |
280 | PrintPattBin(xPattern[ic].At(0)); | |
281 | PrintPattBin(xPattern[ic].At(1)); | |
282 | PrintPattBin(xPattern[ic].At(2)); | |
283 | PrintPattBin(xPattern[ic].At(3)); | |
284 | printf(" Pattern Y:\n"); | |
285 | PrintPattBin(yPattern[ic].At(0)); | |
286 | PrintPattBin(yPattern[ic].At(1)); | |
287 | PrintPattBin(yPattern[ic].At(2)); | |
288 | PrintPattBin(yPattern[ic].At(3)); | |
289 | ||
290 | } | |
291 | } | |
292 | printf("\n\n"); | |
293 | } | |
294 | ||
295 | } // event loop | |
296 | ||
b1d66c10 | 297 | delete fGlobalTriggerBoard; |
298 | delete fCrates; | |
299 | delete calibData; | |
300 | ||
c45527c1 | 301 | } |
302 |