]> 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 1b1f6e2d715eaa0d2f645717d6d7227c673a4439..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 "AliMpBusPatch.h"
 #include "AliMUON.h"
 #include "AliMUONDigitMaker.h"
 #include "AliMUONDigit.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(Bool_t flag)
   : TObject(),
     fMUONData(0x0),
-    fSegFactory(new AliMpSegFactory()),
     fBusPatchManager(new AliMpBusPatch()),
     fScalerEvent(kFALSE),
     fDigitFlag(flag),
@@ -89,15 +96,13 @@ AliMUONDigitMaker::AliMUONDigitMaker(Bool_t flag)
     fDigit(new AliMUONDigit()),
     fLocalTrigger(new AliMUONLocalTrigger()),
     fGlobalTrigger(new AliMUONGlobalTrigger()),
-    fCrateManager(new AliMUONTriggerCrateStore()),
+    fCrateManager(0x0),
     fTrackerTimer(),
     fTriggerTimer(),
     fMappingTimer()
 {
-  //
-  // ctor with AliMUONData as argument
-  // for reconstruction
-  //
+  /// ctor with AliMUONData as argument
+  /// for reconstruction
 
   AliDebug(1,"");
 
@@ -106,9 +111,7 @@ AliMUONDigitMaker::AliMUONDigitMaker(Bool_t flag)
   // bus patch 
   fBusPatchManager->ReadBusPatchFile();
 
-  // Crate manager
-  fCrateManager->ReadFromFile();
-
   fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
   fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
   fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
@@ -118,11 +121,8 @@ AliMUONDigitMaker::AliMUONDigitMaker(Bool_t flag)
 //__________________________________________________________________________
 AliMUONDigitMaker::~AliMUONDigitMaker()
 {
-  //
-  // clean up
-  // and time processing measure
-  //
-  delete fSegFactory;  
+  /// clean up
+  /// and time processing measure
 
   delete fRawStreamTracker;
   delete fRawStreamTrigger;
@@ -131,16 +131,14 @@ AliMUONDigitMaker::~AliMUONDigitMaker()
   delete fLocalTrigger;
   delete fGlobalTrigger;
 
-  delete fCrateManager;
-
   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;
@@ -149,16 +147,15 @@ AliMUONDigitMaker::~AliMUONDigitMaker()
 //____________________________________________________________________
 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);
 
   // generate trigger
-  if (fDigitFlag)
-    ReadTriggerDDL(rawReader);
+  ReadTriggerDDL(rawReader);
 
   return kTRUE;
 
@@ -168,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
@@ -248,7 +245,7 @@ Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
            }
 
            // fill digits
-           iChamber = fDigit->DetElemId()/100 - 1;
+           iChamber = AliMpDEManager::GetChamberId(fDigit->DetElemId());
 
            if (fDigitFlag)
              fMUONData->AddDigit(iChamber, *fDigit);
@@ -270,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);
   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())
@@ -313,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;
@@ -323,6 +319,8 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
   AliMUONLocalStruct*      localStruct     = 0x0;
 
   Int_t loCircuit;
+  TList digitList;
+
 
   fTriggerTimer.Start(kFALSE);
 
@@ -333,17 +331,20 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
     ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
     darcHeader = ddlTrigger->GetDarcHeader();
 
-    // fill global trigger information
-    if (darcHeader->GetGlobalFlag()) {
-      fGlobalTrigger->SetFromGlobalResponse(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
+      // crate info
+      if (!fCrateManager) AliFatal("Crate Store not defined");
       AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
   
       if (!crate) 
@@ -355,7 +356,6 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
 
       Int_t nLocal = regHeader->GetLocalEntries();
-
       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {  
 
        localStruct = regHeader->GetLocalEntry(iLocal);
@@ -363,15 +363,38 @@ Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
        // if card has triggered
        if (localStruct->GetTriggerY() == 0) {
 
+
          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
@@ -382,13 +405,125 @@ 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
+  /// set crate name from DDL & reg number
+  /// method same as in RawWriter, not so nice
+  /// should be put in AliMUONTriggerCrateStore
 
       switch(iReg) {
       case 0: