using namespace std;
# include <math.h>
# include <stdlib.h>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <TMath.h>
# include <TROOT.h>
# include <TF1.h>
# include "hmdcgeomparf.h"
# include "hades.h"
# include "hdetector.h"
# include "hmdcdetector.h"
# include "hmdcmodulegeometry.h"
# include "hmdcgeomstruct.h"
# include "hevent.h"
# include "hmatrixcategory.h"
# include "hmatrixcatiter.h"
# include "hmdchit.h"
# include "hmdchitaux.h"
# include "hruntimedb.h"
# include "hspectrometer.h"
# include "hparrootfileio.h"
# include "mdcsdef.h"
ClassImp(HMdcGeomParF)
Int_t GP_DEBUG=0;
HMdcGeomParF :: HMdcGeomParF(void) : HReconstructor()
{
fLoc.setNIndex(5);
fHits = new TClonesArray("HMdcHit",4);
fLoc.set(5,0,0,1,2,3);
fNumMods = 4;
initDefaults();
}
HMdcGeomParF :: HMdcGeomParF(Int_t sector, Int_t modA, Int_t modB)
: HReconstructor()
{
fLoc.setNIndex(3);
fHits = new TClonesArray("HMdcHit",2);
fLoc.set(3,sector,modA,modB);
fNumMods = 2;
initDefaults();
}
HMdcGeomParF :: HMdcGeomParF(const Text_t* name,const Text_t* title, Int_t sector,
Int_t modA, Int_t modB,
Int_t modC, Int_t modD)
: HReconstructor(name, title)
{
if(modC == -1) {
fHits=new TClonesArray("HMdcHit",2);
fLoc.setNIndex(3);
fLoc.set(3,sector,modA,modB);
fNumMods = 2;
}
else if(modD == -1){
fHits=new TClonesArray("HMdcHit",3);
fLoc.setNIndex(4);
fLoc.set(4,sector,modA,modB,modC);
fNumMods = 3;
}
else {
fHits=new TClonesArray("HMdcHit",4);
fLoc.setNIndex(5);
fLoc.set(5,sector,modA,modB,modC,modD);
fNumMods = 4;
}
initDefaults();
}
HMdcGeomParF::HMdcGeomParF(const Text_t* name,const Text_t* title,
Int_t sector, Int_t modA)
: HReconstructor(name, title)
{
if(sector==6){
fHits=new TClonesArray("HMdcHit",1);
fLoc.setNIndex(3);
fLoc.set(3,sector,modA,0);
fNumMods = 0;
initDefaults();
}
else{
fHits=new TClonesArray("HMdcHit",1);
fLoc.setNIndex(3);
fLoc.set(3,sector,modA,0);
fNumMods = 1;
initDefaults();
}
}
void HMdcGeomParF::initDefaults(void)
{
if(fNumMods>1){
fEulerResult = new HGeomVector[fNumMods-1];
fTransResult = new HGeomVector[fNumMods-1];
fRotMat = new HGeomRotation[fNumMods-1];
fTranslation = new HGeomVector[fNumMods-1];
fEuler = new HGeomVector[fNumMods-1];
fError = new Double_t[(fNumMods-1)*6];
}
else if(fNumMods==1){
fRotMat = new HGeomRotation[1];
fTranslation = new HGeomVector[1];
fEuler = new HGeomVector[1];
}
else {
fRotMat = new HGeomRotation[6];
fTranslation = new HGeomVector[6];
fEuler = new HGeomVector[6];
}
fManual = kFALSE;
fHistoOff = kFALSE;
fUseCut = kTRUE;
fUseYPosCut = kFALSE;
fUseInitValue = kFALSE;
fUseUnitErrors = kFALSE;
fUseAngleCut = kFALSE;
fTFFor2Mods = kFALSE;
fAngleCut = 0.5;
fConstTukey = 10;
fStepTukey = 1;
fResultTukey = 1;
fEndTukey = 0.4;
fMin = 1;
fHistNum = 2;
fZLoCut = -100;
fZHiCut = 100;
fTree = NULL;
fOutFile = NULL;
fFix = 0;
initMinimization();
}
HMdcGeomParF :: ~HMdcGeomParF(void)
{
if(fRotMat) delete[] fRotMat;
if(fTranslation) delete[] fTranslation;
if(fEuler) delete[] fEuler;
if(fHits) delete fHits;
}
void HMdcGeomParF::initMinimization(void){
fIterCriteria = 0.1;
fSteps = new Float_t[6];
fLimits = new Float_t[6];
setSteps(0.01,0.01,0.01,0.1,0.1,0.1);
setLimits(0.,0.,0.,0.,0.,0.);
}
void HMdcGeomParF::setRelParams(HGeomVector*& ang, HGeomVector*& tra)
{
fEulerResult = ang;
fTransResult = tra;
}
void HMdcGeomParF::setOutputAscii(TString name)
{
fNameAscii=name;
}
void HMdcGeomParF::setOutputRoot(TString name)
{
fNameRoot=name;
}
void HMdcGeomParF::setTukeyConstant(Float_t cte, Float_t step, Float_t res, Float_t end)
{
fConstTukey = cte;
fStepTukey = step;
fResultTukey = res;
fEndTukey = end;
}
void HMdcGeomParF::setInitValue(Float_t x, Float_t y, Float_t z)
{
fUseInitValue = kTRUE;
fInitValue.setX(x);
fInitValue.setY(y);
fInitValue.setZ(z);
}
void HMdcGeomParF::setTargetFinderFor2Mods(void)
{
fTFFor2Mods = kTRUE;
}
void HMdcGeomParF :: setHistograms(void)
{
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
Int_t modB = fLoc[2];
Int_t modC = -1;
Int_t modD = -1;
static Char_t newDirName[255];
if(fNumMods>3) {
modC = fLoc[3];
modD = fLoc[4];
sprintf(newDirName,"%s%s%i%s%i%s%i%s%i%s%i","GeomParF_","S_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC,"_ModD_",modD);
}
else if(fNumMods>2) {
modC = fLoc[3];
sprintf(newDirName,"%s%s%i%s%i%s%i%s%i","GeomParF_",
"S_",sector,"_ModA_",modA,"_ModB_",modB,"_ModC_",modC);
}
else if(fNumMods>1) sprintf(newDirName,"%s%s%i%s%i%s%i","GeomParF_",
"S_",sector,"_ModA_",modA,"_ModB_",modB);
else if(fNumMods==1) sprintf(newDirName,"%s%s%i%s%i","GeomParF_",
"S_",sector,"_ModA_",modA);
else sprintf(newDirName,"%s%s%i","GeomParF_","_Mods_",modA);
fOutFile->mkdir(newDirName,newDirName);
fOutFile->cd(newDirName);
fPlanex = new TH2F*[fHistNum];
fPlaney = new TH2F*[fHistNum];
fPlanez = new TH2F*[fHistNum];
fProzY = new TH1F*[fHistNum];
fProzX = new TH1F*[fHistNum];
fProyZ = new TH1F*[fHistNum];
fProyX = new TH1F*[fHistNum];
fProxZ = new TH1F*[fHistNum];
fProxY = new TH1F*[fHistNum];
fTargets = new TH1F*[fHistNum];
fTarTuk = new TH1F*[4];
fTarTukW = new TH1F*[4];
fDisCTuk = new TH3F*[4];
if(fNumMods==0) {
fTarMDC = new TH1F*[fHistNum*6];
fTarCut = new TH1F*[fHistNum];
fTarMDCCut = new TH1F*[fHistNum*6];
}
fZVsTheta = new TH2F*[fHistNum];
fZVsRho = new TH2F*[fHistNum];
fDisZ = new TH1F*[fHistNum];
fDisCenter = new TH1F*[fHistNum];
Char_t title[50], tmp[50];
for(Int_t index=0;index<fHistNum;index++){
if(fNumMods>3) {
modC = fLoc[3];
modD = fLoc[4];
sprintf(title,"%s%i%s%i%s%i%s%i%s%i%s%i","_",index,"_Sector_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC,"_ModD_",modD);
}
else if(fNumMods>2){
modC = fLoc[3];
sprintf(title,"%s%i%s%i%s%i%s%i%s%i","_",index,"_Sector_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC);
}
else if(fNumMods>1) sprintf(title,"%s%i%s%i%s%i%s%i","_",index,"_Sector_",
sector,"_ModA_",modA,"_ModB_",modB);
else if(fNumMods==1) sprintf(title,"%s%i%s%i%s%i","_",index,"_Sector_",
sector,"_ModA_",modA);
else sprintf(title,"%s%i%s%i","_",index,"_Mods_",modA);
sprintf(tmp,"%s%s","fPlanex",title);
fPlanex[index] = new TH2F(tmp,title,100,-1000,1000,100,-1000,1000);
sprintf(tmp,"%s%s","fPlaney",title);
fPlaney[index] = new TH2F(tmp,title,100,-1000,1000,100,-1000,1000);
sprintf(tmp,"%s%s","fPlanez",title);
fPlanez[index] = new TH2F(tmp,title,100,-1000,1000,100,-1000,1000);
sprintf(tmp,"%s%s","fTargets",title);
fTargets[index] = new TH1F(tmp,title,2000,-1000,1000);
sprintf(tmp,"%s%s","fZVsTheta",title);
fZVsTheta[index] = new TH2F(tmp,title,200,0,3.1,200,-1000,1000);
sprintf(tmp,"%s%s","fZVsRho",title);
fZVsRho[index] = new TH2F(tmp,title,200,-100,100,200,-1000,1000);
sprintf(tmp,"%s%s","fDisZ",title);
fDisZ[index] = new TH1F(tmp,title,200,-100,100);
sprintf(tmp,"%s%s","fDisCenter",title);
fDisCenter[index] = new TH1F(tmp,title,200,0,1000);
sprintf(tmp,"%s%s","fProzY",title);
fProzY[index] = new TH1F(tmp,title,200,-1000,1000);
sprintf(tmp,"%s%s","fProzX",title);
fProzX[index] = new TH1F(tmp,title,200,-1000,1000);
sprintf(tmp,"%s%s","fProyZ",title);
fProyZ[index] = new TH1F(tmp,title,100,-500,500);
sprintf(tmp,"%s%s","fProyX",title);
fProyX[index] = new TH1F(tmp,title,100,-500,500);
sprintf(tmp,"%s%s","fProxZ",title);
fProxZ[index] = new TH1F(tmp,title,100,-500,500);
sprintf(tmp,"%s%s","fProxY",title);
fProxY[index] = new TH1F(tmp,title,100,-200,200);
if(fNumMods==0){
sprintf(tmp,"%s%s","fTarCut",title);
fTarCut[index] = new TH1F(tmp,title,2000,-1000,1000);
for(Int_t i=0;i<6;i++){
sprintf(tmp,"%s%i%s%s","fTarMDC_",i,"_",title);
fTarMDC[6*index+i] = new TH1F(tmp,title,2000,-1000,1000);
sprintf(tmp,"%s%i%s%s","fTarMDCCut_",i,"_",title);
fTarMDCCut[6*index+i] = new TH1F(tmp,title,2000,-1000,1000);
}
}
}
for(Int_t index=0;index<4;index++){
sprintf(tmp,"%s%i","fTarTuk_Tk_",index+1);
fTarTuk[index] = new TH1F(tmp,title,1000,-100,100);
sprintf(tmp,"%s%i","fTarTukW_Tk_",index+1);
fTarTukW[index] = new TH1F(tmp,title,1000,-100,100);
sprintf(tmp,"%s%i","fDisCTuk_Tk_",index+1);
fDisCTuk[index] = new TH3F(tmp,title,100,-10,10,100,-10,10,100,-10,10);
}
fOutFile->cd();
}
Bool_t HMdcGeomParF :: init(void)
{
if(fNumMods < 2){
fHitCat=gHades->getCurrentEvent()->getCategory(catMdcHit);
if (!fHitCat) {
fHitCat=gHades->getSetup()->getDetector("Mdc")->buildCategory(catMdcHit);
if (!fHitCat) return kFALSE;
else gHades->getCurrentEvent()->addCategory(catMdcHit,fHitCat,"Mdc");
}
fIter1 = (HIterator *)fHitCat->MakeIterator();
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
Char_t title[50], tmp[50];
sprintf(title,"%s%i%s%i","Sector_",sector,"_ModA_",modA);
sprintf(tmp,"%s%s%i%s%i","All","_Sector_",sector,"_ModA_",modA);
if (fNumMods==0){
sprintf(title,"%s%i","_ModA_",modA);
sprintf(tmp,"%s%s%i","All","_ModA_",modA);
}
fTree = new TTree(tmp,title);
fTree->Branch("hits",&fHits);
}
setParContainers();
return kTRUE;
}
Bool_t HMdcGeomParF :: reinit(void)
{
if(fManual == kFALSE) setGeomAuxPar();
return kTRUE;
}
Bool_t HMdcGeomParF :: initDelayed(void)
{
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
Int_t modB = fLoc[2];
Int_t modC = -1;
Int_t modD = -1;
Char_t tmp[255];
if(fNumMods>3){
modC = fLoc[3];
modD = fLoc[4];
if(fUseCut)
sprintf(tmp,"%s%s%i%s%i%s%i%s%i%s%i","AllCut","_Sector_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC,"_ModD_",modD);
else sprintf(tmp,"%s%s%i%s%i%s%i%s%i%s%i","All","_Sector_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC,"_ModD_",modD);
}
else if(fNumMods>2){
modC = fLoc[3];
if(fUseCut)
sprintf(tmp,"%s%s%i%s%i%s%i%s%i","AllCut","_Sector_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC);
else sprintf(tmp,"%s%s%i%s%i%s%i%s%i","All","_Sector_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC);
}
else {
if(fUseCut) sprintf(tmp,"%s%s%i%s%i%s%i","AllCut","_Sector_",sector,
"_ModA_",modA,"_ModB_",modB);
else sprintf(tmp,"%s%s%i%s%i%s%i","All","_Sector_",sector,
"_ModA_",modA,"_ModB_",modB);
}
if(fEulerResult && fTransResult) {
for(Int_t i=0;i<fNumMods-1;i++){
setEulerAngles(i,fEulerResult[i].getX(),
fEulerResult[i].getY(),
fEulerResult[i].getZ());
fillRotMatrix(i,fEulerResult[i].getX(),
fEulerResult[i].getY(),
fEulerResult[i].getZ());
fillTranslation(i,fTransResult[i].getX(),
fTransResult[i].getY(),
fTransResult[i].getZ());
}
}
else if(fNumMods>1) cout << "FATAL ERROR in HMdcGeomParF::initDelayed(): "
<< "no relative transformation found!" << endl;
if(!fOutFile) fOutFile = new TFile(fNameRoot,"UPDATE");
if(fNumMods>1) {
fTree = (TTree *)fOutFile->Get(tmp);
if (!fTree) cout << "ERROR in HMdcGeomParF::initDelayed(): "
<< "No Tree found in file " << endl;
}
return kTRUE;
}
void HMdcGeomParF :: setGeomParManOn(void)
{
fManual =kTRUE;
cout << "WARNING in HMdcGeomParF::setGeomParManOn(): "
<< "introducing manually Geometrical" << endl;
cout << "Parameters without containers. Parameters "
<< "should be in the macro" << endl;
}
void HMdcGeomParF :: setControlHistoOff(void)
{
fHistoOff = kTRUE;
}
void HMdcGeomParF :: setMinimization(Int_t select)
{
fMin = select;
}
void HMdcGeomParF::setUnitErrors(void)
{
fUseUnitErrors = kTRUE;
}
void HMdcGeomParF::setFix(Int_t fix)
{
fFix = fix;
}
void HMdcGeomParF::setNoCut(void)
{
fUseCut = kFALSE;
}
void HMdcGeomParF::setAngleCut(Float_t aCut=0.5)
{
fUseAngleCut = kTRUE;
fAngleCut = aCut;
}
void HMdcGeomParF::setYPosCut(Float_t aYCut=0.)
{
fUseYPosCut = kTRUE;
fYPosCut = aYCut;
}
void HMdcGeomParF :: setParContainers(void)
{
fMdcGeomPar=(HMdcGeomPar*)gHades
->getRuntimeDb()->getContainer("MdcGeomPar");
}
void HMdcGeomParF :: setGeomAuxPar(void)
{
Int_t sector = fLoc[0];
Int_t moduleA = fLoc[1];
Int_t moduleB = fLoc[2];
Int_t moduleC = -1;
Int_t moduleD = -1;
HGeomVector euler;
HGeomTransform transform;
if(GP_DEBUG>0){
cout << endl <<"Debugging output in HMdcGeomParF::setGeomAuxPar" << endl;
cout << "Original transformation from container" << endl;
cout << " ------ SECTOR " << sector << " ------ " << endl;
}
if(fNumMods>3){
moduleD = fLoc[4];
transform = fMdcGeomPar->getModule(sector,moduleD)->getLabTransform();
if(GP_DEBUG>0){
cout << "Reference: MDC D (Module " << moduleD << ")" << endl;
transform.print();
}
}
else if (fNumMods>2){
moduleC = fLoc[3];
transform = fMdcGeomPar->getModule(sector,moduleC)->getLabTransform();
if(GP_DEBUG>0){
cout << "Reference: MDC C (Module " << moduleC << ")" << endl;
transform.print();
}
}
else if (fNumMods>1){
transform = fMdcGeomPar->getModule(sector,moduleB)->getLabTransform();
if(GP_DEBUG>0){
cout << "Reference: MDC B (Module " << moduleB << ")" << endl;
transform.print();
}
}
else {
if(fNumMods==1)
transform = fMdcGeomPar->getModule(sector,moduleA)->getLabTransform();
else {
for(Int_t i=0; i<6;i++){
if(fMdcGeomPar->getModule(i,moduleA)!=0){
transform = fMdcGeomPar->getModule(i,moduleA)->getLabTransform();
fRotMat[i] = transform.getRotMatrix();
fTranslation[i] = transform.getTransVector();
cout << "**************************************************" << endl;
cout << "* Target finder in a complete frustum *" << endl;
cout << "**************************************************" << endl;
}
}
}
if(GP_DEBUG>0){
cout << "Reference: MDC A (Module " << moduleA << ")" << endl;
transform.print();
}
}
HGeomRotation rot = transform.getRotMatrix();
HGeomVector vect = transform.getTransVector();
euler = findEulerAngles(rot);
fillRotLab(euler.getX(),euler.getY(),euler.getZ());
fillTransLab(vect.getX(),vect.getY(),vect.getZ());
setEulerLabAngles(euler.getX(),euler.getY(),euler.getZ());
cout << "**************************************************" << endl;
cout << "* HMdcGeomParF::setGeomAuxPar: from geom params: *" << endl;
if(fNumMods>1) cout << "* Sector: "<< sector
<< " Reference Module: " <<fNumMods-1<<endl;
else cout << "* Sector: "<< sector
<< " Reference Module: " << moduleA<<endl;
cout << "* Rotation (Lab): " << euler.getX() << ", " << euler.getY()
<< ", " << euler.getZ() << endl;
cout << "* Translation (Lab): " << vect.getX() << ", "
<< vect.getY() << " , " << vect.getZ() << endl;
cout << "**************************************************" << endl;
}
HGeomVector HMdcGeomParF::findEulerAngles(HGeomRotation rot){
Double_t euler[3];
HGeomVector eul;
if(rot(8)< 0.99999 && rot(8)>-0.99999) euler[1] = acos(rot(8));
else euler[1]=0;
Double_t sinaux;
if(euler[1] == 0.){
euler[0]= (TMath::Pi()/2)+acos(rot(0));
euler[2]=-(TMath::Pi()/2);
}
else{
sinaux = sin(euler[1]);
euler[0] = atan2(rot(5)/sinaux,rot(2)/sinaux);
euler[2] = atan2(rot(7)/sinaux,-rot(6)/sinaux);
}
if(GP_DEBUG>0){
cout << endl <<"Euler angles: " << euler[0] << ", "
<< euler[1] << ", " << euler[2] << endl;
}
HGeomRotation test;
test.setEulerAngles(euler[0]*180./TMath::Pi(),
euler[1]*180./TMath::Pi(),
euler[2]*180./TMath::Pi());
if(GP_DEBUG>0){
cout << endl <<"Rotation from Euler angles (first attemp): " << endl;
test.print();
}
Double_t eps = 0.0001;
if( (fabs(test(0)-rot(0))>eps) || (fabs(test(1)-rot(1))>eps) ||
(fabs(test(3)-rot(3))>eps) || (fabs(test(4)-rot(4))>eps) ) {
if(GP_DEBUG>0) cout << endl << "Bad election in first euler angle! "
<< "Trying again. "<< endl;
euler[1] = - euler[1];
sinaux = sin(euler[1]);
euler[0] = atan2(rot(5)/sinaux,rot(2)/sinaux);
euler[2] = atan2(rot(7)/sinaux,-rot(6)/sinaux);
test.setEulerAngles(euler[0]*180./TMath::Pi(),
euler[1]*180./TMath::Pi(),
euler[2]*180./TMath::Pi());
if(GP_DEBUG>0){
cout << "Rotation from Euler angles (second attemp): " << endl;
test.print();
}
if( (fabs(test(0)-rot(0))>eps) || (fabs(test(1)-rot(1))>eps) ||
(fabs(test(3)-rot(3))>eps) || (fabs(test(4)-rot(4))>eps) ){
cout << endl << "FATAL ERROR: Bad election in euler angles! "<< endl;
cout << "Original rot matrix: "<< endl;
rot.print();
cout << "From obtained euler angles: " << endl;
test.print();
}
}
eul.setX(euler[0]);
eul.setY(euler[1]);
eul.setZ(euler[2]);
return eul;
}
Int_t HMdcGeomParF :: execute(void)
{
if(fNumMods==1) execute1();
if(fNumMods==0) execute0();
return 0;
}
void HMdcGeomParF::execute1(void)
{
HMdcHit* pHitA;
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
HLocation local;
local.setNIndex(2);
local.set(2,sector,modA);
fIter1->Reset();
fIter1->gotoLocation(local);
while ((pHitA =(HMdcHit*)fIter1->Next()) != 0){
if(pHitA->getChi2()>0)
{
new((*fHits)[0])HMdcHit(*pHitA);
fTree->Fill();
fHits->Clear();
}
}
}
void HMdcGeomParF::execute0(void)
{
HMdcHit* pHitA;
Int_t modA = fLoc[1];
HLocation local;
local.setNIndex(2);
for(Int_t i=0;i<6;i++){
local.set(2,i,modA);
fIter1->Reset();
fIter1->gotoLocation(local);
while ((pHitA =(HMdcHit*)fIter1->Next()) != 0){
if (pHitA->getChi2()>0)
{
new((*fHits)[0])HMdcHit(*pHitA);
fTree->Fill();
fHits->Clear();
}
}
}
}
Bool_t HMdcGeomParF :: finalize(void)
{
initDelayed();
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
Int_t modB = fLoc[2];
Int_t modC = -1;
Int_t modD = -1;
if(fNumMods>2) modC = fLoc[3];
if(fNumMods>3) modD = fLoc[4];
if(fHistoOff!=kTRUE) setHistograms();
if(fHistoOff!=kTRUE) fillHistograms(0);
ofstream *fout=NULL;
if (fNameAscii) fout = new ofstream(fNameAscii.Data(), ios::app);
if (*fout){
*fout << endl << " Laboratory transformation parameters " << endl;
*fout << endl << "Sector: " << sector << endl;
*fout << "Module A: " << modA;
if(fNumMods>1) *fout << " Module B: " << modB;
if(fNumMods>2) *fout << " Module C: " << modC;
if(fNumMods>3) *fout << " Module D: " << modD;
*fout << endl << endl;
*fout << "Transformation before minimization (init values): " << endl;
*fout << fEulerLab(0) << ", " << fEulerLab(1) << ", "
<< fEulerLab(2) << ", " << fTransLab(0) << ", "
<< fTransLab(1)<< ", " << fTransLab(2)<< endl;
}
if(fNumMods<2 || (fNumMods==2 && fTFFor2Mods)) {
targetFinder(fout);
if(fHistoOff!=kTRUE) fillHistograms(1);
storeInFile();
fout->close();
delete fout;
return kTRUE;
}
if(!fMin){
if (*fout) *fout << "Minimization strategy = 0: No minimization" << endl;
storeInFile();
fout->close();
delete fout;
return kTRUE;
}
Float_t OldEulerLab[3];
Float_t OldTransLab[3];
Int_t IterCounter =0;
Float_t IterCri;
do{
IterCri = 0;
for(Int_t i=0;i<3;i++){
OldEulerLab[i] = fEulerLab(i);
OldTransLab[i] = fTransLab(i);
}
minfit(fFix,fEulerLab(0),fEulerLab(1),fEulerLab(2),
fTransLab(0),fTransLab(1),fTransLab(2));
if (*fout){
*fout << "Parameters after minimization " << endl;
*fout << fEulerLab(0) << "+-" << fError[0] << ","
<< fEulerLab(1) << "+-" << fError[1] << ","
<< fEulerLab(2) << "+-" << fError[2] << ","
<< fTransLab(0) << "+-" << fError[3] << ","
<< fTransLab(1) << "+-" << fError[4] << ","
<< fTransLab(2) << "+-" << fError[5] << endl;
}
for(Int_t i=0;i<3;i++){
IterCri += fabs((fEulerLab(i)-OldEulerLab[i])/fEulerLab(i));
IterCri += fabs((fTransLab(i)-OldTransLab[i])/fTransLab(i));
}
IterCounter++;
if(IterCounter>10) {
cout << "WARNING in HMdcGeomParF :: execute" << endl;
cout << "Sector: " << sector << " ModuleA: " << modA
<< " ModuleB: " << modB;
if(fNumMods>2) *fout << " Module C: " << modC;
if(fNumMods>3) *fout << " Module D: " << modD;
cout << endl;
cout << "More than 10 iterations without results!" <<endl;
break;
}
}while(IterCri>fIterCriteria);
findZComponent();
if (*fout){
*fout << "Parameters after Z centering " << endl;
*fout << fEulerLab(0) << "+-" << fError[0] << ","
<< fEulerLab(1) << "+-" << fError[1] << ","
<< fEulerLab(2) << "+-" << fError[2] << ","
<< fTransLab(0) << "+-" << fError[3] << ","
<< fTransLab(1) << "+-" << fError[4] << ","
<< fTransLab(2) << "+-" << fError[5] << endl;
}
if(fHistoOff!=kTRUE) fillHistograms(1);
fout->close();
delete fout;
storeInFile();
return kTRUE;
}
Bool_t HMdcGeomParF::targetFinder(ofstream *fout)
{
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
HGeomVector aPoint;
HGeomVector aVector;
HGeomVector theTarget,finalTarget;
HGeomVector oldTarget;
Float_t third=0;
Float_t part1, part2, part3, numera,denomi, distRel, disTarget;
Float_t weigth = 1;
Float_t t;
Float_t angularError = 0.015 ;
Float_t distTarMDC,distToModulePC,distAllowed;
Bool_t accepted=kTRUE;
HMdcHit* pHitA;
HMdcHit* pHitB;
Stat_t entries;
Int_t sec=0;
Int_t iternum=0;
Int_t cont=0;
Float_t xcZ, ycZ, phiA, thetaA, ztar;
Float_t x,y,z;
HGeomVector a, b, ainb;
Int_t loopTukHist=4;
Float_t localTuk=-1;
if(fNumMods==0)
distTarMDC = sqrt(fTranslation[1].getX()*fTranslation[1].getX()+
fTranslation[1].getY()*fTranslation[1].getY()+
fTranslation[1].getZ()*fTranslation[1].getZ());
else
distTarMDC = sqrt(fTransLab.getX()*fTransLab.getX()+
fTransLab.getY()*fTransLab.getY()+
fTransLab.getZ()*fTransLab.getZ());
distAllowed = fabs(fAngleCut*distTarMDC);
cout << "distAllowed " << distAllowed << endl;
HGeomVertexFit* targetFinder= new HGeomVertexFit();
targetFinder->reset();
entries = fTree->GetEntries();
if(fUseInitValue) theTarget = fInitValue;
else{
if(fNumMods == 2){
TBranch *branch = fTree->GetBranch("hits");
branch->SetAddress(&fHits);
entries = fTree->GetEntries();
}
for (Int_t i=0;i<entries;i++) {
if(fNumMods == 2){
fHits->Clear();
fTree->GetEntry(i);
pHitB = (HMdcHit*) fHits->At(1);
pHitA = (HMdcHit*) fHits->At(0);
HGeomVector a,b,ainb;
a.setX(pHitA->getX());
a.setY(pHitA->getY());
b.setX(pHitB->getX());
b.setY(pHitB->getY());
a.setZ(0.);
b.setZ(0.);
ainb = fRotMat[0]*a+fTranslation[0];
aPoint = b;
aVector.setX(b.getX() - ainb.getX());
aVector.setY(b.getY() - ainb.getY());
aVector.setZ(b.getZ() - ainb.getZ());
}
else{
fTree->GetEntry(i);
pHitA = (HMdcHit*) fHits->At(0);
sec = pHitA->getSector();
aPoint.setX(pHitA->getX());
aPoint.setY(pHitA->getY());
aPoint.setZ(0.);
Float_t trump = 1-pHitA->getXDir()*pHitA->getXDir()
-pHitA->getYDir()*pHitA->getYDir();
if(trump<0) cout << "WARNING: Trying to sqrt x when x<0";
else third = sqrt(trump);
aVector.setX(pHitA->getXDir());
aVector.setY(pHitA->getYDir());
aVector.setZ(third);
if(fNumMods==0) {
aPoint = fRotMat[sec]*aPoint+fTranslation[sec];
aVector = fRotMat[sec]*aVector;
}
}
cont++;
targetFinder->addLine(aPoint,aVector,1);
}
targetFinder->getVertex(theTarget);
}
cout << "###### TARGET FINDER RESULT #######" << endl;
cout << "Init Value (no weigth)" << endl;
cout << " Sector: " << sector
<< " Module: " << modA << endl;
theTarget.print();
if(!fUseInitValue) cout << "Total entries : " << cont;
if(fout) {
*fout << " Init value: " << endl << theTarget.getX() << ", "
<< theTarget.getY()<< ", " << theTarget.getZ() << endl;
}
while(fConstTukey>=fEndTukey){
targetFinder->reset();
cout << endl << "fConstTukey = " << fConstTukey << endl;
do{
targetFinder->reset();
oldTarget = theTarget;
cont = 0;
if(fNumMods == 2){
TBranch *branch = fTree->GetBranch("hits");
branch->SetAddress(&fHits);
entries = fTree->GetEntries();
}
for (Int_t i=0;i<entries;i++) {
if(fNumMods == 2){
fHits->Clear();
fTree->GetEntry(i);
pHitB = (HMdcHit*) fHits->At(1);
pHitA = (HMdcHit*) fHits->At(0);
HGeomVector a,b,ainb,alab,blab;
a.setX(pHitA->getX());
a.setY(pHitA->getY());
b.setX(pHitB->getX());
b.setY(pHitB->getY());
a.setZ(0.);
b.setZ(0.);
ainb = fRotMat[0]*a+fTranslation[0];
aPoint = b;
aVector.setX(b.getX() - ainb.getX());
aVector.setY(b.getY() - ainb.getY());
aVector.setZ(b.getZ() - ainb.getZ());
}
else{
fTree->GetEntry(i);
pHitA = (HMdcHit*) fHits->At(0);
sec = pHitA->getSector();
aPoint.setX(pHitA->getX());
aPoint.setY(pHitA->getY());
aPoint.setZ(0.);
Float_t trump = 1-pHitA->getXDir()*pHitA->getXDir()
-pHitA->getYDir()*pHitA->getYDir();
if(trump<0) cout << "WARNING: Trying to sqrt x when x<0";
else third = sqrt(trump);
aVector.setX(pHitA->getXDir());
aVector.setY(pHitA->getYDir());
aVector.setZ(third);
}
if(fUseAngleCut) {
distToModulePC=sqrt(aPoint.getX()*aPoint.getX()
+aPoint.getY()*aPoint.getY());
if(fAngleCut>0 && distToModulePC<distAllowed) accepted=kFALSE;
else if(fAngleCut<0 && distToModulePC>distAllowed) accepted=kFALSE;
else accepted=kTRUE;
}
if(fUseYPosCut) {
if(pHitA->getY()<fYPosCut) accepted=kFALSE;
else accepted=kTRUE;
}
if(fNumMods==0) {
aPoint = fRotMat[sec]*aPoint+fTranslation[sec];
aVector = fRotMat[sec]*aVector;
}
part1 = ((theTarget.getX()-aPoint.getX())*(aVector.getY()))
- ((theTarget.getY()-aPoint.getY())*(aVector.getX()));
part2 = ((theTarget.getY()-aPoint.getY())*(aVector.getZ()))
- ((theTarget.getZ()-aPoint.getZ())*(aVector.getY()));
part3 = ((theTarget.getZ()-aPoint.getZ())*(aVector.getX()))
- ((theTarget.getX()-aPoint.getX())*(aVector.getZ()));
numera = (part1*part1)+(part2*part2)+(part3*part3);
denomi = aVector.getX()*aVector.getX()
+ aVector.getY()*aVector.getY()
+ aVector.getZ()*aVector.getZ();
disTarget = sqrt(numera/denomi);
t = disTarget/(angularError*distTarMDC);
if(fabs(t)<fConstTukey && accepted){
weigth = (1-t*t/(fConstTukey*fConstTukey))
* (1-t*t/(fConstTukey*fConstTukey));
cont++;
if(fConstTukey<=fEndTukey+4*fStepTukey && fConstTukey>fEndTukey && iternum==2 && loopTukHist>=0){
if(localTuk == -1.) {
localTuk = fConstTukey;
loopTukHist = 3;
}
else
if(localTuk != fConstTukey){
localTuk = fConstTukey;
loopTukHist--;
}
if(loopTukHist>=0){
xcZ = aPoint.getX()-(aVector.getX())*
aPoint.getZ()/(aVector.getZ());
ycZ = aPoint.getY()-(aVector.getY())*
aPoint.getZ()/(aVector.getZ());
phiA = atan2(aVector.getY(),aVector.getX());
thetaA = acos((aVector.getZ())/
sqrt((aVector.getX())*(aVector.getX())+
(aVector.getY())*(aVector.getY())+
(aVector.getZ())*(aVector.getZ())));
ztar = -(ycZ * sin(phiA) + xcZ*cos(phiA))*cos(thetaA)/sin(thetaA);
fTarTuk[loopTukHist]->Fill(ztar);
fTarTukW[loopTukHist]->Fill(ztar,weigth);
z=(aPoint.getX()*aVector.getY())-(aPoint.getY()*aVector.getX());
x=(aPoint.getY()*aVector.getZ())-(aPoint.getZ()*aVector.getY());
y=(aPoint.getZ()*aVector.getX())-(aPoint.getX()*aVector.getZ());
fDisCTuk[loopTukHist]->Fill(x,y,z);
}
}
targetFinder->addLine(aPoint,aVector,weigth);
}
}
targetFinder->getVertex(theTarget);
theTarget.print();
cout << "Entries with weigth: " << cont;
distRel = sqrt( (theTarget.getX()-oldTarget.getX())*
(theTarget.getX()-oldTarget.getX()) +
(theTarget.getY()-oldTarget.getY())*
(theTarget.getY()-oldTarget.getY()) +
(theTarget.getZ()-oldTarget.getZ())*
(theTarget.getZ()-oldTarget.getZ()) );
iternum++;
if(iternum>100) {
cout << "More than 100 iterations without results!" <<endl;
break;
}
}while(distRel>0.001);
iternum=0;
if(fout) {
*fout << " Tukey = " << fConstTukey << " " << theTarget.getX()
<< ", " << theTarget.getY()<< ", " << theTarget.getZ()
<< " Entries: " << cont << endl;
}
if(fConstTukey==fResultTukey) finalTarget=theTarget;
if(fStepTukey!=1)fConstTukey = fConstTukey-fStepTukey;
else{
if(fConstTukey>1)fConstTukey = fConstTukey-1.;
else fConstTukey = fConstTukey -0.5;
}
}
if(fNumMods==0) {
*fout << "Target estimate in LAB coordinates " <<endl;
*fout << finalTarget.getX() << ", " << finalTarget.getY()<< ", "
<< finalTarget.getZ() << endl;
for(Int_t i=0;i<6;i++){
*fout << "Old fTranslation[" << i << "]:";
*fout << fTranslation[i].getX() << ", "
<< fTranslation[i].getY() << ", "
<< fTranslation[i].getZ() << endl;
fTranslation[i] = fTranslation[i]-finalTarget;
*fout << "New fTranslation[" << i << "]:";
*fout << fTranslation[i].getX() << ", "
<< fTranslation[i].getY() << ", "
<< fTranslation[i].getZ() << endl;
}
}
else{
if(fUseAngleCut) *fout << endl <<"Using an Angle Cut (" << fAngleCut
<< ") = " << distAllowed
<< "mm. around MDC phys. center " <<endl;
*fout << endl <<"Original MDC translation vector: " <<endl;
*fout << fTransLab.getX() << ", " << fTransLab.getY()<< ", "
<< fTransLab.getZ() << endl;
*fout << "Target estimate in MDC coordinates " << endl;
*fout << finalTarget.getX() << ", " << finalTarget.getY()<< ", "
<< finalTarget.getZ() << endl;
finalTarget = fRotLab*finalTarget+fTransLab;
*fout << "Target estimate in LAB coordinates " <<endl;
*fout << finalTarget.getX() << ", " << finalTarget.getY()<< ", "
<< finalTarget.getZ() << endl;
fTransLab = fTransLab-finalTarget;
*fout << endl <<"New estimate of the MDC translation vector: " <<endl;
*fout << fTransLab.getX() << ", " << fTransLab.getY()<< ", "
<< fTransLab.getZ() << endl;
}
return kTRUE;
}
void HMdcGeomParF :: fillHistograms(Int_t index){
HMdcHit* hitA;
HMdcHit* hitB=NULL;
HMdcHit* hitC=NULL;
HMdcHit* hitD=NULL;
Float_t xcZ=0, ycZ=0, xcY=0, zcY=0, ycX=0, zcX=0;
Float_t phi=0, theta=0,ztar=0, rtar=0, xtar=0, ytar=0, canaux;
Float_t myxtar=0, myytar=0, myztar=0, myrho=0, distZ=0;
Float_t part1, part2, part3, numera, denomi, discenter;
Float_t distTarMDC,distToModulePC,distAllowed;
TBranch *branch = fTree->GetBranch("hits");
branch->SetAddress(&fHits);
Stat_t entries = fTree->GetEntries();
for (Int_t i=0;i<entries;i++) {
fHits->Clear();
fTree->GetEntry(i);
if(fNumMods>1) hitB = (HMdcHit*) fHits->At(1);
hitA = (HMdcHit*) fHits->At(0);
if(fNumMods>2){
HGeomVector a,b,c,d;
HGeomVector transf[4];
Float_t errorx[4];
Float_t errory[4];
hitC = (HMdcHit*) fHits->At(2);
if(fNumMods>3){
hitD = (HMdcHit*) fHits->At(3);
d.setX(hitD->getX());
d.setY(hitD->getY());
d.setZ(0.);
}
c.setX(hitC->getX());
c.setY(hitC->getY());
c.setZ(0.);
b.setX(hitB->getX());
b.setY(hitB->getY());
b.setZ(0.);
a.setX(hitA->getX());
a.setY(hitA->getY());
a.setZ(0.);
if(fUseUnitErrors==kFALSE){
errorx[0] = (hitA->getErrX()!=0)? hitA->getErrX() : 0.2;
errorx[1] = (hitB->getErrX()!=0)? hitB->getErrX() : 0.2;
errorx[2] = (hitC->getErrX()!=0)? hitC->getErrX() : 0.2;
if(fNumMods>3) errorx[3] = (hitD->getErrX()!=0)? hitD->getErrX():0.2;
errory[0] = (hitA->getErrY()!=0)? hitA->getErrY() : 0.1;
errory[1] = (hitB->getErrY()!=0)? hitB->getErrY() : 0.1;
errory[2] = (hitC->getErrY()!=0)? hitC->getErrY() : 0.1;
if(fNumMods>3) errory[3] = (hitD->getErrY()!=0)? hitD->getErrY():0.1;
}
else
for(Int_t i=0;i<fNumMods;i++){
errorx[i]=1.0;
errory[i]=1.0;
}
if(fNumMods>3){
transf[3] = d;
transf[2] = fRotMat[0] * c + fTranslation[0];
transf[1] = fRotMat[1] * b + fTranslation[1];
transf[0] = fRotMat[2] * a + fTranslation[2];
}
else{
transf[2] = c;
transf[1] = fRotMat[0] * b + fTranslation[0];
transf[0] = fRotMat[1] * a + fTranslation[1];
}
Float_t ax=0.0, ay=0.0, bx=0.0, by=0.0;
Float_t sigax=0.0, sigay=0.0, sigbx=0.0, sigby=0.0;
Float_t Xwt, Xt, Xsxoss, Xsx=0.0, Xsy=0.0, Xst2=0.0, Xss=0.0;
Float_t Ywt, Yt, Ysxoss, Ysx=0.0, Ysy=0.0, Yst2=0.0, Yss=0.0;
for(Int_t i=0;i<fNumMods;i++){
Xwt = 1.0/(errorx[i]*errorx[i]);
Xss += Xwt;
Xsx += transf[i].getZ()*Xwt;
Xsy += transf[i].getX()*Xwt;
Ywt = 1.0/(errory[i]*errory[i]);
Yss += Ywt;
Ysx += transf[i].getZ()*Ywt;
Ysy += transf[i].getY()*Ywt;
}
Xsxoss = Xsx/Xss;
Ysxoss = Ysx/Yss;
for(Int_t i=0;i<fNumMods;i++){
Xt = (transf[i].getZ()-Xsxoss)/errorx[i];
Xst2 += Xt * Xt;
bx += Xt * transf[i].getX()/errorx[i];
Yt = (transf[i].getZ()-Ysxoss)/errory[i];
Yst2 += Yt * Yt;
by += Yt * transf[i].getY()/errory[i];
}
bx /= Xst2;
ax = (Xsy-(Xsx*bx))/Xss;
by /= Yst2;
ay = (Ysy-(Ysx*by))/Yss;
sigax = sqrt((1.0+Xsx*Xsx/(Xss*Xst2))/Xss);
sigbx = sqrt(1.0/Xst2);
sigay = sqrt((1.0+Ysx*Ysx/(Yss*Yst2))/Yss);
sigby = sqrt(1.0/Yst2);
fPlanez[index]->Fill(ax,bx);
fPlaney[index]->Fill(ax-bx*ay/by,-ay/by);
fPlanex[index]->Fill(ay-by*ax/bx,-ax/bx);
fProzY[index]->Fill(-ay/by);
fProzX[index]->Fill(-ax/bx);
fProyZ[index]->Fill(bx);
fProyX[index]->Fill(ay-by*ax/bx);
fProxZ[index]->Fill(ax);
fProxY[index]->Fill(ax-bx*ay/by);
phi = atan2(by,bx);
theta = atan(sqrt(bx*bx+by*by));
Float_t common = bx*bx + by*by;
xtar = (by*by*ax - ay*bx*by) / common;
ytar = (ay*bx*bx - ax*bx*by) / common;
ztar = -(ay*by + ax*bx) / common;
rtar = (ay*bx-ax*by) / sqrt(common);
discenter = sqrt((ax*ax*(by*by+1)+ay*ay*(bx*bx+1)-2*ax*ay*bx*by) /
bx*bx+by*by+1);
fZVsTheta[index]->Fill(theta,ztar);
fZVsRho[index]->Fill(rtar,ztar);
fTargets[index]->Fill(ztar);
fDisZ[index]->Fill(rtar);
fDisCenter[index]->Fill(discenter);
}
if(fNumMods==2){
HGeomVector a,b,ainb,alab,blab;
a.setX(hitA->getX());
a.setY(hitA->getY());
b.setX(hitB->getX());
b.setY(hitB->getY());
a.setZ(0.);
b.setZ(0.);
if(GP_DEBUG>3){
cout << "MDC HIT A: " << endl;
a.print();
cout << "MDC HIT B: " << endl;
b.print();
}
ainb = fRotMat[0]*a+fTranslation[0];
if(GP_DEBUG>3){
cout << "MDC HIT A IN MDC B CS: "<< endl;
ainb.print();
}
alab = fRotLab*ainb+fTransLab;
blab = fRotLab*b+fTransLab;
if(GP_DEBUG>3){
cout << "MDC HIT A IN LAB CS: " << endl;
alab.print();
cout << "MDC HIT B IN LAB CS: " << endl;
blab.print();
}
xcZ = alab.getX()-(blab.getX()-alab.getX())*
alab.getZ()/(blab.getZ()-alab.getZ());
ycZ = alab.getY()-(blab.getY()-alab.getY())*
alab.getZ()/(blab.getZ()-alab.getZ());
fPlanez[index]->Fill(xcZ,ycZ);
xcY = alab.getX() -(blab.getX()-alab.getX())*
alab.getY()/(blab.getY()-alab.getY());
zcY = alab.getZ() -(blab.getZ()-alab.getZ())*
alab.getY()/(blab.getY()-alab.getY());
fPlaney[index]->Fill(xcY,zcY);
ycX = alab.getY() -(blab.getY()-alab.getY())*
alab.getX()/(blab.getX()-alab.getX());
zcX = alab.getZ() -(blab.getZ()-alab.getZ())*
alab.getX()/(blab.getX()-alab.getX());
fPlanex[index]->Fill(ycX,zcX);
fProzY[index]->Fill(zcY);
fProzX[index]->Fill(zcX);
fProyZ[index]->Fill(ycZ);
fProyX[index]->Fill(ycX);
fProxZ[index]->Fill(xcZ);
fProxY[index]->Fill(xcY);
phi = atan2(blab.getY()-alab.getY(),blab.getX()-alab.getX());
theta = acos((blab.getZ()-alab.getZ())/
sqrt((blab.getX()-alab.getX())*(blab.getX()-alab.getX())+
(blab.getY()-alab.getY())*(blab.getY()-alab.getY())+
(blab.getZ()-alab.getZ())*(blab.getZ()-alab.getZ())));
ztar = -(ycZ * sin(phi) + xcZ*cos(phi))*cos(theta)/sin(theta);
xtar = ((blab.getX()-alab.getX())*(ztar-alab.getZ())/
(blab.getZ()-alab.getZ())) + alab.getX();
ytar = ((blab.getY()-alab.getY())*(ztar-alab.getZ())/
(blab.getZ()-alab.getZ())) + alab.getY();
rtar = ycZ * cos(phi) - xcZ*sin(phi);
fZVsTheta[index]->Fill(theta,ztar);
fZVsRho[index]->Fill(rtar,ztar);
fTargets[index]->Fill(ztar);
canaux = ((alab.getX()-blab.getX())/(blab.getY()-alab.getY())) -
((blab.getY()-alab.getY())/(blab.getX()-alab.getX()));
myxtar = (alab.getY()-
(alab.getX()*(blab.getY()-alab.getY())/
(blab.getX()-alab.getX()))) / canaux;
myytar = (myxtar*(blab.getY()-alab.getY())/(blab.getX()-alab.getX())) +
(alab.getY()-alab.getX()*(blab.getY()-alab.getY())/
(blab.getX()-alab.getX()));
myztar = (myxtar*(blab.getZ()-alab.getZ())/(blab.getX()-alab.getX())) +
(alab.getZ()-alab.getX()*(blab.getZ()-alab.getZ())/
(blab.getX()-alab.getX()));
myrho = sqrt(myxtar*myxtar + myytar*myytar);
distZ = ((alab.getX()*(blab.getY()-alab.getY()))-
(alab.getY()*(blab.getX()-alab.getX()))) /
sqrt(((blab.getY()-alab.getY())*(blab.getY()-alab.getY())) +
((blab.getX()-alab.getX())*(blab.getX()-alab.getX())));
fDisZ[index]->Fill(distZ);
part1 = ((-alab.getX())*(blab.getY()-alab.getY())) -
((-alab.getY())*(blab.getX()-alab.getX()));
part2 = ((-alab.getY())*(blab.getZ()-alab.getZ())) -
((-alab.getZ())*(blab.getY()-alab.getY()));
part3 = ((-alab.getZ())*(blab.getX()-alab.getX())) -
((-alab.getX())*(blab.getZ()-alab.getZ()));
numera = (part1*part1)+(part2*part2)+(part3*part3);
denomi = (blab.getX()-alab.getX())*(blab.getX()-alab.getX())+
(blab.getY()-alab.getY())*(blab.getY()-alab.getY())+
(blab.getZ()-alab.getZ())*(blab.getZ()-alab.getZ());
discenter = sqrt(numera/denomi);
fDisCenter[index]->Fill(discenter);
if(zcY>fZLoCut && zcY<fZHiCut){
}
}
else{
HGeomVector aPoint,aVector;
HGeomVector aPointLab,aVectorLab;
Int_t sec;
Float_t third=0;
aPoint.setX(hitA->getX());
aPoint.setY(hitA->getY());
aPoint.setZ(0.);
third = sqrt(1-hitA->getXDir()*hitA->getXDir()
-hitA->getYDir()*hitA->getYDir());
aVector.setX(hitA->getXDir());
aVector.setY(hitA->getYDir());
aVector.setZ(third);
sec = hitA->getSector();
if(GP_DEBUG>3){
cout << "MDC HIT A. Point: " << endl;
aPoint.print();
cout << "Vector: " << endl;
aVector.print();
}
if(fNumMods==0) {
aPointLab = fRotMat[sec]*aPoint+fTranslation[sec];
aVectorLab = fRotMat[sec]*aVector;
}
else{
aPointLab = fRotLab*aPoint+fTransLab;
aVectorLab = fRotLab*aVector;
}
xcZ = aPointLab.getX()-(aVectorLab.getX())*
aPointLab.getZ()/(aVectorLab.getZ());
ycZ = aPointLab.getY()-(aVectorLab.getY())*
aPointLab.getZ()/(aVectorLab.getZ());
fPlanez[index]->Fill(xcZ,ycZ);
xcY = aPointLab.getX() -(aVectorLab.getX())*
aPointLab.getY()/(aVectorLab.getY());
zcY = aPointLab.getZ() -(aVectorLab.getZ())*
aPointLab.getY()/(aVectorLab.getY());
fPlaney[index]->Fill(xcY,zcY);
ycX = aPointLab.getY() -(aVectorLab.getY())*
aPointLab.getX()/(aVectorLab.getX());
zcX = aPointLab.getZ() -(aVectorLab.getZ())*
aPointLab.getX()/(aVectorLab.getX());
fPlanex[index]->Fill(ycX,zcX);
fProzY[index]->Fill(zcY);
fProzX[index]->Fill(zcX);
fProyZ[index]->Fill(ycZ);
fProyX[index]->Fill(ycX);
fProxZ[index]->Fill(xcZ);
fProxY[index]->Fill(xcY);
phi = atan2(aVectorLab.getY(),aVectorLab.getX());
theta = acos((aVectorLab.getZ())/
sqrt((aVectorLab.getX())*(aVectorLab.getX())+
(aVectorLab.getY())*(aVectorLab.getY())+
(aVectorLab.getZ())*(aVectorLab.getZ())));
ztar = -(ycZ * sin(phi) + xcZ*cos(phi))*cos(theta)/sin(theta);
xtar = ((aVectorLab.getX())*(ztar-aPointLab.getZ())/
(aVectorLab.getZ())) + aPointLab.getX();
ytar = ((aVectorLab.getY())*(ztar-aPointLab.getZ())/
(aVectorLab.getZ())) + aPointLab.getY();
rtar = ycZ * cos(phi) - xcZ*sin(phi);
fZVsTheta[index]->Fill(theta,ztar);
fZVsRho[index]->Fill(rtar,ztar);
fTargets[index]->Fill(ztar);
if(fNumMods==0)
fTarMDC[6*index+sec]->Fill(ztar);
if(fUseAngleCut){
if(fNumMods==0)
distTarMDC = sqrt(fTranslation->getX()*fTranslation->getX()+
fTranslation->getY()*fTranslation->getY()+
fTranslation->getZ()*fTranslation->getZ());
else
distTarMDC = sqrt(fTransLab.getX()*fTransLab.getX()+
fTransLab.getY()*fTransLab.getY()+
fTransLab.getZ()*fTransLab.getZ());
distAllowed = fabs(fAngleCut*distTarMDC);
distToModulePC=sqrt(aPoint.getX()*aPoint.getX()
+aPoint.getY()*aPoint.getY());
if(fAngleCut>0 && distToModulePC<distAllowed) ;
else if(fAngleCut<0 && distToModulePC>distAllowed) ;
else {
fTarCut[index]->Fill(ztar);
if(fNumMods==0){
fTarMDCCut[6*index+sec]->Fill(ztar);
}
}
}
canaux = ((aVectorLab.getX())/(aVectorLab.getY())) -
((aVectorLab.getY())/(aVectorLab.getX()));
myxtar = (aPointLab.getY()-
(aPointLab.getX()*(aVectorLab.getY())/
(aVectorLab.getX()))) / canaux;
myytar = (myxtar*(aVectorLab.getY())/(aVectorLab.getX())) +
(aPointLab.getY()-aPointLab.getX()*(aVectorLab.getY())/
(aVectorLab.getX()));
myztar = (myxtar*(aVectorLab.getZ())/(aVectorLab.getX())) +
(aPointLab.getZ()-aPointLab.getX()*(aVectorLab.getZ())/
(aVectorLab.getX()));
myrho = sqrt(myxtar*myxtar + myytar*myytar);
distZ = ((aPointLab.getX()*(aVectorLab.getY()))-
(aPointLab.getY()*(aVectorLab.getX()))) /
sqrt(((aVectorLab.getY())*(aVectorLab.getY())) +
((aVectorLab.getX())*(aVectorLab.getX())));
fDisZ[index]->Fill(distZ);
part1 = (-aPointLab.getX()*(aVectorLab.getY()))
- (-aPointLab.getY()*(aVectorLab.getX()));
part2 = (-aPointLab.getY()*(aVectorLab.getZ()))
- (-aPointLab.getZ()*(aVectorLab.getY()));
part3 = (-aPointLab.getZ()*(aVectorLab.getX()))
- (-aPointLab.getX()*(aVectorLab.getZ()));
numera = (part1*part1)+(part2*part2)+(part3*part3);
denomi = aVectorLab.getX()*aVectorLab.getX()
+ aVectorLab.getY()*aVectorLab.getY()
+ aVectorLab.getZ()*aVectorLab.getZ();
discenter = sqrt(numera/denomi);
fDisCenter[index]->Fill(discenter);
}
}
}
void HMdcGeomParF :: storeInFile(void)
{
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
Int_t modB = fLoc[2];
Int_t modC =-1;
Int_t modD =-1;
static Char_t newDirName[255];
if(fNumMods>3){
modC = fLoc[3];
modD = fLoc[4];
sprintf(newDirName,"%s%s%i%s%i%s%i%s%i%s%i","GeomParF_","S_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC,"_ModD_",modD);
}
if(fNumMods>2){
modC = fLoc[3];
sprintf(newDirName,"%s%s%i%s%i%s%i%s%i","GeomParF_","S_",sector,
"_ModA_",modA,"_ModB_",modB,"_ModC_",modC);
}
else if(fNumMods>1){
sprintf(newDirName,"%s%s%i%s%i%s%i","GeomParF_","S_",sector,
"_ModA_",modA,"_ModB_",modB);
}
else if(fNumMods==1) {
sprintf(newDirName,"%s%s%i%s%i","GeomParF_","S_",sector,
"_ModA_",modA);
}
else sprintf(newDirName,"%s%s%i","GeomParF_","_Mods_",modA);
fOutFile->cd(newDirName);
fOutFile->cd();
fOutFile->Write();
fOutFile->Close();
}
void HMdcGeomParF :: writeGeomParContainer(void){
Int_t sector = fLoc[0];
Int_t moduleA = fLoc[1];
Int_t moduleB = fLoc[2];
Int_t moduleC =-1;
Int_t moduleD =-1;
HGeomRotation rotA,rotB,rotC;
HGeomVector vectorA,vectorB,vectorC;
cout << endl << " ######## FINAL RESULT ######## "<< endl;
cout << " Sector: " << sector << " ModA: " << moduleA
<< " ModB: " << moduleB ;
cout << endl;
if(fNumMods>3){
moduleC = fLoc[3];
moduleD = fLoc[4];
cout << " ModC: " << moduleC;
cout << " ModD: " << moduleD << endl;
rotA = fRotLab * fRotMat[2];
vectorA = fRotLab * fTranslation[2] + fTransLab;
rotB = fRotLab * fRotMat[1];
vectorB = fRotLab * fTranslation[1] + fTransLab;
rotC = fRotLab * fRotMat[0];
vectorC = fRotLab * fTranslation[0] + fTransLab;
cout << "Params for module A: " << endl;
rotA.print();
vectorA.print();
cout << "Params for module B: " << endl;
rotB.print();
vectorB.print();
cout << "Params for module C: " << endl;
rotC.print();
vectorC.print();
cout << "Params for module D: " << endl;
fRotLab.print();
fTransLab.print();
fMdcGeomPar->getModule(sector,moduleB)
->getLabTransform().setRotMatrix(rotB);
fMdcGeomPar->getModule(sector,moduleB)
->getLabTransform().setTransVector(vectorB);
fMdcGeomPar->getModule(sector,moduleC)
->getLabTransform().setRotMatrix(rotC);
fMdcGeomPar->getModule(sector,moduleC)
->getLabTransform().setTransVector(vectorC);
fMdcGeomPar->getModule(sector,moduleD)
->getLabTransform().setRotMatrix(fRotLab);
fMdcGeomPar->getModule(sector,moduleD)
->getLabTransform().setTransVector(fTransLab);
}
if(fNumMods>2){
moduleC = fLoc[3];
cout << " ModC: " << moduleC << endl;
rotA = fRotLab * fRotMat[1];
vectorA = fRotLab * fTranslation[1] + fTransLab;
rotB = fRotLab * fRotMat[0];
vectorB = fRotLab * fTranslation[0] + fTransLab;
cout << "Params for module A: " << endl;
rotA.print();
vectorA.print();
cout << "Params for module B: " << endl;
rotB.print();
vectorB.print();
cout << "Params for module C: " << endl;
fRotLab.print();
fTransLab.print();
fMdcGeomPar->getModule(sector,moduleB)
->getLabTransform().setRotMatrix(rotB);
fMdcGeomPar->getModule(sector,moduleB)
->getLabTransform().setTransVector(vectorB);
fMdcGeomPar->getModule(sector,moduleC)
->getLabTransform().setRotMatrix(fRotLab);
fMdcGeomPar->getModule(sector,moduleC)
->getLabTransform().setTransVector(fTransLab);
}
else if(fNumMods>1){
rotA = fRotLab * fRotMat[0];
vectorA = fRotLab * fTranslation[0] + fTransLab;
fMdcGeomPar->getModule(sector,moduleB)
->getLabTransform().setRotMatrix(fRotLab);
fMdcGeomPar->getModule(sector,moduleB)
->getLabTransform().setTransVector(fTransLab);
}
else{
rotA = fRotLab;
vectorA = fTransLab;
}
if(fNumMods>0){
fMdcGeomPar->getModule(sector,moduleA)
->getLabTransform().setRotMatrix(rotA);
fMdcGeomPar->getModule(sector,moduleA)
->getLabTransform().setTransVector(vectorA);
}
if(fNumMods==2) {
cout << "Params for module A: " << endl;
rotA.print();
vectorA.print();
cout << "Params for module B: " << endl;
fRotLab.print();
fTransLab.print();
}
if(GP_DEBUG>1){
if(fMdcGeomPar->hasChanged()==kTRUE) cout << " Flag es kTRUE "<< endl;
else cout << " Flag es kFALSE "<< endl;
cout << "Input version[1] = " << fMdcGeomPar->getInputVersion(1)<< endl;
cout << "Input version[2] = " << fMdcGeomPar->getInputVersion(2)<< endl;
}
fMdcGeomPar->setChanged();
Int_t v = fMdcGeomPar->getInputVersion(1);
if (v>0) fMdcGeomPar->setInputVersion(++v,1);
else {
v=fMdcGeomPar->getInputVersion(2);
fMdcGeomPar->setInputVersion(++v,2);
}
if(GP_DEBUG>1){
if(fMdcGeomPar->hasChanged()==kTRUE) cout << " Ahora flag es kTRUE "<< endl;
else cout << " Ahora flag es kFALSE "<< endl;
cout << "Input version[1] = " << fMdcGeomPar->getInputVersion(1)<< endl;
cout << "Input version[2] = " << fMdcGeomPar->getInputVersion(2)<< endl;
}
}
void HMdcGeomParF :: fillRotMatrix(Int_t i,Float_t prim,
Float_t segu, Float_t terc){
const Double_t rad2deg = 57.29577951308;
fRotMat[i].setEulerAngles(prim*rad2deg,segu*rad2deg,terc*rad2deg);
}
void HMdcGeomParF :: fillTranslation(Int_t i,Float_t x,Float_t y, Float_t z){
fTranslation[i].setX(x);
fTranslation[i].setY(y);
fTranslation[i].setZ(z);
}
void HMdcGeomParF :: fillRotLab(Float_t prim,Float_t segu, Float_t terc){
const Double_t rad2deg = 57.29577951308;
fRotLab.setEulerAngles(prim*rad2deg,segu*rad2deg,terc*rad2deg);
}
void HMdcGeomParF :: fillTransLab(Float_t x,Float_t y, Float_t z){
fTransLab.setX(x);
fTransLab.setY(y);
fTransLab.setZ(z);
}
void HMdcGeomParF :: setEulerAngles(Int_t ind, Float_t f,Float_t s, Float_t t){
fEuler[ind].setX(f);
fEuler[ind].setY(s);
fEuler[ind].setZ(t);
}
void HMdcGeomParF :: setEulerLabAngles(Float_t f,Float_t s, Float_t t){
fEulerLab.setX(f);
fEulerLab.setY(s);
fEulerLab.setZ(t);
}
void HMdcGeomParF :: setSearchLimits(Float_t x, Float_t y){
fZLoCut = x;
fZHiCut = y;
}
void HMdcGeomParF :: setIterCriteria(Float_t cri){
fIterCriteria= cri;
}
void HMdcGeomParF :: setSteps(Float_t s0,Float_t s1,Float_t s2,
Float_t s3, Float_t s4, Float_t s5){
fSteps[0]= s0;
fSteps[1]= s1;
fSteps[2]= s2;
fSteps[3]= s3;
fSteps[4]= s4;
fSteps[5]= s5;
cout << "Steps in the minimization adjusted to " << s0 << ", "
<< s1 << ", " << s2 << ", " << s3
<< ", " << s4 << ", " << s5 << endl;
}
void HMdcGeomParF :: setLimits(Float_t l0,Float_t l1,Float_t l2,
Float_t l3, Float_t l4, Float_t l5){
fLimits[0]= l0;
fLimits[1]= l1;
fLimits[2]= l2;
fLimits[3]= l3;
fLimits[4]= l4;
fLimits[5]= l5;
}
void HMdcGeomParF :: minfit(Int_t fix, Float_t fE, Float_t sE,
Float_t tE, Float_t fT, Float_t sT, Float_t tT){
Double_t args[8];
Int_t err = 0;
Float_t* limitL;
Float_t* limitH;
limitL = new Float_t[6];
limitH = new Float_t[6];
Double_t start_val[]={fE, sE, tE, fT, sT, tT};
for(Int_t i=0;i<6;i++){
if(fLimits[i]==0){
limitL[i]=0;
limitH[i]=0;
}
else {
limitL[i]=start_val[i]-fLimits[i];
limitH[i]=start_val[i]+fLimits[i];
cout << " LIMITS IN THE MINIMIZATION " << endl;
cout << " (from 0 to 5) Par " << i << " between "
<< limitL[i] << " and " << limitH[i] << endl;
}
}
TMinuit *minuit=new TMinuit(6);
minuit->SetFCN(fcnGP);
minuit->SetObjectFit(this);
if(GP_DEBUG>0){
cout << "HMdcGeomParF::minfit()" <<endl;
cout << "Start Values for initialization: " << start_val[0] << ","
<< start_val[1] << "," << start_val[2] << "," << start_val[3]
<< "," << start_val[4] << "," << start_val[5] << endl;
}
minuit->mnparm(0,"par0",start_val[0],fSteps[0],limitL[0],limitH[0],err);
minuit->mnparm(1,"par1",start_val[1],fSteps[1],limitL[1],limitH[1],err);
minuit->mnparm(2,"par2",start_val[2],fSteps[2],limitL[2],limitH[2],err);
minuit->mnparm(3,"par3",start_val[3],fSteps[3],limitL[3],limitH[3],err);
minuit->mnparm(4,"par4",start_val[4],fSteps[4],limitL[4],limitH[4],err);
minuit->mnparm(5,"par5",start_val[5],fSteps[5],limitL[5],limitH[5],err);
minuit->FixParameter(5);
if(fix>0 && fix<7) minuit->FixParameter(fix+1);
if(fix == 30) minuit->FixParameter(0);
if(fix == 30) minuit->FixParameter(1);
if(fix == 30) minuit->FixParameter(2);
if(fix == 20) minuit->FixParameter(3);
if(fix == 20) minuit->FixParameter(4);
if(fix == 20) minuit->FixParameter(5);
if(GP_DEBUG<3){
minuit->SetPrintLevel(-1);
}
minuit->mnexcm("MIGRAD",args,0,err);
Double_t parresult[6];
minuit->GetParameter(0,parresult[0],fErrorLab[0]);
minuit->GetParameter(1,parresult[1],fErrorLab[1]);
minuit->GetParameter(2,parresult[2],fErrorLab[2]);
minuit->GetParameter(3,parresult[3],fErrorLab[3]);
minuit->GetParameter(4,parresult[4],fErrorLab[4]);
minuit->GetParameter(5,parresult[5],fErrorLab[5]);
fEulerLab.setX(parresult[0]);
fEulerLab.setY(parresult[1]);
fEulerLab.setZ(parresult[2]);
fTransLab.setX(parresult[3]);
fTransLab.setY(parresult[4]);
fTransLab.setZ(parresult[5]);
fillRotLab(fEulerLab(0),fEulerLab(1),fEulerLab(2));
if (err != 0) cout << endl <<"MINIMIZATION EXITED WITH ERROR "
<< err << endl;
}
void fcnGP(Int_t &npar, Double_t *gin, Double_t &f,
Double_t *par, Int_t iflag){
Double_t chisq = 0.;
HGeomRotation rotlab;
Double_t translab[3];
HGeomRotation rotrel;
HGeomVector transrel;
Float_t pxa, pya, ps0a, ps1a, pxb, pyb, ps0b, ps1b;
Float_t fxalab, fyalab, fzalab, fxblab, fyblab, fzblab;
Float_t xanew, yanew, zanew;
Double_t prim, segu, terc;
Float_t xDir,yDir,aux;
prim = par[0];
segu = par[1];
terc = par[2];
translab[0] = par[3];
translab[1] = par[4];
translab[2] = par[5];
if (GP_DEBUG>2){
cout << "HMdcGeomParF::fcnGP() Parameters: " << par[0] << ","
<< par[1] << "," << par[2] << "," << par[3]
<< "," << par[4] << "," << par[5] << endl;
}
rotlab.setEulerAngles(prim*180./TMath::Pi(),
segu*180./TMath::Pi(),
terc*180./TMath::Pi());
TTree* pData;
HMdcGeomParF* pGeomParF;
TClonesArray* theHits;
theHits = new TClonesArray("HMdcHit",2);
pGeomParF = (HMdcGeomParF*)(gMinuit->GetObjectFit());
pData = pGeomParF->getTree();
rotrel = pGeomParF->getRotMatrix(0);
transrel = pGeomParF->getTranslation(0);
TBranch *branch = pData->GetBranch("hits");
branch->SetAddress(&theHits);
Stat_t entries = pData->GetEntries();
TH1F *targets =new TH1F("que","pasa",800,-200,200);
TF1 *f1 = new TF1("f1","gaus",-100,100);
HMdcHit* hitA;
HMdcHit* hitB;
for (Int_t i=0;i<entries;i++) {
theHits->Clear();
pData->GetEntry(i);
hitB = (HMdcHit*) theHits->At(1);
hitA = (HMdcHit*) theHits->At(0);
pxa = hitA->getX();
pya = hitA->getY();
xDir = hitA->getXDir();
yDir = hitA->getYDir();
aux = sqrt(1 - xDir * xDir - yDir * yDir);
if(aux == 0.) {
ps0a=1;
ps1a=1;
cout<< "ERROR #1 in HMdcGeomParF::fcnGP().";
}
else{
ps0a = xDir/aux;
ps1a = yDir/aux;
}
pxb = hitB->getX();
pyb = hitB->getY();
xDir = hitB->getXDir();
yDir = hitB->getYDir();
aux = sqrt(1 - xDir * xDir - yDir * yDir);
if(aux == 0.) {
ps0b=1;
ps1b=1;
cout<< "ERROR #2 in HMdcGeomParF::fcnGP().";
}
else{
ps0b = xDir/aux;
ps1b = yDir/aux;
}
xanew = rotrel(0)*pxa+rotrel(1)*pya+transrel(0);
yanew = rotrel(3)*pxa+rotrel(4)*pya+transrel(1);
zanew = rotrel(6)*pxa+rotrel(7)*pya+transrel(2);
fxalab = rotlab(0)*xanew+rotlab(1)*yanew+rotlab(2)*zanew+translab[0];
fyalab = rotlab(3)*xanew+rotlab(4)*yanew+rotlab(5)*zanew+translab[1];
fzalab = rotlab(6)*xanew+rotlab(7)*yanew+rotlab(8)*zanew+translab[2];
fxblab = rotlab(0)*pxb+rotlab(1)*pyb+translab[0];
fyblab = rotlab(3)*pxb+rotlab(4)*pyb+translab[1];
fzblab = rotlab(6)*pxb+rotlab(7)*pyb+translab[2];
Float_t distZ = ( (fxalab*(fyblab-fyalab))-(fyalab*(fxblab-fxalab)) ) /
sqrt( ((fyblab-fyalab)*(fyblab-fyalab)) +
((fxblab-fxalab)*(fxblab-fxalab)) );
if(GP_DEBUG >3){
cout << " ++++++++ VALUES IN fcnGP() +++++++++ " << endl;
cout << "HITA: " << pxa << ", " << pya << ", "
<< ps0a << ", " << ps1a << endl;
cout << "HITB: " << pxb << ", " << pyb << ", "
<< ps0b << ", " << ps1b << endl;
cout << "HITA IN MDC B CS: " << xanew << ", " << yanew << ", "
<< zanew << endl;
cout << "HITA IN LAB CS: " << fxalab << ", " << fyalab << ", "
<< fzalab << endl;
cout << "HITB IN LAB CS: " << fxblab << ", " << fyblab << ", "
<< fzblab << endl;
cout << "Distance: " << distZ << endl;
}
Float_t xcZ = fxalab-(fxblab-fxalab)*fzalab/(fzblab-fzalab);
Float_t ycZ = fyalab-(fyblab-fyalab)*fzalab/(fzblab-fzalab);
Float_t phi = atan2(fyblab-fyalab,fxblab-fxalab);
Float_t theta = acos((fzblab-fzalab)/sqrt((fxblab-fxalab)*(fxblab-fxalab)+
(fyblab-fyalab)*(fyblab-fyalab)+
(fzblab-fzalab)*(fzblab-fzalab)));
Float_t ztar = -(ycZ * sin(phi) + xcZ*cos(phi))*cos(theta)/sin(theta);
targets->Fill(ztar);
}
targets->Fit("f1","RQN");
Float_t fitPar1 = f1->GetParameter(1);
f = fitPar1;
if(GP_DEBUG>2){
cout << "chisqr= " << chisq << " out of " << entries
<< " combinations."<< endl;
}
}
void HMdcGeomParF :: findZComponent(void)
{
HGeomVector a,b,ainb,alab,blab;
Float_t xcZ, ycZ;
Float_t phi, theta,ztar, rtar, xtar, ytar;
Int_t sector = fLoc[0];
Int_t modA = fLoc[1];
Int_t modB = fLoc[2];
Char_t title[50], tmp[50];
sprintf(title,"%s%i%s%i%s%i","Sector_",sector,"_ModA_",modA,"_ModB_",modB);
sprintf(tmp,"%s%s%i%s%i%s%i","Mtarget","_Sector_",sector,"_ModA_",modA,"_ModB_",modB);
TH1F *targets2 =new TH1F(tmp,title,800,-200,200);
TBranch *branch = fTree->GetBranch("hits");
branch->SetAddress(&fHits);
Stat_t entries = fTree->GetEntries();
HMdcHit* hitA;
HMdcHit* hitB;
for (Int_t i=0;i<entries;i++) {
fHits->Clear();
fTree->GetEntry(i);
hitB = (HMdcHit*) fHits->At(1);
hitA = (HMdcHit*) fHits->At(0);
a.setX(hitA->getX());
a.setY(hitA->getY());
b.setX(hitB->getX());
b.setY(hitB->getY());
a.setZ(0.);
b.setZ(0.);
ainb = fRotMat[0]*a+fTranslation[0];
alab = fRotLab*ainb+fTransLab;
blab = fRotLab*b+fTransLab;
xcZ = alab.getX()-(blab.getX()-alab.getX())*
alab.getZ()/(blab.getZ()-alab.getZ());
ycZ = alab.getY()-(blab.getY()-alab.getY())*
alab.getZ()/(blab.getZ()-alab.getZ());
phi = atan2(blab.getY()-alab.getY(),blab.getX()-alab.getX());
theta = acos((blab.getZ()-alab.getZ())/
sqrt((blab.getX()-alab.getX())*(blab.getX()-alab.getX())+
(blab.getY()-alab.getY())*(blab.getY()-alab.getY())+
(blab.getZ()-alab.getZ())*(blab.getZ()-alab.getZ())));
ztar = -(ycZ * sin(phi) + xcZ*cos(phi))*cos(theta)/sin(theta);
xtar = ((blab.getX()-alab.getX())*(ztar-alab.getZ())/
(blab.getZ()-alab.getZ())) + alab.getX();
ytar = ((blab.getY()-alab.getY())*(ztar-alab.getZ())/
(blab.getZ()-alab.getZ())) + alab.getY();
rtar = ycZ * cos(phi) - xcZ*sin(phi);
if((xtar*xtar + ytar*ytar)<10 ) targets2->Fill(ztar);
}
TF1 *f1 = new TF1("f1","gaus",-200,200);
targets2->Fit("f1","RQN");
Float_t fitPar1 = f1->GetParameter(1);
fTransLab.setZ(fTransLab(2)-fitPar1);
}
Last change: Sat May 22 13:02:09 2010
Last generated: 2010-05-22 13:02
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.