]> 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 eb6215fffbdeda0a6db58a1db4623b9af9b91d56..8e272510fc9f91da17576e980100559af9acb138 100644 (file)
@@ -24,6 +24,7 @@
 #include "AliMUON1DMap.h"
 #include "AliMUON2DMap.h"
 #include "AliMUONCalibParamND.h"
+#include "AliMUONRejectList.h"
 #include "AliMUONSparseHisto.h"
 #include "AliMUONVStore.h"
 #include "AliMpBusPatch.h"
@@ -55,6 +56,8 @@
 ///
 /// \author Laurent Aphecetche, Subatech
 
+using std::cout;
+using std::endl;
 ///\cond CLASSIMP
 ClassImp(AliMUONTrackerData)
 ///\endcond
@@ -251,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),
@@ -276,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());
   
@@ -324,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)
@@ -336,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));
@@ -381,7 +400,225 @@ 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);  
+}
+
+//_____________________________________________________________________________
+AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
+                                       const AliMUONRejectList& rejectList)
+: AliMUONVTrackerData(name,title),
+fIsSingleEvent(kFALSE),
+fChannelValues(0x0),
+fManuValues(0x0),
+fBusPatchValues(0x0),
+fDEValues(0x0),
+fChamberValues(0x0),
+fPCBValues(0x0),
+fDimension(External2Internal(1)+fgkExtraDimension),
+fNevents(0),
+fDimensionNames(new TObjArray(fDimension+fgkVirtualExtraDimension)),
+fExternalDimensionNames(new TObjArray(1)),
+fExternalDimension(1),
+fHistogramming(new Int_t[fExternalDimension]),
+fHistos(0x0),
+fXmin(0.0),
+fXmax(0.0),
+fIsChannelLevelEnabled(kTRUE),
+fIsManuLevelEnabled(kTRUE),
+fIsBustPatchLevelEnabled(kTRUE),
+fIsPCBLevelEnabled(kFALSE),
+fNofDDLs(0),
+fNofEventsPerDDL(0x0)
+{  
+  
+   /// ctor with values from the given rejectlist
+    
+  if ( !AliMpDDLStore::Instance(kFALSE) && !AliMpManuStore::Instance(kFALSE) )
+  {
+    AliError("Cannot work without (full) mapping");
+    return;
+  }
+  
+  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();
+  
+  
+  for ( Int_t chamberId = 0; chamberId < AliMpConstants::NofChambers(); ++chamberId ) 
+  {
+//    AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
+
+    // FIXME : update the chamber value ?
+    
+    AliMpDEIterator deit;
+  
+    deit.First(chamberId);
+
+    while ( !deit.IsDone() ) 
+    {
+      AliMpDetElement* mpde = deit.CurrentDE();
+      
+      Int_t detElemId = mpde->GetId();
+
+      AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
+
+      DispatchValue(*de,0,rejectList.DetectionElementProbability(detElemId),0.0,mpde->NofChannels());
+      
+      for ( Int_t iBusPatch = 0; iBusPatch < mpde->GetNofBusPatches(); ++iBusPatch ) 
+      {
+        Int_t busPatchId = mpde->GetBusPatchId(iBusPatch);
+        
+        AliMUONVCalibParam* bp = BusPatchParam(busPatchId,kTRUE);
+
+        AliMpBusPatch* mpbp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
+
+        Int_t nch(0);
+        
+        for ( Int_t iManu = 0 ;iManu < mpbp->GetNofManus(); ++iManu )
+        {
+          Int_t manuId = mpbp->GetManuId(iManu);
+          
+          nch += mpde->NofChannelsInManu(manuId);
+          
+          AliMUONVCalibParam* manu = ManuParam(detElemId,manuId,kTRUE);
+          
+          DispatchValue(*manu,0,rejectList.ManuProbability(detElemId,manuId),0.0,mpde->NofChannelsInManu(manuId));
+          
+          AliMUONVCalibParam* c = ChannelParam(detElemId,manuId);
+          
+          if (!c)
+          {
+            c = new AliMUONCalibParamND(Dimension(),
+                                        AliMpConstants::ManuNofChannels(),
+                                        detElemId,
+                                        manuId,
+                                        0.0);
+            fChannelValues->Add(c);
+          }
+          
+          for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
+          {
+            DispatchValue(*c,manuChannel,rejectList.ChannelProbability(detElemId,manuId,manuChannel),0.0,1);
+          }
+        }
+
+        DispatchValue(*bp,0,rejectList.BusPatchProbability(busPatchId),0.0,nch);
+
+      }
+      
+      deit.Next();
+    }
+  }
+  
+  
+  SetDimensionName(0,"RejectProba");
+
+  UpdateNumberOfEvents(0x0);
 }
 
 //_____________________________________________________________________________
@@ -421,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");
@@ -542,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;
 }
@@ -604,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));
     }
   }
 }
@@ -675,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;
@@ -1601,7 +1848,7 @@ AliMUONTrackerData::Merge(TCollection* list)
   while ( ( o = next() ) )
   {
     const AliMUONTrackerData* data = dynamic_cast<const AliMUONTrackerData*>(o);
-    if (!o)
+    if (!data)
     {
       AliError(Form("Object named %s is not an AliMUONTrackerData ! Skipping it",
                     o->GetName()));
@@ -2020,5 +2267,23 @@ AliMUONTrackerData::ExportAsASCIIOccupancyFile(const char* filename, Int_t runNu
   out.close();
   return kTRUE;
 }
-
-
+  
+//_____________________________________________________________________________
+void AliMUONTrackerData::DispatchValue(AliMUONVCalibParam& param, 
+                                       Int_t index,
+                                       Double_t y, 
+                                       Double_t ey,
+                                       Int_t nchannels)
+{
+  /// fills the calibparam with a single value
+  
+  Double_t sumn = 1000.0; // or any value strictly above 1
+  Double_t sumw = sumn*y;
+  Double_t sumw2 = (sumn-1)*ey*ey+sumw*sumw/sumn;
+  
+  param.SetValueAsDouble(index,0,sumw);
+  param.SetValueAsDouble(index,1,sumw2);
+  param.SetValueAsDouble(index,2,sumn);
+  param.SetValueAsDouble(index,3,nchannels);
+  
+}