8 #include "StGmtClusterMaker.h"
9 #include "StEvent/StEvent.h"
10 #include "StEvent/StGmtCollection.h"
11 #include "StEvent/StGmtHit.h"
12 #include "StGmtUtil/geometry/StGmtGeom.h"
13 #include "StMessMgr.h"
17 #include "TSpectrum.h"
19 int StGmtClusterMaker::gmtStat = 0;
20 const unsigned int CLUS_BINS = 128;
21 const double CLUS_MIN = 0.0;
22 const double CLUS_MAX = 128*0.08;
23 const unsigned int MAX_PEAKS = 20;
26 inline Double_t MyGaus(Double_t x, Double_t mean, Double_t sigma, Double_t delta) {
27 return TMath::Freq((x-mean+delta/2)/sigma)-TMath::Freq((x-mean-delta/2)/sigma);
31 Double_t fpeaks(Double_t *x, Double_t *par) {
33 for (UInt_t p=0;p<par[0];p++) {
34 Double_t norm = TMath::Exp(par[3*p+1]);
35 Double_t mean = par[3*p+2];
36 Double_t sigma = par[3*p+3];
37 result += norm*MyGaus(x[0],mean,sigma,0.08);
43 TF1* StGmtClusterMaker::FindPeaks(TH1F* hist) {
44 TSpectrum spect(MAX_PEAKS);
45 TF1 back(
"poly",
"pol0",CLUS_MIN,CLUS_MAX);
46 Double_t par[MAX_PEAKS*3+1];
48 auto xpeaks = spect.GetPositionX();
52 UInt_t nfound = spect.GetNPeaks();
53 for(UInt_t i=0; i < nfound; i++) {
54 Double_t xp=xpeaks[i];
55 int bin=hist->GetXaxis()->FindBin(xp);
56 Double_t yp=hist->GetBinContent(bin);
57 Double_t err=hist->GetBinError(bin);
58 if(err<=0.0)
continue;
60 if((yp-err*3) < back.GetParameter(0))
continue;
61 Double_t yp_left=hist->GetBinContent(bin-1);
62 Double_t yp_right=hist->GetBinContent(bin+1);
63 Double_t err_left=hist->GetBinError(bin-1);
64 Double_t err_right=hist->GetBinError(bin+1);
65 Double_t yp_sum=yp+yp_left+yp_right;
66 Double_t err_sum=TMath::Sqrt(err*err+err_left*err_left+err_right*err_right);
67 if((yp_sum-3*err_sum) < back.GetParameter(0))
continue;
69 par[3*npx+1]=TMath::Log(yp);
74 if (Debug()) {LOG_INFO << hist->GetName() <<
" found " << nfound <<
" Accpeted " << npx << endm;}
77 TString funcName=Form(
"Func%s",hist->GetName());
78 TF1* fitFunc =
nullptr;
79 fitFunc = (TF1*)gROOT->GetListOfFunctions()->FindObject(funcName);
80 if ( fitFunc )
delete fitFunc;
81 fitFunc =
new TF1(funcName,fpeaks,CLUS_MIN,CLUS_MAX,3*npx+1);
83 for(UInt_t i=0; i < npx; i++) {fitFunc->SetParLimits(3*i+3,0.08*0.5,10*0.08);}
84 fitFunc->SetParameters(par);
85 fitFunc->FixParameter(0,(
double)npx);
86 fitFunc->SetNpx(1000);
87 fitFunc->SetLineColor(kGreen);
89 TVirtualFitter::SetDefaultFitter(
"Fumili");
90 int isOk=hist->Fit(fitFunc);
91 if(isOk) isOk=hist->Fit(fitFunc);
99 static TCanvas* canv=0;
100 static TH1F* histX=0;
101 static TH1F* histY=0;
102 static TProfile* profX[8]={0};
103 static TProfile* profY[8]={0};
107 UInt_t stripsNum=strips.getNumStrips();
112 TSpectrum spectX(); TSpectrum spectY();
113 LOG_INFO <<
"Created TSpectrum" << endm;
115 TProfile* profPointer;
118 name=
"PedestalX_"; name += module;
119 profX[module]=
new TProfile(name,name,CLUS_BINS,CLUS_MIN,CLUS_MAX,
"s");
122 name =
"PedestalY_"; name += module;
123 profY[module]=
new TProfile(name,name,CLUS_BINS,CLUS_MIN,CLUS_MAX,
"s");
125 if(!histX) histX=
new TH1F(
"ClusterX",
"ClusterX",CLUS_BINS,CLUS_MIN,CLUS_MAX);
126 if(!histY) histY=
new TH1F(
"ClusterY",
"ClusterY",CLUS_BINS,CLUS_MIN,CLUS_MAX);
129 canv = (TCanvas *) gROOT->GetListOfCanvases()->FindObject(
"GmtClusters");
130 if(!canv) canv=
new TCanvas(
"GmtClusters",
"GmtClusters",768,768);
134 histX->Reset(); histY->Reset();
135 TProfile profXold(*profX[module]); TProfile profYold(*profY[module]);
136 for(UInt_t iStrip=0;iStrip<stripsNum;iStrip++) {
138 pStrip=strips.getSortedStrip(iStrip);
139 if(!pStrip->
isY()) { profPointer=profX[module]; histPointer=histX; }
140 else { profPointer=profY[module]; histPointer=histY; }
141 for(UInt_t iTimeBin=0;iTimeBin<kGmtNumTimeBins;iTimeBin++) {
142 adc_buf=pStrip->
getAdc(iTimeBin);
143 if(adc_buf>-999) adc+=adc_buf;
146 int bin=profPointer->Fill(position,adc);
147 Double_t error=TMath::Sqrt(adc);
148 histPointer->Fill(position,adc);
149 histPointer->SetBinError(bin,error);
151 if (events < 5)
return;
152 histX->Add(&profXold,-1.0); histY->Add(&profYold,-1.0);
154 TF1 *fitX=0, *fitY=0;
155 fitX = FindPeaks(histX); fitY = FindPeaks(histY);
156 UInt_t idx[MAX_PEAKS], idy[MAX_PEAKS];
157 UInt_t nClusX=0, nClusY=0;
159 for(UInt_t i=0; i<fitX->GetParameter(0); i++) {
160 if (fitX->GetParameter(3*i+3) > 0.4)
continue;
161 if (fitX->GetParameter(3*i+1) < 5.0)
continue;
165 if (nClusX) *profX[module]=profXold;
166 if (Debug()) {LOG_INFO <<
"######XPEAKS found =" << fitX->GetParameter(0) <<
", Clusters fitted =" << nClusX << endm;}
167 }
else if (Debug()) {LOG_INFO <<
"######XNULL" << endm; }
169 for(UInt_t i=0; i<fitY->GetParameter(3*i+3); i++) {
170 if (fitY->GetParameter(3*i+3) > 0.4)
continue;
171 if (fitY->GetParameter(3*i+1) < 5.0)
continue;
175 if (nClusY) *profY[module]=profYold;
176 if (Debug()) {LOG_INFO <<
"######YPEAKS found =" << fitY->GetParameter(0) <<
", Clusters fitted =" << nClusY << endm;}
177 }
else if (Debug()) {LOG_INFO <<
"######YNULL" << endm; }
178 for(UInt_t i=0; i < nClusX; i++) {
180 for(UInt_t j = 0; j < nClusY; j++) {
185 TMath::Exp(fitX->GetParameter(3*nx+1)),
186 TMath::Exp(fitY->GetParameter(3*ny+1)),
187 fitX->GetParError(3*nx+1),
188 fitY->GetParError(3*ny+1),
189 fitX->GetParameter(3*nx+2),
190 fitY->GetParameter(3*ny+2),
191 fitX->GetParError(3*nx+2),
192 fitY->GetParError(3*ny+2),
193 fitX->GetParameter(3*nx+3),
194 fitY->GetParameter(3*ny+3),
195 fitX->GetParError(3*nx+3),
196 fitY->GetParError(3*ny+3));
197 if (Debug()) newCluster->
Print();
206 profX[module]->Draw();
208 profY[module]->Draw();
218 if (nClusX || nClusY) {
219 while (!gSystem->ProcessEvents()){gSystem->Sleep(200);}
225 StGmtClusterMaker::StGmtClusterMaker(
const Char_t* name ) :
227 SetAttr(
"gmtCosmics" ,kFALSE);
232 LOG_INFO <<
"MAKE of StGmtClusterMaker" << endm;
234 static ULong_t nEvents=0;
244 LOG_ERROR <<
"Error getting pointer to StEvent from '" << ClassName() <<
"'" << endm;
248 if(!gmtCollectionPtr) {
249 LOG_WARN <<
"Error getting pointer to StGmtCollection from '" << ClassName() <<
"'" << endm;
252 UInt_t noModWithGMT = 0;
253 for(UInt_t moduleIdx=0; moduleIdx<gmtCollectionPtr->
getNumModules(); moduleIdx++) {
255 LOG_INFO <<
"module: " << moduleIdx <<
" has strips: \t" << gmtCollectionPtr->
getNumStrips(moduleIdx) << endm;
256 LOG_INFO <<
"Collection =\t" << gmtCollectionPtr->
getNumStrips() <<
"\t"
259 Int_t nelements = gmtCollectionPtr->
getNumStrips(moduleIdx);
260 if(nelements < kGmtNumStripsPerModule) {
262 LOG_WARN <<
"StClusterMaker::Make(): no data for module " << moduleIdx << endm;
268 ClusterBuilder(nEvents,moduleIdx,*stripCollectionPtr,*hitCollectionPtr);
270 if(stripCollectionPtr && hitCollectionPtr && hitCollectionPtr->
getHitVec().size()) {
272 LOG_INFO <<
"Cluster " << stripCollectionPtr->getNumStrips() <<
"strips\tin module" << stripCollectionPtr->getModule() << endm;
276 if (noModWithGMT) nEvents++;
279 LOG_INFO <<
"End of gmt-clust-maker, print all strips & clusters: " << endm;
281 <<
" totClust=" << gmtCollectionPtr->
getNumHits() <<endm;
283 if (IAttr(
"gmtCosmics")) {
288 for (UShort_t m = 0; m < NumModules; m++) {
290 if (! coll)
continue;
291 const StSPtrVecGmtHit &hits = coll->
getHitVec();
292 UInt_t NoHits = hits.size();
293 for (UInt_t l = 0; l < NoHits; l++) {
305 Int_t StGmtClusterMaker::Init() {
306 LOG_INFO <<
"INTI of StGmtClusterMaker" << endm;
307 if (IAttr(
"gmtCosmics")) SetAttr(
".Privilege",kTRUE);
Holds collections of GMT data.
StGmtHitCollection * getHitCollection(unsigned short moduleIdx)
Pointer to the GMT hit collection in the i-th module.
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
size_t getNumStrips() const
Number total number of strips.
Int_t isY() const
Is it a pad?
Holds collection of GMT hits in the module.
Holds data for the hit in GMT.
size_t getNumModules() const
Number of modules.
void Print(Option_t *option="") const
Print hit information (parameters)
size_t getNumHits() const
Number total number of hits.
Float_t getPosition() const
Coordinate position relative to local origin (in module)
size_t getNumPoints() const
Number of points.
StGmtStripCollection * getStripCollection(unsigned short moduleIdx)
Pointer to the GMT strip collection in the i-th module.
Short_t getAdc(Int_t tb=-1) const
ADC in a strip for a given time bin.
Holds data for the strip in GMT.
StSPtrVecGmtHit & getHitVec()
Vector of hits that belong to the module.