ROOT logo
//#
//#
//#                      FRAMEWORK
//#
//#       Authors:                           W.Koenig
//#       adoption to framework & ROOT       W.Schoen
//#       new framework for different metods M.Jaskula
//#
//#       last mod. M.Jaskula Mon Aug 27 19:20:32 CEST 2001
// ###################################################
using namespace std;
#include "TH1.h"
#include "TH3.h"

#pragma implementation
#include "TROOT.h"
#include <iostream> 
#include <iomanip>
#include "hades.h"
#include "hpario.h"
#include "hdetpario.h"
#include "hlocation.h"
#include "hspectrometer.h"
#include "hshowercalpar.h"
#include "hshowerdetector.h"
#include "hshowerhist.h"
#include "hshowerhistcell.h"

//------------------------------------------------------------------------------

ClassImp(HShowerHist)

//------------------------------------------------------------------------------

////////// **********ShowerHist defintion ****************/////////////
HShowerHist::HShowerHist(const Char_t* name,const Char_t* title,
                                       const Char_t* context)
                   : HParSet(name,title,context) {
    strcpy(detName,"Shower");
    setSetup(6, 3, 32, 32); //default setup
    setCellClassName("HShowerHistCell");
}

//------------------------------------------------------------------------------

HShowerHist::~HShowerHist()
{
    m_ParamsTable.deleteTab();
}

//------------------------------------------------------------------------------

void HShowerHist::setSetup(Int_t nSectors, Int_t nModules,
                           Int_t  nRows, Int_t nColumns)
{
    m_nSectors = nSectors;
    m_nModules = nModules;
    m_nRows = nRows;
    m_nColumns = nColumns;
}

//------------------------------------------------------------------------------

void HShowerHist::setCellClassName(const Char_t* pszName)
{
    strncpy(m_szClassName, pszName, sizeof(m_szClassName));
}

//------------------------------------------------------------------------------

Char_t* HShowerHist::getCellClassName()
{
    return m_szClassName;
}

//------------------------------------------------------------------------------

HShowerHistCell* HShowerHist::getSlot(HLocation &loc)
{
HLocation l;

    l.setNIndex(2);
    l[0] = loc[0];
    l[1] = loc[1];

    return (HShowerHistCell*) m_ParamsTable.getSlot(loc);
}

//------------------------------------------------------------------------------

HShowerHistCell* HShowerHist::getObject(HLocation &loc)
{
HLocation l;

    l.setNIndex(2);
    l[0] = loc[0];
    l[1] = loc[1];

    return (HShowerHistCell*) m_ParamsTable.getObject(l);
}

//------------------------------------------------------------------------------

Bool_t HShowerHist::init(HParIo* inp,Int_t* set) {
  // intitializes the container from an input
  HDetParIo* input=inp->getDetParIo("HShowerParIo");
  if (input) return (input->init(this,set));
  return kFALSE;
}

//------------------------------------------------------------------------------

Int_t HShowerHist::write(HParIo* output) {
  // writes the shower container to the output
  HDetParIo* out=output->getDetParIo("HShowerParIo");
  if (out) return out->write(this);
  return kFALSE;
}

//------------------------------------------------------------------------------

Bool_t HShowerHist::defaultInit()
{
Int_t              ret = kFALSE;
HShowerDetector *pShowerDet;

    if(gHades)
    {
        pShowerDet = (HShowerDetector*)gHades->getSetup()
                                              ->getDetector("Shower");

        if(pShowerDet)
        {
            m_nSectors = pShowerDet->getShowerSectors();
            m_nModules = pShowerDet->getShowerModules();
            m_nRows    = pShowerDet->getRows();
            m_nColumns = pShowerDet->getColumns();
            ret        = kTRUE;
        }
    }

    setSetup(m_nSectors, m_nModules, m_nRows, m_nColumns);

    printf("%d - %d - %d - %d\n", m_nSectors, m_nModules, m_nRows, m_nColumns);
    allocateHist();

    return ret;
}

//------------------------------------------------------------------------------

void HShowerHist::allocateHist()
{
Int_t              sect, mod;
HShowerHistCell *pHistCell;
HLocation        loc;

    loc.setNIndex(2);

    m_ParamsTable.set(2, m_nSectors, m_nModules);

    m_ParamsTable.setCellClassName(getCellClassName());
    m_ParamsTable.makeObjTable();

    for(sect = 0; sect < m_nSectors; sect++)
        for(mod = 0; mod < m_nModules; mod++)
        {
            loc[0] = sect;
            loc[1] = mod;
            pHistCell = (HShowerHistCell*) getSlot(loc);
            if (pHistCell)
            {
                pHistCell = new(pHistCell) HShowerHistCell(sect, mod,
                                                       m_nRows, m_nColumns);
                pHistCell->book();
            }
        }

    setStatic();
}

//------------------------------------------------------------------------------

void HShowerHist::bookAll()
{
HLocation loc;

    loc.setNIndex(2);
    for(loc[0] = 0; loc[0] < m_nSectors; loc[0]++)
        for(loc[1] = 0; loc[1] < m_nModules; loc[1]++)
            book(loc);
}

//------------------------------------------------------------------------------

void HShowerHist::book(HLocation& loc)
{
HShowerHistCell *pHistCell;
HLocation        l;

    l.setNIndex(2);
    l[0] = loc[0];
    l[1] = loc[1];

    pHistCell = getObject(l);
    if (pHistCell)
        pHistCell->book();
}

//------------------------------------------------------------------------------

void HShowerHist::book(Int_t nSector, Int_t nModule)
{
HLocation loc;

    loc.setNIndex(2);
    loc[0] = nSector;
    loc[1] = nModule;

    book(loc);
}

//------------------------------------------------------------------------------

void HShowerHist::resetAll()
{
HLocation loc;

    loc.setNIndex(2);
    for(loc[0] = 0; loc[0] < m_nSectors; loc[0]++)
        for(loc[1] = 0; loc[1] < m_nModules; loc[1]++)
            reset(loc);
}

//------------------------------------------------------------------------------

void HShowerHist::reset(HLocation& loc)
{
HShowerHistCell *pHistCell;
HLocation        l;

    l.setNIndex(2);
    l[0] = loc[0];
    l[1] = loc[1];

    pHistCell = getObject(l);
    if (pHistCell)
        pHistCell->reset();
}

//------------------------------------------------------------------------------

void HShowerHist::reset(Int_t nSector, Int_t nModule)
{
HLocation loc;

    loc.setNIndex(2);
    loc[0] = nSector;
    loc[1] = nModule;

    reset(loc);
}

//------------------------------------------------------------------------------

void HShowerHist::fill(HLocation& loc, Int_t nVal)
{
HShowerHistCell *pHistCell;
Int_t            nRow = loc[2];
Int_t            nCol = loc[3];

    pHistCell = getObject(loc);
    if (pHistCell)
        pHistCell->fill(nRow, nCol, nVal);
}

//------------------------------------------------------------------------------

void HShowerHist::fill(Int_t nSector, Int_t nModule,
                                 Int_t nRow, Int_t nCol, Int_t nVal)
{
HLocation loc;

    loc.setNIndex(4);
    loc[0] = nSector;
    loc[1] = nModule;
    loc[2] = nRow;
    loc[3] = nCol;

    fill(loc, nVal);
}

//------------------------------------------------------------------------------

void HShowerHist::draw(HLocation& loc, Option_t *opt)
{
HShowerHistCell *pHistCell;
Int_t            nRow = loc[2];
Int_t            nCol = loc[3];

    pHistCell = getObject(loc);
    if (pHistCell)
        pHistCell->draw(nRow, nCol, opt);
}

//------------------------------------------------------------------------------

void HShowerHist::draw(Int_t nSector, Int_t nModule,
                                    Int_t nRow, Int_t nCol, Option_t* opt )
{
HLocation loc;

    loc.setNIndex(4);
    loc[0] = nSector;
    loc[1] = nModule;
    loc[2] = nRow;
    loc[3] = nCol;

    draw(loc, opt);
}

//------------------------------------------------------------------------------

Int_t HShowerHist::Write(const Text_t* name, Int_t option, Int_t bufsize)
{
    HParSet::Write(name, option, bufsize);

HLocation loc;

    loc.setNIndex(2);
    for(loc[0] = 0; loc[0] < m_nSectors; loc[0]++)
        for(loc[1] = 0; loc[1] < m_nModules; loc[1]++)
            ((HShowerHistCell*)getObject(loc))->writeHistogram();

    return 0;
}

//------------------------------------------------------------------------------

void HShowerHist::calculate(Int_t iEvents, HShowerCalPar* pCalPar,
                            Int_t iMethod, Float_t fParam1, Float_t fParam2)
{
HLocation        loc;
HShowerHistCell *pHistCell;

    printf("\ncalculating calibration parameters ...\n");

    loc.setNIndex(4);

    for(loc[0] = 0; loc[0] < m_nSectors; loc[0]++)
    {
        for(loc[1] = 0; loc[1] < m_nModules; loc[1]++)
        {
            if((pHistCell = getObject(loc)) == NULL)
                continue;

            pHistCell->calculate(iEvents, pCalPar, iMethod, fParam1, fParam2);
        }
    }
}
 hshowerhist.cc:1
 hshowerhist.cc:2
 hshowerhist.cc:3
 hshowerhist.cc:4
 hshowerhist.cc:5
 hshowerhist.cc:6
 hshowerhist.cc:7
 hshowerhist.cc:8
 hshowerhist.cc:9
 hshowerhist.cc:10
 hshowerhist.cc:11
 hshowerhist.cc:12
 hshowerhist.cc:13
 hshowerhist.cc:14
 hshowerhist.cc:15
 hshowerhist.cc:16
 hshowerhist.cc:17
 hshowerhist.cc:18
 hshowerhist.cc:19
 hshowerhist.cc:20
 hshowerhist.cc:21
 hshowerhist.cc:22
 hshowerhist.cc:23
 hshowerhist.cc:24
 hshowerhist.cc:25
 hshowerhist.cc:26
 hshowerhist.cc:27
 hshowerhist.cc:28
 hshowerhist.cc:29
 hshowerhist.cc:30
 hshowerhist.cc:31
 hshowerhist.cc:32
 hshowerhist.cc:33
 hshowerhist.cc:34
 hshowerhist.cc:35
 hshowerhist.cc:36
 hshowerhist.cc:37
 hshowerhist.cc:38
 hshowerhist.cc:39
 hshowerhist.cc:40
 hshowerhist.cc:41
 hshowerhist.cc:42
 hshowerhist.cc:43
 hshowerhist.cc:44
 hshowerhist.cc:45
 hshowerhist.cc:46
 hshowerhist.cc:47
 hshowerhist.cc:48
 hshowerhist.cc:49
 hshowerhist.cc:50
 hshowerhist.cc:51
 hshowerhist.cc:52
 hshowerhist.cc:53
 hshowerhist.cc:54
 hshowerhist.cc:55
 hshowerhist.cc:56
 hshowerhist.cc:57
 hshowerhist.cc:58
 hshowerhist.cc:59
 hshowerhist.cc:60
 hshowerhist.cc:61
 hshowerhist.cc:62
 hshowerhist.cc:63
 hshowerhist.cc:64
 hshowerhist.cc:65
 hshowerhist.cc:66
 hshowerhist.cc:67
 hshowerhist.cc:68
 hshowerhist.cc:69
 hshowerhist.cc:70
 hshowerhist.cc:71
 hshowerhist.cc:72
 hshowerhist.cc:73
 hshowerhist.cc:74
 hshowerhist.cc:75
 hshowerhist.cc:76
 hshowerhist.cc:77
 hshowerhist.cc:78
 hshowerhist.cc:79
 hshowerhist.cc:80
 hshowerhist.cc:81
 hshowerhist.cc:82
 hshowerhist.cc:83
 hshowerhist.cc:84
 hshowerhist.cc:85
 hshowerhist.cc:86
 hshowerhist.cc:87
 hshowerhist.cc:88
 hshowerhist.cc:89
 hshowerhist.cc:90
 hshowerhist.cc:91
 hshowerhist.cc:92
 hshowerhist.cc:93
 hshowerhist.cc:94
 hshowerhist.cc:95
 hshowerhist.cc:96
 hshowerhist.cc:97
 hshowerhist.cc:98
 hshowerhist.cc:99
 hshowerhist.cc:100
 hshowerhist.cc:101
 hshowerhist.cc:102
 hshowerhist.cc:103
 hshowerhist.cc:104
 hshowerhist.cc:105
 hshowerhist.cc:106
 hshowerhist.cc:107
 hshowerhist.cc:108
 hshowerhist.cc:109
 hshowerhist.cc:110
 hshowerhist.cc:111
 hshowerhist.cc:112
 hshowerhist.cc:113
 hshowerhist.cc:114
 hshowerhist.cc:115
 hshowerhist.cc:116
 hshowerhist.cc:117
 hshowerhist.cc:118
 hshowerhist.cc:119
 hshowerhist.cc:120
 hshowerhist.cc:121
 hshowerhist.cc:122
 hshowerhist.cc:123
 hshowerhist.cc:124
 hshowerhist.cc:125
 hshowerhist.cc:126
 hshowerhist.cc:127
 hshowerhist.cc:128
 hshowerhist.cc:129
 hshowerhist.cc:130
 hshowerhist.cc:131
 hshowerhist.cc:132
 hshowerhist.cc:133
 hshowerhist.cc:134
 hshowerhist.cc:135
 hshowerhist.cc:136
 hshowerhist.cc:137
 hshowerhist.cc:138
 hshowerhist.cc:139
 hshowerhist.cc:140
 hshowerhist.cc:141
 hshowerhist.cc:142
 hshowerhist.cc:143
 hshowerhist.cc:144
 hshowerhist.cc:145
 hshowerhist.cc:146
 hshowerhist.cc:147
 hshowerhist.cc:148
 hshowerhist.cc:149
 hshowerhist.cc:150
 hshowerhist.cc:151
 hshowerhist.cc:152
 hshowerhist.cc:153
 hshowerhist.cc:154
 hshowerhist.cc:155
 hshowerhist.cc:156
 hshowerhist.cc:157
 hshowerhist.cc:158
 hshowerhist.cc:159
 hshowerhist.cc:160
 hshowerhist.cc:161
 hshowerhist.cc:162
 hshowerhist.cc:163
 hshowerhist.cc:164
 hshowerhist.cc:165
 hshowerhist.cc:166
 hshowerhist.cc:167
 hshowerhist.cc:168
 hshowerhist.cc:169
 hshowerhist.cc:170
 hshowerhist.cc:171
 hshowerhist.cc:172
 hshowerhist.cc:173
 hshowerhist.cc:174
 hshowerhist.cc:175
 hshowerhist.cc:176
 hshowerhist.cc:177
 hshowerhist.cc:178
 hshowerhist.cc:179
 hshowerhist.cc:180
 hshowerhist.cc:181
 hshowerhist.cc:182
 hshowerhist.cc:183
 hshowerhist.cc:184
 hshowerhist.cc:185
 hshowerhist.cc:186
 hshowerhist.cc:187
 hshowerhist.cc:188
 hshowerhist.cc:189
 hshowerhist.cc:190
 hshowerhist.cc:191
 hshowerhist.cc:192
 hshowerhist.cc:193
 hshowerhist.cc:194
 hshowerhist.cc:195
 hshowerhist.cc:196
 hshowerhist.cc:197
 hshowerhist.cc:198
 hshowerhist.cc:199
 hshowerhist.cc:200
 hshowerhist.cc:201
 hshowerhist.cc:202
 hshowerhist.cc:203
 hshowerhist.cc:204
 hshowerhist.cc:205
 hshowerhist.cc:206
 hshowerhist.cc:207
 hshowerhist.cc:208
 hshowerhist.cc:209
 hshowerhist.cc:210
 hshowerhist.cc:211
 hshowerhist.cc:212
 hshowerhist.cc:213
 hshowerhist.cc:214
 hshowerhist.cc:215
 hshowerhist.cc:216
 hshowerhist.cc:217
 hshowerhist.cc:218
 hshowerhist.cc:219
 hshowerhist.cc:220
 hshowerhist.cc:221
 hshowerhist.cc:222
 hshowerhist.cc:223
 hshowerhist.cc:224
 hshowerhist.cc:225
 hshowerhist.cc:226
 hshowerhist.cc:227
 hshowerhist.cc:228
 hshowerhist.cc:229
 hshowerhist.cc:230
 hshowerhist.cc:231
 hshowerhist.cc:232
 hshowerhist.cc:233
 hshowerhist.cc:234
 hshowerhist.cc:235
 hshowerhist.cc:236
 hshowerhist.cc:237
 hshowerhist.cc:238
 hshowerhist.cc:239
 hshowerhist.cc:240
 hshowerhist.cc:241
 hshowerhist.cc:242
 hshowerhist.cc:243
 hshowerhist.cc:244
 hshowerhist.cc:245
 hshowerhist.cc:246
 hshowerhist.cc:247
 hshowerhist.cc:248
 hshowerhist.cc:249
 hshowerhist.cc:250
 hshowerhist.cc:251
 hshowerhist.cc:252
 hshowerhist.cc:253
 hshowerhist.cc:254
 hshowerhist.cc:255
 hshowerhist.cc:256
 hshowerhist.cc:257
 hshowerhist.cc:258
 hshowerhist.cc:259
 hshowerhist.cc:260
 hshowerhist.cc:261
 hshowerhist.cc:262
 hshowerhist.cc:263
 hshowerhist.cc:264
 hshowerhist.cc:265
 hshowerhist.cc:266
 hshowerhist.cc:267
 hshowerhist.cc:268
 hshowerhist.cc:269
 hshowerhist.cc:270
 hshowerhist.cc:271
 hshowerhist.cc:272
 hshowerhist.cc:273
 hshowerhist.cc:274
 hshowerhist.cc:275
 hshowerhist.cc:276
 hshowerhist.cc:277
 hshowerhist.cc:278
 hshowerhist.cc:279
 hshowerhist.cc:280
 hshowerhist.cc:281
 hshowerhist.cc:282
 hshowerhist.cc:283
 hshowerhist.cc:284
 hshowerhist.cc:285
 hshowerhist.cc:286
 hshowerhist.cc:287
 hshowerhist.cc:288
 hshowerhist.cc:289
 hshowerhist.cc:290
 hshowerhist.cc:291
 hshowerhist.cc:292
 hshowerhist.cc:293
 hshowerhist.cc:294
 hshowerhist.cc:295
 hshowerhist.cc:296
 hshowerhist.cc:297
 hshowerhist.cc:298
 hshowerhist.cc:299
 hshowerhist.cc:300
 hshowerhist.cc:301
 hshowerhist.cc:302
 hshowerhist.cc:303
 hshowerhist.cc:304
 hshowerhist.cc:305
 hshowerhist.cc:306
 hshowerhist.cc:307
 hshowerhist.cc:308
 hshowerhist.cc:309
 hshowerhist.cc:310
 hshowerhist.cc:311
 hshowerhist.cc:312
 hshowerhist.cc:313
 hshowerhist.cc:314
 hshowerhist.cc:315
 hshowerhist.cc:316
 hshowerhist.cc:317
 hshowerhist.cc:318
 hshowerhist.cc:319
 hshowerhist.cc:320
 hshowerhist.cc:321
 hshowerhist.cc:322
 hshowerhist.cc:323
 hshowerhist.cc:324
 hshowerhist.cc:325
 hshowerhist.cc:326
 hshowerhist.cc:327
 hshowerhist.cc:328
 hshowerhist.cc:329
 hshowerhist.cc:330
 hshowerhist.cc:331
 hshowerhist.cc:332
 hshowerhist.cc:333
 hshowerhist.cc:334
 hshowerhist.cc:335
 hshowerhist.cc:336
 hshowerhist.cc:337
 hshowerhist.cc:338
 hshowerhist.cc:339
 hshowerhist.cc:340
 hshowerhist.cc:341
 hshowerhist.cc:342
 hshowerhist.cc:343
 hshowerhist.cc:344
 hshowerhist.cc:345
 hshowerhist.cc:346
 hshowerhist.cc:347
 hshowerhist.cc:348
 hshowerhist.cc:349
 hshowerhist.cc:350
 hshowerhist.cc:351
 hshowerhist.cc:352
 hshowerhist.cc:353
 hshowerhist.cc:354
 hshowerhist.cc:355
 hshowerhist.cc:356
 hshowerhist.cc:357
 hshowerhist.cc:358
 hshowerhist.cc:359
 hshowerhist.cc:360