75 {
76
78
79 MsgStream log(
msgSvc(), name() );
80
81
82
83 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
84 if ( !eventHeader )
85 {
86 log << MSG::FATAL << "Could not find Event Header" << endmsg;
87 return ( StatusCode::FAILURE );
88 }
89
90
91
92
93
94
95
96
97
100 topTOF.clear();
101 bottomTOF.clear();
102 Identifier id;
103 unsigned int idBarrel_Endcap, iphi;
104 double tdc;
105
107
108 if ( tofDataVec.size() > 1 )
109 {
110 TofDataVector::iterator iterTOF = tofDataVec.begin();
111 for ( ; iterTOF != tofDataVec.end(); iterTOF++ )
112 {
113 if ( ( *iterTOF )->barrel() )
114 {
115 idBarrel_Endcap = 1;
116 int id = ( *iterTOF )->tofId();
117 iphi = id % 88;
118 int ilayer = id / 88;
119 double t1 = ( *iterTOF )->tdc1();
120 double t2 = ( *iterTOF )->tdc2();
121 double tof = -999;
122 if ( t1 < 1500 && t2 < 1500 && t1 > 0 && t2 > 0 ) tof = 0.5 * ( t1 + t2 );
123 else if ( t1 < 1500 && t1 > 0 ) tof = t1;
124 else if ( t2 < 1500 && t2 > 0 ) tof = t2;
125 else continue;
126 log << MSG::DEBUG << "hit: "
127 << "(" << idBarrel_Endcap << "," << ilayer << "," << iphi << ")-->" << tof << " ns"
128 << endmsg;
129
130
131
132
133 if ( iphi < 41 && iphi > 2 )
134 { topTOF.push_back( EFTofHitsCol( idBarrel_Endcap, ilayer, iphi, tof ) ); }
135 else if ( iphi > 46 && iphi < 85 )
136 { bottomTOF.push_back( EFTofHitsCol( idBarrel_Endcap, ilayer, iphi, tof ) ); }
137 }
138 else
139 {
140 int iphi = ( *iterTOF )->tofId();
141 double tof = ( *iterTOF )->tdc();
142 if ( iphi >= 48 )
143 {
144 idBarrel_Endcap = 2;
145 iphi %= 48;
146 }
147 else idBarrel_Endcap = 0;
148 if ( iphi > 1 && iphi < 22 && tof > 0 && tof < 1500 )
149 { topTOF.push_back( EFTofHitsCol( idBarrel_Endcap, 0, iphi, tof ) ); }
150 else if ( iphi > 25 && iphi < 46 && tof > 0 && tof < 1500 )
151 { bottomTOF.push_back( EFTofHitsCol( idBarrel_Endcap, 0, iphi, tof ) ); }
152 }
153 }
154 }
155 double dtof1 = 99;
156 double dphi1 = 180;
157 double dtof2 = 99;
158 double dphi2 = 180;
159 if ( topTOF.size() >= 1 && bottomTOF.size() >= 1 )
160 {
161 for ( unsigned int i = 0; i < topTOF.size(); i++ )
162 {
163 double topPhi = 0.;
164 if ( topTOF[i].ib_e() == 1 ) { topPhi = topTOF[i].iphi() * 360. / 88.; }
165 else if ( topTOF[i].ib_e() == 0 || topTOF[i].ib_e() == 2 )
166 { topPhi = topTOF[i].iphi() * 360. / 48.; }
167 else { log << MSG::ERROR << "TOF Barrel_Encap ID not right!" << endmsg; }
168 for ( unsigned int j = 0; j < bottomTOF.size(); j++ )
169 {
170 double bottomPhi = 0.;
171 if ( bottomTOF[j].ib_e() == 1 ) { bottomPhi = bottomTOF[j].iphi() * 360. / 88.; }
172 else if ( bottomTOF[j].ib_e() == 0 || bottomTOF[j].ib_e() == 2 )
173 { bottomPhi = bottomTOF[j].iphi() * 360. / 48.; }
174 else { log << MSG::ERROR << "TOF Barrel_Encap ID not right!" << endmsg; }
175 double tmp1 = fabs( topTOF[i].GetT() - bottomTOF[j].GetT() );
176 double tmp2 = fabs( topTOF[i].GetT() - bottomTOF[j].GetT() + 7. );
177 if ( tmp2 < fabs( dtof2 + 7. ) )
178 {
179 dtof2 = topTOF[i].GetT() - bottomTOF[j].GetT();
180 dphi2 =
abs( fabs( topPhi - bottomPhi ) - 180. );
181 }
182 if ( tmp1 < fabs( dtof1 ) )
183 {
184 dphi1 =
abs( fabs( topPhi - bottomPhi ) - 180. );
185 dtof1 = topTOF[i].GetT() - bottomTOF[j].GetT();
186 }
187 }
188 }
189 }
190
191 log << MSG::INFO << "dtof1=" << dtof1 << ", dphi1=" << dphi1 << "dtof2=" << dtof2
192 << ", dphi2=" << dphi2 << endmsg;
193
194
195 m_dtof1->setValue( dtof1 );
196 m_dphi1->setValue( dphi1 );
197 m_dtof2->setValue( dtof2 );
198 m_dphi2->setValue( dphi2 );
199 m_ef->appToEFVec( dtof1, 26 );
200 m_ef->appToEFVec( dphi1, 27 );
201 m_ef->appToEFVec( dtof2, 28 );
202 m_ef->appToEFVec( dphi2, 29 );
203 m_ef->setVecBit(
true, 0, 5 );
204 m_ef->addToEFVec( 4 << 8, 1 );
205
207 return StatusCode::SUCCESS;
208}
std::vector< EFTofHitsCol > VTOF
std::vector< TofData * > TofDataVector
IRawDataProviderSvc * m_rawDigiSvc