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 "AliMUONPainterPadStore.h"

#include "AliMUONCalibParamND.h"
#include "AliMUON2DMap.h"
#include "AliMUONVStore.h"
#include "AliMUONVDigit.h"
#include "AliLog.h"
#include <Riostream.h>
#include <TArrayI.h>
#include <TVector2.h>

///\class AliMUONPainterPadStore
///
/// Container for pads
///
///\author Laurent Aphecetche, Subatech

using std::cout;
using std::endl;
///\cond CLASSIMP
ClassImp(AliMUONPainterPadStore)
///\endcond

//_____________________________________________________________________________
AliMUONPainterPadStore::AliMUONPainterPadStore(TRootIOCtor* /*dummy*/) : TObject(),
fPadStore(0x0)
{
  /// ctor
}

//_____________________________________________________________________________
AliMUONPainterPadStore::AliMUONPainterPadStore() : TObject(),
  fPadStore(new AliMUON2DMap(kTRUE))
{
    /// ctor
}

//_____________________________________________________________________________
AliMUONPainterPadStore::~AliMUONPainterPadStore()
{
  /// dtor
  delete fPadStore;
}

//_____________________________________________________________________________
Int_t
AliMUONPainterPadStore::FindPadID(const TArrayI& pads, Double_t x, Double_t y) const
{
  /// Find, in array of pads, the one which contains (x,y). Returns -1 if not
  /// found
  
  for ( Int_t i = 0; i < pads.GetSize(); ++i ) 
  {
    Int_t id = pads.At(i);
    
    TVector2 position;
    TVector2 dimensions;
    
    GetPadGeometry(id,position,dimensions);
    
    TVector2 bl(position-dimensions);
    TVector2 ur(position+dimensions);    
    if ( bl.X() <= x && ur.X() >= x && bl.Y() <= y && ur.Y() >= y ) 
    {
      return id;
    }
  }
  return -1;
}


//_____________________________________________________________________________
AliMUONVCalibParam*
AliMUONPainterPadStore::Get(Int_t detElemId, Int_t manuId) const
{
  /// Get the pad container for a given manu
  
  AliMUONVCalibParam* param = 
  static_cast<AliMUONVCalibParam*>(fPadStore->FindObject(detElemId,manuId));
  
  if (!param)
  {
    param = new AliMUONCalibParamND(4,64,detElemId,manuId,-1.0);
    fPadStore->Add(param);
  }
  
  return param;
}

//_____________________________________________________________________________
void
AliMUONPainterPadStore::GetBoundaries(const TArrayI& pads,
                                      Double_t& xmin,
                                      Double_t& ymin,
                                      Double_t& xmax,
                                      Double_t& ymax) const
{
  /// Get the area covered by an array of pads
  
  xmin=ymin=1E9;
  xmax=ymax=-1E9;
  
  for ( Int_t i = 0; i < pads.GetSize(); ++i ) 
  {
    Int_t id = pads.At(i);
    
    TVector2 position;
    TVector2 dimensions;
    
    GetPadGeometry(id,position,dimensions);
    
    TVector2 bl(position-dimensions);
    TVector2 ur(position+dimensions);
    xmin = TMath::Min(xmin,bl.X());
    ymin = TMath::Min(ymin,bl.Y());
    xmax = TMath::Max(xmax,ur.X());
    ymax = TMath::Max(ymax,ur.Y());
  }     
}

//_____________________________________________________________________________
void
AliMUONPainterPadStore::GetPadGeometry(Int_t padId, 
                                       TVector2& position,
                                       TVector2& dimensions) const
{
  /// Get the geomtry of one pad
  
  if ( padId < 0 ) 
  {
    AliError(Form("padId is < 0 : %d",padId));
    position.Set(0.0,0.0);
    dimensions.Set(-1.0,-1.0);
    return;
  }
  
  Int_t detElemId = AliMUONVDigit::DetElemId(padId);
  Int_t manuId = AliMUONVDigit::ManuId(padId);
  Int_t manuChannel = AliMUONVDigit::ManuChannel(padId);
  
  AliMUONVCalibParam* param = 
    static_cast<AliMUONVCalibParam*>(fPadStore->FindObject(detElemId,manuId));
  
  if (!param)
  {
    AliError(Form("Could not find object DE %d manu %d",detElemId,manuId));
    position.Set(0.0,0.0);
    dimensions.Set(-1.0,-1.0);
    return;
  }
  
  position.Set(param->ValueAsDouble(manuChannel,0),
               param->ValueAsDouble(manuChannel,1));
  
  dimensions.Set(param->ValueAsDouble(manuChannel,2),
                 param->ValueAsDouble(manuChannel,3));
  
  AliDebug(3,Form("DE %4d Manu %4d Channel %2d Pos %e %e Dim %e %e",
                       detElemId,manuId,manuChannel,
                       position.X(),position.Y(),
                       dimensions.X(),dimensions.Y()));                       
}

//_____________________________________________________________________________
Int_t
AliMUONPainterPadStore::GetSize() const
{
  /// Get the number of pads we handle
  
  TIter next(fPadStore->CreateIterator());
  AliMUONVCalibParam* param;
  Int_t n(0);
  
  while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
  {
    for ( Int_t i = 0; i < param->Size(); ++i ) 
    {
      if ( param->ValueAsDouble(i,2) >= 0 && param->ValueAsDouble(i,3) >= 0 ) 
      {
        ++n;
      }
    }
  }
  
  return n;
}

//_____________________________________________________________________________
void
AliMUONPainterPadStore::PrintPads(const TArrayI& pads) const
{
  /// Printout
  cout << "n=" << pads.GetSize() << endl;
  
  for ( Int_t i = 0; i < pads.GetSize(); ++i ) 
  {
    Int_t id = pads.At(i);
    TVector2 position, dimensions;
    GetPadGeometry(id,position,dimensions);
    cout << Form("i %4d DE %4d ManuID %4d ManuChannel %2d (X,Y)=(%7.3f,%7.3f)"
                 " (DX,DY)=(%7.3f,%7.3f)",
                 i,
                 AliMUONVDigit::DetElemId(id),
                 AliMUONVDigit::ManuId(id),
                 AliMUONVDigit::ManuChannel(id),
                 position.X(),position.Y(),
                 dimensions.X(),dimensions.Y()) << endl;
  }
}

 AliMUONPainterPadStore.cxx:1
 AliMUONPainterPadStore.cxx:2
 AliMUONPainterPadStore.cxx:3
 AliMUONPainterPadStore.cxx:4
 AliMUONPainterPadStore.cxx:5
 AliMUONPainterPadStore.cxx:6
 AliMUONPainterPadStore.cxx:7
 AliMUONPainterPadStore.cxx:8
 AliMUONPainterPadStore.cxx:9
 AliMUONPainterPadStore.cxx:10
 AliMUONPainterPadStore.cxx:11
 AliMUONPainterPadStore.cxx:12
 AliMUONPainterPadStore.cxx:13
 AliMUONPainterPadStore.cxx:14
 AliMUONPainterPadStore.cxx:15
 AliMUONPainterPadStore.cxx:16
 AliMUONPainterPadStore.cxx:17
 AliMUONPainterPadStore.cxx:18
 AliMUONPainterPadStore.cxx:19
 AliMUONPainterPadStore.cxx:20
 AliMUONPainterPadStore.cxx:21
 AliMUONPainterPadStore.cxx:22
 AliMUONPainterPadStore.cxx:23
 AliMUONPainterPadStore.cxx:24
 AliMUONPainterPadStore.cxx:25
 AliMUONPainterPadStore.cxx:26
 AliMUONPainterPadStore.cxx:27
 AliMUONPainterPadStore.cxx:28
 AliMUONPainterPadStore.cxx:29
 AliMUONPainterPadStore.cxx:30
 AliMUONPainterPadStore.cxx:31
 AliMUONPainterPadStore.cxx:32
 AliMUONPainterPadStore.cxx:33
 AliMUONPainterPadStore.cxx:34
 AliMUONPainterPadStore.cxx:35
 AliMUONPainterPadStore.cxx:36
 AliMUONPainterPadStore.cxx:37
 AliMUONPainterPadStore.cxx:38
 AliMUONPainterPadStore.cxx:39
 AliMUONPainterPadStore.cxx:40
 AliMUONPainterPadStore.cxx:41
 AliMUONPainterPadStore.cxx:42
 AliMUONPainterPadStore.cxx:43
 AliMUONPainterPadStore.cxx:44
 AliMUONPainterPadStore.cxx:45
 AliMUONPainterPadStore.cxx:46
 AliMUONPainterPadStore.cxx:47
 AliMUONPainterPadStore.cxx:48
 AliMUONPainterPadStore.cxx:49
 AliMUONPainterPadStore.cxx:50
 AliMUONPainterPadStore.cxx:51
 AliMUONPainterPadStore.cxx:52
 AliMUONPainterPadStore.cxx:53
 AliMUONPainterPadStore.cxx:54
 AliMUONPainterPadStore.cxx:55
 AliMUONPainterPadStore.cxx:56
 AliMUONPainterPadStore.cxx:57
 AliMUONPainterPadStore.cxx:58
 AliMUONPainterPadStore.cxx:59
 AliMUONPainterPadStore.cxx:60
 AliMUONPainterPadStore.cxx:61
 AliMUONPainterPadStore.cxx:62
 AliMUONPainterPadStore.cxx:63
 AliMUONPainterPadStore.cxx:64
 AliMUONPainterPadStore.cxx:65
 AliMUONPainterPadStore.cxx:66
 AliMUONPainterPadStore.cxx:67
 AliMUONPainterPadStore.cxx:68
 AliMUONPainterPadStore.cxx:69
 AliMUONPainterPadStore.cxx:70
 AliMUONPainterPadStore.cxx:71
 AliMUONPainterPadStore.cxx:72
 AliMUONPainterPadStore.cxx:73
 AliMUONPainterPadStore.cxx:74
 AliMUONPainterPadStore.cxx:75
 AliMUONPainterPadStore.cxx:76
 AliMUONPainterPadStore.cxx:77
 AliMUONPainterPadStore.cxx:78
 AliMUONPainterPadStore.cxx:79
 AliMUONPainterPadStore.cxx:80
 AliMUONPainterPadStore.cxx:81
 AliMUONPainterPadStore.cxx:82
 AliMUONPainterPadStore.cxx:83
 AliMUONPainterPadStore.cxx:84
 AliMUONPainterPadStore.cxx:85
 AliMUONPainterPadStore.cxx:86
 AliMUONPainterPadStore.cxx:87
 AliMUONPainterPadStore.cxx:88
 AliMUONPainterPadStore.cxx:89
 AliMUONPainterPadStore.cxx:90
 AliMUONPainterPadStore.cxx:91
 AliMUONPainterPadStore.cxx:92
 AliMUONPainterPadStore.cxx:93
 AliMUONPainterPadStore.cxx:94
 AliMUONPainterPadStore.cxx:95
 AliMUONPainterPadStore.cxx:96
 AliMUONPainterPadStore.cxx:97
 AliMUONPainterPadStore.cxx:98
 AliMUONPainterPadStore.cxx:99
 AliMUONPainterPadStore.cxx:100
 AliMUONPainterPadStore.cxx:101
 AliMUONPainterPadStore.cxx:102
 AliMUONPainterPadStore.cxx:103
 AliMUONPainterPadStore.cxx:104
 AliMUONPainterPadStore.cxx:105
 AliMUONPainterPadStore.cxx:106
 AliMUONPainterPadStore.cxx:107
 AliMUONPainterPadStore.cxx:108
 AliMUONPainterPadStore.cxx:109
 AliMUONPainterPadStore.cxx:110
 AliMUONPainterPadStore.cxx:111
 AliMUONPainterPadStore.cxx:112
 AliMUONPainterPadStore.cxx:113
 AliMUONPainterPadStore.cxx:114
 AliMUONPainterPadStore.cxx:115
 AliMUONPainterPadStore.cxx:116
 AliMUONPainterPadStore.cxx:117
 AliMUONPainterPadStore.cxx:118
 AliMUONPainterPadStore.cxx:119
 AliMUONPainterPadStore.cxx:120
 AliMUONPainterPadStore.cxx:121
 AliMUONPainterPadStore.cxx:122
 AliMUONPainterPadStore.cxx:123
 AliMUONPainterPadStore.cxx:124
 AliMUONPainterPadStore.cxx:125
 AliMUONPainterPadStore.cxx:126
 AliMUONPainterPadStore.cxx:127
 AliMUONPainterPadStore.cxx:128
 AliMUONPainterPadStore.cxx:129
 AliMUONPainterPadStore.cxx:130
 AliMUONPainterPadStore.cxx:131
 AliMUONPainterPadStore.cxx:132
 AliMUONPainterPadStore.cxx:133
 AliMUONPainterPadStore.cxx:134
 AliMUONPainterPadStore.cxx:135
 AliMUONPainterPadStore.cxx:136
 AliMUONPainterPadStore.cxx:137
 AliMUONPainterPadStore.cxx:138
 AliMUONPainterPadStore.cxx:139
 AliMUONPainterPadStore.cxx:140
 AliMUONPainterPadStore.cxx:141
 AliMUONPainterPadStore.cxx:142
 AliMUONPainterPadStore.cxx:143
 AliMUONPainterPadStore.cxx:144
 AliMUONPainterPadStore.cxx:145
 AliMUONPainterPadStore.cxx:146
 AliMUONPainterPadStore.cxx:147
 AliMUONPainterPadStore.cxx:148
 AliMUONPainterPadStore.cxx:149
 AliMUONPainterPadStore.cxx:150
 AliMUONPainterPadStore.cxx:151
 AliMUONPainterPadStore.cxx:152
 AliMUONPainterPadStore.cxx:153
 AliMUONPainterPadStore.cxx:154
 AliMUONPainterPadStore.cxx:155
 AliMUONPainterPadStore.cxx:156
 AliMUONPainterPadStore.cxx:157
 AliMUONPainterPadStore.cxx:158
 AliMUONPainterPadStore.cxx:159
 AliMUONPainterPadStore.cxx:160
 AliMUONPainterPadStore.cxx:161
 AliMUONPainterPadStore.cxx:162
 AliMUONPainterPadStore.cxx:163
 AliMUONPainterPadStore.cxx:164
 AliMUONPainterPadStore.cxx:165
 AliMUONPainterPadStore.cxx:166
 AliMUONPainterPadStore.cxx:167
 AliMUONPainterPadStore.cxx:168
 AliMUONPainterPadStore.cxx:169
 AliMUONPainterPadStore.cxx:170
 AliMUONPainterPadStore.cxx:171
 AliMUONPainterPadStore.cxx:172
 AliMUONPainterPadStore.cxx:173
 AliMUONPainterPadStore.cxx:174
 AliMUONPainterPadStore.cxx:175
 AliMUONPainterPadStore.cxx:176
 AliMUONPainterPadStore.cxx:177
 AliMUONPainterPadStore.cxx:178
 AliMUONPainterPadStore.cxx:179
 AliMUONPainterPadStore.cxx:180
 AliMUONPainterPadStore.cxx:181
 AliMUONPainterPadStore.cxx:182
 AliMUONPainterPadStore.cxx:183
 AliMUONPainterPadStore.cxx:184
 AliMUONPainterPadStore.cxx:185
 AliMUONPainterPadStore.cxx:186
 AliMUONPainterPadStore.cxx:187
 AliMUONPainterPadStore.cxx:188
 AliMUONPainterPadStore.cxx:189
 AliMUONPainterPadStore.cxx:190
 AliMUONPainterPadStore.cxx:191
 AliMUONPainterPadStore.cxx:192
 AliMUONPainterPadStore.cxx:193
 AliMUONPainterPadStore.cxx:194
 AliMUONPainterPadStore.cxx:195
 AliMUONPainterPadStore.cxx:196
 AliMUONPainterPadStore.cxx:197
 AliMUONPainterPadStore.cxx:198
 AliMUONPainterPadStore.cxx:199
 AliMUONPainterPadStore.cxx:200
 AliMUONPainterPadStore.cxx:201
 AliMUONPainterPadStore.cxx:202
 AliMUONPainterPadStore.cxx:203
 AliMUONPainterPadStore.cxx:204
 AliMUONPainterPadStore.cxx:205
 AliMUONPainterPadStore.cxx:206
 AliMUONPainterPadStore.cxx:207
 AliMUONPainterPadStore.cxx:208
 AliMUONPainterPadStore.cxx:209
 AliMUONPainterPadStore.cxx:210
 AliMUONPainterPadStore.cxx:211
 AliMUONPainterPadStore.cxx:212
 AliMUONPainterPadStore.cxx:213
 AliMUONPainterPadStore.cxx:214
 AliMUONPainterPadStore.cxx:215
 AliMUONPainterPadStore.cxx:216
 AliMUONPainterPadStore.cxx:217
 AliMUONPainterPadStore.cxx:218
 AliMUONPainterPadStore.cxx:219
 AliMUONPainterPadStore.cxx:220
 AliMUONPainterPadStore.cxx:221
 AliMUONPainterPadStore.cxx:222
 AliMUONPainterPadStore.cxx:223
 AliMUONPainterPadStore.cxx:224
 AliMUONPainterPadStore.cxx:225
 AliMUONPainterPadStore.cxx:226
 AliMUONPainterPadStore.cxx:227