StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtClustFindMaker.cxx
1 // *-- Author : J.Balewski
2 //
3 // $Id: StFgtClustFindMaker.cxx,v 1.2 2011/04/11 19:35:38 fisyak Exp $
4 
5 #include <TVector3.h>
6 #include <TH2.h>
7 #include <TF1.h>
8 #include <TFile.h>
9 #include <TLine.h>
10 #include <TPolyLine.h>
11 #include <TCrown.h>
12 #include <TRandom3.h>
13 
14 #include "StFgtClustFindMaker.h"
15 #include "StFgtSlowSimuMaker.h"
16 
17 ClassImp(StFgtClustFindMaker)
18 
19 
20 //--------------------------------------------
23  setHList(0);
24  memset(hA,0,sizeof(hA));
25  geom=new StFgtGeom();
26  mRnd = new TRandom3(); // general use random generator
27  // mRnd->SetSeed(0); // activate, assure every set of data is different
28 
29  par_bx_valley=3; // min separation between 2 clusters
30  par_cl_width=3; //min cluster width
31  par_seedStripThres=0; // a.u. for valid cluster
32  par_clusterMinAmpl=0.0; // a.u., min cluster ampl
33  par_stripNoiseSigma=0.0 ; // a.u.,added as gauss noise to every strip
34 
35 }
36 
37 //--------------------------------------------
38 void
40  int i;
41  for(i=0;i<kFgtMxDisk;i++) {
42  mRadClustList[i].clear();
43  mPhiClustList[i].clear();
44  }
46 }
47 
48 //--------------------------------------------
49 StFgtClustFindMaker::~StFgtClustFindMaker(){
50 
51 }
52 
53 //_______________________________________________
54 //________________________________________________
55 void
56 StFgtClustFindMaker::saveHisto(TString fname){
57  TString outName=fname+".hist.root";
58  TFile f( outName,"recreate");
59  assert(f.IsOpen());
60  printf("%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
61 
62  HList->Write();
63  f.Close();
64 
65 }
66 
67 
68 //--------------------------------------------
69 //--------------------------------------------
70 //--------------------------------------------
71 Int_t
73  LOG_INFO<<"::Finish() \n"<< endm;
74 
75 
76  return StMaker::Finish();
77 }
78 
79 //--------------------------------------------
80 //--------------------------------------------
81 //--------------------------------------------
82 Int_t
84  mInpEve++;
85 
86  LOG_INFO <<"::Make() inpEve="<< mInpEve<<endm;
87  StFgtSlowSimuMaker *ssMk=(StFgtSlowSimuMaker *) GetMaker("FgtSlowSimu");
88  assert(ssMk);
89 
90  printf(" INPUT: strips\n disk Rad: #strip -> #clust Phi: #strip -> #clust \n");
91 
92  // .... find 1D clusters in every plane of all disks
93  for(int iDisk=0;iDisk<kFgtMxDisk;iDisk++) {
94  int nRCl=findClust1D(ssMk->mRadAdcList[iDisk],mRadClustList[iDisk]);
95  int nPCl=findClust1D(ssMk->mPhiAdcList[iDisk],mPhiClustList[iDisk]);
96 
97  printf("disk=%d %d -->%d %d -->%d \n",iDisk+1,ssMk->mRadAdcList[iDisk].size(),nRCl,ssMk->mPhiAdcList[iDisk].size(),nPCl);
98 
99  UInt_t i;
100  int j;
101 
102  //::::::::::::::::process Rad-strips::::::::::::::::
103  int nRQuad[kFgtMxQuad]; memset(nRQuad,0,sizeof(nRQuad));
104 // delete the last cluster if strip ID out of boundary
105  if(mRadClustList[iDisk].size() > 0) {
106  if(mRadClustList[iDisk][mRadClustList[iDisk].size()-1].fBin_mean >
107  geom->radStripLOCId_number() * kFgtMxQuad - 1) {
108  cout << "A Rad cluster deleted with fBin_mean = " <<
109  mRadClustList[iDisk][mRadClustList[iDisk].size()-1].fBin_mean << endl;
110 
111  mRadClustList[iDisk].erase(mRadClustList[iDisk].end());
112  }
113  }
114 
115  for(i=0; i<mRadClustList[iDisk].size(); i++) {
116  fgt_cluster1D *cl=&mRadClustList[iDisk][i];
117  cl->position=geom->stripID2Rxy(cl->fBin_mean);
118  int iRadID=(int) cl->fBin_mean; // get rid of fractional bin accuracy
119  cl->iQuad=iRadID / geom->radStripLOCId_number();
120  printf("icl=%d rRad=%.3f totAmpl=%.1f totStrip=%d\n",i,cl->position,cl->totAmpl,cl->nbin);
121 // assert( cl->iQuad <kFgtMxQuad);
122  if(cl->iQuad >= 0 && cl->iQuad < kFgtMxQuad) {
123  nRQuad[cl->iQuad]++;
124  hA[5]->Fill(cl->peakAmpl);
125  hA[7]->Fill(cl->nbin);
126  hA[9]->Fill(cl->peakAmpl/cl->totAmpl);
127  }
128  else
129  cout << "ClusterFinder (Rad) error: iQuad = " << cl->iQuad << endl;
130  }
131 
132 
133  //::::::::::::::::process Phi-strips::::::::::::::::
134  int nPQuad[kFgtMxQuad]; memset(nPQuad,0,sizeof(nPQuad));
135 // delete the last cluster if strip ID out of boundary
136  if(mPhiClustList[iDisk].size() > 0) {
137  if(mPhiClustList[iDisk][mPhiClustList[iDisk].size()-1].fBin_mean >
138  geom->phiStripLOCId_number() * kFgtMxQuad - 1 ) {
139  cout << "A Phi cluster deleted with fBin_mean = " <<
140  mPhiClustList[iDisk][mPhiClustList[iDisk].size()-1].fBin_mean << endl;
141 
142  mPhiClustList[iDisk].erase(mPhiClustList[iDisk].end());
143  }
144  }
145 
146  for(i=0; i<mPhiClustList[iDisk].size(); i++) {
147  fgt_cluster1D *cl=&mPhiClustList[iDisk][i];
148  cl->position=geom->stripID2PhiLab(cl->fBin_mean);
149  int iPhiID=(int) cl->fBin_mean; // get rid of fractional bin accuracy
150  cl->iQuad=iPhiID / geom->phiStripLOCId_number();
151  printf("icl=%d rPhi/deg=%.3f totAmpl=%.1f totStrip=%d\n",i,cl->position/3.1417*180.,cl->totAmpl,cl->nbin);
152  if(cl->iQuad >= 0 && cl->iQuad < kFgtMxQuad) {
153  nPQuad[cl->iQuad]++;
154 
155  hA[6]->Fill(cl->peakAmpl);
156  hA[8]->Fill(cl->nbin);
157  hA[10]->Fill(cl->peakAmpl/cl->totAmpl);
158  }
159  else
160  cout << "ClusterFinder (Phi) error: iQuad = " << cl->iQuad << endl;
161  }
162 
163 
164  //... QA results for both planes
165  hA[0]->Fill(20*iDisk+0,nRCl);
166  hA[0]->Fill(20*iDisk+1,nPCl);
167 
168  for(j=0;j<kFgtMxQuad;j++) {
169  hA[1]->Fill(nRQuad[j]);
170  hA[2]->Fill(nPQuad[j]);
171  hA[3]->Fill(nRQuad[j],nPQuad[j]);
172  cout << "iquad nRQuad, nPQuad = " << j << " " << nRQuad[j]
173  << " " << nPQuad[j] << endl;
174  }
175 
176  } // end of given disk
177 
178  return kStOK;
179 }
180 
181 
182 
183 //--------------------------------------------
184 //--------------------------------------------
185 //--------------------------------------------
186 Int_t
187 StFgtClustFindMaker::Init(){
188  LOG_INFO<<"::Init() "<< endm;
189  assert(HList);
190  mInpEve=0;
191  int i;
192  LOG_INFO<<Form("::Init params minPeakWidth=%d, minPeakSepar=%d (# of strips), seedStripThres=%.1f a.u., clusterMinAmpl=%.1f a.u., stripNoiseSigma=%.1f a.u.",par_cl_width,par_bx_valley,par_seedStripThres,par_clusterMinAmpl,par_stripNoiseSigma)<< endm;
193  assert(par_clusterMinAmpl>=0);
194  assert(par_stripNoiseSigma>=0);
195 
196  hA[0]=new TH1F("cl_Stat1D","Found 1D clusters, odd=Rad, even=Phi; x=20*disk",180, -0.5,179.5);
197 
198  hA[1]=new TH1F("cl_rMul","Mult Rad-clusters, 1D , any disks; multiplicity/Quad/event",6,0.5,6.5); // zero is in underflow
199  hA[2]=new TH1F("cl_pMul","Mult Phi-clusters, 1D , any disks; multiplicity/Quad/event",6,0.5,6.5); // zero is in underflow
200  hA[3]=new TH2F("cl_rpMul","Mult per quadrant, 2x1D, any disks;Phi-Rad multiplicity/Quad/event; rad-mult",6,0.5,6.5,6,0.5,6.5); // zero is in underflow
201 
202 
203  hA[5]= new TH1F("cl_RmxAmp"," Rad-strips 1D clust ; Max strip Amplitude (a.u.)",100,0,1000);
204  hA[6]= new TH1F("cl_PmxAmp"," phi-strips 1D clust ; Max strip Amplitude (a.u.)",100,0,1000);
205 
206  hA[7]= new TH1F("cl_Rwid"," Rad-strips 1D clust ;total cluster width ",10,0.5,10.5);
207  hA[8]= new TH1F("cl_Pwid"," Phi-strips 1D clust ;total cluster width ",20,0.5,20.5);
208 
209  hA[9] = new TH1F("cl_Rpf"," Rad-strips 1D clust ; fraction of peak strip energy ",50,0.,1.);
210  hA[10]= new TH1F("cl_Ppf"," Phi-strips 1D clust ; fraction of peak strip energy ",50,0.,1.);
211 
212 
213 
214  for(i=0;i<mxH;i++)
215  if(hA[i]) HList->Add(hA[i]);
216 
217  return StMaker::Init();
218 }
219 
220 //--------------------------------------------
221 //--------------------------------------------
222 //--------------------------------------------
223 int
224 StFgtClustFindMaker::findClust1D(vector<fgt_strip> &sL, vector<fgt_cluster1D> &clL) {
225  // printf("AA %d\n",sL.size());
226  if(sL.size()<=0) return 0;
227  fgt_strip fake; // assures the last cluster gets saved by the code below
228  fake.id=99999999; // set above highest strip
229  sL.push_back(fake);
230 
231  int bx0=-999,bx1=bx0; // first and last bin of current cluster
232  double sum=0, sumx=0, peakA=0;
233  for(UInt_t i=0;i<sL.size();i++) {
234  assert(sL[i].id>=bx1); //assumes strips are ordered increasingly
235  if(sL[i].id>=bx1+par_bx_valley) { // new clusters starts
236  int nbin=bx1-bx0+1;
237  if(nbin>=par_cl_width && peakA>par_seedStripThres) {
238  if(par_stripNoiseSigma>0) { // fold in noise
239  // printf(" before noise sum=%.3f sumx=%.3f meanX=%.3f\n",sum,sumx,sumx/sum);
240  int k;
241  for(k=bx0-1;k<=bx1+1;k++){
242  double rndAdc=mRnd->Gaus(0,par_stripNoiseSigma);
243  sum+=rndAdc;
244  sumx+=rndAdc*(k+0.5); // use center of the bin
245  }
246  // printf(" after noise sum=%.3f sumx=%.3f meanX=%.3f\n",sum,sumx,sumx/sum);
247 
248  }
249  if(sum > par_clusterMinAmpl) { // record old cluster if surviving noise
250  fgt_cluster1D cl;
251  cl.nbin=nbin;
252  cl.fBin_mean=sumx/sum;
253  cl.totAmpl=sum;
254  cl.peakAmpl=peakA;
255  printf("add cl=%d fBin=%.3f, sum=%.1f peakA=%.1f width=%d\n",clL.size(),cl.fBin_mean,sum,peakA,nbin);
256  clL.push_back(cl);
257  }
258  }
259  sum=sumx=peakA=0;
260  bx1=bx0=sL[i].id;
261  }
262  sum+=sL[i].adc;
263  sumx+=sL[i].adc*(sL[i].id+0.5); // use center of thebin
264  if(peakA<sL[i].adc) peakA=sL[i].adc;
265  bx1=sL[i].id;
266  //printf("\nnc=%d i=%d bx=%d adc=%.1f sum=%f sumx=%.1f bx0=%d bx1=%d\n",clL.size(),i,sL[i].id,sL[i].adc,sum,sumx,bx0,bx1);
267  }
268  return clL.size();
269 }
270 
271 
274 
275 // $Log: StFgtClustFindMaker.cxx,v $
276 // Revision 1.2 2011/04/11 19:35:38 fisyak
277 // Replace uint by UInt_t, use TMath
278 //
279 // Revision 1.1 2011/04/07 19:31:22 balewski
280 // start
281 //
282 
283 
284 
285 
286 
virtual void Clear(Option_t *option="")
User defined functions.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776