/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp
ViewVC logotype

Diff of /DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp

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

revision 1.1 by mocchiut, Sun Mar 18 20:22:54 2007 UTC revision 1.8 by mocchiut, Wed Oct 10 16:01:30 2007 UTC
# Line 87  void CaloLevel0::SetVerbose(Bool_t ct){ Line 87  void CaloLevel0::SetVerbose(Bool_t ct){
87  /**  /**
88   * Initialize CaloLevel0 object   * Initialize CaloLevel0 object
89  **/  **/
90  void CaloLevel0::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){  void CaloLevel0::ProcessingInit(GL_TABLES *glt, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){
91      //
92      const TString host = glt->CGetHost();
93      const TString user = glt->CGetUser();
94      const TString psw = glt->CGetPsw();
95      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
96      if ( !dbc->IsConnected() ) throw -116;  
97      stringstream myquery;
98      myquery.str("");
99      myquery << "SET time_zone='+0:00'";
100      dbc->Query(myquery.str().c_str());
101    //    //
102    debug = isdeb;    debug = isdeb;
103    verbose = isverb;    verbose = isverb;
# Line 164  void CaloLevel0::ProcessingInit(TSQLServ Line 174  void CaloLevel0::ProcessingInit(TSQLServ
174    //    //
175    delete glcalo;    delete glcalo;
176    delete glroot;    delete glroot;
177      dbc->Close();
178      delete dbc;
179    //    //
180    return;    return;
181    //    //
182  }  }
183    
184  Int_t CaloLevel0::ChkCalib(TSQLServer *dbc, UInt_t atime){  Int_t CaloLevel0::ChkCalib(GL_TABLES *glt, UInt_t atime){
185    Int_t sgnl = 0;    Int_t sgnl = 0;
186    for ( Int_t s = 0; s < 4; s++){    for ( Int_t s = 0; s < 4; s++){
187      if ( atime > totime[s] ){      if ( atime > totime[s] ){
188        if ( !dbc->IsConnected() ) throw -116;        sgnl = Update(glt,atime,s);
       sgnl = Update(dbc,atime,s);  
189        if ( sgnl < 0 ) return(sgnl);        if ( sgnl < 0 ) return(sgnl);
190      };      };
191    };    };
192    return(sgnl);    return(sgnl);
193  }  }
194    
195  Int_t CaloLevel0::ChkParam(TSQLServer *dbc, UInt_t runheader){  Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){
196      const TString host = glt->CGetHost();
197      const TString user = glt->CGetUser();
198      const TString psw = glt->CGetPsw();
199      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
200      if ( !dbc->IsConnected() ) throw -116;
201      stringstream myquery;
202      myquery.str("");
203      myquery << "SET time_zone='+0:00'";
204      dbc->Query(myquery.str().c_str());
205      //
206    stringstream calfile;    stringstream calfile;
207    stringstream bmfile;    stringstream bmfile;
208    stringstream aligfile;    stringstream aligfile;
# Line 191  Int_t CaloLevel0::ChkParam(TSQLServer *d Line 212  Int_t CaloLevel0::ChkParam(TSQLServer *d
212    GL_PARAM *glparam = new GL_PARAM();    GL_PARAM *glparam = new GL_PARAM();
213    //    //
214    if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){    if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){
215        //
216        //
217        //
218        if ( debug ) printf(" calopar1 %i ftcalopar1 %u ttcalopar1 %u runheader %u \n",calopar1,ftcalopar1,ttcalopar1,runheader);
219        //
220      calopar1 = false;      calopar1 = false;
221      //      //
222      // determine where I can find calorimeter ADC to MIP conversion file        // determine where I can find calorimeter ADC to MIP conversion file  
# Line 218  Int_t CaloLevel0::ChkParam(TSQLServer *d Line 244  Int_t CaloLevel0::ChkParam(TSQLServer *d
244        for (Int_t k = 0; k < 22; k++ ){        for (Int_t k = 0; k < 22; k++ ){
245          for (Int_t l = 0; l < 96; l++ ){          for (Int_t l = 0; l < 96; l++ ){
246            fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f);            fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f);
247              if ( debug ) printf(" %f \n",mip[m][k][l]);
248          };          };
249        };        };
250      };      };
# Line 225  Int_t CaloLevel0::ChkParam(TSQLServer *d Line 252  Int_t CaloLevel0::ChkParam(TSQLServer *d
252    };    };
253    //    //
254    if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){    if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){
255        if ( debug ) printf(" calopar2 %i ftcalopar2 %u ttcalopar2 %u runheader %u \n",calopar2,ftcalopar2,ttcalopar2,runheader);
256      calopar2 = false;      calopar2 = false;
257      //      //
258      // determine where I can find calorimeter alignment file        // determine where I can find calorimeter alignment file  
# Line 240  Int_t CaloLevel0::ChkParam(TSQLServer *d Line 268  Int_t CaloLevel0::ChkParam(TSQLServer *d
268      ftcalopar2 = glparam->FROM_TIME;      ftcalopar2 = glparam->FROM_TIME;
269      ttcalopar2 = glparam->TO_TIME;      ttcalopar2 = glparam->TO_TIME;
270      //      //
271      if ( verbose ) printf("\n Using alignment file: \n %s \n",aligfile.str().c_str());      if ( verbose ) printf("\n Using parameter file: \n %s \n",aligfile.str().c_str());
272      f = fopen(aligfile.str().c_str(),"rb");      f = fopen(aligfile.str().c_str(),"rb");
273      if ( !f ){      if ( !f ){
274        if ( verbose ) printf(" CALORIMETER - ERROR: no alignement file!\n");        if ( verbose ) printf(" CALORIMETER - ERROR: no parameter file!\n");
275        return(-106);        return(-106);
276      };      };
277      //      //
278      fread(&clevel1->xalig,sizeof(clevel1->xalig),1,f);      if ( !mechal ){
279      if ( debug ) printf(" xalig = %f \n",clevel1->xalig);        //
280      fread(&clevel1->yalig,sizeof(clevel1->yalig),1,f);        fread(&clevel1->xalig,sizeof(clevel1->xalig),1,f);
281      if ( debug ) printf(" yalig = %f \n",clevel1->yalig);        if ( debug ) printf(" xalig = %f \n",clevel1->xalig);
282      fread(&clevel1->zalig,sizeof(clevel1->zalig),1,f);        fread(&clevel1->yalig,sizeof(clevel1->yalig),1,f);
283      if ( debug ) printf(" zalig = %f \n",clevel1->zalig);        if ( debug ) printf(" yalig = %f \n",clevel1->yalig);
284          fread(&clevel1->zalig,sizeof(clevel1->zalig),1,f);
285          if ( debug ) printf(" zalig = %f \n",clevel1->zalig);
286        } else {
287          if ( verbose ) printf("\n Using MECHANICAL alignement parameters \n");
288          //
289          CaloStrip cs = CaloStrip();
290          cs.UseMechanicalAlig();
291          clevel1->xalig = cs.GetXalig();
292          if ( debug ) printf(" xalig = %f \n",clevel1->xalig);
293          clevel1->yalig = cs.GetYalig();
294          if ( debug ) printf(" yalig = %f \n",clevel1->yalig);
295          clevel1->zalig = cs.GetZalig();
296          if ( debug ) printf(" zalig = %f \n",clevel1->zalig);
297          //
298          Float_t tmp = 0;
299          fread(&tmp,sizeof(clevel1->xalig),1,f);
300          fread(&tmp,sizeof(clevel1->yalig),1,f);
301          fread(&tmp,sizeof(clevel1->zalig),1,f);
302          //    
303        };
304      fread(&clevel1->emin,sizeof(clevel1->emin),1,f);        fread(&clevel1->emin,sizeof(clevel1->emin),1,f);  
305      if ( debug ) printf(" signal threshold = %f \n",clevel1->emin);      if ( debug ) printf(" signal threshold = %f \n",clevel1->emin);
306      //      //
# Line 262  Int_t CaloLevel0::ChkParam(TSQLServer *d Line 310  Int_t CaloLevel0::ChkParam(TSQLServer *d
310    // Load offline bad strip mask    // Load offline bad strip mask
311    //    //
312    if ( calopar3 || ( ttcalopar3 != 0 && ttcalopar3 < runheader ) ){    if ( calopar3 || ( ttcalopar3 != 0 && ttcalopar3 < runheader ) ){
313        if ( debug ) printf(" calopar3 %i ftcalopar3 %u ttcalopar3 %u runheader %u \n",calopar3,ftcalopar3,ttcalopar3,runheader);
314      calopar3 = false;      calopar3 = false;
315      //      //
316      // determine where I can find calorimeter alignment file        // determine where I can find calorimeter alignment file  
# Line 309  Int_t CaloLevel0::ChkParam(TSQLServer *d Line 358  Int_t CaloLevel0::ChkParam(TSQLServer *d
358    };    };
359    //    //
360    delete glparam;    delete glparam;
361      dbc->Close();
362      delete dbc;
363    //    //
364    return(0);    return(0);
365  }  }
# Line 371  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 422  Int_t CaloLevel0::Calibrate(Int_t ei){
422    //    //
423    Int_t val = 0;    Int_t val = 0;
424    Int_t del = 1100;    Int_t del = 1100;
425      for (Int_t sec = 0; sec < 4; sec++){
426        for (Int_t dsec = 0; dsec < 7; dsec++){
427          val = (Int_t)de->calselftrig[sec][dsec];
428          del = delay(val);
429          clevel2->selfdelay[sec][dsec] = del;
430        };
431      };
432      val = 0;
433      del = 1100;
434    if ( clevel2->trigty != 2. ){    if ( clevel2->trigty != 2. ){
435      Bool_t ck = false;      Bool_t ck = false;
436      for (Int_t sec = 0; sec < 4; sec++){      for (Int_t sec = 0; sec < 4; sec++){
# Line 432  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 492  Int_t CaloLevel0::Calibrate(Int_t ei){
492    for (Int_t l = 0; l < 2; l++){    for (Int_t l = 0; l < 2; l++){
493      for (Int_t m = 0; m < 22; m++){      for (Int_t m = 0; m < 22; m++){
494        //        //
495        // determine the section number        // determine the section number  
496        //        //
497        se = 5;        se = 5;
498        if (l == 0 && m%2 == 0) se = 3;        if (l == 0 && m%2 == 0) se = 3;
499        if (l == 0 && m%2 != 0) se = 2;        if (l == 0 && m%2 != 0) se = 2;
500        if (l == 1 && m%2 == 0) se = 1;        if (l == 1 && m%2 != 0) se = 1;
501        if (l == 1 && m%2 != 0) se = 0;                  if (l == 1 && m%2 == 0) se = 0;          
502        //        //
503        // determine what kind of event we are going to analyze        // determine what kind of event we are going to analyze
504        //        //
# Line 532  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 592  Int_t CaloLevel0::Calibrate(Int_t ei){
592                  } else {                  } else {
593                    ip[i] = pre - 1;                    ip[i] = pre - 1;
594                  };                  };
595                  if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0.) ){                  if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0. || !crosst ) ){
596                    //                    //
597                    ck = 2;                    ck = 2;
598                    if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) {                    if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) {
# Line 546  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 606  Int_t CaloLevel0::Calibrate(Int_t ei){
606              // CALIBRATION ALGORITHM              // CALIBRATION ALGORITHM
607              //              //
608              if ( !doneb ){              if ( !doneb ){
609                  if ( debug ) printf(" ck is %i \n",ck);
610                switch (ck) {                switch (ck) {
611                case 0:                case 0:
612                  base0 = base[l][m][pre];                  base0 = base[l][m][pre];
613                  base2 = calbase[l][m][pre];                  base2 = calbase[l][m][pre];
614                    if ( debug ) printf(" base0 = base l m pre = %f base2 = calbase l m pre = %f \n",base[l][m][pre],calbase[l][m][pre]);
615                  break;                  break;
616                case 1:                case 1:
617                  base0 = base[l][m][ip[i]];                  base0 = base[l][m][ip[i]];
618                  base2 = calbase[l][m][ip[i]];                  base2 = calbase[l][m][ip[i]];
619                    if ( debug ) printf(" base0 = base l m ip(i) = %f base2 = calbase l m ip(i) = %f \n",base[l][m][ip[i]],calbase[l][m][ip[i]]);
620                  break;                  break;
621                case 2:                case 2:
622                  base0 = sbase[l][m][pre];                  base0 = sbase[l][m][pre];
623                  base2 = calbase[l][m][pre];                  base2 = calbase[l][m][pre];    
624                    if ( debug ) printf(" base0 = sbase l m pre = %f base2 = calbase l m pre = %f \n",sbase[l][m][pre],calbase[l][m][pre]);
625                  break;                  break;
626                case 3:                case 3:
627                  base0 = calbase[l][m][pre];                  base0 = calbase[l][m][pre];
628                  base2 = calbase[l][m][pre];                  base2 = calbase[l][m][pre];
629                    if ( debug ) printf(" base0 = calbase l m pre = %f base2 = calbase l m pre = %f \n",calbase[l][m][pre],calbase[l][m][pre]);
630                  break;                  break;
631                };                };
632                base1 = calbase[l][m][pre];                base1 = calbase[l][m][pre];
# Line 571  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 636  Int_t CaloLevel0::Calibrate(Int_t ei){
636              ener0 += ener;              ener0 += ener;
637              clevel1->estrip[n][m][l] = 0.;              clevel1->estrip[n][m][l] = 0.;
638              if ( base0>0 && base0 < 30000. ){              if ( base0>0 && base0 < 30000. ){
639                if ( !donec && (base0 - base1 + base2) != 0. ){                //              if ( !donec && (base0 - base1 + base2) != 0. ){
640                  sbase[l][m][pre] = base0 - base1 + base2;                //                sbase[l][m][pre] = base0 - base1 + base2;
641                  if ( !donec && (base0 + base1 - base2) != 0. ){
642                    sbase[l][m][pre] = base0 + base1 - base2;
643                  donec = 1;                  donec = 1;
644                };                };
645                if ( ener > 0. ){                if ( ener > 0. ){
# Line 581  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 648  Int_t CaloLevel0::Calibrate(Int_t ei){
648                  // OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course)                  // OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course)
649                  //                  //
650                  qpre[pre] += clevel1->estrip[n][m][l];                  qpre[pre] += clevel1->estrip[n][m][l];
651                    //
652                    //
653                };                };
654              };              };
655            };            };
# Line 749  void CaloLevel0::FillTrkVar(CaloLevel2 * Line 818  void CaloLevel0::FillTrkVar(CaloLevel2 *
818      memcpy(t_ca->tibar,clevel2->cibar,sizeof(clevel2->cibar));      memcpy(t_ca->tibar,clevel2->cibar,sizeof(clevel2->cibar));
819      memcpy(t_ca->tbar,clevel2->cbar,sizeof(clevel2->cbar));      memcpy(t_ca->tbar,clevel2->cbar,sizeof(clevel2->cbar));
820      memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax));      memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax));
821        memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay));
822      ca->varcfit[2] = clevel2->varcfit[0];      ca->varcfit[2] = clevel2->varcfit[0];
823      ca->varcfit[3] = clevel2->varcfit[1];      ca->varcfit[3] = clevel2->varcfit[1];
824      ca->npcfit[2] = clevel2->npcfit[0];      ca->npcfit[2] = clevel2->npcfit[0];
# Line 801  void CaloLevel0::FillCommonVar(CaloLevel Line 871  void CaloLevel0::FillCommonVar(CaloLevel
871    ca->selen = clevel2->selen;    ca->selen = clevel2->selen;
872    memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq));    memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq));
873    memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax));    memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax));
874      memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay));
875    ca->varcfit[0] = clevel2->varcfit[0];    ca->varcfit[0] = clevel2->varcfit[0];
876    ca->varcfit[1] = clevel2->varcfit[1];    ca->varcfit[1] = clevel2->varcfit[1];
877    ca->npcfit[0] = clevel2->npcfit[0];    ca->npcfit[0] = clevel2->npcfit[0];
# Line 891  void CaloLevel0::ClearCommonVar(){ Line 962  void CaloLevel0::ClearCommonVar(){
962    memset(clevel2->varcfit, 0, 4*sizeof(Float_t));    memset(clevel2->varcfit, 0, 4*sizeof(Float_t));
963    memset(clevel2->npcfit, 0, 4*sizeof(Int_t));    memset(clevel2->npcfit, 0, 4*sizeof(Int_t));
964    memset(clevel2->planemax, 0, 2*sizeof(Int_t));    memset(clevel2->planemax, 0, 2*sizeof(Int_t));
965      memset(clevel2->selfdelay, 0, 4*7*sizeof(Int_t));
966    memset(clevel2->fmode, 0, 2*sizeof(Int_t));    memset(clevel2->fmode, 0, 2*sizeof(Int_t));
967    memset(clevel2->cibar, 0, 2*22*sizeof(Int_t));    memset(clevel2->cibar, 0, 2*22*sizeof(Int_t));
968    memset(clevel2->cbar, 0, 2*22*sizeof(Float_t));    memset(clevel2->cbar, 0, 2*22*sizeof(Float_t));
# Line 947  void CaloLevel0::ClearCalibVals(Int_t s) Line 1019  void CaloLevel0::ClearCalibVals(Int_t s)
1019    return;    return;
1020  }  }
1021    
1022  Int_t CaloLevel0::Update(TSQLServer *dbc, UInt_t atime, Int_t s){  Int_t CaloLevel0::Update(GL_TABLES *glt, UInt_t atime, Int_t s){
1023    //    //
1024      const TString host = glt->CGetHost();
1025      const TString user = glt->CGetUser();
1026      const TString psw = glt->CGetPsw();
1027      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
1028      if ( !dbc->IsConnected() ) throw -116;
1029      stringstream myquery;
1030      myquery.str("");
1031      myquery << "SET time_zone='+0:00'";
1032      dbc->Query(myquery.str().c_str());
1033    Int_t sgnl = 0;    Int_t sgnl = 0;
1034    //    //
1035    GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();    GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.23