]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONStatusMap.C
Fixes for coverity.
[u/mrichter/AliRoot.git] / MUON / MUONStatusMap.C
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
18 /// \ingroup macros
19 /// \file MUONStatusMap.C
20 /// \brief Macro to check/test pad status and pad status map makers
21 ///
22 /// \author Laurent Aphecetche
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"
33 #include "AliMUONPadStatusMapMaker.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 {
62   /// Read integers from filename, where integers are either
63   /// separated by "," or by return carriage
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 //______________________________________________________________________________
98 void MUONStatusMap(AliMUONVStore*& vstatus,
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   
107   AliMUONCDB::LoadMapping();
108   
109   AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
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& nbadgain,
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   
148   AliMpCDB::LoadDDLStore();
149   
150   AliMUONCalibrationData cd(runNumber,true);
151   
152   AliMUONPadStatusMaker statusMaker(cd);
153   
154   AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
155
156   statusMaker.SetLimits(*recoParam);
157   
158   AliMpManuIterator it;
159   Int_t detElemId, manuId;
160   
161   Int_t pedCheck = ( 
162                      AliMUONPadStatusMaker::kPedMeanZero |
163                      AliMUONPadStatusMaker::kPedMeanTooLow |
164                      AliMUONPadStatusMaker::kPedMeanTooHigh |
165                      AliMUONPadStatusMaker::kPedSigmaTooLow |
166                      AliMUONPadStatusMaker::kPedSigmaTooHigh );
167      
168   Int_t hvCheck = ( 
169                    AliMUONPadStatusMaker::kHVError |
170                    AliMUONPadStatusMaker::kHVTooLow |
171                    AliMUONPadStatusMaker::kHVTooHigh |
172                    AliMUONPadStatusMaker::kHVChannelOFF |
173                    AliMUONPadStatusMaker::kHVSwitchOFF );
174
175   
176   Int_t occCheck = (
177                     AliMUONPadStatusMaker::kManuOccupancyTooHigh 
178                    );
179                     
180   Int_t ntotal(0);
181   Int_t nbad(0);
182   nbadped=0;
183   nbadocc=0;
184   nbadgain=0;
185   nbadhv=0;
186   nmissing=0;
187   nreco=0;
188   
189   while ( it.Next(detElemId,manuId) )
190   {
191     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
192     
193     if ( chamber >= 0 && AliMpDEManager::GetChamberId(detElemId) != chamber ) continue;
194     
195     for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
196     {
197       if ( de->IsConnectedChannel(manuId,manuChannel) )
198       {
199         ++ntotal;
200         
201         UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel);
202         
203         if (!status) continue;
204         
205         bool bad(false);
206         
207         if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) ) 
208         {
209           ++nbadped;
210           bad=true;
211         }
212         
213         if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) ) 
214         {
215           ++nbadhv;
216           bad=true;
217         }
218         
219         if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) ) 
220         {
221           ++nbadocc;
222           bad=true;
223         }
224         
225         if ( status & recoParam->PadGoodnessMask() ) 
226         {
227           ++nreco;
228         }
229         
230         if ( status & AliMUONPadStatusMaker::BuildStatus(AliMUONPadStatusMaker::kMissing,0,0,AliMUONPadStatusMaker::kMissing) )
231         {
232           bad=true;
233           ++nmissing;
234         }
235         
236         if (bad) ++nbad;
237       }
238     }
239   }
240   
241   if ( chamber<0 && ntotal!=NTOTALNUMBEROFPADS)
242   {
243     cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d",
244                  ntotal,runNumber) << endl;
245   }
246   else
247   {
248     cout << Form("Chamber %d - %d channels",chamber,ntotal) << endl;
249     cout << Form("nbadped %5d nbadhv %5d nbadgain %5d nbadocc %5d nmissing %5d nreco %5d",
250                  nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco) << endl;
251   }
252   
253   AliCDBManager::Instance()->ClearCache(); 
254  
255   return nbad;
256 }
257
258 //______________________________________________________________________________
259 void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized)
260 {
261   if (!f) return;
262   
263   TGraph* g = static_cast<TGraph*>(f->Get(gname));
264   
265   if (!g) return;
266   
267   if ( normalized ) 
268   {
269     g = static_cast<TGraph*>(g->Clone());
270     for ( Int_t i = 0; i < g->GetN(); ++i ) 
271     {
272       Double_t y = g->GetY()[i];
273       g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS);
274     }
275   }
276   
277   g->Draw("lp");
278   g->GetXaxis()->SetNdivisions(505);
279   g->GetXaxis()->SetNoExponent();
280   
281   if (l) l->AddEntry(g,gname,"LP");
282 }
283
284 //______________________________________________________________________________
285 void DrawPeriod(double run1, double run2, double ymin, double ymax, const char* label)
286 {
287   TBox* b = new TBox(run1,ymin,run2,ymax);
288   b->SetFillColor(5);
289   b->Draw();
290   TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
291   text->SetTextAlign(22);
292   text->SetTextSize(0.02);
293   text->Draw();
294 }
295
296 //______________________________________________________________________________
297 void DrawEvolution(const char* file, bool normalized=true)
298 {
299
300   TFile* f = TFile::Open(gSystem->ExpandPathName(file));
301   
302   if (!f) return;
303   
304   TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
305   
306   c->SetGridy();
307   c->SetTicky();
308   
309   c->Draw();
310   
311   TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
312
313   TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
314   if (!g) return;
315   
316   int runmin = TMath::Nint(g->GetX()[0]);
317   int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
318   
319   cout << Form("Run range found in file %s = %d - %d",file,runmin,runmax) << endl;
320   
321   double ymax(0.4);
322   
323   TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
324
325   gStyle->SetOptStat(kFALSE);
326   h->Draw();
327   h->GetXaxis()->SetNoExponent();
328   h->GetXaxis()->SetNdivisions(505);
329
330   gStyle->SetOptTitle(kFALSE);
331
332   DrawPeriod(115881,117222,0,ymax,"10b"); 
333
334   DrawPeriod(119159,120824,0,ymax,"10c");
335
336   DrawPeriod(122374,126424,0,ymax,"10d");
337
338   DrawPeriod(127724,130850,0,ymax,"10e");
339
340   DrawPeriod(133005,134929,0,ymax,"10f");
341
342   DrawPeriod(135658,136376,0,ymax,"10g");
343
344   DrawPeriod(137133,139513,0,ymax,"10h");
345   
346   DrawPeriod(143856,146860,0,ymax,"11a");
347
348   DrawPeriod(148370,150702,0,ymax,"11b");
349
350   DrawPeriod(151566,154583,0,ymax,"11c");
351
352   DrawPeriod(158084,159606,0,ymax,"11d");
353
354   DrawPeriod(160677,162717,0,ymax,"11e");
355
356   DrawPeriod(162933,165744,0,ymax,"11f");
357
358   DrawPeriod(167703,170593,0,ymax,"11h");
359
360   // 2012
361     
362     DrawPeriod(176661,177295,0,ymax,"12a");
363
364     DrawPeriod(177384,178053,0,ymax,"12b");
365
366     DrawPeriod(179603,180569,0,ymax,"12c");
367
368     DrawPeriod(183913,186320,0,ymax,"12d");
369     
370     DrawPeriod(186365,186602,0,ymax,"12e");
371     
372     DrawPeriod(186668,188123,0,ymax,"12f");
373     
374     DrawPeriod(188362,188503,0,ymax,"12g");
375     
376     DrawPeriod(189122,190110,0,ymax,"12h");
377   
378   // 2013
379   
380   DrawPeriod(195344,195483,0,ymax,"LHC13b");
381   DrawPeriod(195529,195677,0,ymax,"LHC13c");
382   DrawPeriod(195681,195873,0,ymax,"LHC13d");
383   DrawPeriod(195949,196311,0,ymax,"LHC13e");
384   DrawPeriod(196433,197388,0,ymax,"LHC13f");
385   
386   Draw(f,"nbad",l,normalized);
387   Draw(f,"nbadped",l,normalized);
388   Draw(f,"nbadocc",l,normalized);
389   Draw(f,"nbadhv",l,normalized);
390   Draw(f,"nmissing",l,normalized);
391   Draw(f,"nreco",l,normalized);
392   
393   h->Draw("same");
394
395   c->RedrawAxis("g");
396   
397   l->Draw();
398 }
399
400 //______________________________________________________________________________
401 void MUONStatusMapEvolution(const char* runlist, const char* outfile)
402 {
403   // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy
404   // or missing in configuration)
405   //
406   // output a root file with the different graphs.
407   //
408   // output can be then plotted using the DrawEvolution function
409   //
410   // Note that the output of different runlists can then be merged simply using
411   // the hadd program, and so then the DrawEvolution can be used over
412   // a huge period, e.g. a full year, while this method is better restricted
413   // to a period or even less (depending on your success of accessing the OCDB)
414   //
415   
416   std::vector<int> runs;
417
418   ReadIntegers(runlist,runs);
419   
420   if ( runs.empty() ) 
421   {
422     cout << "No runs to process..." << endl;
423     return;    
424   }
425   
426   int year(2013);
427   
428   if ( runs[0] <= 139699 ) year=2010;
429   
430   if ( runs[0] <= 176000 ) year=2011;
431   
432   if ( runs[0] <= 195344 ) year = 2012;
433       
434   AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year));
435
436 //  AliCDBManager::Instance()->SetDefaultStorage("local:///Users/laurent/Alice/OCDBcopy2013");
437 //
438   TList glist;
439   
440   glist.SetOwner(kTRUE);
441   
442   TGraph* gnbad = new TGraph(runs.size());
443   gnbad->SetName("nbad");
444   glist.Add(gnbad);
445   
446   TGraph* gnbadped = new TGraph(runs.size());
447   gnbadped->SetName("nbadped");
448   glist.Add(gnbadped);
449   
450   TGraph* gnbadocc = new TGraph(runs.size());
451   gnbadocc->SetName("nbadocc");
452   glist.Add(gnbadocc);
453   
454   TGraph* gnbadhv = new TGraph(runs.size());
455   gnbadhv->SetName("nbadhv");
456   glist.Add(gnbadhv);
457   
458   TGraph* gnmissing = new TGraph(runs.size());
459   gnmissing->SetName("nmissing");
460   glist.Add(gnmissing);
461
462   TGraph* gnreco = new TGraph(runs.size());
463   gnreco->SetName("nreco");
464   glist.Add(gnreco);
465   
466   for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i ) 
467   {
468     Int_t runNumber = runs[i];
469     Int_t nbadped;
470     Int_t nbadhv;
471     Int_t nbadgain;
472     Int_t nbadocc;
473     Int_t nmissing;
474     Int_t nreco;
475     
476     Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco);
477     
478     gnbad->SetPoint(i,runNumber,nbad);
479     gnbadped->SetPoint(i,runNumber,nbadped);
480     gnbadhv->SetPoint(i,runNumber,nbadhv);
481     gnbadocc->SetPoint(i,runNumber,nbadocc);
482     gnmissing->SetPoint(i,runNumber,nmissing);
483     gnreco->SetPoint(i,runNumber,nreco);
484   }
485   
486   TIter next(&glist);
487   TGraph* g;
488   Int_t index(0);
489
490   TFile f(outfile,"recreate");
491   Int_t  color[] = {  1 ,  2 ,  3 ,  4,  6, 8 };
492   Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 };
493
494   while ( ( g = static_cast<TGraph*>(next() ) ) )
495   {
496     g->GetXaxis()->SetNdivisions(505);
497     g->GetXaxis()->SetNoExponent();
498     g->SetMinimum(0);
499     g->GetYaxis()->SetNoExponent();
500     g->SetLineColor(color[index]);
501     g->SetMarkerStyle(marker[index]);
502     g->SetMarkerColor(color[index]);
503     g->SetMarkerSize(1.0);
504     ++index;
505     g->Write();
506   }
507     
508   f.Close();
509   
510   
511 }