]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitMaker.cxx
- Removing AliMpSegFactory -> using AliMpSegmentation instead
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitMaker.cxx
index 3a2e9eb5f53ddeab2efdd266fde9d4e9bc8d980d..d54b73be427da115a347b41c22b915086de07f12 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-////////////////////////////////////
-///
-/// MUON Digit maker from rawdata in ALICE-MUON
-/// Using new interface with AliMUONRawStreamTracker(Trigger)
-/// (New interface of AliMUONRawReader class)
-/// Class version 1 (further details could be found in Alice-note)
-///
-/// Implemented non-constant buspatch numbers for tracking
-/// with correct DDL id (first guess)
-/// (Ch. Finck, dec 2005)
-///
+/// \class AliMUONDigitMaker
+/// MUON Digit maker from rawdata.
 ///
 /// Raw2Digits:
 /// Using real mapping  for tracker
 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
+///
+/// Implemented non-constant buspatch numbers for tracking
+/// with correct DDL id.
+/// (Ch. Finck, dec 05)
+///
 /// Add reader for scaler trigger events
 /// Use memcpy instead of assignment elt by elt
 /// (Ch. Finck, Jan 06)
-/// 
-////////////////////////////////////
-
-#include <fstream>
-#include <string>
-
-#include <TClonesArray.h>
-
-#include "AliRawReader.h"
-#include "AliRawDataHeader.h"
-#include "AliLog.h"
-#include "AliRun.h"
+///
+/// Using new interface with AliMUONRawStreamTracker(Trigger)
+/// (New interface of AliMUONRawReader class)
+/// (further details could be found in Alice-note)
+/// (Ch. Finck, March 06)
+///
+/// Add (S)Digit maker tracker (for free)
+/// and for trigger. Create trigger inverse mapping.
+/// (Ch. Finck, oct 06) 
 
 #include "AliMUON.h"
 #include "AliMUONDigitMaker.h"
 #include "AliMUONRegHeader.h"
 #include "AliMUONLocalStruct.h"
 
+#include "AliMUONTriggerCrateStore.h"
+#include "AliMUONTriggerCrate.h"
+#include "AliMUONLocalTriggerBoard.h"
 #include "AliMUONLocalTrigger.h"
 #include "AliMUONGlobalTrigger.h"
+#include "AliMUONTriggerCircuitNew.h"
 
-#include "AliMpSegFactory.h"
+#include "AliMpSegmentation.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpPad.h"
 #include "AliMpDEManager.h"
+#include "AliMpBusPatch.h"
 
+#include "AliRawReader.h"
+#include "AliRawDataHeader.h"
+#include "AliLog.h"
+#include "AliRun.h"
+
+#include <TClonesArray.h>
+#include <TList.h>
+
+#include <fstream>
+#include <string>
+
+/// \cond CLASSIMP
 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
+/// \endcond
+
 //__________________________________________________________________________
-AliMUONDigitMaker::AliMUONDigitMaker(AliMUONData* data)
+AliMUONDigitMaker::AliMUONDigitMaker(Bool_t flag)
   : TObject(),
-    fScalerEvent(kFALSE)
+    fMUONData(0x0),
+    fBusPatchManager(new AliMpBusPatch()),
+    fScalerEvent(kFALSE),
+    fDigitFlag(flag),
+    fRawStreamTracker(new AliMUONRawStreamTracker()),    
+    fRawStreamTrigger(new AliMUONRawStreamTrigger()),    
+    fDigit(new AliMUONDigit()),
+    fLocalTrigger(new AliMUONLocalTrigger()),
+    fGlobalTrigger(new AliMUONGlobalTrigger()),
+    fCrateManager(0x0),
+    fTrackerTimer(),
+    fTriggerTimer(),
+    fMappingTimer()
 {
-  //
-  // ctor with AliMUONData as argument
-  // for reconstruction
-  //
+  /// ctor with AliMUONData as argument
+  /// for reconstruction
 
   AliDebug(1,"");
 
   // Standard Constructor
 
-  // initialize segmentation factory
-  fSegFactory = new AliMpSegFactory();
-
-  // initialize container
-  fMUONData  = data;
-
   // bus patch 
-  fBusPatchManager = new AliMpBusPatch();
   fBusPatchManager->ReadBusPatchFile();
 
-  // raw streamers
-  fRawStreamTracker = new AliMUONRawStreamTracker();    
-  fRawStreamTrigger = new AliMUONRawStreamTrigger();    
-
-  // digit
-  fDigit = new AliMUONDigit();
-
-  // local trigger
-  fLocalTrigger  =  new AliMUONLocalTrigger();
-  fGlobalTrigger =  new AliMUONGlobalTrigger();
-
-  fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
-  fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
-  fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
-
-}
-
-//__________________________________________________________________________
-AliMUONDigitMaker::AliMUONDigitMaker()
-  : TObject(),
-    fMUONData(0),
-    fSegFactory(0),
-    fBusPatchManager(0),
-    fScalerEvent(kFALSE),
-    fRawStreamTracker(0),
-    fRawStreamTrigger(0),
-    fDigit(0),
-    fLocalTrigger(0)
-{
-  //
-  // Default Constructor
-  //
-  AliDebug(1,""); 
   fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
   fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
   fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
-  
-}
 
-//_______________________________________________________________________
-AliMUONDigitMaker::AliMUONDigitMaker (const AliMUONDigitMaker& rhs)
-  : TObject(rhs)
-{
-  //
-  // Protected copy constructor
-  //
-  AliFatal("Not implemented.");
-}
-
-//_______________________________________________________________________
-AliMUONDigitMaker & 
-AliMUONDigitMaker::operator=(const AliMUONDigitMaker& rhs)
-{
-  //
-  // Protected assignement operator
-  //
-  if (this == &rhs) return *this;
-
-  AliFatal("Not implemented.");
-    
-  return *this;  
 }
 
 //__________________________________________________________________________
-AliMUONDigitMaker::~AliMUONDigitMaker(void)
+AliMUONDigitMaker::~AliMUONDigitMaker()
 {
-  //
-  // clean up
-  // and time processing measure
-  //
-  delete fSegFactory;  
+  /// clean up
+  /// and time processing measure
 
   delete fRawStreamTracker;
   delete fRawStreamTrigger;
@@ -177,12 +133,12 @@ AliMUONDigitMaker::~AliMUONDigitMaker(void)
 
   delete fBusPatchManager;
 
-  AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
+  AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
                fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
-  AliInfo(Form("   Execution time for MUON tracker (mapping calls part) "
+  AliDebug(1, Form("   Execution time for MUON tracker (mapping calls part) "
                ": R:%.2fs C:%.2fs",
                fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
-  AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
+  AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
                fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
 
   return;
@@ -191,9 +147,9 @@ AliMUONDigitMaker::~AliMUONDigitMaker(void)
 //____________________________________________________________________
 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
 {
-  // Main method to creates digit
-  // for tracker 
-  // and trigger
+  /// Main method to creates digit
+  /// for tracker 
+  /// and trigger
 
   // generate digits
   ReadTrackerDDL(rawReader);
@@ -209,9 +165,9 @@ Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
 {
 
-  // reading tracker DDL
-  // filling the TClonesArray in MUONData
-  //
+  /// reading tracker DDL
+  /// filling the TClonesArray in MUONData
+
   fTrackerTimer.Start(kFALSE);
 
   // elex info
@@ -222,6 +178,8 @@ Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
   UShort_t charge; 
   Int_t    dataSize;
 
+  Int_t iChamber;
+
   AliMUONDDLTracker*   ddlTracker = 0x0;
   AliMUONBlockHeader*  blkHeader  = 0x0;
   AliMUONDspHeader*    dspHeader  = 0x0;
@@ -268,8 +226,10 @@ Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
 
            // Get Back the hits at pads
            Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit); 
-           if (error) continue;
-
+           if (error) {
+             AliWarning("Mapping Error\n");
+             continue;
+           }
            // debugging 
            if (AliLog::GetGlobalDebugLevel() == 3) {
              Int_t padX  = fDigit->PadX();
@@ -285,7 +245,13 @@ Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
            }
 
            // fill digits
-           fMUONData->AddDigit(fRawStreamTracker->GetDDL()/2, *fDigit);
+           iChamber = AliMpDEManager::GetChamberId(fDigit->DetElemId());
+
+           if (fDigitFlag)
+             fMUONData->AddDigit(iChamber, *fDigit);
+           else
+             fMUONData->AddSDigit(iChamber, *fDigit);
+
 
          } // iData
        } // iBusPatch
@@ -301,16 +267,16 @@ Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
 Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId, 
                                         UChar_t channelId, AliMUONDigit* digit )
 {
-  //
-  // mapping  for tracker
-  //
+  /// mapping  for tracker
+
   fMappingTimer.Start(kFALSE);
   
   // getting DE from buspatch
-  Int_t  detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
+  Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
   AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
 
-  AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);  
+  const AliMpVSegmentation* seg 
+    = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, manuId);  
   AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
 
   if (!pad.IsValid())
@@ -344,9 +310,8 @@ Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId,
 //____________________________________________________________________
 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
 {
-  // reading tracker DDL
-  // filling the TClonesArray in MUONData
-  //
+  /// reading tracker DDL
+  /// filling the TClonesArray in MUONData
 
   AliMUONDDLTrigger*       ddlTrigger      = 0x0;
   AliMUONDarcHeader*       darcHeader      = 0x0;
@@ -354,6 +319,8 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
   AliMUONLocalStruct*      localStruct     = 0x0;
 
   Int_t loCircuit;
+  TList digitList;
+
 
   fTriggerTimer.Start(kFALSE);
 
@@ -364,32 +331,70 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
     ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
     darcHeader = ddlTrigger->GetDarcHeader();
 
-    // fill global trigger information
-    if (darcHeader->GetGlobalFlag() == 2) {
-      fGlobalTrigger->SetGlobalPattern(darcHeader->GetGlobalOutput());
-      fMUONData->AddGlobalTrigger(*fGlobalTrigger);
+    // fill global trigger information in Digit Tree
+    if (fDigitFlag) {
+      if (darcHeader->GetGlobalFlag()) {
+       fGlobalTrigger->SetFromGlobalResponse(darcHeader->GetGlobalOutput());
+       fMUONData->AddGlobalTrigger(*fGlobalTrigger);
+      }
     }
 
     Int_t nReg = darcHeader->GetRegHeaderEntries();
 
     for(Int_t iReg = 0; iReg < nReg ;iReg++){   //reg loop
 
+      // crate info
+      if (!fCrateManager) AliFatal("Crate Store not defined");
+      AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
+  
+      if (!crate) 
+       AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
+
+      TObjArray *boards  = crate->Boards();
+
+
       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
 
       Int_t nLocal = regHeader->GetLocalEntries();
-
       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {  
 
        localStruct = regHeader->GetLocalEntry(iLocal);
 
+       // if card has triggered
        if (localStruct->GetTriggerY() == 0) {
-         loCircuit = localStruct->GetId()+ 16*regHeader->GetId() 
-                                              + 128*fRawStreamTrigger->GetDDL(); 
+
+
+         AliMUONLocalTriggerBoard* localBoard = 
+           (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
+
+         loCircuit = localBoard->GetNumber();
+
+         if (fDigitFlag) {
+           // fill local trigger
+           fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
+
+           fMUONData->AddLocalTrigger(*fLocalTrigger);
+
+         } else {
+           // Make SDigit
+
+           digitList.Clear();
            
-         // fill local trigger
-         fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
+           if( TriggerDigits(localBoard, localStruct, digitList) ) {
+
+             for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); iEntry++) {
+
+               AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry);
+               
+               // filling S container
+               Int_t iChamber = AliMpDEManager::GetChamberId(digit->DetElemId());
+               fMUONData->AddSDigit(iChamber, *digit);
+
+             }
+
+           } // trigger digits
+         } // S flag
 
-         fMUONData->AddLocalTrigger(*fLocalTrigger);
        } // if triggerY
       } // iLocal
     } // iReg
@@ -400,4 +405,146 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
   return kTRUE;
 
 }
+//____________________________________________________________________
+void AliMUONDigitMaker::GetTriggerChamber(AliMUONLocalStruct* localStruct, Int_t& xyPattern, 
+                                         Int_t& iChamber, Int_t& iCath, Int_t icase)
+{
+  /// get chamber & cathode number, (chamber starts at 0 !)
+
+    switch(icase) {
+    case 0: 
+      xyPattern =  localStruct->GetX1();
+      iCath = 0;
+      iChamber = 10;
+      break;
+    case 1: 
+      xyPattern =  localStruct->GetX2();
+      iCath = 0;
+      iChamber = 11;
+      break;
+    case 2: 
+      xyPattern =  localStruct->GetX3();
+      iCath = 0;
+      iChamber = 12;
+      break;
+    case 3: 
+      xyPattern =  localStruct->GetX4();
+      iCath = 0;
+      iChamber = 13;
+      break;
+    case 4: 
+      xyPattern =  localStruct->GetY1();
+      iCath = 1;
+      iChamber = 10;
+      break;
+    case 5: 
+      xyPattern =  localStruct->GetY2();
+      iCath = 1;
+      iChamber = 11;
+      break;
+    case 6: 
+      xyPattern =  localStruct->GetY3();
+      iCath = 1;
+      iChamber = 12;
+      break;
+    case 7: 
+      xyPattern =  localStruct->GetY4();
+      iCath = 1;
+      iChamber = 13;
+      break;
+    }
+}
+//____________________________________________________________________
+Int_t AliMUONDigitMaker::TriggerDigits(AliMUONLocalTriggerBoard* localBoard, 
+                                      AliMUONLocalStruct* localStruct,
+                                      TList& digitList)
+{
+  /// make (S)Digit for trigger
 
+  Int_t detElemId;
+  Int_t nBoard;
+  Int_t iCath = -1;
+  Int_t iChamber = 0;
+  Int_t xyPattern = 0;
+
+  // loop over x1-4 and y1-4
+  for (Int_t icase = 0; icase < 8; icase++) {
+
+    // get chamber, cathode and associated trigger response pattern
+    GetTriggerChamber(localStruct, xyPattern, iChamber, iCath, icase);
+  
+    if (!xyPattern) continue;
+
+    // get detElemId
+    AliMUONTriggerCircuitNew triggerCircuit;
+    detElemId = triggerCircuit.DetElemId(iChamber, localBoard->GetName());
+    nBoard    = localBoard->GetNumber();
+
+    const AliMpVSegmentation* seg 
+      = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, iCath);  
+
+    // loop over the 16 bits of pattern
+    for (Int_t ibitxy = 0; ibitxy < 16; ibitxy++) {
+    
+      if ((xyPattern >> ibitxy) & 0x1) {
+
+       // not quite sure about this
+       Int_t offset = 0;
+       if (iCath && localBoard->GetSwitch(6)) offset = -8;
+
+       AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
+
+       AliMUONDigit* digit = new  AliMUONDigit();
+       if (!pad.IsValid()) {
+         AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
+                         detElemId, nBoard, ibitxy));
+         continue;
+       } // 
+
+       Int_t padX = pad.GetIndices().GetFirst();
+       Int_t padY = pad.GetIndices().GetSecond();
+
+       // file digit
+       digit->SetPadX(padX);
+       digit->SetPadY(padY);
+       digit->SetCathode(iCath);
+       digit->SetDetElemId(detElemId);
+       digit->SetElectronics(nBoard, ibitxy);
+       digitList.Add(digit);
+       
+      }// xyPattern
+    }// ibitxy
+  }// case
+
+  return kTRUE;
+} 
+//____________________________________________________________________
+void  AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg)
+{
+  /// set crate name from DDL & reg number
+  /// method same as in RawWriter, not so nice
+  /// should be put in AliMUONTriggerCrateStore
+
+      switch(iReg) {
+      case 0:
+      case 1:
+       sprintf(name,"%d", iReg+1);
+       break;
+      case 2:
+       strcpy(name, "2-3");
+       break;
+      case 3:
+      case 4:
+      case 5:
+      case 6:
+      case 7:
+       sprintf(name,"%d", iReg);
+       break;
+      }
+
+      // crate Right for first DDL
+      if (iDDL == 0)
+       strcat(name, "R");
+      else 
+       strcat(name, "L"); 
+}