20 #include "StFgtTimeShapeMaker.h"
21 #include "StRoot/StEvent/StFgtCollection.h"
22 #include "StRoot/StEvent/StFgtStrip.h"
23 #include "StRoot/StEvent/StEvent.h"
24 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
25 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
30 StFgtTimeShapeMaker::StFgtTimeShapeMaker(
const Char_t* name ,
const Char_t* dbMkrName ) :
StMaker( name ), mDbMkrName( dbMkrName ), mFgtDbMkr(0) {
39 Int_t StFgtTimeShapeMaker::Init(){
44 mFgtDbMkr =
static_cast< StFgtDbMaker*
>( GetMaker( mDbMkrName.data() ) );
46 if( !ierr && !mFgtDbMkr ){
47 LOG_FATAL <<
"Error finding mFgtDbMkr named '" << mDbMkrName <<
"'" << endm;
51 if( !mFgtDbMkr->InheritsFrom(
"StFgtDbMaker") ){
52 LOG_FATAL <<
"StFgtDbMkr does not inherit from StFgtDbMaker" << endm;
53 LOG_FATAL <<
"Name is '" << mFgtDbMkr->
GetName() <<
"', class is '" << mFgtDbMkr->ClassName() << endm;
58 mFgtDbMkr =
static_cast< StFgtDbMaker*
>( GetMakerInheritsFrom(
"StFgtDbMaker" ) );
60 LOG_FATAL <<
"StFgtDbMaker name not provided and error finding StFgtDbMaker" << endm;
67 TFile ftau(
"htau.root",
"read");
69 htau=(TH1F*)ftau.Get(
"htau");
72 LOG_FATAL <<
"Tau parameter fix requested, but htau.root not found" << endm;
77 LOG_INFO <<
"Using date and time " << mFgtDbMkr->GetDateTime().GetDate() <<
", "
78 << mFgtDbMkr->GetDateTime().GetTime() << endm;
83 hh=
new TH1F(
"hh",
"hh",Ntimebin,0,Ntimebin);
88 StFgtTimeShapeMaker::~StFgtTimeShapeMaker(){
91 Int_t StFgtTimeShapeMaker::InitTree(){
94 if(fname.CompareTo(
"")==0){
95 LOG_ERROR <<
"No output file name given for the TTree" << endm;
99 TString outName=fname+
".tree.root";
100 fFgt =
new TFile(outName,
"recreate");
101 tFgt =
new TTree(
"tFgt",
"TTree for FGT time shape analysis");
103 tFgt->Branch(
"iEvt",&iEvt,
"iEvt/I");
104 tFgt->Branch(
"rdo",&rdo,
"rdo/I");
105 tFgt->Branch(
"arm",&arm,
"arm/I");
106 tFgt->Branch(
"apv",&apv,
"apv/I");
107 tFgt->Branch(
"chn",&chn,
"chn/I");
108 tFgt->Branch(
"disk",&disk,
"disk/S");
109 tFgt->Branch(
"quad",&quad,
"quad/S");
110 tFgt->Branch(
"strip",&strip,
"strip/S");
111 tFgt->Branch(
"stat",&stat,
"stat/S");
112 tFgt->Branch(
"ordinate",&ordinate,
"ordinate/D");
113 tFgt->Branch(
"lowerSpan",&lowerSpan,
"lowerSpan/D");
114 tFgt->Branch(
"upperSpan",&upperSpan,
"upperSpan/D");
115 tFgt->Branch(
"layer",&layer,
"layer/B");
116 tFgt->Branch(
"adc",adc,
"adc[7]/I");
117 tFgt->Branch(
"ped",&ped,
"ped/D");
118 tFgt->Branch(
"pedSig",&pedSig,
"pedSig/D");
119 tFgt->Branch(
"adcmax",&adcmax,
"adcmax/I");
120 tFgt->Branch(
"mmin",&mmin,
"mmin/I");
121 tFgt->Branch(
"mmax",&mmax,
"mmax/I");
122 tFgt->Branch(
"chi2",&chi2,
"chi2/F");
123 tFgt->Branch(
"fmax",&fmax,
"fmax/F");
124 tFgt->Branch(
"norm",&norm,
"norm/F");
125 tFgt->Branch(
"tau",&tau,
"tau/F");
126 tFgt->Branch(
"t0",&t0,
"t0/F");
127 tFgt->Branch(
"beta",&beta,
"beta/F");
128 tFgt->Branch(
"offset",&offset,
"offset/F");
129 tFgt->Branch(
"errCode",&errCode,
"errCode/I");
137 if(iEvt%10==0)cout <<
"iEvt = " << iEvt << endl;
140 LOG_FATAL <<
"Pointer to Fgt DB Maker is null" << endm;
145 fgtTables = mFgtDbMkr->getDbTables();
148 LOG_FATAL <<
"Pointer to Fgt DB Tables is null" << endm;
155 eventPtr = (
StEvent*)GetInputDS(
"StEvent");
158 LOG_ERROR <<
"Error getting pointer to StEvent from '" << ClassName() <<
"'" << endm;
162 mFgtCollectionPtr = 0;
165 mFgtCollectionPtr=eventPtr->fgtCollection();
168 if( !mFgtCollectionPtr) {
169 LOG_ERROR <<
"Error getting pointer to StFgtCollection from '" << ClassName() <<
"'" << endm;
173 if( pedSelect<0 || pedSelect>2 ) {
174 LOG_ERROR <<
"Error no pedestal type selected " << pedSelect << endm;
180 for( UInt_t discIdx=0; discIdx<mFgtCollectionPtr->getNumDiscs(); ++discIdx ){
182 if( stripCollectionPtr ){
183 StSPtrVecFgtStrip& stripVec = stripCollectionPtr->getStripVec();
184 StSPtrVecFgtStripIterator stripIter;
185 rdo=0;arm=-1;apv=-1;chn=-1;
187 for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
188 rdo=0;arm=apv=chn=stat=-1;
189 disk=quad=strip=-1.;layer=
' ';
190 ordinate=lowerSpan=upperSpan=-1.;
191 Int_t dof=Ntimebin-4;
193 (*stripIter)->getElecCoords( rdo, arm, apv, chn );
194 stat=fgtTables->getStatusFromElecCoord(rdo,arm,apv,chn);
197 int geoId=fgtTables->getGeoIdFromElecCoord(rdo, arm, apv, chn);
199 StFgtGeom::decodeGeoId(geoId,disk,quad,layer,strip);
200 StFgtGeom::getPhysicalCoordinate(geoId,disk,quad,layer,ordinate,lowerSpan,upperSpan);
205 ped=99999.;pedSig=0.;
208 ped=(*stripIter)->getAdc(0);
212 for(Int_t is=0;is<Ntimebin;is++){
213 if(ped>(*stripIter)->getAdc(is)){ped=(*stripIter)->getAdc(is);};
219 ped=fgtTables->getPedestalFromElecCoord(rdo,arm,apv,chn);
220 pedSig=fgtTables->getPedestalSigmaFromElecCoord(rdo,arm,apv,chn);
222 default:cout <<
"O_o This should never print" << endl;
225 for(Int_t is=0;is<7;is++){adc[is]=0.;};
226 for(Int_t is=0;is<Ntimebin;is++){
227 adc[is]=(*stripIter)->getAdc(is);
233 if(rdo==1 && arm==0 && apv>-1 && apv<10){}
234 else if(rdo==2 && arm==0 && apv>-1 && apv<10){}
238 chi2=-1.;tau=0.;t0=0.;beta=0.;offset=0.;errCode=0;
240 for(Int_t is=0;is<Ntimebin;is++){
241 hh->SetBinContent(is+1,adc[is]);
242 hh->SetBinError(is+1,pedSig);
244 sprintf(hname,
"rdo%d_arm%d_apv%d_chn%d_%d",rdo,arm,apv,chn,iEvt);
246 mmax=hh->GetMaximumBin()-1;
247 mmin=hh->GetMinimumBin()-1;
248 adcmax=hh->GetBinContent(mmax+1);
250 for(Int_t is=0;is<Ntimebin;is++){
251 printf(
"%d ",(*stripIter)->getAdc(is));
253 printf(
"ped=%f \n",ped);
255 if(adcmax>fitThresh){
256 if(abs(mmax-mmin)==2 && mmin>0 && mmax>0 && mmin<Ntimebin-1 && mmax<Ntimebin-1){
257 Float_t middle1=(hh->GetBinContent(mmin)+hh->GetBinContent(mmin+2))/2.;
258 Float_t middle2=(hh->GetBinContent(mmax)+hh->GetBinContent(mmax+2))/2.;
259 if((middle1-hh->GetBinContent(mmin+1))/hh->GetBinError(mmin+1)>3. && (hh->GetBinContent(mmax+1)-middle2)/hh->GetBinError(mmax+1)>3.){errCode=1;}
262 for(Int_t is=0;is<Ntimebin;is++){
263 if(adc[is]>adcmax*0.95 && adcmax>20.*pedSig)highcnt++;
265 if(highcnt>2){errCode=2;}
270 Int_t binAPV = disk*40 + quad*10 + (apv%12);
271 Float_t tau0=htau->GetBinContent(binAPV+1);
272 if(tau0>0){InitFX(tau0);}
277 hh->Fit(FX,
"Q",
"",0.,Ntimebin);
278 chi2=FX->GetChisquare()/(Float_t)dof;
279 fmax=FX->GetMaximumX();
280 norm=FX->GetParameter(0);
281 tau=FX->GetParameter(1);
282 beta=FX->GetParameter(2);
283 offset=FX->GetParameter(3);
284 t0=FX->GetParameter(4);
285 if(chi2<1. && igoodCnt<120 && adcmax>plotThresh){
286 hGood[igoodCnt]=
new TH1F(*hh);
287 fGood[igoodCnt]=
new TF1(*FX);
288 sprintf(hname,
"fgood%d",igoodCnt);
289 fGood[igoodCnt]->SetTitle(hname);
292 if(chi2>20. && ibadCnt<120 && adcmax>plotThresh){
293 hBad[ibadCnt]=
new TH1F(*hh);
294 fBad[ibadCnt]=
new TF1(*FX);
295 sprintf(hname,
"fbad%d",ibadCnt);
296 fBad[ibadCnt]->SetTitle(hname);
313 TCanvas* tcv1=
new TCanvas(
"tcv1",
"tcv1",850,1100);
315 TCanvas* tcv2=
new TCanvas(
"tcv2",
"tcv2",850,1100);
318 tcv1->Print(
"fits_good.pdf(",
"pdf");
319 tcv2->Print(
"fits_bad.pdf(",
"pdf");
321 for(Int_t i=0;i<igoodCnt;i++){
322 tcv1->GetPad(i%40+1)->SetGridx(0);
323 tcv1->GetPad(i%40+1)->SetGridy(0);
326 fGood[i]->Draw(
"same");
328 tcv1->Print(
"fits_good.pdf",
"pdf");
333 for(Int_t i=0;i<ibadCnt;i++){
334 tcv2->GetPad(i%40+1)->SetGridx(0);
335 tcv2->GetPad(i%40+1)->SetGridy(0);
338 fBad[i]->Draw(
"same");
340 tcv2->Print(
"fits_bad.pdf",
"pdf");
346 tcv1->Print(
"fits_good.pdf)",
"pdf");
347 tcv2->Print(
"fits_bad.pdf)",
"pdf");
353 cout <<
"StFgtTimeShapeMaker::Finish()" << endl;
365 MyFunc(TF1 * f): fFunc(f) {}
366 double Evaluate (
double *x,
double * par)
const {
367 fFunc->SetParameter(0,par[0]);
368 fFunc->SetParameter(1,par[1]);
369 fFunc->SetParameter(2,par[2]);
370 fFunc->SetParameter(3,par[3]);
372 if(x[0]-par[4]<0.){val=par[3];}
373 else{val=fFunc->Eval(x[0]-par[4]);};
380 void StFgtTimeShapeMaker::FitFunc()
382 fs =
new TF1(
"fs",
"[0]*x**[2]*exp(-x/[1])+[3]",-100,100);
384 FX =
new TF1(
"FX",mf,&MyFunc::Evaluate,-10.,10.,5);
390 void StFgtTimeShapeMaker::InitFX()
392 FX->SetParameter(0,200.);
393 FX->SetParLimits(0,0.,100000.);
394 FX->SetParameter(1,1.);
395 FX->SetParLimits(1,0.1,10.);
396 FX->FixParameter(2,2.);
400 FX->SetParameter(4,0.);
401 FX->SetParLimits(4,-10.,17.);
404 void StFgtTimeShapeMaker::InitFX(Float_t ftau)
406 FX->SetParameter(0,200.);
407 FX->SetParLimits(0,0.,100000.);
408 FX->SetParameter(1,ftau);
409 FX->SetParLimits(1,ftau,ftau);
410 FX->FixParameter(2,2.);
412 FX->SetParameter(4,0.);
413 FX->SetParLimits(4,-10.,17.);
virtual const char * GetName() const
special overload