using namespace std;
#include <iostream>
#include "TFile.h"
#include "TH1F.h"
#include "TLorentzVector.h"
#include "TObjArray.h"
#include "TString.h"
#include "TVector3.h"
#include <hades.h>
#include <hcategory.h>
#include <hevent.h>
#include <hiterator.h>
#include <hlinearcategory.h>
#include <hgeantkine.h>
#include <hgeomvector.h>
#include <hgeomvertexfit.h>
#include "hpidparticle.h"
#include "pairsdef.h"
#include "hpairfl.h"
ClassImp(HPairFL)
HPairFL::HPairFL(void)
{
}
HPairFL::~HPairFL(void)
{
}
HCategory* HPairFL::buildLinearCategory(Cat_t cat,const Text_t* catName)
{
HCategory *pCat = 0;
if (gHades && gHades->getCurrentEvent())
{
if ((pCat = ((HEvent*)(gHades->getCurrentEvent()))->getCategory(cat)))
return pCat;
else
{
pCat = new HLinearCategory(catName);
if (!pCat) ::Error("HPairFL::buildLinearCategory",
"Cannot create new category");
}
}
else
{
::Error("HPairFL::buildLinearCategory","Cannot access current event");
return pCat;
}
return pCat;
}
HCategory* HPairFL::getCategory(Cat_t cat, Bool_t bWarning)
{
HEvent *pEvent;
HCategory *pCat;
if((gHades == NULL) || ((pEvent = gHades->getCurrentEvent()) == NULL))
{
if(bWarning)
{
::Error("HPairFL::getCategory",
"Cannot access current event");
}
return NULL;
}
if((pCat = pEvent->getCategory(cat)) == NULL)
{
if(bWarning)
::Error("HPairFL::getCategory", "No category: %d", cat);
}
return pCat;
}
void HPairFL::saveHistos(TFile* pFileOut, TObjArray* pHistArray)
{
if(!pFileOut->IsOpen())
{
TString filename(pFileOut->GetName());
pFileOut=TFile::Open(filename.Data(),"UPDATE");
cout<<"Warning: File "<<pFileOut->GetName()<<" was reopened."<<endl;
pFileOut->Print();
}
pFileOut->cd();
for (Int_t i=0;i<(pHistArray->GetLast()+1);i++)
{
( (TH1*)(*pHistArray)[i] )->Write();
}
}
void HPairFL::printBitField(const Int_t in)
{
Int_t nBits = sizeof(in) * 8 + 1;
Char_t* c = new Char_t[nBits];
for (Int_t k=0; k<=nBits-1 ; k++) c[k]=48;
for (Int_t k=0; k<=nBits-1 ; k++)
if ( in & (1 << k) ) c[nBits-1-k]=49;
c[nBits-1]=13;
cout<<"Bit field: "<<in<<" is "<<dec<<c<<endl;
delete c;
}
void HPairFL::printBitField(const Char_t in)
{
Int_t nBits = sizeof(in) * 8 + 1;
Char_t* c = new Char_t[nBits];
for (Int_t k=0; k<=nBits-1 ; k++) c[k]=48;
for (Int_t k=0; k<=nBits-1 ; k++)
if ( in & (1 << k) ) c[nBits-1-k]=49;
c[nBits-1]=13;
cout<<"Bit field: "<<in<<" is "<<dec<<c<<endl;
delete c;
}
void HPairFL::setBit(UChar_t pos, Int_t& in)
{
UInt_t nBits = sizeof(in) * 8;
if (pos > nBits-1)
{
::Error("HPairFL::setBit","bit position out of range !");
}
Int_t SETTHIS = (1 << pos);
in |= SETTHIS;
}
Int_t HPairFL::getBit(UChar_t pos, const Int_t in)
{
UInt_t nBits = sizeof(in) * 8;
if (pos > nBits-1)
{
::Error("HPairFL::setBit","bit position out of range !");
return -1;
}
if ( in & (1 << pos) ) return 1;
else return 0;
}
void HPairFL::clearBit(UChar_t pos, Int_t& in)
{
UInt_t nBits = sizeof(in) * 8;
if (pos > nBits-1)
{
::Error("HPairFL::setBit","bit position out of range !");
}
Int_t SETTHIS = (Int_t(1) << pos);
in &= ~SETTHIS;
}
void HPairFL::setBit(UInt_t pos, Int_t& in)
{
UInt_t nBits = sizeof(in) * 8;
if (pos > nBits-1)
{
::Error("HPairFL::setBit","bit position out of range !");
}
Int_t SETTHIS = (1 << pos);
in |= SETTHIS;
}
Int_t HPairFL::getBit(UInt_t pos, const Int_t in)
{
UInt_t nBits = sizeof(in) * 8;
if (pos > nBits-1)
{
::Error("HPairFL::setBit","bit position out of range !");
return -1;
}
if ( in & (1 << pos) ) return 1;
else return 0;
}
void HPairFL::clearBit(UInt_t pos, Int_t& in)
{
UInt_t nBits = sizeof(in) * 8;
if (pos > nBits-1)
{
::Error("HPairFL::setBit","bit position out of range !");
}
Int_t SETTHIS = (1 << pos);
in &= ~SETTHIS;
}
Int_t HPairFL::countPositiveBits(const Int_t in)
{
Int_t nBits = sizeof(in) * 8;
Int_t cnt=0;
for (Int_t k=0; k<=nBits-1 ; k++) if ( in & (1 << k) ) cnt++;
return cnt;
}
Float_t HPairFL::calcInvMass(HPidParticle* p1, HPidParticle* p2)
{
TVector3 pvec1 = p1->Vect();
TVector3 pvec2 = p2->Vect();
Float_t opang=pvec1.Angle(pvec2);
Float_t invMass=2.*TMath::Sin(opang/2.)*TMath::Sqrt(p1->P()*p2->P());
if (invMass>0.) return invMass;
else return -1.;
}
Float_t HPairFL::calcInvMass(TLorentzVector* t1, TLorentzVector* t2)
{
TVector3 pvec1 = t1->Vect();
TVector3 pvec2 = t2->Vect();
Float_t opang=pvec1.Angle(pvec2);
Float_t invMass=2.*TMath::Sin(opang/2.)*TMath::Sqrt(t1->P()*t2->P());
if (invMass>0.) return invMass;
else return -1.;
}
HGeantKine* HPairFL::findParent(HGeantKine *kine,HIterator* iter_kine2)
{
Int_t aPar, aMed, aMech;
kine->getCreator(aPar,aMed,aMech);
if (aPar){
HGeantKine *kine2=0;
Int_t aTrackParent,aIDParent;
iter_kine2->Reset();
while((kine2=(HGeantKine *)iter_kine2->Next())!=0)
{
kine2->getParticle(aTrackParent,aIDParent);
if (aPar == aTrackParent)
{
return kine2;
}
}
}
return 0;
}
HGeantKine* HPairFL::findParent(HGeantKine *kine,HCategory* cat)
{
Int_t aPar, aMed, aMech;
kine->getCreator(aPar,aMed,aMech);
if (aPar){
HIterator* iter_kine2 = NULL;
HGeantKine *kine2=0;
Int_t aTrackParent,aIDParent;
iter_kine2 = (HIterator*)(cat->MakeIterator("native"));
iter_kine2->Reset();
while((kine2=(HGeantKine *)iter_kine2->Next())!=0)
{
kine2->getParticle(aTrackParent,aIDParent);
if (aPar == aTrackParent)
{
return kine2;
}
}
if(iter_kine2)
{
delete iter_kine2;
iter_kine2 = NULL;
}
}
return 0;
}
Float_t HPairFL::calcVertex(HPidParticle *p1, HPidParticle *p2,
TVector3 *vertex, TVector3 *distance)
{
HGeomVector hoff[2];
HGeomVector hdir[2];
HGeomVector hvertex;
HGeomVertexFit hfitter;
TVector3 dir[2];
Float_t dist;
Float_t det1, det2;
hoff[0].setXYZ(p1->getR()*TMath::Cos(p1->phiDeg()*TMath::DegToRad()
+ TMath::PiOver2()),
p1->getR()*TMath::Sin(p1->phiDeg()*TMath::DegToRad()
+ TMath::PiOver2()),
p1->getZ());
hoff[1].setXYZ(p2->getR()*TMath::Cos(p2->phiDeg()*TMath::DegToRad()
+ TMath::PiOver2()),
p2->getR()*TMath::Sin(p2->phiDeg()*TMath::DegToRad()
+ TMath::PiOver2()),
p2->getZ());
dir[0] = p1->Vect();
dir[1] = p2->Vect();
hdir[0].setXYZ(dir[0].X(),dir[0].Y(),dir[0].Z());
hdir[1].setXYZ(dir[1].X(),dir[1].Y(),dir[1].Z());
hfitter.reset();
for (Int_t i = 0; i < 2; i++) {
hfitter.addLine(hoff[i],hdir[i]);
}
hfitter.getVertex(hvertex);
vertex->SetXYZ(hvertex.getX(),hvertex.getY(),hvertex.getZ());
det1 = (
(hoff[0].getX()-hoff[1].getX()) *
(hdir[0].getY()*hdir[1].getZ()-hdir[0].getZ()*hdir[1].getY()) -
(hoff[0].getY()-hoff[1].getY()) *
(hdir[0].getX()*hdir[1].getZ()-hdir[0].getZ()*hdir[1].getX()) +
(hoff[0].getZ()-hoff[1].getZ()) *
(hdir[0].getX()*hdir[1].getY()-hdir[0].getY()*hdir[1].getX())
);
det2 = TMath::Sqrt(
(hdir[0].getX()*hdir[1].getY() - hdir[0].getY()*hdir[1].getX()) *
(hdir[0].getX()*hdir[1].getY() - hdir[0].getY()*hdir[1].getX()) +
(hdir[0].getX()*hdir[1].getZ() - hdir[0].getZ()*hdir[1].getX()) *
(hdir[0].getX()*hdir[1].getZ() - hdir[0].getZ()*hdir[1].getX()) +
(hdir[0].getY()*hdir[1].getZ() - hdir[0].getZ()*hdir[1].getY()) *
(hdir[0].getY()*hdir[1].getZ() - hdir[0].getZ()*hdir[1].getY())
);
*distance = dir[0].Cross(dir[1]);
if (det2==0) {
dist = -1.;
} else {
dist = TMath::Abs(det1/det2);
distance->SetMag(dist);
}
return dist;
}
void HPairFL::dumpKine(HGeantKine *kine)
{
if (kine)
{
Int_t aTrack, aID;
Int_t aPar, aMed, aMech;
Float_t ax, ay, az;
Float_t apx, apy, apz;
Float_t aInfo, aWeight;
Float_t ptot;
kine->getParticle(aTrack,aID);
kine->getCreator(aPar,aMed,aMech);
kine->getVertex(ax,ay,az);
kine->getMomentum(apx,apy,apz);
kine->getGenerator(aInfo,aWeight);
ptot=kine->getTotalMomentum();
cout<<"----------------------GEANT KINE------------------------"<<endl;
cout<<"--- GEANT track number: "<<aTrack<<endl;
cout<<"--- track number of parent particle: "<<aPar<<endl;
cout<<"--- GEANT particle ID: "<<aID<<endl;
cout<<"--- GEANT medium of creation: "<<aMed<<endl;
cout<<"--- GEANT creation mechanism: "<<aMech<<endl;
cout<<"--- x of track vertex (in mm): "<<ax<<endl;
cout<<"--- y : "<<ay<<endl;
cout<<"--- z : "<<az<<endl;
cout<<"--- x component of particle momentum (in MeV/c): "<<apx<<endl;
cout<<"--- y : "<<apy<<endl;
cout<<"--- z : "<<apz<<endl;
cout<<"--- total momentum : "<<ptot<<endl;
cout<<"--- event generator info: "<<aInfo<<endl;
cout<<"--- associated weight: "<<aWeight<<endl;
cout<<"--- "<<endl;
cout<<"--- "<<endl;
cout<<"--- "<<endl;
cout<<"--- "<<endl;
cout<<"--------------------------------------------------------"<<endl;
}
}
Bool_t HPairFL::isNewIndex(Int_t i,Int_t* iarr,Int_t max)
{
Int_t n=0;
do{
if(i==iarr[n]) break;
else if(iarr[n]==-2)
{
iarr[n]=i;
return kTRUE;
}
n++;
} while(n<max);
return kFALSE;
}
Bool_t HPairFL::isNew2Tuple(Int_t i,Int_t j,Int_t *tuple,Int_t max)
{
Int_t base=10;
Int_t cnt=1;
while ((max%cnt)<max)
{
cnt=cnt*base;
}
Int_t f1=cnt*i+j;
Int_t f2=cnt*j+i;
Int_t index=-1;
for (Int_t k=0;k<max;k++)
{
if (tuple[k]==-2)
{
index=k;
break;
}
if (f1==tuple[k] || f2==tuple[k])
{
return kFALSE;
}
}
if (index>-1)
{
tuple[index]=f1;
}
else cout<<"(isNew2Tuple,index of new slot not set)"<<endl;
return kTRUE;
}
Last change: Sat May 22 13:06:12 2010
Last generated: 2010-05-22 13:06
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.