]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONpoints.cxx
Introduction of the Copyright and cvs Log
[u/mrichter/AliRoot.git] / MUON / AliMUONpoints.cxx
index 92ed26b82fc68d6dcd1682ca0723640ca05cdd02..0813e9d1ea6ed84c8bcffe51bf13d5e35af72f14 100644 (file)
@@ -1,3 +1,22 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+/*
+$Log$
+*/
+
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 //  This class contains the points for the ALICE event display               //
 //                                                                           //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
-#include "AliMUONdisplay.h"
+
 #include "AliMUONpoints.h"
+#include "AliMUONdisplay.h"
 #include "AliRun.h"
 #include "TPad.h"
+#include "TVirtualPad.h"
+#include "TPolyLine3D.h"
+#include "TPaveText.h"
 #include "TView.h"
 #include "TMath.h"
 
+//const Int_t MAX_Nipx=1026, MAX_Nipy=1026;
 const Int_t MAX_Nipx=400, MAX_Nipy=800;
  
 ClassImp(AliMUONpoints)
@@ -30,6 +54,8 @@ AliMUONpoints::AliMUONpoints()
   fHitIndex = 0;
   fTrackIndex = 0;
   fDigitIndex = 0;
+  fMarker[0] = fMarker[1] = fMarker[2]=0;
+  fMatrix = 0;
 }
 
 //_____________________________________________________________________________
@@ -42,6 +68,8 @@ AliMUONpoints::AliMUONpoints(Int_t npoints)
   fHitIndex = 0;
   fTrackIndex = 0;
   fDigitIndex = 0;
+  fMarker[0] = fMarker[1] = fMarker[2]=0;
+  fMatrix = 0;
 }
         
 //_____________________________________________________________________________
@@ -53,8 +81,26 @@ AliMUONpoints::~AliMUONpoints()
   fHitIndex = 0;
   fTrackIndex = 0;
   fDigitIndex = 0;
+  for (Int_t i=0;i<3;i++){
+      if (fMarker[i]) delete fMarker[i];
+  }
+  fMatrix = 0;
 }
 
+//_____________________________________________________________________________
+//void AliMUONpoints::ExecuteEvent(Int_t event, Int_t px, Int_t py)
+//{
+  //
+  //*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*-*-*-*-*
+  //*-*                =========================================
+  //*-*
+  //*-*  This member function must be implemented to realize the action
+  //*-*  corresponding to the mouse click on the object in the window
+  //*-*
+  //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+//  gPad->SetCursor(kCross);
+  
+//}
 //_____________________________________________________________________________
 void AliMUONpoints::DumpHit()
 {
@@ -81,8 +127,30 @@ void AliMUONpoints::InspectHit()
   //
   //   Inspect hit corresponding to this point
   //
+
+  if (fHitIndex < 0 ) return;
+  TVirtualPad *padsav = gPad;
   AliMUONhit *hit = GetHit();
   if (hit) hit->Inspect();
+  TVirtualPad *padinspect = (TVirtualPad*)(gROOT->GetListOfCanvases())->FindObject("inspect");
+   padinspect->cd();
+   Float_t xmin = gPad->GetX1();
+   Float_t xmax = gPad->GetX2();
+   Float_t ymin = gPad->GetY1();
+   Float_t ymax = gPad->GetY2();
+   Float_t dy   = ymax-ymin;
+
+      TPaveText *pad = new TPaveText(xmin, ymin+0.1*dy, xmax, ymin+0.15*dy);
+      pad->SetBit(kCanDelete);
+      pad->SetFillColor(42);
+      pad->Draw();
+      char ptitle[100];
+      sprintf(ptitle," %s , fTrack: %d  fTrackIndex: %d ",GetName(),fIndex,fTrackIndex);
+      pad->AddText(ptitle);
+      padinspect->cd();
+      padinspect->Update();
+  if (padsav) padsav->cd();
+
 }
 
 //_____________________________________________________________________________
@@ -91,8 +159,34 @@ void AliMUONpoints::InspectDigit()
   //
   //   Inspect digit corresponding to this point
   //
+  if (fDigitIndex < 0) return;
+  TVirtualPad *padsav = gPad;
   AliMUONdigit *digit = GetDigit();
   if (digit) digit->Inspect();
+  TVirtualPad *padinspect = (TVirtualPad*)(gROOT->GetListOfCanvases())->FindObject("inspect");
+   padinspect->cd();
+   Float_t xmin = gPad->GetX1();
+   Float_t xmax = gPad->GetX2();
+   Float_t ymin = gPad->GetY1();
+   Float_t ymax = gPad->GetY2();
+   Float_t dy   = ymax-ymin;
+
+      TPaveText *pad = new TPaveText(xmin, ymin+0.1*dy, xmax, ymin+0.25*dy);
+      pad->SetBit(kCanDelete);
+      pad->SetFillColor(42);
+      pad->Draw();
+      char ptitle[11][100];
+      //      sprintf(ptitle[11],"Tracks making this digit");
+      //      pad->AddText(ptitle[11]);
+  for (int i=0;i<10;i++) {
+      if (digit->fTracks[i] == 0) continue;  
+      sprintf(ptitle[i],"fTrackIndex: %d  Charge: %d",digit->fTracks[i],digit->fTcharges[i]);
+      pad->AddText(ptitle[i]);
+  }
+      padinspect->cd();
+      padinspect->Update();
+  if (padsav) padsav->cd();
+      
 }
 
 //_____________________________________________________________________________
@@ -101,8 +195,16 @@ Int_t AliMUONpoints::GetTrackIndex()
   //
   //   Dump digit corresponding to this point
   //
-  printf("GetTrackIndex - fTrackIndex %d \n",fTrackIndex);
+
   this->Inspect();
+  /*
+  if (fDigitIndex != 0) {
+    Int_t ncol=this->fMatrix->GetNcols();
+    for (int i=0;i<ncol;i++) {
+        printf(" track charge %f %f \n",(*(this->fMatrix))(0,i),(*(this->fMatrix))(1,i));
+    }
+  }
+  */
   return fTrackIndex;
 }
 
@@ -133,7 +235,9 @@ AliMUONdigit *AliMUONpoints::GetDigit() const
    
   AliMUON *MUON  = (AliMUON*)gAlice->GetModule("MUON");
   TClonesArray *MUONdigits  = MUON->DigitsAddress(chamber-1);
-  gAlice->TreeD()->GetEvent(cathode);
+  Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
+  gAlice->TreeD()->GetEvent(nent-2+cathode-1);
+  //gAlice->TreeD()->GetEvent(cathode);
   Int_t ndigits = MUONdigits->GetEntriesFast();
   if (fDigitIndex < 0 || fDigitIndex >= ndigits) return 0;
   return (AliMUONdigit*)MUONdigits->UncheckedAt(fDigitIndex);
@@ -150,11 +254,20 @@ struct PreCluster : public AliMUONreccluster {
    int idx;
    int cut;
    int npeaks;
-   PreCluster() : AliMUONreccluster() {cut=npeaks=0;}
+   int npoly;
+   float xpoly[100];
+   float ypoly[100];
+   float zpoly[100];
+   PreCluster() : AliMUONreccluster() {cut=npeaks=npoly=0; 
+                                       for (int k=0;k<100;k++) {
+                                         xpoly[k]=ypoly[k]=zpoly[k]=0;
+                                      }
+   }
+                              
 };
 //_____________________________________________________________________________
 
-static void FindCluster(AliMUONchamber *iChamber, AliMUONsegmentation *segmentation, int i, int j, Bin bins[MAX_Nipx][MAX_Nipy], PreCluster &c) 
+static void FindCluster(AliMUONchamber *iChamber, AliMUONsegmentation *segmentation, int i, int j, Bin bins[][MAX_Nipy], PreCluster &c) 
 
 {
 
@@ -162,41 +275,78 @@ static void FindCluster(AliMUONchamber *iChamber, AliMUONsegmentation *segmentat
   // Find clusters
   //
 
-  printf("I'm in FindCluster \n"); 
 
   Bin& b=bins[i][j];
   Int_t q=b.dig->fSignal;
 
-  printf("FindCluster - i j q %d %d %d\n",i,j,q);
-  
   if (q<0) { 
     q=-q;
     c.cut=1;
   } 
-  if (b.idx >= 0 && b.idx != c.idx) {
+  //  if (b.idx >= 0 && b.idx != c.idx) {
+  if (b.idx >= 0 && b.idx > c.idx) {
     c.idx=b.idx;
     c.npeaks++;
   }
   
   if (q > TMath::Abs(c.summit->fSignal)) c.summit=b.dig;
 
+  Float_t zpos=iChamber->ZPosition();
+
   Int_t npx  = segmentation->Npx();
   Int_t npy  = segmentation->Npy();
-  Float_t x,y;
-  segmentation->GetPadCxy(i-npx, j-npy, x,y);
-  printf("FindCluster - x  y %f %f \n",x,y);
 
 
+  // get pad coordinates and prepare the up and down steps   
+  Int_t jup  =(j-npy > 0) ? j+1 : j-1;
+  Int_t jdown=(j-npy > 0) ? j-1 : j+1;
+
+  Float_t x, y;
+  segmentation->GetPadCxy(i-npx, j-npy,x, y);
+  Int_t isec0=segmentation->Sector(i-npx,j-npy);
+
+  Float_t dpy  = segmentation->Dpy(isec0);
+  Float_t dpx  = segmentation->Dpx(isec0)/16;
+  Int_t ixx, iyy;
+  Float_t absx=TMath::Abs(x);
+  // iup
+  (y >0) ? segmentation->GetPadIxy(absx+dpx,y+dpy,ixx,iyy) : segmentation->GetPadIxy(absx+dpx,y-dpy,ixx,iyy);
+
+  //  Int_t jtest=TMath::Abs(iyy)-npy-1;
+
+  Int_t iup=(x >0) ? ixx+npx : -ixx+npx;
+  // idown
+  (y >0) ? segmentation->GetPadIxy(absx+dpx,y-dpy,ixx,iyy) : segmentation->GetPadIxy(absx+dpx,y+dpy,ixx,iyy);
+
+  Int_t idown=(x >0) ? ixx+npx : -ixx+npx;
+  if (bins[idown][jdown].dig == 0) {
+     (y >0) ? segmentation->GetPadIxy(absx-dpx,y-dpy,ixx,iyy) : segmentation->GetPadIxy(absx-dpx,y+dpy,ixx,iyy);
+     idown=(x >0) ? ixx+npx : -ixx+npx;
+  }
+
+  // calculate center of gravity
+  c.npoly++;
+  if (c.npoly > 100 ) {
+    printf("FindCluster - npoly >100,  npoly %d \n",c.npoly);
+    c.npoly=100;
+  }
+  c.xpoly[c.npoly-1]=x;
+  c.ypoly[c.npoly-1]=y;
+  c.zpoly[c.npoly-1]=zpos;
+
   c.fX += q*x;
   c.fY += q*y;
   c.fQ += q;
   
   b.dig = 0;  b.idx = c.idx;
-  
+
+  // left and right  
   if (bins[i-1][j].dig) FindCluster(iChamber,segmentation,i-1,j,bins,c);
-  if (bins[i][j-1].dig) FindCluster(iChamber,segmentation,i,j-1,bins,c);
   if (bins[i+1][j].dig) FindCluster(iChamber,segmentation,i+1,j,bins,c);
-  if (bins[i][j+1].dig) FindCluster(iChamber,segmentation,i,j+1,bins,c);
+  // up and down
+  if (bins[iup][jup].dig) FindCluster(iChamber,segmentation,iup,jup,bins,c);
+  if (bins[idown][jdown].dig) FindCluster(iChamber,segmentation,idown,jdown,bins,c);
 
 }
 
@@ -208,8 +358,11 @@ void AliMUONpoints::GetCenterOfGravity()
   // simple MUON cluster finder from digits -- finds neighbours and 
   // calculates center of gravity for the cluster
   //
-  const Int_t MAX_Nipx=400, MAX_Nipy=800;
-  printf("\n Hallo world");
+
+  //  const Int_t MAX_Nipx=1026, MAX_Nipy=1026;
+
+  Bin bins[MAX_Nipx][MAX_Nipy]; 
+
   AliMUONdisplay *display=(AliMUONdisplay*)gAlice->Display();
   Int_t chamber=display->GetChamber();
   Int_t cathode=display->GetCathode();
@@ -222,9 +375,11 @@ void AliMUONpoints::GetCenterOfGravity()
   Int_t npx  = segmentation->Npx();
   Int_t npy  = segmentation->Npy();
   Float_t zpos=iChamber->ZPosition();
-  
+
   TClonesArray *MUONdigits  = MUON->DigitsAddress(chamber-1);
-  gAlice->TreeD()->GetEvent(cathode);
+  Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
+  gAlice->TreeD()->GetEvent(nent-2+cathode-1);
+  //gAlice->TreeD()->GetEvent(cathode);
   Int_t ndigits = MUONdigits->GetEntriesFast();
   if (fDigitIndex < 0 || fDigitIndex >= ndigits) return;
 
@@ -232,41 +387,65 @@ void AliMUONpoints::GetCenterOfGravity()
   dig=(AliMUONdigit*)MUONdigits->UncheckedAt(fDigitIndex);
   Int_t ipx=dig->fPadX;
   Int_t ipy=dig->fPadY;
-  Bin bins[MAX_Nipx][MAX_Nipy]; 
   bins[ipx+npx][ipy+npy].dig=dig;
     
   int ndig;
   int ncls=0;
-  for (ndig=0; ndig<ndigits; ndig++) {
-      dig = (AliMUONdigit*)MUONdigits->UncheckedAt(ndig);
-      int i=dig->fPadX, j=dig->fPadY;
-      bins[i+npx][j+npy].dig=dig;
+  for (ndig=0;ndig<ndigits;ndig++) {
+    dig = (AliMUONdigit*)MUONdigits->UncheckedAt(ndig);
+    int i=dig->fPadX, j=dig->fPadY;
+    bins[i+npx][j+npy].dig=dig;
   }
-
-  PreCluster c; c.summit=bins[ipx+npx][ipy+npy].dig; c.idx=ncls;
-  FindCluster(iChamber,segmentation,ipx+npx, ipy+npy, bins, c);
-  if (c.npeaks>1) {
+   PreCluster c; c.summit=bins[ipx+npx][ipy+npy].dig; c.idx=ncls;
+   FindCluster(iChamber,segmentation,ipx+npx, ipy+npy, bins, c);
+    
+   if (c.npeaks>1) {
       printf("GetCenterOfGravity -- more than one peak");
-  }
-  c.fX /= c.fQ;
-  c.fY /= c.fQ;
-  printf("GetCenterOfGravity - c.fX c.fY c.fQ %f %f %d \n",c.fX,c.fY,c.fQ);
-  
-  c.fTracks[0]=c.summit->fTracks[0];
-  c.fTracks[1]=c.summit->fTracks[1];
-  c.fTracks[2]=c.summit->fTracks[2];
-  ncls++;
-  AliMUONpoints *points = 0;
-  points = new AliMUONpoints(1);
-  points->SetMarkerColor(kYellow);
-  points->SetMarkerStyle(5);
-  points->SetMarkerSize(1.);
-  points->SetPoint(0,c.fX,c.fY,zpos);
-  points->Draw();
-  
-  printf("GetCenterOfGravity -- ncls %d \n",ncls);
+   }
+   c.fX /= c.fQ;
+   c.fY /= c.fQ;
 
-}
+   c.fTracks[0]=c.summit->fTracks[0];
+   c.fTracks[1]=c.summit->fTracks[1];
+   c.fTracks[2]=c.summit->fTracks[2];
+   ncls++;
+   AliMUONpoints *points = 0;
+   points = new AliMUONpoints(1);
+   points->SetMarkerColor(kYellow);
+   points->SetMarkerStyle(5);
+   points->SetMarkerSize(1.);
+   points->SetPoint(0,c.fX,c.fY,zpos);
+   points->SetParticle(-1);
+   points->Draw();
+
+   TPolyLine3D *pline=0;
+   /*
+   pline=new TPolyLine3D(c.npoly);
+   Int_t np=c.npoly;
+   TVector *xp=new TVector(c.npoly);
+   TVector *yp=new TVector(c.npoly);
+   TVector *zp=new TVector(c.npoly);
+   for (int i=0;i<np;i++) {
+     (*xp)(i)=c.xpoly[i];
+     (*yp)(i)=c.ypoly[i];
+     (*zp)(i)=c.zpoly[i];
+     pline->SetPoint(i,(*xp)(i),(*yp)(i),(*zp)(i));
+     //printf("np, i, xp, yp, zp %d %d %f %f %f \n",np,i,(*xp)(i),(*yp)(i),(*zp)(i));
+   }
+   */
+   pline=new TPolyLine3D(c.npoly,c.xpoly,c.ypoly,c.zpoly);
+   pline->SetLineColor(kWhite);
+   pline->Draw();
+   /*
+   delete xp;
+   delete yp;
+   delete zp;
+   */  
+   for (int k=0;k<c.npoly;k++) {
+     c.xpoly[k]=c.ypoly[k]=c.zpoly[k]=0;
+   }
+   c.npoly=0;
 
 
+}