68 def __init__(self,options,FairTasks):
69 self.options = options
70 self.EventNumber = -1
71 self.TStart = -1
72 self.TEnd = -1
73 self.MonteCarlo = False
74 self.Weight = 1
75
76 path = options.path
77 self.myclient = None
78 if path.find('eos')>0:
79 path = options.server+options.path
80 if options.online:
81 path = path.replace("raw_data","convertedData").replace("data/","")
82 self.myclient = client.FileSystem(options.server)
83
86 self.MuFilter = self.snd_geo.modules['MuFilter']
87 self.Scifi = self.snd_geo.modules['Scifi']
88
89
90 self.systemAndPlanes = {1:self.MuFilter.GetConfParI("MuFilter/NVetoPlanes"),
91 2:self.MuFilter.GetConfParI("MuFilter/NUpstreamPlanes"),
92 3:2*self.MuFilter.GetConfParI("MuFilter/NDownstreamPlanes")-1}
93 self.systemAndBars = {1:self.MuFilter.GetConfParI("MuFilter/NVetoBars"),
94 2:self.MuFilter.GetConfParI("MuFilter/NUpstreamBars"),
95 3:self.MuFilter.GetConfParI("MuFilter/NDownstreamBars")}
96 self.systemAndChannels = {1:[self.MuFilter.GetConfParI("MuFilter/VetonSiPMs"),0],
97 2:[self.MuFilter.GetConfParI("MuFilter/UpstreamnSiPMs")-2,2],
98 3:[self.MuFilter.GetConfParI("MuFilter/DownstreamnSiPMs"),0]}
99 self.sdict = {0:'Scifi',1:'Veto',2:'US',3:'DS'}
100
101 self.freq = 160.316E6
102 self.TDC2ns = 1E9/self.freq
103
104 self.zPos = self.getAverageZpositions()
105
106 self.h = {}
107
108 self.runNr = str(options.runNumber).zfill(6)
109
110 if hasattr(self, "saveTo") and options.saveTo!="":
111 name = options.saveTo+'run'+self.runNr+'_'+str(options.nStart//1000000)+'.root'
112 else:
113 name = 'run'+self.runNr+'.root'
114 if options.interactive: name = 'I-'+name
115 self.presenterFile = ROOT.TFile(name,'recreate')
116 for role in ['','shifter', 'expert']:
117 self.presenterFile.mkdir('scifi/'+role)
118 self.presenterFile.mkdir('mufilter/'+role)
119 self.presenterFile.mkdir('daq/'+role)
120 if options.interactive: self.presenterFile.mkdir('eventdisplay/'+role)
121 self.FairTasks = {}
122 for x in FairTasks:
123 self.FairTasks[x.GetName()] = x
124
125
126 if options.online:
127 import ConvRawData
128 options.chi2Max = 2000.
129 options.saturationLimit = 0.95
130 options.stop = False
131 options.withGeoFile = True
133 self.converter.Init(options)
134 self.options.online = self.converter
135 self.fsdict = False
136 self.hasBunchInfo = False
137 self.eventTree = options.online.fSink.GetOutTree()
138 self.Nkeys = 38
139 if self.converter.newFormat: self.Nkeys = 1
140 for t in self.FairTasks:
141 T = self.FairTasks[t]
142 self.converter.run.AddTask(T)
143 if t=='simpleTracking':
144 T.Init(self.converter)
145 self.trackTask = self.FairTasks[t]
146 self.Reco_MuonTracks = T.fittedTracks
147 self.clusMufi = T.clusMufi
148 self.clusScifi = T.clusScifi
149 else: T.Init()
150 self.run = self.converter.run
151 if self.eventTree.EventHeader.GetAccMode()==12:
152 self.Nbunches = 1782
153 self.div = 8
154 else:
155 self.Nbunches = 3564
156 self.div = 4
157 return
158 else:
159 if options.fname:
160 f=ROOT.TFile.Open(options.fname)
161 eventChain = f.Get('rawConv')
162 if not eventChain:
163 eventChain = f.cbmsim
164 if eventChain.GetBranch('MCTrack'): self.MonteCarlo = True
165 partitions = []
166 else:
167 partitions = 0
168 if options.partition < 0:
169 partitions = []
170 if path.find('eos')>0:
171
172 dirlist = str( subprocess.check_output("xrdfs "+options.server+" ls "+options.path+"run_"+self.runNr,shell=True) )
173 for x in dirlist.split('\\n'):
174 ix = x.find('sndsw_raw-')
175 if ix<0: continue
176 partitions.append(x[ix:])
177 else:
178
179 dirlist = os.listdir(options.path+"run_"+self.runNr)
180 for x in dirlist:
181 if not x.find('sndsw_raw-')<0:
182 partitions.append(x)
183 else:
184 partitions = ["sndsw_raw-"+ str(options.partition).zfill(4)+".root"]
185 if options.runNumber>0:
186 eventChain = ROOT.TChain('rawConv')
187 for p in partitions:
188 eventChain.Add(path+'run_'+self.runNr+'/'+p)
189
190 rc = eventChain.GetEvent(0)
191 self.TStart = eventChain.EventHeader.GetEventTime()
192 if options.nEvents <0:
193 rc = eventChain.GetEvent(eventChain.GetEntries()-1)
194 else:
195 rc = eventChain.GetEvent(options.nEvents-1)
196 self.TEnd = eventChain.EventHeader.GetEventTime()
197 rc = eventChain.GetEvent(0)
198
199 self.run = ROOT.FairRunAna()
200 ioman = ROOT.FairRootManager.Instance()
201 ioman.SetTreeName(eventChain.GetName())
202 outFile = ROOT.TMemFile('dummy','CREATE')
203 source = ROOT.FairFileSource(eventChain.GetCurrentFile())
204 for i in range(1,len(partitions)):
205 p = partitions[i]
206 source.AddFile(path+'run_'+self.runNr+'/'+p)
207 self.run.SetSource(source)
208 self.sink = ROOT.FairRootFileSink(outFile)
209 self.run.SetSink(self.sink)
210
211 for t in FairTasks:
212 self.run.AddTask(t)
213
214
215 xrdb = ROOT.FairRuntimeDb.instance()
216 xrdb.getContainer("FairBaseParSet").setStatic()
217 xrdb.getContainer("FairGeoParSet").setStatic()
218
219 self.run.Init()
220 if len(partitions)>0: self.eventTree = ioman.GetInChain()
221 else: self.eventTree = ioman.GetInTree()
222
223 if "simpleTracking" in self.FairTasks:
224 self.trackTask = self.FairTasks["simpleTracking"]
225 self.Reco_MuonTracks = self.trackTask.fittedTracks
226 self.clusMufi = self.trackTask.clusMufi
227 self.clusScifi = self.trackTask.clusScifi
228 self.trackTask.DSnPlanes = 3
229
230
231 rc = eventChain.GetEvent(0)
232 if not self.MonteCarlo:
233 self.snd_geo.modules['Scifi'].InitEvent(eventChain.EventHeader)
234 self.snd_geo.modules['MuFilter'].InitEvent(eventChain.EventHeader)
235
236
237 if eventChain.EventHeader.GetAccMode()==12:
238 self.Nbunches = 1782
239 self.div = 8
240 else:
241 self.Nbunches = 3564
242 self.div = 4
243
244
245 self.hasBunchInfo = False
246 self.fsdict = False
247 if hasattr(eventChain.EventHeader,"GetBunchType"):
248 if not eventChain.EventHeader.GetBunchType()<0:
249 self.hasBunchInfo = True
250 print('take bunch info from event header')
251 if not self.hasBunchInfo:
252 try:
253 fg = ROOT.TFile.Open(options.server+options.path+'FSdict.root')
254 pkl = Unpickler(fg)
255 FSdict = pkl.load('FSdict')
256 fg.Close()
257 if options.runNumber in FSdict: self.fsdict = FSdict[options.runNumber]
258 except:
259 print('continue without knowing filling scheme',options.server+options.path)
260 if self.fsdict:
261 print('extract bunch info from filling scheme')
262 if self.fsdict or self.hasBunchInfo:
263 for x in ['B1only','B2noB1','noBeam']:
264 for role in ['shifter', 'expert']:
265 self.presenterFile.mkdir('mufilter/'+role+'/'+x)
266 self.presenterFile.mkdir('scifi/'+role+'/'+x)
267