#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 // using namespace std; int protomcmped(int mcm = 0,int chip = 0, int saltronb = 0, const char *dir = "",const char *filename = "", const char *title = "") { char name[100]; Char_t iChan; // Channel number Char_t iChip; // Channel number UShort_t iMcm; // MCM/FEC number UShort_t iClLength; //number of samples UInt_t iEventnb; Int_t iSamples[1024]; // Samples Int_t iMax = 0; TH1F* hSignal[16]; TCanvas *c1 = new TCanvas("c1","Single cluster",600,600); TFile *inFile = new TFile(filename); TTree *tree = (TTree*) inFile->Get("tree"); c1->Divide(4,4); 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); Int_t nentries = tree->GetEntries(); printf("ENTRIES %d\n",nentries); for (Int_t j = 0; j < 16; j++) { 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(0); // hSignal[j]->SetMaximum(1024); } gStyle->SetOptStat(1100); for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); if ((iMcm == mcm) && (iChip == chip)) { for(Int_t l = 20; l < iClLength - 20; l++) { hSignal[iChan]->Fill(iSamples[l]); } } } // Print in pedestal file format for chip=7 FILE *fped; sprintf(name,"%s/chip%d/saltro%d-mcm%d-c%d-%s.ped",dir,saltronb,saltronb,mcm,chip,title); fped = fopen(name,"w"); for (Int_t j = 0; j < 16; j++) { printf("%d\t%d\t%5.2f\t%5.3f\t%5.1f\n",j+iChip*16,(int)hSignal[j]->GetMean(), hSignal[j]->GetMean(),hSignal[j]->GetRMS(),hSignal[j]->GetEntries()); fprintf(fped,"%d\t%d\t%5.2f\t%5.3f\t%5.1f\n",j+iChip*16,(int)hSignal[j]->GetMean(), hSignal[j]->GetMean(),hSignal[j]->GetRMS(),hSignal[j]->GetEntries()); } fclose(fped); for (Int_t j = 0; j < 16; j++) { c1->cd(j+1); sprintf(name, "Pedestals ch %d chip %d %s", j,chip,title); hSignal[j]->SetTitle(name); hSignal[j]->GetYaxis()->SetTitle("Entries"); hSignal[j]->GetXaxis()->SetTitle("ADC value"); // hSignal[j]->SetAxisRange(0, 1023, "X"); //hSignal[j]->SetAxisRange(0, 200, "X"); hSignal[j]->Draw(); printf("%d\t%5.2f\t%5.3f\t%5.1f\n",j+iChip*16,hSignal[j]->GetMean(),hSignal[j]->GetRMS(),hSignal[j]->GetEntries()); } sprintf(name,"%s/chip%d/saltro%d-mcm%d-c%d-pedestal-%s.pdf",dir,saltronb,saltronb,mcm,chip,title); c1->SaveAs(name); return 0; } int main (int argc, char *argv[]) { int iret = 0; if (argc<7) { printf("not enough arguments: argc = %d\nSyntax should be:\n./protomcmped.exe saltro mcm chip dir filename title\n",argc); return -1; } int saltronb = atoi(argv[1]); int mcm = atoi(argv[2]); int chip = atoi(argv[3]); iret = protomcmped(mcm,chip,saltronb,argv[4],argv[5],argv[6]); return iret; }