]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTrackerData.cxx
Flexible pt range for the efficiency histogramming
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerData.cxx
index f377a5ac421d881c0554e6435610c2719f071e05..8e272510fc9f91da17576e980100559af9acb138 100644 (file)
@@ -24,7 +24,6 @@
 #include "AliMUON1DMap.h"
 #include "AliMUON2DMap.h"
 #include "AliMUONCalibParamND.h"
-#include "AliMUONConstants.h"
 #include "AliMUONRejectList.h"
 #include "AliMUONSparseHisto.h"
 #include "AliMUONVStore.h"
@@ -57,6 +56,8 @@
 ///
 /// \author Laurent Aphecetche, Subatech
 
+using std::cout;
+using std::endl;
 ///\cond CLASSIMP
 ClassImp(AliMUONTrackerData)
 ///\endcond
@@ -253,7 +254,7 @@ fNofEventsPerDDL(0x0)
 
 //_____________________________________________________________________________
 AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
-                                       const AliMUONVStore& deValues, Int_t val)
+                                       const AliMUONVStore& deOrBpValues, Int_t val)
 : AliMUONVTrackerData(name,title),
 fIsSingleEvent(kFALSE),
 fChannelValues(0x0),
@@ -278,26 +279,42 @@ fIsPCBLevelEnabled(kFALSE),
 fNofDDLs(0),
 fNofEventsPerDDL(0x0)
 {  
-  /// ctor with values at the detection element level
+  /// ctor with values at the detection element OR bus patch level
   /// In this case, we force fIsChannelLevelEnabled = fIsManuLevelEnabled = kFALSE
   /// ctor
   
-  if (deValues.GetSize()==0)
+  if (deOrBpValues.GetSize()==0)
   {
     AliFatal("Cannot create a tracker data from nothing in that case !");
   }
   
-  if ( val != 1 ) 
-  {
-    AliFatal("Wrong parameter. For DE, must be 1");
-  }
-  
   if ( !AliMpDDLStore::Instance(kFALSE) && !AliMpManuStore::Instance(kFALSE) )
   {
     AliError("Cannot work without (full) mapping");
     return;
   }
   
+  if ( val == 1 ) 
+  {
+    BuildFromDEStore(deOrBpValues);
+  }
+  else if ( val == 2 )
+  {
+    BuildFromBPStore(deOrBpValues);
+  }
+  else
+  {
+    AliFatal("Wrong parameter. Must be 1 or 2");
+  }
+  
+  
+}
+
+//_____________________________________________________________________________
+void AliMUONTrackerData::BuildFromDEStore(const AliMUONVStore& deValues)
+{
+  /// Fill internals from a store of values at the detection element level
+  
   TIter next(deValues.CreateIterator());
   AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
   
@@ -326,7 +343,7 @@ fNofEventsPerDDL(0x0)
   while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
   {
     Int_t detElemId = external->ID0();
-
+    
     AliMpDetElement* mpde = AliMpDDLStore::Instance()->GetDetElement(detElemId,kFALSE);
     
     if (!mpde)
@@ -338,7 +355,7 @@ fNofEventsPerDDL(0x0)
     Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
     AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
     AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
-
+    
     AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,detElemId,0,0);
     // as external, but without event count
     wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
@@ -383,7 +400,104 @@ fNofEventsPerDDL(0x0)
   }  
   
   UpdateNumberOfEvents(&nevents);
+}
+
+//_____________________________________________________________________________
+void AliMUONTrackerData::BuildFromBPStore(const AliMUONVStore& bpValues)
+{
+  /// Fill internals from a store of values at the bus patch level
+  
+  fIsBustPatchLevelEnabled = kTRUE;
+  
+  TIter next(bpValues.CreateIterator());
+  AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
+  
+  Int_t dimension = ( m->Dimension() - fgkExtraDimension - fgkVirtualExtraDimension ) / 2;
+  
+  fDimension = External2Internal(dimension)+fgkExtraDimension;
+  
+  fDimensionNames = new TObjArray(fDimension+fgkVirtualExtraDimension);
+  fExternalDimensionNames = new TObjArray(dimension);
+  fExternalDimension = dimension;
+  fHistogramming = new Int_t[fExternalDimension];
+  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
+  
+  fExternalDimensionNames->SetOwner(kTRUE);
+  fDimensionNames->SetOwner(kTRUE);  
+  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
+  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
+  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
+  Clear();
+  TArrayI nevents(AliDAQ::NumberOfDdls("MUONTRK"));
+  AssertStores();
+  
+  next.Reset();
+  AliMUONVCalibParam* external;
+  
+  while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
+  {
+    Int_t busPatchId = external->ID0();
+    
+    AliMpBusPatch* mpbp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId,kFALSE);
+    
+    if (!mpbp)
+    {
+      AliError(Form("Got an invalid buspatchId (%d) from external store",busPatchId));
+      continue;
+    }
+    
+    Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
+    Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
+    AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
+    AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
+    AliMUONVCalibParam* bp = BusPatchParam(busPatchId,kTRUE);
+    
+    AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,busPatchId,0,0);
+    // as external, but without event count
+    wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
+    wec->SetValueAsDouble(0,1,external->ValueAsDouble(0,1));
+    wec->SetValueAsDouble(0,2,external->ValueAsDouble(0,2));
+    wec->SetValueAsDouble(0,3,external->ValueAsDouble(0,3));
+    
+    Int_t n1 = bp->ValueAsInt(0,IndexOfNumberDimension());
+    Int_t n2 = external->ValueAsInt(0,IndexOfNumberDimension());
+    if  ( n1 != n2 )
+    {
+      AliError(Form("Incoherent number of dimensions for BP%d : %d vs %d",
+                    busPatchId,n1,n2));
+      continue;
+    }
+    
+    Int_t nevt = external->ValueAsInt(0,4);
+    
+    Int_t ddl = mpbp->GetDdlId();
+    
+    if ( nevents[ddl] == 0 ) 
+    {
+      nevents[ddl] = nevt;
+    }
+    else
+    {
+      if ( nevents.At(ddl) != nevt ) 
+      {
+        AliError(Form("Nevt mismatch for BP %5d  DDL %d : %d vs %d",
+                      busPatchId,ddl,nevents.At(ddl),nevt));
+        continue;
+      }
+    }
+    
+    for ( Int_t i = 0; i < wec->Dimension()-1; ++i ) 
+    {
+      bp->SetValueAsDouble(0,i,bp->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
+      
+      de->SetValueAsDouble(0,i,de->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
+      
+      chamber->SetValueAsDouble(0,i,chamber->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
+    }    
+    delete wec;
+  }  
   
+  UpdateNumberOfEvents(&nevents);  
 }
 
 //_____________________________________________________________________________
@@ -434,11 +548,11 @@ fNofEventsPerDDL(0x0)
   AssertStores();
   
   
-  for ( Int_t chamberId = 0; chamberId < AliMUONConstants::NCh(); ++chamberId ) 
+  for ( Int_t chamberId = 0; chamberId < AliMpConstants::NofChambers(); ++chamberId ) 
   {
-    AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
+//    AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
 
-    // FIXME : update the chamber value !
+    // FIXME : update the chamber value ?
     
     AliMpDEIterator deit;
   
@@ -544,6 +658,8 @@ AliMUONTrackerData::Add(const AliMUONTrackerData& data)
 
   // First cross check we have compatible objects.
   
+  AliCodeTimerAuto("",0);
+  
   if ( fIsChannelLevelEnabled != data.fIsChannelLevelEnabled ) 
   {
     AliError("Incompatible IsChannelLevelEnabled status");
@@ -665,7 +781,10 @@ AliMUONTrackerData::Add(const AliMUONTrackerData& data)
     }
   }
   
-  fNevents =  TMath::Max(fNevents,data.fNevents);
+  for ( Int_t i = 0 ; i < fNofDDLs; ++i ) 
+  {
+    fNevents = TMath::Max(fNevents,fNofEventsPerDDL[i]);
+  }
   
   return kTRUE;
 }
@@ -727,7 +846,7 @@ AliMUONTrackerData::AddCalibParams(const AliMUONVCalibParam& src, AliMUONVCalibP
   {
     for ( Int_t j = 0; j < src.Dimension(); ++j )
     {
-      dest.SetValueAsFloat(i,j,src.ValueAsFloat(i,j));
+      dest.SetValueAsFloat(i,j,dest.ValueAsFloat(i,j)+src.ValueAsFloat(i,j));
     }
   }
 }
@@ -798,6 +917,11 @@ AliMUONTrackerData::AssertStores()
     // get number of bus patches and number of detection element
     // to initialize fBusPatchValues and fDEValues below
     
+    if (!AliMpDDLStore::Instance(false))
+    {
+      AliMpCDB::LoadAll();
+    }
+    
     TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
     while ( next() ) ++numberOfBusPatches;
     AliMpDEIterator deIt;
@@ -2162,4 +2286,4 @@ void AliMUONTrackerData::DispatchValue(AliMUONVCalibParam& param,
   param.SetValueAsDouble(index,2,sumn);
   param.SetValueAsDouble(index,3,nchannels);
   
-}
\ No newline at end of file
+}