]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
From Bogdan: new files / new implementation of the MUON visualization.
authormtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 31 Oct 2006 09:17:11 +0000 (09:17 +0000)
committermtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 31 Oct 2006 09:17:11 +0000 (09:17 +0000)
EVE/Alieve/MUONChamber.cxx [new file with mode: 0644]
EVE/Alieve/MUONChamber.h [new file with mode: 0644]
EVE/Alieve/MUONChamberData.cxx [new file with mode: 0644]
EVE/Alieve/MUONChamberData.h [new file with mode: 0644]
EVE/Alieve/MUONChamberEditor.cxx [new file with mode: 0644]
EVE/Alieve/MUONChamberEditor.h [new file with mode: 0644]
EVE/Alieve/MUONChamberGL.cxx [new file with mode: 0644]
EVE/Alieve/MUONChamberGL.h [new file with mode: 0644]
EVE/Alieve/MUONData.cxx [new file with mode: 0644]
EVE/Alieve/MUONData.h [new file with mode: 0644]

diff --git a/EVE/Alieve/MUONChamber.cxx b/EVE/Alieve/MUONChamber.cxx
new file mode 100644 (file)
index 0000000..553c819
--- /dev/null
@@ -0,0 +1,306 @@
+#include "MUONChamber.h"
+
+#include <Alieve/MUONData.h>
+#include <Alieve/MUONChamberData.h>
+
+#include <TBuffer3D.h>
+#include <TBuffer3DTypes.h>
+#include <TVirtualPad.h>
+#include <TVirtualViewer3D.h>
+
+#include <TStyle.h>
+#include <TColor.h>
+#include <TMath.h>
+
+using namespace Reve;
+using namespace Alieve;
+
+//______________________________________________________________________
+// MUONChamber
+//
+
+ClassImp(MUONChamber)
+
+//______________________________________________________________________
+MUONChamber::MUONChamber(const Text_t* n, const Text_t* t) :
+Reve::RenderElement(fFrameColor),
+TNamed(n,t),
+fMUONData(0),
+fFrameColor((Color_t)2),
+fRTS(1),
+fChamberID(0),
+fQuadSet1(n,t),
+fQuadSet2(n,t),
+fThreshold(0),
+fMaxVal(1024)
+{
+  //
+  // constructor
+  //
+
+  ComputeBBox();
+
+}
+
+//______________________________________________________________________
+MUONChamber::~MUONChamber()
+{
+  //
+  // destructor
+  //
+
+  if(fMUONData) fMUONData->DecRefCount();
+
+}
+
+//______________________________________________________________________
+void MUONChamber::ComputeBBox()
+{
+  //
+  // bounding box
+  //
+
+#if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2)
+  bbox_init();
+#else
+  BBoxInit();
+#endif
+  
+  fBBox[0] = -300.0;
+  fBBox[1] = +300.0;
+  fBBox[2] = -300.0;
+  fBBox[3] = +300.0;
+  fBBox[4] = -1800.0;
+  fBBox[5] = -500.0;
+
+  Float_t* b1 = fQuadSet1.AssertBBox();
+  for(Int_t i=0; i<6; ++i) { b1[i] = fBBox[i]; }
+  Float_t* b2 = fQuadSet2.AssertBBox();
+  for(Int_t i=0; i<6; ++i) { b2[i] = fBBox[i]; }
+  
+}
+
+//______________________________________________________________________
+void MUONChamber::Paint(Option_t*)
+{
+  //
+  // draw...
+  //
+
+  if(fRnrElement == kFALSE)
+    return;
+
+  TBuffer3D buffer(TBuffer3DTypes::kGeneric);
+
+  buffer.fID           = this;
+  buffer.fColor        = 2;
+  buffer.fTransparency = 0;
+  buffer.fLocalFrame   = 0;
+
+  buffer.SetSectionsValid(TBuffer3D::kCore);
+  Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
+  if (reqSections == TBuffer3D::kNone) {
+    //printf("MUONChamber::Paint viewer was happy with Core buff3d.\n");
+    return;
+  }
+
+  printf("MUONChamber::Paint only GL supported.\n");
+  return;
+
+}
+
+//______________________________________________________________________
+void MUONChamber::SetThreshold(Short_t t)
+{
+  //
+  // digits amplitude threshold
+  //
+
+  fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
+  ClearColorArray();
+  IncRTS();
+
+}
+
+//______________________________________________________________________
+void MUONChamber::SetMaxVal(Int_t mv)
+{
+  //
+  // digits amplitude maximum value
+  //
+
+  fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
+  ClearColorArray();
+  IncRTS();
+
+}
+
+//______________________________________________________________________
+void MUONChamber::SetupColor(Int_t val, UChar_t* pixel) const
+{
+  //
+  // RGBA color for amplitude "val"
+  //
+
+  Float_t div  = TMath::Max(1, fMaxVal - fThreshold);
+  Int_t   nCol = gStyle->GetNumberOfColors();
+  Int_t   cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
+
+  ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
+
+}
+
+//______________________________________________________________________
+Int_t MUONChamber::ColorIndex(Int_t val) const
+{
+  //
+  // index color 
+  //
+
+  if(val < fThreshold) val = fThreshold;
+  if(val > fMaxVal)    val = fMaxVal;
+
+  Float_t div  = TMath::Max(1, fMaxVal - fThreshold);
+  Int_t   nCol = gStyle->GetNumberOfColors();
+  Int_t   cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
+
+  return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin));
+
+}
+
+//______________________________________________________________________
+void MUONChamber::SetupColorArray() const
+{
+  //
+  // build array of colors
+  //
+
+  if(fColorArray)
+    return;
+
+  fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
+  UChar_t* p = fColorArray;
+  for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
+    SetupColor(v, p);
+
+}
+
+//______________________________________________________________________
+void MUONChamber::ClearColorArray()
+{
+  //
+  // delete array of colors
+  //
+
+  if(fColorArray) {
+    delete [] fColorArray;
+    fColorArray = 0;
+  }
+}
+
+//______________________________________________________________________
+void MUONChamber::SetDataSource(MUONData* data)
+{
+
+  if (data == fMUONData) return;
+  if(fMUONData) fMUONData->DecRefCount();
+  fMUONData = data;
+  if(fMUONData) fMUONData->IncRefCount();
+  IncRTS();
+
+}
+
+//______________________________________________________________________
+MUONChamberData* MUONChamber::GetChamberData() const
+{
+  
+  return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0;
+
+}
+
+//______________________________________________________________________
+void MUONChamber::UpdateQuads()
+{
+
+  fQuadSet1.Quads().clear();
+  fQuadSet2.Quads().clear();
+
+  MUONChamberData* data = GetChamberData();
+  
+  Float_t *buffer;
+  Float_t x0, y0, x1, y1, z;
+  Int_t charge, cathode;
+  if (data != 0) {
+
+    SetupColorArray();
+
+    Int_t ndigits = data->GetNDigits();
+    
+    for (Int_t id = 0; id < ndigits; id++) {
+
+      buffer = data->GetDigitBuffer(id);
+
+      x0 = buffer[0]-buffer[2];
+      y0 = buffer[1]-buffer[3];
+      x1 = buffer[0]+buffer[2];
+      y1 = buffer[1]+buffer[3];
+      z  = buffer[4];
+      charge = (Int_t)buffer[5];
+      cathode = (Int_t)buffer[6];
+      
+      if (cathode == 0) {
+
+       fQuadSet1.Quads().push_back(Reve::Quad());
+       
+       fQuadSet1.Quads().back().ColorFromIdx(ColorIndex(charge));
+       //ColorFromArray(charge,(UChar_t*)&fQuadSet1.fQuads.back().color);
+       
+       //UChar_t* c = (UChar_t*)&fQuadSet1.fQuads.back().color; 
+       //printf("%d %d %d %d \n",c[0],c[1],c[2],c[3]);
+       
+       Float_t* p = fQuadSet1.Quads().back().vertices;
+       
+       p[0] = x0;  p[1] = y0;  p[2] = z;  p += 3;
+       p[0] = x1;  p[1] = y0;  p[2] = z;  p += 3;
+       p[0] = x1;  p[1] = y1;  p[2] = z;  p += 3;
+       p[0] = x0;  p[1] = y1;  p[2] = z;  p += 3;
+       
+      }
+
+      if (cathode == 1) {
+
+       fQuadSet2.Quads().push_back(Reve::Quad());
+       
+       fQuadSet2.Quads().back().ColorFromIdx(ColorIndex(charge));
+       //ColorFromArray(charge,(UChar_t*)&fQuadSet2.fQuads.back().color);
+       
+       //UChar_t* c = (UChar_t*)&fQuadSet2.fQuads.back().color; 
+       //printf("%d %d %d %d \n",c[0],c[1],c[2],c[3]);
+       
+       Float_t* p = fQuadSet2.Quads().back().vertices;
+       
+       p[0] = x0;  p[1] = y0;  p[2] = z;  p += 3;
+       p[0] = x1;  p[1] = y0;  p[2] = z;  p += 3;
+       p[0] = x1;  p[1] = y1;  p[2] = z;  p += 3;
+       p[0] = x0;  p[1] = y1;  p[2] = z;  p += 3;
+       
+      }
+
+    } // end digits loop
+
+  }
+
+}
+
+//______________________________________________________________________
+void MUONChamber::SetChamberID(Int_t id)
+{
+
+  if (id <  0) id = 0;
+  if (id > 13) id = 13;
+
+  fChamberID = id;
+  IncRTS();
+
+}
+
diff --git a/EVE/Alieve/MUONChamber.h b/EVE/Alieve/MUONChamber.h
new file mode 100644 (file)
index 0000000..f2e1279
--- /dev/null
@@ -0,0 +1,91 @@
+#ifndef ALIEVE_MUONChamber_H
+#define ALIEVE_MUONChamber_H
+
+#include <Reve/RenderElement.h>
+#include <Reve/QuadSet.h>
+
+#include <TNamed.h>
+#include <TAtt3D.h>
+#include <TAttBBox.h>
+
+namespace Alieve {
+
+class MUONData;
+class MUONChamberData;
+class MUONChamberEditor;
+class MUONChamberGL;
+
+class MUONChamber : public Reve::RenderElement,
+                    public TNamed,
+                    public TAtt3D,
+                    public TAttBBox
+
+{
+
+  friend class MUONChamberGL;
+  friend class MUONChamberEditor;
+
+  MUONChamber(const MUONChamber&);            // Not implemented
+  MUONChamber& operator=(const MUONChamber&); // Not implemented
+
+ protected:
+
+  void UpdateQuads();
+
+  MUONData*         fMUONData;      // data for the current event
+  Color_t           fFrameColor;    // main coloring
+  UInt_t            fRTS;           //! Rendering Time Stamp
+  Int_t             fChamberID;     // number of the chamber, 0 to 13
+  Reve::OldQuadSet  fQuadSet1;      // 1st cathode plane digits
+  Reve::OldQuadSet  fQuadSet2;      // 2nd cathode plane digits
+  Short_t           fThreshold;     // digit amplitude threshold
+  Int_t             fMaxVal;        // digit amplitude maximum value
+
+  void SetupColor(Int_t val, UChar_t* pix) const;
+
+  mutable UChar_t* fColorArray;
+  void ClearColorArray();
+  void SetupColorArray() const;
+  UChar_t* ColorFromArray(Int_t val) const;
+  void     ColorFromArray(Int_t val, UChar_t* pix) const;
+  Int_t    ColorIndex(Int_t val) const;
+
+public:
+
+  MUONChamber(const Text_t* n = "MUONChamber", const Text_t* t = 0);
+  virtual ~MUONChamber();
+
+  virtual void ComputeBBox();
+  virtual void Paint(Option_t* option = "");
+  virtual UInt_t IncRTS()     { return ++fRTS; };
+  virtual Bool_t CanEditMainColor() { return kTRUE; }
+
+  void SetDataSource(MUONData *data);
+  void SetChamberID(Int_t id);
+  void SetFrameColor(Color_t col)     { fFrameColor = col; IncRTS(); };
+  MUONData* GetData() const { return fMUONData; };
+  MUONChamberData* GetChamberData() const;
+  Int_t GetID() const { return fChamberID; };
+  void SetThreshold(Short_t t);
+  void SetMaxVal(Int_t mv);
+
+  ClassDef(MUONChamber,1);  // Visualisation of the MUON chambers
+
+};
+
+inline UChar_t* MUONChamber::ColorFromArray(Int_t val) const
+{
+  if(val < fThreshold) val = fThreshold;
+  if(val > fMaxVal)    val = fMaxVal;
+  return fColorArray + 4 * (val - fThreshold);
+}
+
+inline void MUONChamber::ColorFromArray(Int_t val, UChar_t* pix) const
+{
+  UChar_t* c = ColorFromArray(val);
+  pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2]; pix[3] = c[3];
+}
+
+}
+
+#endif
diff --git a/EVE/Alieve/MUONChamberData.cxx b/EVE/Alieve/MUONChamberData.cxx
new file mode 100644 (file)
index 0000000..4160a16
--- /dev/null
@@ -0,0 +1,253 @@
+#include "MUONChamberData.h"
+
+#include <AliMUONSegmentation.h>
+#include <AliMUONConstants.h>
+#include <AliMUONGeometryTransformer.h>
+#include <AliMUONSegFactory.h>
+#include <mapping/AliMpDEIterator.h>
+#include <mapping/AliMpSectorSegmentation.h>
+#include <mapping/AliMpSector.h>
+#include <mapping/AliMpPad.h>
+#include <mapping/AliMpStationType.h>
+#include <mapping/AliMpDEManager.h>
+#include <mapping/AliMpSegmentation.h>
+
+#include <TMath.h>
+#include <TVector2.h>
+
+///////////////////////////////////////////////////////////////////////////////
+///
+/// MUONChamberData: geometry and digits
+///
+///////////////////////////////////////////////////////////////////////////////
+
+using namespace Reve;
+using namespace Alieve;
+
+ClassImp(MUONChamberData)
+
+AliMUONSegmentation* MUONChamberData::fgSegmentation = 0;
+AliMUONGeometryTransformer* MUONChamberData::fgTransformer = 0;
+
+//______________________________________________________________________
+MUONChamberData::MUONChamberData(Int_t chamber)
+{
+  //
+  // constructor
+  //
+
+  fChamberID = chamber;
+  fNDetElem  = 0;
+  fNDigits   = 0;
+  for (Int_t i = 0; i < 26; i++) {
+    for (Int_t j = 0; j < 4; j++) {
+      fFrameCoord[i][j] = 0.0;
+    }
+  }
+  for (Int_t i = 0; i < 7*4096; i++) {
+    fDigitBuffer[i] = 0.0;
+  }
+
+  for (Int_t i = 0; i < 3; i++) {
+    fChamberBox[i*2  ] = +9999;
+    fChamberBox[i*2+1] = -9999;
+  }
+
+  if (fgSegmentation == 0) {
+    AliMUONSegFactory segFactory("volpath.dat","transform.dat");
+    fgSegmentation = segFactory.CreateSegmentation("FactoryV4");
+    fgTransformer = new AliMUONGeometryTransformer(true);
+    fgTransformer->ReadGeometryData("volpaths.dat","transform.dat");
+  }
+
+  Init(chamber);
+
+}
+
+//______________________________________________________________________
+MUONChamberData::~MUONChamberData()
+{
+  //
+  // destructor
+  //
+
+}
+
+//______________________________________________________________________
+void MUONChamberData::DropData()
+{
+  //
+  // release the chamber data
+  //
+
+  return;
+
+}
+
+//______________________________________________________________________
+void MUONChamberData::Init(Int_t chamber)
+{
+  //
+  // initialize the drawing coordinates of the chamber
+  //
+
+  Float_t locP[3], gloP[3], locD[3], gloD[3];
+  Float_t deltax, deltay;
+  AliMpDEIterator it;
+  const AliMpVSegmentation *vseg;
+  const AliMpSectorSegmentation *sseg;
+  const AliMpSector *sector;
+  TVector2 position;
+  TVector2 dimension;
+
+  for ( it.First(chamber); ! it.IsDone(); it.Next() ) {
+
+    Int_t detElemId = it.CurrentDE();
+
+    if (chamber < 4) {
+
+      sseg = (AliMpSectorSegmentation*)AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,0);
+      sector = sseg->GetSector();
+      
+      position  = sector->Position(); 
+      dimension = sector->Dimensions(); // half length
+      
+      locP[0] =  position.Px();
+      locP[1] =  position.Py();
+      locD[0] =  dimension.Px() * 2.;
+      locD[1] =  dimension.Py() * 2.;
+      
+      locP[2] = 0.0;
+      locD[2] = 0.0;
+
+      fgTransformer->Local2Global(detElemId, 
+                                 locP[0], locP[1], locP[2], 
+                                 gloP[0], gloP[1], gloP[2]);
+      
+      fgTransformer->Local2Global(detElemId,
+                                 locD[0], locD[1], locD[2], 
+                                 gloD[0], gloD[1], gloD[2]);
+      
+      fFrameCoord[fNDetElem][0] = gloP[0]; 
+      fFrameCoord[fNDetElem][1] = gloP[1]; 
+      fFrameCoord[fNDetElem][2] = gloD[0]; 
+      fFrameCoord[fNDetElem][3] = gloD[1]; 
+      fFrameCoord[fNDetElem][4] = gloP[2]; // Z position
+
+      fChamberBox[0] = TMath::Min(fChamberBox[0],gloP[0]-gloD[0]);
+      fChamberBox[1] = TMath::Max(fChamberBox[1],gloP[0]+gloD[0]);
+      fChamberBox[2] = TMath::Min(fChamberBox[2],gloP[1]-gloD[1]);
+      fChamberBox[3] = TMath::Max(fChamberBox[3],gloP[1]+gloD[1]);
+      fChamberBox[4] = TMath::Min(fChamberBox[4],gloP[2]);
+      fChamberBox[5] = TMath::Max(fChamberBox[5],gloP[2]);
+    
+    } else {
+
+      //AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
+
+      if (!fgSegmentation->HasDE(detElemId)) {
+       printf("Segmentation has no %d detElemId! \n",detElemId);
+       continue;
+      }
+
+      vseg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,0);
+
+      if (vseg == 0) {
+       printf("No MpVSegmentation for %d detElemId! \n",detElemId);
+       continue;
+      }
+
+      deltax = vseg->Dimensions().X();
+      deltay = vseg->Dimensions().Y();
+      locP[0] =  -deltax;
+      locP[1] =  -deltay;
+      locD[0] =  +deltax;
+      locD[1] =  +deltay;
+
+      locP[2] = 0.0;
+      locD[2] = 0.0;
+
+      fgTransformer->Local2Global(detElemId, 
+                                 locP[0], locP[1], locP[2], 
+                                 gloP[0], gloP[1], gloP[2]);
+      
+      fgTransformer->Local2Global(detElemId,
+                                 locD[0], locD[1], locD[2], 
+                                 gloD[0], gloD[1], gloD[2]);
+      
+      fFrameCoord[fNDetElem][0] = gloP[0]; 
+      fFrameCoord[fNDetElem][1] = gloP[1]; 
+      fFrameCoord[fNDetElem][2] = gloD[0]; 
+      fFrameCoord[fNDetElem][3] = gloD[1]; 
+      fFrameCoord[fNDetElem][4] = gloP[2]; // Z position
+
+      fChamberBox[0] = TMath::Min(fChamberBox[0],gloP[0]);
+      fChamberBox[0] = TMath::Min(fChamberBox[0],gloD[0]);
+      fChamberBox[1] = TMath::Max(fChamberBox[1],gloP[0]);
+      fChamberBox[1] = TMath::Max(fChamberBox[1],gloD[0]);
+      fChamberBox[2] = TMath::Min(fChamberBox[0],gloP[1]);
+      fChamberBox[2] = TMath::Min(fChamberBox[0],gloD[1]);
+      fChamberBox[3] = TMath::Max(fChamberBox[1],gloP[1]);
+      fChamberBox[3] = TMath::Max(fChamberBox[1],gloD[1]);
+      fChamberBox[4] = TMath::Min(fChamberBox[4],gloP[2]);
+      fChamberBox[5] = TMath::Max(fChamberBox[5],gloP[2]);
+    
+    }
+
+    fNDetElem++;
+
+  }  // end detElemId loop
+
+  //printf("ChamberBox %d \n",chamber);
+  //printf("%f %f \n",fChamberBox[0],fChamberBox[1]);
+  //printf("%f %f \n",fChamberBox[2],fChamberBox[3]);
+  //printf("%f %f \n",fChamberBox[4],fChamberBox[5]);
+
+}
+
+//______________________________________________________________________
+void MUONChamberData::RegisterDigit(Int_t detElemId, Int_t cathode, Int_t ix, Int_t iy, Int_t charge)
+{
+  //
+  // add a digit to this chamber
+  //
+
+  Float_t locP[3], gloP[3], locD[3], gloD[3];
+
+  const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,cathode);
+
+  AliMpPad pad = vseg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
+  
+  locP[0] = pad.Position().X();
+  locP[1] = pad.Position().Y();
+  locD[0] = pad.Dimensions().X();
+  locD[1] = pad.Dimensions().Y();
+  
+  locP[2] = 0.0;
+  locD[2] = 0.0;
+
+  fgTransformer->Local2Global(detElemId, 
+                             locP[0], locP[1], locP[2], 
+                             gloP[0], gloP[1], gloP[2]);
+  
+  gloD[0] = locD[0];
+  gloD[1] = locD[1];
+  gloD[2] = gloP[2];
+
+  //printf("DigitP %f %f %f \n",gloP[0],gloP[1],gloP[2]);
+  //printf("DigitD %f %f \n",gloD[0],gloD[1]);
+
+  if (cathode == 0) gloP[2] += 0.1;
+  if (cathode == 1) gloP[2] -= 0.1;
+
+  fDigitBuffer[fNDigits  ] = gloP[0];
+  fDigitBuffer[fNDigits+1] = gloP[1];
+  fDigitBuffer[fNDigits+2] = gloD[0];
+  fDigitBuffer[fNDigits+3] = gloD[1];
+  fDigitBuffer[fNDigits+4] = gloP[2];
+  fDigitBuffer[fNDigits+5] = charge;
+  fDigitBuffer[fNDigits+6] = cathode;
+
+  fNDigits += 7;
+
+}
diff --git a/EVE/Alieve/MUONChamberData.h b/EVE/Alieve/MUONChamberData.h
new file mode 100644 (file)
index 0000000..862f019
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef ALIEVE_MUONChamberData_H
+#define ALIEVE_MUONChamberData_H
+
+#include <Reve/Reve.h>
+
+#include <TObject.h>
+
+class AliMUONSegmentation;
+class AliMUONGeometryTransformer;
+
+namespace Alieve {
+
+class MUONChamberData : public TObject
+{
+
+  MUONChamberData(const MUONChamberData&);            // Not implemented
+  MUONChamberData& operator=(const MUONChamberData&); // Not implemented
+
+private:
+
+  static AliMUONSegmentation*        fgSegmentation;  // detector segmentation
+  static AliMUONGeometryTransformer* fgTransformer;   // geometry transformer
+
+protected:
+
+  Int_t   fChamberID;                 // number of the chamber, 0 to 13
+  Float_t fFrameCoord[26][5];         // detector elements frames
+  Int_t   fNDetElem;                  // number of detector elements
+  Int_t   fNDigits;                   // number of found digits (times 7)
+  Float_t fDigitBuffer[7*4096];       // digits coordinates, etc.
+  Float_t fChamberBox[6];             // chamber envelope box
+
+public:
+
+  MUONChamberData(Int_t chamber);
+  virtual ~MUONChamberData();
+
+  void DropData();
+
+  void     Init(Int_t chamber);
+  void     RegisterDigit(Int_t detElemId, Int_t cathode, Int_t ix, Int_t iy, Int_t charge);
+  Float_t* GetFrameCoord(Int_t detElemId) { return fFrameCoord[detElemId]; };
+  Int_t    GetNDetElem() { return fNDetElem; };
+  Int_t    GetNDigits() { return fNDigits/7; };
+  Float_t* GetDigitBuffer(Int_t pos) { return &fDigitBuffer[7*pos]; };
+  Float_t* GetChamberBox() { return &fChamberBox[0]; };
+
+  ClassDef(MUONChamberData,1);     // class with data for one chamber
+
+};
+
+}
+
+#endif
diff --git a/EVE/Alieve/MUONChamberEditor.cxx b/EVE/Alieve/MUONChamberEditor.cxx
new file mode 100644 (file)
index 0000000..f02ff81
--- /dev/null
@@ -0,0 +1,57 @@
+#include "MUONChamberEditor.h"
+
+#include <Alieve/MUONChamber.h>
+
+#include <TVirtualPad.h>
+#include <TColor.h>
+
+#include <TGLabel.h>
+#include <TGButton.h>
+#include <TGNumberEntry.h>
+#include <TGColorSelect.h>
+#include <TGSlider.h>
+#include <TGDoubleSlider.h>
+
+using namespace Reve;
+using namespace Alieve;
+
+//______________________________________________________________________
+// MUONChamberEditor
+//
+
+ClassImp(MUONChamberEditor)
+
+//______________________________________________________________________
+MUONChamberEditor::MUONChamberEditor(const TGWindow *p,
+                                     Int_t width, Int_t height,
+                                     UInt_t options, Pixel_t back) :
+  TGedFrame(p, width, height, options | kVerticalFrame, back),
+  fM(0)
+{
+  //
+  // constructor
+  //
+
+  MakeTitle("MUONChamber");
+
+}
+
+//______________________________________________________________________
+MUONChamberEditor::~MUONChamberEditor()
+{
+  //
+  // destructor
+  //
+
+}
+
+//______________________________________________________________________
+void MUONChamberEditor::SetModel(TObject* obj)
+{
+  //
+  // ...
+  //
+
+  fM = dynamic_cast<MUONChamber*>(obj);
+
+}
diff --git a/EVE/Alieve/MUONChamberEditor.h b/EVE/Alieve/MUONChamberEditor.h
new file mode 100644 (file)
index 0000000..3edac17
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef ALIEVE_MUONChamberEditor_H
+#define ALIEVE_MUONChamberEditor_H
+
+#include <TGedFrame.h>
+
+class TGCheckButton;
+class TGNumberEntry;
+class TGColorSelect;
+class TGDoubleHSlider;
+class TGHSlider;
+
+namespace Alieve {
+
+class MUONChamber;
+
+class MUONChamberEditor : public TGedFrame
+{
+
+  MUONChamberEditor(const MUONChamberEditor&);            // Not implemented
+  MUONChamberEditor& operator=(const MUONChamberEditor&); // Not implemented
+  
+ protected:
+
+  MUONChamber* fM; // fModel dynamic-casted to MUONChamberEditor
+
+ public:
+
+  MUONChamberEditor(const TGWindow* p,
+                   Int_t width = 170, Int_t height = 30, 
+                   UInt_t options = kChildFrame, 
+                   Pixel_t back = GetDefaultFrameBackground());
+  
+  ~MUONChamberEditor();
+
+  virtual void SetModel(TObject* obj);
+
+  ClassDef(MUONChamberEditor, 0); // Editor for MUONChamber
+
+};
+
+}
+
+#endif
diff --git a/EVE/Alieve/MUONChamberGL.cxx b/EVE/Alieve/MUONChamberGL.cxx
new file mode 100644 (file)
index 0000000..583c680
--- /dev/null
@@ -0,0 +1,228 @@
+#include "MUONChamberGL.h"
+
+#include <Alieve/MUONChamber.h>
+#include <Alieve/MUONChamberData.h>
+
+#include <TGLDrawFlags.h>
+#include <Reve/QuadSetGL.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+using namespace Reve;
+using namespace Alieve;
+
+//______________________________________________________________________
+// MUONChamberGL
+//
+
+ClassImp(MUONChamberGL)
+
+//______________________________________________________________________
+MUONChamberGL::MUONChamberGL() :
+  TGLObject(),
+  fChamber(0),
+  fRTS(0)
+{
+  //
+  // constructor
+  //
+
+}
+
+//______________________________________________________________________
+MUONChamberGL::~MUONChamberGL()
+{
+  //
+  // destructor
+  //
+
+}
+
+//______________________________________________________________________
+Bool_t MUONChamberGL::SetModel(TObject* obj)
+{
+  //
+  // ...
+  //
+
+#if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2)
+  if(set_model(obj, "Alieve::MUONChamber")) {
+#elif ROOT_VERSION_CODE <= ROOT_VERSION(5,13,0)
+  if(SetModelCheckClass(obj, "Alieve::MUONChamber")) {
+#else
+  if(SetModelCheckClass(obj, Alieve::MUONChamber::Class())) {
+#endif
+    
+    fChamber = (MUONChamber*) fExternalObj;
+    
+    return kTRUE;
+
+  }
+
+  return kFALSE;
+
+}
+
+//______________________________________________________________________
+void MUONChamberGL::SetBBox()
+{
+  //
+  // ...
+  //
+
+#if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2)
+  set_axis_aligned_bbox(((MUONChamber*)fExternalObj)->AssertBBox());
+#else
+  SetAxisAlignedBBox(((MUONChamber*)fExternalObj)->AssertBBox());
+#endif
+
+}
+
+//______________________________________________________________________
+void MUONChamberGL::DirectDraw(const TGLDrawFlags& /*flags*/) const
+{
+  //
+  // Actual GL drawing.
+  //
+
+  glDisable(GL_LIGHTING);
+
+  //Double_t width = 10;
+  //glOrtho(-width,+width,-width,+width,-width,+width);
+
+  if(fRTS < fChamber->fRTS) {
+    fChamber->UpdateQuads();
+    fRTS = fChamber->fRTS;
+  }
+  
+  Bool_t hasData = (fChamber->GetChamberData() != 0);
+  
+  if(hasData) {
+
+    DrawQuads();
+  
+  }
+
+  DrawChamberFrame();
+
+}
+
+//______________________________________________________________________
+void MUONChamberGL::DrawQuads() const
+{
+  //
+  // draw the digits as GL_QUADS
+  //
+
+  glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
+
+  glDisable(GL_LIGHTING);
+  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+  glEnable(GL_COLOR_MATERIAL);
+  glDisable(GL_CULL_FACE);
+
+  //Float_t c[4]; glGetFloatv(GL_CURRENT_COLOR, c);
+
+  glPolygonMode(GL_FRONT, GL_FILL);
+  glPolygonMode(GL_BACK,  GL_LINE);
+
+  glBegin(GL_QUADS);
+  for(std::vector<Quad>::iterator q=fChamber->fQuadSet1.Quads().begin(); q!=fChamber->fQuadSet1.Quads().end(); ++q) {
+    UChar_t* c = (UChar_t*) &q->color;
+    glColor4ubv(c);
+    glVertex3fv(q->vertices);
+    glVertex3fv(q->vertices + 3);
+    glVertex3fv(q->vertices + 6);
+    glVertex3fv(q->vertices + 9);
+  }
+  glEnd();
+
+  glPolygonMode(GL_FRONT, GL_LINE);
+  glPolygonMode(GL_BACK,  GL_FILL);
+
+  glBegin(GL_QUADS);
+  for(std::vector<Quad>::iterator q=fChamber->fQuadSet2.Quads().begin(); q!=fChamber->fQuadSet2.Quads().end(); ++q) {
+    UChar_t* c = (UChar_t*) &q->color;
+    glColor4ubv(c);
+    glVertex3fv(q->vertices);
+    glVertex3fv(q->vertices + 3);
+    glVertex3fv(q->vertices + 6);
+    glVertex3fv(q->vertices + 9);
+  }
+  glEnd();
+
+  glPopAttrib();
+
+}
+
+//______________________________________________________________________
+void MUONChamberGL::DrawChamberFrame() const
+{
+  //
+  // draw the chamber frame as GL_LINE_LOOP
+  // 
+
+  MUONChamberData* chamberData = fChamber->GetChamberData();
+  Int_t nDetElem = chamberData->GetNDetElem();
+  Float_t *frameCoord;
+  Float_t xOrig, yOrig, xRad, yRad, x, y, z;
+
+  UChar_t pix[4];
+  pix[0] = 255;
+  pix[1] =   0;
+  pix[2] =   0;
+  pix[3] = 255;
+
+  glColor4ubv(pix);
+  
+  for (Int_t id = 0; id < nDetElem; id++) {
+
+    frameCoord = chamberData->GetFrameCoord(id);
+
+    if (fChamber->GetID() < 4) {
+
+      xOrig = frameCoord[0];
+      yOrig = frameCoord[1];
+      xRad  = frameCoord[2];
+      yRad  = frameCoord[3];
+      z     = frameCoord[4];
+      
+      xRad += 0.0;
+      yRad += 0.0;
+
+      glBegin(GL_LINE_LOOP);
+
+      glVertex3f(xOrig,yOrig,z);
+      
+      Int_t nstep = 100;
+      Float_t dstep = TMath::Pi()/2.0 / (Float_t)nstep;
+      Float_t d;
+      for (Int_t istep = 0; istep < nstep; istep++) {
+
+       d = istep * dstep;
+       x = xOrig + xRad * TMath::Cos(d);
+       y = yOrig + yRad * TMath::Sin(d);
+
+       glVertex3f(x,y,z);
+
+      }
+      
+      glVertex3f(xOrig,yOrig,z);
+
+      glEnd();
+
+    } else {
+
+      glBegin(GL_LINE_LOOP);
+      glVertex3f(frameCoord[0],frameCoord[1],frameCoord[4]);
+      glVertex3f(frameCoord[0],frameCoord[3],frameCoord[4]);
+      glVertex3f(frameCoord[2],frameCoord[3],frameCoord[4]);
+      glVertex3f(frameCoord[2],frameCoord[1],frameCoord[4]);
+      glVertex3f(frameCoord[0],frameCoord[1],frameCoord[4]);
+      glEnd();
+
+    }
+
+  }
+
+}
diff --git a/EVE/Alieve/MUONChamberGL.h b/EVE/Alieve/MUONChamberGL.h
new file mode 100644 (file)
index 0000000..c7cb745
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef ALIEVE_MUONChamberGL_H
+#define ALIEVE_MUONChamberGL_H
+
+#include <TGLObject.h>
+
+namespace Reve {
+class QuadSetGL;
+}
+
+namespace Alieve {
+
+class MUONChamber;
+
+class MUONChamberGL : public TGLObject
+{
+
+  MUONChamberGL(const MUONChamberGL&);            // Not implemented
+  MUONChamberGL& operator=(const MUONChamberGL&); // Not implemented
+
+ protected:
+
+  virtual void DirectDraw(const TGLDrawFlags & flags) const;
+  void DrawChamberFrame() const;
+  void DrawQuads() const;
+
+  MUONChamber*             fChamber; // fModel dynamic-casted to MUONChamberGL
+  mutable UInt_t           fRTS;     // render time stamp
+
+ public:
+
+  MUONChamberGL();
+  virtual ~MUONChamberGL();
+
+  virtual Bool_t SetModel(TObject* obj);
+  virtual void   SetBBox();
+
+  ClassDef(MUONChamberGL,1);   // the GL drawing class of one chamber
+
+};
+
+}
+
+
+#endif
diff --git a/EVE/Alieve/MUONData.cxx b/EVE/Alieve/MUONData.cxx
new file mode 100644 (file)
index 0000000..37cbe08
--- /dev/null
@@ -0,0 +1,838 @@
+//
+// Sources:
+//
+// GetTrackerMapping = AliMUONDigitMaker::GetMapping
+// GetTriggerMapping = AliMUONDigitMaker::TriggerDigits
+// GetTriggerChamber = AliMUONDigitMaker::GetTriggerChamber
+// LoadRawTracker    = MUONRawStreamTracker.C
+// LoadRawTrigger    = MUONRawStreamTrigger.C
+//
+
+#include "MUONData.h"
+
+#include <Alieve/MUONChamberData.h>
+#include <Alieve/EventAlieve.h>
+
+#include <AliRawReader.h>
+#include <AliRawReaderFile.h>
+#include <AliRawReaderDate.h>
+#include <AliRawReaderRoot.h>
+
+#include <AliTracker.h>
+#include <AliMagFMaps.h>
+
+#include <AliMUONTrack.h>
+#include <AliMUONTrackParam.h>
+#include <AliMUONDigit.h>
+#include <AliMUONRawStreamTracker.h>
+#include <AliMUONRawStreamTrigger.h>
+#include <AliMUONDDLTracker.h>
+#include <AliMUONBlockHeader.h>
+#include <AliMUONDspHeader.h>
+#include <AliMUONBusStruct.h>
+#include <AliMUONDDLTrigger.h>
+#include <AliMUONDarcHeader.h>
+#include <AliMUONRegHeader.h>
+#include <AliMUONLocalStruct.h>
+#include <AliMUONTriggerCrateStore.h>
+#include <AliMUONTriggerCrate.h>
+#include <AliMUONLocalTriggerBoard.h>
+#include <AliMUONTriggerCircuit.h>
+#include <mapping/AliMpBusPatch.h>
+#include <mapping/AliMpVSegmentation.h>
+#include <mapping/AliMpSegmentation.h>
+#include <mapping/AliMpPad.h>
+#include <mapping/AliMpDEManager.h>
+
+#include "TTree.h"
+#include "TString.h"
+#include "TMatrixD.h"
+#include "TClonesArray.h"
+
+using namespace Reve;
+using namespace Alieve;
+
+//______________________________________________________________________
+// MUONData
+//
+
+ClassImp(MUONData)
+
+AliRawReader*            MUONData::fgRawReader        = 0;
+AliMUONRawStreamTracker* MUONData::fgRawStreamTracker = 0;
+AliMUONRawStreamTrigger* MUONData::fgRawStreamTrigger = 0;
+AliMpBusPatch*           MUONData::fgBusPatchManager  = 0;
+
+//______________________________________________________________________
+MUONData::MUONData() :
+  fChambers(14),
+  fNTracks(0),
+  fTrackPoints(0),
+  fNPoints(0)
+{
+  //
+  // Constructor
+  //
+  
+  CreateAllChambers();
+
+}
+
+//______________________________________________________________________
+MUONData::~MUONData()
+{
+  //
+  // Destructor
+  //
+
+  DeleteAllChambers();
+
+  delete [] fTrackPoints;
+
+  fTrackPoints = 0;
+
+}
+
+//______________________________________________________________________
+MUONData::MUONData(const MUONData &mdata) :
+  TObject(mdata)
+{
+  //
+  // Copy constructor
+  //
+
+}
+
+//______________________________________________________________________
+MUONData& MUONData::operator=(const MUONData &mdata)
+{
+  //
+  // Assignment operator
+  //
+
+  if (this != &mdata) {
+
+  }
+
+  return *this;
+
+}
+
+//______________________________________________________________________
+void MUONData::CreateChamber(Int_t chamber)
+{
+  // 
+  // create data for the chamber with id=chamber (0 to 13)
+  //
+
+  if (fChambers[chamber] == 0)
+    fChambers[chamber] = new MUONChamberData(chamber);
+
+}
+
+//______________________________________________________________________
+void MUONData::CreateAllChambers()
+{
+  //
+  // create all 14 chambers data
+  //
+
+  for (Int_t c = 0; c < 14; ++c)
+    CreateChamber(c);
+
+}
+
+//______________________________________________________________________
+void MUONData::DropAllChambers()
+{
+  // 
+  // release data from all chambers 
+  //
+
+  for (Int_t c = 0; c < 14; ++c) {
+
+    if (fChambers[c] != 0)
+      fChambers[c]->DropData();
+
+  }
+
+}
+
+//______________________________________________________________________
+void MUONData::DeleteAllChambers()
+{
+  //
+  // delete all chambers data
+  //
+
+  for (Int_t c = 0; c < 14; ++c) {
+
+    delete fChambers[c];
+    fChambers[c] = 0;
+
+  }
+
+}
+
+//______________________________________________________________________
+void MUONData::LoadTracks(TTree* tree)
+{
+  //
+  // load tracks from the TreeT and creates the track points array
+  // the structure of fTrackPoints:
+  // 0,  0,  0, - new track
+  // px, py, pz - from track param at vertex
+  // x, y, z    - track param at vertex
+  // x, y, z    - track param at hits
+  // ..........
+  //
+  // 0,  0,  0  - new track
+  // ..........
+  //
+
+  Int_t maxTrackHits = 1+2*10+4;
+
+  TClonesArray *tracks = 0;
+  tree->SetBranchAddress("MUONTrack",&tracks);
+  tree->GetEntry(0);
+
+  Int_t ntracks = tracks->GetEntriesFast();
+  printf("Found %d tracks. \n",ntracks);
+
+  fNTracks = ntracks;
+
+  Int_t maxTrackPoints = (3+3+3*maxTrackHits)*ntracks;
+  fTrackPoints = new Float_t [maxTrackPoints];
+
+  TMatrixD smatrix(2,2);
+  TMatrixD sums(2,1);
+  TMatrixD res(2,1);
+
+  Float_t xRec, xRec0;
+  Float_t yRec, yRec0;
+  Float_t zRec, zRec0;
+  Float_t px0, py0, pz0;
+  
+  Float_t zg[4] = { -1603.5, -1620.5, -1703.5, -1720.5 };
+
+  AliMUONTrack *mt;  
+  Int_t count = 0;
+  for (Int_t n = 0; n < ntracks; n++) {
+
+    if (count >= maxTrackPoints) continue;
+    fTrackPoints[3*count  ] = 0.0;
+    fTrackPoints[3*count+1] = 0.0;
+    fTrackPoints[3*count+2] = 0.0;
+    count++;
+
+    mt = (AliMUONTrack*) tracks->At(n);
+
+    printf("Match trigger %d \n",mt->GetMatchTrigger());
+
+    AliMUONTrackParam *trackParam = mt->GetTrackParamAtVertex(); 
+    xRec0  = trackParam->GetNonBendingCoor();
+    yRec0  = trackParam->GetBendingCoor();
+    zRec0  = trackParam->GetZ();
+
+    px0 = trackParam->Px();
+    py0 = trackParam->Py();
+    pz0 = trackParam->Pz();
+
+    if (count >= maxTrackPoints) continue;
+    fTrackPoints[3*count  ] = px0;
+    fTrackPoints[3*count+1] = py0;
+    fTrackPoints[3*count+2] = pz0;
+    count++;
+
+    if (count >= maxTrackPoints) continue;
+    fTrackPoints[3*count  ] = xRec0;
+    fTrackPoints[3*count+1] = yRec0;
+    fTrackPoints[3*count+2] = zRec0;
+    count++;
+    
+    Float_t xr[20], yr[20], zr[20];
+    for (Int_t i = 0; i < 10; i++) xr[i]=yr[i]=zr[i]=0.0;
+
+    Int_t nTrackHits = mt->GetNTrackHits();
+    printf("Nhits = %d \n",nTrackHits);
+    TClonesArray* trackParamAtHit;
+    for (Int_t iHit = 0; iHit < nTrackHits; iHit++){
+      trackParamAtHit = mt->GetTrackParamAtHit();
+      trackParam = (AliMUONTrackParam*) trackParamAtHit->At(iHit); 
+      xRec  = trackParam->GetNonBendingCoor();
+      yRec  = trackParam->GetBendingCoor();
+      zRec  = trackParam->GetZ();
+
+      //printf("Hit %d x %f y %f z %f \n",iHit,xRec,yRec,zRec);
+
+      xr[iHit] = xRec;
+      yr[iHit] = yRec;
+      zr[iHit] = zRec;
+
+      if (count >= maxTrackPoints) continue;
+      fTrackPoints[3*count  ] = xRec;
+      fTrackPoints[3*count+1] = yRec;
+      fTrackPoints[3*count+2] = zRec;
+      count++;
+    
+    }
+
+    Float_t xrc[20], yrc[20], zrc[20];
+    Int_t nrc = 0;
+    if (mt->GetMatchTrigger() && 1) {
+
+      for (Int_t i = 0; i < nTrackHits; i++) {
+       if (TMath::Abs(zr[i]) > 1000.0) {
+         //printf("Hit %d x %f y %f z %f \n",iHit,xr[i],yr[i],zr[i]);
+         xrc[nrc] = xr[i];
+         yrc[nrc] = yr[i];
+         zrc[nrc] = zr[i];
+         nrc++;
+       }
+      }
+
+      if (nrc < 2) continue;
+
+      Double_t xv, yv;
+      Float_t ax, bx, ay, by;
+      
+      // fit x-z
+      smatrix.Zero();
+      sums.Zero();
+      for (Int_t i = 0; i < nrc; i++) {
+       xv = (Double_t)zrc[i];
+       yv = (Double_t)xrc[i];
+       //printf("x-z: xv %f yv %f \n",xv,yv);
+       smatrix(0,0) += 1.0;
+       smatrix(1,1) += xv*xv;
+       smatrix(0,1) += xv;
+       smatrix(1,0) += xv;
+       sums(0,0)    += yv;
+       sums(1,0)    += xv*yv;
+      }
+      res = smatrix.Invert() * sums;
+      ax = res(0,0);
+      bx = res(1,0);
+
+      // fit y-z
+      smatrix.Zero();
+      sums.Zero();
+      for (Int_t i = 0; i < nrc; i++) {
+       xv = (Double_t)zrc[i];
+       yv = (Double_t)yrc[i];
+       //printf("y-z: xv %f yv %f \n",xv,yv);
+       smatrix(0,0) += 1.0;
+       smatrix(1,1) += xv*xv;
+       smatrix(0,1) += xv;
+       smatrix(1,0) += xv;
+       sums(0,0)    += yv;
+       sums(1,0)    += xv*yv;
+      }
+      res = smatrix.Invert() * sums;
+      ay = res(0,0);
+      by = res(1,0);
+
+      Float_t xtc, ytc, ztc;
+      for (Int_t ii = 0; ii < 4; ii++) {
+
+       ztc = zg[ii];
+       ytc = ay+by*zg[ii];
+       xtc = ax+bx*zg[ii];
+
+       //printf("tc: x %f y %f z %f \n",xtc,ytc,ztc);
+
+       if (count >= maxTrackPoints) continue;
+       fTrackPoints[3*count  ] = xtc;
+       fTrackPoints[3*count+1] = ytc;
+       fTrackPoints[3*count+2] = ztc;
+       count++;
+
+      }
+
+    }  // end match trigger
+
+  }
+
+  fNPoints = 3*count;
+
+  printf("MUONData found %d track points. \n",fNPoints);
+
+}
+
+//______________________________________________________________________
+void MUONData::LoadDigits(TTree* tree)
+{
+  // 
+  // load digits from the TreeD
+  //
+
+  Char_t branchname[30];
+  TClonesArray *digits = 0;
+  Int_t ndigits;
+  AliMUONDigit  *mdig;
+  Int_t cathode, detElemId, ix, iy, charge;
+
+  for (Int_t c = 0; c < 14; ++c) {
+
+    if (fChambers[c] == 0) continue;
+    sprintf(branchname,"MUONDigits%d",c+1);
+    tree->SetBranchAddress(branchname,&digits);
+    tree->GetEntry(0);
+
+    ndigits = digits->GetEntriesFast(); 
+
+    for (Int_t id = 0; id < ndigits; id++) {
+      mdig  = (AliMUONDigit*)digits->UncheckedAt(id);
+
+      cathode   = mdig->Cathode();
+      ix        = mdig->PadX();
+      iy        = mdig->PadY();
+      detElemId = mdig->DetElemId();      
+      charge    = (Int_t)mdig->Signal();
+
+      if (c > 9) {
+       //printf("cha %d deid %d cath %1d ix %d iy %d q %d \n",c,detElemId,cathode,ix,iy,charge);  
+      }
+
+      fChambers[c]->RegisterDigit(detElemId,cathode,ix,iy,charge);
+
+    } // end digits loop
+
+  }
+
+}
+
+//______________________________________________________________________
+void MUONData::LoadRaw(TString fileName)
+{
+  //
+  // load raw data from fileName; tracker and trigger data
+  //
+
+  if (fgRawReader == 0) {
+    // check extention to choose the rawdata file format
+    if (fileName.EndsWith("/")) {
+      fgRawReader = new AliRawReaderFile(fileName); // DDL files
+    } else if (fileName.EndsWith(".root")) {
+      fgRawReader = new AliRawReaderRoot(fileName); // ROOT file
+    } else if (!fileName.IsNull()) {
+      fgRawReader = new AliRawReaderDate(fileName); // DATE file
+    }
+    fgRawStreamTracker = new AliMUONRawStreamTracker(fgRawReader);
+    fgRawStreamTrigger = new AliMUONRawStreamTrigger(fgRawReader);
+    fgBusPatchManager = new AliMpBusPatch();
+    fgBusPatchManager->ReadBusPatchFile();
+  }
+  
+  LoadRawTracker();
+  LoadRawTrigger();
+
+}
+
+//______________________________________________________________________
+void MUONData::LoadRawTracker()
+{
+  //
+  // load raw data for the tracking chambers
+  //
+
+  fgRawReader->RewindEvents();
+
+  AliMUONDigit* digit = new AliMUONDigit();
+
+  Int_t maxEvent = 1000;
+  Int_t minDDL = 0, maxDDL = 19;
+  Int_t cathode, detElemId, ix, iy, iChamber;
+
+  AliMUONDDLTracker*       ddlTracker = 0x0;
+  AliMUONBlockHeader*      blkHeader  = 0x0;
+  AliMUONDspHeader*        dspHeader  = 0x0;
+  AliMUONBusStruct*        busStruct  = 0x0;
+
+  Int_t iEvent = 0;
+  Int_t dataSize, buspatchId;
+  
+  Event* aevent = Alieve::gEvent;
+
+  while (fgRawReader->NextEvent()) {
+    
+    if (iEvent != aevent->GetEventId()) {
+      iEvent++;
+      continue;
+    }
+    
+    if (iEvent == maxEvent)
+      break;
+    
+    // read DDL while < 20 DDL
+    while(fgRawStreamTracker->NextDDL()) {
+      
+      if (fgRawStreamTracker->GetDDL() < minDDL || 
+         fgRawStreamTracker->GetDDL() > maxDDL)
+       continue;
+      
+      //printf("\niDDL %d\n", fgRawStreamTracker->GetDDL());
+      
+      ddlTracker =  fgRawStreamTracker->GetDDLTracker();
+      
+      // loop over block structure
+      Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
+      for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
+       
+       blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
+       //printf("Block Total length %d\n",blkHeader->GetTotalLength());
+       
+       // loop over DSP structure
+       Int_t nDsp = blkHeader->GetDspHeaderEntries();
+       for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
+         
+         dspHeader =  blkHeader->GetDspHeaderEntry(iDsp);
+         //   printf("Dsp length %d even word %d\n",dspHeader->GetTotalLength(), dspHeader->GetEventWord());
+         
+         // loop over BusPatch structure
+         Int_t nBusPatch = dspHeader->GetBusPatchEntries();
+         for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
+           
+           busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
+           
+           //printf("busPatchId %d", busStruct->GetBusPatchId());
+           //printf(" BlockId %d", busStruct->GetBlockId());
+           //printf(" DspId %d\n", busStruct->GetDspId());
+           
+           // loop over data
+           dataSize = busStruct->GetLength();
+           buspatchId = busStruct->GetBusPatchId();
+           for (Int_t iData = 0; iData < dataSize; iData++) {
+             
+             Int_t  manuId    = busStruct->GetManuId(iData);
+             Int_t  channelId = busStruct->GetChannelId(iData);
+             Int_t  charge    = busStruct->GetCharge(iData);
+             //printf("manuId: %d, channelId: %d charge: %d\n", manuId, channelId, charge);
+             // set digit charge
+             digit->SetSignal(charge);
+             digit->SetPhysicsSignal(charge);
+             digit->SetADC(charge);
+             // Get Back the hits at pads
+             Int_t error;
+             error = GetTrackerMapping(buspatchId,manuId,channelId,digit); 
+             if (error) {
+               printf("Mapping Error\n");
+               continue;
+             }
+
+             cathode   = digit->Cathode();
+             ix        = digit->PadX();
+             iy        = digit->PadY();
+             detElemId = digit->DetElemId();      
+             charge    = (Int_t)digit->Signal();
+             iChamber  = detElemId/100 - 1;
+
+             fChambers[iChamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
+             
+           } // iData
+         } // iBusPatch
+       } // iDsp
+      } // iBlock
+    } // NextDDL
+
+    break;
+
+  }  // end event loop
+  
+  delete digit;
+
+}
+
+//______________________________________________________________________
+void MUONData::LoadRawTrigger()
+{
+  // 
+  // load raw data for the trigger chambers
+  //
+
+  fgRawReader->RewindEvents();
+
+  Int_t maxEvent = 1000;
+  Int_t minDDL = 0, maxDDL = 1;
+  Int_t detElemId, iChamber, cathode, charge, ix, iy;
+
+  AliMUONDDLTrigger*       ddlTrigger  = 0x0;
+  AliMUONDarcHeader*       darcHeader  = 0x0;
+  AliMUONRegHeader*        regHeader   = 0x0;
+  AliMUONLocalStruct*      localStruct = 0x0;
+  
+  // crate manager
+  AliMUONTriggerCrateStore* crateManager = new AliMUONTriggerCrateStore();   
+  crateManager->ReadFromFile();
+
+  // Loop over events  
+  Int_t iEvent = 0;
+  TList digitList;
+  
+  Event* aevent = Alieve::gEvent;
+  
+  while (fgRawReader->NextEvent()) {
+    
+    if (iEvent != aevent->GetEventId()) {
+      iEvent++;
+      continue;
+    }
+    
+    if (iEvent == maxEvent)
+      break;
+    
+    // read DDL while < 2 DDL
+    while(fgRawStreamTrigger->NextDDL()) {
+      
+      if (fgRawStreamTrigger->GetDDL() < minDDL || 
+         fgRawStreamTrigger->GetDDL() > maxDDL)
+       continue;
+      
+      //printf("\niDDL %d\n", fgRawStreamTrigger->GetDDL());
+      
+      ddlTrigger = fgRawStreamTrigger->GetDDLTrigger();
+      darcHeader = ddlTrigger->GetDarcHeader();
+      
+      //printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
+      
+      // loop over regional structures
+      Int_t nReg = darcHeader->GetRegHeaderEntries();
+      for(Int_t iReg = 0; iReg < nReg ;iReg++){   //REG loop
+       
+       //printf("RegionalId %d\n", iReg);
+       
+       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
+       //  printf("Reg length %d\n",regHeader->GetHeaderLength());
+       
+       // crate info
+       AliMUONTriggerCrate* crate = crateManager->Crate(fgRawStreamTrigger->GetDDL(), iReg);
+       TObjArray *boards = crate->Boards();
+       
+       // loop over local structures
+       Int_t nLocal = regHeader->GetLocalEntries();
+       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {  
+         
+         localStruct = regHeader->GetLocalEntry(iLocal);
+         
+         // check if trigger 
+         if (localStruct->GetTriggerY() == 0) { // no empty data
+           
+           // local trigger circuit number
+           AliMUONLocalTriggerBoard* localBoard = (AliMUONLocalTriggerBoard*)boards->At(iLocal+1);
+           
+           //printf("LocalId %d\n", localStruct->GetId());
+           /*
+           Int_t iLocCard  = localBoard->GetNumber();
+           Int_t loStripX  = (Int_t)localStruct->GetXPos();
+           Int_t loStripY  = (Int_t)localStruct->GetYPos();
+           Int_t loDev     = (Int_t)localStruct->GetXDev();
+           */
+           //printf("iLocCard: %d, XPos: %d, YPos: %d Dev: %d\n", iLocCard, loStripX, loStripY, loDev);
+
+           digitList.Clear();
+           if ( GetTriggerMapping(localBoard, localStruct, digitList) ) {
+             for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); iEntry++) {
+
+               AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry);
+               cathode   = digit->Cathode();
+               ix        = digit->PadX();
+               iy        = digit->PadY();
+               detElemId = digit->DetElemId();      
+               charge    = (Int_t)digit->Signal();
+               iChamber  = detElemId/100 - 1;
+               
+               //printf("cha %d deid %d cath %1d ix %d iy %d q %d \n",iChamber,detElemId,cathode,ix,iy,charge);  
+
+               fChambers[iChamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
+
+             }
+
+           }
+
+         }
+       } // iLocal
+      } // iReg
+    } // NextDDL
+
+    break;
+
+  }  // end event loop
+
+  delete crateManager;
+
+}
+
+//______________________________________________________________________
+Int_t MUONData::GetTrackerMapping(Int_t buspatchId, UShort_t manuId, UChar_t channelId, AliMUONDigit* digit)
+{
+  //
+  // decode digits mapping for the tracking chambers
+  //
+  
+  // getting DE from buspatch
+  Int_t detElemId = fgBusPatchManager->GetDEfromBus(buspatchId);
+  //AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, buspatchId));
+
+  const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, manuId);  
+  AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
+
+  if (!pad.IsValid())
+  {
+    printf("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",detElemId, buspatchId, manuId, channelId);
+    
+    return 1;
+  } // return error
+
+  // Getting padX, padY and cathode number.
+  Int_t padX = pad.GetIndices().GetFirst();
+  Int_t padY = pad.GetIndices().GetSecond();
+  Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
+
+  // storing into digits
+  digit->SetPadX(padX);
+  digit->SetPadY(padY);
+  digit->SetCathode(iCath);
+  digit->SetDetElemId(detElemId);
+  digit->SetElectronics(manuId,channelId);
+  
+  //printf("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",detElemId, buspatchId, manuId, channelId, padX, padY);
+  
+  return 0;
+
+}
+
+//______________________________________________________________________
+Int_t MUONData::GetTriggerMapping(AliMUONLocalTriggerBoard* localBoard, 
+                                 AliMUONLocalStruct* localStruct,
+                                 TList& digitList)
+{
+  //
+  // decode digits mapping for the trigger chambers
+  //
+
+  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
+    AliMUONTriggerCircuit 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->SetSignal(1);
+       digit->SetPadX(padX);
+       digit->SetPadY(padY);
+       digit->SetCathode(iCath);
+       digit->SetDetElemId(detElemId);
+       digit->SetElectronics(nBoard, ibitxy);
+       digitList.Add(digit);
+       
+      }// xyPattern
+    }// ibitxy
+  }// case
+
+  return 1;
+
+}
+
+//____________________________________________________________________
+void MUONData::GetTriggerChamber(AliMUONLocalStruct* localStruct, Int_t& xyPattern, Int_t& iChamber, Int_t& iCath, Int_t icase)
+{
+  //
+  // extract digits pattern
+  //  
+
+  // 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;
+  }
+
+}
+
+//______________________________________________________________________
+MUONChamberData* MUONData::GetChamberData(Int_t chamber)
+{
+  //
+  // return chamber data
+  //
+
+  if (chamber < 0 || chamber > 13) return 0;
+
+  //if (fChambers[chamber] == 0) CreateChamber(chamber);
+
+  return fChambers[chamber];
+
+}
diff --git a/EVE/Alieve/MUONData.h b/EVE/Alieve/MUONData.h
new file mode 100644 (file)
index 0000000..7cf1115
--- /dev/null
@@ -0,0 +1,86 @@
+#ifndef ALIEVE_MUONData_H
+#define ALIEVE_MUONData_H
+
+#include <Reve/Reve.h>
+
+#include <TObject.h>
+
+#include <vector>
+
+class TTree;
+class TString;
+class TList;
+
+class AliRawReader;
+class AliMUONRawStreamTracker;
+class AliMUONRawStreamTrigger;
+class AliMUONDigit;
+class AliMpSegFactory;
+class AliMpBusPatch;
+class AliMUONLocalTriggerBoard;
+class AliMUONLocalStruct;
+class AliMUONLocalStruct;
+
+namespace Alieve {
+
+class MUONChamberData;
+
+class MUONData : public TObject, public Reve::ReferenceCount
+{
+
+ protected:
+
+  std::vector<MUONChamberData*>   fChambers;           // vector of 14 chambers
+
+  static AliRawReader*            fgRawReader;         // raw reader
+  static AliMUONRawStreamTracker* fgRawStreamTracker;  // tracker raw streamer 
+  static AliMUONRawStreamTrigger* fgRawStreamTrigger;  // trigger raw streamer
+  static AliMpSegFactory*         fgSegFactory;        // segmentation mapping
+  static AliMpBusPatch*           fgBusPatchManager;   // bus mapping
+
+  Int_t    fNTracks;              // number of tracks
+  Float_t* fTrackPoints;          // array with track points coordinates
+  Int_t    fNPoints;              // total number of track points
+
+  Int_t GetTrackerMapping(Int_t buspatchId, UShort_t manuId,
+                         UChar_t channelId, AliMUONDigit* digit );
+
+  Int_t GetTriggerMapping(AliMUONLocalTriggerBoard* localBoard, 
+                         AliMUONLocalStruct* localStruct,
+                         TList& digitList);
+
+  void GetTriggerChamber(AliMUONLocalStruct* localStruct,
+                         Int_t& xyPattern, Int_t& iChamber, Int_t& iCath, 
+                        Int_t iCase);
+ public:
+
+  MUONData();
+  virtual ~MUONData();
+
+  MUONData(const MUONData&);
+  MUONData& operator=(const MUONData&);
+
+  void LoadDigits(TTree* tree);
+  void LoadTracks(TTree* tree);
+  void LoadRaw(TString fileName);
+  void LoadRawTracker();
+  void LoadRawTrigger();
+
+  void CreateChamber(Int_t chamber);
+  void CreateAllChambers();
+  void DropAllChambers();
+  void DeleteAllChambers();
+
+  MUONChamberData* GetChamberData(Int_t chamber);
+
+  Int_t    GetNTracks() { return fNTracks; };
+  Int_t    GetNPoints() { return fNPoints; };
+  Float_t* GetTrackPoints() { return fTrackPoints; };
+
+  ClassDef(MUONData,1);           // Manages MUON data for one event
+
+};
+
+}
+
+#endif