Major rewriting using VStores (Laurent)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 17 Jun 2007 20:52:46 +0000 (20:52 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 17 Jun 2007 20:52:46 +0000 (20:52 +0000)
MUON/AliMUONRawWriter.cxx
MUON/AliMUONRawWriter.h
MUON/AliMUONRecoCheck.cxx
MUON/AliMUONRecoCheck.h
MUON/MUONRecoCheck.C

index 743d5cb..eff2320 100644 (file)
@@ -48,8 +48,8 @@
 #include "AliMUONBusStruct.h"
 #include "AliMUONConstants.h"
 #include "AliMUONDarcHeader.h"
-#include "AliMUONData.h"
-#include "AliMUONDigit.h"
+#include "AliMUONVDigit.h"
+#include "AliMUONVDigitStore.h"
 #include "AliMUONDspHeader.h"
 #include "AliMUONGlobalTrigger.h"
 #include "AliMUONLocalStruct.h"
@@ -59,6 +59,9 @@
 #include "AliMUONRegHeader.h"
 #include "AliMUONTriggerCrate.h"
 #include "AliMUONTriggerCrateStore.h"
+#include "AliMUONVTriggerStore.h"
+#include "AliMUONStopwatchGroup.h"
+#include "AliMUONStopwatchGroupElement.h"
 
 #include "AliMpDDLStore.h"
 #include "AliMpDDL.h"
@@ -76,7 +79,6 @@
 #include "AliDAQ.h"
 #include "AliLog.h"
 
-#include "TList.h"
 #include "TObjArray.h"
 #include "TStopwatch.h"
 #include <Riostream.h>
 ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
 /// \endcond
 
-namespace 
-{
-  enum ETimer { kWriteTracker, kWriteTrigger, kDigitLoop, kGetBusPatch, kTest, kLast };
-}
-
 //__________________________________________________________________________
-AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
+AliMUONRawWriter::AliMUONRawWriter()
   : TObject(),
-    fMUONData(data),
     fBlockHeader(new AliMUONBlockHeader()),
     fDspHeader(new AliMUONDspHeader()),
     fDarcHeader(new AliMUONDarcHeader()),
@@ -103,14 +99,13 @@ AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
     fCrateManager(new AliMUONTriggerCrateStore()),
     fScalerEvent(kFALSE),
     fHeader(),
-    fTimers(new TStopwatch[kLast])
-
+    fTimers(new AliMUONStopwatchGroup),
+    fBufferSize((((43*AliMpConstants::ManuNofChannels() + 4)*5 + 10)*5 + 8)*2),
+    fBuffer(new Int_t [fBufferSize])
 {
   /// Standard Constructor
 
   AliDebug(1,"Standard ctor");
-  fFile[0] = fFile[1] = 0x0;  
-  fFile[2] = fFile[3] = 0x0;  
 
   // setting data key to default value (only for writting)
   fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
@@ -119,36 +114,6 @@ AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
   // Crate manager
   fCrateManager->ReadFromFile();
 
-  // timers
-  for ( Int_t i = 0; i < kLast; ++i )
-  {
-    fTimers[i].Start(kTRUE); 
-    fTimers[i].Stop();
-  }
-  
-}
-
-//__________________________________________________________________________
-AliMUONRawWriter::AliMUONRawWriter()
-  : TObject(),
-    fMUONData(0),
-    fBlockHeader(0),
-    fDspHeader(0),
-    fDarcHeader(0),
-    fRegHeader(0),
-    fLocalStruct(0),
-    fDDLStore(0),
-    fCrateManager(0x0),
-    fScalerEvent(kFALSE),
-    fHeader(),
-    fTimers(0)
-{
-  /// Default Constructor
-
-  AliDebug(1,"Default ctor");   
-  fFile[0] = fFile[1] = 0x0;  
-  fFile[2] = fFile[3] = 0x0;  
-
 }
 
 //__________________________________________________________________________
@@ -163,118 +128,95 @@ AliMUONRawWriter::~AliMUONRawWriter(void)
   delete fDarcHeader;
   delete fRegHeader;
   delete fLocalStruct;
-
   delete fCrateManager;
-
-  for ( Int_t i = 0; i < kLast; ++i )
-  {
-    AliDebug(1, Form("Execution time (timer %d) : R:%7.2fs C:%7.2fs",i,
-                 fTimers[i].RealTime(),fTimers[i].CpuTime()));
-  }
-  
-  delete[] fTimers;
+  AliInfo("Timers:");
+  fTimers->Print();
+  delete fTimers;
+  delete[] fBuffer;
 }
 
 //____________________________________________________________________
-Int_t AliMUONRawWriter::Digits2Raw()
+Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
+                                   AliMUONVTriggerStore* triggerStore)
 {
   /// convert digits of the current event to raw data
 
+  AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2Raw");
+  
   Int_t idDDL;
   Char_t name[255];
 
-  fMUONData->GetLoader()->LoadDigits("READ");
-
-  fMUONData->SetTreeAddress("D,GLT");
-
-  fMUONData->ResetDigits();
-  fMUONData->ResetTrigger();
-  
-  // This will get both tracker and trigger digits.
-  fMUONData->GetDigits();
-  
-//  CheckDigits();
-
   // tracking chambers
   
-  for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt) {
-
-    // open files for one station
-    // cos station 3, 1/4 of DE's from 2 chambers has same DDL number 
-    idDDL = iSt * 4;
-    strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
-    fFile[0] = fopen(name,"w");
-
-    idDDL = (iSt * 4) + 1;
-    strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
-    fFile[1] = fopen(name,"w");
+  if ( digitStore ) 
+  {
+    AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2Raw for Tracker");
 
-    idDDL =  (iSt * 4) + 2;;
-    strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
-    fFile[2] = fopen(name,"w");
+    AliMpExMap busPatchMap(true);
 
-    idDDL =  (iSt * 4) + 3;
-    strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
-    fFile[3] = fopen(name,"w");
+    Int_t nDDLs = AliDAQ::NumberOfDdls("MUONTRK");
+    
+    Int_t nofBusPatches(0);
+    
+    for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL ) 
+    {
+      AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
+      nofBusPatches += ddl->GetNofBusPatches();
+    }
+    
+    busPatchMap.SetSize(nofBusPatches);
+    
+    Digits2BusPatchMap(*digitStore,busPatchMap);
 
-    WriteTrackerDDL(iSt);
-  
-    // reset and close when station has been processed
-    fclose(fFile[0]);
-    fclose(fFile[1]);
-    fclose(fFile[2]);
-    fclose(fFile[3]);
-     
+    for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL ) 
+    {
+      WriteTrackerDDL(busPatchMap,iDDL);
+    }
+    AliDebug(1,"Tracker written");
   }
  
-  AliDebug(1,"Tracker written");
-  
-  // trigger chambers
-  // open files
-  idDDL = 0;// MUTR
-  strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
-  fFile[0] = fopen(name,"w");
-
-  idDDL = 1;// MUTR
-  strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
-  fFile[1] = fopen(name,"w");
-
-   WriteTriggerDDL();
-  
-  // reset and close
-  fclose(fFile[0]);
-  fclose(fFile[1]);
-
-  AliDebug(1,"Trigger written");
-
-  fMUONData->ResetDigits();
-  fMUONData->ResetTrigger();  
-  fMUONData->GetLoader()->UnloadDigits();
+  if ( triggerStore )
+  {
+    AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2Raw for Trigger");
 
-  AliDebug(1,"muondata reset");
+    // trigger chambers
+    
+    FILE* file[2];
+    
+    // open files
+    idDDL = 0;// MUTR
+    strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
+    file[0] = fopen(name,"w");
+    
+    idDDL = 1;// MUTR
+    strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
+    file[1] = fopen(name,"w");
+      
+    WriteTriggerDDL(*triggerStore,file);
+      
+    // reset and close
+    fclose(file[0]);
+    fclose(file[1]);
+      
+    AliDebug(1,"Trigger written");
+  }
   
   return kTRUE;
 }
 
-//____________________________________________________________________
-Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iSt)
+//______________________________________________________________________________
+void 
+AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
+                                     AliMpExMap& busPatchMap)
 {
-  /// writing DDL for tracker
-  /// used inverse mapping
-
-  fTimers[kWriteTracker].Start(kFALSE);
+  /// Create bus patch structures corresponding to digits in the store
+  
+  AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::Digits2BusPatchMap");
   
   static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
-
-  // resets
-  TClonesArray* muonDigits = 0;
-
-  // DDL header
-  Int_t headerSize = sizeof(fHeader)/4;
-
+    
   // DDL event one per half chamber
-
+  
   // raw data
   Char_t parity = 0x4;
   UShort_t manuId = 0;
@@ -282,281 +224,221 @@ Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iSt)
   UShort_t charge = 0;
   Int_t busPatchId = 0;
   UInt_t word;
-
-
-  // Dsp length
-  Int_t totalDspLength;
-  Int_t dspLength;
-
-  // block length
-  Int_t totalBlkLength;
-  Int_t blkLength; 
   
-  // total DDL length
-  Int_t totalDDLLength;
+  TIter next(digitStore.CreateTrackerIterator());
+  AliMUONVDigit* digit;
+  
+  while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
+  {
+    charge = digit->ADC();
+    if ( charge > kMAXADC )
+    {
+      // This is most probably an error in the digitizer (which should insure
+      // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
+      AliError(Form("adc value %d above %x for DE %d . Setting to %x. Digit is:",
+                    digit->DetElemId(),charge,kMAXADC,kMAXADC));
+      StdoutToAliError(digit->Print());
+      charge = kMAXADC;
+    }
+    
+    // inverse mapping
+    busPatchId = GetBusPatch(*digit);
 
-  // indexes
-  Int_t index;
-  Int_t indexDsp;
-  Int_t indexBlk;
+    if (busPatchId<0) continue;
+    
+    if ( digit->ManuId() > 0x7FF ||
+         digit->ManuChannel() > 0x3F )
+    {
+      StdoutToAliError(digit->Print(););
+      AliFatal("ManuId,ManuChannel are invalid for the digit above.");
+    }
+    
+    manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
+    channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
+    
+    //packing word
+    word = 0;
+    AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
+    AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
+    AliBitPacking::PackWord((UInt_t)charge,word,0,11);
+    
+    // parity word
+    parity = word & 0x1;
+    for (Int_t i = 1; i <= 30; ++i) 
+    {
+      parity ^=  ((word >> i) & 0x1);
+    }
+    AliBitPacking::PackWord((UInt_t)parity,word,31,31);
+    
+    AliMUONBusStruct* busStruct = 
+      static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
+    
+    if (!busStruct)
+    {
+      busStruct = new AliMUONBusStruct;
+      busStruct->SetDataKey(busStruct->GetDefaultDataKey());
+      busStruct->SetBusPatchId(busPatchId);
+      busStruct->SetLength(0);
+      busPatchMap.Add(busPatchId,busStruct);
+    }
+    
+    // set sub Event
+    busStruct->AddData(word);
+  }
+}
 
+//______________________________________________________________________________
+void
+AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
+{
+  /// Write DDL file for one tracker DDL
+  
   // buffer size (max'ed out)
   // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch 
   //   + 10 dsp words)*5 dsps + 8 block words)*2 blocks 
-  static const Int_t kBufferSize = (((43*64 + 4)*5 + 10)*5 + 8)*2;
-  
-  Int_t nDigits;
+  AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::WriteTrackerDDL");
 
-  AliMpExMap busPatchMap(kTRUE);
+  memset(fBuffer,0,fBufferSize*sizeof(Int_t));
   
-  fTimers[kDigitLoop].Start(kFALSE);
+  AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
+  Int_t iDspMax = ddl->GetMaxDsp();
+  Int_t iBusPerDSP[5]; //number of bus patches per DSP
+  ddl->GetBusPerDsp(iBusPerDSP);
+  Int_t busIter = 0;
   
-  for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh) {
-
-    muonDigits = fMUONData->Digits(iCh);
-    
-    nDigits = muonDigits->GetEntriesFast();
-    
-    // loop over digit
-    for (Int_t idig = 0; idig < nDigits; ++idig) {
-      
-      AliMUONDigit* digit = static_cast<AliMUONDigit*>(muonDigits->UncheckedAt(idig));
-      
-      charge = digit->ADC();
-      if ( charge > kMAXADC )
-      {
-        // This is most probably an error in the digitizer (which should insure
-        // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
-        AliError(Form("adc value %d above %x for ch %d . Setting to %x. Digit is:",iCh,
-                      charge,kMAXADC,kMAXADC));
-        StdoutToAliError(digit->Print());
-        charge = kMAXADC;
-      }
-      
-      // inverse mapping
-      fTimers[kGetBusPatch].Start(kFALSE);
-      busPatchId = GetBusPatch(*digit);
-      fTimers[kGetBusPatch].Stop();
-      if (busPatchId<0) continue;
-      
-      if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 ||
-           digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 )
-      {
-        StdoutToAliError(digit->Print(););
-        AliFatal("ManuId,ManuChannel are invalid for the digit above.");
-      }
-      
-      manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
-      channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
-            
-      //packing word
-      word = 0;
-      AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
-      AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
-      AliBitPacking::PackWord((UInt_t)charge,word,0,11);
-      
-      // parity word
-      parity = word & 0x1;
-      for (Int_t i = 1; i <= 30; ++i) 
-        parity ^=  ((word >> i) & 0x1);
-      AliBitPacking::PackWord((UInt_t)parity,word,31,31);
-      
-      AliMUONBusStruct* busStruct = 
-        static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
-      
-      if (!busStruct)
-      {
-        busStruct = new AliMUONBusStruct;
-        busStruct->SetDataKey(busStruct->GetDefaultDataKey());
-        busStruct->SetBusPatchId(busPatchId);
-        busStruct->SetLength(0);
-        busPatchMap.Add(busPatchId,busStruct);
-      }
-
-      // set sub Event
-      busStruct->AddData(word);
-      
-    } // idig
-  } // loop over chamber in station
-    
-  fTimers[kDigitLoop].Stop();
+  Int_t totalDDLLength = 0;
   
-  // getting info for the number of buspatches
-  Int_t iBusPatch;
-  Int_t length;
-  Int_t iBusPerDSP[5];//number of bus patches per DSP
-  Int_t iDspMax; //number max of DSP per block
-  Int_t iFile = 0;
-
-  AliMUONBusStruct* busStructPtr(0x0);
-
-  // open DDL files, 4 per station
-  for (Int_t iDDL = iSt*4; iDDL < 4 + iSt*4; ++iDDL) {
-
-    AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
-    iDspMax = ddl->GetMaxDsp();
-    ddl->GetBusPerDsp(iBusPerDSP);
-    Int_t busIter = 0;
-
-    Int_t buffer[kBufferSize];
+  Int_t index = 0;
+  
+  // two blocks A and B per DDL
+  for (Int_t iBlock = 0; iBlock < 2; ++iBlock) 
+  {
+    // block header
+    Int_t length = fBlockHeader->GetHeaderLength();
+    memcpy(&fBuffer[index],fBlockHeader->GetHeader(),length*4);
+    Int_t indexBlk = index;
+    index += length; 
     
-    totalDDLLength = 0;
-
-    indexBlk = 0;
-    indexDsp = 0;
-    index = 0;
-
-    // two blocks A and B per DDL
-    for (Int_t iBlock = 0; iBlock < 2; ++iBlock) {
-      
-      // block header
-      length = fBlockHeader->GetHeaderLength();
-      memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4);
-      indexBlk = index;
+    // 5 DSP's max per block
+    for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) 
+    {
+      // DSP header
+      Int_t length = fDspHeader->GetHeaderLength();
+      memcpy(&fBuffer[index],fDspHeader->GetHeader(),length*4);
+      Int_t indexDsp = index;
       index += length; 
       
-      // 5 DSP's max per block
-      for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) {
-        
-        // DSP header
-        length = fDspHeader->GetHeaderLength();
-        memcpy(&buffer[index],fDspHeader->GetHeader(),length*4);
-        indexDsp = index;
-        index += length; 
-        
-        // 5 buspatches max per DSP
-        for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
-          
-          iBusPatch = ddl->GetBusPatchId(busIter++);
-          
-          // iteration over bus patch in DDL
-          if (iBusPatch == -1) {
-            AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
-            continue;
-          }
-          
-          // 4 DDL's per station, condition needed for station 3
-          iFile = iDDL - iSt*4; // works only if DDL begins at zero (as it should be) !!!
-          
-          busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
-          
-          // check if buspatchid has digit
-          if (busStructPtr) {
-            // add bus patch structure header
-            length = busStructPtr->GetHeaderLength();
-            memcpy(&buffer[index],busStructPtr->GetHeader(),length*4);
-            index += length;
-            
-            // add bus patch data
-            length = busStructPtr->GetLength();
-            memcpy(&buffer[index],busStructPtr->GetData(),length*4);
-            index += length;
-            
-            if (AliLog::GetGlobalDebugLevel() == 3) {
-              for (Int_t j = 0; j < busStructPtr->GetLength(); j++) {
-                printf("busPatchId %d, manuId %d channelId %d\n", busStructPtr->GetBusPatchId(), 
-                       busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j));
-              }
-            }
-          } else {
-            // writting anyhow buspatch structure (empty ones)
-            buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
-            buffer[index++] = busStructPtr->GetHeaderLength(); // header length
-            buffer[index++] = 0; // raw data length
-            buffer[index++] = iBusPatch; // bus patch
-          }
-        } // bus patch
+      // 5 buspatches max per DSP
+      for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i) 
+      {
+        Int_t iBusPatch = ddl->GetBusPatchId(busIter++);
         
-        // check if totalLength even
-        // set padding word in case
-        // Add one word 0xBEEFFACE at the end of DSP structure
-        totalDspLength  = index - indexDsp;
-        if ((totalDspLength % 2) == 1) { 
-          buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
-          buffer[index++] = fDspHeader->GetDefaultPaddingWord();
-          totalDspLength++;
+        // iteration over bus patch in DDL
+        if (iBusPatch == -1) 
+        {
+          AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
+          continue;
         }
         
-        dspLength          = totalDspLength - fDspHeader->GetHeaderLength();
+        AliMUONBusStruct* busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
         
-        buffer[indexDsp+1] = totalDspLength; // dsp total length
-        buffer[indexDsp+2] = dspLength; // data length  
-        
-      } // dsp
+        // check if buspatchid has digit
+        if (busStructPtr) 
+        {
+          // add bus patch structure header
+          Int_t length = busStructPtr->GetHeaderLength();
+          memcpy(&fBuffer[index],busStructPtr->GetHeader(),length*4);
+          index += length;
+          
+          // add bus patch data
+          length = busStructPtr->GetLength();
+          memcpy(&fBuffer[index],busStructPtr->GetData(),length*4);
+          index += length;
+        } 
+        else 
+        {
+          // writting anyhow buspatch structure (empty ones)
+          fBuffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
+          fBuffer[index++] = busStructPtr->GetHeaderLength(); // header length
+          fBuffer[index++] = 0; // raw data length
+          fBuffer[index++] = iBusPatch; // bus patch
+        }
+      } // bus patch
       
-      totalBlkLength  = index - indexBlk;
-      blkLength       = totalBlkLength - fBlockHeader->GetHeaderLength();
-      totalDDLLength += totalBlkLength;
+      // check if totalLength even
+      // set padding word in case
+      // Add one word 0xBEEFFACE at the end of DSP structure
+      Int_t totalDspLength  = index - indexDsp;
+      if ((totalDspLength % 2) == 1) 
+      { 
+        fBuffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
+        fBuffer[index++] = fDspHeader->GetDefaultPaddingWord();
+        totalDspLength++;
+      }
       
-      buffer[indexBlk+1] = totalBlkLength; // total block length
-      buffer[indexBlk+2] = blkLength;
+      Int_t dspLength          = totalDspLength - fDspHeader->GetHeaderLength();
       
-    } // block
-    
-    //writting onto disk
-    // write DDL 1 - 4
-    // total length in bytes
-    fHeader.fSize = (totalDDLLength + headerSize) * 4;
+      fBuffer[indexDsp+1] = totalDspLength; // dsp total length
+      fBuffer[indexDsp+2] = dspLength; // data length  
       
-    fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]);
-    fwrite(buffer,sizeof(int),index,fFile[iFile]);
-  }
+    } // dsp
+    
+    Int_t totalBlkLength  = index - indexBlk;
+    Int_t blkLength       = totalBlkLength - fBlockHeader->GetHeaderLength();
+    totalDDLLength += totalBlkLength;
+    
+    fBuffer[indexBlk+1] = totalBlkLength; // total block length
+    fBuffer[indexBlk+2] = blkLength;
+    
+  } // block
   
-  fTimers[kWriteTracker].Stop();
-  return kTRUE;
+  // writting onto disk
+  // total length in bytes
+  // DDL header
+  Int_t headerSize = sizeof(fHeader)/4;
+  
+  fHeader.fSize = (totalDDLLength + headerSize) * 4;
+  
+  FILE* file = fopen(AliDAQ::DdlFileName("MUONTRK",iDDL),"w");
+  
+  fwrite((char*)(&fHeader),headerSize*4,1,file);
+  fwrite(fBuffer,sizeof(int),index,file);
+  fclose(file);
 }
 
-//____________________________________________________________________
-Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) const
+//______________________________________________________________________________
+Int_t AliMUONRawWriter::GetBusPatch(const AliMUONVDigit& digit) const
 {
   /// Determine the BusPatch this digit belongs to.
 
     return fDDLStore->GetBusPatchId(digit.DetElemId(),digit.ManuId());
 }
 
-//____________________________________________________________________
-Int_t AliMUONRawWriter::WriteTriggerDDL()
+//______________________________________________________________________________
+Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, FILE* file[2])
 {
   /// Write trigger DDL
-
-  fTimers[kWriteTrigger].Start(kFALSE);
   
+  AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONRawWriter::WriteTriggerDDL");
+
  // DDL event one per half chamber
 
  // DDL header size
   Int_t headerSize = sizeof(AliRawDataHeader)/4;
 
-  TClonesArray* localTrigger;
-  TClonesArray* globalTrigger;
-  TClonesArray* regionalTrigger;
-
-  AliMUONGlobalTrigger* gloTrg;
-  AliMUONLocalTrigger* locTrg = 0x0;
-  AliMUONRegionalTrigger* regTrg = 0x0;
-
   // global trigger for trigger pattern
-  globalTrigger = fMUONData->GlobalTrigger(); 
-  gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
+  AliMUONGlobalTrigger* gloTrg = triggerStore.Global();
   if (!gloTrg) 
   {
-    fTimers[kWriteTrigger].Stop();
     return 0;
   }
   
   Int_t gloTrigResp = gloTrg->GetGlobalResponse();
 
-  // local trigger 
-  localTrigger = fMUONData->LocalTrigger();   
-
-
-  // regional trigger
-  regionalTrigger = fMUONData->RegionalTrigger();   
-
-
   UInt_t word;
   Int_t* buffer = 0;
   Int_t index;
-  Int_t iEntries = 0;
   Int_t iLocCard, locCard;
   UChar_t locDec, trigY, posY, posX, regOut;
   UInt_t regInpLpt;
@@ -591,11 +473,6 @@ Int_t AliMUONRawWriter::WriteTriggerDDL()
   if(fScalerEvent)
     eventPhys = 0; //set to generate scaler events
 
-  Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
-
-  if (!nEntries)
-    AliDebug(1, "No Trigger information available");
-
   if(fScalerEvent)
     buffer = new Int_t [kScalerBufferSize];
   else
@@ -604,8 +481,8 @@ Int_t AliMUONRawWriter::WriteTriggerDDL()
   // reset crate
 
   // open DDL file, on per 1/2 chamber
-  for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
-
+  for ( Int_t iDDL = 0; iDDL < 2; ++iDDL ) 
+  {
     index = 0; 
 
     if (iDDL == 0) // suppose global info in DDL one
@@ -659,14 +536,10 @@ Int_t AliMUONRawWriter::WriteTriggerDDL()
       AliMUONTriggerCrate* crate = fCrateManager->Crate(iDDL, iReg);
 
       if (!crate) 
-       AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
+        AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
 
       // regional info tree, make sure that no reg card missing
-      for (Int_t i = 0; i < 16; ++i) {
-       regTrg  = (AliMUONRegionalTrigger*)regionalTrigger->At(i);
-       if (regTrg)
-         if (regTrg->GetId() == (iReg + iDDL*8)) break;
-      }
+      AliMUONRegionalTrigger* regTrg  = triggerStore.FindRegional(iReg+iDDL*8);
 
       // Regional card header
       word = 0;
@@ -714,40 +587,41 @@ Int_t AliMUONRawWriter::WriteTriggerDDL()
          
          if (localBoard) { // if not empty slot
              
-             if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
-                 
-                 locTrg  = (AliMUONLocalTrigger*)localTrigger->At(iEntries++);
-                 locCard = locTrg->LoCircuit();
-                 locDec  = locTrg->GetLoDecision();
-                 trigY =  locTrg->LoTrigY();
-                 posY  = locTrg->LoStripY();
-                 posX  = locTrg->LoStripX();
-                 devX  = locTrg->LoDev();
-                 sdevX = locTrg->LoSdev();
-                 
-                 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n", 
-                                 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));  
-                 //packing word
-                 word = 0;
-                 AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
-                 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
-                 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
-                 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
-                 AliBitPacking::PackWord((UInt_t)sdevX,word,9,9);
-                 AliBitPacking::PackWord((UInt_t)devX,word,5,8);
-                 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
-                 
-                 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
-                 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
-                 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
-                 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
-                 buffer[index++] = (Int_t)word; // data word
-
-             } else {// number!=0
-                 // fill with 10CDEAD word for 'non-notified' slots
-                 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
+      if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
+        
+        AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(iLocCard);
+        
+        locCard = locTrg->LoCircuit();
+        
+        locDec  = locTrg->GetLoDecision();
+        trigY =  locTrg->LoTrigY();
+        posY  = locTrg->LoStripY();
+        posX  = locTrg->LoStripX();
+        devX  = locTrg->LoDev();
+        sdevX = locTrg->LoSdev();
+        
+        AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n", 
+                        locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));  
+        //packing word
+        word = 0;
+        AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
+        AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
+        AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
+        AliBitPacking::PackWord((UInt_t)posY,word,10,13);
+        AliBitPacking::PackWord((UInt_t)sdevX,word,9,9);
+        AliBitPacking::PackWord((UInt_t)devX,word,5,8);
+        AliBitPacking::PackWord((UInt_t)posX,word,0,4);
+        
+        buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
+        buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
+        buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
+        buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
+        buffer[index++] = (Int_t)word; // data word
+      } else {// number!=0
+              // fill with 10CDEAD word for 'non-notified' slots
+        for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
                      buffer[index++] = fLocalStruct->GetDisableWord(); 
-             }
+      }
          } else { 
              // fill with 10CDEAD word for empty slots
              for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
@@ -775,16 +649,15 @@ Int_t AliMUONRawWriter::WriteTriggerDDL()
     // writting onto disk
     // write DDL's
     fHeader.fSize = (index + headerSize) * 4;// total length in bytes
-    fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]);
-    fwrite(buffer,sizeof(int),index,fFile[iDDL]);
+    fwrite((char*)(&fHeader),headerSize*4,1,file[iDDL]);
+    fwrite(buffer,sizeof(int),index,file[iDDL]);
   
   }
   delete[] buffer;
 
-  fTimers[kWriteTrigger].Stop();
-  
   return kTRUE;
 }
+
 //____________________________________________________________________
 void AliMUONRawWriter::SetScalersNumbers()
 {
index 2e53d3a..c29699c 100644 (file)
 #include <TObject.h>
 #include "AliRawDataHeader.h"
 
-class AliMUONData;
-class AliMUONDigit;
-class AliMUONDspHeader;
 class AliMUONBlockHeader;
-class AliMUONDarcHeader;
-class AliMUONRegHeader;
-class AliMUONLocalStruct;
-class AliMpExMap;
 class AliMUONBusStruct;
+class AliMUONDarcHeader;
+class AliMUONVDigit;
+class AliMUONDspHeader;
 class AliMUONGlobalTrigger;
-class AliMpDDLStore;
+class AliMUONLocalStruct;
+class AliMUONRegHeader;
+class AliMUONStopwatchGroup;
 class AliMUONTriggerCrateStore;
-class TStopwatch;
+class AliMUONVDigitStore;
+class AliMUONVTriggerStore;
+class AliMpDDLStore;
+class AliMpExMap;
 
 class AliMUONRawWriter : public TObject 
 {
  public:
-  AliMUONRawWriter(AliMUONData* data); // Constructor
+  AliMUONRawWriter(); // Constructor
   virtual ~AliMUONRawWriter(); // Destructor
     
   // write raw data
-  Int_t Digits2Raw();
-
+  Int_t Digits2Raw(AliMUONVDigitStore* digitStore, AliMUONVTriggerStore* triggerStore);
+  
   void SetScalersNumbers();
 
-protected:
-  AliMUONRawWriter();                  // Default constructor
+private:
+
+  void Digits2BusPatchMap(const AliMUONVDigitStore& digitStore, AliMpExMap& busPatchMap);
+  void WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL);
 
-  // writing raw data
-  Int_t WriteTrackerDDL(Int_t iCh);
-  Int_t WriteTriggerDDL();
+  //void WriteBusPatch(AliMUONLocalBusStruct* busStruct);
   
-private:
-  Int_t GetBusPatch(const AliMUONDigit& digit) const;
+  Int_t WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, FILE* file[2]);
+  
+  Int_t GetBusPatch(const AliMUONVDigit& digit) const;
 
 private:
   /// Not implemented copy constructor
@@ -55,11 +57,6 @@ private:
   /// Not implemented assignment operator
   AliMUONRawWriter& operator=(const AliMUONRawWriter& rhs);
 
-
-  AliMUONData*  fMUONData;           //!< Data container for MUON subsystem 
-  FILE*         fFile[4];            //!< DDL binary file pointer one per 1/2 chamber, 4 for one station
-
   AliMUONBlockHeader* fBlockHeader;  //!< DDL block header class pointers
   AliMUONDspHeader*   fDspHeader;    //!< DDL Dsp header class pointers
   AliMUONDarcHeader*  fDarcHeader;   //!< DDL darc header class pointers
@@ -72,11 +69,13 @@ private:
   Bool_t fScalerEvent;               ///< flag to generates scaler event
 
   AliRawDataHeader    fHeader;           ///< header of DDL
-
   
-  TStopwatch* fTimers;             //!< time watchers
-  
-  ClassDef(AliMUONRawWriter,2) // MUON cluster reconstructor in ALICE
+  AliMUONStopwatchGroup* fTimers;             //!< time watchers
+
+  Int_t fBufferSize; //!< size of internal data buffer
+  Int_t* fBuffer; //!< internal data buffer
+
+  ClassDef(AliMUONRawWriter,3) // MUON cluster reconstructor in ALICE
 };
        
 #endif
index 3107421..23db5e9 100644 (file)
@@ -1,17 +1,17 @@
 /**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
 
 /* $Id$ */
 
 /// The reference tracks are built from AliTrackReference for the
 /// hit in chamber (0..9) and from kinematics for the vertex parameters.     
 
-#include "AliMUON.h"
 #include "AliMUONRecoCheck.h"
 #include "AliMUONTrack.h"
-#include "AliMUONRecData.h"
 #include "AliMUONConstants.h"
-
-#include "AliLoader.h" 
-#include "AliRunLoader.h" 
-#include "AliHeader.h"
+#include "AliMUONMCDataInterface.h"
+#include "AliMUONDataInterface.h"
 #include "AliStack.h"
 #include "AliTrackReference.h"
 #include "AliLog.h" 
-
+#include "AliMUONTrackStoreV1.h"
+#include <Riostream.h>
 #include <TParticle.h>
 #include <TParticlePDG.h>
 
@@ -42,349 +39,233 @@ ClassImp(AliMUONRecoCheck)
 /// \endcond
 
 //_____________________________________________________________________________
-  AliMUONRecoCheck::AliMUONRecoCheck(Char_t *chLoader, Char_t *chLoaderSim)
-  : TObject(),
-  fRunLoader(0x0),
-  fMUONData(0x0),
-  fRunLoaderSim(0x0),
-  fMUONDataSim(0x0),
-  fMuonTrackRef(0x0),
-  fTrackReco(0x0),
-  fReconstructibleTracks(0),
-  fRecoTracks(0),
-  fIsLoadConstructor(kTRUE)
+AliMUONRecoCheck::AliMUONRecoCheck(Char_t *chLoader, Char_t *chLoaderSim)
+: TObject(),
+fMCDataInterface(new AliMUONMCDataInterface(chLoaderSim)),
+fDataInterface(new AliMUONDataInterface(chLoader))
 {
-/// Constructor using "galice.root",
-/// takes care of loading/unloading Kinematics, TrackRefs and Tracks
-
-  fMuonTrackRef = new TClonesArray("AliMUONTrack", 10);
-
-  // run loader
-  fRunLoader = AliRunLoader::Open(chLoader,"MUONFolder","READ");
-  if (!fRunLoader) {
-    AliError(Form("no run loader found " ));
-    return;
-  }
-
- // initialize loader   
-  AliLoader *loader = fRunLoader->GetLoader("MUONLoader");
-
-  // container
-  fMUONData  = new AliMUONRecData(loader,"MUON","MUON");
-  if (!fMUONData) {
-    AliError(Form("no MUONData found " ));
-    return;
-  }
-
-  // run loader
-  fRunLoaderSim = AliRunLoader::Open(chLoaderSim,"MUONFolderSim","READ");
-  if (!fRunLoaderSim) {
-    AliError(Form("no run sim loader found " ));
-    return;
-  }
-
- // initialize loader   
-  AliLoader *loaderSim = fRunLoaderSim->GetLoader("MUONLoader");
-
-  // container
-  fMUONDataSim  = new AliMUONSimData(loaderSim,"MUON","MUON");
-  if (!fMUONDataSim) {
-    AliError(Form("no MUONDataSim found " ));
-    return;
-  }
-
-  fRunLoaderSim->LoadKinematics("READ");        
-  fRunLoaderSim->LoadTrackRefs("READ");         
-  loader->LoadTracks("READ");
-
+  /// Normal ctor
 }
 
 //_____________________________________________________________________________
-  AliMUONRecoCheck::AliMUONRecoCheck(AliRunLoader *runloader, AliMUONRecData *muondata,
-                                     AliRunLoader *runloaderSim, AliMUONSimData *muondataSim)
-  : TObject(),
-  fRunLoader(0x0),
-  fMUONData(0x0),
-  fRunLoaderSim(0x0),
-  fMUONDataSim(0x0),
-  fMuonTrackRef(0x0),
-  fTrackReco(0x0),
-  fReconstructibleTracks(0),
-  fRecoTracks(0),
-  fIsLoadConstructor(kFALSE)
+AliMUONRecoCheck::~AliMUONRecoCheck()
 {
-/// Constructor from AliRunLoader and AliMUONData,
-/// does not load/unload Kinematics, TrackRefs and Tracks internally
-/// it should be done in the execution program (e.g. see MUONRecoCheck.C)
-
-  fMuonTrackRef = new TClonesArray("AliMUONTrack", 10);
-
-  // run loader
-  fRunLoader = runloader;
-  if (!fRunLoader) {
-    AliError(Form("no run loader found " ));
-    return;
-  }
-
-  // container
-  fMUONData  = muondata;
-  if (!fMUONData) {
-    AliError(Form("no MUONData found " ));
-    return;
-  }
-
-  // run loader
-  fRunLoaderSim = runloaderSim;
-  if (!fRunLoaderSim) {
-    AliError(Form("no run sim loader found " ));
-    return;
-  }
-
-  // container
-  fMUONDataSim  = muondataSim;
-  if (!fMUONDataSim) {
-    AliError(Form("no MUONDataSim found " ));
-    return;
-  }
-
+  /// Destructor
+  delete fMCDataInterface;
+  delete fDataInterface;
 }
 
+//_____________________________________________________________________________
+AliMUONVTrackStore* 
+AliMUONRecoCheck::ReconstructedTracks(Int_t event)
+{
+  /// Return the reconstructed track store for a given event
+  return fDataInterface->TrackStore(event);
+}
 
 //_____________________________________________________________________________
-AliMUONRecoCheck::~AliMUONRecoCheck()
+AliMUONVTrackStore* 
+AliMUONRecoCheck::TrackRefs(Int_t event)
 {
-/// Destructor
-  delete fMuonTrackRef;
-  if(fIsLoadConstructor){
-    fRunLoaderSim->UnloadKinematics();
-    fRunLoaderSim->UnloadTrackRefs();
-    fRunLoader->UnloadTracks();
-    delete fMUONData;
-    delete fRunLoader;
-    delete fMUONDataSim;
-    delete fRunLoaderSim;
-  }
+  /// Return a track store containing the track references (converted into 
+  /// MUONTrack objects) for a given event
+  return MakeTrackRefs(event);
 }
 
 //_____________________________________________________________________________
-void AliMUONRecoCheck::MakeTrackRef()
+AliMUONVTrackStore* 
+AliMUONRecoCheck::ReconstructibleTracks(Int_t event)
 {
-/// Make reconstructible tracks
+  /// Return a track store containing the reconstructible tracks for a given event
+  AliMUONVTrackStore* tmp = MakeTrackRefs(event);
+  AliMUONVTrackStore* reconstructible = MakeReconstructibleTracks(*tmp);
+  delete tmp;
+  return reconstructible;
+}
 
-  AliTrackReference *trackReference;
-  AliMUONTrack *muonTrack;
-  AliMUONTrackParam *trackParam;
-  AliMUONHitForRec *hitForRec;
-  Float_t x, y, z, pX, pY, pZ, pYZ;
-  Int_t track, trackSave;
-  TParticle *particle;   
-  Float_t bendingSlope = 0;
-  Float_t  nonBendingSlope = 0;
-  Float_t inverseBendingMomentum = 0;
+//_____________________________________________________________________________
+AliMUONVTrackStore*
+AliMUONRecoCheck::MakeTrackRefs(Int_t event)
+{
+  /// Make reconstructible tracks
+    
+  AliMUONVTrackStore* trackRefStore = new AliMUONTrackStoreV1;
+  
+  Int_t nTrackRef = fMCDataInterface->NumberOfTrackRefs(event);
+  
+  Int_t trackSave(-999);
+  Int_t iHitMin(0);
   
-  TTree* treeTR = fRunLoaderSim->TreeTR();
-  if (treeTR == NULL) return;
-
-  TBranch* branch = treeTR->GetBranch("MUON");
-  if (branch == NULL) return;
-
-  TClonesArray* trackRefs = 0;
-  branch->SetAddress(&trackRefs);
-  branch->SetAutoDelete(kTRUE);  
-
-  Int_t nTrackRef = (Int_t)branch->GetEntries();
-  track = trackSave = -999;
   Bool_t isNewTrack;
-  Int_t iHitMin, iChamber, detElemId;
-
-  trackParam = new AliMUONTrackParam();
-  hitForRec = new AliMUONHitForRec();
-
-  Int_t charge;
-  TParticlePDG *ppdg;
-
-  Int_t max = fRunLoaderSim->GetHeader()->Stack()->GetNtrack();
-  for (Int_t iTrackRef  = 0; iTrackRef < nTrackRef; iTrackRef++) {
-
-    branch->GetEntry(iTrackRef);
+    
+  AliStack* stack = fMCDataInterface->Stack(event);
+  Int_t max = stack->GetNtrack();
+  
+  for (Int_t iTrackRef  = 0; iTrackRef < nTrackRef; ++iTrackRef) 
+  {
+    TClonesArray* trackRefs = fMCDataInterface->TrackRefs(event,iTrackRef);
     
     iHitMin = 0;
     isNewTrack = kTRUE;
     
     if (!trackRefs->GetEntries()) continue; 
-
+    
     while (isNewTrack) {
-
-      muonTrack = new AliMUONTrack();
       
-      for (Int_t iHit = iHitMin; iHit < trackRefs->GetEntries(); iHit++) {
+      AliMUONTrack muonTrack;
       
-       trackReference = (AliTrackReference*)trackRefs->At(iHit);
-       x = trackReference->X();
-       y = trackReference->Y();
-       z = trackReference->Z();
-       pX = trackReference->Px();
-       pY = trackReference->Py();
-       pZ = trackReference->Pz();
-
-       track = trackReference->GetTrack();
-
-       if(track >= max){
-         AliWarningStream()
-           << "Track ID " << track 
-           << " larger than max number of particles " << max << endl;
-         isNewTrack = kFALSE;
-         break;
-       }
-       if (track != trackSave && iHit != 0) {
-         iHitMin = iHit;
-         trackSave = track;
-         break;
-       }
-
-       // track parameters at hit
-       trackParam->SetBendingCoor(y);
-       trackParam->SetNonBendingCoor(x);
-       trackParam->SetZ(z);
-
-       if (TMath::Abs(pZ) > 0) {
-         bendingSlope = pY/pZ;
-         nonBendingSlope = pX/pZ;
-       }
-       pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
-       if (pYZ >0) inverseBendingMomentum = 1/pYZ; 
-
-       trackParam->SetBendingSlope(bendingSlope);
-       trackParam->SetNonBendingSlope(nonBendingSlope);
-       trackParam->SetInverseBendingMomentum(inverseBendingMomentum);
-
-       hitForRec->SetBendingCoor(y);
-       hitForRec->SetNonBendingCoor(x);
-       hitForRec->SetZ(z);
-       hitForRec->SetBendingReso2(0.0); 
-       hitForRec->SetNonBendingReso2(0.0);
-       detElemId = hitForRec->GetDetElemId();
-       if (detElemId) iChamber = detElemId / 100 - 1; 
-       else iChamber = AliMUONConstants::ChamberNumber(z);
-       hitForRec->SetChamberNumber(iChamber);
-
-       muonTrack->AddTrackParamAtHit(trackParam,0);
-       muonTrack->AddHitForRecAtHit(hitForRec);
-       muonTrack->SetTrackID(track);
-
-       trackSave = track;
-       if (iHit == trackRefs->GetEntries()-1) isNewTrack = kFALSE;
+      for (Int_t iHit = iHitMin; iHit < trackRefs->GetEntries(); ++iHit) 
+      {        
+        AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->At(iHit));
+        
+        Float_t x = trackReference->X();
+        Float_t y = trackReference->Y();
+        Float_t z = trackReference->Z();
+        Float_t pX = trackReference->Px();
+        Float_t pY = trackReference->Py();
+        Float_t pZ = trackReference->Pz();
+        
+        Int_t track = trackReference->GetTrack();
+        
+        if ( track >= max )
+        {
+          AliWarningStream()
+          << "Track ID " << track 
+          << " larger than max number of particles " << max << endl;
+          isNewTrack = kFALSE;
+          break;
+        }
+        if (track != trackSave && iHit != 0) {
+          iHitMin = iHit;
+          trackSave = track;
+          break;
+        }
+        
+        Float_t bendingSlope = 0;
+        Float_t nonBendingSlope = 0;
+        Float_t inverseBendingMomentum = 0;
+        
+        AliMUONTrackParam trackParam;
+        
+        // track parameters at hit
+        trackParam.SetBendingCoor(y);
+        trackParam.SetNonBendingCoor(x);
+        trackParam.SetZ(z);
+        
+        if (TMath::Abs(pZ) > 0) 
+        {
+          bendingSlope = pY/pZ;
+          nonBendingSlope = pX/pZ;
+        }
+        Float_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
+        if (pYZ >0) inverseBendingMomentum = 1/pYZ; 
+        
+        trackParam.SetBendingSlope(bendingSlope);
+        trackParam.SetNonBendingSlope(nonBendingSlope);
+        trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
+        
+        AliMUONHitForRec hitForRec;
+        
+        hitForRec.SetBendingCoor(y);
+        hitForRec.SetNonBendingCoor(x);
+        hitForRec.SetZ(z);
+        hitForRec.SetBendingReso2(0.0); 
+        hitForRec.SetNonBendingReso2(0.0);
+        Int_t detElemId = hitForRec.GetDetElemId();
+        Int_t iChamber;
+        if (detElemId) 
+        {
+          iChamber = detElemId / 100 - 1; 
+        }
+        else 
+        {
+          iChamber = AliMUONConstants::ChamberNumber(z);
+        }
+        hitForRec.SetChamberNumber(iChamber);
+        
+        muonTrack.AddTrackParamAtHit(&trackParam,0);
+        muonTrack.AddHitForRecAtHit(&hitForRec);
+        muonTrack.SetTrackID(track);
+        
+        trackSave = track;
+        if (iHit == trackRefs->GetEntries()-1) isNewTrack = kFALSE;
       }
-
+      
       // track parameters at vertex 
-      particle = fRunLoaderSim->GetHeader()->Stack()->Particle(muonTrack->GetTrackID());
-
-      if (particle) {
-
-       x = particle->Vx();
-       y = particle->Vy();
-       z = particle->Vz();
-       pX = particle->Px();
-       pY = particle->Py();
-       pZ = particle->Pz();
-
-       trackParam->SetBendingCoor(y);
-       trackParam->SetNonBendingCoor(x);
-       trackParam->SetZ(z);
-       if (TMath::Abs(pZ) > 0) {
-         bendingSlope = pY/pZ;
-         nonBendingSlope = pX/pZ;
-       }
-
-       pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
-       if (pYZ >0) inverseBendingMomentum = 1/pYZ;       
-
-       ppdg = particle->GetPDG(1);
-       charge = (Int_t)(ppdg->Charge()/3.0);
-       inverseBendingMomentum *= charge;
-
-       trackParam->SetBendingSlope(bendingSlope);
-       trackParam->SetNonBendingSlope(nonBendingSlope);
-       trackParam->SetInverseBendingMomentum(inverseBendingMomentum);
+      TParticle* particle = stack->Particle(muonTrack.GetTrackID());
       
-       muonTrack->SetTrackParamAtVertex(trackParam);
+      if (particle) 
+      {        
+        Float_t x = particle->Vx();
+        Float_t y = particle->Vy();
+        Float_t z = particle->Vz();
+        Float_t pX = particle->Px();
+        Float_t pY = particle->Py();
+        Float_t pZ = particle->Pz();
+        
+        AliMUONTrackParam trackParam;
+        
+        trackParam.SetBendingCoor(y);
+        trackParam.SetNonBendingCoor(x);
+        trackParam.SetZ(z);
+        
+        Float_t bendingSlope = 0;
+        Float_t nonBendingSlope = 0;
+        Float_t inverseBendingMomentum = 0;
+                
+        if (TMath::Abs(pZ) > 0) 
+        {
+          bendingSlope = pY/pZ;
+          nonBendingSlope = pX/pZ;
+        }
+        
+        Float_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
+        if (pYZ >0) inverseBendingMomentum = 1/pYZ;       
+        
+        TParticlePDG* ppdg = particle->GetPDG(1);
+        Int_t charge = (Int_t)(ppdg->Charge()/3.0);
+        inverseBendingMomentum *= charge;
+        
+        trackParam.SetBendingSlope(bendingSlope);
+        trackParam.SetNonBendingSlope(nonBendingSlope);
+        trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
+        
+        muonTrack.SetTrackParamAtVertex(&trackParam);
       }
 
-      AddMuonTrackReference(muonTrack);
-      delete muonTrack;
-      muonTrack = NULL;
-      
+      trackRefStore->Add(muonTrack);
     } // end while isNewTrack
+    delete trackRefs;
   }
-  delete trackRefs;
-  CleanMuonTrackRef();
   
-  ReconstructibleTracks();
-
-  delete trackParam;
-  delete hitForRec;
+  AliMUONVTrackStore* rv = CleanMuonTrackRef(*trackRefStore);
+  
+  delete trackRefStore;
 
+  return rv;
 }
 
-//____________________________________________________________________________
-TClonesArray* AliMUONRecoCheck::GetTrackReco()
-{
-/// Return TClonesArray of reconstructed tracks
-
-  fMUONData->ResetRecTracks();
-  fMUONData->SetTreeAddress("RT");
-  fTrackReco = fMUONData->RecTracks(); 
-  fMUONData->GetRecTracks();
-  fRecoTracks = fTrackReco->GetEntriesFast();
-  return fTrackReco;
-}
 //_____________________________________________________________________________
-void AliMUONRecoCheck::PrintEvent() const
+Int_t
+AliMUONRecoCheck::NumberOfEvents() const
 {
-/// Debug facility
-
-  AliMUONTrack *track;
-  AliMUONHitForRec *hitForRec;
-  TClonesArray *  hitForRecAtHit = 0;
-  Float_t xRec,yRec,zRec;
-
-  Int_t nTrackRef = fMuonTrackRef->GetEntriesFast();
-  
-  printf(" ******************************* \n");
-  printf(" nb of tracks %d \n",nTrackRef);
-
-  for (Int_t index = 0; index < nTrackRef; index++) {
-    track = (AliMUONTrack*)fMuonTrackRef->At(index);
-    hitForRecAtHit = track->GetHitForRecAtHit();
-    Int_t nTrackHits = hitForRecAtHit->GetEntriesFast();
-    printf(" track number %d \n",index);
-    for (Int_t iHit = 0; iHit < nTrackHits; iHit++){
-      hitForRec = (AliMUONHitForRec*) hitForRecAtHit->At(iHit); 
-      xRec  = hitForRec->GetNonBendingCoor();
-      yRec  = hitForRec->GetBendingCoor();
-      zRec  = hitForRec->GetZ();
-      printf("  x,y,z: %f , %f , %f \n",xRec,yRec,zRec);
-    }
+  /// Return the number of events
+  if ( fDataInterface ) 
+  {
+    return fDataInterface->NumberOfEvents();
   }
+  return 0;
 }
 
 //_____________________________________________________________________________
-void AliMUONRecoCheck::ResetTracks() const
-{
-/// Reset tracks
-
-  if (fMuonTrackRef) fMuonTrackRef->Delete();
-}
-//_____________________________________________________________________________
-void AliMUONRecoCheck::CleanMuonTrackRef()
+AliMUONVTrackStore*
+AliMUONRecoCheck::CleanMuonTrackRef(const AliMUONVTrackStore& trackRefs)
 {
-/// Re-calculate hits parameters because two AliTrackReferences are recorded for
-/// each chamber (one when particle is entering + one when particle is leaving 
-/// the sensitive volume) 
-
+  /// Re-calculate hits parameters because two AliTrackReferences are recorded for
+  /// each chamber (one when particle is entering + one when particle is leaving 
+  /// the sensitive volume) 
+  
   Float_t maxGasGap = 1.; // cm 
-  AliMUONTrack *track, *trackNew;
   AliMUONHitForRec *hitForRec, *hitForRec1, *hitForRec2;
   AliMUONTrackParam *trackParam, *trackParam1, *trackParam2, *trackParamAtVertex;
   TClonesArray *  hitForRecAtHit = 0;
@@ -395,25 +276,29 @@ void AliMUONRecoCheck::CleanMuonTrackRef()
   Float_t bendingSlope,nonBendingSlope,bendingMomentum;
   Float_t bendingSlope1,nonBendingSlope1,bendingMomentum1;
   Float_t bendingSlope2,nonBendingSlope2,bendingMomentum2;
-  TClonesArray *newMuonTrackRef = new TClonesArray("AliMUONTrack", 10);
+  
+  AliMUONVTrackStore* newMuonTrackRef = static_cast<AliMUONVTrackStore*>(trackRefs.Create());
   Int_t iHit1;
   Int_t iChamber = 0, detElemId = 0;
   Int_t nRec = 0;
   Int_t nTrackHits = 0;
-
+  
   hitForRec = new AliMUONHitForRec();
   trackParam = new AliMUONTrackParam();
-
-  Int_t nTrackRef = fMuonTrackRef->GetEntriesFast();
-  for (Int_t index = 0; index < nTrackRef; index++) {
-    track = (AliMUONTrack*)fMuonTrackRef->At(index);
+  
+  TIter next(trackRefs.CreateIterator());
+  AliMUONTrack* track;
+  
+  while ( ( track = static_cast<AliMUONTrack*>(next())) ) 
+  {
     hitForRecAtHit = track->GetHitForRecAtHit();
     trackParamAtHit = track->GetTrackParamAtHit();
     trackParamAtVertex = track->GetTrackParamAtVertex();
     nTrackHits = hitForRecAtHit->GetEntriesFast();
-    trackNew = new AliMUONTrack();
+    AliMUONTrack trackNew;
     iHit1 = 0;
-    while (iHit1 < nTrackHits) {
+    while (iHit1 < nTrackHits) 
+    {
       hitForRec1 = (AliMUONHitForRec*) hitForRecAtHit->At(iHit1); 
       trackParam1 = (AliMUONTrackParam*) trackParamAtHit->At(iHit1); 
       xRec1  = hitForRec1->GetNonBendingCoor();
@@ -426,35 +311,36 @@ void AliMUONRecoCheck::CleanMuonTrackRef()
       nonBendingSlope1 = trackParam1->GetNonBendingSlope();
       bendingMomentum1 = 0;
       if (TMath::Abs(trackParam1->GetInverseBendingMomentum()) > 0)
-       bendingMomentum1 = 1./trackParam1->GetInverseBendingMomentum();
+        bendingMomentum1 = 1./trackParam1->GetInverseBendingMomentum();
       bendingSlope = bendingSlope1;
       nonBendingSlope = nonBendingSlope1;
       bendingMomentum = bendingMomentum1;
       nRec = 1;  
-      for (Int_t iHit2 = iHit1+1; iHit2 < nTrackHits; iHit2++) {
-       hitForRec2 = (AliMUONHitForRec*) hitForRecAtHit->At(iHit2); 
-       trackParam2 = (AliMUONTrackParam*) trackParamAtHit->At(iHit2); 
-       xRec2  = hitForRec2->GetNonBendingCoor();
-       yRec2  = hitForRec2->GetBendingCoor();
-       zRec2  = hitForRec2->GetZ();      
-       bendingSlope2 = trackParam2->GetBendingSlope();
-       nonBendingSlope2 = trackParam2->GetNonBendingSlope();
-       bendingMomentum2 = 0;
-       if (TMath::Abs(trackParam2->GetInverseBendingMomentum()) > 0)
-         bendingMomentum2 = 1./trackParam2->GetInverseBendingMomentum();
-       
-       if ( TMath::Abs(zRec2-zRec1) < maxGasGap ) {
-
-         nRec++;
-         xRec += xRec2;
-         yRec += yRec2;
-         zRec += zRec2;
-         bendingSlope += bendingSlope2;
-         nonBendingSlope += nonBendingSlope2;
-         bendingMomentum += bendingMomentum2;
-         iHit1 = iHit2;
-       }
-       
+      for (Int_t iHit2 = iHit1+1; iHit2 < nTrackHits; iHit2++)
+      {
+        hitForRec2 = (AliMUONHitForRec*) hitForRecAtHit->At(iHit2); 
+        trackParam2 = (AliMUONTrackParam*) trackParamAtHit->At(iHit2); 
+        xRec2  = hitForRec2->GetNonBendingCoor();
+        yRec2  = hitForRec2->GetBendingCoor();
+        zRec2  = hitForRec2->GetZ();     
+        bendingSlope2 = trackParam2->GetBendingSlope();
+        nonBendingSlope2 = trackParam2->GetNonBendingSlope();
+        bendingMomentum2 = 0;
+        if (TMath::Abs(trackParam2->GetInverseBendingMomentum()) > 0)
+          bendingMomentum2 = 1./trackParam2->GetInverseBendingMomentum();
+        
+        if ( TMath::Abs(zRec2-zRec1) < maxGasGap ) {
+          
+          nRec++;
+          xRec += xRec2;
+          yRec += yRec2;
+          zRec += zRec2;
+          bendingSlope += bendingSlope2;
+          nonBendingSlope += nonBendingSlope2;
+          bendingMomentum += bendingMomentum2;
+          iHit1 = iHit2;
+        }
+        
       } // end iHit2
       xRec /= (Float_t)nRec;
       yRec /= (Float_t)nRec;
@@ -478,69 +364,60 @@ void AliMUONRecoCheck::CleanMuonTrackRef()
       trackParam->SetNonBendingSlope(nonBendingSlope);
       trackParam->SetBendingSlope(bendingSlope);
       if (TMath::Abs(bendingMomentum) > 0)
-       trackParam->SetInverseBendingMomentum(1./bendingMomentum);
-
-      trackNew->AddHitForRecAtHit(hitForRec);
-      trackNew->AddTrackParamAtHit(trackParam,0);
+        trackParam->SetInverseBendingMomentum(1./bendingMomentum);
+      
+      trackNew.AddHitForRecAtHit(hitForRec);
+      trackNew.AddTrackParamAtHit(trackParam,0);
       
       iHit1++;
     } // end iHit1
-
-    trackNew->SetTrackID(track->GetTrackID());
-    trackNew->SetTrackParamAtVertex(trackParamAtVertex);
-    {new ((*newMuonTrackRef)[newMuonTrackRef->GetEntriesFast()]) AliMUONTrack(*trackNew);}   
-    delete trackNew;
-    trackNew = NULL;
+    
+    trackNew.SetTrackID(track->GetTrackID());
+    trackNew.SetTrackParamAtVertex(trackParamAtVertex);
+    newMuonTrackRef->Add(trackNew);
     
   } // end trackRef
-
-  fMuonTrackRef->Delete();
-  nTrackRef = newMuonTrackRef->GetEntriesFast();
-  for (Int_t index = 0; index < nTrackRef; index++) {
-    track = (AliMUONTrack*)newMuonTrackRef->At(index);
-    AddMuonTrackReference(track);
-  }
   
   delete hitForRec;
   delete trackParam;
-  newMuonTrackRef->Delete();
-  delete newMuonTrackRef;
-  
+  return newMuonTrackRef;  
 }
 
 //_____________________________________________________________________________
-void AliMUONRecoCheck::ReconstructibleTracks()
+AliMUONVTrackStore*
+AliMUONRecoCheck::MakeReconstructibleTracks(const AliMUONVTrackStore& trackRefs)
 {
-/// Calculate the number of reconstructible tracks
+  /// Calculate the number of reconstructible tracks
+  
+  AliMUONVTrackStore* reconstructibleStore = static_cast<AliMUONVTrackStore*>(trackRefs.Create());
   
-  AliMUONTrack* track;
   TClonesArray* hitForRecAtHit = NULL;
   AliMUONHitForRec* hitForRec;
   Float_t zRec;
-  Int_t nTrackRef, nTrackHits;
+  Int_t nTrackHits;
   Int_t isChamberInTrack[10];
   Int_t iChamber = 0;
   Bool_t isTrackOK = kTRUE;
+    
+  TIter next(trackRefs.CreateIterator());
+  AliMUONTrack* track;
 
-  fReconstructibleTracks = 0;
-
-  nTrackRef = fMuonTrackRef->GetEntriesFast();
-  for (Int_t index = 0; index < nTrackRef; index++) {
-    track = (AliMUONTrack*)fMuonTrackRef->At(index);
+  while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
+  {
     hitForRecAtHit = track->GetHitForRecAtHit();
     nTrackHits = hitForRecAtHit->GetEntriesFast();
     for (Int_t ch = 0; ch < 10; ch++) isChamberInTrack[ch] = 0;
+    
     for ( Int_t iHit = 0; iHit < nTrackHits; iHit++) {
       hitForRec = (AliMUONHitForRec*) hitForRecAtHit->At(iHit); 
       zRec  = hitForRec->GetZ();
-      iChamber = hitForRec->GetChamberNumber();
+      iChamber = hitForRec->GetChamberNumber(); 
       if (iChamber < 0 || iChamber > 10) continue;
       isChamberInTrack[iChamber] = 1;
     } 
     // track is reconstructible if the particle is depositing a hit
     // in the following chamber combinations:
-
+    
     isTrackOK = kTRUE;
     if (!isChamberInTrack[0] && !isChamberInTrack[1]) isTrackOK = kFALSE;
     if (!isChamberInTrack[2] && !isChamberInTrack[3]) isTrackOK = kFALSE;
@@ -549,10 +426,13 @@ void AliMUONRecoCheck::ReconstructibleTracks()
     for (Int_t ch = 6; ch < AliMUONConstants::NTrackingCh(); ch++)
       if (isChamberInTrack[ch]) nHitsInLastStations++; 
     if(nHitsInLastStations < 3) isTrackOK = kFALSE;
-
-    if (isTrackOK) fReconstructibleTracks++;
-    if (!isTrackOK) fMuonTrackRef->Remove(track); // remove non reconstructible tracks
+    
+    if (isTrackOK) 
+    {
+      reconstructibleStore->Add(*track);
+    }
   }
-  fMuonTrackRef->Compress();
+
+  return reconstructibleStore;
 }
 
index b2ac13c..4529a96 100644 (file)
 #include "AliMUONTrack.h"
 
 class TClonesArray;
-class AliMUONRecData;
-class AliMUONSimData;
-class AliRunLoader;
-
+class AliMUONMCDataInterface;
+class AliMUONDataInterface;
+class AliMUONVTrackStore;
 
 class AliMUONRecoCheck : public TObject 
 {
 public:
   AliMUONRecoCheck(Char_t *chLoader, Char_t *chLoaderSim);
-  AliMUONRecoCheck(AliRunLoader *runloader, AliMUONRecData *muondata,
-                   AliRunLoader *runloaderSim, AliMUONSimData *muondataSim);
-  virtual          ~AliMUONRecoCheck();
-
-  /// Return MUON data          
-  AliMUONRecData*  GetMUONData() {return fMUONData;}
-  /// Return run loader         
-  AliRunLoader* GetRunLoader()    {return fRunLoader;}
-  /// Return run loader for sim data    
-  AliRunLoader* GetRunLoaderSim() {return fRunLoaderSim;}
-
-  void MakeTrackRef();
-                /// Add track reference
-  void AddMuonTrackReference(const AliMUONTrack *muonTrack) 
-    {new ((*fMuonTrackRef)[fMuonTrackRef->GetEntriesFast()]) AliMUONTrack(*muonTrack);}
-
-  void PrintEvent() const;
-  void ResetTracks() const;
-  void CleanMuonTrackRef();
-  void ReconstructibleTracks();
-                /// Return number of reconstructible tracks
-  Int_t GetNumberOfReconstuctibleTracks() {return fReconstructibleTracks;}
-                /// Return number of reconstructed tracks
-  Int_t GetNumberOfRecoTracks() {return fRecoTracks;}
-  TClonesArray *GetTrackReco();
-                /// Return reference muon tracks
-  TClonesArray *GetMuonTrackRef() {return fMuonTrackRef;}
+  virtual ~AliMUONRecoCheck();
+
+  /// Return number of reconstructed tracks
+  AliMUONVTrackStore* ReconstructedTracks(Int_t event);
+  
+  /// Return reference muon tracks
+  AliMUONVTrackStore* TrackRefs(Int_t event);
 
+  /// Return reconstructible ref tracks
+  AliMUONVTrackStore* ReconstructibleTracks(Int_t event);
+  
+  Int_t NumberOfEvents() const;
+  
 private:
   /// Not implemented
   AliMUONRecoCheck(const AliMUONRecoCheck& rhs);
   /// Not implemented
   AliMUONRecoCheck& operator = (const AliMUONRecoCheck& rhs);
-  
-  AliRunLoader*   fRunLoader;     ///< alice run loader 
-  AliMUONRecData* fMUONData;      ///< Data container for MUON subsystem 
-  AliRunLoader*   fRunLoaderSim;  ///< alice run loader 
-  AliMUONSimData* fMUONDataSim;   ///< Data container for MUON subsystem 
-  TClonesArray*   fMuonTrackRef;  ///< reference muon tracks
-  TClonesArray*   fTrackReco;     ///< reconstructed muon tracks
-  Int_t fReconstructibleTracks; ///< number of reconstructible tracks 
-  Int_t fRecoTracks;            ///< number of reconstructed tracks 
-  Bool_t fIsLoadConstructor;    //!< \brief boolean to tag the constructor, 
-                                /// to decide if the class should or not deal with the loaders
 
+  AliMUONVTrackStore* MakeReconstructibleTracks(const AliMUONVTrackStore& refTracks);
 
+  AliMUONVTrackStore* MakeTrackRefs(Int_t event);
+  
+  AliMUONVTrackStore* CleanMuonTrackRef(const AliMUONVTrackStore& refTracks);
+  
+private:
+    
+  AliMUONMCDataInterface* fMCDataInterface; ///< to access MC information
+  AliMUONDataInterface* fDataInterface; ///< to access MUON data
+  
   ClassDef(AliMUONRecoCheck, 0)   //Utility class to check reconstruction
 };
 
index 2f2f6d2..1a15a00 100644 (file)
@@ -1,22 +1,21 @@
 /**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
 
 // ROOT includes
 #include "TClonesArray.h"
 #include "TH1.h"
-#include "TParticle.h"
 #include "TFile.h"
 #include <TGeoManager.h>
 
@@ -25,7 +24,6 @@
 #include "AliHeader.h"
 #include "AliMC.h"
 #include "AliStack.h"
-#include "AliRunLoader.h"
 #include "AliMagFMaps.h"
 #include "AliTracker.h"
 
 #include "AliMUONRecoCheck.h"
 #include "AliMUONTrackParam.h"
 #include "AliMUONTrackExtrap.h"
-#include "AliMUONRecData.h"
-#include "AliMUONSimData.h"
+
+#include "AliMUONVTrackStore.h"
 
 Int_t TrackCheck( Bool_t *compTrack);
 
 void MUONRecoCheck (Int_t nEvent = 1, char* geoFilename = "geometry.root", 
                     char * filenameSim="galice_sim.root", char * filename="galice.root"){
-
+  
   // Utility macro to check the muon reconstruction. Reconstructed tracks are compared
   // to reference tracks. The reference tracks are built from AliTrackReference for the
   // hit in chamber (0..9) and from kinematics (TreeK) for the vertex parameters.     
   
-  Int_t nTrackReco, nTrackRef;
-  AliMUONTrack *trackReco, *trackRef;
   Bool_t *compTrack;
   Bool_t compTrackOK[10];
   Int_t nHitOK = 0;
   Int_t testTrack = 0; 
   Int_t iTrack = 0;
-  Int_t indexOK = 0;
+  AliMUONTrack* trackOK(0x0);
   Int_t trackID = 0;
   Double_t sigma2Cut = 16;  // 4 sigmas cut, sigma2Cut = 4*4
   AliMUONTrackParam *trackParam;
   TClonesArray *trackParamAtHit;
   Double_t x1,y1,z1,pX1,pY1,pZ1,p1;
   Double_t x2,y2,z2,pX2,pY2,pZ2,p2;
-  TParticle* particle = new TParticle();
-
-  TClonesArray *trackRecoArray = NULL;
-  TClonesArray *trackRefArray = NULL;
-
-
+  
   // File for histograms and histogram booking
   TFile *histoFile = new TFile("MUONRecoCheck.root", "RECREATE");
-
+  
   TH1F *hReconstructible = new TH1F("hReconstructible"," Nb of reconstructible tracks ",15,-0.5,14.5);
   TH1F *hReco = new TH1F("hReco"," Nb of reconstructed tracks / evt",15,-0.5,14.5);
   TH1F *hNHitComp = new TH1F("hNHitComp"," Nb of compatible hits / track ",15,-0.5,14.5);
@@ -78,7 +69,7 @@ void MUONRecoCheck (Int_t nEvent = 1, char* geoFilename = "geometry.root",
   
   TH1F *hResMomVertex = new TH1F("hMomVertex"," delta P vertex (GeV/c)",100,-10.,10);
   TH1F *hResMomFirstHit = new TH1F("hMomFirstHit"," delta P first hit (GeV/c)",100,-10.,10);
-
+  
   // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
   if (!gGeoManager) {
     TGeoManager::Import(geoFilename);
@@ -95,21 +86,10 @@ void MUONRecoCheck (Int_t nEvent = 1, char* geoFilename = "geometry.root",
   AliTracker::SetFieldMap(field, kFALSE);
   // set the magnetic field for track extrapolations
   AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
-
-  AliRunLoader* runLoaderSim = AliRunLoader::Open(filenameSim, "MUONFolderSim", "read");
-  AliRunLoader* runLoader = AliRunLoader::Open(filename, "MUONFolder", "read");
-  AliLoader * MUONLoader = runLoader->GetLoader("MUONLoader");
-  AliLoader * MUONLoaderSim = runLoaderSim->GetLoader("MUONLoader");
-  AliMUONRecData * MUONData = new AliMUONRecData(MUONLoader,"MUON","MUON");
-  AliMUONSimData * MUONDataSim = new AliMUONSimData(MUONLoaderSim,"MUON","MUON");
-
-  runLoaderSim->LoadKinematics("READ");
-  runLoaderSim->LoadTrackRefs("READ");
-  MUONLoader->LoadTracks("READ");
-  
-  AliMUONRecoCheck rc(runLoader, MUONData, runLoaderSim, MUONDataSim);
     
-  Int_t nevents = runLoader->GetNumberOfEvents();
+  AliMUONRecoCheck rc(filename,filenameSim);
+  
+  Int_t nevents = rc.NumberOfEvents();
   
   if (nevents < nEvent) nEvent = nevents;
   
@@ -117,126 +97,117 @@ void MUONRecoCheck (Int_t nEvent = 1, char* geoFilename = "geometry.root",
   Int_t nReconstructibleTracks = 0;
   Int_t nReconstructedTracks = 0;
   Int_t nReconstructibleTracksCheck = 0;
-
-  for (ievent=0; ievent<nEvent; ievent++) {
+  
+  for (ievent=0; ievent<nEvent; ievent++)
+  {
     if (!(ievent%10)) printf(" **** event # %d  \n",ievent);
-    runLoaderSim->GetEvent(ievent);
-    runLoader->GetEvent(ievent);
-
-    rc.ResetTracks();
-    rc.MakeTrackRef(); // make reconstructible tracks
-//     rc.PrintEvent();
-
     
-    trackRecoArray = rc.GetTrackReco();
-    trackRefArray = rc.GetMuonTrackRef();
+    AliMUONVTrackStore* trackStore = rc.ReconstructedTracks(ievent);
+    AliMUONVTrackStore* trackRefStore = rc.ReconstructibleTracks(ievent);
     
-    nTrackRef = trackRefArray->GetEntriesFast();
-    nTrackReco = trackRecoArray->GetEntriesFast();
-
-    hReconstructible->Fill(rc.GetNumberOfReconstuctibleTracks());
-    hReco->Fill(rc.GetNumberOfRecoTracks());
-
-    nReconstructibleTracks += rc.GetNumberOfReconstuctibleTracks();
-    nReconstructedTracks += rc.GetNumberOfRecoTracks();
-
-    for (Int_t index1 = 0; index1 < nTrackRef; index1++) {  
-      trackRef = (AliMUONTrack *)trackRefArray->At(index1);
-
+    hReconstructible->Fill(trackRefStore->GetSize());
+    hReco->Fill(trackStore->GetSize());
+    
+    nReconstructibleTracks += trackRefStore->GetSize();
+    nReconstructedTracks += trackStore->GetSize();
+    
+    TIter next(trackRefStore->CreateIterator());
+    AliMUONTrack* trackRef;
+    
+    while ( ( trackRef = static_cast<AliMUONTrack*>(next()) ) )
+    {
       testTrack = 0;
-      indexOK = 0;
+      trackOK = 0x0;
       for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) 
-       compTrackOK[ch] = kFALSE;
-      for (Int_t index2 = 0; index2 < nTrackReco; index2++) {
-       trackReco = (AliMUONTrack *)trackRecoArray->At(index2);
-
-       // check if trackRef is compatible with trackReco
-       compTrack = trackRef->CompatibleTrack(trackReco,sigma2Cut);
-
-       iTrack = TrackCheck(compTrack);
-       
-       if (iTrack > testTrack) {
-         nHitOK = 0;
-         for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
-           if (compTrack[ch]) nHitOK++;
-           compTrackOK[ch] = compTrack[ch];
-         }
-         testTrack = iTrack;
-         indexOK = index2;
-       }
+      {
+        compTrackOK[ch] = kFALSE;
       }
-
+      
+      TIter next2(trackStore->CreateIterator());
+      AliMUONTrack* trackReco;
+      
+      while ( ( trackReco = static_cast<AliMUONTrack*>(next2()) ) )
+      {
+        // check if trackRef is compatible with trackReco
+        compTrack = trackRef->CompatibleTrack(trackReco,sigma2Cut);
+        
+        iTrack = TrackCheck(compTrack);
+        
+        if (iTrack > testTrack) 
+        {
+          nHitOK = 0;
+          for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) 
+          {
+            if (compTrack[ch]) nHitOK++;
+            compTrackOK[ch] = compTrack[ch];
+          }
+          testTrack = iTrack;
+          trackOK = trackReco;
+        }
+      }
+      
       hTestTrack->Fill(testTrack);
       trackID = trackRef->GetTrackID();
       hTrackRefID->Fill(trackID);
-
+      
       if (testTrack == 4) {     // tracking requirements verified, track is found
-       nReconstructibleTracksCheck++;
-       hNHitComp->Fill(nHitOK);
-       particle = runLoaderSim->GetHeader()->Stack()->Particle(trackID);
-//     printf(" trackID: %d , PDG code: %d \n",trackID,particle->GetPdgCode());
-       trackParam = trackRef->GetTrackParamAtVertex();
-       x1 = trackParam->GetNonBendingCoor();
-       y1 = trackParam->GetBendingCoor();
-       z1 = trackParam->GetZ();
-       pX1 = trackParam->Px();
-       pY1 = trackParam->Py();
-       pZ1 = trackParam->Pz();
-       p1  = trackParam->P();
-       
-//     printf(" Ref. track at vertex: x,y,z: %f %f %f px,py,pz,p: %f %f %f %f \n",x1,y1,z1,pX1,pY1,pZ1,p1);
-       trackReco = (AliMUONTrack *)trackRecoArray->At(indexOK);
-       trackParam = new AliMUONTrackParam(*((AliMUONTrackParam*)(trackReco->GetTrackParamAtHit()->First())));
-       AliMUONTrackExtrap::ExtrapToVertex(trackParam,x1,y1,z1);
-       x2 = trackParam->GetNonBendingCoor();
-       y2 = trackParam->GetBendingCoor();
-       z2 = trackParam->GetZ();
-       pX2 = trackParam->Px();
-       pY2 = trackParam->Py();
-       pZ2 = trackParam->Pz();
-       p2  = trackParam->P();
-       delete trackParam;
-//     printf(" Reconst. track at vertex: x,y,z: %f %f %f px,py,pz: %f %f %f %f \n",x2,y2,z2,pX2,pY2,pZ2,p2);
-       
-       hResMomVertex->Fill(p2-p1);
-
-       trackParamAtHit =  trackRef->GetTrackParamAtHit();
-       trackParam = (AliMUONTrackParam*) trackParamAtHit->First();
-       x1 = trackParam->GetNonBendingCoor();
-       y1 = trackParam->GetBendingCoor();
-       z1 = trackParam->GetZ();
-       pX1 = trackParam->Px();
-       pY1 = trackParam->Py();
-       pZ1 = trackParam->Pz();
-       p1  = trackParam->P();
-//     printf(" Ref. track at 1st hit: x,y,z: %f %f %f px,py,pz: %f %f %f \n",x1,y1,z1,pX1,pY1,pZ1);
-       trackParamAtHit =  ((AliMUONTrack *) trackRecoArray->At(indexOK))->GetTrackParamAtHit();
-       trackParam = (AliMUONTrackParam*) trackParamAtHit->First();
-       x2 = trackParam->GetNonBendingCoor();
-       y2 = trackParam->GetBendingCoor();
-       z2 = trackParam->GetZ();
-       pX2 = trackParam->Px();
-       pY2 = trackParam->Py();
-       pZ2 = trackParam->Pz();
-       p2  = trackParam->P();
-//     printf(" Reconst. track at 1st hit: x,y,z: %f %f %f px,py,pz: %f %f %f \n",x2,y2,z2,pX2,pY2,pZ2);
-
-       hResMomFirstHit->Fill(p2-p1);
+        nReconstructibleTracksCheck++;
+        hNHitComp->Fill(nHitOK);
+        trackParam = trackRef->GetTrackParamAtVertex();
+        x1 = trackParam->GetNonBendingCoor();
+        y1 = trackParam->GetBendingCoor();
+        z1 = trackParam->GetZ();
+        pX1 = trackParam->Px();
+        pY1 = trackParam->Py();
+        pZ1 = trackParam->Pz();
+        p1  = trackParam->P();
+        
+        //     printf(" Ref. track at vertex: x,y,z: %f %f %f px,py,pz,p: %f %f %f %f \n",x1,y1,z1,pX1,pY1,pZ1,p1);
+        trackReco = trackOK;
+        trackParam = new AliMUONTrackParam(*((AliMUONTrackParam*)(trackReco->GetTrackParamAtHit()->First())));
+        AliMUONTrackExtrap::ExtrapToVertex(trackParam,x1,y1,z1);
+        x2 = trackParam->GetNonBendingCoor();
+        y2 = trackParam->GetBendingCoor();
+        z2 = trackParam->GetZ();
+        pX2 = trackParam->Px();
+        pY2 = trackParam->Py();
+        pZ2 = trackParam->Pz();
+        p2  = trackParam->P();
+        delete trackParam;
+        //     printf(" Reconst. track at vertex: x,y,z: %f %f %f px,py,pz: %f %f %f %f \n",x2,y2,z2,pX2,pY2,pZ2,p2);
+        
+        hResMomVertex->Fill(p2-p1);
+        
+        trackParamAtHit =  trackRef->GetTrackParamAtHit();
+        trackParam = (AliMUONTrackParam*) trackParamAtHit->First();
+        x1 = trackParam->GetNonBendingCoor();
+        y1 = trackParam->GetBendingCoor();
+        z1 = trackParam->GetZ();
+        pX1 = trackParam->Px();
+        pY1 = trackParam->Py();
+        pZ1 = trackParam->Pz();
+        p1  = trackParam->P();
+        //     printf(" Ref. track at 1st hit: x,y,z: %f %f %f px,py,pz: %f %f %f \n",x1,y1,z1,pX1,pY1,pZ1);
+        trackParamAtHit =  trackOK->GetTrackParamAtHit();
+        trackParam = (AliMUONTrackParam*) trackParamAtHit->First();
+        x2 = trackParam->GetNonBendingCoor();
+        y2 = trackParam->GetBendingCoor();
+        z2 = trackParam->GetZ();
+        pX2 = trackParam->Px();
+        pY2 = trackParam->Py();
+        pZ2 = trackParam->Pz();
+        p2  = trackParam->P();
+        //     printf(" Reconst. track at 1st hit: x,y,z: %f %f %f px,py,pz: %f %f %f \n",x2,y2,z2,pX2,pY2,pZ2);
+        
+        hResMomFirstHit->Fill(p2-p1);
               
       }
     } // end loop track ref.
-    
-  } // end loop on event  
 
-  MUONLoader->UnloadTracks();
-  runLoaderSim->UnloadKinematics();
-  runLoader->UnloadTrackRefs();
-  delete runLoader;
-  delete runLoaderSim;
+  } // end loop on event  
+  
   delete field;
-  delete MUONData;
-  delete MUONDataSim;
-
+  
   printf(" nb of reconstructible tracks: %d \n", nReconstructibleTracks);
   printf(" nb of reconstructed tracks: %d \n", nReconstructedTracks);
   printf(" nb of reconstructible tracks which are reconstructed: %d \n", nReconstructibleTracksCheck);
@@ -264,7 +235,7 @@ Int_t TrackCheck( Bool_t *compTrack)
   if (hitsInLastStations > 2) iTrack++; // at least 3 hits in st. 3 & 4
   
   return iTrack;
-
+  
 }