ROOT logo
using namespace std;
#include "TRandom.h"
#include <time.h>
#include <iostream>
#include <iomanip>
#include "hwallhitf.h" //FK//
#include "walldef.h"   //FK//
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hwalldetector.h" //FK//
#include "hwallraw.h"   //FK//
#include "hevent.h"
#include "hpartialevent.h"
#include "hcategory.h"
#include "hmatrixcategory.h"
#include "hrecevent.h"
#include "hlocation.h"
#include "hwallcalpar.h" //FK//
#include "hwallhit.h"   //FK//
#include "hwallonehit.h"   //FK//
#include "hwallonehitf.h"   //FK//
#include "hstartdef.h"
#include "hstart2hit.h"
#include "hwallgeompar.h"        //FK//
#include "hdetgeompar.h"         //FK//
#include "hgeomvector.h"         //FK//
#include "hspecgeompar.h"        //FK//
#include "hgeomvolume.h"           //FK//
#include "hgeomcompositevolume.h"  //FK//
#include "hgeomtransform.h"        //FK//

//*-- Created : 24/06/2000 by M.Golubeva
//*-- Modified : 27/04/2001 by T.Wojcik
//*-- Modified: 11/8/2005 by F. Krizek
// Modified by M.Golubeva 01.11.2006
// Modified by A.Sadovsky 02.12.2007

//_HADES_CLASS_DESCRIPTION
/////////////////////////////////////////////////////////////////////
//
//  HWallHitf calibrates raw Wall data and puts output
//  values into cal data category
//
/////////////////////////////////////////////////////////////////////

void HWallHitF::initParContainer() {

    pWallGeometry = (HWallGeomPar *)gHades->getRuntimeDb()->getContainer("WallGeomPar");
    pSpecGeometry = (HSpecGeomPar *)gHades->getRuntimeDb()->getContainer("SpecGeomPar");
}

HWallHitF::HWallHitF(void) {

    fHitCat       = NULL;
    fRawCat       = NULL;
    fOneHitCat    = NULL;
    fStartHitCat  = NULL;
    pWallGeometry = NULL;
    fLoc.set(1,-1);
    iter          = NULL;

}

HWallHitF::HWallHitF(const Text_t *name,const Text_t *title) :
HReconstructor(name,title) {

    fHitCat       = NULL;
    fRawCat       = NULL;
    fOneHitCat    = NULL;
    fStartHitCat  = NULL;
    pWallGeometry = NULL;
    pSpecGeometry = NULL;
    fLoc.set(1,-1);
    iter          = NULL;
}

HWallHitF::~HWallHitF(){
    if(iter){
	delete iter;
	iter = NULL;
    }
}

void HWallHitF::fillHit(HWallHit *hit, HWallOneHit *onehit)
{

}

Bool_t HWallHitF::init(void)
{

    initParContainer();

    fOneHitCat=gHades->getCurrentEvent()->getCategory(catWallOneHit);
    if (!fOneHitCat) return kFALSE;

    fHitCat = gHades->getCurrentEvent()->getCategory(catWallHit);
    if (!fHitCat) {
	fHitCat = gHades->getSetup()->getDetector("Wall")
	    ->buildCategory(catWallHit);

	if (!fHitCat)
	    return kFALSE;
	else
	    gHades->getCurrentEvent()->addCategory(catWallHit,fHitCat,"Wall");
    }

    //-- Try Start Hit Category, if exists, use the start time --//
    //-- if it does not exist assume that start time iz zero ----//

    fStartHitCat = gHades->getCurrentEvent()->getCategory(catStart2Hit);
    if (!fStartHitCat){
	Warning("init","Start Hit level not defined: setting start time to 0");
	fStartHitCat = 0;
    }

    iter = (HIterator *)fOneHitCat->MakeIterator("native");

    return kTRUE;
}

void HWallHitF::fillGeometry(HWallHit *hit)
{
    // Fills in the LAB position parameters for the given HTofHit.
    //
    // This is done by transforming the point (x,0,0) in the ROD coordinate
    // system to the LAB coordinate system. Where x is the reconstructed
    // x position inside the hit.

    HGeomVector rLocal,r;
    Float_t d,phi,theta,xx,yy,zz;
    Float_t rad2deg = 180./TMath::Pi();

    HModGeomPar *module       = pWallGeometry->getModule(0);
    HGeomTransform &trans     = module->getLabTransform();
    HGeomVolume *cellVol      = module->getRefVolume()->getComponent(hit->getCell());
    HGeomTransform &cellTrans = cellVol->getTransform();

    // Fill r with the hit coordinates in the cell coordinate system
    // Since we do not have information about x,y,z coordinates of impact
    //  hi occures in centre thus z=0, x=0 and y=0.
    //  Note that (0,0,0) corresponds to the rod center.

    r.setX(0.);
    r.setY(0.);
    r.setZ(0.);

    rLocal = cellTrans.transFrom(r);  // transform to module coordinate system
    r      = trans.transFrom(rLocal); // transform from module to LAB system

    HGeomVolume *tv = pSpecGeometry->getTarget(0);
    if (tv) r      -= tv->getTransform().getTransVector();   // correct for target position

    // Fill output
    d = r.length();
    theta = (d>0.) ? (rad2deg * TMath::ACos(r.getZ() / d)) : 0.;
    phi   = rad2deg * TMath::ATan2( r.getY(), r.getX());
    if (phi < 0.) phi += 360.;
    if (tv)         r += tv->getTransform().getTransVector(); // correct for target position

    hit->setXYZLab(r.getX(), r.getY(), r.getZ());
    hit->setDistance( d );
    hit->setTheta(theta);
    hit->setPhi(phi);
    hit->getXYZLab(xx,yy,zz);

}

Int_t HWallHitF::execute(void)
{
    HWallOneHit* onehit = NULL;
    HWallHit* hit       = NULL;
    Bool_t  startFlag = kFALSE;
    Float_t startTime = 0, calTime = 0;
    fLoc.set(1,-1);

    if (fStartHitCat && fStartHitCat->getEntries()>0) {
	HStart2Hit *h = NULL;
	if((h=(HStart2Hit *)fStartHitCat->getObject(0))!=NULL){
	    startTime   = h->getTime();
	    startFlag   = h->getFlag();
	}
    }

    iter->Reset();   // this works only in split mode=2
    // (for 0 and 1 the iterator must be recreated)
    while ((onehit=(HWallOneHit *)iter->Next()) != 0) {

	fLoc[0] = onehit->getCell();
	if(fLoc[0] == -1) continue;

	if(onehit->getTime() > -399.) {
	    fLoc[0] = onehit->getCell();

	    calTime =  onehit->getTime();

	    if(startFlag) calTime -=  startTime;

	    hit = (HWallHit*) fHitCat->getSlot(fLoc);
	    if(hit != NULL) {
		hit = new(hit) HWallHit;
		hit->setTime(calTime);
		hit->setCharge(onehit->getCharge());

		hit->setAddress(fLoc[0]);
		fillHit(hit,onehit);
		fillGeometry(hit);  //FK// TADY TO KRACHUJE
	    }

	}

    }

    return 0;

}


ClassImp(HWallHitF)










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