/* FakePhysicist.com admin@fakephysicist.com 18 April 2017 Compile with: g++ rootwrite.cpp -o rootwrite `root-config --cflags --libs` */ #include #include #include #include #include #include /****** Include the required ROOT Classes *****/ #include "TRandom.h" #include "TFile.h" #include "TTree.h" using namespace std; int main() { const int points = 11; int sets = 100; double maxV = 5.; double minV = 0.; double res = 1000.; double v_voltage[points] = { 0.,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0 }; // Create a new ROOT File TFile *fileOut = new TFile("/media/surya/Surya_1/Online/FakePhysicist/5.ROOTFiles/test.root","RECREATE"); // Create a tree in which the data will be written TTree *outTree = new TTree("testTree","testTree"); // Arguments: name, title unsigned int pointIn; // Array length float reading[points]; // Data array // Creating branch inside the tree to store data outTree->Branch("pointIn",&pointIn,"pointIn/I"); // Variable for data length: This is very important. Without this the next branch will not work. outTree->Branch("reading",reading,"reading[pointIn]/F"); // Data array: Note the length of array for(int jk=0;jkGaus(v_voltage[ij]/res,0.00005); // Rest entries are current readings } } pointIn = points; // Setting the array length outTree->Fill(); // Filling the entry } fileOut->cd(); // At the end: Call the file outTree->Write(); // Write the tree into it fileOut->Close(); // Close the tree return 0; }