1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 /// \file MUONStatusMap.C
20 /// \brief Macro to check/test pad status and pad status map makers
22 /// \author Laurent Aphecetche
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25 #include "AliCDBManager.h"
26 #include "AliCDBEntry.h"
29 #include "AliMUONCDB.h"
30 #include "AliMUONCalibrationData.h"
31 #include "AliMUONPadStatusMaker.h"
32 #include "AliMUONPadStatusMapMaker.h"
33 #include "AliMUONRecoParam.h"
34 #include "AliMUONVCalibParam.h"
35 #include "AliMUONVStore.h"
36 #include "AliMpConstants.h"
37 #include "AliMpDDLStore.h"
38 #include "AliMpDetElement.h"
39 #include "AliMpManuIterator.h"
40 #include "Riostream.h"
55 Int_t NTOTALNUMBEROFPADS(1064008);
58 //______________________________________________________________________________
59 void ReadIntegers(const char* filename, std::vector<int>& integers)
61 /// Read integers from filename, where integers are either
62 /// separated by "," or by return carriage
63 ifstream in(gSystem->ExpandPathName(filename));
68 in.getline(line,10000,'\n');
72 if (sline.Contains(","))
74 TObjArray* a = sline.Tokenize(",");
77 while ( ( s = static_cast<TObjString*>(next()) ) )
79 integers.push_back(s->String().Atoi());
84 integers.push_back(sline.Atoi());
88 integers.push_back(i);
92 std::sort(integers.begin(),integers.end());
96 //______________________________________________________________________________
97 void MUONStatusMap(AliMUONVStore*& vstatus,
98 AliMUONVStore*& vstatusMap,
99 const char* cdbStorage = "alien://folder=/alice/data/2011/OCDB",
100 Int_t runNumber=145292)
103 AliCDBManager::Instance()->SetDefaultStorage(cdbStorage);
104 AliCDBManager::Instance()->SetRun(runNumber);
106 AliMUONCDB::LoadMapping();
108 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
110 AliMUONCalibrationData cd(runNumber);
112 AliMUONPadStatusMaker statusMaker(cd);
114 statusMaker.SetLimits(*recoParam);
116 UInt_t mask = recoParam->PadGoodnessMask();
118 statusMaker.Report(mask);
120 vstatus = static_cast<AliMUONVStore*>(statusMaker.StatusStore()->Clone());
122 const Bool_t deferredInitialization = kFALSE;
124 AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization);
126 vstatusMap = static_cast<AliMUONVStore*>(statusMapMaker.StatusMap()->Clone());
129 //______________________________________________________________________________
130 Int_t GetBadChannels(Int_t runNumber,
138 if (!AliCDBManager::Instance()->IsDefaultStorageSet())
140 AliCDBManager::Instance()->SetDefaultStorage("raw://");
143 AliCDBManager::Instance()->SetRun(runNumber);
145 AliMpCDB::LoadDDLStore();
147 AliMUONCalibrationData cd(runNumber,true);
149 AliMUONPadStatusMaker statusMaker(cd);
151 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
153 statusMaker.SetLimits(*recoParam);
155 AliMpManuIterator it;
156 Int_t detElemId, manuId;
159 AliMUONPadStatusMaker::kPedMeanZero |
160 AliMUONPadStatusMaker::kPedMeanTooLow |
161 AliMUONPadStatusMaker::kPedMeanTooHigh |
162 AliMUONPadStatusMaker::kPedSigmaTooLow |
163 AliMUONPadStatusMaker::kPedSigmaTooHigh );
166 AliMUONPadStatusMaker::kHVError |
167 AliMUONPadStatusMaker::kHVTooLow |
168 AliMUONPadStatusMaker::kHVTooHigh |
169 AliMUONPadStatusMaker::kHVChannelOFF |
170 AliMUONPadStatusMaker::kHVSwitchOFF );
174 AliMUONPadStatusMaker::kManuOccupancyTooHigh
186 while ( it.Next(detElemId,manuId) )
188 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
189 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
191 if ( de->IsConnectedChannel(manuId,manuChannel) )
195 UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel);
197 if (!status) continue;
201 if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) )
207 if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) )
213 if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) )
219 if ( status & recoParam->PadGoodnessMask() )
224 if ( status & AliMUONPadStatusMaker::BuildStatus(AliMUONPadStatusMaker::kMissing,0,0,AliMUONPadStatusMaker::kMissing) )
235 if (ntotal!=NTOTALNUMBEROFPADS)
237 cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d",
238 ntotal,runNumber) << endl;
241 AliCDBManager::Instance()->ClearCache();
246 //______________________________________________________________________________
247 void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized)
251 TGraph* g = static_cast<TGraph*>(f->Get(gname));
257 g = static_cast<TGraph*>(g->Clone());
258 for ( Int_t i = 0; i < g->GetN(); ++i )
260 Double_t y = g->GetY()[i];
261 g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS);
266 g->GetXaxis()->SetNdivisions(505);
267 g->GetXaxis()->SetNoExponent();
269 if (l) l->AddEntry(g,gname,"LP");
272 //______________________________________________________________________________
273 void DrawPeriod(double run1, double run2, double ymin, double ymax, const char* label)
275 TBox* b = new TBox(run1,ymin,run2,ymax);
278 TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
279 text->SetTextSize(0.05);
283 //______________________________________________________________________________
284 void DrawEvolution(const char* file, bool normalized=true)
287 TFile* f = TFile::Open(file);
291 TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
298 TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
300 TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
303 int runmin = TMath::Nint(g->GetX()[0]);
304 int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
308 TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
310 gStyle->SetOptStat(kFALSE);
312 h->GetXaxis()->SetNoExponent();
313 h->GetXaxis()->SetNdivisions(505);
315 gStyle->SetOptTitle(kFALSE);
317 DrawPeriod(115881,117222,0,ymax,"10b");
319 DrawPeriod(119159,120824,0,ymax,"10c");
321 DrawPeriod(122374,126424,0,ymax,"10d");
323 DrawPeriod(127724,130850,0,ymax,"10e");
325 DrawPeriod(133005,134929,0,ymax,"10f");
327 DrawPeriod(135658,136376,0,ymax,"10g");
329 DrawPeriod(137133,139513,0,ymax,"10h");
331 DrawPeriod(143856,146860,0,ymax,"11a");
333 DrawPeriod(148370,150702,0,ymax,"11b");
335 DrawPeriod(151566,154583,0,ymax,"11c");
337 DrawPeriod(158084,159606,0,ymax,"11d");
339 DrawPeriod(160677,162000,0,ymax,"11e");
341 Draw(f,"nbad",l,normalized);
342 Draw(f,"nbadped",l,normalized);
343 Draw(f,"nbadocc",l,normalized);
344 Draw(f,"nbadhv",l,normalized);
345 Draw(f,"nmissing",l,normalized);
346 Draw(f,"nreco",l,normalized);
355 //______________________________________________________________________________
356 void MUONStatusMapEvolution(const char* runlist, const char* outfile)
358 // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy
359 // or missing in configuration)
361 // output a root file with the different graphs.
363 // output can be then plotted using the DrawEvolution function
365 // Note that the output of different runlists can then be merged simply using
366 // the hadd program, and so then the DrawEvolution can be used over
367 // a huge period, e.g. a full year, while this method is better restricted
368 // to a period or even less (depending on your success of accessing the OCDB)
371 std::vector<int> runs;
373 ReadIntegers(runlist,runs);
377 cout << "No runs to process..." << endl;
383 if ( runs[0] <= 139699 ) year=2010;
385 AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year));
389 glist.SetOwner(kTRUE);
391 TGraph* gnbad = new TGraph(runs.size());
392 gnbad->SetName("nbad");
395 TGraph* gnbadped = new TGraph(runs.size());
396 gnbadped->SetName("nbadped");
399 TGraph* gnbadocc = new TGraph(runs.size());
400 gnbadocc->SetName("nbadocc");
403 TGraph* gnbadhv = new TGraph(runs.size());
404 gnbadhv->SetName("nbadhv");
407 TGraph* gnmissing = new TGraph(runs.size());
408 gnmissing->SetName("nmissing");
409 glist.Add(gnmissing);
411 TGraph* gnreco = new TGraph(runs.size());
412 gnreco->SetName("nreco");
415 for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i )
417 Int_t runNumber = runs[i];
425 Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco);
427 gnbad->SetPoint(i,runNumber,nbad);
428 gnbadped->SetPoint(i,runNumber,nbadped);
429 gnbadhv->SetPoint(i,runNumber,nbadhv);
430 gnbadocc->SetPoint(i,runNumber,nbadocc);
431 gnmissing->SetPoint(i,runNumber,nmissing);
432 gnreco->SetPoint(i,runNumber,nreco);
439 TFile f(outfile,"recreate");
440 Int_t color[] = { 1 , 2 , 3 , 4, 6, 8 };
441 Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 };
443 while ( ( g = static_cast<TGraph*>(next() ) ) )
445 g->GetXaxis()->SetNdivisions(505);
446 g->GetXaxis()->SetNoExponent();
448 g->GetYaxis()->SetNoExponent();
449 g->SetLineColor(color[index]);
450 g->SetMarkerStyle(marker[index]);
451 g->SetMarkerColor(color[index]);
452 g->SetMarkerSize(1.0);