]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONStatusMap.C
Possibility to run analysis train inside AliReconstruction (Andrei)
[u/mrichter/AliRoot.git] / MUON / MUONStatusMap.C
CommitLineData
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 53namespace
54{
55 Int_t NTOTALNUMBEROFPADS(1064008);
56}
57
58//______________________________________________________________________________
59void 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//______________________________________________________________________________
97void 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
e30ab20a 106// AliCDBManager::Instance()->SetSpecificStorage("MUON/Calib/RecoParam","alien://folder=/alice/cern.ch/user/c/cgeuna/OCDB");
8dd92431 107
108 AliMUONCDB::LoadMapping();
109
110 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
d565d56c 111
411a502a 112// man->SetSpecificStorage("MUON/Calib/OccupancyMap","local://$ALICE_ROOT/OCDB");
113// man->SetSpecificStorage("MUON/Calib/OccupancyMap","alien://folder=/alice/cern.ch/user/l/laphecet/OCDB");
114// man->SetSpecificStorage("MUON/Calib/RejectList","alien://folder=/alice/cern.ch/user/l/laphecet/OCDB");
115// man->SetSpecificStorage("MUON/Align/Data","alien://folder=/alice/cern.ch/user/l/laphecet/OCDB");
d565d56c 116
d565d56c 117 AliMUONCalibrationData cd(runNumber);
118
119 AliMUONPadStatusMaker statusMaker(cd);
120
411a502a 121 statusMaker.SetLimits(*recoParam);
d565d56c 122
411a502a 123 UInt_t mask = recoParam->PadGoodnessMask();
8dd92431 124
125 // delete recoParam;
7190ece1 126
411a502a 127 statusMaker.Report(mask);
d565d56c 128
e30ab20a 129 vstatus = static_cast<AliMUONVStore*>(statusMaker.StatusStore()->Clone());
d565d56c 130
7190ece1 131 const Bool_t deferredInitialization = kFALSE;
d565d56c 132
7190ece1 133 AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization);
134
e30ab20a 135 vstatusMap = static_cast<AliMUONVStore*>(statusMapMaker.StatusMap()->Clone());
136}
137
138//______________________________________________________________________________
139Int_t GetBadChannels(Int_t runNumber,
140 Int_t& nbadped,
141 Int_t& nbadhv,
142 Int_t& nbadgain,
143 Int_t& nbadocc,
144 Int_t& nmissing,
145 Int_t& nreco)
146{
147 if (!AliCDBManager::Instance()->IsDefaultStorageSet())
148 {
149 AliCDBManager::Instance()->SetDefaultStorage("raw://");
150 }
151
152 AliCDBManager::Instance()->SetRun(runNumber);
153
154 AliMpCDB::LoadDDLStore();
155
156 AliMUONCalibrationData cd(runNumber,true);
157
158 AliMUONPadStatusMaker statusMaker(cd);
159
160 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
161
162 statusMaker.SetLimits(*recoParam);
163
164 AliMpManuIterator it;
165 Int_t detElemId, manuId;
166
167 Int_t pedCheck = (
168 AliMUONPadStatusMaker::kPedMeanZero |
169 AliMUONPadStatusMaker::kPedMeanTooLow |
170 AliMUONPadStatusMaker::kPedMeanTooHigh |
171 AliMUONPadStatusMaker::kPedSigmaTooLow |
172 AliMUONPadStatusMaker::kPedSigmaTooHigh );
173
174 Int_t hvCheck = (
175 AliMUONPadStatusMaker::kHVError |
176 AliMUONPadStatusMaker::kHVTooLow |
177 AliMUONPadStatusMaker::kHVTooHigh |
178 AliMUONPadStatusMaker::kHVChannelOFF |
179 AliMUONPadStatusMaker::kHVSwitchOFF );
180
181
182 Int_t occCheck = (
183 AliMUONPadStatusMaker::kManuOccupancyTooHigh
184 );
185
186 Int_t ntotal(0);
187 Int_t nbad(0);
188 nbadped=0;
189 nbadocc=0;
190 nbadgain=0;
191 nbadhv=0;
192 nmissing=0;
193 nreco=0;
194
195 while ( it.Next(detElemId,manuId) )
196 {
197 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
198 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
199 {
200 if ( de->IsConnectedChannel(manuId,manuChannel) )
201 {
202 ++ntotal;
203
204 UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel);
205
206 if (!status) continue;
207
208 bool bad(false);
209
210 if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) )
211 {
212 ++nbadped;
213 bad=true;
214 }
215
216 if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) )
217 {
218 ++nbadhv;
219 bad=true;
220 }
221
222 if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) )
223 {
224 ++nbadocc;
225 bad=true;
226 }
227
228 if ( status & recoParam->PadGoodnessMask() )
229 {
230 ++nreco;
231 }
232
233 if ( status & AliMUONPadStatusMaker::BuildStatus(AliMUONPadStatusMaker::kMissing,0,0,AliMUONPadStatusMaker::kMissing) )
234 {
235 bad=true;
236 ++nmissing;
237 }
238
239 if (bad) ++nbad;
240 }
241 }
242 }
243
244 if (ntotal!=NTOTALNUMBEROFPADS)
245 {
246 cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d",
247 ntotal,runNumber) << endl;
248 }
249
250 AliCDBManager::Instance()->ClearCache();
251
252 return nbad;
253}
254
255//______________________________________________________________________________
256void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized)
257{
258 if (!f) return;
259
260 TGraph* g = static_cast<TGraph*>(f->Get(gname));
261
262 if (!g) return;
263
264 if ( normalized )
265 {
266 g = static_cast<TGraph*>(g->Clone());
267 for ( Int_t i = 0; i < g->GetN(); ++i )
268 {
269 Double_t y = g->GetY()[i];
270 g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS);
271 }
272 }
273
274 g->Draw("lp");
275 g->GetXaxis()->SetNdivisions(505);
276 g->GetXaxis()->SetNoExponent();
277
278 if (l) l->AddEntry(g,gname,"LP");
279}
280
281//______________________________________________________________________________
282void DrawPeriod(double run1, double run2, double ymin, double ymax, const char* label)
283{
284 TBox* b = new TBox(run1,ymin,run2,ymax);
285 b->SetFillColor(5);
286 b->Draw();
287 TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
288 text->SetTextSize(0.05);
289 text->Draw();
290}
291
292//______________________________________________________________________________
293void DrawEvolution(const char* file, bool normalized=true)
294{
295 TFile* f = TFile::Open(file);
296
297 if (!f) return;
298
299 TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
300
301 c->SetGridy();
302 c->SetTicky();
303
304 c->Draw();
305
306 TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
307
308 TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
309 if (!g) return;
310
311 int runmin = TMath::Nint(g->GetX()[0]);
312 int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
313
314 double ymax(0.4);
315
316 TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
317
318 gStyle->SetOptStat(kFALSE);
319 h->Draw();
320 h->GetXaxis()->SetNoExponent();
321 h->GetXaxis()->SetNdivisions(505);
322
323 gStyle->SetOptTitle(kFALSE);
324
325 DrawPeriod(115881,117222,0,ymax,"10b");
326
327 DrawPeriod(119159,120824,0,ymax,"10c");
328
329 DrawPeriod(122374,126424,0,ymax,"10d");
330
331 DrawPeriod(127724,130850,0,ymax,"10e");
332
333 DrawPeriod(133005,134929,0,ymax,"10f");
334
335 DrawPeriod(135658,136376,0,ymax,"10g");
336
337 DrawPeriod(137133,139513,0,ymax,"10h");
338
339 DrawPeriod(143856,146860,0,ymax,"11a");
340
341 DrawPeriod(148370,150702,0,ymax,"11b");
342
343 DrawPeriod(155384,155384,0,ymax,"11c");
344
345 DrawPeriod(156477,159606,0,ymax,"11d");
346
347 Draw(f,"nbad",l,normalized);
348 Draw(f,"nbadped",l,normalized);
349 Draw(f,"nbadocc",l,normalized);
350 Draw(f,"nbadhv",l,normalized);
351 Draw(f,"nmissing",l,normalized);
352 Draw(f,"nreco",l,normalized);
353
354 h->Draw("same");
355
356 c->RedrawAxis("g");
357
358 l->Draw();
359}
360
361//______________________________________________________________________________
362void MUONStatusMapEvolution(const char* runlist, const char* outfile)
363{
364 // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy
365 // or missing in configuration)
366 //
367 // output a root file with the different graphs.
368 //
369 // output can be then plotted using the DrawEvolution function
370 //
371
372 std::vector<int> runs;
373
374 ReadIntegers(runlist,runs);
375
376 if ( runs.empty() )
377 {
378 cout << "No runs to process..." << endl;
379 return;
380 }
381
382 int year(2011);
383
384 if ( runs[0] <= 139699 ) year=2010;
385
386 AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year));
387// AliCDBManager::Instance()->SetDefaultStorage("local:///local/cdb/alice/data/2010/OCDB");
388
389 TList glist;
390
391 glist.SetOwner(kTRUE);
392
393 TGraph* gnbad = new TGraph(runs.size());
394 gnbad->SetName("nbad");
395 glist.Add(gnbad);
396
397 TGraph* gnbadped = new TGraph(runs.size());
398 gnbadped->SetName("nbadped");
399 glist.Add(gnbadped);
400
401 TGraph* gnbadocc = new TGraph(runs.size());
402 gnbadocc->SetName("nbadocc");
403 glist.Add(gnbadocc);
404
405 TGraph* gnbadhv = new TGraph(runs.size());
406 gnbadhv->SetName("nbadhv");
407 glist.Add(gnbadhv);
408
409 TGraph* gnmissing = new TGraph(runs.size());
410 gnmissing->SetName("nmissing");
411 glist.Add(gnmissing);
412
413 TGraph* gnreco = new TGraph(runs.size());
414 gnreco->SetName("nreco");
415 glist.Add(gnreco);
416
417 for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i )
418 {
419 Int_t runNumber = runs[i];
420 Int_t nbadped;
421 Int_t nbadhv;
422 Int_t nbadgain;
423 Int_t nbadocc;
424 Int_t nmissing;
425 Int_t nreco;
426
427 Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco);
428
429 gnbad->SetPoint(i,runNumber,nbad);
430 gnbadped->SetPoint(i,runNumber,nbadped);
431 gnbadhv->SetPoint(i,runNumber,nbadhv);
432 gnbadocc->SetPoint(i,runNumber,nbadocc);
433 gnmissing->SetPoint(i,runNumber,nmissing);
434 gnreco->SetPoint(i,runNumber,nreco);
435 }
436
437 TIter next(&glist);
438 TGraph* g;
439 Int_t index(0);
440
441 TFile f(outfile,"recreate");
442 Int_t color[] = { 1 , 2 , 3 , 4, 6, 8 };
443 Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 };
444
445 while ( ( g = static_cast<TGraph*>(next() ) ) )
446 {
447 g->GetXaxis()->SetNdivisions(505);
448 g->GetXaxis()->SetNoExponent();
449 g->SetMinimum(0);
450 g->GetYaxis()->SetNoExponent();
451 g->SetLineColor(color[index]);
452 g->SetMarkerStyle(marker[index]);
453 g->SetMarkerColor(color[index]);
454 g->SetMarkerSize(1.0);
455 ++index;
456 g->Write();
457 }
458
459 f.Close();
460
461
d565d56c 462}