438 def ExecuteEvent(self,event):
439 h = self.M.h
440 for aTrack in self.M.Reco_MuonTracks:
441 if not aTrack.GetUniqueID()==1: continue
442 fitStatus = aTrack.getFitStatus()
443 if not fitStatus.isFitConverged(): continue
444 state = aTrack.getFittedState()
445 mom = state.getMom()
446 slopeX = mom.X()/mom.Z()
447 slopeY = mom.Y()/mom.Z()
448 sortedClusters={}
449 DetID2Key={}
450 for nHit in range(event.Digi_ScifiHits.GetEntries()):
451 DetID2Key[event.Digi_ScifiHits[nHit].GetDetectorID()] = nHit
452
453 pos = {}
454 for s in range(1, nStations+1): sortedClusters[s] = {'H':[],'V':[]}
455 for nM in range(aTrack.getNumPointsWithMeasurement()):
456 state = aTrack.getFittedState(nM)
457 Meas = aTrack.getPointWithMeasurement(nM)
458 W = Meas.getRawMeasurement()
459 clkey = W.getHitId()
460 aCl = self.trackTask.clusScifi[clkey]
461 aHit = event.Digi_ScifiHits[DetID2Key[aCl.GetFirst()]]
462 s = aCl.GetFirst()//1000000
463 aCl.GetPosition(A,B)
464 mat = (aCl.GetFirst()//10000)%10
465
466 if aHit.isVertical():
467 L = B[1]-state.getPos()[1]
468 sortedClusters[s]['V'].append( [clkey,L,B[0],state.getPos()[1],mat,(A[2]+B[2])/2.,state.getPos()[0],aCl.GetFirst(),aCl.GetTime()] )
469 else:
470 L = A[0]-state.getPos()[0]
471 sortedClusters[s]['H'].append( [clkey,L,A[1],state.getPos()[0],mat,(A[2]+B[2])/2.,state.getPos()[1],aCl.GetFirst(),aCl.GetTime()] )
472 stationTimes = {}
473 for s in range(1, nStations+1):
474 if not (len(sortedClusters[s]['V']) * len(sortedClusters[s]['H']) ) ==1: continue
475 sTime = 0
476 for proj in ['V','H']:
477 clkey = sortedClusters[s][proj][0][0]
478 aCl = self.trackTask.clusScifi[clkey]
479 L = sortedClusters[s][proj][0][1]
480 time = aCl.GetTime()
481 mat = sortedClusters[s][proj][0][4]
482 sipm_array = int(sortedClusters[s][proj][0][7]/1000)%10
483 sipm_channel = sortedClusters[s][proj][0][7]%1000
484 if channelTimeAlignment==1 and s==2 and proj=='H':
485 time-= self.tdcScifiStationCalib[s][1][proj][1][sipm_array][sipm_channel]
486 time-= self.tdcScifiStationCalib[s][1][proj][mat]
487 time-= self.tdcScifiStationCalib[s][0]
488 time-= abs(L)/self.V
489
490
491
492
493
494 sTime += time
495 stationTimes[s] = [sTime/2.,(sortedClusters[s]['H'][0][5] + sortedClusters[s]['V'][0][5])/2.]
496
497 if not 1 in stationTimes: continue
498
499 T0 = stationTimes[1][0]
500 Z0 = stationTimes[1][1]
501 for s in stationTimes:
502 if s == 1: continue
503 dZ = stationTimes[s][1]-Z0
504 dT = stationTimes[s][0]-T0
505 dL = dZ * ROOT.TMath.Sqrt( slopeX**2+slopeY**2+1 )
506
507
508 rc = h['dTvsZ'].Fill(dL,dT)
509 if abs(slopeX)<0.1 and abs(slopeY)<0.1:
510 rc = h['dTvsZ_beam'].Fill(dL,dT)
511
512
513