]>
Commit | Line | Data |
---|---|---|
d565d56c | 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 | /* $Id$ */ | |
17 | ||
e54bf126 | 18 | /// \ingroup macros |
19 | /// \file MUONStatusMap.C | |
20 | /// \brief Macro to check/test pad status and pad status map makers | |
3fb89a07 | 21 | /// |
e54bf126 | 22 | /// \author Laurent Aphecetche |
d565d56c | 23 | |
24 | #if !defined(__CINT__) || defined(__MAKECINT__) | |
25 | #include "AliCDBManager.h" | |
e30ab20a | 26 | #include "AliCDBEntry.h" |
27 | #include "AliLog.h" | |
28 | #include "AliMpCDB.h" | |
29 | #include "AliMUONCDB.h" | |
d565d56c | 30 | #include "AliMUONCalibrationData.h" |
d565d56c | 31 | #include "AliMUONPadStatusMaker.h" |
32 | #include "AliMUONPadStatusMapMaker.h" | |
411a502a | 33 | #include "AliMUONRecoParam.h" |
d565d56c | 34 | #include "AliMUONVCalibParam.h" |
7190ece1 | 35 | #include "AliMUONVStore.h" |
7190ece1 | 36 | #include "AliMpConstants.h" |
37 | #include "AliMpDDLStore.h" | |
38 | #include "AliMpDetElement.h" | |
7190ece1 | 39 | #include "AliMpManuIterator.h" |
d565d56c | 40 | #include "Riostream.h" |
e30ab20a | 41 | #include "TAxis.h" |
42 | #include "TCanvas.h" | |
43 | #include "TLegend.h" | |
44 | #include "TFile.h" | |
45 | #include "TGraph.h" | |
46 | #include "TBox.h" | |
47 | #include "TH2F.h" | |
48 | #include "TStyle.h" | |
49 | #include "TText.h" | |
50 | #include <vector> | |
d565d56c | 51 | #endif |
52 | ||
e30ab20a | 53 | namespace |
54 | { | |
55 | Int_t NTOTALNUMBEROFPADS(1064008); | |
56 | } | |
57 | ||
58 | //______________________________________________________________________________ | |
59 | void ReadIntegers(const char* filename, std::vector<int>& integers) | |
60 | { | |
61 | /// Read integers from filename, where integers are either | |
62 | /// separated by "," or by return carriage | |
63 | ifstream in(gSystem->ExpandPathName(filename)); | |
64 | int i; | |
65 | ||
66 | char line[10000]; | |
67 | ||
68 | in.getline(line,10000,'\n'); | |
69 | ||
70 | TString sline(line); | |
71 | ||
72 | if (sline.Contains(",")) | |
73 | { | |
74 | TObjArray* a = sline.Tokenize(","); | |
75 | TIter next(a); | |
76 | TObjString* s; | |
77 | while ( ( s = static_cast<TObjString*>(next()) ) ) | |
78 | { | |
79 | integers.push_back(s->String().Atoi()); | |
80 | } | |
81 | } | |
82 | else | |
83 | { | |
84 | integers.push_back(sline.Atoi()); | |
85 | ||
86 | while ( in >> i ) | |
87 | { | |
88 | integers.push_back(i); | |
89 | } | |
90 | } | |
91 | ||
92 | std::sort(integers.begin(),integers.end()); | |
93 | } | |
94 | ||
95 | ||
96 | //______________________________________________________________________________ | |
97 | void MUONStatusMap(AliMUONVStore*& vstatus, | |
98 | AliMUONVStore*& vstatusMap, | |
99 | const char* cdbStorage = "alien://folder=/alice/data/2011/OCDB", | |
100 | Int_t runNumber=145292) | |
411a502a | 101 | { |
102 | ||
8dd92431 | 103 | AliCDBManager::Instance()->SetDefaultStorage(cdbStorage); |
104 | AliCDBManager::Instance()->SetRun(runNumber); | |
7190ece1 | 105 | |
8dd92431 | 106 | AliMUONCDB::LoadMapping(); |
107 | ||
108 | AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam(); | |
d565d56c | 109 | |
d565d56c | 110 | AliMUONCalibrationData cd(runNumber); |
111 | ||
112 | AliMUONPadStatusMaker statusMaker(cd); | |
113 | ||
411a502a | 114 | statusMaker.SetLimits(*recoParam); |
d565d56c | 115 | |
411a502a | 116 | UInt_t mask = recoParam->PadGoodnessMask(); |
8dd92431 | 117 | |
411a502a | 118 | statusMaker.Report(mask); |
d565d56c | 119 | |
e30ab20a | 120 | vstatus = static_cast<AliMUONVStore*>(statusMaker.StatusStore()->Clone()); |
d565d56c | 121 | |
7190ece1 | 122 | const Bool_t deferredInitialization = kFALSE; |
d565d56c | 123 | |
7190ece1 | 124 | AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization); |
125 | ||
e30ab20a | 126 | vstatusMap = static_cast<AliMUONVStore*>(statusMapMaker.StatusMap()->Clone()); |
127 | } | |
128 | ||
129 | //______________________________________________________________________________ | |
130 | Int_t GetBadChannels(Int_t runNumber, | |
131 | Int_t& nbadped, | |
132 | Int_t& nbadhv, | |
133 | Int_t& nbadgain, | |
134 | Int_t& nbadocc, | |
135 | Int_t& nmissing, | |
136 | Int_t& nreco) | |
137 | { | |
138 | if (!AliCDBManager::Instance()->IsDefaultStorageSet()) | |
139 | { | |
140 | AliCDBManager::Instance()->SetDefaultStorage("raw://"); | |
141 | } | |
142 | ||
143 | AliCDBManager::Instance()->SetRun(runNumber); | |
144 | ||
145 | AliMpCDB::LoadDDLStore(); | |
146 | ||
147 | AliMUONCalibrationData cd(runNumber,true); | |
148 | ||
149 | AliMUONPadStatusMaker statusMaker(cd); | |
150 | ||
151 | AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam(); | |
152 | ||
153 | statusMaker.SetLimits(*recoParam); | |
154 | ||
155 | AliMpManuIterator it; | |
156 | Int_t detElemId, manuId; | |
157 | ||
158 | Int_t pedCheck = ( | |
159 | AliMUONPadStatusMaker::kPedMeanZero | | |
160 | AliMUONPadStatusMaker::kPedMeanTooLow | | |
161 | AliMUONPadStatusMaker::kPedMeanTooHigh | | |
162 | AliMUONPadStatusMaker::kPedSigmaTooLow | | |
163 | AliMUONPadStatusMaker::kPedSigmaTooHigh ); | |
164 | ||
165 | Int_t hvCheck = ( | |
166 | AliMUONPadStatusMaker::kHVError | | |
167 | AliMUONPadStatusMaker::kHVTooLow | | |
168 | AliMUONPadStatusMaker::kHVTooHigh | | |
169 | AliMUONPadStatusMaker::kHVChannelOFF | | |
170 | AliMUONPadStatusMaker::kHVSwitchOFF ); | |
171 | ||
172 | ||
173 | Int_t occCheck = ( | |
174 | AliMUONPadStatusMaker::kManuOccupancyTooHigh | |
175 | ); | |
176 | ||
177 | Int_t ntotal(0); | |
178 | Int_t nbad(0); | |
179 | nbadped=0; | |
180 | nbadocc=0; | |
181 | nbadgain=0; | |
182 | nbadhv=0; | |
183 | nmissing=0; | |
184 | nreco=0; | |
185 | ||
186 | while ( it.Next(detElemId,manuId) ) | |
187 | { | |
188 | AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); | |
189 | for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel ) | |
190 | { | |
191 | if ( de->IsConnectedChannel(manuId,manuChannel) ) | |
192 | { | |
193 | ++ntotal; | |
194 | ||
195 | UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel); | |
196 | ||
197 | if (!status) continue; | |
198 | ||
199 | bool bad(false); | |
200 | ||
201 | if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) ) | |
202 | { | |
203 | ++nbadped; | |
204 | bad=true; | |
205 | } | |
206 | ||
207 | if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) ) | |
208 | { | |
209 | ++nbadhv; | |
210 | bad=true; | |
211 | } | |
212 | ||
213 | if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) ) | |
214 | { | |
215 | ++nbadocc; | |
216 | bad=true; | |
217 | } | |
218 | ||
219 | if ( status & recoParam->PadGoodnessMask() ) | |
220 | { | |
221 | ++nreco; | |
222 | } | |
223 | ||
224 | if ( status & AliMUONPadStatusMaker::BuildStatus(AliMUONPadStatusMaker::kMissing,0,0,AliMUONPadStatusMaker::kMissing) ) | |
225 | { | |
226 | bad=true; | |
227 | ++nmissing; | |
228 | } | |
229 | ||
230 | if (bad) ++nbad; | |
231 | } | |
232 | } | |
233 | } | |
234 | ||
235 | if (ntotal!=NTOTALNUMBEROFPADS) | |
236 | { | |
237 | cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d", | |
238 | ntotal,runNumber) << endl; | |
239 | } | |
240 | ||
241 | AliCDBManager::Instance()->ClearCache(); | |
242 | ||
243 | return nbad; | |
244 | } | |
245 | ||
246 | //______________________________________________________________________________ | |
247 | void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized) | |
248 | { | |
249 | if (!f) return; | |
250 | ||
251 | TGraph* g = static_cast<TGraph*>(f->Get(gname)); | |
252 | ||
253 | if (!g) return; | |
254 | ||
255 | if ( normalized ) | |
256 | { | |
257 | g = static_cast<TGraph*>(g->Clone()); | |
258 | for ( Int_t i = 0; i < g->GetN(); ++i ) | |
259 | { | |
260 | Double_t y = g->GetY()[i]; | |
261 | g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS); | |
262 | } | |
263 | } | |
264 | ||
265 | g->Draw("lp"); | |
266 | g->GetXaxis()->SetNdivisions(505); | |
267 | g->GetXaxis()->SetNoExponent(); | |
268 | ||
269 | if (l) l->AddEntry(g,gname,"LP"); | |
270 | } | |
271 | ||
272 | //______________________________________________________________________________ | |
273 | void DrawPeriod(double run1, double run2, double ymin, double ymax, const char* label) | |
274 | { | |
275 | TBox* b = new TBox(run1,ymin,run2,ymax); | |
276 | b->SetFillColor(5); | |
277 | b->Draw(); | |
278 | TText* text = new TText((run1+run2)/2.0,ymax*0.6,label); | |
279 | text->SetTextSize(0.05); | |
280 | text->Draw(); | |
281 | } | |
282 | ||
283 | //______________________________________________________________________________ | |
284 | void DrawEvolution(const char* file, bool normalized=true) | |
285 | { | |
b57816bd | 286 | |
e30ab20a | 287 | TFile* f = TFile::Open(file); |
288 | ||
289 | if (!f) return; | |
290 | ||
291 | TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution"); | |
292 | ||
293 | c->SetGridy(); | |
294 | c->SetTicky(); | |
295 | ||
296 | c->Draw(); | |
297 | ||
298 | TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution"); | |
299 | ||
300 | TGraph* g = static_cast<TGraph*>(f->Get("nbad")); | |
301 | if (!g) return; | |
302 | ||
303 | int runmin = TMath::Nint(g->GetX()[0]); | |
304 | int runmax = TMath::Nint(g->GetX()[g->GetN()-1]); | |
305 | ||
306 | double ymax(0.4); | |
307 | ||
308 | TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax); | |
309 | ||
310 | gStyle->SetOptStat(kFALSE); | |
311 | h->Draw(); | |
312 | h->GetXaxis()->SetNoExponent(); | |
313 | h->GetXaxis()->SetNdivisions(505); | |
314 | ||
315 | gStyle->SetOptTitle(kFALSE); | |
316 | ||
317 | DrawPeriod(115881,117222,0,ymax,"10b"); | |
318 | ||
319 | DrawPeriod(119159,120824,0,ymax,"10c"); | |
320 | ||
321 | DrawPeriod(122374,126424,0,ymax,"10d"); | |
322 | ||
323 | DrawPeriod(127724,130850,0,ymax,"10e"); | |
324 | ||
325 | DrawPeriod(133005,134929,0,ymax,"10f"); | |
326 | ||
327 | DrawPeriod(135658,136376,0,ymax,"10g"); | |
328 | ||
329 | DrawPeriod(137133,139513,0,ymax,"10h"); | |
330 | ||
331 | DrawPeriod(143856,146860,0,ymax,"11a"); | |
332 | ||
333 | DrawPeriod(148370,150702,0,ymax,"11b"); | |
334 | ||
b57816bd | 335 | DrawPeriod(151566,154583,0,ymax,"11c"); |
336 | ||
337 | DrawPeriod(158084,159606,0,ymax,"11d"); | |
e30ab20a | 338 | |
b57816bd | 339 | DrawPeriod(160677,162000,0,ymax,"11e"); |
e30ab20a | 340 | |
341 | Draw(f,"nbad",l,normalized); | |
342 | Draw(f,"nbadped",l,normalized); | |
343 | Draw(f,"nbadocc",l,normalized); | |
344 | Draw(f,"nbadhv",l,normalized); | |
345 | Draw(f,"nmissing",l,normalized); | |
346 | Draw(f,"nreco",l,normalized); | |
347 | ||
348 | h->Draw("same"); | |
349 | ||
350 | c->RedrawAxis("g"); | |
351 | ||
352 | l->Draw(); | |
353 | } | |
354 | ||
355 | //______________________________________________________________________________ | |
356 | void MUONStatusMapEvolution(const char* runlist, const char* outfile) | |
357 | { | |
358 | // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy | |
359 | // or missing in configuration) | |
360 | // | |
361 | // output a root file with the different graphs. | |
362 | // | |
363 | // output can be then plotted using the DrawEvolution function | |
364 | // | |
b57816bd | 365 | // Note that the output of different runlists can then be merged simply using |
366 | // the hadd program, and so then the DrawEvolution can be used over | |
367 | // a huge period, e.g. a full year, while this method is better restricted | |
368 | // to a period or even less (depending on your success of accessing the OCDB) | |
369 | // | |
e30ab20a | 370 | |
371 | std::vector<int> runs; | |
372 | ||
373 | ReadIntegers(runlist,runs); | |
374 | ||
375 | if ( runs.empty() ) | |
376 | { | |
377 | cout << "No runs to process..." << endl; | |
378 | return; | |
379 | } | |
380 | ||
381 | int year(2011); | |
382 | ||
383 | if ( runs[0] <= 139699 ) year=2010; | |
384 | ||
385 | AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year)); | |
e30ab20a | 386 | |
387 | TList glist; | |
388 | ||
389 | glist.SetOwner(kTRUE); | |
390 | ||
391 | TGraph* gnbad = new TGraph(runs.size()); | |
392 | gnbad->SetName("nbad"); | |
393 | glist.Add(gnbad); | |
394 | ||
395 | TGraph* gnbadped = new TGraph(runs.size()); | |
396 | gnbadped->SetName("nbadped"); | |
397 | glist.Add(gnbadped); | |
398 | ||
399 | TGraph* gnbadocc = new TGraph(runs.size()); | |
400 | gnbadocc->SetName("nbadocc"); | |
401 | glist.Add(gnbadocc); | |
402 | ||
403 | TGraph* gnbadhv = new TGraph(runs.size()); | |
404 | gnbadhv->SetName("nbadhv"); | |
405 | glist.Add(gnbadhv); | |
406 | ||
407 | TGraph* gnmissing = new TGraph(runs.size()); | |
408 | gnmissing->SetName("nmissing"); | |
409 | glist.Add(gnmissing); | |
410 | ||
411 | TGraph* gnreco = new TGraph(runs.size()); | |
412 | gnreco->SetName("nreco"); | |
413 | glist.Add(gnreco); | |
414 | ||
415 | for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i ) | |
416 | { | |
417 | Int_t runNumber = runs[i]; | |
418 | Int_t nbadped; | |
419 | Int_t nbadhv; | |
420 | Int_t nbadgain; | |
421 | Int_t nbadocc; | |
422 | Int_t nmissing; | |
423 | Int_t nreco; | |
424 | ||
425 | Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco); | |
426 | ||
427 | gnbad->SetPoint(i,runNumber,nbad); | |
428 | gnbadped->SetPoint(i,runNumber,nbadped); | |
429 | gnbadhv->SetPoint(i,runNumber,nbadhv); | |
430 | gnbadocc->SetPoint(i,runNumber,nbadocc); | |
431 | gnmissing->SetPoint(i,runNumber,nmissing); | |
432 | gnreco->SetPoint(i,runNumber,nreco); | |
433 | } | |
434 | ||
435 | TIter next(&glist); | |
436 | TGraph* g; | |
437 | Int_t index(0); | |
438 | ||
439 | TFile f(outfile,"recreate"); | |
440 | Int_t color[] = { 1 , 2 , 3 , 4, 6, 8 }; | |
441 | Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 }; | |
442 | ||
443 | while ( ( g = static_cast<TGraph*>(next() ) ) ) | |
444 | { | |
445 | g->GetXaxis()->SetNdivisions(505); | |
446 | g->GetXaxis()->SetNoExponent(); | |
447 | g->SetMinimum(0); | |
448 | g->GetYaxis()->SetNoExponent(); | |
449 | g->SetLineColor(color[index]); | |
450 | g->SetMarkerStyle(marker[index]); | |
451 | g->SetMarkerColor(color[index]); | |
452 | g->SetMarkerSize(1.0); | |
453 | ++index; | |
454 | g->Write(); | |
455 | } | |
456 | ||
457 | f.Close(); | |
458 | ||
459 | ||
d565d56c | 460 | } |