44 const unsigned NTRAINS = 4;
45 const unsigned NBARS = 4;
46 const unsigned NSIDES = 2;
47 enum { FRONT, MIDDLE, END, NPOS } position = NPOS;
87 lb = eventInfo->lumiBlock();
88 lbAandCToFEvents = eventInfo->lumiBlock();
91 if (muPerBXToF == 0.0) {
92 ATH_MSG_DEBUG(
"AverageInteractionsPerCrossing is 0, forcing to 1.0");
96 ToFHits_MU_Weight = 1/muPerBXToF;
97 lbToFBar_Weight = 1/muPerBXToF;
98 weightToFTrainAll = 1/muPerBXToF;
99 weightToFTrainFront = 1/muPerBXToF;
100 weightToFTrainMiddle = 1/muPerBXToF;
101 weightToFTrainEnd = 1/muPerBXToF;
103 for(
unsigned int s = 0; s < NSIDES; s++)
105 lbToFEvents[s] = eventInfo->lumiBlock();
108 fill(
"AFPToFTool",
lb, muPerBXToF);
111 const unsigned int tempBCID = eventInfo->bcid();
114 ATH_MSG_ERROR(
"Unable to retrieve BunchCrossing conditions object (ToF)" );
121 bcidAllToF = tempBCID;
122 fill(
"AFPToFTool", bcidAllToF);
123 if(!bcDataToF->
isFilled(tempBCID-1))
127 else if(bcDataToF->
isFilled(tempBCID+1))
135 bcidToF[position] = tempBCID;
136 fill(
"AFPToFTool", bcidToF[position]);
141 if(! afpToFHitContainer.
isValid())
144 return StatusCode::SUCCESS;
150 if ( !afpTrackContainer.
isValid() ) {
152 return StatusCode::SUCCESS;
156 nTofHits = afpToFHitContainer->size();
157 fill(
"AFPToFTool",
lb, nTofHits);
159 int eventsInStations[4] = {};
162 unsigned int totalHitsPerTrainAll[NSIDES][NTRAINS] = {};
163 unsigned int totalHitsPerTrainFME[NSIDES][NTRAINS][NPOS] = {};
164 unsigned int totalHitsPerBar[NSIDES][NTRAINS][NBARS] = {};
165 unsigned int totalStationHits[NSIDES] = {};
169 if (hitsItr->stationID()<4 && hitsItr->stationID()>=0 && hitsItr->trainID()<4 && hitsItr->trainID()>=0 && hitsItr->barInTrainID()<4 && hitsItr->barInTrainID()>=0)
171 trainID = hitsItr->trainID();
172 barInTrainID = hitsItr->barInTrainID();
173 ++eventsInStations[hitsItr->stationID()];
176 if(hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
179 int side = (hitsItr->stationID() == 3) ? 1 : 0;
180 unsigned int train = hitsItr->trainID();
181 unsigned int bar = hitsItr->barInTrainID();
186 barInTrainIDSide = bar;
189 barInTrainAll = train * 4 + bar;
192 ToFHits_side = eventInfo->lumiBlock();
198 lbToFBar = eventInfo->lumiBlock();
202 ++totalStationHits[side];
203 ++totalHitsPerTrainAll[side][train];
204 if(bar < NBARS) ++totalHitsPerBar[side][train][bar];
205 if(position != NPOS) ++totalHitsPerTrainFME[side][train][position];
208 lbToFTrainAll = eventInfo->lumiBlock();
211 if(position == FRONT)
213 lbToFTrainFront = eventInfo->lumiBlock();
216 else if(position == MIDDLE)
218 lbToFTrainMiddle = eventInfo->lumiBlock();
221 else if(position == END)
223 lbToFTrainEnd = eventInfo->lumiBlock();
231 if(eventsInStations[0] > 0 || eventsInStations[3] > 0)
233 fill(
"AFPToFTool", lbAandCToFEvents);
235 if(eventsInStations[0] > 0)
237 fill(
"AFPToFTool", lbToFEvents[0]);
239 if(eventsInStations[3] > 0)
241 fill(
"AFPToFTool", lbToFEvents[1]);
255 for(
unsigned int side = 0; side < NSIDES; side++)
257 for(
unsigned int train = 0; train < NTRAINS; train++)
259 hitsPerTrainAllPP = totalHitsPerTrainAll[side][train] / muPerBXToF;
262 hitsPerTrainFrontPP = totalHitsPerTrainFME[side][train][FRONT] / muPerBXToF;
263 if(position == FRONT)
266 hitsPerTrainMiddlePP = totalHitsPerTrainFME[side][train][MIDDLE] / muPerBXToF;
267 if(position == MIDDLE)
270 hitsPerTrainEndPP = totalHitsPerTrainFME[side][train][END] / muPerBXToF;
280 for(
unsigned int side = 0; side < NSIDES; side++)
282 for(
unsigned int train = 0; train < NTRAINS; train++)
284 for(
unsigned int bar = 0; bar < NBARS; bar++)
286 hitsPerBarPP = totalHitsPerBar[side][train][bar] / muPerBXToF;
296 for(
unsigned int side = 0; side < NSIDES; side++)
298 hitsPerStationPP = totalStationHits[side] / muPerBXToF;
314 bool channel_present[2][16] = {};
315 bool multihit[2] = {};
316 std::size_t track_count[2] = {};
317 std::size_t train_count[2][4] = {};
321 const auto side = tracksItr->stationID() == 3;
323 if (tracksItr->stationID() != 0 && tracksItr->stationID() != 3)
329 auto times = std::vector<std::vector<std::vector<float>>>(2, std::vector<std::vector<float>>(4, std::vector<float>(4, -10000)));
332 const auto side = hitsItr->stationID() == 3;
333 const auto train = hitsItr->trainID();
334 const auto bar = hitsItr->barInTrainID();
335 const auto channel = 4 * train + bar;
336 const auto tof_time = hitsItr->time();
337 const auto TimePs=(tof_time)*1000;
339 if (track_count[side] != 1)
continue;
341 if (hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
343 if (train < 0 || train >= 4 || bar < 0 || bar >= 4)
continue;
344 if (channel_present[side][channel])
345 multihit[side] =
true;
346 channel_present[side][channel] =
true;
347 ++train_count[side][train];
349 times[side][train][bar]=TimePs;
353 for (uint8_t side : {0, 1})
356 if (track_count[side] != 1)
continue;
358 if (multihit[side])
continue;
360 uint8_t multrain[2] = {};
361 for (uint8_t train = 0; train < 4; ++train) {
362 if (train_count[side][train]>1) {
366 if (multrain[side]>1)
continue;
368 for (uint8_t train = 0; train < 4; ++train) {
369 for (uint8_t bar1 = 0; bar1 < 4; ++bar1) {
370 for (uint8_t bar2 = 0; bar2 < 4; ++bar2) {
372 int comb = bar1*bar2+bar2-1;
373 if (comb==5) {comb=4;}
374 if (comb==8) {comb=5;}
375 int global_comb = train*6 + comb;
376 if (times[side][train][bar1]>-10000 && times[side][train][bar2]>-10000) {
377 crossBarDeltaT[side] = (times[side][train][bar1] - times[side][train][bar2]);
386 return StatusCode::SUCCESS;