ROOT logo
//*-- AUTHOR : Alexander Nekhaev
//*-- Modified : 17/01/2002 by I. Koenig

//_HADES_CLASS_DESCRIPTION 
////////////////////////////////////////////////////////////////
// HMdcLayerGeomPar
//
// Container class for the Mdc specific geometry parameters of
// the layers
// The parameter container is used by several tasks: digitizer,
// hit finder, event display.
// This class replaces the former class HMdcDigitGeomPar.
//
////////////////////////////////////////////////////////////////

#include "hmdclayergeompar.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hmdcdetector.h"
#include "hpario.h"
#include "hdetpario.h"
#include "hmdcgeomstruct.h"
#include "hmessagemgr.h"

ClassImp(HMdcLayerGeomParLay)
ClassImp(HMdcLayerGeomParMod)
ClassImp(HMdcLayerGeomParSec)
ClassImp(HMdcLayerGeomPar)

void HMdcLayerGeomParLay::fill(HMdcLayerGeomParLay& r)
{
  pitch=r.getPitch();
  catDist=r.getCatDist();
  wireOrient=r.getWireOrient();
  centralWireNr=r.getCentralWireNr();
  cathodeWireThickness=r.getCathodeWireThickness();
}

void HMdcLayerGeomParLay::Streamer(TBuffer &R__b)
{
   // Stream an object of class HMdcLayerGeomParLay.

   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
      TObject::Streamer(R__b);
      R__b >> pitch;
      R__b >> catDist;
      R__b >> wireOrient;
      R__b >> centralWireNr;
      if (R__v>1) {
        R__b >> cathodeWireThickness;
      }
      R__b.CheckByteCount(R__s, R__c, HMdcLayerGeomParLay::IsA());
   } else {
      R__c = R__b.WriteVersion(HMdcLayerGeomParLay::IsA(), kTRUE);
      TObject::Streamer(R__b);
      R__b << pitch;
      R__b << catDist;
      R__b << wireOrient;
      R__b << centralWireNr;
      R__b << cathodeWireThickness;
      R__b.SetByteCount(R__c, kTRUE);
   }
}

HMdcLayerGeomParMod::HMdcLayerGeomParMod() {
  // constructor creates an array of 6 pointers of type HMdcLayerGeomParLay
  array = new TObjArray(6);
  for (Int_t i = 0; i < 6; i++)
      array->AddAt( new HMdcLayerGeomParLay(),i);
}

HMdcLayerGeomParMod::~HMdcLayerGeomParMod() {
  // destructor deletes the pointer array
  array->Delete();
  delete array;
}

Int_t HMdcLayerGeomParMod::getSize() {
  // return the size of the pointer array 
  return array->GetEntries();
}

HMdcLayerGeomParSec::HMdcLayerGeomParSec() {
  // constructor creates an array of 4 pointers of type HMdcLayerGeomParMod
  array = new TObjArray(4);
  for (Int_t i = 0; i < 4; i++)
      array->AddAt( new HMdcLayerGeomParMod,i);
}

HMdcLayerGeomParSec::~HMdcLayerGeomParSec() {
  // destructor deletes the pointer array
  array->Delete();
  delete array;
}


Int_t HMdcLayerGeomParSec::getSize() {
  // return the size of the pointer array 
  return array->GetEntries();
}

HMdcLayerGeomPar::HMdcLayerGeomPar(const Char_t* name,const Char_t* title,
                                   const Char_t* context)
                 : HParSet(name,title,context) {
  // constructor creates an array of 6 pointers of type
  // HMdcLayerGeomParSec
  strcpy(detName,"Mdc");
  array = new TObjArray(6);
  for (Int_t i = 0; i < 6; i++) {
    array->AddAt(new HMdcLayerGeomParSec,i);
  }
  gHades->getRuntimeDb()->getContainer("MdcGeomStruct");
  ntuple=0;
}

HMdcLayerGeomPar::~HMdcLayerGeomPar() {
  // destructor deletes the pointer array
  array->Delete();
  delete array;
  if (ntuple) delete ntuple;
}

Int_t HMdcLayerGeomPar::getSize() {
  // return the size of the pointer array
  return array->GetEntries();
}

Bool_t HMdcLayerGeomPar::init(HParIo* inp,Int_t* set) {
  // initializes the container from an input
  // The number of wires is copied from the parameter container "MdcGeomStruct"
  // which must be initialized before calling the constructor.
  HDetParIo* input=inp->getDetParIo("HMdcParIo");
  Bool_t rc=kFALSE;
  if (input) {
    rc=input->init(this,set);
    if (rc&&changed) {
      calcLayerTransformations();
      HMdcGeomStruct* pMdc=
           (HMdcGeomStruct*)gHades->getRuntimeDb()->findContainer("MdcGeomStruct");
      if (pMdc) {
        for(Int_t i=0;i<6;i++) {
          for(Int_t j=0;j<4;j++) {
            for(Int_t k=0;k<6;k++) {
              (*this)[i][j][k].setNumWires(((*pMdc)[i][j][k]));
            }
          }
        }
      } else {
        Error("HMdcLayerGeomPar::init()","numWires in MdcLayerGeomPar not initialized, MdcGeomStruct not found");
        pMdc->setChanged(kFALSE);
        rc=kFALSE;
      }
    }
  }
  return rc;
}

void HMdcLayerGeomPar::calcLayerTransformations() {
  // Calculates the coordinate systems of the layers based on cell and cathode wire
  // thicknesses
  Float_t pos0, catDist;
  HGeomVector pos;
  for(Int_t s=0;s<6;s++) {
    HMdcLayerGeomParSec& sec=(*this)[s];
    for(Int_t m=0;m<4;m++) {
      HMdcLayerGeomParMod& mod=sec[m];
      pos0=mod[3].getCathodeWireThickness()/2.;
      for(Int_t l=0;l<3;l++) {
        pos0-=mod[l].getCatDist();
      }
      for(Int_t l=0;l<mod.getSize();l++) {
        HMdcLayerGeomParLay& lay=mod[l];
        catDist=lay.getCatDist();
        pos.setZ(pos0+catDist/2.);
        lay.getLayerPos().setTransVector(pos);
        pos0+=catDist;
      }
    }
  }
}

Int_t HMdcLayerGeomPar::write(HParIo* output) {
  // writes the container to an output
  HDetParIo* out=output->getDetParIo("HMdcParIo");
  if (out) return out->write(this);
  return -1;
}

void HMdcLayerGeomPar::readline(const Char_t *buf, Int_t *set) {
  // decodes one line read from ascii file I/O
    Int_t sector, module, layer, pos;
    Float_t pit, cd, wor, cwn, cwt;
    sscanf(buf,"%i%i%i%f%f%f%f%f",&sector,&module,&layer,&pit,&cd,&wor,&cwn,&cwt);
    pos=sector*4+module;
    if (!set[pos]) return;
    HMdcLayerGeomParLay& l=(*this)[sector][module][layer];
    l.fill(pit,cd,wor,cwn,cwt);
    set[pos]=999;
    return;
}

void HMdcLayerGeomPar::putAsciiHeader(TString& header) {
  // puts the ascii header to the string used in HMdcParAsciiFileIo
  header=
    "# Geometry parameters for digitization of the MDC\n"
    "# Format:\n"
    "# sector   module   layer\n"
    "#       pitch\n"
    "#       distance of cathode planes\n"
    "#       wire orientation\n"
    "#       number of central wire\n"
    "#       thickness of cathode wires\n";
}

Bool_t HMdcLayerGeomPar::writeline(Char_t *buf, Int_t sec, Int_t mod, Int_t lay) {
  // writes one line to the buffer used by ascii file I/O
    HMdcLayerGeomParLay &l = (*this)[sec][mod][lay];
    if (l.getNumWires()<=0) return kFALSE;
    sprintf(buf,"%1i %1i %1i %8.4f %8.4f %8.4f %8.4f %8.3f\n",
            sec, mod, lay,
            l.getPitch(), l.getCatDist(), l.getWireOrient(),
            l.getCentralWireNr(),l.getCathodeWireThickness());
    return kTRUE;
}

void HMdcLayerGeomPar::clear() {
  // clears the container
  for(Int_t s=0;s<6;s++) {
    HMdcLayerGeomParSec& sec=(*this)[s];
    for(Int_t m=0;m<4;m++) {
      HMdcLayerGeomParMod& mod=sec[m];
      for(Int_t l=0;l<mod.getSize();l++) {
        HMdcLayerGeomParLay& lay=mod[l];
	lay.clear();
      }
    }
  }
  status=kFALSE;
  resetInputVersions();
}

TNtuple* HMdcLayerGeomPar::getNtuple() {
  // fills the parameters into an TNtuple for drawing
  if (ntuple) ntuple->Reset();
  else ntuple=new TNtuple("MdcLayerGeomParNtuple","Ntuple of Mdc layer geometry",
                          "s:m:l:pt:nw:cd:wor:wof:cwt");
  Int_t nw;
  Float_t pt, cd, wor, wof, cwt;
  for(Int_t s=0;s<6;s++) {
    HMdcLayerGeomParSec& sec=(*this)[s];
    for(Int_t m=0;m<4;m++) {
      HMdcLayerGeomParMod& mod=sec[m];
      for(Int_t l=0;l<mod.getSize();l++) {
        HMdcLayerGeomParLay& lay=mod[l];
        pt=lay.getPitch();
        nw=lay.getNumWires();
        cd=lay.getCatDist();
        wor=lay.getWireOrient();
        wof=lay.getCentralWireNr();
        cwt=lay.getCathodeWireThickness();
        ntuple->Fill(s,m,l,pt,nw,cd,wor,wof,cwt);
      }
    }
  }
  return ntuple;
}

void HMdcLayerGeomPar::printParam() {
  for(Int_t s=0;s<6;s++) {
    HMdcLayerGeomParSec& sec=(*this)[s];
    for(Int_t m=0;m<4;m++) {
      HMdcLayerGeomParMod& mod=sec[m];
      for(Int_t l=0;l<mod.getSize();l++) {
        HMdcLayerGeomParLay& lay=mod[l];
        Int_t nw=lay.getNumWires();
        if (nw)
	  gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),
				 "%1i %1i %1i %8.4f %5i %8.4f %8.4f %8.4f %8.4f %8.4f\n",
				 s, m, l, lay.getPitch(), nw, lay.getCatDist(),
				 lay.getWireOrient(), lay.getCentralWireNr(),
                                 lay.getCathodeWireThickness(),
                                 lay.getLayerPos().getTransVector().getZ());
      }
    }
  }
  SEPERATOR_msg("-",60);
}
 hmdclayergeompar.cc:1
 hmdclayergeompar.cc:2
 hmdclayergeompar.cc:3
 hmdclayergeompar.cc:4
 hmdclayergeompar.cc:5
 hmdclayergeompar.cc:6
 hmdclayergeompar.cc:7
 hmdclayergeompar.cc:8
 hmdclayergeompar.cc:9
 hmdclayergeompar.cc:10
 hmdclayergeompar.cc:11
 hmdclayergeompar.cc:12
 hmdclayergeompar.cc:13
 hmdclayergeompar.cc:14
 hmdclayergeompar.cc:15
 hmdclayergeompar.cc:16
 hmdclayergeompar.cc:17
 hmdclayergeompar.cc:18
 hmdclayergeompar.cc:19
 hmdclayergeompar.cc:20
 hmdclayergeompar.cc:21
 hmdclayergeompar.cc:22
 hmdclayergeompar.cc:23
 hmdclayergeompar.cc:24
 hmdclayergeompar.cc:25
 hmdclayergeompar.cc:26
 hmdclayergeompar.cc:27
 hmdclayergeompar.cc:28
 hmdclayergeompar.cc:29
 hmdclayergeompar.cc:30
 hmdclayergeompar.cc:31
 hmdclayergeompar.cc:32
 hmdclayergeompar.cc:33
 hmdclayergeompar.cc:34
 hmdclayergeompar.cc:35
 hmdclayergeompar.cc:36
 hmdclayergeompar.cc:37
 hmdclayergeompar.cc:38
 hmdclayergeompar.cc:39
 hmdclayergeompar.cc:40
 hmdclayergeompar.cc:41
 hmdclayergeompar.cc:42
 hmdclayergeompar.cc:43
 hmdclayergeompar.cc:44
 hmdclayergeompar.cc:45
 hmdclayergeompar.cc:46
 hmdclayergeompar.cc:47
 hmdclayergeompar.cc:48
 hmdclayergeompar.cc:49
 hmdclayergeompar.cc:50
 hmdclayergeompar.cc:51
 hmdclayergeompar.cc:52
 hmdclayergeompar.cc:53
 hmdclayergeompar.cc:54
 hmdclayergeompar.cc:55
 hmdclayergeompar.cc:56
 hmdclayergeompar.cc:57
 hmdclayergeompar.cc:58
 hmdclayergeompar.cc:59
 hmdclayergeompar.cc:60
 hmdclayergeompar.cc:61
 hmdclayergeompar.cc:62
 hmdclayergeompar.cc:63
 hmdclayergeompar.cc:64
 hmdclayergeompar.cc:65
 hmdclayergeompar.cc:66
 hmdclayergeompar.cc:67
 hmdclayergeompar.cc:68
 hmdclayergeompar.cc:69
 hmdclayergeompar.cc:70
 hmdclayergeompar.cc:71
 hmdclayergeompar.cc:72
 hmdclayergeompar.cc:73
 hmdclayergeompar.cc:74
 hmdclayergeompar.cc:75
 hmdclayergeompar.cc:76
 hmdclayergeompar.cc:77
 hmdclayergeompar.cc:78
 hmdclayergeompar.cc:79
 hmdclayergeompar.cc:80
 hmdclayergeompar.cc:81
 hmdclayergeompar.cc:82
 hmdclayergeompar.cc:83
 hmdclayergeompar.cc:84
 hmdclayergeompar.cc:85
 hmdclayergeompar.cc:86
 hmdclayergeompar.cc:87
 hmdclayergeompar.cc:88
 hmdclayergeompar.cc:89
 hmdclayergeompar.cc:90
 hmdclayergeompar.cc:91
 hmdclayergeompar.cc:92
 hmdclayergeompar.cc:93
 hmdclayergeompar.cc:94
 hmdclayergeompar.cc:95
 hmdclayergeompar.cc:96
 hmdclayergeompar.cc:97
 hmdclayergeompar.cc:98
 hmdclayergeompar.cc:99
 hmdclayergeompar.cc:100
 hmdclayergeompar.cc:101
 hmdclayergeompar.cc:102
 hmdclayergeompar.cc:103
 hmdclayergeompar.cc:104
 hmdclayergeompar.cc:105
 hmdclayergeompar.cc:106
 hmdclayergeompar.cc:107
 hmdclayergeompar.cc:108
 hmdclayergeompar.cc:109
 hmdclayergeompar.cc:110
 hmdclayergeompar.cc:111
 hmdclayergeompar.cc:112
 hmdclayergeompar.cc:113
 hmdclayergeompar.cc:114
 hmdclayergeompar.cc:115
 hmdclayergeompar.cc:116
 hmdclayergeompar.cc:117
 hmdclayergeompar.cc:118
 hmdclayergeompar.cc:119
 hmdclayergeompar.cc:120
 hmdclayergeompar.cc:121
 hmdclayergeompar.cc:122
 hmdclayergeompar.cc:123
 hmdclayergeompar.cc:124
 hmdclayergeompar.cc:125
 hmdclayergeompar.cc:126
 hmdclayergeompar.cc:127
 hmdclayergeompar.cc:128
 hmdclayergeompar.cc:129
 hmdclayergeompar.cc:130
 hmdclayergeompar.cc:131
 hmdclayergeompar.cc:132
 hmdclayergeompar.cc:133
 hmdclayergeompar.cc:134
 hmdclayergeompar.cc:135
 hmdclayergeompar.cc:136
 hmdclayergeompar.cc:137
 hmdclayergeompar.cc:138
 hmdclayergeompar.cc:139
 hmdclayergeompar.cc:140
 hmdclayergeompar.cc:141
 hmdclayergeompar.cc:142
 hmdclayergeompar.cc:143
 hmdclayergeompar.cc:144
 hmdclayergeompar.cc:145
 hmdclayergeompar.cc:146
 hmdclayergeompar.cc:147
 hmdclayergeompar.cc:148
 hmdclayergeompar.cc:149
 hmdclayergeompar.cc:150
 hmdclayergeompar.cc:151
 hmdclayergeompar.cc:152
 hmdclayergeompar.cc:153
 hmdclayergeompar.cc:154
 hmdclayergeompar.cc:155
 hmdclayergeompar.cc:156
 hmdclayergeompar.cc:157
 hmdclayergeompar.cc:158
 hmdclayergeompar.cc:159
 hmdclayergeompar.cc:160
 hmdclayergeompar.cc:161
 hmdclayergeompar.cc:162
 hmdclayergeompar.cc:163
 hmdclayergeompar.cc:164
 hmdclayergeompar.cc:165
 hmdclayergeompar.cc:166
 hmdclayergeompar.cc:167
 hmdclayergeompar.cc:168
 hmdclayergeompar.cc:169
 hmdclayergeompar.cc:170
 hmdclayergeompar.cc:171
 hmdclayergeompar.cc:172
 hmdclayergeompar.cc:173
 hmdclayergeompar.cc:174
 hmdclayergeompar.cc:175
 hmdclayergeompar.cc:176
 hmdclayergeompar.cc:177
 hmdclayergeompar.cc:178
 hmdclayergeompar.cc:179
 hmdclayergeompar.cc:180
 hmdclayergeompar.cc:181
 hmdclayergeompar.cc:182
 hmdclayergeompar.cc:183
 hmdclayergeompar.cc:184
 hmdclayergeompar.cc:185
 hmdclayergeompar.cc:186
 hmdclayergeompar.cc:187
 hmdclayergeompar.cc:188
 hmdclayergeompar.cc:189
 hmdclayergeompar.cc:190
 hmdclayergeompar.cc:191
 hmdclayergeompar.cc:192
 hmdclayergeompar.cc:193
 hmdclayergeompar.cc:194
 hmdclayergeompar.cc:195
 hmdclayergeompar.cc:196
 hmdclayergeompar.cc:197
 hmdclayergeompar.cc:198
 hmdclayergeompar.cc:199
 hmdclayergeompar.cc:200
 hmdclayergeompar.cc:201
 hmdclayergeompar.cc:202
 hmdclayergeompar.cc:203
 hmdclayergeompar.cc:204
 hmdclayergeompar.cc:205
 hmdclayergeompar.cc:206
 hmdclayergeompar.cc:207
 hmdclayergeompar.cc:208
 hmdclayergeompar.cc:209
 hmdclayergeompar.cc:210
 hmdclayergeompar.cc:211
 hmdclayergeompar.cc:212
 hmdclayergeompar.cc:213
 hmdclayergeompar.cc:214
 hmdclayergeompar.cc:215
 hmdclayergeompar.cc:216
 hmdclayergeompar.cc:217
 hmdclayergeompar.cc:218
 hmdclayergeompar.cc:219
 hmdclayergeompar.cc:220
 hmdclayergeompar.cc:221
 hmdclayergeompar.cc:222
 hmdclayergeompar.cc:223
 hmdclayergeompar.cc:224
 hmdclayergeompar.cc:225
 hmdclayergeompar.cc:226
 hmdclayergeompar.cc:227
 hmdclayergeompar.cc:228
 hmdclayergeompar.cc:229
 hmdclayergeompar.cc:230
 hmdclayergeompar.cc:231
 hmdclayergeompar.cc:232
 hmdclayergeompar.cc:233
 hmdclayergeompar.cc:234
 hmdclayergeompar.cc:235
 hmdclayergeompar.cc:236
 hmdclayergeompar.cc:237
 hmdclayergeompar.cc:238
 hmdclayergeompar.cc:239
 hmdclayergeompar.cc:240
 hmdclayergeompar.cc:241
 hmdclayergeompar.cc:242
 hmdclayergeompar.cc:243
 hmdclayergeompar.cc:244
 hmdclayergeompar.cc:245
 hmdclayergeompar.cc:246
 hmdclayergeompar.cc:247
 hmdclayergeompar.cc:248
 hmdclayergeompar.cc:249
 hmdclayergeompar.cc:250
 hmdclayergeompar.cc:251
 hmdclayergeompar.cc:252
 hmdclayergeompar.cc:253
 hmdclayergeompar.cc:254
 hmdclayergeompar.cc:255
 hmdclayergeompar.cc:256
 hmdclayergeompar.cc:257
 hmdclayergeompar.cc:258
 hmdclayergeompar.cc:259
 hmdclayergeompar.cc:260
 hmdclayergeompar.cc:261
 hmdclayergeompar.cc:262
 hmdclayergeompar.cc:263
 hmdclayergeompar.cc:264
 hmdclayergeompar.cc:265
 hmdclayergeompar.cc:266
 hmdclayergeompar.cc:267
 hmdclayergeompar.cc:268
 hmdclayergeompar.cc:269
 hmdclayergeompar.cc:270
 hmdclayergeompar.cc:271
 hmdclayergeompar.cc:272
 hmdclayergeompar.cc:273
 hmdclayergeompar.cc:274
 hmdclayergeompar.cc:275
 hmdclayergeompar.cc:276
 hmdclayergeompar.cc:277
 hmdclayergeompar.cc:278
 hmdclayergeompar.cc:279
 hmdclayergeompar.cc:280
 hmdclayergeompar.cc:281
 hmdclayergeompar.cc:282
 hmdclayergeompar.cc:283
 hmdclayergeompar.cc:284
 hmdclayergeompar.cc:285
 hmdclayergeompar.cc:286
 hmdclayergeompar.cc:287
 hmdclayergeompar.cc:288
 hmdclayergeompar.cc:289
 hmdclayergeompar.cc:290