// compile with: // g++ -o plotchipramp.exe plotchipramp.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 plotchipramp(int mcm = 0,int chip = 0, int saltronb = 0, int pattern = 1, const char *dir = "",const char *filename = "", const char *title = "") { char name[255]; unsigned int ErrorCode[16] = {0}; Char_t iChan; // Channel number Char_t iChip; // Channel number UShort_t iMcm; // MCM/FEC number UShort_t iClLength; //number of samples UShort_t iClTime; // time of first sample UInt_t iEventnb; Int_t iSamples[1024]; // Samples int nChan = 0; Int_t iMax = 0; unsigned int toterr; int erraddress; int nbEvents; int prevEvent; int nbChannels[16]; int nbErrors[16]; TH1F* hSignal[16]; TH1F* hPattern[16]; TCanvas *c1 = new TCanvas("c1","Single cluster",600,600); sprintf(name, "%s/%s.root",dir,filename); TFile *inFile = new TFile(name); TTree *tree = (TTree*) inFile->Get("tree"); if(!tree) { cerr << "Tree SALTRO events was not found: " << name << "\n"; return 1; } printf("Run: %s\n",name); // Assign variables to branches 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); for (Int_t j = 0; j < 16; j++) { nbChannels[j] = 0; nbErrors[j] = 0; sprintf(name, "hSignal_%d", j); 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(400); // hSignal[j]->SetMaximum(600); sprintf(name, "hPattern_%d", j); hPattern[j] = ((TH1F *)(gROOT->FindObject(name))); if (hPattern[j]) delete hPattern[j]; hPattern[j] = new TH1F(name, "",1024,-0.5,1023.5); } nbEvents = 0; prevEvent = 0; gStyle->SetOptStat(0); erraddress = 0; for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); if (iEventnb != prevEvent) { nbEvents++; prevEvent = iEventnb; } if ((iMcm == mcm) && (iChip == chip)) { nbChannels[iChan]++; for(Int_t l = 0; l < iClLength; l++) { hSignal[iChan]->Fill(iSamples[l]); hPattern[iChan]->AddBinContent(iClLength-l,iSamples[l]); if (pattern == 1) { if (l != iSamples[iClLength-l-1]) { // rampup nbErrors[iChan]++; } } else if (pattern == 2) { if ((l+16) != iSamples[l]) { // rampdown nbErrors[iChan]++; } } } } } Int_t oldLevel = gErrorIgnoreLevel; gErrorIgnoreLevel = kWarning; for (Int_t j = 0; j < 16; j++) { c1->cd(j+1); sprintf(name, "Channel %d pattern %d",j,pattern); hPattern[j]->Scale(1.0/iEventnb); hPattern[j]->SetTitle(name); hPattern[j]->GetXaxis()->SetTitle("Sample #"); hPattern[j]->GetYaxis()->SetTitle("ADC value"); hPattern[j]->SetAxisRange(0,1100, "Y"); hPattern[j]->Draw(); if (j == 0) sprintf(name,"%s/%s.pdf(",dir,filename); else sprintf(name,"%s/%s.pdf",dir,filename); c1->SaveAs(name,"pdf"); } gStyle->SetOptStat(1100); for (Int_t j = 0; j < 16; j++) { c1->cd(j+1); sprintf(name, "Ramp saltro:%d chip:%d:%d channel %d %s",saltronb,mcm,chip,j,title); hSignal[j]->SetTitle(name); hSignal[j]->GetYaxis()->SetTitle("Entries"); hSignal[j]->GetXaxis()->SetTitle("ADC value"); // hSignal[nChan]->SetAxisRange(0, 1024, "X"); //hSignal[nChan]->SetAxisRange(470, 550, "X"); // hSignal[nChan]->SetAxisRange(470, 500, "Y"); hSignal[j]->SetAxisRange(0,iEventnb + 50, "Y"); hSignal[j]->Draw(); if (j == 15) sprintf(name,"%s/%s.pdf)",dir,filename); else sprintf(name,"%s/%s.pdf",dir,filename); c1->SaveAs(name,"pdf"); } gErrorIgnoreLevel = oldLevel; // Store result in csvfile FILE *csvfile; sprintf(name, "%s/%s.csv",dir,filename); struct stat fileBuffer; int csvexist = 0; if (stat (name, &fileBuffer) == 0) csvexist = 1; printf("CSV EXIST %d\n",csvexist); csvfile = fopen(name,"a"); if (csvfile == NULL) { return 3; } // Errors are: // wrong number of channels // errors found in data toterr = 0; if (csvexist == 0) { fprintf(csvfile,"Channel,nbChannels,Mean,RMS,nbErrors,ErrorCode\n"); } for (Int_t j = 0; j < 16; j++) { if (nbChannels[j] != iEventnb) ErrorCode[j] |= 1; if (nbErrors[j] != 0) ErrorCode[j] |= 2; fprintf(csvfile,"%d,%d,%6.2f,%6.3f,%d,%08X\n", j+iChip*16,nbChannels[j],hSignal[j]->GetMean(),hSignal[j]->GetRMS(),nbErrors[j],ErrorCode[j]); toterr |= ErrorCode[j]; } fclose(csvfile); if (toterr != 0) return 4; return 0; } int main (int argc, char *argv[]) { int iret = 0; if (argc != 8) { printf("not enough arguments: argc = %d\nSyntax should be:\n./plotchipramp.exe saltro mcm chip pattern dir filename title\n",argc); return -1; } int saltronb = atoi(argv[1]); int mcm = atoi(argv[2]); int chip = atoi(argv[3]); int pattern = atoi(argv[4]); iret = plotchipramp(mcm,chip,saltronb,pattern,argv[5],argv[6],argv[7]); return iret; }