Further development on Mapping and Segmentation. Waiting for a critical review
authormartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 Jul 2004 09:51:00 +0000 (09:51 +0000)
committermartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 Jul 2004 09:51:00 +0000 (09:51 +0000)
MUON/AliMUONSegmentIndex.h
MUON/AliMUONSegmentPosition.cxx
MUON/AliMUONSegmentPosition.h
MUON/AliMUONSegmentationDetectionElement.cxx
MUON/AliMUONSegmentationDetectionElement.h

index 01397d39376cdeae1ddb4010928f2707e420da4b..cbb6383f949a1222eff9bcdb9e21db49f6861264 100644 (file)
@@ -28,7 +28,7 @@ class AliMUONSegmentIndex : public TNamed {
   Int_t Compare(const TObject *obj) const;
   Int_t GetChannelId() const {return fChannelId;}
   Int_t GetPadX()      const {return fPadX;} 
-  Int_t GetPadY()      const {return fPadX;} 
+  Int_t GetPadY()      const {return fPadY;} 
   Int_t GetCathode()   const {return fCathode;} 
   
   static TString Name(Int_t padx, Int_t pady, Int_t cathode) ;
index 4ffddf602c50ac40d95f3326080f50db46898698..5aae59562dcb4ce4edef4c186244e7a007c187fd 100644 (file)
@@ -32,6 +32,8 @@
 //___________________________________________
 ClassImp(AliMUONSegmentPosition)
 
+Float_t AliMUONSegmentPosition::fUnit = 0.3 ; // 3mm unit for generation of segmenposition name
+
 //
 //___________________________________________
 AliMUONSegmentPosition::AliMUONSegmentPosition() : TNamed()
@@ -51,6 +53,8 @@ AliMUONSegmentPosition::AliMUONSegmentPosition(const Int_t channelId, const Floa
   fX = x;
   fY = y;
   fCathode=cathode;
+  fPadSizeX=0.;
+  fPadSizeY=0.;  
 }
 //_______________________________________________
 AliMUONSegmentPosition::~AliMUONSegmentPosition()
@@ -64,6 +68,12 @@ Int_t AliMUONSegmentPosition::Compare(const TObject *obj) const
   AliMUONSegmentPosition * myobj = ( AliMUONSegmentPosition *) obj;
   return (fChannelId > myobj->GetChannelId()) ? 1 : -1;
 }
+
+//___________________________________________
+Float_t AliMUONSegmentPosition::Distance(Float_t x, Float_t y)
+{
+  return TMath::Sqrt( (fX-x)*(fX-x) + (fY-y)*(fY-y) ) ;
+}
 //___________________________________________
 TString AliMUONSegmentPosition::Name(Float_t x, Float_t y, Int_t cathode) 
 {
@@ -73,8 +83,8 @@ TString AliMUONSegmentPosition::Name(Float_t x, Float_t y, Int_t cathode)
   // xp = TMath::Nint(x*10./3.);
   // yp = TMath::Nint(y+10./3.);
   // sprintf(name,"%d-%d-%d",xp,yp,cathode);
-  Int_t xp = TMath::Nint(x*10./3.);
-  Int_t yp = TMath::Nint(y*10./3.);
+  Int_t xp = TMath::Nint(x/fUnit);
+  Int_t yp = TMath::Nint(y/fUnit);
   char name[15];
   sprintf(name,"%d-%d-%d",xp,yp,cathode);
   return TString(name);
index 90a3f6a5c1bbf6d0bd13acfd0de2d9bc34175182..7bdc6dc99aed0ea48927267af38c25ef3a527e9b 100644 (file)
@@ -27,13 +27,15 @@ class AliMUONSegmentPosition : public TNamed
     virtual ~AliMUONSegmentPosition();
       
     Int_t   Compare(const TObject *obj) const;
+    Float_t Distance(Float_t x, Float_t y);
     Int_t   GetChannelId()const {return fChannelId;}
     Float_t GetXlocal()   const {return fX;}
     Float_t GetYlocal()   const {return fY;}
     Int_t   GetCathode()  const {return fCathode;}
 
+    static  Float_t GetUnit()            {return fUnit;} 
+    static  TString Name(Float_t x, Float_t y, Int_t cathode) ;
 
-    static TString Name(Float_t x, Float_t y, Int_t cathode) ;
     void    Print() const;
 
  private:
@@ -41,7 +43,11 @@ class AliMUONSegmentPosition : public TNamed
     Float_t fX;           // Position X of the center of the segment (pad, strip, etc...)
     Float_t fY;           // Position Y of the center of the segment (pad, strip, etc...)
     Int_t   fCathode;     // Cathode Side Bending 1  or non bending 0 
-     
+    Float_t fPadSizeX;
+    Float_t fPadSizeY;
+
+    static Float_t fUnit;  // Unit for generation of the name 3mm has been choses     
+
     ClassDef(AliMUONSegmentPosition,1) // Loal positions of segments
        
 };
index ee10b58375ae8e94b9bac97adb75663fba7430f1..2892a515119bb12e9b165a76e82b0ff486d21cee 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "TClonesArray.h"
 #include "TMap.h"
+#include "TMath.h"
 
 #include "AliMUONSegmentationDetectionElement.h"
 #include "AliMUONSegmentManuIndex.h"
@@ -56,6 +57,8 @@ const TString AliMUONSegmentationDetectionElement::fgkNonBendingExt = ".NonBendi
 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
 {
   //Default constructor
+  fWireD  = 0.25; // wire pitch in cm
+  fWireX0 = 0.;  // X0 position of the 1st wire
   fMapManuIndexIndex= 0x0;
   fMapIndexManuIndex= 0x0;
   fMapIndexPosition= 0x0;
@@ -90,6 +93,56 @@ AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
   fMapPositionIndex->Clear();
 }
 
+//__________________________________________________
+AliMUONSegmentIndex *  AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode)
+{
+  // Finding x_wire corresponding to x
+  Float_t x_wire = GetAnod(x);
+
+  //Finding pad corresponding to the position (x_wire, y) in a zone of size 3cm x 10cm or 10cm x 3cm depending on cathode plane
+  // 
+  Int_t ix_max = (cathode==0) ? TMath::Nint(5./AliMUONSegmentPosition::GetUnit())  :  TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit());
+  Int_t iy_max = (cathode==0) ? TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit()) :  TMath::Nint(5./AliMUONSegmentPosition::GetUnit());
+
+  AliMUONSegmentIndex * segmentindex =0x0;
+  AliMUONSegmentIndex * foundsegmentindex =0x0;
+  AliMUONSegmentPosition * segmentposition=0x0;
+  Int_t   ix, iy;
+  Float_t xt,yt;
+  Float_t distance = 99999999.;
+  //printf("%d %d \n",ix_max, iy_max);
+
+  for(ix=-ix_max; ix<ix_max; ix++) {
+    xt = x_wire + ((Float_t)ix)*AliMUONSegmentPosition::GetUnit();
+    for(iy=-iy_max; iy<iy_max; iy++) {
+      yt = y + ((Float_t)iy)*AliMUONSegmentPosition::GetUnit();
+      segmentindex = GetIndexFromPosition( xt, yt, cathode);
+      if ( segmentindex ) {
+       // segmentindex->Print();
+       segmentposition = GetPosition(segmentindex->GetName());
+       if ( segmentposition->Distance(x_wire, y) < distance ) {     
+         //printf("adfafa xt %f yt %f distance %f \n", xt, yt, segmentposition->Distance(xt,yt) );     
+         distance = segmentposition->Distance(x_wire,y);
+         foundsegmentindex = segmentindex;
+       }
+      }
+    }
+  }
+ if (!foundsegmentindex) {
+   Warning("FindIndexFromPosition","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
+ }    
+ return foundsegmentindex;
+}
+
+//____________________________________________________-
+Float_t AliMUONSegmentationDetectionElement::GetAnod(Float_t xhit) const
+{
+  // Returns for a hit position xhit the position of the nearest anode wire    
+  Float_t wire= ( (xhit- fWireX0)>0 ) ? 
+    Int_t( (xhit- fWireX0)/fWireD )+0.5 : 
+    Int_t( (xhit- fWireX0)/fWireD )-0.5;
+  return fWireD*wire+fWireX0; 
+}
 //_________________________________________________
 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
 {
@@ -124,6 +177,26 @@ AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( con
     return 0x0;
   }
 }
+//__________________________________________________
+void  AliMUONSegmentationDetectionElement::GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y )
+{
+  x = GetPosition(ix,iy,cathode)->GetXlocal();
+  y = GetPosition(ix,iy,cathode)->GetYlocal();
+}
+//__________________________________________________
+void  AliMUONSegmentationDetectionElement::GetPadI(Float_t x, Float_t y, Int_t cathode, Int_t &padx, Int_t &pady)
+{
+
+  AliMUONSegmentIndex * segmentindex = FindIndexFromPosition(x,y,cathode);
+
+  if (segmentindex) {
+    padx = segmentindex->GetPadX();
+    pady = segmentindex->GetPadX();
+  }
+  else {
+    Warning("GetPadI","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
+  }    
+}
 //_________________________________________________
 AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
 {
@@ -145,7 +218,7 @@ AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition( cons
 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
 {
   // Getting Index from position if position is a center pad position
-  return GetIndexFromPosition( AliMUONSegmentPosition::Name(x,y, cathode).Data() );
+  return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
 }
 //_________________________________________________
 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
@@ -183,63 +256,11 @@ AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char*
   }
 }
 //_________________________________________________
-AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t /*x*/, Float_t /*y*/, Int_t /*cathode*/ ) const
-{
-
- //  char * name = AliMUONSegmentPosition::Name(x,y);
-
-//   if (GetIndexFromPosition( AliMUONSegmentPosition::Name(x,y)) ) 
-//     return GetIndexFromPosition( AliMUONSegmentPosition::Name(x,y) );
-  
-//   Float_t xl= ((Int_t) x*10 )/10.;
-//   Float_t yl= ((Int_t) y*10 )/10.;
-//   Int_t ix,iy, ixp;
-  
-//   for(ix=1; ix<4; ix++) {
-//     xl = ((Int_t) 0.5+10.*(x +  ((Float_t) ix )*0.1))/10.; 
-//     for(iy=-ix; iy<ix+1; iy++) {
-//       printf("A %d and %d and %f and %f \n",ix,iy,xl,yl);
-//       yl = ((Int_t) 10.*(y +  ((Float_t) iy )*0.1))/10. ;
-//       sprintf(name,"%5.1f-%5.1f",xl, yl);
-//       if (GetIndexFromPosition(name)) break;
-//     }
-//     if (GetIndexFromPosition(name)) break;
-    
-
-//     for(ixp=ix-1; ixp>-ix-1; ixp--) {
-//       xl = ((Int_t) 0.5+10.*(x +  ((Float_t) ixp )*0.1))/10. ;
-//       printf("B %d and %d and %f and %f \n",ixp,ix, xl, yl);
-//       sprintf(name,"%5.1f-%5.1f",xl, yl);
-//       if (GetIndexFromPosition(name)) break;
-//     }
-//     if (GetIndexFromPosition(name)) break;
-    
-//     for(iy=ix-1; iy>-ix-1; iy--) {
-//       yl = ((Int_t) 0.5+10.*(y +  ((Float_t) iy )*0.1))/10. ;
-//       printf("C %d and %d and %f and %f \n",-ix,iy,xl,yl);
-//       sprintf(name,"%5.1f-%5.1f",xl, yl);
-//       if (GetIndexFromPosition(name)) break;
-//     }
-//     if (GetIndexFromPosition(name)) break;
-    
-//     for(ixp=-ix+1; ixp<ix+1; ixp++) {
-//       xl = ((Int_t) 0.5+10.*(x +  ((Float_t) ixp )*0.1))/10. ;
-//       printf("D %d and %d and %f and %f \n",ixp,-ix,xl,yl);
-//       sprintf(name,"%5.1f-%5.1f",xl, yl);
-//       if (GetIndexFromPosition(name)) break;
-//     }
-//     if (GetIndexFromPosition(name)) break;
-//   }
-//   return GetIndexFromPosition(name);
-  return 0x0;
-}
-//_________________________________________________
 void    AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
 {
   TString elementType(DetectionElementType);
   fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
     +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
-  printf("file is %s\n", fSegmentationMappingFileBending.Data());
   fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
     +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
 
@@ -264,9 +285,11 @@ void    AliMUONSegmentationDetectionElement::Init(const char * DetectionElementT
   Int_t icathode;
   //Bendingplane
   icathode=0;
+  Info("ReadingSegmentationMappingFile","%s", fSegmentationMappingFileBending.Data());
   ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
   //NonBendingplane
   icathode=1;
+  Info("Init","Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data());
   ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
   
 }
@@ -275,28 +298,29 @@ void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString
 { 
   ifstream in( infile,  ios::in);
   if (!in) {
-    //    Error("ReadingSegmentationMappingFile", "File not found.");
+    Error("ReadingSegmentationMappingFile", "File not found.");
   }
   else {
     Int_t id, ix, iy, idmanu, idchannel;
     Float_t x, y;
-    while ( !in.eof()) {
+    do {
       in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
-      printf("id=%d ix=%d iy=%d x=%f y=%f idmanu=%d and idchannel=%d\n",id, ix, iy,  x, y,idmanu, idchannel);
+      //     printf("id=%d ix=%d iy=%d x=%f y=%f idmanu=%d and idchannel=%d\n",id, ix, iy,  x, y,idmanu, idchannel);
       
       fListOfIndexes->AddAt(     new AliMUONSegmentIndex(id,ix,iy,cathode), id);
       fListOfManuIndexes->AddAt( new AliMUONSegmentManuIndex(id,idmanu,0,idchannel), id);;
       fListOfPositions->AddAt(   new AliMUONSegmentPosition(id, x, y,cathode), id);;
 
-      ( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
-      ( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
-      ( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
+      //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
+      //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
+      //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
      
       fMapManuIndexIndex->Add( fListOfManuIndexes->At(id), fListOfIndexes->At(id));
       fMapIndexManuIndex->Add( fListOfIndexes->At(id),     fListOfManuIndexes->At(id));
       fMapIndexPosition->Add(  fListOfIndexes->At(id),     fListOfPositions->At(id));
-      fMapPositionIndex->Add(  fListOfPositions->At(id), fListOfIndexes->At(id) );
-    } 
+      fMapPositionIndex->Add(  fListOfPositions->At(id),   fListOfIndexes->At(id) );
+    }  
+    while ( !in.eof()); 
   }
   in.close();
 }
index 13b933b5b1cb5231715eb25d5d078e54ca22d089..d7feb8bfd2b721b592fda4ff6011c0b892bac56f 100644 (file)
 //===========================================================
 #include <Riostream.h>
 
-
-#include <TObject.h>
 #include <TString.h>
-#include <TArrayF.h>
+
+#include "AliSegmentation.h"
 
 class TClonesArray;
 class TMap;
@@ -39,31 +38,38 @@ class AliMUONSegmentationDetectionElement : public TObject {
   //AliMUONSegmentationDetectionElement(const char* ElementType="");
   virtual ~AliMUONSegmentationDetectionElement();
 
-  // User functions
+  // User common functions
+
+  AliMUONSegmentIndex     * FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode);
   AliMUONSegmentIndex     * GetIndex(Int_t manu, Int_t channel) const;
-  AliMUONSegmentIndex     * GetIndexFromPosition(Float_t x, Float_t y, Int_t icathode) const;
+  AliMUONSegmentIndex     * GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const;
   AliMUONSegmentManuIndex * GetManuIndex( Int_t padx, Int_t pady, Int_t cathode) const ;
   AliMUONSegmentPosition  * GetPosition(Int_t padx, Int_t pady, Int_t cathode) const ;
-
+  TObjArray *               ListOfIndexes()     {return fListOfIndexes;}
+  TObjArray *               ListOfManuIndexes() {return fListOfManuIndexes;}
+  TObjArray *               ListOfPositions()   {return fListOfPositions;}
   
+  void                      Init(const char * DetectionElementType="slat220000N");
+  void                      ReadingSegmentationMappingFile(TString infile, Int_t cathode);
+
+  // virtual functions from AliSegmentation. In future this class should derive from AliSegmentation
+  Float_t      GetAnod(Float_t xhit) const; // Anod wire coordinate closest to xhit
+  void         SetDAnod(Float_t D) {fWireD = D;};  // Wire Pitch
+  void         GetPadI(Float_t x, Float_t y , Int_t cathode, Int_t &padx, Int_t &pady); // Transform from Position to closest Index 
+  void         GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y );  // Transform from Index to Position 
+/*   void      FirstPad(Float_t xhit, Float_t yhit, Float_t dx, Float_t dy);// Initialiser  */
+/*   void      NextPad();  // Stepper  */
+/*   Int_t     MorePads(); // Condition  */
+/*   void      Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, Int_t Xlist[10], Int_t Ylist[10]); // Get next neighbours  */ 
+
+ protected:  
   AliMUONSegmentIndex     * GetIndex( const char * SegmentManuIndexName)const;
   AliMUONSegmentIndex     * GetIndexFromPosition( const char * PositionName)const;
   AliMUONSegmentManuIndex * GetManuIndex( const char * SegmentIndexName) const;
   AliMUONSegmentPosition  * GetPosition( const char * SegmentIndexName) const;
-  TObjArray *            ListOfIndexes() {return fListOfIndexes;}
-  TObjArray *            ListOfManuIndexes() {return fListOfIndexes;}
-  TObjArray *            ListOfPositions() {return fListOfIndexes;}
   AliMUONSegmentManuIndex * FindManuIndex(const char* ManuIndexName="") const;
-  AliMUONSegmentIndex * FindIndex(const char* IndexName="") const;
+  AliMUONSegmentIndex     * FindIndex(const char* IndexName="") const;
 
-  AliMUONSegmentIndex * FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const;
-  
-  void     Init(const char * DetectionElementType="slat220000N");
-
-  void     ReadingSegmentationMappingFile(TString infile, Int_t cathode);
-  
- protected:
   AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs);
   
  private:
@@ -77,17 +83,19 @@ class AliMUONSegmentationDetectionElement : public TObject {
   static const TString fgkNonBendingExt;  // bending file extention
 
   // data members
-  TString   fDetectionElementType;               //  Type of detection element St1Sector, slat220000N, etc ....
-  TString   fSegmentationMappingFileBending;    //  Segmentation & mapping file for bending plane
-  TString   fSegmentationMappingFileNonBending; //  Segmentation & mapping file for non bending plane
+  Float_t     fWireD;         // Wire pitch in cm
+  Float_t     fWireX0;        // Initial X0 position in local coordinates of the first wire
+  Int_t       fCurrentSegment;// Index of the current segment
+  TString     fDetectionElementType;               //  Type of detection element St1Sector, slat220000N, etc ....
+  TString     fSegmentationMappingFileBending;    //  Segmentation & mapping file for bending plane
+  TString     fSegmentationMappingFileNonBending; //  Segmentation & mapping file for non bending plane
   TObjArray * fListOfIndexes;        // TObject Array fo AliMUONSegmentIndex
   TObjArray * fListOfManuIndexes;   // TObject Array fo AliMUONSegmentManuIndex
   TObjArray * fListOfPositions;  // TObject Array fo AliMUONSegmentPositions
-  TMap *    fMapManuIndexIndex;  // Map with key ManuIndex and value = Index
-  TMap *    fMapIndexManuIndex;// Map with key ManuIndexIndex and value = ManuIndex
-  TMap *    fMapIndexPosition;// Map with key Index and value = Position
-  TMap *    fMapPositionIndex;// Map with key Index and value = Position
-  
+  TMap *      fMapManuIndexIndex;  // Map with key ManuIndex and value = Index
+  TMap *      fMapIndexManuIndex;// Map with key ManuIndexIndex and value = ManuIndex
+  TMap *      fMapIndexPosition;// Map with key Index and value = Position
+  TMap *      fMapPositionIndex;// Map with key Index and value = Position
 
   ClassDef(AliMUONSegmentationDetectionElement,1) // Segmentation for MUON detection elements