File indexing completed on 2025-09-18 08:17:26
0001 #include "TreeBuilder.hxx"
0002 #include "Particle.hxx"
0003 #include "Constants.hxx"
0004 #include "DEMPEvent.hxx"
0005
0006 #include <iostream>
0007 #include <vector>
0008 #include <stdio.h>
0009 #include <string.h>
0010 #include "json/json.h"
0011
0012 using namespace std;
0013
0014 TreeBuilder::TreeBuilder(const char * file_name, const char * name) {
0015
0016 extern Json::Value obj;
0017
0018 tree_name = name;
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 File_Out = new TFile(file_name, "RECREATE");
0029 Tree_Out = new TTree(tree_name, tree_name);
0030
0031 Tree_Out->SetAutoSave();
0032
0033 nParticles = 0;
0034
0035 nVars = 8;
0036 }
0037
0038 void TreeBuilder::AddParticle(Particle * p)
0039 {
0040 ParticleList.push_back(p);
0041 vector< double* >* TempVec = new vector<double*>(nVars);
0042
0043
0044 for (int i = 0; i<nVars; i++)
0045 TempVec->at(i) = new double();
0046
0047 PropList.push_back(TempVec);
0048
0049 char * p_name = p->GetName();
0050 char b_name[100];
0051 char l_list[100];
0052
0053 strcpy(b_name, p_name);
0054 strcat(b_name, "_pid");
0055 strcpy(l_list, b_name);
0056 strcat(l_list, "/D");
0057 Tree_Out->Branch(b_name,TempVec->at(0),l_list);
0058
0059 strcpy(b_name, p_name);
0060 strcat(b_name, "_Px");
0061 strcpy(l_list, b_name);
0062 strcat(l_list, "/D");
0063 Tree_Out->Branch(b_name,TempVec->at(1),l_list);
0064
0065 strcpy(b_name, p_name);
0066 strcat(b_name, "_Py");
0067 strcpy(l_list, b_name);
0068 strcat(l_list, "/D");
0069 Tree_Out->Branch(b_name,TempVec->at(2),l_list);
0070
0071 strcpy(b_name, p_name);
0072 strcat(b_name, "_Pz");
0073 strcpy(l_list, b_name);
0074 strcat(l_list, "/D");
0075 Tree_Out->Branch(b_name,TempVec->at(3),l_list);
0076
0077
0078 strcpy(b_name, p_name);
0079 strcat(b_name, "_E");
0080 strcpy(l_list, b_name);
0081 strcat(l_list, "/D");
0082 Tree_Out->Branch(b_name,TempVec->at(4),l_list);
0083
0084 strcpy(b_name, p_name);
0085 strcat(b_name, "_theta");
0086 strcpy(l_list, b_name);
0087 strcat(l_list, "/D");
0088 Tree_Out->Branch(b_name,TempVec->at(5),l_list);
0089
0090 strcpy(b_name, p_name);
0091 strcat(b_name, "_phi");
0092 strcpy(l_list, b_name);
0093 strcat(l_list, "/D");
0094 Tree_Out->Branch(b_name,TempVec->at(6),l_list);
0095
0096 strcpy(b_name, p_name);
0097 strcat(b_name, "_P");
0098 strcpy(l_list, b_name);
0099 strcat(l_list, "/D");
0100 Tree_Out->Branch(b_name,TempVec->at(7),l_list);
0101
0102 nParticles++;
0103
0104
0105
0106
0107 }
0108
0109 void TreeBuilder::Fill()
0110 {
0111 Retrieve();
0112 Tree_Out->Fill();
0113 }
0114
0115
0116
0117
0118 void TreeBuilder::Retrieve()
0119 {
0120 for (int i = 0; i < nParticles; i++){
0121
0122 *PropList.at(i)->at(0) = (double)ParticleList.at(i)->GetPid();
0123 *PropList.at(i)->at(1) = ParticleList.at(i)->Px()/1000;
0124 *PropList.at(i)->at(2) = ParticleList.at(i)->Py()/1000;
0125 *PropList.at(i)->at(3) = ParticleList.at(i)->Pz()/1000;
0126 *PropList.at(i)->at(4) = ParticleList.at(i)->E()/1000;
0127 *PropList.at(i)->at(5) = ParticleList.at(i)->Theta()*constants::DEG;
0128 *PropList.at(i)->at(6) = ParticleList.at(i)->Phi()*constants::DEG;
0129 *PropList.at(i)->at(7) = ParticleList.at(i)->P()/1000;
0130
0131 }
0132 }
0133
0134 void TreeBuilder::Save()
0135 {
0136 Tree_Out->AutoSave();
0137
0138 }
0139
0140 void TreeBuilder::AddDouble(double* x, const char* name)
0141 {
0142 char b_name[100];
0143 char l_list[100];
0144
0145 strcpy(b_name, name);
0146 strcpy(l_list, name);
0147 strcat(l_list,"/D");
0148
0149 Tree_Out->Branch(b_name, x, l_list);
0150
0151 }
0152
0153 void TreeBuilder::AddEvent(DEMPEvent * event)
0154 {
0155 this->AddParticle(event->BeamElec);
0156 this->AddParticle(event->ProdPion);
0157 this->AddParticle(event->ProdProt);
0158 this->AddParticle(event->ScatElec);
0159 this->AddParticle(event->TargNeut);
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 }