ROOT logo
#include "hwalleventplanef.h"
#include "walldef.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hcategory.h"
#include "hcategorymanager.h"
#include "hrecevent.h"
#include "hwallhit.h"
#include "hwalleventplane.h"
#include "hwalleventplanepar.h"

#include "TRandom.h"
#include "TFile.h"
#include "TH1F.h"
#include "TMath.h"
#include "TVector2.h"

using namespace std;

//_HADES_CLASS_DESCRIPTION
/////////////////////////////////////////////////////////////////////
//
//  HWallEventPlanef resonstructes the eventplane by HWallHits
//
/////////////////////////////////////////////////////////////////////

ClassImp(HWallEventPlaneF)

Bool_t HWallEventPlaneF::fUseCorrection = kTRUE;

HWallEventPlaneF::HWallEventPlaneF(const Text_t *name,const Text_t *title)
    : HReconstructor(name,title) {
	fWallHitCat         = NULL;
	fWallEventPlaneCat  = NULL;
	fWallEventPlanePar  = NULL;
}

HWallEventPlaneF::~HWallEventPlaneF()
{

}

Bool_t HWallEventPlaneF::init(void)
{
    fWallHitCat = HCategoryManager::getCategory(catWallHit,kTRUE,"catWallHit");
    if (!fWallHitCat) {
	Warning("init()","catWallHit not available!");
    }
    fWallEventPlaneCat = HCategoryManager::addCategory(catWallEventPlane,"HWallEventPlane",10,"Wall",kFALSE);

    if(fUseCorrection) fWallEventPlanePar = (HWallEventPlanePar*)gHades->getRuntimeDb()->getContainer("WallEventPlanePar");
    else               fWallEventPlanePar = NULL;


    return kTRUE;
}


Int_t HWallEventPlaneF::execute(void)
{

    if(!fWallHitCat) return 0;

    Float_t T1_cut   = 0.0;
    Float_t T2_cut   = 0.0;
    Float_t X_shift  = 0.0;
    Float_t Y_shift  = 0.0;
    //Float_t R0_cut   = 0.0;
    Float_t Z1_cut_s = 0.0;
    Float_t Z1_cut_m = 0.0;
    Float_t Z1_cut_l = 0.0;

    //------------------------------------------------------------
    // retrieve correction parameters if available
    if(fWallEventPlanePar) {
	T1_cut   = fWallEventPlanePar->getT1Cut();
	T2_cut   = fWallEventPlanePar->getT2Cut();
	X_shift  = fWallEventPlanePar->getXShift();
	Y_shift  = fWallEventPlanePar->getYShift();
	//R0_cut   = fWallEventPlanePar->getR0Cut();
	Z1_cut_s = fWallEventPlanePar->getZ1_cut_s();
	Z1_cut_m = fWallEventPlanePar->getZ1_cut_m();
	Z1_cut_l = fWallEventPlanePar->getZ1_cut_l();
    }
    //------------------------------------------------------------

    //------------------------------------------------------------
    // loop over wall hits and select good cells for eventplane
    Int_t   multWall   =   0;
    Int_t   cellNum    =   0;
    Float_t cellTime   = 0.0;
    Float_t cellCharge = 0.0;
    Float_t dEdxCut    = 0.0;
    Float_t wallX,wallY,wallZ;
    Float_t wallXc, wallYc; //corrected reCentered
    TVector2 vect(0.,0.);
    TVector2 vsum(0.,0.);
    TVector2   eX(1.,0.);

    fcellsVect.reset(); //

    HWallHit* pWallHit  = NULL;
    for(Int_t i = 0; i < fWallHitCat->getEntries(); i ++ ){
	pWallHit   = HCategoryManager::getObject(pWallHit,fWallHitCat,i);
	cellNum    = pWallHit->getCell();
	cellTime   = pWallHit->getTime();
	cellCharge = pWallHit->getCharge();

	if(cellNum <  144                  ){ dEdxCut = Z1_cut_s; }
	if(cellNum >= 144 && cellNum <= 207){ dEdxCut = Z1_cut_m; }
	if(cellNum >  207                  ){ dEdxCut = Z1_cut_l; }

	if(cellTime > T1_cut && cellTime < T2_cut && cellCharge > dEdxCut){
	    // spectators selected
	    multWall++;

	    pWallHit->getXYZLab(wallX,wallY,wallZ);
	    wallXc = wallX - X_shift;
	    wallYc = wallY - Y_shift;


	    vect.Set(wallXc, wallYc);
	    vect =  vect.Unit();
	    vsum += vect;

	    fcellsVect.setCellVect(vect);

	}
    }
    //------------------------------------------------------------


    //------------------------------------------------------------
    // now we go over spectators and make calculations for A/B subevents
    Int_t NA      = 0;
    Int_t NB      = 0;
    Int_t choiceA = 1;  //
    Int_t choiceB = 1;  //
    Int_t multFWcells = fcellsVect.getNumbOfCells();

    Float_t choice;
    TVector2 vectA(0.,0.), vectB(0.,0.);
    TVector2 vsumA(0.,0.), vsumB(0.,0.);

    for(Int_t ic = 0; ic < multFWcells; ic++){
	choice = gRandom->Rndm();
	// I can be proud that my algorithm has more flat distribution :)
	Float_t levelA = (multFWcells/2.-choiceA+1.)/Float_t(multFWcells);
	Float_t levelB = (multFWcells/2.-choiceB+1.)/Float_t(multFWcells);
	if(choice < levelA/(levelA+levelB)){
	    vectA = fcellsVect.getCellVector(ic);
	    vsumA += vectA;
	    choiceA++;
	    NA++;
	} else {
	    vectB = fcellsVect.getCellVector(ic);
	    vsumB += vectB;
	    choiceB++;
	    NB++;
	}
    }
    //------------------------------------------------------------


    //------------------------------------------------------------
    // calculating eventplane angles
    Float_t phiEP  =  vsum.DeltaPhi(eX)   *TMath::RadToDeg();
    Float_t phiA   = vsumA.DeltaPhi(eX)   *TMath::RadToDeg();
    Float_t phiB   = vsumB.DeltaPhi(eX)   *TMath::RadToDeg();
    Float_t phiAB  = vsumA.DeltaPhi(vsumB)*TMath::RadToDeg();

    if(multFWcells == 0)   phiEP = -1000.;
    if(NA == 0)            phiA  = -1000.;
    if(NB == 0)            phiB  = -1000.;
    if(NB == 0 || NA == 0) phiAB = -1000.;


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

    //------------------------------------------------------------
    // fill output object
    if(fWallEventPlaneCat){
	HWallEventPlane* eventplane = 0;
	Int_t index = 0;
	eventplane = HCategoryManager::newObject(eventplane,fWallEventPlaneCat,index);
	if(eventplane){
	    eventplane->setPhi ( phiEP);
	    eventplane->setPhiA( phiA );
	    eventplane->setPhiB( phiB );
	    eventplane->setPhiAB(phiAB);
	    eventplane->setNA(NA);
	    eventplane->setNB(NB);
	}
    }
    //------------------------------------------------------------


    return 0;
}











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