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 **************************************************************************/
18 #include "AliMUONTrackerHV.h"
24 #include "AliCDBManager.h"
25 #include "AliCDBEntry.h"
26 #include "AliDCSValue.h"
27 #include "AliGRPObject.h"
28 #include "AliMpArrayI.h"
29 #include "AliMpConstants.h"
30 #include "AliMpDCSNamer.h"
31 #include "AliMpDEStore.h"
32 #include "AliMpDetElement.h"
33 #include "AliMUON2DMap.h"
34 #include "AliMUONCalibParamND.h"
35 #include "AliMUONCalibrationData.h"
36 #include "AliMUONCDB.h"
37 #include "AliMUONPainterDataRegistry.h"
38 #include "AliMUONTrackerData.h"
39 #include "AliMUONTrackerDataWrapper.h"
47 #include "TMultiGraph.h"
48 #include "TObjArray.h"
49 #include "TObjString.h"
51 #include "Riostream.h"
54 // Class to inspect the MUON TRACKER HV values
56 // With this class you can :
58 // a) get a list of trips (method ReportTrips)
59 // b) print the values for some (or all) HV channels (method Print)
60 // c) plot the values for some (or all) HV channels (method Plot)
61 // d) get a list of HV channels that are "OFF" (methods Scan and HVoff)
63 // Note that in this class, all the output (either text or canvas) or the
64 // channel *names* used are the same as in the DCS UI at Pt2
65 // Specifically the chamber ids start at 1, the slat numbers at 1 and
66 // the quad and sect number at 1 also. And not at zero like for the
67 // DCS *aliases*. On the contraty, the internal map, coming from the OCDB,
68 // only contains aliases, not names. Confusing ? It is.
71 ClassImp(AliMUONTrackerHV)
73 //______________________________________________________________________________
74 AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath)
75 : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
77 // ctor from a runlist (txt file)
81 //______________________________________________________________________________
82 AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath)
83 : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
85 // ctor for a single run
86 SetRunList(runNumber);
89 //______________________________________________________________________________
90 AliMUONTrackerHV::~AliMUONTrackerHV()
96 //____________________________________________________________________________
97 TMultiGraph* AliMUONTrackerHV::CombineMulti(TObjArray& graphs)
99 // combine multigraphs
101 TMultiGraph* rv = new TMultiGraph;
105 TMultiGraph* ref = static_cast<TMultiGraph*>(next());
107 Int_t dref = ref->GetListOfGraphs()->GetEntries();
109 while ( ( mg = static_cast<TMultiGraph*>(next())) )
111 TList* list = mg->GetListOfGraphs();
112 Int_t d1 = list->GetEntries();
116 AliError(Form("%d vs %d",d1,dref));
121 for ( Int_t i = 0; i < dref; ++i )
125 while ( ( mg = static_cast<TMultiGraph*>(next())) )
127 graph.Add(mg->GetListOfGraphs()->At(i));
128 TGraph* g = Combine(graph);
135 //____________________________________________________________________________
136 TGraph* AliMUONTrackerHV::Combine(TObjArray& graphs)
138 // make one graph out of several
139 // x axis is supposed to be time and will end up ordered in the
142 std::map<int, std::vector<double> > values;
143 std::map<int, std::vector<double> >::const_iterator it;
148 while ( ( g = static_cast<TGraph*>(next())) )
150 for ( Int_t i = 0; i < g->GetN(); ++i )
152 std::vector<double> pair;
154 pair.push_back(g->GetX()[i]);
155 pair.push_back(g->GetY()[i]);
157 values.insert( std::make_pair(g->GetX()[i],pair));
165 std::vector<double> vx;
166 std::vector<double> vy;
168 for ( it = values.begin(); it != values.end(); ++it )
170 const std::vector<double>& q = it->second;
176 rv = new TGraph(values.size(),&vx[0],&vy[0]);
177 rv->GetXaxis()->SetNoExponent();
179 g = static_cast<TGraph*>(graphs.At(0));
181 rv->SetName(g->GetName());
182 rv->SetTitle(g->GetTitle());
188 //______________________________________________________________________________
189 void AliMUONTrackerHV::ReadIntegers(const char* filename, std::vector<int>& integers)
191 /// Read integers from filename, where integers are either
192 /// separated by "," or by return carriage
193 std::ifstream in(gSystem->ExpandPathName(filename));
196 std::set<int> runset;
200 in.getline(line,10000,'\n');
204 if (sline.Contains(","))
206 TObjArray* a = sline.Tokenize(",");
209 while ( ( s = static_cast<TObjString*>(next()) ) )
211 runset.insert(s->String().Atoi());
217 runset.insert(sline.Atoi());
225 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
227 integers.push_back((*it));
230 std::sort(integers.begin(),integers.end());
233 //______________________________________________________________________________
235 AliMUONTrackerHV::DCSNamer() const
237 // return the dcs namer
240 if (!AliMpDEStore::Instance(false))
242 AliMUONCDB::LoadMapping();
244 fDCSNamer = new AliMpDCSNamer("TRACKER");
249 //______________________________________________________________________________
250 void AliMUONTrackerHV::SetRunList(Int_t runNumber)
252 // Make the runlist be a single run
254 fRunList.push_back(runNumber);
257 //______________________________________________________________________________
259 AliMUONTrackerHV::SetRunList(const char* runlist)
261 // Read the runlist from an ASCII file or a comma separated list
262 // or a space separated list
266 if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
268 TObjArray* runs = 0x0;
269 if ( TString(runlist).Contains(",") )
271 runs = TString(runlist).Tokenize(",");
275 runs = TString(runlist).Tokenize(" ");
279 std::set<int> runset;
281 while ( ( s = static_cast<TObjString*>(next()) ) )
283 runset.insert(s->String().Atoi());
286 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
288 fRunList.push_back((*it));
291 std::sort(fRunList.begin(),fRunList.end());
297 ReadIntegers(runlist,fRunList);
302 //______________________________________________________________________________
304 AliMUONTrackerHV::GraphValues(TMap* m, const char* dcsname)
306 // make a graph of HV channels' voltage values for a given dcs name (name, not
309 if ( TString(dcsname).Contains("sw") )
311 // do not graph switches
318 TPair* p = static_cast<TPair*>(m->FindObject(DCSNamer()->DCSAliasFromName(dcsname).Data()));
322 TObjArray* a = static_cast<TObjArray*>(p->Value());
327 TGraph* g = new TGraph(a->GetEntries());
328 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
330 g->SetPoint(i,val->GetTimeStamp(),val->GetFloat());
337 //______________________________________________________________________________
339 AliMUONTrackerHV::Scan(Int_t verbose)
341 /// Retrieve HV values from OCDB for a given run list, and check whether
342 /// we have some issues with them...
343 /// If you pipe the results of this into a text file, you can then
344 /// feed it to the HVoff method for further investigations.
347 if ( fRunList.empty() )
349 AliError("No runs to process...");
353 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
355 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
357 AliMUONCDB::CheckHV(fRunList[i],verbose);
361 //______________________________________________________________________________
362 void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName)
364 /// Check the number of HV which have problem
365 /// the input is the output of e.g.
366 /// .L MUONTrackerHV.C+
367 /// ScanHV("lhc11de.list");> lhc11de.log
370 gStyle->SetOptStat(0);
374 std::ifstream in(logfile);
375 int run(-1),a,b,c,d,e,f,g,h,z,other;
376 std::map<int,std::string> results;
379 const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at ";
381 while ( in.getline(line,1023,'\n') )
384 if (sline.Contains("SUMMARY"))
388 sscanf(line,"I-AliMUONCDB::CheckHV::CheckHV: RUN %09d HVchannel SUMMARY : # of cases A(%3d) B(%3d) C(%3d) D(%3d) E(%3d) F(%3d) G(%3d) H(%3d) Z(%3d) OTHER(%3d)",
389 &r,&a,&b,&c,&d,&e,&f,&g,&h,&z,&other);
394 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
395 AliCDBManager::Instance()->SetRun(r);
396 AliMUONCDB::LoadMapping();
401 results.insert(std::make_pair(run,message));
408 else if ( sline.Contains(testProblem) )
411 message += sline(strlen(testProblem),sline.Length()-1).Data();
415 results.insert(std::make_pair(run,message));
417 TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1);
419 std::map<int,std::string>::const_iterator it;
421 for ( it = results.begin(); it != results.end(); ++it )
423 AliInfo(Form("%d -> %s",it->first,it->second.c_str()));
424 TObjArray* split = TString(it->second.c_str()).Tokenize("|");
427 while ( ( str = static_cast<TObjString*>(next()) ) )
429 TString s(str->String());
430 TObjArray* parts = s.Tokenize(":");
431 TString alias = (static_cast<TObjString*>(parts->At(0)))->String();
432 TString channel = DCSNamer()->DCSNameFromAlias(alias.Data());
433 channel += Form("(%4d)",DCSNamer()->DetElemIdFromDCSAlias(alias.Data()));
434 channel.ReplaceAll(".actual.vMon","");
435 hvoff->Fill(Form("%6d",it->first),channel.Data(),1.0);
441 hvoff->LabelsDeflate("x");
442 hvoff->LabelsDeflate("y");
443 hvoff->LabelsOption("x","<");
444 hvoff->LabelsOption("y","<");
446 TCanvas* c1 = new TCanvas;
447 c1->SetLeftMargin(0.35);
449 c1->Print(Form("%s.pdf",outputBaseName));
450 TCanvas* c2 = new TCanvas;
451 TH1* hx = hvoff->ProjectionX("hvoffperrun");
453 c2->Print(Form("%s-perrun.pdf",outputBaseName));
454 TCanvas* c3 = new TCanvas;
455 c3->SetBottomMargin(0.55);
456 TH1* perchannel = hvoff->ProjectionY("hvoffperchannel");
457 perchannel->GetXaxis()->SetBit(TAxis::kLabelsVert);
458 perchannel->GetXaxis()->LabelsOption(">");
459 perchannel->Draw("texthist");
460 c3->Print(Form("%s-perchannel.pdf",outputBaseName));
463 //______________________________________________________________________________
464 void AliMUONTrackerHV::TimeAxis(TMultiGraph* g)
466 g->GetXaxis()->SetTimeDisplay(1);
467 // g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
468 g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
469 g->GetXaxis()->SetTimeOffset(0,"gmt");
470 g->GetXaxis()->SetNdivisions(505);
473 //______________________________________________________________________________
475 AliMUONTrackerHV::GraphHV(TMap* m, const char* dcsname)
477 // Make a graph of the values matching dcsname
481 TMultiGraph* mg = new TMultiGraph;
483 while ( ( s = static_cast<TObjString*>(next()) ) )
485 TString name(DCSNamer()->DCSNameFromAlias(s->String()));
487 if ( dcsname && !name.Contains(dcsname)) continue;
489 TGraph* g = GraphValues(m,name);
493 g->SetMarkerSize(1.5);
494 g->SetMarkerStyle(2);
497 g->SetTitle(name.Data());
504 //______________________________________________________________________________
506 AliMUONTrackerHV::Print(Option_t* dcsname) const
508 /// Print HV values for a given dcs name (or all if dcsname=0)
510 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
512 messages.SetOwner(kTRUE);
514 for ( std::vector<int>::size_type iRun = 0; iRun < fRunList.size(); ++iRun )
516 Int_t runNumber = fRunList[iRun];
518 AliInfo("---------------------");
519 AliInfo(Form("RUN %09d",runNumber));
523 AliCDBManager::Instance()->SetRun(runNumber);
525 Bool_t patchValues(kFALSE);
526 Bool_t dryRun(kTRUE);
528 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,patchValues,&messages,dryRun);
533 while ( ( s = static_cast<TObjString*>(next()) ) )
535 TString name(DCSNamer()->DCSNameFromAlias(s->String()));
537 if ( dcsname && !name.Contains(dcsname)) continue;
539 TPair* p = static_cast<TPair*>(m->FindObject(s->String()));
543 TObjArray* a = static_cast<TObjArray*>(p->Value());
548 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
550 std::cout << Form("i=%5d ",i) << std::endl;
558 //______________________________________________________________________________
560 AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch, Bool_t plotIntermediate)
562 /// Show HV values for a given dcs name (or all if dcsname=0)
563 /// Each canvas for each run will go to a separate PDF file
565 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
567 messages.SetOwner(kTRUE);
570 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
572 Int_t runNumber = fRunList[i];
576 AliCDBManager::Instance()->SetRun(runNumber);
578 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages,kTRUE);
580 TMultiGraph* mg = GraphHV(m,dcsname);
586 TString cname(Form("MCH_HV_RUN%09d",runNumber));
588 if ( strlen(dcsname) > 0 )
591 s.ReplaceAll("/","_");
592 cname += Form("_dcsname_%s",s.Data());
595 AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
597 TLine* startRunLine(0);
598 TLine* endRunLine(0);
604 AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
607 start = grp->GetTimeStart();
608 end = grp->GetTimeEnd();
614 TGraph* g = new TGraph(1);
615 g->SetPoint(0,end,0);
619 if ( plotIntermediate )
621 TCanvas* c = new TCanvas(cname.Data(),cname.Data());
625 mg->SetTitle(cname.Data());
633 startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
634 startRunLine->SetLineColor(2);
635 startRunLine->SetLineWidth(4);
639 endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
640 endRunLine->SetLineColor(2);
641 endRunLine->SetLineWidth(4);
644 if ( startRunLine ) startRunLine->Draw();
645 if ( endRunLine ) endRunLine->Draw();
647 c->SaveAs(Form("%s.pdf",cname.Data()));
653 TMultiGraph* g = CombineMulti(graphs);
655 TIter next(g->GetListOfGraphs());
658 while ( ( gi = static_cast<TGraph*>(next())))
660 gi->SetMarkerStyle(kPlus);
666 //______________________________________________________________________________
668 AliMUONTrackerHV::ReportTrips(Bool_t includeLowOnes)
671 /// if includeLowOnes is kTRUE we'll report also the trips which starts from non-operational voltage values
673 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
676 messages.SetOwner(kTRUE);
679 std::map<std::string,int> channels;
681 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
683 Int_t runNumber = fRunList[i];
685 AliInfo("---------------------");
691 AliCDBManager::Instance()->SetRun(runNumber);
693 AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages,kTRUE);
695 if (!AliMpDEStore::Instance(false))
697 AliMUONCDB::LoadMapping();
700 TIter next(&messages);
702 while ( ( msg = static_cast<TObjString*>(next())) )
704 if ( msg->String().Contains("TRIP") && ( includeLowOnes || !msg->String().Contains("LOWTRIP") ) )
710 AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' ')));
713 std::map<int,std::string> report;
715 while ( ( msg = static_cast<TObjString*>(next())) )
717 if ( msg->String().Contains("TRIP") )
719 TObjArray* parts = msg->String().Tokenize(" ");
720 TString channelName(static_cast<TObjString*>(parts->At(0))->String());
722 for ( Int_t ip = 0; ip <= parts->GetLast(); ++ip)
724 TString p(static_cast<TObjString*>(parts->At(ip))->String());
726 if ( p.Contains("TRIP") )
728 if ( includeLowOnes || !p.Contains("LOWTRIP") )
730 TString ts(static_cast<TObjString*>(parts->At(ip+2))->String());
734 Int_t index = ts.Index("TS:");
736 UInt_t timeStamp = TString(ts(index+strlen("TS:"),ts.Length()-index)).Atoi();
738 TString tmp(msg->String());
739 tmp.ReplaceAll(channelName.Data(),DCSNamer()->DCSNameFromAlias(channelName.Data()));
740 report[timeStamp] = tmp.Data();
741 channels[channelName.Data()]++;
749 for ( std::map<int,std::string>::const_iterator it = report.begin(); it != report.end(); ++it )
751 AliInfo(Form("%s %s",TTimeStamp(it->first).AsString("s"),it->second.c_str()));
755 AliInfo("--------------------------------------------------------------------");
756 AliInfo("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
759 AliMUON2DMap tripMap(kTRUE);
760 Int_t nofChannels(AliMpConstants::ManuNofChannels());
762 for ( std::map<std::string,int>::const_iterator it = channels.begin(); it != channels.end(); ++it )
764 AliInfo(Form("%40s %3d",DCSNamer()->DCSNameFromAlias(it->first.c_str()).Data(),it->second));
765 totalTrips += it->second;
767 Int_t detElemId = DCSNamer()->DetElemIdFromDCSAlias(it->first.c_str());
769 AliMpDetElement* de = AliMpDEStore::Instance()->GetDetElement(detElemId);
771 // build the list of manuIds for this channel
772 AliMpArrayI manuArray;
774 manuArray.SetSize(300);
776 Int_t index = DCSNamer()->DCSIndexFromDCSAlias(it->first.c_str());
777 Int_t firstIndex(index);
778 Int_t lastIndex(index);
782 // it's a slat, must loop over PCBs
784 lastIndex = DCSNamer()->NumberOfPCBs(detElemId)-1;
787 for ( int i = firstIndex; i <= lastIndex ; ++i )
789 const AliMpArrayI* ma = de->ManusForHV(i);
792 AliError(Form("Could not get ma for de %d index %d",detElemId,i));
795 for ( int j = 0; j < ma->GetSize(); ++j )
797 manuArray.Add(ma->GetValue(j),kFALSE);
801 for ( Int_t iManu = 0; iManu < manuArray.GetSize(); ++iManu )
803 Int_t manuId = manuArray.GetValue(iManu);
805 AliMUONVCalibParam* tripRate = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
807 tripMap.Add(tripRate);
809 for ( Int_t j = 0 ; j < nofChannels; ++j )
811 tripRate->SetValueAsDouble(j,0,it->second*1.0);
816 AliInfo("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
817 AliInfo(Form("Total of %3d trips for %4ld runs",totalTrips,fRunList.size()));
819 AliMUONTrackerData* data = new AliMUONTrackerData("tripcount","Number of trips",1);
821 data->SetDimensionName(0,"ntrips");
823 AliMUONVTrackerDataMaker* dw = new AliMUONTrackerDataWrapper(data);
825 AliMUONPainterDataRegistry::Instance()->Register(dw);