64 |
memset(mip, 0, 2*22*96*sizeof(Float_t)); |
memset(mip, 0, 2*22*96*sizeof(Float_t)); |
65 |
memset(base, 0, 2*22*6*sizeof(Float_t)); |
memset(base, 0, 2*22*6*sizeof(Float_t)); |
66 |
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
67 |
|
memset(obadmask, 0, 2*22*96*sizeof(Int_t)); |
68 |
|
memset(obadpulsemask, 0, 2*22*6*sizeof(Int_t)); |
69 |
|
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
70 |
|
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
71 |
calopar1 = true; |
calopar1 = true; |
72 |
calopar2 = true; |
calopar2 = true; |
73 |
calopar3 = true; |
calopar3 = true; |
84 |
crosst = ct; |
crosst = ct; |
85 |
}; |
}; |
86 |
|
|
87 |
|
void CaloLevel0::SetCrossTalkType(Bool_t ct){ |
88 |
|
ctground = ct; |
89 |
|
}; |
90 |
|
|
91 |
void CaloLevel0::SetVerbose(Bool_t ct){ |
void CaloLevel0::SetVerbose(Bool_t ct){ |
92 |
verbose = ct; |
verbose = ct; |
93 |
}; |
}; |
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){ |
void CaloLevel0::ProcessingInit(GL_TABLES *glt, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
99 |
|
// |
100 |
|
const TString host = glt->CGetHost(); |
101 |
|
const TString user = glt->CGetUser(); |
102 |
|
const TString psw = glt->CGetPsw(); |
103 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
104 |
|
if ( !dbc->IsConnected() ) throw -116; |
105 |
|
stringstream myquery; |
106 |
|
myquery.str(""); |
107 |
|
myquery << "SET time_zone='+0:00'"; |
108 |
|
dbc->Query(myquery.str().c_str()); |
109 |
// |
// |
110 |
debug = isdeb; |
debug = isdeb; |
111 |
verbose = isverb; |
verbose = isverb; |
182 |
// |
// |
183 |
delete glcalo; |
delete glcalo; |
184 |
delete glroot; |
delete glroot; |
185 |
|
dbc->Close(); |
186 |
|
delete dbc; |
187 |
// |
// |
188 |
return; |
return; |
189 |
// |
// |
190 |
} |
} |
191 |
|
|
192 |
Int_t CaloLevel0::ChkCalib(TSQLServer *dbc, UInt_t atime){ |
Int_t CaloLevel0::ChkCalib(GL_TABLES *glt, UInt_t atime){ |
193 |
Int_t sgnl = 0; |
Int_t sgnl = 0; |
194 |
for ( Int_t s = 0; s < 4; s++){ |
for ( Int_t s = 0; s < 4; s++){ |
195 |
if ( atime > totime[s] ){ |
if ( atime > totime[s] ){ |
196 |
if ( !dbc->IsConnected() ) throw -116; |
sgnl = Update(glt,atime,s); |
|
sgnl = Update(dbc,atime,s); |
|
197 |
if ( sgnl < 0 ) return(sgnl); |
if ( sgnl < 0 ) return(sgnl); |
198 |
}; |
}; |
199 |
}; |
}; |
200 |
return(sgnl); |
return(sgnl); |
201 |
} |
} |
202 |
|
|
203 |
Int_t CaloLevel0::ChkParam(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){ |
Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){ |
204 |
|
const TString host = glt->CGetHost(); |
205 |
|
const TString user = glt->CGetUser(); |
206 |
|
const TString psw = glt->CGetPsw(); |
207 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
208 |
|
if ( !dbc->IsConnected() ) throw -116; |
209 |
|
stringstream myquery; |
210 |
|
myquery.str(""); |
211 |
|
myquery << "SET time_zone='+0:00'"; |
212 |
|
dbc->Query(myquery.str().c_str()); |
213 |
|
// |
214 |
stringstream calfile; |
stringstream calfile; |
215 |
stringstream bmfile; |
stringstream bmfile; |
216 |
stringstream aligfile; |
stringstream aligfile; |
252 |
for (Int_t k = 0; k < 22; k++ ){ |
for (Int_t k = 0; k < 22; k++ ){ |
253 |
for (Int_t l = 0; l < 96; l++ ){ |
for (Int_t l = 0; l < 96; l++ ){ |
254 |
fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f); |
fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f); |
255 |
if ( verbose ) printf(" %f \n",mip[m][k][l]); |
if ( debug ) printf(" %f \n",mip[m][k][l]); |
256 |
}; |
}; |
257 |
}; |
}; |
258 |
}; |
}; |
366 |
}; |
}; |
367 |
// |
// |
368 |
delete glparam; |
delete glparam; |
369 |
|
dbc->Close(); |
370 |
|
delete dbc; |
371 |
// |
// |
372 |
return(0); |
return(0); |
373 |
} |
} |
374 |
|
|
375 |
|
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ |
376 |
|
// |
377 |
|
if ( ctground ) return(0); |
378 |
|
// |
379 |
|
const TString host = glt->CGetHost(); |
380 |
|
const TString user = glt->CGetUser(); |
381 |
|
const TString psw = glt->CGetPsw(); |
382 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
383 |
|
if ( !dbc->IsConnected() ) throw -116; |
384 |
|
stringstream myquery; |
385 |
|
myquery.str(""); |
386 |
|
myquery << "SET time_zone='+0:00'"; |
387 |
|
dbc->Query(myquery.str().c_str()); |
388 |
|
// |
389 |
|
stringstream bmfile; |
390 |
|
Int_t error = 0; |
391 |
|
ifstream badfile; |
392 |
|
GL_PARAM *glparam = new GL_PARAM(); |
393 |
|
// |
394 |
|
// determine where I can find file with offline bad pulser mask |
395 |
|
// |
396 |
|
error = 0; |
397 |
|
error = glparam->Query_GL_PARAM(runheader,105,dbc); |
398 |
|
if ( error < 0 ) return(error); |
399 |
|
// |
400 |
|
bmfile.str(""); |
401 |
|
bmfile << glparam->PATH.Data() << "/"; |
402 |
|
bmfile << glparam->NAME.Data(); |
403 |
|
// |
404 |
|
if ( verbose ) printf("\n Using bad pulser offline mask file: \n %s \n\n",bmfile.str().c_str()); |
405 |
|
badfile.open(bmfile.str().c_str()); |
406 |
|
if ( !badfile ){ |
407 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: no bad pulser offline mask file!\n"); |
408 |
|
return(-115); |
409 |
|
}; |
410 |
|
// |
411 |
|
Bool_t isdone = false; |
412 |
|
Int_t bad = 0; |
413 |
|
Int_t view = 1; |
414 |
|
Int_t pre = 0; |
415 |
|
Int_t plane = 21; |
416 |
|
while ( !isdone ) { |
417 |
|
badfile >> bad; |
418 |
|
obadpulsemask[view][plane][pre] = bad; |
419 |
|
if ( debug && bad ) printf(" SETTING view %i plane %i pre %i BAD = %i \n",view,plane,pre,bad); |
420 |
|
pre++; |
421 |
|
if ( pre > 5 ){ |
422 |
|
pre = 0; |
423 |
|
plane--; |
424 |
|
if ( plane < 0 ){ |
425 |
|
plane = 21; |
426 |
|
view--; |
427 |
|
}; |
428 |
|
if ( view < 0 ) isdone = true; |
429 |
|
}; |
430 |
|
}; |
431 |
|
// |
432 |
|
delete glparam; |
433 |
|
badfile.close(); |
434 |
|
// |
435 |
|
// Let's start with cross-talk correction calculation |
436 |
|
// |
437 |
|
GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB(); |
438 |
|
Float_t adcp[2][22][96]; |
439 |
|
Float_t adcpcal[2][22][96]; |
440 |
|
memset(adcp , 0, 2*22*96*sizeof(Float_t)); |
441 |
|
memset(adcpcal , 0, 2*22*96*sizeof(Float_t)); |
442 |
|
// |
443 |
|
UInt_t pampli = 0; |
444 |
|
for (Int_t s=0; s<4; s++){ |
445 |
|
// |
446 |
|
// Save into matrix adcp the values of the highest pulse calibration (pulse amplitude = 2) |
447 |
|
// |
448 |
|
pampli = 2; |
449 |
|
error = 0; |
450 |
|
error = glp->Query_GL_CALOPULSE_CALIB(runheader,s,pampli,dbc); |
451 |
|
if ( error < 0 ){ |
452 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
453 |
|
return(error); |
454 |
|
}; |
455 |
|
// |
456 |
|
UInt_t idcalib = glp->ID_ROOT_L0; |
457 |
|
UInt_t fromtime = glp->FROM_TIME; |
458 |
|
UInt_t calibno = glp->EV_ROOT; |
459 |
|
// |
460 |
|
// determine path and name and entry of the calibration file |
461 |
|
// |
462 |
|
GL_ROOT *glroot = new GL_ROOT(); |
463 |
|
if ( verbose ) printf("\n"); |
464 |
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
465 |
|
// |
466 |
|
error = 0; |
467 |
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
468 |
|
if ( error < 0 ){ |
469 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
470 |
|
return(error); |
471 |
|
}; |
472 |
|
// |
473 |
|
stringstream name; |
474 |
|
name.str(""); |
475 |
|
name << glroot->PATH.Data() << "/"; |
476 |
|
name << glroot->NAME.Data(); |
477 |
|
// |
478 |
|
TString fcalname = (TString)name.str().c_str(); |
479 |
|
ifstream myfile; |
480 |
|
myfile.open(fcalname.Data()); |
481 |
|
if ( !myfile ){ |
482 |
|
return(-107); |
483 |
|
}; |
484 |
|
myfile.close(); |
485 |
|
// |
486 |
|
TFile *File = new TFile(fcalname.Data()); |
487 |
|
if ( !File ) return(-108); |
488 |
|
TTree *tr = (TTree*)File->Get("CalibCalPulse2"); |
489 |
|
if ( !tr ) return(-119); |
490 |
|
// |
491 |
|
TBranch *calo = tr->GetBranch("CalibCalPulse2"); |
492 |
|
// |
493 |
|
pamela::CalibCalPulse2Event *ce = 0; |
494 |
|
tr->SetBranchAddress("CalibCalPulse2", &ce); |
495 |
|
// |
496 |
|
Long64_t ncalibs = calo->GetEntries(); |
497 |
|
// |
498 |
|
if ( !ncalibs ) return(-110); |
499 |
|
// |
500 |
|
calo->GetEntry(calibno); |
501 |
|
if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); |
502 |
|
// |
503 |
|
// retrieve calibration table |
504 |
|
// |
505 |
|
if ( ce->pstwerr[s] && ce->pperror[s] == 0 && ce->unpackError == 0 ){ |
506 |
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
507 |
|
for ( Int_t j=0; j<96 ;j++){ |
508 |
|
if ( s == 2 ){ |
509 |
|
adcp[0][2*d+1][j] = ce->calpuls[3][d][j]; |
510 |
|
}; |
511 |
|
if ( s == 3 ){ |
512 |
|
adcp[0][2*d][j] = ce->calpuls[1][d][j]; |
513 |
|
}; |
514 |
|
if ( s == 0 ){ |
515 |
|
adcp[1][2*d][j] = ce->calpuls[0][d][j]; |
516 |
|
}; |
517 |
|
if ( s == 1 ){ |
518 |
|
adcp[1][2*d+1][j] = ce->calpuls[2][d][j]; |
519 |
|
}; |
520 |
|
}; |
521 |
|
}; |
522 |
|
} else { |
523 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
524 |
|
return(-111); |
525 |
|
}; |
526 |
|
// |
527 |
|
File->Close(); |
528 |
|
delete glroot; |
529 |
|
// |
530 |
|
// Save into matrix adcpcal the calibrated values of the pulse calibration (subtraction of pulse amplitude = 0 relative to the pulse2 calibration used) |
531 |
|
// |
532 |
|
pampli = 0; |
533 |
|
error = 0; |
534 |
|
error = glp->Query_GL_CALOPULSE_CALIB(fromtime,s,pampli,dbc); |
535 |
|
if ( error < 0 ){ |
536 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
537 |
|
return(error); |
538 |
|
}; |
539 |
|
// |
540 |
|
idcalib = glp->ID_ROOT_L0; |
541 |
|
calibno = glp->EV_ROOT; |
542 |
|
// |
543 |
|
// determine path and name and entry of the calibration file |
544 |
|
// |
545 |
|
glroot = new GL_ROOT(); |
546 |
|
if ( verbose ) printf("\n"); |
547 |
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
548 |
|
// |
549 |
|
error = 0; |
550 |
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
551 |
|
if ( error < 0 ){ |
552 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
553 |
|
return(error); |
554 |
|
}; |
555 |
|
// |
556 |
|
name.str(""); |
557 |
|
name << glroot->PATH.Data() << "/"; |
558 |
|
name << glroot->NAME.Data(); |
559 |
|
// |
560 |
|
fcalname = (TString)name.str().c_str(); |
561 |
|
myfile.open(fcalname.Data()); |
562 |
|
if ( !myfile ){ |
563 |
|
return(-107); |
564 |
|
}; |
565 |
|
myfile.close(); |
566 |
|
// |
567 |
|
TFile *File1 = new TFile(fcalname.Data()); |
568 |
|
if ( !File1 ) return(-108); |
569 |
|
TTree *tr1 = (TTree*)File1->Get("CalibCalPulse1"); |
570 |
|
if ( !tr1 ) return(-120); |
571 |
|
// |
572 |
|
TBranch *calo1 = tr1->GetBranch("CalibCalPulse1"); |
573 |
|
// |
574 |
|
pamela::CalibCalPulse1Event *ce1 = 0; |
575 |
|
tr1->SetBranchAddress("CalibCalPulse1", &ce1); |
576 |
|
// |
577 |
|
ncalibs = calo1->GetEntries(); |
578 |
|
// |
579 |
|
if ( !ncalibs ) return(-110); |
580 |
|
// |
581 |
|
calo1->GetEntry(calibno); |
582 |
|
if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); |
583 |
|
// |
584 |
|
// retrieve calibration table |
585 |
|
// |
586 |
|
if ( ce1->pstwerr[s] && ce1->pperror[s] == 0 && ce1->unpackError == 0 ){ |
587 |
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
588 |
|
for ( Int_t j=0; j<96 ;j++){ |
589 |
|
if ( s == 2 ){ |
590 |
|
adcpcal[0][2*d+1][j] = adcp[0][2*d+1][j] - ce1->calpuls[3][d][j]; |
591 |
|
}; |
592 |
|
if ( s == 3 ){ |
593 |
|
adcpcal[0][2*d][j] = adcp[0][2*d][j] - ce1->calpuls[1][d][j]; |
594 |
|
}; |
595 |
|
if ( s == 0 ){ |
596 |
|
adcpcal[1][2*d][j] = adcp[1][2*d][j] - ce1->calpuls[0][d][j]; |
597 |
|
}; |
598 |
|
if ( s == 1 ){ |
599 |
|
adcpcal[1][2*d+1][j] = adcp[1][2*d+1][j] - ce1->calpuls[2][d][j]; |
600 |
|
}; |
601 |
|
}; |
602 |
|
}; |
603 |
|
} else { |
604 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
605 |
|
return(-111); |
606 |
|
}; |
607 |
|
// |
608 |
|
File1->Close(); |
609 |
|
// |
610 |
|
delete glroot; |
611 |
|
// |
612 |
|
};// loop on the four sections |
613 |
|
// |
614 |
|
// |
615 |
|
delete glp; |
616 |
|
dbc->Close(); |
617 |
|
delete dbc; |
618 |
|
// |
619 |
|
// Ok, now we can try to calculate the cross-talk correction for each pre-amplifier |
620 |
|
// |
621 |
|
for ( Int_t v=0; v<2; v++){ |
622 |
|
if ( debug ) printf(" \n\n NEW VIEW \n"); |
623 |
|
for ( Int_t p=0; p<22; p++){ |
624 |
|
for ( Int_t npre=0; npre<6; npre++){ |
625 |
|
ctprecor[v][p][npre] = 1000.; |
626 |
|
ctneigcor[v][p][npre] = 1000.; |
627 |
|
Int_t str0=npre*16; |
628 |
|
Int_t str16= -1 + (1+npre)*16; |
629 |
|
// |
630 |
|
UInt_t neigc = 0; |
631 |
|
UInt_t farc = 0; |
632 |
|
UInt_t pulsc = 0; |
633 |
|
Float_t sigpulsed = 0.; |
634 |
|
Float_t neigbase = 0.; |
635 |
|
Float_t farbase = 0.; |
636 |
|
// |
637 |
|
// Loop over the strip of the pre and sum all signal far away from pulsed strip, signal in the neighbour(s) strip(s) and save the pulsed signal |
638 |
|
// moreover count the number of strips in each case |
639 |
|
// |
640 |
|
for (Int_t s=str0; s<=str16; s++){ |
641 |
|
if ( adcpcal[v][p][s] > 10000.){ |
642 |
|
sigpulsed = adcpcal[v][p][s]; |
643 |
|
pulsc++; |
644 |
|
if ( s > str0 ){ |
645 |
|
neigbase += adcpcal[v][p][s-1]; |
646 |
|
neigc++; |
647 |
|
farbase -= adcpcal[v][p][s-1]; |
648 |
|
farc--; |
649 |
|
}; |
650 |
|
if ( s < str16 ){ |
651 |
|
neigbase += adcpcal[v][p][s+1]; |
652 |
|
neigc++; |
653 |
|
farbase -= adcpcal[v][p][s+1]; |
654 |
|
farc--; |
655 |
|
}; |
656 |
|
} else { |
657 |
|
farc++; |
658 |
|
farbase += adcpcal[v][p][s]; |
659 |
|
}; |
660 |
|
}; |
661 |
|
// |
662 |
|
// Now calculate the corrections |
663 |
|
// |
664 |
|
Float_t avefarbase = 0.; |
665 |
|
if ( farc ) avefarbase = farbase/(Float_t)farc; |
666 |
|
Float_t aveneigbase = 0.; |
667 |
|
if ( neigc ) aveneigbase = neigbase/(Float_t)neigc; |
668 |
|
// |
669 |
|
if ( pulsc == 1 && farc && neigc ){ |
670 |
|
ctprecor[v][p][npre] = -avefarbase/(sigpulsed+fabs(avefarbase)); |
671 |
|
ctneigcor[v][p][npre] = fabs(aveneigbase-avefarbase)/(sigpulsed+fabs(avefarbase)); |
672 |
|
if ( debug ) printf(" Cross-talk correction View %i Plane %i Pre %i : pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
673 |
|
} else { |
674 |
|
// |
675 |
|
// did not find the pulsed strip or more than one pulsed strip found! |
676 |
|
// |
677 |
|
if ( debug ) printf(" Problems finding the cross-talk corrections: \n View %i Plane %i Pre %i number of pulsed strip %i \n Average faraway baseline %f number of strips %i Average neighbour baseline %f number of neighbour strips %i \n",v,p,npre,pulsc,avefarbase,farc,aveneigbase,neigc); |
678 |
|
// |
679 |
|
}; |
680 |
|
}; |
681 |
|
if ( debug ) printf(" \n ==================== \n"); |
682 |
|
}; |
683 |
|
}; |
684 |
|
// |
685 |
|
// Check the calculated corrections |
686 |
|
// |
687 |
|
Int_t opre=0; |
688 |
|
Int_t ppre=0; |
689 |
|
Bool_t found = false; |
690 |
|
for ( Int_t v=0; v<2; v++){ |
691 |
|
for ( Int_t p=0; p<22; p++){ |
692 |
|
for ( Int_t npre=0; npre<6; npre++){ |
693 |
|
if ( ctprecor[v][p][npre] == 1000. || ctneigcor[v][p][npre] == 1000. || obadpulsemask[v][p][npre] != 0 ){ |
694 |
|
if ( debug ) printf(" Cross-talk correction CHANGED for view %i Plane %i Pre %i\n BEFORE: pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
695 |
|
if ( npre%2 ){ |
696 |
|
opre = npre-1; |
697 |
|
} else { |
698 |
|
opre = npre+1; |
699 |
|
}; |
700 |
|
if ( ctprecor[v][p][opre] == 1000. || ctneigcor[v][p][opre] == 1000. || obadpulsemask[v][p][opre] != 0 ){ |
701 |
|
ppre=0; |
702 |
|
found = false; |
703 |
|
while ( ppre < 6 ){ |
704 |
|
if ( ctprecor[v][p][ppre] != 1000. && ctneigcor[v][p][ppre] != 1000. && !obadpulsemask[v][p][ppre] ){ |
705 |
|
found = true; |
706 |
|
ctprecor[v][p][npre] = ctprecor[v][p][ppre]; |
707 |
|
ctneigcor[v][p][npre] = ctneigcor[v][p][ppre]; |
708 |
|
break; |
709 |
|
}; |
710 |
|
ppre++; |
711 |
|
}; |
712 |
|
if ( !found ){ |
713 |
|
if ( verbose ) printf(" WARNING: cannot find a good cross-talk correction for view %i plane %i pre %i \n Setting to default values 0.002 0.002\n",v,p,npre); |
714 |
|
ctprecor[v][p][npre] = 0.002; |
715 |
|
ctneigcor[v][p][npre] = 0.002; |
716 |
|
}; |
717 |
|
} else { |
718 |
|
ctprecor[v][p][npre] = ctprecor[v][p][opre]; |
719 |
|
ctneigcor[v][p][npre] = ctneigcor[v][p][opre]; |
720 |
|
}; |
721 |
|
if ( debug ) printf(" AFTER: pre-correction: %f neighbour strips correction %f \n",ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
722 |
|
}; |
723 |
|
}; |
724 |
|
}; |
725 |
|
}; |
726 |
|
// |
727 |
|
return(0); |
728 |
|
}; |
729 |
|
|
730 |
void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ |
void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ |
731 |
Float_t minstrip = 100000.; |
Float_t minstrip = 100000.; |
783 |
// |
// |
784 |
Int_t val = 0; |
Int_t val = 0; |
785 |
Int_t del = 1100; |
Int_t del = 1100; |
786 |
|
for (Int_t sec = 0; sec < 4; sec++){ |
787 |
|
for (Int_t dsec = 0; dsec < 7; dsec++){ |
788 |
|
val = (Int_t)de->calselftrig[sec][dsec]; |
789 |
|
del = delay(val); |
790 |
|
clevel2->selfdelay[sec][dsec] = del; |
791 |
|
}; |
792 |
|
}; |
793 |
|
val = 0; |
794 |
|
del = 1100; |
795 |
if ( clevel2->trigty != 2. ){ |
if ( clevel2->trigty != 2. ){ |
796 |
Bool_t ck = false; |
Bool_t ck = false; |
797 |
for (Int_t sec = 0; sec < 4; sec++){ |
for (Int_t sec = 0; sec < 4; sec++){ |
1022 |
ipre = ip[i] - 1; |
ipre = ip[i] - 1; |
1023 |
}; |
}; |
1024 |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
1025 |
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; |
if ( !ctground ){ |
1026 |
|
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * ctprecor[l][m][ipre]; |
1027 |
|
} else { |
1028 |
|
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; |
1029 |
|
}; |
1030 |
}; |
}; |
1031 |
}; |
}; |
1032 |
if (ck == 2){ |
if (ck == 2){ |
1033 |
for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ |
for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ |
1034 |
ipre = j/16 + 1; |
ipre = j/16 + 1; |
1035 |
clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; |
if ( !ctground ){ |
1036 |
|
clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; |
1037 |
|
} else { |
1038 |
|
clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; |
1039 |
|
}; |
1040 |
}; |
}; |
1041 |
}; |
}; |
1042 |
}; |
}; |
1051 |
Int_t j4 = -4; |
Int_t j4 = -4; |
1052 |
Int_t jjj = -3; |
Int_t jjj = -3; |
1053 |
Int_t jj = -2; |
Int_t jj = -2; |
1054 |
for (Int_t j = 0 ; j < 100 ; j++){ |
Int_t jjpre = -1; |
1055 |
|
Int_t jjjpre = -1; |
1056 |
|
for (Int_t j = 0 ; j < 100 ; j++){ |
1057 |
jj++; |
jj++; |
1058 |
jjj++; |
jjj++; |
1059 |
j4++; |
j4++; |
1060 |
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
1061 |
if ( crosst ){ |
if ( crosst ){ |
1062 |
if ( jj >= 0 && jj < 96 ){ |
if ( jj >= 0 && jj < 96 ){ |
1063 |
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581; |
if ( !ctground ){ |
1064 |
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581; |
if ( jj%16 == 0 ) jjpre++; |
1065 |
|
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
1066 |
|
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
1067 |
|
} else { |
1068 |
|
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581; |
1069 |
|
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581; |
1070 |
|
}; |
1071 |
}; |
}; |
1072 |
if ( jjj >= 0 && jjj < 96 ){ |
if ( jjj >= 0 && jjj < 96 ){ |
1073 |
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581; |
if ( !ctground ){ |
1074 |
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581; |
if ( jjj%16 == 0 ) jjjpre++; |
1075 |
|
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
1076 |
|
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
1077 |
|
} else { |
1078 |
|
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581; |
1079 |
|
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581; |
1080 |
|
}; |
1081 |
}; |
}; |
1082 |
}; |
}; |
1083 |
if ( j4 >= 0 && j4 < 96 ){ |
if ( j4 >= 0 && j4 < 96 ){ |
1087 |
if ( obadmask[l][m][j4] == 1 || clevel1->estrip[j4][m][l] <= clevel1->emin || calrms[l][m][j4] > 26 ){ |
if ( obadmask[l][m][j4] == 1 || clevel1->estrip[j4][m][l] <= clevel1->emin || calrms[l][m][j4] > 26 ){ |
1088 |
clevel1->estrip[j4][m][l] = 0.; |
clevel1->estrip[j4][m][l] = 0.; |
1089 |
}; |
}; |
1090 |
// |
// |
1091 |
// code and save the energy for each strip in svstrip |
// code and save the energy for each strip in svstrip |
1092 |
// |
// |
1093 |
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
1094 |
// |
// |
1095 |
|
Float_t savel1 = clevel1->estrip[j4][m][l]; |
1096 |
|
if ( dexyc[j4][m][l] == 32767. ) savel1 += 5000.; |
1097 |
|
// |
1098 |
tim = 100000.; |
tim = 100000.; |
1099 |
plo = m; |
plo = m; |
1100 |
fbi = 0; |
fbi = 0; |
1101 |
if ( clevel1->estrip[j4][m][l] > 0.99995 ){ |
if ( savel1 > 0.99995 ){ |
1102 |
tim = 10000.; |
tim = 10000.; |
1103 |
plo = m; |
plo = m; |
1104 |
fbi = 1; |
fbi = 1; |
1105 |
}; |
}; |
1106 |
if ( clevel1->estrip[j4][m][l] > 9.9995 ){ |
if ( savel1 > 9.9995 ){ |
1107 |
tim = 1000.; |
tim = 1000.; |
1108 |
plo = 22 + m; |
plo = 22 + m; |
1109 |
fbi = 1; |
fbi = 1; |
1110 |
}; |
}; |
1111 |
if ( clevel1->estrip[j4][m][l] > 99.995 ){ |
if ( savel1 > 99.995 ){ |
1112 |
tim = 100.; |
tim = 100.; |
1113 |
plo = 22 + m; |
plo = 22 + m; |
1114 |
fbi = 0; |
fbi = 0; |
1115 |
}; |
}; |
1116 |
if ( clevel1->estrip[j4][m][l] > 999.95 ){ |
if ( savel1 > 999.95 ){ |
1117 |
tim = 10.; |
tim = 10.; |
1118 |
plo = 44 + m; |
plo = 44 + m; |
1119 |
fbi = 0; |
fbi = 0; |
1120 |
}; |
}; |
1121 |
if ( clevel1->estrip[j4][m][l] > 9999.5 ){ |
if ( savel1 > 9999.5 ){ |
1122 |
tim = 1.; |
tim = 1.; |
1123 |
plo = 66 + m; |
plo = 66 + m; |
1124 |
fbi = 0; |
fbi = 0; |
1125 |
}; |
}; |
1126 |
// |
// |
1127 |
cle = (Int_t)lroundf(tim*clevel1->estrip[j4][m][l]); |
cle = (Int_t)lroundf(tim*savel1); |
1128 |
// |
// |
1129 |
if ( l == 0 ){ |
if ( l == 0 ){ |
1130 |
// |
// |
1204 |
memcpy(t_ca->tibar,clevel2->cibar,sizeof(clevel2->cibar)); |
memcpy(t_ca->tibar,clevel2->cibar,sizeof(clevel2->cibar)); |
1205 |
memcpy(t_ca->tbar,clevel2->cbar,sizeof(clevel2->cbar)); |
memcpy(t_ca->tbar,clevel2->cbar,sizeof(clevel2->cbar)); |
1206 |
memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); |
memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); |
1207 |
|
memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay)); |
1208 |
ca->varcfit[2] = clevel2->varcfit[0]; |
ca->varcfit[2] = clevel2->varcfit[0]; |
1209 |
ca->varcfit[3] = clevel2->varcfit[1]; |
ca->varcfit[3] = clevel2->varcfit[1]; |
1210 |
ca->npcfit[2] = clevel2->npcfit[0]; |
ca->npcfit[2] = clevel2->npcfit[0]; |
1257 |
ca->selen = clevel2->selen; |
ca->selen = clevel2->selen; |
1258 |
memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq)); |
memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq)); |
1259 |
memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); |
memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); |
1260 |
|
memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay)); |
1261 |
ca->varcfit[0] = clevel2->varcfit[0]; |
ca->varcfit[0] = clevel2->varcfit[0]; |
1262 |
ca->varcfit[1] = clevel2->varcfit[1]; |
ca->varcfit[1] = clevel2->varcfit[1]; |
1263 |
ca->npcfit[0] = clevel2->npcfit[0]; |
ca->npcfit[0] = clevel2->npcfit[0]; |
1289 |
memset(dexyc, 0, 2*22*96*sizeof(Float_t)); |
memset(dexyc, 0, 2*22*96*sizeof(Float_t)); |
1290 |
memset(base, 0, 2*22*6*sizeof(Float_t)); |
memset(base, 0, 2*22*6*sizeof(Float_t)); |
1291 |
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
1292 |
|
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
1293 |
|
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
1294 |
// |
// |
1295 |
} |
} |
1296 |
|
|
1350 |
memset(clevel2->varcfit, 0, 4*sizeof(Float_t)); |
memset(clevel2->varcfit, 0, 4*sizeof(Float_t)); |
1351 |
memset(clevel2->npcfit, 0, 4*sizeof(Int_t)); |
memset(clevel2->npcfit, 0, 4*sizeof(Int_t)); |
1352 |
memset(clevel2->planemax, 0, 2*sizeof(Int_t)); |
memset(clevel2->planemax, 0, 2*sizeof(Int_t)); |
1353 |
|
memset(clevel2->selfdelay, 0, 4*7*sizeof(Int_t)); |
1354 |
memset(clevel2->fmode, 0, 2*sizeof(Int_t)); |
memset(clevel2->fmode, 0, 2*sizeof(Int_t)); |
1355 |
memset(clevel2->cibar, 0, 2*22*sizeof(Int_t)); |
memset(clevel2->cibar, 0, 2*22*sizeof(Int_t)); |
1356 |
memset(clevel2->cbar, 0, 2*22*sizeof(Float_t)); |
memset(clevel2->cbar, 0, 2*22*sizeof(Float_t)); |
1407 |
return; |
return; |
1408 |
} |
} |
1409 |
|
|
1410 |
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){ |
1411 |
// |
// |
1412 |
|
const TString host = glt->CGetHost(); |
1413 |
|
const TString user = glt->CGetUser(); |
1414 |
|
const TString psw = glt->CGetPsw(); |
1415 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
1416 |
|
if ( !dbc->IsConnected() ) throw -116; |
1417 |
|
stringstream myquery; |
1418 |
|
myquery.str(""); |
1419 |
|
myquery << "SET time_zone='+0:00'"; |
1420 |
|
dbc->Query(myquery.str().c_str()); |
1421 |
Int_t sgnl = 0; |
Int_t sgnl = 0; |
1422 |
// |
// |
1423 |
GL_CALO_CALIB *glcalo = new GL_CALO_CALIB(); |
GL_CALO_CALIB *glcalo = new GL_CALO_CALIB(); |