/** * TmtcTemperature * author Marcelli * version 1.1 - 10 December 2005 * * Version 1.2 - 28 December 2004 * If TFile does not exist the function exit to prompt * If nevents = 0 the function exit to promt * Initialize to 0 alla array dedicated to graphs * * version 1.3 - 22 February 2005 - Nagni * For compatibility with batch mode excution: * 1) Added "include " and "using namespace std" * 2) Removed gROOT->Reset() * * version 1.4 - 25 February 2005 - Marcelli * Canvas of thermistors divided in 12 pads * * Version 1.5 * Date 08 March 2005 - Nagni * Added "format" parameter for saving the produced image in various formats * (for a complete list of types refer to TPad::SaveAs method) * * version 1.6 * Date 24 May 2005 - Marcelli * Added four thermistor (files after DW_050516_007 has 16 thermistors instead of 12) * * version 1.7 * Date 02 February 2006 - Marcelli * Modified to work with new version of YODA * * version 1.8 * Date March 2006 - Marcelli * For compilation: * Added function "int main(int argc, char* argv[])" * * Description : To monitor information from TMTC Packet (voltage, CC,....) * * Parameters: * TString base - the path to the root directory for the specific Pamela unpack session * TString outDir - the path where to save the output image (Default = base) * TString format - the format which will be used fo rsave the produced images (Default = "jpg") * */ #include #include #include "TStyle.h" #include "TFile.h" #include "TList.h" #include "TTree.h" #include "TObjString.h" #include "TCanvas.h" #include "TGraph.h" #include "TH1F.h" #include "TGaxis.h" #include "TString.h" #include "TPaveText.h" #include "tmtc/TmtcEvent.h" #include "tmtc/TmtcRecord.h" using namespace std; /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////FUNZIONI DI CONVERSIONE/////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// //reference: Laben Document, TL 18348, pag. 79 float convert_th(int TH) { float a,q,deltax,deltay; float gradi[111],grado=-1; int adc[111]={4095, 3868, 3654, 3454, 3265, 3088, 2922, 2765, 2618, 2479, 2348, 2225, 2110, 2000, 1897, 1800, 1709, 1622, 1541, 1464, 1391, 1322, 1257, 1196, 1138, 1083, 1031, 981, 935, 890, 849, 809, 771, 736, 702, 670, 639, 610, 583, 557, 532, 508, 486, 464, 444, 425, 406, 389, 372, 356, 341, 327, 313, 300, 288, 276, 264, 254, 243, 233, 224, 215, 206, 198, 190, 183, 175, 169, 162, 156, 150, 144, 138, 133, 128, 123, 118, 114, 110, 106, 102, 98, 94, 91, 87, 84, 81, 78, 75, 73, 70, 67, 65, 63, 60, 58, 56, 54, 52, 50, 49, 47, 45, 44, 42, 41, 39, 38, 37, 35, 34}; int maxpos=-1,minpos=-1,i; for (i=0;i<111;i++) { gradi[i]=-35+i; } if (TH > 4095) { grado=100.; return grado; } if (TH <= 34) { grado=100.; return grado; } if (TH==4095) { grado=-35.; return grado; } else { for (i=1;i<111;i++) { if (TH>=adc[i]) { minpos=i; maxpos=i-1; break; } } deltax=adc[maxpos]-adc[minpos]; deltay=gradi[maxpos]-gradi[minpos]; a=deltay/deltax; q=gradi[maxpos]-a*adc[maxpos]; grado=a*TH+q; } return (grado); } //reference: Laben Document, TL 18348, pag. 76 float convert_volt(int in) { float a,q,deltax,deltay; float inputvoltage[52],voltage=-1; float adc[52]; int maxpos=-1,minpos=-1,i; for (i=0;i<52;i++) { inputvoltage[i] = (i*0.10); } for (i=0;i<52;i++) { adc[i] = (i*5); } if (in==0) { voltage= 0.00; } else { for (i=0;i<52;i++) { if (in<=adc[i]) { minpos=i; maxpos=i-1; break; } } deltax=adc[maxpos]-adc[minpos]; deltay=inputvoltage[maxpos]-inputvoltage[minpos]; a=deltay/deltax; q=inputvoltage[maxpos]-a*adc[maxpos]; voltage=a*in+q; } return (voltage); } //////////////////////////////////////////////////////////////////////////////// ////////////////////////// TMTC TEMPERATURE ////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// void TmtcTemperature(TString base, TString outDir, TString format){ //------- load root file -------------- TFile *file = new TFile(base.Data()); if ( outDir == "" ) outDir = "."; if (!file){ printf("No such file in the directory has been found"); return; } //--- Takes the tree of Tmtc ----------- TPaveText *pt=0; TPaveText *pt1=0; TTree *tr = (TTree*)file->Get("Tmtc"); TBranch *tmtcBr = tr->GetBranch("Tmtc"); pamela::TmtcEvent *tme=0; pamela::TmtcRecord *tmr=0; tr->SetBranchAddress("Tmtc", &tme); ///-------to create canvas--------------------// TCanvas *Canvascchot = new TCanvas("Tmtc_1", base, 1280, 1024); Canvascchot->Divide(2,3); Canvascchot->SetFillColor(10); TCanvas *Canvascccold = new TCanvas("Tmtc_2", base, 1280,1024); Canvascccold->Divide(2,3); Canvascccold->SetFillColor(10); TCanvas *Canvasccvrl = new TCanvas("Tmtc_3", base, 1280, 1024); Canvasccvrl->Divide(1,3); Canvasccvrl->SetFillColor(10); TCanvas *Canvasthdea = new TCanvas("Tmtc_4", base, 1280, 1024); if (tr->GetBranch("Records.TM_TH_ANA[12]")){ Canvasthdea->SetFillColor(10); Canvasthdea->Divide(3,4); } else if (tr->GetBranch("Records.TM_TH_ANA[16]")){ Canvasthdea->SetFillColor(10); Canvasthdea->Divide(4,4); } TCanvas *Canvasvoltdea = new TCanvas("Tmtc_5", base, 1280, 1024); Canvasvoltdea->SetFillColor(10); Canvasvoltdea->Divide(2,3); //////--------to analize data-----------------////// Long64_t nevents = tmtcBr->GetEntries(); if (nevents<=0) { file->Close(); printf("nevents = %i", nevents); return; } const Int_t size = nevents; std::stringstream oss; Int_t recordstot=0; Int_t m=0; Int_t l=0; Int_t n=0; for (Int_t i = 0; i < size; i++){ tmtcBr->GetEntry(i); Long64_t tmpSize = tme->Records->GetEntries(); //Int_t size_b = tmpSize; recordstot=recordstot+tmpSize; } const Int_t lungmax=16*recordstot; const Int_t lungmin=6*recordstot; Double_t xrecordobtcc[lungmax], yccdiagacq[lungmax], ythana[lungmax], xrecordobtth[lungmax], xrecordobtdea[lungmin], ydea[lungmin], xrecordobtcc_1[lungmax], yccdiagacq_1[lungmax], ythana_1[lungmax], xrecordobtth_1[lungmax], xrecordobtdea_1[lungmin], ydea_1[lungmin], limth[lungmax], limvolt1[lungmin], limvolt2[lungmin], limvolt3[lungmin]; string titolocc[] ={"IPM1","IPM2","IPM3","IPM4","IPM5","IPM6","KHB_HOT_LATCHUP","KHB_COLD_LATCHUP","IDAQ_HOT_ALARM","IDAQ_COLD_ALARM","VCB_STANDBY","VRL_HOT","VRL_COLD","PSB_ALARM","TOFHV_HOT_ALARM","TOFHV_COLD_ALARM"}; string titoloth[] ={"IPM_TH","S1_TH","S4_TH","S4_ND_PLATE_TH","TRK_TH1","TRK_TH2","FLUID_IN_TH","FLUID_OUT_TH","VME_TH","DCDC_TH","CPU_TH1","CPU_TH2", "", "", "", ""}; recordstot=0; for (Int_t i = 0; i < size; i++){ tmtcBr->GetEntry(i); Long64_t tmpSize = tme->Records->GetEntries(); Int_t size_b = tmpSize; for (Int_t j = 0; j < size_b; j++){ tmr = (pamela::TmtcRecord*)tme->Records->At(j); for (Int_t k =0; k <16; k++){ yccdiagacq[16*recordstot+16*j+k] = (((tmr->TM_DIAG_AND_BILEVEL_ACQ)>>(15-k))&0x0001); xrecordobtcc[16*recordstot+16*j+k] = tmr->TM_RECORD_OBT; } if (tr->GetBranch("Records.TM_TH_ANA[12]")){ for (Int_t k =0; k <12; k++){ ythana[12*recordstot+12*j+k] = convert_th(tmr->TM_TH_ANA[k]); xrecordobtth[12*recordstot+12*j+k] = tmr->TM_RECORD_OBT; } } else if (tr->GetBranch("Records.TM_TH_ANA[16]")){ for (Int_t k =0; k <16; k++){ ythana[16*recordstot+16*j+k] = convert_th(tmr->TM_TH_ANA[k]); xrecordobtth[16*recordstot+16*j+k] = tmr->TM_RECORD_OBT; } } for (Int_t k =0; k <6; k++){ ydea[6*recordstot+6*j+k] = convert_volt(tmr->TM_DEA_ANA[k]); xrecordobtdea[6*recordstot+6*j+k] = tmr->TM_RECORD_OBT; } } recordstot=recordstot+tmpSize; } TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); //CC Graph for (Int_t k =0; k<16; k++){ for (Int_t i = 0; i < recordstot; i++){ yccdiagacq_1[i]= yccdiagacq[16*i+k]; xrecordobtcc_1[i]= xrecordobtcc[16*i+k]; } //CC IPM if (k==0 || k==1 ||k==2 || k==3 || k==4 || k==5 ){ Canvascchot->cd(m+1); gPad->SetFillColor(10); TGraph *ccrecord = new TGraph(recordstot, xrecordobtcc_1, yccdiagacq_1); pt = new TPaveText (.01,.07,.09,.13); pt->AddText("ON"); pt->SetBorderSize(1); pt->Draw(); pt1 = new TPaveText (.01,.47,.09,.53); pt1->AddText("OFF"); pt1->SetBorderSize(1); pt1->Draw(); oss.str(""); oss<SetTitle(oss.str().c_str()); ccrecord->SetMaximum(1.5); ccrecord->SetMinimum(0); ccrecord->SetFillColor(8); ccrecord->GetXaxis()->SetTitle("OBT"); ccrecord->GetXaxis()->CenterTitle(); ccrecord->GetYaxis()->SetTitle(""); ccrecord->GetYaxis()->CenterTitle(); ccrecord->GetYaxis()->SetNdivisions(3,-1); ccrecord->GetYaxis()->SetLabelSize(0); ccrecord->SetMaximum(2); ccrecord->SetMinimum(0); ccrecord->Draw("AB"); pt->Draw(); pt1->Draw(); m=m+1; } //CC idaq-khb-tof if (k==6 || k==7 || k==8 || k==9 || k==14 || k==15){ Canvascccold->cd(l+1); gPad->SetFillColor(10); TGraph *ccrecord = new TGraph(recordstot, xrecordobtcc_1, yccdiagacq_1); if (k==6 || k==7){ TPaveText *pt = new TPaveText (.01,.07,.09,.13); pt->AddText("ON"); pt->SetBorderSize(1); pt->Draw(); TPaveText *pt1 = new TPaveText (.01,.47,.15,.53); pt1->AddText("OFF/LATCHUP"); pt1->SetBorderSize(1); pt1->Draw(); } if (k==8 || k==9 || k==14 || k==15){ TPaveText *pt = new TPaveText (.01,.07,.09,.13); pt->AddText("ON"); pt->SetBorderSize(1); pt->Draw(); TPaveText *pt1 = new TPaveText (.01,.47,.13,.53); pt1->AddText("OFF/ALARM"); pt1->SetBorderSize(1); pt1->Draw(); } oss.str(""); oss<SetTitle(oss.str().c_str()); ccrecord->SetMaximum(1.5); ccrecord->SetMinimum(0); ccrecord->SetFillColor(8); ccrecord->GetXaxis()->SetTitle("OBT"); ccrecord->GetXaxis()->CenterTitle(); ccrecord->GetYaxis()->SetTitle(""); ccrecord->GetYaxis()->CenterTitle(); ccrecord->GetYaxis()->SetNdivisions(3,-1); ccrecord->GetYaxis()->SetLabelSize(0); ccrecord->SetMaximum(2); ccrecord->SetMinimum(0); ccrecord->Draw("AB"); l=l+1; } //CC vrl if (k==11 || k==12 || k==13 ){ Canvasccvrl->cd(n+1); gPad->SetFillColor(10); TGraph *ccrecord = new TGraph(recordstot, xrecordobtcc_1, yccdiagacq_1); if (k==11 || k==12){ TPaveText *pt = new TPaveText (.05,.07,.09,.13); pt->AddText("ON"); pt->SetBorderSize(1); pt->Draw(); TPaveText *pt1 = new TPaveText (.05,.47,.09,.53); pt1->AddText("OFF"); pt1->SetBorderSize(1); pt1->Draw(); } if (k==13){ TPaveText *pt = new TPaveText (.05,.07,.09,.13); pt->AddText("ON"); pt->SetBorderSize(1); pt->Draw(); TPaveText *pt1 = new TPaveText (.03,.47,.11,.53); pt1->AddText("OFF/ALARM"); pt1->SetBorderSize(1); pt1->Draw(); } oss.str(""); oss<SetTitle(oss.str().c_str()); ccrecord->SetMaximum(1.5); ccrecord->SetMinimum(0); ccrecord->SetFillColor(8); ccrecord->GetXaxis()->SetTitle("OBT"); ccrecord->GetXaxis()->CenterTitle(); ccrecord->GetYaxis()->SetTitle(""); ccrecord->GetYaxis()->CenterTitle(); ccrecord->GetYaxis()->SetNdivisions(3,-1); ccrecord->GetYaxis()->SetLabelSize(0); ccrecord->SetMaximum(2); ccrecord->SetMinimum(0); ccrecord->Draw("AB"); n=n+1; } } // TH Graph Canvasthdea->cd(); //thermistors number 12 if (tr->GetBranch("Records.TM_TH_ANA[12]")){ for (Int_t k =0; k<12; k++){ for (Int_t i = 0; i < recordstot; i++){ ythana_1[i]= ythana[12*i+k]; xrecordobtth_1[i]= xrecordobtth[12*i+k]; limth[i] = 45; } Canvasthdea->cd(k+1); TGraph *graph = new TGraph(recordstot, xrecordobtth_1, limth); graph->SetMarkerColor(50); graph->SetLineColor(50); graph->SetMarkerStyle(21); graph->SetMarkerSize(0.3); graph->SetMinimum(-10); graph->SetMaximum(60); graph->GetXaxis()->SetTitle("OBT"); graph->GetXaxis()->CenterTitle(); graph->GetYaxis()->SetTitle("Temperature value (°C)"); graph->GetYaxis()->CenterTitle(); oss.str(""); oss << filename.Data() <<": " <SetTitle(oss.str().c_str()); TPaveText *pt = new TPaveText (.45,.7,.55,.77); pt->AddText("OFF"); pt->SetBorderSize(1); pt->Draw(); graph->Draw("ACP"); pt->Draw(); TGraph *threcord = new TGraph(recordstot, xrecordobtth_1, ythana_1); threcord->SetLineColor(kBlue); threcord->SetMarkerColor(kBlue); threcord->SetMarkerStyle(21); threcord->Draw("C"); } } //thermistors number=16 if (tr->GetBranch("Records.TM_TH_ANA[16]")){ for (Int_t k =0; k<16; k++){ for (Int_t i = 0; i < recordstot; i++){ ythana_1[i]= ythana[16*i+k]; xrecordobtth_1[i]= xrecordobtth[16*i+k]; limth[i] = 45; } Canvasthdea->cd(k+1); TGraph *graph = new TGraph(recordstot, xrecordobtth_1, limth); graph->SetMarkerColor(50); graph->SetLineColor(50); graph->SetMarkerStyle(21); graph->SetMarkerSize(0.3); graph->SetMinimum(-10); graph->SetMaximum(60); graph->GetXaxis()->SetTitle("OBT"); graph->GetXaxis()->CenterTitle(); graph->GetYaxis()->SetTitle("Temperature value (°C)"); graph->GetYaxis()->CenterTitle(); oss.str(""); oss << filename.Data() <<": " <SetTitle(oss.str().c_str()); TPaveText *pt = new TPaveText (.45,.7,.55,.77); pt->AddText("OFF"); pt->SetBorderSize(1); pt->Draw(); graph->Draw("ACP"); pt->Draw(); TGraph *threcord = new TGraph(recordstot, xrecordobtth_1, ythana_1); threcord->SetLineColor(kBlue); threcord->SetMarkerColor(kBlue); threcord->SetMarkerStyle(21); threcord->Draw("C"); } } // DEA Graph Canvasvoltdea->cd(); for (Int_t k =0; k<6; k++){ for (Int_t i = 0; i < recordstot; i++){ ydea_1[i]= ydea[6*i + k]; xrecordobtdea_1[i]= xrecordobtdea[6*i+k]; limvolt1[i]= 0.65; limvolt2[i]= 3.15; limvolt3[i]= 4.25; } Canvasvoltdea->cd(k+1); TGraph *graph1 = new TGraph(recordstot, xrecordobtth_1, limvolt1); TPaveText *pt = new TPaveText (.84,.13,.92,.19); pt->AddText("OFF"); pt->SetBorderSize(1); pt->Draw(); TPaveText *pt1 = new TPaveText (.84,.67,.92,.73); pt1->AddText("ON"); pt1->SetBorderSize(1); pt1->Draw(); graph1->SetMarkerColor(50); graph1->SetLineColor(50); graph1->SetMarkerStyle(21); graph1->SetMarkerSize(0.3); graph1->SetMinimum(0.0); graph1->SetMaximum(5.0); graph1->GetXaxis()->SetTitle("OBT"); graph1->GetXaxis()->CenterTitle(); graph1->GetYaxis()->SetTitle("Voltage value (V)"); graph1->GetYaxis()->CenterTitle(); oss.str(""); oss << filename.Data()<<": IPM "<SetTitle(oss.str().c_str()); graph1->Draw("ACP"); pt1->Draw(); pt->Draw(); TGraph *graph2 = new TGraph(recordstot, xrecordobtth_1, limvolt2); graph2->SetMarkerColor(50); graph2->SetLineColor(50); graph2->SetMarkerStyle(21); graph2->SetMarkerSize(0.2); graph2->SetMinimum(0.0); graph2->SetMaximum(5.0); graph2->Draw("CP"); TGraph *graph3 = new TGraph(recordstot, xrecordobtth_1, limvolt3); graph3->SetMarkerColor(50); graph3->SetLineColor(50); graph3->SetMarkerStyle(21); graph3->SetMarkerSize(0.2); graph3->SetMinimum(0.0); graph3->SetMaximum(5.0); graph3->Draw("CP"); TGraph *dearecord = new TGraph(recordstot, xrecordobtdea_1, ydea_1); dearecord->SetLineColor(kBlue); dearecord->SetLineWidth(1); dearecord->SetMarkerStyle(21); dearecord->SetMarkerSize(0.5); dearecord->SetMarkerColor(kBlue); dearecord->Draw("CPL"); } stringstream oss1, oss2, oss3, oss4; oss.str(""); oss1.str(""); oss2.str(""); oss3.str(""); oss4.str(""); oss << outDir.Data() << filename.Data() << "_Tmtc_cc_hot." << format; oss3 << outDir.Data() << filename.Data() << "_Tmtc_cc_cold." << format; oss4 << outDir.Data() << filename.Data() << "_Tmtc_cc_vrl." << format; oss1 << outDir.Data() << filename.Data() << "_Tmtc_th_dea." << format; oss2 << outDir.Data() << filename.Data() << "_Tmtc_volt_dea." << format; Canvascchot->SaveAs(oss.str().c_str()); Canvascccold->SaveAs(oss3.str().c_str()); Canvasccvrl->SaveAs(oss4.str().c_str()); Canvasthdea->SaveAs(oss1.str().c_str()); Canvasvoltdea->SaveAs(oss2.str().c_str()); file->Close(); } ////////////////////////////////////////////////////////////////////////////////// ///////////////////////// MAIN /////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]){ TString path; TString outDir = "./"; TString format = "jpg"; if (argc < 2){ printf("You have to insert at least the file to analyze \n"); printf("Try '--help' for more information. \n"); exit(1); } if (!strcmp(argv[1], "--help")){ printf( "Usage: TmtcTemperature FILE [OPTION] \n"); printf( "\t --help Print this help and exit \n"); printf( "\t -outDir[path] Path where to put the output [default ./] \n"); printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n"); exit(1); } path=argv[1]; for (int i = 2; i < argc; i++){ if (!strcmp(argv[i], "-outDir")){ if (++i >= argc){ printf( "-outDir needs arguments. \n"); printf( "Try '--help' for more information. \n"); exit(1); } else{ outDir = argv[i]; continue; } } if (!strcmp(argv[i], "-format")){ if (++i >= argc){ printf( "-format needs arguments. \n"); printf( "Try '--help' for more information. \n"); exit(1); } else{ format = argv[i]; continue; } } } TmtcTemperature(argv[1], outDir, format); }