int RampCorrellation_single(std::string file_name, TGraphErrors &graph, TGraphErrors &graph2, vector<double> &vec_errors) { TTree *t = new TTree(); const std::string file_path = "/home/jlab/github/MagCloak_Analysis/calibration/data-calib/DATA_MegaVIEW/"; // std::string file_name = "DataFile_2016-12-08_06-59-11.csv"; std::string file = file_path+file_name; t->ReadFile(file.c_str()); // t->Print(); TCanvas *c = new TCanvas(); t->Draw("TMath::Abs(B1/B2):time"); TGraph *gh = (TGraph*)c->GetListOfPrimitives()->FindObject("Graph"); double ratio_mean = gh->GetMean(2); double ratio_std = gh->GetRMS(2); t->Draw("Bnom:time"); TGraph *gh1 = (TGraph*)c->GetListOfPrimitives()->FindObject("Graph"); double nom_mean = gh1->GetMean(2); double nom_std = 0; // cout << "At " << nom_mean << " mT, B1/B2 is: " << ratio_mean << " +/- " << ratio_std << endl; c->Close(); int n = graph.GetN(); graph.SetPoint(n,nom_mean,ratio_mean); graph.SetPointError(n,nom_std,ratio_std); //------------------------------------------------------------------------------- TCanvas *c2 = new TCanvas(); t->Draw("B3:time"); TGraph *gh2 = (TGraph*)c2->GetListOfPrimitives()->FindObject("Graph"); double B3_mean = -1*(gh2->GetMean(2)); double B3_std = gh2->GetRMS(2); int n2 = graph2.GetN(); graph2.SetPoint(n2, nom_mean, B3_mean); graph2.SetPointError(n2, nom_std, B3_std); c2->Close(); if(nom_mean < 500) vec_errors.push_back(B3_std); return 0; }
TGraphErrors* ExtractCalCurve(vector<calData>& FitPositions, vector<Float_t>& Energies) //void ExtractCalCurve(vector<Float_t>& FitPositions, vector<Float_t>& Energies) { //TF1* calFit = new TF1("calFit","[0]*x + [1]",0,800E3); TGraphErrors* calCurve = new TGraphErrors(Energies.size()); //Get highest energy peak and estimate [0] std::vector<calData>::iterator pit; std::vector<Float_t>::iterator eit; pit = max_element(FitPositions.begin(),FitPositions.end(),CompareByadc); eit = max_element(Energies.begin(),Energies.end()); //Extrapolate coefficient and place first point int currPoint = 1; calCurve->SetPoint(currPoint,(*pit).fadc,*eit); calCurve->SetPointError(currPoint,(*pit).efadc,0.0); TFitResultPtr r = calCurve->Fit("pol1","SQ"); Float_t a = r->Parameter(1); Float_t CurrentPeak = 0.0; Float_t CurrentEnergy = 0.0; Float_t CurrentEnergyEst = 0.0; // Loop through found peaks and locate closest estimated energy // Assume fitted peaks are already ordered from lowest to highest for(std::vector<calData>::iterator i = --(FitPositions.end()); i!=FitPositions.begin(); --i) { currPoint++; CurrentPeak = (*i).fadc; CurrentEnergyEst = CurrentPeak*a; Float_t CurrentDelta = 800E3; for(std::vector<Float_t>::iterator j = Energies.begin(); j!=Energies.end(); j++) { if( abs(*j - CurrentEnergyEst) < CurrentDelta) { CurrentDelta = abs(*j - CurrentEnergyEst); CurrentEnergy = *j; } } calCurve->SetPoint(currPoint,CurrentPeak,CurrentEnergy); calCurve->SetPointError(currPoint,(*i).efadc,CurrentDelta); r = calCurve->Fit("pol1","SQ"); a = r->Parameter(1); } r->Print("V"); return calCurve; }
TGraphErrors* addGraph(TGraphErrors *g1, TGraphErrors *g2) { assert(g1->GetN()==g2->GetN()); TGraphErrors *g = (TGraphErrors*)g1->Clone();//new TGraphErrors(g1->GetN()); for (int i = 0; i != g1->GetN(); ++i) { double x1 = g1->GetX()[i]; double x2 = g2->GetX()[i]; assert(fabs(x1/x2-1)<0.1); double ex1 = g1->GetEX()[i]; double ex2 = g2->GetEX()[i]; double y1 = g1->GetY()[i]; double y2 = g2->GetY()[i]; double ey1 = g1->GetEY()[i]; double ey2 = g2->GetEY()[i]; double x = (ey2*ey2*x1 + ey1*ey1*x2) / (ey2*ey2+ey1*ey1); double y = (ey2*ey2*y1 + ey1*ey1*y2) / (ey2*ey2+ey1*ey1); double ex = (ey2*ey2*ex1 + ey1*ey1*ex2) / (ey2*ey2+ey1*ey1); double ey = (ey2*ey2*ey1 + ey1*ey1*ey2) / (ey2*ey2+ey1*ey1); g->SetPoint(i, x, y); g->SetPointError(i, ex, ey); } return g; }
void add_point( double coefover, double sigma, double dsigma ){//============================================================ TGraphErrors *fisig; if ( gROOT->GetListOfSpecials()->FindObject("fisig")!=NULL ){ fisig=(TGraphErrors*) gROOT->GetListOfSpecials()->FindObject("fisig"); printf("fisig exists\n%s",""); }else{ printf("\n\n NO fisig exists NONONO \n\n\n%s",""); fisig=new TGraphErrors(); fisig->SetTitle("fisig"); fisig->SetName("fisig"); gROOT->GetListOfSpecials()->Add( fisig );// TRICK TO KEEP IT gDirectory->Add( fisig ); fisig->SetMarkerStyle(7); } int n=fisig->GetN(); fisig->SetPoint(n,coefover,sigma); fisig->SetPointError(n,0.0,dsigma); // fisig->Print(); // too many data char text[100]; sprintf(text,"%.3f ... %d",coefover, fisig->GetN() ); // TText *t=new TText(from,0,text ); // t->SetTextSize(0.08);t->Draw(); }//============================================================
//______________________________________________________________________________ TGraphErrors *GraphRatio(TGraphErrors *g1,TGraphErrors *g2) { Int_t n = g1->GetN(); if (n != g2->GetN()) { Printf("!!!!!!!!!!!!!!!!"); return 0; } TGraphErrors *g = new TGraphErrors(n); g->SetMarkerStyle(20); g->GetXaxis()->SetTitle("p_{t}, GeV/c"); g->SetTitle(Form("#frac{%s}{%s}", g1->GetTitle(), g2->GetTitle())); Double_t x, y1, y2; Double_t c0, c1, c12, e0, e1; Double_t *ex = g1->GetEX(); Double_t *ey = g1->GetEY(); for (Int_t i = 0; i < n; i++) { g1->GetPoint(i, x, y1); g2->GetPoint(i, x, y2); if (TMath::Abs(y2) < 1.E-12) y2 = 1.0; c0 = y1; c1 = y2; c12 = c1*c1; e0 = g1->GetErrorY(i); e1 = g2->GetErrorY(i); g->SetPoint(i, x, y1/y2); g->SetPointError(i, ex[i], (e0*e0*c1*c1 + e1*e1*c0*c0)/(c12*c12)); } return g; }
TGraphErrors* getMoliereGraph( std::vector<DataFile> dataFiles ) { TGraphErrors* graph = new TGraphErrors(0); for( unsigned i=0; i<dataFiles.size(); ++i ) { if( dataFiles[i].file==0 ) continue; Double_t x = (i==0) ? -1 : dataFiles[i].absThickness; Double_t y = ((TH1D*)(dataFiles[i].file->Get("Rmoliere")))->GetMean(); Double_t yerr = ((TH1D*)(dataFiles[i].file->Get("Rmoliere")))->GetMeanError(); graph->SetPoint(i, x, y); graph->SetPointError(i, 0, yerr); if( i==0 ) std::cout << "LYSO Moliere radius: " << y << std::endl; } graph->SetName( "mol" ); graph->SetTitle( "Moliere Radius [mm]" ); return graph; }
TGraphErrors bestFit(TTree *tree, TString alphaName, TString constTermName){ Double_t alpha, constTerm; alphaName.ReplaceAll("-","_"); constTermName.ReplaceAll("-","_"); tree->SetBranchAddress(alphaName,&alpha); tree->SetBranchAddress(constTermName,&constTerm); //Long64_t nEntries=genTree->GetEntries(); TGraphErrors graph; Int_t iPoint=0; tree->GetEntry(0); graph.SetPoint(0, constTerm, alpha); graph.SetPointError(0,0, 0); iPoint++; graph.Set(iPoint); tree->ResetBranchAddresses(); graph.Draw("A P"); // graph.SetFillColor(kBlue); // graph.SetLineColor(kYellow); // graph.GetXaxis()->SetTitle("Energy [GeV]"); // graph.GetYaxis()->SetTitle("Additional smearing [%]"); return graph; }
TGraphErrors g(TTree *tree, TString alphaName, TString constTermName){ Double_t alpha, constTerm; alphaName.ReplaceAll("-","_"); constTermName.ReplaceAll("-","_"); tree->SetBranchAddress(alphaName,&alpha); tree->SetBranchAddress(constTermName,&constTerm); //Long64_t nEntries=genTree->GetEntries(); TGraphErrors graph; Int_t iPoint=0; tree->GetEntry(0); std::cout << alpha << "\t" << constTerm << std::endl; Double_t alpha2=alpha*alpha; Double_t const2=constTerm*constTerm; for(Double_t energy=20; energy<150; energy+=10){ Double_t addSmearing = (sqrt(alpha2/energy+const2)); graph.SetPoint(iPoint, energy, addSmearing); graph.SetPointError(iPoint,0, 0); iPoint++; } graph.Set(iPoint); tree->ResetBranchAddresses(); graph.Draw("A L"); graph.SetFillColor(kBlue); graph.SetLineColor(kYellow); graph.GetXaxis()->SetTitle("Energy [GeV]"); graph.GetYaxis()->SetTitle("Additional smearing [%]"); return graph; }
void draw() { gStyle->SetOptStat(0000); TGraphErrors* gr = new TGraphErrors("papel_um.txt", "%lg %lg %lg %lg"); gr->Draw("A"); gr->GetXaxis()->SetTitle("Diametro (mm)"); gr->GetYaxis()->SetTitle("Massa (u.m.)"); gr->SetTitle("Dimensao Fractal - Papel"); gr->SetMarkerStyle(20); gr->SetMarkerSize(gr->GetMarkerSize()/2.); TCanvas* c1 = new TCanvas(); gr->Draw("AP"); c1->Print("gr1.png"); TGraphErrors* grlog = new TGraphErrors(); for (int i=0; i<gr->GetN(); i++) { grlog->SetPoint(i, TMath::Log(gr->GetX()[i]), TMath::Log(gr->GetY()[i])); grlog->SetPointError(i, gr->GetEX()[i]/gr->GetX()[i], 0.0); } grlog->Draw("A"); grlog->GetXaxis()->SetTitle("Logaritmo do diametro (diametro em mm)"); grlog->GetYaxis()->SetTitle("Logaritmo da massa (massa em unidade arbitraria)"); grlog->SetTitle("Dimensao Fractal - Papel"); grlog->SetMarkerStyle(20); // grlog->SetMarkerSize(gr->GetMarkerSize()/2.); grlog->Fit("pol1"); TCanvas* c2 = new TCanvas(); grlog->Draw("AP"); c2->Print("gr2.png"); }
void ExpManager::GetExp1DGraphX(TString NameTitle, double zmin, double zmax, double ymin, double ymax, TString grid){ // do the same thing as for the polar interpolation TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetTitle("Experimental Data;X (mm);Magnetic Field (mT)"); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(2); int graph_counter = 0 ; for (unsigned i=0; i< fExpY.size(); i++) { //cout << " X " << fExpX.at(i) ; if( (fExpY.at(i) >= ymin && fExpY.at(i) <= ymax) && (fExpZ.at(i) >= zmin && fExpZ.at(i) <= zmax) && fGrid.at(i)== grid ){ cout << " < ----- " ; fGraph->SetPoint(graph_counter,fExpX.at(i),fExpB.at(i)); // CHECK, add new the stuff for emag fGraph->SetPointError(graph_counter,fExpXErr.at(i),fExpBErr.at(i)); // CHECK, add new the stuff for emag graph_counter++; } cout << endl ; } fGraph->SetTitle(NameTitle+Form(" Experimental Data : %.2f < Depth < %.2f mm __ %.2f < Y < %.2f mm;X (mm);Magnetic Field (mT)",zmin,zmax,ymin,ymax)); fGraph->SetName(NameTitle+Form("_Exp_Depth_%.2f_%.2fmm_Y_%.2f_%.2fmm",zmin,zmax,ymin,ymax)); fGraph->Write(); }
TGraphErrors g(TTree *genTree, TString constTermName=""){ Double_t alpha, constTerm; genTree->SetBranchAddress("alpha",&alpha); genTree->SetBranchAddress("constTerm",&constTerm); Long64_t nEntries=genTree->GetEntries(); TH1F h("smearingHist","",10000,0,0.1); TGraphErrors graph; Int_t iPoint=0; for(Double_t energy=20; energy<150; energy+=10){ h.Reset(); for(Long64_t jentry=0; jentry<nEntries; jentry++){ genTree->GetEntry(jentry); h.Fill(sqrt(alpha*alpha/energy+constTerm*constTerm)); } graph.SetPoint(iPoint, energy, h.GetMean()); graph.SetPointError(iPoint,0, h.GetRMS()); iPoint++; } h.SetTitle(constTermName); h.SaveAs("tmp/h-"+constTermName+".root"); graph.Set(iPoint); genTree->ResetBranchAddresses(); graph.Draw("A L3"); graph.SetFillColor(kBlue); graph.SetLineColor(kYellow); graph.GetXaxis()->SetTitle("Energy [GeV]"); graph.GetYaxis()->SetTitle("Additional smearing [%]"); return graph; }
void ExpManager::GetSim1DGraphZ(TString NameTitle, double xmin, double xmax, double ymin, double ymax, TString grid ){ // do the same thing as for the polar interpolation TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetTitle("Simulated Data;Z (mm);Magnetic Field (mT)"); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(2); int graph_counter = 0 ; for (unsigned i=0; i< fExpY.size(); i++) { //cout << " X " << fExpX.at(i) ; if( (fExpX.at(i) >= xmin && fExpX.at(i) <= xmax) && (fExpY.at(i) >= ymin && fExpY.at(i) <= ymax) && fGrid.at(i)==grid ){ fGraph->SetPoint(graph_counter,fExpZ.at(i),fSimB.at(i)); fGraph->SetPointError(graph_counter,fExpZErr.at(i),0); graph_counter++; } } fGraph->SetTitle(NameTitle+Form(" Simulated Data : %.2f < X < %.2f mm __ %.2f < Y < %.2f mm;Z (mm);Magnetic Field (mT)",xmin,xmax,ymin,ymax)); fGraph->SetName(NameTitle+Form("_Sim_X_%.2f_%.2fmm_Y_%.2f_%.2fmm",xmin,xmax,ymin,ymax)); fGraph->Write(); }
TGraphErrors *DataPoint(TH1 *hD, TH1 *hp, int t, double y) { double ymin = hp->GetMinimum(); double ymax = hp->GetMaximum(); double yDrawData = y>0? y : ymin + 0.2*(ymax-ymin); TGraphErrors *dataPoint = new TGraphErrors(); dataPoint->SetPoint(0, hD->GetBinContent(t+1), yDrawData); dataPoint->SetPointError(0, hD->GetBinError(t+1), 0.0); SetGraphProps(dataPoint, kBlack, kNone, kBlack, kFullCircle, 1.0); return dataPoint; }
int main(int narg,char **arg) { int i; double x,y; ifstream file; TApplication myapp("App",NULL,NULL); TCanvas tela; TGraphErrors graf; TF1 fun("fun","[0]*exp(-x*x/(2*[1]*[1]))"); if(narg<2) { cerr<<"usa: "<<arg[0]<<" file"<<endl; exit(0); } file.open(arg[1]); if(file.good()==0) { cout<<"File: "<<arg[1]<<" inesistente!"<<endl; exit(0); } i=0; double dum,N=1; while(file>>x>>dum>>y) { if(i==0) N=y; graf.SetPoint(i,x,y); graf.SetPointError(i,0,0.0001); i++; } fun.SetParameter(0,N); fun.SetParameter(1,1); fun.SetParName(0,"N"); fun.SetParName(1,"S"); graf.Draw("AP"); graf.Fit("fun"); //graf.GetXaxis()->SetLimits(0,x); tela.Modified(); tela.Update(); myapp.Run(true); return 0; }
TGraphErrors *MD68Point(TH1 *hp, double y) { double ymin = hp->GetMinimum(); double ymax = hp->GetMaximum(); double yDraw = y>0? y : ymin + 0.25*(ymax-ymin); TGraphErrors *g = new TGraphErrors(); MaxDensityInterval mdi = GetMDI(hp, 0.68); g->SetPoint(0, mdi.u, yDraw); g->SetPointError(0, mdi.du, 0); SetGraphProps(g, kAzure, kAzure, kAzure, kOpenSquare, 1.5); return g; }
/// /// Make an evolution graph for one parameter. /// TGraphErrors* ParameterEvolutionPlotter::makeEvolutionGraphErrors(vector<RooSlimFitResult*> results, TString parName) { TGraphErrors *g = new TGraphErrors(results.size()); int iGraph = 0; for ( int i=0; i<results.size(); i++ ){ if ( results[i] ){ g->SetPoint(iGraph, results[i]->getParVal(scanVar1), results[i]->getParVal(parName)); g->SetPointError(iGraph, 0, results[i]->getParErr(parName)); iGraph++; } } return g; }
void OneBin(Int_t bin, TH1* h0900, TH1* h2760, TH1* h7000, TH1* h8000, TMultiGraph* mg, TNtuple* tuple, Double_t sysErr=0.076) { Info("OneBin", "Getting one bin %d,%p,%p,%p,%p,%p", bin, h0900,h2760,h7000,h8000,tuple); Double_t eta = h0900->GetXaxis()->GetBinCenter(bin); Double_t w = h0900->GetXaxis()->GetBinWidth(bin); Info("", "Eta=%f +/- %f", eta, w); Double_t e[] = { 900., 2760., 7000., 8000., 0 }; TH1* h[] = { h0900, h2760, h7000, h8000, 0 }; Float_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; x[0] = eta; x[1] = w; TGraphErrors* g = new TGraphErrors(0); g->SetName(Form("eta%03d", bin)); g->SetTitle(Form("%f", eta)); g->SetMarkerStyle(bin % 10 + 20); g->SetMarkerColor(bin % 6 + 2); Double_t* pe = e; TH1** ph = h; Int_t i = 0; Int_t j = 1; while (*pe && *ph) { Double_t c = (*ph)->GetBinContent(bin); Double_t v = sysErr*c; if (c > 1e-6){ g->SetPoint(i, *pe, c); g->SetPointError(i, w, v); x[Int_t(2*j+0)] = c; x[Int_t(2*j+1)] = v; i++; } j++; pe++; ph++; } if (tuple) tuple->Fill(x); if (i > 0) mg->Add(g); else delete g; }
/// /// Plot the discrepancy between the observable and the predicted /// observable when making predictions about observables by scanning /// them. This checks if the chi2 term of the observable is tight enough. /// This only works for 1D scans for now. /// void ParameterEvolutionPlotter::plotObsScanCheck() { vector<RooSlimFitResult*> results = curveResults; cout << "ParameterEvolutionPlotter::plotObsScanCheck() : plotting ..." << endl; TCanvas *c2 = newNoWarnTCanvas("plotObsScanCheck"+getUniqueRootName(), title, 800,600); c2->SetLeftMargin(0.2); // get observable TGraphErrors *g = new TGraphErrors(results.size()); int iGraph = 0; for ( int i=0; i<results.size(); i++ ){ assert(results[i]); // get value of observable float obsValue = results[i]->getParVal(scanVar1); float obsError = w->var(scanVar1)->getError(); // get value of theory prediction setParameters(w,parsName,results[i]); TString thName = scanVar1; thName.ReplaceAll("_obs","_th"); if ( !w->function(thName) ){ cout << "ParameterEvolutionPlotter::plotObsScanCheck() : ERROR : theory value not found: " << thName << endl; continue; } float thValue = w->function(thName)->getVal(); g->SetPoint(iGraph, iGraph, obsValue-thValue); g->SetPointError(iGraph, 0., obsError); iGraph++; } g->SetTitle(scanVar1); g->GetXaxis()->SetTitle("scan step"); g->GetYaxis()->SetTitleSize(0.06); g->GetYaxis()->SetLabelSize(0.04); g->GetYaxis()->SetTitleOffset(1.5); g->GetYaxis()->SetTitle(scanVar1); Int_t ci = 927; TColor *col = new TColor(ci, 0, 0, 1, " ", 0.5); g->SetFillColor(ci); g->SetFillStyle(1001); g->Draw("a3"); g->Draw("lxsame"); c2->Update(); savePlot(c2, "parEvolutionObsSanCheck_"+name+"_"+scanVar1); }
void CreateAndFillUserTGraph(const char* nameAndTitle, Int_t npoint, Double_t xvalue, Double_t yvalue, Double_t xErr, Double_t yErr) { map<std::string , TGraphErrors*>::iterator nh_h = userTGraphs_.find(std::string(nameAndTitle)); TGraphErrors * h; if( nh_h == userTGraphs_.end() ) { h = new TGraphErrors(0); userTGraphs_[std::string(nameAndTitle)] = h; h->SetPoint(npoint, xvalue, yvalue); h->SetPointError(npoint, xErr, yErr); } else { nh_h->second->SetPoint(npoint, xvalue, yvalue); nh_h->second->SetPointError(npoint, xErr, yErr); } }
//____________________________________________________________ TGraphErrors* histo_to_tgraph( TH1* h, bool zero_sup ) { if( !h ) return 0; TGraphErrors *tg = new TGraphErrors( 0 ); int point( 0 ); for( int i=0; i<h->GetNbinsX(); i++ ) { double x = h->GetXaxis()->GetBinCenter( i+1 ); double y = double( h->GetBinContent( i+1 ) ); double error = double( h->GetBinError( i+1 ) ); if( zero_sup && !y ) continue; tg->SetPoint( point, x, y ); tg->SetPointError( point, 0, error ); point++; } return tg; }
TGraphErrors* getTheoXSec(TString file) { TTree t; t.ReadFile(file); TGraphErrors *g = new TGraphErrors(t.GetEntries()); float m,x,e; t.SetBranchAddress("mass",&m); t.SetBranchAddress("xsec",&x); t.SetBranchAddress("err",&e); int iEntry=-1; while(t.GetEntry(++iEntry)) { g->SetPoint(iEntry,m,x); g->SetPointError(iEntry,0,e); } return g; }
void ExpManager::DrawMap(TString NameTitle, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) { TMultiGraph *mg = new TMultiGraph(); //Draw a cross TGraphErrors *frame = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); frame->SetPoint(0,+0,+100); frame->SetPoint(1,+0,-100); frame->SetPoint(2,0,0); frame->SetPoint(3,-100,0); frame->SetPoint(4,+100,0); frame->SetPoint(5,+0,+0); frame->SetPoint(6,+0,-100); frame->SetMarkerColor(kWhite); frame->SetDrawOption("ap"); //Draw the map TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(1); //fGraph->SetDrawOption("ap"); int graph_counter = 0 ; for (unsigned i=0; i< fExpY.size(); i++) { if( (fExpX.at(i) >= xmin && fExpX.at(i) <= xmax) && (fExpY.at(i) >= ymin && fExpY.at(i) <= ymax) && (fExpZ.at(i) >= zmin && fExpZ.at(i) <= zmax) ) { fGraph->SetPoint(graph_counter,fExpX.at(i),fExpY.at(i)); fGraph->SetPointError(graph_counter,fExpXErr.at(i),fExpYErr.at(i)); graph_counter++; } } //fGraph->Write(); mg->SetTitle(NameTitle+Form(" Map : %.2f < X < %.2f mm %.2f < Y < %.2f mm %.2f < Z < %.2f mm;X (mm);Y (mm)",xmin,xmax,ymin,ymax,zmin,zmax)); mg->SetName(NameTitle+Form("_Map__X_%.2f_%.2fmm__Y_%.2f_%.2fmm__Z_%.2f_%.2fmm",xmin,xmax,ymin,ymax,zmin,zmax)); mg->Add(frame); mg->Add(fGraph); mg->Write(); }
TGraphErrors g(Double_t alpha, Double_t constTerm){ TGraphErrors graph; Int_t iPoint=0; // std::cout << alpha << "\t" << constTerm << std::endl; Double_t alpha2=alpha*alpha; Double_t const2=constTerm*constTerm; for(Double_t energy=20; energy<150; energy+=10){ Double_t addSmearing = (sqrt(alpha2/energy+const2)); graph.SetPoint(iPoint, energy, addSmearing); graph.SetPointError(iPoint,0, 0); iPoint++; } graph.Set(iPoint); graph.Draw("A L"); graph.SetFillColor(kBlue); graph.SetLineColor(kYellow); graph.GetXaxis()->SetTitle("Energy [GeV]"); graph.GetYaxis()->SetTitle("Additional smearing [%]"); return graph; }
void ExpManager::GetExp1DGraphPolar(TString NameTitle, double zmin, double zmax, double anglemin, double anglemax, TString grid) { TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetTitle("Experimental Data;Radius (mm);Magnetic Field (mT)"); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(2); int graph_counter = 0 ; for (unsigned i=0; i< fExpR.size(); i++) { if( (fExpTheta.at(i) >= anglemin && fExpTheta.at(i) <= anglemax) && (fExpZ.at(i) >= zmin && fExpZ.at(i) <= zmax) && fGrid.at(i)== grid ){ fGraph->SetPoint(graph_counter,fExpR.at(i),fExpB.at(i)); fGraph->SetPointError(graph_counter,fExpRErr.at(i),fExpBErr.at(i)); graph_counter++; } } fGraph->SetTitle(NameTitle+Form(" Experimental Data : %.2f < Depth < %.2f mm __ %.2f#circ < Angle < %.2f#circ;Radius (mm);Magnetic Field (mT)",zmin,zmax,anglemin,anglemax)); fGraph->SetName(NameTitle+Form("_Exp_Depth_%.2f_%.2fmm_Angle_%.2f_%.2fdeg",zmin,zmax,anglemin,anglemax)); fGraph->Write(); }
// Better to keep this in a seperate file TGraphErrors* CMS_7TEV(Double_t scale) { //7 TeV measurement at CMS TGraphErrors *gre = new TGraphErrors(33); gre->SetName("Graph"); gre->SetTitle("Graph"); gre->SetFillColor(1); gre->SetMarkerStyle(21); gre->SetPoint(0,0.15,9.94559); gre->SetPointError(0,0,0.4460492); gre->SetPoint(1,0.25,6.4274); gre->SetPointError(1,0,0.2867568); gre->SetPoint(2,0.35,3.69525); gre->SetPointError(2,0,0.1654095); gre->SetPoint(3,0.45,2.2442); gre->SetPointError(3,0,0.1009501); gre->SetPoint(4,0.55,1.40735); gre->SetPointError(4,0,0.06369867); gre->SetPoint(5,0.65,0.920301); gre->SetPointError(5,0,0.04193949); gre->SetPoint(6,0.75,0.616821); gre->SetPointError(6,0,0.0283265); gre->SetPoint(7,0.85,0.426732); gre->SetPointError(7,0,0.01975661); gre->SetPoint(8,0.95,0.299085); gre->SetPointError(8,0,0.01397616); gre->SetPoint(9,1.1,0.183225); gre->SetPointError(9,0,0.00845129); gre->SetPoint(10,1.3,0.0995915); gre->SetPointError(10,0,0.004670335); gre->SetPoint(11,1.5,0.056565); gre->SetPointError(11,0,0.002704398); gre->SetPoint(12,1.7,0.0337805); gre->SetPointError(12,0,0.001650384); gre->SetPoint(13,1.9,0.0208494); gre->SetPointError(13,0,0.001043639); gre->SetPoint(14,2.1,0.01323271); gre->SetPointError(14,0,0.0006804352); gre->SetPoint(15,2.3,0.00852133); gre->SetPointError(15,0,0.0004520424); gre->SetPoint(16,2.5,0.00555772); gre->SetPointError(16,0,0.0003051332); gre->SetPoint(17,2.7,0.00369416); gre->SetPointError(17,0,0.0002105437); gre->SetPoint(18,2.9,0.00275361); gre->SetPointError(18,0,0.0001617788); gre->SetPoint(19,3.1,0.001784498); gre->SetPointError(19,0,0.0001103706); gre->SetPoint(20,3.3,0.001251193); gre->SetPointError(20,0,8.105581e-05); gre->SetPoint(21,3.5,0.000932109); gre->SetPoint(22,3.7,0.00072809); gre->SetPointError(22,0,5.106009e-05); gre->SetPoint(23,3.9,0.000483879); gre->SetPointError(23,0,3.643427e-05); gre->SetPoint(24,4.1,0.000397255); gre->SetPointError(24,0,3.101453e-05); gre->SetPoint(25,4.3,0.000281682); gre->SetPointError(25,0,2.426278e-05); gre->SetPoint(26,4.5,0.0001898557); gre->SetPointError(26,0,1.777722e-05); gre->SetPoint(27,4.7,0.0001404168); gre->SetPointError(27,0,1.377145e-05); gre->SetPoint(28,4.9,0.0001152827); gre->SetPointError(28,0,1.228788e-05); gre->SetPoint(29,5.1,8.94332e-05); gre->SetPointError(29,0,1.021356e-05); gre->SetPoint(30,5.3,6.56232e-05); gre->SetPointError(30,0,8.759586e-06); gre->SetPoint(31,5.5,5.48406e-05); gre->SetPointError(31,0,8.112416e-06); gre->SetPoint(32,5.7,4.50414e-05); gre->SetPointError(32,0,7.518979e-06); /* gre->SetPoint(33,5.9,3.60633e-05); gre->SetPointError(33,0,5.641449e-06); gre->SetPoint(34,6.25,2.018451e-05); gre->SetPointError(34,0,3.081411e-06); gre->SetPoint(35,6.75,1.966985e-05); gre->SetPointError(35,0,2.63818e-06); gre->SetPoint(36,7.25,1.572381e-05); gre->SetPointError(36,0,2.668063e-06); gre->SetPoint(37,7.75,8.84664e-06); gre->SetPointError(37,0,2.136684e-06); gre->SetPoint(38,8.25,1.264757e-05); gre->SetPointError(38,0,3.756436e-06); gre->SetPoint(39,8.75,6.31772e-06); gre->SetPointError(39,0,2.762383e-06); gre->SetPoint(40,9.25,5.99949e-06); gre->SetPointError(40,0,3.246975e-06); gre->SetPoint(41,9.25,5.99949e-06); gre->SetPointError(41,0,3.239439e-06); /* /* Double_t x[33], y[33]; Double_t xerr[33], yerr[33]; for(Int_t i=0; i<33;i++){ gre->GetPoint(i,x[i],y[i]); gre->SetPoint(i,x[i],scale*y[i]); //gre->GetPointError(i,x[i],yerr[i]); xerr[i] = 0, yerr[i] = 0; gre->SetPointError(i,scale*xerr[i],scale*yerr[i]); } */ return gre; }
void ratiofit_vbf() { const Int_t nbins = 11; double Bins[12] = {130.,200.,300.,400.,500.,600.,700.,800.,900.,1000.,1250.,1500.}; TString OutDir = "vbf_plots_pol1Func"; //TString OutDir = "vbf_plots_OneoversqrtXFunc"; //TString OutDir = "vbf_plots_OneoverXFunc"; gSystem->mkdir(OutDir); TFile *fname; fname = new TFile("mWW_sf_reweighted/scaleFactors.root"); char tmpName[50]; char a0Name[50]; char a1Name[50]; char histName[50]; char mWWrange[50]; //Histograms TH1D* h1_powheg_phantom[5]; TString pol1Func("pol1"); //TString pol2Func("pol2"); //TString ExpFunc("ExpFunc"); //TString sqrtFunc("sqrtFunc"); //TString OneoverXFunc("OneoverXFunc"); //TString OneoversqrtXFunc("OneoversqrtXFunc"); TFitResultPtr fitres; TF1 *fit_func = new TF1("fit_func",pol1Func,130,1620); //TFitResultPtr fitres; TF1 *fit_func = new TF1("fit_func",pol2Func,0,1500); //TFitResultPtr fitres; TF1 *fit_func = new TF1("fit_func",ExpFunc,130,1500,3); //TFitResultPtr fitres; TF1 *fit_func = new TF1("fit_func",sqrtFunc,130,1500,3); //TF1 *fit_func = new TF1("fit_func",OneoverXFunc,130,1620,2); //TF1 *fit_func = new TF1("fit_func",OneoversqrtXFunc,130,1620,2); TGraphErrors *grRatio = 0; Double_t xval[nbins]; Double_t xerr[nbins]; Double_t rMean[nbins]; Double_t rMeanErr[nbins]; TCanvas *c = MakeCanvas("c","c",900,900); TGraphErrors *errBand = new TGraphErrors(nbins+2); char fitparam[100]; char chi2ndf[50]; for(int i(0);i<5;i++) { sprintf(tmpName,"h1_powheg_phantom_%d",i); h1_powheg_phantom[i] = (TH1D*)fname->Get(tmpName)->Clone(tmpName);// h1_powheg_phantom[i]->Sumw2(); for(Int_t ibin=0; ibin<nbins; ibin++) { xval[ibin] = 0.5*(Bins[ibin+1]+Bins[ibin]); xerr[ibin] = 0.5*(Bins[ibin+1]-Bins[ibin]); rMean[ibin] = h1_powheg_phantom[i]->GetBinContent(ibin+1); rMeanErr[ibin] = h1_powheg_phantom[i]->GetBinError(ibin+1); } grRatio = new TGraphErrors(nbins,xval,rMean,xerr,rMeanErr); grRatio->SetName("grRatio"); //njet=0 set fit function parameter limits //fit_func->SetParLimits(0,0.93,0.97); //fit_func->SetParLimits(1,-0.00015,-0.000095); //njet=1 set fit function parameter limits //fit_func->SetParLimits(0,0.,5.); //fit_func->SetParLimits(1,-5.0,0.0); //fit_func->SetRange(300.,1000.); //fit_func->SetParameters(0.9582,-0.0001); //njet=0 fix fit function parameters //fit_func->SetParameter(0,0.95); //fit_func->SetParameter(1,1.52); //fit_func->SetParameter(2,-0.0041); //fit_func->FixParameter(0,0); //fit_func->SetParameter(0,1); //fit_func->SetParameter(1,-30); //fit_func->SetParameter(2,-0.00001); //fit_func->FixParameter(2,-0.00425127); //fit_func->SetParLimits(1,0.0,0.0); //fit_func->FixParameter(1,0); if(i==1) { //fit_func->SetParameter(0,1.1); //fit_func->SetParameter(1,0.0); } if(i==2) { fit_func->SetParameter(0,0.9); fit_func->SetParameter(1,0.00001); } if(i==3) { //fit_func->SetParLimits(1,-0.00015,-0.000095); fit_func->SetParameter(0,0.4); fit_func->SetParameter(1,0.000001); } fitres = grRatio->Fit("fit_func","QMRN0FBSE"); //fitres = grRatio->Fit("fit_func","QMRN0SE"); sprintf(chi2ndf,"#chi^{2}/ndf = %.4f",(fit_func->GetChisquare())/(fit_func->GetNDF())); //errBand->SetPoint(0,0.002*(xval[nbins-1]),fit_func->Eval(0.002*(xval[nbins-1]))); errBand->SetPoint(0,0,130); errBand->SetPointError(0,0,dpol1Func(fit_func,0.002*(xval[nbins-1]),fitres)); //errBand->SetPointError(0,0,dpol2Func(fit_func,0.002*(xval[nbins-1]),fitres)); //errBand->SetPointError(0,0,dExpFunc(fit_func,0.002*(xval[nbins-1]),fitres)); //errBand->SetPointError(0,0,dsqrtFunc(fit_func,0.002*(xval[nbins-1]),fitres)); //errBand->SetPointError(0,0,dOneoverXFunc(fit_func,0.002*(xval[nbins-1]),fitres)); //errBand->SetPointError(0,0,dOneoversqrtXFunc(fit_func,0.002*(xval[nbins-1]),fitres)); //cout <<"0\t" << 0.002*(xval[nbins-1])<<"\t"<<fit_func->Eval(0.002*(xval[nbins-1]))<<"\t"<<dOneoversqrtXFunc(fit_func,0.002*(xval[nbins-1]),fitres)<<endl; errBand->SetPoint(1,130,fit_func->Eval(130)); //errBand->SetPointError(1,0,dOneoverXFunc(fit_func,130,fitres)); //errBand->SetPointError(1,0,dOneoversqrtXFunc(fit_func,130,fitres)); errBand->SetPointError(1,0,dpol1Func(fit_func,130,fitres)); for(Int_t j=2; j<=nbins; j++) { errBand->SetPoint(j,xval[j-1],fit_func->Eval(xval[j-1])); //errBand->SetPointError(j,0,dExpFunc(fit_func,xval[j-1],fitres)); //errBand->SetPointError(j,0,dsqrtFunc(fit_func,xval[j-1],fitres)); //errBand->SetPointError(j,0,dOneoverXFunc(fit_func,xval[j-1],fitres)); //errBand->SetPointError(j,0,dOneoversqrtXFunc(fit_func,xval[j-1],fitres)); errBand->SetPointError(j,0,dpol1Func(fit_func,xval[j-1],fitres)); //cout <<j<<"\t"<<xval[j-1]<<"\t"<<fit_func->Eval(xval[j-1])<<"\t"<<dOneoversqrtXFunc(fit_func,xval[j-1],fitres)<<endl; } errBand->SetPoint(nbins+1,1.2*(xval[nbins-1]),fit_func->Eval(1.2*(xval[nbins-1]))); errBand->SetPointError(nbins+1,0,dpol1Func(fit_func,1.2*(xval[nbins-1]),fitres)); //errBand->SetPointError(nbins+1,0,dpol2Func(fit_func,1.2*(xval[nbins-1]),fitres)); //errBand->SetPointError(nbins+1,0,dExpFunc(fit_func,1.2*(xval[nbins-1]),fitres)); //errBand->SetPointError(nbins+1,0,dsqrtFunc(fit_func,1.2*(xval[nbins-1]),fitres)); //errBand->SetPointError(nbins+1,0,dOneoverXFunc(fit_func,1.2*(xval[nbins-1]),fitres)); //errBand->SetPointError(nbins+1,0,dOneoversqrtXFunc(fit_func,1.2*(xval[nbins-1]),fitres)); sprintf(histName,"Fit_%d_jet",i); CPlot plotFunc(histName,"","mWW","POWHEG/Phantom"); plotFunc.setOutDir(OutDir); if(i>6) { plotFunc.AddGraph(grRatio,""); plotFunc.AddGraph(errBand,"3",kAzure-9,kFullDotSmall); } plotFunc.AddGraph(grRatio,"",kBlack,kFullCircle); if(i>6) plotFunc.AddFcn(fit_func,kRed); sprintf(histName,"njet=%d",i); if(i==3) sprintf(histName,"njet#geq3"); if(i==4) sprintf(histName,"Inclusive jet bins"); plotFunc.AddTextBox(histName,0.68,0.9,0.88,0.86,0,kBlack,-1); if(i>6) { plotFunc.AddTextBox(chi2ndf,0.25,0.9,0.45,0.86,0,kBlack,-1); sprintf(fitparam,"a = %.4f #pm %.4f",fit_func->GetParameter(0),fit_func->GetParError(0)); plotFunc.AddTextBox(fitparam,0.25,0.86,0.45,0.82,0,kBlack,-1); sprintf(fitparam,"b = %.6f #pm %.6f",fit_func->GetParameter(1),fit_func->GetParError(1)); plotFunc.AddTextBox(fitparam,0.25,0.82,0.5,0.78,0,kBlack,-1); } //sprintf(fitparam,"c = %.8f #pm %.8f",fit_func->GetParameter(2),fit_func->GetParError(2)); //plotFunc.AddTextBox(fitparam,0.25,0.78,0.45,0.74,0,kBlack,-1); if(i==0) { // plotFunc.SetYRange(0.5,4.0); //plotFunc.AddLine(0,1.52049,1640,1.52049,kBlack,2); } if(i==1) { //plotFunc.SetYRange(0.8,1.5); //plotFunc.AddLine(0,0.97262,1640,0.97262,kBlack,2); } if(i==2) { //plotFunc.SetYRange(0.8,1.2); plotFunc.AddLine(0,0.993992,1640,0.993992,kBlack,2); } if(i==3) { //plotFunc.SetYRange(0.0,1.3); plotFunc.AddLine(0,0.720189,1640,0.720189,kBlack,2); } plotFunc.Draw(c,kTRUE,"png"); } }
void countMuonsPerRunD3PD(){ //gInterpreter->GenerateDictionary("map<int, double >","map.h;map"); int cutValue = 11; float ptmin = 10.0; //float ptmin = 4.; //TString fileNameMuonIn = "/afs/cern.ch/user/t/tbalestr/public/16.6.2.5/WorkArea/run/HISingleMuon.root"; ///7.3 ub^-1 2010 data //TString fileNameMuonIn = "/tmp/tbalestr/HISingleMuon_Aug4_v2.root"; ///2011 PbPb data //TString fileNameMuonIn = "/tmp/tbalestr/HISingleMuon_DPD_HP_merged_26May.root"; //TString fileNameMuonIn = "/tmp/tbalestr/HISingleMuon_DPD_HP_30May.root"; TString baseString = "/mnt/Lustre/cgrp/atlas_hi/tbalestri/"; TString fileNameMuonIn = baseString+"HardProbesFiles/HISingleMuonHardProbesData.04.17.2013.root"; TFile* fMuIn = new TFile(fileNameMuonIn, "READ"); if ( !fMuIn->IsOpen() ) { std::cout << fMuIn << " not found!" << std::endl; } TFile* outFile = new TFile("muonsPerRun.root","recreate"); ///lumi in ub^-1 std::vector<double> vLumi; vLumi.push_back(0.0137422); vLumi.push_back(0.126333); vLumi.push_back(1.28605451); vLumi.push_back(0.08307752); vLumi.push_back(3.948807); vLumi.push_back(2.766361); vLumi.push_back(3.606919); vLumi.push_back(3.809249); vLumi.push_back(4.11709); vLumi.push_back(4.88581); vLumi.push_back(2.50513); vLumi.push_back(0.0619227); vLumi.push_back(0.9694949); vLumi.push_back(0.582203); vLumi.push_back(5.42834); vLumi.push_back(4.20247); vLumi.push_back(0.38549); vLumi.push_back(5.50425); vLumi.push_back(3.15969); vLumi.push_back(4.19951); vLumi.push_back(5.24396); vLumi.push_back(5.30817); vLumi.push_back(0.0433861); vLumi.push_back(5.29888); vLumi.push_back(5.30346); vLumi.push_back(0.757212); vLumi.push_back(5.985104); vLumi.push_back(5.1515); vLumi.push_back(6.57761); vLumi.push_back(1.75062); vLumi.push_back(5.43771); vLumi.push_back(3.13928); vLumi.push_back(5.14981); vLumi.push_back(4.90751); vLumi.push_back(2.521785); vLumi.push_back(6.45269); vLumi.push_back(3.59951); vLumi.push_back(5.33795); vLumi.push_back(6.16766); vLumi.push_back(1.77379); vLumi.push_back(0.923454); vLumi.push_back(2.07656); std::vector<int> vRun; vRun.push_back(193211); vRun.push_back(193270); vRun.push_back(193291); vRun.push_back(193295); vRun.push_back(193321); vRun.push_back(193403); vRun.push_back(193412); vRun.push_back(193447); vRun.push_back(193463); vRun.push_back(193481); vRun.push_back(193491); vRun.push_back(193492); vRun.push_back(193493); vRun.push_back(193494); vRun.push_back(193546); vRun.push_back(193558); vRun.push_back(193599); vRun.push_back(193604); vRun.push_back(193641); vRun.push_back(193655); vRun.push_back(193662); vRun.push_back(193679); vRun.push_back(193687); vRun.push_back(193718); vRun.push_back(193795); vRun.push_back(193823); vRun.push_back(193825); vRun.push_back(193826); vRun.push_back(193834); vRun.push_back(193890); vRun.push_back(194017); vRun.push_back(194060); vRun.push_back(194061); vRun.push_back(194121); vRun.push_back(194160); vRun.push_back(194163); vRun.push_back(194179); vRun.push_back(194192); vRun.push_back(194193); vRun.push_back(194370); vRun.push_back(194374); vRun.push_back(194382); const int nRuns = vRun.size(); TGraphErrors* grLumi = new TGraphErrors(nRuns); TGraphErrors* grMuPerLumi = new TGraphErrors(nRuns); int valNt[30], EF_mu4_MSonly_L1TE50_Matched20[30],EF_mu4_L1VTE50_Matched20[30],runNt, mu_muid_nNt; int EF_mu10_MSonly_EFFS_L1ZDC_Matched20[30], EF_mu10_MSonly_EFFS_L1TE10_Matched20[30],EF_mu10_MSonly_EFFS_L1TE20_Matched20[30]; int EF_mu10_MSonly_EFFS_L1ZDC, EF_mu10_MSonly_EFFS_L1TE10, EF_mu10_MSonly_EFFS_L1TE20, EF_mu4_MSonly_L1TE50, EF_mu4_L1VTE50; float ptNt[30], centralityNt,etaNt[30],eLossNt[30],scatNt[30]; TChain* tree = new TChain("tree","tree"); std::cout << "Filling the tree for " << fileNameMuonIn << std::endl; tree->Add(fileNameMuonIn); // --- Set branch adresses --- tree->SetBranchAddress("val", &valNt); tree->SetBranchAddress("pt", &ptNt); tree->SetBranchAddress("eta", &etaNt); tree->SetBranchAddress("eLoss",&eLossNt); tree->SetBranchAddress("scat",&scatNt); tree->SetBranchAddress("mu_muid_n", &mu_muid_nNt); tree->SetBranchAddress("run", &runNt); tree->SetBranchAddress("centrality", ¢ralityNt); tree->SetBranchAddress("EF_mu4_MSonly_L1TE50", &EF_mu4_MSonly_L1TE50); tree->SetBranchAddress("EF_mu4_L1VTE50", &EF_mu4_L1VTE50); tree->SetBranchAddress("EF_mu4_MSonly_L1TE50_Matched20", &EF_mu4_MSonly_L1TE50_Matched20); tree->SetBranchAddress("EF_mu4_L1VTE50_Matched20", &EF_mu4_L1VTE50_Matched20); tree->SetBranchAddress("EF_mu10_MSonly_EFFS_L1ZDC", &EF_mu10_MSonly_EFFS_L1ZDC); tree->SetBranchAddress("EF_mu10_MSonly_EFFS_L1TE10", &EF_mu10_MSonly_EFFS_L1TE10); tree->SetBranchAddress("EF_mu10_MSonly_EFFS_L1TE20", &EF_mu10_MSonly_EFFS_L1TE20); tree->SetBranchAddress("EF_mu10_MSonly_EFFS_L1ZDC_Matched20", &EF_mu10_MSonly_EFFS_L1ZDC_Matched20); tree->SetBranchAddress("EF_mu10_MSonly_EFFS_L1TE10_Matched20", &EF_mu10_MSonly_EFFS_L1TE10_Matched20); tree->SetBranchAddress("EF_mu10_MSonly_EFFS_L1TE20_Matched20", &EF_mu10_MSonly_EFFS_L1TE20_Matched20); tree->SetBranchStatus("*",0); tree->SetBranchStatus("val", 1); tree->SetBranchStatus("pt", 1); tree->SetBranchStatus("eta", 1); tree->SetBranchStatus("eLoss",1); tree->SetBranchStatus("scat",1); tree->SetBranchStatus("mu_muid_n", 1); tree->SetBranchStatus("run", 1); tree->SetBranchStatus("centrality", 1); tree->SetBranchStatus("EF_mu4_MSonly_L1TE50", 1); tree->SetBranchStatus("EF_mu4_L1VTE50", 1); tree->SetBranchStatus("EF_mu4_MSonly_L1TE50_Matched20", 1); tree->SetBranchStatus("EF_mu4_L1VTE50_Matched20", 1); tree->SetBranchStatus("EF_mu10_MSonly_EFFS_L1ZDC", 1); tree->SetBranchStatus("EF_mu10_MSonly_EFFS_L1TE10", 1); tree->SetBranchStatus("EF_mu10_MSonly_EFFS_L1TE20", 1); tree->SetBranchStatus("EF_mu10_MSonly_EFFS_L1ZDC_Matched20", 1); tree->SetBranchStatus("EF_mu10_MSonly_EFFS_L1TE10_Matched20", 1); tree->SetBranchStatus("EF_mu10_MSonly_EFFS_L1TE20_Matched20", 1); std::cout << "Number of entries: " << tree->GetEntries() << std::endl; ///map runnumber to #mu ///need to used multimap since >1 muon ///value for each run number key std::multimap < int, int> runMap; ///loop over all events for ( int i = 0; i < tree->GetEntries(); ++i ) { // if(i>10000) break; tree->LoadTree(i); tree->GetEntry(i); if(i%10000==0) std::cout << "Event " << i << std::endl; for(int imu = 0; imu<mu_muid_nNt; imu++){ if ( (valNt[imu]>cutValue) && abs(etaNt[imu])>0.1 && abs(etaNt[imu])<2.4 && ptNt[imu]>ptmin && centralityNt>=0. && centralityNt<=0.8 && ( (EF_mu10_MSonly_EFFS_L1ZDC&&EF_mu10_MSonly_EFFS_L1ZDC_Matched20[imu]) || (EF_mu10_MSonly_EFFS_L1TE10&&EF_mu10_MSonly_EFFS_L1TE10_Matched20[imu]) ||(EF_mu10_MSonly_EFFS_L1TE20&&EF_mu10_MSonly_EFFS_L1TE20_Matched20[imu]) ) ){ ///count number of muons in this run that pass runMap.insert(make_pair (runNt,1) ); } } //imu } //i std::cout << std::endl; std::cout << "------------------------- " << std::endl; std::cout << " S U M M A R Y " << std::endl; std::cout << "------------------------- " << std::endl; TString spreadSheetName = "muonCountingSpreadSheet.csv"; std::ofstream spreadSheet; spreadSheet.open(spreadSheetName); double totLumi = 0.0, totalMu = 0; for(int iRun = 0; iRun<nRuns; ++iRun){ int muonsPassed = runMap.count( vRun[iRun] ); ///Muons per nb^-1 double muPerLumi = (double)muonsPassed/vLumi[iRun]/1000.0; ///Number of muons passed in run iRun std::cout << "Index: " << iRun+1 << "\tRun: " << vRun[iRun] << "\tLumi: " << vLumi[iRun]/1000.0 << "\tMuons: " << muonsPassed << "\tMuons/nb^-1: " << muPerLumi << std::endl; totLumi += vLumi[iRun]/1000.0; totalMu += muonsPassed; grMuPerLumi->SetPoint(iRun,vRun[iRun],muPerLumi); grMuPerLumi->SetPointError(iRun,0.5, TMath::Sqrt(muonsPassed)/vLumi[iRun]/1000.0); grLumi->SetPoint(iRun,totLumi,totalMu); grLumi->SetPointError(iRun, 0.0, 0.0); writeToSpreadsheet(spreadSheet,iRun+1,vRun[iRun],vLumi[iRun]/1000.,muonsPassed); } grMuPerLumi->Draw("ape"); grLumi->Draw("ape"); outFile->cd(); grLumi->Write("muonLumiDependence"); grMuPerLumi->Write("muonPerLumi"); std::cout << " Total Luminosity: " << totLumi << " nb^-1 " << std::endl; std::cout << " Total Muons passed: " << totalMu << std::endl; spreadSheet.close(); /* cout << "Number of runs: " << runMap.size() << endl; cout << "Run \t" << "Luminosity(ub^-1) \t" << " #muons \t" << "muons/lumi" << endl; ///map run lumi to #mu //std::map < int, double> lumiMap; for (unsigned int j = 0; j<runMap.size(); ++j){ int runTemp = vRun.at(j); double lumiTemp = vLumi.at(j); map <int,int>::const_iterator iPairFound = runMap.find(runTemp); cout << iPairFound->first << " \t " << lumiTemp << " \t " << " \t " << iPairFound->second << " \t " << " \t " << (double)iPairFound->second/lumiTemp << endl; sum += runMap[runTemp]; } cout << "Total Luminosity = " << totLumi << endl; cout << "Total = " << sum << endl; */ }
map<int,vector<double> > RPCChambersCluster::getReconstructedHits(vector<unsigned> vectorOfReferenceChambers, const int & timeWindow,const int & timeReference,bool & isVerticalTrack,map<int,double> & scintilatorsCoordinates,const bool & keepRecoTrack,TFile * fileForRecoTracks,const int & eventNum,const double & correlationFactor, const ESiteFileType & fileType){ // map<int,vector<double> > mapOfHits; // // the default value for Chi2goodness is 20 //double best_chi2goodnes_value = Chi2goodness+10 ; // this variable is used as reference so that it holds the best chi2 found for a track, so its used only a track with better chi2 to be accepted double currentBestCorrFact = -2; int lastFitPoint = 0; for (int i = 0 ; i < this->getNumberOfChambers() ; i++){ this->getChamberNumber(i+1)->findAllClustersForTriggerTimeReferenceAndTimeWindow(timeReference,timeWindow,5); //cout << "Chamber is " << i+1 << endl; } vector<vector<int> > vectorOfClusterNumberCombinations; if (fileType == kIsCERNrawFile ){ assert(vectorOfReferenceChambers.size() == 3 ); lastFitPoint = 9; for ( int i = 0 ; i < this->getChamberNumber(vectorOfReferenceChambers[0])->getNumberOfClusters() ; i++ ){ for( int j = 0 ; j < this->getChamberNumber(vectorOfReferenceChambers[1])->getNumberOfClusters() ; j++ ){ for( int k = 0 ; k < this->getChamberNumber(vectorOfReferenceChambers[vectorOfReferenceChambers.size()-1])->getNumberOfClusters() ; k++ ){ vector<int> singleCombination; singleCombination.push_back(i+1); singleCombination.push_back(j+1); singleCombination.push_back(k+1); for (int f = 0 ; f < singleCombination.size() ; f++){ if(this->getChamberNumber(vectorOfReferenceChambers[f])->getSizeOfCluster(singleCombination.at(f)) > 5 ) continue; // don't insert combination if there is too big cluster. } vectorOfClusterNumberCombinations.push_back(singleCombination); } } } } if (fileType == kIsBARCrawFile || fileType == kIsGENTrawFile ){ // add implementation for BARC and Ghent stand . lastFitPoint = 5; assert(vectorOfReferenceChambers.size() == 2); for ( int i = 0 ; i < this->getChamberNumber(vectorOfReferenceChambers[0])->getNumberOfClusters() ; i++ ){ for( int j = 0 ; j < this->getChamberNumber(vectorOfReferenceChambers[1])->getNumberOfClusters() ; j++ ){ vector<int> singleCombination; singleCombination.push_back(i+1); singleCombination.push_back(j+1); for (int f = 0 ; f < singleCombination.size() ; f++){ if(this->getChamberNumber(vectorOfReferenceChambers[f])->getSizeOfCluster(singleCombination.at(f)) > 5 ) continue; // don't insert combination if there is too big cluster. } vectorOfClusterNumberCombinations.push_back(singleCombination); } } } string topScintToString, botScintToString; for (int combinationsVectorElement = 0 ; combinationsVectorElement < vectorOfClusterNumberCombinations.size() ; combinationsVectorElement ++){ // the partition logic start here - track could pass more than one partition int direction = 0 ; // direction should describe how the partition changes from one reference chamber to another. It vector<int> RefChamberClusterPartition; bool positive = false; bool negative = false; int partitionPenetrated = 1; // the Y coordinate is the partition number (1 2 or 3 - A B or C) vector<int> clusterNum = vectorOfClusterNumberCombinations.at(combinationsVectorElement); for (int ii = 0; ii < clusterNum.size() ; ii++){ RefChamberClusterPartition.push_back(this->getChamberNumber(vectorOfReferenceChambers[ii])->getXYCoordinatesOfCluster(clusterNum.at(ii)).at(1)); } isVerticalTrack = true; for ( int ii = 0; ii < RefChamberClusterPartition.size() - 1 ; ii++ ){ direction = (RefChamberClusterPartition.at(ii) - RefChamberClusterPartition.at(ii+1)); if (direction != 0) { direction = direction/abs(direction); partitionPenetrated++; } // get only the sign ( +1 or -1) if (direction && direction == -1) { positive = true; isVerticalTrack = false; } if (direction && direction == 1 ) { negative = true; isVerticalTrack = false; } } if ( positive && negative ) continue; // cannot have a track that goes in both direction /* TH1F * histXZ = new TH1F("fitHistogram","XZ plane",110,0,11); histXZ->GetYaxis()->SetRangeUser(-20,52); histXZ->SetMarkerColor(kBlue); histXZ->SetMarkerStyle(kCircle); histXZ->GetXaxis()->SetTitle("Shelf number"); histXZ->GetYaxis()->SetTitle("Channel number"); */ TF1 * fitfunc = new TF1("FitTrack","[0]+x*[1]",0,lastFitPoint+1); TGraphErrors * graphXZ = new TGraphErrors(); graphXZ->GetXaxis()->SetTitle("Shelf number"); graphXZ->GetYaxis()->SetTitle("Channel number"); //graphXZ->SetLineColor(0); graphXZ->SetMarkerColor(kBlack); graphXZ->SetMarkerStyle(kFullCircle); graphXZ->SetName("fit graph"); graphXZ->SetTitle("XZ plane"); graphXZ->GetXaxis()->SetTitle("Muon station"); graphXZ->GetYaxis()->SetTitle("Channel number"); fitfunc->SetLineColor(kBlue); vector<double> coordinates; double xCoordinate = 0; int yCoordinate = 0; int zCoorinate = 0; for (int ii=0 ; ii < vectorOfReferenceChambers.size() ; ii++){ coordinates = this->getChamberNumber(vectorOfReferenceChambers[ii])->getXYCoordinatesOfCluster(clusterNum[ii]); xCoordinate = coordinates.at(0); yCoordinate = coordinates.at(1); zCoorinate = 10*vectorOfReferenceChambers[ii]; Double_t errorValue = this->getChamberNumber(vectorOfReferenceChambers[ii])->getSizeOfCluster(clusterNum[ii]); // histXZ->SetBinContent(zCoorinate,xCoordinate); // histXZ->SetBinError(zCoorinate,errorValue/2); //cout << xCoordinate << " " << yCoordinate << endl; graphXZ->SetPoint(ii,vectorOfReferenceChambers[ii],xCoordinate); graphXZ->SetPointError(ii,0,errorValue/2); } Double_t params[2]; graphXZ->Fit(fitfunc,"RFQ"); fitfunc->GetParameters(params); //cout << "par1 " << params[0] << " par2 " << params[1] << " chi2 " << fitfunc->GetChisquare() << endl; // The resudials - difference between estimated fit value and the middle of the nearest cluster int prevReference = 0 , nextReference = 0 , prevReferencePartition = 0 , nextReferencePartition = 0; bool currentChamberIsReference = false; int startCounter = 0, endCounter = 0; if ( abs(graphXZ->GetCorrelationFactor()) >= correlationFactor && abs(graphXZ->GetCorrelationFactor()) > currentBestCorrFact ) { // in case of only one partition, get the partition number of the first reference point currentBestCorrFact = abs(graphXZ->GetCorrelationFactor()); int referenceChambersIncrementor = 0; bool negativeChannelNumberIsFound = false; // --------- for ( int currentChNumber = 0 ; currentChNumber < this->getNumberOfChambers() ; currentChNumber++ ) { // check where the chamber is according to the reference chambers vector<double> vectorOfpartitionsAndHit; double channelNum = fitfunc->Eval(currentChNumber+1); /** four cases 1. the chamber is before the first reference 2. the chamber is after the last reference 3. the chamber is between two references 4. the chamber is a reference */ for(int refCheck = 0 ; refCheck < vectorOfReferenceChambers.size(); refCheck++){ // find the surounding references if (currentChNumber+1 == vectorOfReferenceChambers.at(refCheck)){ currentChamberIsReference = true; break; } if ( vectorOfReferenceChambers.at(refCheck) > currentChNumber+1 && refCheck == 0 ){ // its before the first reference chamber nextReference = vectorOfReferenceChambers.at(refCheck); nextReferencePartition = this->getChamberNumber(nextReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1); break; } if ( vectorOfReferenceChambers.at(refCheck) < currentChNumber+1 && refCheck == vectorOfReferenceChambers.size() - 1 ){ // its after the last chamber prevReference = vectorOfReferenceChambers.at(refCheck); prevReferencePartition = this->getChamberNumber(prevReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1); break; } if ( vectorOfReferenceChambers.at(refCheck) < currentChNumber+1 && vectorOfReferenceChambers.at(refCheck+1) > currentChNumber+1 ){ // its between two references prevReference = vectorOfReferenceChambers.at(refCheck) ; nextReference = vectorOfReferenceChambers.at(refCheck+1); prevReferencePartition = this->getChamberNumber(prevReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1); nextReferencePartition = this->getChamberNumber(nextReference)->getXYCoordinatesOfCluster(clusterNum[refCheck+1]).at(1); break; } } // end of partition possibilities if(!currentChamberIsReference){ if (nextReference && prevReference == 0){ if (positive){ prevReferencePartition = 1; } if(negative){ prevReferencePartition = this->getChamberNumber(1)->getClones(); } } if (prevReferencePartition && nextReferencePartition == 0){ if (positive){ nextReferencePartition = this->getChamberNumber(1)->getClones(); } if(negative){ nextReferencePartition = 1; } } if (partitionPenetrated == 1 ){ prevReferencePartition = yCoordinate; nextReferencePartition = yCoordinate; int firstRef = vectorOfReferenceChambers.at(0); int lastRef = vectorOfReferenceChambers.at(vectorOfReferenceChambers.size() - 1); int ccham = currentChNumber+1; if(! (lastRef > ccham && firstRef < ccham) ){ // all partitions are possible, chambers are out of the reference scope prevReferencePartition = this->getChamberNumber(1)->getClones(); nextReferencePartition = 1; // 3 in case of ecap chamber } } if (positive){ startCounter = prevReferencePartition; endCounter = nextReferencePartition; } else { startCounter = nextReferencePartition ; endCounter = prevReferencePartition ; } for (int currentCounter = startCounter ; currentCounter <= endCounter; currentCounter ++ ){ assert(currentCounter > 0 && currentCounter < 4); vectorOfpartitionsAndHit.push_back(currentCounter); } } else{ vectorOfpartitionsAndHit.push_back(this->getChamberNumber(currentChNumber+1)->getXYCoordinatesOfCluster(clusterNum[referenceChambersIncrementor]).at(1)); referenceChambersIncrementor ++; } prevReference = 0 ; nextReference = 0 ; prevReferencePartition = 0 ; nextReferencePartition = 0; currentChamberIsReference = false; //cout << "Chamber " << l+1 << " " << coordinates.at(1) << " " << fitfunc->Eval(l+1) << " " << endl; int channelNumberToStore = channelNum; if (channelNumberToStore < 96/this->getChamberNumber(1)->getClones()){ channelNumberToStore += 1; } // add one to represent the fired channel, or none if the channel is on the right border vectorOfpartitionsAndHit.push_back(channelNumberToStore); // the last element is the number of the channel // Debug lines /** cout << "Chamber is " << currentChNumber+1 << " partitions " ; for (int thesize = 0 ; thesize < vectorOfpartitionsAndHit.size() - 1; thesize++){ cout << vectorOfpartitionsAndHit.at(thesize) << " " ; } cout << "channel " << vectorOfpartitionsAndHit.at(vectorOfpartitionsAndHit.size()-1) << endl; */ mapOfHits[currentChNumber+1] = vectorOfpartitionsAndHit; } // ---------- scintilators coordinates estimate for (int scintNum = 0 ; scintNum < 31 ; scintNum++){ if(this->getTriggerObjectNumber(1)->getChannel(scintNum+1)->hasHit() && vectorOfClusterNumberCombinations.size() == 1 ) { if (scintNum < 10) { scintilatorsCoordinates[scintNum+1] = graphXZ->Eval(0); topScintToString = boost::lexical_cast<string>(scintNum+1); } else { scintilatorsCoordinates[scintNum+1] = graphXZ->Eval(lastFitPoint+1); botScintToString = boost::lexical_cast<string>(scintNum+1); } } } } // get only vertical tracks from the A partition if there are only two scint hits if (keepRecoTrack && isVerticalTrack && !mapOfHits.empty() && scintilatorsCoordinates.size() == 2){ graphXZ->SetName(boost::lexical_cast<string>(eventNum).c_str()); string partition; if (mapOfHits.find(vectorOfReferenceChambers.at(0))->second.at(0) == 1) partition = "A"; else if (mapOfHits.find(vectorOfReferenceChambers.at(0))->second.at(0) == 2) partition = "B"; else partition = "C"; graphXZ->SetTitle(("Correlation factor is "+boost::lexical_cast<string>(graphXZ->GetCorrelationFactor()) + " trigger channels top: " + topScintToString + " bottom: " + botScintToString ).c_str()); if(abs(graphXZ->GetCorrelationFactor()) >= correlationFactor) { string scintCombination="_"+topScintToString+"_"+botScintToString+"_"+partition; TDirectory * dir = fileForRecoTracks->GetDirectory(scintCombination.c_str(),true); if(!dir) { //fileForRecoTracks->ls(); fileForRecoTracks->mkdir(scintCombination.c_str()) ; fileForRecoTracks->cd(""); } fileForRecoTracks->cd(scintCombination.c_str()); //cout << fileForRecoTracks->GetPath() << endl; } else{ fileForRecoTracks->cd("") ; fileForRecoTracks->cd("badTracks") ; } graphXZ->Write(graphXZ->GetName(),TObject::kOverwrite); fileForRecoTracks->cd(""); //fileForRecoTracks->Write(graphXZ->GetName(),TObject::kOverwrite); } fitfunc->Delete(); //histXZ->Delete(); graphXZ->Delete(); } return mapOfHits; }
void makePlots(vector<inputValues> b, vector<inputValues> t, vector<outputValues> o, double cut) { // Plot output values vs pulse width TGraphErrors * eLPlot = new TGraphErrors(); TGraphErrors * ePsiPlot = new TGraphErrors (); eLPlot->SetTitle("Average Number of LED-induced Photoelectrons per Trigger"); ePsiPlot->SetTitle("Single-photoelectron Response Mean Amplitude"); eLPlot->SetMarkerColor(4); ePsiPlot->SetMarkerColor(4); eLPlot->SetMarkerStyle(21); ePsiPlot->SetMarkerStyle(21); for (int i = 0; i < b.size(); i++) { for (int j = 0; j < t.size(); j++) { eLPlot->SetPoint((i+1)*j, t[j].pw, o[(i+1)*j].eL); eLPlot->SetPointError((i+1)*j, 0.02, sqrt(o[(i+1)*j].v_eL)); ePsiPlot->SetPoint((i+1)*j, t[j].pw, o[(i+1)*j].ePsi); ePsiPlot->SetPointError((i+1)*j, 0.02, sqrt(o[(i+1)*j].v_ePsi)); } } TCanvas * eL_c = new TCanvas("eL_c", "eL Canvas", 200, 10, 700, 500); eLPlot->GetXaxis()->SetTitle("LED Pulse Width / (ns)"); eLPlot->GetYaxis()->SetTitle("Photoelectrons / Trigger"); eLPlot->Draw("AP"); TCanvas * ePsi_c = new TCanvas("ePsi_c", "ePsi Canvas", 200, 10, 700, 500); ePsiPlot->GetXaxis()->SetTitle("LED Pulse Width / (ns)"); ePsiPlot->GetYaxis()->SetTitle("Mean Amplitude / (mV)"); ePsiPlot->GetYaxis()->SetRangeUser(0.3, 1.6); ePsiPlot->Draw("AP"); TF1 * fit = new TF1("fit", "[0]", 0, 10); ePsiPlot->Fit(fit); // Plot spectra TCanvas * spectra_c = new TCanvas("spectra_c", "Spectra Canvas", 200, 10, 700, 500); spectra_c->SetLogy(); for (int i = t.size() - 1; i >= 0; i--) { t[i].h->SetLineColor(i+2); t[i].h->SetLineWidth(2); t[i].h->Draw("SAME"); t[i].h->SetStats(0); t[i].h->SetTitle("PMT Spectra of Pulsed LED w/ Varying Pulse Width"); t[i].h->GetXaxis()->SetTitle("Amplitude / (mV)"); t[i].h->GetYaxis()->SetTitle("Events"); t[i].h->GetYaxis()->SetRangeUser(0.5, 20000); } b[0].h->SetLineColor(1); b[0].h->SetLineWidth(2); b[0].h->Draw("SAME"); b[0].h->SetStats(0); TLine * cutLine_t = new TLine(-1*cut, 0.0, -1*cut, 20000.0); cutLine_t->SetLineWidth(2); cutLine_t->SetLineColor(1); cutLine_t->SetLineStyle(2); cutLine_t->Draw(); TLine * meanLine_t = new TLine(b[0].e + 0.89, 0.0, b[0].e + 0.89, 20000.0); meanLine_t->SetLineWidth(2); meanLine_t->SetLineColor(2); meanLine_t->SetLineStyle(2); meanLine_t->Draw(); // Add legend //TLegend * leg = new TLegend(0.1, 0.7, 0.48, 0.9); //leg->SetHeader("Legend"); //leg->AddEntry(t[0].h, " // Plot background //TCanvas * b_c = new TCanvas("b_c", "Background Canvas", 200, 10, 700, 500); //b_c->SetLogy(); ////b[0].h->Sumw2(); ////b[0].h->Draw(); //b[0].h->GetYaxis()->SetRangeUser(1.0, 100000.0); //b[0].h->SetTitle("Background PMT Spectrum"); //b[0].h->GetXaxis()->SetTitle("Amplitude / (mV)"); //b[0].h->GetYaxis()->SetTitle("Events"); //TLine * cutLine_b = new TLine(cut, 0.0, cut, 1000000.0); //cutLine_b->SetLineWidth(2); //cutLine_b->Draw(); }
void AnalyzeData(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt, Int_t startEv = 1, char *PedFile, Int_t DrawExtraGraphs = 0) { // Redefine DOMINO Depth in ADC counts const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH); // open file FILE *fdata = OpenDataFile(DataFile); struct channel_struct *p; struct channel_struct *dep; // create histograms // create list of histograms for channels and distribution TList *DistChList = new TList(); TH1F *distch; // histo with distribution of cell-charge, for each channel TList *DistChSubList = new TList(); TH1F *distchsub; // histo with distribution of cell-charge, pedestals subtracted, for each channel TList *DistCh0SubList = new TList(); TH1F *distch0sub; // histo with distribution of cell-charge, pedestals subtracted, // channel 0 subtracted for each channel TList *grPedList = new TList(); TGraphErrors *grPed; // for each channel, pedestal value and RMS for each cell is plotted TList *hCellList = new TList(); TH1F *hCell; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos) TList *hCellSubList = new TList(); TH1F *hCellSub; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos), pedestal subtracted TList *hRMSList = new TList(); TH1F *hRMSdist; // histo with RMS distribution (statistical RMS of distribution) TList *hRMSFitList = new TList(); TH1F *hRMSFitdist; // histo with RMS distribution (RMS of Gaussian fit) TList *grDataList = new TList(); TGraphErrors *grData; // charge-cell and RMS for each cell is plotted TList *grDataSubList = new TList(); TGraphErrors *grDataSub; // pedestal subtracted charge-cell and RMS for each cell is plotted for (int h = 0; h < DOMINO_NCH; h++) { // TString title = "Data Dist channel"; title += h; distch = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC); DistChList->Add(distch); // TString title = "Data Dist Ped Sub channel"; title += h; distchsub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2); DistChSubList->Add(distchsub); // TString title = "Data Dist Ped Ch0 Sub channel"; title += h; distch0sub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2); DistCh0SubList->Add(distch0sub); // TString title = "Pedestal ch"; title += h; grPed = new TGraphErrors(DOMINO_NCELL); grPed->SetTitle(title); grPedList->Add(grPed); // TString title = "Data ch"; title += h; grData = new TGraphErrors(DOMINO_NCELL); grData->SetTitle(title); grDataList->Add(grData); // // Mean data and RMS for each channel and cell TString title = "Data PedSubtracted ch"; title += h; grDataSub = new TGraphErrors(DOMINO_NCELL); grDataSub->SetTitle(title); grDataSubList->Add(grDataSub); // for (int ch = 0; ch < DOMINO_NCELL; ch++) { // data distribution histos TString title = "Data ch"; title += h; title += " cell"; title += ch; hCell = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC); hCellList->Add(hCell); // data (ped subtracted) distribution histos TString title = "Data PedSub ch"; title += h; title += " cell "; title += ch; hCellSub = new TH1F(title, title, 2 * DominoDepthADC, -1 * DominoDepthADC, DominoDepthADC); hCellSubList->Add(hCellSub); } // Data-RMS distribution histos TString title = "RMSDist channel"; title += h; hRMSdist = new TH1F(title, title, 100, 0, 20.); hRMSList->Add(hRMSdist); // Data-RMS (calculated through a fit) distribution histos TString title = "RMSFitDist channel"; title += h; hRMSFitdist = new TH1F(title, title, 100, 0, 20.); hRMSFitList->Add(hRMSFitdist); } //-------------- // // calculate or read pedestals from file grPedList = OpenPedestals(PedFile); // return; // // ====== Read data file and subtract the pedestals // // Count number of events in data file int nevtDataMax = 0; while (!feof(fdata)) { fread((void *) &event_data, 1, sizeof(event_data), fdata); nevtDataMax++; } printf("nevtDataMax: %d\n", nevtDataMax); if (nevt > (nevtDataMax - startEv) || nevt == 0) nevt = nevtDataMax - startEv; cout << endl << "==>> Processing " << nevt << " events from file " << DataFile << endl; rewind(fdata); Int_t ievt = 1; // go to first event (startEv) while (ievt < startEv) { fread((void *) &event_data, 1, sizeof(event_data), fdata); if (feof(fdata)) break; ievt++; } // filling ievt = 1; Int_t flagEnd = 0; Double_t chtmp; Double_t PedVal, itmp, Ch0Val; // loop on events cout << endl << " --- read DATA file:" << fdata << endl; while (ievt <= nevt && !flagEnd) { fread((void *) &event_data, 1, sizeof(event_data), fdata); if (feof(fdata)) flagEnd = 1; if (ievt % (nevt / 10 + 1) == 0) cout << "*" << endl; p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data TGraphErrors *grCh0 = new TGraphErrors(DOMINO_NCELL); // loop on channels for (int h = 0; h < DOMINO_NCH; h++) { // loop on cells distch = (TH1F *) DistChList->At(h); distchsub = (TH1F *) DistChSubList->At(h); grPed = (TGraphErrors *) grPedList->At(h); distch0sub = (TH1F *) DistCh0SubList->At(h); if(h==0) { for(i = 0; i < DOMINO_NCELL;i++) { grPed->GetPoint(i, itmp, PedVal); chtmp = (Double_t)(p->data[i]); chtmp = chtmp - PedVal; grCh0->SetPoint(i,itmp, chtmp); } } for (int i = 0; i < DOMINO_NCELL; i++) { // Read pedestal value for this cell grPed->GetPoint(i, itmp, PedVal); grCh0->GetPoint(i, itmp, Ch0Val); // cout << itmp << ", " << PedVal << endl; // Read calibration correction for this cell // CalFact = //charge distribution for each cell, pedestal subtracted chtmp = (Double_t)(p->data[i]); // data value // cout << "tcell, tcell, depth: " << chtmp << "," << p->data[i] << "," << deptmp << endl; distch->Fill(chtmp); // Check data value: must be within DOMINO Depth // if(chtmp > DominoDepthADC) // cout << " === WARNING!!! Channel " << h << " Cell " << i << " has value " << chtmp << endl; // cout << "Charge: " << p->data[i] << endl; ((TH1 *) hCellList->At(h * DOMINO_NCELL + i))->Fill(chtmp); // Now the pedestal is subtracted chtmp = chtmp - PedVal; distchsub->Fill(chtmp); ((TH1 *) hCellSubList->At(h * DOMINO_NCELL + i))->Fill(chtmp); chtmp = chtmp - Ch0Val; distch0sub->Fill(chtmp); } p++; // next channel } ievt++; // next event } cout << endl; // now mean and RMS for each cell are computed and save in histos and graphs cout << " --- filling data histos and grphs " << endl; TF1 *fgauss = new TF1("fgauss", Gauss, -10., 10., 3); fgauss->SetParLimits(0, 0.1, 10000.); fgauss->SetParLimits(1, 0., 4096.); fgauss->SetParLimits(2, 0.1, 20.); Float_t mean, rms, meansub, rmssub; for (int h = 0; h < DOMINO_NCH; h++) { // for (int h=5; h<6; h++){ cout << " Channel:" << h << endl; hRMSdist = (TH1F *) hRMSList->At(h); hRMSFitdist = (TH1F *) hRMSFitList->At(h); grData = (TGraphErrors *) grDataList->At(h); grDataSub = (TGraphErrors *) grDataSubList->At(h); for (int ch = 0; ch < DOMINO_NCELL; ch++) { // data distribution histos // cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<<hCell->GetMean()<< "," << hCell->GetRMS()<<endl; hCell = (TH1F *) hCellList->At(h * DOMINO_NCELL + ch); mean = hCell->GetMean(); rms = hCell->GetRMS(); hCellSub = (TH1F *) hCellSubList->At(h * DOMINO_NCELL + ch); meansub = hCellSub->GetMean(); rmssub = hCellSub->GetRMS(); fgauss->SetParameter(0, (Double_t) nevt / 4.); fgauss->SetParameter(1, mean); fgauss->SetParameter(2, rms); // hCell->Fit("fgauss","QN0"); grData->SetPoint(ch, ch, mean); grData->SetPointError(ch, 0, rms); grDataSub->SetPoint(ch, ch, meansub); // grDataSub->SetPointError(ch,0.5,rmssub); grDataSub->SetPointError(ch, 0.5, 2.1); hRMSdist->Fill(rms); hRMSFitdist->Fill(fgauss->GetParameter(2)); // cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<< mean << "," << rms<<endl; } } Double_t x, y, chtmp, x1, x2, y1, y2; /*TList *grCellCalibList = OpenCalibFile("CalibrationData1000events.root"); TGraphErrors *grCellCalib; TGraphErrors *grDataSubCalib = new TGraphErrors(DOMINO_NCELL); grDataSubCalib->SetTitle("Data after calibration correction"); grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel); for(ch = 0; ch < DOMINO_NCELL; ch++) { grCellCalib = ((TGraphErrors *) grCellCalibList->At(ch)); grCellCalib->Fit("pol3", "Q"); TF1 *pol3fit = ((TF1 *) grCellCalib->GetFunction("pol3")); grDataSub->GetPoint(ch, x, y); chtmp = y - (Double_t)(pol3fit->Eval(y/3.25)); grDataSubCalib->SetPoint(ch, x, chtmp); } TCanvas *cGrTest = new TCanvas("grTest", "test per vedere i dati", 1000,1000); grDataSubCalib->Draw("APEL");*/ TString Title = "Charge Distribution per channel"; gStyle->SetOptFit(111); TCanvas *cdistch = new TCanvas("cdistch", Title, 1000, 1000); cdistch->Divide(3, 3); for (int i = 0; i < DOMINO_NCH; i++) { cdistch->cd(i + 1); TH1 *dhist = (TH1 *) DistChList->At(i); dhist->DrawCopy(); dhist->SetLineWidth(1); dhist->Fit("gaus", "Q"); dhist->GetFunction("gaus")->SetLineColor(4); dhist->GetFunction("gaus")->SetLineWidth(2); } TString Title = "Charge Distribution Pedestals Subtracted per channel"; TCanvas *cdistchsub = new TCanvas("cdistchsub", Title, 1000, 1000); cdistchsub->Divide(3, 3); for (int i = 0; i < DOMINO_NCH; i++) { cdistchsub->cd(i + 1); TH1 *dsubhist = (TH1 *) DistChSubList->At(i); dsubhist->DrawCopy(); dsubhist->SetLineWidth(1); dsubhist->Fit("gaus", "Q"); dsubhist->GetFunction("gaus")->SetLineColor(4); dsubhist->GetFunction("gaus")->SetLineWidth(2); } TString Title = "Charge Distribution Pedestals and Ch0 Subtracted per channel"; TCanvas *cdistch0sub = new TCanvas("cdistch0sub", Title, 1000, 1000); cdistch0sub->Divide(3, 3); for (int i = 0; i < DOMINO_NCH; i++) { cdistch0sub->cd(i + 1); TH1 *dch0subhist = (TH1 *) DistCh0SubList->At(i); dch0subhist->DrawCopy(); dch0subhist->SetLineWidth(1); dch0subhist->Fit("gaus", "Q"); dch0subhist->GetFunction("gaus")->SetLineColor(4); dch0subhist->GetFunction("gaus")->SetLineWidth(2); } TCanvas *cDataSubTest = new TCanvas("cDataSubTest", "Data after pedestal subtraction", 1000, 1000); cDataSubTest->Divide(1,8); for (h = 0; h< DOMINO_NCH; h++) { grDataSub = (TGraphErrors *) grDataSubList->At(h); cDataSubTest->cd(h+1); grDataSub->GetYaxis()->SetLabelSize(0.06); grDataSub->GetXaxis()->SetLabelSize(0.06); grDataSub->Draw("APE"); } TCanvas *cDataSubTestCh5 = new TCanvas("cDataSubTestCh5", "Data after pedestal subtraction Ch5", 1200, 800); grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel); grDataSub->GetYaxis()->SetLabelSize(0.06); grDataSub->GetYaxis()->SetTitle("ADC Counts"); grDataSub->GetXaxis()->SetTitle("Cell"); grDataSub->GetXaxis()->SetLabelSize(0.06); TLine *refval = new TLine(0,350,1024,350); refval->SetLineWidth(3); refval->SetLineStyle(2); refval->SetLineColor(2); TLine *i1 = new TLine(121,-50,121,800); i1->SetLineStyle(2); TLine *i2 = new TLine(291,-50,291,800); i2->SetLineStyle(2); TLine *i3 = new TLine(461,-50,461,800); i3->SetLineStyle(2); TLine *i4 = new TLine(632,-50,632,800); i4->SetLineStyle(2); TLine *i5 = new TLine(803,-50,803,800); i5->SetLineStyle(2); TLine *i6 = new TLine(975,-50,975,800); i6->SetLineStyle(2); TLine *ireal1 = new TLine(121+20,600,121+20,800); ireal1->SetLineWidth(3); ireal1->SetLineColor(4); TLine *ireal2 = new TLine(291-20,600,291-20,800); ireal2->SetLineWidth(3); ireal2->SetLineColor(4); TLine *ireal3 = new TLine(461+20,600,461+20,800); ireal3->SetLineWidth(3); ireal3->SetLineColor(4); TLine *ireal4 = new TLine(632-20,600,632-20,800); ireal4->SetLineWidth(3); ireal4->SetLineColor(4); TLine *ireal5 = new TLine(803+20,600,803+20,800); ireal5->SetLineWidth(3); ireal5->SetLineColor(4); TLine *ireal6 = new TLine(975-20,600,975-20,800); ireal6->SetLineWidth(3); ireal6->SetLineColor(4); grDataSub->Draw("APE"); refval->Draw("SAME"); i1->Draw("SAME"); i2->Draw("SAME"); i3->Draw("SAME"); i4->Draw("SAME"); i5->Draw("SAME"); i6->Draw("SAME"); ireal1->Draw("SAME"); ireal2->Draw("SAME"); ireal3->Draw("SAME"); ireal4->Draw("SAME"); ireal5->Draw("SAME"); ireal6->Draw("SAME"); TCanvas *cDataTest = new TCanvas("cDataTest", "Raw Data", 1000,1000); cDataTest->Divide(1,8); for(h = 0; h < DOMINO_NCH; h++) { cDataTest->cd(h+1); grData = (TGraphErrors *) grDataList->At(h); grData->SetMarkerStyle(20); grData->SetMarkerSize(0.5); grData->Draw("APE"); } // save root file with graph containing channel 5 data after pedestals subtraction. /* cout << "test" << endl; TString OutFile = DataSubFile; TFile *f = new TFile(OutFile,"RECREATE"); int h = anaChannel; TString key="DataSubGraph"; key += h; ((TGraphErrors*)grDataSubList->At(h))->Write(key); f->Close(); cout << " ---- Write data on file " << endl; */ // =======================================================// // =====================Matteo's Code=====================// // =======================================================// /* Int_t cht, incCht, decCht, xflag, nPeriods, iMax, iMin; Double_t xdiff, incDiff, decDiff, incDiffTemp, decDiffTemp, incXDiff, decXDiff; Double_t fitMax, fitMin, fitPeriod, chisquare; Double_t DominoXval[DOMINO_NCELL]; Double_t DominoYval[DOMINO_NCELL]; Double_t FitXval[DOMINO_NCELL]; Double_t FitYval[DOMINO_NCELL]; // opens grDataSub.root TString FileName = DataSubFile; TGraphErrors *grDataSub; int h = anaChannel; TFile *f = new TFile(FileName); TString key = "DataSubGraph"; key += h; grDataSub = (TGraphErrors *) f->Get(key); f->Close(); // Create a new graph with channel 5 data TGraphErrors *grDataSubAnaCh; int h = anaChannel; grDataSubAnaCh = (TGraphErrors *) grDataSubList->At(h); TGraphErrors *grDataSubFix = grDataSubAnaCh->Clone(); TGraphErrors *grRes = new TGraphErrors(DOMINO_NCELL); TList *grResPeriodList = new TList(); Double_t xtemp, ytemp, DominoMax, DominoMin; for (int ch = 0; ch < DOMINO_NCELL; ch++){ // get domino-output point and save in array grDataSubAnaCh->GetPoint(ch, DominoXval[ch], DominoYval[ch]); } // find the domino point with max y-value iMax = 0; for(int ch = 0; ch < DOMINO_NCELL; ch++) { if(DominoYval[ch] > DominoYval[iMax]) { DominoMax = DominoYval[ch]; iMax = ch; } } cout << "DominoMax e': " << DominoMax << endl; // find the domino point with min y-value iMin = 0; for (int ch = 0; ch < DOMINO_NCELL; ch++) { if(DominoYval[ch] < DominoYval[iMin]) { DominoMin = DominoYval[ch]; iMin = ch; } } cout << "DominoMin e': " << DominoMin << endl; // remove points from the graph that will be used for fit for (int ch = 0; ch < DOMINO_NCELL; ch++){ grDataSubFix->GetPoint(ch, xtemp, ytemp); if(ytemp > 0.8*DominoMax || ytemp < 0.2*DominoMin) grDataSubFix->RemovePoint(ch); } TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4); fsin->SetParameters(600., DOMINO_NCELL / 4., 150., 150.); fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset"); grDataSubFix->Fit("fsin"); TF1 *fsinFit = grDataSubFix->GetFunction("fsin"); fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset"); chisquare = grDataSub->Chisquare(fsinFit); cout << "il chi quadro della funzione di fit e' : " << chisquare << endl; for (int ch = 0; ch < DOMINO_NCELL; ch++) { // get Fit-value and save in array FitXval[ch] = DominoXval[ch]; FitYval[ch] = fsinFit->Eval(FitXval[ch]); } fitPeriod = fsinFit->GetParameter("Period"); cout << "il periodo della funzione e': " << fitPeriod << endl; nPeriods = (Int_t) (DOMINO_NCELL/fitPeriod); cout << "il numero di periodi della funzione e': " << nPeriods << endl; fitMax = fsinFit->GetMaximum(); cout << "il massimo della funzione e': " << fitMax << endl; fitMin = fsinFit->GetMinimum(); cout << "il minimo della funzione e': " << fitMin << endl; // computes the y difference between the ch-domino point and the i-fit point // and stops when the difference changes sign // // first and last points are not included in the cicle // // if the fit point y-value is bigger or smaller than the fit function max*0.8 or min*0.2 // the point is removed for (int ch = 1; ch < DOMINO_NCELL - 1; ch++) { if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) { grRes->RemovePoint(ch); continue; } incDiff = DominoYval[ch] - FitYval[ch]; incDiffTemp = DominoYval[ch] - FitYval[ch + 1]; decDiff = DominoYval[ch] - FitYval[ch]; decDiffTemp = DominoYval[ch] - FitYval[ch - 1]; if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) { for (int i = ch; i < DOMINO_NCELL; i++, incDiff = incDiffTemp) { incDiffTemp = DominoYval[ch] - FitYval[i]; if (sign(incDiff) != sign(incDiffTemp)) { if(abs(incDiffTemp) < abs(incDiff)) incCht = i; else incCht = i - 1; break; } } xflag = 1; } else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) { for (int j = ch; j >= 0 ; j--, decDiff = decDiffTemp) { decDiffTemp = DominoYval[ch] - FitYval[j]; if (sign(decDiff) != sign(decDiffTemp)) { if(abs(decDiffTemp) < abs(decDiff)) decCht = j; else decCht = j + 1; break; } } xflag = -1; } if(xflag == 1) xdiff = FitXval[incCht] - DominoXval[ch]; else xdiff = FitXval[decCht] - DominoXval[ch]; grRes->SetPoint(ch, (Double_t) ch, xdiff); } cout << "Draw Time Residuals" << endl; TString Title = "Time Residuals"; TCanvas *timeres = new TCanvas("timeres", Title, 1200, 780); grRes->SetMarkerStyle(20); grRes->SetMarkerSize(0.3); grRes->GetYaxis()->SetLabelSize(0.12); grRes->GetXaxis()->SetLabelSize(0.12); grRes->Draw("APE"); // The previous graph is now split in N graphs, where N is the number of fit periods // this will be needed to set the function phase // // iMax = 0; // // for(ch = 0; ch < fitPeriod - 1; ch++) { // if(FitYval[ch] > FitYval[iMax]) iMax = ch; // } cout << "il primo massimo ha l'indice : " << iMax << endl; for (i = 0; i < nPeriods; i++) { TGraphErrors *grResPeriod = new TGraphErrors((Int_t) fitPeriod); grResPeriodList->Add(grResPeriod); for(ch = i*fitPeriod + 1; ch < fitPeriod + (i*fitPeriod); ch++) { if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) { grResPeriod->RemovePoint(ch); continue; } incDiff = DominoYval[ch] - FitYval[ch]; incDiffTemp = DominoYval[ch] - FitYval[ch + 1]; decDiff = DominoYval[ch] - FitYval[ch]; decDiffTemp = DominoYval[ch] - FitYval[ch - 1]; if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) { for (int k = ch; k < k*fitPeriod + fitPeriod; k++, incDiff = incDiffTemp) { incDiffTemp = DominoYval[ch] - FitYval[k]; if (sign(incDiff) != sign(incDiffTemp)) { if(abs(incDiffTemp) < abs(incDiff)) incCht = k; else incCht = k - 1; break; } } xflag = 1; } else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) { for (int j = ch; j > i*fitPeriod; j--, decDiff = decDiffTemp) { decDiffTemp = DominoYval[ch] - FitYval[j]; if (sign(decDiff) != sign(decDiffTemp)) { if(abs(decDiffTemp) < abs(decDiff)) decCht = j; else decCht = j + 1; break; } } xflag = -1; } if(xflag == 1) xdiff = FitXval[incCht] - DominoXval[ch]; else xdiff = FitXval[decCht] - DominoXval[ch]; grResPeriod->SetPoint(ch - i*fitPeriod, (Double_t) (ch - i*fitPeriod), xdiff); } } TCanvas *timeresperiod = new TCanvas("timeresperiod", "Time Residuals Period", 1200, 780); for(i = 0; i < nPeriods; i++) { grResPeriod = ((TGraphErrors *) grResPeriodList->At(i)); grResPeriod->SetMarkerStyle(20); grResPeriod->SetMarkerSize(0.3); grResPeriod->GetYaxis()->SetLabelSize(0.12); grResPeriod->GetXaxis()->SetLabelSize(0.12); grResPeriod->Draw("APEsame"); } cout << "Draw Data - Pedestals Subtracted" << endl; TString Title = "Average Charge - Pedestal subtracted"; TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780); grDataSubAnaCh->SetMarkerStyle(20); grDataSubAnaCh->SetMarkerSize(0.3); grDataSubAnaCh->GetYaxis()->SetLabelSize(0.12); grDataSubAnaCh->GetXaxis()->SetLabelSize(0.12); grDataSubAnaCh->Draw("APE"); fsinFit->Draw("same"); */ // draw extra graphs if (DrawExtraGraphs == 1) { cout << " ----- DRAW Results ------" << endl; //================ DRAW Results ================== TCanvas *c = new TCanvas("ctmp", "test", 800, 800); c->Divide(3, 3); for (int pad = 1; pad < 10; pad++) { c->cd(pad); ((TH1 *) hCellList->At(pad * 512 + 219))->DrawCopy(); hCellSub = (TH1F *) hCellSubList->At(pad * 512 + 219); hCellSub->SetLineColor(2); hCellSub->DrawCopy("same"); } cout << "Draw RMS distributions" << endl; TString Title = "RMS distributions per channel"; TCanvas *c4 = new TCanvas("c4", Title, 700, 700); c4->Divide(3, 3); for (int i = 0; i < DOMINO_NCH; i++) { c4->cd(i + 2); hRMSdist = (TH1F *) hRMSList->At(i); hRMSFitdist = (TH1F *) hRMSFitList->At(i); hRMSFitdist->SetLineColor(2); hRMSFitdist->DrawCopy(); hRMSdist->DrawCopy("same"); } TList *grDataCh0SubList = new TList(); TGraphErrors *grDataCh0Sub; for(h = 0; h< DOMINO_NCELL; h++) { grDataCh0Sub = new TGraphErrors(DOMINO_NCELL); grDataCh0SubList->Add(grDataCh0Sub); } TGraphErrors *grDataSubCh0 = (TGraphErrors *) grDataSubList->At(6); for(h = 0; h < DOMINO_NCH; h++) { grDataSub = (TGraphErrors *) grDataSubList->At(h); grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h); for(ch = 0; ch < DOMINO_NCELL; ch++) { grDataSubCh0->GetPoint(ch, x1, y1); grDataSub->GetPoint(ch, x2, y2); grDataCh0Sub->SetPoint(ch, x1 , y2 - y1); } } TCanvas *cDataCH0Sub = new TCanvas("cDataCH0Sub","cDataCH0Sub", 1000,1000); cDataCH0Sub->Divide(1,8); for(h = 0; h < DOMINO_NCH; h++) { cDataCH0Sub->cd(h+1); grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h); grDataCh0Sub->GetYaxis()->SetLabelSize(0.12); grDataCh0Sub->GetXaxis()->SetLabelSize(0.12); grDataCh0Sub->Draw("APEL"); } cout << "Draw Data - Pedestals Subtracted" << endl; TString Title = "Average Charge - Pedestal subtracted"; TCanvas *csubdata = new TCanvas("csubdata", Title, 1000, 1000); csubdata->Divide(3,3); for(h = 0; h < DOMINO_NCH; h++) { csubdata->cd(h+1); TString title = "DataSub channel "; title += h; TH1F *hCellDataSub = new TH1F(title, title, 100, -20, 20); grDataSub = (TGraphErrors *) grDataSubList->At(h); for(ch = 0; ch < DOMINO_NCELL; ch++) { grDataSub->GetPoint(ch, x, y); hCellDataSub->Fill(y); } hCellDataSub->Fit("gaus", "Q"); hCellDataSub->GetXaxis()->SetTitle("ADC Counts"); hCellDataSub->GetFunction("gaus")->SetLineColor(4); hCellDataSub->DrawCopy(); } cout << "breakpoint" << endl; TCanvas *csubdata2 = new TCanvas("csubdata2", "DataSub for every channel", 1000, 1000); TString title = "DataSub every channel "; TH1F *hCellChDataSubTot = new TH1F(title, title, 100, -20, 20); for(h = 0; h < DOMINO_NCH; h++) { grDataSub = (TGraphErrors *) grDataSubList->At(h); for(ch = 0; ch < DOMINO_NCELL; ch++) { grDataSub->GetPoint(ch, x, y); hCellChDataSubTot->Fill(y); } hCellChDataSubTot->Fit("gaus", "Q"); hCellChDataSubTot->GetXaxis()->SetTitle("ADC Counts"); hCellChDataSubTot->GetFunction("gaus")->SetLineColor(4); hCellChDataSubTot->Draw(); } cout << "Draw Pedestals" << endl; TString Title = "Pedestals"; TCanvas *c2 = new TCanvas("c2", Title, 1050, 780); c2->SetBorderMode(0); c2->SetBorderSize(0.); c2->Divide(1, 8); // gStyle->SetCanvasBorderMode(0.); // gStyle->SetCanvasBorderSize(0.); Double_t x, y; for (int h = 0; h < DOMINO_NCH; h++) { c2->cd(h + 1); grPed = ((TGraphErrors *) grPedList->At(h)); grPed->SetMarkerStyle(20); grPed->SetMarkerSize(0.5); grPed->GetYaxis()->SetLabelSize(0.12); grPed->GetXaxis()->SetLabelSize(0.12); // cout << " err:" << grPed->GetErrorY(102) << " " ; // cout << x << "--" << y << endl; grPed->Draw("APE"); } cout << "Draw Data - Average charge" << endl; TString Title = "Average_Charge"; TCanvas *cdata = new TCanvas("cdata", Title, 1050, 780); cdata->Divide(1, 8); Double_t x, y; for (int h = 0; h < DOMINO_NCH; h++) { cdata->cd(h + 1); grData = ((TGraphErrors *) grDataList->At(h)); grData->SetMarkerStyle(20); grData->SetMarkerSize(0.3); grData->GetYaxis()->SetLabelSize(0.12); grData->GetXaxis()->SetLabelSize(0.12); grData->GetPoint(10, x, y); // cout << x << "-" << y << endl; grData->Draw("APE"); } cout << "Draw Data - Pedestals Subtracted" << endl; TString Title = "Average Charge - Pedestal subtracted"; TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780); csubdata->Divide(1, 8); TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4); TH1D *resDist = new TH1D("resDist", "Residuals Signal", 100, -100., 100.); cout << "Draw Data - Pedestals Subtracted" << endl; TString Title = "Residuals"; TCanvas *residuals = new TCanvas("residuals", Title, 1200, 780); resDist->DrawCopy(); } fclose(fdata); hCellList->Delete(); hCellSubList->Delete(); hRMSList->Delete(); hRMSFitList->Delete(); }