How run this macro?

Hello, I’ve this root file made by a Geant4 simulation (I’m not the author of the simulation).
I’ve to study the released energy by particles in calorimeters then I’m interested to the Ntupla
**LEMMA->Calo_EnDep**

In this file Calo_EnDep is just a vector…in the ROOT files regarding of the test beam, I have arrays of Calo_EnDep, for example in this file https://we.tl/t-2UfsLzNiud regarding of the test beam th Ntupla lemma->Calo_EnDep is an array Calo_EnDep[%d] and I can decide the subdetector to study (for example Calo_EnDep[0] is releated to a lead glass etc

indeed, in the same directory of the simulation I found this macro

Vector_To_Array.C (11.4 KB)

to convert Vector to array

so I tried to convert the vector to array replacing the line
TFile *file_input = new TFile( file_input_name );
by
TFile *file_input = new TFile( "C:/LemmaMC.root" );

and

TFile *file_output = new TFile( file_output_name, "RECREATE" );
by

TFile *file_output = new TFile( "C:/LemmaMC_array.root", "RECREATE" );

but if I try to run I get error

root [9] .x Vector_To_Array.c
input_line_121:2:2: error: no matching function for call to 'Vector_To_Array'
 Vector_To_Array() /* '.x' tries to invoke a function with the same name as the macro */
 ^~~~~~~~~~~~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.c:14:6: note: candidate function not viable: requires 2 arguments, but 0 were provided
void Vector_To_Array( TString file_input_name, TString file_output_name ) {

do you know how running it https://we.tl/t-IRV8E5tbYd ?
Thank you


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi @faca87,

Despite the fact that you changed file_input_name and file_output_name to string literals in your code, the entry point of your macro, i.e., the Vector_To_Array() function, still requires 2 arguments of type TString -see line 14-.

At this point, you can revert to using the provided parameters (instead of hardcoded strings) and invoke your macro as:

root [9] .x Vector_To_Array.c("C:/LemmaMC.root", "C:/LemmaMC_array.root")

Alternatively, you can stick to hardcoded string literals (maybe a bad practice, though), and change line 14 so that it looks as follows:

void Vector_To_Array() {

Cheers,
J.

Hello @jalopezg I tried:

  1. Writing

void Vector_To_Array( "C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root" ) {

TFile *file_input = new TFile( "C:/LemmaMC.root" );

TFile *file_output = new TFile( "C:/testbeam/LemmaMC_array.root", "RECREATE" );

but I get this error


C:\root_v6.25.01_master-build\macrorun>root -l
root [0] .x Vector_To_Array.c("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.c:15:6: error: variable has incomplete type 'void'
void Vector_To_Array( "C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root" ) {
     ^
C:\root_v6.25.01_master-build\macros\Vector_To_Array.c:15:76: error: expected ';' after top level declarator
void Vector_To_Array( "C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root" ) {
  1. Writing

void Vector_To_Array( ) {


TFile *file_input = new TFile( "C:/LemmaMC.root" );

TFile *file_output = new TFile( "C:/testbeam/LemmaMC_array.root", "RECREATE" );

and running

                                                                         ^
                                                                           ;
root [2] .x Vector_To_Array.c
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamX
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamY
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamZ
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamCX
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamCY
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamCZ
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamEne
Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<double>" by the branch: BeamPart
Error in <TTree::SetBranchAddress>: unknown branch -> xh
Error in <TTree::SetBranchAddress>: unknown branch -> yh
Error in <TTree::SetBranchAddress>: unknown branch -> zh
Event 0

==========================================
=============== STACKTRACE ===============
==========================================


================ Thread 0 ================
  libCling!TClingCallbacks::PrintStackTrace()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  0x64d03d ??
  0x3391037 ??
  libCling!cling::Value::isValid()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!TClingLookupHelper__ExistingTypeCheck()
  libCling!TCling::ProcessLine()
  libCling!TCling::ProcessLineSynch()
  libCore!TApplication::ExecuteFile()
  libCore!TApplication::ProcessFile()
  libCore!TApplication::ProcessLine()
  libRint!TRint::ProcessLineNr()
  libRint!TRint::HandleTermInput()
  libCore!TWinNTSystem::DispatchOneEvent()
  libCore!TSystem::InnerLoop()
  libCore!TSystem::Run()
  libCore!TApplication::Run()
  libRint!TRint::Run()
  root!Init_thread_footer()
  root!Init_thread_footer()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 1 ================
  ntdll!NtDelayExecution()
  KERNELBASE!Sleep()
  libCore!TWinNTSystem::TimerThread()
  libCore!TWinNTSystem::ThreadStub()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 2 ================
  win32u!NtUserGetMessage()
  libCore!TWinNTSystem::GetProcInfo()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 3 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 4 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 5 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

==========================================
============= END STACKTRACE =============
==========================================


C:\root_v6.25.01_master-build\macrorun>

you see…I get error in both the way…

Hi @faca87,

In reply to the first change your made, the code quoted below is not a legal C++ function declarator.

In my last post I meant that you could take one of two possible ways:

  1. Leave the function prototype (line 14) as
void Vector_To_Array( TString file_input_name, TString file_output_name ) {

and call the macro from the ROOT prompt as:

root [0] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
  1. Or change line 14 of Vector_To_Array.C to
void Vector_To_Array() {

and, provided that you hardcode the previous paths in lines 20 and 57, invoke the macro as:

root [0] .x Vector_To_Array.C

Now, to reply to the latest issue that you are having, it seems that the TTree schema of the input file does not match the branches that you are defining. Specifically, it seems that the expected type for several branches (e.g., BeamX, BeamY, …, and BeamPart) is vector<double> and not Double_t as it appears in lines 23-30. Additionally, it also seems that the branches xh, yh, and zh are not part of the input file.

Cheers,
J.

Hello @jalopezg

I replaced


 Double_t BeamX;                 tree_input->SetBranchAddress( "BeamX",     &BeamX     );
    Double_t BeamY;                 tree_input->SetBranchAddress( "BeamY",     &BeamY     );
    Double_t BeamZ;                 tree_input->SetBranchAddress( "BeamZ",     &BeamZ     );
    Double_t BeamCX;                tree_input->SetBranchAddress( "BeamCX",    &BeamCX    );
    Double_t BeamCY;                tree_input->SetBranchAddress( "BeamCY",    &BeamCY    );
    Double_t BeamCZ;                tree_input->SetBranchAddress( "BeamCZ",    &BeamCZ    );
    Double_t BeamEne;               tree_input->SetBranchAddress( "BeamEne",   &BeamEne   );
    Double_t BeamPart;              tree_input->SetBranchAddress( "BeamPart",  &BeamPart  );
    Double_t nhits;                 tree_input->SetBranchAddress( "nhits",     &nhits     );

by

vector<double> *BeamX;                 tree_input->SetBranchAddress( "BeamX",     &BeamX     );
    vector<double> *BeamY;                 tree_input->SetBranchAddress( "BeamY",     &BeamY     );
    vector<double> *BeamZ;                 tree_input->SetBranchAddress( "BeamZ",     &BeamZ     );
    vector<double> *BeamCX;                tree_input->SetBranchAddress( "BeamCX",    &BeamCX    );
    vector<double> *BeamCY;                tree_input->SetBranchAddress( "BeamCY",    &BeamCY    );
    vector<double> *BeamCZ;                tree_input->SetBranchAddress( "BeamCZ",    &BeamCZ    );
    vector<double> *BeamEne;               tree_input->SetBranchAddress( "BeamEne",   &BeamEne   );
    vector<double> *BeamPart;              tree_input->SetBranchAddress( "BeamPart",  &BeamPart  );
    vector<double> *nhits;                 tree_input->SetBranchAddress( "nhits",     &nhits     );

and because of in the root file I read there are xhit, yhit and zhit I replaced

   vector<double> *xh=0;           tree_input->SetBranchAddress( "xh",        &xh        );
    vector<double> *yh=0;           tree_input->SetBranchAddress( "yh",        &yh        );
    vector<double> *zh=0;           tree_input->SetBranchAddress( "zh",        &zh        );

by

vector<double> *xhit=0;           tree_input->SetBranchAddress( "xh",        &xhit        );
    vector<double> *yhit=0;           tree_input->SetBranchAddress( "yh",        &yhit        );
    vector<double> *zhit=0;           tree_input->SetBranchAddress( "zh",        &zhit        );

but I got this error

root [0] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:160:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamX_new    = BeamX;
                       ^~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:161:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamY_new    = BeamY;
                       ^~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:162:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamZ_new    = BeamZ;
                       ^~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:163:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamCX_new   = BeamCX;
                       ^~~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:164:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamCY_new   = BeamCY;
                       ^~~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:165:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamCZ_new   = BeamCZ;
                       ^~~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:166:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamEne_new  = BeamEne;
                       ^~~~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:167:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        BeamPart_new = BeamPart;
                       ^~~~~~~~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:168:24: error: assigning to 'Double_t' (aka 'double') from incompatible type 'vector<double> *'
        nhits_new    = nhits;
                       ^~~~~

then I replaced

 Double_t BeamX_new;                            tree_output->Branch( "BeamX",     &BeamX_new,    "BeamX/D"                                      );
    Double_t BeamY_new;                            tree_output->Branch( "BeamY",     &BeamY_new,    "BeamY/D"                                      );
    Double_t BeamZ_new;                            tree_output->Branch( "BeamZ",     &BeamZ_new,    "BeamZ/D"                                      );
    Double_t BeamCX_new;                           tree_output->Branch( "BeamCX",    &BeamCX_new,   "BeamCX/D"                                     );
    Double_t BeamCY_new;                           tree_output->Branch( "BeamCY",    &BeamCY_new,   "BeamCY/D"                                     );
    Double_t BeamCZ_new;                           tree_output->Branch( "BeamCZ",    &BeamCZ_new,   "BeamCZ/D"                                     );
    Double_t BeamEne_new;                          tree_output->Branch( "BeamEne",   &BeamEne_new,  "BeamEne/D"                                    );
    Double_t BeamPart_new;                         tree_output->Branch( "BeamPart",  &BeamPart_new, "BeamPart/D"                                   );
    Double_t nhits_new;                            tree_output->Branch( "nhits",     &nhits_new,    "nhits/D"                                      );

by

  vector<double> BeamX_new;                            tree_output->Branch( "BeamX",     &BeamX_new,    "BeamX/D"                                      );
    vector<double> BeamY_new;                            tree_output->Branch( "BeamY",     &BeamY_new,    "BeamY/D"                                      );
    vector<double> BeamZ_new;                            tree_output->Branch( "BeamZ",     &BeamZ_new,    "BeamZ/D"                                      );
    vector<double> BeamCX_new;                           tree_output->Branch( "BeamCX",    &BeamCX_new,   "BeamCX/D"                                     );
    vector<double> BeamCY_new;                           tree_output->Branch( "BeamCY",    &BeamCY_new,   "BeamCY/D"                                     );
    vector<double> BeamCZ_new;                           tree_output->Branch( "BeamCZ",    &BeamCZ_new,   "BeamCZ/D"                                     );
   vector<double> BeamEne_new;                          tree_output->Branch( "BeamEne",   &BeamEne_new,  "BeamEne/D"                                    );
    vector<double> BeamPart_new;                         tree_output->Branch( "BeamPart",  &BeamPart_new, "BeamPart/D"                                   );
    vector<double> nhits_new;                            tree_output->Branch( "nhits",     &nhits_new,    "nhits/D"                                      );

buy I get this big error

root [0] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:160:22: error: no viable overloaded '='
        BeamX_new    = BeamX;
        ~~~~~~~~~    ^ ~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:161:22: error: no viable overloaded '='
        BeamY_new    = BeamY;
        ~~~~~~~~~    ^ ~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:162:22: error: no viable overloaded '='
        BeamZ_new    = BeamZ;
        ~~~~~~~~~    ^ ~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:163:22: error: no viable overloaded '='
        BeamCX_new   = BeamCX;
        ~~~~~~~~~~   ^ ~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:164:22: error: no viable overloaded '='
        BeamCY_new   = BeamCY;
        ~~~~~~~~~~   ^ ~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:165:22: error: no viable overloaded '='
        BeamCZ_new   = BeamCZ;
        ~~~~~~~~~~   ^ ~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:166:22: error: no viable overloaded '='
        BeamEne_new  = BeamEne;
        ~~~~~~~~~~~  ^ ~~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:167:22: error: no viable overloaded '='
        BeamPart_new = BeamPart;
        ~~~~~~~~~~~~ ^ ~~~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:168:22: error: no viable overloaded '='
        nhits_new    = nhits;
        ~~~~~~~~~    ^ ~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:671:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(vector&& _Right) noexcept(noexcept(_Move_assign(_Right, _Choose_pocma<_Alty>{}))) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1174:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'const std::vector<double,
      std::allocator<double> >' for 1st argument; dereference the argument with *
    vector& operator=(const vector& _Right) {
            ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vector:1182:13: note: candidate function not viable: no known conversion from 'vector<double> *' to 'initializer_list<double>' for 1st
      argument
    vector& operator=(initializer_list<_Ty> _Ilist) {
            ^
root [1]

Hi @faca87,

I will reply to the issues that you had in your latest post, in order. First, the branch nhits seems to be of type Double_t, which means that you should leave it as:

Double_t nhits;                 tree_input->SetBranchAddress( "nhits",     &nhits     );

Second (I quote below), provided that the source TTree has branches named xhit, yhit, and zhit, you should change the branch name in the corresponding SetBranchAddress() call, i.e., the first parameter.

Those should be changed to something like:

vector<double> *xhit=0;           tree_input->SetBranchAddress( "xhit",        &xhit        );
vector<double> *yhit=0;           tree_input->SetBranchAddress( "yhit",        &yhit        );
vector<double> *zhit=0;           tree_input->SetBranchAddress( "zhit",        &zhit        );

Third, from what I can tell by reading the comment at the top of the macro file, what you try to attain is to convert the type of some branches from std::vector to Double_t[]. This relates to the errors I have quoted below.

If you intend to perform such type conversion (that’s what I have understood), it doesn’t make any sense to declare the output branches as std::vector<>. The correct way to solve that, should be filling the corresponding array entries using the data contained in the std::vector. You are already doing that for other branches (as seen in lines 151-172 of the file attached in your first post). IIUC what you are trying to do, you should add several lines to the for-loop body, e.g.:

            BeamX_new[i]    = BeamX->at(i);
            BeamY_new[i]    = BeamY->at(i);
            ...

Finally, if you want to optimize your code, it should be possible to remove the loop that copies values from the vector to the array, and reuse the std::vector<> internal array which can be accessed via the data() member function.

Cheers,
J.

Hello @jalopezg thank for your help… I tried to follow your message but

  1. I get this error
C:\root_v6.25.01_master-build\macrorun>root -l
root [0] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
In file included from input_line_8:1:
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:199:22: error: subscripted value is not an array, pointer, or vector
            BeamX_new[i]    = BeamX->at(i);
            ~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:200:19: error: subscripted value is not an array, pointer, or vector
                BeamY_new[i]   = BeamY->at(i);
                ~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:201:19: error: subscripted value is not an array, pointer, or vector
                BeamZ_new[i]   = BeamZ->at(i);
                ~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:202:20: error: subscripted value is not an array, pointer, or vector
                BeamCX_new[i]   = BeamCX->at(i);
                ~~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:203:20: error: subscripted value is not an array, pointer, or vector
                BeamCY_new[i]   = BeamCY->at(i);
                ~~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:204:20: error: subscripted value is not an array, pointer, or vector
                BeamCZ_new[i]   = BeamCZ->at(i);
                ~~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:205:21: error: subscripted value is not an array, pointer, or vector
                BeamEne_new[i]  = BeamEne->at(i);
                ~~~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:206:22: error: subscripted value is not an array, pointer, or vector
                BeamPart_new[i] = BeamPart->at(i);
                ~~~~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:207:19: error: subscripted value is not an array, pointer, or vector
                nhits_new[i]    = nhits->at(i);
                ~~~~~~~~~^~
C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:207:35: error: member reference type 'Double_t' (aka 'double') is not a pointer
                nhits_new[i]    = nhits->at(i);

maybe I understood bad something.

  1. I didnt’ understand what I’ve to do here

Here the update macro

Vector_To_Array.C (14.5 KB)

Hi @faca87,

First of all, I would like to confirm that what you are trying to achieve is to convert the type of several branches in the input file (type is std::vector<Double_t>, to an array of Double_t[] in the output file. Is that correct?

Now, regarding your first point, you get this error because operator[] is not defined over BeamX_new, etc. Less technically speaking, these have not been declared as arrays. To solve that problem you have to declare it as an array of type Double_t. You are already doing that, e.g. in line 99, for subdet_new. Try to declare BeamX_new, BeamY_new, etc., in the same way.

Finally, in the second point I was only mentioning that there’s a more efficient way to implement the same behavior, but doing so it is not a requirement.

Cheers,
J.

Hello @jalopezg

Here WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free an example of ROOT file regarding of the data stored during the Test Beam. You can see that the Calo_EnDep Ntupla is Calo_EnDep[n], then I can plot the deposited energy in a particular detector (for example Calo_EnDep[0] etc).
In the ROOT file of this Geant Simulation Calo_EnDep isn’t like Calo_EnDep[n], but I found this macro to trasform vector to array …so I guess/hope that modifying Calo_EnDep to Calo_EnDep[n] I will be able to select the detector to study the deposited energy into it. Is it right? If it’s right…I want to do it.

I wrote

  Double_t BeamX_new[nMaxHits];                            tree_output->Branch( "BeamX",     &BeamX_new,    "BeamX/D"                                      );
    Double_t BeamY_new[nMaxHits];                            tree_output->Branch( "BeamY",     &BeamY_new,    "BeamY/D"                                      );
    Double_t BeamZ_new[nMaxHits];                            tree_output->Branch( "BeamZ",     &BeamZ_new,    "BeamZ/D"                                      );
    Double_t BeamCX_new[nMaxHits];                           tree_output->Branch( "BeamCX",    &BeamCX_new,   "BeamCX/D"                                     );
    Double_t BeamCY_new[nMaxHits];                           tree_output->Branch( "BeamCY",    &BeamCY_new,   "BeamCY/D"                                     );
    Double_t BeamCZ_new[nMaxHits];                           tree_output->Branch( "BeamCZ",    &BeamCZ_new,   "BeamCZ/D"                                     );
    Double_t BeamEne_new[nMaxHits];                          tree_output->Branch( "BeamEne",   &BeamEne_new,  "BeamEne/D"                                    );
    Double_t BeamPart_new[nMaxHits];                         tree_output->Branch( "BeamPart",  &BeamPart_new, "BeamPart/D"                                   );
    Double_t nhits_new[nMaxHits];                            tree_output->Branch( "nhits",     &nhits_new,    "nhits/D"                                      );

but I got this error

C:\root_v6.25.01_master-build\macros\Vector_To_Array.C:207:35: error: member reference type 'Double_t' (aka 'double') is not a pointer
                nhits_new[i]    = nhits->at(i);

then I replaced

Double_t nhits; tree_input->SetBranchAddress( "nhits", &nhits );

by

vector<double> *nhits; tree_input->SetBranchAddress( "nhits", &nhits );

but I got this error and the macro crashes

root [1] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
IncrementalExecutor::executeFunction: symbol '??$GetClass@V?$vector@NV?$allocator@N@std@@@std@@@TClass@@SAPAV0@_N0@Z' unresolved while linking function '??__E?id@?$num_put@DV?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@2V0locale@2@A@@YAXXZcling_module_13_'!
You are probably missing the definition of public: static class TClass * __cdecl TClass::GetClass<class std::vector<double,class std::allocator<double> > >(bool,bool)
Maybe you need to load the corresponding shared library?
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamCX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamCY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamCZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamEne". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamPart". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "subdet". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Idp". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Ipar". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "itrack". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Time". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "xhit". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "yhit". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "zhit". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "P". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "VertexX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "VertexY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "VertexZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Kinev". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PXvdir". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PYvdir". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PZvdir". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Iev". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Step". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "InextStep". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Event 0

==========================================
=============== STACKTRACE ===============
==========================================


================ Thread 0 ================
  libCling!TClingCallbacks::PrintStackTrace()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  0x12bcc41 ??
  0x3a110b6 ??
  libCling!cling::Value::isValid()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!TClingLookupHelper__ExistingTypeCheck()
  libCling!TCling::ProcessLine()
  libCling!TCling::ProcessLineSynch()
  libCore!TApplication::ExecuteFile()
  libCore!TApplication::ProcessFile()
  libCore!TApplication::ProcessLine()
  libRint!TRint::ProcessLineNr()
  libRint!TRint::HandleTermInput()
  libCore!TWinNTSystem::DispatchOneEvent()
  libCore!TSystem::InnerLoop()
  libCore!TSystem::Run()
  libCore!TApplication::Run()
  libRint!TRint::Run()
  root!Init_thread_footer()
  root!Init_thread_footer()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 1 ================
  ntdll!NtDelayExecution()
  KERNELBASE!Sleep()
  libCore!TWinNTSystem::TimerThread()
  libCore!TWinNTSystem::ThreadStub()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 2 ================
  win32u!NtUserGetMessage()
  libCore!TWinNTSystem::GetProcInfo()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 3 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 4 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 5 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 6 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

==========================================
============= END STACKTRACE =============
==========================================


C:\root_v6.25.01_master-build\macrorun>

How can I do that?

I also tried

Double_t nhits_new; tree_output->Branch( "nhits", &nhits_new, "nhits/D"
nhits_new = nhits;

but I get this error

root [1] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamCX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamCY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamCZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamEne". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "BeamPart". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "subdet". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Idp". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Ipar". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "itrack". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Time". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "xhit". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "yhit". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "zhit". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "P". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "VertexX". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "VertexY". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "VertexZ". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Kinev". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PXvdir". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PYvdir". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "PZvdir". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Iev". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "Step". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "InextStep". This is probably due to a missing dictionary, the original data class for this branch is vector<double>.
Event 0

==========================================
=============== STACKTRACE ===============
==========================================


================ Thread 0 ================
  libCling!TClingCallbacks::PrintStackTrace()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  0xbccd21 ??
  0x39010b6 ??
  libCling!cling::Value::isValid()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::EvaluateDynamicExpression()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!TClingLookupHelper__ExistingTypeCheck()
  libCling!TCling::ProcessLine()
  libCling!TCling::ProcessLineSynch()
  libCore!TApplication::ExecuteFile()
  libCore!TApplication::ProcessFile()
  libCore!TApplication::ProcessLine()
  libRint!TRint::ProcessLineNr()
  libRint!TRint::HandleTermInput()
  libCore!TWinNTSystem::DispatchOneEvent()
  libCore!TSystem::InnerLoop()
  libCore!TSystem::Run()
  libCore!TApplication::Run()
  libRint!TRint::Run()
  root!Init_thread_footer()
  root!Init_thread_footer()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 1 ================
  ntdll!NtDelayExecution()
  KERNELBASE!Sleep()
  libCore!TWinNTSystem::TimerThread()
  libCore!TWinNTSystem::ThreadStub()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 2 ================
  win32u!NtUserGetMessage()
  libCore!TWinNTSystem::GetProcInfo()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 3 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 4 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

================ Thread 5 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlGetAppContainerNamedObjectPath()
  ntdll!RtlGetAppContainerNamedObjectPath()

==========================================
============= END STACKTRACE =============
==========================================


C:\root_v6.25.01_master-build\macrorun>

Here the update macro Vector_To_Array.C (14.8 KB)

Hi @faca87,

Given your explanation above, I think it would be useful if you could share the code of your original macro that plots individual array elements, e.g. Calo_EnDep[0], etc. We could probably make it work with minimal modifications, given that std::vector<...> overloads operator[]().

I think that this is the way to go, as it avoids any .root file conversion in the first place.

Cheers,
J.

Hello @jalopezg I talked with the author of the Geant simulation and he explained me that I can plot Calo_EnDep[n] using the vectors too …ie. I don’t need to trasform to arrays. He wrote the macro to transform the vectors to arrays just to give simulation to other researcher who wanted the arrays (I don’t know the reason because of).

Then for the moment I don’t need to transform the vectors to arrays, but…given that I started to fix (thanks to your help) the macro maybe it should be better if I finish to fix it (one day the reasercher could ask to me the simulations using the arrays as he made before). So…I ask you if you can help me to fix the error showed in my previous message
Thank you

Hi @faca87,

You have not shared the corresponding .root file (only an example that has a different schema), and that is causing more round-trips.

First, based on the example file, I think that the “nhits” branch is an scalar of type int; therefore, both nhits and nhits_new should be declared as:

Int_t nhits_new; // or `n_hits`
tree_output->Branch( "nhits",     &nhits_new,    "nhits/I"`);

Second, note that you were not initializing your stack variables. For the branches that use a std::vector<double>, you should initialize the pointer to nullptr (), e.g.

vector<double> *BeamX = nullptr;                 tree_input->SetBranchAddress( "BeamX",     &BeamX     );

If that does not fix it, I would suggest either sharing the .root file, or at least the output of

tree_input->Print();

so that I can take a look at the schema and make the required suggestions to your code.

Cheers,
J.

Hello @jalopezg sorry…I forgot to share the link of the root file
Here the file WeTransfer

Unfortunately, I still get error

root [0] .x Vector_To_Array.C("C:/LemmaMC.root", "C:/testbeam/LemmaMC_array.root")
Error in <TTree::SetBranchAddress>: The pointer type given "Int_t" (3) does not correspond to the type needed "Double_t" (8) by the branch: nhits
Event 0
root [1]

it looks like it wants Double_t ?

Here updated macro
Vector_To_Array.C (14.7 KB)

Hi @faca87,

Yes, as you can see if you try to dump the TTree schema, i.e. tree_input->Print();, the data type of the nhits branch is Double_t:

*Br    8 :nhits     : Double_t LEMMA                                         *
*Entries :     1000 : Total  Size=      12657 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *

IMHO, that is a design flaw in the original .root file: if nhits was the expected to hold the number of hits, i.e., an integer (?), Int_t should have been the correct data type.

The aforementioned change should fix the previous issue. If the macro works as expected, please mark the topic as solved.

Cheers,
J.

Hello @jalopezg thank you…it looks like it worked!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.