#ifndef RTUBE_
#define RTUBE_
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <TTree.h>
#include <TClass.h>
#include "./treeread/towermap.C"
#include "./treeread/tube_list.C"
#include "./treeread/tube.C"
#include "./treeread/mask.C"
#include <TObject.h>
using namespace std;
class Rtube : public TObject {
public:
Rtube(char * map_file_location="./maps/");
virtual ~Rtube();
Int_t PMTtower[4][20];
Int_t BPRStube[2];
Int_t PMTid[4801];
Int_t getPMT(Int_t towerid);
Int_t getTowersPMT(Int_t pmtId);
Int_t getTube(Int_t towerid);
Int_t getMask(Int_t tower);
Int_t getMapPlot();
Int_t getTubePlot();
Int_t getPMTidPlot();
Int_t tubearrtower[4801];
Int_t tubearrtowtp[4801];
Int_t towervspmt[4801];
ClassDef(Rtube, 1)
private:
Int_t fillTube();
towermap *ptowermap;
tube_list *ptubelist;
tube *ptubemap;
Int_t flagFilltube;
Int_t flagFillmask;
TTree *ttowermap;
TTree *ttube_list;
TTree *ttube;
char* textfilepath;
Int_t maskPMT();
Int_t amask[4801];
};
ClassImp(Rtube);
Rtube::Rtube(char * map_file_location){
flagFilltube=0;flagFillmask=0;
textfilepath=(char*)map_file_location;
ostringstream name;
ttowermap = new TTree("towermap","towermap");
ttube_list = new TTree("tube_list","tube_list");
ttube = new TTree("tube","tube");
name.str("");name << textfilepath << "towers.txt";
ttowermap->ReadFile(TString(name.str()) ,"WPMT/I:WMOD/I:WROW/I:TOWERID[40]/I:EROW/I:EMOD/I:EPMT/I");
name.str("");name << textfilepath<< "tube_list.txt";
ttube_list->ReadFile(TString(name.str()),"TWPMT/I:TWTYPE/I:TEPMT/I:TETYPE/I");
name.str("");name << textfilepath << "tube.txt";
ttube->ReadFile(TString(name.str()),"LTYP/I:LTU[20]");
ptowermap = new towermap(ttowermap);
ptubelist = new tube_list(ttube_list);
ptubemap = new tube(ttube);
for (Int_t i=0;i<120;i++){
ptowermap->GetEntry(i);
for( Int_t j=0 ;j<20;j++) {towervspmt[ptowermap->TOWERID[j]]= ptowermap->WPMT;}
for( Int_t j=20;j<40;j++) {towervspmt[ptowermap->TOWERID[j]]= ptowermap->EPMT;}
}
getMask(100);
for (Int_t i=1;i<61;i++){getTowersPMT(i);}
}
Int_t Rtube::getPMT(Int_t towerid){
if (towerid >4800 || towerid < 1) {cout << "ERROR TowerID out of range" << endl; return -1;}
return(towervspmt[towerid]);
}
Int_t Rtube::getTowersPMT(Int_t pmtId){
Int_t VPMT[5][21];
Int_t row[5];
Int_t drow[5];
Int_t n=0;
if ( pmtId>60 || pmtId < 1) {cout << "ERROR PMTID out of range" << endl; return -1;}
for (Int_t i=0;i<120;i++){
ptowermap->GetEntry(i);
if (ptowermap->WPMT==pmtId || ptowermap->EPMT==pmtId){
row[n]=i;
if(pmtId<31){
for( Int_t j= 0;j<20;j++) {
VPMT[n][j]=ptowermap->TOWERID[j]; }
}
if(pmtId>30){
for( Int_t j=20;j<40;j++) {
VPMT[n][j-20]=ptowermap->TOWERID[j]; }
}
n=n+1;
}
}
if(n!=4){cout << "Towermap layout error, 4 PMT rows were not found!" << endl; return -1;}
drow[1]=0;drow[2]=1;drow[3]=2;drow[4]=3;
if ( ((row[1]-row[0])!=1) || ((row[2]-row[1])!=1) || ((row[3]-row[2])!=1) ){
drow[1]=1;drow[2]=2;drow[3]=3;drow[4]=0;
}
for(Int_t i=0 ; i<4; i++){
for(Int_t j=0;j<20;j++){
PMTtower[i][j]= VPMT[drow[i+1]][j];
PMTid[(PMTtower[i][j])]=(i*20)+(j+1);
}
}
return 0;
}
Int_t Rtube::getTube(Int_t towerId){
Int_t error=0;
BPRStube[2]=getPMT(towerId);
if (flagFilltube==0) {error=fillTube();flagFilltube=1;}
if (error==-1) {return -1;}
BPRStube[0]=tubearrtowtp[towerId];
BPRStube[1]=tubearrtower[towerId];
return 0;
}
Int_t Rtube::fillTube(){
Int_t type=0,i=0,j=0;
for (Int_t tu= 0; tu<4800; tu++){
type=0;
for (Int_t l = 0; l< ttube_list->GetEntries() ; l++){
ptubelist->GetEntry(l);
if(ptubelist->TWPMT==getPMT(tu+1)){type=ptubelist->TWTYPE ;break;}
if(ptubelist->TEPMT==getPMT(tu+1)){type=ptubelist->TETYPE ;break;}
}
if(type==0){cout << "ERROR, tube type not found, tube map is empty!!!!"; return -1;}
getTowersPMT(getPMT(tu+1));
Int_t kill=0;
for(i=0;i<4;i++){
for(j=0;j<20;j++){
if (PMTtower[i][j]==tu+1) {kill=-1; break;}
}
if (kill==-1) break;
}
for(Int_t map=0; map < ttube->GetEntries() ; map++){
ptubemap->GetEntry(map);
if(ptubemap->LTYP==type){ptubemap->GetEntry(map+i); break;}
}
tubearrtower[tu+1]=ptubemap->LTU[j];
tubearrtowtp[tu+1]=type;
}
return 0;
}
Int_t Rtube::getMask(Int_t tower){
if (flagFillmask==0){maskPMT();flagFillmask=1;}
Int_t towerid=(tower * amask[tower]);
return towerid;
}
Int_t Rtube::maskPMT(){
ostringstream namem;
TTree *mmask = new TTree("mask","mask");
namem.str("");namem << textfilepath << "mask.txt";
mmask->ReadFile(TString(namem.str()) ,"PMT/I:TOWARR/I:TIDS/I:TIDE/I");
mask * pmask=new mask(mmask);
for (Int_t i=0 ;i <4801 ;i++){amask[i]=1;}
for (Int_t row =0 ; row < mmask->GetEntries();row++){
pmask->GetEntry(row);
if (pmask->TIDS!=0){
for(Int_t i=pmask->TIDS ; i<((pmask->TIDE)+1); i++){
amask[i]=0;
}
}
if (pmask->TIDS==0 && pmask->TOWARR!=0){
getTowersPMT(pmask->PMT);
for(Int_t i =0 ; i<80 ;i++){
getTube(*((Int_t*)&PMTtower+i));
if(BPRStube[1]==pmask->TOWARR){ amask[*((Int_t*)&PMTtower+i)]=0;}
}
}
if (pmask->TIDS==0 && pmask->TOWARR==0){
getTowersPMT(pmask->PMT);
for(Int_t i =0 ; i<80 ;i++){
amask[*((Int_t*)&PMTtower+i)]=0;
}
}
}
delete pmask;
return 0;
}
Int_t Rtube::getMapPlot(){
for (Int_t i=1;i<61;i++){
getTowersPMT(i);
cout << "************** PMT: " << i << endl;
for (Int_t j=0;j<80;j++){
cout << getMask(*((Int_t*)PMTtower+j)) << " " ;
if ((j+1)%20==0){cout << endl;}
}
}
return 0;
}
Int_t Rtube::getTubePlot(){
for (Int_t i=1;i<31;i++){
getTowersPMT(i);
cout << "************** PMT: " << i << endl;
for (Int_t j=0;j<80;j++){
cout << tubearrtower[*((Int_t*)PMTtower+j)] << " ";
if ((j+1)%20==0){cout << endl;}
}
}
return 0;
}
Int_t Rtube::getPMTidPlot(){
for (Int_t i=1;i<61;i++){
getTowersPMT(i);
cout << "************** PMT: " << i << endl;
for (Int_t j=0;j<80;j++){
cout << PMTid[*((Int_t*)PMTtower+j)] << "," << *((Int_t*)PMTtower+j) << " " ;
if ((j+1)%20==0){cout << endl;}
}
}
return 0;
}
Rtube::~Rtube(){
delete ttowermap;
delete ttube_list;
delete ttube;
delete ptowermap;
delete ptubelist;
delete ptubemap;
}
#endif
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.