/////////////////////////////////////////////////////////////////// //////// Go4 GUI example script addhistos.C // J.Adamczewski, gsi, May 2006 // NOTE: to be run in Go4 GUI local command line only! // NEVER call this script in remote analysis process!!! /////// Functionality: // divide histogram of name 1 by histogram of name2 /////// Usage: // The draw flag switches if the results are displayed each time this makro is called // if display is switched off, the result histogram is just updated in browser and existing displays /////// Bool_t divhistos(const char* name1, const char* name2, Bool_t draw) { if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) { std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl; return kFALSE; } TString fullname1 = go4->FindItem(name1); TObject* ob1 = go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms TH1 *his1(0), *his2(0); if(ob1 && ob1->InheritsFrom("TH1")) his1 = (TH1*)ob1; if(his1==0) { std::cout <<"divhistos could not get histogram "<<fullname1 << std::endl; return kFALSE; } TString fullname2 = go4->FindItem(name2); TObject* ob2 = go4->GetObject(fullname2,1000); // 1000=timeout to get object from analysis in ms if(ob2 && ob2->InheritsFrom("TH1")) his2 = (TH1*)ob2; if(his2==0) { std::cout <<"divhistos could not get histogram "<<fullname2 << std::endl; return kFALSE; } TH1* result= (TH1*) his1->Clone(); TString n1 = his1->GetName(); TString n2 = his2->GetName(); TString t1 = his1->GetTitle(); TString t2 = his2->GetTitle(); TString soper; soper.Form(") : ("); TString finalname = TString("(")+n1+soper+n2+")"; TString finaltitle = TString("(")+t1+soper+t2+")"; result->SetName(finalname); result->SetTitle(finalname); result->Sumw2(); result->Divide(his2); result->SetDirectory(0); TString rname = go4->SaveToMemory("Divs", result, kTRUE); std::cout<< "Saved result histogram to " << rname.Data() <<std::endl; if(draw) go4->DrawItem(rname); return kTRUE; }
/////////////////////////////////////////////////////////////////// //////// Go4 GUI example script addhistos.C // J.Adamczewski, gsi, May 2006 // JAM May 2015: added support for 2d histograms // NOTE: to be run in Go4 GUI local command line only! // NEVER call this script in remote analysis process!!! /////// Functionality: // adds histogram of name2 to histogram of name1 /////// Usage: // histogram name2 will be scaled by factor. // (e.g. if factor==-1, his2 is substracted from his1) // The draw flag switches if the results are displayed each time this makro is called // if display is switched off, the result histogram is just updated in browser and existing displays /////// Bool_t addhistos(const char* name1, const char* name2, Double_t factor, Bool_t draw) { if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) { std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl; return kFALSE; } TString fullname1 = go4->FindItem(name1); TObject* ob1=go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms TH1 *his1(0), *his2(0); if(ob1 && ob1->InheritsFrom("TH1")) his1 = (TH1*) ob1; if(his1==0) { std::cout <<"addhistos could not get histogram "<<fullname1 << std::endl; return kFALSE; } TString fullname2 = go4->FindItem(name2); TObject* ob2=go4->GetObject(fullname2,1000); // 1000=timeout to get object from analysis in ms if(ob2 && ob2->InheritsFrom("TH1")) his2 = (TH1*)ob2; if(his2==0) { std::cout <<"addhistos could not get histogram "<<fullname2 << std::endl; return kFALSE; } if((his1->GetDimension()) != (his2->GetDimension())) { std::cout <<"addhistos could not add histograms of different dimensions "<< std::endl; return kFALSE; } TH1* result = (TH1*) his1->Clone(); TString n1 = his1->GetName(); TString n2 = his2->GetName(); TString t1 = his1->GetTitle(); TString t2 = his2->GetTitle(); TString soper; if(factor>0) soper.Form(") + %4.1E * (",factor); else soper.Form(") - %4.1E * (",-1*factor); TString finalname = TString("(")+n1+soper+n2+")"; TString finaltitle = TString("(")+t1+soper+t2+")"; result->SetName(finalname); result->SetTitle(finaltitle); result->Sumw2(); result->Add(his2,factor); result->SetDirectory(0); TString rname = go4->SaveToMemory("Sums", result, kTRUE); std::cout<< "Saved result histogram to " << rname.Data() <<std::endl; if(draw) { ViewPanelHandle vpanel = go4->StartViewPanel(); if(result->GetDimension()>1) { // superimpose mode is not supported for 2d histograms go4->DrawItem(rname, vpanel); } else { go4->SetSuperimpose(vpanel,kTRUE); go4->DrawItem(fullname1, vpanel); go4->DrawItem(fullname2, vpanel); go4->DrawItem(rname, vpanel); } } return kTRUE; }
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++; } }