void FitSignals(TTree * treeB, TCut cut, Int_t max){ AliSignalProcesor proc; TF1 * f1 = proc.GetAsymGauss(); TTreeSRedirector cstream("FitSignal.root"); TFile *f = cstream.GetFile(); char lname[100]; sprintf(lname,"Fit%s", cut.GetTitle()); TEventList *list = new TEventList(lname,lname); sprintf(lname,">>Fit%s", cut.GetTitle()); treeB->Draw(lname,cut); treeB->SetEventList(list); Int_t nFits=0; for (Int_t ievent=0; ievent<list->GetN(); ievent++){ if (nFits>max) break; if (nFits%50==0) printf("%d\n",nFits); char ename[100]; sprintf(ename,"Fit%d", ievent); Double_t nsample = treeB->Draw("Graph.fY-Mean09:Graph.fX","","",1,ievent); Double_t * signal = treeB->GetV1(); Double_t * time = treeB->GetV2(); Double_t maxpos =0; Double_t max = 0; for (Int_t ipos = 0; ipos<nsample; ipos++){ if (signal[ipos]>max){ max = signal[ipos]; maxpos = ipos; } } Int_t first = TMath::Max(maxpos-10,0.); Int_t last = TMath::Min(maxpos+60, nsample); // f->cd(); TH1F his(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his.SetBinContent(ipos+1,signal[ipos+first]); } treeB->Draw("Sector:Row:Pad","","",1,ievent); Double_t sector = treeB->GetV1()[0]; Double_t row = treeB->GetV2()[0]; Double_t pad = treeB->GetV3()[0]; // TGraph graph(last-first,&time[first],&signal[first]); f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); // TH1F * his = (TH1F*)graph.GetHistogram(); his.Fit(f1,"q"); his.Write(ename); gPad->Clear(); his.Draw(); gPad->Update(); Double_t params[6]; for (Int_t ipar=0; ipar<6; ipar++) params[ipar] = f1->GetParameters()[ipar]; Double_t chi2 = TFitter::GetFitter()->Chisquare(6,params); TMatrixD cov(6,6); cov.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); // // tail cancellation // Double_t x0[1000]; Double_t x1[1000]; Double_t x2[1000]; for (Int_t ipos=0; ipos<last-first; ipos++){ x0[ipos] = signal[ipos+first]; } proc.TailCancelationALTRO1(x0,x1,0.85*0.339,0.09,last-first); proc.TailCancelationALTRO1(x1,x2,0.85,0.789,last-first); // sprintf(ename,"Cancel1_%d", ievent); TH1F his1(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his1.SetBinContent(ipos+1,x1[ipos]); } his1.Write(ename); sprintf(ename,"Cancel2_%d", ievent); TH1F his2(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his2.SetBinContent(ipos+1,x1[ipos]); } f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); his2.Fit(f1,"q"); his2.Write(ename); Double_t params2[6]; for (Int_t ipar=0; ipar<6; ipar++) params2[ipar] = f1->GetParameters()[ipar]; Double_t chi22 = TFitter::GetFitter()->Chisquare(6,params2); TMatrixD cov2(6,6); cov2.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); TGraph gr0(last-first, &time[first],x0); TGraph gr1(last-first, &time[first],x1); TGraph gr2(last-first, &time[first],x2); // cstream<<"Fit"<< "Sector="<<sector<< "Row="<<row<< "Pad="<<pad<< "First="<<first<< "Max="<<max<< "MaxPos="<<maxpos<< "chi2="<<chi2<< "chi22="<<chi22<< "Cov="<<&cov<< "Cov2="<<&cov2<< "gr0.="<<&gr0<< "gr1.="<<&gr1<< "gr2.="<<&gr2<< "p0="<<params[0]<< "p1="<<params[1]<< "p2="<<params[2]<< "p3="<<params[3]<< "p4="<<params[4]<< "p5="<<params[5]<< "p02="<<params2[0]<< "p12="<<params2[1]<< "p22="<<params2[2]<< "p32="<<params2[3]<< "p42="<<params2[4]<< "p52="<<params2[5]<< "\n"; // delete his; nFits++; } }
/* * Creates the nE by nV (num edges by num vertices/tasks) fusion penalty * matrix * * pairs is an nE * 2 matrix of which tasks are in which pair */ int gennetwork(double *y, int n, int K, double corthresh, int cortype, double *C, int *pairs, int *edges) { int i, j, k, e, nE = K * (K - 1) / 2; double *S = NULL, *R = NULL, *W = NULL; int *eFrom = NULL, *eTo = NULL; CALLOCTEST(S, K * K, sizeof(double)); CALLOCTEST(R, K * K, sizeof(double)); CALLOCTEST(W, K * K, sizeof(double)); CALLOCTEST(eFrom, nE, sizeof(int)); CALLOCTEST(eTo, nE, sizeof(int)); cov2(y, S, n, K); cov2cor(S, R, K); #ifdef DEBUG if(!writematrixf(S, K, K, "S.txt")) return FAILURE; if(!writematrixf(R, K, K, "R.txt")) return FAILURE; #endif for(i = 0 ; i < K ; i++) { for(j = 0 ; j < K ; j++) { k = i * K + j; R[k] = fabs(R[k]) < corthresh ? 0 : R[k]; if(cortype == CORTYPE_IND) W[k] = fabs(R[k]) > corthresh; else if(cortype == CORTYPE_ABS) W[k] = fabs(R[k]); else if(cortype == CORTYPE_SQR) W[k] = R[k] * R[k]; } } e = 0; for(j = 0 ; j < K ; j++) { for(i = 0 ; i < K ; i++) { if(i < j && R[i * K + j] != 0) { eFrom[e] = i; eTo[e] = j; pairs[e] = i; pairs[e + nE] = j; e++; } } } for(e = 0 ; e < nE ; e++) { i = eFrom[e]; j = eTo[e]; C[e + nE * i] = W[i * K + j]; C[e + nE * j] = -W[i * K + j] * sign(R[i * K + j]); } /* make the (K-1) by K edges matrix */ for(j = 0 ; j < K ; j++) { e = 0; for(i = 0 ; i < nE ; i++) { if(C[i + nE * j] != 0) { edges[e + (K - 1) * j] = i; e++; } } } FREENULL(S); FREENULL(R); FREENULL(W); FREENULL(eFrom); FREENULL(eTo); return SUCCESS; }