ROOT logo
#include "hparticlegeantpair.h"
#include "hparticletool.h"
#include "hphysicsconstants.h"

#include <iostream>
#include <iomanip>

using namespace std;

ClassImp(HParticleGeantPair)

//_HADES_CLASS_DESCRIPTION
////////////////////////////////////////////////////////////////////////////////
//
//
// HParticleGeantPair
//
// a pair build of 2 HGeantKine objects. Opening Angle + Vertex variables
// are calulated when the pair is set.
//
////////////////////////////////////////////////////////////////////////////////
Bool_t HParticleGeantPair::fbCheckAcceptance=kTRUE;

HParticleGeantPair::HParticleGeantPair()
{
    clear();
}

HParticleGeantPair::~HParticleGeantPair()
{

}

Bool_t HParticleGeantPair::isTruePair()
{
    // true if daughters are from source
    //
    if(fstatusFlags&0x01) return kTRUE;
    return kFALSE;
}

Bool_t HParticleGeantPair::isInAcceptance(Int_t ver)
{
    if(ver<0)        { if( (fstatusFlags&6) == 6 ) return kTRUE; }  // both candidates
    else if(ver==0)  { if( (fstatusFlags&2) == 2 ) return kTRUE; }  // candidate 1
    else if(ver==1)  { if( (fstatusFlags&4) == 4 ) return kTRUE; }  // candidate 2
    return kFALSE;
}

Int_t HParticleGeantPair::isFakePair()
{

    // checkes the assigned pids (not GEANT!)
    // return 2 if both cands are fake, 1 if one is
    // fake and 0 if none is fake

    if     (fPID[0] < 0 && fPID[1] < 0 ) return 2;
    else if(fPID[0] < 0 || fPID[1] < 0 ) return 1;
    else                                 return 0;
}

Bool_t  HParticleGeantPair::calcVertex()
{

    if(!fcand[0] || !fcand[1]) {
	Error("calcVertex()","Candidates not yet filled! Skipped!");
	return kFALSE;
    }
    HGeomVector base1,dir1,base2,dir2,dirMother;
    Float_t x,y,z;
    fcand[0]->getVertex(x,y,z);
    base1.setXYZ(x,y,z);
    fcand[1]->getVertex(x,y,z);
    base2.setXYZ(x,y,z);

    dir1.setXYZ(fc[0].X(),fc[0].Y(),fc[0].Z());
    dir2.setXYZ(fc[1].X(),fc[1].Y(),fc[1].Z());

    fDecayVertex  = HParticleTool::calcVertexAnalytical(base1,dir1,base2,dir2); // vertex of the two tracks

    dirMother.setXYZ((*this).X(),(*this).Y(),(*this).Z());

    fVerMinDistCand[0]   = HParticleTool::calculateMinimumDistanceStraightToPoint(base1,dir1,fEventVertex); //distance first secondary particle from primary vertex
    fVerMinDistCand[1]   = HParticleTool::calculateMinimumDistanceStraightToPoint(base2,dir2,fEventVertex); //distance second secondary particle from primary vertex
    fVerMinDistMother    = HParticleTool::calculateMinimumDistanceStraightToPoint(fDecayVertex,dirMother,fEventVertex);//?? distance decay vertex from primary vertex
    fVerDistMother       = (fDecayVertex-fEventVertex).length(); // decay vertex <-> global vertex
    fMinDistCandidates   = HParticleTool::calculateMinimumDistance(base1,dir1,base2,dir2);

    return kTRUE;
}

Bool_t  HParticleGeantPair::calcVectors(Int_t pid1,Int_t pid2,Int_t motherpid,HGeomVector& vertex)
{
    // sets fPID1,fPID2,fMotherPID and fills lorentz vectors
    // opening Angle etc.

    if(!fcand[0] || !fcand[1]) { Error("calcVectors()","Candidates not yet filled! Skipped!"); return kFALSE; }

    fPID[0]    = pid1;
    fPID[1]    = pid2;
    fMotherPID = motherpid;
    fEventVertex = vertex;

    HParticleTool::getTLorentzVector(fcand[0],fc[0],fPID[0]);
    HParticleTool::getTLorentzVector(fcand[1],fc[1],fPID[1]);

    (*((TLorentzVector*)this)) =  fc[0] + fc[1];

    foAngle = fc[0].Angle(fc[1].Vect()) * TMath::RadToDeg();

    calcVertex();

    return kTRUE;
}


Bool_t  HParticleGeantPair::setPair(HGeantKine* cnd1,Int_t pid1,
			    HGeantKine* cnd2,Int_t pid2,
			    HGeantKine* mother,Int_t motherpid,HGeomVector& vertex)
{
    // sets candidates and calls
    // calcvectors. Supposed to be called at initial
    // filling. uses provided pids for mass calculation.
    // if  fmother!=0 && motherpid > 0    fMotherPID = motherpid
    // if  fmother!=0 && motherpid <= 0   fMotherPID = GeantmotherPID
    // if  fmother==0 && motherpid > 0    fMotherPID = motherid
    // vertex = event vertex
    fcand[0]     = cnd1;
    fcand[1]     = cnd2;
    fmother      = mother;

    if(fmother){
	if(motherpid <= 0  ) fMotherPID = fmother->getID();
	else                 fMotherPID = motherpid;
    } else {
	if(motherpid > 0)    fMotherPID = motherpid;
	else {
	    Warning("setPair()","HGeantKine pointer for mother == 0 and motherpid not valid");
	}
    }

    if(fcand[0] && fcand[1]){
       if( fcand[0]->getParentTrack()!=0 && fcand[0]->getParentTrack() == fcand[1]->getParentTrack() ) fstatusFlags = fstatusFlags|0x01;
       if(fbCheckAcceptance && fcand[0]->isInAcceptance()) fstatusFlags = fstatusFlags|0x02;
       if(fbCheckAcceptance && fcand[1]->isInAcceptance()) fstatusFlags = fstatusFlags|0x04;
    }

    return calcVectors(pid1,pid2,motherpid,vertex);
}

Bool_t  HParticleGeantPair::setPair(HGeantKine* cnd1,HGeantKine* cnd2,
			    HGeantKine* mother, Int_t motherpid,HGeomVector& vertex)
{
    // sets candidates and calls
    // calcvectors. Supposed to be called at initial
    // filling. uses Geant id for mass calculation
    // if  fmother!=0 && motherpid > 0    fMotherPID = motherpid
    // if  fmother!=0 && motherpid <= 0   fMotherPID = GeantmotherPID
    // if  fmother==0 && motherpid > 0    fMotherPID = motherid
    // vertex = event vertex

    fcand[0]     = cnd1;
    fcand[1]     = cnd2;
    fmother      = mother;

    if(fmother){
	if(motherpid <= 0  ) fMotherPID = fmother->getID();
	else                 fMotherPID = motherpid;
    } else {
	if(motherpid > 0)    fMotherPID = motherpid;
        else {
	    Warning("setPair()","HGeantKine pointer for mother == 0 and motherpid not valid");
	}
    }

    Int_t pid1 =  cnd1->getID();
    Int_t pid2 =  cnd2->getID();

    if(fcand[0] && fcand[1]){
       if( fcand[0]->getParentTrack()!=0 && fcand[0]->getParentTrack() == fcand[1]->getParentTrack() ) fstatusFlags = fstatusFlags|0x01;
       if(fbCheckAcceptance && fcand[0]->isInAcceptance()) fstatusFlags = fstatusFlags|0x02;
       if(fbCheckAcceptance && fcand[1]->isInAcceptance()) fstatusFlags = fstatusFlags|0x04;
    }

    return calcVectors(pid1,pid2,motherpid,vertex);
}


void  HParticleGeantPair::print(UInt_t selection)
{
    // print option bits
    // bit   1 : print particle infos                      (selection == 1)
    //       2 : print pids, oAngle and polarities         (selection == 2)
    //       3 : print vertex infos                        (selection == 4)
    // default : print all


    cout<<"HParticleGeantPair::print() --------------------------------------"<<endl;

    if( (selection>>0) & 0x01){
	if(fcand[0]) fcand[0]->print();
	if(fcand[1]) fcand[1]->print();
        if(fmother)  fmother->print();

    }

    if( (selection>>1) & 0x01){
	cout<<"    pid1 = "   <<fPID[0]
	    <<", pid2 = "     <<fPID[1]
	    <<", motherpid = "<<fMotherPID
	    <<", oAngle = "<<foAngle
	    <<", chrg1 = "  << HPhysicsConstants::charge(fPID[0])
	    <<", chrg2 = "  << HPhysicsConstants::charge(fPID[1])
	    <<endl;
    }

    if( (selection>>2) & 0x01){
	cout<<"primary vertex    : "<<setw(12)<<fEventVertex.X()   <<", "<<setw(12)<<fEventVertex.Y()<<", "<<setw(12)<<fEventVertex.Z()<<endl;
	cout<<"decay   vertex    : "<<setw(12)<<fDecayVertex.X()   <<", "<<setw(12)<<fDecayVertex.Y()<<", "<<setw(12)<<fDecayVertex.Z()<<endl;
	cout<<"vermindist cand1  : "<<setw(12)<<fVerMinDistCand[0] <<", vermindist cand2 : "<<setw(12)<<fVerMinDistCand[1]<<", mindist candidates : "<<setw(12)<<fMinDistCandidates<<endl;
	cout<<"vermindist mother : "<<setw(12)<<fVerMinDistMother  <<", verdist mother   : "<<setw(12)<<fVerDistMother<<endl;
    }

}


void  HParticleGeantPair::clear()
{
    // clears all data elements but not vectors!
    fcand[0]         = 0;
    fcand[1]         = 0;
    fmother          = 0;
    fPID[0]          = -10;
    fPID[1]          = -10;
    fMotherPID       = -10;
    foAngle          = -1;
    fstatusFlags     = 0;

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