AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONTrackerData.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 "AliMUONTrackerData.h"
19 
20 #include "AliCodeTimer.h"
21 #include "AliDAQ.h"
22 #include "AliLog.h"
23 #include "AliMUON1DArray.h"
24 #include "AliMUON1DMap.h"
25 #include "AliMUON2DMap.h"
26 #include "AliMUONCalibParamND.h"
27 #include "AliMUONRejectList.h"
28 #include "AliMUONSparseHisto.h"
29 #include "AliMUONVStore.h"
30 #include "AliMpBusPatch.h"
31 #include "AliMpConstants.h"
32 #include "AliMpCDB.h"
33 #include "AliMpDDLStore.h"
34 #include "AliMpManuStore.h"
35 #include "AliMpDEIterator.h"
36 #include "AliMpDEManager.h"
37 #include "AliMpDetElement.h"
38 #include "AliMpDCSNamer.h"
39 #include "AliMpManuIterator.h"
40 #include "AliMpEncodePair.h"
41 #include "AliMpSegmentation.h"
42 #include <Riostream.h>
43 #include <TClass.h>
44 #include <TMath.h>
45 #include <TObjArray.h>
46 #include <TObjString.h>
47 #include <TString.h>
48 #include <TTimeStamp.h>
49 #include <TVector2.h>
50 #include <cassert>
51 #include <float.h>
52 
58 
59 using std::cout;
60 using std::endl;
64 
65 const Int_t AliMUONTrackerData::fgkExtraDimension = 2;
66 const Int_t AliMUONTrackerData::fgkVirtualExtraDimension = 1;
67 
68 namespace
69 {
70 
71 #define PRECISION 1E-12
72 
73  Double_t Difference(Double_t v1, Double_t v2)
74  {
75  Double_t d = v1-v2;
76  return TMath::Abs(d) < PRECISION ? 0.0 : d;
77  }
78 
79  Double_t AbsoluteDifference(Double_t v1, Double_t v2)
80  {
81  return TMath::Abs(Difference(v1,v2));
82  }
83 
84 
85  Double_t RelativeDifference(Double_t v1, Double_t v2)
86  {
87  if ( TMath::Abs(v1) < PRECISION ) return 0.0;
88  return (v1-v2)/v1;
89  }
90 
91  Double_t AbsoluteRelativeDifference(Double_t v1, Double_t v2)
92  {
93  return TMath::Abs(RelativeDifference(v1,v2));
94  }
95 }
96 
97 //_____________________________________________________________________________
98 AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
99  Int_t dimension,
100  Bool_t issingleevent)
101 : AliMUONVTrackerData(name,title),
102 fIsSingleEvent(issingleevent),
103 fChannelValues(0x0),
104 fManuValues(0x0),
105 fBusPatchValues(0x0),
106 fDEValues(0x0),
107 fChamberValues(0x0),
108 fPCBValues(0x0),
109 fDimension(External2Internal(dimension)+fgkExtraDimension),
110 fNevents(0),
111 fDimensionNames(new TObjArray(fDimension+fgkVirtualExtraDimension)),
112 fExternalDimensionNames(new TObjArray(dimension)),
113 fExternalDimension(dimension),
114 fHistogramming(new Int_t[fExternalDimension]),
115 fHistos(0x0),
116 fXmin(0.0),
117 fXmax(0.0),
118 fIsChannelLevelEnabled(kTRUE),
119 fIsManuLevelEnabled(kTRUE),
120 fIsBustPatchLevelEnabled(kTRUE),
121 fIsPCBLevelEnabled(kTRUE),
122 fNofDDLs(0),
123 fNofEventsPerDDL(0x0)
124 {
126  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
127  fExternalDimensionNames->SetOwner(kTRUE);
128  fDimensionNames->SetOwner(kTRUE);
129  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
130  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
131  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
132  Clear();
133 }
134 
135 //_____________________________________________________________________________
136 AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
137  const AliMUONVStore& manuValues)
138 : AliMUONVTrackerData(name,title),
139 fIsSingleEvent(kFALSE),
140 fChannelValues(0x0),
141 fManuValues(0x0),
142 fBusPatchValues(0x0),
143 fDEValues(0x0),
144 fChamberValues(0x0),
145 fPCBValues(0x0),
146 fDimension(0),
147 fNevents(0),
148 fDimensionNames(0x0),
149 fExternalDimensionNames(0x0),
150 fExternalDimension(0),
151 fHistogramming(0x0),
152 fHistos(0x0),
153 fXmin(0.0),
154 fXmax(0.0),
155 fIsChannelLevelEnabled(kFALSE),
156 fIsManuLevelEnabled(kTRUE),
157 fIsBustPatchLevelEnabled(kTRUE),
158 fIsPCBLevelEnabled(kTRUE),
159 fNofDDLs(0),
160 fNofEventsPerDDL(0x0)
161 {
165 
166  if (manuValues.GetSize()==0)
167  {
168  AliFatal("Cannot create a tracker data from nothing in that case !");
169  }
170 
171  if ( !AliMpDDLStore::Instance(kFALSE) && !AliMpManuStore::Instance(kFALSE) )
172  {
173  AliError("Cannot work without (full) mapping");
174  return;
175  }
176 
177  TIter next(manuValues.CreateIterator());
178  AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
179 
180  Int_t dimension = ( m->Dimension() - fgkExtraDimension - fgkVirtualExtraDimension ) / 2;
181 
183 
184  fDimensionNames = new TObjArray(fDimension+fgkVirtualExtraDimension);
185  fExternalDimensionNames = new TObjArray(dimension);
186  fExternalDimension = dimension;
187  fHistogramming = new Int_t[fExternalDimension];
188  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
189 
190  fExternalDimensionNames->SetOwner(kTRUE);
191  fDimensionNames->SetOwner(kTRUE);
192  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
193  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
194  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
195  Clear();
196  TArrayI nevents(AliDAQ::NumberOfDdls("MUONTRK"));
197  AssertStores();
198 
199  next.Reset();
200  AliMUONVCalibParam* external;
201 
202  while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
203  {
204  Int_t detElemId, manuId;
205 
206  GetDEManu(*external,detElemId,manuId);
207 
208  AliMUONVCalibParam* chamber(0x0);
209  AliMUONVCalibParam* de(0x0);
210  AliMUONVCalibParam* busPatch(0x0);
211  AliMUONVCalibParam* pcb(0x0);
212  AliMUONVCalibParam* manu(0x0);
213  AliMUONVCalibParam* channel(0x0);
214  AliMpDetElement* mpde(0x0);
215 
216  AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,detElemId,manuId,0);
217  // as external, but without event count
218  wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
219  wec->SetValueAsDouble(0,1,external->ValueAsDouble(0,1));
220  wec->SetValueAsDouble(0,2,external->ValueAsDouble(0,2));
221  wec->SetValueAsDouble(0,3,external->ValueAsDouble(0,3));
222 
223  Int_t mid = GetParts(wec,chamber,de,busPatch,pcb,manu,channel,mpde);
224 
225  if ( manuId != mid )
226  {
227  AliError(Form("Something is wrong for DE %5d : manuId = %d vs mid = %d",detElemId,manuId,mid));
228  continue;
229  }
230 
231  if ( manuId < 0 )
232  {
233  AliError("Got a < 0 manuId. Should not happen here !");
234  continue;
235  }
236 
237  assert(channel==0x0);
238 
239  Int_t n1 = manu->ValueAsInt(0,IndexOfNumberDimension());
240  Int_t n2 = external->ValueAsInt(0,IndexOfNumberDimension());
241  if ( n1 != n2 )
242  {
243  AliError(Form("Incoherent number of manu channels for DE %5d MANU %5d : %d vs %d",
244  detElemId,manuId,n1,n2));
245  }
246 
247  Int_t nevt = external->ValueAsInt(0,4);
248 
249  Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
250 
251  Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(busPatchId);
252 
253  if ( nevents[ddl] == 0 )
254  {
255  nevents[ddl] = nevt;
256  }
257  else
258  {
259  if ( nevents.At(ddl) != nevt )
260  {
261  AliError(Form("Nevt mismatch for DE %5d MANU %5d DDL %d : %d vs %d",
262  detElemId,manuId,ddl,nevents.At(ddl),nevt));
263  continue;
264  }
265  }
266 
267  for ( Int_t i = 0; i < wec->Dimension()-1; ++i )
268  {
269  manu->SetValueAsDouble(0,i,manu->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
270 
271  busPatch->SetValueAsDouble(0,i,busPatch->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
272 
273  de->SetValueAsDouble(0,i,de->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
274 
275  chamber->SetValueAsDouble(0,i,chamber->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
276  }
277  delete wec;
278  }
279 
280  UpdateNumberOfEvents(&nevents);
281 
282 }
283 
284 //_____________________________________________________________________________
285 AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
286  const AliMUONVStore& deOrBpValues, Int_t val)
287 : AliMUONVTrackerData(name,title),
288 fIsSingleEvent(kFALSE),
289 fChannelValues(0x0),
290 fManuValues(0x0),
291 fBusPatchValues(0x0),
292 fDEValues(0x0),
293 fChamberValues(0x0),
294 fPCBValues(0x0),
295 fDimension(0),
296 fNevents(0),
297 fDimensionNames(0x0),
298 fExternalDimensionNames(0x0),
299 fExternalDimension(0),
300 fHistogramming(0x0),
301 fHistos(0x0),
302 fXmin(0.0),
303 fXmax(0.0),
304 fIsChannelLevelEnabled(kFALSE),
305 fIsManuLevelEnabled(kFALSE),
306 fIsBustPatchLevelEnabled(kFALSE),
307 fIsPCBLevelEnabled(kFALSE),
308 fNofDDLs(0),
309 fNofEventsPerDDL(0x0)
310 {
314 
315  if (deOrBpValues.GetSize()==0)
316  {
317  AliFatal("Cannot create a tracker data from nothing in that case !");
318  }
319 
320  if ( !AliMpDDLStore::Instance(kFALSE) && !AliMpManuStore::Instance(kFALSE) )
321  {
322  AliError("Cannot work without (full) mapping");
323  return;
324  }
325 
326  if ( val == 1 )
327  {
328  BuildFromDEStore(deOrBpValues);
329  }
330  else if ( val == 2 )
331  {
332  BuildFromBPStore(deOrBpValues);
333  }
334  else
335  {
336  AliFatal("Wrong parameter. Must be 1 or 2");
337  }
338 
339 
340 }
341 
342 //_____________________________________________________________________________
344 {
346 
347  TIter next(deValues.CreateIterator());
348  AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
349 
350  Int_t dimension = ( m->Dimension() - fgkExtraDimension - fgkVirtualExtraDimension ) / 2;
351 
353 
354  fDimensionNames = new TObjArray(fDimension+fgkVirtualExtraDimension);
355  fExternalDimensionNames = new TObjArray(dimension);
356  fExternalDimension = dimension;
357  fHistogramming = new Int_t[fExternalDimension];
358  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
359 
360  fExternalDimensionNames->SetOwner(kTRUE);
361  fDimensionNames->SetOwner(kTRUE);
362  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
363  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
364  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
365  Clear();
366  TArrayI nevents(AliDAQ::NumberOfDdls("MUONTRK"));
367  AssertStores();
368 
369  next.Reset();
370  AliMUONVCalibParam* external;
371 
372  while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
373  {
374  Int_t detElemId = external->ID0();
375 
376  AliMpDetElement* mpde = AliMpDDLStore::Instance()->GetDetElement(detElemId,kFALSE);
377 
378  if (!mpde)
379  {
380  AliError(Form("Got an invalid DE (%d) from external store",detElemId));
381  continue;
382  }
383 
384  Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
385  AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
386  AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
387 
388  AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,detElemId,0,0);
389  // as external, but without event count
390  wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
391  wec->SetValueAsDouble(0,1,external->ValueAsDouble(0,1));
392  wec->SetValueAsDouble(0,2,external->ValueAsDouble(0,2));
393  wec->SetValueAsDouble(0,3,external->ValueAsDouble(0,3));
394 
395  Int_t n1 = de->ValueAsInt(0,IndexOfNumberDimension());
396  Int_t n2 = external->ValueAsInt(0,IndexOfNumberDimension());
397  if ( n1 != n2 )
398  {
399  AliError(Form("Incoherent number of dimensions for DE%d : %d vs %d",
400  detElemId,n1,n2));
401  continue;
402  }
403 
404  Int_t nevt = external->ValueAsInt(0,4);
405 
406  Int_t ddl = mpde->GetDdlId();
407 
408  if ( nevents[ddl] == 0 )
409  {
410  nevents[ddl] = nevt;
411  }
412  else
413  {
414  if ( nevents.At(ddl) != nevt )
415  {
416  AliError(Form("Nevt mismatch for DE %5d DDL %d : %d vs %d",
417  detElemId,ddl,nevents.At(ddl),nevt));
418  continue;
419  }
420  }
421 
422  for ( Int_t i = 0; i < wec->Dimension()-1; ++i )
423  {
424  de->SetValueAsDouble(0,i,de->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
425 
426  chamber->SetValueAsDouble(0,i,chamber->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
427  }
428  delete wec;
429  }
430 
431  UpdateNumberOfEvents(&nevents);
432 }
433 
434 //_____________________________________________________________________________
436 {
438 
439  fIsBustPatchLevelEnabled = kTRUE;
440 
441  TIter next(bpValues.CreateIterator());
442  AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
443 
444  Int_t dimension = ( m->Dimension() - fgkExtraDimension - fgkVirtualExtraDimension ) / 2;
445 
447 
448  fDimensionNames = new TObjArray(fDimension+fgkVirtualExtraDimension);
449  fExternalDimensionNames = new TObjArray(dimension);
450  fExternalDimension = dimension;
451  fHistogramming = new Int_t[fExternalDimension];
452  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
453 
454  fExternalDimensionNames->SetOwner(kTRUE);
455  fDimensionNames->SetOwner(kTRUE);
456  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
457  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
458  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
459  Clear();
460  TArrayI nevents(AliDAQ::NumberOfDdls("MUONTRK"));
461  AssertStores();
462 
463  next.Reset();
464  AliMUONVCalibParam* external;
465 
466  while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
467  {
468  Int_t busPatchId = external->ID0();
469 
470  AliMpBusPatch* mpbp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId,kFALSE);
471 
472  if (!mpbp)
473  {
474  AliError(Form("Got an invalid buspatchId (%d) from external store",busPatchId));
475  continue;
476  }
477 
478  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
479  Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
480  AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
481  AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
482  AliMUONVCalibParam* bp = BusPatchParam(busPatchId,kTRUE);
483 
484  AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,busPatchId,0,0);
485  // as external, but without event count
486  wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
487  wec->SetValueAsDouble(0,1,external->ValueAsDouble(0,1));
488  wec->SetValueAsDouble(0,2,external->ValueAsDouble(0,2));
489  wec->SetValueAsDouble(0,3,external->ValueAsDouble(0,3));
490 
491  Int_t n1 = bp->ValueAsInt(0,IndexOfNumberDimension());
492  Int_t n2 = external->ValueAsInt(0,IndexOfNumberDimension());
493  if ( n1 != n2 )
494  {
495  AliError(Form("Incoherent number of dimensions for BP%d : %d vs %d",
496  busPatchId,n1,n2));
497  continue;
498  }
499 
500  Int_t nevt = external->ValueAsInt(0,4);
501 
502  Int_t ddl = mpbp->GetDdlId();
503 
504  if ( nevents[ddl] == 0 )
505  {
506  nevents[ddl] = nevt;
507  }
508  else
509  {
510  if ( nevents.At(ddl) != nevt )
511  {
512  AliError(Form("Nevt mismatch for BP %5d DDL %d : %d vs %d",
513  busPatchId,ddl,nevents.At(ddl),nevt));
514  continue;
515  }
516  }
517 
518  for ( Int_t i = 0; i < wec->Dimension()-1; ++i )
519  {
520  bp->SetValueAsDouble(0,i,bp->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
521 
522  de->SetValueAsDouble(0,i,de->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
523 
524  chamber->SetValueAsDouble(0,i,chamber->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
525  }
526  delete wec;
527  }
528 
529  UpdateNumberOfEvents(&nevents);
530 }
531 
532 //_____________________________________________________________________________
533 AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
534  const AliMUONRejectList& rejectList)
535 : AliMUONVTrackerData(name,title),
536 fIsSingleEvent(kFALSE),
537 fChannelValues(0x0),
538 fManuValues(0x0),
539 fBusPatchValues(0x0),
540 fDEValues(0x0),
541 fChamberValues(0x0),
542 fPCBValues(0x0),
543 fDimension(External2Internal(1)+fgkExtraDimension),
544 fNevents(0),
545 fDimensionNames(new TObjArray(fDimension+fgkVirtualExtraDimension)),
546 fExternalDimensionNames(new TObjArray(1)),
547 fExternalDimension(1),
548 fHistogramming(new Int_t[fExternalDimension]),
549 fHistos(0x0),
550 fXmin(0.0),
551 fXmax(0.0),
552 fIsChannelLevelEnabled(kTRUE),
553 fIsManuLevelEnabled(kTRUE),
554 fIsBustPatchLevelEnabled(kTRUE),
555 fIsPCBLevelEnabled(kFALSE),
556 fNofDDLs(0),
557 fNofEventsPerDDL(0x0)
558 {
559 
561 
562  if ( !AliMpDDLStore::Instance(kFALSE) && !AliMpManuStore::Instance(kFALSE) )
563  {
564  AliError("Cannot work without (full) mapping");
565  return;
566  }
567 
568  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
569 
570  fExternalDimensionNames->SetOwner(kTRUE);
571  fDimensionNames->SetOwner(kTRUE);
572  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
573  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
574  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
575  Clear();
576  TArrayI nevents(AliDAQ::NumberOfDdls("MUONTRK"));
577  AssertStores();
578 
579 
580  for ( Int_t chamberId = 0; chamberId < AliMpConstants::NofChambers(); ++chamberId )
581  {
582 // AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
583 
584  // FIXME : update the chamber value ?
585 
586  AliMpDEIterator deit;
587 
588  deit.First(chamberId);
589 
590  while ( !deit.IsDone() )
591  {
592  AliMpDetElement* mpde = deit.CurrentDE();
593 
594  Int_t detElemId = mpde->GetId();
595 
596  AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
597 
598  DispatchValue(*de,0,rejectList.DetectionElementProbability(detElemId),0.0,mpde->NofChannels());
599 
600  for ( Int_t iBusPatch = 0; iBusPatch < mpde->GetNofBusPatches(); ++iBusPatch )
601  {
602  Int_t busPatchId = mpde->GetBusPatchId(iBusPatch);
603 
604  AliMUONVCalibParam* bp = BusPatchParam(busPatchId,kTRUE);
605 
606  AliMpBusPatch* mpbp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
607 
608  Int_t nch(0);
609 
610  for ( Int_t iManu = 0 ;iManu < mpbp->GetNofManus(); ++iManu )
611  {
612  Int_t manuId = mpbp->GetManuId(iManu);
613 
614  nch += mpde->NofChannelsInManu(manuId);
615 
616  AliMUONVCalibParam* manu = ManuParam(detElemId,manuId,kTRUE);
617 
618  DispatchValue(*manu,0,rejectList.ManuProbability(detElemId,manuId),0.0,mpde->NofChannelsInManu(manuId));
619 
620  AliMUONVCalibParam* c = ChannelParam(detElemId,manuId);
621 
622  if (!c)
623  {
624  c = new AliMUONCalibParamND(Dimension(),
626  detElemId,
627  manuId,
628  0.0);
629  fChannelValues->Add(c);
630  }
631 
632  for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
633  {
634  DispatchValue(*c,manuChannel,rejectList.ChannelProbability(detElemId,manuId,manuChannel),0.0,1);
635  }
636  }
637 
638  DispatchValue(*bp,0,rejectList.BusPatchProbability(busPatchId),0.0,nch);
639 
640  }
641 
642  deit.Next();
643  }
644 
645  }
646 
647 
648  SetDimensionName(0,"RejectProba");
649 
651 }
652 
653 //_____________________________________________________________________________
655 {
657  delete fChannelValues;
658  delete fManuValues;
659  delete fBusPatchValues;
660  delete fDEValues;
661  delete fChamberValues;
662  delete fPCBValues;
663  delete fDimensionNames;
665  delete[] fHistogramming;
666  delete fHistos;
667  delete[] fNofEventsPerDDL;
668 }
669 
670 //_____________________________________________________________________________
671 Bool_t
672 AliMUONTrackerData::Add(const AliMUONVStore& store, TArrayI* nevents)
673 {
675  return InternalAdd(store,nevents);
676 }
677 
678 //_____________________________________________________________________________
679 Bool_t
681 {
683  // We do this by looping on all VCalibParam stored in the various containers,
684  // and simply adding the values there.
685  // Same thing for the number of events per DDL.
686  // Same thing for sparsehistograms, if we have some.
687 
688  // First cross check we have compatible objects.
689 
690  AliCodeTimerAuto("",0);
691 
693  {
694  AliError("Incompatible IsChannelLevelEnabled status");
695  return kFALSE;
696  }
697 
699  {
700  AliError("Incompatible IsManuLevelEnabled status");
701  return kFALSE;
702  }
703 
704  if ( fIsSingleEvent != data.fIsSingleEvent )
705  {
706  AliError("Incompatible IsSingleEvent status");
707  return kFALSE;
708  }
709 
711  {
712  AliError("Incompatible dimensions");
713  return kFALSE;
714  }
715 
716  if ( fNofDDLs != data.fNofDDLs )
717  {
718  AliError("Incompatible number of Ddls");
719  return kFALSE;
720  }
721 
722  if ( ( !fHistogramming && data.fHistogramming ) || ( fHistogramming && !data.fHistogramming )
723  || fXmin != data.fXmin || fXmax != data.fXmax )
724  {
725  AliError(Form("Incompatible histogramming (%p vs %p) (xmax = %e vs %e ; xmin = %e vs %e)",
727  return kFALSE;
728  }
729 
730  if ( fHistogramming )
731  {
732  for ( Int_t i = 0; i < fExternalDimension; ++i )
733  {
734  if ( fHistogramming[i] != data.fHistogramming[i] )
735  {
736  AliError(Form("Incompatible histogramming for external dimension %d",i));
737  return kFALSE;
738  }
739  }
740  }
741 
742  // OK. Seems we have compatible objects, so we can proceed with the actual
743  // merging...
744 
745  if ( data.fChannelValues )
746  {
748  }
749 
750  if ( data.fManuValues )
751  {
752  Add2D(*(data.fManuValues),*fManuValues);
753  }
754 
755  if ( data.fPCBValues )
756  {
757  Add2D(*(data.fPCBValues),*fPCBValues);
758  }
759 
760  if ( data.fBusPatchValues )
761  {
763  }
764 
765  if ( data.fDEValues )
766  {
767  Add1D(*(data.fDEValues),*fDEValues);
768  }
769 
770  if ( data.fChamberValues )
771  {
773  }
774 
775  for ( Int_t i = 0; i < fNofDDLs; ++i )
776  {
777  fNofEventsPerDDL[i] += data.fNofEventsPerDDL[i];
778  }
779 
780  if ( data.fHistos )
781  {
782  TIter nexthisto(data.fHistos->CreateIterator());
783  AliMUONVStore* store;
784  while ( ( store = static_cast<AliMUONVStore*>(nexthisto()) ) )
785  {
786  TIter ns(store->CreateIterator());
788  while ( ( h = static_cast<AliMUONSparseHisto*>(ns()) ) )
789  {
790  AliMUONVStore* thisStore = static_cast<AliMUONVStore*>(fHistos->FindObject(store->GetUniqueID()));
791 
792  if (!thisStore)
793  {
794  thisStore = store->Create();
795  thisStore->SetUniqueID(store->GetUniqueID());
796  fHistos->Add(thisStore);
797  }
798 
799  AliMUONSparseHisto* mine = static_cast<AliMUONSparseHisto*>(thisStore->FindObject(h->GetUniqueID()));
800 
801  if (!mine)
802  {
803  thisStore->Add(h);
804  }
805  else
806  {
807  mine->Add(*h);
808  }
809  }
810  }
811  }
812 
813  for ( Int_t i = 0 ; i < fNofDDLs; ++i )
814  {
815  fNevents = TMath::Max(fNevents,fNofEventsPerDDL[i]);
816  }
817 
818  return kTRUE;
819 }
820 
821 //_____________________________________________________________________________
822 void
824 {
826 
827  TIter next(src.CreateIterator());
829 
830  while ( ( p = static_cast<AliMUONVCalibParam*>(next()) ) )
831  {
832  AliMUONVCalibParam* a = static_cast<AliMUONVCalibParam*>(dest.FindObject(p->ID0(),p->ID1()));
833 
834  if (!a)
835  {
836  dest.Add(static_cast<AliMUONVCalibParam*>(p->Clone()));
837  }
838  else
839  {
840  AddCalibParams(*p,*a);
841  }
842  }
843 }
844 
845 //_____________________________________________________________________________
846 void
848 {
850 
851  TIter next(src.CreateIterator());
853 
854  while ( ( p = static_cast<AliMUONVCalibParam*>(next()) ) )
855  {
856  AliMUONVCalibParam* a = static_cast<AliMUONVCalibParam*>(dest.FindObject(p->GetUniqueID()));
857 
858  if (!a)
859  {
860  dest.Add(static_cast<AliMUONVCalibParam*>(p->Clone()));
861  }
862  else
863  {
864  AddCalibParams(*p,*a);
865  }
866  }
867 }
868 
869 //_____________________________________________________________________________
870 void
872 {
874  for ( Int_t i = 0; i < src.Size(); ++i )
875  {
876  for ( Int_t j = 0; j < src.Dimension(); ++j )
877  {
878  dest.SetValueAsFloat(i,j,dest.ValueAsFloat(i,j)+src.ValueAsFloat(i,j));
879  }
880  }
881 }
882 
883 //_____________________________________________________________________________
884 Bool_t
886 {
888 
889  Clear();
890  Bool_t rv = InternalAdd(store,0x0);
892  return rv;
893 }
894 
895 //_____________________________________________________________________________
896 Bool_t
898 {
900 
901  if (!fNofDDLs)
902  {
903  fNofDDLs = AliDAQ::NumberOfDdls("MUONTRK");
904  fNofEventsPerDDL = new Int_t[fNofDDLs];
905  for ( Int_t i = 0; i < fNofDDLs; ++i )
906  {
907  fNofEventsPerDDL[i] = 0;
908  }
909  }
910 
911  if (nevents)
912  {
913  if (nevents->GetSize() != fNofDDLs )
914  {
915  AliError(Form("nof of ddl per event array size is incorrect : got %d, expecting %d",
916  nevents->GetSize(),fNofDDLs));
917  return kFALSE;
918  }
919 
920  for ( Int_t i = 0 ; i < fNofDDLs; ++i )
921  {
922  fNofEventsPerDDL[i] += nevents->At(i);
923  fNevents = TMath::Max(fNevents,fNofEventsPerDDL[i]);
924  }
925  }
926  else
927  {
928  for ( Int_t i = 0 ; i < fNofDDLs; ++i )
929  {
930  ++fNofEventsPerDDL[i];
931  fNevents = TMath::Max(fNevents,fNofEventsPerDDL[i]);
932  }
933  }
934  return kTRUE;
935 }
936 
937 //_____________________________________________________________________________
938 void
940 {
942 
943  if (!fChamberValues)
944  {
945  Int_t numberOfBusPatches(0);
946  Int_t numberOfDEs(0);
947 
948  // get number of bus patches and number of detection element
949  // to initialize fBusPatchValues and fDEValues below
950 
951  if (!AliMpDDLStore::Instance(false))
952  {
954  }
955 
956  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
957  while ( next() ) ++numberOfBusPatches;
958  AliMpDEIterator deIt;
959  deIt.First();
960  while (!deIt.IsDone())
961  {
962  ++numberOfDEs;
963  deIt.Next();
964  }
965 
966  if ( fIsChannelLevelEnabled )
967  {
968  fChannelValues = new AliMUON2DMap(kTRUE);
969  }
970  if ( fIsManuLevelEnabled )
971  {
972  fManuValues = new AliMUON2DMap(kTRUE);
973  }
974  if ( fIsPCBLevelEnabled )
975  {
976  fPCBValues = new AliMUON2DMap(kFALSE);
977  }
979  {
980  fBusPatchValues = new AliMUON1DMap(numberOfBusPatches);
981  }
982  fDEValues = new AliMUON1DMap(numberOfDEs);
984  }
985 }
986 
987 //_____________________________________________________________________________
988 Bool_t
989 AliMUONTrackerData::InternalAdd(const AliMUONVStore& store, TArrayI* nevents)
990 {
992 
993  AliCodeTimerAuto(GetName(),0);
994 
995  if ( IsSingleEvent() && NumberOfEvents(-1) == 1 )
996  {
997  AliError(Form("%s is supposed to be single event only",GetName()));
998  return kFALSE;
999  }
1000 
1001  UpdateNumberOfEvents(nevents);
1002 
1003  AssertStores();
1004 
1005  TIter next(store.CreateIterator());
1006  AliMUONVCalibParam* external;
1007 
1008  Int_t nk(2);
1009 
1010  if ( IsSingleEvent() ) nk = 1;
1011 
1012  while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
1013  {
1014  if ( external->Dimension() != ExternalDimension() )
1015  {
1016  AliError(Form("Incompatible dimensions %d vs %d",
1017  external->Dimension(),ExternalDimension()));
1018  return kFALSE;
1019  }
1020 
1021  AliMUONVCalibParam* chamber(0x0);
1022  AliMUONVCalibParam* de(0x0);
1023  AliMUONVCalibParam* busPatch(0x0);
1024  AliMUONVCalibParam* pcb(0x0);
1025  AliMUONVCalibParam* manu(0x0);
1026  AliMUONVCalibParam* channel(0x0);
1027  AliMpDetElement* mpde(0x0);
1028 
1029  Int_t manuId = GetParts(external,chamber,de,busPatch,pcb,manu,channel,mpde);
1030 
1031  if ( manuId < 0 ) continue;
1032 
1033  Int_t detElemId = mpde->GetId();
1034 
1035  Double_t value[] = { 0.0, 0.0 };
1036 
1037  Int_t nch = mpde->NofChannelsInManu(manuId);
1038 
1039  for ( Int_t i = 0; i < external->Size(); ++i )
1040  {
1041  Bool_t existingChannel = ( nch == AliMpConstants::ManuNofChannels() ? kTRUE
1042  : mpde->IsConnectedChannel(manuId,i));
1043  // note we only use IsConnectedChannel method when really needed, as
1044  // it costs (some) CPU time...
1045 
1046  if ( existingChannel )
1047  {
1048  Bool_t validChannel(kFALSE);
1049 
1050  for ( Int_t j = 0; j < external->Dimension(); ++j )
1051  {
1052  Double_t vext = external->IsDoublePrecision() ?
1053  external->ValueAsDoubleFast(i,j) :
1054  external->ValueAsFloatFast(i,j);
1055 
1056  if ( vext >= AliMUONVCalibParam::InvalidFloatValue() ) continue;
1057 
1058  validChannel = kTRUE;
1059 
1060  Int_t ix = External2Internal(j);
1061 
1062  value[0] = vext;
1063  value[1] = vext*vext;
1064 
1065  if ( IsHistogrammed(j) )
1066  {
1067  FillHisto(detElemId,manuId,i,j,vext);
1068  }
1069 
1070  for ( Int_t k = 0; k < nk; ++k )
1071  {
1072  if ( channel )
1073  {
1074  channel->SetValueAsDoubleFast(i,ix+k,channel->ValueAsDoubleFast(i,ix+k)+value[k]);
1075  }
1076 
1077  if (manu)
1078  {
1079  manu->SetValueAsDoubleFast(0,ix+k,manu->ValueAsDoubleFast(0,ix+k)+value[k]);
1080  }
1081 
1082  busPatch->SetValueAsDoubleFast(0,ix+k,busPatch->ValueAsDoubleFast(0,ix+k)+value[k]);
1083 
1084  de->SetValueAsDoubleFast(0,ix+k,de->ValueAsDoubleFast(0,ix+k)+value[k]);
1085 
1086  chamber->SetValueAsDoubleFast(0,ix+k,chamber->ValueAsDoubleFast(0,ix+k)+value[k]);
1087 
1088  if ( pcb )
1089  {
1090  pcb->SetValueAsDoubleFast(0,ix+k,pcb->ValueAsDoubleFast(0,ix+k)+value[k]);
1091  }
1092  }
1093  }
1094 
1095  if ( validChannel )
1096  {
1097  if ( channel )
1098  {
1100  channel->ValueAsDoubleFast(i,IndexOfOccupancyDimension())+1.0);
1101  }
1102 
1103  if (manu)
1104  {
1107  }
1108 
1110  busPatch->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
1114  chamber->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
1115  if ( pcb )
1116  {
1119  }
1120  }
1121  }
1122  }
1123  }
1124 
1126 
1127  return kTRUE;
1128 }
1129 
1130 //_____________________________________________________________________________
1131 Double_t
1132 AliMUONTrackerData::BusPatch(Int_t busPatchId, Int_t dim) const
1133 {
1136  AliMUONVCalibParam* param = BusPatchParam(busPatchId);
1137  return param ? Value(*param,0,dim,DdlIdFromBusPatchId(busPatchId)) : 0.0;
1138 }
1139 
1140 //_____________________________________________________________________________
1142 AliMUONTrackerData::BusPatchParam(Int_t busPatchId, Bool_t create) const
1143 {
1145 
1146  AliMUONVCalibParam* busPatch = fBusPatchValues ? static_cast<AliMUONVCalibParam*>
1147  (fBusPatchValues->FindObject(busPatchId)) : 0x0;
1148 
1149  if (!busPatch && create && fBusPatchValues)
1150  {
1151  busPatch = CreateBusPatchParam(busPatchId);
1152  fBusPatchValues->Add(busPatch);
1153  }
1154 
1155  return busPatch;
1156 }
1157 
1158 //_____________________________________________________________________________
1161 {
1163 
1164  AliCodeTimerAuto("",0);
1165 
1166  AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1167 
1168  if (!bp)
1169  {
1170  AliError(Form("Got an invalid buspatchId = %d",busPatchId));
1171  return 0x0;
1172  }
1173 
1174  AliMUONVCalibParam* busPatch = new AliMUONCalibParamND(Dimension(),1,busPatchId,0,0.0);
1175 
1176  // set the number of channels in that buspatch
1177 
1178  Int_t nchannels(0);
1179 
1180  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
1181 
1183 
1184  for ( Int_t i = 0; i < bp->GetNofManus(); ++i )
1185  {
1186  Int_t manuId = bp->GetManuId(i);
1187  nchannels += de->NofChannelsInManu(manuId);
1188  }
1189 
1190  busPatch->SetValueAsDouble(0,IndexOfNumberDimension(),nchannels);
1191 
1192  return busPatch;
1193 }
1194 
1195 //_____________________________________________________________________________
1196 Double_t
1197 AliMUONTrackerData::Chamber(Int_t chamberId, Int_t dim) const
1198 {
1201 
1202  // FIXME: is the Value() correct wrt to number of events in the case of
1203  // chamber ? Or should we do something custom at the chamber level
1204  // (as it spans several ddls) ?
1205 
1206  AliMUONVCalibParam* param = ChamberParam(chamberId);
1207  return param ? Value(*param,0,dim,DdlIdFromChamberId(chamberId)) : 0.0;
1208 }
1209 
1210 //_____________________________________________________________________________
1212 AliMUONTrackerData::ChamberParam(Int_t chamberId, Bool_t create) const
1213 {
1215 
1216  AliMUONVCalibParam* chamber = fChamberValues ? static_cast<AliMUONVCalibParam*>
1217  (fChamberValues->FindObject(chamberId)) : 0x0;
1218 
1219  if (!chamber && create && fChamberValues)
1220  {
1221  chamber = CreateChamberParam(chamberId);
1222  fChamberValues->Add(chamber);
1223  }
1224 
1225  return chamber;
1226 }
1227 
1228 //_____________________________________________________________________________
1231 {
1233 
1234  AliCodeTimerAuto("",0);
1235 
1236  AliMUONVCalibParam* chamber = new AliMUONCalibParamND(Dimension(),1,chamberId,0,0.0);
1237 
1238  // set the number of channels in that chamber
1239 
1240  Int_t nchannels(0);
1241 
1242  AliMpDEIterator it;
1243 
1244  it.First(chamberId);
1245 
1246  while ( !it.IsDone() )
1247  {
1248  AliMpDetElement* det = it.CurrentDE();
1249 
1250  for ( Int_t i = 0; i < det->GetNofBusPatches(); ++i )
1251  {
1252  Int_t busPatchId = det->GetBusPatchId(i);
1253  AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1254  for ( Int_t j = 0; j < bp->GetNofManus(); ++j )
1255  {
1256  Int_t manuId = bp->GetManuId(j);
1257  nchannels += det->NofChannelsInManu(manuId);
1258  }
1259  }
1260 
1261  it.Next();
1262  }
1263 
1264  chamber->SetValueAsDouble(0,IndexOfNumberDimension(),nchannels);
1265 
1266  return chamber;
1267 }
1268 
1269 //_____________________________________________________________________________
1270 Double_t
1271 AliMUONTrackerData::Channel(Int_t detElemId, Int_t manuId,
1272  Int_t manuChannel, Int_t dim) const
1273 {
1275 
1276  AliMUONVCalibParam* param = ChannelParam(detElemId,manuId);
1277 
1278  return param ? Value(*param,manuChannel,dim,DdlIdFromDetElemId(detElemId)) : 0.0;
1279 }
1280 
1281 //_____________________________________________________________________________
1283 AliMUONTrackerData::ChannelParam(Int_t detElemId, Int_t manuId,
1284  const AliMUONVCalibParam* external) const
1285 {
1287 
1288  AliMUONVCalibParam* param = fChannelValues ? static_cast<AliMUONVCalibParam*>
1289  (fChannelValues->FindObject(detElemId,manuId)) : 0x0 ;
1290 
1291  if (!param && external && fChannelValues)
1292  {
1293  param = CreateDouble(*external,detElemId,manuId);
1294  fChannelValues->Add(param);
1295  }
1296 
1297  return param;
1298 }
1299 
1300 //_____________________________________________________________________________
1301 void
1303 {
1306  if ( fManuValues ) fManuValues->Clear();
1308  if ( fPCBValues ) fPCBValues->Clear();
1309  if ( fDEValues) fDEValues->Clear();
1311  if ( fHistos ) fHistos->Clear();
1312  for ( Int_t i = 0; i < fNofDDLs; ++i )
1313  {
1314  fNofEventsPerDDL[i] = 0;
1315  }
1316  fNevents = 0;
1318 }
1319 
1320 //______________________________________________________________________________
1323  const AliMUONVTrackerData& d2,
1324  const char* outnamebase,
1326 {
1330 
1331  Double_t (*difffunction)(Double_t,Double_t)=0x0;
1332  TString suffix("unknown");
1333 
1334  if ( difftype == kDifference )
1335  {
1336  difffunction = Difference;
1337  suffix = "D";
1338  }
1339  if ( difftype == kAbsoluteDifference )
1340  {
1341  difffunction = AbsoluteDifference;
1342  suffix = "AD";
1343  }
1344  if ( difftype == kRelativeDifference )
1345  {
1346  difffunction = RelativeDifference;
1347  suffix = "RD";
1348  }
1349  if ( difftype == kAbsoluteRelativeDifference )
1350  {
1351  difffunction = AbsoluteRelativeDifference;
1352  suffix = "ARD";
1353  }
1354 
1355  TString outname;
1356 
1357  outname.Form("%s:%s",outnamebase,suffix.Data());
1358 
1359  if (difffunction)
1360  {
1361  return CompareData(d1,d2,outname.Data(),difffunction);
1362  }
1363  else
1364  {
1365  return 0x0;
1366  }
1367 }
1368 
1369 //______________________________________________________________________________
1372  const AliMUONVTrackerData& d2,
1373  const char* outname,
1374  Double_t(*diff)(Double_t,Double_t))
1375 {
1377 
1378  if ( d1.NumberOfDimensions() != d2.NumberOfDimensions() )
1379  {
1380  AliErrorClass("Cannot compare data of incompatible dimensions");
1381  return 0x0;
1382  }
1383 
1384  AliMpManuIterator it;
1385  Int_t detElemId, manuId;
1386 
1387  AliMUONVStore* store = new AliMUON2DMap(kTRUE);
1388 
1389  while ( it.Next(detElemId,manuId) )
1390  {
1391  if ( d1.HasDetectionElement(detElemId) && d2.HasDetectionElement(detElemId) &&
1392  d1.HasManu(detElemId,manuId) && d2.HasManu(detElemId,manuId) )
1393  {
1395 
1396  AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
1397 
1398  if (!param)
1399  {
1400  param = new AliMUONCalibParamND(d1.ExternalDimension(),64,detElemId,manuId,
1402  store->Add(param);
1403  }
1404 
1405  for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1406  {
1407  if ( de->IsConnectedChannel(manuId,i) )
1408  {
1409  for ( Int_t k = 0; k < d1.ExternalDimension(); ++k )
1410  {
1411 
1412  Double_t d = diff(d1.Channel(detElemId,manuId,i,k),
1413  d2.Channel(detElemId,manuId,i,k));
1414 
1415  param->SetValueAsDouble(i,k,d);
1416  }
1417  }
1418  }
1419  }
1420  }
1421 
1422  AliMUONVTrackerData* d = new AliMUONTrackerData(outname,outname,d1.ExternalDimension(),kTRUE);
1423  for ( Int_t k = 0; k < d1.ExternalDimension(); ++k )
1424  {
1425  d->SetDimensionName(k,Form("D:%s",d1.ExternalDimensionName(k).Data()));
1426  }
1427  d->Add(*store);
1428 
1429  return d;
1430 }
1431 //_____________________________________________________________________________
1432 Double_t
1433 AliMUONTrackerData::Count(Int_t detElemId, Int_t manuId,
1434  Int_t manuChannel) const
1435 {
1437 
1438  return Channel(detElemId,manuId,manuChannel,IndexOfNumberDimension());
1439 }
1440 
1441 
1442 //_____________________________________________________________________________
1445  Int_t detElemId, Int_t manuId) const
1446 {
1448 
1449  AliCodeTimerAuto("",0);
1450 
1452  param.Size(),
1453  detElemId,
1454  manuId,
1455  0.0);
1456 
1457  AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId,manuId);
1458 
1459  for ( Int_t i = 0; i < c->Size(); ++i )
1460  {
1461  Double_t value(0.0);
1462 
1463  if ( de->IsConnectedChannel(manuId,i) ) value = 1.0;
1464 
1466  }
1467 
1468  return c;
1469 }
1470 
1471 //_____________________________________________________________________________
1472 Double_t
1473 AliMUONTrackerData::DetectionElement(Int_t detElemId, Int_t dim) const
1474 {
1476  AliMUONVCalibParam* param = DetectionElementParam(detElemId);
1477  return param ? Value(*param,0,dim,DdlIdFromDetElemId(detElemId)) : 0.0;
1478 
1479 }
1480 
1481 //_____________________________________________________________________________
1483 AliMUONTrackerData::DetectionElementParam(Int_t detElemId, Bool_t create) const
1484 {
1486 
1487  AliMUONVCalibParam* de = fDEValues ? static_cast<AliMUONVCalibParam*>
1488  (fDEValues->FindObject(detElemId)) : 0x0 ;
1489 
1490  if (!de && create && fDEValues)
1491  {
1492  de = CreateDetectionElementParam(detElemId);
1493  fDEValues->Add(de);
1494  }
1495 
1496  return de;
1497 
1498 }
1499 
1500 //_____________________________________________________________________________
1503 {
1505 
1506  AliCodeTimerAuto("",0);
1507 
1508  AliMUONVCalibParam* de = new AliMUONCalibParamND(Dimension(),1,detElemId,0,0.0);
1509 
1511  Int_t nchannels(0);
1512 
1513  for ( Int_t i = 0; i < det->GetNofBusPatches(); ++i )
1514  {
1515  Int_t busPatchId = det->GetBusPatchId(i);
1516  AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1517  for ( Int_t j = 0; j < bp->GetNofManus(); ++j )
1518  {
1519  Int_t manuId = bp->GetManuId(j);
1520  nchannels += det->NofChannelsInManu(manuId);
1521  }
1522  }
1523 
1524  de->SetValueAsDouble(0,IndexOfNumberDimension(),nchannels);
1525 
1526  return de;
1527 }
1528 
1529 //_____________________________________________________________________________
1530 Int_t
1532 {
1534  AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(buspatchid);
1535  if (bp)
1536  {
1537  return bp->GetDdlId();
1538  }
1539  return -1;
1540 }
1541 
1542 //_____________________________________________________________________________
1543 Int_t
1545 {
1548  if (de)
1549  {
1550  return de->GetDdlId();
1551  }
1552  return -1;
1553 }
1554 
1555 //_____________________________________________________________________________
1556 Int_t
1558 {
1562 
1563  AliMpDEIterator it;
1564 
1565  it.First(chamberid);
1566  Int_t n(0);
1567  Int_t d(-1);
1568 
1569  while (!it.IsDone())
1570  {
1571  Int_t detElemId = it.CurrentDEId();
1572  Int_t ddlId = DdlIdFromDetElemId(detElemId);
1573  if ( NumberOfEvents(ddlId) > n )
1574  {
1575  n = NumberOfEvents(ddlId);
1576  d = ddlId;
1577  }
1578  it.Next();
1579  }
1580 
1581  return d;
1582 }
1583 
1584 //_____________________________________________________________________________
1585 TString
1587 {
1589  TObjString* value = static_cast<TObjString*>(fDimensionNames->At(dim));
1590  if ( value )
1591  {
1592  return value->String();
1593  }
1594  else
1595  {
1596  return TString("Invalid");
1597  }
1598 }
1599 
1600 //_____________________________________________________________________________
1601 void
1603 {
1605 
1606  delete fChannelValues;
1607  fChannelValues = 0x0;
1608  fIsChannelLevelEnabled = kFALSE;
1609 }
1610 
1611 //_____________________________________________________________________________
1612 void
1614 {
1616 
1618  delete fManuValues;
1619  fManuValues = 0x0;
1620  fIsManuLevelEnabled = kFALSE;
1621 }
1622 
1623 //_____________________________________________________________________________
1624 Int_t
1626 {
1628  return IsSingleEvent() ? index : index*2;
1629 }
1630 
1631 //_____________________________________________________________________________
1632 TString
1634 {
1636 
1637  TObjString* value = static_cast<TObjString*>(fExternalDimensionNames->At(dim));
1638  if ( value )
1639  {
1640  return value->String();
1641  }
1642  else
1643  {
1644  return TString("Invalid");
1645  }
1646 }
1647 
1648 //_____________________________________________________________________________
1649 void
1650 AliMUONTrackerData::FillHisto(Int_t detElemId, Int_t manuId, Int_t manuChannel,
1651  Int_t dim, Double_t value)
1652 {
1654 
1655  AliMUONSparseHisto* h(0x0);
1656 
1657  if ( fIsChannelLevelEnabled )
1658  {
1659  h = GetChannelSparseHisto(detElemId, manuId, manuChannel,dim);
1660  }
1661  else if ( fIsManuLevelEnabled )
1662  {
1663  h = GetManuSparseHisto(detElemId,manuId,dim);
1664  }
1665 
1666  AliDebug(1,Form("DE %04d MANU %04d CH %02d dim %d value %e h %p",detElemId,manuId,manuChannel,dim,value,h));
1667 
1668  if (h)
1669  {
1670  h->Fill(static_cast<Int_t>(TMath::Nint(value)));
1671  }
1672 }
1673 
1674 //_____________________________________________________________________________
1676 AliMUONTrackerData::GetManuSparseHisto(Int_t detElemId, Int_t manuId,
1677  Int_t dim) const
1678 {
1680 
1681  if (!fHistos) return 0x0;
1682 
1683  AliMUON1DArray* m = static_cast<AliMUON1DArray*>(fHistos->FindObject(detElemId,manuId));
1684  if (!m) return 0x0;
1685 
1686  AliMUONSparseHisto* h = static_cast<AliMUONSparseHisto*>(m->FindObject(dim));
1687 
1688  return h;
1689 }
1690 
1691 //_____________________________________________________________________________
1693 AliMUONTrackerData::GetManuSparseHisto(Int_t detElemId, Int_t manuId, Int_t dim)
1694 {
1696 
1697  if (!fHistos) fHistos = new AliMUON2DMap(kTRUE);
1698 
1699  AliMUON1DArray* m = static_cast<AliMUON1DArray*>(fHistos->FindObject(detElemId,manuId));
1700  if (!m)
1701  {
1703  m->SetUniqueID( ( manuId << 16 ) | detElemId );
1704  fHistos->Add(m);
1705  }
1706 
1707  AliMUONSparseHisto* h = static_cast<AliMUONSparseHisto*>(m->FindObject(dim));
1708  if (!h)
1709  {
1710  h = new AliMUONSparseHisto(fXmin,fXmax);
1711 
1712  h->SetUniqueID(dim);
1713 
1714  m->Add(h);
1715  }
1716 
1717  return h;
1718 }
1719 
1720 //_____________________________________________________________________________
1722 AliMUONTrackerData::GetChannelSparseHisto(Int_t detElemId, Int_t manuId,
1723  Int_t manuChannel, Int_t dim) const
1724 {
1726 
1727  if (!fHistos) return 0x0;
1728 
1729  AliMUON1DMap* m = static_cast<AliMUON1DMap*>(fHistos->FindObject(detElemId,manuId));
1730  if (!m) return 0x0;
1731 
1732  UInt_t uid = ( manuChannel << 16 ) | dim;
1733 
1734  AliMUONSparseHisto* h = static_cast<AliMUONSparseHisto*>(m->FindObject(uid));
1735 
1736  return h;
1737 }
1738 
1739 //_____________________________________________________________________________
1741 AliMUONTrackerData::GetChannelSparseHisto(Int_t detElemId, Int_t manuId,
1742  Int_t manuChannel, Int_t dim)
1743 {
1745 
1746  if (!fHistos) fHistos = new AliMUON2DMap(kTRUE);
1747 
1748  AliMUON1DMap* m = static_cast<AliMUON1DMap*>(fHistos->FindObject(detElemId,manuId));
1749  if (!m)
1750  {
1751  m = new AliMUON1DMap(AliMpConstants::ManuNofChannels()); // start with only 1 dim
1752  m->SetUniqueID( ( manuId << 16 ) | detElemId );
1753  fHistos->Add(m);
1754  }
1755 
1756  UInt_t uid = ( manuChannel << 16 ) | dim;
1757 
1758  AliMUONSparseHisto* h = static_cast<AliMUONSparseHisto*>(m->FindObject(uid));
1759  if (!h)
1760  {
1761  h = new AliMUONSparseHisto(fXmin,fXmax);
1762 
1763  h->SetUniqueID(uid);
1764 
1765  m->Add(h);
1766  }
1767 
1768  return h;
1769 }
1770 
1771 //_____________________________________________________________________________
1772 void
1774  Int_t& detElemId, Int_t& manuId) const
1775 {
1777 
1778  // Load mapping manu store
1779  if ( ! AliMpCDB::LoadManuStore() ) {
1780  AliError("Could not access manu store from OCDB !");
1781  return;
1782  }
1783 
1784  if ( param.ID1() <= 0 )
1785  {
1786  // we (probably) get a manu serial number
1787  Int_t serial = param.ID0();
1789  detElemId = AliMp::PairFirst(pair);
1790  manuId = AliMp::PairSecond(pair);
1791  if ( !detElemId )
1792  {
1793  AliDebug(1,Form("DE %d manuId %d from serial %d is not correct !",
1794  detElemId,manuId,serial));
1795  }
1796  }
1797  else
1798  {
1799  // we get a (de,manu) pair
1800  detElemId = param.ID0();
1801  manuId = param.ID1();
1802  }
1803 }
1804 
1805 
1806 //_____________________________________________________________________________
1807 Int_t
1809  AliMUONVCalibParam*& chamber,
1810  AliMUONVCalibParam*& de,
1811  AliMUONVCalibParam*& busPatch,
1812  AliMUONVCalibParam*& pcb,
1813  AliMUONVCalibParam*& manu,
1814  AliMUONVCalibParam*& channel,
1815  AliMpDetElement*& mpde)
1816 {
1818 
1819  chamber = de = busPatch = pcb = manu = channel = 0x0;
1820  mpde = 0x0;
1821 
1822  AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
1823 
1824  Int_t detElemId;
1825  Int_t manuId;
1826 
1827  GetDEManu(*external,detElemId,manuId);
1828 
1829  mpde = ddlStore->GetDetElement(detElemId,kFALSE);
1830 
1831  if (!mpde) // can happen if reading e.g. capacitances store where we have data for non-connected manus
1832  {
1833  return -1;
1834  }
1835 
1836  // explicitely check that de,manu is correct
1837  const AliMpVSegmentation* mpseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, manuId,kFALSE);
1838 
1839  if (!mpseg)
1840  {
1841  return -1;
1842  }
1843 
1844  Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
1845 
1846  Int_t busPatchId = ddlStore->GetBusPatchId(detElemId,manuId);
1847 
1848  if ( busPatchId <= 0 )
1849  {
1850  return -1;
1851  }
1852 
1853  Int_t pcbIndex = -1;
1854 
1855  AliMp::StationType stationType = mpde->GetStationType();
1856 
1857  if ( stationType == AliMp::kStation345 )
1858  {
1859  AliMpDCSNamer namer("TRACKER");
1860  pcbIndex = namer.ManuId2PCBIndex(detElemId,manuId);
1861  }
1862 
1863  if ( fIsChannelLevelEnabled )
1864  {
1865  channel = ChannelParam(detElemId,manuId,external);
1866  }
1867 
1868  manu = ManuParam(detElemId,manuId,kTRUE);
1869 
1870  busPatch = BusPatchParam(busPatchId,kTRUE);
1871 
1872  de = DetectionElementParam(detElemId,kTRUE);
1873 
1874  chamber = ChamberParam(chamberId,kTRUE);
1875 
1876  pcb = 0x0;
1877 
1878  if ( pcbIndex >= 0 )
1879  {
1880  pcb = PCBParam(detElemId,pcbIndex,kTRUE);
1881  }
1882 
1883  return manuId;
1884 }
1885 
1886 //_____________________________________________________________________________
1887 Bool_t
1888 AliMUONTrackerData::HasBusPatch(Int_t busPatchId) const
1889 {
1891  return ( BusPatchParam(busPatchId) != 0 );
1892 }
1893 
1894 //_____________________________________________________________________________
1895 Bool_t
1896 AliMUONTrackerData::HasChamber(Int_t chamberId) const
1897 {
1899  return ( ChamberParam(chamberId) != 0 );
1900 }
1901 
1902 //_____________________________________________________________________________
1903 Bool_t
1905 {
1907  return ( DetectionElementParam(detElemId) != 0 );
1908 }
1909 
1910 //_____________________________________________________________________________
1911 Bool_t
1912 AliMUONTrackerData::HasManu(Int_t detElemId, Int_t manuId) const
1913 {
1915  return ( ManuParam(detElemId,manuId) != 0 );
1916 }
1917 
1918 //_____________________________________________________________________________
1919 Bool_t
1920 AliMUONTrackerData::HasPCB(Int_t detElemId, Int_t pcbIndex) const
1921 {
1923  return ( PCBParam(detElemId,pcbIndex) != 0 );
1924 }
1925 
1926 //_____________________________________________________________________________
1927 Double_t
1928 AliMUONTrackerData::Manu(Int_t detElemId, Int_t manuId, Int_t dim) const
1929 {
1931 
1932  AliMUONVCalibParam* param = ManuParam(detElemId,manuId);
1933  return param ? Value(*param,0,dim,DdlIdFromDetElemId(detElemId)) : 0.0;
1934 }
1935 
1936 //_____________________________________________________________________________
1938 AliMUONTrackerData::ManuParam(Int_t detElemId, Int_t manuId, Bool_t create) const
1939 {
1941 
1942  AliMUONVCalibParam* manu = fManuValues ? static_cast<AliMUONVCalibParam*>
1943  (fManuValues->FindObject(detElemId,manuId)) : 0x0 ;
1944 
1945  if (!manu && create && fManuValues)
1946  {
1947  manu = CreateManuParam(detElemId,manuId);
1948  fManuValues->Add(manu);
1949  }
1950 
1951  return manu;
1952 }
1953 
1954 //_____________________________________________________________________________
1956 AliMUONTrackerData::CreateManuParam(Int_t detElemId, Int_t manuId) const
1957 {
1959 
1960  AliCodeTimerAuto("",0);
1961 
1962  AliMUONVCalibParam* manu = new AliMUONCalibParamND(Dimension(),1,detElemId,manuId,0.0);
1963 
1964  // set the number of channels in that manu
1965 
1967 
1969 
1970  return manu;
1971 }
1972 
1973 //_____________________________________________________________________________
1974 Long64_t
1975 AliMUONTrackerData::Merge(TCollection* list)
1976 {
1978 
1979  if (!list) return 0;
1980 
1981  if ( list->IsEmpty() ) return NumberOfEvents(-1);
1982 
1983  TIter next(list);
1984  const TObject* o(0x0);
1985 
1986  while ( ( o = next() ) )
1987  {
1988  const AliMUONTrackerData* data = dynamic_cast<const AliMUONTrackerData*>(o);
1989  if (!data)
1990  {
1991  AliError(Form("Object named %s is not an AliMUONTrackerData ! Skipping it",
1992  o->GetName()));
1993  }
1994  else
1995  {
1996  Bool_t ok = Add(*data);
1997  if (!ok)
1998  {
1999  AliError("Got incompatible objects");
2000  }
2001  }
2002  }
2003 
2004  return NumberOfEvents(-1);
2005 }
2006 
2007 //_____________________________________________________________________________
2008 Int_t
2010 {
2012 
2014 }
2015 
2016 //_____________________________________________________________________________
2017 Int_t
2019 {
2022 
2023  Int_t n(0);
2024 
2025  if ( fNofEventsPerDDL && ddlNumber >= 0 && ddlNumber < fNofDDLs )
2026  {
2027  n = fNofEventsPerDDL[ddlNumber];
2028  }
2029  else
2030  {
2031  // get the max number of events
2032  return fNevents;
2033  }
2034 
2035  return n;
2036 }
2037 
2038 //_____________________________________________________________________________
2039 Double_t
2040 AliMUONTrackerData::PCB(Int_t detElemId, Int_t pcbIndex, Int_t dim) const
2041 {
2043 
2044  AliMUONVCalibParam* param = PCBParam(detElemId,pcbIndex);
2045 
2046  return param ? Value(*param,0,dim,DdlIdFromDetElemId(detElemId)) : 0.0;
2047 }
2048 
2049 //_____________________________________________________________________________
2051 AliMUONTrackerData::PCBParam(Int_t detElemId, Int_t pcbIndex, Bool_t create) const
2052 {
2054 
2055  AliMUONVCalibParam* pcb = fPCBValues ? static_cast<AliMUONVCalibParam*>
2056  (fPCBValues->FindObject(detElemId,pcbIndex)) : 0x0 ;
2057 
2058  if (create && fPCBValues && !pcb)
2059  {
2060  pcb = CreatePCBParam(detElemId,pcbIndex);
2061  fPCBValues->Add(pcb);
2062  }
2063 
2064  return pcb;
2065 }
2066 
2067 //_____________________________________________________________________________
2069 AliMUONTrackerData::CreatePCBParam(Int_t detElemId, Int_t pcbIndex) const
2070 {
2072 
2073  AliCodeTimerAuto("",0);
2074 
2075  AliMpDCSNamer namer("TRACKER");
2076 
2078  namer.NumberOfPCBs(detElemId),
2079  detElemId,
2080  pcbIndex,
2081  0.0);
2082  return pcb;
2083 }
2084 
2085 //_____________________________________________________________________________
2086 void
2087 AliMUONTrackerData::Print(Option_t* wildcard, Option_t* opt) const
2088 {
2090 
2091  TNamed::Print(opt);
2092 
2093  if ( !fIsSingleEvent )
2094  {
2095  for ( Int_t i = 0; i < fNofDDLs; ++i )
2096  {
2097  cout << Form("DDL %04d Nevents=%10d",AliDAQ::DdlID("MUONTRK",i),fNofEventsPerDDL[i]) << endl;
2098  }
2099  }
2100 
2101  if ( !fIsChannelLevelEnabled )
2102  {
2103  cout << "Is not storing data at the channel level" << endl;
2104  }
2105 
2106  if ( !fIsManuLevelEnabled )
2107  {
2108  cout << "Is not storing data at the manu level" << endl;
2109  }
2110 
2111  for ( Int_t i = 0; i <= fExternalDimensionNames->GetLast(); ++i )
2112  {
2113  TObjString* name = static_cast<TObjString*>(fExternalDimensionNames->At(i));
2114  cout << Form("External Dimension %2d Name %s %s",i,
2115  ( name ? name->String().Data() : "null"),
2116  ( IsHistogrammed(i) ? "(histogrammed)" : "")) << endl;
2117  }
2118 
2119  for ( Int_t i = 0; i <= fDimensionNames->GetLast(); ++i )
2120  {
2121  TObjString* name = static_cast<TObjString*>(fDimensionNames->At(i));
2122  cout << Form("Internal Dimension %2d Name %s",i,
2123  ( name ? name->String().Data() : "null")) << endl;
2124  }
2125 
2126  TString sopt(opt);
2127  sopt.ToUpper();
2128 
2129  if ( sopt.Contains("CHANNEL") )
2130  {
2131  if ( fIsChannelLevelEnabled )
2132  {
2133  if ( fChannelValues ) fChannelValues->Print(wildcard,opt);
2134  }
2135  else
2136  {
2137  AliWarning("You requested channel values, but they were not stored !");
2138  }
2139  }
2140 
2141  if ( sopt.Contains("MANU") )
2142  {
2143  if ( fIsManuLevelEnabled )
2144  {
2145  if ( fManuValues ) fManuValues->Print(wildcard,opt);
2146  }
2147  else
2148  {
2149  AliWarning("You requested manu values, but they were not stored !");
2150  }
2151  }
2152 
2153  if ( sopt.Contains("BUSPATCH") && fBusPatchValues )
2154  {
2155  fBusPatchValues->Print(wildcard,opt);
2156  }
2157 
2158  if ( sopt.Contains("DE") && fDEValues )
2159  {
2160  fDEValues->Print(wildcard,opt);
2161  }
2162 
2163  if ( sopt.Contains("CHAMBER") && fChamberValues )
2164  {
2165  fChamberValues->Print(wildcard,opt);
2166  }
2167 
2168 }
2169 
2170 //_____________________________________________________________________________
2171 void
2172 AliMUONTrackerData::SetDimensionName(Int_t index, const char* name)
2173 {
2175 
2176  if ( index >= fExternalDimension )
2177  {
2178  AliError(Form("%s : dimension %s : Index out of bounds : %d / %d",
2179  GetName(),
2180  name,index,fExternalDimension));
2181  return;
2182  }
2183 
2184  Int_t ix = External2Internal(index);
2185 
2186  if ( !IsSingleEvent() )
2187  {
2188  const char* prefix[] = { "mean", "sigma" };
2189 
2190  for ( Int_t i = 0; i < 2; ++i )
2191  {
2192  Int_t j = ix+i;
2193 
2194  SetInternalDimensionName(j,Form("%s of %s",prefix[i],name));
2195  }
2196  }
2197  else
2198  {
2199  SetInternalDimensionName(index,name);
2200  }
2201 
2202  SetExternalDimensionName(index,name);
2203 }
2204 
2205 //_____________________________________________________________________________
2206 void
2207 AliMUONTrackerData::MakeHistogramForDimension(Int_t index, Bool_t value, Double_t xmin, Double_t xmax)
2208 {
2210  if ( index >= ExternalDimension() )
2211  {
2212  AliError(Form("Index out of bounds : %d / %d",index,ExternalDimension()));
2213  return;
2214  }
2215 
2216  AliWarning(Form("Will %s make histogram for data %s index %d : that might ressemble a memory leak depending on the input data",
2217  value ? "":"not", GetName(),index));
2218  fHistogramming[index] = value;
2219  fXmin = xmin;
2220  fXmax = xmax;
2221 }
2222 
2223 //_____________________________________________________________________________
2224 void
2225 AliMUONTrackerData::SetInternalDimensionName(Int_t index, const char* value)
2226 {
2228  if ( index >= fDimension )
2229  {
2230  AliError(Form("Index out of bounds : %d / %d",index,fDimension));
2231  return;
2232  }
2233 
2234  TObjString* ovalue = static_cast<TObjString*>(fDimensionNames->At(index));
2235 
2236  if ( ovalue )
2237  {
2238  fDimensionNames->Remove(ovalue);
2239  delete ovalue;
2240  }
2241  fDimensionNames->AddAt(new TObjString(value),index);
2242 }
2243 
2244 //_____________________________________________________________________________
2245 void
2246 AliMUONTrackerData::SetExternalDimensionName(Int_t index, const char* value)
2247 {
2249  if ( index >= fExternalDimension )
2250  {
2251  AliError(Form("Index out of bounds : %d / %d",index,fExternalDimension));
2252  return;
2253  }
2254 
2255  TObjString* ovalue = static_cast<TObjString*>(fExternalDimensionNames->At(index));
2256 
2257  if ( ovalue )
2258  {
2259  fExternalDimensionNames->Remove(ovalue);
2260  delete ovalue;
2261  }
2262  fExternalDimensionNames->AddAt(new TObjString(value),index);
2263 }
2264 
2265 //_____________________________________________________________________________
2266 Double_t
2268  Int_t dim, Int_t ddlId) const
2269 {
2273 
2274  Double_t n = param.ValueAsDouble(i,IndexOfNumberDimension());
2275 
2276  if ( dim == IndexOfNumberDimension() ) return n; // the number of channels in any given element does not depend on the number of events
2277 
2278  Double_t occ = param.ValueAsDouble(i,IndexOfOccupancyDimension());
2279 
2280  if ( dim >= fDimension )
2281  {
2282  return occ;
2283  }
2284 
2285  if ( dim == IndexOfOccupancyDimension() )
2286  {
2287  if ( ddlId < 0 ) AliError("Got a negative ddl id !");
2288  return occ/n/NumberOfEvents(ddlId);
2289  }
2290 
2291  Double_t value = param.ValueAsDouble(i,dim);
2292 
2294 
2295  if ( TMath::Even(dim) || IsSingleEvent() )
2296  {
2297  Double_t x = value/occ;
2298 
2299  return ( TMath::Finite(x) ? x : 0.0 ) ;
2300  }
2301  else
2302  {
2303  Double_t nn = occ;
2304 
2305  if ( nn > 1.0 )
2306  {
2307  Double_t mean = param.ValueAsDouble(i,dim-1)/nn;
2308 
2309  return TMath::Sqrt(TMath::Abs((value-nn*mean*mean)/(nn-1.0)));
2310  }
2311  else
2312  {
2313  return 0.0;
2314  }
2315  }
2316 }
2317 
2318 //_____________________________________________________________________________
2319 void
2320 AliMUONTrackerData::Streamer(TBuffer &R__b)
2321 {
2323 
2324  if (R__b.IsReading()) {
2325  AliMUONTrackerData::Class()->ReadBuffer(R__b, this);
2326  if ( !fNofDDLs )
2327  {
2328  // backward compatible mode : we set number of events
2329  // per DDL to the total number of events (the only information
2330  // we had before version 7 of that class)
2331  delete[] fNofEventsPerDDL;
2332  fNofDDLs=20;
2333  fNofEventsPerDDL = new Int_t[fNofDDLs];
2334  for ( Int_t i = 0; i < fNofDDLs; ++i )
2335  {
2337  }
2338  }
2339  }
2340  else {
2341  AliMUONTrackerData::Class()->WriteBuffer(R__b, this);
2342  }
2343 }
2344 
2345 //_____________________________________________________________________________
2346 Bool_t
2347 AliMUONTrackerData::ExportAsASCIIOccupancyFile(const char* filename, Int_t runNumber) const
2348 {
2351 
2352  if ( ! AliMpDDLStore::Instance(kFALSE) )
2353  {
2354  AliError("Mapping not loaded. Cannot work");
2355  return kFALSE;
2356  }
2357 
2358  if (!fManuValues)
2359  {
2360  AliError("No manu values. Cannot work");
2361  return kFALSE;
2362  }
2363 
2364  ofstream out(filename);
2365 
2366  if (out.bad())
2367  {
2368  AliError(Form("Cannot create file %s",filename));
2369  return kFALSE;
2370  }
2371 
2372  out << "//===========================================================================" << endl;
2373  out << "// Hit counter exported from $Id$" << endl;
2374  out << "//===========================================================================" << endl;
2375  out << "//" << endl;
2376  out << "// * Run Number : " << runNumber << endl;
2377  out << "// * File Creation Date : " << TTimeStamp().AsString("l") << endl;
2378  out << "//---------------------------------------------------------------------------" << endl;
2379  out << "// BP MANU SUM_N NEVENTS" << endl;
2380  out << "//---------------------------------------------------------------------------" << endl;
2381 
2382  TIter next(fManuValues->CreateIterator());
2383  AliMUONVCalibParam* manu;
2384 
2385  while ( ( manu = static_cast<AliMUONVCalibParam*>(next()) ) )
2386  {
2387  Int_t detElemId = manu->ID0();
2388  Int_t manuId = manu->ID1();
2389  Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
2390  Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus( busPatchId);
2391  if ( busPatchId < 0 || ddl < 0 )
2392  {
2393  AliError(Form("Got invalid (DE,manu,bp,ddl)=(%d,%d,%d,%d). Skipping it",detElemId,manuId,busPatchId,ddl));
2394  continue;
2395  }
2396 
2397  Int_t nevents = fNofEventsPerDDL[ddl];
2398 
2399  out << Form("%5d %5d %10d %10d",busPatchId,manuId,manu->ValueAsInt(0,IndexOfOccupancyDimension()),nevents) << endl;
2400  }
2401 
2402  out.close();
2403  return kTRUE;
2404 }
2405 
2406 //_____________________________________________________________________________
2408  Int_t index,
2409  Double_t y,
2410  Double_t ey,
2411  Int_t nchannels)
2412 {
2414 
2415  Double_t sumn = 1000.0; // or any value strictly above 1
2416  Double_t sumw = sumn*y;
2417  Double_t sumw2 = (sumn-1)*ey*ey+sumw*sumw/sumn;
2418 
2419  param.SetValueAsDouble(index,0,sumw);
2420  param.SetValueAsDouble(index,1,sumw2);
2421  param.SetValueAsDouble(index,2,sumn);
2422  param.SetValueAsDouble(index,3,nchannels);
2423 
2424 }
Int_t GetNofManus() const
virtual TIterator * CreateIterator() const =0
Return an iterator to loop over the whole store.
static Int_t NofChambers()
Return number of chambers.
Implementation of AliMUONVTrackerData.
virtual TString ExternalDimensionName(Int_t dim) const
Get the name of a given (external) dimension.
The iterator over detection elements.
Float_t ManuProbability(Int_t detElemId, Int_t manuId) const
Bool_t fIsSingleEvent
whether we can deal with more than one event
static Float_t InvalidFloatValue()
Return 1E38 as invalid float value.
Int_t ManuId2PCBIndex(Int_t detElemId, Int_t manuId) const
Returns the index of PCB (within a St345 slat) for a given manu number.
virtual Int_t NumberOfEvents(Int_t ddlNumber) const
Returns the number of events we have seen so far.
Bool_t fIsManuLevelEnabled
whether we allow storing of manu (fManuValues) values
Int_t External2Internal(Int_t index) const
Convert from external to internal index.
Double_t fXmin
min x value for histograms
virtual Double_t Channel(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t dim=0) const
Get the value for a given channel and given dimension.
virtual Bool_t Add(TObject *object)
virtual Int_t IndexOfOccupancyDimension() const
Index of the dimension containing the occupancy number.
static AliMpSegmentation * Instance(Bool_t warn=true)
virtual Float_t ValueAsFloat(Int_t i, Int_t j=0) const =0
#define PRECISION
virtual void Print(Option_t *wildcard="") const
Print all objects whose name matches wildcard.
#define TObjArray
Int_t DdlIdFromBusPatchId(Int_t buspatchid) const
void SetExternalDimensionName(Int_t index, const char *value)
AliMUONVCalibParam * CreatePCBParam(Int_t detElemId, Int_t pcbIndex) const
virtual Int_t Size() const =0
The number of channels handled by this object.
The top container class for DDLs, det elements and bus patched.
Definition: AliMpDDLStore.h:35
Bool_t UpdateNumberOfEvents(TArrayI *nevents)
virtual void SetValueAsFloat(Int_t i, Int_t j, Float_t value)=0
Set one value, for channel i, dimension j. Consider value is a float.
Int_t fDimension
the dimension of the data
virtual Bool_t Replace(const AliMUONVStore &store)=0
Replace values.
Bool_t IsDone() const
virtual Double_t BusPatch(Int_t busPatchId, Int_t dim=0) const
Get the value for a given buspatch and given dimension.
AliMp::StationType GetStationType() const
station 3,4,5 (slats)
AliMUONVStore * fHistos
the lowest histograms we have
virtual Int_t GetSize() const =0
The number of objects stored.
Int_t GetDEfromBus(Int_t busPatchId) const
virtual Bool_t HasManu(Int_t detElemId, Int_t manuId) const =0
Whether we have data for a given manu.
AliMUONVStore * fBusPatchValues
the bus patch store
AliMUONVCalibParam * ChannelParam(Int_t detElemId, Int_t manuId, const AliMUONVCalibParam *external=0x0) const
virtual Double_t Channel(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t dim=0) const =0
Get the value for a given channel and given dimension.
Collection of methods usefull to DCS handling for MUON TRK and TRG.
Definition: AliMpDCSNamer.h:21
const AliMpVSegmentation * GetMpSegmentationByElectronics(Int_t detElemId, Int_t elCardID, Bool_t warn=true) const
virtual void SetDimensionName(Int_t index, const char *value)
Set the name of a given dimension.
virtual void SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value)
Same as above but w/o bound checking.
Int_t NumberOfPCBs(Int_t detElemId) const
void BuildFromBPStore(const AliMUONVStore &bpStore)
Int_t * fHistogramming
whether we should histogram the dimension(s)
TObjArray * fExternalDimensionNames
the names of the external (i.e. original) dimensions
virtual Bool_t HasChamber(Int_t chamberId) const
Whether we have data for a given chamber.
void Add2D(const AliMUONVStore &src, AliMUONVStore &dest) const
AliMpDetElement * CurrentDE() const
Int_t CurrentDEId() const
virtual Bool_t Replace(const AliMUONVStore &channelValues)
Replace values.
AliMUONVCalibParam * CreateDouble(const AliMUONVCalibParam &param, Int_t detElemId, Int_t manuId) const
Double_t Value(const AliMUONVCalibParam &param, Int_t i, Int_t dim, Int_t ddlId) const
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
virtual Double_t ValueAsDouble(Int_t i, Int_t j=0) const
void BuildFromDEStore(const AliMUONVStore &deStore)
Int_t GetManuId(Int_t index) const
virtual Bool_t HasPCB(Int_t detElemId, Int_t pcbIndex) const
Whether we have data for a given PCB.
Int_t Dimension() const
The number of values we actually store for each item.
static AliMpManuStore * Instance(Bool_t warn=true)
static Bool_t LoadManuStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:203
The class defines the electronics properties of detection element.
AliMUONVCalibParam * CreateChamberParam(Int_t chamberId) const
virtual Bool_t Add(TObject *object)
Add an object to the store.
Bool_t Next(Int_t &detElemId, Int_t &manuId)
Class to loop over all manus of MUON Tracker.
MpPair_t GetDetElemIdManu(Int_t manuSerial) const
AliMUONVStore * fChamberValues
the chamber store
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Float_t DetectionElementProbability(Int_t detElemId) const
void Print(const char *method, TStopwatch &timer, Int_t n)
AliMUONVStore * fPCBValues
the pcb store
virtual Bool_t HasBusPatch(Int_t busPatchId) const
Whether we have data for a given buspath.
Container of calibration values for a given number of channels.
virtual void Print(Option_t *wildcard, Option_t *opt) const
Print, with option, all objects whose name matches wildcard.
virtual void DisableManuLevel()
Disable storing values at the manu level.
virtual TString DimensionName(Int_t dim) const
Get the name of a given (internal) dimension.
static AliMpDDLStore * Instance(Bool_t warn=true)
virtual Bool_t IsSingleEvent() const
Whether we can be run.
static Int_t GetChamberId(Int_t detElemId, Bool_t warn=true)
static Int_t ManuNofChannels()
Max number of channels per manu.
virtual void NumberOfEventsChanged()
Signal to indicate that the number of events changed.
virtual Double_t PCB(Int_t detElemId, Int_t pcbIndex, Int_t dim=0) const
Get the value for a given PCDB and given dimension.
TObjArray * fDimensionNames
the names of the (internal) dimensions
void SetInternalDimensionName(Int_t index, const char *value)
Bool_t fIsBustPatchLevelEnabled
whether we allow storing of bus patches (fBusPatchValues) values
Int_t GetBusPatchId(Int_t detElemId, Int_t manuId) const
virtual Double_t Chamber(Int_t chamberId, Int_t dim=0) const
Get the value for a given chamber and given dimension.
virtual Bool_t IsHistogrammed(Int_t dim) const
Whether we have histograms for a given dimension, or not.
virtual AliMUONVStore * Create() const =0
Create an empty copy of this.
void AddCalibParams(const AliMUONVCalibParam &src, AliMUONVCalibParam &dest) const
char * prefix
Int_t DdlIdFromDetElemId(Int_t detelemid) const
AliMUONVCalibParam * CreateBusPatchParam(Int_t busPatch) const
Float_t ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
virtual Int_t ID0() const
First id of this object.
Int_t DdlIdFromChamberId(Int_t chamberid) const
virtual Int_t ID1() const
Second id of this object (might not be required)
Int_t GetParts(AliMUONVCalibParam *external, AliMUONVCalibParam *&chamber, AliMUONVCalibParam *&de, AliMUONVCalibParam *&busPatch, AliMUONVCalibParam *&pcb, AliMUONVCalibParam *&manu, AliMUONVCalibParam *&channel, AliMpDetElement *&mpde)
virtual Bool_t HasDetectionElement(Int_t detElemId) const =0
Whether we have data for a given detection element.
virtual Int_t IndexOfNumberDimension() const
Index of the dimension containing the number of time an item was hit.
Implementation of AliMUONVCalibParam for tuples of double.
virtual Double_t DetectionElement(Int_t detElemId, Int_t dim=0) const
Get the value for a given DE and given dimension.
virtual void DisableChannelLevel()
Disable storing values at the channel level.
AliMpBusPatch * GetBusPatch(Int_t busPatchId, Bool_t warn=true) const
Int_t GetDdlId() const
Return the Ddl Id.
Definition: AliMpBusPatch.h:97
virtual void SetDimensionName(Int_t index, const char *value)=0
Set the name of a given dimension.
AliMUONVCalibParam * BusPatchParam(Int_t busPatch, Bool_t create=kFALSE) const
A very memory compact histogram to hold some tracker distributions.
virtual TObject * FindObject(UInt_t identifier) const
Return the object stored with id.
virtual Double_t Count(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
Get the number of times a given channel was hit.
Implementation of AliMUONVStore.
Int_t Fill(Double_t value)
void MakeHistogramForDimension(Int_t index, Bool_t value, Double_t xmin=0.0, Double_t xmax=4096.0)
Select a dimension to be histogrammed (if CanHistogram==kTRUE) only.
AliMUONVStore * fChannelValues
the channel store
AliMUONVStore * fDEValues
the detection element store
Int_t NofChannelsInManu(Int_t manuId) const
virtual Int_t ValueAsInt(Int_t i, Int_t j=0) const =0
Bool_t Add(const AliMUONTrackerData &data)
void Add1D(const AliMUONVStore &src, AliMUONVStore &dest) const
virtual Bool_t HasManu(Int_t detElemId, Int_t manuId) const
Whether we have data for a given manu.
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
Int_t GetDdlId() const
Return DDL Id.
static void DispatchValue(AliMUONVCalibParam &param, Int_t index, Double_t y, Double_t ey, Int_t nchannels)
void FillHisto(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t dim, Double_t value)
Double_t fXmax
max x value for histograms
virtual Bool_t Add(TObject *object)=0
Add an object to the store.
Int_t GetNofBusPatches() const
The class defines the properties of BusPatch.
Definition: AliMpBusPatch.h:21
virtual Int_t Dimension() const =0
j indices in following methods are valid from 0 to Dimension()-1.
AliMUONVCalibParam * DetectionElementParam(Int_t detElemId, Bool_t create=kFALSE) const
Int_t MpPair_t
virtual Double_t Manu(Int_t detElemId, Int_t manuId, Int_t dim=0) const
Get the value for a given manu and given dimension.
static const Int_t fgkExtraDimension
to hold extra information
The abstract base class for the segmentation.
Implementation of AliMUONVStore.
Definition: AliMUON1DMap.h:21
Int_t GetBusPatchId(Int_t index) const
AliMUONVCalibParam * CreateDetectionElementParam(Int_t detElemId) const
Int_t fNevents
the number of events treated
virtual Bool_t Add(const AliMUONVStore &store, TArrayI *arrayOfNofEventsPerDDL=0x0)=0
Add values for one event from one full store.
Int_t PairFirst(MpPair_t pair)
Decode the first integer from encoded pair.
virtual Int_t NumberOfDimensions() const
Returns the number of dimensions (i.e. the number of values) each element has.
virtual Bool_t HasDetectionElement(Int_t detElemId) const
Whether we have data for a given detection element.
AliMUONVCalibParam * CreateManuParam(Int_t detElemInd, Int_t manuId) const
static AliMUONVTrackerData * CompareData(const AliMUONVTrackerData &d1, const AliMUONVTrackerData &d2, const char *outname, Double_t(*diff)(Double_t, Double_t))
virtual TString ExternalDimensionName(Int_t dim) const =0
Get the name of a given (external) dimension.
Object to hold the list of elements we want to reject from the reconstruction.
virtual void Clear(Option_t *opt="")
Reset the data.
virtual Int_t ExternalDimension() const
The number of values we are inputting.
virtual TObject * FindObject(UInt_t i) const
Find an object using a single id.
virtual Int_t NumberOfDimensions() const =0
The number of dimensions we are handling.
AliMUONVCalibParam * ManuParam(Int_t detElemId, Int_t manuId, Bool_t create=kFALSE) const
AliMUONSparseHisto * GetManuSparseHisto(Int_t detElemId, Int_t manuId, Int_t dim=0)
virtual Long64_t Merge(TCollection *list)
To allow merging of different objects.
Float_t BusPatchProbability(Int_t busPatchId) const
virtual void Clear(Option_t *opt="")=0
Clear ourselves (i.e. Reset)
Bool_t InternalAdd(const AliMUONVStore &store, TArrayI *nevents)
Bool_t IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
Bool_t ExportAsASCIIOccupancyFile(const char *filename, Int_t runNumber) const
Bool_t Add(const AliMUONSparseHisto &h)
Int_t PairSecond(MpPair_t pair)
Decode the second integer from encoded pair.
Int_t * fNofEventsPerDDL
the number of events treated (per DDL)
Base class for MUON data stores.
Definition: AliMUONVStore.h:22
Int_t NofChannels() const
Return the number of channels in this detection element.
void GetDEManu(const AliMUONVCalibParam &param, Int_t &detElemId, Int_t &manuId) const
static const Int_t fgkVirtualExtraDimension
to give access to information not stored, but computed on the fly
static Bool_t LoadAll(Bool_t warn=false)
Definition: AliMpCDB.cxx:196
AliMUONVCalibParam * ChamberParam(Int_t chamberId, Bool_t create=kFALSE) const
Base class for MUON data that can be presented at different levels in the hierarchy of the MUON syste...
Int_t GetId() const
Return Id.
AliMUONSparseHisto * GetChannelSparseHisto(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t dim=0)
Int_t GetDDLfromBus(Int_t busPatchId) const
AliMUONVStore * fManuValues
the manu store
virtual Int_t ExternalDimension() const =0
The number of dimensions we are inputting.
AliMUONTrackerData(const char *name="", const char *title="", Int_t dimension=0, Bool_t issingleevent=kFALSE)
virtual TObject * FindObject(const char *name) const
Find an object by name.
Bool_t fIsPCBLevelEnabled
whether we allow storing of PCB values (fPCBValues)
virtual Double_t ValueAsDoubleFast(Int_t i, Int_t j=0) const
virtual void SetValueAsDouble(Int_t i, Int_t j, Double_t value)
AliMUONVCalibParam * PCBParam(Int_t detElemId, Int_t pcbIndex, Bool_t create=kFALSE) const
Bool_t fIsChannelLevelEnabled
whether we allow storing of channel (fChannelValues) values