ROOT logo
/**************************************************************************
* 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.                  *
**************************************************************************/

// $Id$

#include "AliMUONClusterFinderCOG.h"

#include "AliLog.h"
#include "AliMUONCluster.h"
#include "AliMUONVDigit.h"
#include "AliMUONPad.h"
#include "AliMpArea.h"
#include "TVector2.h"
#include "AliMUONVDigitStore.h"

//-----------------------------------------------------------------------------
/// \class AliMUONClusterFinderCOG
///
/// A very basic (and mostly useless, probably) cluster finder.
/// 
/// We use AliMUONPreClusterFinder to actually build the cluster,
/// and then we simply use center-of-gravity to get the coordinates
/// of the cluster.
/// Only point to note is that we compute separately both
/// cathodes when doing, in order to take the positions from the 
/// direction with the better resolution.
///
/// \author Laurent Aphecetche
//-----------------------------------------------------------------------------

/// \cond CLASSIMP
ClassImp(AliMUONClusterFinderCOG)
/// \endcond

//_____________________________________________________________________________
AliMUONClusterFinderCOG::AliMUONClusterFinderCOG(AliMUONVClusterFinder* clusterFinder)
: AliMUONVClusterFinder(),
fPreClusterFinder(clusterFinder)
{
  /// ctor
}

//_____________________________________________________________________________
AliMUONClusterFinderCOG::~AliMUONClusterFinderCOG()
{
  /// dtor
  delete fPreClusterFinder;
}

//_____________________________________________________________________________
Bool_t 
AliMUONClusterFinderCOG::Prepare(Int_t detElemId,
                                 TObjArray* pads[2],
                                 const AliMpArea& area)
{
  /// Prepare for clustering
  
  return fPreClusterFinder->Prepare(detElemId,pads,area);
}

//_____________________________________________________________________________
AliMUONCluster* 
AliMUONClusterFinderCOG::NextCluster()
{
  /// Get next cluster
  
  if ( !fPreClusterFinder ) return 0x0;
  AliMUONCluster* cluster = fPreClusterFinder->NextCluster();
  if ( cluster )
  {
    ComputePosition(*cluster);

    if ( cluster->Charge() < 1.0675 ) // JC: adc -> fc
    {
      // skip that one
      return NextCluster();
    }    
  }
  return cluster;
}

//_____________________________________________________________________________
void 
AliMUONClusterFinderCOG::ComputePosition(AliMUONCluster& cluster)
{
  /// Compute a first estimate of cluster position by a basic center-of-gravity
  
  Double_t xmin = 1E9;
  Double_t ymin = 1E9;
  Double_t xmax = -1E9;
  Double_t ymax = -1E9;
  
  Double_t x[] = { 0.0, 0.0 };
  Double_t y[] = { 0.0, 0.0 };
  
  Double_t xsize[] = { 0.0, 0.0 } ;
  Double_t ysize[] = { 0.0, 0.0 } ;
  
  for ( Int_t cathode = 0; cathode < 2; ++cathode )
  {
    for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
    {
      AliMUONPad* pad = cluster.Pad(i);
      TVector2 padPosition = pad->Position();
      AliMpArea area(pad->X(), pad->Y(), pad->DX(), pad->DY());
      xmin = TMath::Min(area.LeftBorder(),xmin);
      xmax = TMath::Max(area.RightBorder(),xmax);
      ymin = TMath::Min(area.DownBorder(),ymin);
      ymax = TMath::Max(area.UpBorder(),ymax);
      if ( cathode == pad->Cathode() )
      {
        x[cathode] += padPosition.X()*pad->Charge();
        y[cathode] += padPosition.Y()*pad->Charge();
        xsize[cathode] += pad->Dimensions().X();
        ysize[cathode] += pad->Dimensions().Y();
      }
    }
    if ( cluster.Charge(cathode) )
    {
      x[cathode] /= cluster.Charge(cathode);
      y[cathode] /= cluster.Charge(cathode);
    }
    if ( cluster.Multiplicity(cathode) )
    {
      xsize[cathode] /= cluster.Multiplicity(cathode);
      ysize[cathode] /= cluster.Multiplicity(cathode);
    }
  }
  
  Double_t xCOG = 0;
  Double_t yCOG = 0;

  // take the positions from the direction with the better resolution
  xCOG = ( xsize[0] < xsize[1] ) ? x[0] : x[1];
  yCOG = ( ysize[0] < ysize[1] ) ? y[0] : y[1];
  
  AliDebug(1,Form("Cluster mult %d (x,y)=(%e,%e) boundaries=(xmin,ymin,xmax,ymax)=(%e,%e,%e,%e)"
                  " (x0,y0,x1,y1)=(%e,%e,%e,%e) ",
                  cluster.Multiplicity(),xCOG,yCOG,xmin,ymin,xmax,ymax,
                  x[0],y[0],x[1],y[1]));
  
  cluster.SetPosition(TVector2(xCOG,yCOG),cluster.Pad(0)->Dimensions()); // FIXME: what to put as an error here ?
}



 AliMUONClusterFinderCOG.cxx:1
 AliMUONClusterFinderCOG.cxx:2
 AliMUONClusterFinderCOG.cxx:3
 AliMUONClusterFinderCOG.cxx:4
 AliMUONClusterFinderCOG.cxx:5
 AliMUONClusterFinderCOG.cxx:6
 AliMUONClusterFinderCOG.cxx:7
 AliMUONClusterFinderCOG.cxx:8
 AliMUONClusterFinderCOG.cxx:9
 AliMUONClusterFinderCOG.cxx:10
 AliMUONClusterFinderCOG.cxx:11
 AliMUONClusterFinderCOG.cxx:12
 AliMUONClusterFinderCOG.cxx:13
 AliMUONClusterFinderCOG.cxx:14
 AliMUONClusterFinderCOG.cxx:15
 AliMUONClusterFinderCOG.cxx:16
 AliMUONClusterFinderCOG.cxx:17
 AliMUONClusterFinderCOG.cxx:18
 AliMUONClusterFinderCOG.cxx:19
 AliMUONClusterFinderCOG.cxx:20
 AliMUONClusterFinderCOG.cxx:21
 AliMUONClusterFinderCOG.cxx:22
 AliMUONClusterFinderCOG.cxx:23
 AliMUONClusterFinderCOG.cxx:24
 AliMUONClusterFinderCOG.cxx:25
 AliMUONClusterFinderCOG.cxx:26
 AliMUONClusterFinderCOG.cxx:27
 AliMUONClusterFinderCOG.cxx:28
 AliMUONClusterFinderCOG.cxx:29
 AliMUONClusterFinderCOG.cxx:30
 AliMUONClusterFinderCOG.cxx:31
 AliMUONClusterFinderCOG.cxx:32
 AliMUONClusterFinderCOG.cxx:33
 AliMUONClusterFinderCOG.cxx:34
 AliMUONClusterFinderCOG.cxx:35
 AliMUONClusterFinderCOG.cxx:36
 AliMUONClusterFinderCOG.cxx:37
 AliMUONClusterFinderCOG.cxx:38
 AliMUONClusterFinderCOG.cxx:39
 AliMUONClusterFinderCOG.cxx:40
 AliMUONClusterFinderCOG.cxx:41
 AliMUONClusterFinderCOG.cxx:42
 AliMUONClusterFinderCOG.cxx:43
 AliMUONClusterFinderCOG.cxx:44
 AliMUONClusterFinderCOG.cxx:45
 AliMUONClusterFinderCOG.cxx:46
 AliMUONClusterFinderCOG.cxx:47
 AliMUONClusterFinderCOG.cxx:48
 AliMUONClusterFinderCOG.cxx:49
 AliMUONClusterFinderCOG.cxx:50
 AliMUONClusterFinderCOG.cxx:51
 AliMUONClusterFinderCOG.cxx:52
 AliMUONClusterFinderCOG.cxx:53
 AliMUONClusterFinderCOG.cxx:54
 AliMUONClusterFinderCOG.cxx:55
 AliMUONClusterFinderCOG.cxx:56
 AliMUONClusterFinderCOG.cxx:57
 AliMUONClusterFinderCOG.cxx:58
 AliMUONClusterFinderCOG.cxx:59
 AliMUONClusterFinderCOG.cxx:60
 AliMUONClusterFinderCOG.cxx:61
 AliMUONClusterFinderCOG.cxx:62
 AliMUONClusterFinderCOG.cxx:63
 AliMUONClusterFinderCOG.cxx:64
 AliMUONClusterFinderCOG.cxx:65
 AliMUONClusterFinderCOG.cxx:66
 AliMUONClusterFinderCOG.cxx:67
 AliMUONClusterFinderCOG.cxx:68
 AliMUONClusterFinderCOG.cxx:69
 AliMUONClusterFinderCOG.cxx:70
 AliMUONClusterFinderCOG.cxx:71
 AliMUONClusterFinderCOG.cxx:72
 AliMUONClusterFinderCOG.cxx:73
 AliMUONClusterFinderCOG.cxx:74
 AliMUONClusterFinderCOG.cxx:75
 AliMUONClusterFinderCOG.cxx:76
 AliMUONClusterFinderCOG.cxx:77
 AliMUONClusterFinderCOG.cxx:78
 AliMUONClusterFinderCOG.cxx:79
 AliMUONClusterFinderCOG.cxx:80
 AliMUONClusterFinderCOG.cxx:81
 AliMUONClusterFinderCOG.cxx:82
 AliMUONClusterFinderCOG.cxx:83
 AliMUONClusterFinderCOG.cxx:84
 AliMUONClusterFinderCOG.cxx:85
 AliMUONClusterFinderCOG.cxx:86
 AliMUONClusterFinderCOG.cxx:87
 AliMUONClusterFinderCOG.cxx:88
 AliMUONClusterFinderCOG.cxx:89
 AliMUONClusterFinderCOG.cxx:90
 AliMUONClusterFinderCOG.cxx:91
 AliMUONClusterFinderCOG.cxx:92
 AliMUONClusterFinderCOG.cxx:93
 AliMUONClusterFinderCOG.cxx:94
 AliMUONClusterFinderCOG.cxx:95
 AliMUONClusterFinderCOG.cxx:96
 AliMUONClusterFinderCOG.cxx:97
 AliMUONClusterFinderCOG.cxx:98
 AliMUONClusterFinderCOG.cxx:99
 AliMUONClusterFinderCOG.cxx:100
 AliMUONClusterFinderCOG.cxx:101
 AliMUONClusterFinderCOG.cxx:102
 AliMUONClusterFinderCOG.cxx:103
 AliMUONClusterFinderCOG.cxx:104
 AliMUONClusterFinderCOG.cxx:105
 AliMUONClusterFinderCOG.cxx:106
 AliMUONClusterFinderCOG.cxx:107
 AliMUONClusterFinderCOG.cxx:108
 AliMUONClusterFinderCOG.cxx:109
 AliMUONClusterFinderCOG.cxx:110
 AliMUONClusterFinderCOG.cxx:111
 AliMUONClusterFinderCOG.cxx:112
 AliMUONClusterFinderCOG.cxx:113
 AliMUONClusterFinderCOG.cxx:114
 AliMUONClusterFinderCOG.cxx:115
 AliMUONClusterFinderCOG.cxx:116
 AliMUONClusterFinderCOG.cxx:117
 AliMUONClusterFinderCOG.cxx:118
 AliMUONClusterFinderCOG.cxx:119
 AliMUONClusterFinderCOG.cxx:120
 AliMUONClusterFinderCOG.cxx:121
 AliMUONClusterFinderCOG.cxx:122
 AliMUONClusterFinderCOG.cxx:123
 AliMUONClusterFinderCOG.cxx:124
 AliMUONClusterFinderCOG.cxx:125
 AliMUONClusterFinderCOG.cxx:126
 AliMUONClusterFinderCOG.cxx:127
 AliMUONClusterFinderCOG.cxx:128
 AliMUONClusterFinderCOG.cxx:129
 AliMUONClusterFinderCOG.cxx:130
 AliMUONClusterFinderCOG.cxx:131
 AliMUONClusterFinderCOG.cxx:132
 AliMUONClusterFinderCOG.cxx:133
 AliMUONClusterFinderCOG.cxx:134
 AliMUONClusterFinderCOG.cxx:135
 AliMUONClusterFinderCOG.cxx:136
 AliMUONClusterFinderCOG.cxx:137
 AliMUONClusterFinderCOG.cxx:138
 AliMUONClusterFinderCOG.cxx:139
 AliMUONClusterFinderCOG.cxx:140
 AliMUONClusterFinderCOG.cxx:141
 AliMUONClusterFinderCOG.cxx:142
 AliMUONClusterFinderCOG.cxx:143
 AliMUONClusterFinderCOG.cxx:144
 AliMUONClusterFinderCOG.cxx:145
 AliMUONClusterFinderCOG.cxx:146
 AliMUONClusterFinderCOG.cxx:147
 AliMUONClusterFinderCOG.cxx:148
 AliMUONClusterFinderCOG.cxx:149
 AliMUONClusterFinderCOG.cxx:150
 AliMUONClusterFinderCOG.cxx:151
 AliMUONClusterFinderCOG.cxx:152
 AliMUONClusterFinderCOG.cxx:153
 AliMUONClusterFinderCOG.cxx:154
 AliMUONClusterFinderCOG.cxx:155
 AliMUONClusterFinderCOG.cxx:156
 AliMUONClusterFinderCOG.cxx:157
 AliMUONClusterFinderCOG.cxx:158