LCOV - code coverage report
Current view: top level - MUON/MUONcalib - AliMUONTrackerData.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 288 1027 28.0 %
Date: 2016-06-14 17:26:59 Functions: 30 84 35.7 %

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

Generated by: LCOV version 1.11