49 |
*/ |
*/ |
50 |
Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){ |
Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){ |
51 |
|
|
52 |
GL_TRK_CALIB q2; |
if( !CalibIsLoaded() || |
53 |
GL_ROOT q3; |
(glrun->TRK_CALIB_USED==104 && !calib104) || |
54 |
GL_PARAM q4; |
(glrun->TRK_CALIB_USED!=104 && calib104) || |
55 |
|
glrun->RUNHEADER_TIME < calib.FROM_TIME || |
56 |
if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) )return false; |
glrun->RUNHEADER_TIME > calib.TO_TIME || |
57 |
if(q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2) |
false ){ |
58 |
printf("WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2); |
|
59 |
if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) )return false; |
GL_TRK_CALIB q2; |
60 |
|
GL_ROOT q3; |
61 |
calib = q2; |
GL_PARAM q4; |
62 |
calibpathf = q3.PATH + q3.NAME; |
|
63 |
calib104 = (glrun->TRK_CALIB_USED==104); |
cout << " UPDATING calibration -- run-header time "<< glrun->RUNHEADER_TIME <<endl; |
64 |
calibload = kFALSE; |
if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) ){ |
65 |
if(calib104){ |
cout << "Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "<<endl; |
66 |
if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false; |
return false; |
67 |
calibpatht = q4.PATH + q4.NAME; |
} |
68 |
} |
if( q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2 ) |
69 |
|
printf("WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2); |
70 |
|
if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){ |
71 |
|
cout << "Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "<<endl; |
72 |
|
return false; |
73 |
|
} |
74 |
|
|
75 |
|
cout << "selected "<<q2.ID<<" from_time "<<q2.FROM_TIME<<" to time "<<q2.TO_TIME<<" --> VALIDATION "<<q2.VALIDATION<<endl; |
76 |
|
calib = q2; |
77 |
|
calibpathf = q3.PATH + q3.NAME; |
78 |
|
calib104 = (glrun->TRK_CALIB_USED==104); |
79 |
|
calibload = kFALSE; |
80 |
|
if(calib104){ |
81 |
|
if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false; |
82 |
|
calibpatht = q4.PATH + q4.NAME; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
// return TrkParams::LoadCalib(); |
// return TrkParams::LoadCalib(); |
87 |
return true; |
return true; |
88 |
|
} |
89 |
|
|
90 |
|
return false; |
91 |
}; |
}; |
92 |
|
|
93 |
/** |
/** |
94 |
|
* Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation |
95 |
|
* in YodaProfiler. |
96 |
|
*/ |
97 |
|
UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){ |
98 |
|
|
99 |
|
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
100 |
|
// UInt_t timeaftercalib=120000; //2000; |
101 |
|
TString classname = caltrk->GetName(); |
102 |
|
// ---------- |
103 |
|
// Check CRCs |
104 |
|
// ---------- |
105 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
106 |
|
cout << "DSP n. "<<caltrk->DSPnumber[ipkt]<<endl; |
107 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
108 |
|
if( caltrk->crc_hcal[ipkt] ){ |
109 |
|
cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl; |
110 |
|
// return 0; // :-( |
111 |
|
} |
112 |
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
113 |
|
cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl; |
114 |
|
// return 0; // :-( |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
// ----------------------- |
119 |
|
// Check missing packets: |
120 |
|
// ----------------------- |
121 |
|
// Readout order: |
122 |
|
// ------------------ |
123 |
|
// DSP packet board |
124 |
|
// ------------------ |
125 |
|
// 12 0 1 |
126 |
|
// 10 1 1 |
127 |
|
// 8 2 1 |
128 |
|
// 4 3 1 |
129 |
|
// 6 4 1 |
130 |
|
// 2 5 1 |
131 |
|
// ------------------ |
132 |
|
// 11 0 2 |
133 |
|
// 9 1 2 |
134 |
|
// 7 2 2 |
135 |
|
// 3 3 2 |
136 |
|
// 5 4 2 |
137 |
|
// 1 5 2 |
138 |
|
// ------------------ |
139 |
|
// ------------------------------------------------- |
140 |
|
// Check if it is first or second calibration packet |
141 |
|
// ------------------------------------------------- |
142 |
|
UInt_t build=0; |
143 |
|
UInt_t base=0; |
144 |
|
UInt_t mask=0; |
145 |
|
if(classname.Contains("CalibTrk1Event")){ |
146 |
|
base=12; |
147 |
|
mask=0x03F000; |
148 |
|
} |
149 |
|
if(classname.Contains("CalibTrk2Event")){ |
150 |
|
base=18; |
151 |
|
mask=0xFC0000; |
152 |
|
} |
153 |
|
// ------------------------------------------------- |
154 |
|
// Count number of packets and set build variable |
155 |
|
// ------------------------------------------------- |
156 |
|
Int_t npkts=0; |
157 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
158 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
159 |
|
npkts++; |
160 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
161 |
|
}; |
162 |
|
} |
163 |
|
if( npkts==6 )return 1; // :-) |
164 |
|
else cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-( ( "<<npkts<<" instead of 6 ) --> "<<endl; |
165 |
|
|
166 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
167 |
|
|
168 |
|
// ----------------------------------------------- |
169 |
|
// If missing packets: check the acq configuration |
170 |
|
// (some DSPs might be excluded from acquisition) |
171 |
|
// ----------------------------------------------- |
172 |
|
|
173 |
|
// ----------------------------------------------- |
174 |
|
// retrieve the first run header after calib |
175 |
|
// ----------------------------------------------- |
176 |
|
// PacketType *pctp; |
177 |
|
// EventCounter *cod; |
178 |
|
// cod = eh->GetCounter(); |
179 |
|
// Int_t irun = cod->Get(pctp->RunHeader); |
180 |
|
// TTree *rh=(TTree*)file->Get("RunHeader"); |
181 |
|
// if ( !rh || rh->IsZombie() ) throw -17; |
182 |
|
// if( rh->GetEntries() == irun ){ |
183 |
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
184 |
|
// return 0; // :-( |
185 |
|
// } |
186 |
|
|
187 |
|
// RunHeaderEvent *run = 0; |
188 |
|
// EventHeader *hrun = 0; |
189 |
|
// rh->SetBranchAddress("RunHeader", &run); |
190 |
|
// rh->SetBranchAddress("Header", &hrun); |
191 |
|
// rh->GetEntry(irun); |
192 |
|
// // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
193 |
|
|
194 |
|
// if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
195 |
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
196 |
|
// return 0; // :-( |
197 |
|
// } |
198 |
|
|
199 |
|
// if( !run->RM_ACQ_AFTER_CALIB ){ |
200 |
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
201 |
|
// return 0; // :-( |
202 |
|
// } |
203 |
|
|
204 |
|
// UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
205 |
|
// if( dtime > timeaftercalib ){ |
206 |
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
207 |
|
// return 0; // :-( |
208 |
|
// } |
209 |
|
|
210 |
|
// if( (run->ACQ_BUILD_INFO & mask) != build ){ |
211 |
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
212 |
|
// return 0; // :-( |
213 |
|
// } |
214 |
|
return 1; // :-) |
215 |
|
|
216 |
|
} |
217 |
|
/** |
218 |
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
219 |
*/ |
*/ |
220 |
void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
231 |
tr1->GetEntry(ev_reg1); |
tr1->GetEntry(ev_reg1); |
232 |
tr2->GetEntry(ev_reg2); |
tr2->GetEntry(ev_reg2); |
233 |
Int_t dspn1(0),dspn2(0); |
Int_t dspn1(0),dspn2(0); |
234 |
|
|
235 |
|
// --- TEST TEST TEST TEST --- // |
236 |
|
TrkParams::ValidateTrkCalib(calibdata1); |
237 |
|
TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
238 |
|
|
239 |
for(Int_t i=0;i<6;i++){ |
for(Int_t i=0;i<6;i++){ |
240 |
dspn1=calibdata1->DSPnumber[i]-1; |
dspn1=calibdata1->DSPnumber[i]-1; |
290 |
tr1->GetEntry(ev_reg1); |
tr1->GetEntry(ev_reg1); |
291 |
tr2->GetEntry(ev_reg2); |
tr2->GetEntry(ev_reg2); |
292 |
Int_t dspn1(0),dspn2(0); |
Int_t dspn1(0),dspn2(0); |
293 |
|
|
294 |
|
// --- TEST TEST TEST TEST --- // |
295 |
|
TrkParams::ValidateTrkCalib(calibdata1); |
296 |
|
TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
297 |
|
|
298 |
for(Int_t i=0;i<6;i++){ |
for(Int_t i=0;i<6;i++){ |
299 |
dspn1=calibdata1->DSPnumber[i]-1; |
dspn1=calibdata1->DSPnumber[i]-1; |
346 |
tr2->GetEntry(ev_reg2); |
tr2->GetEntry(ev_reg2); |
347 |
Int_t dspn1(0),dspn2(0); |
Int_t dspn1(0),dspn2(0); |
348 |
|
|
349 |
|
// --- TEST TEST TEST TEST --- // |
350 |
|
TrkParams::ValidateTrkCalib(calibdata1); |
351 |
|
TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
352 |
|
|
353 |
for(Int_t i=0;i<6;i++){ |
for(Int_t i=0;i<6;i++){ |
354 |
dspn1=calibdata1->DSPnumber[i]-1; |
dspn1=calibdata1->DSPnumber[i]-1; |
355 |
dspn2=calibdata2->DSPnumber[i]-1; |
dspn2=calibdata2->DSPnumber[i]-1; |
426 |
|
|
427 |
}; |
}; |
428 |
|
|
429 |
|
// Bool_t TrkParams::CalibIsLoaded(UInt_t time){ |
430 |
|
|
431 |
|
// if( !calibload ) return false; |
432 |
|
|
433 |
|
// }; |
434 |
|
|
435 |
|
|
436 |
/** |
/** |
437 |
* Static method to load calibration. |
* Static method to load calibration. |
438 |
* Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the |
* Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the |
492 |
// ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
// ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
493 |
TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
494 |
}; |
}; |
495 |
for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal_t[64][12][i] << endl; |
// for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal_t[64][12][i] << endl; |
496 |
f0_c->Close(); |
f0_c->Close(); |
497 |
// delete f0_c; |
// delete f0_c; |
498 |
cout << "--------------------------------------"<<endl; |
cout << "--------------------------------------"<<endl; |
681 |
if ( !TrkParams::Set(0,dbc) )return false; |
if ( !TrkParams::Set(0,dbc) )return false; |
682 |
dbc->Close(); |
dbc->Close(); |
683 |
}else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false; |
}else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false; |
684 |
|
|
685 |
|
return true; |
686 |
} |
} |
687 |
|
|
688 |
/** |
/** |