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