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 "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"
56 Int_t NTOTALNUMBEROFPADS(1064008);
59 //______________________________________________________________________________
60 void ReadIntegers(const char* filename, std::vector<int>& integers)
62 /// Read integers from filename, where integers are either
63 /// separated by "," or by return carriage
64 ifstream in(gSystem->ExpandPathName(filename));
69 in.getline(line,10000,'\n');
73 if (sline.Contains(","))
75 TObjArray* a = sline.Tokenize(",");
78 while ( ( s = static_cast<TObjString*>(next()) ) )
80 integers.push_back(s->String().Atoi());
85 integers.push_back(sline.Atoi());
89 integers.push_back(i);
93 std::sort(integers.begin(),integers.end());
97 //______________________________________________________________________________
98 void MUONStatusMap(AliMUONVStore*& vstatus,
99 AliMUONVStore*& vstatusMap,
100 const char* cdbStorage = "alien://folder=/alice/data/2011/OCDB",
101 Int_t runNumber=145292)
104 AliCDBManager::Instance()->SetDefaultStorage(cdbStorage);
105 AliCDBManager::Instance()->SetRun(runNumber);
107 AliMUONCDB::LoadMapping();
109 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
111 AliMUONCalibrationData cd(runNumber);
113 AliMUONPadStatusMaker statusMaker(cd);
115 statusMaker.SetLimits(*recoParam);
117 UInt_t mask = recoParam->PadGoodnessMask();
119 statusMaker.Report(mask);
121 vstatus = static_cast<AliMUONVStore*>(statusMaker.StatusStore()->Clone());
123 const Bool_t deferredInitialization = kFALSE;
125 AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization);
127 vstatusMap = static_cast<AliMUONVStore*>(statusMapMaker.StatusMap()->Clone());
130 //______________________________________________________________________________
131 Int_t GetBadChannels(Int_t runNumber,
140 if (!AliCDBManager::Instance()->IsDefaultStorageSet())
142 // AliCDBManager::Instance()->SetDefaultStorage("alien://folder=/alice/data/2011/OCDB?cacheFold=/local/cdb");
143 AliCDBManager::Instance()->SetDefaultStorage("raw://");
146 AliCDBManager::Instance()->SetRun(runNumber);
148 AliMpCDB::LoadDDLStore();
150 AliMUONCalibrationData cd(runNumber,true);
152 AliMUONPadStatusMaker statusMaker(cd);
154 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
156 statusMaker.SetLimits(*recoParam);
158 AliMpManuIterator it;
159 Int_t detElemId, manuId;
162 AliMUONPadStatusMaker::kPedMeanZero |
163 AliMUONPadStatusMaker::kPedMeanTooLow |
164 AliMUONPadStatusMaker::kPedMeanTooHigh |
165 AliMUONPadStatusMaker::kPedSigmaTooLow |
166 AliMUONPadStatusMaker::kPedSigmaTooHigh );
169 AliMUONPadStatusMaker::kHVError |
170 AliMUONPadStatusMaker::kHVTooLow |
171 AliMUONPadStatusMaker::kHVTooHigh |
172 AliMUONPadStatusMaker::kHVChannelOFF |
173 AliMUONPadStatusMaker::kHVSwitchOFF );
177 AliMUONPadStatusMaker::kManuOccupancyTooHigh
189 while ( it.Next(detElemId,manuId) )
191 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
193 if ( chamber >= 0 && AliMpDEManager::GetChamberId(detElemId) != chamber ) continue;
195 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
197 if ( de->IsConnectedChannel(manuId,manuChannel) )
201 UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel);
203 if (!status) continue;
207 if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) )
213 if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) )
219 if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) )
225 if ( status & recoParam->PadGoodnessMask() )
230 if ( status & AliMUONPadStatusMaker::BuildStatus(AliMUONPadStatusMaker::kMissing,0,0,AliMUONPadStatusMaker::kMissing) )
241 if ( chamber<0 && ntotal!=NTOTALNUMBEROFPADS)
243 cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d",
244 ntotal,runNumber) << endl;
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;
253 AliCDBManager::Instance()->ClearCache();
258 //______________________________________________________________________________
259 void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized)
263 TGraph* g = static_cast<TGraph*>(f->Get(gname));
269 g = static_cast<TGraph*>(g->Clone());
270 for ( Int_t i = 0; i < g->GetN(); ++i )
272 Double_t y = g->GetY()[i];
273 g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS);
278 g->GetXaxis()->SetNdivisions(505);
279 g->GetXaxis()->SetNoExponent();
281 if (l) l->AddEntry(g,gname,"LP");
284 //______________________________________________________________________________
285 void DrawPeriod(double run1, double run2, double ymin, double ymax, const char* label)
287 TBox* b = new TBox(run1,ymin,run2,ymax);
290 TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
291 text->SetTextAlign(22);
292 text->SetTextSize(0.02);
296 //______________________________________________________________________________
297 void DrawEvolution(const char* file, bool normalized=true)
300 TFile* f = TFile::Open(gSystem->ExpandPathName(file));
304 TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
311 TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
313 TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
316 int runmin = TMath::Nint(g->GetX()[0]);
317 int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
319 cout << Form("Run range found in file %s = %d - %d",file,runmin,runmax) << endl;
323 TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
325 gStyle->SetOptStat(kFALSE);
327 h->GetXaxis()->SetNoExponent();
328 h->GetXaxis()->SetNdivisions(505);
330 gStyle->SetOptTitle(kFALSE);
332 DrawPeriod(115881,117222,0,ymax,"10b");
334 DrawPeriod(119159,120824,0,ymax,"10c");
336 DrawPeriod(122374,126424,0,ymax,"10d");
338 DrawPeriod(127724,130850,0,ymax,"10e");
340 DrawPeriod(133005,134929,0,ymax,"10f");
342 DrawPeriod(135658,136376,0,ymax,"10g");
344 DrawPeriod(137133,139513,0,ymax,"10h");
346 DrawPeriod(143856,146860,0,ymax,"11a");
348 DrawPeriod(148370,150702,0,ymax,"11b");
350 DrawPeriod(151566,154583,0,ymax,"11c");
352 DrawPeriod(158084,159606,0,ymax,"11d");
354 DrawPeriod(160677,162717,0,ymax,"11e");
356 DrawPeriod(162933,165744,0,ymax,"11f");
358 DrawPeriod(167703,170593,0,ymax,"11h");
362 DrawPeriod(176661,177295,0,ymax,"12a");
364 DrawPeriod(177384,178053,0,ymax,"12b");
366 DrawPeriod(179603,180569,0,ymax,"12c");
368 DrawPeriod(183913,186320,0,ymax,"12d");
370 DrawPeriod(186365,186602,0,ymax,"12e");
372 DrawPeriod(186668,188123,0,ymax,"12f");
374 DrawPeriod(188362,188503,0,ymax,"12g");
376 DrawPeriod(189122,190110,0,ymax,"12h");
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");
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);
400 //______________________________________________________________________________
401 void MUONStatusMapEvolution(const char* runlist, const char* outfile)
403 // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy
404 // or missing in configuration)
406 // output a root file with the different graphs.
408 // output can be then plotted using the DrawEvolution function
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)
416 std::vector<int> runs;
418 ReadIntegers(runlist,runs);
422 cout << "No runs to process..." << endl;
428 if ( runs[0] <= 139699 ) year=2010;
430 if ( runs[0] <= 176000 ) year=2011;
432 if ( runs[0] <= 195344 ) year = 2012;
434 AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year));
436 // AliCDBManager::Instance()->SetDefaultStorage("local:///Users/laurent/Alice/OCDBcopy2013");
440 glist.SetOwner(kTRUE);
442 TGraph* gnbad = new TGraph(runs.size());
443 gnbad->SetName("nbad");
446 TGraph* gnbadped = new TGraph(runs.size());
447 gnbadped->SetName("nbadped");
450 TGraph* gnbadocc = new TGraph(runs.size());
451 gnbadocc->SetName("nbadocc");
454 TGraph* gnbadhv = new TGraph(runs.size());
455 gnbadhv->SetName("nbadhv");
458 TGraph* gnmissing = new TGraph(runs.size());
459 gnmissing->SetName("nmissing");
460 glist.Add(gnmissing);
462 TGraph* gnreco = new TGraph(runs.size());
463 gnreco->SetName("nreco");
466 for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i )
468 Int_t runNumber = runs[i];
476 Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco);
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);
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 };
494 while ( ( g = static_cast<TGraph*>(next() ) ) )
496 g->GetXaxis()->SetNdivisions(505);
497 g->GetXaxis()->SetNoExponent();
499 g->GetYaxis()->SetNoExponent();
500 g->SetLineColor(color[index]);
501 g->SetMarkerStyle(marker[index]);
502 g->SetMarkerColor(color[index]);
503 g->SetMarkerSize(1.0);