]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONStatusMap.C
Fixes for coverity: SELF_ASSIGN
[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->SetTextSize(0.05);
292   text->Draw();
293 }
294
295 //______________________________________________________________________________
296 void DrawEvolution(const char* file, bool normalized=true)
297 {
298
299   TFile* f = TFile::Open(file);
300   
301   if (!f) return;
302   
303   TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
304   
305   c->SetGridy();
306   c->SetTicky();
307   
308   c->Draw();
309   
310   TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
311
312   TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
313   if (!g) return;
314   
315   int runmin = TMath::Nint(g->GetX()[0]);
316   int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
317   
318   double ymax(0.4);
319   
320   TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
321
322   gStyle->SetOptStat(kFALSE);
323   h->Draw();
324   h->GetXaxis()->SetNoExponent();
325   h->GetXaxis()->SetNdivisions(505);
326
327   gStyle->SetOptTitle(kFALSE);
328
329   DrawPeriod(115881,117222,0,ymax,"10b"); 
330
331   DrawPeriod(119159,120824,0,ymax,"10c");
332
333   DrawPeriod(122374,126424,0,ymax,"10d");
334
335   DrawPeriod(127724,130850,0,ymax,"10e");
336
337   DrawPeriod(133005,134929,0,ymax,"10f");
338
339   DrawPeriod(135658,136376,0,ymax,"10g");
340
341   DrawPeriod(137133,139513,0,ymax,"10h");
342   
343   DrawPeriod(143856,146860,0,ymax,"11a");
344
345   DrawPeriod(148370,150702,0,ymax,"11b");
346
347   DrawPeriod(151566,154583,0,ymax,"11c");
348
349   DrawPeriod(158084,159606,0,ymax,"11d");
350
351   DrawPeriod(160677,162717,0,ymax,"11e");
352
353   DrawPeriod(167703,170207,0,ymax,"11h");
354              
355   Draw(f,"nbad",l,normalized);
356   Draw(f,"nbadped",l,normalized);
357   Draw(f,"nbadocc",l,normalized);
358   Draw(f,"nbadhv",l,normalized);
359   Draw(f,"nmissing",l,normalized);
360   Draw(f,"nreco",l,normalized);
361   
362   h->Draw("same");
363
364   c->RedrawAxis("g");
365   
366   l->Draw();
367 }
368
369 //______________________________________________________________________________
370 void MUONStatusMapEvolution(const char* runlist, const char* outfile)
371 {
372   // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy
373   // or missing in configuration)
374   //
375   // output a root file with the different graphs.
376   //
377   // output can be then plotted using the DrawEvolution function
378   //
379   // Note that the output of different runlists can then be merged simply using
380   // the hadd program, and so then the DrawEvolution can be used over
381   // a huge period, e.g. a full year, while this method is better restricted
382   // to a period or even less (depending on your success of accessing the OCDB)
383   //
384   
385   std::vector<int> runs;
386
387   ReadIntegers(runlist,runs);
388   
389   if ( runs.empty() ) 
390   {
391     cout << "No runs to process..." << endl;
392     return;    
393   }
394   
395   int year(2011);
396   
397   if ( runs[0] <= 139699 ) year=2010;
398   
399   AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year));
400   
401   TList glist;
402   
403   glist.SetOwner(kTRUE);
404   
405   TGraph* gnbad = new TGraph(runs.size());
406   gnbad->SetName("nbad");
407   glist.Add(gnbad);
408   
409   TGraph* gnbadped = new TGraph(runs.size());
410   gnbadped->SetName("nbadped");
411   glist.Add(gnbadped);
412   
413   TGraph* gnbadocc = new TGraph(runs.size());
414   gnbadocc->SetName("nbadocc");
415   glist.Add(gnbadocc);
416   
417   TGraph* gnbadhv = new TGraph(runs.size());
418   gnbadhv->SetName("nbadhv");
419   glist.Add(gnbadhv);
420   
421   TGraph* gnmissing = new TGraph(runs.size());
422   gnmissing->SetName("nmissing");
423   glist.Add(gnmissing);
424
425   TGraph* gnreco = new TGraph(runs.size());
426   gnreco->SetName("nreco");
427   glist.Add(gnreco);
428   
429   for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i ) 
430   {
431     Int_t runNumber = runs[i];
432     Int_t nbadped;
433     Int_t nbadhv;
434     Int_t nbadgain;
435     Int_t nbadocc;
436     Int_t nmissing;
437     Int_t nreco;
438     
439     Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco);
440     
441     gnbad->SetPoint(i,runNumber,nbad);
442     gnbadped->SetPoint(i,runNumber,nbadped);
443     gnbadhv->SetPoint(i,runNumber,nbadhv);
444     gnbadocc->SetPoint(i,runNumber,nbadocc);
445     gnmissing->SetPoint(i,runNumber,nmissing);
446     gnreco->SetPoint(i,runNumber,nreco);
447   }
448   
449   TIter next(&glist);
450   TGraph* g;
451   Int_t index(0);
452
453   TFile f(outfile,"recreate");
454   Int_t  color[] = {  1 ,  2 ,  3 ,  4,  6, 8 };
455   Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 };
456
457   while ( ( g = static_cast<TGraph*>(next() ) ) )
458   {
459     g->GetXaxis()->SetNdivisions(505);
460     g->GetXaxis()->SetNoExponent();
461     g->SetMinimum(0);
462     g->GetYaxis()->SetNoExponent();
463     g->SetLineColor(color[index]);
464     g->SetMarkerStyle(marker[index]);
465     g->SetMarkerColor(color[index]);
466     g->SetMarkerSize(1.0);
467     ++index;
468     g->Write();
469   }
470     
471   f.Close();
472   
473   
474 }