2import ROOT,os,time,sys,operator,atexit
3ROOT.gROOT.ProcessLine(
'typedef std::unordered_map<int, std::unordered_map<int, std::unordered_map<int, std::vector<MufluxSpectrometerHit*>>>> nestedList;')
5from decorators
import *
6import __builtin__
as builtin
7ROOT.gStyle.SetPalette(ROOT.kGreenPink)
8PDG = ROOT.TDatabasePDG.Instance()
10timer = ROOT.TStopwatch()
12ROOT.gErrorIgnoreLevel = ROOT.kBreak
13from argparse
import ArgumentParser
16from array
import array
21from bson.json_util
import loads, dumps
39cuts[
'minLayersUV'] = 2
40cuts[
'maxClusterSize'] = 2
41cuts[
'delxAtGoliath'] = 8.
42cuts[
'lateArrivalsToT'] = 9999.
44cuts[
'RTsegmentation'] = 12
46cuts[
'muTaggerCluster_max'] = 6
47cuts[
'muTaggerCluster_sep'] = 15
48cuts[
'muTrackMatchX']= 5.
49cuts[
'muTrackMatchY']= 10.
50cuts[
'muTaggerCluster_grouping'] = 3
51cuts[
"RPCmaxDistance"] = 10.
60views = {1:[
'_x',
'_u'],2:[
'_x',
'_v'],3:[
'_x'],4:[
'_x']}
61viewsI = {1:[0,1],2:[0,2],3:[0],4:[0]}
62viewC = {0:
"_x",1:
"_u",2:
"_v"}
64muSources = {
'eta':221,
'omega':223,
'phi':333,
'rho0':113,
'eta_prime':331}
65muSourcesIDs = muSources.values()
72parser = ArgumentParser()
73parser.add_argument(
"-f",
"--files", dest=
"listOfFiles", help=
"list of files comma separated", required=
True)
74parser.add_argument(
"-l",
"--fileCatalog", dest=
"catalog", help=
"list of files in file", default=
False)
75parser.add_argument(
"-c",
"--cmd", dest=
"command", help=
"command to execute", default=
"")
76parser.add_argument(
"-d",
"--Display", dest=
"withDisplay", help=
"detector display", default=
True)
77parser.add_argument(
"-e",
"--eos", dest=
"onEOS", help=
"files on EOS", default=
False)
78parser.add_argument(
"-u",
"--update", dest=
"updateFile", help=
"update file", default=
False)
79parser.add_argument(
"-i",
"--input", dest=
"inputFile", help=
"input histo file", default=
'residuals.root')
80parser.add_argument(
"-g",
"--geofile", dest=
"geoFile", help=
"input geofile", default=
'')
81parser.add_argument(
"-s",
"--smearing", dest=
"MCsmearing", help=
"additional MC smearing", default=MCsmearing)
83options = parser.parse_args()
84MCsmearing = options.MCsmearing
87 tmp = open(options.listOfFiles)
88 for x
in tmp.readlines():
89 fname = x.replace(
'\n',
'')
90 if fname.find(
"root")<0:
continue
91 f=ROOT.TFile.Open(fname)
93 if not sTree.GetBranch(
"FitTracks"):
94 print "does not contain FitTracks",fname
98 fnames.append(x.replace(
'\n',
''))
101 fnames = options.listOfFiles.split(
',')
103if options.updateFile:
104 f=ROOT.TFile(fname,
'update')
105 sTree=f.Get(
'cbmsim')
107 print "Problem with updateFile",f
110 sTree = ROOT.TChain(
'cbmsim')
113 if options.onEOS: sTree.Add(os.environ[
'EOSSHIP']+f)
118 rnames.append(fname[fname.rfind(
'/')+1:])
122from ShipGeoConfig
import ConfigRegistry
123if options.geoFile==
"":
124 ShipGeo = ConfigRegistry.loadpy(
"$FAIRSHIP/geometry/charm-geometry_config.py")
126 from ShipGeoConfig
import ConfigRegistry
127 from rootpyPickler
import Unpickler
129 fgeo = ROOT.TFile.Open(options.geoFile)
131 ShipGeo = upkl.load(
'ShipGeo')
132builtin.ShipGeo = ShipGeo
134run = ROOT.FairRunSim()
135run.SetName(
"TGeant4")
136run.SetOutputFile(ROOT.TMemFile(
'output',
'recreate'))
137run.SetUserConfig(
"g4Config_basic.C")
138rtdb = run.GetRuntimeDb()
142sGeo = ROOT.gGeoManager
143nav = sGeo.GetCurrentNavigator()
144top = sGeo.GetTopVolume()
146if options.withDisplay:
151import saveBasicParameters
153 run.CreateGeometryFile(
"muflux_geofile.root")
166Nchannels = {1:12,2:12,3:48,4:48}
175conditionsDB = api_factory.construct_DB_API()
176daniel = (conditionsDB.get_condition_by_name_and_tag(
"muflux/driftTubes",
"strawPositions",
"muflux/driftTubes_daniel_2020-03-23 18:14"))[
"values"]
177survey = (conditionsDB.get_condition_by_name_and_tag(
"muflux/driftTubes",
"strawPositions",
"muflux/driftTubes_survey_2020-03-23 18:14"))[
"values"]
181Lcorrection[
'T1_MA_01'] = -(20.+150.+8.65)/10.
182Lcorrection[
'T1_MA_02'] = -(20.+150.+8.65)/10.
183Lcorrection[
'T1_MA_03'] = (20.+50.+8.35)/10.
184Lcorrection[
'T1_MA_04'] = (20.+50.+8.35)/10.
185Lcorrection[
'T1_MB_01'] = -(20.+150.)/10.
186Lcorrection[
'T1_MB_02'] = -(20.+150.)/10.
187Lcorrection[
'T1_MB_03'] = (20.+50.)/10.
188Lcorrection[
'T1_MB_04'] = (20.+50.)/10.
189Lcorrection[
'T2_MC_01'] = -(20.+150.)/10.
190Lcorrection[
'T2_MC_02'] = -(20.+150.)/10.
191Lcorrection[
'T2_MC_03'] = (20.+50.)/10.
192Lcorrection[
'T2_MC_04'] = (20.+50.)/10.
193Lcorrection[
'T2_MD_01'] = -(20.+150.+7.3)/10.
194Lcorrection[
'T2_MD_02'] = -(20.+150.+7.3)/10.
195Lcorrection[
'T2_MD_03'] = (20.+50.+8.45)/10.
196Lcorrection[
'T2_MD_04'] = (20.+50.+8.45)/10.
200 surveyXYZ[s]=[survey[s][1]*100.,survey[s][2]*100.,survey[s][0]*100.]
201for s
in daniel: daniel[s]=[daniel[s][0]/10.,daniel[s][1]/10.,daniel[s][2]/10.]
204for s
in [
'T1_MA_',
'T1_MB_',
'T2_MC_',
'T2_MD_']:
205 delx = surveyXYZ[s+
'01'][0]-surveyXYZ[s+
'04'][0]
206 dely = surveyXYZ[s+
'01'][1]-surveyXYZ[s+
'04'][1]
207 Langle[s+
'01-04'] = ROOT.TMath.ATan2(dely,delx)
208 delx = surveyXYZ[s+
'02'][0]-surveyXYZ[s+
'03'][0]
209 dely = surveyXYZ[s+
'02'][1]-surveyXYZ[s+
'03'][1]
210 Langle[s+
'02-03'] = ROOT.TMath.ATan2(dely,delx)
212 if s.find(
'T1')<0
and s.find(
'T2')<0:
continue
213 if s.find(
'01')>0: a = s.replace(
'01',
'01-04')
214 elif s.find(
'04')>0: a = s.replace(
'04',
'01-04')
215 elif s.find(
'02')>0: a = s.replace(
'02',
'02-03')
216 elif s.find(
'03')>0: a = s.replace(
'03',
'02-03')
221ut.bookHist(h,
'lengthCalibration',
'length Calibration',100,-0.2,0.2)
223 for s
in [
'T1_MA_0',
'T2_MD_0']:
224 delta = daniel[s+
'1'][0]-daniel[s+
'2'][0]
225 print s,
'top',delta-45.2
226 rc=h[
'lengthCalibration'].Fill(delta-45.2)
227 delta = daniel[s+
'4'][0]-daniel[s+
'3'][0]
228 rc=h[
'lengthCalibration'].Fill(delta-45.2)
229 print s,
'bottom',delta-45.2
231 for s
in [
'T3_T0',
'T4_T0']:
232 delta = daniel[s+str(2*k+1)][0]-daniel[s+str(2*k+2)][0]
233 rc=h[
'lengthCalibration'].Fill(delta-8.*4.2)
237rn[
'T1_MB_01'] = [21.55,72.60]
238rn[
'T1_MB_02'] = [-23.65,72.60]
239rn[
'T1_MB_04'] = [21.55,-62.60]
240rn[
'T1_MB_03'] = [-23.65,-62.60]
241rn[
'T2_MC_01'] = rn[
'T1_MB_01']
242rn[
'T2_MC_02'] = rn[
'T1_MB_02']
243rn[
'T2_MC_04'] = rn[
'T1_MB_04']
244rn[
'T2_MC_03'] = rn[
'T1_MB_03']
248zpos[
'T1X'] = (daniel[
'T1_MA_01'][2]+daniel[
'T1_MA_02'][2]+daniel[
'T1_MA_03'][2]+daniel[
'T1_MA_04'][2])/4. + 3.03
249ypos[
'T1X'] = [(daniel[
'T1_MA_01'][1]+daniel[
'T1_MA_02'][1])/2.,(daniel[
'T1_MA_04'][1]+daniel[
'T1_MA_03'][1])/2.]
250test = ROOT.MufluxSpectrometerHit(10002012,0.)
251test.MufluxSpectrometerEndPoints(vbot,vtop)
252deltaZ = zpos[
'T1X']-(vbot[2]+vtop[2])/2.
254start = daniel[
'T1_MA_01'][0]
255delta = (start - (daniel[
'T1_MA_02'][0]+daniel[
'T1_MA_03'][0])/2.-1.1-2.1) / 10.
258 xpos[n-i] = start - delta * i
259 ypos[n-i] = ypos[
'T1X']
260 zpos[n-i] = zpos[
'T1X']-deltaZ
262start = daniel[
'T1_MA_02'][0] +1.1
264 xpos[n+i] = start + delta * i
265 ypos[n+i] = ypos[
'T1X']
266 zpos[n+i] = zpos[
'T1X']+3.64-deltaZ
270 xpos[n+i] = start + delta * i
271 ypos[n+i] = ypos[
'T1X']
272 zpos[n+i] = zpos[
'T1X']+3.64+4.06-deltaZ
276 xpos[n+i] = start + delta * i
277 ypos[n+i] = ypos[
'T1X']
278 zpos[n+i] = zpos[
'T1X']+3.64+4.06+3.64-deltaZ
281zpos[
'T1U'] = (daniel[
'T1_MB_01'][2]+daniel[
'T1_MB_02'][2]+daniel[
'T1_MB_03'][2]+daniel[
'T1_MB_04'][2])/4. - 3.03 -3.64 -4.06 -3.64
282angleu1 = ROOT.TMath.ATan2((daniel[
'T1_MB_01'][0]-daniel[
'T1_MB_04'][0]),(daniel[
'T1_MB_01'][1]-daniel[
'T1_MB_04'][1]))
283angleu2 = ROOT.TMath.ATan2((daniel[
'T1_MB_02'][0]-daniel[
'T1_MB_03'][0]),(daniel[
'T1_MB_02'][1]-daniel[
'T1_MB_03'][1]))
284angleu = (angleu1+angleu2)/2.
290 tx += daniel[p][0] - (rn[p][0]*ROOT.TMath.Cos(angle) - rn[p][1]*ROOT.TMath.Sin(angle))
291 ty += daniel[p][1] - (rn[p][0]*ROOT.TMath.Sin(angle) + rn[p][1]*ROOT.TMath.Cos(angle))
292 if debug:
print "%s: %5.4F, %5.4F"%(p, (daniel[p][0] - (rn[p][0]*ROOT.TMath.Cos(angle) - rn[p][1]*ROOT.TMath.Sin(angle)))*10,\
293 (daniel[p][1] - (rn[p][0]*ROOT.TMath.Sin(angle) + rn[p][1]*ROOT.TMath.Cos(angle)))*10)
298start = (rn[
'T1_MB_01'][0]+rn[
'T1_MB_04'][0])/2.
299delta = (start - ( (rn[
'T1_MB_02'][0]+rn[
'T1_MB_03'][0])/2.+1.1+2.1) )/ 10.
304 xnom = start - delta * i
306 xpos[n-i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
307 ypos[n-i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
309 xposb[n-i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
310 yposb[n-i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
311 zpos[n-i] = zpos[
'T1U']-deltaZ
313start = (rn[
'T1_MB_02'][0]+rn[
'T1_MB_03'][0])/2.+1.1
315 xnom = start + delta * i
317 xpos[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
318 ypos[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
320 xposb[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
321 yposb[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
322 zpos[n+i] = zpos[
'T1U']+3.64-deltaZ
324start = (rn[
'T1_MB_02'][0]+rn[
'T1_MB_03'][0])/2.
326 xnom = start + delta * i
328 xpos[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
329 ypos[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
331 xposb[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
332 yposb[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
333 zpos[n+i] = zpos[
'T1U']+3.64+4.06 -deltaZ
337 xnom = start + delta * i
339 xpos[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
340 ypos[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
342 xposb[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
343 yposb[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
344 zpos[n+i] = zpos[
'T1U']+3.64+4.06+3.64-deltaZ
347zpos[
'T2X'] = (daniel[
'T2_MD_01'][2]+daniel[
'T2_MD_02'][2]+daniel[
'T2_MD_03'][2]+daniel[
'T2_MD_04'][2])/4. - 3.03 - 3.64 - 4.06 - 3.6480
348ypos[
'T2X'] = [(daniel[
'T2_MD_01'][1]+daniel[
'T2_MD_02'][1])/2.,(daniel[
'T2_MD_04'][1]+daniel[
'T2_MD_03'][1])/2.]
350start = daniel[
'T2_MD_03'][0]
351delta = ( (daniel[
'T2_MD_01'][0]+daniel[
'T2_MD_04'][0])/2. - (start+1.1-2.1)) / 11.
355 xpos[n+i] = start + delta * i
356 ypos[n+i] = ypos[
'T2X']
357 zpos[n+i] = zpos[
'T2X']+3.64+4.06+3.64-deltaZ
361 xpos[n+i] = start + delta * i
362 ypos[n+i] = ypos[
'T2X']
363 zpos[n+i] = zpos[
'T2X']+3.64+4.06-deltaZ
367 xpos[n+i] = start + delta * i
368 ypos[n+i] = ypos[
'T2X']
369 zpos[n+i] = zpos[
'T2X']+3.64-deltaZ
373 xpos[n+i] = start + delta * i
374 ypos[n+i] = ypos[
'T2X']
375 zpos[n+i] = zpos[
'T2X']-deltaZ
378anglev1 = ROOT.TMath.ATan2((daniel[
'T2_MC_02'][0]-daniel[
'T2_MC_03'][0]),(daniel[
'T2_MC_02'][1]-daniel[
'T2_MC_03'][1]))
379anglev2 = ROOT.TMath.ATan2((daniel[
'T2_MC_01'][0]-daniel[
'T2_MC_04'][0]),(daniel[
'T2_MC_01'][1]-daniel[
'T2_MC_04'][1]))
380anglev = (anglev1+anglev2)/2.
382zpos[
'T2V'] = (daniel[
'T2_MC_01'][2]+daniel[
'T2_MC_02'][2]+daniel[
'T2_MC_03'][2]+daniel[
'T2_MC_04'][2])/4. + 3.03
388 tx += daniel[p][0] - (rn[p][0]*ROOT.TMath.Cos(angle) - rn[p][1]*ROOT.TMath.Sin(angle))
389 ty += daniel[p][1] - (rn[p][0]*ROOT.TMath.Sin(angle) + rn[p][1]*ROOT.TMath.Cos(angle))
390 if debug:
print "%s: %5.4F, %5.4F"%(p, (daniel[p][0] - (rn[p][0]*ROOT.TMath.Cos(angle) - rn[p][1]*ROOT.TMath.Sin(angle)))*10,\
391 (daniel[p][1] - (rn[p][0]*ROOT.TMath.Sin(angle) + rn[p][1]*ROOT.TMath.Cos(angle)))*10)
396start = (rn[
'T2_MC_02'][0]+rn[
'T2_MC_03'][0])/2.
397delta = ((rn[
'T2_MC_01'][0]+rn[
'T2_MC_04'][0])/2. - ( (rn[
'T2_MC_02'][0]+rn[
'T2_MC_03'][0])/2.-2.1+1.1)) / 11.
401 xnom = start + delta * i
403 xpos[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
404 ypos[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
406 xposb[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
407 yposb[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
408 zpos[n+i] = zpos[
'T2V']+3.64+4.06+3.64-deltaZ
412 xnom = start + delta * i
414 xpos[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
415 ypos[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
417 xposb[n+i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
418 yposb[n+i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
419 zpos[n+i] = zpos[
'T2V']+3.64+4.06-deltaZ
421start = (rn[
'T2_MC_01'][0]+rn[
'T2_MC_04'][0])/2.
423 xnom = start - delta * i
425 xpos[n-i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
426 ypos[n-i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
428 xposb[n-i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
429 yposb[n-i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
430 zpos[n-i] = zpos[
'T2V']+3.64-deltaZ
434 xnom = start - delta * i
436 xpos[n-i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
437 ypos[n-i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
439 xposb[n-i] = xnom *ROOT.TMath.Cos(angle) - ynom*ROOT.TMath.Sin(angle) + tx
440 yposb[n-i] = xnom *ROOT.TMath.Sin(angle) + ynom*ROOT.TMath.Cos(angle) + ty
441 zpos[n-i] = zpos[
'T2V']-deltaZ
444zpos[
'T3aX'] = (( daniel[
'T3_T01'][2] + daniel[
'T3_B01'][2] + daniel[
'T3_T02'][2] + daniel[
'T3_B02'][2])/4. + 4.33)
445ypos[
'T3aX'] = [(daniel[
'T3_T01'][1]+daniel[
'T3_T02'][1])/2.,(daniel[
'T3_B01'][1]+daniel[
'T3_B02'][1])/2.]
447delta = ( (daniel[
'T3_T01'][0] + daniel[
'T3_B01'][0])/2. - (daniel[
'T3_T02'][0] + daniel[
'T3_B02'][0])/2. )/8.
451start = (daniel[
'T3_T02'][0] + daniel[
'T3_B02'][0])/2. -delta +2.1 -delta
453 xpos[n+i] = start + delta * i
454 zpos[n+i] = zpos[
'T3aX']-deltaZ
456start = (daniel[
'T3_T02'][0] + daniel[
'T3_B02'][0])/2. -delta
458 xpos[n+i] = start + delta * i
459 zpos[n+i] = zpos[
'T3aX']+3.64-deltaZ
461start = (daniel[
'T3_T02'][0] + daniel[
'T3_B02'][0])/2. -delta -1.1
463 xpos[n+i] = start + delta * i
464 zpos[n+i] = zpos[
'T3aX']+3.64+4.06-deltaZ
466start = (daniel[
'T3_T02'][0] + daniel[
'T3_B02'][0])/2. -delta -1.1 -2.1
468 xpos[n+i] = start + delta * i
469 zpos[n+i] = zpos[
'T3aX']+3.64+4.06+3.64-deltaZ
472zpos[
'T3bX'] = (( daniel[
'T3_T03'][2] + daniel[
'T3_B03'][2] + daniel[
'T3_T04'][2] + daniel[
'T3_B04'][2])/4. + 4.33)
473ypos[
'T3bX'] = [(daniel[
'T3_T03'][1]+daniel[
'T3_T04'][1])/2.,(daniel[
'T3_B03'][1]+daniel[
'T3_B04'][1])/2.]
475delta = ( (daniel[
'T3_T03'][0] + daniel[
'T3_B03'][0])/2. - (daniel[
'T3_T04'][0] + daniel[
'T3_B04'][0])/2. )/8.
479start = (daniel[
'T3_T04'][0] + daniel[
'T3_B04'][0])/2. -delta +2.1 -delta
481 xpos[n+i] = start + delta * i
482 zpos[n+i] = zpos[
'T3bX']-deltaZ
484start = (daniel[
'T3_T04'][0] + daniel[
'T3_B04'][0])/2. -delta
486 xpos[n+i] = start + delta * i
487 zpos[n+i] = zpos[
'T3bX']+3.64-deltaZ
489start = (daniel[
'T3_T04'][0] + daniel[
'T3_B04'][0])/2. -delta -1.1
491 xpos[n+i] = start + delta * i
492 zpos[n+i] = zpos[
'T3bX']+3.64+4.06-deltaZ
494start = (daniel[
'T3_T04'][0] + daniel[
'T3_B04'][0])/2. -delta -1.1 -2.1
496 xpos[n+i] = start + delta * i
497 zpos[n+i] = zpos[
'T3bX']+3.64+4.06+3.64-deltaZ
500zpos[
'T3cX'] = (( daniel[
'T3_T05'][2] + daniel[
'T3_B05'][2] + daniel[
'T3_T06'][2] + daniel[
'T3_B06'][2])/4. + 4.33)
501ypos[
'T3cX'] = [(daniel[
'T3_T05'][1]+daniel[
'T3_T06'][1])/2.,(daniel[
'T3_B05'][1]+daniel[
'T3_B06'][1])/2.]
503delta = ( (daniel[
'T3_T05'][0] + daniel[
'T3_B05'][0])/2. - (daniel[
'T3_T06'][0] + daniel[
'T3_B06'][0])/2. )/8.
507start = (daniel[
'T3_T06'][0] + daniel[
'T3_B06'][0])/2. -delta +2.1 -delta
509 xpos[n+i] = start + delta * i
510 zpos[n+i] = zpos[
'T3cX']-deltaZ
512start = (daniel[
'T3_T06'][0] + daniel[
'T3_B06'][0])/2. -delta
514 xpos[n+i] = start + delta * i
515 zpos[n+i] = zpos[
'T3cX']+3.64-deltaZ
519 xpos[n+i] = start + delta * i
520 zpos[n+i] = zpos[
'T3cX']+3.64+4.06-deltaZ
524 xpos[n+i] = start + delta * i
525 zpos[n+i] = zpos[
'T3cX']+3.64+4.06+3.64-deltaZ
528zpos[
'T3dX'] = (( daniel[
'T3_T07'][2] + daniel[
'T3_B07'][2] + daniel[
'T3_T08'][2] + daniel[
'T3_B08'][2])/4. + 4.33)
529ypos[
'T3dX'] = [(daniel[
'T3_T07'][1]+daniel[
'T3_T08'][1])/2.,(daniel[
'T3_B07'][1]+daniel[
'T3_B08'][1])/2.]
531delta = ( (daniel[
'T3_T07'][0] + daniel[
'T3_B07'][0])/2. - (daniel[
'T3_T08'][0] + daniel[
'T3_B08'][0])/2. )/8.
536start = (daniel[
'T3_T08'][0] + daniel[
'T3_B08'][0])/2. -delta +2.1 -delta
538 xpos[n+i] = start + delta * i
539 zpos[n+i] = zpos[
'T3dX'] -deltaZ
541start = (daniel[
'T3_T08'][0] + daniel[
'T3_B08'][0])/2. -delta
543 xpos[n+i] = start + delta * i
544 zpos[n+i] = zpos[
'T3dX']+3.64-deltaZ
546start =(daniel[
'T3_T08'][0] + daniel[
'T3_B08'][0])/2. -delta -1.1
548 xpos[n+i] = start + delta * i
549 zpos[n+i] = zpos[
'T3dX']+3.64+4.06-deltaZ
551start = (daniel[
'T3_T08'][0] + daniel[
'T3_B08'][0])/2. -delta -1.1 -2.1
553 xpos[n+i] = start + delta * i
554 zpos[n+i] = zpos[
'T3dX']+3.64+4.06+3.64-deltaZ
557zpos[
'T4aX'] = (( daniel[
'T4_T01'][2] + daniel[
'T4_B01'][2] + daniel[
'T4_T02'][2] + daniel[
'T4_B02'][2])/4. - 4.33 -3.64-4.06-3.64)
558ypos[
'T4aX'] = [(daniel[
'T4_T01'][1]+daniel[
'T4_T02'][1])/2.,(daniel[
'T4_B01'][1]+daniel[
'T4_B02'][1])/2.]
560delta = ( (daniel[
'T4_T01'][0] + daniel[
'T4_B01'][0])/2. - (daniel[
'T4_T02'][0] + daniel[
'T4_B02'][0])/2. )/8.
564start = (daniel[
'T4_T02'][0] + daniel[
'T4_B02'][0])/2. -delta +45.2
566 xpos[n-i] = start - delta * i
567 zpos[n-i] = zpos[
'T4aX']-deltaZ
569start = (daniel[
'T4_T02'][0] + daniel[
'T4_B02'][0])/2. -delta +1.1
571 xpos[n+i] = start + delta * i
572 zpos[n+i] = zpos[
'T4aX']+3.64-deltaZ
574start = (daniel[
'T4_T02'][0] + daniel[
'T4_B02'][0])/2. -delta
576 xpos[n+i] = start + delta * i
577 zpos[n+i] = zpos[
'T4aX']+3.64+4.06-deltaZ
579start = (daniel[
'T4_T02'][0] + daniel[
'T4_B02'][0])/2. -delta -2.1
581 xpos[n+i] = start + delta * i
582 zpos[n+i] = zpos[
'T4aX']+3.64+4.06+3.64-deltaZ
585zpos[
'T4bX'] = (( daniel[
'T4_T03'][2] + daniel[
'T4_B03'][2] + daniel[
'T4_T04'][2] + daniel[
'T4_B04'][2])/4. - 4.33 -3.64-4.06-3.64)
586ypos[
'T4bX'] = [(daniel[
'T4_T03'][1]+daniel[
'T4_T04'][1])/2.,(daniel[
'T4_B03'][1]+daniel[
'T4_B04'][1])/2.]
588delta = ( (daniel[
'T4_T03'][0] + daniel[
'T4_B03'][0])/2. - (daniel[
'T4_T04'][0] + daniel[
'T4_B04'][0])/2. )/8.
592start = (daniel[
'T4_T04'][0] + daniel[
'T4_B04'][0])/2. -delta +45.2
594 xpos[n-i] = start - delta * i
595 zpos[n-i] = zpos[
'T4bX']-deltaZ
597start = (daniel[
'T4_T04'][0] + daniel[
'T4_B04'][0])/2. -delta +45.2 -10*delta-2.1
599 xpos[n+i] = start + delta * i
600 zpos[n+i] = zpos[
'T4bX']+3.64-deltaZ
602start = (daniel[
'T4_T04'][0] + daniel[
'T4_B04'][0])/2. -delta
604 xpos[n+i] = start + delta * i
605 zpos[n+i] = zpos[
'T4bX']+3.64+4.06-deltaZ
607start = (daniel[
'T4_T04'][0] + daniel[
'T4_B04'][0])/2. -delta -2.1
609 xpos[n+i] = start + delta * i
610 zpos[n+i] = zpos[
'T4bX']+3.64+4.06+3.64-deltaZ
613zpos[
'T4cX'] = (( daniel[
'T4_T05'][2] + daniel[
'T4_B05'][2] + daniel[
'T4_T06'][2] + daniel[
'T4_B06'][2])/4. - 4.33 -3.64-4.06-3.64)
614ypos[
'T4cX'] = [(daniel[
'T4_T05'][1]+daniel[
'T4_T06'][1])/2.,(daniel[
'T4_B05'][1]+daniel[
'T4_B06'][1])/2.]
616delta = ( (daniel[
'T4_T05'][0] + daniel[
'T4_B05'][0])/2. - (daniel[
'T4_T06'][0] + daniel[
'T4_B06'][0])/2. )/8.
620start = (daniel[
'T4_T06'][0] + daniel[
'T4_B06'][0])/2. -delta +45.2
622 xpos[n-i] = start - delta * i
623 zpos[n-i] = zpos[
'T4cX']-deltaZ
625start = (daniel[
'T4_T06'][0] + daniel[
'T4_B06'][0])/2. -delta +45.2 -10*delta-2.1
627 xpos[n+i] = start + delta * i
628 zpos[n+i] = zpos[
'T4cX']+3.64-deltaZ
630start = (daniel[
'T4_T06'][0] + daniel[
'T4_B06'][0])/2. -delta
632 xpos[n+i] = start + delta * i
633 zpos[n+i] = zpos[
'T4cX']+3.64+4.06-deltaZ
635start = (daniel[
'T4_T06'][0] + daniel[
'T4_B06'][0])/2. -delta -2.1
637 xpos[n+i] = start + delta * i
638 zpos[n+i] = zpos[
'T4cX']+3.64+4.06+3.64-deltaZ
641zpos[
'T4dX'] = (( daniel[
'T4_T07'][2] + daniel[
'T4_B07'][2] + daniel[
'T4_T08'][2] + daniel[
'T4_B08'][2])/4. - 4.33 -3.64-4.06-3.64)
642ypos[
'T4dX'] = [(daniel[
'T4_T07'][1]+daniel[
'T4_T08'][1])/2.,(daniel[
'T4_B07'][1]+daniel[
'T4_B08'][1])/2.]
644delta = ( (daniel[
'T4_T07'][0] + daniel[
'T4_B07'][0])/2. - (daniel[
'T4_T08'][0] + daniel[
'T4_B08'][0])/2. )/8.
648start = (daniel[
'T4_T08'][0] + daniel[
'T4_B08'][0])/2. -delta +45.2
650 xpos[n-i] = start - delta * i
651 zpos[n-i] = zpos[
'T4dX']-deltaZ
653start = (daniel[
'T4_T08'][0] + daniel[
'T4_B08'][0])/2. -delta +45.2 -10*delta-2.1
655 xpos[n+i] = start + delta * i
656 zpos[n+i] = zpos[
'T4dX']+3.64-deltaZ
658start = (daniel[
'T4_T08'][0] + daniel[
'T4_B08'][0])/2. -delta
660 xpos[n+i] = start + delta * i
661 zpos[n+i] = zpos[
'T4dX']+3.64+4.06-deltaZ
663start = (daniel[
'T4_T08'][0] + daniel[
'T4_B08'][0])/2. -delta -2.1
665 xpos[n+i] = start + delta * i
666 zpos[n+i] = zpos[
'T4dX']+3.64+4.06+3.64-deltaZ
670 print a,Langle[a]*180./ROOT.TMath.Pi()
671 for s
in [
'T1_MA_',
'T1_MB_',
'T2_MC_',
'T2_MD_']:
672 for x
in [
'01',
'02',
'03',
'04']:
673 print 'delta survey corrected - Daniel: %s %6.4F,%6.4F,%6.4F'%(s+x,surveyXYZ[s+x][0]-daniel[s+x][0],surveyXYZ[s+x][1]-daniel[s+x][1],surveyXYZ[s+x][2]-daniel[s+x][2])
674 for s
in [
'T1_MA_',
'T1_MB_',
'T2_MC_',
'T2_MD_']:
675 for top
in [
'01',
'02']:
676 delx = surveyXYZ[s+top][0]-surveyXYZ[s+top.replace(
'01',
'04').replace(
'02',
'03')][0]
677 dely = surveyXYZ[s+top][1]-surveyXYZ[s+top.replace(
'01',
'04').replace(
'02',
'03')][1]
678 r = ROOT.TMath.Sqrt(delx**2+dely**2)
679 angle = ROOT.TMath.ATan2(delx,dely)*180./ROOT.TMath.Pi()
687 ut.bookHist(h,
'alignCompare',
'compare Alignments',100,-120.,120.,100,-120.,120.)
688 ut.bookHist(h,
'alignCompareDiffs',
'compare Alignments',100,-1.,1.)
692 test = ROOT.MufluxSpectrometerHit(d,0.)
693 test.MufluxSpectrometerEndPoints(vbot,vtop)
694 statnb,vnb,pnb,lnb,view,channelID,tdcId,nRT =
stationInfo(test)
695 angle = ROOT.TMath.ATan2(-vtop[0]+vbot[0],-vtop[1]+vbot[1])/ROOT.TMath.Pi()*180
696 L = ROOT.TMath.Sqrt( (vbot[0]-vtop[0])**2+(vbot[1]-vtop[1])**2)
697 if view==
'_x': vbotD,vtopD = ROOT.TVector3(xpos[d],L/2.,zpos[d]),ROOT.TVector3(xpos[d],-L/2.,zpos[d])
698 else: vbotD,vtopD = ROOT.TVector3(xposb[d],yposb[d],zpos[d]),ROOT.TVector3(xpos[d],ypos[d],zpos[d])
699 angleD = ROOT.TMath.ATan2(vtopD[0]-vbotD[0],vtopD[1]-vbotD[1])/ROOT.TMath.Pi()*180
700 if abs(vtop[0]-vbot[0])<1:
701 x0 = (vtop[0]+vbot[0])/2.
703 m = (vtop[1]-vbot[1])/(vtop[0]-vbot[0])
704 b = vtop[1]-m*vtop[0]
706 if abs(vtopD[0]-vbotD[0])<1:
707 x0D = (vtopD[0]+vbotD[0])/2.
709 mD = (vtopD[1]-vbotD[1])/(vtopD[0]-vbotD[0])
710 bD = vtopD[1]-mD*vtopD[0]
713 z = (vbot[2]+vtop[2])/2.
715 if abs(diff)>0.1 : txt =
"!!! "
716 if abs(z-vbotD[2])>0.1: txt+=
"!!z"
717 print "%s %i x/y pos from Daniel %7.4F %7.4F %7.4F %7.4F %7.4F from FairShip %7.4F %7.4F %7.4F %7.4F %7.4F diff %5.4F zdiff %5.4F"\
718 %(txt,d,x0D,angleD,vbotD[1],vtopD[1],vbotD[2],x0,angle,vtop[1],vbot[1],vbot[2],(x0D-x0)*10.,(z-vbotD[2])*10)
719 if abs(vbot[2]-vtop[2])>0.1:
print "!!! z tilt",vbot[2],vtop[2]
720 rc = h[
'alignCompare'].Fill(x0D,x0)
721 rc = h[
'alignCompareDiffs'].Fill(x0D-x0)
722 z0_D = zpos[
'T1X']/10.
723 test = ROOT.MufluxSpectrometerHit(10002001,0.)
724 test.MufluxSpectrometerEndPoints(vbot,vtop)
725 z0_F = (vbot[2]+vtop[2])/2.
727 test = ROOT.MufluxSpectrometerHit(11002001,0.)
728 test.MufluxSpectrometerEndPoints(vbot,vtop)
729 z1_U = (vbot[2]+vtop[2])/2. - z0_F
730 print "distance T1 X to T1 U:",zpos[
'T1U']/10.-z0_D,z1_U
732 test = ROOT.MufluxSpectrometerHit(20002001,0.)
733 test.MufluxSpectrometerEndPoints(vbot,vtop)
734 z2_V = (vbot[2]+vtop[2])/2. - z0_F
735 print "distance T1 X to T2 V:",zpos[
'T2V']/10.-z0_D,z2_V
737 test = ROOT.MufluxSpectrometerHit(21002001,0.)
738 test.MufluxSpectrometerEndPoints(vbot,vtop)
739 z2_X = (vbot[2]+vtop[2])/2. - z0_F
740 print "distance T1 X to T2 X:",zpos[
'T2X']/10.-z0_D,z2_X
742 test = ROOT.MufluxSpectrometerHit(30002001,0.)
743 test.MufluxSpectrometerEndPoints(vbot,vtop)
744 z3_X = (vbot[2]+vtop[2])/2. - z0_F
745 print "distance T1 X to T3 X:",(zpos[
'T3aX']+zpos[
'T3bX']+zpos[
'T3cX']+zpos[
'T3dX'])/(4*10.)-z0_D,z3_X
747 test = ROOT.MufluxSpectrometerHit(40002001,0.)
748 test.MufluxSpectrometerEndPoints(vbot,vtop)
749 z4_X = (vbot[2]+vtop[2])/2. - z0_F
750 print "distance T1 X to T4 X:",(zpos[
'T4aX']+zpos[
'T4bX']+zpos[
'T4cX']+zpos[
'T4dX'])/(4*10.)-z0_D,z4_X
753 print "z-positions relative to station 1"
754 test = ROOT.MufluxSpectrometerHit(10002012,0.)
755 test.MufluxSpectrometerEndPoints(vbot,vtop)
756 z1 = (surveyXYZ[
'T1_MA_01'][2]+surveyXYZ[
'T1_MA_04'][2])/2.+3.03
758 print " X topY botY Z"
759 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T1_MA_01/04 survey corrected",(surveyXYZ[
'T1_MA_01'][0]+surveyXYZ[
'T1_MA_04'][0])/2.,surveyXYZ[
'T1_MA_01'][1],surveyXYZ[
'T1_MA_04'][1],z1-z1)
760 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T1_MA_01/04 Daniel ",(daniel[
'T1_MA_01'][0]+daniel[
'T1_MA_04'][0])/2.,daniel[
'T1_MA_01'][1],daniel[
'T1_MA_04'][1],(daniel[
'T1_MA_01'][2]+daniel[
'T1_MA_04'][2])/2.+3.03-z1)
761 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 10002012 ",vtop[0],vbot[1],vtop[1],vtop[2]-z1F)
763 vtop2,vbot2 = ROOT.TVector3(),ROOT.TVector3()
764 test2 = ROOT.MufluxSpectrometerHit(10102001,0.)
765 test2.MufluxSpectrometerEndPoints(vbot2,vtop2)
766 delx = (daniel[
'T1_MA_01'][0]+daniel[
'T1_MA_04'][0])/2.-(daniel[
'T1_MA_02'][0]+daniel[
'T1_MA_03'][0])/2.
767 dely = [daniel[
'T1_MA_01'][1]-daniel[
'T1_MA_02'][1],daniel[
'T1_MA_04'][1]-daniel[
'T1_MA_03'][1]]
768 delz = ((daniel[
'T1_MA_01'][2]+daniel[
'T1_MA_04'][2])/2.+3.03) - ((daniel[
'T1_MA_02'][2]+daniel[
'T1_MA_03'][2])/2.+3.03+3.64+4.06)
769 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T1_MA_01/04 - T1_MA_02/03 ",delx,dely[0],dely[1],delz)
770 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 10002012 - 10102001 ",vtop[0]-vtop2[0],vtop[1]-vtop2[1],vbot[1]-vbot2[1],vtop[2]-vtop2[2])
771 test = ROOT.MufluxSpectrometerHit(21112001,0.)
772 test.MufluxSpectrometerEndPoints(vbot,vtop)
773 z2 = (surveyXYZ[
'T2_MD_02'][2]+surveyXYZ[
'T2_MD_03'][2])/2.-3.03
774 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T2_MD_02/03 survey corrected",(surveyXYZ[
'T2_MD_02'][0]+surveyXYZ[
'T2_MD_03'][0])/2.,surveyXYZ[
'T2_MD_02'][1],surveyXYZ[
'T2_MD_03'][1],z2-z1)
775 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T2_MD_02/03 Daniel ",(daniel[
'T2_MD_02'][0]+daniel[
'T2_MD_03'][0])/2.,daniel[
'T2_MD_02'][1],daniel[
'T2_MD_03'][1],(daniel[
'T2_MD_02'][2]+daniel[
'T2_MD_03'][2])/2.-3.03-z1)
776 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 21112001 ",vtop[0],vbot[1],vtop[1],vtop[2]-z1F)
777 test = ROOT.MufluxSpectrometerHit(11002012,0.)
778 test.MufluxSpectrometerEndPoints(vbot,vtop)
779 z1b = (surveyXYZ[
'T1_MB_01'][2]+surveyXYZ[
'T1_MB_04'][2])/2.-3.03-3.64-4.06-3.64
781 m = (surveyXYZ[
'T1_MB_01'][1]-surveyXYZ[
'T1_MB_04'][1])/(surveyXYZ[
'T1_MB_01'][0]-surveyXYZ[
'T1_MB_04'][0])
782 b = surveyXYZ[
'T1_MB_01'][1] - m*surveyXYZ[
'T1_MB_01'][0]
784 m = (daniel[
'T1_MB_01'][1]-daniel[
'T1_MB_04'][1])/(daniel[
'T1_MB_01'][0]-daniel[
'T1_MB_04'][0])
785 b = daniel[
'T1_MB_01'][1] - m*daniel[
'T1_MB_01'][0]
787 m = (vbot[1]-vtop[1])/(vbot[0]-vtop[0])
788 b = vbot[1] - m*vbot[0]
790 print " X@Y=0 topY botY Z"
791 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T1_MB_01/04 survey corrected",xposAty0,surveyXYZ[
'T1_MB_01'][1],surveyXYZ[
'T1_MB_04'][1],z1b-z1)
792 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T1_MB_01/04 Daniel ",xposAty0D,daniel[
'T1_MB_01'][1],daniel[
'T1_MB_04'][1],(daniel[
'T1_MB_01'][2]+daniel[
'T1_MB_04'][2])/2.-3.03-3.64-4.06-3.64-z1)
793 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 11002012 ",xposAty0F,vbot[1],vtop[1],vtop[2]-z1F)
794 test = ROOT.MufluxSpectrometerHit(20012012,0.)
795 test.MufluxSpectrometerEndPoints(vbot,vtop)
796 z2b = (surveyXYZ[
'T2_MC_01'][2]+surveyXYZ[
'T2_MC_04'][2])/2.+3.03+3.64
797 m = (surveyXYZ[
'T2_MC_01'][1]-surveyXYZ[
'T2_MC_04'][1])/(surveyXYZ[
'T2_MC_01'][0]-surveyXYZ[
'T2_MC_04'][0])
798 b = surveyXYZ[
'T2_MC_01'][1] - m*surveyXYZ[
'T2_MC_01'][0]
800 m = (daniel[
'T2_MC_01'][1]-daniel[
'T2_MC_04'][1])/(daniel[
'T2_MC_01'][0]-daniel[
'T2_MC_04'][0])
801 b = daniel[
'T2_MC_01'][1] - m*daniel[
'T2_MC_01'][0]
803 m = (vbot[1]-vtop[1])/(vbot[0]-vtop[0])
804 b = vbot[1] - m*vbot[0]
806 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T2_MC_01/04 survey corrected",xposAty0,surveyXYZ[
'T2_MC_01'][1],surveyXYZ[
'T2_MC_04'][1],z2b-z1)
807 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T2_MC_01/04 Daniel ",xposAty0D,daniel[
'T2_MC_01'][1],daniel[
'T2_MC_04'][1],(daniel[
'T2_MC_01'][2]+daniel[
'T2_MC_04'][2])/2.+3.03+3.64-z1)
808 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 20012012 ",xposAty0F,vbot[1],vtop[1],vtop[2]-z1F)
809 test = ROOT.MufluxSpectrometerHit(30012046,0.)
810 test.MufluxSpectrometerEndPoints(vbot,vtop)
812 z3 = (surveyXYZ[
'T3_T01'][2]+surveyXYZ[
'T3_B01'][2])/2.+4.33+3.64 + 7.0
813 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T3_T01/B01 survey corrected",(surveyXYZ[
'T3_T01'][0]+surveyXYZ[
'T3_B01'][0])/2.,surveyXYZ[
'T3_T01'][1],surveyXYZ[
'T3_B01'][1],z3-z1)
814 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T3_T01/B01 Daniel ",(daniel[
'T3_T01'][0]+daniel[
'T3_B01'][0])/2.,daniel[
'T3_T01'][1],daniel[
'T3_B01'][1],(daniel[
'T3_T01'][2]+daniel[
'T3_B01'][2])/2.+4.33+3.64-z1)
815 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 30012046 ",vtop[0],vbot[1],vtop[1],vtop[2]-z1F)
816 test = ROOT.MufluxSpectrometerHit(40102046,0.)
817 test.MufluxSpectrometerEndPoints(vbot,vtop)
818 z4 = (surveyXYZ[
'T4_T01'][2]+surveyXYZ[
'T4_B01'][2])/2.-4.33-3.64 - 7.0
819 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T4_T01/B01 survey corrected",(surveyXYZ[
'T4_T01'][0]+surveyXYZ[
'T4_B01'][0])/2.,surveyXYZ[
'T4_T01'][1],surveyXYZ[
'T4_B01'][1],z4-z1)
820 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"T4_T01/B01 Daniel ",(daniel[
'T4_T01'][0]+daniel[
'T4_B01'][0])/2.,daniel[
'T4_T01'][1],daniel[
'T4_B01'][1],(daniel[
'T4_T01'][2]+daniel[
'T4_B01'][2])/2.-4.33-3.64-z1)
821 print "%s, %7.3F,%7.3F,%7.3F,%7.3F"%(
"tube 40102046 ",vtop[0],vbot[1],vtop[1],vtop[2]-z1F)
825 for s
in [
'T1_MA_',
'T1_MB_',
'T2_MC_',
'T2_MD_']:
827 for x
in [
'01',
'02',
'03',
'04']:
828 meanZ += daniel[s+x][2]
831 for x
in [
'01',
'02',
'03',
'04']:
832 rms += (daniel[s+x][2]-meanZ)**2
833 rms = ROOT.TMath.Sqrt(rms)
834 diffTopBot = daniel[s+
'01'][2]-daniel[s+
'04'][2],daniel[s+
'02'][2]-daniel[s+
'03'][2]
835 diffLefRig = daniel[s+
'01'][2]-daniel[s+
'02'][2],daniel[s+
'04'][2]-daniel[s+
'03'][2]
836 print s,meanZ,rms,
' top/bot ',diffTopBot,
' left/right ',diffLefRig
838 for s
in [
'T3',
'T4']:
840 for y
in [
'_T',
'_B']:
841 for x
in [
'01',
'02',
'03',
'04',
'05',
'06',
'07',
'08']:
842 meanZ += daniel[s+y+x][2]
843 print s+y+x,daniel[s+y+x][2]
846 for y
in [
'_T',
'_B']:
847 for x
in [
'01',
'02',
'03',
'04',
'05',
'06',
'07',
'08']:
848 rms += (daniel[s+y+x][2]-meanZ)**2
849 rms = ROOT.TMath.Sqrt(rms)
858withDefaultAlignment =
True
864 nt = len(h[
'dispTrack3D'])
865 h[
'dispTrack3D'].append( ROOT.TPolyLine3D(nPoints) )
866 h[
'dispTrack3D'][nt].SetLineWidth(3)
867 h[
'dispTrack3D'][nt].SetLineColor(ROOT.kBlack)
868 for nP
in range(nPoints):
871 if not rc:
print "extrap failed"
873 h[
'dispTrack3D'][nt].SetPoint(nP,pos[0],pos[1],pos[2])
874 rc = ROOT.gROOT.FindObject(
'c1').cd()
875 h[
'dispTrack3D'][nt].Draw(
'oglsame')
876 rc = ROOT.gROOT.FindObject(
'c1').Update()
878 ut.bookHist(h,
'upstream',
'upstream layers',12,-0.5,11.5,30,-0.5,29.5)
879 if not h.has_key(
'layerDisplay'): ut.bookCanvas(h,key=
'layerDisplay',title=
'Upstream Layers',nx=1600,ny=1200,cx=1,cy=0)
880 h[
'upstreamG'] = ROOT.TGraph()
881 h[
'upstreamG'].Set(0)
882 h[
'upstreamG'].SetMarkerStyle(8)
883 h[
'upstreamG'].SetMarkerSize(2)
885 for hit
in sTree.Digi_MufluxSpectrometerHits:
886 detID = hit.GetDetectorID()
888 statnb,vnb,pnb,lnb,view,channelID,tdcId,nRT =
stationInfo(hit)
890 y = 2*pnb+lnb+(statnb-1)*16
892 if view==
'_x' and statnb>1: y+=8
893 h[
'upstreamG'].SetPoint(n,nr,y)
895 tc = h[
'layerDisplay'].cd(1)
897 h[
'upstreamG'].Draw(
'sameP')
900 rc = h[
'simpleDisplay'].cd(1)
901 h[
'yprojtxt'] = ROOT.TLatex(200,100,
'Y projection')
902 h[
'xprojtxt'] = ROOT.TLatex(600,-20,
'X projection')
903 h[
'xprojtxt'].SetTextColor(ROOT.kMagenta)
904 h[
'yprojtxt'].SetTextColor(ROOT.kCyan)
907 myPrint(h[
'simpleDisplay'],
'EventDisplay')
912 if not n<0: rc = sTree.GetEvent(n)
913 h[
'hitCollection']= {
'upstream':[0,ROOT.TGraph()],
'downstream':[0,ROOT.TGraph()],
'muonTaggerX':[0,ROOT.TGraph()],
'muonTaggerY':[0,ROOT.TGraph()]}
915 for c
in h[
'hitCollection']: rc=h[
'hitCollection'][c][1].SetName(c)
916 for c
in h[
'hitCollection']: rc=h[
'hitCollection'][c][1].Set(0)
917 ut.bookHist(h,
'xz',
'x (y) vs z; Z [cm]; X(Y) [cm]',500,0.,1200.,100,-100.,100.)
918 if not h.has_key(
'simpleDisplay'): ut.bookCanvas(h,key=
'simpleDisplay',title=
'simple event display',nx=1200,ny=800,cx=1,cy=0)
919 rc = h[
'simpleDisplay'].cd(1)
920 h[
'xz'].SetMarkerStyle(30)
923 for hit
in sTree.Digi_MufluxSpectrometerHits:
924 if not hit.hasTimeOverThreshold():
continue
925 statnb,vnb,pnb,lnb,view,channelID,tdcId,nRT =
stationInfo(hit)
927 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
929 stereoHit = ROOT.TGraph()
930 stereoHit.SetPoint(0,vbot[2],vbot[0])
931 stereoHit.SetPoint(1,vtop[2],vtop[0])
932 h[
'stereoHits'].append(stereoHit)
935 c = h[
'hitCollection'][
'upstream']
936 rc = c[1].SetPoint(c[0],vbot[2],vbot[0])
939 c = h[
'hitCollection'][
'downstream']
940 rc = c[1].SetPoint(c[0],vbot[2],vbot[0])
942 c = h[
'hitCollection'][
'muonTaggerX']
943 cy = h[
'hitCollection'][
'muonTaggerY']
944 if sTree.GetBranch(
"Digi_MuonTaggerHits"):
945 for hit
in sTree.Digi_MuonTaggerHits:
946 channelID = hit.GetDetectorID()
947 statnb = channelID/10000
948 view = (channelID-10000*statnb)/1000
949 channel = channelID%1000
950 vbot,vtop = RPCPositionsBotTop[channelID]
952 x,z = (vtop[0]+vbot[0])/2.,(vtop[2]+vbot[2])/2.
953 rc = c[1].SetPoint(c[0],z,x)
956 y,z = (vtop[1]+vbot[1])/2.,(vtop[2]+vbot[2])/2.
957 rc = cy[1].SetPoint(cy[0],z,y)
959 h[
'hitCollection'][
'downstream'][1].SetMarkerColor(ROOT.kRed)
960 h[
'hitCollection'][
'upstream'][1].SetMarkerColor(ROOT.kBlue)
961 h[
'hitCollection'][
'muonTaggerX'][1].SetMarkerColor(ROOT.kGreen)
962 h[
'hitCollection'][
'muonTaggerY'][1].SetMarkerColor(ROOT.kCyan)
963 for c
in h[
'hitCollection']: rc=h[
'hitCollection'][c][1].SetMarkerStyle(30)
964 for c
in h[
'hitCollection']:
965 if h[
'hitCollection'][c][1].GetN()<1:
continue
966 rc=h[
'hitCollection'][c][1].Draw(
'sameP')
967 h[
'display:'+c]=h[
'hitCollection'][c][1]
968 for g
in h[
'stereoHits']:
971 h[
'simpleDisplay'].Update()
973viewDict = {0:
'_x',1:
'_u',2:
'_v'}
975 info = hit.StationInfo()
976 return info[0],info[1],info[2],info[3],viewDict[info[4]],info[5],info[6],info[7]/cuts[
'RTsegmentation']
979tdcIds ={
'1000_x':[0],
'1001_x':[0],
'1010_x':[0],
'1011_x':[0],
980 '1100_u':[0],
'1101_u':[0],
'1110_u':[0],
'1111_u':[0],
981 '2000_v':[0],
'2001_v':[0],
'2010_v':[1],
'2011_v':[1],
982 '2100_x':[1],
'2101_x':[1],
'2110_x':[1],
'2111_x':[1],
983 '3000_x':[3,4],
'3001_x':[3,4],
'3010_x':[3,4],
'3011_x':[3,4],
984 '4000_x':[3,2,1],
'4001_x':[3,2,1],
'4010_x':[2,1],
'4011_x':[2,1]}
997 for view
in [
'_x',
'_u',
'_v']:
998 if (s==1
and view==
'_v')
or (s==2
and view==
'_u')
or (s>2
and view !=
'_x'):
continue
999 ut.bookHist(h,str(1000*s+100*p+10*l)+view,
'hit map station'+str(s)+
' plane'+str(p)+
' layer '+str(l)+view,50,-0.5,49.5)
1001 if s==2
and view ==
"_x": v = 1
1002 if s==1
and view ==
"_u": v = 1
1003 myDetID = s * 1000 + v * 100 + p * 10 + l
1004 for nRT
in range(576 / cuts[
'RTsegmentation'] ):
1005 ut.bookHist(h,
"TDC" +str(nRT),
'TDC station'+str(s)+
' plane'+str(p)+
' layer '+str(l)+view,1500,-500.,2500.)
1006 ut.bookHist(h,
"TDC" +str(nRT)+
'_noToT',
'TDC station'+str(s)+
' plane'+str(p)+
' layer '+str(l)+view,1500,-500.,2500.)
1007 xLayers[s][p][l][view]=h[str(1000*s+100*p+10*l)+view]
1008 channels[s][p][l][view]=12
1009 if s>2: channels[s][p][l][view]=48
1010for x
in xpos.keys():
1011 ut.bookHist(h,
"TDC" +str(x),
'TDC '+str(x)+
'; TDC [ns]' ,1500,-500.,2500.)
1012 ut.bookHist(h,
"TDC" +str(x),
'noToT '+str(x)+
'; TDC [ns]',1500,-500.,2500.)
1014ut.bookCanvas(h,
'dummy',
' ',900,600,1,1)
1015ut.bookHist(h,
'T0tmp',
'T0 temp',1250,-500.,2000.)
1016ut.bookHist(h,
'T0',
'T0',1250,-500.,2000.)
1020deadChannels4MC = ROOT.std.vector(
'int')()
1021for c
in [10112001,11112012,20112003,30002042,30012026,30102021,30102025,30112013,30112018,40012014]: deadChannels4MC.push_back(c)
1022deadChannelsRPC4MC = ROOT.std.vector(
'int')()
1023for c
in [31093,31094,31095,31096,11029,11030,51141,51142,10057,10058]: deadChannelsRPC4MC.push_back(c)
1025gol = sGeo.GetTopVolume().GetNode(
"volGoliath_1")
1026zgoliath = gol.GetMatrix().GetTranslation()[2]
1029 for x
in ROOT.gGeoManager.GetTopVolume().GetNodes():
1030 if x.GetName().find(
'volDriftTube')<0:
continue
1031 for y
in x.GetVolume().GetNodes():
1032 if y.GetName().find(
'plane')<0:
continue
1033 for z
in y.GetVolume().GetNodes():
1034 rc = nav.cd(
'/'+x.GetName()+
'/'+y.GetName()+
'/'+z.GetName())
1035 vol = nav.GetCurrentNode()
1036 shape = vol.GetVolume().GetShape()
1037 local = array(
'd',[0,0,0])
1038 globOrigin = array(
'd',[0,0,0])
1039 nav.LocalToMaster(local,globOrigin)
1040 DT[z.GetName()] = [shape.GetDX(),shape.GetDY(),globOrigin[2]]
1042nav.cd(
'/VMuonBox_1/VSensitive1_1')
1043loc = array(
'd',[0,0,0])
1044glob = array(
'd',[0,0,0])
1045nav.LocalToMaster(loc,glob)
1047cuts[
'zRPC1'] = zRPC1
1048node = nav.GetCurrentNode()
1049dx = node.GetVolume().GetShape().GetDX()
1050dy = node.GetVolume().GetShape().GetDY()
1051loc = array(
'd',[-dx,0,0])
1052nav.LocalToMaster(loc,glob)
1053cuts[
'xLRPC1'] = glob[0]
1054loc = array(
'd',[dx,0,0])
1055nav.LocalToMaster(loc,glob)
1056cuts[
'xRRPC1'] = glob[0]
1057loc = array(
'd',[0,-dy,0])
1058nav.LocalToMaster(loc,glob)
1059cuts[
'yBRPC1'] = glob[1]
1060loc = array(
'd',[0,dy,0])
1061nav.LocalToMaster(loc,glob)
1062cuts[
'yTRPC1'] = glob[1]
1063cuts[
"firstDTStation_z"] = DT[
'Station_1_x_plane_0_layer_0_10000000'][2]
1064cuts[
"lastDTStation_z"] = DT[
'Station_4_x_plane_1_layer_1_40110000'][2]
1067 if method <1: effFudgeFactors = {
"u":1.1,
"v":1.1,
"x2":1.1,
"x3":1.1,
"x1":1.1,
"x4":1.1}
1068 if method ==0: effFudgeFactors = {
"x1":0.97,
"u":0.95,
"x2":0.96,
"v":0.96,
"x3":0.92,
"x4":0.97}
1069 if method ==2: effFudgeFactors = {
"x1":0.94,
"u":0.93,
"x2":0.95,
"v":0.93,
"x3":0.90,
"x4":0.94}
1070 for x
in effFudgeFactors: muflux_Reco.setEffFudgeFactor(x,effFudgeFactors[x])
1073xSHiP = ROOT.TTreeReader(sTree)
1074muflux_Reco = ROOT.MufluxReco(xSHiP)
1075for x
in cuts: muflux_Reco.setCuts(x,cuts[x])
1077if sTree.GetBranch(
'MCTrack'):
1078 muflux_Reco.setNoisyChannels(deadChannels4MC)
1079 muflux_Reco.setDeadChannels(deadChannelsRPC4MC)
1083 for hit
in sTree.Digi_MufluxSpectrometerHits:
1086 if not hit.isValid()
and MCdata:
continue
1087 detID=hit.GetDetectorID()
1088 if detID<0:
continue
1089 if keysToDThits.has_key(detID):
1090 prevTDC = sTree.Digi_MufluxSpectrometerHits[keysToDThits[detID][0]].GetDigi()
1091 prevToT = sTree.Digi_MufluxSpectrometerHits[keysToDThits[detID][0]].GetTimeOverThreshold()
1093 if hit.hasTimeOverThreshold(): keysToDThits[detID]=[key]
1095 keysToDThits[detID]=[key]
1097 for hit
in sTree.Digi_LateMufluxSpectrometerHits:
1099 if not hit.isValid()
and MCdata:
continue
1100 if not hit.hasTimeOverThreshold():
continue
1101 if hit.GetTimeOverThreshold()<minToT :
continue
1102 detID=hit.GetDetectorID()
1103 if not keysToDThits.has_key(detID):
1104 print "MakeKeysToDThits, late hit but no first one",detID
1105 keysToDThits[detID]=[-1]
1106 keysToDThits[detID].append(key)
1111 ut.bookHist(h,
'multLateDTHits',
'multiplicity of late DT hits',11,-1.5,9.5)
1112 ut.bookHist(h,
'ToverTvsTDC',
'Time over threshold vs tdc',300,-1000.,2000.,300,-1000.,2000.)
1114 for n
in range(nStart,nevents):
1115 rc=sTree.GetEvent(n)
1117 for channel
in keysToDThits:
1118 if keysToDThits[channel][0]<0: rc=h[
'multLateDTHits'].Fill(-1)
1121 rc=h[
'multLateDTHits'].Fill(len(keysToDThits[channel])-1)
1122 for n
in range(1,len(keysToDThits[channel])):
1123 key = keysToDThits[channel][n]
1124 aHit = sTree.Digi_LateMufluxSpectrometerHits[key]
1125 rc=h[
'ToverTvsTDC'].Fill( aHit.GetTimeOverThreshold() ,aHit.GetDigi())
1126 ROOT.gROOT.FindObject(
'c1').cd()
1127 h[
'multLateDTHits'].Draw()
1132 t0 = sTree.ShipEventHeader.GetEventTime()
1133 print "station layer channels (tdc MCTrackID) ..."
1134 else :
print "station layer channels (tdc time-over-threshold) ..."
1137 for s
in range(1,5):
1139 if v==2
and s!=2:
continue
1140 if v==1
and s!=1:
continue
1142 txt = str(s) +
' '+viewC[v]+
' '+str(l)+
' : '
1144 for hit
in hits[v][s][l]:
1145 statnb,vnb,pnb,lnb,view,channelID,tdcId,nRT =
stationInfo(hit)
1146 txt+=str(channelID)+
' '
1148 detID = hit.GetDetectorID()
1149 MCTrackID = sTree.MufluxSpectrometerPoint[keysToDThits[detID][0]].GetTrackID()
1150 tdc+=
"%5.0F %5i "%(hit.GetDigi()-t0,MCTrackID)
1152 tdc+=
"%5.0F %5.0F "%(hit.GetDigi()-t0,hit.GetTimeOverThreshold())
1153 lateArrivals = len(keysToDThits[hit.GetDetectorID()])
1154 if lateArrivals>1
and not MCdata:
1155 tmp = str(s) +
' '+viewC[v]+
' '+str(l)+
' : '+str(channelID)+
' '
1156 for n
in range(1,len(keysToDThits[hit.GetDetectorID()])):
1157 key = keysToDThits[hit.GetDetectorID()][n]
1158 lHit = sTree.Digi_LateMufluxSpectrometerHits[key]
1159 tmp+=
"%5.0F %5.0F "%(lHit.GetDigi()-t0,lHit.GetTimeOverThreshold())
1160 lateText.append(tmp)
1161 print "%-20s %s"%(txt,tdc)
1162 print "---- channels with late hits",len(lateText)
1163 for txt
in lateText:
print txt
1165 if not onlyPlotting: muflux_Reco.fillHitMaps()
1169 for s
in range(1,5):
1172 xLayers[s][p][l][
'_x'].Reset()
1173 if s==1: xLayers[s][p][l][
'_u'].Reset()
1174 if s==2: xLayers[s][p][l][
'_v'].Reset()
1177 for aTrack
in event.FitTracks:
1179 fst = aTrack.getFitStatus()
1180 if not fst.isFitConverged():
continue
1181 sta = aTrack.getFittedState(0)
1182 if sta.getMomMag() < 5.:
continue
1183 trInfo = event.TrackInfos[nt]
1184 for n
in range(trInfo.N()):
1185 if trInfo.wL(n) <0.1
and trInfo.wR(n) <0.1:
continue
1186 detID = trInfo.detId(n)
1187 hit = ROOT.MufluxSpectrometerHit(detID,0)
1188 s,v,p,l,view,channelID,tdcId,mdoduleId =
stationInfo(hit)
1189 rc = xLayers[s][p][l][view].Fill(channelID)
1190 ut.writeHists(h,
'histos-HitmapsFromFittedTracks-'+rname)
1193 deadThreshold = 1.E-4
1195 if sTree.GetBranch(
"FitTracks"):
1196 FitTracksBrStatus = sTree.GetBranchStatus(
"FitTracks")
1197 sTree.SetBranchStatus(
"FitTracks",0)
1198 if not onlyPlotting:
1200 for hit
in event.Digi_MufluxSpectrometerHits:
1201 s,v,p,l,view,channelNr,tdcId,nRT =
stationInfo(hit)
1203 if not hit.hasTimeOverThreshold(): tot=
'_noToT'
1205 rc = xLayers[s][p][l][view].Fill(channelNr)
1207 print "plotHitMaps error",hit.GetDetectorID(),s,v,p,l,view,channelNr,tdcId
1209 if hit.GetDetectorID()
not in noisyChannels:
1211 if MCdata: t0 = sTree.ShipEventHeader.GetEventTime()
1212 rc = h[
'TDC'+str(nRT)+tot].Fill(hit.GetDigi()-t0)
1213 channel =
'TDC'+str(hit.GetDetectorID())
1214 if not h.has_key(channel+tot): h[channel+tot]=h[
'TDC'+str(nRT)+tot].Clone(channel)
1215 rc = h[channel+tot].Fill(hit.GetDigi()-t0)
1216 if not h.has_key(
'hitMapsX'): ut.bookCanvas(h,key=
'hitMapsX',title=
'Hit Maps All Layers',nx=1600,ny=1200,cx=4,cy=6)
1217 if not h.has_key(
'TDCMapsX'): ut.bookCanvas(h,key=
'TDCMapsX',title=
'TDC Maps All Layers',nx=1600,ny=1200,cx=5,cy=10)
1218 if not h.has_key(
'TDCMapsX_noToT'): ut.bookCanvas(h,key=
'TDCMapsX_noToT',title=
'TDC Maps All Layers noToT',nx=1600,ny=1200,cx=5,cy=10)
1221 for s
in range(1,5):
1222 for view
in [
'_x',
'_u',
'_v']:
1225 if not xLayers[s][p][l].has_key(view):
continue
1226 if s>2
and view !=
'_x':
continue
1227 if s==1
and view ==
'_v'or s==2
and view ==
'_u':
continue
1229 rc = h[
'hitMapsX'].cd(j)
1230 xLayers[s][p][l][view].Draw()
1231 mean = xLayers[s][p][l][view].GetEntries()/channels[s][p][l][view]
1233 if s==2
and view ==
"_x": v = 1
1234 if s==1
and view ==
"_u": v = 1
1235 myDetID = s * 10000000 + v * 1000000 + p * 100000 + l*10000
1236 for i
in range(2,int(xLayers[s][p][l][view].GetEntries())+1):
1237 if i+1>Nchannels[s]:
continue
1238 channel = myDetID+i-1 + 2000
1239 if xLayers[s][p][l][view].GetBinContent(i) > noiseThreshold * mean:
1240 print "noisy channel:",s,p,l,view,xLayers[s][p][l][view].GetBinContent(i) , noiseThreshold , mean
1241 if not channel
in noisyChannels: noisyChannels.append(myDetID+i-1)
1242 if xLayers[s][p][l][view].GetBinContent(i) < max(1,deadThreshold * mean):
1243 print "dead channel:",s,p,l,view,i,xLayers[s][p][l][view].GetBinContent(i) , deadThreshold , mean
1244 deadChannels.append(channel)
1246 for nRT
in range(1,576/cuts[
'RTsegmentation']+1):
1248 tp = h[
'TDCMapsX'].cd(jt)
1250 h[
'TDC'+str(nRT-1)].Draw()
1251 tp = h[
'TDCMapsX_noToT'].cd(jt)
1253 h[
'TDC'+str(nRT-1)+
'_noToT'].Draw()
1255 print "list of noisy channels"
1256 for n
in noisyChannels:
print n
1257 print "list of dead channels"
1258 for n
in deadChannels:
print n
1259 if sTree.GetBranch(
"FitTracks"): sTree.SetBranchStatus(
"FitTracks",FitTracksBrStatus)
1262 ut.bookHist(h,
'integratedrate',
'rate integrated',100,-0.5,99.5)
1263 ut.bookHist(h,
'rate',
'rate',100,-0.5,99.5)
1264 ut.bookHist(h,
'scalers',
'rate',100,-0.5,99.5)
1265 if not h.has_key(
'rates'): ut.bookCanvas(h,key=
'rates',title=
'Rates',nx=800,ny=400,cx=2,cy=1)
1266 rc = h[
'rates'].cd(1)
1267 scalers = sTree.GetCurrentFile().Get(
'scalers')
1269 print "no scalers in this file"
1273 for x
in scalers.GetListOfBranches():
1275 s = eval(
'scalers.'+name)
1277 print "%20s :%8i"%(name,s)
1278 rc=h[
'scalers'].Fill(ns,s)
1282 for n
in range(s.size()):
1285 rc=h[
'rate'].Fill(n,r0)
1286 rc=h[
'integratedrate'].Fill(n,s[n])
1288 h[
'rate'].Draw(
'hist')
1289 rc = h[
'rates'].cd(2)
1290 h[
'integratedrate'].Draw(
'hist')
1292ut.bookHist(h,
'delx',
'delta x',200,-50.,50.)
1293ut.bookHist(h,
'delta_mean_uv',
'delta to mean u and v',200,-10.,10.)
1294ut.bookHist(h,
'magPos',
'XY at goliath, PR',100,-50.,50.,100,-50.,50.)
1295for dets
in [
'34',
'stereo12',
'y12']: ut.bookHist(h,
'tracklets'+dets,
'hits per view',10,-0.5,9.5)
1296ut.bookHist(h,
'rpcHitmap',
'rpc Hitmaps',60,-0.5,59.5)
1299 ut.bookHist(h,
'rpcHitmap'+str(n)+str(l),
'rpc Hitmaps station '+str(n)+
'layer '+str(l),200,-0.5,199.5)
1302 if not h.has_key(
'rpcPlot'): ut.bookCanvas(h,key=
'rpcPlot',title=
'RPC Hitmaps',nx=1200,ny=600,cx=4,cy=3)
1304 for n
in range(1,6):
1307 rc = h[
'rpcPlot'].cd(j)
1308 h[
'rpcHitmap'+str(n)+str(l)].SetStats(0)
1310 h[
'rpcHitmap'+str(n)+str(l)].SetTitle(
'RPC hitmap station '+str(n)+
'Y readout; channel number N')
1311 h[
'rpcHitmap'+str(n)+str(l)].GetXaxis().SetRangeUser(0,120)
1313 h[
'rpcHitmap'+str(n)+str(l)].SetTitle(
'RPC hitmap station '+str(n)+
'X readout; channel number N')
1314 h[
'rpcHitmap'+str(n)+str(l)].Draw()
1315 rc = h[
'rpcPlot'].cd(j)
1316 h[
'rpcHitmap'].SetTitle(
'Number of hits per station ; station number ')
1317 h[
'rpcHitmap'].Draw()
1318 myPrint(h[
'rpcPlot'],
'RPCHitMap')
1320 h[
'X'] = ROOT.TFile(
'RPCHitMap.root')
1322 h[
'rpcPlot']=h[
'X'].Get(
'rpcPlot').Clone(
'rpcPlot')
1323 for pad
in h[
'rpcPlot'].GetListOfPrimitives():
1324 if pad.GetListOfPrimitives().GetSize()==0:
continue
1325 hist = pad.GetListOfPrimitives()[1]
1327 s = hist.GetName()[9:10]
1328 if hist.GetTitle().find(
'layer 1')>0:
1329 hist.SetTitle(
'RPC hitmap station '+s+
'X readout; channel number N')
1330 elif hist.GetTitle().find(
'layer 0')>0:
1331 hist.SetTitle(
'RPC hitmap station '+s+
'Y readout; channel number N')
1332 hist.GetXaxis().SetRangeUser(0,120)
1334 hist.SetTitle(
'Number of hits per station ; station number ')
1336 h[
'rpcPlot'].Update()
1338 myPrint(h[
'rpcPlot'],
'RPCHitMap')
1341 ut.bookHist(h,
'ToverT',
'Time over threshold',3000,-1000.,2000.)
1342 ut.bookHist(h,
'endTime',
'End Time',100,0.,2000.)
1343 ut.bookHist(h,
'tdc',
'tdc',100,-200.,2000.)
1345 rc = sTree.GetEvent(n)
1347 for aHit
in sTree.Digi_MufluxSpectrometerHits:
1348 detID=hit.GetDetectorID()
1349 if detID<0:
continue
1350 if not aHit.hasTimeOverThreshold():
1351 rc=h[
'ToverT'].Fill( -999. )
1353 rc=h[
'ToverT'].Fill( aHit.GetTimeOverThreshold() )
1354 rc=h[
'tdc'].Fill( aHit.GetDigi())
1355 rc=h[
'endTime'].Fill( aHit.GetDigi()+aHit.GetTimeOverThreshold() )
1356 if aHit.GetTimeOverThreshold() < 10: flag =
True
1359 spectrHitsSorted = ROOT.nestedList()
1360 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
True)
1361 for s
in range(1,5):
1362 for view
in viewsI[s]:
1364 for hit
in spectrHitsSorted[view][s][l]:
1365 print s,viewC[view],l,hit.GetDetectorID()%1000,hit.GetTimeOverThreshold()
1367from array
import array
1369gMan = ROOT.gGeoManager
1370geoMat = ROOT.genfit.TGeoMaterialInterface()
1372if zeroField: bfield = ROOT.genfit.BellField()
1373else: bfield = ROOT.genfit.FairShipFields()
1374fM = ROOT.genfit.FieldManager.getInstance()
1376ROOT.genfit.MaterialEffects.getInstance().
init(geoMat)
1377if zeroField: ROOT.genfit.MaterialEffects.getInstance().setNoEffects()
1379fitter = ROOT.genfit.DAF()
1380fitter.setMaxIterations(50)
1384 mat = ROOT.genfit.MaterialEffects.getInstance()
1388 mat.setMscModel(
'GEANE')
1389 mat.setEnergyLossBetheBloch(
True)
1390 mat.setNoiseBetheBloch(
True)
1391 mat.setNoiseCoulomb(
True)
1392 mat.setEnergyLossBrems(
True)
1393 mat.setNoiseBrems(
True)
1397 for p
in h[
'TDCMapsX'].GetListOfPrimitives():
1398 for x
in p.GetListOfPrimitives():
1399 if x.InheritsFrom(
'TH1'):
1404 for n
in range(1,x.GetNbinsX()-2):
1405 if x.GetBinContent(n)>2
and x.GetBinContent(n+1)>x.GetBinContent(n)+2
and x.GetBinContent(n+10)>x.GetBinContent(n):
1406 tmin = x.GetBinCenter(n)
1408 tmp = x.Clone(
'tmp')
1411 mean = tmp.GetBinContent(tmp.FindBin(tmp.GetMean()))
1412 for m
in range(tmp.GetNbinsX()-1,0,-1):
1413 runningMean=max(tmp.Integral(m,tmp.GetNbinsX()) / float(tmp.GetNbinsX()-m),2)
1414 if tmp.GetBinContent(m)>mean/5.:
1415 tmax = tmp.GetBinCenter(m)
1417 h[
'tMinAndTmax'][x.GetName()]=[tmin,tmax]
1418 h[x.GetName()+
'tMin'] = ROOT.TArrow(tmin,-5.,tmin,0.8,0.05,
">")
1419 h[x.GetName()+
'tMax'] = ROOT.TArrow(tmax,-5.,tmax,0.8,0.05,
">")
1420 h[x.GetName()+
'tMin'].SetLineColor(ROOT.kRed)
1421 h[x.GetName()+
'tMax'].SetLineColor(ROOT.kRed)
1422 h[x.GetName()+
'tMin'].Draw()
1423 h[x.GetName()+
'tMax'].Draw()
1427 R = ShipGeo.MufluxSpectrometer.InnerTubeDiameter/2.
1428 h[
'rt'+hname] = ROOT.TGraph()
1429 h[
'rt'+hname].SetName(
'rt'+hname)
1430 n0 = h[hname].FindBin(h[
'tMinAndTmax'][hname][0])
1431 n1 = h[hname].FindBin(h[
'tMinAndTmax'][hname][1])
1433 for n
in range(n0,n1):
1434 Ntot += h[hname].GetBinContent(n)
1435 for n
in range(n0,n1):
1437 for k
in range(n0,n):
1438 N+=h[hname].GetBinContent(k)
1439 h[
'rt'+hname].SetPoint(n-n0,h[hname].GetBinCenter(n), N/float(Ntot+1E-20)*R)
1440 h[
'rt'+hname].SetTitle(
'rt'+hname)
1441 h[
'rt'+hname].SetLineWidth(2)
1442 if not hname.find(
'TDC1')<0: h[
'rt'+hname].SetLineColor(ROOT.kBlue)
1443 elif not hname.find(
'TDC2')<0: h[
'rt'+hname].SetLineColor(ROOT.kCyan)
1444 elif not hname.find(
'TDC3')<0: h[
'rt'+hname].SetLineColor(ROOT.kGreen)
1445 elif not hname.find(
'TDC4')<0: h[
'rt'+hname].SetLineColor(ROOT.kGreen+2)
1446 h[
'RTrelations'].cd(1)
1447 h[
'legRT'].AddEntry(h[
'rt'+hname],h[
'rt'+hname].GetTitle(),
'PL')
1448 h[
'rt'+hname].Draw(
'same')
1451 if not h.has_key(
'RTrelations'):
1452 ut.bookCanvas(h,key=
'RTrelations',title=
'RT relations',nx=800,ny=500,cx=1,cy=1)
1453 h[
'RTrelations'].cd(1)
1455 h[
'emptyHist'] = ROOT.TH2F(
'empty',
' ;[ns];[cm] ',100,x.GetBinCenter(1),x.GetBinCenter(x.GetNbinsX()),100,0.,2.)
1456 h[
'emptyHist'].SetStats(0)
1457 h[
'emptyHist'].Draw()
1459 h[
'legRT'] = ROOT.TLegend(0.76,0.11,0.997,0.869)
1460 for p
in h[
'TDCMapsX'].GetListOfPrimitives():
1461 for o
in p.GetListOfPrimitives():
1463 h[
'legRT'].Draw(
'same')
1465ut.bookHist(h,
'TDC2R',
'RT relation; t [ns] ; r [cm]',100,0.,3000.,100,0.,2.)
1469 R = ShipGeo.MufluxSpectrometer.InnerTubeDiameter/2.
1472 t0 = t-sTree.ShipEventHeader.GetEventTime()
1473 r = t0*ShipGeo.MufluxSpectrometer.v_drift
1475 r+=rnr.Gaus(0,MCsmearing)
1478 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
1479 if nRT
in [16,17]: nRT = 18
1480 if nRT
in [30,31]: nRT = 32
1481 name =
'TDC'+str(nRT)
1483 if t > h[
'tMinAndTmax'][name][1]: r = R
1484 elif t< h[
'tMinAndTmax'][name][0]: r = 0
1486 r = h[
'rt'+name].Eval(t)
1487 if h.has_key(
'RTcorr'): r+=h[
'RTcorrFun_'+str(s)+view+str(2*p+l)].Eval(r)
1488 h[
'TDC2R'].Fill(t-t0,r)
1492 ut.bookHist(h,
'spr',
'spatial resolution MC',100,-1.,1.)
1493 ut.bookHist(h,
'MCposX',
'diff position X',100,-1.,1.)
1494 ut.bookHist(h,
'nMeasMC',
'number of hits per track',50,-0.5,49.5)
1495 for i
in range(sTree.GetEntries()):
1497 rc = sTree.GetEvent(i)
1498 if sTree.Digi_MufluxSpectrometerHits.GetEntries() != sTree.MufluxSpectrometerPoint.GetEntries():
1499 print "digi does not agree with MC, break"
1501 for n
in range(sTree.Digi_MufluxSpectrometerHits.GetEntries()):
1502 p = sTree.Digi_MufluxSpectrometerHits[n]
1503 pmc = sTree.MufluxSpectrometerPoint[n]
1504 mcp = pmc.GetTrackID()
1506 if abs(sTree.MCTrack[mcp].GetPdgCode())!=13:
continue
1510 rc = h[
'spr'].Fill(r-pmc.dist2Wire())
1511 vbot,vtop = strawPositionsBotTop[p.GetDetectorID()]
1512 rc = h[
'MCposX'].Fill(pmc.GetX()-vbot[0]+r)
1513 rc = h[
'MCposX'].Fill(pmc.GetX()-vbot[0]-r)
1514 if not trackID.has_key(mcp): trackID[mcp]=[]
1515 trackID[mcp].append(n)
1517 rc=h[
'nMeasMC'].Fill(len(trackID[mcp]))
1519 ut.bookHist(h,
'mass',
'mass',100,0.,2.)
1521 for m
in event.MCTrack:
1523 if not h.has_key(str(p)):
1524 h[str(p)]=h[
'mass'].Clone(str(p))
1525 rc=h[str(p)].Fill(m.GetMass())
1529 mo = m.GetMotherId()
1531 m = sTree.MCTrack[mo]
1532 mo = m.GetMotherId()
1533 if debug:
print m.GetPdgCode()
1534 if abs(m.GetPdgCode())==13:
1542 ut.bookHist(h,
'mom',
'momentum',400,0.,400.)
1547 for track
in event.FitTracks:
1549 info = event.TrackInfos[n]
1550 mcID = info.McTrack()
1552 pid = event.MCTrack[mcID].GetPdgCode()
1553 hname =
'mom'+str(pid)
1554 if not h.has_key(hname): h[hname]=h[
'mom'].Clone(hname)
1555 sta = track.getFittedState(0)
1557 if abs(pid)!=13: mu =
check4muon(event.MCTrack[mcID],
True)
1558 if not mu: rc = h[hname].Fill(sta.getMomMag())
1560 print N,pid, event.MCTrack[mcID].GetStartZ(),event.MCTrack[event.MCTrack[mcID].GetMotherId()].GetPdgCode(),mu
1565 if len(x)<4
or x.find(
'mom')!=0
or not x.find(
'momRes')<0:
continue
1566 pid = int(x.replace(
'mom',
''))
1567 pname = PDG.GetParticle(pid).GetName()
1568 h[
'stats'][pname]=h[x].GetEntries()
1569 h[
'stats10'][pname]=h[x].GetEntries() - h[x].Integral(0,h[
'mom'].FindBin(10.))
1570 sorted_pnames = sorted(h[
'stats'].items(), key=operator.itemgetter(1))
1571 for p
in sorted_pnames:
1572 print "%7s : %5.2F / 1M PoT"%(p[0],p[1]/18.)
1573 print "with P>10GeV"
1574 sorted_pnames = sorted(h[
'stats10'].items(), key=operator.itemgetter(1))
1575 for p
in sorted_pnames:
1576 print "%7s : %5.2F / 1M PoT"%(p[0],p[1]/18.)
1580 ut.bookHist(h,
'origin z/r',
'origin, z vs r',1000,-600.,600.,100,0.,10.)
1581 ut.bookHist(h,
'origin z/r mu',
'origin of muons, z vs r',1000,-600.,600.,100,0.,10.)
1582 ut.bookHist(h,
'origin z/r muJpsi',
'origin of muons Jpsi, z vs r',1000,-600.,600.,100,0.,10.)
1583 for i
in range(sTree.GetEntries()):
1584 rc = sTree.GetEvent(i)
1586 for m
in sTree.MCTrack:
1587 r = ROOT.TMath.Sqrt(m.GetStartX()**2+m.GetStartY()**2)
1590 rc = h[
'origin z/r'].Fill(m.GetStartZ(),r)
1591 if abs(m.GetPdgCode())!=13:
continue
1592 rc = h[
'origin z/r mu'].Fill(m.GetStartZ(),r)
1593 if abs(sTree.MCTrack[m.GetMotherId()].GetPdgCode())!=443:
continue
1594 rc = h[
'origin z/r muJpsi'].Fill(m.GetStartZ(),r)
1596 Mproton = 0.938272081
1598 Ebeam = ROOT.TMath.Sqrt(400.**2+Mproton**2)
1600 sqrtS = ROOT.TMath.Sqrt(2*Mproton**2+2*Ebeam*Mproton)
1601 y_beam = ROOT.TMath.Log(sqrtS/Mproton)
1606 for c
in [221,223,113,331,333,443]:
1607 names[c] = PDG.GetParticle(c).GetName()
1608 if not onlyPlotting:
1611 ut.bookHist(h,name+
'PandPt',
'P and Pt of original '+name,100,0.,400.,100,0.,10.)
1612 ut.bookHist(h,name+
'PandPt_rec',
'P and Pt of original '+name+
' for muons reconstructed',100,0.,400.,100,0.,10.)
1613 ut.bookHist(h,name+
'Y',
'rapidity of original '+name,80,-2.,6.)
1614 ut.bookHist(h,name+
'Y_rec',
'rapidity of reconstructed '+name,80,-2.,6.)
1615 for n
in range(sTree.GetEntries()):
1616 rc=sTree.GetEvent(n)
1617 for m
in range(sTree.MCTrack.GetEntries()):
1618 p = sTree.MCTrack[m]
1619 if p.GetPdgCode()
in names:
1620 rc=h[names[p.GetPdgCode()]+
'PandPt'].Fill(p.GetP(),p.GetPt())
1621 rc=h[names[p.GetPdgCode()]+
'Y'].Fill(p.GetRapidity()-beam)
1623 for k
in range(sTree.FitTracks.GetEntries()):
1624 mu = sTree.TrackInfos[k].McTrack()
1626 if sTree.MCTrack[mu].GetMotherId()==m: nRec += 1
1628 rc=h[names[p.GetPdgCode()]+
'PandPt_rec'].Fill(p.GetP(),p.GetPt())
1629 rc=h[names[p.GetPdgCode()]+
'Y_rec'].Fill(p.GetRapidity()-beam)
1631 ut.writeHists(h,
'histos-Jpsi'+rname)
1633 ut.readHists(h,
'JpsiKinematics-1GeV-mbias.root')
1634 ut.readHists(h,
'JpsiKinematics-1GeV-charm.root')
1635 ut.readHists(h,
'JpsiKinematics-10GeV.root')
1636 h[
'lowMassPandPt_rec']=h[names[443]+
'PandPt_rec'].Clone(
'lowMassPandPt_rec')
1637 h[
'lowMassPandPt']=h[names[443]+
'PandPt'].Clone(
'lowMassPandPt')
1639 h[
'lowMassPandPt_rec'].Add(h[names[c]+
'PandPt_rec'])
1640 h[
'lowMassPandPt'].Add(h[names[c]+
'PandPt'])
1641 names[
'lowMass']=
'lowMass'
1643 ut.bookCanvas(h,
'acc'+names[c],names[c]+
' acceptance',1200,800,1,3)
1644 for x
in [names[c]+
'PandPt_rec',names[c]+
'PandPt']:
1645 h[x].GetYaxis().SetRangeUser(0.,5.)
1647 h[x].SetTitle(h[x].GetTitle()+
';#it{p} [GeV/c];#it{p}_{T} [GeV/c]')
1648 h[names[c]+
'recoEff']=ROOT.TEfficiency(h[names[c]+
'PandPt_rec'],h[names[c]+
'PandPt'])
1649 ROOT.gStyle.SetPalette(ROOT.kTemperatureMap)
1650 tc = h[
'acc'+names[c]].cd(1)
1651 h[names[c]+
'PandPt'].Draw(
'colz')
1652 tc = h[
'acc'+names[c]].cd(2)
1653 h[names[c]+
'PandPt_rec'].Draw(
'colz')
1654 tc = h[
'acc'+names[c]].cd(3)
1655 h[names[c]+
'recoEff'].Draw(
'colz')
1657 h[names[c]+
'recoEff'].GetPaintedHistogram().GetYaxis().SetRangeUser(0.,5.)
1659 myPrint(h[
'acc'+names[c]],names[c]+
'Acceptance')
1661 ut.bookCanvas(h,
'accRap'+names[c],names[c]+
' acceptance',1200,800,1,2)
1662 for x
in [names[c]+
'Y_rec',names[c]+
'Y']:
1664 h[x].SetTitle(h[x].GetTitle()+
';rapidity Y;')
1665 h[names[c]+
'YrecoEff']=ROOT.TEfficiency(h[names[c]+
'Y_rec'],h[names[c]+
'Y'])
1666 ROOT.gStyle.SetPalette(ROOT.kTemperatureMap)
1667 tc = h[
'accRap'+names[c]].cd(1)
1668 h[names[c]+
'Y'].Draw()
1669 h[names[c]+
'Y_rec'].SetLineColor(ROOT.kMagenta)
1670 h[names[c]+
'Y_rec'].Draw(
'same')
1671 tc = h[
'accRap'+names[c]].cd(2)
1672 h[names[c]+
'YrecoEff'].Draw()
1673 myPrint(h[
'accRap'+names[c]],names[c]+
'RapAcceptance')
1677parallelToZ = ROOT.TVector3(0., 0., 1.)
1679 rc,pos,mom =
False,
None,
None
1680 fst = fT.getFitStatus()
1681 if not fst.isFitConverged():
return rc,pos,mom
1684 pos = ROOT.TVector3()
1685 mom = ROOT.TVector3()
1687 trackLength = muflux_Reco.extrapolateToPlane(fT,z,pos,mom)
1693 if z > DT[
'Station_1_x_plane_0_layer_0_10000000'][2]-10
and z < DT[
'Station_4_x_plane_1_layer_1_40110000'][2] + 10:
1697 M = min(fT.getNumPointsWithMeasurement(),30)
1698 for m
in range(0,M):
1701 try: st = fT.getFittedState(m)
1703 print "cannot get fitted state"
1706 if abs(z-Pos.z())<mZmin:
1707 mZmin = abs(z-Pos.z())
1709 fstate = fT.getFittedState(mClose)
1710 NewPosition = ROOT.TVector3(0., 0., z)
1711 pdgcode = -int(13*fstate.getCharge())
1712 rep = ROOT.genfit.RKTrackRep( pdgcode )
1713 state = ROOT.genfit.StateOnPlane(rep)
1714 pos,mom = fstate.getPos(),fstate.getMom()
1715 rep.setPosMom(state,pos,mom)
1717 rep.extrapolateToPlane(state, NewPosition, parallelToZ )
1718 pos,mom = state.getPos(),state.getMom()
1721 print 'error with extrapolation: z=',z/u.m,
'm',pos.X(),pos.Y(),pos.Z(),mom.X(),mom.Y(),mom.Z()
1722 error =
"extrapolateToPlane: error with extrapolation: z=%7.3F m %7.3F %7.3F %7.3F %7.3F %7.3F %7.3F "%(z/u.m,pos.X(),pos.Y(),pos.Z(),mom.X(),mom.Y(),mom.Z())
1723 ut.reportError(error)
1724 if Debug:
print error
1728 if z < DT[
'Station_1_x_plane_0_layer_0_10000000'][2]:
1730 fstate = fT.getFittedState(0)
1731 elif z > DT[
'Station_4_x_plane_1_layer_1_40110000'][2]:
1732 M = min(fT.getNumPointsWithMeasurement()-1,30)
1734 fstate = fT.getFittedState(fT.getNumPointsWithMeasurement()-1)
1736 fstate = fT.getFittedState(0)
1737 pos,mom = fstate.getPos(),fstate.getMom()
1739 lam = (z-pos[2])/mom[2]
1741 pos[0]=pos[0]+lam*mom[0]
1742 pos[1]=pos[1]+lam*mom[1]
1747 for s
in [
"",
"Decay",
"Hadronic inelastic",
"Lepton pair",
"Positron annihilation",
"charm",
"beauty",
"Di-muon P8",
"invalid"]:
1748 ut.bookHist(h,
'p/pt'+x+s,
'momentum vs Pt (GeV);#it{p} [GeV/c]; #it{p}_{T} [GeV/c]',500,0.,500.,100,0.,10.)
1749 ut.bookHist(h,
'p/px'+x+s,
'momentum vs Px (GeV);#it{p} [GeV/c]; #it{p}_{X} [GeV/c]',500,0.,500.,200,-10.,10.)
1750 ut.bookHist(h,
'p/Abspx'+x+s,
'momentum vs Px (GeV);#it{p} [GeV/c]; #it{p}_{X} [GeV/c]',500,0.,500.,100,0.,10.)
1751 ut.bookHist(h,
'pz/Abspx'+x+s,
'Pz vs Px (GeV);#it{p} [GeV/c]; #it{p}_{X} [GeV/c]',500,0.,500.,100,0.,10.)
1752 ut.bookHist(h,
'p/pxy'+x+s,
'momentum vs Px (GeV);#it{p} [GeV/c]; #it{p}_{X} [GeV/c]',500,0.,500.,200,-10.,10.)
1753 ut.bookHist(h,
'p/Abspxy'+x+s,
'momentum vs Px (GeV) tagged RPC X;#it{p} [GeV/c]; #it{p}_{X} [GeV/c]',500,0.,500.,100,0.,10.)
1754 ut.bookHist(h,
'pz/Abspxy'+x+s,
'Pz vs Px (GeV) tagged RPC X;#it{p} [GeV/c]; #it{p}_{X} [GeV/c]',500,0.,500.,100,0.,10.)
1755 ut.bookHist(h,
'TrackMult'+x+s,
'track multiplicity',10,-0.5,9.5)
1756 ut.bookHist(h,
'chi2'+x+s,
'chi2/nDoF',100,0.,10.)
1757 ut.bookHist(h,
'Nmeasurements'+x+s,
'number of measurements used',25,-0.5,24.5)
1758 ut.bookHist(h,
'xy'+x+s,
'xy of first state;x [cm];y [cm]',100,-30.,30.,100,-30.,30.)
1759 ut.bookHist(h,
'pxpy'+x+s,
'px/pz py/pz of first state',100,-0.2,0.2,100,-0.2,0.2)
1760 ut.bookHist(h,
'p1/p2'+x+s,
'momentum p1 vs p2;#it{p} [GeV/c]; #it{p} [GeV/c]',500,0.,500.,500,0.,500.)
1761 ut.bookHist(h,
'pt1/pt2'+x+s,
'P_{T} 1 vs P_{T} 2;#it{p} [GeV/c]; #it{p} [GeV/c]',100,0.,10.,100,0.,10.)
1762 ut.bookHist(h,
'p1/p2s'+x+s,
'momentum p1 vs p2 same sign;#it{p} [GeV/c]; #it{p} [GeV/c]',500,0.,500.,500,0.,500.)
1763 ut.bookHist(h,
'pt1/pt2s'+x+s,
'P_{T} 1 vs P_{T} 2 same sign;#it{p} [GeV/c]; #it{p} [GeV/c]',100,0.,10.,100,0.,10.)
1764 ut.bookHist(h,
'trueMom'+x+s,
'true MC momentum;#it{p} [GeV/c];#it{p}_{T} [GeV/c]',500,0.,500.,100,0.,10.)
1765 ut.bookHist(h,
'recoMom'+x+s,
'reco MC momentum;#it{p} [GeV/c];#it{p}_{T} [GeV/c]',500,0.,500.,100,0.,10.)
1766 ut.bookHist(h,
'truePz/Abspx'+x+s,
'true MC momentum;#it{p} [GeV/c];#it{p}_{x} [GeV/c]',500,0.,500.,100,0.,10.)
1767 ut.bookHist(h,
'recoPz/Abspx'+x+s,
'reco MC momentum;#it{p}[GeV/c];#it{p}_{x} [GeV/c]',500,0.,500.,100,0.,10.)
1768 ut.bookHist(h,
'momResol'+x+s,
'momentum resolution function of momentum;P [GeV/c];#sigma P/P', 200,-0.5,0.5,40,0.,400.)
1769ut.bookHist(h,
'trueUpOcc',
'true Upstream Occupancy function of true Mom;#it{p} [GeV/c];N',400,0.,400.,100,-0.5,99.5)
1770ut.bookHist(h,
'Trscalers',
'scalers for track counting',20,0.5,20.5)
1771ut.bookHist(h,
'weightVsSource',
'weight vs source MC check',10,-0.5,9.5,1000,0.0,1000.)
1772for view
in [
'_u1',
'_v2',
'_x1',
'_x2',
'_x3',
'_x4']:
1773 ut.bookHist(h,
'Fitpoints'+view,
'points'+view,100,0,400,10,-0.5,9.5)
1776bfield = ROOT.genfit.FairShipFields()
1777Bx,By,Bz = ROOT.Double(),ROOT.Double(),ROOT.Double()
1781 delz = 1000./nPoints
1782 nt = len(h[
'dispTrack'])
1783 h[
'dispTrack'].append( ROOT.TGraph(nPoints) )
1784 h[
'dispTrackY'].append( ROOT.TGraph(nPoints) )
1785 for nP
in range(nPoints):
1788 if not rc:
print "dispTrack extrap failed"
1790 h[
'dispTrack'][nt].SetPoint(nP,zstart,pos[0])
1791 h[
'dispTrackY'][nt].SetPoint(nP,zstart,pos[1])
1793 bfield.get(pos[0],pos[1],pos[2],Bx,By,Bz)
1794 print "%5.2F %5.2F %5.2F %5.2F %5.2F %5.2F %5.2F %5.2F %5.2F "%(pos[0],pos[1],pos[2],Bx,By,Bz,mom[0],mom[1],mom[2])
1797 fitStatus = theTrack.getFitStatus()
1798 print "trackinfo P/Pt/chi2/DoF/Ndf:%6.2F %6.2F %6.2F %6.2F"%(mom.Mag(),mom.Pt(),fitStatus.getChi2()/fitStatus.getNdf(),fitStatus.getNdf())
1799 st = theTrack.getFittedState(0)
1802 N = theTrack.getNumPointsWithMeasurement()
1803 momU = theTrack.getFittedState(0).getMom()
1804 momD = theTrack.getFittedState(N-1).getMom()
1805 dalpha = momU[0]/momU[2] - ( momD[0]/momD[2] )
1806 slopeA = momU[0]/momU[2]
1807 slopeB = momD[0]/momD[2]
1808 posU = theTrack.getFittedState(0).getPos()
1809 posD = theTrack.getFittedState(N-1).getPos()
1810 bA = posU[0]-slopeA*posU[2]
1811 bB = posD[0]-slopeB*posD[2]
1812 x1 = zgoliath*slopeA+bA
1813 x2 = zgoliath*slopeB+bB
1815 rc = h[
'delx'].Fill(delx)
1816 print "mom from pt kick=",1.03/dalpha
1817 for j
in range(theTrack.getNumPointsWithMeasurement()):
1818 st = theTrack.getFittedState(j)
1819 pos,mom = st.getPos(), st.getMom()
1820 print "%i %5.2F %5.2F %5.2F %5.2F %5.2F %5.2F %i %i "%(j,pos[0],pos[1],pos[2],mom[0],mom[1],mom[2],st.getPDG(),st.getCharge())
1821 h[
'dispTrack'][nt].SetLineColor(ROOT.kMagenta)
1822 h[
'dispTrack'][nt].SetLineWidth(3)
1823 h[
'dispTrackY'][nt].SetLineColor(ROOT.kOrange)
1824 h[
'dispTrackY'][nt].SetLineWidth(3)
1825 h[
'dispTrackY'][nt].SetLineStyle(10)
1826 h[
'simpleDisplay'].cd(1)
1827 h[
'dispTrack'][nt].Draw(
'same')
1828 h[
'dispTrackY'][nt].Draw(
'same')
1829 h[
'simpleDisplay'].Update()
1832 for view
in [
'X',
'Y']:
1833 for muTrack
in muTracks[view]:
1834 h[
'simpleDisplay'].cd(1)
1835 nt = len(h[
'dispTrack'])
1836 h[
'dispTrack'].append( ROOT.TGraph(2) )
1837 h[
'dispTrackY'].append( ROOT.TGraph(2) )
1839 x = muTrack[0]*zStart+muTrack[1]
1840 h[
'dispTrack'][nt].SetPoint(0,zStart,x)
1842 x = muTrack[0]*zEnd+muTrack[1]
1843 h[
'dispTrack'][nt].SetPoint(1,zEnd,x)
1844 if view ==
'X': h[
'dispTrack'][nt].SetLineColor(ROOT.kRed)
1846 h[
'dispTrack'][nt].SetLineColor(ROOT.kBlue)
1847 h[
'dispTrack'][nt].SetLineStyle(10)
1848 h[
'dispTrack'][nt].SetLineWidth(3)
1849 h[
'dispTrack'][nt].Draw(
'same')
1850 h[
'simpleDisplay'].Update()
1853 spectrHitsSorted = ROOT.nestedList()
1854 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
True)
1855 nH = {1:0,2:0,3:0,4:0}
1857 for s
in range(1,5):
1859 for hit
in spectrHitsSorted[0][s][l]: nH[s]+=1
1860 if nH[s]<nmin
or nH[s]>nmax: passed =
False
1863 for hit
in spectrHitsSorted[1][1][l]: nu+=1
1864 if nu<nmin
or nu>nmax: passed =
False
1867 for hit
in spectrHitsSorted[2][2][l]: nv+=1
1868 if nv<nmin
or nv>nmax: passed =
False
1871def fitTracks(nMax=-1,simpleEvents=True,withDisplay=False,nStart=0,debug=False,PR=1,withRT=False,chi2UL=3):
1873 for x
in [
'p/pt',
'p/px',
'p/Abspx',
'Nmeasurements',
'chi2',
'xy',
'pxpy',
'TDC2R',
'p1/p2',
'pt1/pt2',
1874 'p/ptmu',
'p/pxmu',
'p/Abspxmu',
'Nmeasurementsmu',
'chi2mu',
'xymu',
'pxpymu']: h[x].Reset()
1875 if not withDisplay
and not Debug
and not simpleEvents:
1876 muflux_Reco.trackKinematics(3.)
1879 for n
in range(nStart,sTree.GetEntries()):
1880 rc = sTree.GetEvent(n)
1882 if sTree.Digi_MufluxSpectrometerHits.GetEntries() != sTree.MufluxSpectrometerPoint.GetEntries():
1883 print "digi does not agree with MC, break",n
1885 if PR<10
and sTree.ShipEventHeader.GetUniqueID()==1:
continue
1886 if not withDisplay
and n%10000==0:
print "event #",n
1888 if simpleEvents
and simpleEvents<2:
1894 if simpleEvents==2
and len(theTracks)<simpleEvents:
continue
1898 if len(theTracks)>0:
1899 for aTrack
in theTracks:
1901 fitStatus = aTrack.getFitStatus()
1902 if not fitStatus.isFitConverged():
continue
1906 if len(hitsPerStation[
'x1'])<2:
continue
1907 if len(hitsPerStation[
'x2'])<2:
continue
1908 if len(hitsPerStation[
'x3'])<2:
continue
1909 if len(hitsPerStation[
'x4'])<2:
continue
1910 chi2 = fitStatus.getChi2()/fitStatus.getNdf()
1911 fittedState = aTrack.getFittedState()
1912 P = fittedState.getMomMag()
1913 Px,Py,Pz = fittedState.getMom().x(),fittedState.getMom().y(),fittedState.getMom().z()
1915 if abs(Py/Pz)>0.15:
print 'event with large angle track:',n
1916 rc = h[
'chi2'].Fill(chi2)
1917 rc = h[
'Nmeasurements'].Fill(fitStatus.getNdf())
1918 if chi2 > chi2UL:
continue
1919 rc = h[
'p/pt'].Fill(P,ROOT.TMath.Sqrt(Px*Px+Py*Py))
1920 rc = h[
'p/px'].Fill(P,Px)
1921 rc = h[
'p/Abspx'].Fill(P,abs(Px))
1922 pos = fittedState.getPos()
1923 rc = h[
'xy'].Fill(pos[0],pos[1])
1924 rc = h[
'pxpy'].Fill(Px/Pz,Py/Pz)
1928 tagged = {
'X':
False,
'Y':
False}
1929 for proj
in [
'X',
'Y']:
1930 for m
in RPCtracks[proj]:
1931 if abs(posRPC[0]-m[0]*zRPC1+m[1]) < cuts[
'muTrackMatch'+proj]: tagged[proj]=
True
1932 if tagged[
'X']
and tagged[
'Y'] :
1933 rc = h[
'chi2mu'].Fill(chi2)
1934 rc = h[
'Nmeasurementsmu'].Fill(fitStatus.getNdf())
1935 rc = h[
'p/ptmu'].Fill(P,ROOT.TMath.Sqrt(Px*Px+Py*Py))
1936 rc = h[
'p/pxmu'].Fill(P,Px)
1937 rc = h[
'p/Abspxmu'].Fill(P,abs(Px))
1938 rc = h[
'xymu'].Fill(pos[0],pos[1])
1939 rc = h[
'pxpymu'].Fill(Px/Pz,Py/Pz)
1941 if len(theTracks)==2
and N==0:
1942 bTrack = theTracks[1]
1943 fitStatus = bTrack.getFitStatus()
1944 if not fitStatus.isFitConverged():
continue
1945 chi2 = fitStatus.getChi2()/fitStatus.getNdf()
1946 fittedState = bTrack.getFittedState()
1947 Pb = fittedState.getMomMag()
1948 Pbx,Pby,Pbz = fittedState.getMom().x(),fittedState.getMom().y(),fittedState.getMom().z()
1949 if chi2 > chi2UL:
continue
1950 rc = h[
'p1/p2'].Fill(P,Pb)
1951 rc = h[
'pt1/pt2'].Fill(ROOT.TMath.Sqrt(Px*Px+Py*Py),ROOT.TMath.Sqrt(Pbx*Pbx+Pby*Pby))
1953 for hit
in sTree.Digi_MufluxSpectrometerHits:
1954 if not hit.hasTimeOverThreshold():
continue
1955 rc =
RT(hit,hit.GetDigi())
1957 for theTrack
in theTracks:
1958 fitStatus = theTrack.getFitStatus()
1959 if not fitStatus.isFitConverged():
continue
1961 next = raw_input(
"Next (Ret/Quit): ")
1963 if len(theTracks)>0: nMax-=1
1964 if not hasattr(theTracks,
'Class'):
1965 for theTrack
in theTracks: theTrack.Delete()
1968 ROOT.gStyle.SetPalette(ROOT.kGreenPink)
1971 if not h.has_key(t): ut.bookCanvas(h,key=t,title=
'trackfit'+x,nx=1200,ny=600,cx=4,cy=2)
1973 h[
'p/pt'+x].SetStats(0)
1974 rc = h[
'p/pt'+x].Draw(
'colz')
1977 h[
'p/pt'+x+
'_x']=h[
'p/pt'+x].ProjectionX()
1978 h[
'p/pt'+x+
'_x'].SetName(
'p/pt'+x+
'_x')
1979 h[
'p/pt'+x+
'_x'].SetTitle(
'#it{p}[GeV/c]')
1980 h[
'p/pt'+x+
'_x'].Draw()
1982 h[
'p/pt'+x+
'_y']=h[
'p/pt'+x].ProjectionY()
1983 h[
'p/pt'+x+
'_y'].SetName(
'p/pt'+x+
'_y')
1984 h[
'p/pt'+x+
'_y'].SetTitle(
'#it{p}_{T} [GeV/c]')
1985 h[
'p/pt'+x+
'_y'].Draw()
1987 stats = h[
'p/pt'+x+
'_x'].FindObject(
'stats')
1988 stats.SetOptStat(11111111)
1992 h[
'Nmeasurements'+x].Draw()
1994 h[
'xy'+x].Draw(
'colz')
1996 h[
'pxpy'+x].Draw(
'colz')
1998 if x==
'' and h[
'TDC2R'].GetEntries()>0:
1999 h[
'TDC2R_projx'] = h[
'TDC2R'].ProjectionY()
2000 h[
'TDC2R_projx'].SetTitle(
'RT Relation r projection')
2001 h[
'TDC2R_projx'].SetXTitle(
'drift distance [cm]')
2002 h[
'TDC2R_projx'].Draw()
2004 h[
'px'+x]=h[
'p/pt'+x].ProjectionX()
2005 h[
'px'+x].SetName(
'px'+x)
2006 h[
'px'+x].SetTitle(
'#it{p} [GeV/c]')
2022 posM = ROOT.TVector3(0, 0, 20.)
2023 momM = ROOT.TVector3(0,0,Pstart*u.GeV)
2025 covM = ROOT.TMatrixDSym(6)
2026 resolution = sigma_spatial
2027 if not withTDC: resolution = 10*sigma_spatial
2028 for i
in range(3): covM[i][i] = resolution*resolution
2030 for i
in range(3,6): covM[i][i] = ROOT.TMath.Power(resolution / (4.*2.) / ROOT.TMath.Sqrt(3), 2)
2031 rep = ROOT.genfit.RKTrackRep(13)
2033 state = ROOT.genfit.MeasuredStateOnPlane(rep)
2034 rep.setPosMomCov(state, posM, momM, covM)
2036 seedState = ROOT.TVectorD(6)
2037 seedCov = ROOT.TMatrixDSym(6)
2038 rep.get6DStateCov(state, seedState, seedCov)
2039 theTrack = ROOT.genfit.Track(rep, seedState, seedCov)
2045 for nhit
in hitlist:
2047 if type(nhit)==type(1):
2048 hit = sTree.Digi_MufluxSpectrometerHits[nhit]
2052 if type(nhit)!=type(1):
2053 detID = hit.GetDetectorID()
2054 keyList = detIDToKey[detID]
2059 for x
in range(1,len(keyList)):
2061 if sTree.Digi_MufluxSpectrometerHits[numHit].GetDigi()==tdc:
2064 if not found:
print "fittrack: digi not found, something wrong here",tdc
2065 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
2066 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
2068 if withTDC: distance =
RT(hit,tdc)
2069 tmp = array(
'd',[vtop[0],vtop[1],vtop[2],vbot[0],vbot[1],vbot[2],distance])
2070 unSortedList[k] = [ROOT.TVectorD(7,tmp),hit.GetDetectorID(),numHit,view]
2071 tmpList[k] = vtop[2]
2073 sorted_z = sorted(tmpList.items(), key=operator.itemgetter(1))
2075 tp = ROOT.genfit.TrackPoint()
2076 hitCov = ROOT.TMatrixDSym(7)
2077 hitCov[6][6] = resolution*resolution
2079 measurement = ROOT.genfit.WireMeasurement(unSortedList[k[0]][0],hitCov,1,6,tp)
2080 measurement.setMaxDistance(ShipGeo.MufluxSpectrometer.InnerTubeDiameter/2.)
2081 measurement.setDetId(unSortedList[k[0]][1])
2083 measurement.setHitId(unSortedList[k[0]][2])
2084 tp.addRawMeasurement(measurement)
2085 theTrack.insertPoint(tp)
2086 if not theTrack.checkConsistency():
2087 print "track not consistent"
2092 try: fitter.processTrack(theTrack)
2099 if timer.RealTime()>1:
2100 error =
"fitTrack::very long fit time %8.6F %6i"%(timer.RealTime(),len(hitlist))
2101 ut.reportError(error)
2102 if Debug:
print error
2103 fitStatus = theTrack.getFitStatus()
2104 if Debug:
print "Fit result: converged chi2 Ndf",fitStatus.isFitConverged(),fitStatus.getChi2(),fitStatus.getNdf()
2105 if not fitStatus.isFitConverged():
2109 chi2 = fitStatus.getChi2()/fitStatus.getNdf()
2110 fittedState = theTrack.getFittedState()
2111 P = fittedState.getMomMag()
2112 print "track fitted Ndf #Meas P",fitStatus.getNdf(), theTrack.getNumPointsWithMeasurement(),P
2113 for p
in theTrack.getPointsWithMeasurement():
2114 rawM = p.getRawMeasurement()
2115 info = p.getFitterInfo()
2116 if not info:
continue
2117 detID = rawM.getDetId()
2118 test = ROOT.MufluxSpectrometerHit(detID,0.)
2119 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(test)
2120 print s,view,2*p+l,channelID,
"weights",info.getWeights()[0],info.getWeights()[1]
2121 if fitStatus.getNdf() < cuts[
'Ndf']:
2128 for cl
in [cl1,cl2]:
2134 x.append(cl[hit][3])
2135 z.append(cl[hit][4])
2136 line = numpy.polyfit(z,x,1)
2137 return line[0],line[1]
2141minHitsPerCluster, maxHitsPerCluster = 2,10
2142topA,botA = ROOT.TVector3(),ROOT.TVector3()
2143topB,botB = ROOT.TVector3(),ROOT.TVector3()
2145pl = {0:
'00',1:
'01',2:
'10',3:
'11'}
2146ut.bookHist(h,
'biasResTrackMom',
'momentum of tracks used for biased residuals',400,0.0,400.0)
2149 for view
in [
'_x',
'_u',
'_v']:
2150 if s>2
and view !=
'_x':
continue
2151 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
2152 ut.bookHist(h,
'del'+view+str(s),
'del x for '+str(s)+view,100,-20.,20.)
2153 clusters[s][view]={}
2155 for layer
in range(0,4):
2157 if not x.find(
'Station_'+str(s)+view+
'_plane_'+pl[layer][0]+
'_layer_'+pl[layer][1] )<0:
2162 print "this should never happen",
'Station_'+str(s)+view+
'_plane_'+pl[layer][0]+
'_layer_'+pl[layer][1]
2163 ut.bookHist(h,
'biasResX_'+str(s)+view+str(layer),
'biased residual for '+str(s)+view+
' '+str(layer),100,-0.5,0.5,20,-dx,dx)
2164 ut.bookHist(h,
'biasResXL_'+str(s)+view+str(layer),
'biased residual for '+str(s)+view+
' '+str(layer),300,-6.,6.,20,-dx,dx)
2165 ut.bookHist(h,
'linearRes'+str(s)+view+str(layer),
'linear track model residual for '+str(s)+view+
' '+str(layer),100,-20.,20.,10,-dx,dx)
2166 ut.bookHist(h,
'biasResY_'+str(s)+view+str(layer),
'biased residual for '+str(s)+view+
' '+str(layer),100,-0.5,0.5,20,-dy,dy)
2167 ut.bookHist(h,
'biasResYL_'+str(s)+view+str(layer),
'biased residual for '+str(s)+view+
' '+str(layer),100,-2.,2.,20,-dy,dy)
2168 ut.bookHist(h,
'biasResDist_'+str(s)+view+str(layer),
'residual versus drift radius',100,0.,2.,1000,-2.0,2.0)
2169 ut.bookHist(h,
'biasResXLA_'+str(s)+view+str(layer),
'dist biased residual for '+str(s)+view+
' '+str(layer),300,-6.,6.,20,-dx,dx)
2170 ut.bookHist(h,
'biasResYLA_'+str(s)+view+str(layer),
'dist biased residual for '+str(s)+view+
' '+str(layer),300,-6.,6.,20,-dy,dy)
2174 ut.bookHist(h,
'biasResX_' +str(detID),
'biased residual for channel '+str(detID)+
';[cm];[cm]',100,-0.5,0.5,20,-dx,dx)
2175 ut.bookHist(h,
'biasResXL_'+str(detID),
'biased residual for channel '+str(detID)+
';[cm];[cm]',300,-6.,6.,20,-dx,dx)
2176 ut.bookHist(h,
'biasResY_' +str(detID),
'biased residual for channel '+str(detID)+
';[cm];[cm]',100,-0.5,0.5,20,-dy,dy)
2177 ut.bookHist(h,
'biasResYL_'+str(detID),
'biased residual for channel '+str(detID)+
';[cm];[cm]',300,-6.,6.,20,-dy,dy)
2178ut.bookHist(h,
'biasResDist',
'residual versus drift radius;[cm];[cm]',100,0.,2.,1000,-2.0,2.0)
2179ut.bookHist(h,
'biasResDist2',
'residual versus track distance;[cm];[cm]',100,0.,2.,1000,-2.0,2.0)
2181ut.bookHist(h,
'clsN',
'cluster sizes',10,-0.5,9.5)
2182ut.bookHist(h,
'Ncls',
'number of clusters / event',10,-0.5,9.5)
2183ut.bookHist(h,
'delY',
'del Y from stereo; [cm]',100,-40.,40.)
2184ut.bookHist(h,
'yest',
'estimated Y from stereo; [cm]',100,-100.,100.)
2186myGauss = ROOT.TF1(
'gauss',
'abs([0])/(abs([2])*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+abs([3])',4)
2187myGauss.SetParName(0,
'Signal')
2188myGauss.SetParName(1,
'Mean')
2189myGauss.SetParName(2,
'Sigma')
2190myGauss.SetParName(3,
'bckgr')
2195 global exclude_layer
2196 trackCandidates = []
2202 for hit
in sTree.Digi_MufluxSpectrometerHits:
2205 if not hit.hasTimeOverThreshold():
continue
2206 if hit.GetDetectorID()
in noisyChannels:
continue
2207 detID = hit.GetDetectorID()
2208 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
2209 if exclude_layer !=
None and view !=
'_x':
2210 if (2*p+l)==exclude_layer:
continue
2211 vbot,vtop = strawPositionsBotTop[detID]
2214 if withTDCPR: distance =
RT(hit,tdc)
2215 DTHits.append( {
'digiHit':key,
'xtop':vtop.x(),
'ytop':vtop.y(),
'z':vtop.z(),
'xbot':vbot.x(),
'ybot':vbot.y(),
'dist':distance,
'detID':detID} )
2220 print "PR returned %i track candidates"%(len(track_hits))
2222 for nTrack
in track_hits:
2223 h[
'magPos'].Fill(track_hits[nTrack][
'x_in_magnet'],track_hits[nTrack][
'y_in_magnet'])
2228 for dets
in [
'34',
'stereo12',
'y12']:
2229 rc = h[
'tracklets'+dets].Fill(len(track_hits[nTrack][dets]))
2230 for aHit
in track_hits[nTrack][dets]:
2231 hitlist[k].append( aHit[
'digiHit'])
2232 aTrack =
fitTrack(hitlist[k],abs(track_hits[nTrack][
'p']))
2233 if type(aTrack) != type(1):
2234 trackCandidates.append(aTrack)
2236 if onlyHits:
return hitlist
2237 return trackCandidates
2240 for nTrack
in track_hits:
2242 for x
in [track_hits[nTrack][
'y12'],track_hits[nTrack][
'34']]:
2245 detID = hits[
'detID']/10000000
2246 if detID>2: detID-=2
2247 clus[detID].append([0,(hits[
'xtop']+hits[
'xbot'])/2.,hits[
'z']])
2249 x1 = zgoliath*slopeA+bA
2250 nt = len(h[
'dispTrackSeg'])
2251 h[
'dispTrackSeg'].append( ROOT.TGraph(2) )
2253 h[
'dispTrackSeg'][nt].SetPoint(0,0.,bA)
2254 h[
'dispTrackSeg'][nt].SetPoint(1,400.,slopeA*400+bA)
2255 h[
'dispTrackSeg'][nt].SetLineColor(ROOT.kRed)
2258 h[
'dispTrackSeg'][nt].SetPoint(0,300.,slopeA*300+bA)
2259 h[
'dispTrackSeg'][nt].SetPoint(1,900.,slopeA*900+bA)
2260 h[
'dispTrackSeg'][nt].SetLineColor(ROOT.kBlue)
2261 h[
'dispTrackSeg'][nt].SetLineWidth(2)
2262 h[
'simpleDisplay'].cd(1)
2263 h[
'dispTrackSeg'][nt].Draw(
'same')
2264 h[
'simpleDisplay'].Update()
2270 for n
in clusters[s][view]:
2273 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(x[0])
2275 detID = x[0].GetDetectorID()
2276 MCTrackID = sTree.MufluxSpectrometerPoint[keysToDThits[detID][0]].GetTrackID()
2277 print k,
':',s,view,2*p+l,x[2],x[3],
':',MCTrackID
2278 else:
print k,
':',s,view,2*p+l,x[2],x[3]
2282 for p
in aTrack.getPointsWithMeasurement():
2283 rawM = p.getRawMeasurement()
2284 info = p.getFitterInfo()
2285 if not info:
continue
2286 if info.getWeights()[0] <0.1
and info.getWeights()[1] <0.1:
continue
2287 detID = rawM.getDetId()
2288 theKey = rawM.getHitId()
2289 trackID = sTree.MufluxSpectrometerPoint[theKey].GetTrackID()
2290 if not trackIDs.has_key(trackID): trackIDs[trackID]=0
2291 trackIDs[trackID]+=1
2292 sorted_trackIDs = sorted(trackIDs.items(), key=operator.itemgetter(1),reverse=
True)
2293 sz = trackIDs.values()
2294 ghFrac = 1.-sorted_trackIDs[0][1]/float(sum(sz))
2295 return ghFrac,sorted_trackIDs[0][0]
2298 spectrHitsSorted = ROOT.nestedList()
2299 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
True)
2302 for s
in range(1,5):
2304 for view
in viewsI[s]:
2309 for hit
in spectrHitsSorted[view][s][l]:
2310 channelID = hit.GetDetectorID()%1000
2311 allHits[l][channelID]=hit
2312 if removeBigClusters:
2313 clustersPerLayer = {}
2315 clustersPerLayer[l] = dict(enumerate(
grouper(allHits[l].keys(),1), 1))
2316 for Acl
in clustersPerLayer[l]:
2317 if len(clustersPerLayer[l][Acl])>cuts[
'maxClusterSize']:
2318 for x
in clustersPerLayer[l][Acl]:
2319 dead = allHits[l].pop(x)
2320 if Debug:
print "pop",s,viewC[view],l,x
2324 perLayerUsedHits = {0:[],1:[],2:[],3:[]}
2326 for i
in range(1,Nchannels[s]+1):
2327 perLayer = {0:0,1:0,2:0,3:0}
2328 for i0
in range( max(1,i-1),min(Nchannels[s]+1,i+2)):
2329 if allHits[0].has_key(i0):
2330 tmp[ncl].append(allHits[0][i0])
2332 for i1
in range( max(1,i-1), min(Nchannels[s]+1,i+2)):
2333 if allHits[1].has_key(i1):
2334 tmp[ncl].append(allHits[1][i1])
2336 for i2
in range( max(1,i-1), min(Nchannels[s]+1,i+2)):
2337 if allHits[2].has_key(i2):
2338 tmp[ncl].append(allHits[2][i2])
2340 for i3
in range( max(1,i-1), min(Nchannels[s]+1,i+2)):
2341 if allHits[3].has_key(i3):
2342 tmp[ncl].append(allHits[3][i3])
2344 if ( (perLayer[0]>0) + (perLayer[1]>0) + (perLayer[2]>0) + (perLayer[3]>0) ) > level:
2348 if len(tmp[ncl])==0: tmp.pop(ncl)
2354 for hit
in tmp[ncl]:
2355 bot,top = strawPositionsBotTop[hit.GetDetectorID()]
2356 x = (bot[0]+top[0])/2.
2358 test.append([hit,x])
2359 mean=mean/float(len(test))
2363 if abs(mean-cl[1])<2.5 :
2364 tmpClean[ncl].append(cl[0])
2366 clusters[s][view]=[]
2370 for n1
in range(len(tmpClean)):
2371 if len(tmpClean[n1])==0:
continue
2373 for n2
in range(len(tmpClean)):
2375 if n2
in marked:
continue
2376 if set(tmpClean[n1]) <=
set(tmpClean[n2]):
2379 if contained: marked.append(n1)
2380 for n1
in range(len(tmpClean)):
2381 if len(tmpClean[n1])<2:
continue
2382 if n1
in marked:
continue
2385 for hit
in tmpClean[n1]:
2386 bot,top = strawPositionsBotTop[hit.GetDetectorID()]
2387 x = (bot[0]+top[0])/2.
2388 z = (bot[2]+top[2])/2.
2390 test.append([hit,x,z,hit.GetDetectorID()%1000])
2391 mean=mean/float(len(test))
2393 clusters[s][view].append([])
2395 if abs(mean-cl[1])<2.5: clusters[s][view][ncl].append(cl)
2396 if len(clusters[s][view][ncl])==0:
2397 clusters[s][view].pop(ncl)
2399 rc = h[
'clsN'].Fill(ncl)
2402 for view
in viewsI[s]:
2406 for cl
in clusters[s][view]:
2409 if not tmp.has_key(hit[3]):
2412 if hit[0].GetDetectorID()
in check[hit[3]]:
continue
2413 tmp[hit[3]].append(hit)
2414 check[hit[3]].append(hit[0].GetDetectorID())
2417 clusters[s][view].append(tmp[n])
2419 for s
in range(1,5):
2420 for view
in viewsI[s]:
2426 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
2427 bot,top = strawPositionsBotTop[hit.GetDetectorID()]
2428 print s,v,p*2+l,channelID,(bot[0]+top[0])/2.
2435def findTracks(PR = 1,linearTrackModel = False,withCloneKiller=True):
2437 if sTree.GetBranch(
'FitTracks_refitted'):
return sTree.FitTracks_refitted
2438 print "findTracks called with PR=3 but FitTracks_refitted does not exist. "
2441 if sTree.GetBranch(
'FitTracks'):
return sTree.FitTracks
2442 print "findTracks called with PR=1 but FitTracks does not exist. "
2445 trackCandidates =
testPR()
2446 if len(trackCandidates)>1: trackCandidates=
cloneKiller(trackCandidates)
2447 return trackCandidates
2451 for itrack
in range(sTree.FitTracks.GetEntries()):
2452 trInfo = sTree.TrackInfos[itrack]
2453 oTrack = sTree.FitTracks[itrack]
2455 fst = oTrack.getFitStatus()
2456 if fst.isFitConverged()
and fst.getNdf()>1:
2458 sta = oTrack.getFittedState(0)
2461 print "cannot get fittedState(0)"
2463 for n
in range(trInfo.N()):
2464 detID = trInfo.detId(n)
2465 hitList.append(keysToDThits[detID][0])
2467 if type(aTrack) == type(1):
continue
2468 trackCandidates.append(aTrack)
2469 return trackCandidates
2473 vbot,vtop = strawPositionsBotTop[30002001]
2477 trackCandidates = []
2481 for s
in range(1,5):
2482 if len(clusters[s][0])==0: allStations =
False
2483 if len(clusters[1][1])==0
or len(clusters[2][2])==0: allStations =
False
2488 h[
'dispTrackSeg'] = []
2490 for cl1
in clusters[1][0]:
2491 for cl2
in clusters[2][0]:
2493 x1 = zgoliath*slopeA+bA
2494 t1t2cand.append([cl1,cl2,x1,slopeA,bA])
2497 nt = len(h[
'dispTrackSeg'])
2498 h[
'dispTrackSeg'].append( ROOT.TGraph(2) )
2499 h[
'dispTrackSeg'][nt].SetPoint(0,0.,bA)
2500 h[
'dispTrackSeg'][nt].SetPoint(1,400.,slopeA*400+bA)
2501 h[
'dispTrackSeg'][nt].SetLineColor(ROOT.kRed+nTrx)
2502 h[
'dispTrackSeg'][nt].SetLineWidth(2)
2503 h[
'simpleDisplay'].cd(1)
2504 h[
'dispTrackSeg'][nt].Draw(
'same')
2506 for cl1
in clusters[3][0]:
2507 for cl2
in clusters[4][0]:
2509 x1 = zgoliath*slopeA+bA
2510 t3t4cand.append([cl1,cl2,x1,slopeA,bA])
2512 nt = len(h[
'dispTrackSeg'])
2513 h[
'dispTrackSeg'].append( ROOT.TGraph(2) )
2514 h[
'dispTrackSeg'][nt].SetPoint(0,300.,slopeA*300+bA)
2515 h[
'dispTrackSeg'][nt].SetPoint(1,900.,slopeA*900+bA)
2516 h[
'dispTrackSeg'][nt].SetLineColor(ROOT.kBlue)
2517 h[
'dispTrackSeg'][nt].SetLineWidth(2)
2518 h[
'simpleDisplay'].cd(1)
2519 h[
'dispTrackSeg'][nt].Draw(
'same')
2522 print "trackCandidates",len(t1t2cand),len(t3t4cand)
2523 h[
'simpleDisplay'].Update()
2525 for nt1t2
in range(len(t1t2cand)):
2526 t1t2 = t1t2cand[nt1t2]
2528 for nt3t4
in range(len(t3t4cand)):
2529 t3t4 = t3t4cand[nt3t4]
2530 delx = t3t4[2]-t1t2[2]
2531 h[
'delx'].Fill(delx)
2535 if abs(delx) < cuts[
'delxAtGoliath']:
2538 if Debug:
print "stereo clusters",len(clusters[1][1]),len(clusters[2][2])
2539 for nu
in range(len(clusters[1][1])):
2541 clu = clusters[1][1][nu]
2545 botA,topA = strawPositionsBotTop[cl[0].GetDetectorID()]
2546 z = (botA[2]+topA[2])/2.
2547 sl = (botA[1]-topA[1])/(botA[0]-topA[0])
2548 b = topA[1]-sl*topA[0]
2549 yest = sl*(t1t2[3]*topA[2]+t1t2[4])+b
2550 rc = h[
'yest'].Fill(yest)
2551 if yest > botA[1]+cuts[
'yMax'] :
continue
2552 if yest < topA[1]-cuts[
'yMax'] :
continue
2553 stereoHits[1][cl[0].GetDetectorID()]=[cl[0],sl,b,yest,z]
2556 mean_u = mean_u/float(n_u)
2557 if Debug:
print "0 stereo u",len(stereoHits[1])
2558 for x
in stereoHits[1].keys():
2559 delta = stereoHits[1][x][3]-mean_u
2560 rc = h[
'delta_mean_uv'].Fill(delta)
2561 if abs(delta)>cuts[
'hitDist']: stereoHits[1].pop(x)
2563 for nv
in range(len(clusters[2][2])):
2567 clv = clusters[2][2][nv]
2569 botA,topA = strawPositionsBotTop[cl[0].GetDetectorID()]
2570 z = (botA[2]+topA[2])/2.
2571 sl = (botA[1]-topA[1])/(botA[0]-topA[0])
2572 b = topA[1]-sl*topA[0]
2573 yest = sl*(t1t2[3]*topA[2]+t1t2[4])+b
2574 rc = h[
'yest'].Fill(yest)
2575 if yest > botA[1]+cuts[
'yMax'] :
continue
2576 if yest < topA[1]-cuts[
'yMax'] :
continue
2577 stereoHits[2][cl[0].GetDetectorID()]=[cl[0],sl,b,yest,z]
2580 mean_v = mean_v/float(n_v)
2581 if Debug:
print "1 stereo v",len(stereoHits[2])
2582 for x
in stereoHits[2].keys():
2583 delta = stereoHits[2][x][3]-mean_v
2584 rc = h[
'delta_mean_uv'].Fill(delta)
2585 if abs(delta)>cuts[
'hitDist']: stereoHits[2].pop(x)
2587 if Debug:
print "stereo u v",len(stereoHits[1]),len(stereoHits[2])
2588 if len(stereoHits[1])<cuts[
'minLayersUV']
or len(stereoHits[2])<cuts[
'minLayersUV']:
continue
2589 slopeA,bA =
getSlopes(stereoHits[1],stereoHits[2],
'_uv')
2591 print "y slope",slopeA,bA
2593 for x
in stereoHits[1]:
print stereoHits[1][x][3],stereoHits[1][x][4]
2595 for x
in stereoHits[2]:
print stereoHits[2][x][3],stereoHits[2][x][4]
2597 yAtT3 = T3z*slopeA + bA
2598 if Debug:
print "uv",nu,nv,yAtT3,T3ybot ,T3ytop , (yAtT3 - T3ybot) > 2*cuts[
'yMax'] ,(T3ytop - yAtT3) > 2*cuts[
'yMax']
2599 if (yAtT3 - T3ybot) > 2*cuts[
'yMax']
or (T3ytop - yAtT3) > 2*cuts[
'yMax'] :
continue
2601 nt = len(h[
'dispTrackSeg'])
2602 h[
'dispTrackSeg'].append( ROOT.TGraph(2) )
2603 h[
'dispTrackSeg'][nt].SetPoint(0,0.,bA)
2604 h[
'dispTrackSeg'][nt].SetPoint(1,900.,slopeA*900+bA)
2605 h[
'dispTrackSeg'][nt].SetLineColor(ROOT.kGreen+nTrx)
2606 h[
'dispTrackSeg'][nt].SetLineWidth(2)
2607 h[
'simpleDisplay'].cd(1)
2608 h[
'dispTrackSeg'][nt].Draw(
'same')
2609 h[
'simpleDisplay'].Update()
2614 for cl
in t1t2[p]: hitList.append(cl[0])
2615 for p
in stereoHits:
2616 for cl
in stereoHits[p]: hitList.append(stereoHits[p][cl][0])
2618 for cl
in t3t4[p]: hitList.append(cl[0])
2620 if cuts[
'lateArrivalsToT']<3000:
2623 l = len(keysToDThits[x.GetDetectorID()])
2624 for k
in range(1,l):
2625 key = keysToDThits[x.GetDetectorID()][k]
2626 tmp.append(sTree.Digi_LateMufluxSpectrometerHits[key])
2628 if linearTrackModel:
2629 trackCandidates = hitList
2631 if zeroField: momFromptkick = 1000.
2632 else: momFromptkick=ROOT.TMath.Abs(1.03/(t3t4[3]-t1t2[3]+1E-20))
2633 if Debug:
print "fit track t1t2 %i t3t4 %i stereo %i,%i, with hits %i, delx %6.3F, pstart %6.3F"%(nt1t2,nt3t4,nu,nv,len(hitList),delx,momFromptkick)
2634 aTrack =
fitTrack(hitList,momFromptkick)
2635 if Debug:
print "result of trackFit",aTrack
2636 if type(aTrack) != type(1):
2640 if ( (pos[1] - T3ybot) > 1.2*cuts[
'yMax']
or (T3ytop - pos[1]) > 1.2*cuts[
'yMax'] ): reject =
True
2642 if len(mStatistics[
'u'])<cuts[
'minLayersUV']
or len(mStatistics[
'v'])<cuts[
'minLayersUV']: reject =
True
2647 aTrack.setMcTrackId( int(mcTrackID*1000+int(ghFraction*100+0.5) ) )
2648 if Debug:
print "ghost fraction: ", ghFraction,mcTrackID
2649 trackCandidates.append(aTrack)
2653 print "track rejected, outside T3 acceptance or not enough u/v measurements"
2654 print (pos[1] - T3ybot) > 1.2*cuts[
'yMax'] , (T3ytop - pos[1]) > 1.2*cuts[
'yMax'] , \
2655 len(mStatistics[
'u'])<2, len(mStatistics[
'v'])<2
2658 if len(trackCandidates)>1: trackCandidates =
cloneKiller(trackCandidates)
2659 if Debug:
print "# tracks after clonekiller = ",len(trackCandidates)
2661 for aTrack
in trackCandidates:
2662 fitter.processTrack(aTrack)
2665 return trackCandidates
2668 return [x
for x
in a
if x
in b]
2671 effFudgeFac = {
'u': 0.84,
'v': 0.82,
'x2': 0.91,
'x3': 0.89,
'x1': 0.94,
'x4': 0.96}
2673 detectors = {
'x1':0,
'x2':0,
'x3':0,
'x4':0,
'u':0,
'v':0}
2675 for m
in measurements[d]:
2676 if rnr.Uniform() < effFudgeFac[d]: detectors[d]+=1
2685 mStatistics = {
'x1':[],
'x2':[],
'x3':[],
'x4':[],
'xAll':[],
'xDown':[],
'xUp':[],
'uv':[],
'u':[],
'v':[]}
2686 if PR==1
and sTree.GetBranch(
"TrackInfos")
or PR==3
and sTree.GetBranch(
"TrackInfos_refitted"):
2687 if PR==1: trInfo = sTree.TrackInfos[aTrack]
2688 if PR==3: trInfo = sTree.TrackInfos_refitted[aTrack]
2689 for n
in range(trInfo.N()):
2690 detID = trInfo.detId(n)
2691 hit = ROOT.MufluxSpectrometerHit(detID,0)
2692 s,v,p,l,view,channelID,tdcId,mdoduleId =
stationInfo(hit)
2693 if trInfo.wL(n) <0.1
and trInfo.wR(n) <0.1:
continue
2695 mStatistics[
'uv'].append(detID)
2696 if view ==
'_u': mStatistics[
'u'].append(detID)
2697 if view ==
'_v': mStatistics[
'v'].append(detID)
2699 mStatistics[
'xAll'].append(detID)
2700 mStatistics[
'x'+str(s)].append(detID)
2701 if s > 2: mStatistics[
'xDown'].append(detID)
2702 else: mStatistics[
'xUp'].append(detID)
2704 for p
in aTrack.getPointsWithMeasurement():
2705 rawM = p.getRawMeasurement()
2706 info = p.getFitterInfo()
2707 if not info:
continue
2708 detID = rawM.getDetId()
2709 test = ROOT.MufluxSpectrometerHit(detID,0.)
2710 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(test)
2711 if info.getWeights()[0] <0.1
and info.getWeights()[1] <0.1:
continue
2713 mStatistics[
'uv'].append(detID)
2714 if view !=
'_u': mStatistics[
'u'].append(detID)
2715 if view !=
'_v': mStatistics[
'v'].append(detID)
2716 else: mStatistics[
'xAll'].append(detID)
2717 if s > 2: mStatistics[
'xDown'].append(detID)
2720 for s
in range(1,5):
2721 for view
in [
'_x',
'_u',
'_v']:
2723 if view==
'_u' and s!=1:
continue
2724 if view==
'_v' and s!=2:
continue
2725 ut.bookHist(h,
'used-'+str(s)+view+str(l),
'channel used in fit',200,-0.5,199.5)
2726 ut.bookHist(h,
'w-'+str(s)+view+str(l),
'sum of weight',100,0.,2.)
2727 for n
in range(sTree.GetEntries()):
2728 rc = sTree.GetEvent(n)
2730 for aTrack
in sTree.FitTracks:
2732 fitStatus = aTrack.getFitStatus()
2733 if not fitStatus.isFitConverged():
continue
2734 pMom0 = aTrack.getFittedState(0).getMomMag()
2735 if pMom0 < 1.:
continue
2736 trInfo = sTree.TrackInfos[nTrack]
2737 h[
'used-1_x0'].Fill(199)
2738 for n
in range(trInfo.N()):
2739 detID = trInfo.detId(n)
2740 hit = ROOT.MufluxSpectrometerHit(detID,0)
2741 s,v,p,l,view,channelID,tdcId,mdoduleId =
stationInfo(hit)
2742 w = trInfo.wL(n) + trInfo.wR(n)
2743 h[
'used-'+str(s)+view+str(2*p+l)].Fill(channelID)
2744 h[
'w-'+str(s)+view+str(2*p+l)].Fill(w)
2745 h[
'w']=h[
'w-1_x1'].Clone(
'w')
2747 for s
in range(1,5):
2748 for view
in [
'_x',
'_u',
'_v']:
2750 if view==
'_u' and s!=1:
continue
2751 if view==
'_v' and s!=2:
continue
2752 N = h[
'used-'+str(s)+view+str(l)].GetEntries()
2753 if s==1
and view==
'_x' and l==0: N = N - h[
'used-1_x0'].GetBinContent(200)
2754 rc = h[
'w'].Add(h[
'w-'+str(s)+view+str(l)])
2755 print s,view,l,N/h[
'used-1_x0'].GetBinContent(200)
2761 for j
in range( len(trackCandidates) ):
2763 for j
in range(len(detIDs)-1):
2764 if len(detIDs[j][
'xDown'])==0:
continue
2765 tj = float(len(detIDs[j][
'xDown']))
2766 sj = trackCandidates[j].getFitStatus()
2767 for k
in range(j+1,len(detIDs)):
2768 if len(detIDs[k][
'xDown'])==0:
continue
2774 o =
overlap(detIDs[j][
'xDown'],detIDs[k][
'xDown'])
2775 tk = float(len(detIDs[k][
'xDown']))
2776 if max(len(o)/tj,len(o)/tk)>0.49:
2777 sk = trackCandidates[k].getFitStatus()
2778 if sj.getNdf() < sk.getNdf()-cuts[
'deltaNdf']: detIDs[j][
'xDown']=[]
2779 elif sk.getNdf() < sj.getNdf()-cuts[
'deltaNdf']: detIDs[k][
'xDown']=[]
2780 elif sj.getChi2()/sj.getNdf() < sk.getChi2()/sk.getNdf(): detIDs[k][
'xDown']=[]
2781 elif sk.getChi2()/sk.getNdf() < sj.getChi2()/sj.getNdf(): detIDs[j][
'xDown']=[]
2782 else: detIDs[j][
'xDown']=[]
2783 if Debug:
print "j,k",j,sj.getNdf(),sj.getChi2(),sj.getChi2()/sj.getNdf(),len(detIDs[j][
'xDown']),len(detIDs[j][
'uv']),
' | ', k,sk.getNdf(),sk.getChi2(),sk.getChi2()/sk.getNdf(),len(detIDs[k][
'xDown']),len(detIDs[k][
'uv'])
2784 if len(detIDs[j][
'xDown'])==0:
break
2785 cloneKilledTracks = []
2787 for aTrack
in trackCandidates:
2789 if Debug:
print "clone killer at work",j,len(detIDs[j][
'xDown'])
2790 if len(detIDs[j][
'xDown'])>0:
2791 cloneKilledTracks.append(aTrack)
2793 for aTrack
in trackCandidates:
2795 if len(detIDs[j][
'xDown'])==0: aTrack.Delete()
2796 return cloneKilledTracks
2799 for hit
in sTree.Digi_MufluxSpectrometerHits:
2800 if not hit.hasTimeOverThreshold():
continue
2801 if hit.GetDetectorID()
in noisyChannels:
continue
2802 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
2803 if view !=
'_x':
continue
2804 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
2805 z = (vbot[2]+vtop[2])/2.
2806 x = (vbot[0]+vtop[0])/2.
2807 if s < 3: track = t3t4
2809 delX = x - (track[3]*z+track[4])
2810 h[
'linearRes'+str(s)+view+str(2*p+l)].Fill(delX,x)
2812 for hit
in sTree.Digi_MuonTaggerHits:
2813 channelID = hit.GetDetectorID()
2815 v = (channelID-10000*s)/1000
2817 vtop,vbot = RPCPositionsBotTop[channelID]
2818 z = (vtop[2]+vbot[2])/2.
2819 x = (vtop[0]+vbot[0])/2.
2820 delX = x - (track[3]*z+track[4])
2821 h[
'RPCResX_'+str(s)+str(v)].Fill(delX,x)
2824 eventRange = [0,sTree.GetEntries()]
2825 if not nEvent<0: eventRange = [nEvent,nEvent+nTot]
2826 for Nr
in range(eventRange[0],eventRange[1]):
2828 print "===== New Event =====",Nr
2831 print "tracks found",len(trackCandidates)
2832 for aTrack
in trackCandidates:
2834 next = raw_input(
"Next (Ret/Quit): ")
2838 if not aTrack.getNumPointsWithMeasurement()>0:
return
2839 sta = aTrack.getFittedState(0)
2843 for hit
in sTree.Digi_MufluxSpectrometerHits:
2844 if not hit.hasTimeOverThreshold():
continue
2845 if hit.GetDetectorID()
in noisyChannels:
continue
2846 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
2847 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
2848 z = (vbot[2]+vtop[2])/2.
2851 error =
"printResiduals: plotBiasedResiduals extrap failed"
2852 ut.reportError(error)
2855 if RTrelations.has_key(rname)
or MCdata:
2856 distance =
RT(hit,hit.GetDigi())
2857 tmp = (vbot[0] - vtop[0])*pos[1] - (vbot[1] - vtop[1])*pos[0] + vtop[0]*vbot[1] - vbot[0]*vtop[1]
2858 tmp = -tmp/ROOT.TMath.Sqrt( (vtop[0]-vbot[0])**2+(vtop[1]-vbot[1])**2)
2861 if abs(xL)<abs(xR):res = xL
2864 txt[k]=
"%i %s %i %5.3F %5.3F %5.3F %5.3F "%( s,view,2*p+l,pos[0],pos[1],pos[2],res)
2866 sorted_z = sorted(tmpList.items(), key=operator.itemgetter(1))
2872 timerStats = {
'fit':0,
'analysis':0,
'prepareTrack':0,
'extrapTrack':0,
'fillRes':0}
2873 if not onlyPlotting:
2874 h[
'biasResDist'].Reset()
2875 h[
'biasResDist2'].Reset()
2876 h[
'biasResDistLR']=h[
'biasResDist'].Clone(
'biasResDistLR')
2879 for p
in xLayers[s]:
2880 for l
in xLayers[s][p]:
2881 for view
in xLayers[s][p][l]:
2882 h[xLayers[s][p][l][view].GetName()].Reset()
2883 hkey = str(s)+view+str(2*p+l)
2884 h[
'biasResDist_'+hkey].Reset()
2885 h[
'biasResDistLR_'+hkey]=h[
'biasResDist_'+hkey].Clone(
'biasResDistLR_'+hkey)
2886 h[
'biasResDist2Wire_'+hkey] = h[
'biasResDist2'].Clone(
'biasResDist2Wire_'+hkey)
2887 ut.bookHist(h,
'distIfNoHit_'+hkey,
'shortest distance to wire if no hit',100,0.,5.)
2888 for n
in range(576/cuts[
'RTsegmentation'] ): h[
'TDC'+str(n)].Reset()
2890 pos = ROOT.TVector3()
2891 mom = ROOT.TVector3()
2892 eventRange = [0,sTree.GetEntries()]
2893 if not nEvent<0: eventRange = [nEvent,nEvent+nTot]
2894 timerStats = {
'fit':0,
'analysis':0,
'prepareTrack':0,
'extrapTrack':0,
'fillRes':0}
2895 for Nr
in range(eventRange[0],eventRange[1]):
2898 if Nr%10000==0:
print "now at event",Nr,
' of ',sTree.GetEntries(),sTree.GetCurrentFile().GetName(),time.ctime()
2902 timerStats[
'fit']+=timer.RealTime()
2903 if len(trackCandidates)==1:
2905 spectrHitsSorted = ROOT.nestedList()
2906 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
True)
2907 for aTrack
in trackCandidates:
2908 fst = aTrack.getFitStatus()
2909 if not fst.isFitConverged():
continue
2911 sta = aTrack.getFittedState(0)
2913 print "problem with getting state, event",sTree.GetCurrentFile().GetName(),Nr
2915 if sta.getMomMag() < minP
and not zeroField:
continue
2919 if len(RPCtracks[
'X'])==1
and len(RPCtracks[
'Y'])==1:
2920 posRPC = ROOT.TVector3()
2921 momRPC = ROOT.TVector3()
2922 rc = muflux_Reco.extrapolateToPlane(aTrack,cuts[
"zRPC1"], posRPC, momRPC)
2923 Xpos = RPCtracks[
'X'][0][0]*cuts[
"zRPC1"]+RPCtracks[
'X'][0][1]
2924 distX = ROOT.TMath.Abs(posRPC[0]-Xpos)
2925 Ypos = RPCtracks[
'Y'][0][0]*cuts[
"zRPC1"]+RPCtracks[
'Y'][0][1]
2926 distY = ROOT.TMath.Abs(posRPC[1]-Ypos)
2927 if abs(distX)<cuts[
'muTrackMatchX']
and abs(distY)<cuts[
'muTrackMatchY']: muonTag =
True
2928 if not muonTag:
continue
2930 stations={1:0,2:0,3:0,4:0}
2931 for p
in aTrack.getPoints():
2932 rawM = p.getRawMeasurement()
2933 s = rawM.getDetId()/10000000
2935 print "error with rawM", rawM.getDetId()
2937 if not (stations[1]>1
and stations[2]>1
and stations[3]>1
and stations[4]>1) :
continue
2938 rc = h[
'biasResTrackMom'].Fill(sta.getMomMag())
2939 timerStats[
'prepareTrack']+=timer.RealTime()
2941 for s
in range(1,5):
2942 for view
in viewsI[s]:
2945 for hit
in spectrHitsSorted[view][s][l]:
2946 ss,vv,pp,ll,vw,channelID,tdcId,nRT =
stationInfo(hit)
2947 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
2948 z = (vbot[2]+vtop[2])/2.
2951 trackLength = muflux_Reco.extrapolateToPlane(aTrack,z,pos,mom)
2952 timerStats[
'extrapTrack']+=timer.RealTime()
2955 error =
"plotBiasedResiduals: extrapolation failed"
2956 ut.reportError(error)
2959 if withTDC
or MCdata:
2960 distance =
RT(hit,hit.GetDigi())
2963 normal = mom.Cross(vtop-vbot)
2964 d = normal.Dot(pos-vbot)/normal.Mag()
2965 res = abs(d) - distance
2966 h[
'biasResDist'].Fill(distance,res)
2967 h[
'biasResDist2'].Fill(abs(d),res)
2968 if abs(res) < 0.2: hitFound =
True
2969 hkey = str(ss)+vw+str(2*pp+ll)
2970 h[
'biasResDist2Wire_'+hkey].Fill(abs(d),res)
2971 h[
'biasResDist_'+hkey].Fill(distance,res)
2972 m = (vtop[0]-vbot[0])/(vtop[1]-vbot[1])
2973 b = vtop[0]-m*vtop[1]
2974 if pos[0]<m*pos[1]+b:
2979 h[
'biasResDistLR'].Fill(distance,resR)
2980 h[
'biasResDistLR'].Fill(distance,resL)
2981 h[
'biasResDistLR_'+hkey].Fill(distance,resR)
2982 h[
'biasResDistLR_'+hkey].Fill(distance,resL)
2983 h[
'biasResXLA_'+hkey].Fill(res,pos[0])
2984 h[
'biasResYLA_'+hkey].Fill(res,pos[1])
2985 h[
'biasResX_'+hkey].Fill(resR,pos[0])
2986 h[
'biasResY_'+hkey].Fill(resR,pos[1])
2987 h[
'biasResXL_'+hkey].Fill(resR,pos[0])
2988 h[
'biasResYL_'+hkey].Fill(resR,pos[1])
2989 h[
'biasResX_'+hkey].Fill(resL,pos[0])
2990 h[
'biasResY_'+hkey].Fill(resL,pos[1])
2991 h[
'biasResXL_'+hkey].Fill(resL,pos[0])
2992 h[
'biasResYL_'+hkey].Fill(resL,pos[1])
2994 detID = str(hit.GetDetectorID())
2995 h[
'biasResX_'+detID].Fill(resR,pos[0])
2996 h[
'biasResY_'+detID].Fill(resR,pos[1])
2997 h[
'biasResXL_'+detID].Fill(resR,pos[0])
2998 h[
'biasResYL_'+detID].Fill(resR,pos[1])
2999 h[
'biasResX_'+detID].Fill(resL,pos[0])
3000 h[
'biasResY_'+detID].Fill(resL,pos[1])
3001 h[
'biasResXL_'+detID].Fill(resL,pos[0])
3002 h[
'biasResYL_'+detID].Fill(resL,pos[1])
3006 if MCdata: t0 = sTree.ShipEventHeader.GetEventTime()
3007 rc = h[
'TDC'+str(nRT)].Fill(hit.GetDigi()-t0)
3008 rc = xLayers[ss][pp][ll][vw].Fill( channelID )
3009 rc = h[
'T0tmp'].Fill(hit.GetDigi()-t0)
3013 if (s==1
and view==1)
or (s==2
and view==0): v=1000000
3014 firstWire = s*10000000+v+2000+(l%2)*10000+(l/2)*100000+1
3015 vbot,vtop = strawPositionsBotTop[firstWire]
3016 z = (vbot[2]+vtop[2])/2.
3017 trackLength = muflux_Reco.extrapolateToPlane(aTrack,z,pos,mom)
3019 for n
in range(Nchannels[s]):
3020 vbot,vtop = strawPositionsBotTop[firstWire+n]
3021 normal = mom.Cross(vtop-vbot)
3022 d = normal.Dot(pos-vbot)/normal.Mag()
3023 if abs(d)<minDist: minDist=abs(d)
3024 h[
'distIfNoHit_'+hkey].Fill(minDist)
3025 t0 = h[
'T0tmp'].GetMean()
3026 rc = h[
'T0'].Fill(t0)
3027 timerStats[
'fillRes']+=timer.RealTime()
3029 timerStats[
'analysis']+=timer.RealTime()
3030 for aTrack
in trackCandidates: aTrack.Delete()
3031 if not h.has_key(
'biasedResiduals'):
3032 ut.bookCanvas(h,key=
'biasedResiduals',title=
'biasedResiduals',nx=1600,ny=1200,cx=4,cy=6)
3033 ut.bookCanvas(h,key=
'biasedResidualsX',title=
'biasedResiduals function of X',nx=1600,ny=1200,cx=4,cy=6)
3034 ut.bookCanvas(h,key=
'biasedResidualsY',title=
'biasedResiduals function of Y',nx=1600,ny=1200,cx=4,cy=6)
3036 for s
in range(1,5):
3037 for view
in [
'_x',
'_u',
'_v']:
3038 if s>2
and view !=
'_x':
continue
3039 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
3040 for l
in range(0,4):
3041 if withTDC: hname =
'biasResX_'+str(s)+view+str(l)
3042 else: hname =
'biasResXL_'+str(s)+view+str(l)
3043 hnameProjX =
'biasRes_'+str(s)+view+str(l)
3044 h[hnameProjX] = h[hname].ProjectionX()
3045 tc = h[
'biasedResiduals'].cd(j)
3046 if h[hname].GetEntries()<10:
3047 h[hnameProjX].Draw()
3050 fitResult = h[hnameProjX].Fit(
'gaus',
'SQ',
'',-0.5,0.5)
3051 rc = fitResult.Get()
3052 fitFunction = h[hnameProjX].GetFunction(
'gauss')
3053 if not fitFunction : fitFunction = myGauss
3055 print "simple gaus fit failed"
3056 fitFunction.SetParameter(0,h[hnameProjX].GetEntries()*h[hnameProjX].GetBinWidth(1))
3057 fitFunction.SetParameter(1,0.)
3058 fitFunction.SetParameter(2,0.1)
3059 fitFunction.SetParameter(3,1.)
3061 fitFunction.SetParameter(0,rc.GetParams()[0]*ROOT.TMath.Sqrt(2*ROOT.TMath.Pi())*rc.GetParams()[2])
3062 fitFunction.SetParameter(1,rc.GetParams()[1])
3063 fitFunction.SetParameter(2,rc.GetParams()[2])
3064 fitFunction.SetParameter(3,0.)
3065 fitResult = h[hnameProjX].Fit(fitFunction,
'SQ',
'',-0.2,0.2)
3066 fitResult = h[hnameProjX].Fit(fitFunction,
'SQ',
'',-0.5,0.5)
3067 rc = fitResult.Get()
3070 h[hnameProjX].Draw()
3074 stats = h[hnameProjX].FindObject(
"stats")
3075 stats.SetX1NDC(0.563258)
3076 stats.SetY1NDC(0.526687)
3077 stats.SetX2NDC(0.938728)
3078 stats.SetY2NDC(0.940086)
3079 stats.SetOptFit(111)
3081 mean = rc.GetParams()[1]
3082 rms = rc.GetParams()[2]
3083 Emean = rc.GetErrors()[1]
3084 Erms = rc.GetErrors()[2]
3085 print "%i, %s, %i mean=%5.2F+/-%5.2F RMS=%5.2F+/-%5.2F [mm]"%(s,view,l,mean*10,Emean*10,rms*10,Erms*10)
3086 residuals[j-1]= h[hnameProjX].GetMean()
3089 if withTDC: hname =
'biasRes'+p+
'_'+str(s)+view+str(l)
3090 else: hname =
'biasRes'+p+
'L_'+str(s)+view+str(l)
3091 hmean = hname+
'_mean'+p
3092 h[hmean] = h[hname].ProjectionY(hname+
'_mean')
3094 rc = h[
'biasedResiduals'+p].cd(j)
3095 for k
in range(1,h[hname].GetNbinsY()+1):
3096 sli = hname+
'_'+str(k)
3097 h[sli] = h[hname].ProjectionX(sli,k,k)
3098 if h[sli].GetEntries()<10:
continue
3099 fitResult = h[sli].Fit(
'gaus',
'SQ',
'',-0.5,0.5)
3100 rc = fitResult.Get()
3101 fitFunction = h[sli].GetFunction(
'gauss')
3102 if not fitFunction : fitFunction = myGauss
3104 print "simple gaus fit failed"
3105 fitFunction.SetParameter(0,h[sli].GetEntries()*h[sli].GetBinWidth(1))
3106 fitFunction.SetParameter(1,0.)
3107 fitFunction.SetParameter(2,0.1)
3108 fitFunction.SetParameter(3,1.)
3110 fitFunction.SetParameter(0,rc.GetParams()[0]*ROOT.TMath.Sqrt(2*ROOT.TMath.Pi())*rc.GetParams()[2])
3111 fitFunction.SetParameter(1,rc.GetParams()[1])
3112 fitFunction.SetParameter(2,rc.GetParams()[2])
3113 fitFunction.SetParameter(3,0.)
3114 fitResult = h[sli].Fit(fitFunction,
'SQ',
'',-0.3,0.3)
3115 rc = fitResult.Get()
3118 mean = rc.GetParams()[1]
3119 rms = rc.GetParams()[2]
3120 rc = h[hmean].SetBinContent( k, mean)
3121 rc = h[hmean].SetBinError(k, rms)
3122 amin,amax,nmin,nmax = ut.findMaximumAndMinimum(h[hmean])
3123 if amax<3.
and amin>-3.:
3124 h[hmean].SetMaximum(0.2)
3125 h[hmean].SetMinimum(-0.2)
3127 h[hmean].SetLineColor(ROOT.kRed)
3128 h[hmean].SetMaximum(0.2)
3129 h[hmean].SetMinimum(-0.2)
3132 myPrint(h[
'biasedResiduals'],
'biasedResiduals')
3133 myPrint(h[
'biasedResidualsX'],
'biasedResidualsX')
3135 print "timing:",timerStats
3138 h[
'biasResDist2_projx'].Draw()
3139 h[
'tubeLine']=ROOT.TLine(r,0,r,2000)
3140 h[
'tubeLine'].SetLineColor(ROOT.kRed)
3141 h[
'tubeLine'].Draw(
'same')
3142 h[
'tubeLineX']=ROOT.TLine(r-0.19,0,r-0.19,2000)
3143 h[
'tubeLineX'].SetLineColor(ROOT.kMagenta)
3144 h[
'tubeLineX'].Draw(
'same')
3147 ut.bookHist(h,
'resDistr',
'residuals',50,0.,0.1)
3148 for tc
in h[
'biasedResiduals'].GetListOfPrimitives():
3149 for p
in tc.GetListOfPrimitives():
3150 if p.InheritsFrom(
'TH1'):
3151 fitFun = p.GetFunction(
'gauss')
3152 h[
'resDistr'].Fill(fitFun.GetParameter(2))
3153 ROOT.gROOT.FindObject(
'c1').cd()
3154 h[
'resDistr'].Draw()
3158 if not hist.find(
'proj')<0:
continue
3159 if not hist.find(
'slice')<0:
continue
3160 if not hist.find(
'LR')<0:
continue
3161 if not hist.find(
'biasResDist2Wire')<0:
continue
3162 if not hist ==
'biasResDist' and not hist.find(
'biasResDist_')==0:
continue
3163 v=hist.replace(
'biasResDist',
'')
3164 h[
'RTcorr'+v]=ROOT.TGraph()
3166 tmpx = h[hist].ProjectionX()
3167 hresol =
'resVsDr'+v
3168 h[hresol]=tmpx.Clone(hresol)
3169 h[hresol].SetTitle(
'resolution as function of driftRadius')
3171 for n
in range(1,h[hist].GetNbinsX()):
3172 if tmpx.GetBinCenter(n)>1.8:
break
3173 name = hist+
'slice'+str(n)
3174 h[name] = h[hist].ProjectionY(name,n,n+1)
3175 fitResult = h[name].Fit(
'gaus',
'SQ',
'',-0.2,0.2)
3176 rc = fitResult.Get()
3179 h[
'RTcorr'+v].SetPoint(N,tmpx.GetBinCenter(n),rc.GetParams()[1])
3180 h[hresol].SetBinContent(n,rc.GetParams()[2])
3182 if not h.has_key(
'RTCorrection'):
3183 ut.bookCanvas(h,key=
'RTCorrection',title=
'RTCorrection',nx=1200,ny=1400,cx=1,cy=2)
3184 ut.bookCanvas(h,
'dummy',
' ',900,600,1,1)
3185 case = {
'dummy':1,
'RTCorrection':1}
3187 tc = h[z].cd(case[z])
3188 h[
'RTcorr'].SetLineColor(ROOT.kMagenta)
3189 h[
'RTcorr'].SetLineWidth(2)
3190 h[
'hRTCorrection']=h[
'resVsDr'].Clone(
'hRTCorrection')
3191 h[
'hRTCorrection'].SetTitle(
';drift radius [cm]; mean difference [cm]')
3192 h[
'hRTCorrection'].SetStats(0)
3193 h[
'hRTCorrection'].SetMaximum(0.02)
3194 h[
'hRTCorrection'].SetMinimum(-0.06)
3195 h[
'hRTCorrection'].Reset()
3196 h[
'hRTCorrection'].SetLineColor(0)
3197 h[
'hRTCorrection'].Draw()
3200 if x.find(
'RTcorr')!=0:
continue
3201 if not x.find(
'LR')<0
or not x.find(
'Par')<0:
continue
3203 rc = h[x].Fit(
'pol3',
'SQ')
3204 fitresult = rc.Get()
3205 h[x+
'Par'+x]=[fitresult.Parameter(0),fitresult.Parameter(1),fitresult.Parameter(2),fitresult.Parameter(3)]
3206 if z==
'dummy':
myPrint(h[
'dummy'],
'RTCorrection')
3207 case = {
'RTCorrection':2}
3209 tc = h[z].cd(case[z])
3210 h[
'resVsDr'].SetLineColor(ROOT.kMagenta)
3211 h[
'resVsDr'].SetLineWidth(2)
3212 h[
'resVsDr'].SetMaximum(0.2)
3213 h[
'resVsDr'].SetMinimum(-0.06)
3214 h[
'resVsDr'].SetTitle(
';drift radius [cm]; sigma [cm]')
3215 h[
'resVsDr'].SetStats(0)
3218 if x.find(
'resVsDr')!=0:
continue
3219 if x.find(
'u')>0
or x.find(
'v')>0:
3220 h[x].SetLineColor(ROOT.kGreen)
3221 elif x.find(
'_3')>0
or x.find(
'_4')>0:
3222 h[x].SetLineColor(ROOT.kRed)
3225 h[
'biasResX_all']=h[
'biasResX_1_x1_projx'].Clone(
'biasResX_all')
3226 h[
'biasResX_all'].Reset()
3228 for p
in xLayers[s]:
3229 for l
in xLayers[s][p]:
3230 for view
in xLayers[s][p][l]:
3231 h[
'biasResX_all'].Add(h[
'biasResX_'+str(s)+view+str(2*p+l)+
'_projx'])
3234 h[
'test'] = h[
'biasResDist_projy'].Clone(
'test')
3236 h[
'test0'] = h[
'test'].Clone(
'test0')
3237 for k
in range( int(1.8/dr)):
3239 offset = h[
'RTcorr'].Eval(r)
3241 for n
in range(10000):
3242 rr = rnr.Gaus(offset,sigma)
3243 rc = h[
'test'].Fill(rr)
3244 rr = rnr.Gaus(0.,sigma)
3245 rc = h[
'test0'].Fill(rr)
3252 histo = h[
'biasResX_'+str(detID)+
'_projx']
3254 if histo.GetSumOfWeights()>25:
3255 fitResult = histo.Fit(
'gaus',
'SQ',
'',-0.5,0.5)
3256 rc = fitResult.Get()
3257 fitFunction = histo.GetFunction(
'gauss')
3258 if not fitFunction : fitFunction = myGauss
3261 fitFunction.SetParameter(0,histo.GetEntries()*histo.GetBinWidth(1))
3262 fitFunction.SetParameter(1,0.)
3263 fitFunction.SetParameter(2,0.1)
3264 fitFunction.SetParameter(3,1.)
3266 fitFunction.SetParameter(0,rc.GetParams()[0]*ROOT.TMath.Sqrt(2*ROOT.TMath.Pi())*rc.GetParams()[2])
3267 fitFunction.SetParameter(1,rc.GetParams()[1])
3268 fitFunction.SetParameter(2,rc.GetParams()[2])
3269 fitFunction.SetParameter(3,0.)
3270 fitResult = histo.Fit(fitFunction,
'SQ',
'',-0.3,0.3)
3271 rc = fitResult.Get()
3273 mean = rc.GetParams()[1]
3274 rms = rc.GetParams()[2]
3275 uf = histo.GetBinContent(0)
3276 of = histo.GetBinContent(histo.GetNbinsX()+1)
3277 if mean < -900:
print "channel:%i : not enough statistics, integral=%i, under- over-flow: %i,%i"%(detID,histo.GetSumOfWeights(),uf,of)
3278 else:
print "channel:%i : mean=%6.3Fmm, sigma=%6.3Fmm"%(detID,mean*10,rms*10)
3281 if not h.has_key(
'biasedResiduals2dX'):
3282 ut.bookCanvas(h,key=
'biasedResiduals2dX',title=
'biasedResiduals function of X',nx=1600,ny=1200,cx=4,cy=6)
3283 ut.bookCanvas(h,key=
'biasedResiduals2dY',title=
'biasedResiduals function of Y',nx=1600,ny=1200,cx=4,cy=6)
3285 for s
in range(1,5):
3286 for view
in [
'_x',
'_u',
'_v']:
3287 if s>2
and view !=
'_x':
continue
3288 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
3289 for l
in range(0,4):
3290 hname =
'biasResX_'+str(s)+view+str(l)
3291 if h[hname].GetEntries()<1:
continue
3292 print s,view,l,h[hname].GetEntries()
3294 hname =
'biasRes'+p+
'_'+str(s)+view+str(l)
3295 rc = h[
'biasedResiduals2d'+p].cd(j)
3296 if minEntries >0: h[hname].SetMinimum(minEntries)
3297 h[hname].Draw(
'box')
3300myGauss2 = ROOT.TF1(
'test',
'abs([0])/(abs([2])*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+abs( [3]+[6]*x+[7]*x**2 )+abs([4])/(abs([5])*sqrt(2*pi))*exp(-0.5*((x-[1])/[5])**2)',8)
3301myGauss2.SetParName(0,
'Signal')
3302myGauss2.SetParName(1,
'Mean')
3303myGauss2.SetParName(2,
'Sigma')
3304myGauss2.SetParName(3,
'bckgr')
3305myGauss2.SetParName(4,
'Tail')
3306myGauss2.SetParName(5,
'Sigma2')
3307myGauss2.SetParName(6,
'bckgr2')
3308myGauss2.SetParName(7,
'bckgr3')
3309myGauss2.FixParameter(6,0.)
3310myGauss2.FixParameter(7,0.)
3315 for i
in range(k,n+1): totEff += ROOT.TMath.Binomial(n,i)*eff**i*(1-eff)**(n-i)
3316 print "global efficiency = %5.4F %i %i"%(totEff,n,k)
3320 addCuts = {
'':0,
'Chi2<':0.7,
'Dely<':5,
'Delx<':2,
'All':1}
3321 align2RPC = {4:[-1.,3.2],3:[-2.,5.],2:[-6.,8.],1:[-6.,8.]}
3322 stationDetIDs = {
'x1':[10002001,10002012],
'u':[11002001,11002012],
'x2':[21102001,21102012],
3323 'v':[20112001,20112012],
'x3':[30002001,30002048],
'x4':[40002001,40002048]}
3325 for s
in range(1,5):
3326 vbot,vtop = strawPositionsBotTop[stationDetIDs[
'x'+str(s)][0]]
3327 z = (vbot[2]+vtop[2])/2.
3328 xmin = (vbot[0]+vtop[0])/2.
3329 vbot,vtop = strawPositionsBotTop[stationDetIDs[
'x'+str(s)][1]]
3330 xmax = (vbot[0]+vtop[0])/2.
3331 stationZ[s] = [z,xmin,xmax]
3332 if not onlyPlotting:
3333 if Nevents==0: Nevents = sTree.GetEntries()
3334 for tag_s
in range(1,5):
3335 ut.bookHist(h,
'upStreamOcc'+str(tag_s),
"station 1&2",200,-0.5,199.5)
3336 ut.bookHist(h,
'upStreamOccWithTrack'+str(tag_s),
"station 1&2",200,-0.5,199.5)
3337 ut.bookHist(h,
'upStreamOccWithTrack_mu'+str(tag_s),
"station 1&2",200,-0.5,199.5)
3338 ut.bookHist(h,
'upStreamOccWithTrack_muX'+str(tag_s),
"station 1&2",200,-0.5,199.5)
3339 ut.bookHist(h,
'upStreamOccWithTrack_Chi2'+str(tag_s),
"station 1&2",200,-0.5,199.5)
3340 ut.bookHist(h,
'upStreamOccWithTrack_Chi2mu'+str(tag_s),
"station 1&2",200,-0.5,199.5)
3341 for tag_s
in range(1,5):
3342 for s
in range(1,5):
3343 ut.bookHist(h,
'hitsIn'+str(s)+
'_'+str(tag_s),
'number of hits '+str(s),10,-0.5,9.5)
3344 ut.bookHist(h,
'hits' +str(s)+
'_'+str(tag_s),
'number of hits in layer '+str(s),7,-0.5,6.5)
3346 if tag_s==1: ut.bookHist(h,
'distX' +str(s)+str(l),
'distance of RPC track to hit '+str(s)+str(l),100,-10.,10.)
3347 ut.bookHist(h,
'distXref'+str(s)+str(l)+
'_'+str(tag_s),
'distance of refitted RPC track to hit '+str(s)+str(l),100,-10.,10.)
3349 Ntrack = [0,0,0,0,0]
3352 for n
in range(Nevents):
3353 rc = sTree.GetEvent(n)
3355 if len(sTree.RPCTrackX)!=1
or len(sTree.RPCTrackY)!=1 :
continue
3358 if len(clusters[1][1])==0
or len(clusters[1][1])>2:
continue
3359 if len(clusters[2][2])==0
or len(clusters[2][2])>2:
continue
3361 spectrHitsSorted = ROOT.nestedList()
3362 candidates= {1:{0:[],1:[],2:[],3:[]}, 2:{0:[],1:[],2:[],3:[]}, 3:{0:[],1:[],2:[],3:[]},4:{0:[],1:[],2:[],3:[]}}
3363 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
False)
3365 for k
in range(1,7):
3376 stationOcc[k]+=spectrHitsSorted[t][s][l].size()
3377 upStreamOcc = stationOcc[1]+stationOcc[5]+stationOcc[2]+stationOcc[6]
3378 for mu
in sTree.RPCTrackX:
3380 for s
in range(1,5):
3382 if len(clusters[s][0]) > 1:
continue
3383 for cl
in clusters[s][0]:
3386 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
3387 z = (vbot[2]+vtop[2])/2.
3388 x = (vbot[0]+vtop[0])/2.
3389 xExtr = mu.m()*z + mu.b()
3390 diff = x-xExtr - align2RPC[s][0]
3392 l = 2*temp[2]+temp[3]
3393 if abs(diff)<align2RPC[s][1]: candidates[s][l].append(hit)
3394 rc = h[
'distX'+str(s)+str(l)].Fill(diff)
3396 for tag_s
in range(1,5):
3398 for l
in candidates[tag_s]:
3399 if len(candidates[tag_s][l])>1: unique =
False
3400 if not unique:
continue
3403 pos[zRPC1] = mu.m()*zRPC1 + mu.b()
3404 for l
in candidates[tag_s]:
3405 for hit
in candidates[tag_s][l]:
3406 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
3407 pos[(vbot[2]+vtop[2])/2.]=(vbot[0]+vtop[0])/2.
3412 distance =
RT(hit,tdc)
3413 pos[(vbot[2]+vtop[2])/2.]=(vbot[0]+vtop[0])/2. + distance
3414 pos[(vbot[2]+vtop[2])/2.]=(vbot[0]+vtop[0])/2. - distance
3415 if len(pos)<3:
continue
3416 coefficients = numpy.polyfit(pos.keys(),pos.values(),1)
3420 xExtr = coefficients[0]*stationZ[s][0] + coefficients[1]
3421 if xExtr<stationZ[s][1]
or xExtr>stationZ[s][2]: inAcc =
False
3422 if not inAcc:
continue
3423 rc = h[
'upStreamOcc'+str(tag_s)].Fill(upStreamOcc)
3426 goodTracks = {
'':[],
'Chi2<':[],
'mu':[],
'muX':[],
'Chi2<mu':[]}
3428 for aTrack
in sTree.FitTracks:
3431 fitStatus = aTrack.getFitStatus()
3432 if not fitStatus.isFitConverged():
continue
3434 if len(hitsPerStation[
'x1'])<2
or len(hitsPerStation[
'x2'])<2
or len(hitsPerStation[
'x3'])<2
or len(hitsPerStation[
'x4'])<2:
continue
3435 goodTracks[
''].append(k)
3436 chi2OK = fitStatus.getChi2()/fitStatus.getNdf() < addCuts[
'Chi2<']
3437 if chi2OK: goodTracks[
'Chi2<'].append(k)
3439 posRPC=ROOT.TVector3()
3440 momRPC=ROOT.TVector3()
3441 rc = muflux_Reco.extrapolateToPlane(aTrack,cuts[
"zRPC1"], posRPC, momRPC)
3444 for hit
in sTree.RPCTrackX:
3445 Xpos = hit.m()*cuts[
"zRPC1"]+hit.b()
3446 dist = ROOT.TMath.Abs(posRPC[0]-Xpos)
3447 if dist<cuts[
"muTrackMatchX"]: X=ROOT.kTRUE
3448 for hit
in sTree.RPCTrackY:
3449 Ypos = hit.m()*cuts[
"zRPC1"]+hit.b()
3450 dist = ROOT.TMath.Abs(posRPC[1]-Ypos)
3451 if dist<cuts[
"muTrackMatchY"]: Y=ROOT.kTRUE
3452 if X
and Y: goodTracks[
'mu'].append(k)
3453 if X: goodTracks[
'muX'].append(k)
3454 if X
and Y
and chi2OK: goodTracks[
'Chi2<mu'].append(k)
3455 for c
in goodTracks:
3456 for x
in goodTracks[c]:
3458 rc = h[
'upStreamOccWithTrack'+str(tag_s)].Fill(upStreamOcc)
3461 rc = h[
'upStreamOccWithTrack_mu'+str(tag_s)].Fill(upStreamOcc)
3463 if c==
'muX': rc = h[
'upStreamOccWithTrack_muX'+str(tag_s)].Fill(upStreamOcc)
3464 if c==
'Chi2<': rc = h[
'upStreamOccWithTrack_Chi2'+str(tag_s)].Fill(upStreamOcc)
3465 if c==
'Chi2<mu': rc = h[
'upStreamOccWithTrack_Chi2mu'+str(tag_s)].Fill(upStreamOcc)
3467 nhits={1:0,2:0,3:0,4:0}
3468 for s
in range(1,5):
3471 for hit
in spectrHitsSorted[view][s][l]:
3472 vbot,vtop = strawPositionsBotTop[hit.GetDetectorID()]
3473 z = (vbot[2]+vtop[2])/2.
3474 x = (vbot[0]+vtop[0])/2.
3475 xExtr = coefficients[0]*z + coefficients[1]
3476 rc = h[
'distXref'+str(s)+str(l)+
'_'+str(tag_s)].Fill(x-xExtr)
3481 h[
'hits'+str(s)+
'_'+str(tag_s)].Fill(l)
3482 h[
'hitsIn'+str(s)+
'_'+str(tag_s)].Fill(nhits[s])
3484 if nhits[4] < 2: Ineff+=1
3486 if not anyTrack[s]
and Debug:
print "no fitted track found",n
3487 for tag_s
in range(1,5):
3488 for s
in range(1,5):
3489 h[
'hits'+str(s)+
'_'+str(tag_s)].SetBinContent(6,Ntot[tag_s])
3490 h[
'hits'+str(s)+
'_'+str(tag_s)].SetBinContent(7,Ntrack[tag_s])
3491 print "rough estimate of station inefficiency:",float(Ineff)/(Ntot[tag_s]+1E-5)
3492 ut.writeHists(h,
'histos-DTEff'+rname)
3495 ut.bookHist(h,
'effLayer',
'efficiency per Layer',24,-0.5,23.5)
3496 if not h.has_key(
'hits1_1'):
3497 if fHisto: ut.readHists(h,fHisto)
3498 else: ut.readHists(h,
'DTEff.root')
3500 for tag_s
in range(1,5):
3501 t =
'tagstation'+str(tag_s)
3502 if not h.has_key(t):
3503 ut.bookCanvas(h,key=t,title=
'with tagging station '+str(tag_s),nx=1600,ny=1200,cx=4,cy=4)
3504 print "analysis with tagging station ",tag_s
3505 effPerLayer[tag_s] = {}
3506 for s
in range(1,5):
3510 hname =
'distXref'+str(s)+str(l)+
'_'+str(tag_s)
3511 fitFunction = myGauss
3512 fitFunction.SetParameter(0,h[hname].GetEntries()*h[hname].GetBinWidth(1))
3513 fitFunction.SetParameter(1,0.)
3514 fitFunction.SetParameter(2,1.2)
3515 fitFunction.SetParameter(3,0.)
3516 fitResult = h[hname].Fit(fitFunction,
'SQ',
'',-10.,10.)
3517 rc = fitResult.Get()
3518 background = rc.Parameter(3) * h[hname].GetNbinsX()
3519 bckInterval = float(h[hname].GetNbinsX() - (h[hname].FindBin(4.) - h[hname].FindBin(-4.)) )
3520 backgroundBinary = h[hname].Integral(1,h[hname].FindBin(-4.)) + h[hname].Integral(h[hname].FindBin(4.),h[hname].GetNbinsX())
3521 estSignalBinary = h[hname].GetSumOfWeights() - backgroundBinary/bckInterval*h[hname].GetNbinsX()
3522 signal1 = h[hname].GetSumOfWeights()-background
3523 signal2 = rc.Parameter(0)
3524 err = ROOT.TMath.Sqrt(float(h[
'hits'+str(s)+
'_'+str(tag_s)].GetBinContent(6))-estSignalBinary)/float(h[
'hits'+str(s)+
'_'+str(tag_s)].GetBinContent(6))
3526 signal = estSignalBinary
3527 effPerLayer[tag_s][10*s+l] = signal / float(h[
'hits'+str(s)+
'_'+str(tag_s)].GetBinContent(6))
3528 if tag_s == 1
and s!=1
or tag_s == 2
and s==1:
3532 h[
'effLayer'].SetBinContent(L,effPerLayer[tag_s][10*s+l])
3533 h[
'effLayer'].SetBinError(L,err)
3536 for p
in h[t].GetListOfPrimitives():
3540 test = t+
'_'+str((tag_s-1)*4+l+1)
3541 if pname == test: p.Delete()
3542 myPrint(h[t],
'DTeffPerLayer-station'+str(tag_s)+
'_res')
3543 print "tagging station : 1 2 3 4"
3544 for s
in range(1,5):
3546 text =
"efficiencies for station %i layer %i:"%(s,l)
3547 for tag_s
in range(1,5):
3548 text+=
" %5.2F%% "%(effPerLayer[tag_s][10*s+l]*100)
3550 ut.bookHist(h,
'DTeffPerLayer',
'DT hit efficiency per layer',50,0.5,50.5)
3551 choice = {1:[2,ROOT.kRed],2:[1,ROOT.kGreen],3:[1,ROOT.kBlue],4:[1,ROOT.kMagenta]}
3554 for s
in range(1,5):
3555 for view
in [
'_x',
'_u',
'_v']:
3556 if s>2
and view !=
'_x':
continue
3557 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
3561 tag_s = choice[s][0]
3564 h[
'DTeffPerLayer'].SetBinContent(j,effPerLayer[tag_s][10*s+l])
3565 h[
'DTeffPerLayer'].SetMinimum(0.6)
3566 h[
'DTeffPerLayer'].SetMaximum(1.0)
3567 h[
'DTeffPerLayer'].SetStats(0)
3568 ut.bookCanvas(h,
'ct',
'',700,500,1,1)
3569 ut.bookCanvas(h,
'c2',
'',700,500,1,1)
3571 h[
'effLayer'].SetMaximum(1.)
3572 h[
'effLayer'].SetMinimum(0.5)
3573 h[
'effLayer'].SetStats(0)
3574 h[
'effLayer'].SetMarkerStyle(21)
3575 h[
'effLayer'].SetMarkerColor(h[
'effLayer'].GetLineColor())
3576 h[
'effLayer'].GetXaxis().SetLabelSize(0.05)
3577 h[
'effLayer'].GetYaxis().SetLabelSize(0.05)
3578 h[
'effLayer'].Draw()
3579 fitResult = h[
'effLayer'].Fit(
'pol0',
'SQ',
'',0.,24.)
3581 h[
'Efftxt'] = ROOT.TLatex(2,0.60,
'mean efficiency = %5.2F'%(rc.GetParams()[0]))
3583 myPrint(h[
'ct'],
'EffLayerWithRPCTracks')
3586 h[
'leghits']=ROOT.TLegend(0.51,0.41,0.84,0.59)
3589 tag_s = choice[s][0]
3590 ntags = h[
'hits4_'+str(tag_s)].GetBinContent(6)
3591 xHits = h[
'hitsIn'+str(s)+
'_'+str(tag_s)]
3592 inEff = xHits.GetBinContent(1)+xHits.GetBinContent(2)
3593 xx =
'tmphitsIn'+str(s)+
'_'+str(tag_s)
3594 h[xx]=xHits.Clone(xx)
3595 h[xx].Scale(1./ntags)
3597 h[xx].SetLineColor(choice[s][1])
3598 h[xx].SetLineWidth(2)
3599 h[xx].SetMarkerStyle(20)
3601 h[xx].GetXaxis().SetRangeUser(-0.5,5.5)
3602 h[xx].GetXaxis().SetLabelSize(0.05)
3603 h[xx].GetXaxis().SetTitleSize(0.04)
3604 h[xx].GetYaxis().SetLabelSize(0.05)
3605 h[xx].SetTitle(
';number of hits;occurence per track')
3608 else: h[xx].Draw(
'same')
3609 ltext = xHits.GetName().split(
'_')[0].replace(
'hitsIn',
'hits in station ')
3610 rc = h[
'leghits'].AddEntry(h[xx],ltext,
'PL')
3611 print "station %i ineff=%5.2F%%"%(s,inEff/ntags*100.)
3613 for tag_s
in range(1,5):
3614 ntags = h[
'hits4_'+str(tag_s)].GetBinContent(6)
3615 ntracks = h[
'hits4_'+str(tag_s)].GetBinContent(7)
3616 recoEff += ntracks/ntags
3617 print "track eff %i ineff=%5.2F%%"%(tag_s,ntracks/ntags*100.)
3618 print "average track eff = %5.2F%%"%(recoEff/4.*100.)
3619 for x
in [
'upStreamOcc',
'upStreamOccWithTrack',
'upStreamOccWithTrack_mu',
'upStreamOccWithTrack_muX',
'upStreamOccWithTrack_Chi2',
'upStreamOccWithTrack_Chi2mu']:
3621 h[x] = h[x+str(1)].Clone(x)
3622 h[x].Add(h[x+str(2)])
3624 Ntag = h[
'upStreamOcc'].GetEntries()
3625 Ntrack = h[
'upStreamOccWithTrack'].GetEntries()
3626 Nmu = h[
'upStreamOccWithTrack_mu'].GetEntries()
3627 NmuX = h[
'upStreamOccWithTrack_muX'].GetEntries()
3628 NChi2 = h[
'upStreamOccWithTrack_Chi2'].GetEntries()
3629 NChi2mu = h[
'upStreamOccWithTrack_Chi2mu'].GetEntries()
3630 print "====== Ntags=",Ntag
3631 print "average track eff = %5.2F%%"%( (Ntrack*100.)/Ntag)
3632 print "average track mu eff = %5.2F%%"%( (Nmu*100.)/Ntag)
3633 print "average track Chi2 eff = %5.2F%%"%( (NChi2*100.)/Ntag)
3634 print "average track Chi2 mu eff = %5.2F%%"%( (NChi2mu*100.)/Ntag)
3635 print "average chi2 eff on top of = %5.2F%%"%( (NChi2*100.)/Ntrack)
3636 print "average chi2 eff on top of mu = %5.2F%%"%( (NChi2mu*100.)/Nmu)
3638 myPrint(h[
'c2'],
'DTeffHitsPerStation')
3641 path =
"/media/truf/disk2/home/truf/ShipSoft/ship-ubuntu-1710-48/zeroField"
3642 ut.bookHist(h,
'Teff',
'efficiency',100,0.9,1.0)
3644 interestingHistos = []
3645 for k
in range(1,5):
3646 interestingHistos.append(
'upStreamOcc'+str(k))
3647 interestingHistos.append(
'upStreamOccWithTrack'+str(k))
3648 interestingHistos.append(
'upStreamOccWithTrack_mu'+str(k))
3649 interestingHistos.append(
'upStreamOccWithTrack_muX'+str(k))
3650 interestingHistos.append(
'upStreamOccWithTrack_Chi2'+str(k))
3651 interestingHistos.append(
'upStreamOccWithTrack_Chi2mu'+str(k))
3652 for f
in os.listdir(path):
3653 if f.find(
"histos-DTEffSPILLDATA_")==0:
3654 for x
in interestingHistos:
3655 if h.has_key(x): h[x].Reset()
3656 print " now analyzing histo",f
3658 ut.readHists(h,fHisto,interestingHistos)
3660 if h[
'upStreamOccWithTrack_Chi21'].GetEntries()<1:
continue
3661 Ntag = h[
'upStreamOcc1'].GetEntries()
3662 Ntrack = h[
'upStreamOccWithTrack1'].GetEntries()
3663 Nmu = h[
'upStreamOccWithTrack_mu1'].GetEntries()
3664 NmuX = h[
'upStreamOccWithTrack_muX1'].GetEntries()
3665 NChi2 = h[
'upStreamOccWithTrack_Chi21'].GetEntries()
3666 NChi2mu = h[
'upStreamOccWithTrack_Chi2mu1'].GetEntries()
3669 print "====== Ntags=",Ntag
3670 print "average track eff = %5.2F%%"%( (Ntrack*100.)/Ntag)
3671 print "average track mu eff = %5.2F%%"%( (Nmu*100.)/Ntag)
3672 print "average track Chi2 eff = %5.2F%%"%( (NChi2*100.)/Ntag)
3673 print "average track Chi2 mu eff = %5.2F%%"%( (NChi2mu*100.)/Ntag)
3674 print "average chi2 eff on top of = %5.2F%%"%( (NChi2*100.)/Ntrack)
3675 print "average chi2 eff on top of mu = %5.2F%%"%( (NChi2mu*100.)/Nmu)
3676 rc = h[
'Teff'].Fill(float(Ntrack)/Ntag)
3677 goodFiles.append(fHisto)
3679 cmd =
"hadd -f DTEff.root "
3685 if h[
'biasResDist'].GetEntries()==0:
3687 if not MCdata: ut.readHists(h,
'residuals.root')
3689 ut.readHists(h,
'residuals-mbias.root')
3690 ut.readHists(h,
'residuals-charm.root')
3691 print "don't forget to set MCdata = True for MC"
3693 hinweis[0] =
"method 0: use biasResDistX, count entries between -0.5 and 0.5"
3694 hinweis[1] =
"method 1: use biasResDistX, but take signal from single gauss fit"
3695 hinweis[2] =
"method 2: use biasRes, subtract background from fit on number of entries"
3696 hinweis[3] =
"method 3: use biasRes, take signal from double gauss fit"
3698 Ntracks = h[
'biasResTrackMom'].GetEntries()
3699 ut.bookHist(h,
'effLayer',
'efficiency per Layer;continuous layer number',24,-0.5,23.5)
3700 ut.bookHist(h,
'effLayerBinary',
'efficiency per Layer;continuous layer number',24,-0.5,23.5)
3701 if not h.has_key(
'biasResDistX_1_x1'):
3702 for s
in range(1,5):
3703 for view
in [
'_x',
'_u',
'_v']:
3704 if s>2
and view !=
'_x':
continue
3705 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
3706 for l
in range(0,4):
3707 hname =
'biasResDistX_'+str(s)+view+str(l)
3708 h[hname] = h[
'biasResDist_'+str(s)+view+str(l)].ProjectionY().Clone(hname)
3711 print "efficiencies using ",hinweis[method]
3712 for s
in range(1,5):
3713 for view
in [
'_x',
'_u',
'_v']:
3714 if s>2
and view !=
'_x':
continue
3715 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
3717 effStationBinary = 0
3718 for l
in range(0,4):
3719 tc = h[
'biasedResiduals'].cd(j+1)
3720 if method == 0
or method == 1: hname =
'biasResDistX_'+str(s)+view+str(l)
3721 else: hname =
'biasResXL_'+str(s)+view+str(l)+
'_projx'
3724 if method==0
or method==1:
3727 fitResult = h[hname].Fit(
'gaus',
'SQ',
'',xmin,xmax)
3728 rc = fitResult.Get()
3729 fitFunction = h[hname].GetFunction(
'DoubleGauss')
3730 if not fitFunction : fitFunction = myGauss2
3732 print "simple gaus fit failed"
3733 fitFunction.SetParameter(0,h[hname].GetEntries()*h[hname].GetBinWidth(1))
3734 fitFunction.SetParameter(1,0.)
3735 fitFunction.SetParameter(2,0.1)
3736 fitFunction.SetParameter(3,1.)
3737 fitFunction.SetParameter(4,0.)
3738 fitFunction.SetParameter(5,1.)
3740 fitFunction.SetParameter(0,rc.GetParams()[0]*ROOT.TMath.Sqrt(2*ROOT.TMath.Pi())*rc.GetParams()[2])
3741 fitFunction.SetParameter(1,rc.GetParams()[1])
3742 fitFunction.SetParameter(2,rc.GetParams()[2])
3743 fitFunction.SetParameter(3,0.)
3744 fitFunction.SetParameter(4,fitFunction.GetParameter(0)*0.1)
3745 fitFunction.SetParameter(5,fitFunction.GetParameter(2)*10.)
3747 fitFunction.FixParameter(4,0.)
3748 fitFunction.FixParameter(5,1.)
3749 fitResult = h[hname].Fit(fitFunction,
'SQ',
'',xmin,xmax)
3751 rc = fitResult.Get()
3752 if method == 0: estSignal = h[hname].Integral(375,625)
3753 elif method == 1
or method == 3: estSignal = ( abs(rc.GetParams()[0])+abs(rc.GetParams()[4]))/h[hname].GetBinWidth(1)
3755 imin,imax = h[hname].FindBin(xmin),h[hname].FindBin(xmax)
3756 estSignal = h[hname].Integral(imin,imax) - abs(rc.GetParams()[3]) * (imax-imin+1)
3757 bckInterval = float(h[hname].GetNbinsX() - (h[hname].FindBin(4.) - h[hname].FindBin(-4.)) )
3758 backgroundBinary = h[hname].Integral(1,h[hname].FindBin(-4.)) + h[hname].Integral(h[hname].FindBin(4.),h[hname].GetNbinsX())
3759 estSignalBinary = h[hname].GetSumOfWeights() - backgroundBinary/bckInterval*h[hname].GetNbinsX()
3760 effBinary = estSignalBinary/float(2*Ntracks)
3761 effBinaryError = ROOT.TMath.Sqrt(2*Ntracks-estSignalBinary)/float(2*Ntracks)
3762 effStationBinary += effBinary
3763 rc = h[
'effLayerBinary'].SetBinContent(j,effBinary)
3764 rc = h[
'effLayerBinary'].SetBinError(j,effBinaryError)
3765 eff = estSignal/float(Ntracks)
3766 effError = ROOT.TMath.Sqrt(Ntracks-estSignal)/float(Ntracks)
3768 print "eff for %s = %5.2F binary %5.2F"%(hname,eff,effBinary)
3770 print "eff for %s = %5.2F"%(hname,eff)
3771 h[
'effDict'][hname]=eff
3773 rc = h[
'effLayer'].SetBinContent(j,eff)
3774 rc = h[
'effLayer'].SetBinError(j,effError)
3777 print "station, %i %s, average efficiency: %5.3F binary %5.2F"%(s,view,effStation/4.,effStationBinary/4.)
3779 print "station, %i %s, average efficiency: %5.3F"%(s,view,effStation/4.)
3780 for p
in h[
'biasedResiduals'].GetListOfPrimitives(): p.SetLogy(1)
3781 tc1 = ROOT.gROOT.FindObject(
'c1')
3782 tc1.SetWindowSize(1200,800)
3784 h[
'effLayer'].SetMaximum(1.)
3785 h[
'effLayer'].SetMinimum(0.)
3786 h[
'effLayer'].SetStats(0)
3787 h[
'effLayer'].SetMarkerStyle(21)
3788 h[
'effLayer'].SetMarkerColor(h[
'effLayer'].GetLineColor())
3789 h[
'effLayerBinary'].SetStats(0)
3790 fitResult = h[
'effLayer'].Fit(
'pol0',
'SQ',
'',0.,22.)
3792 h[
'Efftxt'] = ROOT.TLatex(2,0.60,
'mean efficiency = %5.2F'%(rc.GetParams()[0]))
3794 txt =
'effEstimate-method'+str(method)
3795 if MCdata: txt =
'MC'+txt
3797 fitResult = h[
'effLayerBinary'].Fit(
'pol0',
'SQ',
'',0.,22.)
3799 h[
'EfftxtBinary'] = ROOT.TLatex(2,0.56,
'mean efficiency (binary) = %5.2F'%(rc.GetParams()[0]))
3800 h[
'EfftxtBinary'].SetTextColor(ROOT.kMagenta)
3801 h[
'effLayerBinary'].SetLineColor(ROOT.kMagenta)
3802 h[
'effLayerBinary'].SetMarkerStyle(8)
3803 h[
'effLayerBinary'].SetMarkerColor(h[
'effLayerBinary'].GetLineColor())
3804 h[
'effLayerBinary'].GetFunction(
'pol0').SetLineColor(h[
'effLayerBinary'].GetLineColor())
3805 h[
'effLayer'].GetFunction(
'pol0').SetLineColor(h[
'effLayer'].GetLineColor())
3806 h[
'effLayer'].GetXaxis().SetLabelSize(0.04)
3807 h[
'effLayer'].GetXaxis().SetTitleSize(0.04)
3808 h[
'effLayer'].GetYaxis().SetLabelSize(0.04)
3809 h[
'effLayer'].Draw()
3810 h[
'effLayer'].SetMinimum(0.5)
3811 h[
'effLayerBinary'].Draw(
'same')
3812 h[
'EfftxtBinary'].Draw()
3817 mult = {
'_x':0,
'_u':0,
'_v':0}
3818 rej = {
'_x':0,
'_u':0,
'_v':0}
3819 if PR==1
and sTree.GetBranch(
"TrackInfos"):
3820 trInfo = sTree.TrackInfos[atrack]
3821 for n
in range(trInfo.N()):
3822 detID = trInfo.detId(n)
3823 hit = ROOT.MufluxSpectrometerHit(detID,0)
3824 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
3825 print "%3i %3i %3i %3i %3s %3i %3i %4.2F %4.2F "%(\
3826 s,v,p,l,view,channelID,tdcId,trInfo.wL(n),trInfo.wR(n))
3827 if trInfo.wL(n)<0.1
and trInfo.wR(n) < 0.1: rej[view]+=1
3830 for p
in atrack.getPointsWithMeasurement():
3831 rawM = p.getRawMeasurement()
3832 info = p.getFitterInfo()
3833 if not info:
continue
3834 detID = rawM.getDetId()
3835 hit = ROOT.MufluxSpectrometerHit(detID,0)
3836 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
3837 coords = rawM.getRawHitCoords()
3838 print "%3i %3i %3i %3i %3s %3i %3i %4.2F %4.2F %5.2F %5.2F %5.2F "%(
3839 s,v,p,l,view,channelID,tdcId,info.getWeights()[0],info.getWeights()[1],coords[0],coords[1],coords[2])
3840 if info.getWeights()[0]<0.1
and info.getWeights()[1] < 0.1: rej[view]+=1
3842 print "views used",mult
3843 print "views rejected",rej
3846 matches={
'good':[],
'bad':[]}
3847 ut.bookHist(h,
'residuals',
'all residuals',100,-1.,1.)
3848 ut.bookHist(h,
'extrapX',
'extrap in X',100,-20.,20.)
3849 ut.bookHist(h,
'extrapY',
'extrap in Y',100,-20.,20.)
3850 ut.bookHist(h,
'fitfail_good',
'fitfailure by channel for good events',700,0.5,700.5)
3851 ut.bookHist(h,
'fitfail_bad',
'fitfailure by channel for bad events',700,0.5,700.5)
3855 for n
in range(nStart,nStart+nEvents):
3856 rc = sTree.GetEvent(n)
3860 if singleTrack
and len(tracks)!=1:
continue
3863 if len(RPCtracks[
'X'])>1
or len(RPCtracks[
'Y'])>1:
print n,len(RPCtracks[
'X']),len(RPCtracks[
'Y'])
3864 if len(RPCtracks[
'X'])!=1
or len(RPCtracks[
'Y'])!=1:
continue
3865 X = RPCtracks[
'X'][0][0]*zRPC1+RPCtracks[
'X'][0][1]
3866 Y = RPCtracks[
'Y'][0][0]*zRPC1+RPCtracks[
'Y'][0][1]
3868 for atrack
in tracks:
3870 st = atrack.getFitStatus()
3871 if not st.isFitConverged():
continue
3874 if abs(pos[0]-X)>5. :
continue
3876 if Debug:
print "event# %i difference in X,Y %5.3F %5.3F "%(n,pos[0]-X,delta)
3877 rc = h[
'extrapX'].Fill(pos[0]-X)
3878 rc = h[
'extrapY'].Fill(delta)
3879 if abs(delta)<10. : matches[
'good'].append(n)
3881 matches[
'bad'].append(n)
3882 print "event# %i difference in X,Y %5.3F %5.3F "%(n,pos[0]-X,delta)
3883 Nmeas = atrack.getNumPointsWithMeasurement()
3884 if Nmeas>2: Npoints = Nmeas
3886 tr = sTree.TrackInfos[track_index]
3888 for kp
in range(Npoints):
3891 p = atrack.getPointsWithMeasurement()[kp]
3892 rawM = p.getRawMeasurement()
3893 detID = rawM.getDetId()
3894 info = p.getFitterInfo()
3896 wL = info.getWeights()[0]
3897 wR = info.getWeights()[1]
3899 detID = tr.detId(kp)
3902 if abs(delta)<10.: k=0
3903 elif abs(pos[1]-Y)>50.: k=1
3905 if wL<0.1
and wR < 0.1:
3907 if not detID
in fitFailures[k]: fitFailures[k][detID]=0
3908 fitFailures[k][detID]+=1
3910 if not detID
in fitSuccess[k]: fitSuccess[k][detID]=0
3911 fitSuccess[k][detID]+=1
3915 for detID
in fitFailures[k]:
3916 test = ROOT.MufluxSpectrometerHit(detID,0)
3917 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(test)
3918 vbot,vtop = strawPositionsBotTop[detID]
3920 if s > 2: x+= (s-2)*200 + 48*(2*l+p)
3922 if view ==
'_u': x+=50
3923 elif view ==
'_v': x+=100
3927 if fitSuccess[k].has_key(detID): r=fitFailures[k][detID]/float(fitSuccess[k][detID]+fitFailures[k][detID])
3928 if k==0: rc=h[
'fitfail_good'].SetBinContent(x,r)
3929 else: rc=h[
'fitfail_bad'].SetBinContent(x,r)
3931 print "Summary: good matches: %i bad matches: %i failure rate %5.2F"%(
3932 len(matches[
'good']),len(matches[
'bad']),len(matches[
'bad'])/float(len(matches[
'bad'])+len(matches[
'good']) ) )
3933 ROOT.gROOT.FindObject(
'c1').cd()
3938 if not h.has_key(
'linearResiduals2dX'):
3940 ut.bookCanvas(h,key=
'linearResiduals2dX',title=
'linear track model, residuals function of X',nx=1600,ny=1200,cx=4,cy=4)
3941 ut.bookCanvas(h,key=
'linearResidualsX',title=
'linear track model, residuals',nx=1600,ny=1200,cx=4,cy=4)
3942 for s
in range(1,5):
3944 for l
in range(0,4):
3945 hname =
'linearRes'+str(s)+view+str(l)
3947 for Nr
in range(sTree.GetEntries()):
3949 if Nr%10000==0:
print "now at event",Nr,
' of ',sTree.GetEntries(),sTree.GetCurrentFile().GetName()
3951 trackCandidates =
findTracks(PR = 3,linearTrackModel =
True)
3953 for s
in range(1,5):
3955 for l
in range(0,4):
3956 hname =
'linearRes'+str(s)+view+str(l)
3957 rc = h[
'linearResiduals2dX'].cd(j)
3958 h[hname].Draw(
'box')
3959 rc = h[
'linearResidualsX'].cd(j)
3960 proj = h[hname].ProjectionX(hname+
'_projx')
3962 print "%s: %7.3F"%(hname, proj.GetMean())
3965 for s
in range(1,5):
3966 h[
'RPCResiduals'].cd(j*2-1)
3967 h[
'RPCResX_'+str(s)+
'1'].Draw(
'colz')
3968 h[
'RPCResiduals'].cd(j*2)
3969 h[
'RPCResX_'+str(s)+
'1'].ProjectionX().Draw()
3977 versions = [
'-repro',
"-0"]
3980 sim10fact = MCStats/(MC10Stats)
3981 charmNorm = {1:MCStats/10.21E9,10:MC10Stats/153.90E9}
3982 beautyNorm = {1:0., 10:0.01218}
3983 sources = {
"":1.,
"Hadronic inelastic":100.,
"Lepton pair":100.,
"Positron annihilation":100.,
3984 "charm":1./charmNorm[10],
"beauty":1./beautyNorm[10],
"Di-muon P8":100.,
"invalid":1.}
3986 interestingHistos = []
3987 for a
in [
'trueMom',
'recoMom',
'momResol',
'curvResol',
'Fitpoints_u1',
'Fitpoints_v2',
'Fitpoints_x1',
'Fitpoints_x2',
'Fitpoints_x3',
'Fitpoints_x4']:
3988 for source
in sources: interestingHistos.append(a+source)
3990 h[v]={
'1GeV':{},
'1GeVCharm':{},
'10GeV':{}}
3991 if v.find(
'repro')<0:
3992 ut.readHists(h[v][
'1GeV'],
'momDistributions-1GeV-mbias'+v+
'.root',interestingHistos)
3993 ut.readHists(h[v][
'1GeVCharm'],
'momDistributions-1GeV-charm'+v+
'.root',interestingHistos)
3994 ut.readHists(h[v][
'10GeV'],
'momDistributions-10GeV-mbias'+v+
'.root',interestingHistos)
3996 ut.readHists(h[v][
'1GeV'],
'sumHistos--simulation1GeV'+v+
'.root',interestingHistos)
3997 ut.readHists(h[v][
'1GeVCharm'],
'sumHistos--simulation1GeV'+v+
'-charm.root',interestingHistos)
3998 ut.readHists(h[v][
'10GeV'],
'sumHistos--simulation10GeV'+v+
'.root',interestingHistos)
3999 for res
in versions:
4000 for a
in [
'trueMom',
'recoMom',
'Fitpoints_u1',
'Fitpoints_v2',
'Fitpoints_x1',
'Fitpoints_x2',
'Fitpoints_x3',
'Fitpoints_x4']:
4001 if a.find(
'Fit')==0
and not withFitPoints:
continue
4002 h[
'MC'+res+a] = h[res][
'1GeV'][a].Clone(
'MC'+res+a)
4003 h[
'MC'+res+a].Add(h[res][
'1GeVCharm'][a],charmNorm[1])
4004 h[
'MC10'+res+a] = h[res][
'10GeV'][a].Clone(
'MC10'+res+a)
4006 h[
'MC10'+res+a].Add(h[res][
'10GeV'][a+
"charm"],-1.+charmNorm[10])
4007 h[
'MC10'+res+a].Add(h[res][
'10GeV'][a+
"beauty"],-1.+beautyNorm[10])
4008 h[
'MC10'+res+a].Scale(sim10fact)
4010 h[
"momResol"+res] = h[res][
'1GeV'][
"momResol"].Clone()
4011 h[
"momResol"+res].Add(h[res][
'1GeVCharm'][
"momResol"])
4012 h[
"momResol"+res].Add(h[res][
'10GeV'][
"momResol"])
4014 for a
in [
'trueMom',
'recoMom']:
4015 h[res+a]=h[
"MC10"+res+a].Clone()
4016 for n
in range(h[a].GetNbinsX()):
4017 if h[res+a].GetBinCenter(n)<20. :
4018 h[res+a].SetBinContent(n,h[
"MC"+res+a].GetBinContent(n))
4019 h[res+
'trueMom'].SetLineColor(ROOT.kGreen)
4020 ut.makeIntegralDistrib(h,res+
'trueMom')
4021 ut.makeIntegralDistrib(h,res+
'recoMom')
4022 h[
'I-'+res+
'trueMom'].SetTitle(
' ;x [GeV/c]; #SigmaN/PoT with P>x')
4023 h[
'I-'+res+
'trueMom'].Scale(1./MCStats)
4024 h[
'I-'+res+
'recoMom'].Scale(1./MCStats)
4025 h[
'I-'+res+
'trueMom'].SetMinimum(5E-11)
4026 h[
'I-'+res+
'trueMom'].SetStats(0)
4027 h[
'I-'+res+
'trueMom'].GetXaxis().SetRangeUser(5.,500.)
4030 if not h.has_key(t): ut.bookCanvas(h,t,
'true and reco momentum',900,600,1,1)
4035 h[
'I--0trueMom'].Draw()
4036 h[
'I--0recoMom'].Draw(
'same')
4037 h[
'I-'+v+
'recoMom'].SetLineColor(ROOT.kMagenta)
4038 h[
'I-'+v+
'recoMom'].Draw(
'same')
4039 h[
'leg'+t]=ROOT.TLegend(0.31,0.67,0.85,0.85)
4040 h[
'leg'+t].AddEntry(h[
'I--0trueMom'],
'true momentum ',
'PL')
4041 h[
'leg'+t].AddEntry(h[
'I--0recoMom'],
'reconstructed momentum 270#mum',
'PL')
4042 h[
'leg'+t].AddEntry(h[
'I-'+v+
'recoMom'],
'reconstructed momentum 350#mum',
'PL')
4046 fSqrt = ROOT.TF1(
'momResol',
'sqrt([0]**2+x**2*[1]**2)',2)
4047 fSqrt.SetParName(0,
'constant')
4048 fSqrt.SetParName(1,
'linear')
4050 if not h.has_key(t): ut.bookCanvas(h,t,
'momentum Resolution',900,600,1,1)
4052 for res
in [
'-0',v]:
4053 hname =
'momResol'+res
4054 h[hname+
'P'] = h[hname].ProjectionY(hname+
'P')
4055 h[hname+
'P'].Reset()
4056 h[hname+
'Perr']=h[hname+
'P'].Clone(hname+
'Perr')
4057 for n
in range(1,h[hname+
'P'].GetNbinsX()+1):
4058 h[hname+str(n)] = h[hname].ProjectionX(hname+str(n),n,n)
4059 if h[hname+str(n)].GetEntries()<50:
continue
4060 if n>10: h[hname+str(n)].Rebin(5)
4061 fitFunction = h[hname+str(n)].GetFunction(
'gauss')
4062 if not fitFunction: fitFunction = myGauss
4063 fitFunction.SetParameter(0,h[hname+str(n)].GetMaximum()*0.02)
4064 fitFunction.SetParameter(1,0.)
4065 fitFunction.SetParameter(2,0.01)
4066 fitFunction.FixParameter(3,0.)
4067 fitResult = h[hname+str(n)].Fit(fitFunction,
'SQ',
'',-1.,1.)
4068 rc = fitResult.Get()
4070 mean = rc.GetParams()[1]
4071 rms = rc.GetParams()[2]
4073 h[hname+
'Perr'].SetBinContent(n,mean)
4074 h[hname+
'Perr'].SetBinError(n,abs(rms))
4075 h[hname+
'P'].SetBinContent(n,abs(rms))
4076 h[hname+
'P'].Fit(
'pol1',
'QW',
'',0.,300.)
4077 fitFun = h[hname+
'P'].GetFunction(
'pol1')
4078 fSqrt.SetParameter(0,fitFun.GetParameter(0))
4079 fSqrt.SetParameter(1,fitFun.GetParameter(1))
4080 h[hname+
'P'].Fit(fSqrt,
'QW',
'',0.,300.)
4081 h[
'leg'+t]=ROOT.TLegend(0.14,0.75,0.64,0.87)
4082 for res
in [
'-0',v]:
4083 hname =
'momResol'+res
4084 h[hname+
'P'].SetTitle(
'momentum resolution function of momentum;#it{p} [GeV/c];#sigma_{#it{p}} / #it{p}')
4085 h[hname+
'P'].SetStats(0)
4086 h[hname+
'P'].SetMaximum(0.15)
4087 fSqrt = h[hname+
'P'].GetFunction(
'momResol')
4088 p0 =
"%4.3F"%(100*fSqrt.GetParameter(0))
4089 p1 =
"%4.3F"%(100*fSqrt.GetParameter(1))
4091 h[
'text'+res] = ROOT.TLatex(21.,0.073,
'#sigma_{#it{p}}/#it{p} = ('+p0+
' #oplus '+p1+
'#times#it{p})%')
4092 h[hname+
'P'].Draw(
'same')
4093 h[hname+
'P'].SetLineColor(ROOT.kMagenta)
4094 h[
'text'+res].SetTextColor(ROOT.kMagenta)
4095 h[
'leg'+t].AddEntry(h[hname+
'P'],
'adjusted 350#mum',
'PL')
4097 h[
'text'+res] = ROOT.TLatex(120.,0.01,
'#sigma_{#it{p}}/#it{p} = ('+p0+
' #oplus '+p1+
'#times#it{p})%')
4098 h[
'text'+res].SetTextColor(ROOT.kBlue)
4099 h[hname+
'P'].GetXaxis().SetRangeUser(0.,330)
4100 h[hname+
'P'].SetMaximum(max(h[hname+
'P'].GetMaximum(),h[
'momResol-0P'].GetMaximum()))
4102 h[
'leg'+t].AddEntry(h[hname+
'P'],
'default 270#mum ',
'PL')
4103 h[
'text'+res].Draw(
'same')
4105 myPrint(h[t],
'momentumResolution')
4108 ut.bookHist(h,
'hitResol',
'hit resolution',100,-0.5,0.5)
4109 for n
in range(sTree.GetEntries()):
4110 rc = sTree.GetEvent(n)
4111 for k
in range(sTree.Digi_MufluxSpectrometerHits.GetEntries()):
4112 hit = sTree.Digi_MufluxSpectrometerHits[k]
4113 trueHit = sTree.MufluxSpectrometerPoint[k]
4114 hit.MufluxSpectrometerEndPoints(vbot,vtop)
4115 TDC = hit.GetDigi() - (vtop[0]-trueHit.GetX())/(ROOT.TMath.C() *100./1000000000.0)
4116 distance =
RT(
'x',TDC)
4117 h[
'hitResol'].Fill(distance - trueHit.dist2Wire())
4120 for n
in range(sTree.GetEntries()):
4121 rc = sTree.GetEvent(n)
4122 for aTrack
in sTree.FitTracks:
4123 st = aTrack.getFitStatus()
4124 if not st.isFitConverged():
continue
4125 if not aTrack.getNumPointsWithMeasurement()>0:
continue
4126 sta = aTrack.getFittedState(0)
4127 if sta.getMomMag() < 5.:
continue
4131 if pos[0]>cuts[
'xLRPC1']
and pos[0]<cuts[
'xRRPC1']
and pos[1]>cuts[
'yBRPC1']
and pos[1]<cuts[
'yTRPC1']:
4133 print "number of tracks ",Ntracks,
" in acceptance ",inAcc,
"=",
"%F5.2"%(inAcc/float(Ntracks)*100),
"%"
4136 matchedHits={1:{0:[],1:[]},2:{0:[],1:[]},3:{0:[],1:[]},4:{0:[],1:[]},5:{0:[],1:[]}}
4141 if pos[0]>cuts[
'xLRPC1']
and pos[0]<cuts[
'xRRPC1']
and pos[1]>cuts[
'yBRPC1']
and pos[1]<cuts[
'yTRPC1']:
4143 for hit
in sTree.Digi_MuonTaggerHits:
4144 if hit.GetDetectorID()
in deadChannelsRPC4MC:
continue
4145 channelID = hit.GetDetectorID()
4147 v = (channelID-10000*s)/1000
4148 vtop,vbot = RPCPositionsBotTop[channelID]
4149 z = (vtop[2]+vbot[2])/2.
4152 error =
"RPCextrap: plotRPCExtrap failed"
4153 ut.reportError(error)
4154 if Debug:
print error
4157 Y = (vtop[1]+vbot[1])/2.
4160 X = (vtop[0]+vbot[0])/2.
4162 if abs(res)<maxDistance:
4163 matchedHits[s][v].append(hit)
4164 for s
in matchedHits:
4165 for v
in matchedHits[s]:
4166 Nmatched+= len(matchedHits[s][v])
4167 return inAcc,Nmatched
4170 vtop = ROOT.TVector3()
4171 vbot = ROOT.TVector3()
4172 for s
in range(1,6):
4174 ut.bookHist(h,
'RPC'+str(s)+str(v),
'hit resolution',100,-10.,10.)
4175 for n
in range(sTree.GetEntries()):
4176 rc = sTree.GetEvent(n)
4179 for m
in sTree.MuonTaggerPoint:
4181 if not track.has_key(t): track[t]=[]
4182 track[t].append([m.GetDetectorID(),m.GetX(),m.GetY()])
4183 if len(track)!=1:
continue
4187 truex,truey = d[1],d[2]
4188 for hit
in sTree.Digi_MuonTaggerHits:
4189 channelID = hit.GetDetectorID()
4191 v = (channelID-10000*s)/1000
4192 vtop,vbot = RPCPositionsBotTop[channelID]
4194 if v==0: delpos = (vtop[1]+vbot[1])/2. - truey
4195 if v==1: delpos = (vtop[0]+vbot[0])/2. - truex
4196 h[
'RPC'+str(s)+str(v)].Fill(delpos)
4199 if not onlyPlotting:
4200 eventRange = [0,sTree.GetEntries()]
4201 if not nEvent<0: eventRange = [nEvent,nEvent+nTot]
4202 for s
in range(1,6):
4206 ut.bookHist(h,
'RPCResX_'+str(s)+str(v),
'RPC residual for '+str(s)+
' '+ str(v),100,-dx,dx,20,-140.,140.)
4207 ut.bookHist(h,
'RPCResY_'+str(s)+str(v),
'RPC residual for '+str(s)+
' '+ str(v),100,-dx,dx,20,-140.,140.)
4208 ut.bookHist(h,
'RPCextTrack_'+str(s)+str(v),
'mom of tracks extr to RPC k with RPC k+1 matched',100,0.,100.,100,-140.,140.)
4209 ut.bookHist(h,
'RPCfired_'+str(s)+str(v),
'mom of tracks extr to RPC k and matched with RPC k+1 matched',100,0.,100.)
4210 ut.bookHist(h,
'RPCfired_or_'+str(s),
'mom of tracks extr to RPC k and matched with RPC k+1 or of 0 and 1',100,0.,100.)
4211 ut.bookHist(h,
'RPCResX'+str(s)+
'_p',
'RPC residual for station '+str(s)+
' as function of track momentum',100,-dx,dx,100,0.,100.)
4212 ut.bookHist(h,
'RPCMatchedHits',
'matched RPC hits as function of track momentum',10,0.5,10.5,20,-0.5,19.5,100,0.,100.)
4213 ut.bookHist(h,
'RPCMeanMatchedHits',
'mean matched RPC hits as function of track momentum',100,0.,100.)
4214 ut.bookHist(h,
'RPC>1',
'fraction of tracks with > 1 RPC hits',100,0.,100.)
4215 ut.bookHist(h,
'RPC<2XY',
'position of tracks with < 2 RPC hits and p>30GeV',50,-100.,100.,50,-100.,100.)
4216 ut.bookHist(h,
'RPC_p',
'momentum of tracks pointing to RPC',100,0.,100.)
4217 for k
in range(2,20):
4218 ut.bookHist(h,
'RPC<'+str(k)+
'_p',
' < '+str(k)+
' RPC hits p',100,0.,100.)
4220 muflux_Reco.RPCextrap()
4222 for Nr
in range(eventRange[0],eventRange[1]):
4224 if Nr%10000==0:
print "now at event",Nr,
' of ',sTree.GetEntries(),sTree.GetCurrentFile().GetName(),time.ctime()
4225 if not sTree.Digi_MuonTaggerHits.GetEntries()>0:
continue
4229 for aTrack
in trackCandidates:
4230 matchedHits={1:{0:[],1:[]},2:{0:[],1:[]},3:{0:[],1:[]},4:{0:[],1:[]},5:{0:[],1:[]}}
4232 st = aTrack.getFitStatus()
4233 if not st.isFitConverged():
continue
4234 if not aTrack.getNumPointsWithMeasurement()>0:
continue
4235 sta = aTrack.getFittedState(0)
4236 if sta.getMomMag() < 1.:
continue
4241 if pos1[0]>cuts[
'xLRPC1']
and pos1[0]<cuts[
'xRRPC1']
and pos1[1]>cuts[
'yBRPC1']
and pos1[1]<cuts[
'yTRPC1']:
4243 for hit
in sTree.Digi_MuonTaggerHits:
4244 if hit.GetDetectorID()
in deadChannelsRPC4MC:
continue
4246 channelID = hit.GetDetectorID()
4248 v = (channelID-10000*s)/1000
4250 layer = channelID/1000
4251 rc = h[
'rpcHitmap'].Fill(layer)
4252 channel = channelID%1000
4253 rc = h[
'rpcHitmap'+str(layer)].Fill(channel)
4254 vtop,vbot = RPCPositionsBotTop[channelID]
4255 z = (vtop[2]+vbot[2])/2.
4258 error =
"RPCextrap: plotRPCExtrap failed"
4259 ut.reportError(error)
4260 if Debug:
print error
4266 Y = (vtop[1]+vbot[1])/2.
4268 h[
'RPCResY_'+str(s)+str(v)].Fill(res,Y)
4269 trackPos[s*10+v]=pos[1]
4271 X = (vtop[0]+vbot[0])/2.
4273 h[
'RPCResX_'+str(s)+str(v)].Fill(res,X)
4274 h[
'RPCResX'+str(s)+
'_p'].Fill(res,sta.getMomMag())
4275 trackPos[s*10+v]=pos[0]
4276 if abs(res)<cuts[
"RPCmaxDistance"]:
4277 matchedHits[s][v].append(nHit)
4283 p = min(99.9,sta.getMomMag())
4287 for k
in range(1,5):
4288 if len(matchedHits[k+1][0])==0
or len(matchedHits[k+1][1])==0:
continue
4289 rc = h[
'RPCextTrack_'+str(k)+str(v)].Fill(p,trackPos[(k+1)*10+v])
4290 if p<8
and abs(trackPos[(k+1)*10+v]) <1:
print Nr
4291 for v
in range(0,2):
4292 if len(matchedHits[k][v])>0: rc = h[
'RPCfired_'+str(k)+str(v)].Fill(p)
4294 if len(matchedHits[k][v])>0
or len(matchedHits[k][v+1])>0: rc = h[
'RPCfired_or_'+str(k)].Fill(p)
4295 for s
in matchedHits:
4296 for v
in matchedHits[s]:
4297 rc = h[
'RPCMatchedHits'].Fill(2*s-1+v,len(matchedHits[s][v]),p)
4298 Nmatched+=len(matchedHits[s][v])
4299 if Nmatched <2
and p>30: rc = h[
'RPC<2XY'].Fill(pos1[0],pos1[1])
4300 rc = h[
'RPC_p'].Fill(p)
4301 for k
in range(2,20):
4302 if Nmatched<k: rc = h[
'RPC<'+str(k)+
'_p'].Fill(p)
4303 if not h.has_key(
'RPCResiduals'):
4304 ut.bookCanvas(h,key=
'RPCResiduals',title=
'RPCResiduals',nx=1600,ny=1200,cx=2,cy=5)
4305 ut.bookCanvas(h,key=
'RPCResidualsXY',title=
'RPCResiduals function of Y/X',nx=1600,ny=1200,cx=2,cy=5)
4306 ut.bookCanvas(h,key=
'RPCResidualsP',title=
'RPCResiduals function of muon momentum',nx=900,ny=900,cx=1,cy=1)
4310 for s
in range(1,6):
4311 for v
in range(0,2):
4313 hname =
'RPCResX_'+str(s)+str(v)
4317 hname =
'RPCResY_'+str(s)+str(v)
4320 hnameProjX =
'RPCRes_'+str(s)+str(v)
4321 if h[hname].GetEntries()==0:
continue
4322 h[hnameProjX] = h[hname].ProjectionX()
4323 h[hnameProjX].GetXaxis().SetTitle(
'#Delta [cm]')
4324 myGauss.SetParameter(0,h[hnameProjX].GetMaximum())
4325 myGauss.SetParameter(1,0.)
4326 myGauss.SetParameter(2,4.)
4327 myGauss.SetParameter(3,1.)
4328 rc = h[
'RPCResiduals'].cd(jk)
4329 if v==0: fitResult = h[hnameProjX].Fit(myGauss,
'SQ',
'',-40.,40.)
4330 else: fitResult = h[hnameProjX].Fit(myGauss,
'SQ',
'',-10.,10.)
4331 rc = fitResult.Get()
4333 myGauss2.SetParameter(0,rc.GetParams()[0])
4334 myGauss2.SetParameter(1,rc.GetParams()[1])
4335 myGauss2.SetParameter(2,abs(rc.GetParams()[2]))
4336 myGauss2.SetParameter(3,rc.GetParams()[3])
4337 myGauss2.SetParameter(4,0.)
4338 myGauss2.SetParameter(5,10.)
4339 if v==0: fitResult = h[hnameProjX].Fit(myGauss2,
'SQ',
'',-40.,40.)
4340 else: fitResult = h[hnameProjX].Fit(myGauss2,
'SQ',
'',-10.,10.)
4341 rc = fitResult.Get()
4342 if rc.GetParams()[3]<0: myGauss2.SetParameter(3,abs(rc.GetParams()[3]))
4343 if v==0: fitResult = h[hnameProjX].Fit(myGauss2,
'SQ',
'',-40.,40.)
4344 else: fitResult = h[hnameProjX].Fit(myGauss2,
'SQ',
'',-10.,10.)
4345 rc = fitResult.Get()
4346 mean = rc.GetParams()[1]
4347 rms1 = rc.GetParams()[2]
4348 rms2 = rc.GetParams()[5]
4349 N1 = rc.GetParams()[0]
4350 N2 = rc.GetParams()[4]
4351 avRMS = (rms1*N1+rms2*N2)/(N1+N2)
4352 print "%i, %i, mean=%5.2F RMS=%5.2F"%(s,v,mean,avRMS)
4353 t =
"#sigma_{av}=%5.2Fcm"%(avRMS)
4354 rc = T.DrawLatexNDC(0.13,0.7,t)
4356 rc = h[
'RPCResidualsXY'].cd(jk)
4357 hname =
'RPCRes'+p+
'_'+str(s)+str(v)
4358 hmean = hname+
'_mean'+p
4359 h[hmean] = h[hname].ProjectionY(hname+
'_mean')
4361 for k
in range(1,h[hname].GetNbinsY()+1):
4362 sli = hname+
'_'+str(k)
4363 h[sli] = h[hname].ProjectionX(sli,k,k)
4364 if h[sli].GetEntries()<10:
continue
4365 myGauss.SetParameter(0,h[sli].GetMaximum())
4366 myGauss.SetParameter(1,0.)
4367 myGauss.SetParameter(2,4.)
4368 myGauss.SetParameter(3,1.)
4369 if v==0: fitResult = h[sli].Fit(myGauss,
'SQ',
'',-40.,40.)
4370 else: fitResult = h[sli].Fit(myGauss,
'SQ',
'',-10.,10.)
4371 rc = fitResult.Get()
4373 params = rc.GetParams()
4374 if not params:
continue
4375 mean = rc.GetParams()[1]
4376 rms = abs(rc.GetParams()[2])
4377 rc = h[hmean].SetBinContent(k,mean)
4378 rc = h[hmean].SetBinError(k,rms)
4381 if not h.has_key(
'RPCResiduals2dXY'):
4382 ut.bookCanvas(h,key=
'RPCResiduals2dXY',title=
'muon tagger Residuals function of X/Y',nx=1600,ny=1200,cx=2,cy=5)
4384 for s
in range(1,6):
4385 for v
in range(0,2):
4392 rc = h[
'RPCResiduals2dXY'].cd(jk)
4393 hname =
'RPCRes'+p+
'_'+str(s)+str(v)
4394 h[hname].Draw(
'box')
4396 h[
'RPCResidualsP'].cd(1)
4397 h[
'RPCResX1_p'].Draw(
'colz')
4399 zax = h[
'RPCMatchedHits'].GetZaxis()
4400 xax = h[
'RPCMatchedHits'].GetXaxis()
4401 yax = h[
'RPCMatchedHits'].GetYaxis()
4402 for ip
in range(1,zax.GetNbins()+1):
4406 for ks
in range(1,xax.GetNbins()+1):
4407 Ntracks1=h[
'RPCMatchedHits'].GetBinContent(ks,1,ip)+h[
'RPCMatchedHits'].GetBinContent(ks,2,ip)
4408 for n
in range(1,yax.GetNbins()+1):
4409 Nmean += h[
'RPCMatchedHits'].GetBinContent(ks,n,ip)*yax.GetBinCenter(n)
4410 Nentries+=h[
'RPCMatchedHits'].GetBinContent(ks,n,ip)
4411 Nmean = Nmean / float(Nentries+1E-10)
4412 rc = h[
'RPCMeanMatchedHits'].SetBinContent(ip,Nmean)
4413 fraction = (Nentries-Ntracks1)/(Nentries+1E-10)
4414 rc = h[
'RPC>1'].SetBinContent(ip,fraction)
4415 for k
in range(2,20):
4416 h[
'RPCeff_'+str(k)]=h[
'RPC<'+str(k)+
'_p'].Clone(
'RPCeff_'+str(k))
4417 h[
'RPCeff_'+str(k)].Divide(h[
'RPC_p'])
4418 ut.bookCanvas(h,key=
'RPCEff',title=
'RPC efficiencies',nx=1600,ny=1200,cx=3,cy=4)
4419 const = ROOT.TF1(
'const',
'pol0',10,100)
4422 for s
in range(1,5):
4425 hname =
'RPCfired_or_'+str(s)
4426 h[
'Eff'+hname]=ROOT.TEfficiency(h[hname],h[
'RPCextTrack_'+str(s)+str(0)+
'_projx'])
4428 hname =
'RPCfired_'+str(s)+str(v)
4429 h[
'Eff'+hname]=ROOT.TEfficiency(h[hname],h[
'RPCextTrack_'+str(s)+str(v)+
'_projx'])
4430 pad = h[
'RPCEff'].cd(l)
4432 rc = h[
'Eff'+hname].Fit(const)
4433 h[
'Eff'+hname].Draw(
'AP')
4435 graph = h[
'Eff'+hname].GetPaintedGraph()
4436 graph.SetMinimum(0.9)
4437 graph.SetMaximum(1.01)
4439 fun = h[
'Eff'+hname].GetListOfFunctions()[0]
4440 eff = fun.GetParameter(0)
4441 err = fun.GetParError(0)
4443 rc = T.DrawLatexNDC(0.3,0.2,
'eff = (%5.2F\pm%5.2F)%s'%(eff*100,err*100,
'%'))
4444 txt =
"station "+str(s)+
" X"
4445 if v==0: txt =
"station "+str(s)+
" Y"
4446 if v==2: txt =
"station "+str(s)+
" X or Y"
4448 rc = T.DrawLatexNDC(0.2,0.8,txt)
4449 myPrint(h[
'RPCEff'],
"rpchiteff")
4450 h[
'RPCResiduals'].Draw()
4451 for x
in h[
'RPCResiduals'].GetListOfPrimitives():
4452 for xx
in x.GetListOfPrimitives():
4453 if xx.ClassName()==
'TH1D':
4454 stats = xx.GetListOfFunctions().FindObject(
"stats")
4455 stats.SetOptStat(1000000001)
4456 stats.SetOptFit(10001)
4457 stats.SetX1NDC(0.70)
4458 stats.SetY1NDC(0.23)
4459 stats.SetX2NDC(0.97)
4460 stats.SetY2NDC(0.94)
4461 h[
'RPCResiduals'].Update()
4462 myPrint(h[
'RPCResiduals'],
'RPCResiduals')
4463 print "do not forget there were runs without one RPC station"
4466 ut.bookHist(h,
'RPCstrips',
'RPC strips',1000,-100.,100.,1000,-100.,100.)
4467 h[
'RPCstrips'].Draw()
4470 for c
in range(1,185):
4471 if v==0
and c>105:
continue
4472 if v==1
and c<12:
continue
4474 h[
'RPCstrip'+str(v)+str(c)]=ROOT.TGraph()
4475 detID = s*10000+v*1000+c
4476 vbot,vtop = RPCPositionsBotTop[detID]
4477 h[
'RPCstrip'+str(v)+str(c)].SetPoint(0,vtop[0],vtop[1])
4478 h[
'RPCstrip'+str(v)+str(c)].SetPoint(1,vbot[0],vbot[1])
4479 if v == 0: h[
'RPCstrip'+str(v)+str(c)].SetLineColor(ROOT.kRed)
4480 if v == 1: h[
'RPCstrip'+str(v)+str(c)].SetLineColor(ROOT.kBlue)
4481 h[
'RPCstrip'+str(v)+str(c)].Draw(
'same')
4483 ut.bookHist(h,
'y1y2',
'y1 vs y2 of RPC',100,-100.,100.,100,-100.,100.)
4484 for n
in range(10000):
4485 rc = sTree.GetEvent(n)
4487 for hit
in sTree.Digi_MuonTaggerHits:
4488 channelID = hit.GetDetectorID()
4490 v = (channelID-10000*s)/1000
4492 vbot,vtop = RPCPositionsBotTop[channelID]
4493 y1 = (vtop[1]+vbot[1])/2.
4494 for hit
in sTree.Digi_MuonTaggerHits:
4495 channelID = hit.GetDetectorID()
4497 v = (channelID-10000*s)/1000
4499 vbot,vtop = RPCPositionsBotTop[channelID]
4500 y2 = (vtop[1]+vbot[1])/2.
4501 rc = h[
'y1y2'].Fill(y1,y2)
4504for p
in range(32): alignCorrection[p]=[0,0,0]
4505slopeX = {3:[0,0,0,0],
4507slopeY = {2:[0,0,0,0]}
4511if MCdata: withCorrections=
False
4513 alignCorrectionTMP = (conditionsDB.get_condition_by_name_and_tag(
"muflux/driftTubes",
"alignCorrection",
"muflux/driftTubes_align_2020-03-23"))[
"values"]
4516 for i
in range (0, len(alignCorrectionTMP)):
4517 alignCorrection[i] = alignCorrectionTMP[str(i)]
4519 slopeX = {2:[-0.001,-0.001,-0.001,-0.001],
4520 3:[-0.0048,-0.0048,-0.0048,-0.0048]}
4521 slopeY = {2:[0.0065,0.0065,0.0065,0.0065]}
4523strawPositionsBotTop={}
4525 for detID
in alignConstants[
'strawPositions']:
4526 b = alignConstants[
'strawPositions'][detID][
'bot']
4527 t = alignConstants[
'strawPositions'][detID][
'top']
4528 strawPositionsBotTop[detID]=[ROOT.TVector3(b[0],b[1],b[2]),ROOT.TVector3(t[0],t[1],t[2])]
4529 muflux_Reco.setDTPositions(int(detID),t[0],t[1],t[2],b[0],b[1],b[2])
4531RPCPositionsBotTop = {}
4533 for s
in range(1,6):
4535 for c
in range(1,185):
4536 if v==0
and c>116:
continue
4537 detID = s*10000+v*1000+c
4538 hit = ROOT.MuonTaggerHit(detID,0)
4540 RPCPositionsBotTop[detID] = [a.Clone(),b.Clone()]
4544 muflux_Reco.setRPCPositions(detID,x,y,z)
4547 detID = hit.GetDetectorID()
4548 vbot,vtop = ROOT.TVector3(), ROOT.TVector3()
4549 rc = hit.MufluxSpectrometerEndPoints(vbot,vtop)
4550 if withDefaultAlignment
and not withCorrections:
return vbot,vtop
4551 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(hit)
4552 if withDefaultAlignment
and withCorrections:
4554 if s==1
and view==
'_u': x+=4
4555 if s==2
and view==
'_v': x+=8
4556 if s==2
and view==
'_x': x+=12
4564 vbot[i] = vbot[i]+alignCorrection[x][i]
4565 vtop[i] = vtop[i]+alignCorrection[x][i]
4572 vtop[0]=xposb[detID]
4573 vtop[1]=yposb[detID]
4580 if s==1
and view==
'_u': x = pl+4
4581 if s==2
and view==
'_v': x = pl+8
4582 if s==2
and view==
'_x': x = pl+12
4590 vbot[0] += slopeX[s][pl]*vbot[0]
4591 vtop[0] += slopeX[s][pl]*vtop[0]
4593 vbot[0] += (slopeY[s][pl]*vbot[1] + slopeX[s][pl]*vbot[0])
4594 vtop[0] += (slopeY[s][pl]*vtop[1] + slopeX[s][pl]*vtop[0])
4596 vbot[i] = vbot[i]+alignCorrection[x][i]
4597 vtop[i] = vtop[i]+alignCorrection[x][i]
4602 w = os.fdopen(w,
'w')
4604 for Nr
in listOfTracks:
4605 rc=sTree.GetEvent(Nr)
4606 hitlist = listOfTracks[Nr]
4608 if type(aTrack) != type(1):
4609 fitStatus = aTrack.getFitStatus()
4610 chisq+=fitStatus.getChi2()/fitStatus.getNdf()
4612 chisq = chisq/len(listOfTracks)
4613 print "chisq=",chisq
4618def FCN(npar, gin, f, par, iflag):
4622 alignCorrection[p]=[par[p],0,0]
4628 print(
"In the parent process after forking the child {}".format(pid))
4629 finished = os.waitpid(0, 0)
4633 f[0] = float(r.read())
4634 print "FCN returns",f[0],len(listOfTracks)
4635 print "T1x",par[0],par[1],par[2],par[3]
4636 print "T1u",par[4],par[5],par[6],par[7]
4637 print "T2v",par[8],par[9],par[10],par[11]
4638 print "T2x",par[12],par[13],par[14],par[15]
4644 for Nr
in range(50000):
4645 rc = sTree.GetEvent(Nr)
4647 track_hits =
testPR(onlyHits=
True)
4648 if len(track_hits)!=1:
continue
4649 listOfTracks[Nr]= []
4650 for nhit
in track_hits[0]: listOfTracks[Nr].append(nhit)
4652 ierflg = ROOT.Long(0)
4653 gMinuit = ROOT.TMinuit(npar)
4655 gMinuit.SetErrorDef(0.5)
4656 vstart = array(
'd',[0]*npar)
4658 vstart[p] = alignCorrection[p][0]
4660 for s
in [
'T1_x',
'T1_u',
'T2_v',
'T2_x',
'T3_x',
'T4_x']:
4662 gMinuit.mnparm(p, s+str(l), vstart[p], 0.5, 0.,0.,ierflg)
4664 for p
in range(4,24):gMinuit.FixParameter(p)
4665 strat = array(
'd',[0])
4666 gMinuit.mnexcm(
"SET STR",strat,1,ierflg)
4667 gMinuit.mnexcm(
"SIMPLEX",vstart,npar,ierflg)
4668 gMinuit.mnexcm(
"MIGRAD",vstart,npar,ierflg)
4671 test = ROOT.MufluxSpectrometerHit(10002012,0)
4672 test.MufluxSpectrometerEndPoints(vbot,vtop)
4673 print vtop[1],vbot[1]
4674 test = ROOT.MufluxSpectrometerHit(11002012,0)
4675 test.MufluxSpectrometerEndPoints(vbot,vtop)
4676 m = (vtop[1]-vbot[1])/((vtop[0]-vbot[0]))
4677 b = vtop[1] - m*vtop[0]
4679 print vtop[1],vbot[1]
4680 statnb,vnb,pnb,lnb,view,channelID,tdcId,nRT =
stationInfo(test)
4681 nav = ROOT.gGeoManager.GetCurrentNavigator()
4682 prefix =
"Station_"+str(statnb)+str(view)+
"_plane_"+str(pnb)+
"_"
4683 plane = prefix+str(statnb)+str(vnb)+str(pnb)+
"00000"
4684 layer = prefix+
"layer_"+str(lnb)+
"_"+str(statnb)+str(vnb)+str(pnb)+str(lnb)+
"0000"
4685 wire =
"gas_"+str(test.GetDetectorID())
4686 if statnb<3: wire =
"gas_12_"+str(test.GetDetectorID())
4687 stat =
"volDriftTube"+str(statnb)+
"_"+str(statnb)
4688 path =
"/"+stat+
"/"+plane+
"/"+layer+
"/"+wire
4690 W = nav.GetCurrentNode()
4691 S = W.GetVolume().GetShape()
4692 top = array(
'd',[0,0,S.GetDZ()])
4693 bot = array(
'd',[0,0,-S.GetDZ()])
4694 Gtop = array(
'd',[0,0,0])
4695 Gbot = array(
'd',[0,0,0])
4696 nav.LocalToMaster(top, Gtop)
4697 nav.LocalToMaster(bot, Gbot)
4699 o = [S.GetOrigin()[0],S.GetOrigin()[1],S.GetOrigin()[2]]
4700 local = array(
'd',o)
4701 globOrigin = array(
'd',[0,0,0])
4702 nav.LocalToMaster(local,globOrigin)
4708 global exclude_layer
4711 for s
in [
'1_x',
'1_u',
'2_x',
'2_u',
'3_x',
'4_x']:
4712 name =
'biasResX_'+s+str(2*p+l)
4713 h[
'un'+name] = h[name].Clone(
'un'+name)
4714 name =
'biasResY_'+s+str(2*p+l)
4715 h[
'un'+name] = h[name].Clone(
'un'+name)
4716 exclude_layer =
None
4717 if not h.has_key(
'unbiasedResiduals'):
4718 ut.bookCanvas(h,key=
'unbiasedResiduals',title=
'unbiasedResiduals',nx=1600,ny=1200,cx=4,cy=6)
4719 ut.bookCanvas(h,key=
'unbiasedResidualsX',title=
'unbiasedResiduals function of X',nx=1600,ny=1200,cx=4,cy=6)
4720 ut.bookCanvas(h,key=
'unbiasedResidualsY',title=
'unbiasedResiduals function of Y',nx=1600,ny=1200,cx=4,cy=6)
4722 for s
in range(1,5):
4723 for view
in [
'_x',
'_u',
'_v']:
4724 if s>2
and view !=
'_x':
continue
4725 if s==1
and view ==
'_v' or s==2
and view ==
'_u':
continue
4726 for l
in range(0,4):
4727 hname =
'biasResX_'+str(s)+view+str(l)
4728 hnameProjX =
'biasRes_'+str(s)+view+str(l)
4729 if h[hname].GetEntries()<10:
4730 h[hnameProjX].Draw()
4733 h[hnameProjX] = h[hname].ProjectionX()
4734 tc = h[
'unbiasedResiduals'].cd(j)
4735 fitResult = h[hnameProjX].Fit(
'gaus',
'SQ',
'',-0.5,0.5)
4736 rc = fitResult.Get()
4739 myGauss.SetParameter(0,h[hnameProjX].GetEntries())
4740 myGauss.SetParameter(1,0.)
4741 myGauss.SetParameter(2,0.1)
4742 myGauss.SetParameter(3,1.)
4744 myGauss.SetParameter(0,rc.GetParams()[0])
4745 myGauss.SetParameter(1,rc.GetParams()[1])
4746 myGauss.SetParameter(2,rc.GetParams()[2])
4747 myGauss.SetParameter(3,0.)
4748 fitResult = h[hnameProjX].Fit(myGauss,
'SQ',
'',-0.2,0.2)
4749 fitResult = h[hnameProjX].Fit(myGauss,
'SQ',
'',-0.5,0.5)
4750 rc = fitResult.Get()
4753 h[hnameProjX].Draw()
4757 stats = h[hnameProjX].FindObject(
"stats")
4758 stats.SetX1NDC(0.563258)
4759 stats.SetY1NDC(0.526687)
4760 stats.SetX2NDC(0.938728)
4761 stats.SetY2NDC(0.940086)
4762 stats.SetOptFit(111)
4764 mean = rc.GetParams()[1]
4765 rms = rc.GetParams()[2]
4766 Emean = rc.GetErrors()[1]
4767 Erms = rc.GetErrors()[2]
4768 print "%i, %s, %i mean=%5.2F+/-%5.2F RMS=%5.2F+/-%5.2F [mm]"%(s,view,l,mean*10,Emean*10,rms*10,Erms*10)
4769 residuals[j-1]= h[hnameProjX].GetMean()
4772 hname =
'biasRes'+p+
'_'+str(s)+view+str(l)
4773 hmean = hname+
'_mean'+p
4774 h[hmean] = h[hname].ProjectionY(hname+
'_mean')
4776 rc = h[
'unbiasedResiduals'+p].cd(j)
4777 for k
in range(1,h[hname].GetNbinsY()+1):
4778 sli = hname+
'_'+str(k)
4779 h[sli] = h[hname].ProjectionX(sli,k,k)
4780 if h[sli].GetEntries()<10:
continue
4781 myGauss.SetParameter(0,h[sli].GetMaximum())
4782 myGauss.SetParameter(1,0.)
4783 myGauss.SetParameter(2,0.1)
4784 myGauss.SetParameter(3,1.)
4785 fitResult = h[sli].Fit(myGauss,
'SQ',
'',-5.,5.)
4786 rc = fitResult.Get()
4789 mean = rc.GetParams()[1]
4790 rms = rc.GetParams()[2]
4791 rc = h[hmean].Fill( h[hmean].GetBinCenter(k), mean)
4792 amin,amax,nmin,nmax = ut.findMaximumAndMinimum(h[hmean])
4793 if amax<3.
and amin>-3.:
4794 h[hmean].SetMaximum(2.)
4795 h[hmean].SetMinimum(-2.)
4797 h[hmean].SetLineColor(ROOT.kRed)
4798 h[hmean].SetMaximum(10.)
4799 h[hmean].SetMinimum(-10.)
4804 hit.EndPoints(vtop,vbot)
4805 if not sTree.GetBranch(
'MuonTaggerPoint'):
4807 vbot[0] = -vbot[0] -1.21
4808 vtop[0] = -vtop[0] -1.21
4810 vbot[1] = vbot[1] -1.21
4811 vtop[1] = vtop[1] -1.21
4814 vbot[0] = vbot[0] -1.049
4815 vtop[0] = vtop[0] -1.049
4817 vbot[1] = vbot[1] -0.53
4818 vtop[1] = vtop[1] -0.53
4823 ut.bookHist(h,
'RPCXY',
'RPC XY True - digi',100,-5.,5.,100,-5.,5.)
4824 for n
in range(sTree.GetEntries()):
4825 rc=sTree.GetEvent(n)
4826 for hit
in sTree.Digi_MuonTaggerHits:
4827 hit.EndPoints(vtop,vbot)
4828 for point
in sTree.MuonTaggerPoint:
4829 if point.GetDetectorID()//10000 != hit.GetDetectorID()//10000:
continue
4830 rc=h[
'RPCXY'].Fill(point.GetX()-(vtop[0]+vbot[0])/2.,point.GetY()-(vtop[1]+vbot[1])/2.)
4835 for item
in iterable:
4836 if not prev
or item - prev <= grouping:
4844import numpy, warnings
4845warnings.filterwarnings(
'error')
4849 clustersPerStation={}
4851 if sTree.GetBranch(
'RPCTrackY')
and PR==1:
4852 for view
in [
'X',
'Y']:
4854 for aTrack
in eval(
'sTree.RPCTrack'+view):
4855 tracks[view].append([aTrack.m(),aTrack.b()])
4856 return clustersPerStation,tracks
4857 for s
in range(1,6):
4859 hitsPerStation[10*s+l]=[]
4860 clustersPerStation[10*s+l]=[]
4861 for m
in sTree.Digi_MuonTaggerHits:
4862 if m.GetDetectorID()
in deadChannelsRPC4MC:
continue
4863 layer = m.GetDetectorID()/1000
4864 channel = m.GetDetectorID()%1000
4865 hitsPerStation[layer].append(channel)
4867 for s
in range(1,6):
4868 L = len(hitsPerStation[10*s+l])
4870 temp = dict(enumerate(
grouper(hitsPerStation[10*s+l],cuts[
'muTaggerCluster_grouping']), 1))
4871 clustersPerStation[10*s+l]={}
4873 if len(temp[cl])>cuts[
'muTaggerCluster_max']:
continue
4876 for hit
in temp[cl]:
4877 vbot,vtop = RPCPositionsBotTop[(10*s+l)*1000+hit]
4878 clusCentre+=vbot[1-l]
4879 zCentre+=(vbot[2]+vtop[2])/2.
4880 clusCentre = clusCentre/float(len(temp[cl]))
4881 zCentre = zCentre/float(len(temp[cl]))
4882 clusCentre = (int(clusCentre*1000) + float(s)/10.)/1000.
4883 clustersPerStation[10*s+l][cl]=[temp[cl],clusCentre,zCentre]
4888 for s
in range(1,6):
4889 for cl
in clustersPerStation[10*s+l]:
4890 test.append(clustersPerStation[10*s+l][cl][1])
4891 tmp = dict(enumerate(
grouper(test,cuts[
'muTaggerCluster_sep']), 1))
4894 if len(tmp[x])>2: trackCand.append(tmp[x])
4900 for s
in range(1,6):
4902 for cl
in clustersPerStation[10*s+l]:
4903 if clustersPerStation[10*s+l][cl][1]==coord:
4904 zpositions.append(clustersPerStation[10*s+l][cl][2])
4907 tmp = list(zpositions)
4908 test = dict(enumerate(
grouper(tmp,10.), 1))
4910 coefficients = numpy.polyfit(zpositions,n,1)
4911 tracks[view].append(coefficients)
4912 return clustersPerStation,tracks
4915 ut.bookHist(h,
'multHits',
'DT hits multiplicity',10,-0.5,9.5)
4916 ut.bookHist(h,
'multHits_deltaT',
'DT multiple hits delta T',100,0.,2000.)
4917 ut.bookHist(h,
'multHits_deltaTz',
'DT multiple hits delta T',400,-200.,200.)
4918 eventRange = [0,sTree.GetEntries()]
4919 if not nEvent<0: eventRange = [nEvent,nEvent+nTot]
4921 for Nr
in range(eventRange[0],eventRange[1]):
4922 rc = sTree.GetEvent(Nr)
4924 for hit
in sTree.Digi_MufluxSpectrometerHits:
4925 detID = hit.GetDetectorID()
4926 if detID<0:
continue
4927 if not listOfDigits.has_key(detID):
4928 listOfDigits[detID]=[0,[]]
4929 listOfTDCs[detID]={}
4930 tdcModule = hit.GetTDC()
4931 if not listOfTDCs[detID].has_key(tdcModule):
4932 listOfTDCs[detID][tdcModule] = 0
4933 listOfTDCs[detID][tdcModule] +=1
4934 listOfDigits[detID][0]+=1
4935 listOfDigits[detID][1].append(hit.GetDigi())
4936 for x
in listOfDigits:
4937 rc=h[
'multHits'].Fill(listOfDigits[x][0])
4938 if listOfDigits[x][0]>1:
4940 listOfDigits[x][1].sort()
4941 for t
in range(1,len(listOfDigits[x][1])):
4942 rc=h[
'multHits_deltaT'].Fill(abs(t-listOfDigits[x][1][0]))
4943 rc=h[
'multHits_deltaTz'].Fill(abs(t-listOfDigits[x][1][0]))
4945 for detID
in listOfTDCs:
4946 test = ROOT.MufluxSpectrometerHit(detID,0.)
4947 s,v,p,l,view,channelID,tdcId,nRT =
stationInfo(test)
4948 if tdcId
not in listOfTDCs[detID].keys():
4949 print "not matching TDC id",detID,tdcId,listOfTDCs[detID]
4950 if len(listOfTDCs[detID])>1:
4951 print detID,listOfTDCs[detID]
4954 ut.bookHist(h,
'ToverT',
'Time over threshold',3000,-1000.,2000.)
4955 for s
in range(1,5):
4956 for view
in views[s]:
4958 ut.bookHist(h,
'multHits_'+str(s)+view+str(l),
'DT cluster size',16,-0.5,15.5)
4959 for Nr
in range(nevents):
4960 rc = sTree.GetEvent(Nr)
4961 spectrHitsSorted = ROOT.nestedList()
4962 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
True)
4963 for s
in range(1,5):
4964 for view
in viewsI[s]:
4967 for x
in spectrHitsSorted[view][s][l]:
4968 allHits.append(x.GetDetectorID()%1000)
4969 clustersPerLayer = dict(enumerate(
grouper(allHits,1), 1))
4970 for Acl
in clustersPerLayer:
4971 rc = h[
'multHits_'+str(s)+viewC[view]+str(l)].Fill(len(clustersPerLayer[Acl]))
4972 if len(clustersPerLayer[Acl])>3:
4973 for aHit
in spectrHitsSorted[view][s][l]:
4975 h[
'ToverT'].Fill(aHit.GetTimeOverThreshold())
4976 ut.bookCanvas(h,key=
'clusSizes',title=
'Cluster sizes per Layer',nx=1600,ny=1200,cx=4,cy=6)
4978 for s
in range(1,5):
4979 for view
in views[s]:
4981 tc=h[
'clusSizes'].cd(j)
4983 hname =
'multHits_'+str(s)+viewC[view]+str(l)
4984 h[hname+
'x']=h[hname].Clone(hname+
'x')
4985 h[hname+
'x'].Scale(1./float(h[hname].GetEntries()))
4991 interestingHistos=[
'station1Occ',
'station1OccX',
'deltaRay',
'deltaRayN',
'deltaRayNvsE']
4992 ut.readHists(hMC,
"deltaRaysMC.root",interestingHistos)
4993 ut.readHists(h,
"deltaRays.root",interestingHistos)
4994 ut.bookCanvas(h,
"s1Occ",
"station 1 occupancy",1200,900,1,1)
4995 tc = h[
"s1Occ"].cd(1)
4997 h[
'MCstation1Occ']=hMC[
'station1Occ'].Clone(
'MCstation1Occ')
4998 A = h[
'station1Occ'].GetBinContent(4)+h[
'station1Occ'].GetBinContent(5)
4999 B = hMC[
'station1Occ'].GetBinContent(4)+hMC[
'station1Occ'].GetBinContent(5)
5000 h[
'MCstation1Occ'].Scale(A/B)
5001 h[
'station1Occ'].Draw()
5002 h[
'MCstation1Occ'].SetLineColor(ROOT.kRed)
5003 h[
'MCstation1Occ'].Draw(
"same")
5006 ut.bookHist(h,
'station1Occ',
'station1 Occupancy',50,0.0,50.)
5007 ut.bookHist(h,
'station1OccX',
'station1 Occupancy deltaRay present',50,0.0,50.)
5008 ut.bookHist(h,
'deltaRay',
'E vs z',100,-1.0,1.0,100,0.0,10.)
5009 ut.bookHist(h,
'deltaRayN',
'hits vs z',100,-1.0,1.0,50,0.0,50.)
5010 ut.bookHist(h,
'deltaRayNvsE',
'hits vs E',100,0.0,10.0,50,0.0,50.)
5011 for n
in range(sTree.GetEntries()):
5012 rc=sTree.GetEvent(n)
5013 if not (sTree.RPCTrackX.GetEntries()==1)
or not (sTree.RPCTrackY.GetEntries()==1) :
continue
5015 spectrHitsSorted = ROOT.nestedList()
5016 muflux_Reco.sortHits(sTree.Digi_MufluxSpectrometerHits,spectrHitsSorted,
True)
5017 for l
in range(4): N+= len(spectrHitsSorted[0][1][l])
5018 rc = h[
'station1Occ'].Fill(N)
5021 for m
in sTree.MCTrack:
5022 pName = m.GetProcName().Data()
5023 if not pName.find(
'Delta ray')<0:
5024 if m.GetStartZ()/100. < 0.05
and m.GetStartZ()/100. > -0.3:
5025 rc = h[
'deltaRayNvsE'].Fill(m.GetP(),N)
5027 rc = h[
'station1OccX'].Fill(N)
5029 rc = h[
'deltaRay'].Fill(m.GetStartZ()/100.,m.GetP())
5030 rc = h[
'deltaRayN'].Fill(m.GetStartZ()/100.,N)
5032 tmp = sTree.GetCurrentFile().GetName()
5033 k = tmp.find(
'SPILLDATA')
5034 if k<0: outFile =
'deltaRays-'+tmp
5035 else: outFile =
'deltaRays-'+tmp[k:]
5036 ut.writeHists(h,outFile)
5042 for point
in sTree.MufluxSpectrometerPoint:
5043 trackID = point.GetTrackID()
5044 if trackID<0 :
continue
5045 if not trackList.has_key(trackID):
5046 trackList[trackID]= {1:0,2:0,3:0,4:0,5:0,6:0}
5047 detID = point.GetDetectorID()
5048 hit = ROOT.MufluxSpectrometerHit(detID,0)
5049 info = hit.StationInfo()
5051 if info[4]>0: s=4+info[4]
5052 trackList[trackID][s]+=1
5053 if point.GetZ()<minZ:
5055 pTrue[trackID]=ROOT.TVector3(point.GetPx(),point.GetPy(),point.GetPz())
5056 return trackList,pTrue
5059 ut.readHists(h,
'ghostStudy.root')
5060 ut.bookCanvas(h,
'ghosts',
'ghosts',1600,700,1,1)
5061 h[
'gf_perfect'].SetTitle(
' ;#it{p} [GeV/c];N/5GeV')
5062 h[
'gf_perfect'].SetLineColor(ROOT.kGreen)
5063 h[
'gf_ghosts'].SetTitle(
'ghost > 33;#it{p}[GeV/c];N/5GeV')
5064 h[
'ghosts'].cd(1).SetLogy(1)
5065 h[
'gf_perfect'].Draw()
5066 for x
in [
'gf_perfect',
'gf_ghosts',
'P',
'Ptrue']:
5067 h[x].SetLineWidth(2)
5070 h[x].Draw(
'hist same')
5072 myPrint(h[
'ghosts'],
'ghostStudy')
5073 h[
'gf_perfect'].GetXaxis().SetRangeUser(250.,500.)
5074 h[
'ghosts'].Update()
5075 myPrint(h[
'ghosts'],
'ghostStudy_zoom')
5077 badTracks = h[
'P'].GetBinContent(h[
'P'].GetNbinsX())
5078 h[
'P_backsubtr']= h[
'P'].Clone(
'P_backsubtr')
5079 h[
'P_backsubtr'].SetLineColor(ROOT.kCyan)
5080 for n
in range(1,h[
'P'].GetNbinsX()):
5081 h[
'P_backsubtr'].SetBinContent(n,h[
'P'].GetBinContent(n)-badTracks)
5082 h[
'P_backsubtr'].Draw()
5084 h[
'gf_perfect'].Draw(
'same')
5085 h[
'ghosts'].Update()
5086 myPrint(h[
'ghosts'],
'ghostStudy_backsubtr')
5088 for x
in [
'gfDiff']:
5089 h[x+
'_perfect'] =h[x].ProjectionY(x+
'_perfect',1,1)
5090 h[x+
'_ghosts'] =h[x].ProjectionY(x+
'_ghosts',33,100)
5091 h[x+
'_ghosts'].SetLineColor(ROOT.kRed)
5092 h[x+
'_perfect'].SetLineColor(ROOT.kGreen)
5093 h[x+
'_perfect'].SetTitle(
'perfect;#it{p} [GeV/c];N/5GeV')
5094 h[x+
'_ghosts'].SetTitle(
'ghost > 33;#it{p} [GeV/c];N/5GeV')
5095 for x
in [
'gfDiff_perfect',
'gfDiff_ghosts']:
5097 ut.makeIntegralDistrib(h,x)
5098 h[
'I-'+x].Scale(1./h[
'I-'+x].GetBinContent(1))
5099 h[
'I-'+x].SetLineWidth(2)
5100 h[
'I-'+x].SetStats(0)
5101 if x.find(
'perfect')>0:
5102 h[
'I-'+x].SetMinimum(0.001)
5104 h[
'I-'+x].Draw(
'hist same')
5105 h[
'I-'+x].Draw(
'hist same')
5106 h[
'ghosts'].Update()
5107 myPrint(h[
'ghosts'],
'ghostStudy_tails')
5110 if nEnd == 0: nEnd = sTree.GetEntries()
5111 for n
in range(nStart,nEnd):
5112 rc = sTree.GetEvent(n)
5114 for aTrack
in sTree.FitTracks:
5116 fitStatus = aTrack.getFitStatus()
5117 if not fitStatus.isFitConverged():
continue
5120 if len(hitsPerStation[
'x1'])<2:
continue
5121 if len(hitsPerStation[
'x2'])<2:
continue
5122 if len(hitsPerStation[
'x3'])<2:
continue
5123 if len(hitsPerStation[
'x4'])<2:
continue
5124 chi2 = fitStatus.getChi2()/fitStatus.getNdf()
5125 fittedState = aTrack.getFittedState()
5126 P = fittedState.getMomMag()
5127 Px,Py,Pz = fittedState.getMom().x(),fittedState.getMom().y(),fittedState.getMom().z()
5128 if chi2 > chi2UL:
continue
5129 if Px<pxLow:
continue
5133 tagged = {
'X':
False,
'Y':
False}
5134 for proj
in [
'X',
'Y']:
5136 for mu
in sTree.RPCTrackX:
5137 if abs(posRPC[0]-mu.m()*zRPC1+mu.b() ) < cuts[
'muTrackMatch'+proj]: tagged[proj]=
True
5139 for mu
in sTree.RPCTrackY:
5140 if abs(posRPC[0]-mu.m()*zRPC1+mu.b() )< cuts[
'muTrackMatch'+proj]: tagged[proj]=
True
5141 if not tagged[
'X']
or not tagged[
'Y'] :
5145 ut.bookHist(h,
'sc',
'sc',1000,-500.,2000.)
5146 ut.bookHist(h,
'sc6',
'sc',1000,-500.,2000.)
5147 ut.bookHist(h,
'sc7',
'sc',1000,-500.,2000.)
5148 ut.bookHist(h,
'scmult',
'sc multiplicity',10,-0.5,9.5)
5149 for n
in range(sTree.GetEntries()):
5150 rc=sTree.GetEvent(n)
5151 rc=h[
'scmult'].Fill(sTree.Digi_ScintillatorHits.GetEntries())
5152 for sc
in sTree.Digi_ScintillatorHits:
5153 rc=h[
'sc'].Fill(sc.GetDigi())
5154 rc=h[
'sc'+str(sc.GetDetectorID())].Fill(sc.GetDigi())
5160 a = ROOT.TVector3(PosDir[t1][0](0) ,PosDir[t1][0](1) ,PosDir[t1][0](2))
5161 u = ROOT.TVector3(PosDir[t1][1](0) ,PosDir[t1][1](1) ,PosDir[t1][1](2))
5162 c = ROOT.TVector3(PosDir[t2][0](0) ,PosDir[t2][0](1) ,PosDir[t2][0](2))
5163 v = ROOT.TVector3(PosDir[t2][1](0) ,PosDir[t2][1](1) ,PosDir[t2][1](2))
5165 a = ROOT.TVector3(PosDir[t1][0](0) ,0, PosDir[t1][0](2))
5166 u = ROOT.TVector3(PosDir[t1][1](0), 0, PosDir[t1][1](2))
5167 c = ROOT.TVector3(PosDir[t2][0](0) ,0, PosDir[t2][0](2))
5168 v = ROOT.TVector3(PosDir[t2][1](0), 0, PosDir[t2][1](2))
5171 uCrossv = u.Cross(v)
5172 dist = pq.Dot(uCrossv)/(uCrossv.Mag()+1E-8)
5175 E = u.Dot(a) - u.Dot(c)
5176 F = v.Dot(a) - v.Dot(c)
5177 A,B = u.Mag2(), -u.Dot(v)
5178 C,D = u.Dot(v), -v.Mag2()
5179 t = -(C*E-A*F)/(B*C-A*D)
5183 return X,Y,Z,abs(dist)
5186 if nmax<0: nmax = sTree.GetEntries()
5187 ut.bookHist(h,
'doca',
'distance between two tracks',100,0.,50.)
5188 ut.bookHist(h,
'nRPC',
'matchedRPCHits',50,0.,50.)
5189 ut.bookHist(h,
'v0mass_wc',
'V0 mass wrong charge combinations',100,0.2,1.8,100,-120.,120.)
5190 ut.bookHist(h,
'v0mass',
'V0 mass ',100,0.2,1.8,100,-120.,120.)
5191 mass = PDG.GetParticle(211).Mass()
5192 for n
in range(nstart,nmax):
5193 rc = sTree.GetEvent(n)
5195 if len(tracks)<2:
continue
5198 for aTrack
in tracks:
5199 st = aTrack.getFitStatus()
5200 if not st.isFitConverged():
continue
5201 if st.getNdf()<12:
continue
5203 rc = h[
'nRPC'].Fill(nRPC)
5204 if not inAcc:
continue
5205 if nRPC > 5:
continue
5206 xx = aTrack.getFittedState()
5207 PosDir[tr] = [xx.getPos(),xx.getDir(),ROOT.TLorentzVector(),xx.getCharge(),aTrack.getFitStatus().getNdf()]
5209 E = ROOT.TMath.Sqrt( mass*mass + mom.Mag2() )
5210 PosDir[tr][2].SetPxPyPzE(mom.x(),mom.y(),mom.z(),E)
5212 for tr1
in range(tr-1):
5213 for tr2
in range(tr1+1,tr):
5214 xv,yv,zv,doca =
myVertex(0,1,PosDir)
5215 V0Mom = PosDir[0][2]+PosDir[1][2]
5216 rc = h[
'doca'].Fill(doca)
5217 print n,doca,zv,V0Mom.M(),PosDir[0][3],PosDir[1][3],PosDir[0][4],PosDir[1][4]
5218 if doca > 5:
continue
5219 if PosDir[tr1][3]*PosDir[tr2][3]< 0: rc = h[
'v0mass'].Fill(V0Mom.M(),zv)
5220 else: rc = h[
'v0mass_wc'].Fill(V0Mom.M(),zv)
5223 rc = sTree.GetEvent(n)
5224 if sTree.GetListOfFiles().GetEntries()>1:
5225 temp = sTree.GetCurrentFile().GetName()
5226 curFile = temp[temp.rfind(
'/')+1:]
5227 if curFile != rname:
5230 h[
'tMinAndTmax'] = RTrelations[rname][
'tMinAndTmax']
5231 for s
in h[
'tMinAndTmax']: h[
'rt'+s] = RTrelations[rname][
'rt'+s]
5234from rootpyPickler
import Pickler
5235from rootpyPickler
import Unpickler
5237from shutil
import copyfile
5240 for fname
in fnames:
5241 rname = fname[fname.rfind(
'/')+1:]
5242 newName = rname.replace(
'.root',
'_RT.root')
5243 if fname.find(
'eos')<0:
5244 copyfile(fname,newName)
5247 rc = os.system(
"xrdcp -f $EOSSHIP"+fname+
" "+newName)
5251 print "Problem with copying file",fname,rc
5253 ftemp = ROOT.TFile.Open(newName,
'update')
5254 sTree = ftemp.Get(
"cbmsim")
5256 print "Problem with making RTrel persistent, file",ftemp,ftemp.ls()
5261 for s
in RTrelations:
5262 if s.find(
'rt')<0:
continue
5263 RTrelations[s].Write()
5265 pkl.dump(h[
'tMinAndTmax'],
'tMinAndTmax')
5267 ftemp.mkdir(
'histos')
5269 h[
'TDCMapsX'].Write()
5270 h[
'hitMapsX'].Write()
5271 h[
"RTrelations"].Write()
5272 ftemp.Write(
"",ROOT.TFile.kOverwrite)
5275 ftemp=sTree.GetCurrentFile()
5279 strawPositionsP = {}
5281 vbot,vtop = strawPositionsBotTop[straw]
5282 strawPositionsP[straw]={
'top':[vtop[0],vtop[1],vtop[2]],
'bot':[vbot[0],vbot[1],vbot[2]]}
5283 alignConstants={
'strawPositions':strawPositionsP,
'alignCorrection':alignCorrection}
5284 conditionsDB.add_condition(
"muflux/driftTubes",
"alignConstants",
"TUE2019",
"2020-03-24", loads(dumps(alignConstants)))
5287 global alignConstants
5290 if not sTree.GetCurrentFile().Get(
'alignConstants')
or withCorrections:
5292 hit = ROOT.MufluxSpectrometerHit(straw,0.)
5294 print "importing alignment constants from code"
5297 alignConstants = ast.literal_eval(json.dumps((conditionsDB.get_condition_by_name_and_tag(
"muflux/driftTubes",
"alignConstants",
"TUE2019"))[
"values"]))
5298 print "importing alignment constants from file",sTree.GetCurrentFile().GetName()
5301 print "loading of alignment constants failed for file",sTree.GetCurrentFile().GetName()
5303 for fname
in fnames:
5304 if len(fnames)==1: f=sTree.GetCurrentFile()
5305 else: f = ROOT.TFile.Open(fname)
5306 rname = fname[fname.rfind(
'/')+1:]
5308 RTrelations[rname]={}
5310 RTrelations[rname][
'tMinAndTmax'] = upkl.load(
'tMinAndTmax')
5311 for x
in RTrelations[rname][
'tMinAndTmax']: RTrelations[rname][
'rt'+x]=f.RT.Get(
'rt'+x)
5312 h[
'tMinAndTmax'] = RTrelations[rname][
'tMinAndTmax']
5313 for s
in h[
'tMinAndTmax']: h[
'rt'+s] = RTrelations[rname][
'rt'+s]
5315 print "loading of RT failed for file",rname
5316 if len(fnames)!=1: f.Close()
5320 pars[
'RTcorr_3_x2'] = [ 0.00831, -0.07374, 0.02906, 0.00208]
5321 pars[
'RTcorr_3_x3'] = [ 0.00681, -0.07238, 0.02892, 0.00166]
5322 pars[
'RTcorr_3_x0'] = [ 0.01101, -0.09078, 0.04499, -0.00141]
5323 pars[
'RTcorr_3_x1'] = [ 0.01742, -0.09704, 0.05228, -0.00443]
5324 pars[
'RTcorr_1_x0'] = [ 0.01154, -0.12568, 0.05343, 0.00328]
5325 pars[
'RTcorr_1_x1'] = [ 0.01198, -0.12964, 0.06247, -0.00039]
5326 pars[
'RTcorr_1_x2'] = [ 0.01161, -0.12784, 0.06131, -0.00023]
5327 pars[
'RTcorr_1_x3'] = [ 0.01347, -0.13834, 0.07343, -0.00372]
5328 pars[
'RTcorr_4_x3'] = [ 0.01728, -0.10018, 0.04357, 0.00202]
5329 pars[
'RTcorr_4_x2'] = [ 0.00721, -0.09512, 0.04784, 0.00004]
5330 pars[
'RTcorr_4_x1'] = [ 0.00657, -0.09035, 0.04213, 0.00092]
5331 pars[
'RTcorr_4_x0'] = [ 0.00574, -0.08853, 0.03935, 0.00204]
5332 pars[
'RTcorr_2_x1'] = [ 0.00924, -0.12481, 0.06797, -0.00409]
5333 pars[
'RTcorr_2_x0'] = [ 0.02527, -0.14195, 0.07045, -0.00305]
5334 pars[
'RTcorr_2_x3'] = [ 0.00816, -0.11859, 0.06268, -0.00366]
5335 pars[
'RTcorr_2_x2'] = [ 0.00889, -0.11218, 0.04914, 0.00214]
5336 pars[
'RTcorr_2_v3'] = [ 0.00148, -0.08058, 0.01316, 0.01340]
5337 pars[
'RTcorr_2_v2'] = [ 0.00443, -0.08887, 0.01707, 0.01278]
5338 pars[
'RTcorr_2_v1'] = [ 0.01399, -0.11404, 0.04792, 0.00191]
5339 pars[
'RTcorr_2_v0'] = [ 0.00164, -0.10222, 0.03695, 0.00631]
5340 pars[
'RTcorr_1_u3'] = [ 0.01792, -0.11791, 0.04498, 0.00483]
5341 pars[
'RTcorr_1_u2'] = [ 0.00220, -0.09611, 0.04685, 0.00020]
5342 pars[
'RTcorr_1_u1'] = [ -0.00148, -0.07691, 0.00984, 0.01453]
5343 pars[
'RTcorr_1_u0'] = [ 0.00043, -0.07272, 0.01027, 0.01312]
5344 pars[
'RTcorr'] = [ 0.00863, -0.10303, 0.04328, 0.00299]
5345 h[
'RTcorr'] = ROOT.TGraph()
5346 for s
in range(1,5):
5347 for view
in views[s]:
5349 fun =
'RTcorrFun_'+str(s)+view+str(l)
5350 h[fun]=ROOT.TF1(fun,
'[0]+[1]*x+[2]*x*x+[3]*x*x*x',4)
5351 for k
in range(4): h[fun].SetParameter(k,pars[fun.replace(
'Fun',
'')][k])
5355 for x
in os.listdir(
'.'):
5356 if x.find(
'_RT')>0
and x.find(
'histos')<0: fnames.append(x)
5358 for x
in RTrelations[fnames[0]][
'tMinAndTmax']:
5359 ut.bookHist(h,x+
'Tmin',x+
'Tmin',100,-130.,-30.)
5360 ut.bookHist(h,x+
'Tmax',x+
'Tmax',600,1100.,1700.)
5361 for fname
in RTrelations:
5362 for x
in RTrelations[fname][
'tMinAndTmax']:
5363 rc = h[x+
'Tmin'].Fill(RTrelations[fname][
'tMinAndTmax'][x][0])
5364 rc = h[x+
'Tmax'].Fill(RTrelations[fname][
'tMinAndTmax'][x][1])
5365 ut.bookCanvas(h,
'RTMins',
'RT Min',1200,900,7,5)
5366 ut.bookCanvas(h,
'RTMaxs',
'RT Max',1200,900,7,5)
5367 keys = RTrelations[fnames[0]][
'tMinAndTmax'].keys()
5369 for n
in range(1,35):
5370 tc = h[
'RTMins'].cd(n)
5371 h[keys[n-1]+
'Tmin'].Draw()
5372 tc = h[
'RTMaxs'].cd(n)
5373 h[keys[n-1]+
'Tmax'].Draw()
5377zeroFieldData=[
'SPILLDATA_8000_0515970150_20180715_220030.root']
5378def init(database='muflux_RTrelations.pkl',remake=False,withReco=False):
5379 global withTDC,RTrelations
5380 if os.path.exists(database): RTrelations = pickle.load(open(database))
5381 N = sTree.GetEntries()
5382 if not RTrelations.has_key(rname)
or remake:
5384 sTree.SetBranchStatus(
"FitTracks",0)
5386 print "start making RT relations"
5388 RTrelations[rname] = {
'tMinAndTmax':h[
'tMinAndTmax']}
5389 for s
in h[
'tMinAndTmax']: RTrelations[rname][
'rt'+s] = h[
'rt'+s]
5390 fpkl=open(database,
'w')
5391 pickle.dump(RTrelations,fpkl)
5394 h[
'tMinAndTmax'] = RTrelations[rname][
'tMinAndTmax']
5395 for s
in h[
'tMinAndTmax']: h[
'rt'+s] = RTrelations[rname][
'rt'+s]
5400 ut.writeHists(h,
'histos-'+rname,plusCanvas=
True)
5403 ut.bookHist(h,
'masterTrigger',
't of master trigger',1000,200.,400.)
5404 ut.bookHist(h,
'delay',
'delay time',1000,-2000.,2000.)
5405 ut.bookHist(h,
'tdcCor',
'corrected TDC time',1000,-2000.,3000.)
5406 ut.bookHist(h,
'tdc',
'TDC time from hit', 1000,-2000.,3000.)
5407 ut.bookHist(h,
'tdc#4',
'TDC 4', 1000,-2000.,10000.)
5408 for n
in range(sTree.GetEntries()):
5409 rc=sTree.GetEvent(n)
5410 for mt
in sTree.Digi_MasterTrigger:
5411 rc = h[
'masterTrigger'].Fill(mt.GetDigi())
5412 if sTree.Digi_MasterTrigger.GetEntries()==0:
5413 rc = h[
'masterTrigger'].Fill(201.)
5416 for k
in range(sTree.Digi_Triggers.GetEntries()):
5417 hit = sTree.Digi_Triggers[k]
5418 if tdcDict.has_key(k):
5419 print "Error, double trigger TDC ID",k
5420 if not hit.GetDigi()<tdcDict[k]:
continue
5421 tdcDict[hit.GetTDC()]=hit.GetDigi()
5422 if not tdcDict.has_key(4):
5423 h[
'masterTrigger'].Fill(210+4)
5425 else: rc = h[
'tdc#4'].Fill(tdcDict[4])
5426 delay = sTree.Digi_MasterTrigger[0].GetDigi() - tdcDict[4]
5427 rc = h[
'delay'].Fill(delay)
5428 for hit
in sTree.Digi_MufluxSpectrometerHits:
5429 detID=hit.GetDetectorID()
5430 if detID<0:
continue
5431 rc = h[
'tdc'].Fill(hit.GetDigi())
5432 if not hit.hasDelay():
5433 tdcID = hit.GetTDC()
5434 if not tdcDict.has_key(tdcID):
5435 h[
'masterTrigger'].Fill(210+tdcID*10)
5436 if hit.hasTrigger() :
print "this should not happen, no trigger but hasTrigger",n
5438 if not hit.hasTrigger() :
print "this should not happen, trigger but hasTrigger false",n
5440 tdcCor = hit.GetDigi() - delay - lt - 1323.0
5441 rc = h[
'tdcCor'].Fill(tdcCor)
5445 if sTree.GetBranchStatus(
"Digi_BeamCounters"): sTree.SetBranchStatus(
"Digi_BeamCounters",0)
5446 if sTree.GetBranchStatus(
"Digi_LateMufluxSpectrometerHits"): sTree.SetBranchStatus(
"Digi_LateMufluxSpectrometerHits",0)
5447 if sTree.GetBranchStatus(
"Digi_MufluxSpectrometerHits"): sTree.SetBranchStatus(
"Digi_MufluxSpectrometerHits",0)
5448 if sTree.GetBranchStatus(
"Digi_Scintillators"): sTree.SetBranchStatus(
"Digi_Scintillators",0)
5449 if sTree.GetBranchStatus(
"Digi_Triggers"): sTree.SetBranchStatus(
"Digi_Triggers",0)
5450 if sTree.GetBranchStatus(
"Digi_MasterTrigger"): sTree.SetBranchStatus(
"Digi_MasterTrigger",0)
5451 if sTree.GetBranchStatus(
"Digi_MuonTaggerHits"): sTree.SetBranchStatus(
"Digi_MuonTaggerHits",0)
5454 for t
in sTree.MCTrack:
5455 if abs(t.GetPdgCode())!=13:
continue
5456 moID = abs(sTree.MCTrack[t.GetMotherId()].GetPdgCode())
5457 if moID
in muSourcesIDs:
5460 pName = t.GetProcName().Data()
5461 if not( pName.find(
'Lepton pair')<0
and pName.find(
'Positron annihilation')<0
and pName.find(
'Hadronic inelastic')<0 ):
5468 doubleProc = [0,0,0]
5469 N = sTree.GetEntries()
5471 rc=sTree.GetEvent(n)
5475 for hit
in sTree.MufluxSpectrometerPoint:
5478 if i
in processed:
continue
5481 if abs(t.GetPdgCode())!=13:
continue
5482 moID = abs(sTree.MCTrack[t.GetMotherId()].GetPdgCode())
5483 pName = t.GetProcName().Data()
5490 if not muonO.has_key(pName):
5493 if not muonO2[pName].has_key(moID): muonO2[pName][moID]=0
5495 muonO2[pName][moID]+=1
5496 if len(processed)>0: doubleProc[0] +=1
5497 sorted_o = sorted(muonO.items(), key=operator.itemgetter(1))
5499 print "%30s %5.2F %%"%(p[0],p[1]/float(doubleProc[0])*100.)
5500 for p
in [
'Primary particle emission',
'Decay']:
5501 print "for process ",p
5502 sorted_p = sorted(muonO2[p].items(), key=operator.itemgetter(1))
5504 part = PDG.GetParticle(x[0])
5505 if not part: particleName = str(x[0])
5506 else: particleName = PDG.GetParticle(x[0]).GetName()
5507 print " %20s %5.2F %%"%(particleName,x[1]/float(doubleProc[0])*100.)
5508 print "double process ",doubleProc
5512 curFile = sTree.GetCurrentFile().GetName()
5513 newFile1 = curFile.replace(
".root",
"_dimuon99.root")
5514 newFile2 = curFile.replace(
".root",
"_dimuon1.root")
5515 os.system(
'cp '+curFile+
' '+newFile1)
5516 os.system(
'cp '+curFile+
' '+newFile2)
5518 sTree.SetBranchStatus(
"FitTracks",0)
5519 sTree.SetBranchStatus(
"RPCTrackX",0)
5520 sTree.SetBranchStatus(
"RPCTrackY",0)
5521 sTree.SetBranchStatus(
"TrackInfos",0)
5522 newf1 = ROOT.TFile(newFile1,
"recreate")
5523 newTree1 = sTree.CloneTree(0)
5524 newf2 = ROOT.TFile(newFile2,
"recreate")
5525 newTree2 = sTree.CloneTree(0)
5526 for n
in range(sTree.GetEntries()):
5527 rc = sTree.GetEntry(n)
5528 if checkForDiMuon()
and rnr.Uniform(0.,1.)<0.99: rc = newTree1.Fill()
5529 else: rc = newTree2.Fill()
5535 newf1 = ROOT.TFile(newFile1)
5536 newf2 = ROOT.TFile(newFile2)
5537 n12 = newf1.cbmsim.GetEntries() + newf2.cbmsim.GetEntries()
5538 N = sTree.GetEntries()
5541 sTree.GetCurrentFile().Close()
5544 os.system(
'mv '+newFile2+
' '+curFile)
5545 else:
print "unitarity violated",f,n1,n2,sTree.GetEntries()
5547 views = [
'_u1',
'_v2',
'_x1',
'_x2',
'_x3',
'_x4']
5548 if not onlyPlotting:
5550 ut.bookHist(h,
'points'+view,
'points'+view,100,0,400,10,-0.5,9.5)
5551 ut.bookHist(h,
'Fitpoints'+view,
'points'+view,100,0,400,10,-0.5,9.5)
5552 for n
in range(sTree.GetEntries()):
5553 rc = sTree.GetEvent(n)
5556 for p
in sTree.MufluxSpectrometerPoint:
5558 if not hitsPerTrack.has_key(t):
5559 if abs(p.PdgCode())!=13:
continue
5560 P = ROOT.TVector3(p.GetPx(),p.GetPy(),p.GetPz())
5561 if P.Mag() < 10:
continue
5562 if abs(p.GetX())>10
or abs(p.GetY())>10 :
continue
5563 hitsPerTrack[t] = {
'_u1':0,
'_v2':0,
'_x1':0,
'_x2':0,
'_x3':0,
'_x4':0}
5565 test = ROOT.MufluxSpectrometerHit(p.GetDetectorID(),0.)
5566 statnb,vnb,pnb,lnb,view,channelID,tdcId,nRT =
stationInfo(test)
5567 key = view+str(statnb)
5568 hitsPerTrack[t][key]+=1
5570 for t
in hitsPerTrack:
5571 rc = h[
'points'+view].Fill(mom[t],hitsPerTrack[t][view])
5573 for aTrack
in sTree.FitTracks:
5574 fst = aTrack.getFitStatus()
5575 if not fst.isFitConverged():
continue
5576 fstate = aTrack.getFittedState(0)
5577 mom = fstate.getMom()
5580 v = view.replace(
'_',
'')
5583 rc = h[
'Fitpoints'+view].Fill(mom.Mag(),len(mStatistics[v]))
5584 ut.writeHists(h,
'histos-DTPoints-'+rname)
5585 cases = {
'FitPoints':
'Fitpoints'}
5586 if MCdata: cases[
'MC-DTPoints']=
'points'
5588 if not h.has_key(t):
5589 ut.bookCanvas(h,key=t,title=t,nx=1200,ny=600,cx=3,cy=2)
5590 ut.bookCanvas(h,key=t+
'proj',title=t,nx=1200,ny=600,cx=3,cy=2)
5593 mean =
'mean'+cases[t]+view
5594 oneHit234 =
'oneHit234'+cases[t]+view
5595 twoHit34 =
'twoHit34'+cases[t]+view
5596 h[mean] = h[cases[t]+view].ProjectionX().Clone(mean)
5597 h[oneHit234]= h[cases[t]+view].ProjectionX().Clone(oneHit234)
5598 h[twoHit34]= h[cases[t]+view].ProjectionX().Clone(twoHit34)
5599 h[cases[t]+view+
'proj']= h[cases[t]+view].ProjectionY().Clone(cases[t]+view+
'proj')
5600 h[oneHit234].SetMaximum(-1111)
5601 h[oneHit234].SetMinimum(-1111)
5602 h[twoHit34].SetMaximum(-1111)
5603 h[twoHit34].SetMinimum(-1111)
5604 for k
in range(1,h[mean].GetNbinsX()):
5605 test = h[cases[t]+view].ProjectionY(
'test',k,k)
5606 h[mean].SetBinContent(k,test.GetMean())
5607 h[mean].SetBinError(k,0)
5608 ratio = float(test.GetBinContent(2))/(test.GetBinContent(3)+test.GetBinContent(4)+test.GetBinContent(5)+1E-6)
5609 h[oneHit234].SetBinContent(k,ratio)
5610 h[oneHit234].SetBinError(k,0)
5611 ratio = float(test.GetBinContent(3))/(test.GetBinContent(4)+test.GetBinContent(5)+1E-6)
5612 h[twoHit34].SetBinContent(k,ratio)
5613 h[twoHit34].SetBinError(k,0)
5615 h[mean].SetMinimum(2.)
5616 h[mean].SetMaximum(4.)
5617 h[mean].Fit(
'pol1',
'PL',
'',50,300)
5619 h[mean].Draw(
'hist')
5620 h[mean].GetFunction(
'pol1').Draw(
'same')
5621 tc = h[t+
'proj'].cd(n)
5623 h[cases[t]+view+
'proj'].GetXaxis().SetRangeUser(-0.5,6.5)
5624 h[cases[t]+view+
'proj'].Draw(
'hist')
5627 myPrint(h[t+
'proj'],t+
'distribution')
5630 views = [
'_u1',
'_v2',
'_x1',
'_x2',
'_x3',
'_x4']
5631 interestingHistos=[]
5632 for view
in views: interestingHistos.append(t+view)
5633 ut.readHists(hMC,
'../DTPoints-mbias.root',interestingHistos)
5634 ut.readHists(h,
'momDistributions.root',interestingHistos)
5635 if not h.has_key(t):
5636 ut.bookCanvas(h,key=t,title=t,nx=1200,ny=600,cx=3,cy=2)
5637 ut.bookCanvas(h,key=t+
'proj',title=t,nx=1200,ny=600,cx=3,cy=2)
5638 histos = {
'data':h,
'MC':hMC}
5639 for data
in [
'data',
'MC']:
5642 mean = data+
'mean'+t+view
5643 oneHit234 = data+
'oneHit234'+t+view
5644 twoHit34 = data+
'twoHit34'+t+view
5645 h[mean] = hx[t+view].ProjectionX().Clone(mean)
5646 h[oneHit234]= hx[t+view].ProjectionX().Clone(oneHit234)
5647 h[twoHit34] = hx[t+view].ProjectionX().Clone(twoHit34)
5648 h[data+t+view+
'proj']= hx[t+view].ProjectionY().Clone(data+t+view+
'proj')
5649 h[oneHit234].SetMaximum(-1111)
5650 h[oneHit234].SetMinimum(-1111)
5651 h[twoHit34].SetMaximum(-1111)
5652 h[twoHit34].SetMinimum(-1111)
5653 for k
in range(1,h[mean].GetNbinsX()):
5654 test = hx[t+view].ProjectionY(
'test',k,k)
5655 h[mean].SetBinContent(k,test.GetMean())
5656 h[mean].SetBinError(k,0)
5657 ratio = float(test.GetBinContent(2))/(test.GetBinContent(3)+test.GetBinContent(4)+test.GetBinContent(5)+1E-6)
5658 h[oneHit234].SetBinContent(k,ratio)
5659 h[oneHit234].SetBinError(k,0)
5660 ratio = float(test.GetBinContent(3))/(test.GetBinContent(4)+test.GetBinContent(5)+1E-6)
5661 h[twoHit34].SetBinContent(k,ratio)
5662 h[twoHit34].SetBinError(k,0)
5663 h[mean].SetMinimum(2.)
5664 h[mean].SetMaximum(4.)
5665 h[mean].Fit(
'pol1',
'PL',
'',50,300)
5667 for data
in [
'data',
'MC']:
5672 mean = data+
'mean'+t+view
5674 h[mean].SetLineColor(ROOT.kGreen)
5675 h[mean].Draw(
'histsame')
5677 h[mean].SetLineColor(ROOT.kBlue)
5678 h[mean].Draw(
'hist')
5679 h[mean].GetFunction(
'pol1').Draw(
'same')
5680 tc = h[t+
'proj'].cd(n)
5682 hname = data+t+view+
'proj'
5683 h[hname].GetXaxis().SetRangeUser(-0.5,6.5)
5685 h[hname].SetLineColor(ROOT.kGreen)
5686 h[hname].Draw(
'histsame')
5688 h[hname].SetLineColor(ROOT.kBlue)
5689 h[hname].Draw(
'hist')
5692 myPrint(h[t+
'proj'],t+
'distribution')
5694 f=ROOT.TFile(
'PinPout.root')
5697 PinPout.SetTitle(
'incoming vs. outgoing momentum;#it{p} [GeV/c];#it{p} [GeV/c]; ')
5699 lx = ROOT.TLine(0.,1.,10.,1.)
5701 ly = ROOT.TLine(5.,0.,5.,10.)
5725 charmNorm = {1:0.176,10:0.424}
5726 beautyNorm = {1:0., 10:0.01218}
5727 sim10fact = 1.8/(65.*(1.-0.016))
5728 sources = {
"":1.,
"Hadronic inelastic":100.,
"Lepton pair":100.,
"Positron annihilation":100.,
"charm":1./charmNorm[10],
"beauty":1./beautyNorm[10]}
5729 interestingHistos = []
5732 for source
in sources: interestingHistos.append(a+x+source)
5733 ut.readHists(hMC,
'../momDistributions-mbias.root',interestingHistos)
5734 ut.readHists(hCharm,
'../momDistributions-charm.root',interestingHistos)
5735 ut.readHists(hMC10GeV,
'../momDistributions-10GeVTR.root',interestingHistos)
5736 ut.readHists(hMCD,
'momDistributions-1GeV-mbias-withDeadChannels.root',interestingHistos)
5737 ut.readHists(hCharmD,
'momDistributions-1GeV-charm-withDeadChannels.root ',interestingHistos)
5738 ut.readHists(hMC10GeVD,
'momDistributions-10GeV-mbias-withDeadChannels.root ',interestingHistos)
5739 ut.readHists(hMC0,
'../momDistributions-1GeV-mbias-effTuned-M0.root',interestingHistos)
5740 ut.readHists(hMC2,
'../momDistributions-1GeV-mbias-effTuned-M2.root', interestingHistos)
5741 ut.readHists(hMCrec0,
'../momDistributions-1GeV-mbias-effTuned-M0-reco.root',interestingHistos)
5742 ut.readHists(hMCrec2,
'../momDistributions-1GeV-mbias-effTuned-M2-reco.root',interestingHistos)
5743 ut.readHists(hCharm0,
'../momDistributions-1GeV-charm-effTuned-M0.root',interestingHistos)
5744 ut.readHists(hCharm2,
'../momDistributions-1GeV-charm-effTuned-M2.root', interestingHistos)
5745 ut.readHists(hCharmrec0,
'../momDistributions-1GeV-charm-effTuned-M0-reco.root',interestingHistos)
5746 ut.readHists(hCharmrec2,
'../momDistributions-1GeV-charm-effTuned-M2-reco.root',interestingHistos)
5747 ut.readHists(hMC10GeV0,
'../momDistributions-10GeV-mbias-effTuned-M0.root',interestingHistos)
5748 ut.readHists(hMC10GeV2,
'../momDistributions-10GeV-mbias-effTuned-M2.root',interestingHistos)
5749 ut.readHists(hMC10GeVrec0,
'../momDistributions-10GeV-mbias-effTuned-M0-reco.root',interestingHistos)
5750 ut.readHists(hMC10GeVrec2,
'../momDistributions-10GeV-mbias-effTuned-M2-reco.root',interestingHistos)
5752 print "with deadChannels / default"
5753 print "1GeV mbias:",hMCD[a].GetEntries()/hMC[a].GetEntries()
5754 print "1GeV charm:",hCharmD[a].GetEntries()/hCharm[a].GetEntries()
5755 print "10GeV :",hMC10GeVD[a].GetEntries()/hMC10GeV[a].GetEntries()
5756 print "method 0 / default"
5757 print "1GeV mbias:",hMC0[a].GetEntries()/hMC[a].GetEntries(),hMCrec0[a].GetEntries()/hMC[a].GetEntries()
5758 print "1GeV charm:",hCharm0[a].GetEntries()/hCharm[a].GetEntries(),hCharmrec0[a].GetEntries()/hCharm[a].GetEntries()
5759 print "10GeV :",hMC10GeV0[a].GetEntries()/hMC10GeV[a].GetEntries(),hMC10GeVrec0[a].GetEntries()/hMC10GeV[a].GetEntries()
5760 print "method 2 / default"
5761 print "1GeV mbias:",hMC2[a].GetEntries()/hMC[a].GetEntries(),hMCrec2[a].GetEntries()/hMC[a].GetEntries()
5762 print "1GeV charm:",hCharm2[a].GetEntries()/hCharm[a].GetEntries(),hCharmrec2[a].GetEntries()/hCharm[a].GetEntries()
5763 print "10GeV :",hMC10GeV2[a].GetEntries()/hMC10GeV[a].GetEntries(),hMC10GeVrec2[a].GetEntries()/hMC10GeV[a].GetEntries()
5766 methods = {
'default':[hMC,hCharm,hMC10GeV],
'M0rec':[hMCrec0,hCharmrec0,hMC10GeVrec0],
'M2rec':[hMCrec2,hCharmrec2,hMC10GeVrec2],
'D':[hMCD,hCharmD,hMC10GeVD]}
5767 colors = {
'M0':ROOT.kRed,
'M2':ROOT.kCyan,
'M0rec':ROOT.kMagenta,
'M2rec':ROOT.kBlue,
'D':ROOT.kOrange}
5769 h[
'MC'+m+a] = methods[m][0][a].Clone(
'MC'+m+a)
5770 h[
'MC'+m+a].Add(methods[m][1][a],charmNorm[1])
5771 h[
'MC10'+m+a] = methods[m][2][a].Clone(
'MC'+m+a)
5772 h[
'MC10'+m+a].Add(methods[m][2][a.replace(
"_",
"charm_")],-1.+charmNorm[10])
5773 h[
'MC10'+m+a].Add(methods[m][2][a.replace(
"_",
"beauty_")],-1.+beautyNorm[10])
5774 h[
'MC10'+m+a].Scale(sim10fact)
5775 for n
in range(1,h[
'MC'+m+a].GetNbinsX()+1):
5776 if h[
'MC'+m+a].GetBinCenter(n)<6:
5777 h[
'MC'+m+a].SetBinContent(n,0.)
5778 h[
'MC'+m+a].SetBinError(n,0.)
5779 if h[
'MC'+m+a].GetBinCenter(n)>5.5:
5780 h[
'MC'+m+a].SetBinContent(n,h[
'MC10'+m+a].GetBinContent(n))
5781 h[
'MC'+m+a].SetBinError(n,h[
'MC10'+m+a].GetBinError(n))
5782 h[
'MC'+m+a].Rebin(5)
5783 ut.makeIntegralDistrib(h,
'MC'+m+a)
5784 t =
'MC-Comparison eff tuning'
5785 if not h.has_key(t): ut.bookCanvas(h,key=t,title=
'MC-Comparison eff tuning',nx=900,ny=600,cx=1,cy=1)
5787 h[
'leg'+t]=ROOT.TLegend(0.55,0.65,0.85,0.85)
5791 if m ==
'default':
continue
5792 ihist = plot+m+
'OverDefault'
5793 h[ihist] = h[plot+
'MC'+m+a].Clone(ihist)
5794 h[ihist].Divide(h[plot+
'MCdefault'+a])
5795 h[ihist].SetLineColor(colors[m])
5796 h[ihist].GetXaxis().SetRangeUser(5,400)
5797 h[ihist].SetStats(0)
5798 h[ihist].SetMaximum(1.1)
5799 h[ihist].SetMinimum(0.8)
5800 h[ihist].SetTitle(
'efficiency correction as function of momentum ;#it{p} [GeV/c];efficiency correction')
5801 if n == 0: h[ihist].Draw()
5802 else: h[ihist].Draw(
'same')
5804 h[
'leg'+t].AddEntry(h[ihist],
'method '+m+
' / default',
'PL')
5806 myPrint(h[t],
'MCcomparison-Efficiency-Tuning')
5809 interestingHistos = []
5810 cuts = {
'':ROOT.kBlue,
'All':ROOT.kCyan,
'Chi2<':ROOT.kGreen,
'Delx<':ROOT.kOrange,
'Dely<':ROOT.kMagenta}
5812 for a
in [
'p/pt',
'Chi2/DoF']:
5814 interestingHistos.append(c+a+x)
5815 ut.readHists(h,hname,interestingHistos)
5817 for a
in [
'p/pt',
'Chi2/DoF']:
5819 h[c+a+x].SetLineColor(cuts[c])
5820 h[c+a+x+
'_projx'].SetLineColor(cuts[c])
5821 h[c+a+x+
'2d'] = h[c+
'p/pt'+x].Rebin2D(10,10,c+a+x+
'2d')
5822 h[c+a+x+
'_projy'].SetLineColor(cuts[c])
5827 ntracks[c] = h[c+
'p/pt'+x+
'_projx'].Integral(5,15)
5828 h[c+x] = h[c+
'p/pt'+x+
'_projx'].Clone(c+x)
5830 h[
'p/pt'+x+
'_projx'].Draw()
5832 h[c+
'p/pt'+x+
'_projx'].Draw(
'same')
5833 h[c+x].Divide(h[
'p/pt'+x+
'_projx'])
5834 h[c+
'p/pt'+x+
'2d'].Divide(h[
'p/pt'+x+
'2d'])
5837 print "%s efficiency=%5.3F"%(c,ntracks[c]/ntracks[
''])
5839def MCcomparison(pot = -1, pMin = 5.,pMax=300.,ptMax = 4.,simpleEffCor=0.023,effCor=False,eric=False,version="-repro",withOverFlow=False,withDisplay=True,cuts='',noTitle=False):
5846 simpleEffCorMu = simpleEffCor
5848 simpleEffCorMu = simpleEffCor + 0.130
5849 simpleEffCor += 0.056
5851 simpleEffCor += 0.056
5852 simpleEffCorMu = 0.021
5854 label =
'MC-Comparison'+cuts.replace(
'<',
'')
5866 sim10fact = MCStats/(MC10Stats)
5868 charmNorm = {1:MCStats/10.21E9,10:MC10Stats/153.90E9}
5869 beautyNorm = {1:0., 10:0.01218}
5870 sources = {
"":1.,
"Hadronic inelastic":100.,
"Lepton pair":100.,
"Positron annihilation":100.,
5871 "charm":1./charmNorm[10],
"beauty":1./beautyNorm[10],
"Di-muon P8":100.,
"invalid":1.}
5873 interestingHistos = [
'Trscalers',
'chi2']
5874 for a
in [
'p/pt',
'pz/Abspx',
'p1/p2',
'p1/p2s']:
5875 for x
in [
'',
'mu',
'ymu']:
5876 for source
in sources:
5878 if x==
'' and ( cuts ==
'Delx' or cuts ==
'Dely' or cuts ==
'All' ): c=
''
5879 if x==
'ymu' and ( cuts ==
'Delx' or cuts ==
'All' ): c=
''
5880 interestingHistos.append(c+a+x+source)
5882 ut.readHists(h,
'momDistributions'+version+
'.root',interestingHistos)
5884 ut.readHists(h,
'sumHistos'+version+
'.root',interestingHistos)
5892 ut.readHists(hMC,
'momDistributions-1GeV-mbias'+version+
'.root',interestingHistos)
5893 ut.readHists(hCharm,
'momDistributions-1GeV-charm'+version+
'.root',interestingHistos)
5894 ut.readHists(hMC10GeV,
'momDistributions-10GeV-mbias'+version+
'.root',interestingHistos)
5896 ut.readHists(hMC,
'sumHistos--simulation1GeV'+version+
'.root',interestingHistos)
5897 ut.readHists(hCharm,
'sumHistos--simulation1GeV'+version+
'-charm.root',interestingHistos)
5898 ut.readHists(hMC10GeV,
'sumHistos--simulation10GeV'+version+
'.root',interestingHistos)
5901 ut.readHists(hMC,
'../momDistributions-1GeV-mbias-effTuned-M0-reco.root',interestingHistos)
5902 ut.readHists(hMC,
'../momDistributions-1GeV-mbias-effTuned-M2.root', interestingHistos)
5903 ut.readHists(hCharm,
'../momDistributions-1GeV-charm-effTuned-M0-reco.root',interestingHistos)
5904 ut.readHists(hCharm,
'../momDistributions-1GeV-charm-effTuned-M2.root', interestingHistos)
5905 ut.readHists(hMC10GeV,
'../momDistributions-10GeV-mbias-effTuned-M0-reco.root',interestingHistos)
5906 ut.readHists(hMC10GeV,
'../momDistributions-10GeV-mbias-effTuned-M2.root',interestingHistos)
5907 MCStats = MCStats*2.
5910 for a
in [
'p/pt',
'pz/Abspx',
'p1/p2',
'p1/p2s',
'Trscalers',
'RPCResX/Y']:
5911 for x
in [
'',
'mu',
'ymu']:
5912 for source
in sources:
5914 if cuts ==
'All' and x==
'': theCut=
'Chi2<'
5915 if h.has_key(theCut+a+x+source):
5916 h[a+x+source]= h[theCut+a+x+source].Clone(a+x+source)
5917 hMC[a+x+source]= hMC[theCut+a+x+source].Clone(a+x+source)
5918 hCharm[a+x+source]= hCharm[theCut+a+x+source].Clone(a+x+source)
5919 hMC10GeV[a+x+source]= hMC10GeV[theCut+a+x+source].Clone(a+x+source)
5921 for a
in [
'p/pt',
'pz/Abspx',
'p1/p2',
'p1/p2s']:
5923 if a.find(
'p1/p2')==0
and x!=
'':
continue
5924 for hstore
in [hMC,hCharm,hMC10GeV]:
5926 hstore[a+x+
"G4default"]=hstore[a+x].Clone(a+x+
"G4default")
5927 hstore[a+x+
"G4default"].Add(hstore[a+x+
"Hadronic inelastic"],-1.)
5931 POTdata = h[
'Trscalers'].GetBinContent(2) * muPerPot
5932 if version==
"-repro": POTdata=POTdata/0.994
5933 MCscaleFactor = POTdata / MCStats
5935 print "PoT data",POTdata / 1E9,
"+/-",POTdata*daSysError / 1E9,
" billion"
5937 norm[
''] = MCscaleFactor * (1.-simpleEffCor)
5938 norm[
'mu'] = MCscaleFactor * (1.-simpleEffCorMu)
5939 for a
in [
'p/pt',
'pz/Abspx',
'p1/p2',
'p1/p2s']:
5941 if a.find(
'p1/p2')==0
and x==
'mu':
continue
5943 h[
'MC'+a+x] = hMC[a+x].Clone(
'MC'+a+x)
5944 h[
'MC'+a+x].Add(hCharm[a+x],charmNorm[1])
5945 h[
'MC'+a+x].Scale(norm[x])
5946 for source
in sources:
5947 if source ==
"" or source ==
"beauty":
continue
5949 if source ==
"charm":
5950 h[
'MC'+xxx] = hCharm[a+x].Clone(
'MC'+xxx)
5951 h[
'MC'+xxx].Scale(charmNorm[1])
5953 h[
'MC'+xxx] = hMC[xxx].Clone(
'MC'+xxx)
5954 h[
'MC'+xxx].Scale(norm[x])
5956 h[
'MC10'+a+x] = hMC10GeV[a+x].Clone(
'MC10'+a+x)
5959 for source
in sources:
5960 if source ==
"":
continue
5962 h[
'MC10'+a+x].Add(hMC10GeV[xxx],-1.+1./sources[source])
5963 h[
'MC10'+xxx] = hMC10GeV[xxx].Clone(
'MC10'+xxx)
5964 h[
'MC10'+xxx].Scale(1./sources[source])
5965 h[
'MC10'+xxx].Scale(sim10fact)
5966 h[
'MC10'+a+x].Scale(sim10fact)
5968 h[
'MC10'+a+x].Add(hMC10GeV[a+x+
"charm"],-1.+charmNorm[10])
5969 h[
'MC10'+a+x].Add(hMC10GeV[a+x+
"beauty"],-1.+beautyNorm[10])
5970 for source
in sources:
5971 if source ==
"":
continue
5973 h[
'MC10'+xxx] = hMC10GeV[xxx].Clone(
'MC10'+xxx)
5974 if source ==
"charm" or source ==
"beauty": h[
'MC10'+xxx].Scale(sim10fact/sources[source]*norm[x])
5975 else: h[
'MC10'+xxx].Scale(sim10fact*norm[x])
5976 h[
'MC10'+a+x].Scale(sim10fact*norm[x])
5978 h[
'MC10'+a+x+
"Decay"]=h[
'MC10'+a+x].Clone(
'MC10'+a+x+
"Decay")
5979 h[
'MC'+a+x+
"Decay"]=h[
'MC'+a+x].Clone(
'MC'+a+x+
"Decay")
5982 h[
'MC10'+a+x+
"Decay"].Add(h[
'MC10'+a+x+s],-1.)
5983 if s!=
"beauty": h[
'MC'+a+x+
"Decay"].Add(h[
'MC'+a+x+s],-1.)
5992 optSorted = [
'',
'MC',
'MC10',
'MCcharm',
'MCDi-muon P8',
'MCHadronic inelastic',
'MCLepton pair',
'MCPositron annihilation',
5993 'MC10charm',
'MC10Hadronic inelastic',
'MC10Di-muon P8',
'MC10Lepton pair',
'MC10Positron annihilation']
5994 opt = {
'':[
'hist',ROOT.kBlue,
'data'],
'MC':[
'same',ROOT.kRed,
'MC inclusive'],
'MC10':[
'same',ROOT.kRed,
'MC 10GeV total'],
5995 'MCcharm':[
'same',ROOT.kGreen,
'Charm'],
'MC10charm':[
'same',ROOT.kGreen,
'Charm'],
5996 'MCHadronic inelastic':[
'same',ROOT.kCyan+1,
'Decays to di-muons (GEANT4)'],
5997 'MC10Hadronic inelastic':[
'same',ROOT.kCyan+1,
'Decays to di-muons (GEANT4)'],
5998 'MCLepton pair':[
'same',ROOT.kGreen+1,
'Photon conversion'],
'MCPositron annihilation':[
'same',ROOT.kRed+2,
'Positron annihilation'],
5999 'MC10Lepton pair':[
'same',ROOT.kGreen+1,
'Photon conversion'],
'MC10Positron annihilation':[
'same',ROOT.kRed+2,
'Positron annihilation'],
6000 'MCDi-muon P8':[
'same',ROOT.kCyan,
'Decays to di-muons (PYTHIA8)'],
6001 'MC10Di-muon P8':[
'same',ROOT.kCyan,
'Decays to di-muons (PYTHIA8)']}
6002 ptMaxBin = h[
'p/pt'].GetYaxis().FindBin(ptMax)
6003 ptInterval = [ [pMin,10.],[10.,25.],[25.,50.],[50.,75.],[75.,100.],[100.,125.],[125.,150.],[150.,200.],[200.,250.],[250.,300.] ,[300.,400.] ]
6004 ptIntervalRebin = [ 1, 1, 1, 1, 1, 1, 2, 2, 4, 4, 4 ]
6006 for a
in [
'p/pt',
'pz/Abspx',
'p1/p2']:
6007 if a==
'p1/p2' and x==
'mu':
continue
6008 for source
in sources:
6010 h[
'MC10'+xxx+
'_x'] = h[
'MC10'+xxx].ProjectionX(
'MC10'+xxx+
'_x',1,ptMaxBin)
6011 if source ==
"": h[xxx+
'_x'] = h[xxx].ProjectionX(xxx+
'_x',1,ptMaxBin)
6012 if source ==
"beauty":
continue
6013 h[
'MC'+xxx+
'_x'] = h[
'MC'+xxx].ProjectionX(
'MC'+xxx+
'_x',1,ptMaxBin)
6019 if not i.find(
'MC10')<0:
6021 source = i1.split(
'MC10')[1]
6022 elif not i.find(
'MC')<0:
6024 source = i1.split(
'MC')[1]
6030 h[i+
'p/pt'+z+
'_y'] =h[i+
'p/pt'+z].ProjectionY(i+
'p/pt'+z+
'_y' ,h[i+
'p/pt'+x+
'_x'].FindBin(pMin),h[i+
'p/pt'+x+
'_x'].FindBin(20.))
6031 tmp = h[i+
'10p/pt'+z].ProjectionY(
'tmp',h[i+
'p/pt'+x+
'_x'].FindBin(20.)+1,h[i+
'p/pt'+x+
'_x'].FindBin(pMax))
6033 h[i+
'p/pt'+z+
'_y'].Add(tmp)
6035 h[i+
'pz/Abspx'+z+
'_y']=h[i+
'pz/Abspx'+z].ProjectionY(i+
'pz/Abspx'+z+
'_y',h[i+
'pz/Abspx'+x+
'_x'].FindBin(pMin),h[i+
'pz/Abspx'+x+
'_x'].FindBin(20.))
6036 tmp = h[i+
'10pz/Abspx'+z].ProjectionY(
'tmp',h[i+
'pz/Abspx'+x+
'_x'].FindBin(20)+1,h[i+
'pz/Abspx'+x+
'_x'].FindBin(pMax))
6037 h[i+
'pz/Abspx'+z+
'_y'].Add(tmp)
6039 h[i+
'totp/pt'+z+
'_x']=h[i+
'10p/pt'+z+
'_x'].Clone(i+
'totp/pt'+z+
'_x')
6040 h[i+
'totpz/Abspx'+z+
'_x']=h[i+
'10pz/Abspx'+z+
'_x'].Clone(i+
'totpz/Abspx'+z+
'_x')
6041 for k
in range(h[i+
'totp/pt'+z+
'_x'].FindBin(pMin),h[i+
'totp/pt'+z+
'_x'].FindBin(20.)+1):
6042 h[i+
'totp/pt'+z+
'_x'].SetBinContent(k,h[i+
'p/pt'+z+
'_x'].GetBinContent(k))
6043 h[i+
'totpz/Abspx'+z+
'_x'].SetBinContent(k,h[i+
'pz/Abspx'+z+
'_x'].GetBinContent(k))
6045 for pInterval
in ptInterval:
6046 interval =
'_y'+str(pInterval[0])+
'-'+str(pInterval[1])
6048 h[i+
'p/pt'+z+interval] =h[i+
'p/pt'+z].ProjectionY(i+
'p/pt'+z+interval ,h[i+
'p/pt'+x+
'_x'].FindBin(pInterval[0]),h[i+
'p/pt'+x+
'_x'].FindBin(20.))
6049 tmp = h[i+
'10p/pt'+z].ProjectionY(
'tmp',h[i+
'p/pt'+x+
'_x'].FindBin(20.)+1,h[i+
'p/pt'+x+
'_x'].FindBin(pInterval[1]))
6051 h[i+
'p/pt'+z+interval].Add(tmp)
6052 h[i+
'pz/Abspx'+z+interval]=h[i+
'pz/Abspx'+z].ProjectionY(i+
'pz/Abspx'+z+interval,h[i+
'pz/Abspx'+x+
'_x'].FindBin(pInterval[0]),h[i+
'pz/Abspx'+x+
'_x'].FindBin(20.))
6053 tmp = h[i+
'10pz/Abspx'+z].ProjectionY(
'tmp',h[i+
'pz/Abspx'+x+
'_x'].FindBin(20.)+1,h[i+
'pz/Abspx'+x+
'_x'].FindBin(pInterval[1]))
6054 h[i+
'pz/Abspx'+z+interval].Add(tmp)
6056 h[i+
'p/pt'+z+interval] =h[i+
'p/pt'+z].ProjectionY(i+
'p/pt'+z+interval ,h[i+
'p/pt'+x+
'_x'].FindBin(pInterval[0]),h[i+
'p/pt'+x+
'_x'].FindBin(pInterval[1]))
6057 h[i+
'pz/Abspx'+z+interval]=h[i+
'pz/Abspx'+z].ProjectionY(i+
'pz/Abspx'+z+interval,h[i+
'pz/Abspx'+x+
'_x'].FindBin(pInterval[0]),h[i+
'pz/Abspx'+x+
'_x'].FindBin(pInterval[1]))
6058 h[i+
'p/pt'+z+interval].SetTitle(
'#it{p}_{T} for '+str(pInterval[0])+
' < #it{p} < '+str(pInterval[1]))
6059 h[i+
'pz/Abspx'+z+interval].SetTitle(
'|#it{p}_{X}| for '+str(pInterval[0])+
' < #it{p} < '+str(pInterval[1]))
6061 h[i+
'p/pt'+z+
'_y'] =h[i+
'p/pt'+z].ProjectionY(i+
'p/pt'+z+
'_y' ,h[i+
'p/pt'+x+
'_x'].FindBin(pMin),h[i+
'p/pt'+x+
'_x'].GetNbinsX())
6062 h[i+
'pz/Abspx'+z+
'_y']=h[i+
'pz/Abspx'+z].ProjectionY(i+
'pz/Abspx'+z+
'_y',h[i+
'pz/Abspx'+x+
'_x'].FindBin(pMin),h[i+
'pz/Abspx'+x+
'_x'].GetNbinsX())
6063 for pInterval
in ptInterval:
6064 interval =
'_y'+str(pInterval[0])+
'-'+str(pInterval[1])
6065 h[i+
'p/pt'+z+interval] =h[i+
'p/pt'+z].ProjectionY(i+
'p/pt'+z+interval ,h[i+
'p/pt'+x+
'_x'].FindBin(pInterval[0]),h[i+
'p/pt'+x+
'_x'].FindBin(pInterval[1]))
6066 h[i+
'pz/Abspx'+z+interval]=h[i+
'pz/Abspx'+z].ProjectionY(i+
'pz/Abspx'+z+interval,h[i+
'pz/Abspx'+x+
'_x'].FindBin(pInterval[0]),h[i+
'pz/Abspx'+x+
'_x'].FindBin(pInterval[1]))
6067 h[i+
'p/pt'+z+interval].SetTitle(
'#it{p}_{T} for '+str(pInterval[0])+
' < #it{p}/(GeV/c) < '+str(pInterval[1]))
6068 h[i+
'pz/Abspx'+z+interval].SetTitle(
'|#it{p}_{X}| for '+str(pInterval[0])+
' < #it{p} < '+str(pInterval[1]))
6074 if not i.find(
'MC10')<0:
6076 source = i1.split(
'MC10')[1]
6077 elif not i.find(
'MC')<0:
6079 source = i1.split(
'MC')[1]
6081 for a
in [
'p/pt',
'pz/Abspx']:
6082 if i ==
"MC": hname = i+
'tot'+a+z+
'_x'
6083 elif i ==
"MC10":
continue
6084 else: hname = i+a+z+
'_x'
6085 h[hname+
'original']=h[hname].Clone(hname+
'original')
6086 if not withOverFlow:
6087 for n
in range(h[hname].FindBin(pMax),h[hname].GetNbinsX()+2):
6088 h[hname].SetBinContent(n,0.)
6089 h[hname].SetBinError(n,0.)
6090 ut.makeIntegralDistrib(h,hname,withOverFlow)
6091 h[
'I-'+hname].GetXaxis().SetRangeUser(pMin,pMax)
6093 h[
'I-'+i+a+z+
'_x']=h[
'I-'+hname].Clone(
'I-'+i+a+z+
'_x')
6094 ut.makeIntegralDistrib(h,i+a+z+
'_y',withOverFlow)
6096 h[
'I-'+i+
'p/pt'+z+
'_x'].SetTitle(
' ;x [GeV/c]; #SigmaN/PoT with #it{p}>x')
6097 h[
'I-'+i+
'p/pt'+z+
'_x'].Scale(1./POTdata)
6098 h[
'I-'+i+
'pz/Abspx'+z+
'_x'].SetTitle(
' ;x [GeV/c]; #SigmaN/PoT with #it{p}>x')
6099 h[
'I-'+i+
'pz/Abspx'+z+
'_x'].Scale(1./POTdata)
6100 h[
'I-'+i+
'pz/Abspx'+z+
'_y'].SetTitle(
' ;x [GeV/c]; #SigmaN/PoT with #it{p}_{X}>x')
6101 h[
'I-'+i+
'pz/Abspx'+z+
'_y'].Scale(1./POTdata)
6102 h[
'I-'+i+
'p/pt'+z+
'_y'].SetTitle(
' ;x [GeV/c]; #SigmaN/PoT with #it{p}_{T}>x')
6103 h[
'I-'+i+
'p/pt'+z+
'_y'].Scale(1./POTdata)
6105 bz =
"%iGeV/c"%(h[i+
'p/pt'+z+
'_x'].GetBinWidth(1))
6106 h[i+
'p/pt'+z+
'_x'].SetTitle(
'#it{p} ;#it{p} [GeV/c]; N/'+bz+
'/PoT')
6107 h[i+
'p/pt'+z+
'_x'].Scale(1./POTdata)
6109 bz =
"%iGeV/c"%(h[i+
'pz/Abspx'+z+
'_x'].GetBinWidth(1))
6110 h[i+
'pz/Abspx'+z+
'_x'].SetTitle(
'#it{p}_{z} ;#it{p}_{z} [GeV/c]; N/'+bz+
'/PoT')
6111 h[i+
'pz/Abspx'+z+
'_x'].Scale(1./POTdata)
6113 bz =
"%iMeV/c"%(1000*h[i+
'pz/Abspx'+z+
'_y'].GetBinWidth(1))
6114 h[i+
'pz/Abspx'+z+
'_y'].SetTitle(
'#it{p}_{x} ;#it{p}_{x} [GeV/c]; N/'+bz+
'/PoT')
6115 h[i+
'pz/Abspx'+z+
'_y'].Scale(1./POTdata)
6117 bz =
"%iMeV/c"%(1000*h[i+
'p/pt'+z+
'_y'].GetBinWidth(1))
6118 h[i+
'p/pt'+z+
'_y'].SetTitle(
'#it{p}_{T} ;#it{p}_{T} [GeV/c]; N/'+bz+
'/PoT')
6119 h[i+
'p/pt'+z+
'_y'].Scale(1./POTdata)
6121 ut.bookCanvas(h,
'output',
'',1200,800,1,1)
6124 t = d+
'MC-Comparison'+x
6125 if not h.has_key(t):
6126 ut.bookCanvas(h,key=t,title=d+
' MC / Data '+x,nx=1800,ny=900,cx=4,cy=2)
6127 ut.bookCanvas(h,key=
'simple'+t,title=d+
' MC / Data '+x,nx=1800,ny=900,cx=4,cy=2)
6129 if not withDisplay:
return
6133 rc.SetLeftMargin(0.2)
6134 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.50,0.61,0.96,0.93)
6135 mx1 = ut.findMaximumAndMinimum(h[d+
'pz/Abspx'+x+
'_x'])[1]
6136 mx2 = ut.findMaximumAndMinimum(h[d+
'MCpz/Abspx'+x+
'_x'])[1]
6138 for i1
in optSorted:
6141 if not i.find(
'MC10')<0:
6144 source = i1.split(
'MC10')[1]
6145 elif not i.find(
'MC')<0:
6147 source = i1.split(
'MC')[1]
6149 histo = h[d+i+
'pz/Abspx'+xx+
'_x']
6150 histo.SetMaximum(hMax*5.)
6151 histo.SetLineWidth(1)
6152 histo.SetMarkerSize(1)
6153 histo.SetLineColor(opt[i1][1])
6156 histo.SetMinimum( histo.GetBinContent(histo.FindBin(pMax)-1)*0.01 )
6157 histo.GetXaxis().SetRangeUser(pMin,pMax)
6158 if i ==
'MC' and d==
'': histo.GetXaxis().SetRangeUser(pMin,30.)
6159 if i ==
'MC10': histo.GetXaxis().SetRangeUser(20.,pMax)
6160 if d !=
'': histo.GetXaxis().SetRangeUser(pMin,pMax)
6161 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6162 if noTitle: histo.SetTitle(
'')
6163 histo.Draw(opt[i1][0])
6164 h[
'leg'+t+str(tc)].Draw(
'same')
6168 rc.SetLeftMargin(0.2)
6169 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.42,0.54,0.88,0.86)
6170 for i1
in optSorted:
6173 if not i.find(
'MC10')<0:
6176 source = i1.split(
'MC10')[1]
6177 elif not i.find(
'MC')<0:
6179 source = i1.split(
'MC')[1]
6181 h[
'lin'+d+i+
'pz/Abspx'+xx+
'_x']=h[d+i+
'pz/Abspx'+xx+
'_x'].Clone(
'lin'+d+i+
'pz/Abspx'+xx+
'_x')
6182 histo = h[
'lin'+d+i+
'pz/Abspx'+xx+
'_x']
6183 if i==
'': histo.GetXaxis().SetRangeUser(pMin,120)
6184 if i ==
'MC' and d==
'': histo.GetXaxis().SetRangeUser(pMin,30.)
6185 if i ==
'MC10': histo.GetXaxis().SetRangeUser(20.,pMax)
6186 histo.SetMaximum(hMax*1.1)
6187 histo.SetMinimum(0.)
6188 if noTitle: histo.SetTitle(
'')
6189 histo.Draw(opt[i1][0])
6190 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6191 h[
'leg'+t+str(tc)].Draw(
'same')
6196 rc.SetLeftMargin(0.2)
6197 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.50,0.61,0.96,0.93)
6198 mx1 = ut.findMaximumAndMinimum(h[d+
'pz/Abspx'+x+
'_y'])[1]
6199 mx2 = ut.findMaximumAndMinimum(h[d+
'MCpz/Abspx'+x+
'_y'])[1]
6201 for i1
in optSorted:
6204 if not i.find(
'MC10')<0:
continue
6205 elif not i.find(
'MC')<0:
6207 source = i1.split(
'MC')[1]
6208 if i==
'MC10':
continue
6210 histo = h[d+i+
'pz/Abspx'+xx+
'_y']
6211 histo.SetMaximum(hMax*5.)
6212 histo.SetLineWidth(1)
6213 histo.SetMarkerSize(1)
6214 histo.SetLineColor(opt[i1][1])
6217 histo.SetMinimum( histo.GetBinContent(histo.FindBin(ptMax))*0.01 )
6218 histo.GetXaxis().SetRangeUser(0.,ptMax)
6219 if noTitle: histo.SetTitle(
'')
6220 histo.Draw(opt[i1][0])
6221 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6222 h[
'leg'+t+str(tc)].Draw(
'same')
6226 rc.SetLeftMargin(0.2)
6227 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.42,0.54,0.88,0.86)
6228 for i1
in optSorted:
6231 if not i.find(
'MC10')<0:
continue
6232 elif not i.find(
'MC')<0:
6234 source = i1.split(
'MC')[1]
6235 if i==
'MC10':
continue
6237 h[
'lin'+d+i+
'pz/Abspx'+xx+
'_y']=h[d+i+
'pz/Abspx'+xx+
'_y'].Clone(
'lin'+d+i+
'pz/Abspx'+xx+
'_y')
6238 histo = h[
'lin'+d+i+
'pz/Abspx'+xx+
'_y']
6239 if i==
'': histo.GetXaxis().SetRangeUser(0.,2.)
6240 histo.SetMaximum(hMax*1.1)
6241 histo.SetMinimum(0.)
6242 if noTitle: histo.SetTitle(
'')
6243 histo.Draw(opt[i1][0])
6244 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6245 h[
'leg'+t+str(tc)].Draw(
'same')
6250 rc.SetLeftMargin(0.2)
6251 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.50,0.61,0.96,0.93)
6252 mx1 = ut.findMaximumAndMinimum(h[d+
'p/pt'+x+
'_x'])[1]
6253 mx2 = ut.findMaximumAndMinimum(h[d+
'MCp/pt'+x+
'_x'])[1]
6255 for i1
in optSorted:
6258 if not i.find(
'MC10')<0:
6261 source = i1.split(
'MC10')[1]
6262 elif not i.find(
'MC')<0:
6264 source = i1.split(
'MC')[1]
6266 histo = h[d+i+
'p/pt'+xx+
'_x']
6267 histo.SetMaximum(hMax*5.)
6268 histo.SetLineWidth(1)
6269 histo.SetMarkerSize(1)
6270 histo.SetLineColor(opt[i1][1])
6273 histo.SetMinimum( histo.GetBinContent(histo.FindBin(pMax)-1)*0.01 )
6274 histo.GetXaxis().SetRangeUser(pMin,pMax)
6275 if d !=
'': histo.GetXaxis().SetRangeUser(pMin,pMax)
6276 if i ==
'MC' and d==
'': histo.GetXaxis().SetRangeUser(pMin,30.)
6277 if i ==
'MC10': histo.GetXaxis().SetRangeUser(20.,pMax)
6278 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6279 if noTitle: histo.SetTitle(
'')
6280 histo.Draw(opt[i1][0])
6281 h[
'output'].cd().SetLogy(1)
6282 histo.Draw(opt[i1][0])
6284 h[
'leg'+t+str(tc)].Draw(
'same')
6285 rc = h[
'output'].cd()
6286 h[
'leg'+t+str(tc)].Draw(
'same')
6287 myPrint(h[
'output'],label+d+x+
'_P')
6291 rc.SetLeftMargin(0.2)
6292 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.42,0.54,0.88,0.86)
6293 for i1
in optSorted:
6296 if not i.find(
'MC10')<0:
6299 source = i1.split(
'MC10')[1]
6300 elif not i.find(
'MC')<0:
6302 source = i1.split(
'MC')[1]
6304 h[
'lin'+d+i+
'p/pt'+xx+
'_x']=h[d+i+
'p/pt'+xx+
'_x'].Clone(
'lin'+d+i+
'p/pt'+xx+
'_x')
6305 histo = h[
'lin'+d+i+
'p/pt'+xx+
'_x']
6306 if i==
'': histo.GetXaxis().SetRangeUser(pMin,120)
6307 if i ==
'MC' and d==
'': histo.GetXaxis().SetRangeUser(pMin,30.)
6308 if i ==
'MC10': histo.GetXaxis().SetRangeUser(20.,pMax)
6309 histo.SetMaximum(hMax*1.1)
6310 histo.SetMinimum(0.)
6311 if noTitle: histo.SetTitle(
'')
6312 histo.Draw(opt[i1][0])
6313 h[
'output'].cd().SetLogy(0)
6314 histo.Draw(opt[i1][0])
6316 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6317 h[
'leg'+t+str(tc)].Draw(
'same')
6318 rc = h[
'output'].cd()
6319 h[
'leg'+t+str(tc)].Draw(
'same')
6320 myPrint(h[
'output'],label+d+x+
'_linP')
6325 rc.SetLeftMargin(0.2)
6326 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.50,0.61,0.96,0.93)
6327 mx1 = ut.findMaximumAndMinimum(h[d+
'p/pt'+x+
'_y'])[1]
6328 mx2 = ut.findMaximumAndMinimum(h[d+
'MCp/pt'+x+
'_y'])[1]
6330 for i1
in optSorted:
6333 if not i.find(
'MC10')<0:
continue
6334 elif not i.find(
'MC')<0:
6336 source = i1.split(
'MC')[1]
6337 if i==
'MC10':
continue
6339 histo = h[d+i+
'p/pt'+xx+
'_y']
6340 histo.SetMaximum(hMax*5.)
6341 histo.SetLineWidth(1)
6342 histo.SetMarkerSize(1)
6343 histo.SetLineColor(opt[i1][1])
6346 histo.SetMinimum( histo.GetBinContent(histo.FindBin(ptMax))*0.01 )
6347 histo.GetXaxis().SetRangeUser(0.,ptMax)
6348 if noTitle: histo.SetTitle(
'')
6349 histo.Draw(opt[i1][0])
6350 h[
'output'].cd().SetLogy(1)
6351 histo.Draw(opt[i1][0])
6353 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6354 h[
'leg'+t+str(tc)].Draw(
'same')
6355 rc = h[
'output'].cd()
6356 h[
'leg'+t+str(tc)].Draw(
'same')
6357 myPrint(h[
'output'],label+d+x+
'_Pt')
6361 rc.SetLeftMargin(0.2)
6362 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.42,0.54,0.88,0.86)
6363 for i1
in optSorted:
6366 if not i.find(
'MC10')<0:
continue
6367 elif not i.find(
'MC')<0:
6369 source = i1.split(
'MC')[1]
6370 if i==
'MC10':
continue
6372 h[
'lin'+d+i+
'p/pt'+xx+
'_y']=h[d+i+
'p/pt'+xx+
'_y'].Clone(
'lin'+d+i+
'p/pt'+xx+
'_y')
6373 histo = h[
'lin'+d+i+
'p/pt'+xx+
'_y']
6374 if i==
'': histo.GetXaxis().SetRangeUser(0.,2.)
6375 histo.SetMaximum(hMax*1.1)
6376 histo.SetMinimum(0.)
6377 if noTitle: histo.SetTitle(
'')
6378 histo.Draw(opt[i1][0])
6379 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(histo,opt[i1][2],
'PL')
6380 h[
'output'].cd().SetLogy(0)
6381 histo.Draw(opt[i1][0])
6383 h[
'leg'+t+str(tc)].Draw(
'same')
6386 rc = h[
'output'].cd()
6387 h[
'leg'+t+str(tc)].Draw(
'same')
6388 myPrint(rc,label+d+x+
'_linPt')
6395 rc.SetLeftMargin(0.2)
6396 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6397 for i
in [
'',
'MC',
'MC10']:
6398 if i==
'MC10' and d !=
"":
continue
6401 histo = h[d+i+
'pz/Abspx'+xx+
'_x']
6402 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6403 histo.SetMinimum(1E-10)
6404 if noTitle: histo.SetTitle(
'')
6405 histo.Draw(opt[i][0])
6406 h[
'leg'+ts+str(tc)].Draw(
'same')
6410 rc.SetLeftMargin(0.2)
6411 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6415 histo = h[d+i+
'pz/Abspx'+xx+
'_y']
6416 histo.SetMinimum(1E-10)
6417 if noTitle: histo.SetTitle(
'')
6418 histo.Draw(opt[i][0])
6419 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(h[d+i+
'pz/Abspx'+xx+
'_y'],opt[i][2],
'PL')
6420 h[
'leg'+ts+str(tc)].Draw(
'same')
6425 rc.SetLeftMargin(0.2)
6426 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6428 for i
in [
'',
'MC',
'MC10']:
6429 if i==
'MC10' and d !=
"":
continue
6432 histo = h[d+i+
'p/pt'+xx+
'_x']
6433 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6434 if noTitle: histo.SetTitle(
'')
6435 histo.SetMinimum(1E-10)
6436 histo.Draw(opt[i][0])
6437 h[
'leg'+ts+str(tc)].Draw(
'same')
6438 tx = h[
'dummy'].cd()
6440 for i
in [
'',
'MC',
'MC10']:
6441 if i==
'MC10' and d !=
"":
continue
6444 histo = h[d+i+
'p/pt'+xx+
'_x']
6445 if noTitle: histo.SetTitle(
'')
6446 histo.Draw(opt[i][0])
6447 h[
'leg'+ts+str(tc)].Draw(
'same')
6448 myPrint(h[
'dummy'],label+
'-simple-P'+d+x)
6452 rc.SetLeftMargin(0.2)
6453 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6457 histo = h[d+i+
'p/pt'+xx+
'_y']
6458 if noTitle: histo.SetTitle(
'')
6459 histo.SetMinimum(1E-10)
6460 histo.Draw(opt[i][0])
6461 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6462 h[
'leg'+ts+str(tc)].Draw(
'same')
6463 tx = h[
'dummy'].cd()
6466 if i==
'MC10' and d !=
"":
continue
6469 histo = h[d+i+
'p/pt'+xx+
'_y']
6470 if noTitle: histo.SetTitle(
'')
6471 histo.Draw(opt[i][0])
6472 h[
'leg'+ts+str(tc)].Draw(
'same')
6473 myPrint(h[
'dummy'],label+
'-simple-Pt'+d+x)
6475 rc.SetLeftMargin(0.2)
6477 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6478 for i
in [
'',
'MC',
'MC10']:
6479 if i==
'MC10' and d !=
"":
continue
6482 histo = h[
'lin'+d+i+
'pz/Abspx'+xx+
'_x']
6483 if noTitle: histo.SetTitle(
'')
6484 histo.Draw(opt[i][0])
6485 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6486 h[
'leg'+ts+str(tc)].Draw(
'same')
6489 rc.SetLeftMargin(0.2)
6490 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6494 histo = h[
'lin'+d+i+
'pz/Abspx'+xx+
'_y']
6495 if noTitle: histo.SetTitle(
'')
6496 histo.Draw(opt[i][0])
6497 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6498 h[
'leg'+ts+str(tc)].Draw(
'same')
6501 rc.SetLeftMargin(0.2)
6502 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6503 for i
in [
'',
'MC',
'MC10']:
6504 if i==
'MC10' and d !=
"":
continue
6507 histo = h[
'lin'+d+i+
'p/pt'+xx+
'_x']
6508 if noTitle: histo.SetTitle(
'')
6509 histo.Draw(opt[i][0])
6510 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6511 h[
'leg'+ts+str(tc)].Draw(
'same')
6513 rc.SetLeftMargin(0.2)
6515 h[
'leg'+ts+str(tc)]=ROOT.TLegend(0.50,0.68,0.88,0.88)
6519 histo = h[
'lin'+d+i+
'p/pt'+xx+
'_y']
6520 if noTitle: histo.SetTitle(
'')
6521 histo.Draw(opt[i][0])
6522 if i.find(
'MC10')<0: h[
'leg'+ts+str(tc)].AddEntry(histo,opt[i][2],
'PL')
6523 h[
'leg'+ts+str(tc)].Draw(
'same')
6525 myPrint(h[ts],label+
'-simple-'+d+x)
6526 for Aproj
in [
'p/pt']:
6531 if x !=
'':
print "=== muon tagged ===="
6532 else:
print "=== all tracks ===="
6533 for P
in [5.,10.,50.,100.,150.,200.,300.]:
6534 nbin = h[Aproj+x+
'_x'].FindBin(P)
6535 print "data/MC P>%5i GeV: %5.2F"%(int(P),h[
'I-'+Aproj+x+
'_x'].GetBinContent(nbin-1)/h[
'I-MC'+Aproj+x+
'_x'].GetBinContent(nbin-1))
6536 n5 = h[Aproj+x+
'_x'].FindBin(5.)
6537 n300 = h[Aproj+x+
'_x'].FindBin(300.)
6538 n450 = h[Aproj+x+
'_x'].FindBin(450.)
6539 n480 = h[Aproj+x+
'_x'].FindBin(480.)
6540 n500 = h[Aproj+x+
'_x'].FindBin(500.)
6541 ghostRateMC = h[
'MCtot'+Aproj+x+
'_xoriginal'].Integral(n450,n500-1)/20.*295./h[
'MCtot'+Aproj+x+
'_xoriginal'].Integral(n5,n300)
6542 ghostRateData = h[Aproj+x+
'_xoriginal'].Integral(n450,n500-1)/20.*295./h[Aproj+x+
'_xoriginal'].Integral(n5,n300)
6543 print "ghostRate MC: %5.2FperMille ghostRate Data: %5.2FperMille"%(ghostRateMC*1000,ghostRateData*1000)
6545 ratioGhostsMC = h[
'MCtot'+Aproj+x+
'_xoriginal'].Integral(n450,n500-1)/h[
'MCtot'+Aproj+x+
'_xoriginal'].Integral(n450,n500)
6546 ratioGhostsData = h[Aproj+x+
'_xoriginal'].Integral(n450,n500-1)/h[Aproj+x+
'_xoriginal'].Integral(n450,n500)
6547 ratioGhostsDataMC = h[Aproj+x+
'_xoriginal'].Integral(n450,n500-1)/h[
'MCtot'+Aproj+x+
'_xoriginal'].Integral(n450,n500-1)
6548 print "tracks [450-500]/[>450] = MC: %5.2F, data: %5.2F. Absolute data/MC=%5.2F"%(ratioGhostsMC,ratioGhostsData,ratioGhostsDataMC)
6551 for xx
in [x+
'_x',x+
'_y']:
6552 h[
'I-'+proj+xx+
'Ratio'] =h[
'I-'+proj+xx].Clone(
'I-'+proj+xx+
'Ratio')
6553 h[
'I-'+proj+xx+
'RatioG4'] =h[
'I-'+proj+xx].Clone(
'I-'+proj+xx+
'RatioG4')
6554 h[
'I-'+proj+xx+
'RatioG4noCharm']=h[
'I-'+proj+xx].Clone(
'I-'+proj+
''+x+
'_xRatioG4noCharm')
6556 h[mc+proj+xx+
'G4'] =h[mc+proj+xx].Clone(mc+proj+xx+
'G4')
6557 h[mc+proj+xx+
'G4'].Add(h[mc+proj+xx.replace(
'_',
'Hadronic inelastic_')],-1.)
6558 h[mc+proj+xx+
'G4noCharm']=h[mc+proj+xx].Clone(
'I-MC'+proj+
''+x+
'_xG4noCharm')
6559 h[mc+proj+xx+
'G4noCharm'].Add(h[mc+proj+xx.replace(
'_',
'Hadronic inelastic_')],-1.)
6560 h[mc+proj+xx+
'G4noCharm'].Add(h[mc+proj+xx.replace(
'_',
'charm_')],-1.)
6561 for c
in [
'',
'G4',
'G4noCharm']:
6562 ratio = h[
'I-'+proj+xx+
'Ratio'+c]
6563 for mx
in range(1,ratio.GetNbinsX()+1):
6564 Nmc = h[
'I-MC'+proj+xx+c].GetBinContent(mx)
6565 ratio.SetBinContent(mx,ratio.GetBinContent(mx)/Nmc)
6566 if withAllTracks
and x ==
'':
continue
6567 t =
'MC-Comparison ratios'+proj+xx
6568 if not h.has_key(t):
6569 ut.bookCanvas(h,key=t,title=
'Data / MC',nx=900,ny=600,cx=1,cy=1)
6571 h[
'leg'+t]=ROOT.TLegend(0.11,0.67,0.56,0.86)
6572 histo = h[
'I-'+proj+xx+
'Ratio']
6573 histo.SetLineColor(ROOT.kBlue)
6574 histo.SetMaximum(3.)
6576 histo.GetXaxis().SetRangeUser(0.,ptMax)
6578 histo.GetXaxis().SetRangeUser(pMin,pMax)
6579 histo.SetMinimum(0.0)
6580 histo.SetTitle(
'Ratio Data/MC '+h[
'I-'+proj+xx+
'Ratio'].GetTitle())
6581 if noTitle: histo.SetTitle(
'')
6583 h[
'leg'+t].AddEntry(histo,
'Ratio Data / MC muon tagged tracks',
'PL')
6584 histo = h[
'I-'+proj+xx+
'RatioG4']
6585 histo.SetLineColor(ROOT.kMagenta)
6586 if noTitle: histo.SetTitle(
'')
6587 histo.SetMaximum(3.)
6588 if noTitle: histo.SetTitle(
'')
6590 h[
'leg'+t].AddEntry(histo,
'muon tagged tracks no G4 dimuon ',
'PL')
6591 histo = h[
'I-'+proj+xx+
'RatioG4noCharm']
6592 histo.SetLineColor(ROOT.kCyan)
6593 histo.SetMaximum(3.)
6595 h[
'leg'+t].AddEntry(histo,
'muon tagged tracks no G4 dimuon no charm ',
'PL')
6596 if noTitle: histo.SetTitle(
'')
6597 h[
'leg'+t].Draw(
'same')
6598 myPrint(h[t],label+
'Ratios'+Aproj.replace(
'/',
''))
6601 t =
'MC-Comparison ratios'+proj+
'2D'
6602 if not h.has_key(t):
6603 ut.bookCanvas(h,key=t,title=
'Data / MC',nx=1800,ny=900,cx=1,cy=1)
6605 ROOT.gStyle.SetPaintTextFormat(
"5.2f")
6607 hname =
'MCtot'+proj+x
6608 h[hname]=h[
'MC'+proj+x].Clone(hname)
6610 h[
'Data'+proj+x]=h[proj+x].Clone(
'Data'+proj+x)
6611 tmpx = h[hname].ProjectionX()
6612 tmpy = h[hname].ProjectionY()
6613 for mx
in range(1,h[hname].GetNbinsX()+1):
6614 for my
in range(1,h[hname].GetNbinsY()+1):
6615 if tmpx.GetBinCenter(mx)<5.:
6616 h[
'Data'+proj+x].SetBinContent(mx,my,0.)
6617 h[
'Data'+proj+x].SetBinError(mx,my,0.)
6618 elif tmpx.GetBinCenter(mx)<20.:
6619 h[hname].SetBinContent(mx,my,h[
'MC'+proj+x].GetBinContent(mx,my))
6620 h[hname].SetBinError(mx,my,h[
'MC'+proj+x].GetBinError(mx,my))
6622 h[hname].SetBinContent(mx,my,h[
'MC10'+proj+x].GetBinContent(mx,my))
6623 h[hname].SetBinError(mx,my,h[
'MC10'+proj+x].GetBinError(mx,my))
6624 h[
'Data'+proj+x+
'rebin'] = h[proj+x].Rebin2D(25,5,
'Data'+proj+x+
'rebin')
6625 h[
'MC'+proj+x+
'rebin'] = h[hname].Rebin2D(25,5,
'MC'+proj+x+
'rebin')
6626 h[proj+x+
'Ratio']=h[
'MC'+proj+x+
'rebin'].Clone(proj+x+
'Ratio')
6627 for mx
in range(1,h[proj+x+
'Ratio'].GetNbinsX()+1):
6628 for my
in range(1,h[proj+x+
'Ratio'].GetNbinsY()+1):
6629 Nmc = h[
'MC'+proj+x+
'rebin'].GetBinContent(mx,my)
6630 Nda = h[
'Data'+proj+x+
'rebin'].GetBinContent(mx,my)
6631 eNmc = h[
'MC'+proj+x+
'rebin'].GetBinError(mx,my)
6632 eNda = h[proj+x+
'Ratio'].GetBinError(mx,my)
6633 if Nmc>10
and Nda>10:
6635 R = (Nda-Nmc)/(Nda+Nmc)
6636 sig_data = ROOT.TMath.Sqrt(eNda**2+(Nda*daSysError)**2)
6637 sig_MC = ROOT.TMath.Sqrt(eNmc**2+(Nmc*mcSysError)**2)
6638 e1 = 2*Nda/(Nda+Nmc)**2
6639 e2 = 2*Nmc/(Nda+Nmc)**2
6640 eR = ROOT.TMath.Sqrt( (e1*sig_MC)**2+(e2*sig_data)**2 )
6643 eR = ROOT.TMath.Sqrt( (R/Nmc*eNmc)**2+(R/Nda*eNda)**2 )
6647 h[proj+x+
'Ratio'].SetBinContent(mx,my,R)
6648 h[proj+x+
'Ratio'].SetBinError(mx,my,eR)
6649 histo = h[proj+x+
'Ratio']
6650 histo.SetMinimum(-1.)
6651 histo.SetMaximum(+1.)
6652 histo.GetXaxis().SetRangeUser(pMin,pMax)
6653 histo.GetYaxis().SetRangeUser(0.,ptMax)
6655 histo.SetMarkerSize(1.2)
6656 if noTitle: histo.SetTitle(
'')
6658 myPrint(h[t],label+
'Ratios2D'+proj.replace(
'/',
''))
6661 if not h.has_key(t):
6662 ut.bookCanvas(h,key=t,title=
'Data',nx=1200,ny=900,cx=1,cy=1)
6666 histo.SetMinimum(0.)
6667 histo.SetMaximum(5.E6)
6668 histo.GetXaxis().SetRangeUser(0,pMax)
6669 histo.GetYaxis().SetRangeUser(0,ptMax-0.1)
6670 histo.GetXaxis().SetTitleOffset(1.7)
6671 histo.GetXaxis().SetTitle(
' #it{p} [GeV/c]')
6672 histo.GetYaxis().SetTitle(
' #it{p}_{T} [GeV/c] ')
6673 histo.GetYaxis().SetTitleOffset(1.7)
6677 if noTitle: histo.SetTitle(
'')
6682 for t
in [
'MC-Comparison Pt']:
6683 if not h.has_key(t):
6684 if pMax > 310: ut.bookCanvas(h,key=t,title=
' MC / Data '+t.split(
' ')[1],nx=1800,ny=900,cx=6,cy=2)
6685 else: ut.bookCanvas(h,key=t,title=
' MC / Data '+t.split(
' ')[1],nx=1800,ny=900,cx=5,cy=2)
6687 for pInterval
in ptInterval:
6688 if pInterval[1] > pMax:
continue
6689 if pInterval[1]<11: x =
''
6691 interval =
'_y'+str(pInterval[0])+
'-'+str(pInterval[1])
6693 rebinValue = ptIntervalRebin[y-1]
6695 h[
'leg'+t+str(tc)]=ROOT.TLegend(0.42,0.54,0.88,0.86)
6696 for i1
in optSorted:
6699 if not i.find(
'MC10')<0:
6701 source = i1.split(
'MC10')[1]
6702 elif not i.find(
'MC')<0:
6704 source = i1.split(
'MC')[1]
6705 if i==
'MC10':
continue
6708 if t.find(
'Px')>0: proj =
'pz/Abspx'
6709 hname = i+proj+xx+interval
6710 mx1 = ut.findMaximumAndMinimum(h[ proj+x+interval])[1]
6711 mx2 = ut.findMaximumAndMinimum(h[
'MC'+proj+x+interval])[1]
6712 hMaPx = max(mx1,mx2)
6714 h[hname].Rebin(rebinValue)
6715 h[hname].Scale(1./rebinValue)
6716 h[hname].GetXaxis().SetRangeUser(0.,ptMax)
6717 h[hname].SetMaximum(hMaPx*1.1)
6718 h[hname].SetMinimum(0.)
6719 h[hname].SetStats(0)
6720 h[hname].SetLineWidth(1)
6721 h[hname].SetMarkerSize(1)
6722 h[hname].SetLineColor(opt[i1][1])
6723 h[hname].Draw(opt[i][0])
6724 if i.find(
'MC10')<0: h[
'leg'+t+str(tc)].AddEntry(h[hname],opt[i1][2],
'PL')
6725 h[
'leg'+t+str(tc)].Draw(
'same')
6727 myPrint(h[t],label+t.replace(
'MC-Comparison ',
''))
6729 print " interval data MC ratio data/MC charm per 1E9 PoT / GeV/c "
6730 for pInterval
in ptInterval:
6731 if pInterval[1]<11: x =
''
6733 interval =
'_y'+str(pInterval[0])+
'-'+str(pInterval[1])
6735 hname = proj+x+interval
6737 data = h[hname].IntegralAndError(0,h[hname].FindBin(ptMax),err)/POTdata/(pInterval[1]-pInterval[0])*1E9
6738 sig_data=err/POTdata/(pInterval[1]-pInterval[0])*1E9
6739 sig_data = ROOT.TMath.Sqrt(sig_data**2+(data*daSysError)**2)
6740 mc = h[
'MC'+hname].IntegralAndError(0,h[hname].FindBin(ptMax),err)/POTdata/(pInterval[1]-pInterval[0])*1E9
6741 sig_MC = err/POTdata/(pInterval[1]-pInterval[0])*1E9
6742 sig_MC = ROOT.TMath.Sqrt(sig_MC**2+(mc*mcSysError)**2)
6743 mcCharm = h[
'MC'+hname.replace(
'_y',
'charm_y')].IntegralAndError(0,h[hname].FindBin(ptMax),err)/POTdata/(pInterval[1]-pInterval[0])*1E9
6745 sig_ratio = ROOT.TMath.Sqrt( (ratio/data*sig_data)**2+(ratio/mc*sig_MC)**2)
6746 sig_Charm=err/POTdata/(pInterval[1]-pInterval[0])*1E9
6747 sig_Charm=ROOT.TMath.Sqrt(sig_Charm**2+(mcCharm*mcSysError)**2)
6748 print "%11s %7.2E +/- %7.2E %7.2E +/- %7.2E %5.2F +/- %5.2F %6.2E +/- %6.2E"%(str(pInterval[0])+
'-'+str(pInterval[1]),data,sig_data,mc,sig_MC,ratio,sig_ratio,mcCharm,sig_Charm)
6750 print " interval data MC charm mean PT [GeV/c] "
6751 for pInterval
in ptInterval:
6752 if pInterval[1]<11: x =
''
6754 interval =
'_y'+str(pInterval[0])+
'-'+str(pInterval[1])
6756 hname = proj+x+interval
6757 data = h[hname].GetMean()
6758 mc = h[
'MC'+hname].GetMean()
6759 mcCharm = h[
'MC'+hname.replace(
'_y',
'charm_y')].GetMean()
6760 print "%11s %5.2G %5.2G %5.2G "%(str(pInterval[0])+
'-'+str(pInterval[1]),data,mc,mcCharm)
6763 osign = {
'':
'opposite sign',
's':
'same sign'}
6764 txt = {6:
'P>5GeV/c',21:
'P>20GeV/c'}
6770 t =
'2trackOverAll'+osign[s]+txt[case]
6771 if not h.has_key(t): ut.bookCanvas(h,key=t,title=
' momentum of muons in 2-track events '+osign[s],nx=800,ny=800,cx=1,cy=1)
6773 h[
'leg'+t+str(pad)+s]=ROOT.TLegend(0.42,0.54,0.88,0.86)
6774 hn =
'p1p2'+txt[case]+s
6775 h[hn] = h[
'p1/p2'+s].ProjectionX(hn,case,h[
'p1/p2'+s].GetYaxis().FindBin(pMax))
6776 h[hn].Add(h[
'p1/p2'+s].ProjectionY(
'p1p2y'+txt[case]+s,case,h[
'p1/p2'+s].GetXaxis().FindBin(pMax)) )
6777 if rebin>1: h[hn].Rebin(rebin)
6778 norm = h[
'p/ptmu_x'].Integral(case,h[
'p/ptmu_x'].FindBin(pMax))*POTdata
6779 h[hn].Scale(1./norm)
6780 h[hn].SetTitle(
'P in 2-track events '+txt[case]+
'; GeV/c;N2/Nall with P > / ')
6782 h[hn].SetMaximum(0.5)
6783 h[hn].SetMinimum(2E-6)
6784 ut.makeIntegralDistrib(h,hn,withOverFlow)
6786 h[Ihn].GetXaxis().SetRangeUser(case,pLimit)
6787 if noTitle: h[Ihn].SetTitle(
'')
6789 h[
'leg'+t+str(pad)+s].AddEntry(h[hn],opt[
''][2],
'PL')
6792 if case < 20: mchist =
'MCp1/p2'+s
6793 else: mchist =
'MC10p1/p2'+s
6794 hn=
'MCp1p2'+txt[case]+s
6795 h[hn] = h[mchist].ProjectionX(hn,case,h[mchist].GetYaxis().FindBin(pMax))
6796 h[hn].Add(h[mchist].ProjectionY(
'MCp1p2y'+txt[case]+s,case,h[mchist].GetYaxis().FindBin(pMax)) )
6797 if rebin>1: h[hn].Rebin(rebin)
6798 if case < 20: norm = h[
'MCp/ptmu_x'].Integral(case,h[
'MCp/ptmu_x'].FindBin(pMax))*POTdata
6799 else: norm = h[
'MC10p/ptmu_x'].Integral(case,h[
'MC10p/ptmu_x'].FindBin(pMax))*POTdata
6800 h[hn].Scale(1./norm)
6802 h[hn].SetTitle(
'P in 2-track events, one track with '+txt[case]+
'; GeV/c')
6803 h[hn].SetLineColor(opt[
'MC'][1])
6804 ut.makeIntegralDistrib(h,hn,withOverFlow)
6806 if noTitle: h[Ihn].SetTitle(
'')
6808 h[Ihn].GetXaxis().SetRangeUser(case,pLimit)
6809 h[
'leg'+t+str(pad)+s].AddEntry(h[hn],opt[
'MC'][2],
'PL')
6811 for i1
in optSorted:
6812 if i1.find(
'MC')<0:
continue
6813 if i1.find(
'MC10')<0
and case==21:
continue
6814 if not i1.find(
'MC10')<0
and case==6:
continue
6815 if not i1.find(
'MC10')<0:
6817 source = i1.split(
'MC10')[1]
6818 elif not i.find(
'MC')<0:
6820 source = i1.split(
'MC')[1]
6821 if source ==
'':
continue
6822 hn=
'MCp1p2'+source+txt[case]+s
6823 h[hn] = h[i+
'p1/p2'+s+source].ProjectionX(hn,case,h[i+
'p1/p2'+s+source].GetYaxis().FindBin(pMax))
6824 h[hn].Add(h[i+
'p1/p2'+s+source].ProjectionY(i+
'p1/p2y'+source+txt[case]+s,case,h[i+
'p1/p2'+s+source].GetXaxis().FindBin(pMax)))
6825 if rebin>1: h[hn].Rebin(5)
6826 h[hn].SetLineColor(opt[i1][1])
6828 h[hn].Scale(1./norm)
6829 ut.makeIntegralDistrib(h,hn,withOverFlow)
6831 if noTitle: h[Ihn].SetTitle(
'')
6833 h[Ihn].GetXaxis().SetRangeUser(case,pMax)
6834 h[
'leg'+t+str(pad)+s].AddEntry(h[hn],opt[i1][2],
'PL')
6835 h[
'leg'+t+str(pad)+s].Draw(
'same')
6837 myPrint(h[t],label+
'2Tracks'+osign[s]+str(case))
6839 for x
in [
'MC-ComparisonChi2mu_*P*.pdf',
'MC-ComparisonPt_*.pdf',
'True-RecoP*.pdf',
'MC-ComparisonChi2Ratios2Dppt.pdf',
'MC-ComparisonChi2DatapPt.pdf']:
6840 os.system(
'cp '+x+
' /mnt/hgfs/Images/VMgate/muflux/ ')
6843 t=
'MC-Comparison Pt'
6844 tx = h[
'dummy'].cd()
6846 for c
in h[t].GetListOfPrimitives():
6849 for p
in c.GetListOfPrimitives():
6850 if p.GetName().find(
'p/pt')==0: histos[1]=p
6851 elif p.GetName().find(
'MCp/pt')==0:
6854 elif p.GetTitle().find(
'Legend')==0:histos[0]=p
6856 histos[1].Draw(
'histsame')
6857 for i
in range(k): histos[i].Draw(
'same')
6859 myPrint(h[
'dummy'],c.GetName().replace(
' ',
''))
6862 charmNorm = {1:0.176,10:0.424}
6863 beautyNorm = {1:0., 10:0.01218}
6864 sources = {
"":1.,
"Hadronic inelastic":100.,
"Lepton pair":100.,
"Positron annihilation":100.,
"charm":1./charmNorm[10],
"beauty":1./beautyNorm[10],
"Di-muon P8":100.}
6865 print " source P>5GeV/c P>20GeV/c"
6869 hname = d+i+
'p/pt'+xx+
'_x'
6870 hname10 = d+i+
'10p/pt'+xx+
'_x'
6871 if not h.has_key(hname):
continue
6872 ratio = h[hname].GetBinContent(1)/h[d+i+
'p/pt_x'].GetBinContent(1)*100
6873 ratio10 = h[hname10].GetBinContent(21)/h[d+i+
'10p/pt_x'].GetBinContent(21)*100
6874 print " %25s %4.2F%% %4.2F%% "%(xx,ratio,ratio10)
6880 ut.readHists(h,
"HitmapsFromFittedTracks-"+MC+
"-mbias.root")
6882 f = ROOT.TFile(
'TCanvas-HitmapsFromFittedTracks-'+MC+
'-mbias.root',
'recreate')
6885 for s
in range(1,5):
6888 xLayers[s][p][l][
'_x'].Reset()
6889 if s==1: xLayers[s][p][l][
'_u'].Reset()
6890 if s==2: xLayers[s][p][l][
'_v'].Reset()
6892 ut.readHists(h,
"histos-HitmapsFromFittedTracks-"+rname)
6894 h[
'fMC'+t]=ROOT.TFile(
'TCanvas-HitmapsFromFittedTracks-'+MC+
'-mbias.root')
6895 h[
'TMC'+t]= h[
'fMC'+t].GetListOfKeys()[0].ReadObj()
6896 for n
in range(1,25):
6898 tmp = h[
'TMC'+t].GetPad(n)
6899 for obj
in tmp.GetListOfPrimitives():
6900 if obj.Class().GetName().find(
'TH1')<0:
continue
6901 NMC = obj.GetEntries()
6902 NDA = tc.FindObject(obj.GetName()).GetEntries()
6904 newName =
'MC'+obj.GetName()
6905 h[newName]=obj.Clone(newName)
6906 h[newName].SetLineColor(ROOT.kRed)
6907 h[newName].Draw(
'histsame')
6908 myPrint(h[t],
'MCcomparison-hitmaps')
6912 for n
in range(sTree.GetEntries()):
6913 rc=sTree.GetEvent(n)
6914 if n%10000==0:
print n
6916 for m
in sTree.MCTrack:
6917 if abs(m.GetPdgCode())==13:
6919 p = m.GetProcName().Data()
6920 if not muon.has_key(p): muon[p]=0
6923 print "MCchecks",sTree.GetCurrentFile().GetName()
6924 sTree.MCTrack.Dump()
6926 if not mult.has_key(p): mult[p]={}
6928 if not mult[p].has_key(N): mult[p][N]=0
6933 NfitTracks_refitted = [0,0]
6934 EventsWithTracks = [0,0]
6937 if event.FitTracks.GetEntries()>0: EventsWithTracks[0]+=1
6938 if event.FitTracks_refitted.GetEntries()>0: EventsWithTracks[1]+=1
6939 NfitTracks[0] +=event.FitTracks.GetEntries()
6940 NfitTracks_refitted[0]+=event.FitTracks_refitted.GetEntries()
6941 for atrack
in sTree.FitTracks:
6942 fst = atrack.getFitStatus()
6943 if fst.isFitConverged(): NfitTracks[1]+=1
6944 for atrack
in sTree.FitTracks_refitted:
6945 fst = atrack.getFitStatus()
6946 if fst.isFitConverged(): NfitTracks_refitted[1]+=1
6947 print "run, number of original tracks",sTree.GetCurrentFile(),NfitTracks,
" number of refitted tracks",NfitTracks_refitted,
" lumi:",EventsWithTracks
6949 for r
in os.listdir(
'.'):
6950 if not r.find(
'RUN_8000_')==0:
continue
6951 for l
in os.listdir(r):
6954 tmp = txt[len(txt)-1].split(
'[')
6955 if tmp[0].find(
'run')!=0:
continue
6956 fitted = tmp[1].split(
']')[0]
6957 NfitTracks[0] += int(fitted.split(
',')[0])
6958 NfitTracks[1] += int(fitted.split(
',')[1])
6959 refitted = tmp[2].split(
']')[0]
6960 NfitTracks_refitted[0] += int(refitted.split(
',')[0])
6961 NfitTracks_refitted[1] += int(refitted.split(
',')[1])
6962 refitted = tmp[3].split(
']')[0]
6963 EventsWithTracks[0] += int(refitted.split(
',')[0])
6964 EventsWithTracks[1] += int(refitted.split(
',')[1])
6965 print "number of original tracks",NfitTracks,
" number of refitted tracks",NfitTracks_refitted,
" lumi counts:",EventsWithTracks
6966 print "ratios",NfitTracks_refitted[0]/float(NfitTracks[0]),NfitTracks_refitted[1]/float(NfitTracks[1]),EventsWithTracks[1]/float(EventsWithTracks[0])
6973 noField = [2199,2200,2201]
6974 intermediateField = [2383,2388,2389,2390,2392,2395,2396]
6975 noTracks = [2334, 2335, 2336, 2337, 2345, 2389,2390]
6976 ROOT.gStyle.SetPalette(ROOT.kGreenPink)
6977 interestingHistos=[
'Trscalers',
'p/pt',
'p/ptmu']
6979 keyword =
'RUN_8000_2'
6980 temp = os.listdir(
'.')
6982 if x.find(keyword)<0:
continue
6983 if not os.path.isdir(x):
continue
6984 r = int(x[x.rfind(
'/')+1:].split(
'_')[2])
6985 if r
in noField:
continue
6986 if not hruns.has_key(r):
6989 ut.readHists(hruns[r],
'momDistributions-'+r+
'.root',interestingHistos)
6992 if not hruns.has_key(r):
6994 ut.readHists(hruns[r],
'momDistributions_RUN_8000_'+str(r)+
'.root')
6998 if not h.has_key(
'RunComparison'):
6999 ut.bookCanvas(h,key=
'RunComparison',title=
'Momentum',nx=1600,ny=1200,cx=1,cy=0)
7000 ut.bookCanvas(h,key=
'EventStatistics',title=
'Event Statistics',nx=1800,ny=800,cx=1,cy=0)
7001 ut.bookHist(h,
'HEventStatistics',
'Event Statistics;run number',100,2000,3000)
7002 h[
'legRunComparison']=ROOT.TLegend(0.35,0.16,0.86,0.46)
7003 tc = h[
'RunComparison'].cd(1)
7007 hname =
'p/pt_projx'
7008 if not hruns[r].has_key(
'Trscalers'):
7009 print "!!!!! no entry for RUN",r
7011 print ">>>>>> statistics for RUN",r
7012 N = hruns[r][
'Trscalers'].GetBinContent(1)
7013 print "number of events",hruns[r][
'Trscalers'].GetBinContent(1)
7014 print "events with tracks %5.2F%%"%(hruns[r][
'Trscalers'].GetBinContent(2)/hruns[r][
'Trscalers'].GetBinContent(1)*100)
7015 print "tracks/event %5.2F%%"%(hruns[r][
'Trscalers'].GetBinContent(3)/hruns[r][
'Trscalers'].GetBinContent(1)*100)
7016 print "ratio of muon tagged tracks / all tracks %5.2F%%"%(hruns[r][
'p/ptmu'].GetEntries()/(hruns[r][
'p/pt'].GetEntries()+1E-6))
7017 print "mean p %5.2F GeV/c, rms %5.2F GeV/c"%(hruns[r][hname].GetMean(),hruns[r][hname].GetRMS())
7018 eventStats[r]=[hruns[r][
'Trscalers'].GetBinContent(2)/hruns[r][
'Trscalers'].GetBinContent(1),
7019 hruns[r][
'Trscalers'].GetBinContent(3)/hruns[r][
'Trscalers'].GetBinContent(1),
7020 hruns[r][hname].GetMean(),
7021 hruns[r][
'Trscalers'].GetBinContent(2),
7022 hruns[r][
'p/ptmu'].GetEntries()/(hruns[r][
'p/pt'].GetEntries()+1E-6)]
7023 hruns[r][hname].Scale(1/N)
7024 hruns[r][hname].SetLineWidth(3)
7025 hruns[r][hname].SetStats(0)
7026 hruns[r][hname].SetTitle(str(r))
7028 hruns[r][hname].Draw(
'PLC PMC')
7030 else: hruns[r][hname].Draw(
'same PLC PMC')
7031 h[
'legRunComparison'].AddEntry(hruns[r][hname],str(r),
'PL')
7034 tc = h[
'EventStatistics'].cd(1)
7035 h[
'eventStats1']=ROOT.TGraph(len(eventStats))
7036 h[
'eventStats2']=ROOT.TGraph(len(eventStats))
7037 h[
'eventStats3']=ROOT.TGraph(len(eventStats))
7038 h[
'eventStats4']=ROOT.TGraph(len(eventStats))
7040 for r
in eventStats:
7041 h[
'eventStats1'].SetPoint(n,r,eventStats[r][0])
7042 h[
'eventStats2'].SetPoint(n,r,eventStats[r][1])
7043 h[
'eventStats3'].SetPoint(n,r,eventStats[r][2]/100.)
7044 h[
'eventStats4'].SetPoint(n,r,eventStats[r][4]/5.)
7047 h[
'legruns']=ROOT.TLegend(0.35,0.12,0.86,0.42)
7048 h[
'eventStats1'].SetMarkerColor(ROOT.kBlue)
7049 h[
'eventStats1'].SetMarkerSize(1.5)
7050 h[
'eventStats1'].SetMarkerStyle(34)
7051 h[
'eventStats2'].SetMarkerColor(ROOT.kBlue-4)
7052 h[
'eventStats2'].SetMarkerSize(1.5)
7053 h[
'eventStats2'].SetMarkerStyle(24)
7054 h[
'eventStats2'].SetMarkerColor(3)
7055 h[
'eventStats3'].SetMarkerColor(ROOT.kRed)
7056 h[
'eventStats3'].SetMarkerSize(1.0)
7057 h[
'eventStats3'].SetMarkerStyle(47)
7058 h[
'eventStats4'].SetMarkerColor(ROOT.kMagenta)
7059 h[
'eventStats4'].SetMarkerSize(1.5)
7060 h[
'eventStats4'].SetMarkerStyle(29)
7061 h[
'eventStats1'].SetTitle(
'Run statistics Data Quality')
7062 h[
'eventStats1'].SetMinimum(-0.01)
7063 h[
'eventStats1'].SetMaximum(0.25)
7064 h[
'eventStats1'].Draw(
'AP')
7065 lg = h[
'legruns'].AddEntry(h[
'eventStats1'],
'N events with tracks / N events',
'PL')
7066 lg.SetTextColor(h[
'eventStats1'].GetMarkerColor())
7068 lg = h[
'legruns'].AddEntry(h[
'eventStats3'],
'mean momentum [GeV /100]',
'PL')
7069 lg.SetTextColor(h[
'eventStats1'].GetMarkerColor())
7070 lg = h[
'legruns'].AddEntry(h[
'eventStats4'],
'N of mu tracks / N of tracks /5',
'PL')
7071 lg.SetTextColor(h[
'eventStats1'].GetMarkerColor())
7073 h[
'eventStats3'].Draw(
'P')
7074 h[
'eventStats4'].Draw(
'P')
7075 h[
'legruns'].Draw(
'same')
7076 myPrint(h[
'EventStatistics'],
'DataQualityPlot')
7079 h[
'f']=ROOT.TFile.Open(os.environ[
'EOSSHIP']+
'/eos/experiment/ship/user/odurhan/muflux-recodata/RUN_8000_2278/SPILLDATA_8000_0517453245_20180719_082409_RT.root')
7081 h[
'tMinAndTmax'] = upkl.load(
'tMinAndTmax')
7083 h[
'TDCMapsX'] = h[
'f'].histos.Get(
'TDCMapsX').Clone(
'TDCMapsX')
7084 h[
'TDCMapsX'].Draw()
7085 h[
'TDCMapsX'].Update()
7086 for p
in h[
'TDCMapsX'].GetListOfPrimitives():
7088 if t.find(
"TDCMapsX")<0:
continue
7089 h[
'Pad'+t] = p.Clone(
'Pad'+t)
7090 if len(h[
'Pad'+t].GetListOfPrimitives())<2:
continue
7091 n = h[
'Pad'+t].GetListOfPrimitives()[1].GetName()
7092 h[
'x'+n] = h[
'Pad'+t].GetListOfPrimitives()[1].Clone(
'x'+n)
7093 h[
'x'+n].SetTitle(
"Group "+str(n)+
'; TDC [ns]')
7095 ut.bookCanvas(h,
'TDC1example',
' ',1200,600,1,1)
7096 ut.bookCanvas(h,key=
'TDCMaps',title=
'TDC Maps All Layers',nx=3*1600,ny=3*1200,cx=5,cy=9)
7099 if x
in [16 ,17, 30, 31]:
continue
7101 if not h.has_key(
'xTDC'+str(x)):
continue
7104 tmin = h[
'tMinAndTmax'][
'TDC'+str(x)][0]
7105 tmax = h[
'tMinAndTmax'][
'TDC'+str(x)][1]
7106 h[z+
'tMin'] = ROOT.TArrow(tmin,-5.,tmin,0.8,0.05,
">")
7107 h[z+
'tMax'] = ROOT.TArrow(tmax,-5.,tmax,0.8,0.05,
">")
7108 h[z+
'tMin'].SetLineColor(ROOT.kRed)
7109 h[z+
'tMax'].SetLineColor(ROOT.kRed)
7112 h[
'TDC1example'].cd()
7116 myPrint(h[
'TDC1example'],
'xTDC'+str(x))
7118 h[
'TDCMaps'].Update()
7119 myPrint(h[
'TDCMaps'],
'TDCMaps')
7121 ut.bookCanvas(h,key=
'RTrelations',title=
'RT relations',nx=1600,ny=1200,cx=1,cy=1)
7122 h[
'RTrelations'].cd(1)
7124 h[
'emptyHist'] = ROOT.TH2F(
'empty',
' ;[ns];[cm] ',100,x.GetBinCenter(1),x.GetBinCenter(x.GetNbinsX()),100,0.,2.)
7125 h[
'emptyHist'].SetStats(0)
7126 h[
'emptyHist'].Draw()
7127 h[
'legRT'] = ROOT.TLegend(0.69,0.10,0.99,0.98)
7129 if x
in [16 ,17, 30, 31]:
continue
7131 h[
'g'+g]=h[
'f'].RT.Get(g).Clone(
'g'+g)
7132 if not g.find(
'TDC1')<0: h[
'g'+g].SetLineColor(ROOT.kBlue)
7133 elif not g.find(
'TDC2')<0: h[
'g'+g].SetLineColor(ROOT.kCyan)
7134 elif not g.find(
'TDC3')<0: h[
'g'+g].SetLineColor(ROOT.kGreen)
7135 elif not g.find(
'TDC4')<0: h[
'g'+g].SetLineColor(ROOT.kGreen+2)
7137 h[
'legRT'].AddEntry(h[
'g'+g],h[
'g'+g].GetTitle(),
'PL')
7139 myPrint(h[
'RTrelations'],
'RTRelations')
7141 ut.bookHist(h,
'eloss12',
'energy loss between stations 1 and 2;dE [GeV]',100,0.,5.)
7142 ut.bookHist(h,
'eloss345',
'energy loss between stations 3,4 and 5;dE [GeV]',100,0.,5.)
7143 for n
in range(sTree.GetEntries()):
7144 rc=sTree.GetEvent(n)
7146 for p
in sTree.MuonTaggerPoint:
7147 if abs(p.PdgCode())!=13:
continue
7148 tid = p.GetTrackID()
7149 if not E.has_key(tid): E[tid]={}
7150 s=p.GetDetectorID()//10000
7151 mom=ROOT.TVector3(p.GetPx(),p.GetPy(),p.GetPz())
7154 for s
in range(1,5):
7156 if E[t].has_key(s+1):
7157 if s==1: rc = h[
'eloss12'].Fill(E[t][s]-E[t][s+1])
7158 else: rc = h[
'eloss345'].Fill(E[t][s]-E[t][s+1])
7159 ut.bookCanvas(h,
'cx',
' ',1200,600,1,1)
7161 h[
'eloss345'].SetLineColor(ROOT.kMagenta)
7162 h[
'eloss12'].SetLineColor(ROOT.kBlue)
7163 h[
'eloss12'].SetTitle(
';dE [GeV]')
7164 h[
'eloss12'].SetStats(0)
7165 h[
'eloss345scaled']=h[
'eloss345'].Clone(
'eloss345scaled')
7166 h[
'eloss345scaled'].Scale(1./3.)
7167 h[
'eloss345scaled'].SetTitle(
';dE [GeV]')
7168 h[
'eloss345scaled'].SetStats(0)
7169 h[
'eloss345scaled'].Draw(
'hist')
7170 h[
'eloss12'].Draw(
'same')
7171 myPrint(h[
'cx'],
'energyLossBetweenRPCs')
7173 if not h.has_key(
'biasedResiduals'):
7174 ut.readHists(h,
'residuals_refit.root')
7176 ut.bookCanvas(h,
'Residualsexample',
' ',1200,600,1,1)
7177 h[
'Residualsexample'].cd()
7178 h[
'theResidualPlot']=h[
'biasRes_1_x1'].Clone(
'theResidualPlot')
7179 h[
'theResidualPlot'].Reset()
7180 for l
in range(0,4):
7181 for z
in [
'x',
'u',
'v']:
7182 for s
in range(1,5):
7183 if z==
'u' and s!=1:
continue
7184 if z==
'v' and s!=2:
continue
7185 hname =
'biasRes_'+str(s)+
'_'+z+str(l)
7186 h[hname].SetTitle(h[hname].GetTitle()+
';[cm]')
7188 h[
'theResidualPlot'].Add(h[hname])
7189 myPrint(h[
'Residualsexample'],hname)
7190 hname =
'theResidualPlot'
7191 h[hname].SetTitle(
';[cm]')
7192 fitFunction = h[
'biasRes_1_x0'].GetFunction(
'gauss').Clone()
7193 fitResult = h[hname].Fit(fitFunction,
'S',
'',-0.5,0.5)
7195 h[
'Residualsexample'].Update()
7196 stats = h[
'Residualsexample'].GetPrimitive(
'stats')
7197 stats.SetOptFit(10111)
7198 stats.SetFitFormat(
'5.4g')
7201 stats.SetX2NDC(0.98)
7202 stats.SetY2NDC(0.94)
7203 h[
'Residualsexample'].Update()
7204 myPrint(h[
'Residualsexample'],hname)
7205 hname =
'biasResDist_projy'
7206 h[
'biasResDist_projy'].GetXaxis().SetRangeUser(-0.5,0.5)
7207 h[
'biasResDist_projy'].Draw()
7208 h[hname].SetTitle(
';[cm]')
7209 fitFunction = h[
'biasRes_1_x1'].GetFunction(
'gauss')
7210 fitFunction.ReleaseParameter(3)
7211 rc = h[hname].Fit(fitFunction,
'SQ',
'',-0.3,0.3)
7214 myGauss2.SetParameter(n,fitResult.Parameter(n))
7215 myGauss2.FixParameter(4,0)
7216 myGauss2.FixParameter(5,0.04)
7217 rc = h[hname].Fit(myGauss2,
'S',
'',-0.3,0.3)
7218 myGauss2.ReleaseParameter(4)
7219 rc = h[hname].Fit(myGauss2,
'S',
'',-0.3,0.3)
7220 myGauss2.ReleaseParameter(5)
7221 rc = h[hname].Fit(myGauss2,
'S',
'',-0.3,0.3)
7223 n1 = fitResult.Parameter(0)
7224 n2 = fitResult.Parameter(4)
7225 s1 = fitResult.Parameter(2)
7226 s2 = fitResult.Parameter(5)
7227 a = (s1*n1+s2*n2)/(n1+n2)
7228 txt = ROOT.TLatex(-0.45,h[hname].GetMaximum()*0.8,
"#sigma_{mean} = %5.0F#mum"%(a*10*1000))
7229 h[hname].SetTitle(
'')
7232 h[
'Residualsexample'].Update()
7233 stats = h[
'Residualsexample'].GetPrimitive(
'stats')
7234 stats.SetOptFit(10111)
7235 stats.SetFitFormat(
'5.4g')
7238 stats.SetX2NDC(0.98)
7239 stats.SetY2NDC(0.94)
7240 myPrint(h[
'Residualsexample'],
'biasResDistAll')
7243 h[
'example'] = h[
'biasResDist_4_x2'].ProjectionY(
'example',40,60)
7244 h[
'example'].GetXaxis().SetRangeUser(-0.5,0.5)
7245 fitFunction = h[
'biasResX_1_x1_px'].GetFunction(
'gauss')
7246 fitResult = h[
'example'].Fit(fitFunction,
'S',
'',-0.2,0.2)
7247 fitFunction.ReleaseParameter(3)
7248 fitResult = h[
'example'].Fit(fitFunction,
'S',
'',-0.2,0.2)
7249 stats = h[
'Residualsexample'].GetPrimitive(
'stats')
7250 stats.SetOptFit(10111)
7251 stats.SetFitFormat(
'5.4g')
7254 stats.SetX2NDC(0.98)
7255 stats.SetY2NDC(0.94)
7257 h[
'example2'] = h[
'biasResDistLR_4_x2'].ProjectionY(
'example',40,60)
7258 fitResult = h[
'example'].Fit(fitFunction,
'S',
'',-0.2,0.2)
7263 ut.bookCanvas(h,
'Residualsexample',
' ',1200,600,1,1)
7264 h[
'Residualsexample'].SetLogy(1)
7265 for l
in range(0,4):
7266 for z
in [
'x',
'u',
'v']:
7267 for s
in range(1,5):
7268 if z==
'u' and s!=1:
continue
7269 if z==
'v' and s!=2:
continue
7270 hname =
'biasResXL_'+str(s)+
'_'+z+str(l)+
'_projx'
7271 h[hname].SetTitle(h[hname].GetTitle()+
'; [cm]')
7273 h[
'Residualsexample'].Update()
7274 stats = h[hname].FindObject(
"stats")
7275 stats.SetX1NDC(0.60)
7276 stats.SetY1NDC(0.60)
7277 stats.SetX2NDC(0.97)
7278 stats.SetY2NDC(0.93)
7279 stats.SetOptFit(111)
7280 h[
'Residualsexample'].Update()
7281 myPrint(h[
'Residualsexample'],hname)
7284 t =
'tagstation'+str(1)
7285 ut.bookCanvas(h,
'Residualsexample',
' ',1200,600,1,1)
7286 h[
'Residualsexample'].cd()
7287 for p
in h[t].GetListOfPrimitives():
7288 hist = p.GetListOfPrimitives()[1]
7289 hist.GetXaxis().SetTitle(
'[cm]')
7291 myPrint(h[
'Residualsexample'],hist.GetName())
7293 ut.bookCanvas(h,
'Residualsexample',
' ',1200,600,1,1)
7295 h[
'Residualsexample'].cd()
7296 for p
in h[t].GetListOfPrimitives():
7297 hist = p.GetListOfPrimitives()[1]
7299 p.GetListOfPrimitives()[2].Draw()
7300 myPrint(h[
'Residualsexample'],hist.GetName())
7302 for p
in h[t].GetListOfPrimitives():
7303 hist = p.GetListOfPrimitives()[1]
7304 hist.SetTitle(
';track momentum [GeV/c]')
7306 txt1 = p.GetListOfPrimitives()[2].Clone(
'1')
7308 txt2 = p.GetListOfPrimitives()[3].Clone(
'2')
7310 myPrint(h[
'Residualsexample'],hist.GetName())
7312 ut.bookCanvas(h,
'Residualsexample',
' ',1200,600,1,1)
7313 h[
'RPCextTrack_21-70-100GeV'] = h[
'RPCextTrack_21'].ProjectionY(
'RPCextTrack_21-70-100GeV',70,100)
7314 h[
'RPCextTrack_31-70-100GeV'] = h[
'RPCextTrack_31'].ProjectionY(
'RPCextTrack_31-70-100GeV',70,100)
7315 h[
'RPCextTrack_21-5-10GeV'] = h[
'RPCextTrack_21'].ProjectionY(
'RPCextTrack_21-5-10GeV',5,10)
7316 h[
'RPCextTrack_31-5-10GeV'] = h[
'RPCextTrack_31'].ProjectionY(
'RPCextTrack_31-5-10GeV',5,10)
7317 h[
'RPCextTrack_21-70-100GeV'].SetLineColor(ROOT.kRed)
7318 h[
'RPCextTrack_21-5-10GeV'].SetLineColor(ROOT.kRed)
7319 h[
'Residualsexample'].cd()
7320 h[
'RPCextTrack_21-5-10GeV'].SetTitle(
'track with 5<P<10GeV position X at station 3 close to hit ; x [cm]')
7321 h[
'RPCextTrack_21-5-10GeV'].Draw()
7322 h[
'RPCextTrack_31-5-10GeV'].Draw(
'same')
7323 myPrint(h[
'Residualsexample'],
"XRPClowMom")
7324 h[
'RPCextTrack_21-70-100GeV'].SetTitle(
'track with 70<P<100GeV position X at station 3 close to hit ; x [cm]')
7325 h[
'RPCextTrack_21-70-100GeV'].Draw()
7326 h[
'RPCextTrack_31-70-100GeV'].Draw(
'same')
7327 myPrint(h[
'Residualsexample'],
"XRPChighMom")
7332 noField = [2199,2200,2201]
7333 intermediateField = [2383,2388,2389,2390,2392,2395,2396]
7334 noTracks = [2334, 2335, 2336, 2337, 2345, 2389, 2390]
7335 RPCbad = [2144,2154,2183,2192,2210,2211,2217,2218,2235,2236,2237,2240,2241,2243,2291,2345,2359]
7336 badRuns = [2142, 2143, 2144, 2149]
7337 keyword =
'RUN_8000_2'
7338 temp = os.listdir(path)
7339 cmd =
'hadd -f momDistributions.root '
7341 if x.find(keyword)<0:
continue
7343 if not os.path.isdir(path+
'/'+x):
continue
7344 r = int(x[x.rfind(
'/')+1:].split(
'_')[2])
7345 if r
in badRuns
or r
in noTracks
or r
in intermediateField
or r
in noField :
continue
7346 if excludeRPC
and (r
in RPCbad
or (r>2198
and r < 2275)) :
continue
7347 test = path+
'/'+x+
'/momDistributions.root '
7348 if not os.path.isfile(test.replace(
' ',
'')):
7349 print "no file found, skip run:",x,test
7352 if x.find(
"momDistributions-RUN_8000_2")!=0:
continue
7357 for d
in os.listdir(
'.'):
7358 if os.path.isdir(d):
7359 for f
in os.listdir(d):
7360 if f.find(
'ntuple-')==0:
7361 s = f.replace(
'ntuple-',
'')
7362 ff = ROOT.TFile.Open(os.environ[
'EOSSHIP']+
'/eos/experiment/ship/user/truf/muflux-sim/10GeV-withDeadChannels/'+d+
'/'+s)
7365 for m
in sTree.MCTrack:
7366 if abs(m.GetPdgCode())==13
and m.GetP()>350: sTree.MCTrack.Dump()
7368def fcn(npar, gin, f, par, iflag):
7372 dataMC = abs(par[0])
7373 charmMbias = abs(par[1])
7374 for proj
in [
'p/Abspx_y'+x,
'p/pt'+x+
'_x']:
7375 for n
in range(1, h[proj].GetNbinsX()+1 ):
7376 if proj ==
'p/pt'+x+
'_x' and h[proj].GetBinCenter(n)<5:
continue
7377 delta = h[proj].GetBinContent(n) - dataMC*(hMC[proj].GetBinContent(n)+charmMbias*hCharm[proj].GetBinContent(n))
7378 errSq = h[proj].GetBinContent(n) + dataMC**2*hMC[proj].GetBinContent(n)+\
7379 (dataMC*charmMbias)**2*hCharm[proj].GetBinContent(n)
7380 if errSq>0: chisq += delta**2/errSq
7382 if iflag !=2:
print par[0],par[1],chisq
7388 for a
in [
'p/pt',
'p/px']:
7389 for H
in [h,hMC,hCharm]:
7390 H[a+
'_x'+x] = H[a+x].ProjectionX(a+
'_x'+x)
7392 for H
in [h,hMC,hCharm]:
7393 H[a+
'_y'+x] = H[a+x].ProjectionY(a+
'_y'+x,h[a+
'_x'+x].FindBin(pMin),h[a+
'_x'+x].GetNbinsX())
7395 gMinuit = ROOT.TMinuit(npar)
7396 gMinuit.SetMaxIterations(100000)
7398 vstart = array(
'd',[p0,p1])
7399 step = array(
'd',[2.,2.])
7400 ierflg = ROOT.Long(0)
7401 name = [ROOT.TString(
"dataMC"),ROOT.TString(
"charmMbias")]
7402 for i
in range(npar): gMinuit.mnparm(i, name[i], vstart[i], step[i], 0.,0.,ierflg)
7404 gMinuit.mnexcm(
"SIMPLEX",vstart,npar,ierflg)
7405 gMinuit.mnexcm(
"MIGRAD",vstart,npar,ierflg)
7407 charmNorm = ROOT.Double()
7409 gMinuit.GetParameter(0,pot,e)
7410 gMinuit.GetParameter(1,charmNorm,e)
7411 print "RESULT:",abs(pot), abs(charmNorm)
7421 for p0
in numpy.linspace(p0min,p0max,N):
7422 for p1
in numpy.linspace(p1min,p1max,N):
7429 print chi2Max,pChi2Min
7435 sigma = [0.36/100.*fudge,0.036/100.*fudge]
7436 h[folname]=h[hname].Clone(folname)
7438 for n
in range(1,h[hname].GetNbinsX()+1):
7439 P = h[hname].GetBinCenter(n)
7440 N = h[hname].GetBinContent(n)
7441 sig = (sigma[0]+P*sigma[1])*P
7442 for n
in range(int(N+0.5)):
7444 rc = h[folname].Fill(p)
7445 ut.makeIntegralDistrib(h,hname)
7447 h[folname].SetLineColor(ROOT.kBlue)
7448 h[folname].Draw(
'same')
7450 name = aname.replace(
'/',
'')
7452 obj.Print(name+
'.root')
7453 obj.Print(name+
'.pdf')
7454 obj.Print(name+
'.png')
7455 obj.Print(name+
'.eps')
7457 f = sTree.GetCurrentFile()
7459 rawName = fname.replace(
'_RT.root',
'.root')
7460 ftemp = fname.replace(
'_RT.root',
'_RTx.root')
7461 os.system(
'cp '+rawName +
' '+ftemp)
7462 h[
'TDCMapsX'] = f.histos.Get(
'TDCMapsX').Clone(
'TDCMapsX')
7463 h[
'hitMapsX'] = f.histos.Get(
'hitMapsX').Clone(
'hitMapsX')
7464 h[
'RTrelations'] = f.histos.Get(
'RTrelations').Clone(
'RTrelations')
7465 h[
'TDC2R_py'] = f.histos.Get(
'TDC2R_py').Clone(
'TDC2R_py')
7467 f = ROOT.TFile.Open(ftemp,
'update')
7468 event = f.Get(
"cbmsim")
7470 print "Problem with making RTrel persistent, file",f,f.ls()
7475 for s
in RTrelations[fname]:
7476 if s.find(
'rt')<0:
continue
7477 RTrelations[fname][s].Write()
7479 pkl.dump(h[
'tMinAndTmax'],
'tMinAndTmax')
7483 h[
'TDCMapsX'].Write()
7484 h[
'hitMapsX'].Write()
7485 h[
"RTrelations"].Write()
7486 f.Write(
"",ROOT.TFile.kOverwrite)
7492 withMaterial =
False
7496 RTrelations = {
'tMinAndTmax':h[
'tMinAndTmax']}
7497 for s
in h[
'tMinAndTmax']: RTrelations[
'rt'+s] = h[
'rt'+s]
7503 fGenFitArray = ROOT.TClonesArray(
"genfit::Track")
7504 fGenFitArray.BypassStreamer(ROOT.kTRUE)
7505 fitTracks = sTree.Branch(
"FitTracks", fGenFitArray,32000,-1)
7506 fTrackInfoArray = ROOT.TClonesArray(
"TrackInfo")
7507 fTrackInfoArray.BypassStreamer(ROOT.kTRUE)
7508 TrackInfos = sTree.Branch(
"TrackInfos", fTrackInfoArray,32000,-1)
7509 fRPCTrackArray = {
'X':ROOT.TClonesArray(
"RPCTrack"),
'Y':ROOT.TClonesArray(
"RPCTrack")}
7511 for x
in fRPCTrackArray:
7512 fRPCTrackArray[x].BypassStreamer(ROOT.kTRUE)
7513 RPCTrackbranch[x] = sTree.Branch(
"RPCTrack"+x, fRPCTrackArray[x],32000,-1)
7514 if sTree.GetBranch(
'MCTrack'): MCdata =
True
7516 for n
in range(sTree.GetEntries()):
7517 if n%10000==0:
print "Now at event",n,
"of",sTree.GetEntries(),sTree.GetCurrentFile().GetName(),time.ctime()
7518 rc = sTree.GetEvent(n)
7519 fGenFitArray.Clear()
7520 fTrackInfoArray.Clear()
7521 for x
in [
'X',
'Y']: fRPCTrackArray[x].Clear()
7523 for aTrack
in theTracks:
7524 nTrack = fGenFitArray.GetEntries()
7525 fTrackInfoArray[nTrack] = ROOT.TrackInfo(aTrack)
7527 fGenFitArray[nTrack] = aTrack
7530 for aTrack
in RPCtracks[x]:
7531 nTrack = fRPCTrackArray[x].GetEntries()
7533 fRPCTrackArray[x][nTrack] = ROOT.RPCTrack(aTrack[0],aTrack[1])
7535 print nTrack,x,aTrack
7536 RPCTrackbranch[x].Fill()
7539 for aTrack
in theTracks: aTrack.Delete()
7542 ftemp=sTree.GetCurrentFile()
7543 ftemp.Write(
"",ROOT.TFile.kOverwrite)
7545 print "finished adding fitted tracks",options.listOfFiles
7547 os.system(
'kill '+str(os.getpid()))
7551 if x.find(
'RTcorr')!=0:
continue
7552 if not x.find(
'LR')<0
or not x.find(
'Par')<0:
continue
7553 txt =
" pars['"+x+
"'] = ["
7554 for x
in h[x+
'Par'+x]:
7557 print txt.replace(
', ]',
']')
7561 fGenFitArray = ROOT.TClonesArray(
"genfit::Track")
7562 fGenFitArray.BypassStreamer(ROOT.kTRUE)
7563 fitTracks = sTree.Branch(
"FitTracks_refitted", fGenFitArray,32000,-1)
7564 fTrackInfoArray = ROOT.TClonesArray(
"TrackInfo")
7565 fTrackInfoArray.BypassStreamer(ROOT.kTRUE)
7566 TrackInfos = sTree.Branch(
"TrackInfos_refitted", fTrackInfoArray,32000,-1)
7567 if sTree.GetBranch(
'MCTrack'): MCdata =
True
7568 for n
in range(sTree.GetEntries()):
7569 if n%10000==0:
print "Now at event",n,
"of",sTree.GetEntries(),sTree.GetCurrentFile().GetName(),time.ctime()
7570 rc = sTree.GetEvent(n)
7571 fGenFitArray.Clear()
7572 fTrackInfoArray.Clear()
7574 for aTrack
in theTracks:
7575 nTrack = fGenFitArray.GetEntries()
7576 fTrackInfoArray[nTrack] = ROOT.TrackInfo(aTrack)
7578 fGenFitArray[nTrack] = aTrack
7581 for aTrack
in theTracks: aTrack.Delete()
7583 ftemp=sTree.GetCurrentFile()
7584 ftemp.Write(
"",ROOT.TFile.kOverwrite)
7586 print "finished adding fitted tracks",options.listOfFiles
7588 os.system(
'kill '+str(os.getpid()))
7592 if sTree.GetBranch(
'MCTrack'): MCdata =
True
7593 fname = sTree.GetCurrentFile().GetName()
7594 if sTree.GetBranch(
"RPCTrackX"):
7595 print "remove RECO branch and rerun muonTagger reconstruction"
7596 os.system(
'cp '+fname+
' '+fname.replace(
'.root',
'orig.root'))
7597 for br
in [
'RPCTrackX',
'RPCTrackY']:
7598 b = sTree.GetBranch(br)
7599 sTree.GetListOfBranches().Remove(b)
7600 l = sTree.GetLeaf(br)
7601 sTree.GetListOfLeaves().Remove(l)
7603 fn = sTree.GetCurrentFile().GetName()
7604 f = ROOT.TFile(fn,
'update')
7606 fRPCTrackArray = {
'X':ROOT.TClonesArray(
"RPCTrack"),
'Y':ROOT.TClonesArray(
"RPCTrack")}
7608 for x
in fRPCTrackArray:
7609 fRPCTrackArray[x].BypassStreamer(ROOT.kTRUE)
7610 RPCTrackbranch[x] = sTree.Branch(
"RPCTrack"+x, fRPCTrackArray[x],32000,-1)
7611 for n
in range(sTree.GetEntries()):
7612 if n%10000==0:
print "Now at event",n,
"of",sTree.GetEntries(),sTree.GetCurrentFile().GetName(),time.ctime()
7613 rc = sTree.GetEvent(n)
7614 for x
in [
'X',
'Y']: fRPCTrackArray[x].Clear()
7616 if sTree.FitTracks.GetEntries()==0:
7617 for x
in [
'X',
'Y']: RPCTrackbranch[x].Fill()
7621 for aTrack
in RPCtracks[x]:
7622 nTrack = fRPCTrackArray[x].GetEntries()
7624 fRPCTrackArray[x][nTrack] = ROOT.RPCTrack(aTrack[0],aTrack[1])
7626 print nTrack,x,aTrack
7627 RPCTrackbranch[x].Fill()
7629 ftemp = sTree.GetCurrentFile()
7630 ftemp.Write(
"",ROOT.TFile.kOverwrite)
7632 ftest = ROOT.TFile(fname)
7634 if ftest.GetKey(
'cbmsim'):
7635 sTree = ftest.cbmsim
7636 check = sTree.GetBranch(
'RPCTrackY').GetZipBytes()
7637 check += sTree.GetBranch(
'RPCTrackY').GetZipBytes()
7638 if check/float(sTree.GetBranch(
'FitTracks').GetZipBytes())>0.003: OK =
True
7640 print "muon track reco failed, reinstall original file"
7641 os.system(
'mv '+fname.replace(
'.root',
'orig.root')+
' '+fname)
7643 os.system(
'rm '+fname.replace(
'.root',
'orig.root'))
7644 print "finished adding muonTagger tracks",options.listOfFiles
7646 os.system(
'kill '+str(os.getpid()))
7648 if sTree.GetBranch(
'FitTracks_refitted'):
7650 elif sTree.GetBranch(
'FitTracks'):
7653 print "this file has no tracks",sTree.GetCurrentFile().GetName()
7655 muflux_Reco.trackKinematics(3.)
7656 if MCdata
and sTree.GetCurrentFile().GetName().find(
'Jpsi')<0:
7661 norm = h[
'TrackMult'].GetEntries()
7662 print '*** Track Stats ***',norm
7663 ut.writeHists(h,
'histos-analysis-'+rname)
7664if options.command ==
"":
7665 print "existing methods"
7666 print " --- plotHitMaps(): hitmaps / layer, TDC / layer, together with list of noisy channels"
7667 print " --- plotEvent(n) : very basic event display, just x hits in x/z projection "
7668 print " --- plotRPCHitmap() : basic plots for RPC "
7669 print " --- momentum plot and track fitting tests:"
7670 print " --- fitTracks(100) and fitTracks(100,True,True) with simple Display and 3d display of tracks with detector, low occupancy events"
7671 print " --- testClusters(nstart,nevents), clustering of hits and pattern recognition followed by track fit"
7672 print " --- plotBiasedResiduals(nstart,nevents), fit tracks in low occupancy events and plot residuals, plot2dResiduals() for display del vs x, del vs y"
7673 print " --- plotLinearResiduals(), to be used for zero field"
7674 print " --- plotRPCExtrap(nstart,nevents), extrapolate track to RPC hits"
7675 print " --- printScalers()"
7676 print " --- init(): outdated! do boostrapping, determine RT relation using fitted tracks, do plotBiasedResiduals and plotRPCExtrap with TDC"
7677 print " --- momResolution(), with MC data"
7680 database=
'muflux_RTrelations.pkl'
7681 if sTree.GetBranch(
'MCTrack'):
7682 print "MC data identified"
7684 elif sTree.GetCurrentFile().GetKey(
'RT'):
7686 elif os.path.exists(database):
7687 RTrelations = pickle.load(open(database))
7688 if not RTrelations.has_key(rname):
7689 print "You should run init() to determine the RT relations or use _RT file"
7691 h[
'tMinAndTmax'] = RTrelations[rname][
'tMinAndTmax']
7692 for s
in h[
'tMinAndTmax']: h[
'rt'+s] = RTrelations[rname][
'rt'+s]
7693 withCorrections =
False
7696if options.command ==
"recoStep0":
7698 print "make clean TDC distributions"
7701 print "finished making RT relations"
7702elif options.command ==
"recoStep1":
7703 if sTree.GetBranch(
'MCTrack'):
7705 withDefaultAlignment =
True
7706 sigma_spatial = 0.25
7707 withCorrections =
False
7711 withDefaultAlignment =
False
7712 sigma_spatial = 0.25
7713 withCorrections =
True
7714 print "add fitted tracks"
7717elif options.command ==
"recoStep2":
7718 if sTree.GetBranch(
'MCTrack'):
7720 withDefaultAlignment =
True
7721 sigma_spatial = 0.25
7722 withCorrections =
False
7726 withDefaultAlignment =
False
7727 sigma_spatial = 0.25
7728 withCorrections =
True
7729 print "add refitted tracks"
7732elif options.command ==
"anaResiduals":
7733 ROOT.gROOT.SetBatch(
True)
7734 if sTree.GetEntries()>0:
7735 if sTree.GetBranch(
'MCTrack'):
7739 withCorrections =
False
7742 print "finished with analysis step",options.listOfFiles
7743 else:
print "no events, exit ",sTree.GetCurrentFile()
7744elif options.command ==
"alignment":
7745 ROOT.gROOT.SetBatch(
True)
7746 if sTree.GetBranch(
'MCTrack'):
7748 withDefaultAlignment =
True
7749 sigma_spatial = 0.25
7750 withCorrections =
False
7753 withDefaultAlignment =
False
7754 sigma_spatial = 0.25
7755 withCorrections =
True
7759 ut.writeHists(h,
'histos-residuals-'+rname)
7761elif options.command ==
"plotResiduals":
7762 print "reading histograms with residuals"
7763 ut.readHists(h,options.listOfFiles)
7765 if h.has_key(
'RPCResY_10'):
7767elif options.command ==
"recoMuonTaggerTracks":
7770elif options.command ==
"momResolution":
7772 withDefaultAlignment =
True
7773 sigma_spatial = 0.25
7774 withCorrections =
False
7776 momResolution(PR=1,onlyPlotting=
False)
7778elif options.command ==
"countTracks":
countTracks()
7780elif options.command ==
"DTeffWithRPCTracks":
7781 withCorrections =
False
7784elif options.command ==
"hitMapsFromFittedTracks":
7786elif options.command ==
"studyDeltaRays":
7787 if sTree.GetBranch(
'MCTrack'): MCdata =
True
7789elif options.command ==
"MCJpsiProd":
7791elif options.command ==
"test":
7792 yep.start(
'output.prof')
7793 for x
in sTree.GetListOfBranches(): sTree.SetBranchStatus(x.GetName(),0)
7795 sTree.SetBranchStatus(
'FitTracks',1)
7796 for n
in range(50000):
7797 rc=sTree.GetEvent(n)
set(INCLUDE_DIRECTORIES ${SYSTEM_INCLUDE_DIRECTORIES} ${VMC_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/shipdata ${CMAKE_SOURCE_DIR}/shipLHC ${CMAKE_SOURCE_DIR}/analysis/cuts ${CMAKE_SOURCE_DIR}/analysis/tools ${FMT_INCLUDE_DIR}) include_directories($
This class creates an instance of the specified database API.
execute(SmearedHits, TaggerHits, withNTaggerHits, withDist2Wire, debug=0)
configure(run, ship_geo, Gfield='')
checkTrackEfficiencyPerSpill()
plotHitMaps(onlyPlotting=False)
plotDTPoints(onlyPlotting=False)
correctAlignmentRPC(hit, v)
findDTClusters(removeBigClusters=True)
countMeasurements(aTrack, PR=1)
cloneKiller(trackCandidates)
makeLinearExtrapolations(t1t2, t3t4)
countTracks(analyse=False)
findDTClustersDebug1(n, tmp)
studyLateDTHits(nevents=1000, nStart=0)
grouper(iterable, grouping)
efficiencyEstimates(method=2, MCdata=False)
plotMuonTaggerTrack(muTracks)
ghostSuppression(hname="sumHistos--simulation10GeV-withDeadChannels.root")
muonTaggerClustering(PR=11)
makeAlignmentConstantsPersistent()
plot2dResiduals(minEntries=-1)
findSimpleEvent(event, nmin=2, nmax=6)
printTrackMeasurements(atrack, PR=1)
makeRTrelPersistent(RTrelations)
testForSameDetID(nEvent=-1, nTot=1000)
displayTrack(theTrack, debug=False)
init(database='muflux_RTrelations.pkl', remake=False, withReco=False)
extractRTPanda(hname='TDC1000_x')
MCcomparisonHitmaps(MC='1GeV', first=False)
plotWithRPCTrackEffExample()
mergeHistosForMomResol(withFitPoints=False)
plotTimeOverThreshold(N, Debug=False)
studyGhostTracks(nStart=0, nEnd=0, chi2UL=3, pxLow=5.)
clusterSizesPerLayer(nevents)
matchedRPCHits(aTrack, maxDistance=10.)
findTracks(PR=1, linearTrackModel=False, withCloneKiller=True)
FCN(npar, gin, f, par, iflag)
plotRPCExtrap(nEvent=-1, nTot=1000, PR=1, onlyPlotting=False)
MCcomparison(pot=-1, pMin=5., pMax=300., ptMax=4., simpleEffCor=0.023, effCor=False, eric=False, version="-repro", withOverFlow=False, withDisplay=True, cuts='', noTitle=False)
plotBiasedResiduals(nEvent=-1, nTot=1000, PR=11, onlyPlotting=False, minP=3.)
MakeKeysToDThits(minToT=-999)
extrapolateToPlane(fT, z, cplusplus=True)
fcn(npar, gin, f, par, iflag)
fitTracks(nMax=-1, simpleEvents=True, withDisplay=False, nStart=0, debug=False, PR=1, withRT=False, chi2UL=3)
debugTrackFit(nEvents, nStart=0, simpleEvents=True, singleTrack=True, PR=1)
plotRPCResidualsExample()
printClustersPerStation(clusters, s, view)
DTEfficiencyFudgefactor(method=-1)
fitTrack(hitlist, Pstart=3.)
myVertex(t1, t2, PosDir, xproj=False)
findV0(nstart=0, nmax=-1, PR=1)
getSlopes(cl1, cl2, view='_x')
residualLoop(nstart=0, nend=50000)
importAlignmentConstants()
studyDeltaRays(onlyPlots=False)
plotTracklets(track_hits)
testClusters(nEvent=-1, nTot=1000)
hitMapsFromFittedTracks()
MCJpsiProd(onlyPlotting=False)
check4muon(m, debug=False)
mergeGoodRuns(excludeRPC=False, path='.', fromEOS=True)
DTeffWithRPCTracks(Nevents=0, onlyPlotting=False, fHisto=None)
plotHitMapsOld(onlyPlotting=False)
execute(f, ox, name='ShipGeo')