diff --git a/.vscode/settings.json b/.vscode/settings.json index 41fe7f2..6387501 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -91,7 +91,8 @@ "transfer_test.C": "cpp", "Transfer.C": "cpp", "Simulation_Helper.C": "cpp", - "Check_Simulation.C": "cpp" + "Check_Simulation.C": "cpp", + "AutoFit.C": "cpp" }, "better-comments.multilineComments": true, diff --git a/armory/AutoFit.C b/armory/AutoFit.C index 1881fff..95e2fc5 100644 --- a/armory/AutoFit.C +++ b/armory/AutoFit.C @@ -21,9 +21,9 @@ //Global fit paramaters -vector BestFitMean; -vector BestFitCount; -vector BestFitSigma; +std::vector BestFitMean; +std::vector BestFitCount; +std::vector BestFitSigma; TString recentFitMethod; diff --git a/armory/GeneralSort.C b/armory/GeneralSort.C index 08f0196..7c4145f 100644 --- a/armory/GeneralSort.C +++ b/armory/GeneralSort.C @@ -12,7 +12,6 @@ #include #include - Long64_t processedEntry = 0; float lastPercentage = 0; @@ -26,6 +25,12 @@ Bool_t GeneralSort::Process(Long64_t entry){ for( int j = 0; j < detNum[i]; j++){ eE[i][j] = TMath::QuietNaN(); eT[i][j] = 0; + + if( isTraceExist && traceMethod > 0){ + teE[i][j] = TMath::QuietNaN(); + teT[i][j] = TMath::QuietNaN(); + teR[i][j] = TMath::QuietNaN(); + } } } @@ -40,9 +45,7 @@ Bool_t GeneralSort::Process(Long64_t entry){ for( int i = 0 ; i < multi; i++){ int detID = mapping[bd[i]][ch[i]]; int detType = FindDetType(detID, detMaxID); - int low = (i == 0 ? 0 : detMaxID[detType-1]); - int reducedDetID = detID - low; eE[detType][reducedDetID] = e[i] * detParity[detType]; @@ -50,6 +53,7 @@ Bool_t GeneralSort::Process(Long64_t entry){ } + //@===================================== Trace if( isTraceExist && traceMethod >= 0 ){ b_tl->GetEntry(entry); @@ -74,6 +78,42 @@ Bool_t GeneralSort::Process(Long64_t entry){ gTrace->SetPoint(k, k, trace[i][k]); } + //***=================== fit + if( traceMethod == 1){ + gFit = new TF1("gFit", fitFunc, 0, traceLength, numPara); + gFit->SetLineColor(6); + gFit->SetRange(0, traceLength); + + gFit->SetParameter(0, e[i]); + gFit->SetParameter(1, 100); //triggerTime //TODO how to not hardcode? + gFit->SetParameter(2, 10); //rise time //TODO how to not hardcode? + gFit->SetParameter(3, trace[i][0]); //base line + gFit->SetParameter(4, 100); // decay //TODO how to not hardcode? + gFit->SetParameter(5, -0.01); // pre-rise slope //TODO how to not hardcode? + + gFit->SetParLimits(1, 85, 125); //raneg for the trigger time + gFit->SetParLimits(5, -2, 0); + + gTrace->Fit("gFit", "QR", "", 0, traceLength); + + + int detType = FindDetType(detID, detMaxID); + int low = (i == 0 ? 0 : detMaxID[detType-1]); + int reducedDetID = detID - low; + + teE[detType][reducedDetID] = gFit->GetParameter(0); + teT[detType][reducedDetID] = gFit->GetParameter(1); + teR[detType][reducedDetID] = gFit->GetParameter(2); + + delete gFit; + gFit = nullptr; + } + + //***=================== Trapezoid filter + if( traceMethod == 2){ + //TODO + } + } } diff --git a/armory/GeneralSort.h b/armory/GeneralSort.h index da297ba..ad9386b 100644 --- a/armory/GeneralSort.h +++ b/armory/GeneralSort.h @@ -28,11 +28,12 @@ the sequence of each method ******************************************/ - /// in Process_Sort, copy the GeneralSortMapping.h to ~/.proof/working/ #include "../working/Mapping.h" #include "../armory/AnalysisLib.h" +//^######################################### FIT FUNCTION +const int numPara = 6; double fitFunc(double * x, double * par){ /// par[0] = A /// par[1] = t0 @@ -46,6 +47,50 @@ double fitFunc(double * x, double * par){ return par[3] + par[0] * (1 - TMath::Exp(- (x[0] - par[1]) / par[2]) ) * TMath::Exp(- (x[0] - par[1]) / par[4]); } +//^######################################### TRAPEZOID +TGraph * TrapezoidFilter(TGraph * trace){ + ///Trapezoid filter https://doi.org/10.1016/0168-9002(94)91652-7 + + //TODO how to not hard code? + int baseLineEnd = 80; + int riseTime = 10; //ch + int flatTop = 20; + float decayTime = 2000; + + TGraph * trapezoid = new TGraph(); + trapezoid->Clear(); + + ///find baseline; + double baseline = 0; + for( int i = 0; i < baseLineEnd; i++){ + baseline += trace->Eval(i); + } + baseline = baseline*1./baseLineEnd; + + int length = trace->GetN(); + + double pn = 0.; + double sn = 0.; + for( int i = 0; i < length ; i++){ + + double dlk = trace->Eval(i) - baseline; + if( i - riseTime >= 0 ) dlk -= trace->Eval(i - riseTime) - baseline; + if( i - flatTop - riseTime >= 0 ) dlk -= trace->Eval(i - flatTop - riseTime) - baseline; + if( i - flatTop - 2*riseTime >= 0) dlk += trace->Eval(i - flatTop - 2*riseTime) - baseline; + + if( i == 0 ){ + pn = dlk; + sn = pn + dlk*decayTime; + }else{ + pn = pn + dlk; + sn = sn + pn + dlk*decayTime; + } + trapezoid->SetPoint(i, i, sn / decayTime / riseTime); + } + return trapezoid; +} + +//^######################################### Class definition // Header file for the classes stored in the TTree if any. class GeneralSort : public TSelector { public : @@ -95,6 +140,7 @@ public : arr = nullptr; gTrace = nullptr; + gFit = nullptr; arrTrapezoid = nullptr; gTrapezoid = nullptr; @@ -146,6 +192,7 @@ public : //trace TClonesArray * arr ;//! TGraph * gTrace; //! + TF1 * gFit; //! TClonesArray * arrTrapezoid ;//! TGraph * gTrapezoid; //! diff --git a/armory/Process_Run b/armory/Process_Run index 631c8cb..0ee760a 100755 --- a/armory/Process_Run +++ b/armory/Process_Run @@ -15,7 +15,7 @@ if [ $# -eq 0 ] || [ $1 == "-help" ]; then echo " RunNum = run number / \"lastRun\" " echo " EventBld = 2/1/0/-1/-2 || 2 = with Trace" echo " GeneralSort = n/0/-n || n = number of worker" - echo " TraceMethod = -1/0/1/2 || -1 no trace, 0 save trace, 1 fit, 2 trapezoid" + echo " TraceMethod = -1/0/1/2 || -1 no trace, 0 save trace, 1 fit, 2 trapezoid(not implemented)" echo " Monitors = 2/1/0 || 1 = single run, 2 = using the list in ChainMonitors.C" echo " 10 = single run and post to websrv, 20 = list runs and post to websrv" echo ""