9 from __future__
import print_function
11 from CoolLumiUtilities.CoolBCIDData
import LumiBCIDData
13 from ROOT
import TFile, TTree, gROOT, AddressOf
14 from array
import array
30 self.
algDict[101] =
'lucidEvtAND'
31 self.
algDict[102] =
'lucidEvtOR'
32 self.
algDict[103] =
'lucidHitOR'
33 self.
algDict[104] =
'lucidHitAND'
37 self.
algDict[111] =
'lucBiEvtAND'
38 self.
algDict[112] =
'lucBiEvtOR'
39 self.
algDict[113] =
'lucBiHitOR'
43 self.
algDict[121] =
'lucModEvtAND'
44 self.
algDict[122] =
'lucModEvtOR'
45 self.
algDict[123] =
'lucModHitOR'
46 self.
algDict[124] =
'lucModHitAND'
47 self.
algDict[125] =
'lucModEvtA'
48 self.
algDict[126] =
'lucModEvtC'
50 self.
algDict[131] =
'lucBiPMTA1'
51 self.
algDict[132] =
'lucBiPMTA5'
52 self.
algDict[133] =
'lucBiPMTA9'
53 self.
algDict[134] =
'lucBiPMTA13'
54 self.
algDict[135] =
'lucBiPMTC1'
55 self.
algDict[136] =
'lucBiPMTC5'
56 self.
algDict[137] =
'lucBiPMTC9'
57 self.
algDict[138] =
'lucBiPMTC13'
67 self.
algDict[202] =
'bcmHEvtAND'
72 self.
algDict[212] =
'bcmVEvtAND'
77 self.
algDict[222] =
'bcmTEvtAND'
81 self.
algDict[231] =
'bcmHEarlyOR'
82 self.
algDict[235] =
'bcmHEarlyA'
83 self.
algDict[236] =
'bcmHEarlyC'
85 self.
algDict[241] =
'bcmVEarlyOR'
86 self.
algDict[245] =
'bcmVEarlyA'
87 self.
algDict[246] =
'bcmVEarlyC'
90 self.
algDict[302] =
'mbtsEvtAND'
158 print(
'ScanNtupleHandler.open() called')
164 print(
'ScanNtupleHandler.init() called')
184 print(
'ScanNtupleHandler.fill() called')
188 for obj
in data.scanData.data:
222 print(
'ScanNtupleHandler.fill() - filled', nfilled,
'entries')
225 print(
'ScanNtupleHandler.close() called')
235 structStr =
"struct ScanDataStruct {\
236 ULong64_t fStartTime;\
240 Float_t fStepProgress;\
241 Float_t fScanningIP;\
242 Float_t fAcquisitionFlag;\
243 Float_t fMovingBeam;\
244 Float_t fNominalSeparation;\
245 Float_t fScanInPlane;\
249 gROOT.ProcessLine(structStr)
250 from ROOT
import ScanDataStruct
254 self.
tree.Branch(
'SCANDATA', self.
scanDataStruct,
'StartTime/l:EndTime/l:ScanRun/i:ScanLB/i:StepProgress/F:ScanningIP/F:AcquisitionFlag/F:MovingBeam/F:NominalSeparation/F:ScanInPlane/F')
264 self.
scanDataStruct.fAcquisitionFlag = obj.payload()[
'AcquisitionFlag']
266 self.
scanDataStruct.fNominalSeparation = obj.payload()[
'NominalSeparation']
273 gROOT.ProcessLine(
"struct BeamPositionStruct {\
274 Float_t fB1PositionH;\
275 Float_t fB1PositionV;\
276 Float_t fB2PositionH;\
277 Float_t fB2PositionV;\
283 from ROOT
import BeamPositionStruct
286 self.
tree.Branch(
'BEAMPOSITION', self.
beamPositionStruct,
'B1PositionH/F:B1PositionV/F:B2PositionH/F:B2PositionV/F:B1AngleH/F:B1AngleV/F:B2AngleH/F:B2AngleV/F')
294 if timeobj.since() != obj.since():
continue
308 print(
"scanNtupleHandler.fillBeamPosition - Didn't find beam position data to match scan data!")
323 gROOT.ProcessLine(
"struct FillParamsStruct {\
325 Int_t fB1BCIDs[3564];\
327 Int_t fB2BCIDs[3564];\
328 Int_t fLuminousBunches;\
329 Int_t fLuminousBCIDs[3564];\
331 from ROOT
import FillParamsStruct
341 self.
tree.Branch(
'FILLPARAMSB1', AddressOf(self.
fillParamsStruct,
'fB1Bunches'),
'B1Bunches/I:B1BCIDs[B1Bunches]/I')
342 self.
tree.Branch(
'FILLPARAMSB2', AddressOf(self.
fillParamsStruct,
'fB2Bunches'),
'B2Bunches/I:B2BCIDs[B2Bunches]/I')
343 self.
tree.Branch(
'FILLPARAMS', AddressOf(self.
fillParamsStruct,
'fLuminousBunches'),
'LuminousBunches/I:LuminousBCIDs[LuminousBunches]/I')
345 print(
'Defined FillParams data type')
356 if timeobj.since() < obj.since():
continue
357 if timeobj.since() >= obj.until():
continue
365 self.
bcidData.fillMask(obj.payload())
388 print(
"scanNtupleHandler.fillFillParams - Didn't find FILLPARAMS data to match scan data!")
393 for i
in range(3564):
402 gROOT.ProcessLine(
"struct LbdataStruct {\
403 Float_t fB1IntensityBPTX;\
404 Float_t fB2IntensityBPTX;\
405 Float_t fB1IntensityAllBPTX;\
406 Float_t fB2IntensityAllBPTX;\
407 Float_t fB1IntensityBCT;\
408 Float_t fB2IntensityBCT;\
409 Float_t fB1IntensityAllBCT;\
410 Float_t fB2IntensityAllBCT;\
411 Float_t fB1IntensityAllDCCT;\
412 Float_t fB2IntensityAllDCCT;\
414 from ROOT
import LbdataStruct
417 self.
tree.Branch(
'BPTX_LBDATA', AddressOf(self.
lbdataStruct,
'fB1IntensityBPTX'),
'BPTX_B1Intensity/F:BPTX_B2Intensity/F:BPTX_B1IntensityAll/F:BPTX_B2IntensityAll/F')
418 self.
tree.Branch(
'BCT_LBDATA', AddressOf(self.
lbdataStruct,
'fB1IntensityBCT'),
'BCT_B1Intensity/F:BCT_B2Intensity/F:BCT_B1IntensityAll/F:BCT_B2IntensityAll/F')
419 self.
tree.Branch(
'DCCT_LBDATA', AddressOf(self.
lbdataStruct,
'fB1IntensityAllDCCT'),
'DCCT_B1IntensityAll/F:DCCT_B2IntensityAll/F')
430 if timeobj.since() != obj.since():
continue
432 if obj.channelId() == 0:
435 self.
lbdataStruct.fB1IntensityBPTX = obj.payload()[
'Beam1Intensity']
436 self.
lbdataStruct.fB2IntensityBPTX = obj.payload()[
'Beam2Intensity']
437 self.
lbdataStruct.fB1IntensityAllBPTX = obj.payload()[
'Beam1IntensityAll']
438 self.
lbdataStruct.fB2IntensityAllBPTX = obj.payload()[
'Beam2IntensityAll']
440 elif obj.channelId() == 1:
443 self.
lbdataStruct.fB1IntensityBCT = obj.payload()[
'Beam1Intensity']
444 self.
lbdataStruct.fB2IntensityBCT = obj.payload()[
'Beam2Intensity']
445 self.
lbdataStruct.fB1IntensityAllBCT = obj.payload()[
'Beam1IntensityAll']
446 self.
lbdataStruct.fB2IntensityAllBCT = obj.payload()[
'Beam2IntensityAll']
448 elif obj.channelId() == 2:
451 self.
lbdataStruct.fB1IntensityAllDCCT = obj.payload()[
'Beam1IntensityAll']
452 self.
lbdataStruct.fB2IntensityAllDCCT = obj.payload()[
'Beam2IntensityAll']
455 print(
'scanNtupleHandler.fillLbdata - Found unknown channel', obj.channelId(),
'!')
457 if foundBCT
and foundBPTX
and foundDCCT :
break
460 if (
not foundBPTX)
and (
not foundBCT)
and (
not foundDCCT):
461 print(
"scanNtupleHandler.fillLBdata - Couldn't find LBDATA!")
463 print(
"scanNtupleHandler.fillLBdata - Couldn't find BCT data in LBDATA!")
465 print(
"scanNtupleHandler.fillLBdata - Couldn't find BPTX data in LBDATA!")
467 print(
"scanNtupleHandler.fillLBdata - Couldn't find DCCT data in LBDATA!")
489 gROOT.ProcessLine(
"struct BunchDataStruct {\
491 Float_t fB1BunchAverageBPTX;\
492 Float_t fB2BunchAverageBPTX;\
493 Int_t fB1BunchesBPTX;\
494 Int_t fB2BunchesBPTX;\
495 Float_t fB1BunchIntensitiesBPTX[3564];\
496 Int_t fB1BCIDsBPTX[3564];\
497 Float_t fB2BunchIntensitiesBPTX[3564];\
498 Int_t fB2BCIDsBPTX[3564];\
500 Float_t fB1BunchAverageBCT;\
501 Float_t fB2BunchAverageBCT;\
502 Int_t fB1BunchesBCT;\
503 Int_t fB2BunchesBCT;\
504 Int_t fB1BCIDsBCT[3564];\
505 Float_t fB1BunchIntensitiesBCT[3564];\
506 Int_t fB2BCIDsBCT[3564];\
507 Float_t fB2BunchIntensitiesBCT[3564];\
509 from ROOT
import BunchDataStruct
518 self.
tree.Branch(
'BCT_BUNCHDATA', AddressOf(self.
bunchDataStruct,
'fValidBCT'),
'BCT_Valid/i:BCT_B1BunchAverage/F:BCT_B2BunchAverage/F:BCT_B1Bunches/I:BCT_B2Bunches/I')
519 self.
tree.Branch(
'BCT_B1BCID', AddressOf(self.
bunchDataStruct,
'fB1BCIDsBCT'),
'BCT_B1BCID[BCT_B1Bunches]/I')
520 self.
tree.Branch(
'BCT_B2BCID', AddressOf(self.
bunchDataStruct,
'fB2BCIDsBCT'),
'BCT_B2BCID[BCT_B2Bunches]/I')
521 self.
tree.Branch(
'BCT_B1BunchIntensity', AddressOf(self.
bunchDataStruct,
'fB1BunchIntensitiesBCT'),
'BCT_B1BunchIntensity[BCT_B1Bunches]/F')
522 self.
tree.Branch(
'BCT_B2BunchIntensity', AddressOf(self.
bunchDataStruct,
'fB2BunchIntensitiesBCT'),
'BCT_B2BunchIntensity[BCT_B2Bunches]/F')
524 self.
tree.Branch(
'BPTX_BUNCHDATA', AddressOf(self.
bunchDataStruct,
'fValidBPTX'),
'BPTX_Valid/i:BPTX_B1BunchAverage/F:BPTX_B2BunchAverage/F:BPTX_B1Bunches/I:BPTX_B2Bunches/I')
525 self.
tree.Branch(
'BPTX_B1BCID', AddressOf(self.
bunchDataStruct,
'fB1BCIDsBPTX'),
'BPTX_B1BCID[BPTX_B1Bunches]/I')
526 self.
tree.Branch(
'BPTX_B2BCID', AddressOf(self.
bunchDataStruct,
'fB2BCIDsBPTX'),
'BPTX_B2BCID[BPTX_B2Bunches]/I')
527 self.
tree.Branch(
'BPTX_B1BunchIntensity', AddressOf(self.
bunchDataStruct,
'fB1BunchIntensitiesBPTX'),
'BPTX_B1BunchIntensity[BPTX_B1Bunches]/F')
528 self.
tree.Branch(
'BPTX_B2BunchIntensity', AddressOf(self.
bunchDataStruct,
'fB2BunchIntensitiesBPTX'),
'BPTX_B2BunchIntensity[BPTX_B2Bunches]/F')
539 if timeobj.since() != obj.since():
continue
542 self.
bcidData.fillCurrents(obj.payload())
544 if obj.channelId() == 0:
547 self.
bunchDataStruct.fB1BunchAverageBPTX = obj.payload()[
'B1BunchAverage']
548 self.
bunchDataStruct.fB2BunchAverageBPTX = obj.payload()[
'B2BunchAverage']
558 for (bcid, val)
in self.
bcidData.b1Curr.iteritems():
568 for (bcid, val)
in self.
bcidData.b2Curr.iteritems():
573 elif obj.channelId() == 1:
576 self.
bunchDataStruct.fB1BunchAverageBCT = obj.payload()[
'B1BunchAverage']
577 self.
bunchDataStruct.fB2BunchAverageBCT = obj.payload()[
'B2BunchAverage']
585 for (bcid, val)
in self.
bcidData.b1Curr.iteritems():
595 for (bcid, val)
in self.
bcidData.b2Curr.iteritems():
601 print(
'scanNtupleHandler.fillLbdata - Found unknown channel', obj.channelId(),
'!')
603 if foundBCT
and foundBPTX:
break
606 if (
not foundBPTX)
and (
not foundBCT):
607 print(
"scanNtupleHandler.fillBunchData - Couldn't find BUNCHDATA!")
609 print(
"scanNtupleHandler.fillBunchData - Couldn't find BCT data in BUNCHDATA!")
611 print(
"scanNtupleHandler.fillBunchData - Couldn't find BPTX data in BUNCHDATA!")
635 gROOT.ProcessLine(
"struct BunchLumiStruct {\
638 Float_t fAverageRawInstLum;\
639 Int_t fLuminousBunches;\
640 Int_t fLuminousBCIDs[3564];\
641 Float_t fBunchRawInstLum[3564];\
643 from ROOT
import BunchLumiStruct
650 print(
'scanNtupleHandler.initLumiData - initializing', algstr,
'as channel', chId)
657 branchString1 =
'ALG_Channel/i:ALG_Valid/i:ALG_AverageRawInstLum/F:ALG_LuminousBunches/I'
658 branchString2 =
'ALG_LuminousBCIDs[ALG_LuminousBunches]/I'
659 branchString3 =
'ALG_BunchRawInstLum[ALG_LuminousBunches]/F'
661 self.
tree.Branch(algstr+
'_BUNCHDATA', self.
bunchLumiStruct[chId], branchString1.replace(
'ALG', algstr))
664 self.
tree.Branch(algstr+
'_BCID', self.
fLuminousBCIDs[chId], branchString2.replace(
'ALG', algstr))
665 self.
tree.Branch(algstr+
'_BunchRawInstLum', self.
fBunchRawInstLum[chId], branchString3.replace(
'ALG', algstr))
678 if timeobj.since() != obj.since():
continue
681 chId = obj.channelId()
683 print(
'scanNtupleHandler.fillBunchLumi - Unknown lumi channel', chId,
'!')
689 self.
bcidData.fillRawLumi(obj.payload())
694 self.
bunchLumiStruct[chId].fAverageRawInstLum = obj.payload()[
'AverageRawInstLum']
703 bcidList = self.
bcidData.rawLumi.keys()
704 for bcid
in sorted(bcidList):
714 print(
'scanNtupleHandler.fillBunchLumi - Found no BUNCHLUMIS data to match IOV!')
719 print(
'scanNtupleHandler.fillBunchLumi - Found no BUNCHLUMIS data for', algstr,
'!')
729 print(
'scanNtupleHandler.initLumiData() called')
734 gROOT.ProcessLine(
"struct LumiDataStruct {\
736 Float_t fLBAvInstLumPhys;\
737 Float_t fLBAvEvtsPerBXPhys;\
738 Float_t fLBAvRawInstLumPhys;\
739 Float_t fLBAvInstLumAll;\
740 Float_t fLBAvRawInstLumAll;\
741 Float_t fLBAvEvtsPerBXAll;\
742 Float_t fLBAvOLCInstLum;\
743 Float_t fLBAvOLCRawInstLum;\
744 Float_t fLBAvOLCEvtsPerBX;\
748 UInt_t fDetectorState;\
751 from ROOT
import LumiDataStruct
755 print(
'scanNtupleHandler.initLumiData - initializing', algstr,
'as channel', chId)
757 branchString =
'ALG_LumiChannel/i:ALG_LBAvInstLumPhys/F:ALG_LBAvEvtsPerBXPhys/F:ALG_LBAvRawInstLumPhys/F:ALG_LBAvInstLumAll/F:ALG_LBAvRawInstLumAll/F:ALG_LBAvEvtsPerBXAll/F:ALG_LBAvOLCInstLum/F:ALG_LBAvOLCRawInstLum/F:ALG_LBAvOLCEvtsPerBX/F:ALG_NOrbPhys/i:ALG_NOrbAll/i:ALG_NOrbOLC/i:ALG_DetectorState/i:ALG_LumiValid/i'
759 self.
tree.Branch(algstr+
'_LUMI', self.
lumiStruct[chId], branchString.replace(
'ALG', algstr))
774 if timeobj.since() != obj.since():
continue
777 chId = obj.channelId()
781 elif chId >= 50
and chId <=70:
782 liveDict[chId] = obj.payload()[
'LBAvOLCInstLum']
786 print(
'scanNtupleHandler.fillLumiData - Unknown lumi channel', chId,
'!')
793 self.
lumiStruct[chId].fChannel = obj.channelId()
794 self.
lumiStruct[chId].fLBAvInstLumPhys = obj.payload()[
'LBAvInstLumPhys']
795 self.
lumiStruct[chId].fLBAvEvtsPerBXPhys = obj.payload()[
'LBAvEvtsPerBXPhys']
796 self.
lumiStruct[chId].fLBAvRawInstLumPhys = obj.payload()[
'LBAvRawInstLumPhys']
797 self.
lumiStruct[chId].fLBAvInstLumAll = obj.payload()[
'LBAvInstLumAll']
798 self.
lumiStruct[chId].fLBAvEvtsPerBXAll = obj.payload()[
'LBAvEvtsPerBXAll']
799 self.
lumiStruct[chId].fLBAvRawInstLumAll = obj.payload()[
'LBAvRawInstLumAll']
800 self.
lumiStruct[chId].fLBAvOLCInstLum = obj.payload()[
'LBAvOLCInstLum']
801 self.
lumiStruct[chId].fLBAvOLCEvtsPerBX = obj.payload()[
'LBAvOLCEvtsPerBX']
802 self.
lumiStruct[chId].fLBAvOLCRawInstLum = obj.payload()[
'LBAvOLCRawInstLum']
803 self.
lumiStruct[chId].fDetectorState = obj.payload()[
'DetectorState']
805 self.
lumiStruct[chId].fNOrbPhys = obj.payload()[
'NOrbPhys']
806 self.
lumiStruct[chId].fNOrbAll = obj.payload()[
'NOrbAll']
807 self.
lumiStruct[chId].fNOrbOLC = obj.payload()[
'NOrbOLC']
808 except Exception
as e:
814 self.
lumiStruct[chId].fValid = obj.payload()[
'Valid']
817 print(
'scanNtupleHandler.fillLumiData - Found no LUMINOSITY data to match IOV!')
822 print(
'scanNtupleHandler.fillLumiData - Found no LUMINOSITY data for', algstr,
'!')
829 self.
lumiStruct[chId].fLBAvRawInstLumPhys = 0.
853 def fillLive(self, liveDict, denchan, numchan, dest):
854 num = liveDict.get(numchan, 0.)
855 den = liveDict.get(denchan, 0.)
868 gROOT.ProcessLine(
"struct LiveDataStruct {\
869 Float_t fRD0_Filled;\
874 Float_t fMBTS_1_BGRP9;\
875 Float_t fMBTS_2_BGRP9;\
877 from ROOT
import LiveDataStruct
880 self.
tree.Branch(
'LiveFractions', AddressOf(self.
liveDataStruct,
'fRD0_Filled'),
'RD0_Filled/f,MBTS_1_1/f,MBTS_2/f,EM12/f,RD0_BGRP9/f,MBTS_1_BGRP9/f,MBTS_2_BGRP9/f')