Reputation: 155
Yes, title looks like weird but this stiuation as weird as title. I have wrote a ROOT script and result of this script must be draw two histogram. Script has a few ROOT header file and random number generator. When I run this with terminal
$ root example.cpp
It has execute as how I want to. Output histogram ;
But when compile to exe file with cmake, it is not work properly. Results does not match with the terminal output and -i think- random generator does not work right. This output make this situation clear,
as you see in this histogram, values stack over a few value. There is I am confused. CMake command and making exe file does not give an error, made it properly. But same code, same random generator and results are so much different each other. My opinion is CMakeLists.txt file does not prepare properly. Because I found it in internet example and edit. Now this is C++ file :
#include "TRandom3.h"
#include "TH1F.h"
#include "TLorentzVector.h"
#include "TCanvas.h"
void TLV()
{
TCanvas* c1 = new TCanvas("table", "TLVs", 800,800 );
TH1F* histoM = new TH1F("masses","Lorentz Vectors' Masses",600,0,20.);
TH1F* histoPt = new TH1F("pts","Lorentz PTs", 600,-0.5 , 7.);
TRandom3* uret = new TRandom3(); // - RANDOM GENERATOR
uret->SetSeed(855); // SEED
TLorentzVector v1; // - DECLARING LORENTZ
TLorentzVector v2; // VECTORS
TPad *pad1 = new TPad("pad1", "pad1", 0, 0.5, 1, 1.0);
TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.5);
for (int j=0;j<100;j++){
// doing some calculation
histoPt->Fill(tb2); //INSERT VALUES TO HISTOGRAMS
histoM->Fill(tb1);
};
// drawing
}
/*---------- END OF FUNCTION -------------*/
int main() { TLV(); }
and CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
project(TLV)
set(CMAKE_CXX_FLAGS "-O3 -fPIC -Wall -Wextra -std=c++11 -m64")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} $ENV{ROOTSYS}/etc/cmake)
#print conf
message(STATUS "Environmental CMAKE_MODULE_PATH is $ENV{ROOTSYS}")
find_package(ROOT MODULE REQUIRED Cling TreePlayer Tree Rint Postscript Matrix RIO Core Foam RooStats RooFit RooFitCore Gpad Graf3d Graf Hist Net TMVA XMLIO MLP)
include(${ROOT_USE_FILE})
message(STATUS "Environmental ROOTSYS is $ENV{ROOTSYS}")
message(STATUS "found root at: ${ROOT_USE_FILE}")
message(STATUS "ROOT_LIBRARIES=${ROOT_LIBRARIES}")
set(EXECUTABLE_OUTPUT_PATH EXE_CIKTI)
add_executable( TLV TLV.cpp )
target_link_libraries(TLV ${ROOT_LIBRARIES})
Root library include cmake well. Because TLorentzVector command is valid in result. But Random command has weird behavior. Is CMakeLists.txt wrong or Did I miss something important.
Upvotes: 2
Views: 149
Reputation: 298
When you run ROOT as a macro script it makes certain assumptions about how your code should be. When you compile the code however it does not make the same assumptions.
In your case, ROOT assumes that the variables you fill your histogram with are floats, whereas your compiler thinks that they are ints. (This will be because of some math library it imports, as an educated guess)
The compiler is always right, if there is some difference between ROOT and the compiler.
The only way to ensure consistent behaviour is to write your code such that it is explicit. For example use casting on variables that would be interpreted by your compiler as integers.
Upvotes: 3