9 |
// |
// |
10 |
// |
// |
11 |
// HOWTO (RECOMMENDED): |
// HOWTO (RECOMMENDED): |
12 |
// ./ Pamelagp2Digits filename.his |
// ./ Pamelagp2Digits -hbookfile filename.his |
13 |
// It generates filename.pam (PAMELA raw data) and filename.gp.root (sim info) |
// It generates filename.pam (PAMELA raw data) and filename.gp.root (sim info) |
14 |
// |
// |
15 |
// NB: more details are present in the file HOW-TO-DIGIT.TXT |
// NB: more details are present in the file HOW-TO-DIGIT.TXT |
16 |
// |
// |
17 |
// HOWTO (only for testing purposes) |
// HOWTO |
18 |
// Pamelagp2Digits hbook_filename root_filename raw_filename compress tolower |
// see usage(). Example: |
19 |
// - If the 2nd and 3rd parameters are missing the names are generated from the hbook file name. |
// Pamelagp2Digits -hbookfile filename.his -rootfile filename.root -pamfile filename.pam -calocompress [VAL] -rootcompress [VAL] |
20 |
// - The following flags are from h2root and default values are used: |
// The following flags are from h2root and default values are used: |
21 |
// if compress is missing (or = 1) the ROOT file will be compressed |
// if rootcompress is missing (or = 1) the ROOT file will be compressed |
22 |
// if compress = 0 the ROOT file will not be compressed. |
// if rootcompress = 0 the ROOT file will not be compressed. |
23 |
// if tolower is missing (or = 1) ntuple column names are converted to lower case |
// if tolower is missing (or = 1) ntuple column names are converted to lower case |
24 |
// but the first character is converted to upper case. |
// but the first character is converted to upper case. |
25 |
// if tolower = 2 same as tolower=1 except that the first character is also |
// if tolower = 2 same as tolower=1 except that the first character is also |
26 |
// convertex to lower case |
// convertex to lower case |
27 |
// |
// |
28 |
|
// |
29 |
// MODIFICATIONS: |
// MODIFICATIONS: |
30 |
|
// (C.Pizzolotto. Trieste. october 2009) |
31 |
|
// - added DigitizeCALOCOMPRESS to write calorimeter data in compress mode |
32 |
|
// - changed way of reading input parameters. now the input order is not important. |
33 |
|
// |
34 |
// v. 1.5 (S.Orsi, Roma2, 11 October 2007) |
// v. 1.5 (S.Orsi, Roma2, 11 October 2007) |
35 |
// - file HOW-TO-DIGIT.TXT written (mainly by S.Bottai): contains information on how to run the chain from the DB creation to DarthVader through Digitizer, yoda and YodaProfiler |
// - file HOW-TO-DIGIT.TXT written (mainly by S.Bottai): contains information on how to run the chain from the DB creation to DarthVader through Digitizer, yoda and YodaProfiler |
36 |
// |
// |
68 |
// |
// |
69 |
///////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////// |
70 |
|
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <ctype.h> |
|
|
#include "Riostream.h" |
|
|
#include "TFile.h" |
|
|
#include "TDirectory.h" |
|
|
#include "TTree.h" |
|
|
#include "TLeafI.h" |
|
|
#include "TH1.h" |
|
|
#include "TH2.h" |
|
|
#include "TProfile.h" |
|
|
#include "TGraph.h" |
|
|
#include "TMath.h" |
|
71 |
#include "Digitizer.h" |
#include "Digitizer.h" |
72 |
|
|
73 |
int Error; //to be removed soon |
using namespace std; |
74 |
|
|
75 |
|
//int Error; //to be removed soon |
76 |
|
|
77 |
// Define the names of the Fortran common blocks for the different OSs |
// Define the names of the Fortran common blocks for the different OSs |
78 |
|
|
111 |
int ncx,ncy,nwt,idb; |
int ncx,ncy,nwt,idb; |
112 |
int lcont, lcid, lcdir; |
int lcont, lcid, lcdir; |
113 |
float xmin,xmax,ymin,ymax; |
float xmin,xmax,ymin,ymax; |
114 |
|
int comprcalomode; |
115 |
const Int_t kMIN1 = 7; |
const Int_t kMIN1 = 7; |
116 |
const Int_t kMAX1 = 8; |
const Int_t kMAX1 = 8; |
117 |
|
|
270 |
Int_t bufsize = 64000; |
Int_t bufsize = 64000; |
271 |
Int_t optcwn = 1; |
Int_t optcwn = 1; |
272 |
|
|
273 |
|
char *DigitizerInfo(bool print); |
274 |
|
|
|
int main(int argc, char **argv) |
|
275 |
|
|
|
{ |
|
|
if (argc < 2) { |
|
|
printf("Error: Pamelagp2Digits \n"); |
|
|
printf("Pamelagp2Digits file.hbook file.root file.pam [compress] [tolower] [lrecl] [bufsize] [optcwn] \n"); |
|
|
printf(" if file.root is not given it will be = file.root\n"); |
|
|
printf(" compress = 1 by default (use 0 for no compression)\n"); |
|
|
printf(" tolower = 1 by default (use 0 to keep case of column names)\n"); |
|
|
printf(" lrecl =0 by default (must be specified if >8092)\n"); |
|
|
printf(" bufsize = 8000 by default (branch buffer size)\n"); |
|
|
printf(" for cwn ntuple only: optcwn = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n"); |
|
|
return 1; |
|
|
} |
|
276 |
|
|
277 |
|
void usage(){ |
278 |
|
printf("\nUsage:\n"); |
279 |
|
printf("\n Pamelagp2Digits [options] -hbookfile file.hbook \n"); |
280 |
|
printf("\n -hbookfile path to the file that has to be converted \n"); |
281 |
|
printf("\n Options are:\n\n"); |
282 |
|
printf(" -h | --help print this help and exit \n"); |
283 |
|
printf(" -rootfile name of the root file in output finename.root,\n"); |
284 |
|
printf(" if parameter is missing the name is generated from the hbook file name\n"); |
285 |
|
printf(" -pamfile name of the pam file in output filename.pam \n"); |
286 |
|
printf(" if parameter is missing the name is generated from the hbook file name\n"); |
287 |
|
printf(" -calocompress compression of data in calorimeter- By default is 1.\n"); |
288 |
|
printf(" 0 is RAW, 1 is COMPRESS, 2 is FULL (2 not yet implemented)\n"); |
289 |
|
printf(" -rootcompress compression of root file = 1 by default (use 0 for no compression)\n"); |
290 |
|
printf(" -tolower = 1 by default : ntuple column names are converted to lower case \n"); |
291 |
|
printf(" but the first character is converted to upper case.\n"); |
292 |
|
printf(" if 2 same as tolower=1 but also the first character is converted to lower case.\n"); |
293 |
|
printf(" use 0 to keep case of column names\n"); |
294 |
|
printf(" -lrecl =0 by default (must be specified if >8092)\n"); |
295 |
|
printf(" -bufsize = 8000 by default (branch buffer size)\n"); |
296 |
|
printf(" -optcwn for cwn ntuple only: optcwn\n"); |
297 |
|
printf(" = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n"); |
298 |
|
printf("\n The order of input files and options does not matter. \n"); |
299 |
|
printf("\n Example: \n"); |
300 |
|
printf(" Pamelagp2Digits -hbookfile /path/to/files/protons_1_300-500.rz -caloCompress 1 \n\n"); |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
int main(int argc, char *argv[]) |
305 |
|
{ |
306 |
|
|
307 |
|
printf("init\n"); |
308 |
lq = &pawc[9]; |
lq = &pawc[9]; |
309 |
iq = &pawc[17]; |
iq = &pawc[17]; |
310 |
void *qq = iq; |
void *qq = iq; |
311 |
q = (float*)qq; |
q = (float*)qq; |
|
char *file_in=argv[1]; |
|
|
char *file_out = " "; |
|
|
char *file_raw; |
|
312 |
|
|
313 |
Int_t compress = 1; |
char *file_out = new char[512]; |
314 |
int ier=0, record_size=0; |
strcpy(file_out," "); |
315 |
|
char *file_raw; |
316 |
if (argc > 8) { |
Int_t rootcompress = 1; |
317 |
optcwn = atoi(argv[8]); |
Int_t calocompress = 1; |
318 |
} |
int ier=0, record_size=0; |
319 |
if (argc > 7) { |
|
320 |
bufsize = atoi(argv[7]); |
char *rootfile = new char[512]; |
321 |
} |
strcpy(rootfile," "); |
322 |
if (argc > 6) { |
char *pamfile = new char[512]; |
323 |
record_size = atoi(argv[6]); |
strcpy(pamfile," "); |
324 |
} |
char *file_in; |
325 |
if (argc > 5) { |
file_in = NULL ; |
326 |
golower = atoi(argv[5]); |
|
327 |
} |
Int_t i = 0; |
328 |
if (argc > 4) { |
if ( argc > 1 ){ |
329 |
compress = atoi(argv[4]); |
while ( i < argc ){ |
330 |
} |
if ( !strcmp(argv[i],"-h") || !strcmp(argv[i],"--help") ){ |
331 |
|
usage(); |
332 |
if (argc > 3) { |
return 0; |
333 |
file_raw=argv[3]; |
}; |
334 |
|
if ( !strcmp(argv[i],"-hbookfile") ) { |
335 |
|
if ( argc-1 < i+1 ){ |
336 |
|
usage(); |
337 |
|
return 1; |
338 |
|
}; |
339 |
|
file_in = argv[i+1]; |
340 |
|
}; |
341 |
|
if ( !strcmp(argv[i],"-rootfile") ) { |
342 |
|
if ( argc-1 < i+1 ){ |
343 |
|
usage(); |
344 |
|
return 1; |
345 |
|
}; |
346 |
|
rootfile = argv[i+1]; |
347 |
|
}; |
348 |
|
if ( !strcmp(argv[i],"-pamfile") ) { |
349 |
|
if ( argc-1 < i+1 ){ |
350 |
|
usage(); |
351 |
|
return 1; |
352 |
|
}; |
353 |
|
pamfile = argv[i+1]; |
354 |
|
}; |
355 |
|
if ( !strcmp(argv[i],"-calocompress") ) { |
356 |
|
if ( argc-1 < i+1 ){ |
357 |
|
usage(); |
358 |
|
return 1; |
359 |
|
}; |
360 |
|
calocompress = atoi(argv[i+1]); |
361 |
|
}; |
362 |
|
if ( !strcmp(argv[i],"-rootcompress") ) { |
363 |
|
if ( argc-1 < i+1 ){ |
364 |
|
usage(); |
365 |
|
return 1; |
366 |
|
}; |
367 |
|
rootcompress = atoi(argv[i+1]); |
368 |
|
}; |
369 |
|
if ( !strcmp(argv[i],"-tolower") ) { |
370 |
|
if ( argc-1 < i+1 ){ |
371 |
|
usage(); |
372 |
|
return 1; |
373 |
|
}; |
374 |
|
golower = atoi(argv[i+1]); |
375 |
|
}; |
376 |
|
if ( !strcmp(argv[i],"-lrecl") ) { |
377 |
|
if ( argc-1 < i+1 ){ |
378 |
|
usage(); |
379 |
|
return 1; |
380 |
|
}; |
381 |
|
record_size = atoi(argv[i+1]); |
382 |
|
}; |
383 |
|
if ( !strcmp(argv[i],"-bufsize") ) { |
384 |
|
if ( argc-1 < i+1 ){ |
385 |
|
usage(); |
386 |
|
return 1; |
387 |
|
}; |
388 |
|
bufsize = atoi(argv[i+1]); |
389 |
|
}; |
390 |
|
if ( !strcmp(argv[i],"-optcwn") ) { |
391 |
|
if ( argc-1 < i+1 ){ |
392 |
|
usage(); |
393 |
|
return 1; |
394 |
|
}; |
395 |
|
optcwn = atoi(argv[i+1]); |
396 |
|
}; |
397 |
|
i++; |
398 |
|
}; |
399 |
} else { |
} else { |
400 |
|
// |
401 |
|
// no input parameters exit with error, we need at least the input file |
402 |
|
// |
403 |
|
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
404 |
|
usage(); |
405 |
|
return 1; |
406 |
|
}; |
407 |
|
|
408 |
|
if ( file_in==NULL) { |
409 |
|
// |
410 |
|
// file is not defined. exit with error, we need at least the input file |
411 |
|
// |
412 |
|
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
413 |
|
usage(); |
414 |
|
return 1; |
415 |
|
} |
416 |
|
|
417 |
|
// define calo writing format (general variable) |
418 |
|
comprcalomode = calocompress ; |
419 |
|
// Define the root and pam file |
420 |
|
if ( !strcmp(pamfile," ")) { |
421 |
file_raw= new char[2000]; |
file_raw= new char[2000]; |
422 |
strcpy(file_raw,file_in); |
strcpy(file_raw,file_in); |
423 |
char *dot = strrchr(file_raw,'.'); |
char *dot = strrchr(file_raw,'.'); |
424 |
if (dot) strcpy(dot+1,"pam"); |
if (dot) strcpy(dot+1,"pam"); |
425 |
else strcat(file_out,".pam"); |
else strcat(file_out,".pam"); |
|
} |
|
|
|
|
|
if (argc > 2) { |
|
|
file_out=argv[2]; |
|
426 |
} else { |
} else { |
427 |
|
file_raw=pamfile; |
428 |
|
} |
429 |
|
if (!strcmp(rootfile," ")) { |
430 |
file_out= new char[2000]; |
file_out= new char[2000]; |
431 |
strcpy(file_out,file_in); |
strcpy(file_out,file_in); |
432 |
char *dot = strrchr(file_out,'.'); |
char *dot = strrchr(file_out,'.'); |
433 |
if (dot) strcpy(dot+1,"gp.root"); //modified S.Orsi 09/'07 |
if (dot) strcpy(dot+1,"gp.root"); //modified S.Orsi 09/'07 |
434 |
else strcat(file_out,".gp.root"); |
else strcat(file_out,".gp.root"); |
435 |
|
} else { |
436 |
|
file_out=rootfile; |
437 |
} |
} |
438 |
|
|
439 |
|
|
440 |
|
cout<<" Check input parameters inputfile="<<file_in<<" root="<<file_out<<" pam="<<file_raw<<endl; |
441 |
|
cout<<" calocompress="<<calocompress<<" rootcompress="<<rootcompress<<" golow="<<golower<<endl; |
442 |
|
cout<<" bufsize="<<bufsize<<" cwn="<<optcwn<<endl; |
443 |
|
|
444 |
|
|
445 |
#if defined(_HIUX_SOURCE) && !defined(__GNUC__) |
#if defined(_HIUX_SOURCE) && !defined(__GNUC__) |
446 |
hf_fint((char *)NULL); |
hf_fint((char *)NULL); |
465 |
|
|
466 |
char root_file_title[2000]; |
char root_file_title[2000]; |
467 |
|
|
468 |
TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,compress); |
TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,rootcompress); |
469 |
|
|
470 |
if (!hfile) { |
if (!hfile) { |
471 |
printf("Error: can't open output file: %s \n",file_out); |
printf("Error: can't open output file: %s \n",file_out); |
629 |
} |
} |
630 |
h1->SetEntries(nentries); |
h1->SetEntries(nentries); |
631 |
h1->Write(); |
h1->Write(); |
632 |
delete h1; |
// delete h1; |
633 |
|
h1->Delete(); |
634 |
} |
} |
635 |
//____________________________________________________________________________ |
//____________________________________________________________________________ |
636 |
void convert_cwn(Int_t id,char* file_raw) |
void convert_cwn(Int_t id,char* file_raw) |
918 |
|
|
919 |
tree->Write(); |
tree->Write(); |
920 |
|
|
921 |
std::cout << "Invoking Digitizer" << endl << flush; |
cout << "Invoking Digitizer" << endl << flush; |
922 |
|
const char *ndl[9]; |
923 |
Digitizer* dig = new Digitizer(tree,file_raw); |
char *q,*q1; |
924 |
|
q=(char*)malloc(5 *sizeof(char)); |
925 |
|
q1=(char*)malloc(5 *sizeof(char)); |
926 |
|
ndl[0]="nspe"; |
927 |
|
ndl[1]="ntof"; |
928 |
|
ndl[2]="ncat"; |
929 |
|
ndl[3]="ncas"; |
930 |
|
ndl[4]="ncar"; |
931 |
|
ndl[5]="ncal"; |
932 |
|
ndl[6]="nndd"; |
933 |
|
ndl[7]="nstr"; |
934 |
|
ndl[8]="comprcalomod"; |
935 |
|
|
936 |
|
int nspe=200,ntof=200,ncat=50,ncas=50,ncar=100,ncal=1000,nnd=200,nstr=1000,par[9],tmp=0,t; |
937 |
|
par[0]=nspe; |
938 |
|
par[1]=ntof; |
939 |
|
par[2]=ncat; |
940 |
|
par[3]=ncas; |
941 |
|
par[4]=ncar; |
942 |
|
par[5]=ncal; |
943 |
|
par[6]=nnd; |
944 |
|
par[7]=nstr; |
945 |
|
par[8]=comprcalomode; |
946 |
|
|
947 |
|
ifstream np("vectpar.dat",ios::in); |
948 |
|
if(!np)printf("ATTENTION: Using default vector legths!\n"); |
949 |
|
else{ |
950 |
|
while(!np.eof()){ |
951 |
|
np>>q>>tmp; |
952 |
|
if(np.eof())break; |
953 |
|
if(tmp<=0){ |
954 |
|
cout<<"ATTENTION: Length of one vector is negative or equal 0!"<<endl<<q<<"="<<tmp<<endl; |
955 |
|
break; |
956 |
|
} |
957 |
|
t=0; |
958 |
|
while(tmp){ |
959 |
|
strcpy(q1,ndl[t]); |
960 |
|
if(q[0]==q1[0] && q[1]==q1[1] && q[2]==q1[2] && q[3]==q1[3]){ |
961 |
|
par[t]=tmp; |
962 |
|
tmp=0; |
963 |
|
cout<<q<<" "<<par[t]<<"["<<t<<"]"<<endl; |
964 |
|
} |
965 |
|
t++; |
966 |
|
} |
967 |
|
} |
968 |
|
nspe=par[0]; |
969 |
|
ntof=par[1]; |
970 |
|
ncat=par[2]; |
971 |
|
ncas=par[3]; |
972 |
|
ncar=par[4]; |
973 |
|
ncal=par[5]; |
974 |
|
nnd=par[6]; |
975 |
|
nstr=par[7]; |
976 |
|
comprcalomode=par[8]; |
977 |
|
} |
978 |
|
Digitizer* dig = new Digitizer(tree,file_raw,nspe,ntof,ncat,ncas,ncar,ncal,nnd,nstr,comprcalomode); |
979 |
dig->Loop(); |
dig->Loop(); |
980 |
dig->Close(); |
dig->Close(); |
981 |
|
|
982 |
std::cout << "Finished" << endl << flush; |
cout << "Finished" << endl; |
983 |
|
|
984 |
} |
} |
985 |
|
|