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