Why can't I define colPalette[]?

Hello everyone,
I have been working in a program to plot histograms in 2D. I do not know if I am in the right way.

...
static Int_t ColPalette[255];
...

the result is

Error: No memory for static ColPalette\a42\0

CheersMC_Analyzer.cc (9.0 KB)
2017-10-20_4-26-30_events.root (109.7 KB)
MC_Analyzer.cc (9.0 KB)
2017-10-20_4-26-30_events.root (109.7 KB)

In order to run your macro a file is missing:

Processing MC_Analyzer.cc...
In file included from input_line_11:1:
/Users/couet/Downloads/MC_Analyzer.cc:24:10: fatal error: 'src/optPhot_matching.cc' file not found
#include "src/optPhot_matching.cc"
         ^~~~~~~~~~~~~~~~~~~~~~~~~

I forgot it. These are in a ‘‘src’’ file.
fileoperations.cc (1.3 KB)
TPC_Definition.cc (3.7 KB)
calibration_source.cc (26.8 KB)
optPhot_matching.cc (38.4 KB)
optPhot_S1.cc (51.2 KB)

Thanks for the new files. Now I get more errors .

Processing MC_Analyzer.cc...
In file included from input_line_11:1:
In file included from /Users/couet/Downloads/MC_Analyzer.cc:24:
/Users/couet/Downloads/optPhot_matching.cc:48:2: error: no matching function for call to 'optPhot_matching'
        optPhot_matching(datafile_kr,"",AFT_S2_Kr,datafile_mc,bin_z,bin_r,bin_rr,strnbinst,filenumber_start,filenumber_end,output_dir,batch);
        ^~~~~~~~~~~~~~~~
/Users/couet/Downloads/optPhot_matching.cc:46:6: note: candidate function not viable: requires at most 11 arguments, but 12 were provided
void optPhot_matching(string datafile_kr, double AFT_S2_Kr, string datafile_mc, int bin_z, int bin_r, int bin_rr, string strnbinst, int filenumber_start = 0, int fi...
     ^
In file included from input_line_11:1:
In file included from /Users/couet/Downloads/MC_Analyzer.cc:26:
/Users/couet/Downloads/calibration_source.cc:48:2: error: no matching function for call to 'calibration_source'
        calibration_source(datafile,50,45,22,output_dir,export_format,true);
        ^~~~~~~~~~~~~~~~~~
/Users/couet/Downloads/calibration_source.cc:44:6: note: candidate function not viable: requires at most 3 arguments, but 7 were provided
void calibration_source(string datafile, string output_dir = "", string export_format = "png") {
     ^
In file included from input_line_11:1:
/Users/couet/Downloads/MC_Analyzer.cc:109:3: error: use of undeclared identifier 'data_maps'
                data_maps(datafile,9,4,4);
                ^
/Users/couet/Downloads/MC_Analyzer.cc:158:3: error: use of undeclared identifier 'optPhot_comparison'
                optPhot_comparison(datafile_kr,pmtini,0.645,datafile_mc,9,4,4,"4 6 8 12");
                ^
/Users/couet/Downloads/MC_Analyzer.cc:184:3: error: use of undeclared identifier 'optPhot_parameter_variations'
                optPhot_parameter_variations(datafile,parameter);
                ^
/Users/couet/Downloads/MC_Analyzer.cc:262:3: error: use of undeclared identifier 'optPhot_S2'
                optPhot_S2(datafile);
                ^
root [1] 

May be you can produce a small a smaller reproducer of your problem ?

Hello,
Excuse me. First, I had to specify, root version is 5.34.34. In 6.08.06 I don’t know why is a little different I have to modify

calibration_source(datafile,50,45,22,output_dir,export_format,true); 

Root 5.34.34 the result is

localhost.localdomain:/MC-TPC < 14 >root MC_Analyzer.cc                           *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.34/34    2 October 2015   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************

ROOT 5.34/34 (v5-34-34@v5-34-34, Oct 02 2015, 16:30:37 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] 
Processing MC_Analyzer.cc...
============================================================
============================================================
= Starting MC-Analyzer =====================================
============================================================
============================================================
= (1) S1 - MC analysis =====================================
============================================================
= (2) data maps (Kr83m) ====================================
============================================================
= (3) S1 - comparison of MC vs. data maps ==================
= (4) S1 - parameter variations (of dir) ===================
============================================================
= (5) calibration source ===================================
============================================================
= (6) matching prepare MC values ===========================
= (7) matching process =====================================
============================================================
= (8) S2 - MC analysis =====================================
============================================================
1
= S1 - MC analysis =========================================
============================================================
Which datafile(s) do you want to analyse?
------------------------------------------------------------
(l) for: 2017-10-20_4-26-30_events.root
l
= reading datafile ===== single file =======================
 file: 2017-10-20_4-26-30_events.root 100 events 
============================================================
Error: No memory for static ColPalette\a40\0  src/optPhot_S1.cc:195:
*** Interpreter error recovered ***

I am having problems to run 5.34 right now on my Mac (some issue with the new OS) . If you could make it work with ROOT 6 it would be great. Also ROOT 6 is more strict regarding C++ . It would be good you run your macro using AClic with root 5 to see if you do not have any C++ issue. Just do:

root MC_Analyzer.cc++

In root 6 I have the following

root [0] 
Processing MC_Analyzer.cc++...
Info in <TUnixSystem::ACLiC>: creating shared library /home/local1/Desktop/MC-TPC/./MC_Analyzer_cc.so
In file included from input_line_12:9:
In file included from ././MC_Analyzer.cc:20:
/home/local1/Desktop/MC-TPC/src/optPhot_S1.cc:50:3: error: no matching function
      for call to 'optPhot_S1'
                optPhot_S1(datafile,26,50,22,output_dir,export_format,ba...
                ^~~~~~~~~~
/home/local1/Desktop/MC-TPC/src/optPhot_S1.cc:46:6: note: candidate function not
      viable: requires at most 4 arguments, but 7 were provided
void optPhot_S1(string datafile, string output_dir = "", string export_f...
     ^
Error in <ACLiC>: Dictionary generation failed!

I have to change a part of the code in order to get the following

...
/*=================================================================*/
void optPhot_S1(string datafile, string output_dir = "", string export_format = "png", bool batch = true) {
	// Some good binnings
	//TPC.Set_Bins(26,50,22) - default
	//TPC.Set_Bins(52,100,44)- nevents > 10000000
		//optPhot_S1(datafile,26,50,22,output_dir,export_format,batch);//this goes down in root 6.08.06 
}

void optPhot_S1(string datafile, int bin_z, int bin_r, int bin_rr, string output_dir = "", string export_format = "png", bool batch = true) {
	
	optPhot_S1(datafile,26,50,22,output_dir,export_format,batch);`
....

and what I get is

root [0] 
Processing MC_Analyzer.cc...
============================================================
============================================================
= Starting MC-Analyzer =====================================
============================================================
============================================================
= (1) S1 - MC analysis =====================================
============================================================
= (2) data maps (Kr83m) ====================================
============================================================
= (3) S1 - comparison of MC vs. data maps ==================
= (4) S1 - parameter variations (of dir) ===================
============================================================
= (5) calibration source ===================================
============================================================
= (6) matching prepare MC values ===========================
= (7) matching process =====================================
============================================================
= (8) S2 - MC analysis =====================================
============================================================
1
= S1 - MC analysis =========================================
============================================================
Which datafile(s) do you want to analyse?
------------------------------------------------------------
(l) for: 2017-10-20_4-26-30_events.root
l
root [1] 

nothing is the result.

ROOt 6/aclic points a C++ mistake… as I said. You can also use aclic with root 5 but you will get the same result.
With root 6 you are not obliged to put ++ after cc … Root 6 is real c++

With root 5, I have nothing

root [3] .x MC_Analyzer.cc++
============================================================
============================================================
= Starting MC-Analyzer =====================================
============================================================
============================================================
= (1) S1 - MC analysis =====================================
============================================================
= (2) data maps (Kr83m) ====================================
============================================================
= (3) S1 - comparison of MC vs. data maps ==================
= (4) S1 - parameter variations (of dir) ===================
============================================================
= (5) calibration source ===================================
============================================================
= (6) matching prepare MC values ===========================
= (7) matching process =====================================
============================================================
= (8) S2 - MC analysis =====================================
============================================================
1
= S1 - MC analysis =========================================
============================================================
Which datafile(s) do you want to analyse?
------------------------------------------------------------
(l) for: 2017-10-20_4-26-30_events.root
l
root [4] 

but if I change to root5, I will get the following

root [4] .x MC_Analyzer.cc++
In file included from /home/local1/Desktop/MC-TPC/./MC_Analyzer.cc:20:0,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.h:3,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.cxx:17:
/home/local1/Desktop/MC-TPC/./src/optPhot_S1.cc: In function ‘void optPhot_S1(std::string, std::string, std::string, bool)’:
/home/local1/Desktop/MC-TPC/./src/optPhot_S1.cc:50:62: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
   optPhot_S1(datafile,26,50,22,output_dir,export_format,batch);//this goes down in root 6.08.06 
                                                              ^
In file included from /usr/include/c++/4.8.2/string:53:0,
                 from /usr/local/root/5.34.34/include/root/TSchemaHelper.h:25,
                 from /usr/local/root/5.34.34/include/root/TGenericClassInfo.h:17,
                 from /usr/local/root/5.34.34/include/root/Rtypes.h:270,
                 from /usr/local/root/5.34.34/include/root/TObject.h:31,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.h:3,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.cxx:17:
/usr/include/c++/4.8.2/bits/basic_string.tcc:212:5: error:   initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ [-fpermissive]
     basic_string<_CharT, _Traits, _Alloc>::
     ^
In file included from /home/local1/Desktop/MC-TPC/./MC_Analyzer.cc:20:0,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.h:3,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.cxx:17:
/home/local1/Desktop/MC-TPC/./src/optPhot_S1.cc:50:62: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
   optPhot_S1(datafile,26,50,22,output_dir,export_format,batch);//this goes down in root 6.08.06 
                                                              ^
In file included from /usr/include/c++/4.8.2/string:53:0,
                 from /usr/local/root/5.34.34/include/root/TSchemaHelper.h:25,
                 from /usr/local/root/5.34.34/include/root/TGenericClassInfo.h:17,
                 from /usr/local/root/5.34.34/include/root/Rtypes.h:270,
                 from /usr/local/root/5.34.34/include/root/TObject.h:31,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.h:3,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.cxx:17:
/usr/include/c++/4.8.2/bits/basic_string.tcc:212:5: error:   initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ [-fpermissive]
     basic_string<_CharT, _Traits, _Alloc>::
     ^
In file included from /home/local1/Desktop/MC-TPC/./MC_Analyzer.cc:20:0,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.h:3,
                 from /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.cxx:17:
/home/local1/Desktop/MC-TPC/./src/optPhot_S1.cc:50:62: error: too many arguments to function ‘void optPhot_S1(std::string, std::string, std::string, bool)’
   optPhot_S1(datafile,26,50,22,output_dir,export_format,batch);//this goes down in root 6.08.06 
                                                              ^
/home/local1/Desktop/MC-TPC/./src/optPhot_S1.cc:46:6: note: declared here
 void optPhot_S1(string datafile, string output_dir = "", string export_format = "png", bool batch = true) {
      ^
g++: error: /home/local1/Desktop/MC-TPC/MC_Analyzer_cc_ACLiC_dict.o: No such file or directory
Error: Function MC_Analyzer() is not defined in current scope  :0:
!!!Dictionary position not recovered because G__unloadfile() is used in a macro!!!
*** Interpreter error recovered ***

It seems to be interesting. I did not expect that there are other types of errors. I am torn between what I did since the beginning and what I have now because it had compiled at the beginning then I closed it, when I opened it again, it did not run.

Yes it seems your code as many C++ issues …
As i said if you are using ROOT 6 you do not need to using the ++ after cc…

with root 6.

>source /usr/local/root/6.08.06/bin/thisroot.csh
localhost.localdomain:/MC-TPC < 23 >root MC_Analyzer.cc                            ------------------------------------------------------------
  | Welcome to ROOT 6.08/06                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-08-06, 2 March 2017                            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] 
Processing MC_Analyzer.cc...
In file included from input_line_8:1:
In file included from /home/local1/Desktop/MC-TPC/MC_Analyzer.cc:20:
/home/local1/Desktop/MC-TPC/src/optPhot_S1.cc:50:3: error: no matching function
      for call to 'optPhot_S1'
                optPhot_S1(datafile,26,50,22,output_dir,export_format,ba...
                ^~~~~~~~~~
/home/local1/Desktop/MC-TPC/src/optPhot_S1.cc:46:6: note: candidate function not
      viable: requires at most 4 arguments, but 7 were provided
void optPhot_S1(string datafile, string output_dir = "", string export_f...
     ^
root [1] 

is so different. So far I do not know what I have to do.

Hello Sir.

what is the meaning of the following?

root.exe ERROR: cannot open image file "2017-10-20_4-26-30_events.root/2017-10-20_4-26-30_events_S1_xy_LCE.png" for writing. Please check permissions.

That’s a invalid file name for a picture … you have a / in it and I doubt you have a directory named: 017-10-20_4-26-30_events.root

Hello Sir,

I have a directory called 2017-10-20_4-26-30_events.root. I checked my code out. I think my computer is the problem. Could you test it on your PC? 2017-10-20_4-26-30_events.root (109.7 KB)

Here some changes that I did in order to compile in Root 6.

MC_Analyzer.cc (9.0 KB)
optPhot_S1.cc (51.3 KB)

It worked for me but with the error of the previous post.

Your program starts and seems to wait for an input … what should I give as input ?

The file that I want to analyze is https:2017-10-20_4-26-30_events.root (109.7 KB)

If you find the followwing,

root [3] .x MC_Analyzer.cc++
============================================================
============================================================
= Starting MC-Analyzer =====================================
============================================================
============================================================
= (1) S1 - MC analysis =====================================
============================================================
= (2) data maps (Kr83m) ====================================
============================================================
= (3) S1 - comparison of MC vs. data maps ==================
= (4) S1 - parameter variations (of dir) ===================
============================================================
= (5) calibration source ===================================
============================================================
= (6) matching prepare MC values ===========================
= (7) matching process =====================================
============================================================
= (8) S2 - MC analysis =====================================
============================================================
1
= S1 - MC analysis =========================================
============================================================
Which datafile(s) do you want to analyse?
------------------------------------------------------------
(l) for: 2017-10-20_4-26-30_events.root
l
root [4] 

Only you must press number ‘‘1’’ and then ‘‘l’’ or instead of ‘l’’ copy the name of file ‘‘2017-10-20_4-26-30_events.root’’ I think it is input. In my case appear root.exe ERROR: cannot open image file…
There are histograms but with Root I want to plot in 2d o 3d with pallete and try to compare.

Your macro optPhot_S1.cc has some logical problem … you try to write for instance in:

"2017-10-20_4-26-30_events.root/2017-10-20_4-26-30_events_S1_xy_LCE.png"

As i said earlier that’s wrong… you should write in an existing directory or in the current one. For instance:

"./2017-10-20_4-26-30_events_S1_xy_LCE.png"

please have a look at the sprintf instructions … you will understand what is wrong I am sure.

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