]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONReCalcGlobalTrigger.C
Restoring backward compatibility of the SSD calibration objects + output of the SSD...
[u/mrichter/AliRoot.git] / MUON / MUONReCalcGlobalTrigger.C
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 "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"
36
37 #include <TArrayS.h>
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;
48 AliMUONRegionalTriggerConfig* regionalConfig;
49 AliMUONGlobalCrateConfig * globalConfig;
50
51 TIterator *cratesIterator;
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 //___________________________________________________________________________
83 Bool_t ReCalcGlobalTrigger(TIter *nextCrates) {
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   
91   nextCrates->Reset();
92   
93   Int_t irb(0);
94   
95   while ( ( cr = static_cast<AliMUONTriggerCrate*>(nextCrates->Next()) ) ) {
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     
135     AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName());
136     UShort_t rmask= crateConfig->GetMask();
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   
151   if (!globalConfig)
152     printf("No valid trigger crate configuration in CDB\n");
153
154   UShort_t gmask = 0;
155
156   gmask = globalConfig->GetFirstDarcDisable();
157   fGlobalTriggerBoard->Mask(0,gmask);
158   
159   gmask = globalConfig->GetSecondDarcDisable();
160   fGlobalTriggerBoard->Mask(1,gmask);
161   
162   nextCrates->Reset();
163   
164   UShort_t regional[16];
165   irb = 0;
166   
167   if ( !fCrates->NumberOfCrates() >= 16 ) {
168     printf("Something is wrong : too many crates %d",fCrates->NumberOfCrates());
169     return kFALSE;
170   }
171   
172   while ( ( cr = static_cast<AliMUONTriggerCrate*>(nextCrates->Next()) ) ) {
173     AliMUONTriggerBoard* rb =
174       static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
175     regional[irb] = rb->GetResponse();
176     ++irb;
177   }
178   
179   fGlobalTriggerBoard->SetRegionalResponse(regional);
180   fGlobalTriggerBoard->Response();
181   
182   if (fGlobalTriggerBoard->GetResponse() != 0) {
183     fGlobalTriggerBoard->Scan("");
184     printf("Global trigger response = ");
185     PrintGloBin(fGlobalTriggerBoard->GetResponse());
186     return kTRUE;
187   }
188   
189   return kFALSE;
190   
191 }
192
193 //___________________________________________________________________________
194 void MUONReCalcGlobalTrigger(const char* input) {
195   /// create array of local triggers from the raw data, run the re-calculation
196   /// and print-out the results
197
198   debug = 0;
199
200   Int_t runNumber = 0;
201
202   AliCDBManager* man = AliCDBManager::Instance();
203   man->SetDefaultStorage("local://$ALICE_ROOT");
204   man->SetRun(runNumber);
205   AliMpCDB::LoadDDLStore();
206
207   calibData = new AliMUONCalibrationData(runNumber);
208
209   regionalConfig = calibData->RegionalTriggerConfig();
210   globalConfig = calibData->GlobalTriggerCrateConfig();
211
212   fCrates = new AliMUONTriggerCrateStore;
213   fCrates->ReadFromFile(calibData);
214   cratesIterator = fCrates->CreateCrateIterator();
215   fGlobalTriggerBoard = new AliMUONGlobalTriggerBoard;
216   
217   TIter nextCrates(cratesIterator);
218
219   AliMUONDataInterface diRec(input);
220
221   printf("Number of events = %d \n",diRec.NumberOfEvents());
222   Int_t nEvents = diRec.NumberOfEvents();
223
224   AliMUONLocalTrigger* localTrig;
225   Int_t circ, loLpt, loHpt, lutLpt[2], lutHpt[2];
226   TArrayS xPattern[235];
227   TArrayS yPattern[235];
228
229   for (Int_t ievent = 0; ievent < nEvents; ++ievent) {
230
231     for (Int_t i = 0; i < 234; i++) {
232       locResp[i] = 0;
233     }
234
235     AliMUONVTriggerStore* triggerStore = diRec.TriggerStore(ievent,"R");
236     TIter nextLocal(triggerStore->CreateLocalIterator());
237     while ( (localTrig = static_cast<AliMUONLocalTrigger*>( nextLocal() )) ) {
238
239       if (localTrig->IsNull()) continue;
240
241       circ = localTrig->LoCircuit();
242       
243       loLpt = localTrig->LoLpt();
244       loHpt = localTrig->LoHpt();
245       
246       lutLpt[0] =  loLpt & 1;
247       lutLpt[1] = (loLpt & 2) >> 1;
248       lutHpt[0] =  loHpt & 1;
249       lutHpt[1] = (loHpt & 2) >> 1;
250       
251       locResp[circ] = lutLpt[0]              +
252         static_cast<int>(lutLpt[1]<<1) +
253         static_cast<int>(lutHpt[0]<<2) +
254         static_cast<int>(lutHpt[1]<<3);
255       
256       localTrig->GetXPattern(xPattern[circ]);
257       localTrig->GetYPattern(yPattern[circ]);
258
259       if (debug) {
260         printf("Event %4d circ %3d loLpt %1d loHpt %1d resp %3d\n",ievent,circ,loLpt,loHpt,locResp[circ]);
261       }
262       
263     } // local trigger loop
264
265     if (ReCalcGlobalTrigger(&nextCrates)) {
266       printf("............ for event %5d \n",ievent);
267       for (Int_t ic = 1; ic <= 234; ic++) {
268         if (locResp[ic] != 0) {
269           UShort_t response = locResp[ic];
270           loLpt =  response &  3;
271           loHpt = (response & 12) >> 2;
272           printf("............ in circuit %3d loLpt %1d loHpt %1d resp %3d\n",ic,loLpt,loHpt,response);
273           
274           printf("   Pattern X:\n");
275           PrintPattBin(xPattern[ic].At(0));
276           PrintPattBin(xPattern[ic].At(1));
277           PrintPattBin(xPattern[ic].At(2));
278           PrintPattBin(xPattern[ic].At(3));
279           printf("   Pattern Y:\n");
280           PrintPattBin(yPattern[ic].At(0));
281           PrintPattBin(yPattern[ic].At(1));
282           PrintPattBin(yPattern[ic].At(2));
283           PrintPattBin(yPattern[ic].At(3));
284           
285         }
286       }
287       printf("\n\n");
288     }
289     
290   } // event loop
291
292   delete fGlobalTriggerBoard;
293   delete fCrates;
294   delete calibData;
295
296 }
297