1 #include "StFgtLenTreeMaker.h"
2 #include "StRoot/StEvent/StFgtCollection.h"
3 #include "StRoot/StEvent/StFgtHitCollection.h"
4 #include "StRoot/StEvent/StFgtHit.h"
5 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
6 #include "StRoot/StEvent/StEvent.h"
7 #include "StRoot/StEvent/StEventInfo.h"
17 eventPtr = (
StEvent*)GetInputDS(
"StEvent");
20 Bool_t anycluster=
false;
23 for(
int iD=0;iD<kFgtNumDiscs;iD++)
26 for(
int iCl=0;iCl<20;iCl++)
29 cl_seedType[iD][iCl]=-1;
31 cl_z[iD][iCl]=0.;cl_ez[iD][iCl]=0.;
32 cl_phi[iD][iCl]=0;cl_ephi[iD][iCl]=0;
33 cl_r[iD][iCl]=-1;cl_er[iD][iCl]=-1;
34 cl_charge[iD][iCl]=-1;cl_echarge[iD][iCl]=-1;
35 cl_numStrips[iD][iCl]=-1;
37 cl_tStrip[iD][iCl]=-1;
38 cl_layer[iD][iCl]=
' ';
40 cl_pointers[iD][iCl]=0;
41 maxadc[iD][iCl]=-1;seedadc[iD][iCl]=-1;
46 for(
int iTr=0;iTr<4;iTr++)
48 tr_phi[iTr]=0.;tr_slope[iTr]=0.;tr_vtx[iTr]=0.;
49 tr_chi2[iTr]=0.;tr_ncluster[iTr]=0;
50 trkArray[iTr].phi=0.;trkArray[iTr].slope=0.;trkArray[iTr].vtx=0.;
51 trkArray[iTr].chi2=0.;trkArray[iTr].ncluster=0;
52 for(
int iD=0;iD<6;iD++)
55 trkArray[iTr].clArray[iD]=0;
59 cout <<
"in plotter make " << endl;
60 for(
int iD=0;iD<kFgtNumDiscs;iD++)
62 cout <<
"trying to get clusters in disc " << iD << endl;
69 cout <<
"got collection, looking at hits .. " <<endl;
70 const StSPtrVecFgtHit &hitVec=clusterCol->getHitVec();
71 StSPtrVecFgtHitConstIterator hitIter;
72 for(hitIter=hitVec.begin();hitIter != hitVec.end();hitIter++)
74 Int_t iq=(*hitIter)->getQuad();
75 Float_t phi=(*hitIter)->getPositionPhi();
76 Float_t ephi=(*hitIter)->getErrorPhi();
77 Float_t r=(*hitIter)->getPositionR();
78 Float_t er=(*hitIter)->getErrorR();
79 Float_t z=(*hitIter)->getPositionZ();
80 Float_t ez=(*hitIter)->getErrorZ();
81 Int_t geoId=(*hitIter)->getCentralStripGeoId();
82 Float_t charge=(*hitIter)->charge();
83 Float_t echarge=(*hitIter)->getChargeUncert();
84 Int_t numStrips=(*hitIter)->getStripWeightMap().size();
87 Bool_t containsSeed=
false;
90 for(stripWeightMap_t::iterator it=(*hitIter)->getStripWeightMap().begin();it!=(*hitIter)->getStripWeightMap().end();it++)
92 if(it->first->getClusterSeedType()==kFgtSeedType1 || it->first->getClusterSeedType()==kFgtSeedType2 ||it->first->getClusterSeedType()==kFgtSeedType3)
95 if(seedA < it->first->getMaxAdc())seedA=it->first->getMaxAdc();
96 if(it->first->getClusterSeedType()==kFgtSeedType1)seedType=1;
97 if(it->first->getClusterSeedType()==kFgtSeedType2 && seedType!=1)seedType=2;
98 if(it->first->getClusterSeedType()==kFgtSeedType3 && seedType!=1 && seedType!=2)seedType=3;
100 if(maxA < it->first->getMaxAdc())maxA=it->first->getMaxAdc();
103 maxadc[iD][iCl]=maxA;
104 seedadc[iD][iCl]=seedA;
108 cout <<
"cluster contains a seed " <<endl;
109 if((*hitIter)->getLayer()!=
'R')
114 Short_t tDisc, tQuad,tStrip;
116 StFgtGeom::decodeGeoId(geoId,tDisc,tQuad,tLayer,tStrip);
118 cout <<
"filling cluster information " <<endl;
119 cl_geoId[iD][iCl]=geoId;
120 cl_seedType[iD][iCl]=seedType;
122 cl_z[iD][iCl]=z;cl_ez[iD][iCl]=ez;
123 cl_phi[iD][iCl]=phi;cl_ephi[iD][iCl]=ephi;
124 cl_r[iD][iCl]=r;cl_er[iD][iCl]=er;
125 cl_charge[iD][iCl]=charge;cl_echarge[iD][iCl]=echarge;
126 cl_numStrips[iD][iCl]=numStrips;
127 cl_tQuad[iD][iCl]=tQuad;
128 cl_tStrip[iD][iCl]=tStrip;
129 cl_layer[iD][iCl]=(*hitIter)->getLayer();
130 cl_key[iD][iCl]=(*hitIter)->getKey();
131 cl_pointers[iD][iCl]=(*hitIter);
141 for(Int_t iphi=0;iphi<2;iphi++)
147 Float_t maxA[6]={0.,0.,0.,0.,0.,0.};
148 Int_t kcl[6]={-1,-1,-1,-1,-1,-1};
150 for(Int_t iD=0;iD<6;iD++)
157 for(Int_t iC=0;iC<Ntot;iC++)
160 if(maxadc[iD][iC]>maxA[iD] && cl_quad[iD][iC]==iphi)
164 maxr=cl_r[iD][iC];emaxr=cl_er[iD][iC];
165 maxA[iD]=maxadc[iD][iC];
172 Int_t zbin=htrk->FindBin(maxz);
173 htrk->SetBinContent(zbin,maxr);
175 htrk->SetBinError(zbin,errR);
180 cout <<
"Track found, fitting .. " <<endl;
181 f0->SetParameter(0,0);
182 f0->SetParameter(1,0);
185 htrk->SetMaximum(50);
186 trkArray[iTrk].slope=f0->GetParameter(1);
187 trkArray[iTrk].vtx=-f0->GetParameter(0)/f0->GetParameter(1);
188 trkArray[iTrk].chi2=f0->GetChisquare()/(trNcl-2);
189 trkArray[iTrk].ncluster=trNcl;
190 trkArray[iTrk].phi=iphi;
191 printf(
"slope=%f vtx=%f chi2=%f \n",trkArray[iTrk].slope,trkArray[iTrk].vtx,trkArray[iTrk].chi2);
192 tr_phi[iTrk]=trkArray[iTrk].phi;
193 tr_slope[iTrk]=trkArray[iTrk].slope;
194 tr_vtx[iTrk]=trkArray[iTrk].vtx;
195 tr_chi2[iTrk]=trkArray[iTrk].chi2;
196 tr_ncluster[iTrk]=trkArray[iTrk].ncluster;
197 for(Int_t iD=0;iD<6;iD++)
199 printf(
"%d \n",kcl[iD]);
200 tr_iCl[iTrk][iD]=kcl[iD];
203 trkArray[iTrk].clArray[iD]=cl_pointers[iD][kcl[iD]];
204 Int_t qq=trkArray[iTrk].clArray[iD]->getQuad();
205 Float_t pp=trkArray[iTrk].clArray[iD]->getPositionPhi();
206 Float_t rr=trkArray[iTrk].clArray[iD]->getPositionR();
207 printf(
"********##########*************** iTrk=%d ncluster=%d iD=%d quad=%d phi=%f r=%f",iTrk,trkArray[iTrk].ncluster,iD,qq,pp,rr);
216 printf(
"*************** FILLING THE TREE %d **********************\n", iEvt);
221 for(
int iTr=0;iTr<Ntrk;iTr++)
223 for(
int iD=0;iD<6;iD++)
225 if(trkArray[iTr].clArray[iD])
228 StFgtHit* clTr=trkArray[iTr].clArray[iD];
229 for(stripWeightMap_t::iterator it=clTr->getStripWeightMap().begin();it!=clTr->getStripWeightMap().end();it++)
231 rdo=0;arm=apv=chn=stat=-1;
232 disk=quad=strip=-1.;layer=
' ';
233 ordinate=lowerSpan=upperSpan=-1.;
234 Int_t dof=Ntimebin-4;
236 it->first->getElecCoords( rdo, arm, apv, chn );
240 int geoId=it->first->getGeoId();
242 StFgtGeom::decodeGeoId(geoId,disk,quad,layer,strip);
243 StFgtGeom::getPhysicalCoordinate(geoId,disk,quad,layer,ordinate,lowerSpan,upperSpan);
248 ped=it->first->getPed();
249 pedSig=it->first->getPedErr();
251 for(Int_t is=0;is<7;is++){adc[is]=0.;};
252 for(Int_t is=0;is<Ntimebin;is++){
253 adc[is]=it->first->getAdc(is);
264 chi2=-1.;tau=0.;t0=0.;beta=0.;offset=0.;errCode=0;
266 for(Int_t is=0;is<Ntimebin;is++){
267 hh->SetBinContent(is+1,adc[is]);
268 hh->SetBinError(is+1,pedSig);
270 sprintf(hname,
"rdo%d_arm%d_apv%d_chn%d_%d",rdo,arm,apv,chn,iEvt);
272 mmax=hh->GetMaximumBin()-1;
273 mmin=hh->GetMinimumBin()-1;
274 adcmax=hh->GetBinContent(mmax+1);
276 for(Int_t is=0;is<Ntimebin;is++){
277 printf(
"%d ",it->first->getAdc(is));
279 printf(
"ped=%f \n",ped);
281 if(adcmax>fitThresh){
282 if(abs(mmax-mmin)==2 && mmin>0 && mmax>0 && mmin<Ntimebin-1 && mmax<Ntimebin-1){
283 Float_t middle1=(hh->GetBinContent(mmin)+hh->GetBinContent(mmin+2))/2.;
284 Float_t middle2=(hh->GetBinContent(mmax)+hh->GetBinContent(mmax+2))/2.;
285 if((middle1-hh->GetBinContent(mmin+1))/hh->GetBinError(mmin+1)>3. && (hh->GetBinContent(mmax+1)-middle2)/hh->GetBinError(mmax+1)>3.){errCode=1;}
288 for(Int_t is=0;is<Ntimebin;is++){
289 if(adc[is]>adcmax*0.95 && adcmax>20.*pedSig)highcnt++;
295 hh->Fit(FX,
"QI",
"",0.,Ntimebin);
296 chi2=FX->GetChisquare()/(Float_t)dof;
297 fmax=FX->GetMaximumX();
298 norm=FX->GetParameter(0);
299 tau=FX->GetParameter(1);
300 beta=FX->GetParameter(2);
301 offset=FX->GetParameter(3);
302 t0=FX->GetParameter(4);
315 StFgtLenTreeMaker::StFgtLenTreeMaker(
const Char_t* name):runningEvtNr(0)
323 StFgtLenTreeMaker::~StFgtLenTreeMaker()
331 gStyle->SetPalette(1);
332 cout <<
"cluster tree maker finish funciton " <<endl;
344 cout <<
"StFgtLenTreeMaker::Finish()" << endl;
349 Int_t StFgtLenTreeMaker::Init(){
354 htrk=
new TH1F(
"htrk",
"Hits in FGT Discs;z (cm);r (cm)",300,-100,200);
355 f0=
new TF1(
"f0",
"[0]+[1]*x",-500,500);
356 hh=
new TH1F(
"hh",
"hh",Ntimebin,0,Ntimebin);
361 Int_t StFgtLenTreeMaker::InitTree(){
364 if(fname.CompareTo(
"")==0){
365 LOG_ERROR <<
"No output file name given for the TTree" << endm;
369 TString outName=fname+
".tree.root";
370 fFgt =
new TFile(outName,
"recreate");
371 tCl =
new TTree(
"tCl",
"TTree for FGT cluster analysis");
372 tCl->Branch(
"iEvt",&iEvt,
"iEvt/I");
373 tCl->Branch(
"Ncl",Ncl,
"Ncl[6]/I");
374 tCl->Branch(
"cl_geoId",cl_geoId,
"cl_geoId[6][20]/I");
375 tCl->Branch(
"cl_seedType",cl_seedType,
"cl_seedType[6][20]/I");
376 tCl->Branch(
"cl_quad",cl_quad,
"cl_quad[6][20]/I");
377 tCl->Branch(
"cl_z",cl_z,
"cl_z[6][20]/F");
378 tCl->Branch(
"cl_ez",cl_ez,
"cl_ez[6][20]/F");
379 tCl->Branch(
"cl_phi",cl_phi,
"cl_phi[6][20]/F");
380 tCl->Branch(
"cl_ephi",cl_ephi,
"cl_ephi[6][20]/F");
381 tCl->Branch(
"cl_r",cl_r,
"cl_r[6][20]/F");
382 tCl->Branch(
"cl_er",cl_er,
"cl_er[6][20]/F");
383 tCl->Branch(
"cl_charge",cl_charge,
"cl_charge[6][20]/F");
384 tCl->Branch(
"cl_echarge",cl_echarge,
"cl_echarge[6][20]/F");
385 tCl->Branch(
"cl_numStrips",cl_numStrips,
"cl_numStrips[6][20]/I");
386 tCl->Branch(
"cl_tStrip",cl_tStrip,
"cl_tStrip[6][20]/I");
387 tCl->Branch(
"cl_layer",cl_layer,
"cl_layer[6][20]/B");
388 tCl->Branch(
"cl_key",cl_key,
"cl_key[6][20]/I");
389 tCl->Branch(
"maxadc",maxadc,
"maxadc[6][20]/I");
390 tCl->Branch(
"seedadc",seedadc,
"seedadc[6][20]/I");
391 tCl->Branch(
"Ntrk",&Ntrk,
"Ntrk/I");
392 tCl->Branch(
"tr_phi",tr_phi,
"tr_phi[4]/F");
393 tCl->Branch(
"tr_slope",tr_slope,
"tr_slope[4]/F");
394 tCl->Branch(
"tr_vtx",tr_vtx,
"tr_vtx[4]/F");
395 tCl->Branch(
"tr_chi2",tr_chi2,
"tr_chi2[4]/F");
396 tCl->Branch(
"tr_ncluster",tr_ncluster,
"tr_ncluster[4]/I");
397 tCl->Branch(
"tr_iCl",tr_iCl,
"tr_iCl[4][6]/I");
399 tFgt =
new TTree(
"tFgt",
"TTree for FGT time shape analysis");
401 tFgt->Branch(
"iEvt",&iEvt,
"iEvt/I");
402 tFgt->Branch(
"rdo",&rdo,
"rdo/I");
403 tFgt->Branch(
"arm",&arm,
"arm/I");
404 tFgt->Branch(
"apv",&apv,
"apv/I");
405 tFgt->Branch(
"chn",&chn,
"chn/I");
406 tFgt->Branch(
"disk",&disk,
"disk/S");
407 tFgt->Branch(
"quad",&quad,
"quad/S");
408 tFgt->Branch(
"strip",&strip,
"strip/S");
409 tFgt->Branch(
"stat",&stat,
"stat/S");
410 tFgt->Branch(
"ordinate",&ordinate,
"ordinate/D");
411 tFgt->Branch(
"lowerSpan",&lowerSpan,
"lowerSpan/D");
412 tFgt->Branch(
"upperSpan",&upperSpan,
"upperSpan/D");
413 tFgt->Branch(
"layer",&layer,
"layer/B");
414 tFgt->Branch(
"adc",adc,
"adc[7]/I");
415 tFgt->Branch(
"ped",&ped,
"ped/D");
416 tFgt->Branch(
"pedSig",&pedSig,
"pedSig/D");
417 tFgt->Branch(
"adcmax",&adcmax,
"adcmax/I");
418 tFgt->Branch(
"mmin",&mmin,
"mmin/I");
419 tFgt->Branch(
"mmax",&mmax,
"mmax/I");
420 tFgt->Branch(
"chi2",&chi2,
"chi2/F");
421 tFgt->Branch(
"fmax",&fmax,
"fmax/F");
422 tFgt->Branch(
"norm",&norm,
"norm/F");
423 tFgt->Branch(
"tau",&tau,
"tau/F");
424 tFgt->Branch(
"t0",&t0,
"t0/F");
425 tFgt->Branch(
"beta",&beta,
"beta/F");
426 tFgt->Branch(
"offset",&offset,
"offset/F");
427 tFgt->Branch(
"errCode",&errCode,
"errCode/I");
438 MyFunc(TF1 * f): fFunc(f) {}
439 double Evaluate (
double *x,
double * par)
const {
440 fFunc->SetParameter(0,par[0]);
441 fFunc->SetParameter(1,par[1]);
442 fFunc->SetParameter(2,par[2]);
443 fFunc->SetParameter(3,par[3]);
445 if(x[0]-par[4]<0.){val=par[3];}
446 else{val=fFunc->Eval(x[0]-par[4]);};
453 void StFgtLenTreeMaker::FitFunc()
455 fs =
new TF1(
"fs",
"[0]*x**[2]*exp(-x/[1])+[3]",-100,100);
457 FX =
new TF1(
"FX",mf,&MyFunc::Evaluate,-10.,10.,5);
463 void StFgtLenTreeMaker::InitFX()
465 FX->SetParameter(0,200.);
466 FX->SetParLimits(0,0.,100000.);
467 FX->SetParameter(1,1.);
468 FX->SetParLimits(1,0.1,10.);
469 FX->FixParameter(2,2.);
470 FX->SetParameter(4,0.);
471 FX->SetParLimits(4,-10.,17.);