void JEC_fit_Uncertainty(int N) { TF1 *func[1000]; TFile *inf = new TFile("L3Graphs_test_Icone5.root"); TGraphErrors *g = (TGraphErrors*)inf->Get("Correction_vs_CaloPt"); TGraphErrors *vg[1000]; int i,k; double x[20],y[20],ex[20],ey[20]; double vx[20],vy[20],vex[20],vey[20]; for(i=0;i<g->GetN();i++) { g->GetPoint(i,x[i],y[i]); ex[i]=g->GetErrorX(i); ey[i]=g->GetErrorY(i); } TRandom *rnd = new TRandom(); rnd->SetSeed(0); for(k=0;k<N;k++) { for(i=0;i<g->GetN();i++) { vx[i] = rnd->Gaus(x[i],ex[i]); //vx[i] = x[i]; vy[i] = rnd->Gaus(y[i],ey[i]); vex[i] = ex[i]; vey[i] = ey[i]; } vg[k] = new TGraphErrors(g->GetN(),vx,vy,vex,vey); func[k] = new TF1("func","[0]+[1]/(pow(log10(x),[2])+[3])",1,2000); func[k]->SetParameters(1,3,6,5); vg[k]->Fit(func[k],"RQ"); } TCanvas *c = new TCanvas("c","c"); gPad->SetLogx(); g->SetMarkerStyle(20); g->SetMaximum(3.5); g->Draw("AP"); for(k=0;k<N;k++) { func[k]->SetLineColor(5); func[k]->SetLineWidth(1); cout<<func[k]->GetChisquare()<<endl; vg[k]->SetMarkerColor(2); vg[k]->SetLineColor(2); vg[k]->SetMarkerStyle(21); //if (func[k]->GetChisquare()<0.1) //vg[k]->Draw("sameP"); func[k]->Draw("same"); } }
void drawTimeDifference (TDirectory* directory, TH1* refHisto, const char* fname=0) { TGraphErrors* graphX = (TGraphErrors*)directory->Get("x"); if ( graphX==0 ) return; TH1I* hFirst = (TH1I*)directory->Get("firstTime"); TH1I* hLast = (TH1I*)directory->Get("lastTime"); if ( hFirst==0 || hLast==0 ) return; std::string fullName("cDeltaT"); if ( fname ) fullName += fname; else fullName += directory->GetName(); TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str()); TH1* h = refHisto->Clone("DeltaT"); h->Reset(); h->SetTitle("DeltaT"); TGraph* graph = new TGraph(); graph->SetName("gDeltaT"); double xg,yg; for ( unsigned int i=1; i<=hFirst->GetNbinsX(); ++i ) { std::time_t t1 = hFirst->GetAt(i); std::time_t t2 = hLast->GetAt(i); TTimeStamp ts1(hFirst->GetAt(i)); std::cout << "Fit started at " << ts1.AsString() << std::endl; graphX->GetPoint(i-1,xg,yg); graph->SetPoint(i-1,xg,difftime(t2,t1)); } double xmin,xmax,ymin,ymax; graph->ComputeRange(xmin,ymin,xmax,ymax); h->SetMinimum(0.); h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.); h->Draw(); graph->SetMarkerStyle(20); // graph->SetMarkerColor(2); // graph->SetLineColor(2); graph->Draw("P"); }
void drawEventDifference (TDirectory* directory, TH1* refHisto, const char* fname=0) { TGraphErrors* graphX = (TGraphErrors*)directory->Get("x"); if ( graphX==0 ) return; TH1I* hFirst = (TH1I*)directory->Get("firstEvent"); TH1I* hLast = (TH1I*)directory->Get("lastEvent"); if ( hFirst==0 || hLast==0 ) return; std::string fullName("cDeltaE"); if ( fname ) fullName += fname; else fullName += directory->GetName(); TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str()); TH1* h = refHisto->Clone("DeltaE"); h->Reset(); h->SetTitle("DeltaE"); TGraph* graph = new TGraph(); graph->SetName("gDeltaE"); double xg,yg; for ( unsigned int i=1; i<=hFirst->GetNbinsX(); ++i ) { int e1 = hFirst->GetAt(i); int e2 = hLast->GetAt(i); graphX->GetPoint(i-1,xg,yg); graph->SetPoint(i-1,xg,e2-e1); } double xmin,xmax,ymin,ymax; graph->ComputeRange(xmin,ymin,xmax,ymax); h->SetMinimum(0.); h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.); h->Draw(); graph->SetMarkerStyle(20); // graph->SetMarkerColor(2); // graph->SetLineColor(2); graph->Draw("P"); }
void profileDistributions(TString dist) { gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetPalette(1); TFile *inF=TFile::Open("~/work/top_539/plotter.root"); TFile *inSystF=TFile::Open("~/work/top_539/plotter_syst.root"); bool isPhi(dist.Contains("phi")); TString profs[]={dist, dist+"toward", dist+"transverse", dist+"away"}; const size_t nprofs= isPhi ? 1 : sizeof(profs)/sizeof(TString); Int_t colors[]={1,kBlue,kRed,kGreen-3}; TString cats[]={"inclusive","away","transverse","toward"}; /* TFile *inNomF=inF; TString nomTTbar="t#bar{t}"; TString nomTTbarTitle="MG+PY"; //TString systList[]={"t#bar{t}systmcatnlo"}; //TString systLabels[]={"MC@NLO+HW"}; //TString systList[]={"t#bar{t}systq2down","t#bar{t}systq2up"}; //TString systLabels[]={"-Q^{2}","+Q^{2}"}; //TString systList[]={"t#bar{t}systmepsdown","t#bar{t}systmepsup"}; // TString systLabels[]={"-ME-PS","+ME-PS"}; */ TFile *inNomF=inSystF; TString nomTTbar="t#bar{t}systtunep11"; TString nomTTbarTitle="P11"; TString systList[]={"t#bar{t}systtunep11nocr","t#bar{t}systtunep11tev"}; TString systLabels[]={"P11-noCR","P11TeV"}; Int_t systColors[]={1,kAzure,kRed-6,kGreen+3}; const size_t nSysts=sizeof(systList)/sizeof(TString); TString ch[]={"emu"}; const size_t nch=sizeof(ch)/sizeof(TString); for(size_t ich=0; ich<nch; ich++) { TCanvas *c=new TCanvas("c"+ch[ich]+dist,"c"+ch[ich]+dist,800,800); c->SetTopMargin(0); c->SetBottomMargin(0); c->Divide(1,nprofs); TCanvas *cratios=new TCanvas("cratios"+ch[ich]+dist,"cratios"+ch[ich]+dist,800,800); cratios->SetTopMargin(0); cratios->SetBottomMargin(0); cratios->Divide(1,nprofs); TCanvas *cproj=new TCanvas("cproj"+ch[ich]+dist,"cproj"+ch[ich]+dist,600,600); TLegend *dataprojLeg=new TLegend(0.5,0.9,0.6,0.7,"Data","brNDC"); TLegend *mcprojLeg=new TLegend(0.7,0.9,0.92,0.7,"MC","brNDC"); for(size_t i=0; i<nprofs; i++) { TH2 *bckgMC = (TH2 *) inF->Get("Z#rightarrow ll/"+ch[ich]+"_"+profs[i]); bckgMC->Add( (TH2 *) inF->Get("VV/"+ch[ich]+"_"+profs[i]) ); bckgMC->Add( (TH2 *) inF->Get("Single top/"+ch[ich]+"_"+profs[i]) ); bckgMC->Add( (TH2 *) inF->Get("W+jets-multijets/"+ch[ich]+"_"+profs[i]) ); //build the total MC with signal alternatives TH2 *MC = (TH2 *) inNomF->Get(nomTTbar+"/"+ch[ich]+"_"+profs[i]) ; Double_t totalTTbar(MC->Integral()); MC->Add(bckgMC); MC->SetDirectory(0); MC->Sumw2(); std::vector<TH2 *> systMC; for(size_t isyst=0; isyst<nSysts; isyst++) { TH2F *h=(TH2F *)inSystF->Get(systList[isyst]+"/"+ch[ich]+"_"+profs[i]) ; h->Scale(totalTTbar/h->Integral()); h->Add(bckgMC); h->Sumw2(); h->SetDirectory(0); systMC.push_back(h); } //get the data TH2 *Data = (TH2 *) inF->Get("data/"+ch[ich]+"_"+profs[i]); Data->SetDirectory(0); Data->Sumw2(); TGraphErrors *MCProf = new TGraphErrors(MC->ProfileX()); MCProf->SetMarkerStyle(24); MCProf->SetFillStyle(0); MCProf->SetName(ch[ich]+profs[i]+"mc"); TGraphErrors *DataProf = new TGraphErrors(Data->ProfileX()); DataProf->SetMarkerStyle(20); DataProf->SetFillStyle(0); DataProf->SetName(ch[ich]+profs[i]+"data"); //build data/MC scale factors std::vector<TGraphErrors *> data2mcProfs; for(size_t isyst=0; isyst<=systMC.size(); isyst++) { TGraphErrors *prof= (isyst==0 ? MCProf : new TGraphErrors(systMC[isyst-1]->ProfileX())); TString baseName(ch[ich]+profs[i]); if(isyst) baseName += systList[isyst]; prof = (TGraphErrors *) prof->Clone(baseName+"data2mc"); for(int ip=0; ip<DataProf->GetN(); ip++) { Double_t x,y,ydata,y_err,ydata_err; prof->GetPoint(ip,x,y); y_err=prof->GetErrorY(ip); DataProf->GetPoint(ip,x,ydata); ydata_err=DataProf->GetErrorY(ip); if(y<=0) continue; prof->SetPoint(ip,x,ydata/y); prof->SetPointError(ip,0,sqrt(pow(ydata*y_err,2)+pow(ydata_err*y,2))/pow(y,2)); } prof->SetFillColor(systColors[isyst]); prof->SetFillStyle(3001+isyst%2); prof->SetTitle( isyst==0 ? nomTTbarTitle : systLabels[isyst-1] ); //prof->SetMarkerStyle(24); prof->SetFillStyle(3001); prof->SetMarkerColor(1+isyst); prof->SetMarkerColor(1+isyst); prof->SetLineColor(1+isyst); data2mcProfs.push_back(prof); } TH1D *MCProjY=MC->ProjectionY(); MCProjY->Scale(1./MCProjY->Integral()); TGraphErrors *MCProj = new TGraphErrors(MCProjY); MCProj->SetMarkerStyle(24); MCProj->SetFillStyle(0); MCProj->SetName(ch[ich]+profs[i]+"projmc"); TH1D *DataProjY=Data->ProjectionY(); DataProjY->Scale(1./DataProjY->Integral()); TGraphErrors *DataProj = new TGraphErrors(DataProjY); DataProj->SetMarkerStyle(20); DataProj->SetFillStyle(0); DataProj->SetName(ch[ich]+profs[i]+"projdata"); MCProj->SetLineColor(colors[i]); MCProj->SetMarkerColor(colors[i]); MCProj->SetFillColor(colors[i]); MCProj->SetFillStyle(1001); DataProj->SetLineColor(colors[i]); DataProj->SetMarkerColor(colors[i]); DataProj->SetFillColor(colors[i]); TPad *p=(TPad *)cproj->cd(); p->SetLeftMargin(0.15); p->SetRightMargin(0.02); p->SetTopMargin(0.05); p->SetLogy(); MCProj->SetFillStyle(0); MCProj->Draw(i==0 ? "al3" : "l3"); MCProj->GetYaxis()->SetRangeUser(1e-5,1.0); MCProj->GetXaxis()->SetTitle( MC->GetYaxis()->GetTitle() ); MCProj->GetYaxis()->SetTitle( "1/N dN/dx" ); MCProj->GetYaxis()->SetTitleOffset(1.8); DataProj->Draw("p"); std::pair<float,int> chi2=computeChiSquareFor(DataProj,MCProj); char buf[200]; sprintf(buf,"#scale[0.7]{#chi^{2}/ndof=%3.1f}", chi2.first/chi2.second ); dataprojLeg->AddEntry(DataProj,buf,"p"); mcprojLeg->AddEntry(MCProj,cats[i],"l"); if(i==0) drawCMSHeader(ch[ich]); p=(TPad *)c->cd(i+1); if(i<nprofs-1) p->SetBottomMargin(0.01); if(i>0) p->SetTopMargin(0); if(i==0)p->SetTopMargin(0.1); if(i==nprofs-1) p->SetBottomMargin(0.15); TGraphErrors *frame=DataProf; frame->Draw("ap"); //frame->GetYaxis()->SetRangeUser(0.54,1.46); frame->GetXaxis()->SetTitle(MC->GetXaxis()->GetTitle()); //frame->GetXaxis()->SetRangeUser(0,4.75); TString yTit("<"); yTit+=MC->GetYaxis()->GetTitle(); yTit +=">"; frame->GetYaxis()->SetTitle(yTit); frame->GetYaxis()->SetLabelSize(0.07); frame->GetYaxis()->SetTitleSize(0.09); frame->GetYaxis()->SetTitleOffset(0.5); frame->GetXaxis()->SetLabelSize(0.07); frame->GetXaxis()->SetTitleSize(0.09); frame->GetXaxis()->SetTitleOffset(0.7); //p->SetGridy(); //DataProf->Draw("p"); MCProf->Draw("p"); if(i==0) { drawCMSHeader(ch[ich],0.08); TLegend *leg=new TLegend(0.6,0.95,1.0,0.99); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetTextFont(42); leg->SetTextSize(0.09); leg->AddEntry(DataProf,"data","p"); leg->AddEntry(MCProf,"simulation","p"); leg->SetNColumns(2); leg->Draw(); } TPaveText *pt=new TPaveText(0.15,0.5,0.8,0.85,"brNDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(13); pt->SetTextFont(42); pt->SetTextColor(kBlue); pt->SetTextSize(0.08); pt->AddText("[ "+cats[i]+" ]"); if(i==0) { pt->AddText("p_{T}>0.5 GeV"); pt->AddText("|#eta|<2.1"); } pt->Draw(); p=(TPad *) cratios->cd(i+1); if(i<nprofs-1) p->SetBottomMargin(0.01); if(i>0) p->SetTopMargin(0); if(i==0)p->SetTopMargin(0.1); if(i==nprofs-1) p->SetBottomMargin(0.15); frame=data2mcProfs[0]; frame->Draw("a3"); TLine *l=new TLine(frame->GetXaxis()->GetXmin(),1,frame->GetXaxis()->GetXmax(),1); l->Draw(); frame->GetYaxis()->SetRangeUser(0.54,1.46); frame->GetXaxis()->SetTitle(MC->GetXaxis()->GetTitle()); frame->GetYaxis()->SetTitle("Data/Simulation"); frame->GetYaxis()->SetLabelSize(0.07); frame->GetYaxis()->SetTitleSize(0.09); frame->GetYaxis()->SetTitleOffset(0.5); frame->GetXaxis()->SetLabelSize(0.07); frame->GetXaxis()->SetTitleSize(0.09); frame->GetXaxis()->SetTitleOffset(0.7); //p->SetGridy(); for(size_t ip=1; ip<data2mcProfs.size(); ip++) data2mcProfs[ip]->Draw("3"); if(i==0) { drawCMSHeader(ch[ich],0.08); TLegend *leg=new TLegend(0.6,0.94,1.0,0.98); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetTextFont(42); leg->SetTextSize(0.09); leg->SetNColumns(data2mcProfs.size()); for(size_t ip=0; ip<data2mcProfs.size(); ip++) leg->AddEntry(data2mcProfs[ip],data2mcProfs[ip]->GetTitle(),"f"); leg->Draw(); } pt=new TPaveText(0.12,0.65,0.8,0.9,"brNDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(13); pt->SetTextFont(42); pt->SetTextColor(kBlue); pt->SetTextSize(0.08); pt->AddText("[ "+cats[i]+" ]"); if(i==0) { pt->AddText("p_{T}>0.5 GeV"); pt->AddText("|#eta|<2.1"); } pt->Draw(); } cproj->cd(); dataprojLeg->SetFillStyle(0); dataprojLeg->SetBorderSize(0); dataprojLeg->SetTextFont(42); dataprojLeg->SetTextSize(0.03); dataprojLeg->Draw(); mcprojLeg->SetFillStyle(0); mcprojLeg->SetBorderSize(0); mcprojLeg->SetTextFont(42); mcprojLeg->SetTextSize(0.03); mcprojLeg->Draw(); TString pf(".png"); c->SaveAs(outDir+c->GetName()+pf); cproj->SaveAs(outDir+cproj->GetName()+pf); cratios->SaveAs(outDir+cratios->GetName()+pf); } inF->Close(); inSystF->Close(); }
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(); }
int plotResoVsIC(){ SetTdrStyle(); const unsigned nIC = 10; const unsigned ICval[nIC] = {0,1,2,3,4,5,10,15,20,50}; std::ostringstream label; TFile *fcalib[nIC]; TGraphErrors *constant = new TGraphErrors(); constant->SetName("constant"); constant->SetTitle(";intercalib. smearing"); constant->SetMarkerStyle(20); constant->SetMarkerColor(1); constant->SetLineColor(1); TGraphErrors *constantSR7 = new TGraphErrors(); constantSR7->SetName("constantSR7"); constantSR7->SetTitle(";intercalib. smearing"); constantSR7->SetMarkerStyle(23); constantSR7->SetMarkerColor(2); constantSR7->SetLineColor(2); TGraphErrors *noise = (TGraphErrors *) constant->Clone("noise"); TGraphErrors *sampling = (TGraphErrors *) constant->Clone("sampling"); TGraphErrors *samplingSR7 = (TGraphErrors *) constantSR7->Clone("samplingSR7"); TCanvas *mycReso = new TCanvas("mycReso","mycReso",1500,1000); mycReso->Divide(2,5); TCanvas *mycR = new TCanvas("mycR","Sampling",1500,1000); TCanvas *mycC = new TCanvas("mycC","Constant",1500,1000); TCanvas *mycN = new TCanvas("mycN","Noise",1500,1000); gStyle->SetOptFit(1111); gStyle->SetOptStat(0); gStyle->SetStatW(0.2); gStyle->SetStatH(0.5); TLatex lat; char buf[500]; TGraphErrors *gr[nIC][2]; double x0,y0; double x0_7,y0_7; for (unsigned ic(0);ic<nIC;++ic){//loop on intercalib label.str(""); label << "PLOTS/CalibReso"; label << "_vsE"; label << "_IC" << ICval[ic]; label << ".root"; fcalib[ic] = TFile::Open(label.str().c_str()); if (!fcalib[ic]) { std::cout << " -- failed to open file: " << label.str() << std::endl; continue; } else { std::cout << " -- file " << label.str() << " successfully opened." << std::endl; } fcalib[ic]->cd("SR2"); gr[ic][0] = (TGraphErrors *)gDirectory->Get("resoRecoFit2eta21pu1"); fcalib[ic]->cd("SR7"); gr[ic][1] = (TGraphErrors *)gDirectory->Get("resoRecoFit7eta21pu1"); TF1 *fit = gr[ic][0]->GetFunction("reso"); TF1 *fit7 = gr[ic][1]->GetFunction("reso"); mycReso->cd(ic+1); gr[ic][0]->Draw("APE"); fit->SetLineColor(6); fit->Draw("same"); lat.SetTextSize(0.1); sprintf(buf,"Single #gamma, #eta=2.1, 3#times3 cm^{2}"); lat.DrawLatexNDC(0.2,0.8,buf); sprintf(buf,"ICsmear = %d %%",ICval[ic]); lat.DrawLatexNDC(0.2,0.7,buf); double cval = sqrt(pow(fit->GetParameter(1),2)-pow(y0,2)); constant->SetPoint(ic,ICval[ic]/100.,cval); constant->SetPointError(ic,0,fit->GetParameter(1)*fit->GetParError(1)/cval); noise->SetPoint(ic,ICval[ic]/100.,fit->GetParameter(2)); noise->SetPointError(ic,0,fit->GetParError(2)); sampling->SetPoint(ic,ICval[ic]/100.,fit->GetParameter(0)); sampling->SetPointError(ic,0,fit->GetParError(0)); cval = sqrt(pow(fit7->GetParameter(1),2)-pow(y0_7,2)); constantSR7->SetPoint(ic,ICval[ic]/100.,cval); constantSR7->SetPointError(ic,0,fit7->GetParameter(1)*fit7->GetParError(1)/cval); //constantSR7->SetPoint(ic,ICval[ic]/100.,fit7->GetParameter(1)); //constantSR7->SetPointError(ic,0,fit7->GetParError(1)); samplingSR7->SetPoint(ic,ICval[ic]/100.,fit7->GetParameter(0)); samplingSR7->SetPointError(ic,0,fit7->GetParError(0)); if (ic==0) { constant->GetPoint(0,x0,y0); constantSR7->GetPoint(0,x0_7,y0_7); cval = sqrt(pow(fit->GetParameter(1),2)-pow(y0,2)); constant->SetPoint(ic,ICval[ic]/100.,cval); constant->SetPointError(ic,0,fit->GetParameter(1)*fit->GetParError(1)/cval); cval = sqrt(pow(fit7->GetParameter(1),2)-pow(y0_7,2)); constantSR7->SetPoint(ic,ICval[ic]/100.,cval); constantSR7->SetPointError(ic,0,fit7->GetParameter(1)*fit7->GetParError(1)/cval); } } mycReso->Update(); mycReso->Print("PLOTS/ResolutionFitvsIC.pdf"); TLegend *leg = new TLegend(0.6,0.6,0.8,0.8); leg->SetFillColor(10); leg->AddEntry(sampling,"3#times3 cm^{2}","P"); leg->AddEntry(samplingSR7,"All detector","P"); mycR->cd(); gPad->SetGridy(1); sampling->GetYaxis()->SetTitle("Sampling term (GeV^{1/2})"); sampling->SetMinimum(0.2); sampling->SetMaximum(0.3); sampling->Draw("APE"); samplingSR7->Draw("PEsame"); lat.SetTextSize(0.04); sprintf(buf,"Single #gamma, #eta=2.1"); lat.DrawLatexNDC(0.2,0.87,buf); lat.DrawLatexNDC(0.01,0.01,"HGCAL G4 standalone"); leg->Draw("same"); mycR->Update(); mycR->Print("PLOTS/SamplingvsIC.pdf"); mycC->cd(); gPad->SetLogx(1); gPad->SetGridy(1); gStyle->SetOptFit(0); //gStyle->SetStatH(0.1); //gStyle->SetStatW(0.2); constant->GetYaxis()->SetTitle("Constant from intercalib."); constant->SetMinimum(0); constant->SetMaximum(0.08); constant->Draw("APE"); //constantSR7->Draw("PEsame"); sprintf(buf,"Single #gamma, #eta=2.1"); lat.DrawLatexNDC(0.2,0.87,buf); lat.DrawLatexNDC(0.01,0.01,"HGCAL G4 standalone"); TF1 *BE = new TF1("BE","sqrt([0]*[0] + pow(x*1/sqrt([1]),2))",0,1); BE->SetParameters(0,30); // BE->SetParLimits(0,1,1); BE->FixParameter(0,0); BE->SetLineColor(1); constant->Fit("BE","BI"); lat.SetTextColor(1); //sprintf(buf,"c #propto c_{0} #oplus #frac{x}{#sqrt{n}}, n=%3.1f #pm %3.1f",BE->GetParameter(1),BE->GetParError(1)); sprintf(buf,"c_{ic}=#frac{x}{#sqrt{n}}, n=%3.1f #pm %3.1f",BE->GetParameter(1),BE->GetParError(1)); lat.DrawLatexNDC(0.2,0.77,"c=c_{0} #oplus c_{ic}"); lat.DrawLatexNDC(0.2,0.67,buf); //BE->SetParameter(0,y0_7); //constantSR7->Fit("BE","BI","same"); //BE->SetLineColor(2); //BE->Draw("same"); //lat.SetTextColor(2); //sprintf(buf,"c #propto c_{0} #oplus #frac{x}{#sqrt{n}}, n=%3.1f #pm %3.1f",BE->GetParameter(1),BE->GetParError(1)); //lat.DrawLatexNDC(0.2,0.6,buf); //lat.SetTextColor(1); //leg->Draw("same"); mycC->Update(); mycC->Print("PLOTS/ConstantvsIC.pdf"); mycN->cd(); noise->GetYaxis()->SetTitle("Noise term (GeV)"); noise->Draw("APE"); sprintf(buf,"Single #gamma, #eta=2.1, 3#times3 cm^{2}"); lat.DrawLatexNDC(0.2,0.87,buf); lat.DrawLatexNDC(0.01,0.01,"HGCAL G4 standalone"); mycN->Print("PLOTS/NoisevsIC.pdf"); return 0; }//main
double FitCurve(TGraphErrors* g, int debug=0) { double vdep=0; if(!g) return vdep; TF1* f3 = new TF1("fp1", "pol1", 20, 360); f3->SetLineColor(4); double y; double xlow=350; double ymax=0; double vdep1=0; // prendre le point le plus haut est robuste et marche bien pour les hauts vdep TGraphErrors *gsmooth = MedianFilter(g); gsmooth = MedianFilter(gsmooth); for(int ipt=0; ipt<gsmooth->GetN(); ipt++) { gsmooth->GetPoint(ipt, xlow, y); if(y>ymax) {ymax=y; vdep1=xlow;} } //g=gsmooth; int npt = g->GetN()-5; xlow=350; double chi2=0; int status = 0; while(chi2<5. && xlow>100 && npt>=0) { g->GetPoint(npt, xlow, y); f3->SetRange(xlow, 350); status = g->Fit("fp1", "rqn"); chi2 = f3->GetChisquare()/f3->GetNDF(); if(debug>=1) cout<<"xlow "<<xlow<<" chi2 "<<chi2<<endl; npt--; } g->GetPoint(npt+2, xlow, y); f3->SetRange(xlow, 350); g->Fit("fp1", "rqn"); vdep = xlow; //if(vdep>230) vdep = vdep1; //else if(fabs(vdep-vdep1)>40) vdep = vdep1; //vdep=vdep1; cout<<" Vdepl = "<<vdep<<endl; TF1* f1 = new TF1("fitsigmo", fitsigmo, 50, 350, 5); f1->SetParameter(0, 3.); f1->SetParameter(1, 0.02); f1->SetParameter(2, vdep); f1->SetParameter(3, -10.); f1->SetParameter(4, -0.00001); f1->SetParLimits(2, 100., 300.); f1->SetParLimits(4, -0.1, 0); TF1* f2 = new TF1("fitpol", fitpol, 20, 360, 6); f2->SetParLimits(4, 100., 300.); f2->SetParLimits(5, -0.1, 0); /* xlow = 30; chi2 = 100; double xmin = xlow; double chi2min = chi2; string opt="rq"; if(debug>=2) opt="r"; while(chi2>0.1 && xlow<vdep-80) { f2->SetParameter(0, 1.); f2->SetParameter(1, 0.005); f2->SetParameter(2, 0.0001); f2->SetParameter(3, 0.); f2->SetParameter(4, vdep); f2->SetParameter(5, -0.00001); f2->SetRange(xlow, 350); status = g->Fit("fitpol", opt.c_str()); if(status!=0) status = g->Fit("fitpol", opt.c_str()); chi2 = f2->GetChisquare()/f2->GetNDF(); if(debug>=1) cout<<"xlow "<<xlow<<" chi2 "<<chi2<<endl; if(debug>=2) cout<<" chi2 "<<f2->GetChisquare()<<" ndf "<<f2->GetNDF()<<endl; if(chi2<chi2min) {chi2min=chi2; xmin=xlow;} xlow+=10; } f2->SetParameter(0, 1.); f2->SetParameter(1, 0.005); f2->SetParameter(2, 0.0001); f2->SetParameter(3, 0.); f2->SetParameter(4, vdep); f2->SetParameter(5, -0.00001); f2->SetRange(xmin, 350); status = g->Fit("fitpol", opt.c_str()); if(status!=0) status = g->Fit("fitpol", opt.c_str()); vdep = f2->GetParameter(4); cout<<" Vdepl2 = "<<vdep<<" xmin "<<xmin<<endl; if(fabs(vdep-vdep1)>30) vdep = vdep1; */ TGraphErrors* gmedian; gmedian = MedianFilter( g ); int nfilt=1; /*while (!IsMonoton(gmedian) && nfilt<4) { gmedian = MedianFilter( gmedian ); nfilt++; }*/ gmedian = HanningFilter(gsmooth); cout<<nfilt<<" median filter applied"<<endl; TGraphErrors* gscurv = GetCurvatureGraph( gmedian ); gscurv->SetMarkerStyle(20); TGraph* g3pts = new TGraph(); float xopt = GetOptimalMinNPts(gscurv, g3pts); vdep = xopt; cout<<" Kink = "<<xopt<<endl; TCanvas *c1; TCanvas *c2; if(debug>=1) { c1 = new TCanvas(); g->Draw("AP"); f2->Draw("same"); f3->Draw("same"); //gsmooth->SetMarkerColor(17); //gsmooth->Draw("P"); //gmedian->SetMarkerColor(4); //gmedian->Draw("P"); TLine *l = new TLine(vdep,2, vdep, ymax+0.1); l->SetLineStyle(3); l->Draw(); c1->Modified(); c1->Update(); string detid = g->GetTitle(); detid.erase(0,6); //c1->Print(Form("ClusterWidthVsVbias_detid_%s_run203832.eps", detid.c_str())); c2 = new TCanvas; gscurv->Draw("AP"); g3pts->Draw("P"); g3pts->Fit("pol2", "q"); c2->Modified(); c2->Update(); //c2->Print(Form("ClusterWidthVsVbias_detid_%s_curv_run203832.eps", detid.c_str())); getchar(); c1->Close(); c2->Close(); } return vdep; }
void DrawKinvarPlot(TString filename="kinvarset/FMSOR_Pt_vs_run.root", TString classname="pi0") { TFile * infile = new TFile(filename.Data(),"READ"); char trig[32]; char typ[32]; char tmp[128]; TString tmpstr = filename; tmpstr.ReplaceAll("_"," "); TRegexp re("^.*\/"); tmpstr(re) = ""; cout << tmpstr << endl; sscanf(tmpstr.Data(),"%s %s",trig,typ); printf("%s %s\n",trig,typ); TString hname = "h2_"+classname; TH2D * h = (TH2D*)infile->Get(hname.Data()); TString gname = "g_"+classname; TGraphErrors * g = (TGraphErrors*)infile->Get(gname.Data()); TString gtname = "gt_"+classname; TGraphErrors * gt; if(!strcmp(typ,"Pt")) gt = (TGraphErrors*)infile->Get(gtname.Data()); char htitle[256]; char hnewtitle[512]; strcpy(htitle,h->GetTitle()); sprintf(hnewtitle,"%s -- %s triggers",htitle,trig); h->SetTitle(hnewtitle); h->SetMinimum(0.001); if(!strcmp(typ,"Pt")) { gt->SetLineWidth(2); gt->SetLineColor(kBlack); }; // temporary hack to cut out fluctuations of pt_thresh vs. run to 0 Double_t xx,yy; Int_t gtn = gt->GetN(); for(int ii=0; ii<gtn; ii++) { gt->GetPoint(ii,xx,yy); printf("xx=%f yy=%f\n",xx,yy); if(yy<0.001) gt->RemovePoint(ii); }; // drawing range Float_t xmin = h->GetXaxis()->GetXmin(); Float_t xmax = h->GetXaxis()->GetXmax(); xmax = 515; if(xmax<gtn) { fprintf(stderr,"\nWARNING: xmax < gt->GetN(); graphs will be cut off!\n\n"); }; TCanvas * c = new TCanvas("c","c",1500,700); c->Divide(1,2); gStyle->SetOptStat(0); for(int x=1; x<=2; x++) c->GetPad(x)->SetGrid(1,1); c->cd(1); c->GetPad(1)->SetLogz(); h->GetXaxis()->SetRangeUser(xmin,xmax); h->Draw("colz"); if(!strcmp(typ,"Pt")) gt->Draw("LX"); c->cd(2); g->SetFillColor(kGray); printf("%f %f\n",xmin,xmax); g->GetXaxis()->SetLimits(xmin,xmax); g->GetXaxis()->SetRangeUser(xmin,xmax); /* g->Draw("A3"); g->Draw("PLX"); */ g->Draw("APLX"); TString outname = filename.ReplaceAll(".root"," "+classname); outname = outname+".png"; c->Print(outname.Data(),"png"); };
void AnalyzeWaveforms(char *WaveformsFile = "Waveforms.root", const int nAddedChannels = 5) { //try to access waveforms file and in case of failure return if(gSystem->AccessPathName(WaveformsFile,kFileExists)) { cout << "Error: file " << WaveformsFile << " does not exsist. Run .x WaveformsFileMaker.C to create it" << endl; return; } // gStyle->SetOptFit(111); // gStyle->SetStatFormat("1.3E"); // gStyle->SetFitFormat("1.3E"); // fetch the list of trees contained in the waveforms file // for every tree generate a waveform graph TFile *f = TFile::Open(WaveformsFile); TList *listOfKeys = f->GetListOfKeys(); Int_t numberOfKeys = listOfKeys->GetEntries(); TList *listOfGraphs = new TList(); // if the waveform file name begins with the string "comparator" it goes in this list TList *listOfCompWaves = new TList(); // if the waveform file name begins with the string "sum output" it goes in this list TList *listOfAdderWaves = new TList(); for(Int_t i = 0; i < numberOfKeys; i++) { TString *keyName = new TString(listOfKeys->At(i)->GetName()); TTree *tree = (TTree*)f->Get(keyName->Data()); Float_t x = 0; Float_t y = 0; tree->SetBranchAddress("x",&x); tree->SetBranchAddress("y",&y); Int_t nentries = tree->GetEntries(); TString *gName = new TString(keyName->Data()); gName->Append(" graph"); TGraphErrors *gWave = new TGraphErrors(nentries); gWave->SetName(gName->Data()); gWave->SetTitle(gName->Data()); gWave->GetXaxis()->SetTitle("Time"); gWave->GetYaxis()->SetTitle("Voltage"); // gWave->SetBit(TH1::kCanRebin); for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); gWave->SetPoint(j,x,y); } listOfGraphs->Add(gWave); if(keyName->BeginsWith("comparator")) listOfCompWaves->Add(gWave); if(keyName->BeginsWith("sum output")) listOfAdderWaves->Add(gWave); /* TString *cName = new TString(keyName->Data()); cName->Append(" canvas"); TCanvas *cy = new TCanvas(cName->Data(),cName->Data(),800,600); gWave->Draw("AL"); */ } cout << listOfAdderWaves->GetEntries() << endl; // analysis for waves with no delay // global variables Double_t xMin,xMax,yStart,yEnd; Int_t graphPoints; Double_t step; // comparator outputs waves sum TGraphErrors *gFirstCompWave = (TGraphErrors *)listOfCompWaves->First(); graphPoints = gFirstCompWave->GetN(); gFirstCompWave->GetPoint(0,xMin,yStart); gFirstCompWave->GetPoint(graphPoints - 1,xMax,yEnd); step = (xMax - xMin)/graphPoints; cout << gFirstCompWave->GetName() << endl; cout << "xMin = " << xMin << " xMax = " << xMax << " graphPoints = " << graphPoints << endl; TGraphErrors *gCompSum = new TGraphErrors(graphPoints); gCompSum->SetLineColor(kBlue); gCompSum->SetLineWidth(2); gCompSum->SetName("Comparator Outputs Sum"); gCompSum->SetTitle("Comparator Outputs Sum"); Int_t nCompWaves = listOfCompWaves->GetEntries(); Float_t gx,gy = 0; // Alpha coefficiens are now written "hard coded" here Float_t alphaArray[3] = {0.199,0.201,0.197}; // Deleays coming from the multiplexer are written "hard coded" here Float_t muxDelayArray[3] = {0,77.14E-12,192.01E-12}; for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nCompWaves; j++) { TGraphErrors *gCompWave = (TGraphErrors *)listOfCompWaves->At(j); gy += (gCompWave->Eval(xMin + i*step + muxDelayArray[j]))*alphaArray[j]; } gCompSum->SetPoint(i,xMin + i*step,gy); gy = 0; } // note that there is a manual correction on the x axis for the comparator waves sum to compare them better in the multigraph Double_t *xArray = gCompSum->GetX(); for(Int_t i = 0; i < graphPoints; i++) { xArray[i] += 5.6E-9; } // TCanvas *cCompSum = new TCanvas("cCompSum","Comparator Outputs Sum",800,600); // gCompSum->Draw("AL"); // adder outputs waves sum // THE ANALYSIS FOR THE ADDER OUTPUT WITH NOT DELAY AND 3 CHANNELS ADDED IS DEPRECATED. // THERE WAS A MISTAKE IN THE DATA TAKING // I'LL KEEP THE CODE HERE FOR FURTHER REFERENCE /* TGraphErrors *gFirstAdderWave = (TGraphErrors *)listOfAdderWaves->First(); graphPoints = gFirstAdderWave->GetN(); gFirstAdderWave->GetPoint(0,xMin,yStart); gFirstAdderWave->GetPoint(graphPoints - 1,xMax,yEnd); step = (xMax - xMin)/graphPoints; cout << gFirstAdderWave->GetName() << endl; cout << "xMin : " << xMin << " xMax : " << xMax << endl; TGraphErrors *gAdderSum = new TGraphErrors(graphPoints); gAdderSum->SetLineWidth(2); // gAdderSum->SetLineColor(kGreen); gAdderSum->SetLineStyle(9); gAdderSum->SetName("Sum of the adder outputs with no delay"); gAdderSum->SetTitle("Sum of the adder outputs with no delay"); Int_t nAdderWaves = listOfAdderWaves->GetEntries(); gy = 0; for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nAdderWaves; j++) { TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j); gy += gAdderWave->Eval(xMin + i*step); } gAdderSum->SetPoint(i,xMin + i*step,gy); gy = 0; } // TCanvas *cAdderSum = new TCanvas("cAdderSum","Sum of the adder outputs",800,600); // gAdderSum->Draw("AL"); TGraphErrors *g3ChannelsSumNoDelay = listOfGraphs->FindObject("sum_output_3_channels_(3) graph"); g3ChannelsSumNoDelay->SetLineColor(kRed); g3ChannelsSumNoDelay->SetLineWidth(2); // note that there is a manual correction on the x axis for the adder output to compare it better in the multigraph Double_t *xArray = g3ChannelsSumNoDelay->GetX(); graphPoints = g3ChannelsSumNoDelay->GetN(); for(Int_t i = 0; i < graphPoints; i++) { xArray[i] -= 600E-12; } // comparison among the computed adder output ,the real one and the sum of the comparator outputs with alpha coefficients correction TMultiGraph *mgSumNoDelay = new TMultiGraph(); mgSumNoDelay->Add(g3ChannelsSumNoDelay); mgSumNoDelay->Add(gAdderSum); mgSumNoDelay->Add(gCompSum); mgSumNoDelay->SetTitle("Collection of graphs for 3 channels sum with no delay"); TCanvas *cmgSumNoDelay = new TCanvas("cmgSumNoDelay", "Collection of graphs for 3 channels sum with no delay", 1200,800); cmgSumNoDelay->Update(); mgSumNoDelay->Draw("AL"); legend = new TLegend(0.6,0.78,0.99,0.99); legend->AddEntry(g3ChannelsSumNoDelay, "Actual sum done by the adder", "lp"); legend->AddEntry(gAdderSum, "Sum of the adder outputs", "lp"); legend->AddEntry(gCompSum, "Sum of the comparator outputs","lp"); legend->Draw(); mgSumNoDelay->GetXaxis()->SetTitle("Seconds"); mgSumNoDelay->GetYaxis()->SetTitle("Volts"); TPaveText *title = (TPaveText*)cmgSumNoDelay->GetPrimitive("title"); title->SetX1NDC(0.009); title->SetY1NDC(0.94); title->SetX2NDC(0.56); title->SetY2NDC(0.99); cmgSumNoDelay->Modified(); */ // analysis for delayed adder outputs Int_t nAdderWaves = listOfAdderWaves->GetEntries(); TGraphErrors *g3ChannelsSumDelay = listOfGraphs->FindObject("sum_output_3_channels_(1-1-1) graph"); g3ChannelsSumDelay->SetLineColor(kRed); g3ChannelsSumDelay->SetLineWidth(2); // Delay coming from cables are written "hard coded" here Float_t cablesDelayArray[3] = {0,1.45E-9,3.21E-9}; graphPoints = g3ChannelsSumDelay->GetN(); //g3ChannelsSumDelay->GetPoint(0,xMin,yStart); //g3ChannelsSumDelay->GetPoint(graphPoints - 1,xMax,yEnd); xMin = 6E-9; xMax = 16E-9; step = (xMax - xMin)/graphPoints; cout << "Sum of the adder outputs with delay" << endl; cout << "xMin : " << xMin << " xMax : " << xMax << endl; TGraphErrors *gAdderSumDelay = new TGraphErrors(graphPoints); gAdderSumDelay->SetLineColor(kBlue); gAdderSumDelay->SetLineWidth(2); gAdderSumDelay->SetName("Sum of the adder outputs with delay"); gAdderSumDelay->SetTitle("Sum of the adder outputs with delay"); gy = 0; // note that there is a manual correction on the delay of 500E-12 to compare the adder output better in the multigraph for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nAdderWaves; j++) { TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j); gy += gAdderWave->Eval(xMin + i*step + cablesDelayArray[j] - 500E-12); } gAdderSumDelay->SetPoint(i,xMin + i*step,gy); gy = 0; } // TCanvas *cSumSumDelay = new TCanvas("cSumSumDelay","Sum of the sum outputs with delay",800,600); // gAdderSumDelay->Draw("APEL"); TMultiGraph *mg3ChannelsSumDelay = new TMultiGraph(); mg3ChannelsSumDelay->Add(gAdderSumDelay); mg3ChannelsSumDelay->Add(g3ChannelsSumDelay); mg3ChannelsSumDelay->SetTitle("Collection of graphs for 3 channels sum with delay"); TCanvas *cmg3ChannelsSumDelay = new TCanvas("cmg3ChannelsSumDelay", "Collection of graphs for 3 channels sum with delay", 1200, 800); cmg3ChannelsSumDelay->Update(); legend = new TLegend(0.6,0.78,0.99,0.99); legend->AddEntry(g3ChannelsSumDelay, "Actual sum done by the adder", "lp"); legend->AddEntry(gAdderSumDelay, "Sum of the delayed adder outputs", "lp"); mg3ChannelsSumDelay->Draw("AL"); legend->Draw(); mg3ChannelsSumDelay->GetXaxis()->SetTitle("Seconds"); mg3ChannelsSumDelay->GetYaxis()->SetTitle("Volts"); TPaveText *title = (TPaveText*)cmg3ChannelsSumDelay->GetPrimitive("title"); title->SetX1NDC(0.009); title->SetY1NDC(0.94); title->SetX2NDC(0.56); title->SetY2NDC(0.99); cmg3ChannelsSumDelay->Modified(); /* // delay test just to try a different method TMultiGraph *mgDelayTest = new TMultiGraph(); Double_t gxTest,gyTest; TGraphErrors *gDelayTest0 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(0))->GetN()); for(Int_t j = 0; j < gDelayTest0->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(0))->GetPoint(j,gxTest,gyTest); gDelayTest0->SetPoint(j,gxTest - cablesDelayArray[0],gyTest); } mgDelayTest->Add(gDelayTest0); TGraphErrors *gDelayTest1 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(1))->GetN()); for(Int_t j = 0; j < gDelayTest1->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(1))->GetPoint(j,gxTest,gyTest); gDelayTest1->SetPoint(j,gxTest - cablesDelayArray[1],gyTest); } mgDelayTest->Add(gDelayTest1); TGraphErrors *gDelayTest2 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(2))->GetN()); for(Int_t j = 0; j < gDelayTest2->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(2))->GetPoint(j,gxTest,gyTest); gDelayTest2->SetPoint(j,gxTest - cablesDelayArray[2],gyTest); } mgDelayTest->Add(gDelayTest2); // TCanvas *cmgDelayTest = new TCanvas("cmgDelayTest", "cmgDelayTest", 800,600); // mgDelayTest->Draw("APEL"); graphPoints = 12000; xMin = 2E-9; xMax = 22E-9; step = (xMax - xMin)/graphPoints; cout << "xMin : " << xMin << " xMax : " << xMax << endl; Double_t delayTest0xMin,delayTest0xMax,delayTest1xMin,delayTest1xMax,delayTest2xMin,delayTest2xMax; gDelayTest0->GetPoint(0,delayTest0xMin,gyTest); gDelayTest0->GetPoint(gDelayTest0->GetN() - 1,delayTest0xMax,gyTest); gDelayTest1->GetPoint(0,delayTest1xMin,gyTest); gDelayTest1->GetPoint(gDelayTest1->GetN() - 1,delayTest1xMax,gyTest); gDelayTest2->GetPoint(0,delayTest2xMin,gyTest); gDelayTest2->GetPoint(gDelayTest2->GetN() - 1,delayTest2xMax,gyTest); cout << delayTest0xMin << endl; TGraphErrors *gAdderSumDelayV2 = new TGraphErrors(graphPoints); for(Int_t i = 0; i < graphPoints; i++) { gyTest = gDelayTest0->Eval(xMin + i*step); gyTest += gDelayTest1->Eval(xMin + i*step); gyTest += gDelayTest2->Eval(xMin + i*step); gAdderSumDelayV2->SetPoint(i,xMin + i*step+ 500E-12,gyTest); } gAdderSumDelayV2->SetLineColor(kGreen); gAdderSumDelayV2->SetLineWidth(2); mg3ChannelsSumDelay->Add(gAdderSumDelayV2); c3ChannelsSumDelay->Modified(); TCanvas *cAdderSumDelayV2 = new TCanvas("cAdderSumDelayV2","cAdderSumDelayV2",800,600); gAdderSumDelayV2->Draw("APL"); */ // List of waves representing the adder output with 5,4,3,2,1 channels in input TGraphErrors *gAdder5Channels = listOfGraphs->FindObject("adder output 5 channels v2 graph"); TGraphErrors *gAdder4Channels = listOfGraphs->FindObject("adder output 4 channels v2 graph"); TGraphErrors *gAdder3Channels = listOfGraphs->FindObject("adder output 3 channels v2 graph"); TGraphErrors *gAdder2Channels = listOfGraphs->FindObject("adder output 2 channels v2 graph"); TGraphErrors *gAdder1Channel = listOfGraphs->FindObject("adder output 1 channel v2 graph"); TGraphErrors *gAdderSingleCh0 = listOfGraphs->FindObject("single sum output ch 0 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh1 = listOfGraphs->FindObject("single sum output ch 1 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh4 = listOfGraphs->FindObject("single sum output ch 4 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh5 = listOfGraphs->FindObject("single sum output ch 5 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh7 = listOfGraphs->FindObject("single sum output ch 7 input 500 mV DT 100 mV graph"); TMultiGraph *mgAdder54321Channels = new TMultiGraph(); mgAdder54321Channels->SetTitle("Collection of graphs for different numbers of added channels"); mgAdder54321Channels->Add(gAdder5Channels); mgAdder54321Channels->Add(gAdder4Channels); mgAdder54321Channels->Add(gAdder3Channels); mgAdder54321Channels->Add(gAdder2Channels); mgAdder54321Channels->Add(gAdder1Channel); TCanvas *cmgAdder54321Channels = new TCanvas("cmgAdder54321Channels", "Collection of graphs for different numbers of added channels",1200,800); mgAdder54321Channels->Draw("AL"); cmgAdder54321Channels->Update(); mgAdder54321Channels->GetXaxis()->SetTitle("seconds"); mgAdder54321Channels->GetYaxis()->SetTitle("Volts"); cmgAdder54321Channels->Modified(); // analysis of the linearity of the adder Double_t addedVMax[nAddedChannels]; addedVMax[0] = TMath::MaxElement(gAdder1Channel->GetN(), gAdder1Channel->GetY()); addedVMax[1] = TMath::MaxElement(gAdder2Channels->GetN(), gAdder2Channels->GetY()); addedVMax[2] = TMath::MaxElement(gAdder3Channels->GetN(), gAdder3Channels->GetY()); addedVMax[3] = TMath::MaxElement(gAdder4Channels->GetN(), gAdder4Channels->GetY()); addedVMax[4] = TMath::MaxElement(gAdder5Channels->GetN(), gAdder5Channels->GetY()); Double_t singleVMax[nAddedChannels]; singleVMax[0] = TMath::MaxElement(gAdderSingleCh0->GetN(), gAdderSingleCh0->GetY()); singleVMax[1] = TMath::MaxElement(gAdderSingleCh1->GetN(), gAdderSingleCh1->GetY()); singleVMax[2] = TMath::MaxElement(gAdderSingleCh4->GetN(), gAdderSingleCh4->GetY()); singleVMax[3] = TMath::MaxElement(gAdderSingleCh5->GetN(), gAdderSingleCh5->GetY()); singleVMax[4] = TMath::MaxElement(gAdderSingleCh7->GetN(), gAdderSingleCh7->GetY()); vector<double> expectedVMax(nAddedChannels); Double_t previousVmax = 0; for(Int_t i = 0; i < expectedVMax.size(); i++) { expectedVMax[i] = singleVMax[i] + previousVmax; previousVmax = expectedVMax[i]; cout << "singleVMax[" <<i <<"] = " << singleVMax[i] << endl; cout << "addedVMax[" <<i <<"] = " << addedVMax[i] << endl; cout << "expectedVMax[" <<i <<"] = " << expectedVMax[i] << endl; } TGraph *gAdderLinearity = new TGraph(expectedVMax.size(),&expectedVMax[0],addedVMax); gAdderLinearity->SetTitle("Linearity of the adder"); gAdderLinearity->GetXaxis()->SetTitle("Expected amplitude value (V)"); gAdderLinearity->GetYaxis()->SetTitle("Actual amplitude value (V)"); gAdderLinearity->GetYaxis()->SetTitleOffset(1.3); TCanvas *cgAdderLinearity = new TCanvas("cgAdderLinearity","Linearity of the adder",800,600); cgAdderLinearity->SetGrid(); cgAdderLinearity->Update(); gAdderLinearity->SetMarkerStyle(20); gAdderLinearity->SetMarkerSize(0.8); //gAdderLinearity->Fit("pol1","Q+","",expectedVMax[0],expectedVMax[2]); TF1 *line = new TF1("line","x",expectedVMax.back(),expectedVMax.front()); gAdderLinearity->Draw("APEL"); line->Draw("SAME"); //gAdderLinearity->GetFunction("pol1")->SetRange(expectedVMax.back(),expectedVMax.front());; cgAdderLinearity->SetLeftMargin(0.13); cgAdderLinearity->Modified(); f->Close(); }
void CalcPeriod(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt, Int_t startEv = 1, char *PedFile) { // create progress bar TGHProgressBar *gProgress = ProgressBar("Calcolo periodo"); // 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 list of graphs for pedestals TList *grPedList = new TList(); TGraphErrors *grPed; // create period histogram TString title = "Period histogram"; TH1 *hPeriod = new TH1F(title,title, 2*((Int_t) DOMINO_NCELL), (Double_t) -DOMINO_NCELL, (Double_t) DOMINO_NCELL); // calculate or read pedestals from file grPedList = OpenPedestals(PedFile); grPed = (TGraphErrors *) grPedList->At(anaChannel); // 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 - 1); 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++; } ievt = 1; Int_t flagEnd = 0; Int_t fitusati = 0; Double_t chtmp; Double_t PedVal, itmp; Double_t mean, rms; Double_t ratio; //debug canvas TCanvas *cfitTest = new TCanvas("cfitTest", "fit tests", 1200, 780); cfitTest->Divide(1,nevt); // loop on events gProgress->Reset(); gProgress->SetMax(nevt); gSystem->ProcessEvents(); while (ievt <= nevt && !flagEnd) { fread((void *) &event_data, 1, sizeof(event_data), fdata); if (feof(fdata)) flagEnd = 1; p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data // goes to channel to analyze p += anaChannel; // read data, subtract pedestals values and save results in grAnaChDataTemp graph with // fixed error for each point (x = 0.5 and y = 2.1). Also generate an array with Domino // X and Y values TGraphErrors *grAnaChDataTemp = new TGraphErrors(DOMINO_NCELL); for (int ch = 0; ch < DOMINO_NCELL; ch++) { // Read pedestal value for this cell grPed->GetPoint(ch, itmp, PedVal); chtmp = (Double_t)(p->data[ch]); // data value chtmp = chtmp - PedVal; grAnaChDataTemp->SetPoint(ch, (Double_t) ch, chtmp); grAnaChDataTemp->SetPointError(ch, 0.5, 2.1); } // create fit functions TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4); fsin->SetParameters(600., 255., 150., 150.); fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset"); grAnaChDataTemp->Fit("fsin", "Q"); TF1 *fsinFit = grAnaChDataTemp->GetFunction("fsin"); fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset"); // debug cfitTest->cd(ievt); grAnaChDataTemp->SetMarkerStyle(20); grAnaChDataTemp->SetMarkerSize(0.3); grAnaChDataTemp->GetYaxis()->SetLabelSize(0.12); grAnaChDataTemp->GetXaxis()->SetLabelSize(0.12); grAnaChDataTemp->Draw("APE"); Double_t fitPeriod, fitAmplitude, chisquare; fitPeriod = fsinFit->GetParameter("Period"); fitAmplitude = TMath::Abs(fsinFit->GetParameter("amplitude")); chisquare = fsinFit->GetChisquare(); cout << "period: " << fitPeriod << " amplitude: " << fitAmplitude << " chisquare: " << chisquare << endl; if(chisquare > 0.1e+06) { gProgress->Increment(1); gSystem->DispatchOneEvent(kTRUE); ievt++; continue; } gProgress->Increment(1); gSystem->DispatchOneEvent(kTRUE); hPeriod->Fill(fitPeriod); fitusati++; ievt++; } cout << "fit scartati :" << nevt - fitusati << endl; //draw TString Title = "Period distribution for nevt events"; TCanvas *cPeriod = new TCanvas("cPeriod", Title, 700, 700); hPeriod->Draw(); hPeriod->Fit("gaus"); TF1 *fgausFit = hPeriod->GetFunction("gaus"); //mean = fgausFit->GetParameter(1); // rms = fgausFit->GetParameter(2); mean = hPeriod->GetMean(); rms = hPeriod->GetRMS(); TString OutFile = "Period"; OutFile += nevt; OutFile += "events.dat"; FILE *f = fopen(OutFile.Data(), "w"); fwrite(&mean, sizeof(mean), 1, f); fwrite(&rms, sizeof(rms), 1, f); ((TGMainFrame *) gProgress->GetParent())->CloseWindow(); fclose(f); cout << "mean: " << mean << " rms: " << rms << endl; fclose(fdata); }