/[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.20 by mocchiut, Fri Apr 18 18:55:47 2008 UTC revision 1.21 by mocchiut, Mon May 12 14:36:08 2008 UTC
# Line 95  void CaloLevel0::SetVerbose(Bool_t ct){ Line 95  void CaloLevel0::SetVerbose(Bool_t ct){
95  /**  /**
96   * Initialize CaloLevel0 object   * Initialize CaloLevel0 object
97  **/  **/
98    void CaloLevel0::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){
99      if ( !dbc->IsConnected() ) throw -116;  
100      this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb);
101    }
102    
103    /**
104     * Initialize CaloLevel0 object
105    **/
106  void CaloLevel0::ProcessingInit(GL_TABLES *glt, 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){
107    //    //
108    const TString host = glt->CGetHost();    const TString host = glt->CGetHost();
# Line 102  void CaloLevel0::ProcessingInit(GL_TABLE Line 110  void CaloLevel0::ProcessingInit(GL_TABLE
110    const TString psw = glt->CGetPsw();    const TString psw = glt->CGetPsw();
111    TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());    TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
112    if ( !dbc->IsConnected() ) throw -116;      if ( !dbc->IsConnected() ) throw -116;  
113      this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb);
114      dbc->Close();
115      delete dbc;
116    }
117    
118    
119    void CaloLevel0::InitDo(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){
120    stringstream myquery;    stringstream myquery;
121    myquery.str("");    myquery.str("");
122    myquery << "SET time_zone='+0:00'";    myquery << "SET time_zone='+0:00'";
# Line 182  void CaloLevel0::ProcessingInit(GL_TABLE Line 197  void CaloLevel0::ProcessingInit(GL_TABLE
197    //    //
198    delete glcalo;    delete glcalo;
199    delete glroot;    delete glroot;
   dbc->Close();  
   delete dbc;  
200    //    //
201    return;    return;
202    //    //
# Line 200  Int_t CaloLevel0::ChkCalib(GL_TABLES *gl Line 213  Int_t CaloLevel0::ChkCalib(GL_TABLES *gl
213    return(sgnl);    return(sgnl);
214  }  }
215    
216    Int_t CaloLevel0::ChkParam(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){
217      Int_t sig = this->ChkParamDo(dbc,runheader,mechal);
218      return(sig);
219    }
220    
221  Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){  Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){
222    const TString host = glt->CGetHost();    const TString host = glt->CGetHost();
223    const TString user = glt->CGetUser();    const TString user = glt->CGetUser();
# Line 211  Int_t CaloLevel0::ChkParam(GL_TABLES *gl Line 229  Int_t CaloLevel0::ChkParam(GL_TABLES *gl
229    myquery << "SET time_zone='+0:00'";    myquery << "SET time_zone='+0:00'";
230    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
231    //    //
232      Int_t sig = this->ChkParamDo(dbc,runheader,mechal);
233      dbc->Close();
234      delete dbc;
235      return(sig);
236    }
237    
238    Int_t CaloLevel0::ChkParamDo(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){
239      //
240    stringstream calfile;    stringstream calfile;
241    stringstream bmfile;    stringstream bmfile;
242    stringstream aligfile;    stringstream aligfile;
# Line 221  Int_t CaloLevel0::ChkParam(GL_TABLES *gl Line 247  Int_t CaloLevel0::ChkParam(GL_TABLES *gl
247    //    //
248    if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){    if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){
249      //      //
     //  
     //  
250      if ( debug ) printf(" calopar1 %i ftcalopar1 %u ttcalopar1 %u runheader %u \n",calopar1,ftcalopar1,ttcalopar1,runheader);      if ( debug ) printf(" calopar1 %i ftcalopar1 %u ttcalopar1 %u runheader %u \n",calopar1,ftcalopar1,ttcalopar1,runheader);
251      //      //
252      calopar1 = false;      calopar1 = false;
# Line 260  Int_t CaloLevel0::ChkParam(GL_TABLES *gl Line 284  Int_t CaloLevel0::ChkParam(GL_TABLES *gl
284    };    };
285    //    //
286    if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){    if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){
287        //
288      if ( debug ) printf(" calopar2 %i ftcalopar2 %u ttcalopar2 %u runheader %u \n",calopar2,ftcalopar2,ttcalopar2,runheader);      if ( debug ) printf(" calopar2 %i ftcalopar2 %u ttcalopar2 %u runheader %u \n",calopar2,ftcalopar2,ttcalopar2,runheader);
289      calopar2 = false;      calopar2 = false;
290      //      //
# Line 367  Int_t CaloLevel0::ChkParam(GL_TABLES *gl Line 392  Int_t CaloLevel0::ChkParam(GL_TABLES *gl
392    };    };
393    //    //
394    delete glparam;    delete glparam;
   dbc->Close();  
   delete dbc;  
395    //    //
396    return(0);    return(0);
397  }  }
398    
399    Int_t CaloLevel0::CalcCrossTalkCorr(TSQLServer *dbc, UInt_t runheader){
400      Int_t sig = CalcCrossTalkCorrDo(dbc,runheader);
401      return(sig);
402    }
403    
404  Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){  Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){
   //  
   if ( ctground ) return(0);  
   //  
405    const TString host = glt->CGetHost();    const TString host = glt->CGetHost();
406    const TString user = glt->CGetUser();    const TString user = glt->CGetUser();
407    const TString psw = glt->CGetPsw();    const TString psw = glt->CGetPsw();
# Line 387  Int_t CaloLevel0::CalcCrossTalkCorr(GL_T Line 412  Int_t CaloLevel0::CalcCrossTalkCorr(GL_T
412    myquery << "SET time_zone='+0:00'";    myquery << "SET time_zone='+0:00'";
413    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
414    //    //
415      Int_t sig = CalcCrossTalkCorrDo(dbc,runheader);
416      dbc->Close();
417      delete dbc;
418      //
419      return(sig);
420      //
421    }
422    
423    Int_t CaloLevel0::CalcCrossTalkCorrDo(TSQLServer *dbc, UInt_t runheader){
424      //
425      if ( ctground ) return(0);
426      //
427    stringstream bmfile;    stringstream bmfile;
428    Int_t error = 0;    Int_t error = 0;
429    ifstream badfile;    ifstream badfile;
# Line 614  Int_t CaloLevel0::CalcCrossTalkCorr(GL_T Line 651  Int_t CaloLevel0::CalcCrossTalkCorr(GL_T
651    //    //
652    //    //
653    delete glp;    delete glp;
   dbc->Close();  
   delete dbc;  
654    //    //
655    // Ok, now we can try to calculate the cross-talk correction for each pre-amplifier    // Ok, now we can try to calculate the cross-talk correction for each pre-amplifier
656    //    //
# Line 751  void CaloLevel0::FindBaseRaw(Int_t l, In Line 786  void CaloLevel0::FindBaseRaw(Int_t l, In
786    //    //
787    Float_t minstrip = 100000.;    Float_t minstrip = 100000.;
788    Float_t rms = 0.;    Float_t rms = 0.;
789    base[l][m][pre] = 0.;    Int_t process = 0;
790    qp = 0.;    Int_t onlmask[16];
791    //    memset(onlmask, 0, 16*sizeof(Int_t));
792    for (Int_t e = pre*16; e < (pre+1)*16 ; e++){    //
793      if ( calgood[l][m][e] == 0. && obadmask[l][m][e] == 0 &&  dexy[l][m][e]-calped[l][m][e] < minstrip &&  dexy[l][m][e] > 0.) {    while ( process < 2 ){
794        minstrip = dexy[l][m][e]-calped[l][m][e];      //
795        rms = calthr[l][m][pre];      minstrip = 100000.;
796      };      rms = 0.;
797      qp += (dexy[l][m][e]-calped[l][m][e]-sbase[l][m][e]);      base[l][m][pre] = 0.;
798    };      qp = 0.;
799    //      //
800    if ( debug && l==1 ){      Int_t spos = -1;
801      printf("\n BASELINE CALCULATION for view %i pl %i pre %i: \n => minstrip %f rms %f \n => qp = %f \n",l,m,pre,minstrip,rms,qp);      Int_t ee = 0;
   };  
   if ( minstrip != 100000. ) {  
     Float_t strip6s = 0.;  
802      for (Int_t e = pre*16; e < (pre+1)*16 ; e++){      for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
803        if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) {        if ( calgood[l][m][e] == 0. && obadmask[l][m][e] == 0 &&  dexy[l][m][e]-calped[l][m][e] < minstrip &&  dexy[l][m][e] > 0. && onlmask[ee] == 0 ) {
804          strip6s += 1.;          minstrip = dexy[l][m][e]-calped[l][m][e];
805          base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]);          rms = calthr[l][m][pre];
806        };          spos = ee;
       //  
       //  compression  
       //  
       if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) {  
         dexyc[l][m][e] = 0.;  
       } else {  
         dexyc[l][m][e] = dexy[l][m][e];  
807        };        };
808          ee++;
809          qp += (dexy[l][m][e]-calped[l][m][e]-sbase[l][m][e]);
810      };      };
811      //      //
812      nst = (Int_t)strip6s;      if ( debug && l==0 ){
813      //        printf("\n BASELINE CALCULATION for view %i pl %i pre %i: \n => minstrip %f rms %f \n => qp = %f \n",l,m,pre,minstrip,rms,qp);
     if ( debug && l==1 ){  
       printf(" strip6s %f \n",strip6s);  
814      };      };
815      //  if ( strip6s >= 9. ){            if ( minstrip != 100000. ) {
816      if ( strip6s >= 2. ){                  Float_t strip6s = 0.;
817        Double_t arro = base[l][m][pre]/strip6s;        for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
818        Float_t deci = 1000.*((float)arro - float(int(arro)));                            if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) {
819        if ( deci < 500. ) {            strip6s += 1.;
820          arro = double(int(arro));            base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]);
821        } else {          };
822          arro = 1. + double(int(arro));          //
823            //  compression
824            //
825            //      if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) {
826            //        dexyc[l][m][e] = 0.;
827            //      } else {
828            dexyc[l][m][e] = dexy[l][m][e];
829              //    };
830        };        };
       base[l][m][pre] = arro;  
       //  
       // if too few strips were used to determine the baseline check if it is comparable with the previous event, if not mark it as bad  
831        //        //
832        if ( debug && l==1 ) printf(" Calculated baseline: base %f sbase*1.02 %f \n",base[l][m][pre],1.02*sbase[l][m][pre]);        if ( strip6s == 1. && process < 1 ){
833            onlmask[spos] = 1;
834            process++;
835            continue;
836          };
837          process += 2;
838          nst = (Int_t)strip6s;
839        //        //
840        if ( strip6s < 4 && base[l][m][pre] > 1.02*sbase[l][m][pre] && sbase[l][m][pre] > 0. ){        if ( debug && l==1 ){
841          if ( debug ) printf(" Suspicious calculated baseline: base %f sbase*1.02 %f strip6s %i \n",base[l][m][pre],1.02*sbase[l][m][pre],(Int_t)strip6s);          printf(" strip6s %f \n",strip6s);
842          base[l][m][pre] = 31000.;              };
843          //        if ( strip6s >= 9. ){      
844          if ( (strip6s >= 2. && process == 2) || (strip6s >= 9. && process > 2) ){    
845            Double_t arro = base[l][m][pre]/strip6s;
846            Float_t deci = 1000.*((float)arro - float(int(arro)));                
847            if ( deci < 500. ) {
848              arro = double(int(arro));
849            } else {
850              arro = 1. + double(int(arro));
851            };
852            base[l][m][pre] = arro;
853            //
854            // if too few strips were used to determine the baseline check if it is comparable with the previous event, if not mark it as bad
855            //
856            if ( debug && l==1 ) printf(" Calculated baseline: base %f sbase*1.02 %f \n",base[l][m][pre],1.02*sbase[l][m][pre]);
857            //
858            if ( strip6s < 4 && base[l][m][pre] > 1.02*sbase[l][m][pre] && sbase[l][m][pre] > 0. ){
859              if ( debug ) printf(" Suspicious calculated baseline: base %f sbase*1.02 %f strip6s %i \n",base[l][m][pre],1.02*sbase[l][m][pre],(Int_t)strip6s);
860              base[l][m][pre] = 31000.;    
861              for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
862                dexyc[l][m][e] = dexy[l][m][e];
863              };      
864            };
865          } else {
866            base[l][m][pre] = 31000.;
867            for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
868              dexyc[l][m][e] = dexy[l][m][e];
869            };
870        };        };
871      } else {      } else {
872          process += 2;
873        base[l][m][pre] = 31000.;        base[l][m][pre] = 31000.;
874        for (Int_t e = pre*16; e < (pre+1)*16 ; e++){        for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
875          dexyc[l][m][e] = dexy[l][m][e];          dexyc[l][m][e] = dexy[l][m][e];
876        };        };
877      };      };
   } else {  
     base[l][m][pre] = 31000.;  
878    };    };
879  }  }
880    
# Line 954  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 1015  Int_t CaloLevel0::Calibrate(Int_t ei){
1015          Int_t nstt[2];          Int_t nstt[2];
1016          Float_t rqp[2];          Float_t rqp[2];
1017          for (Int_t i = 0; i < 3; i++){          for (Int_t i = 0; i < 3; i++){
1018            nstt[0] = 0;            //      nstt[0] = 0; // BUG
1019            nstt[1] = 0;            //      nstt[1] = 0; // BUG
1020              nstt[0] = 1000;
1021              nstt[1] = 1000;
1022            rqp[0] = 0.;            rqp[0] = 0.;
1023            rqp[1] = 0.;            rqp[1] = 0.;
1024            for (Int_t j = 0; j < 2; j++){            for (Int_t j = 0; j < 2; j++){
# Line 984  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 1047  Int_t CaloLevel0::Calibrate(Int_t ei){
1047            //            //
1048            // if we are able to calculate the baseline with more than 3 strips on one pre and not in the other one choose the pre with more calculated strips            // if we are able to calculate the baseline with more than 3 strips on one pre and not in the other one choose the pre with more calculated strips
1049            //            //
1050            if ( nstt[0] < 4 && nstt[1] >= 4 ) base[l][m][pre-1] = 31000.;            if ( nstt[0] < 4 && nstt[1] >= 4 && nstt[0] != 1000 && nstt[1] != 1000 ) base[l][m][pre-1] = 31000.;
1051            if ( nstt[0] >= 4 && nstt[1] < 4 ) base[l][m][pre] = 31000.;            if ( nstt[0] >= 4 && nstt[1] < 4 && nstt[0] != 1000 && nstt[1] != 1000 ) base[l][m][pre] = 31000.;
1052              //      if ( nstt[0] < 4 && nstt[1] >= 4 ) base[l][m][pre-1] = 31000.;  // BUG
1053              //      if ( nstt[0] >= 4 && nstt[1] < 4 ) base[l][m][pre] = 31000.; // BUG
1054  //        //  //        //
1055  //        // if we are NOT able to calculate the baseline with more than 3 strips on both pres take the baseline (if any) of the one which has less energy  //        // if we are NOT able to calculate the baseline with more than 3 strips on both pres take the baseline (if any) of the one which has less energy
1056  //        //  //        //
# Line 1030  Int_t CaloLevel0::Calibrate(Int_t ei){ Line 1095  Int_t CaloLevel0::Calibrate(Int_t ei){
1095                      ck[pre] = 3;                      ck[pre] = 3;
1096                    };                    };
1097                  };                  };
1098                  done = 1;                  //              done = 1;
1099                };                };
1100                  done = 1;
1101              };                                };                  
1102              //              //
1103              // CALIBRATION ALGORITHM              // CALIBRATION ALGORITHM

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.23