ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Created : 10/11/2003

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
// HGeomHit
//
// Base class for hit definition in GEANT
//
/////////////////////////////////////////////////////////////

#include "hgeomhit.h"
#include "hgeomset.h"
#include "hgeomnode.h"
#include "TString.h"
#include <ctype.h>

ClassImp(HGeomHit)

HGeomHit::HGeomHit(HGeomSet* p) {
  // Non-public constructor
  pSet=p;
  currentNode=0;
  nh=0;
  chnamh=0;
  nbitsh=0;
  orig=0;
  fact=0;
  nv=0;
  chnmsv=0;
  nbitsv=0;
  copies=0;
}

HGeomHit::~HGeomHit() {
  // Destructor
  if (chnamh) {
    delete [] chnamh;
    chnamh=0;
  }
  if (nbitsh) {
    delete [] nbitsh;
    nbitsh=0;
  }
  if (orig) {
    delete [] orig;
    orig=0;
  }
  if (fact) {
    delete [] fact;
    fact=0;
  }
  if (chnmsv) {
    delete [] chnmsv;
    chnmsv=0;
  }
  if (nbitsv) {
    delete [] nbitsv;
    nbitsv=0;
  }
  if (copies) {
    copies->Delete();
    delete copies;
    copies=0;
  }
}

const Char_t* HGeomHit::getDetectorName() {
  // Returns the name of the corresponding detector
  return pSet->GetName();
}

void HGeomHit::read(fstream& fin) {
  // Reads the hit definition from file
  const Int_t maxbuf=256;
  Char_t buf[maxbuf];
  TString tmp;
  while(!fin.eof()) {
    fin>>tmp;
    tmp=tmp.Strip(tmp.kBoth);
    if (tmp.IsNull() || tmp.BeginsWith("/")) fin.getline(buf,maxbuf);
    else {
      fName=tmp(0,4);
      fin>>nh;
      if (nh>0) {
        chnamh=new char[nh*5];
        nbitsh=new Int_t[nh];
        orig=new Float_t[nh];
        fact=new Float_t[nh];
        for(Int_t i=0;i<nh;i++) {
          fin>>tmp;
          tmp.Resize(4);
          strcpy(&chnamh[i*5],tmp.Data());
        }
        for(Int_t i=0;i<nh;i++) fin>>nbitsh[i];
        for(Int_t i=0;i<nh;i++) fin>>orig[i];
        for(Int_t i=0;i<nh;i++) fin>>fact[i];
      }
    }
  }
}


void HGeomHit::write(fstream& fout) {
  // Writes the hit definition to file
  fout<<fName<<'\n';
  fout<<nh<<'\n';  
  if (nh>0) {
      fout.precision(2);
      fout.setf(ios::fixed,ios::floatfield);
    for(Int_t i=0;i<nh;i++) fout<<setw(8)<<right<<&chnamh[i*5]<<" ";
    fout<<endl;
    for(Int_t i=0;i<nh;i++) fout<<setw(8)<<right<<nbitsh[i]<<" ";
    fout<<endl;
    for(Int_t i=0;i<nh;i++) fout<<setw(8)<<right<<orig[i]<<" ";
    fout<<endl;
    fout.setf(ios::scientific,ios::floatfield);
    fout.precision(1);
    for(Int_t i=0;i<nh;i++) fout<<setw(8)<<right<<fact[i]<<" ";
    fout<<endl;
  }
}

void HGeomHit::print() {
  // Prints the hit definition
  cout<<fName<<'\n';
  cout<<nh<<'\n';  
  if (nh>0) {
    for(Int_t i=0;i<nh;i++) cout<<setiosflags(ios::fixed)<<setprecision(2)<<setw(8)<<right<<&chnamh[i*5]<<" ";
    cout<<endl;
    for(Int_t i=0;i<nh;i++) cout<<setiosflags(ios::fixed)<<setprecision(2)<<setw(8)<<right<<nbitsh[i]<<" ";
    cout<<endl;
    for(Int_t i=0;i<nh;i++) cout<<setiosflags(ios::fixed)<<setprecision(2)<<setw(8)<<right<<orig[i]<<" ";
    cout<<endl;
    for(Int_t i=0;i<nh;i++) cout<<setiosflags(ios::scientific|ios::floatfield)<<setprecision(1)<<setw(8)<<right<<fact[i]<<" ";
    cout<<endl;
  }
  if (nv>0) {
    cout<<"Hits for sensitive volume: "<<currentNode->GetName()
        <<"   idtype: "<<getIdType()<<"   nv: "<<nv<<endl;
    for(Int_t i=0;i<nv;i++) cout<<i<<"  "<<&chnmsv[i*5]<<"  "<<nbitsv[i]<<endl;
  }
}

Bool_t HGeomHit::setCurrentNode(HGeomNode* node) {
  // Sets the current node, fills chnmsv and calculates nbitsv  
  currentNode=node;
  if (chnmsv) {
    delete [] chnmsv;
    chnmsv=0;
  }
  if (nbitsv) {
    delete [] nbitsv;
    nbitsv=0;
  }
  nv=0;
  if (!currentNode||nh<=0) return kFALSE;
  strncpy(compName,currentNode->GetName(),4);
  compName[4]='\0';
  if (!copies) {
    copies=new TList;
    TListIter iter(pSet->getListOfVolumes());
    HGeomNode* vol;
    while((vol=(HGeomNode*)iter.Next())) {
      Int_t num=vol->getCopyNo();
      if (num>1) {
        TString volName(vol->GetName(),4);
        HGeomCopyNodeNum* v=(HGeomCopyNodeNum*)(copies->FindObject(volName.Data()));
        if (v) {
          if (num>v->maxCopyNum) v->maxCopyNum=num;
        } else copies->Add(new HGeomCopyNodeNum(volName,num));
      }
    }
  }
  Char_t treeNames[20][5];
  Int_t i, j, copyNo[20], nvmax=20;
  HGeomNode* pNode=currentNode;
  while (pNode&&nv<=nvmax) {
    if (nv==nvmax) {
      Error("restoreTree()",
            "number of levels in tree too large, only %i allowed!\n",nvmax);
      return kFALSE;
    }
    TString nodeName(pNode->GetName());
    if (nodeName.Length()<=4) {
      strcpy(treeNames[nv],nodeName.Data());
      copyNo[nv]=1;
    } else {
      TString s(nodeName,4);
      HGeomCopyNodeNum* v=(HGeomCopyNodeNum*)(copies->FindObject(s));
      strcpy(treeNames[nv],s.Data());
      if (v) {
        copyNo[nv]=v->maxCopyNum;
      } else {
        copyNo[nv]=1;
      }
    }
    nv++;
    if (pNode->isModule()) break;
    pNode=pNode->getMotherNode();
  }
  chnmsv=new char[nv*5];
  nbitsv=new Int_t[nv];
  for(j=0,i=nv-1;j<nv;i--,j++) strcpy(&chnmsv[j*5],treeNames[i]);
  for(j=0,i=nv-1;j<nv;i--,j++) nbitsv[j]=int(log10((Double_t)copyNo[i])/log10(2.)+0.01)+1;
  if (nv>0) return kTRUE;
  return kFALSE;
}

Bool_t HGeomHit::calcRefPos(HGeomVector& refPos,TString& shape) {
  // Calculates the position in the module reference system
  shape=currentNode->getShape();
  return currentNode->calcRefPos(refPos);
}

void HGeomHit::setNh(Int_t n) {
  // Sets the number of components
  if (chnamh) delete [] chnamh;
  if (nbitsh) delete [] nbitsh;
  if (orig)   delete [] orig;
  if (fact)   delete [] fact;
  nh=n;
  if (n>0) {
    chnamh=new char[nh*5];
    nbitsh=new Int_t[nh];
    orig=new Float_t[nh];
    fact=new Float_t[nh];
  }
}

void HGeomHit::fill(Int_t i,const Char_t* cn,Int_t cb,Float_t co,Float_t cf) {
  // Sets the ith component 
  if (i<nh) {
    TString tmp=cn;
    tmp.Resize(4);
    strcpy(&chnamh[i*5],tmp.Data());
    nbitsh[i]=cb;
    orig[i]=co;
    fact[i]=cf;
  }
}
 hgeomhit.cc:1
 hgeomhit.cc:2
 hgeomhit.cc:3
 hgeomhit.cc:4
 hgeomhit.cc:5
 hgeomhit.cc:6
 hgeomhit.cc:7
 hgeomhit.cc:8
 hgeomhit.cc:9
 hgeomhit.cc:10
 hgeomhit.cc:11
 hgeomhit.cc:12
 hgeomhit.cc:13
 hgeomhit.cc:14
 hgeomhit.cc:15
 hgeomhit.cc:16
 hgeomhit.cc:17
 hgeomhit.cc:18
 hgeomhit.cc:19
 hgeomhit.cc:20
 hgeomhit.cc:21
 hgeomhit.cc:22
 hgeomhit.cc:23
 hgeomhit.cc:24
 hgeomhit.cc:25
 hgeomhit.cc:26
 hgeomhit.cc:27
 hgeomhit.cc:28
 hgeomhit.cc:29
 hgeomhit.cc:30
 hgeomhit.cc:31
 hgeomhit.cc:32
 hgeomhit.cc:33
 hgeomhit.cc:34
 hgeomhit.cc:35
 hgeomhit.cc:36
 hgeomhit.cc:37
 hgeomhit.cc:38
 hgeomhit.cc:39
 hgeomhit.cc:40
 hgeomhit.cc:41
 hgeomhit.cc:42
 hgeomhit.cc:43
 hgeomhit.cc:44
 hgeomhit.cc:45
 hgeomhit.cc:46
 hgeomhit.cc:47
 hgeomhit.cc:48
 hgeomhit.cc:49
 hgeomhit.cc:50
 hgeomhit.cc:51
 hgeomhit.cc:52
 hgeomhit.cc:53
 hgeomhit.cc:54
 hgeomhit.cc:55
 hgeomhit.cc:56
 hgeomhit.cc:57
 hgeomhit.cc:58
 hgeomhit.cc:59
 hgeomhit.cc:60
 hgeomhit.cc:61
 hgeomhit.cc:62
 hgeomhit.cc:63
 hgeomhit.cc:64
 hgeomhit.cc:65
 hgeomhit.cc:66
 hgeomhit.cc:67
 hgeomhit.cc:68
 hgeomhit.cc:69
 hgeomhit.cc:70
 hgeomhit.cc:71
 hgeomhit.cc:72
 hgeomhit.cc:73
 hgeomhit.cc:74
 hgeomhit.cc:75
 hgeomhit.cc:76
 hgeomhit.cc:77
 hgeomhit.cc:78
 hgeomhit.cc:79
 hgeomhit.cc:80
 hgeomhit.cc:81
 hgeomhit.cc:82
 hgeomhit.cc:83
 hgeomhit.cc:84
 hgeomhit.cc:85
 hgeomhit.cc:86
 hgeomhit.cc:87
 hgeomhit.cc:88
 hgeomhit.cc:89
 hgeomhit.cc:90
 hgeomhit.cc:91
 hgeomhit.cc:92
 hgeomhit.cc:93
 hgeomhit.cc:94
 hgeomhit.cc:95
 hgeomhit.cc:96
 hgeomhit.cc:97
 hgeomhit.cc:98
 hgeomhit.cc:99
 hgeomhit.cc:100
 hgeomhit.cc:101
 hgeomhit.cc:102
 hgeomhit.cc:103
 hgeomhit.cc:104
 hgeomhit.cc:105
 hgeomhit.cc:106
 hgeomhit.cc:107
 hgeomhit.cc:108
 hgeomhit.cc:109
 hgeomhit.cc:110
 hgeomhit.cc:111
 hgeomhit.cc:112
 hgeomhit.cc:113
 hgeomhit.cc:114
 hgeomhit.cc:115
 hgeomhit.cc:116
 hgeomhit.cc:117
 hgeomhit.cc:118
 hgeomhit.cc:119
 hgeomhit.cc:120
 hgeomhit.cc:121
 hgeomhit.cc:122
 hgeomhit.cc:123
 hgeomhit.cc:124
 hgeomhit.cc:125
 hgeomhit.cc:126
 hgeomhit.cc:127
 hgeomhit.cc:128
 hgeomhit.cc:129
 hgeomhit.cc:130
 hgeomhit.cc:131
 hgeomhit.cc:132
 hgeomhit.cc:133
 hgeomhit.cc:134
 hgeomhit.cc:135
 hgeomhit.cc:136
 hgeomhit.cc:137
 hgeomhit.cc:138
 hgeomhit.cc:139
 hgeomhit.cc:140
 hgeomhit.cc:141
 hgeomhit.cc:142
 hgeomhit.cc:143
 hgeomhit.cc:144
 hgeomhit.cc:145
 hgeomhit.cc:146
 hgeomhit.cc:147
 hgeomhit.cc:148
 hgeomhit.cc:149
 hgeomhit.cc:150
 hgeomhit.cc:151
 hgeomhit.cc:152
 hgeomhit.cc:153
 hgeomhit.cc:154
 hgeomhit.cc:155
 hgeomhit.cc:156
 hgeomhit.cc:157
 hgeomhit.cc:158
 hgeomhit.cc:159
 hgeomhit.cc:160
 hgeomhit.cc:161
 hgeomhit.cc:162
 hgeomhit.cc:163
 hgeomhit.cc:164
 hgeomhit.cc:165
 hgeomhit.cc:166
 hgeomhit.cc:167
 hgeomhit.cc:168
 hgeomhit.cc:169
 hgeomhit.cc:170
 hgeomhit.cc:171
 hgeomhit.cc:172
 hgeomhit.cc:173
 hgeomhit.cc:174
 hgeomhit.cc:175
 hgeomhit.cc:176
 hgeomhit.cc:177
 hgeomhit.cc:178
 hgeomhit.cc:179
 hgeomhit.cc:180
 hgeomhit.cc:181
 hgeomhit.cc:182
 hgeomhit.cc:183
 hgeomhit.cc:184
 hgeomhit.cc:185
 hgeomhit.cc:186
 hgeomhit.cc:187
 hgeomhit.cc:188
 hgeomhit.cc:189
 hgeomhit.cc:190
 hgeomhit.cc:191
 hgeomhit.cc:192
 hgeomhit.cc:193
 hgeomhit.cc:194
 hgeomhit.cc:195
 hgeomhit.cc:196
 hgeomhit.cc:197
 hgeomhit.cc:198
 hgeomhit.cc:199
 hgeomhit.cc:200
 hgeomhit.cc:201
 hgeomhit.cc:202
 hgeomhit.cc:203
 hgeomhit.cc:204
 hgeomhit.cc:205
 hgeomhit.cc:206
 hgeomhit.cc:207
 hgeomhit.cc:208
 hgeomhit.cc:209
 hgeomhit.cc:210
 hgeomhit.cc:211
 hgeomhit.cc:212
 hgeomhit.cc:213
 hgeomhit.cc:214
 hgeomhit.cc:215
 hgeomhit.cc:216
 hgeomhit.cc:217
 hgeomhit.cc:218
 hgeomhit.cc:219
 hgeomhit.cc:220
 hgeomhit.cc:221
 hgeomhit.cc:222
 hgeomhit.cc:223
 hgeomhit.cc:224
 hgeomhit.cc:225
 hgeomhit.cc:226
 hgeomhit.cc:227
 hgeomhit.cc:228
 hgeomhit.cc:229
 hgeomhit.cc:230
 hgeomhit.cc:231
 hgeomhit.cc:232
 hgeomhit.cc:233
 hgeomhit.cc:234
 hgeomhit.cc:235
 hgeomhit.cc:236
 hgeomhit.cc:237
 hgeomhit.cc:238
 hgeomhit.cc:239
 hgeomhit.cc:240
 hgeomhit.cc:241