54 const unsigned NTRAINS = 4;
55 const unsigned NBARS = 4;
56 const unsigned NSIDES = 2;
57 enum { FRONT, MIDDLE, END, NPOS } position = NPOS;
97 lb = eventInfo->lumiBlock();
98 lbAandCToFEvents = eventInfo->lumiBlock();
101 if (muPerBXToF == 0.0) {
102 ATH_MSG_DEBUG(
"AverageInteractionsPerCrossing is 0, forcing to 1.0");
106 ToFHits_MU_Weight = 1/muPerBXToF;
107 lbToFBar_Weight = 1/muPerBXToF;
108 weightToFTrainAll = 1/muPerBXToF;
109 weightToFTrainFront = 1/muPerBXToF;
110 weightToFTrainMiddle = 1/muPerBXToF;
111 weightToFTrainEnd = 1/muPerBXToF;
113 for(
unsigned int s = 0; s < NSIDES; s++)
115 lbToFEvents[s] = eventInfo->lumiBlock();
118 fill(
"AFPToFTool",
lb, muPerBXToF);
121 const unsigned int tempBCID = eventInfo->bcid();
124 ATH_MSG_ERROR(
"Unable to retrieve BunchCrossing conditions object (ToF)" );
131 bcidAllToF = tempBCID;
132 fill(
"AFPToFTool", bcidAllToF);
133 if(!bcDataToF->
isFilled(tempBCID-1))
137 else if(bcDataToF->
isFilled(tempBCID+1))
145 bcidToF[position] = tempBCID;
146 fill(
"AFPToFTool", bcidToF[position]);
151 if(! afpToFHitContainer.
isValid())
154 return StatusCode::SUCCESS;
160 if ( !afpTrackContainer.
isValid() ) {
162 return StatusCode::SUCCESS;
166 nTofHits = afpToFHitContainer->size();
167 fill(
"AFPToFTool",
lb, nTofHits);
169 int eventsInStations[4] = {};
172 unsigned int totalHitsPerTrainAll[NSIDES][NTRAINS] = {};
173 unsigned int totalHitsPerTrainFME[NSIDES][NTRAINS][NPOS] = {};
174 unsigned int totalHitsPerBar[NSIDES][NTRAINS][NBARS] = {};
175 unsigned int totalStationHits[NSIDES] = {};
179 if (hitsItr->stationID()<4 && hitsItr->stationID()>=0 && hitsItr->trainID()<4 && hitsItr->trainID()>=0 && hitsItr->barInTrainID()<4 && hitsItr->barInTrainID()>=0)
181 trainID = hitsItr->trainID();
182 barInTrainID = hitsItr->barInTrainID();
183 ++eventsInStations[hitsItr->stationID()];
186 if(hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
189 int side = (hitsItr->stationID() == 3) ? 1 : 0;
190 unsigned int train = hitsItr->trainID();
191 unsigned int bar = hitsItr->barInTrainID();
196 barInTrainIDSide = bar;
199 barInTrainAll = train * 4 + bar;
202 ToFHits_side = eventInfo->lumiBlock();
208 lbToFBar = eventInfo->lumiBlock();
212 ++totalStationHits[side];
213 ++totalHitsPerTrainAll[side][train];
214 if(bar < NBARS) ++totalHitsPerBar[side][train][bar];
215 if(position != NPOS) ++totalHitsPerTrainFME[side][train][position];
218 lbToFTrainAll = eventInfo->lumiBlock();
221 if(position == FRONT)
223 lbToFTrainFront = eventInfo->lumiBlock();
226 else if(position == MIDDLE)
228 lbToFTrainMiddle = eventInfo->lumiBlock();
231 else if(position == END)
233 lbToFTrainEnd = eventInfo->lumiBlock();
241 if(eventsInStations[0] > 0 || eventsInStations[3] > 0)
243 fill(
"AFPToFTool", lbAandCToFEvents);
245 if(eventsInStations[0] > 0)
247 fill(
"AFPToFTool", lbToFEvents[0]);
249 if(eventsInStations[3] > 0)
251 fill(
"AFPToFTool", lbToFEvents[1]);
265 for(
unsigned int side = 0; side < NSIDES; side++)
267 for(
unsigned int train = 0; train < NTRAINS; train++)
269 hitsPerTrainAllPP = totalHitsPerTrainAll[side][train] / muPerBXToF;
272 hitsPerTrainFrontPP = totalHitsPerTrainFME[side][train][FRONT] / muPerBXToF;
273 if(position == FRONT)
276 hitsPerTrainMiddlePP = totalHitsPerTrainFME[side][train][MIDDLE] / muPerBXToF;
277 if(position == MIDDLE)
280 hitsPerTrainEndPP = totalHitsPerTrainFME[side][train][END] / muPerBXToF;
290 for(
unsigned int side = 0; side < NSIDES; side++)
292 for(
unsigned int train = 0; train < NTRAINS; train++)
294 for(
unsigned int bar = 0; bar < NBARS; bar++)
296 hitsPerBarPP = totalHitsPerBar[side][train][bar] / muPerBXToF;
306 for(
unsigned int side = 0; side < NSIDES; side++)
308 hitsPerStationPP = totalStationHits[side] / muPerBXToF;
324 bool channel_present[2][16] = {};
325 bool multihit[2] = {};
326 std::size_t track_count[2] = {};
327 std::size_t train_count[2][4] = {};
331 const auto side = tracksItr->stationID() == 3;
333 if (tracksItr->stationID() != 0 && tracksItr->stationID() != 3)
339 auto times = std::vector<std::vector<std::vector<float>>>(2, std::vector<std::vector<float>>(4, std::vector<float>(4, -10000)));
342 const auto side = hitsItr->stationID() == 3;
343 const auto train = hitsItr->trainID();
344 const auto bar = hitsItr->barInTrainID();
345 const auto channel = 4 * train + bar;
346 const auto tof_time = hitsItr->time();
347 const auto TimePs=(tof_time)*1000;
349 if (track_count[side] != 1)
continue;
351 if (hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
353 if (train < 0 || train >= 4 || bar < 0 || bar >= 4)
continue;
354 if (channel_present[side][channel])
355 multihit[side] =
true;
356 channel_present[side][channel] =
true;
357 ++train_count[side][train];
359 times[side][train][bar]=TimePs;
363 for (uint8_t side : {0, 1})
366 if (track_count[side] != 1)
continue;
368 if (multihit[side])
continue;
370 uint8_t multrain[2] = {};
371 for (uint8_t train = 0; train < 4; ++train) {
372 if (train_count[side][train]>1) {
376 if (multrain[side]>1)
continue;
378 for (uint8_t train = 0; train < 4; ++train) {
379 for (uint8_t bar1 = 0; bar1 < 4; ++bar1) {
380 for (uint8_t bar2 = 0; bar2 < 4; ++bar2) {
382 int comb = bar1*bar2+bar2-1;
383 if (comb==5) {comb=4;}
384 if (comb==8) {comb=5;}
385 int global_comb = train*6 + comb;
386 if (times[side][train][bar1]>-10000 && times[side][train][bar2]>-10000) {
387 crossBarDeltaT[side] = (times[side][train][bar1] - times[side][train][bar2]);
396 return StatusCode::SUCCESS;