AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MUONStatusMap.C
Go to the documentation of this file.
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 
23 
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25 #include "AliCDBManager.h"
26 #include "AliCDBEntry.h"
27 #include "AliLog.h"
28 #include "AliMpCDB.h"
29 #include "AliMpDEManager.h"
30 #include "AliMUONCDB.h"
31 #include "AliMUONCalibrationData.h"
32 #include "AliMUONPadStatusMaker.h"
34 #include "AliMUONRecoParam.h"
35 #include "AliMUONVCalibParam.h"
36 #include "AliMUONVStore.h"
37 #include "AliMpConstants.h"
38 #include "AliMpDDLStore.h"
39 #include "AliMpDetElement.h"
40 #include "AliMpManuIterator.h"
41 #include "Riostream.h"
42 #include "TAxis.h"
43 #include "TCanvas.h"
44 #include "TLegend.h"
45 #include "TFile.h"
46 #include "TGraph.h"
47 #include "TBox.h"
48 #include "TH2F.h"
49 #include "TStyle.h"
50 #include "TText.h"
51 #include <vector>
52 #endif
53 
54 namespace
55 {
56  Int_t NTOTALNUMBEROFPADS(1064008);
57 }
58 
59 //______________________________________________________________________________
60 void ReadIntegers(const char* filename, std::vector<int>& integers)
61 {
64  ifstream in(gSystem->ExpandPathName(filename));
65  int i;
66 
67  char line[10000];
68 
69  in.getline(line,10000,'\n');
70 
71  TString sline(line);
72 
73  if (sline.Contains(","))
74  {
75  TObjArray* a = sline.Tokenize(",");
76  TIter next(a);
77  TObjString* s;
78  while ( ( s = static_cast<TObjString*>(next()) ) )
79  {
80  integers.push_back(s->String().Atoi());
81  }
82  }
83  else
84  {
85  integers.push_back(sline.Atoi());
86 
87  while ( in >> i )
88  {
89  integers.push_back(i);
90  }
91  }
92 
93  std::sort(integers.begin(),integers.end());
94 }
95 
96 
97 //______________________________________________________________________________
99  AliMUONVStore*& vstatusMap,
100  const char* cdbStorage = "alien://folder=/alice/data/2011/OCDB",
101  Int_t runNumber=145292)
102 {
103 
104  AliCDBManager::Instance()->SetDefaultStorage(cdbStorage);
105  AliCDBManager::Instance()->SetRun(runNumber);
106 
108 
110 
111  AliMUONCalibrationData cd(runNumber);
112 
113  AliMUONPadStatusMaker statusMaker(cd);
114 
115  statusMaker.SetLimits(*recoParam);
116 
117  UInt_t mask = recoParam->PadGoodnessMask();
118 
119  statusMaker.Report(mask);
120 
121  vstatus = static_cast<AliMUONVStore*>(statusMaker.StatusStore()->Clone());
122 
123  const Bool_t deferredInitialization = kFALSE;
124 
125  AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization);
126 
127  vstatusMap = static_cast<AliMUONVStore*>(statusMapMaker.StatusMap()->Clone());
128 }
129 
130 //______________________________________________________________________________
131 Int_t GetBadChannels(Int_t runNumber,
132  Int_t& nbadped,
133  Int_t& nbadhv,
134  Int_t& nbadlv,
135  Int_t& nbadocc,
136  Int_t& nmissing,
137  Int_t& nreco,
138  Int_t chamber=-1)
139 {
140  if (!AliCDBManager::Instance()->IsDefaultStorageSet())
141  {
142 // AliCDBManager::Instance()->SetDefaultStorage("alien://folder=/alice/data/2011/OCDB?cacheFold=/local/cdb");
143  AliCDBManager::Instance()->SetDefaultStorage("raw://");
144  }
145 
146  AliCDBManager::Instance()->SetRun(runNumber);
147 
149 
150  AliMUONCalibrationData cd(runNumber,true);
151 
152  AliMUONPadStatusMaker statusMaker(cd);
153 
155 
156  statusMaker.SetLimits(*recoParam);
157 
159  Int_t detElemId, manuId;
160 
161  Int_t pedCheck = (
167 
168  Int_t hvCheck = (
174 
175 
176  Int_t occCheck = (
178  );
179 
180  Int_t lvCheck = ( AliMUONPadStatusMaker::kLVTooLow );
181 
182  Int_t ntotal(0);
183  Int_t nbad(0);
184  nbadped=0;
185  nbadocc=0;
186  nbadhv=0;
187  nbadlv=0;
188  nmissing=0;
189  nreco=0;
190 
191  while ( it.Next(detElemId,manuId) )
192  {
194 
195  if ( chamber >= 0 && AliMpDEManager::GetChamberId(detElemId) != chamber ) continue;
196 
197  for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
198  {
199  if ( de->IsConnectedChannel(manuId,manuChannel) )
200  {
201  ++ntotal;
202 
203  UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel);
204 
205  if (!status) continue;
206 
207  bool bad(false);
208 
209  if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) )
210  {
211  ++nbadped;
212  bad=true;
213  }
214 
215  if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) )
216  {
217  ++nbadhv;
218  bad=true;
219  }
220 
221  if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,lvCheck,0) )
222  {
223  ++nbadlv;
224  bad=true;
225  }
226 
227  if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) )
228  {
229  ++nbadocc;
230  bad=true;
231  }
232 
233  if ( status & recoParam->PadGoodnessMask() )
234  {
235  ++nreco;
236  }
237 
239  {
240  bad=true;
241  ++nmissing;
242  }
243 
244  if (bad) ++nbad;
245  }
246  }
247  }
248 
249  if ( chamber<0 && ntotal!=NTOTALNUMBEROFPADS)
250  {
251  cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d",
252  ntotal,runNumber) << endl;
253  }
254  else
255  {
256  cout << Form("Chamber %d - %d channels",chamber,ntotal) << endl;
257  cout << Form("nbadped %5d nbadhv %5d nbadlv %5d nbadocc %5d nmissing %5d nreco %5d",
258  nbadped,nbadhv,nbadlv,nbadocc,nmissing,nreco) << endl;
259  }
260 
261  AliCDBManager::Instance()->ClearCache();
262 
263  return nbad;
264 }
265 
266 //______________________________________________________________________________
267 void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized)
268 {
269  if (!f) return;
270 
271  TGraph* g = static_cast<TGraph*>(f->Get(gname));
272 
273  if (!g) return;
274 
275  if ( normalized )
276  {
277  g = static_cast<TGraph*>(g->Clone());
278  for ( Int_t i = 0; i < g->GetN(); ++i )
279  {
280  Double_t y = g->GetY()[i];
281  g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS);
282  }
283  }
284 
285  g->Draw("lp");
286  g->GetXaxis()->SetNdivisions(505);
287  g->GetXaxis()->SetNoExponent();
288 
289  if (l) l->AddEntry(g,gname,"LP");
290 }
291 
292 //______________________________________________________________________________
293 void DrawPeriod(int runmin, int runmax, int run1, int run2, double ymin, double ymax, const char* label)
294 {
295  if ( run1 < runmin || run1 > runmax || run2 < runmin || run2 > runmax ) return;
296 
297  TBox* b = new TBox(run1,ymin,run2,ymax);
298  b->SetFillColor(5);
299  b->Draw();
300  TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
301  text->SetTextAlign(22);
302  text->SetTextSize(0.02);
303  text->Draw();
304 }
305 
306 //______________________________________________________________________________
307 void DrawEvolution(const char* file, bool normalized=true)
308 {
309 
310  TFile* f = TFile::Open(gSystem->ExpandPathName(file));
311 
312  if (!f) return;
313 
314  TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
315 
316  c->SetGridy();
317  c->SetTicky();
318 
319  c->Draw();
320 
321  TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
322 
323  TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
324  if (!g) return;
325 
326  int runmin = TMath::Nint(g->GetX()[0]);
327  int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
328 
329  cout << Form("Run range found in file %s = %d - %d",file,runmin,runmax) << endl;
330 
331  double ymax(0.4);
332 
333  TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
334 
335  gStyle->SetOptStat(kFALSE);
336  h->Draw();
337  h->GetXaxis()->SetNoExponent();
338  h->GetXaxis()->SetNdivisions(505);
339 
340  gStyle->SetOptTitle(kFALSE);
341 
342  DrawPeriod(runmin,runmax,115881,117222,0,ymax,"10b");
343 
344  DrawPeriod(runmin,runmax,119159,120824,0,ymax,"10c");
345 
346  DrawPeriod(runmin,runmax,122374,126424,0,ymax,"10d");
347 
348  DrawPeriod(runmin,runmax,127724,130850,0,ymax,"10e");
349 
350  DrawPeriod(runmin,runmax,133005,134929,0,ymax,"10f");
351 
352  DrawPeriod(runmin,runmax,135658,136376,0,ymax,"10g");
353 
354  DrawPeriod(runmin,runmax,137133,139513,0,ymax,"10h");
355 
356  DrawPeriod(runmin,runmax,143856,146860,0,ymax,"11a");
357 
358  DrawPeriod(runmin,runmax,148370,150702,0,ymax,"11b");
359 
360  DrawPeriod(runmin,runmax,151566,154583,0,ymax,"11c");
361 
362  DrawPeriod(runmin,runmax,158084,159606,0,ymax,"11d");
363 
364  DrawPeriod(runmin,runmax,160677,162717,0,ymax,"11e");
365 
366  DrawPeriod(runmin,runmax,162933,165744,0,ymax,"11f");
367 
368  DrawPeriod(runmin,runmax,167703,170593,0,ymax,"11h");
369 
370  // 2012
371 
372  DrawPeriod(runmin,runmax,176661,177295,0,ymax,"12a");
373 
374  DrawPeriod(runmin,runmax,177384,178053,0,ymax,"12b");
375 
376  DrawPeriod(runmin,runmax,179603,180569,0,ymax,"12c");
377 
378  DrawPeriod(runmin,runmax,183913,186320,0,ymax,"12d");
379 
380  DrawPeriod(runmin,runmax,186365,186602,0,ymax,"12e");
381 
382  DrawPeriod(runmin,runmax,186668,188123,0,ymax,"12f");
383 
384  DrawPeriod(runmin,runmax,188362,188503,0,ymax,"12g");
385 
386  DrawPeriod(runmin,runmax,189122,190110,0,ymax,"12h");
387 
388  // 2013
389 
390  DrawPeriod(runmin,runmax,195344,195483,0,ymax,"13b");
391  DrawPeriod(runmin,runmax,195529,195677,0,ymax,"13c");
392  DrawPeriod(runmin,runmax,195681,195873,0,ymax,"13d");
393  DrawPeriod(runmin,runmax,195949,196311,0,ymax,"13e");
394  DrawPeriod(runmin,runmax,196433,197388,0,ymax,"13f");
395 
396  // 2015
397  // periods are from the logbook, taking only PHYSICS% partitions
398  // into account
399  DrawPeriod(runmin,runmax,213329,215151,0,ymax,"15a");
400  DrawPeriod(runmin,runmax,215160,215579,0,ymax,"15b");
401  DrawPeriod(runmin,runmax,215580,219968,0,ymax,"15c");
402  DrawPeriod(runmin,runmax,220050,223195,0,ymax,"15d");
403  DrawPeriod(runmin,runmax,223227,224779,0,ymax,"15e");
404  DrawPeriod(runmin,runmax,224826,226606,0,ymax,"15f");
405 
406  DrawPeriod(runmin,runmax,228936,231321,0,ymax,"15g");
407  DrawPeriod(runmin,runmax,232914,234050,0,ymax,"15h");
408  DrawPeriod(runmin,runmax,235196,236866,0,ymax,"15i");
409  DrawPeriod(runmin,runmax,236965,238621,0,ymax,"15j");
410  DrawPeriod(runmin,runmax,238890,239025,0,ymax,"15k");
411  DrawPeriod(runmin,runmax,239319,241544,0,ymax,"15l");
412  DrawPeriod(runmin,runmax,244340,244628,0,ymax,"15n");
413  DrawPeriod(runmin,runmax,244918,246994,0,ymax,"15o");
414 
415  Draw(f,"nbad",l,normalized);
416  Draw(f,"nbadped",l,normalized);
417  Draw(f,"nbadocc",l,normalized);
418  Draw(f,"nbadhv",l,normalized);
419  Draw(f,"nbadlv",l,normalized);
420  Draw(f,"nmissing",l,normalized);
421  Draw(f,"nreco",l,normalized);
422 
423  h->Draw("same");
424 
425  c->RedrawAxis("g");
426 
427  l->Draw();
428 }
429 
430 //______________________________________________________________________________
431 void MUONStatusMapEvolution(const char* runlist, const char* outfile)
432 {
433  // Compute the number of bad pads (because of bad ped, bad hv, bad lv,
434  // or missing in configuration)
435  //
436  // output a root file with the different graphs.
437  //
438  // output can be then plotted using the DrawEvolution function
439  //
440  // Note that the output of different runlists can then be merged simply using
441  // the hadd program, and so then the DrawEvolution can be used over
442  // a huge period, e.g. a full year, while this method is better restricted
443  // to a period or even less (depending on your success of accessing the OCDB)
444  //
445 
446  std::vector<int> runs;
447 
448  ReadIntegers(runlist,runs);
449 
450  if ( runs.empty() )
451  {
452  cout << "No runs to process..." << endl;
453  return;
454  }
455 
456  int year(2015);
457 
458  if ( runs[0] <= 139699 ) year=2010;
459 
460  if ( runs[0] <= 176000 ) year=2011;
461 
462  if ( runs[0] <= 195344 ) year = 2012;
463 
464  if ( runs[0] <= 198000 ) year = 2013;
465 
466  TString defaultOCDB;
467 
468  defaultOCDB.Form("local:///cvmfs/alice-ocdb.cern.ch/calibration/data/%d/OCDB",year);
469 
470 // defaultOCDB.Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year);
471 
472  AliCDBManager::Instance()->SetDefaultStorage(defaultOCDB.Data());
473  AliCDBManager::Instance()->SetRun(0);
474 
475  TList glist;
476 
477  glist.SetOwner(kTRUE);
478 
479  TGraph* gnbad = new TGraph(runs.size());
480  gnbad->SetName("nbad");
481  glist.Add(gnbad);
482 
483  TGraph* gnbadped = new TGraph(runs.size());
484  gnbadped->SetName("nbadped");
485  glist.Add(gnbadped);
486 
487  TGraph* gnbadocc = new TGraph(runs.size());
488  gnbadocc->SetName("nbadocc");
489  glist.Add(gnbadocc);
490 
491  TGraph* gnbadhv = new TGraph(runs.size());
492  gnbadhv->SetName("nbadhv");
493  glist.Add(gnbadhv);
494 
495  TGraph* gnbadlv = new TGraph(runs.size());
496  gnbadlv->SetName("nbadlv");
497  glist.Add(gnbadlv);
498 
499  TGraph* gnmissing = new TGraph(runs.size());
500  gnmissing->SetName("nmissing");
501  glist.Add(gnmissing);
502 
503  TGraph* gnreco = new TGraph(runs.size());
504  gnreco->SetName("nreco");
505  glist.Add(gnreco);
506 
507  for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i )
508  {
509  Int_t runNumber = runs[i];
510  Int_t nbadped;
511  Int_t nbadhv;
512  Int_t nbadlv;
513  Int_t nbadocc;
514  Int_t nmissing;
515  Int_t nreco;
516 
517  Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadlv,nbadocc,nmissing,nreco);
518 
519  gnbad->SetPoint(i,runNumber,nbad);
520  gnbadped->SetPoint(i,runNumber,nbadped);
521  gnbadhv->SetPoint(i,runNumber,nbadhv);
522  gnbadlv->SetPoint(i,runNumber,nbadlv);
523  gnbadocc->SetPoint(i,runNumber,nbadocc);
524  gnmissing->SetPoint(i,runNumber,nmissing);
525  gnreco->SetPoint(i,runNumber,nreco);
526  }
527 
528  TIter next(&glist);
529  TGraph* g;
530  Int_t index(0);
531 
532  TFile f(outfile,"recreate");
533  Int_t color[] = { 1 , 2 , 3 , 4, 6, 8 };
534  Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 };
535 
536  while ( ( g = static_cast<TGraph*>(next() ) ) )
537  {
538  g->GetXaxis()->SetNdivisions(505);
539  g->GetXaxis()->SetNoExponent();
540  g->SetMinimum(0);
541  g->GetYaxis()->SetNoExponent();
542  g->SetLineColor(color[index]);
543  g->SetMarkerStyle(marker[index]);
544  g->SetMarkerColor(color[index]);
545  g->SetMarkerSize(1.0);
546  ++index;
547  g->Write();
548  }
549 
550  f.Close();
551 
552 
553 }
Convert a pad status container into a pad status map container.
TFile * Open(const char *filename, Long64_t &nevents)
TStyle * gStyle
#define TObjArray
static Int_t BuildStatus(Int_t pedStatus, Int_t hvStatus, Int_t lvStatus, Int_t otherStatus)
TFile f("CalibObjects.root")
static Bool_t LoadDDLStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:149
Class with MUON reconstruction parameters.
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
The class defines the electronics properties of detection element.
void MUONStatusMap(AliMUONVStore *&vstatus, AliMUONVStore *&vstatusMap, const char *cdbStorage="alien://folder=/alice/data/2011/OCDB", Int_t runNumber=145292)
Definition: MUONStatusMap.C:98
Bool_t Next(Int_t &detElemId, Int_t &manuId)
Class to loop over all manus of MUON Tracker.
static AliMpDDLStore * Instance(Bool_t warn=true)
static Int_t GetChamberId(Int_t detElemId, Bool_t warn=true)
AliMUONVStore * StatusMap() const
static Int_t ManuNofChannels()
Max number of channels per manu.
AliMUONVCalibParam * PadStatus(Int_t detElemId, Int_t manuId) const
Int_t GetBadChannels(Int_t runNumber, Int_t &nbadped, Int_t &nbadhv, Int_t &nbadlv, Int_t &nbadocc, Int_t &nmissing, Int_t &nreco, Int_t chamber=-1)
std::vector< RunInfo > runs
void ReadIntegers(const char *filename, std::vector< int > &integers)
Definition: MUONStatusMap.C:60
AliMUONVStore * StatusStore() const
void DrawPeriod(int runmin, int runmax, int run1, int run2, double ymin, double ymax, const char *label)
Single entry point to access MUON calibration data.
TArrayI runlist(10000)
void MUONStatusMapEvolution(const char *runlist, const char *outfile)
UInt_t PadGoodnessMask() const
Get the goodness mask.
Bool_t IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
Base class for MUON data stores.
Definition: AliMUONVStore.h:22
Bool_t LoadMapping(Bool_t segmentationOnly=kFALSE)
Definition: AliMUONCDB.cxx:522
Int_t run1
void DrawEvolution(const char *file, bool normalized=true)
Make a 2DStore of pad statuses, using different sources of information.
AliMUONRecoParam * LoadRecoParam()
Definition: AliMUONCDB.cxx:555
void SetLimits(const AliMUONRecoParam &recoParams)
void Draw(TFile *f, const char *gname, TLegend *l, Bool_t normalized)