add mapping file in EventBuilder

This commit is contained in:
Ryan Tang 2024-05-29 15:29:21 -04:00
parent 7940f1cd95
commit dff1bcaae6
2 changed files with 100 additions and 22 deletions

View File

@ -9,6 +9,13 @@ Thie event builder both sort and build event. skip the *.to file.
#include <string.h> #include <string.h>
#include <cmath> #include <cmath>
#include <stdbool.h> #include <stdbool.h>
#include <iostream>
#include <fstream>
#include <sys/time.h> /** struct timeval, select() */
#include <chrono>
#include <sstream>
#include <algorithm> // for std::remove_if
#include <cctype> // for std::isspace
#include "TFile.h" #include "TFile.h"
#include "TTree.h" #include "TTree.h"
@ -17,22 +24,10 @@ Thie event builder both sort and build event. skip the *.to file.
#include "TStopwatch.h" #include "TStopwatch.h"
#include "TTreeIndex.h" #include "TTreeIndex.h"
#include <sys/time.h> /** struct timeval, select() */ std::string trimSpaces(const std::string& str);
inline unsigned int getTime_us(){ std::vector<std::string> split(const std::string& str, char delimiter);
unsigned int time_us; unsigned int getTime_us();
struct timeval t1; unsigned long long getTime_ns();
struct timezone tz;
gettimeofday(&t1, &tz);
time_us = (t1.tv_sec) * 1000 * 1000 + t1.tv_usec;
return time_us;
}
// #include <chrono>
// inline unsigned long long getTime_ns(){
// std::chrono::high_resolution_clock::time_point currentTime = std::chrono::high_resolution_clock::now();
// std::chrono::nanoseconds nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime.time_since_epoch());
// return nanoseconds.count();
// }
#include "evtReader.h" #include "evtReader.h"
@ -73,10 +68,53 @@ int main(int argn, char **argv){
printf("%2ld | %s \n", i, inFileList[i].c_str()); printf("%2ld | %s \n", i, inFileList[i].c_str());
} }
printf("================================== Digesting Mapping file (to be impletmented\n"); printf("================================== Digesting Mapping file\n");
std::ifstream mapFile( mappingFilePath.Data() );
int mapping[16*12]; // fixed to be 12 digitizers
for( int i = 0; i < 16*12 ; i++ ) mapping[i] = -1;
if( !mapFile.is_open() ){
printf("Cannot open mapping file : %s. Skip. \n", mappingFilePath.Data());
}else{
int index = 0;
bool startMap = false;
std::string line;
while( std::getline(mapFile, line) ){
// printf("|%s|\n", line.c_str());
if( line.find("//-") != std::string::npos ) continue;
if( line.find("<--") != std::string::npos ){
startMap = true;
continue;
}
if( startMap && line.find("<--") != std::string::npos ) break;
if( startMap ){
std::vector<std::string> list = split(line, ',');
for( size_t k = 0; k < list.size(); k ++ ){
if( list[k].find("//") != std::string::npos || k >= 16 ) continue;
// printf("%ld | %s \n", k, list[k].c_str());
mapping[index] = atoi(list[k].c_str());
index ++;
}
}
}
mapFile.close();
}
//---- print mapping;
for( int i = 0; i < 16*11; i++){
if( i % 16 == 0 ) printf("Mod-%02d | ", i/16);
if( mapping[i] < 0 ) printf("%4d,", mapping[i]);
if( 0 <= mapping[i] && mapping[i] < 100 ) printf("\033[31m%4d\033[0m,", mapping[i]);
if( 100 <= mapping[i] && mapping[i] < 200 ) printf("\033[34m%4d\033[0m,", mapping[i]);
if( 200 <= mapping[i] && mapping[i] < 300 ) printf("\033[32m%4d\033[0m,", mapping[i]);
if( 300 <= mapping[i] && mapping[i] < 400 ) printf("\033[35m%4d\033[0m,", mapping[i]);
if( i % 16 == 15 ) printf("\n");
}
printf("================================== Creating Tree\n"); printf("================================== Creating Tree\n");
@ -145,6 +183,8 @@ int main(int argn, char **argv){
if( timeWindow < 0 ) { // no event build if( timeWindow < 0 ) { // no event build
multi = 1; multi = 1;
int index = event[0].crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (event[0].slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + event[0].ch;
id[0] = mapping[index];
e[0] = event[0].energy; e[0] = event[0].energy;
e_t[0] = event[0].time; e_t[0] = event[0].time;
@ -174,6 +214,8 @@ int main(int argn, char **argv){
if( DEBUG ) printf("====================== event %u, event size %u\n", eventID, multi); if( DEBUG ) printf("====================== event %u, event size %u\n", eventID, multi);
for( size_t p = 0; p < multi; p++ ) { for( size_t p = 0; p < multi; p++ ) {
if( DEBUG ) printf("%lu | %6d, %12llu \n", p, event[p].energy, event[p].time); if( DEBUG ) printf("%lu | %6d, %12llu \n", p, event[p].energy, event[p].time);
int index = event[p].crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (event[p].slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + event[p].ch;
id[p] = mapping[index];
e[p] = event[p].energy; e[p] = event[p].energy;
e_t[p] = event[p].time; e_t[p] = event[p].time;
} }
@ -203,6 +245,8 @@ int main(int argn, char **argv){
multi = event.size(); multi = event.size();
for( size_t p = 0; p < multi; p++ ) { for( size_t p = 0; p < multi; p++ ) {
if( DEBUG ) printf("%lu | %6d, %12llu \n", p, event[p].energy, event[p].time); if( DEBUG ) printf("%lu | %6d, %12llu \n", p, event[p].energy, event[p].time);
int index = event[p].crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (event[p].slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + event[p].ch;
id[p] = mapping[index];
e[p] = event[p].energy; e[p] = event[p].energy;
e_t[p] = event[p].time; e_t[p] = event[p].time;
} }
@ -234,3 +278,37 @@ int main(int argn, char **argv){
return 0; return 0;
} }
unsigned int getTime_us(){
unsigned int time_us;
struct timeval t1;
struct timezone tz;
gettimeofday(&t1, &tz);
time_us = (t1.tv_sec) * 1000 * 1000 + t1.tv_usec;
return time_us;
}
unsigned long long getTime_ns(){
std::chrono::high_resolution_clock::time_point currentTime = std::chrono::high_resolution_clock::now();
std::chrono::nanoseconds nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime.time_since_epoch());
return nanoseconds.count();
}
std::string trimSpaces(const std::string& str) {
std::string trimmed = str;
trimmed.erase(std::remove_if(trimmed.begin(), trimmed.end(), ::isspace), trimmed.end());
return trimmed;
}
std::vector<std::string> split(const std::string& str, char delimiter) {
std::vector<std::string> tokens;
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, delimiter)) {
tokens.push_back(trimSpaces(token));
}
return tokens;
}

View File

@ -17,8 +17,8 @@ ZERO DEGREE : 300 - 399
#define NZEROGAGG 2 ///NZERO is used #define NZEROGAGG 2 ///NZERO is used
int mapping[176] ={ int mapping[176] ={
//***************** <-- load indicator //***************** <-- load indicator for EventBuidler
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 //-0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0, 1, 2, 3, 100, 4, 5, 6, 7, 101, 8, 9, 10, 11, 102, -1, //mod-0 0, 1, 2, 3, 100, 4, 5, 6, 7, 101, 8, 9, 10, 11, 102, -1, //mod-0
12, 13, 14, 15, 103, 16, 17, 18, 19, 104, 20, 21, 22, 23, 105, -1, //mod-1 12, 13, 14, 15, 103, 16, 17, 18, 19, 104, 20, 21, 22, 23, 105, -1, //mod-1
24, 25, 26, 27, 106, 28, 29, 30, 31, 107, 32, 33, 34, 35, 108, -1, //mod-2 24, 25, 26, 27, 106, 28, 29, 30, 31, 107, 32, 33, 34, 35, 108, -1, //mod-2
@ -26,11 +26,11 @@ int mapping[176] ={
204, 205, 206, 207, 208, 209, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, //mod-4 204, 205, 206, 207, 208, 209, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, //mod-4
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, //mod-5, Ring 4A 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, //mod-5, Ring 4A
260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, //mod-6, Ring 4B 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, //mod-6, Ring 4B
-1, -1, -1, -1, 4, 5, -1, -1, 8, 9, -1, -1, -1, -1, -1, -1, //mod-7 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //mod-7
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //mod-8 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //mod-8
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //mod-9 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //mod-9
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 //mod-10 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //mod-10
//&*************** <-- end of mapping indicator //**************** <-- end of mapping indicator EventBuidler
}; };
//200- 209 GAGG 2A //200- 209 GAGG 2A