10 #include "FairRootManager.h"
12 #include "TClonesArray.h"
14 #include "TMultiLayerPerceptron.h"
36 , fTRDGeometryType(
"h++") {}
44 string fileName = string(gSystem->Getenv(
"VMCWORKDIR"));
45 vector<string> weightsFilesANN;
49 <<
" is wrong geometry type." << endl;
54 for (
int i = 0;
i < 10;
i++) {
56 ss << fileName <<
"ann_weights_" << (
i + 1) <<
".txt";
57 weightsFilesANN.push_back(ss.str());
65 for (UInt_t
i = 0;
i < weightsFilesANN.size();
i++) {
66 ifstream myfile(weightsFilesANN[
i].c_str());
67 if (!myfile.is_open()) {
68 cout <<
"-E- CbmTrdSetTracksPidANN::Init: "
69 <<
"Could not open input file:" << weightsFilesANN[
i] << endl;
70 weightsFilesANN[
i] =
"";
80 TTree* simu =
new TTree(
"MonteCarlo",
"MontecarloData");
81 simu->Branch(
"x1", &inVector[0],
"x1/F");
82 simu->Branch(
"x2", &inVector[1],
"x2/F");
83 simu->Branch(
"x3", &inVector[2],
"x3/F");
84 simu->Branch(
"x4", &inVector[3],
"x4/F");
85 simu->Branch(
"x5", &inVector[4],
"x5/F");
86 simu->Branch(
"x6", &inVector[5],
"x6/F");
87 simu->Branch(
"x7", &inVector[6],
"x7/F");
88 simu->Branch(
"x8", &inVector[7],
"x8/F");
89 simu->Branch(
"x9", &inVector[8],
"x9/F");
90 simu->Branch(
"x10", &inVector[9],
"x10/F");
91 simu->Branch(
"xOut", &xOut,
"xOut/I");
95 for (
int iH = 0; iH < 10; iH++) {
96 if (weightsFilesANN[iH] ==
"") {
101 for (
int iL = 0; iL <= iH; iL++) {
102 if (iL != iH) ss <<
"x" << (iL + 1) <<
",";
103 int nofHidden = 2 * (iH + 1);
104 if (iL == iH) ss <<
"x" << (iL + 1) <<
":" << nofHidden <<
":xOut";
106 TMultiLayerPerceptron* ann =
107 new TMultiLayerPerceptron(ss.str().c_str(), simu);
108 ann->LoadWeights(weightsFilesANN[iH].c_str());
116 if (!
ReadData()) { Fatal(
"CbmTrdSetTracksPidANN::Init",
"ReadData"); }
118 FairRootManager* ioman = FairRootManager::Instance();
120 Fatal(
"CbmTrdSetTracksPidANN::Init",
"RootManager not instantised");
123 fTrackArray = (TClonesArray*) ioman->GetObject(
"TrdTrack");
125 Fatal(
"CbmTrdSetTracksPidANN::Init",
"No TrdTrack array");
128 fTrdHitArray = (TClonesArray*) ioman->GetObject(
"TrdHit");
130 Fatal(
"CbmTrdSetTracksPidANN::Init",
"No TrdHit array");
138 std::vector<Double_t> eLossVector;
140 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
144 for (Int_t iTRD = 0; iTRD < nofHits; iTRD++) {
147 eLossVector.push_back(trdHit->
GetELoss());
151 for (UInt_t j = 0; j < eLossVector.size(); j++) {
152 eLossVector[j] = eLossVector[j] * 1.e6;
155 sort(eLossVector.begin(), eLossVector.end());
156 for (UInt_t j = 0; j < eLossVector.size(); j++) {
157 eLossVector[j] = TMath::LandauI(eLossVector[j]);
161 Int_t iANN = nofHits - 1;
163 if (iANN < 0 || iANN >= 12 ||
fNN[iANN] == NULL) {
166 nnEval =
fNN[iANN]->Evaluate(0, &eLossVector[0]);
167 if (TMath::IsNaN(nnEval) == 1) {
168 cout <<
" -W- CbmTrdSetTracksPidANN: nnEval nan " << endl;