using namespace std;
#include "hkickresolution.h"
#include "hcategory.h"
#include "hmdcgeompar.h"
#include "htofgeompar.h"
#include "hgeanttof.h"
#include "hades.h"
#include "hevent.h"
#include "hiterator.h"
#include "hgeantmdc.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hgeomvector.h"
#include "hgeomvolume.h"
#include "hgeomcompositevolume.h"
#include "hgeantkine.h"
#include "hmdcgeompar.h"
#include "hdetector.h"
#include "htofgeompar.h"
#include "TRandom.h"
#include <iostream>
#include <iomanip>
HKickResolution::HKickResolution(void) {
initVars();
}
HKickResolution::HKickResolution(const Text_t name[],const Text_t title[]) :
HKickTask(name,title) {
initVars();
}
HKickResolution::~HKickResolution(void) {
initVars();
}
void HKickResolution::initVars(void) {
fInput=0;
fKine=0;
fData=0;
fGeometry=0;
fIter=0;
fUsingTofResol=fUsingMdcResol=kTRUE;
}
Bool_t HKickResolution::init(void) {
setKickParIo(gHades->getRuntimeDb());
fInput=gHades->getCurrentEvent()->getCategory(catMdcGeantRaw);
if (!fInput) return kFALSE;
else fIter=(HIterator *)fInput->MakeIterator();
fKine=gHades->getCurrentEvent()->getCategory(catGeantKine);
fTofInput=gHades->getCurrentEvent()->getCategory(catTofGeantRaw);
if (!fTofInput) {
Warning("init","No TOF input");
fTofInput = gHades->getSetup()->getDetector("Tof")
->buildCategory(catTofGeantRaw);
if (fTofInput) gHades->getCurrentEvent()->addCategory(catTofGeantRaw,
fTofInput,
"Mdc");
else return kFALSE;
}
else fTofIter=(HIterator *)fTofInput->MakeIterator();
fGeometry=(HMdcGeomPar *)gHades->getRuntimeDb()->getContainer("MdcGeomPar");
fTofGeometry=(HTofGeomPar *)gHades->getRuntimeDb()
->getContainer("TofGeomPar");
if (gHades->getOutputFile()) {
fData=new TNtuple("Data","Datos",
"p:pc:flag:a:b:c:x:y:z:ptg:ptf:ptt:pt:ptc:d:et1:et2:pmdc");
fControl=new TNtuple("con","con","p:t1:t2:f1:f2");
} else Warning("init","Output file not defined");
fEvCounter=0;
return kTRUE;
}
Bool_t HKickResolution::finalize(void) {
if (gHades->getOutputFile() && fData && fControl) {
gHades->getOutputFile()->cd();
fData->Write();
fControl->Write();
}
return kTRUE;
}
void HKickResolution::transform(HGeantTof *data,HGeomVector &r,
HGeomVector &err,Double_t &tanAlpha,
Double_t &offset) {
HGeomVector rLocal,errLocal;
Float_t en,x,y,tof,rodHeight,pp,len;
const Float_t tofXResol=15.5;
HModGeomPar *module=fTofGeometry->getModule(data->getSector(),
21-data->getModule());
HGeomTransform &modTrans=module->getLabTransform();
HGeomVolume *rodVol=module->getRefVolume()->getComponent(7-data->getCell());
HGeomTransform &rodTrans=rodVol->getTransform();
const HGeomRotation &modRot=modTrans.getRotMatrix();
rodHeight=TMath::Abs(rodVol->getPoint(0)->getY() - rodVol->getPoint(1)->getY());
data->getHit(en,x,y,tof,pp,len);
if (usingTofResolution()) {
x+=gRandom->Gaus(0,tofXResol);
y=0;
errLocal.setX(tofXResol);
errLocal.setY(rodHeight/(TMath::Sqrt(12.)));
errLocal.setZ(0.);
} else {
errLocal.setX(0.);
errLocal.setY(0.);
errLocal.setZ(0.);
}
r.setX(x);
r.setY(y);
r.setZ(0.);
rLocal=rodTrans.transFrom(r);
r=modTrans.transFrom(rLocal);
err=modRot*errLocal;
tanAlpha=modRot(2*3+1)/modRot(1*3+1);
offset=modTrans.getTransVector().getZ() - tanAlpha *
modTrans.getTransVector().getY();
}
void HKickResolution::transform(HGeantMdc *data,
HGeomVector &r,HGeomVector &alpha) {
Float_t x,y,tof,mom,theta,phi;
Double_t k=TMath::Pi()/180.0;
HGeomVector rLocal,alphaLocal;
HModGeomPar *module=fGeometry->
getModule(data->getSector(),data->getModule());
if (!module) Error("transform",
"Module %i:%i invalid\n",
data->getSector(),data->getModule());
HGeomTransform &modTrans=module->getLabTransform();
data->getHit(x,y,tof,mom);
data->getIncidence(theta,phi);
if (data->getLayer() != 6) {
HGeomVolume *layerVol=module->getRefVolume()->
getComponent(data->getLayer());
if (!layerVol) Error("transform","Layer %i invalid",
data->getLayer());
HGeomTransform &layerTrans=layerVol->getTransform();
alphaLocal.setX(TMath::Sin(theta*k)*TMath::Cos(phi*k));
alphaLocal.setY(TMath::Sin(theta*k)*TMath::Sin(phi*k));
alphaLocal.setZ(TMath::Cos(theta*k));
r.setX(x);
r.setY(y);
r.setZ(0.0);
rLocal=layerTrans.transFrom(r);
r=modTrans.transFrom(rLocal);
alpha=modTrans.getRotMatrix()*alphaLocal;
} else {
alphaLocal.setX(TMath::Sin(theta*k)*TMath::Cos(phi*k));
alphaLocal.setY(TMath::Sin(theta*k)*TMath::Sin(phi*k));
alphaLocal.setZ(TMath::Cos(theta*k));
rLocal.setX(x);
rLocal.setY(y);
rLocal.setZ(0.0);
r = modTrans.transFrom(rLocal);
alpha = modTrans.getRotMatrix()*alphaLocal;
}
}
Bool_t HKickResolutionTof::init(void) {
fKickPlane = HKickPlane2::getMeta();
return HKickResolution::init();
}
Int_t HKickResolutionTof::execute(void) {
HGeantMdc *data=0;
HGeantTof *tofdata=0;
HGeantKine *kineTrack=0;
HGeomVector r[2],alpha[2],inter,cross,tofR,tofAlpha;
HGeomVector pR,pAlpha;
Int_t tofCell=0;
HGeomVector errTofR;
Double_t errP,k,yR;
Float_t en=0,x=0,y=0,tof=0,len=0;
Float_t Pmdc;
Double_t rad2grad = 180. / TMath::Pi();
Int_t pcount=0,count=0,sector=0;
Double_t sintheta=0.;
Double_t Pt,Ptt,Ptg,Ptc,Pp,Pcalc,dist;
Float_t P=0,Ptof;
Float_t Px=0,Py=0,Pz=0;
kineTrack=(HGeantKine *)fKine->getObject(0);
kineTrack->getMomentum(Px,Py,Pz);
tofdata = (HGeantTof *)fTofInput->getObject(0);
if (!tofdata) return 0;
tofdata->getHit(en,x,y,tof,Ptof,len);
P = sqrt(Px*Px + Py*Py + Pz*Pz);
fFitter.reset();
fIter->Reset();
fTofIter->Reset();
while ( (data=(HGeantMdc *)fIter->Next()) != 0) {
if ( (data->getModule() == 0 && data->getLayer() == 6) ||
(data->getModule() == 3 && data->getLayer() == 6)) {
if (count <2) {
sector=data->getSector();
transform(data,r[count],alpha[count]);
}
count++;
} else if ( (data->getModule() == 1 && data->getLayer() == 6) ) {
transform(data,pR,pAlpha);
pcount++;
data->getHit(x,y,tof,Pmdc);
}
}
if (pcount == 1) {
alpha[0] = pR - r[0];
alpha[0] /= alpha[0].length();
}
fKickPlane->calcIntersection(r[0],alpha[0],inter);
while ( (tofdata=(HGeantTof *)fTofIter->Next()) != 0) {
if (tofdata->getSector() == sector && tofdata->getModule()<22 ) {
if (count <3) {
transform(tofdata,tofR,errTofR,k,yR);
tofAlpha=tofR-inter;
tofAlpha/=tofAlpha.length();
tofCell=(21 - tofdata->getModule())*22+(7-tofdata->getCell());
count++;
}
}
}
if (count > 3) Warning("execute","Inconsistent point fit");
else if (count == 3 && pcount==1) {
Double_t D;
Double_t deltaY,deltaPt;
Double_t g1,g2,f1,f2,t1,t2,et1,et2;
Double_t Ptf;
Float_t tuple_args[18];
for (Int_t i=0;i<2;i++) {
fFitter.addLine(r[i],alpha[i]);
}
fFitter.getVertex(cross);
Pp=P*(alpha[0].scalarProduct(alpha[1]));
Ptg=TMath::Sqrt(P*P-Pp*Pp);
tofAlpha=tofR-inter;
tofAlpha/=tofAlpha.length();
D=TMath::Sqrt( (tofR.getY() - inter.getY()) *
(tofR.getY() - inter.getY()) +
(tofR.getZ() - inter.getZ()) *
(tofR.getZ() - inter.getZ()) );
g1=TMath::ATan2(alpha[0].getZ(),alpha[0].getY());
g2=TMath::ATan2(tofAlpha.getZ(),tofAlpha.getY());
f1 = TMath::ATan2(alpha[0].getX(), alpha[0].getY());
f2 = TMath::ATan2(tofAlpha.getX(), tofAlpha.getY());
t1 = TMath::ACos(alpha[0].getZ());
t2 = TMath::ACos(tofAlpha.getZ());
et1 = TMath::ATan2(alpha[0].getX(),alpha[0].getZ());
et2 = TMath::ATan2(tofAlpha.getX(),tofAlpha.getZ());
sintheta=sin((g2-g1)/2);
if (usingTofResolution() || usingMdcResolution()) {
Ptg=0.; Ptf=0.; Ptt=0.; Pt=0.;
} else {
Pt = 2 * P * sin( acos(alpha[0].scalarProduct(tofAlpha)) / 2. );
Ptg = 2 * P * sintheta;
Ptf = 2 * P * sin( (f2-f1) / 2. );
Ptt = 2 * P * sin( (t2-t1) / 2. );
}
Ptc = Pcalc = 0.;
deltaPt = 1.52e-2;
deltaY= cos((g2-g1)/2) *
(inter.getZ() - k * inter.getY() - yR) * errTofR.getY();
deltaY/= 2 * D * D * sintheta;
errP=TMath::Sqrt(2.)*TMath::Sqrt(deltaY*deltaY + deltaPt*deltaPt);
HGeomVector prod=alpha[0].vectorProduct(alpha[1]);
prod/=prod.length();
dist=TMath::Abs((r[0]-r[1]).scalarProduct(prod));
if (fData) {
tuple_args[0]=P; tuple_args[1]=Pcalc; tuple_args[2]=errP;
tuple_args[3]=cross.getX();
tuple_args[4]=cross.getY();
tuple_args[5]=cross.getZ();
tuple_args[6]=inter.getX();
tuple_args[7]=inter.getY();
tuple_args[8]=inter.getZ();
tuple_args[9]=Ptg;
tuple_args[10]=Ptf;
tuple_args[11]=Ptt;
tuple_args[12]=Pt;
tuple_args[13]=Ptc;
tuple_args[14]=dist;
tuple_args[15]=et1;
tuple_args[16]=et2;
tuple_args[17]=Pmdc;
fData->Fill(tuple_args);
}
if (fControl) fControl->Fill(P,(t1 * rad2grad),
(TMath::ACos(tofR.getZ()/tofR.length()) *
rad2grad),
(TMath::ATan2(alpha[0].getY(),alpha[0].getX())
* rad2grad),
(TMath::ATan2(tofR.getY(),tofR.getX()) *
rad2grad) );
} else {
}
return 0;
}
Bool_t HKickResolutionMdc::init(void) {
fKickPlane = HKickPlane::getMDC3();
return HKickResolution::init();
}
Int_t HKickResolutionMdc::execute(void) {
HGeantMdc *data=0;
HGeantKine *kineTrack=0;
HGeomVector r[2],alpha[2],inter,cross;
Int_t count=0,sector=0;
Double_t sintheta,costheta=0.0;
Double_t P,Pt,Ptg,Ptf,Ptc,Pp,Pcalc,errPt;
Float_t Px=0,Py=0,Pz=0;
Double_t dist=0.;
Int_t pcount = 0;
HGeomVector partR,partAlpha;
kineTrack=(HGeantKine *)fKine->getObject(0);
kineTrack->getMomentum(Px,Py,Pz);
P=TMath::Sqrt(Px*Px + Py*Py + Pz*Pz);
fIter->Reset();
fFitter.reset();
while ( (data=(HGeantMdc *)fIter->Next()) != 0) {
if ( (data->getModule() == 0 && data->getLayer() == 6) ||
(data->getModule() == 2 && data->getLayer() == 6) ) {
if (count <2) {
sector=data->getSector();
transform(data,r[count],alpha[count]);
count++;
}
} else if ( data->getModule() == 1 && data->getLayer() == 6 ) {
transform(data,partR,partAlpha);
pcount++;
}
}
if (count > 2) Warning("execute","Inconsistent point fit");
else if (count == 2 && pcount==1) {
alpha[0] = partR - r[0];
alpha[0] /= alpha[0].length();
for (Int_t i=0;i<2;i++) {
fFitter.addLine(r[i],alpha[i]);
}
fFitter.getVertex(cross);
Double_t g1=TMath::ATan2(alpha[0].getZ(),alpha[0].getY());
Double_t g2=TMath::ATan2(alpha[1].getZ(),alpha[1].getY());
Double_t f1 = TMath::ATan2(alpha[0].getY(), alpha[0].getX());
Double_t f2 = TMath::ATan2(alpha[1].getY(), alpha[1].getX());
fKickPlane->calcIntersection(r[0],alpha[0],inter);
Ptc=fKickPlane->getPt(inter,errPt);
HGeomVector dir = alpha[1];
g2 = TMath::ATan2(dir.getZ(), dir.getY());
costheta=alpha[0].scalarProduct(dir);
sintheta=TMath::Sqrt(1 - costheta * costheta);
Pp=P*costheta;
Pt=TMath::Sqrt(P*P-Pp*Pp);
Ptg = 2. * P * sin( (g2 - g1) / 2.);
Ptf = 2. * P * sin( (f2 - f1) / 2.);
Pcalc=Ptc/(2. * sin( (g2 - g1) / 2.));
HGeomVector prod=alpha[0].vectorProduct(alpha[1]);
prod/=prod.length();
dist=TMath::Abs((r[0]-r[1]).scalarProduct(prod));
if (fData) fData->Fill(P,Pcalc,0.,
cross.getX(),cross.getY(),cross.getZ(),
inter.getX(),inter.getY(),inter.getZ(),
Ptg,Ptf,0,Pt,Pt,dist);
} else {
}
return 0;
}
Bool_t HKickResolutionMdc2::init(void) {
fKickPlane = HKickPlane2::getMDC3();
return HKickResolution::init();
}
Int_t HKickResolutionMdc2::execute(void) {
HGeantMdc *data=0;
HGeantKine *kineTrack=0;
HGeomVector r[2],alpha[2],inter,cross;
Int_t sector=0;
Double_t sintheta,costheta=0.0;
Double_t P,Pt,Ptg,Ptf,Ptc,Pp,Pcalc;
Float_t Px=0,Py=0,Pz=0;
Double_t dist=0.;
Int_t count[4];
HGeomVector partR[2],partAlpha[2];
HGeantTof *tofdata=0;
Float_t en,x,y,tof,Ptof,Pmdc,len;
Double_t k,yR;
HGeomVector tofR,errTofR;
Float_t tuple_args[18];
kineTrack=(HGeantKine *)fKine->getObject(0);
kineTrack->getMomentum(Px,Py,Pz);
P=TMath::Sqrt(Px*Px + Py*Py + Pz*Pz);
fIter->Reset();
fFitter.reset();
for (Int_t i=0;i<4;i++) count[i]=0;
Int_t idx=0;
while ( (data=(HGeantMdc *)fIter->Next()) != 0) {
if (data->getLayer() == 6) {
if (count[(Int_t)data->getModule()]<1) {
sector=data->getSector();
if (data->getModule() == 0 || data->getModule()==2) {
idx = data->getModule() / 2;
transform(data,r[idx],alpha[idx]);
} else {
idx = data->getModule() / 2;
transform(data,partR[idx],partAlpha[idx]);
if (data->getModule()==1) data->getHit(x,y,tof,Pmdc);
}
}
count[(Int_t)data->getModule()]++;
}
}
if (count[0]==1 && count[1]==1 && count[2]==1 && count[3]==1 ) {
alpha[0] = partR[0] - r[0];
alpha[0] /= alpha[0].length();
HGeomVector dir;
fKickPlane->calcIntersection(r[0],alpha[0],inter);
switch (fMode) {
case kKickPosMode:
dir = r[1] - inter;
dir /= dir.length();
break;
case kSlopeMode:
dir = alpha[1];
break;
case kMdcTofMode:
tofdata = (HGeantTof *)fTofInput->getObject(0);
if (!tofdata) return 0;
tofdata->getHit(en,x,y,tof,Ptof,len);
printf("toftran\n");
transform(tofdata,tofR,errTofR,k,yR);
alpha[1] = tofR - r[1];
alpha[1] /= alpha[1].length();
dir = alpha[1];
break;
case kMdc34Mode:
dir = partR[1] - r[1];
dir /= dir.length();
alpha[1]=dir;
break;
default:
Error("execute","Internal error 1 %i",fMode);
};
for (Int_t i=0;i<2;i++) {
fFitter.addLine(r[i],alpha[i]);
}
fFitter.getVertex(cross);
Double_t g1=TMath::ATan2(alpha[0].getZ(),alpha[0].getY());
Double_t g2=TMath::ATan2(dir.getZ(),dir.getY());
Double_t f1 = TMath::ATan2(alpha[0].getY(), alpha[0].getX());
Double_t f2 = TMath::ATan2(dir.getY(), dir.getX());
Float_t et1 = TMath::ATan2(alpha[0].getX(), alpha[0].getZ());
Float_t et2 = TMath::ATan2(dir.getX(), dir.getZ());
Ptc = 0;
costheta = alpha[0].scalarProduct(dir);
sintheta = 2*TMath::Sin(TMath::ACos(costheta)/2.);
Pp=P*costheta;
Pt=P*sintheta;
Ptg = 2. * P * sin( (g2 - g1) / 2.);
Ptf = 2. * P * sin( (f2 - f1) / 2.);
Pcalc=fKickPlane->getP(inter,sintheta,1);
HGeomVector prod=alpha[0].vectorProduct(dir);
prod/=prod.length();
dist=TMath::Abs((r[0]-r[1]).scalarProduct(prod));
tuple_args[0] = P;
tuple_args[1] = Pcalc;
tuple_args[2] = fMode;
tuple_args[3] = cross.getX();
tuple_args[4] = cross.getY();
tuple_args[5] = cross.getZ();
tuple_args[6] = inter.getX();
tuple_args[7] = inter.getY();
tuple_args[8] = inter.getZ();
tuple_args[9] = Ptg;
tuple_args[10] = Ptf;
tuple_args[11] = 0;
tuple_args[12] = Pt;
tuple_args[13] = Pt;
tuple_args[14] = dist;
tuple_args[15] = et1;
tuple_args[16] = et2;
tuple_args[17] = Pmdc;
if (fData) fData->Fill(tuple_args);
} else {
}
return 0;
}
ClassImp(HKickResolution)
ClassImp(HKickResolutionTof)
ClassImp(HKickResolutionMdc)
ClassImp(HKickResolutionMdc2)
Last change: Sat May 22 12:58:32 2010
Last generated: 2010-05-22 12:58
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.