- Disentangle masks effect from trigger chamber efficiency estimation.
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerDataMaker.cxx
index 1af7f1f..e640c03 100644 (file)
@@ -33,6 +33,7 @@
 #include "AliMUONCalibParamND.h"
 #include "AliMUONCalibrationData.h"
 #include "AliMUONDigitCalibrator.h"
+#include "AliMUONLogger.h"
 #include "AliMUONRawStreamTrackerHP.h"
 #include "AliMUONTrackerData.h"
 #include "AliMpDDLStore.h"
@@ -52,6 +53,7 @@ AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*)
 AliMUONVTrackerDataMaker(),
 fRawReader(0x0),
 fAccumulatedData(0x0),
+fIsOwnerOfAccumulatedData(kTRUE),
 fOneEventData(0x0),
 fDigitCalibrator(0x0),
 fCalibrationData(0x0), 
@@ -61,7 +63,14 @@ fNumberOfEvents(0),
 fRunNumber(0),
 fIsRunning(kFALSE),
 fIsOwnerOfRawReader(kFALSE),
-fIsEventByEvent(kFALSE)
+fIsEventByEvent(kFALSE),
+fLogger(0x0),
+fLastEventWasEmpty(kFALSE),
+fNumberOfPhysicsEvents(0),
+fNumberOfGoodPhysicsEvents(0),
+fTryRecover(kFALSE),
+fFirstEvent(-1),
+fLastEvent(-1)
 {
 /// Root IO ctor
 }
@@ -79,6 +88,7 @@ AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoPar
 AliMUONVTrackerDataMaker(),
 fRawReader(rawReader),
 fAccumulatedData(0x0),
+fIsOwnerOfAccumulatedData(kTRUE),
 fOneEventData(new AliMUON2DMap(true)),
 fDigitCalibrator(0x0),
 fCalibrationData(0x0), 
@@ -88,7 +98,14 @@ fNumberOfEvents(0),
 fRunNumber(runNumber),
 fIsRunning(kFALSE),
 fIsOwnerOfRawReader(kFALSE),
-fIsEventByEvent(kFALSE)
+fIsEventByEvent(kFALSE),
+fLogger(0x0),
+fLastEventWasEmpty(kFALSE),
+fNumberOfPhysicsEvents(0),
+fNumberOfGoodPhysicsEvents(0),
+fTryRecover(kFALSE),
+fFirstEvent(-1),
+fLastEvent(-1)
 {
   /// Ctor in which this object will NOT be the owner of the reader
   /// and can NOT apply rewind to it, nor use Next on it. 
@@ -108,6 +125,7 @@ AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoPar
 AliMUONVTrackerDataMaker(),
 fRawReader(rawReader),
 fAccumulatedData(0x0),
+fIsOwnerOfAccumulatedData(kTRUE),
 fOneEventData(new AliMUON2DMap(true)),
 fDigitCalibrator(0x0),
 fCalibrationData(0x0), 
@@ -117,14 +135,20 @@ fNumberOfEvents(0),
 fRunNumber(0),
 fIsRunning(kFALSE),
 fIsOwnerOfRawReader(kTRUE),
-fIsEventByEvent(kFALSE)
+fIsEventByEvent(kFALSE),
+fLogger(0x0),
+fLastEventWasEmpty(kFALSE),
+fNumberOfPhysicsEvents(0),
+fNumberOfGoodPhysicsEvents(0),
+fTryRecover(kFALSE),
+fFirstEvent(-1),
+fLastEvent(-1)
 {
   /// Ctor in which we take the ownership of the rawReader, so we can rewind
   /// and advance it as we wish
   
-  if (fRawReader) 
+  if ( fRawReader && fRawReader->NextEvent() ) 
   {
-    fRawReader->NextEvent(); // to be sure to get run number available
     fRunNumber = fRawReader->GetRunNumber();
     fRawReader->RewindEvents();
   }
@@ -138,6 +162,7 @@ AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t
 AliMUONVTrackerDataMaker(),
 fRawReader(rawReader),
 fAccumulatedData(0x0),
+fIsOwnerOfAccumulatedData(kTRUE),
 fOneEventData(new AliMUON2DMap(true)),
 fDigitCalibrator(0x0),
 fCalibrationData(0x0), 
@@ -147,11 +172,18 @@ fNumberOfEvents(0),
 fRunNumber(0),
 fIsRunning(kFALSE),
 fIsOwnerOfRawReader(kTRUE),
-fIsEventByEvent(kFALSE)
+fIsEventByEvent(kFALSE),
+fLogger(0x0),
+fLastEventWasEmpty(kFALSE),
+fNumberOfPhysicsEvents(0),
+fNumberOfGoodPhysicsEvents(0),
+fTryRecover(kFALSE),
+fFirstEvent(-1),
+fLastEvent(-1)
 {
-  if (fRawReader) 
+  /// Ctor from raw data reader
+  if ( fRawReader && fRawReader->NextEvent() ) 
   {
-    fRawReader->NextEvent(); // to be sure to get run number available
     fRunNumber = fRawReader->GetRunNumber();
     fRawReader->RewindEvents();
   }
@@ -169,7 +201,8 @@ AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
                               Double_t xmin, Double_t xmax)
 {
   /// "designated constructor"
-  Bool_t calibrate = ( fOCDBPath.Length() > 0 );
+
+  Bool_t calibrate = ( strlen(calibMode) > 0 );
   
   TString name;
   TString type("RAW");
@@ -211,12 +244,17 @@ AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
     // out of sync)
     // But with the current CDBManager implementation, I don't know how to solve
     // this better (e.g. to avoid clearing cache messages and so on).
+
+    AliCDBStorage* storage(0x0);
     
-    AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
-    
-    if ( storage->GetURI() != fOCDBPath.Data() ) 
+    if ( fOCDBPath.Length() > 0 )
     {
-      AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
+      storage = AliCDBManager::Instance()->GetDefaultStorage();
+
+      if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
+      {
+        AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
+      }
     }
     
     fCalibrationData->Pedestals();
@@ -225,7 +263,7 @@ AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
     fCalibrationData->HV();
     fCalibrationData->Capacitances();
     
-    if ( storage->GetURI() != fOCDBPath.Data() ) 
+    if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
     {
       AliCDBManager::Instance()->SetDefaultStorage(storage);
     }
@@ -241,7 +279,7 @@ AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
 /// dtor
 
   delete fOneEventData;
-  delete fAccumulatedData;
+  if ( fIsOwnerOfAccumulatedData ) delete fAccumulatedData;
   if ( fIsOwnerOfRawReader ) delete fRawReader;
   delete fCalibrationData;
   delete fDigitCalibrator;
@@ -267,7 +305,9 @@ AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
   fSource += other.fSource;
   
   fNumberOfEvents += other.fNumberOfEvents;
-  
+  fNumberOfPhysicsEvents += other.fNumberOfPhysicsEvents;
+  fNumberOfGoodPhysicsEvents += other.fNumberOfGoodPhysicsEvents;
+
   TList list;
   list.Add(other.fAccumulatedData);
   
@@ -288,36 +328,43 @@ AliMUONTrackerDataMaker::NextEvent()
     return kFALSE;
   }
   
-  AliCodeTimerAuto("");
-  
-  static Int_t nphysics(0);
-  static Int_t ngood(0);
+  AliCodeTimerAuto("",0);
   
   if ( !IsRunning() ) return kTRUE;
   
-  Bool_t ok = fRawReader->NextEvent();
+  Bool_t ok(kTRUE);
   
-  if (!ok) 
+  if ( fLastEvent >= fFirstEvent && fLastEvent > 0 ) // do we have an event range to consider ?
   {
-    return kFALSE;
+    // skip up to first event
+    
+    while ( (fNumberOfEvents-1) < fFirstEvent && ( ok = fRawReader->NextEvent() ) ) 
+    {
+      ++fNumberOfEvents; 
+    }
+    
+    if ( ok && (fNumberOfEvents-1) <= fLastEvent ) 
+    {
+      ok = fRawReader->NextEvent();
+    }
+    else
+    {
+      fNumberOfEvents=fLastEvent+1;
+      return kFALSE;
+    }
   }
-  
-  Int_t eventType = fRawReader->GetType();
-  
-  ++fNumberOfEvents;
-  
-  if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) 
+  else
   {
-    return kTRUE; // for the moment
+    // no event range, just proceed...
+    ok = fRawReader->NextEvent();
   }
   
-  ++nphysics;
+  if (!ok) 
+  {
+    return kFALSE;
+  }
   
-       Bool_t pok = ProcessEvent();
-       
-       if ( pok ) ++ngood;
-       
-       AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
+       ProcessEvent();
        
        return kTRUE;  
 }
@@ -335,12 +382,42 @@ Bool_t AliMUONTrackerDataMaker::ProcessEvent()
   /// duplicate this critical piece of calibration code !
   ///
   
-  AliCodeTimerAuto("");
+  ++fNumberOfEvents;
   
-  AliMUONRawStreamTrackerHP stream(fRawReader);
+  Int_t eventType = fRawReader->GetType();
+  
+  if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) 
+  {
+    return kTRUE; // for the moment
+  }
+  
+  ++fNumberOfPhysicsEvents;
+  
+  fLastEventWasEmpty = kFALSE;
+  
+  AliCodeTimerAuto("",0);
   
+  AliMUONRawStreamTrackerHP stream(fRawReader);
+
   stream.DisableWarnings();
-//  stream.EnabbleErrorLogger();
+  stream.DisableRawReaderErrorLogger();
+  stream.DisableMUONErrorLogger();
+
+  if ( fTryRecover ) 
+  {
+    stream.TryRecover(kTRUE);
+  }
+  else
+  {
+    stream.TryRecover(kFALSE);
+  }
+  
+  if (fLogger)
+  {
+    stream.EnableMUONErrorLogger();  
+    stream.SetMUONErrorLogger(fLogger);    
+    stream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
+  }
   
   const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
   TArrayI nevents(nddls);
@@ -381,7 +458,7 @@ Bool_t AliMUONTrackerDataMaker::ProcessEvent()
     {
       if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
       {
-        charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
+        charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
       }
       else
       {
@@ -399,9 +476,13 @@ Bool_t AliMUONTrackerDataMaker::ProcessEvent()
 
        if (!badEvent)
   {
-    fAccumulatedData->Add(*fOneEventData,&nevents);    
+    fAccumulatedData->Add(*fOneEventData,&nevents);  
+    if ( fOneEventData->GetSize() == 0 ) fLastEventWasEmpty = kTRUE;
+    ++fNumberOfGoodPhysicsEvents;
   }
-  
+    
+  AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,fNumberOfPhysicsEvents,fNumberOfGoodPhysicsEvents));
+       
   return !badEvent;
 }
 
@@ -424,6 +505,8 @@ void AliMUONTrackerDataMaker::Rewind()
   {
     fRawReader->RewindEvents();
     fNumberOfEvents=0;  
+    fNumberOfPhysicsEvents=0;
+    fNumberOfGoodPhysicsEvents=0;
   }
   else
   {
@@ -446,7 +529,7 @@ Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
   while ( ( o = next() ) )
   {
     const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
-    if (!o)
+    if (!data)
     {
       AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
                     o->GetName()));