Ejemplo n.º 1
0
//=============================================================================
// GetStartPosition
// is_vertex must be "true" when the vert is muon vertex
// is_vertex must be "false" when the vert is for reference
//=============================================================================
bool HTBlob::GetStartPosition( Minerva::IDBlob *idBlob, Gaudi::XYZPoint vert, bool is_vertex ) const
{

    debug() << " HTBlob::GetStartPosition " << endmsg;

    TH2D *hU = new TH2D ( "hU", "hU", 480,4510,9990,127,-1075,1075);
    TH2D *hV = new TH2D ( "hV", "hV", 480,4510,9990,127,-1075,1075);

    if ( is_vertex ){	
        hU->Fill( vert.z(), m_mathTool->calcUfromXY(vert.x(), vert.y()), 20 );
        hV->Fill( vert.z(), m_mathTool->calcVfromXY(vert.x(), vert.y()), 20);
    }

    SmartRefVector<Minerva::IDCluster> idClusters = idBlob->clusters();
    SmartRefVector<Minerva::IDCluster>::iterator itClus = idClusters.begin();
    Gaudi::XYZPoint pos;

    double Dx = 0.0;
    double Dz = 0.0;
    double distance = 0.0;

    double vt_x = -9999;
    double vt_u;
    double vt_v;
    double vt_z = -9999;

    double vtX = -9999;
    double vtY = -9999;
    double vtZ = -9999;


    double dis_min_x = 10000;
    double xu[2] = {0.0};
    double xv[2] = {0.0};
    double zu[2] = {0.0};
    double zv[2] = {0.0}; // to NC Pi0 events, there is no muon vertex

    int countu = 0;
    int countv = 0; // to NC Pi0 events, there is no muon vertex

    for ( ; itClus != idClusters.end(); itClus++ ){

        Dx = (*itClus)->position() - vert.x(); 
        Dz = (*itClus)->z() - vert.z();// to avoid 0

        if( (*itClus)->view()== Minerva::IDCluster::X ) {
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if (distance <= dis_min_x  ) {
                dis_min_x = distance;
                vt_x = (*itClus)->position();
                vt_z = (*itClus)->z();
            }
        }

        if( (*itClus)->view()== Minerva::IDCluster::U ){
            debug() <<  " StartPoint U view, pe " << (*itClus)->pe() << "; z = " << (*itClus)->z()
                << "; coord " << (*itClus)->position() << endmsg;
            Dx = (*itClus)->position() - m_mathTool->calcUfromXY(vert.x(),vert.y());
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if ( is_vertex ) {
                hU->Fill( (*itClus)->z()-12,(*itClus)->tpos1(), (*itClus)->pe()/distance );
                hU->Fill( (*itClus)->z()+12,(*itClus)->tpos2(), (*itClus)->pe()/distance );
            }
            hU->Fill( (*itClus)->z(),(*itClus)->position(), (*itClus)->pe()/distance );
            if ( countu < 2 ){
                zu[countu] = (*itClus)->z();
                xu[countu] = (*itClus)->position();
                countu++;
            }
        }

        if( (*itClus)->view()== Minerva::IDCluster::V ){
            debug() <<  " StartPoint V view, pe " << (*itClus)->pe() << "; z = " << (*itClus)->z()
                << "; coord " << (*itClus)->position() << endmsg;
            Dx = (*itClus)->position() -  m_mathTool->calcVfromXY(vert.x(),vert.y());
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if ( is_vertex ){
                hV->Fill( (*itClus)->z()-12,(*itClus)->tpos1(), (*itClus)->pe()/distance );
                hV->Fill( (*itClus)->z()+12,(*itClus)->tpos2(), (*itClus)->pe()/distance );
            }
            hV->Fill( (*itClus)->z(),(*itClus)->position(), (*itClus)->pe()/distance );
            if ( countv < 2 ){
                zv[countu] = (*itClus)->z();
                xv[countu] = (*itClus)->position();
                countv++;
            }
        }
    }

    TF1 *fU, *fV;

    double slopeu = -9999;
    double slopev = -9999;
    double bu = -9999;
    double bv = -9999;

    bool goodFit_U = false;
    bool goodFit_V = false;
    if ( hU->GetEntries() > 3 ){
        hU->Fit("pol1","Q0");
        fU = hU->GetFunction("pol1");
        bu = fU->GetParameter(0);
        slopeu = fU->GetParameter(1);
        goodFit_U = true;

        delete fU;
    }
    else if ( hU->GetEntries() == 2 ){ // to deal with 2 clusters on NCPi0
        if ( zu[0] > zu[1] ){
            slopeu = (xu[0] - xu[1]) / (zu[0] - zu[1]);
            bu = xu[1] - zu[1]*slopeu;
            goodFit_U = true;
        }
        else if (zu[0] < zu[1] ) {
            slopeu = (xu[1] - xu[0]) / (zu[1] - zu[0]);
            bu = xu[0] - zu[0]*slopeu;
            goodFit_U = true;
        }
    }

    if ( hV->GetEntries() > 3 ){
        hV->Fit("pol1","Q0");
        fV = hV->GetFunction("pol1");
        bv = fV->GetParameter(0);
        slopev = fV->GetParameter(1);
        goodFit_V = true;

        delete fV;
    }
    else if ( hV->GetEntries() == 2 ){ // to deal with 2 clusters on NCPi0
        if ( zv[0] > zv[1] ){
            slopev = (xv[0] - xv[1]) / (zv[0] - zv[1]);
            bv = xv[1] - zv[1]*slopeu;
            goodFit_V = true;
        }
        else if (zu[1] < zu[0] ) { /* Trung: why zu instead of zv? */
            slopev = (xv[1] - xv[0]) / (zv[1] - zv[0]);
            bv = xv[0] - zv[0]*slopev;
            goodFit_V = true;
        }
    }

    vtX = vt_x;
    vtZ = vt_z;
    debug() << " Startpoint, slope u " << slopeu << " slope v" << slopev << endmsg;
    if ( goodFit_U && goodFit_V ){ 	     //3D blobs
        vt_u = slopeu*vt_z + bu;
        vt_v = slopev*vt_z + bv;
        vtY = m_mathTool->calcYfromUV(vt_u,vt_v);
    }
    else if ( goodFit_U ) {                  //2D blobs 
        vt_u = slopeu*vt_z + bu;
        vtY = (vt_x*.5 - vt_u)*2/sqrt(3);    //calcYfromXU?
    }
    else if ( goodFit_V ) { 	             //2D blobs 
        vt_v = slopev*vt_z + bv;
        vtY = (vt_v - vt_x*.5)*2/sqrt(3);    //calcYfromXV?
    }

    pos.SetX(vtX); pos.SetY(vtY); pos.SetZ(vtZ);

    idBlob->setStartPoint(pos);

    debug() << " Setting StarPoint " << pos << " Blob" << idBlob << endmsg;

    delete hU;
    delete hV;

    if (goodFit_U || goodFit_V) return true;

    return false;

}