2 /// \file MUONReCalcGlobalTrigger.C
3 /// \brief Re-calculate regional/global trigger response from local response.
7 /// MUONReCalcGlobalTrigger("path_to_reconstruction_galice");
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.
16 /// \author Bogdan Vulpescu
18 #if !defined(__CINT__) || defined(__MAKECINT__)
20 #include "AliCDBManager.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 "AliMUONTriggerCrateConfig.h"
30 #include "AliMUONGlobalCrateConfig.h"
31 #include "AliMUONRegionalTriggerBoard.h"
32 #include "AliMUONRegionalTriggerConfig.h"
33 #include "AliMUONLocalTriggerBoard.h"
34 #include "AliMUONVCalibParam.h"
35 #include "AliMUONTriggerBoard.h"
38 #include <TObjArray.h>
43 UShort_t locResp[235];
45 AliMUONCalibrationData *calibData;
46 AliMUONTriggerCrateStore *fCrates;
47 AliMUONGlobalTriggerBoard *fGlobalTriggerBoard;
48 AliMUONRegionalTriggerConfig* regionalConfig;
49 AliMUONGlobalCrateConfig * globalConfig;
51 TIterator *cratesIterator;
55 //___________________________________________________________________________
56 void PrintPattBin(Short_t s) {
57 /// binary print-out of the strip patterns
61 for (Int_t i = 15; i >= 0; i--) {
62 mask = (Int_t)TMath::Power(2,i);
63 printf("%1d",(s & mask) >> i);
69 //___________________________________________________________________________
70 void PrintGloBin(UShort_t s) {
71 /// binary print-out of global trigger decision
74 for (Int_t i = 5; i >= 0; i--) {
75 mask = (Int_t)TMath::Power(2,i);
76 printf("%1d",(s & mask) >> i);
82 //___________________________________________________________________________
83 Bool_t ReCalcGlobalTrigger(TIter *nextCrates) {
84 /// re-calculate regional/global decision from array of local triggers
87 AliMUONTriggerCrate* cr;
95 while ( ( cr = static_cast<AliMUONTriggerCrate*>(nextCrates->Next()) ) ) {
97 if (debug) printf("Crate nr = %2d \n",++irb);
99 TObjArray *boards = cr->Boards();
101 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
106 UShort_t regLocResp[16]; for (Int_t j=0; j<16; j++) regLocResp[j] = 0;
108 for (Int_t j = 1; j < boards->GetEntries(); j++) {
110 TObject *o = boards->At(j);
112 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
114 if (board->GetNumber() == 0) continue;
117 printf("...Board nr = %2d : ",++nrBoard);
118 printf("%3d %s in slot %2d of crate %s \n",board->GetNumber(),board->GetName(),j,cr->GetName());
121 UShort_t response = locResp[board->GetNumber()];
123 if (debug) printf("......Response = %x \n",response);
126 loLpt = response & 3;
127 loHpt = (response & 12) >> 2;
128 //printf("Response loLpt = %02b loHpt = %02b \n",loLpt,loHpt);
131 regLocResp[j-1] = response;
133 } // local board loop
135 AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName());
136 UShort_t rmask= crateConfig->GetMask();
138 regb->SetLocalResponse(regLocResp);
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);
149 fGlobalTriggerBoard->Reset();
152 printf("No valid trigger crate configuration in CDB\n");
156 for (Int_t i = 0; i < 4; i++) {
157 gmask = globalConfig->GetGlobalMask(i);
158 fGlobalTriggerBoard->Mask(i,gmask);
163 UShort_t regional[16];
166 if ( !fCrates->NumberOfCrates() >= 16 ) {
167 printf("Something is wrong : too many crates %d",fCrates->NumberOfCrates());
171 for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
173 for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
175 cr = fCrates->Crate(iSide, iReg);
177 AliMUONTriggerBoard* rb =
178 static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
179 regional[irb] = rb->GetResponse();
184 fGlobalTriggerBoard->SetRegionalResponse(regional);
185 fGlobalTriggerBoard->Response();
187 if (fGlobalTriggerBoard->GetResponse() != 0) {
188 fGlobalTriggerBoard->Scan("");
189 printf("Global trigger response = ");
190 PrintGloBin(fGlobalTriggerBoard->GetResponse());
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
207 AliCDBManager* man = AliCDBManager::Instance();
208 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
209 man->SetRun(runNumber);
210 AliMpCDB::LoadDDLStore();
212 calibData = new AliMUONCalibrationData(runNumber);
214 regionalConfig = calibData->RegionalTriggerConfig();
215 globalConfig = calibData->GlobalTriggerCrateConfig();
217 fCrates = new AliMUONTriggerCrateStore;
218 fCrates->ReadFromFile(calibData);
219 cratesIterator = fCrates->CreateCrateIterator();
220 fGlobalTriggerBoard = new AliMUONGlobalTriggerBoard;
222 TIter nextCrates(cratesIterator);
224 AliMUONDataInterface diRec(input);
226 printf("Number of events = %d \n",diRec.NumberOfEvents());
227 Int_t nEvents = diRec.NumberOfEvents();
229 AliMUONLocalTrigger* localTrig;
230 Int_t circ, loLpt, loHpt, lutLpt[2], lutHpt[2];
231 TArrayS xPattern[235];
232 TArrayS yPattern[235];
234 for (Int_t ievent = 0; ievent < nEvents; ++ievent) {
236 for (Int_t i = 0; i < 234; i++) {
240 AliMUONVTriggerStore* triggerStore = diRec.TriggerStore(ievent,"R");
241 TIter nextLocal(triggerStore->CreateLocalIterator());
242 while ( (localTrig = static_cast<AliMUONLocalTrigger*>( nextLocal() )) ) {
244 if (localTrig->IsNull()) continue;
246 circ = localTrig->LoCircuit();
248 loLpt = localTrig->LoLpt();
249 loHpt = localTrig->LoHpt();
251 lutLpt[0] = loLpt & 1;
252 lutLpt[1] = (loLpt & 2) >> 1;
253 lutHpt[0] = loHpt & 1;
254 lutHpt[1] = (loHpt & 2) >> 1;
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);
261 localTrig->GetXPattern(xPattern[circ]);
262 localTrig->GetYPattern(yPattern[circ]);
265 printf("Event %4d circ %3d loLpt %1d loHpt %1d resp %3d\n",ievent,circ,loLpt,loHpt,locResp[circ]);
268 } // local trigger loop
270 if (ReCalcGlobalTrigger(&nextCrates)) {
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);
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));
297 delete fGlobalTriggerBoard;