AliRoot Core  edcc906 (edcc906)
AliMUONTrackerHV.cxx
Go to the documentation of this file.
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 #include "AliMUONTrackerHV.h"
19 
20 #include <algorithm>
21 #include <map>
22 #include <set>
23 
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"
38 #include "AliMUONTrackerData.h"
40 #include "AliLog.h"
41 
42 #include "TCanvas.h"
43 #include "TGraph.h"
44 #include "TH2.h"
45 #include "TLine.h"
46 #include "TMap.h"
47 #include "TMultiGraph.h"
48 #include "TObjArray.h"
49 #include "TObjString.h"
50 #include "TStyle.h"
51 #include "Riostream.h"
52 
53 //
54 // Class to inspect the MUON TRACKER HV values
55 //
56 // With this class you can :
57 //
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)
62 //
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.
69 //
70 
72 ClassImp(AliMUONTrackerHV)
74 
75 //______________________________________________________________________________
76 AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath)
77  : AliMUONTrackerVoltages(runlist,ocdbPath)
78 {
79  // ctor from a runlist (txt file)
80  fOCDBObjectPath = "MUON/Calib/HV";
81 }
82 
83 //______________________________________________________________________________
84 AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath)
85 : AliMUONTrackerVoltages(runNumber,ocdbPath)
86 {
87  // ctor for a single run
88  fOCDBObjectPath = "MUON/Calib/HV";
89 }
90 
91 //______________________________________________________________________________
93 {
94  // dtor
95 }
96 
97 //______________________________________________________________________________
98 TMap*
99 AliMUONTrackerHV::CreateMap(Int_t runNumber, Bool_t patched) const
100 {
101  if (!patched) {
102  return AliMUONTrackerVoltages::CreateMap(runNumber,kFALSE);
103  }
104 
105  return AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,0x0,kTRUE);
106 }
107 
108 //______________________________________________________________________________
109 void
111 {
117 
118  if ( fRunList.empty() )
119  {
120  AliError("No runs to process...");
121  return;
122  }
123 
125 
126  for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
127  {
128  AliMUONCDB::CheckHV(fRunList[i],verbose);
129  }
130 }
131 
132 //______________________________________________________________________________
133 void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName)
134 {
140 
141  gStyle->SetOptStat(0);
142 
143  char line[1024];
144 
145  std::ifstream in(logfile);
146  int run(-1),a,b,c,d,e,f,g,h,z,other;
147  std::map<int,std::string> results;
148 
149  std::string message;
150  const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at ";
151 
152  while ( in.getline(line,1023,'\n') )
153  {
154  TString sline(line);
155  if (sline.Contains("SUMMARY"))
156  {
157  AliInfo(line);
158  int r;
159  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)",
160  &r,&a,&b,&c,&d,&e,&f,&g,&h,&z,&other);
161  if ( r != run )
162  {
163  if ( run == -1 )
164  {
168  }
169 
170  if ( run > 0 )
171  {
172  results.insert(std::make_pair(run,message));
173 
174  }
175  message = "";
176  run = r;
177  }
178  }
179  else if ( sline.Contains(testProblem) )
180  {
181  message += "|";
182  message += sline(strlen(testProblem),sline.Length()-1).Data();
183  }
184  }
185 
186  results.insert(std::make_pair(run,message));
187 
188  TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1);
189 
190  std::map<int,std::string>::const_iterator it;
191 
192  for ( it = results.begin(); it != results.end(); ++it )
193  {
194  AliInfo(Form("%d -> %s",it->first,it->second.c_str()));
195  TObjArray* split = TString(it->second.c_str()).Tokenize("|");
196  TIter next(split);
197  TObjString* str;
198  while ( ( str = static_cast<TObjString*>(next()) ) )
199  {
200  TString s(str->String());
201  TObjArray* parts = s.Tokenize(":");
202  TString alias = (static_cast<TObjString*>(parts->At(0)))->String();
203  TString channel = DCSNamer()->DCSNameFromAlias(alias.Data());
204  channel += Form("(%4d)",DCSNamer()->DetElemIdFromDCSAlias(alias.Data()));
205  channel.ReplaceAll(".actual.vMon","");
206  hvoff->Fill(Form("%6d",it->first),channel.Data(),1.0);
207  delete parts;
208  }
209  delete split;
210  }
211 
212  hvoff->LabelsDeflate("x");
213  hvoff->LabelsDeflate("y");
214  hvoff->LabelsOption("x","<");
215  hvoff->LabelsOption("y","<");
216 
217  TCanvas* c1 = new TCanvas;
218  c1->SetLeftMargin(0.35);
219  hvoff->Draw("text");
220  c1->Print(Form("%s.pdf",outputBaseName));
221  TCanvas* c2 = new TCanvas;
222  TH1* hx = hvoff->ProjectionX("hvoffperrun");
223  hx->Draw();
224  c2->Print(Form("%s-perrun.pdf",outputBaseName));
225  TCanvas* c3 = new TCanvas;
226  c3->SetBottomMargin(0.55);
227  TH1* perchannel = hvoff->ProjectionY("hvoffperchannel");
228  perchannel->GetXaxis()->SetBit(TAxis::kLabelsVert);
229  perchannel->GetXaxis()->LabelsOption(">");
230  perchannel->Draw("texthist");
231  c3->Print(Form("%s-perchannel.pdf",outputBaseName));
232 }
233 
234 //______________________________________________________________________________
235 void
236 AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch, Bool_t plotIntermediate)
237 {
240 
242  TList messages;
243  messages.SetOwner(kTRUE);
244  TObjArray graphs;
245 
246  for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
247  {
248  Int_t runNumber = fRunList[i];
249 
250  messages.Delete();
251 
252  AliCDBManager::Instance()->SetRun(runNumber);
253 
254  TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages,kTRUE);
255 
256  TMultiGraph* mg = Map2Graph(m,dcsname);
257 
258  if ( !mg ) continue;
259 
260  graphs.Add(mg);
261 
262  TString cname(Form("MCH_HV_RUN%09d",runNumber));
263 
264  if ( strlen(dcsname) > 0 )
265  {
266  TString s(dcsname);
267  s.ReplaceAll("/","_");
268  cname += Form("_dcsname_%s",s.Data());
269  }
270 
271  AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
272 
273  TLine* startRunLine(0);
274  TLine* endRunLine(0);
275  time_t start(0);
276  time_t end(0);
277 
278  if ( e )
279  {
280  AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
281  if (grp)
282  {
283  start = grp->GetTimeStart();
284  end = grp->GetTimeEnd();
285  }
286  }
287 
288  if ( start && end )
289  {
290  TGraph* g = new TGraph(2);
291  g->SetName("runBoundaries");
292  g->SetTitle("run boundaries");
293  g->SetPoint(0,start,0);
294  g->SetPoint(1,end,0);
295  mg->Add(g,"");
296  }
297 
298  if ( plotIntermediate )
299  {
300  TCanvas* c = new TCanvas(cname.Data(),cname.Data());
301 
302  c->Draw();
303 
304  mg->SetTitle(cname.Data());
305 
306  mg->Draw("AL");
307 
308  TimeAxis(mg);
309 
310  if ( start )
311  {
312  startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
313  startRunLine->SetLineColor(2);
314  startRunLine->SetLineWidth(4);
315  }
316  if ( end )
317  {
318  endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
319  endRunLine->SetLineColor(2);
320  endRunLine->SetLineWidth(4);
321  }
322 
323  if ( startRunLine ) startRunLine->Draw();
324  if ( endRunLine ) endRunLine->Draw();
325 
326  c->SaveAs(Form("%s.pdf",cname.Data()));
327  }
328  }
329 
330  new TCanvas;
331 
332  TMultiGraph* g = CombineMulti(graphs);
333 
334  TIter next(g->GetListOfGraphs());
335  TGraph* gi;
336 
337  while ( ( gi = static_cast<TGraph*>(next())))
338  {
339  gi->SetMarkerStyle(kPlus);
340  }
341  g->Draw("alp");
342  TimeAxis(g);
343 }
344 
345 //______________________________________________________________________________
346 void
347 AliMUONTrackerHV::ReportTrips(Bool_t includeLowOnes)
348 {
351 
353 
354  TList messages;
355  messages.SetOwner(kTRUE);
356  TObjString* msg(0);
357 
358  std::map<std::string,int> channels;
359 
360  for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
361  {
362  Int_t runNumber = fRunList[i];
363 
364  AliInfo("---------------------");
365 
366  Int_t ntrips(0);
367 
368  messages.Delete();
369 
370  AliCDBManager::Instance()->SetRun(runNumber);
371 
372  AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages,kTRUE);
373 
374  if (!AliMpDEStore::Instance(false))
375  {
377  }
378 
379  TIter next(&messages);
380 
381  while ( ( msg = static_cast<TObjString*>(next())) )
382  {
383  if ( msg->String().Contains("TRIP") && ( includeLowOnes || !msg->String().Contains("LOWTRIP") ) )
384  {
385  ++ntrips;
386  }
387  }
388 
389  AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' ')));
390 
391  next.Reset();
392  std::map<int,std::string> report;
393 
394  while ( ( msg = static_cast<TObjString*>(next())) )
395  {
396  if ( msg->String().Contains("TRIP") )
397  {
398  TObjArray* parts = msg->String().Tokenize(" ");
399  TString channelName(static_cast<TObjString*>(parts->At(0))->String());
400 
401  for ( Int_t ip = 0; ip <= parts->GetLast(); ++ip)
402  {
403  TString p(static_cast<TObjString*>(parts->At(ip))->String());
404 
405  if ( p.Contains("TRIP") )
406  {
407  if ( includeLowOnes || !p.Contains("LOWTRIP") )
408  {
409  TString ts(static_cast<TObjString*>(parts->At(ip+2))->String());
410 
411  ip += 3;
412 
413  Int_t index = ts.Index("TS:");
414 
415  UInt_t timeStamp = TString(ts(index+strlen("TS:"),ts.Length()-index)).Atoi();
416 
417  TString tmp(msg->String());
418  tmp.ReplaceAll(channelName.Data(),DCSNamer()->DCSNameFromAlias(channelName.Data()));
419  report[timeStamp] = tmp.Data();
420  channels[channelName.Data()]++;
421  }
422  }
423  }
424  delete parts;
425  }
426  }
427 
428  for ( std::map<int,std::string>::const_iterator it = report.begin(); it != report.end(); ++it )
429  {
430  AliInfo(Form("%s %s",TTimeStamp(it->first).AsString("s"),it->second.c_str()));
431  }
432  }
433 
434  AliInfo("--------------------------------------------------------------------");
435  AliInfo("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
436 
437  int totalTrips(0);
438  AliMUON2DMap tripMap(kTRUE);
439  Int_t nofChannels(AliMpConstants::ManuNofChannels());
440 
441  for ( std::map<std::string,int>::const_iterator it = channels.begin(); it != channels.end(); ++it )
442  {
443  AliInfo(Form("%40s %3d",DCSNamer()->DCSNameFromAlias(it->first.c_str()).Data(),it->second));
444  totalTrips += it->second;
445 
446  Int_t detElemId = DCSNamer()->DetElemIdFromDCSAlias(it->first.c_str());
447 
449 
450  // build the list of manuIds for this channel
451  AliMpArrayI manuArray;
452 
453  manuArray.SetSize(300);
454 
455  Int_t index = DCSNamer()->DCSIndexFromDCSAlias(it->first.c_str());
456  Int_t firstIndex(index);
457  Int_t lastIndex(index);
458 
459  if ( index < 0 )
460  {
461  // it's a slat, must loop over PCBs
462  firstIndex = 0;
463  lastIndex = DCSNamer()->NumberOfPCBs(detElemId)-1;
464  }
465 
466  for ( int i = firstIndex; i <= lastIndex ; ++i )
467  {
468  const AliMpArrayI* ma = de->ManusForHV(i);
469  if (!ma)
470  {
471  AliError(Form("Could not get ma for de %d index %d",detElemId,i));
472  continue;
473  }
474  for ( int j = 0; j < ma->GetSize(); ++j )
475  {
476  manuArray.Add(ma->GetValue(j),kFALSE);
477  }
478  }
479 
480  for ( Int_t iManu = 0; iManu < manuArray.GetSize(); ++iManu )
481  {
482  Int_t manuId = manuArray.GetValue(iManu);
483 
484  AliMUONVCalibParam* tripRate = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
485 
486  tripMap.Add(tripRate);
487 
488  for ( Int_t j = 0 ; j < nofChannels; ++j )
489  {
490  tripRate->SetValueAsDouble(j,0,it->second*1.0);
491  }
492  }
493  }
494 
495  AliInfo("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
496  AliInfo(Form("Total of %3d trips for %4ld runs",totalTrips,fRunList.size()));
497 
498  AliMUONTrackerData* data = new AliMUONTrackerData("tripcount","Number of trips",1);
499  data->Add(tripMap);
500  data->SetDimensionName(0,"ntrips");
501 
503 
505 
506 }
507 
508 //______________________________________________________________________________
509 Int_t AliMUONTrackerHV::CompareMaps(const TMap& hv1, const TMap& hv2, Bool_t verbose) const
510 {
513 
514  Int_t ndiff(0);
515  TIter next(&hv1);
516  TObjString* hvChannelName;
517 
518  while ( ( hvChannelName = static_cast<TObjString*>(next()) ) )
519  {
520  TString name(hvChannelName->String());
521 
522  if ( name.Contains("sw") ) continue; // skip switches for the moment
523  if ( name.Contains("iMon") ) continue; // skip HV currents for the moment
524 
525  Bool_t st1Check(kFALSE);
526 
527  if ( name.Contains("Chamber00Left") )
528  {
529  if (name.Contains("Quad1Sect0")) st1Check=kTRUE;
530  if (name.Contains("Quad1Sect1")) st1Check=kTRUE;
531  if (name.Contains("Quad1Sect2")) st1Check=kTRUE;
532  if (name.Contains("Quad2Sect2")) st1Check=kTRUE;
533  if (name.Contains("Quad2Sect1")) st1Check=kTRUE;
534  if (name.Contains("Quad2Sect0")) st1Check=kTRUE;
535  }
536  else if ( name.Contains("Chamber01Left"))
537  {
538  if (name.Contains("Quad2Sect2")) st1Check=kTRUE;
539  if (name.Contains("Quad2Sect0")) st1Check=kTRUE;
540  }
541 
542  TPair* hvPair1 = static_cast<TPair*>(hv1.FindObject(name.Data()));
543  TObjArray* values1 = static_cast<TObjArray*>(hvPair1->Value());
544 
545  TPair* hvPair2 = static_cast<TPair*>(hv2.FindObject(name.Data()));
546  TObjArray* values2 = static_cast<TObjArray*>(hvPair2->Value());
547 
548  Bool_t same(kTRUE);
549 
550  if ( values1->GetEntries() != values2->GetEntries() )
551  {
552  same = kFALSE;
553  }
554  else
555  {
556  Int_t n = values1->GetEntries();
557  for ( Int_t i = 0; i < n && same == kTRUE; ++i )
558  {
559  AliDCSValue* v1 = dynamic_cast<AliDCSValue*>(values1->At(i));
560  AliDCSValue* v2 = dynamic_cast<AliDCSValue*>(values2->At(i));
561 
562  if ( v1->Compare(v2) != 0 || v1->GetType() != v2->GetType() || !IsAlmostEqualRelative(v1->GetFloat(),v2->GetFloat() ))
563  {
564  same = kFALSE;
565  }
566  }
567  }
568 
569  if (!same)
570  {
571  ++ndiff;
572  }
573 
574  if ( verbose && !same && st1Check )
575  {
576  std::cout << name << std::endl;
577  values1->Print();
578  values2->Print();
579  }
580  }
581 
582  return ndiff;
583 }
TBrowser b
Definition: RunAnaESD.C:12
Implementation of AliMUONVTrackerData.
void Plot(const char *dcsname=0x0, Bool_t withPatch=kFALSE, Bool_t plotIntermediate=kFALSE)
time_t GetTimeStart() const
Definition: AliGRPObject.h:55
static AliMpDEStore * Instance(Bool_t warn=true)
TStyle * gStyle
Int_t GetSize() const
AliMUONTrackerHV(const char *runlist, const char *ocdbPath="raw://")
#define TObjArray
void HVoff(const char *logfile="lhc11de.log", const char *outputBaseName="hvoff")
Producer of some AliMUONVTrackerData.
Float_t p[]
Definition: kNNTest.C:133
strP3 Tokenize("+") -> Print()
Bool_t Add(Int_t value, Bool_t warn=kTRUE)
Definition: AliMpArrayI.cxx:97
virtual void SetDimensionName(Int_t index, const char *value)
Set the name of a given dimension.
Int_t NumberOfPCBs(Int_t detElemId) const
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
Int_t CompareMaps(const TMap &hv1, const TMap &hv2, Bool_t verbose=kFALSE) const
Bool_t LoadMapping(Bool_t segmentationOnly)
Definition: AliMUONCDB.cxx:502
The class defines the electronics properties of detection element.
void CheckHV(Int_t runNumber, Int_t verbose)
Definition: AliMUONCDB.cxx:217
Float_t GetFloat() const
TMap * CreateMap(Int_t runNumber, Bool_t patched) const
AliMpDCSNamer * DCSNamer() const
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
TMap * CreateMap(Int_t runNumber, Bool_t patched=kFALSE) const
void Register(AliMUONVTrackerDataMaker *reader)
static AliMUONPainterDataRegistry * Instance()
Container of calibration values for a given number of channels.
TString DCSNameFromAlias(const char *dcsAlias) const
static Int_t ManuNofChannels()
Max number of channels per manu.
#define AliInfo(message)
Definition: AliLog.h:484
void ReportTrips(Bool_t includeLowOnes=kFALSE)
TMultiGraph * Map2Graph(TMap *m, const char *dcsname)
Implementation of AliMUONVCalibParam for tuples of double.
void SetSize(Int_t size)
Int_t DCSIndexFromDCSAlias(const char *dcsAlias) const
Int_t Compare(const TObject *obj) const
Definition: AliDCSValue.h:66
TMultiGraph * CombineMulti(TObjArray &graphs)
void SetRun(Int_t run)
Helper class for sorted integer array.
Definition: AliMpArrayI.h:21
time_t GetTimeEnd() const
Definition: AliGRPObject.h:56
Definition: AliCDBEntry.h:18
Bool_t Add(const AliMUONTrackerData &data)
TF1 * f
Definition: interpolTest.C:21
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
void SetDefaultStorage(const char *dbString)
Simple wrapper of AliMUONVTrackerData (for backward compatibility)
virtual Bool_t Add(TObject *object)
Add an object to the store.
TArrayI runlist(10000)
Int_t grp(UInt_t run, TString &gdc)
Definition: onlineReco.C:70
virtual ~AliMUONTrackerHV()
static Int_t runNumber
Definition: pdc06_config.C:126
bool IsAlmostEqualRelative(float A, float B, float maxRelDiff=FLT_EPSILON) const
static TMap * CreateHV(Int_t runNumber, Int_t *startOfValidity=0, Bool_t patched=kTRUE, TList *messages=0x0, Bool_t dryRun=kFALSE)
Create a hv map (which must be deleted) from OCDB for the given run.
const AliMpArrayI * ManusForHV(Int_t hvIndex) const
#define AliError(message)
Definition: AliLog.h:591
Int_t GetValue(Int_t index) const
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
Int_t DetElemIdFromDCSAlias(const char *dcsAlias) const
void Scan(Int_t verbose=0)
void Print(Option_t *) const
Type GetType() const
Definition: AliDCSValue.h:53
virtual void SetValueAsDouble(Int_t i, Int_t j, Double_t value)