// compile with: // g++ -o plotsmalltpcped.exe plotsmalltpcped.cpp `root-config --cflags --glibs` // #include "TH1F.h" #include "TProfile.h" #include "TMath.h" #include "TF1.h" #include "TLegend.h" #include "TCanvas.h" // #include "TROOT.h" //#include "TStyle.h" #include "TTree.h" #include "TFile.h" #include "TGraphErrors.h" #include "TStyle.h" #include #include #include #include #include #include // #include #include #include using namespace std; int plotsmalltpcped(const char *dir = "", const char *filename = "",const char *title = "") { char name[100]; Char_t iChan; // Channel number Char_t iChip; // Chip number Int_t nChan; UShort_t iClLength; //number of samples UShort_t iClTime; // time of first sample UShort_t iMcm; // MCM(DTC) UInt_t iEventnb; Int_t iSamples[1024]; // Samples Int_t iMax = 0; float MaxRMS = 3.0; float MaxPed = 170.0; float MinEntries = 1000.0; TH1F* hSignal[256]; TCanvas *c1 = new TCanvas("c1","Single cluster",600,600); sprintf(name, "%s/%s.root",dir,filename); printf("%s: %s %s\n",name,dir,filename); TFile *inFile = new TFile(name); TTree *tree = (TTree*) inFile->Get("tree"); c1->Divide(4,4); Int_t chan_low; Int_t chan_high; if(!tree) { cerr << "Tree SALTRO events was not found: " << name << "\n"; return 1; } // tree->Show(iEntry); tree->SetBranchAddress("iEventnb",&iEventnb); tree->SetBranchAddress("iSamples",&iSamples); tree->SetBranchAddress("iChan",&iChan); tree->SetBranchAddress("iChip",&iChip); tree->SetBranchAddress("iMcm",&iMcm); tree->SetBranchAddress("iClLength",&iClLength); tree->SetBranchAddress("iClTime",&iClTime); Int_t nentries = tree->GetEntries(); printf("ENTRIES %d\n",nentries); int dcl = 0; chan_low = 128 * dcl; chan_high = chan_low + 256; for (Int_t j = 0; j < 256; j++) { sprintf(name, "hSignal_%d", j+chan_low); hSignal[j] = ((TH1F *)(gROOT->FindObject(name))); if (hSignal[j]) delete hSignal[j]; hSignal[j] = new TH1F(name, "",1024,-0.5,1023.5); hSignal[j]->SetMinimum(0); // hSignal[j]->SetMaximum(1024); } gStyle->SetOptStat(111110); for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); nChan = iMcm*128 + iChip*16 + iChan; for(Int_t l = 20; l < iClLength - 20; l++) { hSignal[nChan]->Fill(iSamples[l]); } } // Print in pedestal file format for chip=7 FILE *fped; int mcmnb,traceid,gain,shaper,polarity; int clk,thresh,ped,source; sscanf(filename,"chamber-fec01-debug-clk%d-ped%d-thr%d-g%d-s%d-p%d-s%d.root",&clk,&ped,&thresh,&gain,&shaper,&polarity,&source); sprintf(name,"%s/%s-%s.csv",dir,filename,title); fped = fopen(name,"w"); for (Int_t j = 0; j < 256; j++) { // printf("%d\t%d\t%5.2f\t%5.3f\t%5.1f\n",j,(int)hSignal[j]->GetMean(), hSignal[j]->GetMean(),hSignal[j]->GetRMS(),hSignal[j]->GetEntries()); fprintf(fped,"%d,%d,%5.2f,%5.3f,%5.1f\n",j,(int)hSignal[j]->GetMean(), hSignal[j]->GetMean(),hSignal[j]->GetRMS(),hSignal[j]->GetEntries()); if ((hSignal[j]->GetRMS() > MaxRMS) || (hSignal[j]->GetMean() > MaxPed) || (hSignal[j]->GetEntries() < MinEntries)) printf("ERR: %d %5.2f %5.3f %6.1f\n",j,hSignal[j]->GetMean(),hSignal[j]->GetRMS(),hSignal[j]->GetEntries()); } fclose(fped); gErrorIgnoreLevel = kWarning; for (Int_t d = 0; d < 2; d++) { for (Int_t i = 0; i < 8; i++) { for (Int_t j = 0; j < 16; j++) { nChan = d*128 + i*16 + j; c1->cd(j+1); sprintf(name, "Pedestals %s ch %d %s", filename, nChan ,title); hSignal[nChan]->SetTitle(name); hSignal[nChan]->GetYaxis()->SetTitle("Entries"); hSignal[nChan]->GetXaxis()->SetTitle("ADC value"); //hSignal[nChan]->SetAxisRange(0, 100, "Y"); //hSignal[nChan]->SetAxisRange(0, 1023, "X"); if (polarity==0) hSignal[nChan]->SetAxisRange(750, 950, "X"); else hSignal[nChan]->SetAxisRange(0, 150, "X"); hSignal[nChan]->Draw(); //printf("%d\t%5.2f\t%5.3f\t%5.1f\n",nChan,hSignal[nChan]->GetMean(),hSignal[nChan]->GetRMS(),hSignal[nChan]->GetEntries()); } if (i == 0) sprintf(name,"%s/%s-%s-dcl%d.pdf(",dir,filename,title,d); else if ( i == 7) sprintf(name,"%s/%s-%s-dcl%d.pdf)",dir,filename,title,d); else sprintf(name,"%s/%s-%s-dcl%d.pdf",dir,filename,title,d); c1->SaveAs(name,"pdf"); } } return 0; } int main (int argc, char *argv[]) { int iret = 0; printf("%s %s %s\n",argv[1],argv[2],argv[3]); if (argc != 4) { printf("Wrong number of arguments: argc = %d\nSyntax should be:\n./plotsmalltpcped.exe dir filename title\n",argc); return -1; } iret =plotsmalltpcped(argv[1],argv[2],argv[3]); printf("END\n"); return iret; }