ROOT logo
//*-- AUTHOR :  Kirill Lapidus
//*-- Created :
//*-- modified : 20/02/2017 by Vladimir Pechenov

//_HADES_CLASS_DESCRIPTION
/////////////////////////////////////////////////////////////
//
//  HEmcDetector
//
//  The Emc detector class
//
/////////////////////////////////////////////////////////////

using namespace std;
#include "hemcdetector.h"
#include "emcdef.h"
#include "hcategory.h"
#include "hlinearcategory.h"
#include "hmatrixcategory.h"
#include "hgeantmaxtrk.h"
#include "hades.h"
#include "hevent.h"
#include "hpario.h"
#include "hparrootfileio.h"
#include "hparasciifileio.h"
#include "hdetpario.h"
#include "hemcparrootfileio.h"
#include "hemcparasciifileio.h"
#include "TClass.h"
#include <iostream> 
#include <iomanip>

ClassImp(HEmcDetector) // Emc detector class

const Int_t HEmcDetector::cellMap[163] = {  // 17 x 15
                                    6,   7,   8,   9,  10,
                                   23,  24,  25,  26,  27,
                              39,  40,  41,  42,  43,  44,  45,
                              56,  57,  58,  59,  60,  61,  62,
                         72,  73,  74,  75,  76,  77,  78,  79,  80,
                         89,  90,  91,  92,  93,  94,  95,  96,  97,
                        106, 107, 108, 109, 110, 111, 112, 113, 114,
                   122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
                   139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
              155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
              172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
         188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
         205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
    221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
    238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254
};

Int_t HEmcDetector::posMap[255] = {0}; // need to initialize it for sake of the linker JAM

HEmcDetector::HEmcDetector(void) : HDetector("Emc","The Emc detector") {
  // constructor
  fName="Emc";
  maxSectors=6;
  maxModules=1;
  maxComponents=emcMaxRows*emcMaxColumns; // including spares (needed for parameter containers)
  numCells=163;
  modules = new TArrayI(getMaxSectors());

  for (Int_t i = 0; i < 255; ++i)
    posMap[i] = -1; 
  for (Int_t i = 0; i < 163; ++i)
    posMap[cellMap[i]] = i;
}

HEmcDetector::~HEmcDetector(void) {
  delete modules;
  modules = 0;
}

HCategory* HEmcDetector::buildLinearCategory(const Text_t *classname, Float_t fillRate) {
  HLinearCategory* category=new HLinearCategory(classname,(Int_t)(numCells*fillRate));
  return category;
}

HCategory *HEmcDetector::buildMatrixCategory(const Text_t* classname, Float_t fillRate) {
  //making the categories for different types of data levels
  HMatrixCategory* category = NULL;
  Int_t* sizes2  = new Int_t[2];

  if (strcmp(classname,"HGeantEmc")==0) {
    sizes2[0]= getMaxSectors();
    sizes2[1]= MAXTRKEMC;
    category = new HMatrixCategory(classname,2,sizes2,fillRate);   
  } else if (strcmp(classname,"HEmcRaw")==0) {
     sizes2[0]=getMaxSectors();
     sizes2[1]=emcMaxRows*emcMaxColumns;
     category = new HMatrixCategory(classname,2,sizes2,fillRate);
  } else if (strcmp(classname,"HEmcCal")==0 || strcmp(classname,"HEmcCalSim")==0) {
    sizes2[0]=getMaxSectors();
    sizes2[1]=emcMaxRows*emcMaxColumns;
    category = new HMatrixCategory(classname,2,sizes2,fillRate);
  } else if (strcmp(classname,"HEmcCluster")==0 || strcmp(classname,"HEmcClusterSim")==0) {
    sizes2[0]=getMaxSectors();
    sizes2[1]=emcMaxRows*emcMaxColumns;
    category = new HMatrixCategory(classname,2,sizes2,fillRate);
  } else {
    sizes2[0]=getMaxSectors();
    sizes2[1]=maxComponents;
    category = new HMatrixCategory(classname,2,sizes2,fillRate);
  }
  delete [] sizes2;
  return category;
}

HCategory *HEmcDetector::buildCategory(Cat_t cat) {
  // builds the categories for the Emc
  // gets the category if existing
  // builts and adds if not existing
  // returns the pointer to the category or zero
  HCategory *pcat = gHades->getCurrentEvent()->getCategory(cat);
  if (pcat) return (pcat);  // already existing
  switch (cat) {
    case catEmcRaw :
      pcat = buildMatrixCategory("HEmcRaw",0.5);
      break;
    case catEmcCal :
      pcat = buildMatrixCategory("HEmcCal",0.5);
      break;
    case catEmcCalQA :
      pcat = buildMatrixCategory("HEmcCalQA",0.5);
      break;
    case catEmcCluster :
//      pcat = buildLinearCategory("HEmcCluster",0.5);
      pcat = buildMatrixCategory("HEmcCluster",0.5);
      break;
    default :
      pcat = NULL;
  }
  if (pcat) gHades->getCurrentEvent()->addCategory(cat, pcat, "Emc");
  return (pcat);
}

void HEmcDetector::activateParIo(HParIo* io) {
  // activates the input/output class for the Emc parameters
  if (strcmp(io->IsA()->GetName(),"HParOraIo")==0) {
    io->setDetParIo("HEmcParIo");
    return;
  }
  if (strcmp(io->IsA()->GetName(),"HParRootFileIo")==0) {
    HEmcParRootFileIo* p=new HEmcParRootFileIo(((HParRootFileIo*)io)->getParRootFile());
    io->setDetParIo(p);
  }
  if (strcmp(io->IsA()->GetName(),"HParAsciiFileIo")==0) {
    HEmcParAsciiFileIo* p=new HEmcParAsciiFileIo(((HParAsciiFileIo*)io)->getFile());
    io->setDetParIo(p);
  }
}

Bool_t HEmcDetector::write(HParIo* output) {
  // writes the Emc setup to output
  HDetParIo* out=output->getDetParIo("HEmcParIo");
  if (out) return out->write(this);
  return kFALSE;
}

Int_t HEmcDetector::getCell(const Char_t row, const Char_t col) {
  // returns the cell index
  if (row<0 || row>=emcMaxRows || col<0 || col>=emcMaxColumns) return -1;
  else return row*emcMaxColumns + col;
}

void HEmcDetector::getRowCol(const Int_t cell, Char_t& row, Char_t& col) {
  // returns the row and column indexes
  if (cell>=0 && cell<emcMaxComponents) {
    row=(Char_t)(cell/emcMaxColumns);
    col=(Char_t)(cell%emcMaxColumns);
  } else row=col=-1;
} 

Int_t HEmcDetector::getMaxSecInSetup(void) {
  // returns the maximum number of modules in the actual setup
  Int_t maxSec = -1;
  for (Int_t i = 0; i < maxSectors; i++) {
    if (modules->At(i)) maxSec = (i > maxSec) ? i : maxSec;
  }
  maxSec++;
  return maxSec;
}

Int_t HEmcDetector::getCellFromPosition(Int_t pos)
{
  if (pos >= 0 && pos < 163)
    return cellMap[pos];
  return -1;
}

Int_t HEmcDetector::getPositionFromCell(Int_t cell)
{
  if (cell >= 0 && cell < 255)
    return posMap[cell];
  return -1;
}
 hemcdetector.cc:1
 hemcdetector.cc:2
 hemcdetector.cc:3
 hemcdetector.cc:4
 hemcdetector.cc:5
 hemcdetector.cc:6
 hemcdetector.cc:7
 hemcdetector.cc:8
 hemcdetector.cc:9
 hemcdetector.cc:10
 hemcdetector.cc:11
 hemcdetector.cc:12
 hemcdetector.cc:13
 hemcdetector.cc:14
 hemcdetector.cc:15
 hemcdetector.cc:16
 hemcdetector.cc:17
 hemcdetector.cc:18
 hemcdetector.cc:19
 hemcdetector.cc:20
 hemcdetector.cc:21
 hemcdetector.cc:22
 hemcdetector.cc:23
 hemcdetector.cc:24
 hemcdetector.cc:25
 hemcdetector.cc:26
 hemcdetector.cc:27
 hemcdetector.cc:28
 hemcdetector.cc:29
 hemcdetector.cc:30
 hemcdetector.cc:31
 hemcdetector.cc:32
 hemcdetector.cc:33
 hemcdetector.cc:34
 hemcdetector.cc:35
 hemcdetector.cc:36
 hemcdetector.cc:37
 hemcdetector.cc:38
 hemcdetector.cc:39
 hemcdetector.cc:40
 hemcdetector.cc:41
 hemcdetector.cc:42
 hemcdetector.cc:43
 hemcdetector.cc:44
 hemcdetector.cc:45
 hemcdetector.cc:46
 hemcdetector.cc:47
 hemcdetector.cc:48
 hemcdetector.cc:49
 hemcdetector.cc:50
 hemcdetector.cc:51
 hemcdetector.cc:52
 hemcdetector.cc:53
 hemcdetector.cc:54
 hemcdetector.cc:55
 hemcdetector.cc:56
 hemcdetector.cc:57
 hemcdetector.cc:58
 hemcdetector.cc:59
 hemcdetector.cc:60
 hemcdetector.cc:61
 hemcdetector.cc:62
 hemcdetector.cc:63
 hemcdetector.cc:64
 hemcdetector.cc:65
 hemcdetector.cc:66
 hemcdetector.cc:67
 hemcdetector.cc:68
 hemcdetector.cc:69
 hemcdetector.cc:70
 hemcdetector.cc:71
 hemcdetector.cc:72
 hemcdetector.cc:73
 hemcdetector.cc:74
 hemcdetector.cc:75
 hemcdetector.cc:76
 hemcdetector.cc:77
 hemcdetector.cc:78
 hemcdetector.cc:79
 hemcdetector.cc:80
 hemcdetector.cc:81
 hemcdetector.cc:82
 hemcdetector.cc:83
 hemcdetector.cc:84
 hemcdetector.cc:85
 hemcdetector.cc:86
 hemcdetector.cc:87
 hemcdetector.cc:88
 hemcdetector.cc:89
 hemcdetector.cc:90
 hemcdetector.cc:91
 hemcdetector.cc:92
 hemcdetector.cc:93
 hemcdetector.cc:94
 hemcdetector.cc:95
 hemcdetector.cc:96
 hemcdetector.cc:97
 hemcdetector.cc:98
 hemcdetector.cc:99
 hemcdetector.cc:100
 hemcdetector.cc:101
 hemcdetector.cc:102
 hemcdetector.cc:103
 hemcdetector.cc:104
 hemcdetector.cc:105
 hemcdetector.cc:106
 hemcdetector.cc:107
 hemcdetector.cc:108
 hemcdetector.cc:109
 hemcdetector.cc:110
 hemcdetector.cc:111
 hemcdetector.cc:112
 hemcdetector.cc:113
 hemcdetector.cc:114
 hemcdetector.cc:115
 hemcdetector.cc:116
 hemcdetector.cc:117
 hemcdetector.cc:118
 hemcdetector.cc:119
 hemcdetector.cc:120
 hemcdetector.cc:121
 hemcdetector.cc:122
 hemcdetector.cc:123
 hemcdetector.cc:124
 hemcdetector.cc:125
 hemcdetector.cc:126
 hemcdetector.cc:127
 hemcdetector.cc:128
 hemcdetector.cc:129
 hemcdetector.cc:130
 hemcdetector.cc:131
 hemcdetector.cc:132
 hemcdetector.cc:133
 hemcdetector.cc:134
 hemcdetector.cc:135
 hemcdetector.cc:136
 hemcdetector.cc:137
 hemcdetector.cc:138
 hemcdetector.cc:139
 hemcdetector.cc:140
 hemcdetector.cc:141
 hemcdetector.cc:142
 hemcdetector.cc:143
 hemcdetector.cc:144
 hemcdetector.cc:145
 hemcdetector.cc:146
 hemcdetector.cc:147
 hemcdetector.cc:148
 hemcdetector.cc:149
 hemcdetector.cc:150
 hemcdetector.cc:151
 hemcdetector.cc:152
 hemcdetector.cc:153
 hemcdetector.cc:154
 hemcdetector.cc:155
 hemcdetector.cc:156
 hemcdetector.cc:157
 hemcdetector.cc:158
 hemcdetector.cc:159
 hemcdetector.cc:160
 hemcdetector.cc:161
 hemcdetector.cc:162
 hemcdetector.cc:163
 hemcdetector.cc:164
 hemcdetector.cc:165
 hemcdetector.cc:166
 hemcdetector.cc:167
 hemcdetector.cc:168
 hemcdetector.cc:169
 hemcdetector.cc:170
 hemcdetector.cc:171
 hemcdetector.cc:172
 hemcdetector.cc:173
 hemcdetector.cc:174
 hemcdetector.cc:175
 hemcdetector.cc:176
 hemcdetector.cc:177
 hemcdetector.cc:178
 hemcdetector.cc:179
 hemcdetector.cc:180
 hemcdetector.cc:181
 hemcdetector.cc:182
 hemcdetector.cc:183
 hemcdetector.cc:184
 hemcdetector.cc:185
 hemcdetector.cc:186
 hemcdetector.cc:187
 hemcdetector.cc:188
 hemcdetector.cc:189
 hemcdetector.cc:190
 hemcdetector.cc:191
 hemcdetector.cc:192
 hemcdetector.cc:193
 hemcdetector.cc:194
 hemcdetector.cc:195
 hemcdetector.cc:196
 hemcdetector.cc:197