20 host = gSystem->HostName();
33 cout<<
"<hLabHelper:: hLabHelper > Initializing as primary with "<<
ACTIVECHANNELS<<
" active channels"<<endl;
38 cout<<
"<hLabHelper:: hLabHelper> Initializing as secondary";
41 TString
fN =
"hcalHelper_"; fN += T.GetDate(); fN +=
"_"; fN += T.GetTime(); fN +=
".root";
43 cout<<
"<hLabHelper:: hLabHelper> ROOT graphic objects will be written into TFile "<<
rootTempFileName<<endl;
47 cout<<
"<runToRootFile> : File "<<
rootTempFileName<<
" still does not exist"<<endl;
48 }
else {cout<<
"<hLabHelper:: hLabHelper> ROOT file "<<
rootTempFileName<<
" created"<<endl;}
68 rdata =
new TH2F(
"rdata",
"Raw Peak Values for all active channels",ACTIVECHANNELS, 0, ACTIVECHANNELS, 1024, -2048., 2048.);
88 for (
int ig = 0; ig<2; ig++){
91 TString
sum =
"adcsum_"; sum += (ig==
HIGH)?
"HG" :
"LG";
92 TString sig =
"signal_"; sig += (ig==
HIGH)?
"HG" :
"LG";
103 if(rn<=0)
return false;
106 cout<<
"<setPRDFRun> Failed to find the .prdf file for run number "<<rn<<endl;
114 cout <<
"Couldn't open input file " <<
prdfName << endl;
132 gStyle->SetOptFit(111);
133 gStyle->SetFitFormat(
"5.2g");
135 TCanvas * evdisplay[panels];
136 TString cnvsName =
"EvDisplay_";
137 TString cnvsTitle =
"sPhenix Channel display for CHANNELS ";
138 for (
int iC = 0; iC < panels; iC++) {
139 TString cN = cnvsName;
141 TString cT = cnvsTitle;
142 cT += (chperpanel*iC);
144 cT += (chperpanel*(iC+1)-1);
145 evdisplay[iC] =
new TCanvas(cN, cT, 300*nx_c, 150*ny_c);
146 evdisplay[iC]->SetEditable(kTRUE);
147 evdisplay[iC]->Divide(nx_c,ny_c);
157 TString
name =
"gch"; name += ich;
158 gpulse[ich]->SetName(name);
159 name =
"Channel "; name += ich; name +=
" / "; name +=
feechinsp[ich]; name += (
feechinsp[ich]%2==
HIGH?
" HG" :
" LG");
160 gpulse[ich]->SetTitle(name);
161 gpulse[ich]->SetMarkerStyle(20);
162 gpulse[ich]->SetMarkerSize(0.4);
174 cout <<
"eventseq " <<
eventseq <<
" event type = " << evt->
getEvtType() <<
" ignored "<< endl;
200 int iC = ich/chperpanel;
201 int iPad = (ich-chperpanel*iC);
203 int iPy = ny_c - iPad/nx_c - 1;
204 iPad = iPy*nx_c + iPx + 1;
205 evdisplay[iC] ->cd(iPad);
218 for (
int iC = 0; iC < panels; iC++) evdisplay[iC]->Update();
224 }
else cout<<
"<evDisplay> Packet hbd not found. EventSeq "<<
eventseq<<
" EventType "<< evt->
getEvtType()<<endl;
228 cout<<
"<evDisplay> EoF reached "<<endl;
241 cout<<
"hLabHelper::setRunKind> will look for run data in "<<
runKind<<endl;
254 cout<<
"<hLabHelper::getFileLists> "<<
rootdirname<<endl;
255 cout<<
"<hLabHelper::getFileLists> "<<
prdfdirname<<endl;
258 cout<<
"hLabHelper::getFileLists> PRDF Directory name updated "<<
prdfdirname<<endl;
262 TList * rootfiles = rdir.GetListOfFiles();
263 TList * prdffiles = pdir.GetListOfFiles();
269 TIter
next(rootfiles);
270 while((file = (TSystemFile *)
next())) {
271 fname = file->GetName();
272 if(!file->IsDirectory() && fname.EndsWith(
".root")) {
289 TIter
next(prdffiles);
290 while((file = (TSystemFile *)
next())) {
291 fname = file->GetName();
293 if(!file->IsDirectory() && fname.EndsWith(
".prdf")) {
308 cout<<
"<getFileLists> .root files found "<<
roots.size()<<
" .prdf files found "<<
prdfs.size()<<endl;
313 if(fname.Contains(
".root") || fname.Contains(
".prdf")) {
316 rid.ReplaceAll(
".root",
""); rid.ReplaceAll(
".prdf",
"");
317 Ssiz_t lastslash = rid.Last(
'/');
318 rid.Remove(0,lastslash+1);
319 rid.ReplaceAll(
"HClab_",
""); rid.ReplaceAll(
"rc-",
""); rid.ReplaceAll(
"cosmics_",
""); rid.ReplaceAll(
"beam_",
"");
322 id.Remove(rid.Last(
'-'));
331 cout<<
"<attachrootrun> No .root files in the list: Collecting "<<endl;
335 std::list<rootfile>::iterator
it =
roots.begin();
337 while (it!=
roots.end()) {
339 if(it->runnumber==rn) {
342 cout<<
"<hLabHelper::attachrootrun> ROOT file with "<<
runId<<
" identifier found: "<<it->name<<endl;
344 return new TFile(it->name);
347 cout<<
"<hLabHelper::attachrootrun> Requested ROOT file for Run "<<rn<<
" not found"<<endl;
364 if(run<=0)
return false;
367 cout<<
"<setPRDFRun> Failed to find the .prdf file for run number "<<run<<endl;
379 cout<<
"<setROOTRun> Failed to find the .root file for run number "<<run<<endl;
392 cout<<
"<runToRootFile> WARNING : Requested run number = "<<run<<endl;
393 TSeqCollection * sq = gROOT->GetListOfFiles();
397 TString current = ((TObject *)(sq->First()))->GetName();
399 if(current.Contains(
".root")) {
400 cout<<
"<hLabHelper::runToRootFile> : attached .root file "<<current<<
" found"<<endl;
403 runId.ReplaceAll(
".root",
"");
404 Ssiz_t lastslash =
runId.Last(
'/');
405 runId.Remove(0,lastslash+1);
406 runId.ReplaceAll(
"HClab_",
"");
408 rn.Remove(rn.Last(
'-'));
417 cout<<
"<runToRootFile> : looking into .root directory for runnumber "<<run<<endl;
424 fname +=
"HClab_"; fname +=
runId; fname +=
".root";
425 if(gSystem->GetPathInfo(fname, buf)) {
428 fname +=
"HClab_"; fname +=
runId; fname +=
".root";
430 if(gSystem->GetPathInfo(fname, buf)) {
431 cout<<
"<runToRootFile> : File "<<fname<<
" does not exist"<<endl;
432 }
else cout<<
"<runToRootFile> : File "<<fname<<
" already exist and will be recreated"<<endl;
437 cout<<
"<hLabHelper:: runToRootFile> found temporaly root file "<<
rootTempFileName<<endl; }
else {
439 cout<<
"hLabHelper:: runToRootFile> "<<
rootfName<<
" opened"<<endl;
454 cout<<
"hLabHelper::runToPRDFFile> PRDF Directory name updated "<<
prdfName<<endl;
461 fname +=
runKind; fname +=
"_";
462 fname +=
runId; fname +=
".prdf";
463 if(gSystem->GetPathInfo(fname, buf)) {
468 fname +=
runKind; fname +=
"_";
469 fname +=
runId; fname +=
".prdf";
470 if(gSystem->GetPathInfo(fname, buf)) {
471 cout<<
"<runToPRDFFile> File "<<fname<<
" with runId "<<
runId<<
" does not exist"<<endl;
477 cout<<
"<runToPRDFFile> Parsed prdf file name "<<
prdfName<<endl;
493 cout<<
"<hLabHelper::initPRDFRun> Cant instantiate run with runnumber = 0. Exiting"<<endl;
499 gROOT->SetStyle(
"Plain");
508 TString fhn =
"ft_"; fhn += ich; TString fht =
"Fitted pulse peak time CH="; fht += ich;
509 ft[ich] =
new TH1F(fhn, fht, 100, 0.,
NSAMPLES);
510 fhn =
"fm_"; fhn += ich; fht =
"Fitted pulse amplitude CH="; fht += ich;
511 fm[ich] =
new TH1F(fhn, fht, 4100, 0., 4100.);
512 fhn =
"fw_"; fhn += ich; fht =
"Fitted pulse width CH="; fht += ich;
513 fw[ich] =
new TH1F(fhn, fht, 100, 0., 5.);
514 fhn =
"fpd_"; fhn += ich; fht =
"Fitted pedestal at t=PEAK CH="; fht += ich;
515 fpd[ich] =
new TH1F(fhn, fht, 200, 2000., 2100.);
516 fhn =
"fint_"; fhn += ich; fht =
"Integral of fitted curve (pedestal suppressed) CH="; fht += ich;
517 fint[ich] =
new TH1F(fhn, fht, 4000, 0., 4000.);
518 fhn =
"fchi2_";fhn += ich; fht =
"Chi2 of fit CH="; fht += ich;
519 fchi2[ich] =
new TH1F(fhn, fht, 500, 0., 100.);
521 for(
int ip=0; ip<
NPARAMETERS; ip++){ TString phn =
"p_"; phn += ip; phn +=
"_"; phn += ich;
522 TString pht =
"Fit Parameter "; pht += ip; pht +=
" Channel "; pht += ich;
526 TString rvn =
"rv_"; rvn += ich; TString rvt =
"Raw peak value CH = "; rvt += ich;
527 rpeak[ich] =
new TH1F(rvn, rvt, 4100, 0., 4100.);
528 TString rtn =
"rt_"; rtn += ich; TString rtt =
"Raw peak time CH = "; rtt += ich;
532 TString fn =
"S_"; fn += ich;
551 name =
"gch"; name += ich;
552 gpulse[ich]->SetName(name);
553 gpulse[ich]->SetMarkerStyle(20);
554 gpulse[ich]->SetMarkerSize(0.4);
566 cout<<
"<hLabHelper::copyAndCloseRootFile> Renamed "<<endl;
580 cout<<
"<hLabHelper::makeCanvasDirectory> Directory "<<
cDirectory<<
" already exists "<<endl;
583 TString command =
"mkdir "; command +=
cDirectory;
584 gSystem->Exec(command);
585 cout<<
"<hLabHelper::makeCanvasDirectory> Directory "<<
cDirectory<<
" created "<<endl;
593 TString fitName =
active[ich]%2?
"HG_" :
"LG_";
608 Int_t rMaxVal =
adc[ich][iss]; Int_t maxsmpl = iss;
609 Int_t rMinVal =
adc[ich][iss]; Int_t minsmpl = iss;
611 for (
int is = iss; is<=ise; is++) {
612 if(
adc[ich][is]>rMaxVal) {
613 rMaxVal =
adc[ich][is];
616 if(
adc[ich][is]<rMinVal) {
617 rMinVal =
adc[ich][is];
623 if(abs(rMinVal) > abs(rMaxVal)) {
624 rVal = rMinVal; rTime = minsmpl;
626 rVal = rMaxVal; rTime = maxsmpl;
675 gpulse[ich]->SetPoint(is,(Double_t)is,
adc[ich][is]);
686 Int_t rMaxVal =
adc[ich][iss]; Int_t maxsmpl = iss;
687 Int_t rMinVal =
adc[ich][iss]; Int_t minsmpl = iss;
689 for (
int is = iss; is<=ise; is++) {
690 if(
adc[ich][is]>rMaxVal) {
691 rMaxVal =
adc[ich][is];
694 if(
adc[ich][is]<rMinVal) {
695 rMinVal =
adc[ich][is];
700 if(abs(rMinVal) > abs(rMaxVal)) {
701 rVal = rMinVal; rTime = minsmpl;
703 rVal = rMaxVal; rTime = maxsmpl;
714 sigFit[ich]->SetParameter(4, 0.);
715 sigFit[ich]->SetParameter(5, 0.);
723 Double_t pVal = rVal;
724 Double_t pTime = rTime;
725 if(tmp!=0&&abs(sgp)>abs(sgn)) {
736 Double_t pInt = (pVal!=0?
sigFit[ich]->Integral(xmin, xmax) : 0);
749 Double_t mom2 = (pVal!=0?
sigFit[ich]->CentralMoment(2, xmin, xmax) : 0.);
753 Double_t
rms = sqrt(mom2);
775 for(
int is = 0; is <
NSAMPLES; is++){
783 for (
int is = 0; is <
NSAMPLES; is++) {
787 Double_t rVal, rTime;
788 for(
int ig = 0; ig<2; ig++) {
790 Int_t rMaxVal =
evtadcsum[ig][iss]; Int_t maxsmpl = iss;
791 Int_t rMinVal =
evtadcsum[ig][iss]; Int_t minsmpl = iss;
793 for (
int is = iss; is<=ise; is++) {
804 cout<<
"getDetectorTiming: Event "<<
eventseq<<
" Gain "<<ig<<
" Min "<<minsmpl<<
" / "<<rMinVal<<
" Max "<<maxsmpl<<
" / "<<rMaxVal<<endl;
807 if(abs(rMinVal) > abs(rMaxVal)) {
808 rVal = rMinVal; rTime = minsmpl;
810 rVal = rMaxVal; rTime = maxsmpl;
812 cout<<
"getDetectorTimingT: Signal at "<<rTime<<
" Amplitude "<<rVal<<endl;
817 par0[1] = max(0.,(Double_t)(rTime-
RISETIME));
840 cout<<
"<getDetectorTimingT>: Gain "<<ig<<
" Peak0 "<<
evtpeak[ig]<<
" Time0 "<<
evttime[ig]<<endl;
841 if(tmp!=0&&abs(sgp)>abs(sgn)) {
844 cout<<
"<getDetectorTimingT>: Positive peak selected"<<endl;
848 cout<<
"<getDetectorTimingT>: Negative peak selected"<<endl;
851 cout<<
"<getDetectorTimingT>: Gain "<<ig<<
" Peak "<<
evtpeak[ig]<<
" Time "<<
evttime[ig]<<
" Chi2 "<<
tChi2[ig]<<endl;
860 TCanvas * eventSum = (TCanvas *)(gROOT->FindObject(
"eventSum"));
861 if(!eventSum) eventSum =
new TCanvas(
"eventSum",
"sPhenix eventSum display", 300, 300, 800, 500);
862 else eventSum->Clear();
863 eventSum -> Divide(1,ng);
864 for(
int ig = 0; ig < ng; ig++){