AliRoot Core  edcc906 (edcc906)
MUONBusPatchEvolution.C
Go to the documentation of this file.
1 
27 #include "AliCDBEntry.h"
28 #include "AliCDBManager.h"
29 #include "AliDAQ.h"
30 #include "AliMergeableCollection.h"
31 #include "AliMpBusPatch.h"
32 #include "AliMpCDB.h"
33 #include "AliMpDDL.h"
34 #include "AliMpDEIterator.h"
35 #include "AliMpDEManager.h"
36 #include "AliMpDetElement.h"
38 #include "Riostream.h"
39 #include "TCanvas.h"
40 #include "TFile.h"
41 #include "TH1.h"
42 #include "TLegend.h"
43 #include "TLegendEntry.h"
44 #include "TStyle.h"
45 #include "TSystem.h"
46 #include <AliMpDDLStore.h>
47 #include <cassert>
48 #include <limits>
49 #include <map>
50 #include <set>
51 
52 //_________________________________________________________________________________________________
53 void AssertMapping(Int_t runNumber=0) {
54 
56 
57  if (!cdbm->IsDefaultStorageSet()) {
58  cdbm->SetDefaultStorage(
59  "local:///cvmfs/alice-ocdb.cern.ch/calibration/data/2015/OCDB");
60  }
61 
62  cdbm->SetRun(runNumber);
63 
65 }
66 
67 //_________________________________________________________________________________________________
68 AliMergeableCollection* BPEVO(Int_t runNumber, const char* output = "mchbepevo.complete.root")
69 {
71 
72 
73  if (!cdb->IsDefaultStorageSet()) {
74  cdb->SetDefaultStorage(
75  "local:///cvmfs/alice-ocdb.cern.ch/calibration/data/2015/OCDB");
76  }
77 
78  AssertMapping(runNumber);
79 
80  AliCDBEntry* e = cdb->Get("MUON/Calib/BPEVO");
81 
82  AliMergeableCollection* hc = static_cast<AliMergeableCollection*>(e->GetObject()->Clone());
83 
84  if (!hc) return 0x0;
85 
86  AliMUONBusPatchEvolution bpe(*hc);
87 
88  bpe.Augment();
89 
90  if (output)
91  {
92  TFile* fout = TFile::Open(gSystem->ExpandPathName(output), "RECREATE");
93  hc->Write("bpevo");
94  delete fout;
95  }
96 
97  return hc;
98 }
99 
100 //_________________________________________________________________________________________________
101 AliMergeableCollection* BPEVO(const char* daoutput, const char* output = "mchbepevo.complete.root")
102 {
104 
105  TFile* f = TFile::Open(gSystem->ExpandPathName(daoutput));
106 
107  AliMergeableCollection* hc = static_cast<AliMergeableCollection*>(f->Get(
108  "bpevo"))->Clone();
109 
110  delete f;
111 
112  AliMUONBusPatchEvolution bpe(*hc);
113 
114  bpe.Augment();
115 
116  if (output)
117  {
118  TFile* fout = TFile::Open(gSystem->ExpandPathName(output), "RECREATE");
119  hc->Write("bpevo");
120  delete fout;
121  }
122 
123  return hc;
124 }
125 
126 //_________________________________________________________________________________________________
127 void MakeConfigFileForBPEVOda(const char* filename = "mchbpevo.conf") {
130 
131  std::ofstream out(gSystem->ExpandPathName(filename));
132 
133  AssertMapping();
134 
135  out << "# Histogram the hit counts in 10 and 60 seconds bins" << std::endl
136  << std::endl;
137  out << "+timeResolutions: 10s" << std::endl;
138  out << "+timeResolutions: 60s" << std::endl << std::endl;
139 
140  out << "# maxDuration set to 5 hours" << std::endl << std::endl;
141  out << "maxDuration: 18000" << std::endl << std::endl;
142 
143  out << "# number of events needed to take a decision" << std::endl
144  << std::endl;
145  out << "nofEventsRequiredForDecision: 1000" << std::endl << std::endl;
146 
147  out << "# occupancy threshold for alarm" << std::endl << std::endl;
148  out << "occupancyThreshold: 0.5" << std::endl << std::endl;
149 
150  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
151  AliMpBusPatch* bp;
152 
153  std::map<int, int> buspatches;
154 
155  while ((bp = static_cast<AliMpBusPatch*>(next()))) {
156  int npads(0);
157 
158  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
159 
161  detElemId);
162 
163  for (Int_t i = 0; i < bp->GetNofManus(); ++i) {
164  Int_t manuId = bp->GetManuId(i);
165 
166  npads += de->NofChannelsInManu(manuId);
167  }
168 
169  buspatches[bp->GetId()] = npads;
170  }
171 
172  std::map<int, int>::const_iterator it;
173  int total(0);
174 
175  out << "# +bp: buspatchId:nofPadsInThatBusPatch" << std::endl << std::endl;
176 
177  for (it = buspatches.begin(); it != buspatches.end(); ++it) {
178  total += it->second;
179  out << "+bp: " << it->first << ":" << it->second << std::endl;
180  }
181 
182  assert(total == 1064008);
183 }
184 
185 //_________________________________________________________________________________________________
186 void MakeConfigCodeForBPEVOda(const char* buspatchmapname = "buspatches") {
189 
190  AssertMapping();
191 
192  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
193  AliMpBusPatch* bp;
194 
195  int total(0);
196 
197  while ((bp = static_cast<AliMpBusPatch*>(next()))) {
198  int npads(0);
199 
200  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
201 
203  detElemId);
204 
205  for (Int_t i = 0; i < bp->GetNofManus(); ++i) {
206  Int_t manuId = bp->GetManuId(i);
207 
208  npads += de->NofChannelsInManu(manuId);
209  }
210 
211  std::cout << Form("%s[%d]=%d;", buspatchmapname, bp->GetId(), npads)
212  << std::endl;
213 
214  total += npads;
215  }
216  assert(total == 1064008);
217 }
218 
219 
220 //_________________________________________________________________________________________________
221 void plot(const std::vector<TH1*>& v, Double_t min, Double_t max, Double_t factor)
222 {
223  if ( !v.size() ) return;
224 
225  gStyle->SetOptTitle(0);
226  gStyle->SetOptStat(0);
227 
228  if (!v[0]) return;
229 
230  TString title = v[0]->GetName();
231  title.ReplaceAll("RIGHT","");
232  title.ReplaceAll("LEFT","");
233 
234  TLegend* legend = new TLegend(0.8,0.1,0.99,0.90,title.Data());
235  legend->SetTextSize(0.08);
236  gPad->SetRightMargin(0.22);
237 
238  for ( std::vector<TH1*>::size_type i = 0; i < v.size(); ++i )
239  {
240  if (!v[i]) continue;
241 
242  TString tf = v[i]->GetXaxis()->GetTimeFormat();
243 
244  tf.ReplaceAll(":%s","");
245  v[i]->GetXaxis()->SetTimeFormat(tf.Data());
246 
247  v[i]->Scale(factor);
248  v[i]->SetMaximum(max);
249  v[i]->SetMinimum(min);
250  v[i]->GetYaxis()->SetLabelSize(0.10);
251  v[i]->GetXaxis()->SetLabelSize(0.10);
252  v[i]->GetYaxis()->SetRange(min,max);
253  Double_t integralError;
254  Double_t integral = v[i]->IntegralAndError(1,v[i]->GetNbinsX(),integralError);
255  integralError /= integral;
256  integral /= v[i]->GetNbinsX();
257  integralError *= integral;
258  TLegendEntry* entry = legend->AddEntry(v[i],Form("Mean %5.2g #pm %5.2g %%",integral,integralError));
259  entry->SetTextSize(0.04);
260  if (i)
261  {
262  v[i]->Draw("same");
263  }
264  else
265  {
266  v[i]->Draw();
267  }
268  }
269  legend->Draw();
270 
271 }
272 
273 //_________________________________________________________________________________________________
275  int timeResolution = 60) {
276 
277  TCanvas* c = new TCanvas("station", "station");
278  c->Divide(1, 5);
279 
280  for (int i = 1; i <= 5; ++i) {
281 
282  c->cd(i);
283 
284  std::vector<TH1*> v;
285 
286  v.push_back(hc.Histo(Form("/STATION/OCC/%ds/STATION%dRIGHT", timeResolution, i)));
287  v.push_back(hc.Histo(Form("/STATION/OCC/%ds/STATION%dLEFT", timeResolution, i)));
288  v.push_back(hc.Histo(Form("/STATION/OCC/%ds/STATION%d", timeResolution, i)));
289 
290  gPad->SetLogy();
291 
292 
293  plot(v,1E-2,10,100.0);
294 
295  }
296 }
297 
298 //_________________________________________________________________________________________________
300  int stationId = 3,
301  int timeResolution = 60) {
302 
303  TCanvas* c = new TCanvas("chamber", "chamber");
304 
305  c->Divide(1, 2);
306 
307  for (int i = 1; i <= 2; ++i) {
308 
309  c->cd(i);
310 
311  std::vector<TH1*> v;
312 
313  int chamberId = (stationId-1)*2 + i;
314 
315  v.push_back(hc.Histo(Form("/CHAMBER/OCC/%ds/CHAMBER%dRIGHT", timeResolution, chamberId)));
316  v.push_back(hc.Histo(Form("/CHAMBER/OCC/%ds/CHAMBER%dLEFT", timeResolution, chamberId)));
317  v.push_back(hc.Histo(Form("/CHAMBER/OCC/%ds/CHAMBER%d", timeResolution, chamberId)));
318 
319  gPad->SetLogy();
320 
321  plot(v,1E-2,10,100.0);
322  }
323 }
324 
325 //_________________________________________________________________________________________________
327  int timeResolution = 60) {
328 
329  TCanvas* c = new TCanvas("ddl", "ddl");
330 
331  c->Divide(4, 5);
332 
333  for ( int i = 1; i < 20; ++i ) {
334 
335  c->cd(i);
336 
337  std::vector<TH1*> v;
338 
339  v.push_back(hc.Histo(Form("/DDL/OCC/%ds/DDL%04d", timeResolution, 2560+i)));
340 
341  gPad->SetLogy();
342 
343  plot(v,1E-2,10,100.0);
344  }
345 }
346 
347 //_________________________________________________________________________________________________
349  int chamberId = 5,
350  int timeResolution = 60) {
351 
352  AssertMapping();
353 
354  TCanvas* c = new TCanvas("de", "de");
355 
356  c->Divide(5, 5);
357 
358  AliMpDEIterator it;
359 
360  it.First(chamberId-1);
361 
362  int i(1);
363 
364  while (!it.IsDone()) {
365 
366  c->cd(i);
367 
368  int detElemId = it.CurrentDEId();
369 
370  std::vector<TH1*> v;
371 
372  v.push_back(hc.Histo(Form("/DE/OCC/%ds/DE%04d", timeResolution, detElemId)));
373 
374  it.Next();
375 
376  gPad->SetLogy();
377 
378  plot(v,1E-2,10,100.0);
379 
380  ++i;
381  }
382 }
383 
384 //_________________________________________________________________________________________________
386  int ddlId = 2575,
387  int timeResolution = 60) {
388 
389  AssertMapping();
390 
391  TCanvas* c = new TCanvas("bp", "bp");
392 
393  AliMpDDL* ddl = AliMpDDLStore::Instance()->GetDDL(ddlId - AliDAQ::DdlIDOffset("MUONTRK"));
394 
395  int nbuspatches = ddl->GetNofBusPatches();
396 
397  c->DivideSquare(nbuspatches);
398 
399  for ( int i = 1; i < nbuspatches; ++i ) {
400 
401  c->cd(i);
402 
403  std::vector<TH1*> v;
404 
405  v.push_back(hc.Histo(Form("/BUSPATCH/OCC/%ds/BP%04d", timeResolution, ddl->GetBusPatchId(i))));
406 
407  gPad->SetLogy();
408 
409  plot(v,1E-1,100,100.0);
410  }
411 }
412 
Int_t GetNofManus() const
TFile * Open(const char *filename, Long64_t &nevents)
The iterator over detection elements.
TStyle * gStyle
void PlotDEOccupancies(AliMergeableCollection &hc, int chamberId=5, int timeResolution=60)
void MakeConfigFileForBPEVOda(const char *filename="mchbpevo.conf")
Bool_t IsDone() const
Int_t GetDEfromBus(Int_t busPatchId) const
TH1 * Histo(const char *fullIdentifier) const
Int_t CurrentDEId() const
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
Int_t GetManuId(Int_t index) const
The class defines the electronics properties of detection element.
The class defined electronics properties of DDL.
Definition: AliMpDDL.h:20
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
void PlotChamberOccupancies(AliMergeableCollection &hc, int stationId=3, int timeResolution=60)
static AliMpDDLStore * Instance(Bool_t warn=true)
TObject * GetObject()
Definition: AliCDBEntry.h:56
Int_t GetNofBusPatches() const
Definition: AliMpDDL.cxx:203
AliMpDDL * GetDDL(Int_t ddlId, Bool_t warn=true) const
AliMergeableCollection * BPEVO(Int_t runNumber, const char *output="mchbepevo.complete.root")
TFile * fout
Definition: PlotSys.C:39
Int_t GetId() const
Return the unique Id.
Definition: AliMpBusPatch.h:89
void PlotDDLOccupancies(AliMergeableCollection &hc, int timeResolution=60)
static Int_t DdlIDOffset(const char *detectorName)
Definition: AliDAQ.cxx:238
void PlotBusPatchOccupancies(AliMergeableCollection &hc, int ddlId=2575, int timeResolution=60)
void SetRun(Int_t run)
void plot(const std::vector< TH1 * > &v, Double_t min, Double_t max, Double_t factor)
Definition: AliCDBEntry.h:18
Int_t NofChannelsInManu(Int_t manuId) const
TF1 * f
Definition: interpolTest.C:21
void SetDefaultStorage(const char *dbString)
The class defines the properties of BusPatch.
Definition: AliMpBusPatch.h:21
void AssertMapping(Int_t runNumber=0)
static Int_t runNumber
Definition: pdc06_config.C:126
void MakeConfigCodeForBPEVOda(const char *buspatchmapname="buspatches")
Int_t GetBusPatchId(Int_t index) const
Definition: AliMpDDL.cxx:211
Utility class to massage the output of the MCHBPEVO DA.
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
Bool_t IsDefaultStorageSet() const
Definition: AliCDBManager.h:60
static Bool_t LoadAll(Bool_t warn=false)
Definition: AliMpCDB.cxx:196
void PlotStationOccupancies(AliMergeableCollection &hc, int timeResolution=60)