/[PAMELA software]/DarthVader/ToFLevel2/src/ToFLevel2.cpp
ViewVC logotype

Diff of /DarthVader/ToFLevel2/src/ToFLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by pamelats, Thu Dec 4 11:41:08 2008 UTC revision 1.25 by pamelats, Wed Apr 15 10:05:22 2009 UTC
# Line 5  Line 5 
5   * WM dec 2008: Description of "GetdEdx" changed   * WM dec 2008: Description of "GetdEdx" changed
6   * WM dec 2008: "GetdEdxPaddle" modified: Now includes saturation limit   * WM dec 2008: "GetdEdxPaddle" modified: Now includes saturation limit
7   *              PMTs higher than the saturation limit are not used for dEdx   *              PMTs higher than the saturation limit are not used for dEdx
8     * WM apr 2009: bug found by Nicola in method "GetPaddlePlane"
9   */   */
10    
 #include <TObject.h>  
11  #include <ToFLevel2.h>  #include <ToFLevel2.h>
 #include <iostream>  
12  using namespace std;  using namespace std;
13  ClassImp(ToFPMT);  ClassImp(ToFPMT);
14  ClassImp(ToFTrkVar);  ClassImp(ToFTrkVar);
# Line 736  void ToFLevel2::GetPMTPaddle(Int_t pmt_i Line 735  void ToFLevel2::GetPMTPaddle(Int_t pmt_i
735  // gf Apr 07  // gf Apr 07
736    
737  void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){  void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){
738      pmtleft=paddle*2;
739    if(paddle==0){    pmtright= pmtleft+1;  
     pmtleft=0;  
     pmtright=1;  
   }  
   
   if(paddle==1){  
     pmtleft=2;  
     pmtright=3;  
   }  
   
   if(paddle==2){  
     pmtleft=4;  
     pmtright=5;  
   }  
   
   if(paddle==3){  
     pmtleft=6;  
     pmtright=7;  
   }  
   
   if(paddle==4){  
     pmtleft=8;  
     pmtright=9;  
   }  
   
   if(paddle==5){  
     pmtleft=10;  
     pmtright=11;  
   }  
   
   if(paddle==6){  
     pmtleft=12;  
     pmtright=13;  
   }  
   
   if(paddle==7){  
     pmtleft=14;  
     pmtright=15;  
   }  
   
   if(paddle==8){  
     pmtleft=16;  
     pmtright=17;  
   }  
   
   if(paddle==9){  
     pmtleft=18;  
     pmtright=19;  
   }  
   
   if(paddle==10){  
     pmtleft=20;  
     pmtright=21;  
   }  
   
   if(paddle==11){  
     pmtleft=22;  
     pmtright=23;  
   }  
   
   if(paddle==12){  
     pmtleft=24;  
     pmtright=25;  
   }  
   
   if(paddle==13){  
     pmtleft=26;  
     pmtright=27;  
   }  
   
   if(paddle==14){  
     pmtleft=28;  
     pmtright=29;  
   }  
   
   if(paddle==15){  
     pmtleft=30;  
     pmtright=31;  
   }  
   
   if(paddle==16){  
     pmtleft=32;  
     pmtright=33;  
   }  
   
   if(paddle==17){  
     pmtleft=34;  
     pmtright=35;  
   }  
   
   if(paddle==18){  
     pmtleft=36;  
     pmtright=37;  
   }  
   
   if(paddle==19){  
     pmtleft=38;  
     pmtright=39;  
   }  
   
   if(paddle==20){  
     pmtleft=40;  
     pmtright=41;  
   }  
   
   if(paddle==21){  
     pmtleft=42;  
     pmtright=43;  
   }  
   
   if(paddle==22){  
     pmtleft=44;  
     pmtright=45;  
   }  
   
   if(paddle==23){  
     pmtleft=46;  
     pmtright=47;  
   }  
     
740    return;    return;
741  }  }
742    
# Line 970  void ToFLevel2::GetPaddleGeometry(Int_t Line 850  void ToFLevel2::GetPaddleGeometry(Int_t
850   */   */
851  Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle)  Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle)
852  {  {
   
853    Int_t padid=-1;    Int_t padid=-1;
854    Int_t pads11=8;    Int_t pads[6]={8,6,2,2,3,3};
   Int_t pads12=6;  
   Int_t pads21=2;  
   Int_t pads22=2;  
   Int_t pads31=3;  
   //  Int_t pads32=3;  
   
855    
856    if(plane == 0){    int somma=0;
857      padid=paddle;    int np=plane;
858    }    for(Int_t j=0; j<np; j++){
859        somma+=pads[j];
   if(plane == 1){  
     padid=pads11+paddle;  
   }  
   
   if(plane == 2){  
     padid=pads11+pads12+paddle;  
   }  
   
   if(plane == 3){  
     padid=pads11+pads12+pads21+paddle;  
   }  
   
   if(plane == 4){  
     padid=pads11+pads12+pads21+pads22+paddle;  
   }  
   
   if(plane == 5){  
     padid=pads11+pads12+pads21+pads22+pads31+paddle;  
860    }    }
861      padid=paddle+somma;
862    return padid;    return padid;
863    
864  }  }
# Line 1034  void ToFLevel2::GetPaddlePlane(Int_t pad Line 889  void ToFLevel2::GetPaddlePlane(Int_t pad
889      return;      return;
890    }    }
891    
892    if(7<pad<14){    if((7<pad)&&(pad<14)){
893      plane=1;      plane=1;
894      paddle=pad-pads11;      paddle=pad-pads11;
895      return;      return;
896    }    }
897        
898    if(13<pad<16){    if((13<pad)&&(pad<16)){
899      plane=2;      plane=2;
900      paddle=pad-pads11-pads12;      paddle=pad-pads11-pads12;
901      return;      return;
902    }    }
903    
904    if(15<pad<18){    if((15<pad)&&(pad<18)){
905      plane=3;      plane=3;
906      paddle=pad-pads11-pads12-pads21;      paddle=pad-pads11-pads12-pads21;
907      return;      return;
908    }    }
909    
910    if(17<pad<21){    if((17<pad)&&(pad<21)){
911      plane=4;      plane=4;
912      paddle=pad-pads11-pads12-pads21-pads22;      paddle=pad-pads11-pads12-pads21-pads22;
913      return;      return;
914    }    }
915    
916    if(20<pad<24){    if((20<pad)&&(pad<24)){
917      plane=5;      plane=5;
918      paddle=pad-pads11-pads12-pads21-pads22-pads31;      paddle=pad-pads11-pads12-pads21-pads22-pads31;
919      return;      return;
# Line 1283  void ToFLevel2::GetLevel2Struct(cToFLeve Line 1138  void ToFLevel2::GetLevel2Struct(cToFLeve
1138        }        }
1139    } //ELENA    } //ELENA
1140  }  }
1141    
1142    
1143    //
1144    // Reprocessing tool // Emiliano 08/04/07
1145    //
1146    Int_t ToFLevel2::Process(TrkLevel2 *trk, TrigLevel2 *trg, GL_RUN *run, OrbitalInfo *orb, Bool_t force){
1147      //
1148      // Copiare qui qualcosa di simile a calonuclei per evitare di riprocessare sempre tutto
1149      //
1150    
1151    
1152    
1153    
1154      //
1155      // structures to communicate with F77
1156      //
1157      extern struct ToFInput  tofinput_;
1158      extern struct ToFOutput tofoutput_;
1159      //
1160      // DB connection
1161      //
1162      TString host;
1163      TString user;
1164      TString psw;
1165      const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
1166      const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
1167      const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
1168      if ( !pamdbhost ) pamdbhost = "";
1169      if ( !pamdbuser ) pamdbuser = "";
1170      if ( !pamdbpsw ) pamdbpsw = "";
1171      if ( strcmp(pamdbhost,"") ) host = pamdbhost;
1172      if ( strcmp(pamdbuser,"") ) user = pamdbuser;
1173      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
1174      //
1175      //
1176      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
1177      if ( !dbc->IsConnected() ) return 1;
1178      stringstream myquery;
1179      myquery.str("");
1180      myquery << "SET time_zone='+0:00'";
1181      dbc->Query(myquery.str().c_str());
1182      GL_PARAM *glparam = new GL_PARAM();
1183      glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
1184      trk->LoadField(glparam->PATH+glparam->NAME);
1185      //
1186      Bool_t defcal = true;
1187      Int_t error=glparam->Query_GL_PARAM(run->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
1188      if ( error<0 ) {
1189        return(1);
1190      };
1191      printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
1192      if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
1193      //
1194      Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
1195      rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
1196      //
1197      Int_t adc[4][12];
1198      Int_t tdc[4][12];
1199      Float_t tdcc[4][12];
1200      //
1201      // process tof data
1202      //
1203      for (Int_t hh=0; hh<12;hh++){
1204        for (Int_t kk=0; kk<4;kk++){
1205               adc[kk][hh] = 4095;
1206               tdc[kk][hh] = 4095;
1207               tdcc[kk][hh] = 4095.;
1208               tofinput_.adc[hh][kk] = 4095;
1209               tofinput_.tdc[hh][kk] = 4095;
1210        };
1211      };
1212      Int_t ntrkentry = 0;
1213      Int_t npmtentry = 0;
1214      Int_t gg = 0;
1215      Int_t hh = 0;
1216      Int_t adcf[48];
1217      memset(adcf, 0, 48*sizeof(Int_t));
1218      Int_t tdcf[48];
1219      memset(tdcf, 0, 48*sizeof(Int_t));
1220      for (Int_t pm=0; pm < this->ntrk() ; pm++){
1221         ToFTrkVar *ttf = this->GetToFTrkVar(pm);
1222         for ( Int_t nc=0; nc < ttf->npmttdc; nc++){
1223                if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1;
1224         };
1225         for ( Int_t nc=0; nc < ttf->npmtadc; nc++){
1226                if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1;
1227         };
1228      };
1229      //
1230      for (Int_t pm=0; pm < this->npmt() ; pm++){
1231         ToFPMT *pmt = this->GetToFPMT(pm);
1232         this->GetPMTIndex(pmt->pmt_id, gg, hh);
1233         if ( adcf[pmt->pmt_id] == 0 ){
1234                 tofinput_.adc[gg][hh] = (int)pmt->adc;
1235                 adc[hh][gg] = (int)pmt->adc;
1236         };
1237         if ( tdcf[pmt->pmt_id] == 0 ){
1238                 tofinput_.tdc[gg][hh] = (int)pmt->tdc;
1239                 tdc[hh][gg] = (int)pmt->tdc;
1240         };
1241         tdcc[hh][gg] = (float)pmt->tdc_tw;
1242         // Int_t pppid = this->GetPMTid(hh,gg);
1243         //      printf(" pm %i pmt_id %i pppid %i hh %i gg %i tdcc %f tdc %f adc %f \n",pm,pmt->pmt_id,pppid,hh,gg,pmt->tdc_tw,pmt->tdc,pmt->adc);
1244      };
1245      //
1246      Int_t unpackError = this->unpackError;
1247      //
1248      for (Int_t hh=0; hh<5;hh++){
1249         tofinput_.patterntrig[hh]=trg->patterntrig[hh];
1250      };
1251      //
1252      this->Clear();
1253      //
1254          Int_t pmt_id = 0;
1255          ToFPMT *t_pmt = new ToFPMT();
1256          if(!(this->PMT)) this->PMT = new TClonesArray("ToFPMT",12); //ELENA
1257          TClonesArray &tpmt = *this->PMT;
1258          ToFTrkVar *t_tof = new ToFTrkVar();
1259          if(!(this->ToFTrk)) this->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
1260          TClonesArray &t = *this->ToFTrk;
1261          //
1262          //
1263          // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related  variables.
1264          //
1265          npmtentry = 0;
1266          //
1267          ntrkentry = 0;
1268          //
1269          // Calculate tracks informations from ToF alone
1270          //
1271          tofl2com();
1272          //
1273          memcpy(this->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
1274          //
1275          t_tof->trkseqno = -1;
1276          //
1277          // and now we must copy from the output structure to the level2 class:
1278          //
1279          t_tof->npmttdc = 0;
1280          //
1281          for (Int_t hh=0; hh<12;hh++){
1282            for (Int_t kk=0; kk<4;kk++){
1283              if ( tofoutput_.tofmask[hh][kk] != 0 ){
1284                pmt_id = this->GetPMTid(kk,hh);
1285                t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1286                t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1287                t_tof->npmttdc++;
1288              };
1289            };
1290          };
1291          for (Int_t kk=0; kk<13;kk++){
1292            t_tof->beta[kk] = tofoutput_.betatof_a[kk];
1293          }
1294          //
1295          t_tof->npmtadc = 0;
1296          for (Int_t hh=0; hh<12;hh++){
1297            for (Int_t kk=0; kk<4;kk++){
1298              if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
1299                t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc);
1300                pmt_id = this->GetPMTid(kk,hh);
1301                t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1302                t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1303                t_tof->npmtadc++;
1304              };
1305            };
1306          };
1307          //
1308          memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1309          memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1310          memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1311          memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1312          //
1313          new(t[ntrkentry]) ToFTrkVar(*t_tof);
1314          ntrkentry++;
1315          t_tof->Clear();
1316          //
1317          //
1318          //
1319          t_pmt->Clear();
1320          //
1321          for (Int_t hh=0; hh<12;hh++){
1322            for (Int_t kk=0; kk<4;kk++){
1323             // new WM
1324              if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095  || tdc[kk][hh] < 4095 ){
1325    //          if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095  || tdc[kk][hh] < 4095 ){
1326                //
1327                t_pmt->pmt_id = this->GetPMTid(kk,hh);
1328                t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
1329                t_pmt->adc = (Float_t)adc[kk][hh];
1330                t_pmt->tdc = (Float_t)tdc[kk][hh];
1331                //
1332                new(tpmt[npmtentry]) ToFPMT(*t_pmt);
1333                npmtentry++;
1334                t_pmt->Clear();
1335              };
1336            };
1337          };
1338          //
1339          // Calculate track-related variables
1340          //
1341          if ( trk->ntrk() > 0 ){
1342            //
1343            // We have at least one track
1344            //
1345            //
1346            // Run over tracks
1347            //
1348            for(Int_t nt=0; nt < trk->ntrk(); nt++){
1349              //
1350              TrkTrack *ptt = trk->GetStoredTrack(nt);
1351              //
1352              // Copy the alpha vector in the input structure
1353              //
1354              for (Int_t e = 0; e < 5 ; e++){
1355                tofinput_.al_pp[e] = ptt->al[e];
1356              };
1357              //
1358              // Get tracker related variables for this track
1359              //
1360              toftrk();
1361              //
1362              // Copy values in the class from the structure (we need to use a temporary class to store variables).
1363              //
1364              t_tof->npmttdc = 0;
1365              for (Int_t hh=0; hh<12;hh++){
1366                for (Int_t kk=0; kk<4;kk++){
1367                  if ( tofoutput_.tofmask[hh][kk] != 0 ){
1368                    pmt_id = this->GetPMTid(kk,hh);
1369                    t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1370                    t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1371                    t_tof->npmttdc++;
1372                  };
1373                };
1374              };
1375              for (Int_t kk=0; kk<13;kk++){
1376                t_tof->beta[kk] = tofoutput_.beta_a[kk];
1377              };
1378              //
1379              t_tof->npmtadc = 0;
1380              for (Int_t hh=0; hh<12;hh++){
1381                for (Int_t kk=0; kk<4;kk++){
1382                  if ( tofoutput_.adc_c[hh][kk] < 1000 ){
1383                    t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc);
1384                    pmt_id = this->GetPMTid(kk,hh);
1385                    t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1386                    t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1387                    t_tof->npmtadc++;
1388                  };
1389                };
1390              };
1391              //
1392              memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1393              memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1394              memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1395              memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1396              //
1397              // Store the tracker track number in order to be sure to have shyncronized data during analysis
1398              //
1399              t_tof->trkseqno = nt;
1400              //
1401              // create a new object for this event with track-related variables
1402              //
1403              new(t[ntrkentry]) ToFTrkVar(*t_tof);
1404              ntrkentry++;
1405              t_tof->Clear();
1406              //
1407            }; // loop on all the tracks
1408          //
1409          this->unpackError = unpackError;
1410          if ( defcal ){
1411            this->default_calib = 1;
1412          } else {
1413            this->default_calib = 0;
1414          };
1415     };
1416    
1417    
1418    
1419      return(0);
1420    }

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.23