tested with trace fitting with multi-thread

This commit is contained in:
Ryan Tang 2024-07-03 16:41:17 -04:00
parent 76976482fe
commit 83177e57c7
4 changed files with 72 additions and 36 deletions

View File

@ -20,13 +20,16 @@ Bool_t GeneralSort::Process(Long64_t entry){
if( entry < 1 ) printf("============================== start processing data\n");
if( entry > 5000) return true;
///initialization
for( int i = 0; i < mapping::nDetType; i++){
if( mapping::detNum[i] == 0 ) continue;
for( int j = 0; j < mapping::detNum[i]; j++){
eE[i][j] = TMath::QuietNaN();
eT[i][j] = 0;
if( isTraceExist && traceMethod > 0){
if( isTraceExist && traceMethod > 1){
teE[i][j] = TMath::QuietNaN();
teT[i][j] = TMath::QuietNaN();
teR[i][j] = TMath::QuietNaN();
@ -34,7 +37,6 @@ Bool_t GeneralSort::Process(Long64_t entry){
}
}
b_evID->GetEntry(entry);
b_multi->GetEntry(entry);
b_bd->GetEntry(entry);
@ -47,8 +49,7 @@ Bool_t GeneralSort::Process(Long64_t entry){
int detID = mapping::map[bd[i]][ch[i]];
if( detID < 0 ) continue;
int detType = mapping::FindDetTypeIndex(detID);
int low = (i == 0 ? 0 : mapping::detMaxID[detType-1]);
int reducedDetID = detID - low;
int reducedDetID = detID - (detID/100) * 100;
eE[detType][reducedDetID] = e[i] * mapping::detParity[detType];
eT[detType][reducedDetID] = e_t[i];
}
@ -65,7 +66,7 @@ Bool_t GeneralSort::Process(Long64_t entry){
for( unsigned int i = 0; i < multi; i++){
int detID = mapping::map[bd[i]][ch[i]];
if( detID < 0 ) continue;
int traceLength = tl[i];
gTrace = (TGraph*) arr->ConstructedAt(countTrace, "C");
@ -83,12 +84,11 @@ Bool_t GeneralSort::Process(Long64_t entry){
if( traceMethod == 2){
int detType = mapping::FindDetTypeIndex(detID);
if( mapping::detNum[detType] == 0 ) continue;
//TODO use a blackList
//if( mapping::detTypeName[detType] != "rdt") continue;
//TODO try custom build fiting algorithm. May be faster?
gFit = new TF1("gFit", fitFunc, 0, traceLength, numPara);
gFit->SetLineColor(6);
gFit->SetRange(0, traceLength);
gFit->SetParameter(0, e[i]);
@ -103,15 +103,13 @@ Bool_t GeneralSort::Process(Long64_t entry){
gTrace->Fit("gFit", "QR", "", 0, traceLength);
int low = (i == 0 ? 0 : mapping::detMaxID[detType-1]);
int reducedDetID = detID - low;
int reducedDetID = detID - (detID/100) * 100;
teE[detType][reducedDetID] = gFit->GetParameter(0);
teT[detType][reducedDetID] = gFit->GetParameter(1);
teR[detType][reducedDetID] = gFit->GetParameter(2);
delete gFit;
gFit = nullptr;
// delete gFit;
// gFit = nullptr;
}
//***=================== Trapezoid filter
@ -147,7 +145,7 @@ void GeneralSort::Terminate(){
printf("=============================== %s\n", __func__);
DecodeOption();
// CleanUpMemory(); //? Should Clean?
if( !isParallel){
stpWatch.Start(kFALSE);
@ -161,10 +159,8 @@ void GeneralSort::Terminate(){
saveFile = TFile::Open(saveFileName);
if( saveFile->IsOpen() ){
TTree * tree = (TTree*) saveFile->FindObjectAny("gen_tree");
int validCount = tree->GetEntries();
int validCount = tree->GetEntries();
saveFile->Close();
printf("=========================================================================\n");
PrintTraceMethod();
printf("----- saved as \033[1;33m%s\033[0m. valid event: %d\n", saveFileName.Data() , validCount);
@ -190,16 +186,16 @@ void GeneralSort::Begin(TTree * tree){
}
void GeneralSort::SlaveBegin(TTree * /*tree*/){
}
void GeneralSort::SlaveTerminate(){
void GeneralSort::SlaveTerminate(){
printf("============= %s\n", __func__);
if( isParallel){
printf("%s::SaveTree\n", __func__);
saveFile->cd();
newSaveTree->Write();
fOutput->Add(proofFile);
saveFile->Close();
printf("---- closing this worker\n");
}
}

View File

@ -129,6 +129,8 @@ public :
bool isTraceExist;
int traceMethod;
void CleanUpMemory();
void SetTraceMethod(int methodID) {traceMethod = methodID;}
void PrintTraceMethod();
@ -186,6 +188,7 @@ void GeneralSort::SetUpTree(){
eT = new ULong64_t * [mapping::nDetType];
for( int i = 0 ; i < mapping::nDetType; i++){
if( mapping::detNum[i] == 0 ) continue;
eE[i] = new Float_t[mapping::detNum[i]];
eT[i] = new ULong64_t[mapping::detNum[i]];
@ -205,6 +208,7 @@ void GeneralSort::SetUpTree(){
newSaveTree->Branch("trace", arr, 256000);
arr->BypassStreamer();
arr->Clear("C");
if( traceMethod > 1 ){
@ -213,6 +217,7 @@ void GeneralSort::SetUpTree(){
teR = new Float_t * [mapping::nDetType];
for( int i = 0 ; i < mapping::nDetType; i++){
if( mapping::detNum[i] == 0 ) continue;
teE[i] = new Float_t[mapping::detNum[i]];
teT[i] = new Float_t[mapping::detNum[i]];
teR[i] = new Float_t[mapping::detNum[i]];
@ -226,14 +231,14 @@ void GeneralSort::SetUpTree(){
//TODO use a blackList to skip some trace
newSaveTree->Branch( ("w" + mapping::detTypeName[i]).c_str(), teE[i], Form("trace_%s[%d]/F", mapping::detTypeName[i].c_str(), mapping::detNum[i]));
newSaveTree->Branch( ("w" + mapping::detTypeName[i]+"T").c_str(), teT[i], Form("trace_%s_time[%d]/l", mapping::detTypeName[i].c_str(), mapping::detNum[i]));
newSaveTree->Branch( ("w" + mapping::detTypeName[i]+"R").c_str(), teR[i], Form("trace_%s_rise[%d]/l", mapping::detTypeName[i].c_str(), mapping::detNum[i]));
newSaveTree->Branch( ("w" + mapping::detTypeName[i]+"T").c_str(), teT[i], Form("trace_%s_time[%d]/F", mapping::detTypeName[i].c_str(), mapping::detNum[i]));
newSaveTree->Branch( ("w" + mapping::detTypeName[i]+"R").c_str(), teR[i], Form("trace_%s_rise[%d]/F", mapping::detTypeName[i].c_str(), mapping::detNum[i]));
}
}
}
newSaveTree->Print("toponly"); //very important, otherwise the mac will blow up.
if( !isParallel ) newSaveTree->Print("toponly");
}
//^##############################################################
@ -258,7 +263,7 @@ void GeneralSort::DecodeOption(){
//^##############################################################
void GeneralSort::Init(TTree *tree){
printf("============= %s\n", __func__);
// Set branch addresses and branch pointers
if (!tree) return;
fChain = tree;
@ -273,31 +278,28 @@ void GeneralSort::Init(TTree *tree){
fChain->SetBranchAddress("lowFlag", lowFlag, &b_lowFlag);
fChain->SetBranchAddress("highFlag", highFlag, &b_highFlag);
TBranch * br = (TBranch *) fChain->GetListOfBranches()->FindObject("tl");
TBranch * br = (TBranch *) fChain->GetListOfBranches()->FindObject("traceLen");
if( br == NULL ){
printf(" ++++++++ no Trace.\n");
isTraceExist = false;
}else{
printf(" ++++++++ Found Trace.\n");
isTraceExist = true;
fChain->SetBranchAddress("tl", tl, &b_tl);
fChain->SetBranchAddress("traceLen", tl, &b_tl);
fChain->SetBranchAddress("trace", trace, &b_trace);
}
NumEntries = fChain->GetEntries();
printf( " ========== total Entry : %ld\n", NumEntries);
printf( " ======== total Entry : %ld\n", NumEntries);
//########################### Get Option
DecodeOption();
if( isTraceExist ){
PrintTraceMethod();
}else{
printf("++++++++ no Trace found\n");
}
SetUpTree();
gFit = new TF1("gFit", fitFunc, 0, 1250, numPara);
gFit->SetLineColor(6);
printf("---- end of Init %s\n ", __func__);
}
@ -315,7 +317,43 @@ void GeneralSort::PrintTraceMethod(){
case 3 : traceMethodStr = "Trapezoid"; break;
default: traceMethodStr = "Unknown"; break;
}
printf("\033[1;33m ===== Trace method ? %s \033[m\n", traceMethodStr);
printf("\033[1;33m ===== Trace method ? %s (%d) \033[m\n", traceMethodStr, traceMethod);
}
void GeneralSort::CleanUpMemory(){
printf("Clean up memory");
if( traceMethod > 1 ){
for( int i = 0 ; i < mapping::nDetType; i++){
if( mapping::detNum[i] == 0 ) continue;
delete [] teE[i];
delete [] teT[i];
delete [] teR[i];
delete [] eE[i];
delete [] eT[i];
}
delete [] teE;
delete [] teT;
delete [] teR;
}
for( int i = 0 ; i < mapping::nDetType; i++){
if( mapping::detNum[i] == 0 ) continue;
delete [] eE[i];
delete [] eT[i];
}
delete [] eE;
delete [] eT;
//trace
if( arr ) delete arr ;
if( gTrace ) delete gTrace;
if( gFit ) delete gFit;
if( arrTrapezoid ) delete arrTrapezoid ;
if( gTrapezoid ) delete gTrapezoid;
printf(".... done\n");
}
#endif // #ifdef GeneralSort_cxx

View File

@ -44,7 +44,7 @@ if [ $# -ge 3 ]; then nWorker=$3; fi
if [ $# -ge 4 ]; then isMonitor=$4; fi
TraceMethod=$((nWorker / 100));
temp=$((nWorker / 100));
if [ $temp -lt 0 ]; then
TraceMethod=$((-1 * temp));
fi

View File

@ -46,3 +46,5 @@ function ShowRunSize {
fi
du -hc $SOLARISANADIR/data_raw/${expName}_${RUN}_*.sol
}
2Working