AGAPRO_TB_Detector.cpp 5.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/***************************************************************************
 *   Copyright (C) 2018 by Jeremie Dudouet                                 *
 *   jeremie.dudouet(AT)csnsm.in2p3.fr                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef AGAPRO_TB_Detector
#include "AGAPRO_TB_Detector.h"
#endif

25 26
#include "TGeoMatrix.h"

27 28 29
using namespace AGAPRO;

TB_Detector::TB_Detector(TString name, TString ADFKey) :
Jérémie Dudouet's avatar
Jérémie Dudouet committed
30
    gActualClass("TB_Detector"),
31
    Log(Form("Log_%s",name.Data())),
Jérémie Dudouet's avatar
Jérémie Dudouet committed
32 33
    fName(name),
    fTriggerName(ADFKey)
34 35 36 37 38 39 40 41
{

}

TB_Detector::~TB_Detector()
{
    if(fCompFrame)
        delete fCompFrame;
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    if(fSFrame)
        delete fSFrame;
    if(fMatrixList)
        delete fMatrixList;
}


TGeoCombiTrans* TB_Detector::FillTransMatrix(Double_t* trans, Double_t* rot)
{
    TGeoRotation rotation;  rotation.SetMatrix(rot);

    TGeoTranslation translation;
    translation.SetTranslation(trans[0], trans[1], trans[2]);

    return new TGeoCombiTrans(translation, rotation);
}

void TB_Detector::Local2Global(Int_t detID,
                                    Double_t xl, Double_t yl, Double_t zl,
                                    Double_t& xg, Double_t& yg, Double_t& zg)
{
    Log.ClearMessage();
    Log.GetProcessName() = gActualClass;
    Log.SetProcessMethod("Local2Global()");

    Double_t local[3]  = {xl, yl, zl};
    Double_t global[3] = {0., 0., 0.};

    if (detID < 0 || detID > 180) {
        Log << error << "Wrong detector id number" << dolog;
        return;
    }

    if(fMatrixList) {
        TGeoCombiTrans* mat = static_cast<TGeoCombiTrans*> ( fMatrixList->At(detID) );
        mat->LocalToMaster(local, global);
    }

    xg = global[0];
    yg = global[1];
    zg = global[2];
}

bool TB_Detector::ReadTransformation()
{
    Log.ClearMessage();
    Log.GetProcessName() = gActualClass;
    Log.SetProcessMethod("ReadTransformation()");

    Log << info << " Ge positions extracted from CrystalPositionLookUpTable " << nline;

    TString FileName = fConfPath + "/CrystalPositionLookUpTable";

    ifstream in(FileName, ios::in);
    if (!in) {
        Log << error << Form("file %s not found\n", FileName.Data()) << dolog;
        return false;
    }

    fMatrixList = new TObjArray(180);
    fMatrixList->SetOwner();

    Int_t nd, k;
    Double_t x,y,z;

    Double_t trans[3];
    Double_t rot[9];
    Char_t line[255];

    while ( !in.eof() ) {

        in.getline(line,255);

        if((((TString)line)==""))
            continue;

        if(sscanf(line, "%d %d %lf %lf %lf", &nd, &k, &x, &y, &z) != 5) {
            Log << error << "a Problem reading translation factors" << dolog;

            cin.get();
            return false;
        }
        trans[0] = x; trans[1] = y, trans[2] = z;

        if (nd > 180) {
            Log << error <<   Form("Id %d too large, max: %d\n", nd, 180) << dolog;
            return false;
        }

        in.getline(line,255);
        if(sscanf(line, "%d  %lf %lf %lf", &k, &x, &y, &z) != 4) {
            Log << error << Form("b Problem reading 1st rotation factors for id %d\n", nd) << dolog;
            return false;
        }
        rot[0] = x; rot[1] = y; rot[2] = z;

        in.getline(line,255);
        if(sscanf(line, "%d  %lf %lf %lf", &k, &x, &y, &z) != 4) {
            Log << error << Form("c Problem reading 2nd rotation factors for id %d\n", nd) << dolog;
            return false;
        }
        rot[3] = x; rot[4] = y; rot[5] = z;

        in.getline(line,255);
        if(sscanf(line, "%d  %lf %lf %lf", &k, &x, &y, &z) != 4) {
            Log << error << Form("d Problem reading 3rd rotation factors for id %d\n", nd) << dolog;
            return false;
        }
        rot[6] = x; rot[7] = y; rot[8] = z;

        // add matrix for the given id
        if (fMatrixList->At(nd)) {
            Log << error << Form("Matrix transformation already exist for id %d\n", nd) << dolog;
            return false;
        } else
            fMatrixList->AddAt( FillTransMatrix(trans, rot), nd );
    }

    in.close( );

    Log << dolog;
J. Dudouet's avatar
J. Dudouet committed
163 164

    return true;
165
}