741 |
// |
// |
742 |
if ( !ncalibs ) return(-110); |
if ( !ncalibs ) return(-110); |
743 |
// |
// |
744 |
calo->GetEntry(calibno); |
if ( calo->GetEntry(calibno) <= 0) throw -36; |
745 |
if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); |
if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); |
746 |
// |
// |
747 |
// retrieve calibration table |
// retrieve calibration table |
822 |
// |
// |
823 |
if ( !ncalibs ) return(-110); |
if ( !ncalibs ) return(-110); |
824 |
// |
// |
825 |
calo1->GetEntry(calibno); |
if ( calo1->GetEntry(calibno) <= 0 ) throw -36; |
826 |
if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); |
if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); |
827 |
// |
// |
828 |
// retrieve calibration table |
// retrieve calibration table |
1160 |
if ( strip6s < 4 && base[l][m][pre] > (-0.015*qp+sbase[l][m][pre]) && sbase[l][m][pre] > 0. ){ |
if ( strip6s < 4 && base[l][m][pre] > (-0.015*qp+sbase[l][m][pre]) && sbase[l][m][pre] > 0. ){ |
1161 |
if ( debug ) printf(" Suspicious calculated baseline: base %f sbase-0.02*qp %f strip6s %i \n",base[l][m][pre],(-qp*0.02+sbase[l][m][pre]),(Int_t)strip6s); |
if ( debug ) printf(" Suspicious calculated baseline: base %f sbase-0.02*qp %f strip6s %i \n",base[l][m][pre],(-qp*0.02+sbase[l][m][pre]),(Int_t)strip6s); |
1162 |
base[l][m][pre] = 31000.; |
base[l][m][pre] = 31000.; |
1163 |
|
nst = 0; // 9RED BUG |
1164 |
|
qp = 0.; // 9RED BUG |
1165 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1166 |
dexyc[l][m][e] = dexy[l][m][e]; |
dexyc[l][m][e] = dexy[l][m][e]; |
1167 |
}; |
}; |
1168 |
}; |
}; |
1169 |
} else { |
} else { |
1170 |
|
if ( debug ) printf(" reset baseline here if ! ( (strip6s >=2 && process == 2) || (strip6s >= 9 and process > 2) ) \n"); |
1171 |
base[l][m][pre] = 31000.; |
base[l][m][pre] = 31000.; |
1172 |
|
nst = 0; // 9RED BUG |
1173 |
|
qp = 0.; // 9RED BUG |
1174 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1175 |
dexyc[l][m][e] = dexy[l][m][e]; |
dexyc[l][m][e] = dexy[l][m][e]; |
1176 |
}; |
}; |
1177 |
}; |
}; |
1178 |
} else { |
} else { |
1179 |
|
if ( debug ) printf(" reset baseline here if no minimum find\n"); |
1180 |
|
nst = 0; // 9RED BUG |
1181 |
|
qp = 0.; // 9RED BUG |
1182 |
process += 2; |
process += 2; |
1183 |
base[l][m][pre] = 31000.; |
base[l][m][pre] = 31000.; |
1184 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1186 |
}; |
}; |
1187 |
}; |
}; |
1188 |
}; |
}; |
1189 |
|
if ( debug ) printf(" Baseline calculation: baseline for view %i plane %i pre %i is %f nst %i qp %f \n",l,m,pre,base[l][m][pre],nst,qp); |
1190 |
} |
} |
1191 |
|
|
1192 |
Int_t CaloLevel0::Calibrate(Int_t ei){ |
Int_t CaloLevel0::Calibrate(Int_t ei){ |
1193 |
// |
// |
1194 |
// get entry ei |
// get entry ei |
1195 |
// |
// |
1196 |
l0calo->GetEntry(ei); |
if ( l0calo->GetEntry(ei) <= 0 ) throw -36; |
1197 |
// |
// |
1198 |
// if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. |
// if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. |
1199 |
// |
// |
1262 |
// |
// |
1263 |
Float_t ener0 = 0.; |
Float_t ener0 = 0.; |
1264 |
Float_t cbase0 = 0.; |
Float_t cbase0 = 0.; |
1265 |
|
Float_t totbase = 0.; |
1266 |
|
Float_t totped = 0.; |
1267 |
Bool_t pproblem = false; |
Bool_t pproblem = false; |
1268 |
Bool_t negbase = false; |
Bool_t negbase = false; |
1269 |
// |
// |
1378 |
// |
// |
1379 |
pre = -1; |
pre = -1; |
1380 |
ener0 = 0.; |
ener0 = 0.; |
1381 |
|
totbase = 0.; |
1382 |
|
totped = 0.; |
1383 |
for (Int_t i = 0 ; i < 3 ; i++){ |
for (Int_t i = 0 ; i < 3 ; i++){ |
1384 |
ip[i] = 0; |
ip[i] = 0; |
1385 |
for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ |
for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ |
1397 |
// no suitable new baseline, use old ones! |
// no suitable new baseline, use old ones! |
1398 |
// |
// |
1399 |
if ( !done ){ |
if ( !done ){ |
1400 |
|
if ( debug ) printf(" l %i m %i pre %i ip[i] %i base %f base ip[i] %f sbase %f \n",l,m,pre,ip[i],base[l][m][pre],base[l][m][ip[i]],sbase[l][m][pre]); |
1401 |
if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ |
if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ |
1402 |
ck[l][m][pre] = 1; |
ck[l][m][pre] = 1; |
1403 |
if (pre%2 == 0) { |
if (pre%2 == 0) { |
1448 |
ener = dexyc[l][m][n]; |
ener = dexyc[l][m][n]; |
1449 |
ener0 += ener; |
ener0 += ener; |
1450 |
clevel1->estrip[n][m][l] = 0.; |
clevel1->estrip[n][m][l] = 0.; |
1451 |
|
totbase += de->base[l][m][pre]/96.; |
1452 |
|
totped += fabs(calped[l][m][n]); |
1453 |
if ( de->base[l][m][pre] < 0 ) negbase = true; |
if ( de->base[l][m][pre] < 0 ) negbase = true; |
1454 |
if ( base0>0 && base0 < 30000. ){ |
if ( base0>0 && base0 < 30000. ){ |
1455 |
// |
// |
1464 |
// |
// |
1465 |
// 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) |
1466 |
// |
// |
1467 |
|
if ( debug && l==0 && (m==17 || m==18) ) printf(" view %i plane %i strip %i ener %f calped %f base0 %f base1 %f base2 %f mip %f ENERGIA %f \n",l,m,n,ener,calped[l][m][n],base0,base1,base2,mip[l][m][n],clevel1->estrip[n][m][l]); |
1468 |
if ( clevel1->estrip[n][m][l] > 0. ) qpre[l][m][pre] += clevel1->estrip[n][m][l]; |
if ( clevel1->estrip[n][m][l] > 0. ) qpre[l][m][pre] += clevel1->estrip[n][m][l]; |
1469 |
// |
// |
1470 |
// |
// |
1474 |
}; |
}; |
1475 |
// |
// |
1476 |
// check if there were problems with 5.7 or glitches in the power supply |
// check if there were problems with 5.7 or glitches in the power supply |
1477 |
// |
// |
1478 |
if ( ((ener0 == 0. && cbase0 == 0.) || negbase ) && !pproblem && clevel2->perr[se] == 0){ |
// if ( ((ener0 == 0. && cbase0 == 0.) || negbase || totbase > 196600. || totped < 1. ) && !pproblem && clevel2->perr[se] == 0){ // check pedestal and baseline values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
1479 |
if ( verbose ) printf(" L0 entry %i : calorimeter power problems! event marked as bad perr %f swerr %X view %i plane %i \n",ei,de->perror[se],de->stwerr[se],l,m); |
if ( ((ener0 == 0. && cbase0 == 0.) || negbase || totbase > 32700. || totped < 1. ) && !pproblem && clevel2->perr[se] == 0){ // check pedestal and baseline values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
1480 |
|
if ( verbose ) printf(" L0 entry %i : calorimeter power problems! event marked as bad perr %f swerr %X view %i plane %i negbase %i totbase %f totped %f\n",ei,de->perror[se],de->stwerr[se],l,m, negbase, totbase, totped); |
1481 |
pproblem = true; |
pproblem = true; |
1482 |
pe++; |
pe++; |
1483 |
}; |
}; |
1509 |
// |
// |
1510 |
// Cross-talk corrections |
// Cross-talk corrections |
1511 |
// |
// |
1512 |
if ( crosst ){ |
if ( crosst ){ |
1513 |
// |
// |
1514 |
// energy on silicon ladders |
// energy on silicon ladders |
1515 |
// |
// |
1526 |
if ( noselfct ){ |
if ( noselfct ){ |
1527 |
for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
1528 |
ipre = j/16 ; |
ipre = j/16 ; |
1529 |
|
if ( debug ) printf(" CT STEP1 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1530 |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] -= clevel1->estrip[j][m][l] * ctprecor[l][m][ipre]; |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] -= clevel1->estrip[j][m][l] * ctprecor[l][m][ipre]; |
1531 |
|
if ( debug ) printf(" CT STEP2 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1532 |
}; |
}; |
1533 |
}; |
}; |
1534 |
// |
// |
1550 |
// |
// |
1551 |
if ( debug ) printf(" CK1 Limit for while: 0.07 \n"); |
if ( debug ) printf(" CK1 Limit for while: 0.07 \n"); |
1552 |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
1553 |
|
if ( debug ) printf(" CT STEP3 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipp]); |
1554 |
if ( !ctground ){ |
if ( !ctground ){ |
1555 |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * ctprecor[l][m][ipp]; |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * ctprecor[l][m][ipp]; |
1556 |
} else { |
} else { |
1557 |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * 0.00478; |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * 0.00478; |
1558 |
}; |
}; |
1559 |
if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; |
if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; |
1560 |
|
if ( debug ) printf(" CT STEP4 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipp]); |
1561 |
}; |
}; |
1562 |
qpre[l][m][ipre] = nqpre; |
qpre[l][m][ipre] = nqpre; |
1563 |
nqpre = 0.; |
nqpre = 0.; |
1568 |
while ( it < 10 && deltaqpre > 0.07 ){ |
while ( it < 10 && deltaqpre > 0.07 ){ |
1569 |
nqpre = 0.; |
nqpre = 0.; |
1570 |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
1571 |
|
if ( debug ) printf(" CT STEP5 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1572 |
if ( !ctground ){ |
if ( !ctground ){ |
1573 |
if ( debug ) printf(" CK1 pre correction: iteration %i deltaqpre %f ctprecor %f TOTAL CORRECTION %f \n",it,deltaqpre,ctprecor[l][m][ipre],deltaqpre * ctprecor[l][m][ipre]); |
if ( debug ) printf(" CK1 pre correction: iteration %i deltaqpre %f ctprecor %f TOTAL CORRECTION %f \n",it,deltaqpre,ctprecor[l][m][ipre],deltaqpre * ctprecor[l][m][ipre]); |
1574 |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * ctprecor[l][m][ipre]; |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * ctprecor[l][m][ipre]; |
1576 |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * 0.00478; |
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * 0.00478; |
1577 |
}; |
}; |
1578 |
if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; |
if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; |
1579 |
|
if ( debug ) printf(" CT STEP6 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1580 |
}; |
}; |
1581 |
if ( ctground ) it = 100; |
if ( ctground ) it = 100; |
1582 |
it++; |
it++; |
1683 |
nqpre[0] = 0.; |
nqpre[0] = 0.; |
1684 |
nqpre[1] = 0.; |
nqpre[1] = 0.; |
1685 |
for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
1686 |
|
if ( debug ) printf(" CT STEP6 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctsicor[l][m][si2]); |
1687 |
ipre = 0; |
ipre = 0; |
1688 |
if ( j > (ladder*32)+15 ) ipre = 1; |
if ( j > (ladder*32)+15 ) ipre = 1; |
1689 |
jpre = j/16 ; |
jpre = j/16 ; |
1699 |
}; |
}; |
1700 |
if ( clevel1->estrip[j][m][l] > 0. ) nqsi += clevel1->estrip[j][m][l] ; |
if ( clevel1->estrip[j][m][l] > 0. ) nqsi += clevel1->estrip[j][m][l] ; |
1701 |
if ( clevel1->estrip[j][m][l] > 0. ) nqpre[ipre] += clevel1->estrip[j][m][l] ; |
if ( clevel1->estrip[j][m][l] > 0. ) nqpre[ipre] += clevel1->estrip[j][m][l] ; |
1702 |
|
if ( debug ) printf(" CT STEP7 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctsicor[l][m][si2]); |
1703 |
}; |
}; |
1704 |
if ( ctground ) it = 100; |
if ( ctground ) it = 100; |
1705 |
deltaqsi = nqsi-snqsi; |
deltaqsi = nqsi-snqsi; |
|
snqsi = nqsi; |
|
|
it++; |
|
1706 |
deltaqpre[0] = nqpre[0] - qpre[l][m][pre-1]; |
deltaqpre[0] = nqpre[0] - qpre[l][m][pre-1]; |
1707 |
deltaqpre[1] = nqpre[1] - qpre[l][m][pre]; |
deltaqpre[1] = nqpre[1] - qpre[l][m][pre]; |
1708 |
|
// |
1709 |
|
// Check for divergence and stop if it happens! [9RED bug noticed with plane 18X] |
1710 |
|
// |
1711 |
|
if ( deltaqpre[0] > qpre[l][m][pre-1] || deltaqpre[1] > qpre[l][m][pre] || deltaqsi >snqsi ){ |
1712 |
|
if ( debug ) printf(" WARNING!! DIVERGING CORRECTION EXIT IMMEDIATLY FROM THE LOOP!! dqpre0 %f qpre0 %f // dqpre1 %f qpre1 %f // dqsi %f qsi %f \n",deltaqpre[0],qpre[l][m][pre-1],deltaqpre[1],qpre[l][m][pre],deltaqsi,snqsi); |
1713 |
|
it = 1000; |
1714 |
|
}; |
1715 |
|
// |
1716 |
|
snqsi = nqsi; |
1717 |
|
it++; |
1718 |
if ( debug ) printf(" BEFORE: qpre 0 %f qpre 1 %f \n",qpre[l][m][pre-1],qpre[l][m][pre]); |
if ( debug ) printf(" BEFORE: qpre 0 %f qpre 1 %f \n",qpre[l][m][pre-1],qpre[l][m][pre]); |
1719 |
qpre[l][m][pre-1] = nqpre[0]; |
qpre[l][m][pre-1] = nqpre[0]; |
1720 |
qpre[l][m][pre] = nqpre[1]; |
qpre[l][m][pre] = nqpre[1]; |
1750 |
jjj++; |
jjj++; |
1751 |
j4++; |
j4++; |
1752 |
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
1753 |
if ( crosst ){ |
if ( crosst ){ |
1754 |
// |
// |
1755 |
// "Real" crosstalk effect on the neighbour strips respect to the one which have seen the energy deposit |
// "Real" crosstalk effect on the neighbour strips respect to the one which have seen the energy deposit |
1756 |
// |
// |
1786 |
clevel1->estrip[j4][m][l] = 0.; |
clevel1->estrip[j4][m][l] = 0.; |
1787 |
}; |
}; |
1788 |
// |
// |
1789 |
|
if ( debug ) printf(" STRIP: view %i plane %i strip %i energy: %f \n",l,m,j4,clevel1->estrip[j4][m][l]); |
1790 |
|
// |
1791 |
// code and save the energy for each strip in svstrip |
// code and save the energy for each strip in svstrip |
1792 |
// |
// |
1793 |
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
1794 |
// |
// |
1795 |
Float_t savel1 = clevel1->estrip[j4][m][l]; |
Float_t savel1 = clevel1->estrip[j4][m][l]; |
1796 |
|
// |
1797 |
|
if ( m == 18 && l == 0 ){ |
1798 |
|
if ( debug ) printf(" Resetting plane 18X for variable calculation: view %i plane %i strip %i \n",l,m,j4); |
1799 |
|
clevel1->estrip[j4][m][l] = 0.; // SAVE STRIPS VALUE FOR PLANE 18 X but DO NOT USE IT FOR VARIABLE CALCULATION |
1800 |
|
}; |
1801 |
|
if ( debug ) printf(" HIT STRIP: view %i plane %i strip %i energy: %f \n",l,m,j4,clevel1->estrip[j4][m][l]); |
1802 |
// if ( dexyc[l][m][j4] == 32767. ){ |
// if ( dexyc[l][m][j4] == 32767. ){ |
1803 |
if ( dexyc[l][m][j4] > 32000. ){ |
if ( dexyc[l][m][j4] > 32000. || savel1 > 5000.){ // CaloLevel1 bug with plane 18X [9RED 14/04/2010] |
1804 |
savel1 += 5000.; |
if ( savel1 > 5000 ){ |
1805 |
|
if ( debug ) printf(" Absurd plane 18X energy... resetting value to 1100 MIP \n"); |
1806 |
|
savel1 = 1100.; // CaloLevel1 bug with plane 18x [9RED 14/04/2010] |
1807 |
|
}; |
1808 |
|
savel1 += 5000.; |
1809 |
clevel2->nsatstrip += 1.; |
clevel2->nsatstrip += 1.; |
1810 |
}; |
}; |
1811 |
// |
// |
1848 |
} else { |
} else { |
1849 |
svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); |
svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); |
1850 |
}; |
}; |
1851 |
|
if ( debug ) printf(" svstrip[%i] = %i fbi %i plo %i j4 %i cle %i \n",istrip,svstrip[istrip],fbi,plo,j4,cle); |
1852 |
// |
// |
1853 |
istrip++; |
istrip++; |
1854 |
}; |
}; |
2228 |
// |
// |
2229 |
if ( !ncalibs ) return(-110); |
if ( !ncalibs ) return(-110); |
2230 |
// |
// |
2231 |
calo->GetEntry(calibno[s]); |
if ( calo->GetEntry(calibno[s]) <= 0 ) throw -36; |
2232 |
// |
// |
2233 |
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
2234 |
for ( Int_t d=0 ; d<11 ;d++ ){ |
for ( Int_t d=0 ; d<11 ;d++ ){ |