/** * \file TrkParams.cpp * \author Elena Vannuccini */ #include #include #include using namespace std; // ------------------------- // CALIBRATION (PED,SIG,BAD) // ------------------------- GL_TRK_CALIB TrkParams::calib = GL_TRK_CALIB(); TString TrkParams::calibpatht = ""; TString TrkParams::calibpathf = ""; Bool_t TrkParams::calib104 = 0; Bool_t TrkParams::calibload = false; // ------------------------- // PARAMETERS loaded from DB // ------------------------- UInt_t TrkParams::trkparamtype[] = {1,2,3,4,5,6,7}; GL_PARAM TrkParams::gl[] = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()}; TString TrkParams::glpath[] = {"","","","","","",""}; Bool_t TrkParams::glload[] = {false,false,false,false,false,false,false}; // ---------------- // other parameters // ---------------- cDbg TrkParams::init__dbg_mode = {0,0,0}; //int TrkParams::init__pfa = 14;//COG4 int TrkParams::init__pfa = 5;//ETAL int TrkParams::init__mini_trackmode = 0; int TrkParams::init__mini_istepmin = 5; //3; double TrkParams::init__mini_fact = 1.e4; //100.; float TrkParams::init__pfa_e234ax[] = {0.,10.,10.,15.,15.,90.}; float TrkParams::init__pfa_e234ay[] = {0.,20.,90.,90.,90.,90.}; TrkParams::TrkParams(){ cout<<"TrkParams::TrkParams()"< RUNHEADER_TIME "<RUNHEADER_TIME <TRK_CALIB_USED==104 && !calib104) || (glrun->TRK_CALIB_USED!=104 && calib104) || glrun->RUNHEADER_TIME < calib.FROM_TIME || glrun->RUNHEADER_TIME > calib.TO_TIME || false ){ // cout <<">>> isloaded? "<< CalibIsLoaded() << endl; // cout <<">>> trk_calib_used "<< glrun->TRK_CALIB_USED<>> 104 loaded? "<< calib104 <>> from time "<< calib.FROM_TIME<>> to time "<< calib.TO_TIME<IsConnected()) ){ // if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<Getenv("PAM_DBHOST"); // const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); // const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); // if ( !pamdbhost ) pamdbhost = ""; // if ( !pamdbuser ) pamdbuser = ""; // if ( !pamdbpsw ) pamdbpsw = ""; // if ( strcmp(pamdbhost,"") ) host = pamdbhost; // if ( strcmp(pamdbuser,"") ) user = pamdbuser; // if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; // if(TrkParams::VerboseMode()){ // cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<IsConnected() )return false; // if(TrkParams::VerboseMode()){ // cout << " ...done"<RUNHEADER_TIME <RUNHEADER_TIME,dbc) ){ cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "< EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2); if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){ cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "< VALIDATION "<TRK_CALIB_USED==104); calibload = kFALSE; if(calib104){ if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false; calibpatht = q4.PATH + q4.NAME; } // return TrkParams::LoadCalib(); return true; } return false; }; /** * Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation * in YodaProfiler. */ UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){ UInt_t validate = 1; Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; // UInt_t timeaftercalib=120000; //2000; TString classname = caltrk->GetName(); // ---------- // Check CRCs // ---------- if(TrkParams::VerboseMode())cout << " DSP: "; for(Int_t ipkt=0; ipkt<6; ipkt++){ if(TrkParams::VerboseMode())cout <<" "<DSPnumber[ipkt]; if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ if( caltrk->crc_hcal[ipkt] ){ if(TrkParams::WarningMode())cout<<"(CRC Header)"; // if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<crc_cal[ipkt][ilad] ){ if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ npkts++; build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); }; } if( npkts==6 ){}//return 1; // :-) else { if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "< "<GetPscuHeader()->GetOrbitalTime()<GetCounter(); // Int_t irun = cod->Get(pctp->RunHeader); // TTree *rh=(TTree*)file->Get("RunHeader"); // if ( !rh || rh->IsZombie() ) throw -17; // if( rh->GetEntries() == irun ){ // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<SetBranchAddress("RunHeader", &run); // rh->SetBranchAddress("Header", &hrun); // rh->GetEntry(irun); // // cout << classname << " "<GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<RM_ACQ_AFTER_CALIB ){ // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); // if( dtime > timeaftercalib ){ // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<ACQ_BUILD_INFO & mask) != build ){ // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<ACQ_BUILD_INFO&mask) << " != "<< build << dec<Reset(); TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); CalibTrk1Event *calibdata1 = 0; CalibTrk2Event *calibdata2 = 0; tr1->SetBranchAddress("CalibTrk1",&calibdata1); tr2->SetBranchAddress("CalibTrk2",&calibdata2); tr1->GetEntry(ev_reg1); tr2->GetEntry(ev_reg2); Int_t dspn1(0),dspn2(0); // --- TEST TEST TEST TEST --- // // TrkParams::ValidateTrkCalib(calibdata1); // TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); if( !test1 || !test2 ){ if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<DSPnumber[i]-1; dspn2=calibdata2->DSPnumber[i]-1; // cout<<"dspn1= "<Get("CalibTrk2"); CalibTrk1Event *calibdata1 = 0; CalibTrk2Event *calibdata2 = 0; tr1->SetBranchAddress("CalibTrk1",&calibdata1); tr2->SetBranchAddress("CalibTrk2",&calibdata2); tr1->GetEntry(ev_reg1); tr2->GetEntry(ev_reg2); Int_t dspn1(0),dspn2(0); // --- TEST TEST TEST TEST --- // // TrkParams::ValidateTrkCalib(calibdata1); // TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); if( !test1 || !test2 ){ if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<DSPnumber[i]-1; dspn2=calibdata2->DSPnumber[i]-1; /* cout<<"dspn1= "<Get("CalibTrk2"); CalibTrk1Event *calibdata1 = 0; CalibTrk2Event *calibdata2 = 0; tr1->SetBranchAddress("CalibTrk1",&calibdata1); tr2->SetBranchAddress("CalibTrk2",&calibdata2); tr1->GetEntry(ev_reg1); tr2->GetEntry(ev_reg2); Int_t dspn1(0),dspn2(0); // --- TEST TEST TEST TEST --- // // TrkParams::ValidateTrkCalib(calibdata1); // TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); if( !test1 || !test2 ){ if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<DSPnumber[i]-1; dspn2=calibdata2->DSPnumber[i]-1; /* cout<<"dspn1= "<SetBranchAddress("CalibTrk1",calib->GetPointerTo()); tr->GetEntry(ev_reg1); } if(i==1){ //------------------------- //read calibration packet 2 //------------------------- tr = (TTree*)f0->Get("CalibTrk2"); tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo()); tr->GetEntry(ev_reg2); } for(Int_t ipkt=0; ipktGetView(ipkt); if( (view-1)>= 0 && (view-1)<12 ){ for(Int_t ivk=0; ivkGetMean("SIG-BAD",ipkt,ivk+1); Float_t sigmin = 0.; if(view%2)sigmin = 6.5; else sigmin = 2.5; Int_t mask = 1; if( sigmmask_vk_run[ivk][view-1] = mask; } } } if(tr)tr->Delete(); } if(TrkParams::VerboseMode()){ for(Int_t iv=0; ivmask_vk_run[ivk][iv]; cout << endl; } } if(calib)calib->Delete(); }; // Bool_t TrkParams::CalibIsLoaded(UInt_t time){ // if( !calibload ) return false; // }; /** * \brief Static method to load calibration. * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens after the method TrkParams::SetCalib(***) is called. */ Bool_t TrkParams::LoadCalib( ){ if( TrkParams::CalibIsLoaded() )return false; // ============================================================= // retrieve calibration file needed to reduce data // ============================================================= // if run OBT is > last calibration "expiration date" // - search for new calibration packet // - load calibration parameters (full + truncated) if(TrkParams::VerboseMode()){ cout << "--------------------------------------"<> loading from LEVEL0 file: "<< calibpathf << endl; } FileStat_t t; if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false; bool alreadyopened = false; TFile *f0_c=0; f0_c = (TFile*)gROOT->GetListOfFiles()->FindObject(calibpathf); if(f0_c)alreadyopened=true; else f0_c = new TFile(calibpathf); if ( !f0_c ) return false; if(TrkParams::VerboseMode()){ cout << " calibration entry "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2; cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<> loading default calibration: "<< calibpatht << endl; TrkParams::FillTCalibFrom(calibpatht); }else{ // if ( !f0_c ) return false; if(TrkParams::VerboseMode())cout << ">> already loaded " << endl; // TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); }; if(!alreadyopened)f0_c->Close(); if(TrkParams::VerboseMode())cout << "--------------------------------------"<RUNHEADER_TIME < gl[index].FROM_TIME || glrun->RUNHEADER_TIME > gl[index].TO_TIME || false ){ if( !dbc || (dbc && !dbc->IsConnected()) ){ if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<Getenv("PAM_DBHOST"); const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); if ( !pamdbhost ) pamdbhost = ""; if ( !pamdbuser ) pamdbuser = ""; if ( !pamdbpsw ) pamdbpsw = ""; if ( strcmp(pamdbhost,"") ) host = pamdbhost; if ( strcmp(pamdbuser,"") ) user = pamdbuser; if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; if(TrkParams::VerboseMode()){ cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<IsConnected() )return false; if(TrkParams::VerboseMode()){ cout << " ...done"<::max(); if(glrun)runheadtime = glrun->RUNHEADER_TIME; else cout <<"Missing run info -- taking last entry "<ID<Getenv("PAM_CALIB"); if( !glpath[index].IsNull() ){ switch(type){ case 1: glpath[index].Append("/trk-param/field_param-0/"); break; case 2: glpath[index].Append("/trk-param/mip_param-0/"); break; case 3: glpath[index].Append("/trk-param/charge_param-1/"); break; case 4: glpath[index].Append("/trk-param/eta_param-0/"); break; case 5: glpath[index].Append("/trk-param/align_param-0/"); break; case 6: glpath[index].Append("/trk-param/mask_param-1/"); break; case 7: glpath[index].Append("/trk-param/default_calib/"); break; } }else{ cout << " TrkParams::Set( UInt_t type) ==> No PAMELA environment variables defined "<>"<Getenv("PAM_DBHOST"); const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); if ( !pamdbhost ) pamdbhost = ""; if ( !pamdbuser ) pamdbuser = ""; if ( !pamdbpsw ) pamdbpsw = ""; if ( strcmp(pamdbhost,"") ) host = pamdbhost; if ( strcmp(pamdbuser,"") ) user = pamdbuser; if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; if(TrkParams::VerboseMode()){ cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<IsConnected() )connected = true; else cout << " >> DB connection FAILED!!!"<Close(); }else for(Int_t i=0; i> not implemented <<"<0 )if( !TrkParams::Load(trkparamtype[i]) )return false; return true; }; Bool_t TrkParams::IsLoaded( ){ for(Int_t i=0 ; i0 )return false; return true; }; /** * Get BY (kGauss) * @param v (x,y,z) coordinates in cm */ float TrkParams::GetBX(float* v){ TrkParams::Load(1); if( !TrkParams::IsLoaded(1) )return 0.; float b[3]; gufld_(v,b); return b[0]/10.; } /** * Get BY (kGauss) * @param v (x,y,z) coordinates in cm */ float TrkParams::GetBY(float* v){ TrkParams::Load(1); if( !TrkParams::IsLoaded(1) )return 0.; float b[3]; gufld_(v,b); return b[1]/10.; } /** * Get BY (kGauss) * @param v (x,y,z) coordinates in cm */ float TrkParams::GetBZ(float* v){ TrkParams::Load(1); if( !TrkParams::IsLoaded(1) )return 0.; float b[3]; gufld_(v,b); return b[2]/10.; } /** * \brief Set tracking mode (0=standard. 1=???) */ void TrkParams::SetTrackingMode(int trackmode) { init__mini_trackmode = trackmode; SetTrackingMode(); }; /** * \brief Set fit-precision factor (typical value fact=100.) */ void TrkParams::SetPrecisionFactor(double fact){ init__mini_fact = fact; SetPrecisionFactor(); }; /** * \brief Set minimum number of step in track fitting */ void TrkParams::SetStepMin(int istepmin){ init__mini_istepmin = istepmin; SetStepMin(); }; /** * Fill F77 commons with PFA settings */ void TrkParams::SetPFA(){ sw_.pfaid = init__pfa; for(int i=0; i<6; i++){ pfa_.e234ax[i] = init__pfa_e234ax[i]; pfa_.e234ay[i] = init__pfa_e234ay[i]; } }; /** * \brief Set p.f.a. * * Implemented algorythms: * 0 ETA * 1 --- * 2 ETA2 * 3 ETA3 * 4 ETA4 * 5 ETAL ==> ETA+LANDI * 10 COG * 11 COG1 * 12 COG2 * 13 COG3 * 14 COG4 */ void TrkParams::SetPFA(int pfaid){ init__pfa = pfaid; SetPFA(); }; /** * \brief Set p.f.a. angular intervals * * This methods allows to set these amgular intervals to apply ETA2,ETA3 or ETA4 * algorythm, in case ETA or ETAL is chosen (see TrkParams::SetPFA(int pfaid)). * @param v Pointer to a vector of 12 components, which represent the * angular limits for ETA2,ETA3 and ETA4, for x and y views, respectivelly. * */ void TrkParams::SetPFA(float *v){ for(int i=0; i<6; i++){ init__pfa_e234ax[i] = v[i]; init__pfa_e234ay[i] = v[i+6]; } SetPFA(); }; /** * \brief Get spatial resolution. * * Method to retrieve the spatial resolution associated with the * adopted p.f.a. * @param view Tracker view (1-12) * @param angle Track projected angle * * In order to change p.f.a. use the SetPFA(int pfaid) method, eg.: * * TrkParams::SetPFA(0) // ETA * */ float TrkParams::GetResolution(int view, float angle){ float res = 1000; if( init__pfa == 0 )res = riseta_(&view,&angle); else cout << "float TrkParams::GetResolution(int view, float angle) -- PFA "<