157 std::string trackstate_location,
158 EVENT::LCCollection* gbl_kink_data,
159 EVENT::LCCollection* track_data) {
177 std::map<std::string, int> trackstateLocationMapV30_ =
178 { {
"",EVENT::TrackState::AtPerigee},
179 {
"AtPerigee",EVENT::TrackState::AtPerigee},
180 {
"AtIP",EVENT::TrackState::AtIP},
181 {
"AtTarget",EVENT::TrackState::AtTarget},
182 {
"AtFirstHit",EVENT::TrackState::AtFirstHit},
183 {
"AtLastHit",EVENT::TrackState::AtLastHit},
184 {
"AtCalorimeter",EVENT::TrackState::AtCalorimeter},
185 {
"AtVertex",EVENT::TrackState::AtVertex},
186 {
"LastLocation",EVENT::TrackState::LastLocation}
189 std::map<std::string, int> trackstateLocationMapV23_ =
190 { {
"",EVENT::TrackState::AtIP},
217 double bTmp = lc_track->getTrackState(1)->getBLocal();
218 std::map<std::string, int> trackstateLocationMap_;
220 trackstateLocationMap_=trackstateLocationMapV30_;
222 trackstateLocationMap_=trackstateLocationMapV23_;
225 auto it = trackstateLocationMap_.find(trackstate_location);
226 if (it != trackstateLocationMap_.end()){
230 std::cout <<
"[utilities]::ERROR Track State Location " << trackstate_location <<
" Doesn't Exist!" << std::endl;
231 std::cout <<
"Check map in utilities::buildTrack for defined locations" << std::endl;
237 const EVENT::TrackState* ts = lc_track->getTrackState(loc);
249 double tsD0 = ts->getD0();
250 double tsZ0 = ts->getZ0();
251 if(loc==EVENT::TrackState::AtTarget){
252 tsD0=ts->getReferencePoint()[1];
253 tsZ0=ts->getReferencePoint()[2];
257 track->setTrackParameters(tsD0,
263 double position[3] = {
264 ts->getReferencePoint()[1],
265 ts->getReferencePoint()[2],
266 ts->getReferencePoint()[0]
269 track->setCov(
static_cast<std::vector<float>
> (ts->getCovMatrix()));
270 track->setPosition(position);
272 double bLocal = lc_track->getTrackState(loc)->getBLocal();
274 track->setMomentum(bLocal);
277 track->setID(lc_track->id());
280 track->setType(lc_track->getType());
283 track->setChi2(lc_track->getChi2());
286 track->setNdf(lc_track->getNdf());
290 const EVENT::TrackState* track_state
291 = lc_track->getTrackState(trackstateLocationMap_[
"AtCalorimeter"]);
294 double position_at_ecal[3] = {
295 track_state->getReferencePoint()[1],
296 track_state->getReferencePoint()[2],
297 track_state->getReferencePoint()[0]
299 track->setPositionAtEcal(position_at_ecal);
305 std::shared_ptr<UTIL::LCRelationNavigator> gbl_kink_data_nav = std::make_shared<UTIL::LCRelationNavigator>(gbl_kink_data);
308 EVENT::LCObjectVec gbl_kink_data_list
309 = gbl_kink_data_nav->getRelatedFromObjects(lc_track);
313 if (gbl_kink_data_list.size() == 1) {
322 IMPL::LCGenericObjectImpl* gbl_kink_datum
323 =
static_cast<IMPL::LCGenericObjectImpl*
>(gbl_kink_data_list.at(0));
326 for (
int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) {
327 track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink));
328 track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink));
339 std::shared_ptr<UTIL::LCRelationNavigator> track_data_nav = std::make_shared<UTIL::LCRelationNavigator>(track_data);
342 EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track);
346 if (track_data_list.size() == 1) {
349 IMPL::LCGenericObjectImpl* track_datum =
static_cast<IMPL::LCGenericObjectImpl*
>(track_data_list.at(0));
353 if (track_datum->getNDouble() > 14 || track_datum->getNFloat() > 8 || track_datum->getNInt() != 1) {
354 throw std::runtime_error(
"[ TrackingProcessor ]: The collection "
356 +
" has the wrong structure.");
360 for (
int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) {
361 track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index));
365 track->setTrackTime(track_datum->getFloatVal(0));
371 if (track_datum->getNFloat()>3 && abs(bLocal)>10.0)
372 track->setMomentum(track_datum->getFloatVal(1),track_datum->getFloatVal(2),track_datum->getFloatVal(3));
375 track->setTrackVolume(track_datum->getIntVal(0));
379 if( abs(bLocal)>10.0){
380 double bfieldY = -999.9;
381 if(track_datum->getNFloat() > 4){
382 if (loc == trackstateLocationMap_[
""])
383 bfieldY = track_datum->getFloatVal(4);
384 if (loc == trackstateLocationMap_[
"AtTarget"]){
385 bfieldY = track_datum->getFloatVal(5);
387 if (loc == trackstateLocationMap_[
"AtCalorimeter"])
388 bfieldY = track_datum->getFloatVal(6);
389 track->setMomentum(-bfieldY);
400 EVENT::LCCollection* raw_svt_hit_fits) {
402 EVENT::long64 value =
403 EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) |
404 ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 );
405 decoder.setValue(value);
413 rawHit->
setSide(decoder[
"side"]);
418 (int)rawTracker_hit->getADCValues().at(0),
419 (int)rawTracker_hit->getADCValues().at(1),
420 (int)rawTracker_hit->getADCValues().at(2),
421 (int)rawTracker_hit->getADCValues().at(3),
422 (int)rawTracker_hit->getADCValues().at(4),
423 (int)rawTracker_hit->getADCValues().at(5)};
426 if (raw_svt_hit_fits) {
427 std::shared_ptr<UTIL::LCRelationNavigator> rawTracker_hit_fits_nav = std::make_shared<UTIL::LCRelationNavigator>(raw_svt_hit_fits);
431 EVENT::LCObjectVec rawTracker_hit_fits_list
432 = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit);
435 IMPL::LCGenericObjectImpl* hit_fit_param
436 =
static_cast<IMPL::LCGenericObjectImpl*
>(rawTracker_hit_fits_list.at(0));
438 double fit_params[5] = {
439 (double)hit_fit_param->getDoubleVal(0),
440 (double)hit_fit_param->getDoubleVal(1),
441 (double)hit_fit_param->getDoubleVal(2),
442 (double)hit_fit_param->getDoubleVal(3),
443 (double)hit_fit_param->getDoubleVal(4)
445 rawHit->
setFit(fit_params, 0);
446 if(rawTracker_hit_fits_list.size()>1)
448 hit_fit_param =
static_cast<IMPL::LCGenericObjectImpl*
>(rawTracker_hit_fits_list.at(1));
449 fit_params[0] = (double)hit_fit_param->getDoubleVal(0);
450 fit_params[1] = (double)hit_fit_param->getDoubleVal(1);
451 fit_params[2] = (double)hit_fit_param->getDoubleVal(2);
452 fit_params[3] = (double)hit_fit_param->getDoubleVal(3);
453 fit_params[4] = (double)hit_fit_param->getDoubleVal(4);
455 rawHit->
setFit(fit_params, 1);
457 rawHit->
setFitN(rawTracker_hit_fits_list.size());
500 IMPL::TrackerHitImpl* lc_tracker_hit,
501 EVENT::LCCollection* raw_svt_fits, std::vector<RawSvtHit*>* rawHits,
int type,
bool storeRawHit) {
503 if (!tracker_hit || !lc_tracker_hit)
513 UTIL::BitField64 decoder(
"system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12");
516 EVENT::LCObjectVec lc_rawHits = lc_tracker_hit->getRawHits();
518 std::vector<int> rawhit_strips;
519 for (
unsigned int irh = 0 ; irh < lc_rawHits.size(); ++irh) {
521 EVENT::TrackerRawData* rawTracker_hit
522 =
static_cast<EVENT::TrackerRawData*
>(lc_rawHits.at(irh));
525 EVENT::long64 value = EVENT::long64( rawTracker_hit->getCellID0() & 0xffffffff ) |
526 ( EVENT::long64( rawTracker_hit->getCellID1() ) << 32 ) ;
527 decoder.setValue(value);
530 int stripnumber = decoder[
"strip"];
531 rawhit_strips.push_back(stripnumber);
535 rawcharge += rawHit->
getAmp(0);
536 int currentHitVolume = rawHit->
getModule() % 2 ? 1 : 0;
537 int currentHitLayer = (rawHit->
getLayer() - 1 ) / 2;
539 currentHitLayer = rawHit->
getLayer() - 1;
541 volume = currentHitVolume;
543 if ( currentHitVolume != volume)
544 std::cout<<
"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent volume found" <<std::endl;
548 layer = currentHitLayer;
550 if (currentHitLayer != layer)
551 std::cout<<
"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent layer found" <<std::endl;
557 rawHits->push_back(rawHit);
626 double L1_axial_iso = 999999.9;
627 double L1_stereo_iso = 999999.9;
629 for(
int i = 0; i < track->getSvtHits().GetEntries(); i++){
632 int trackhit_id = track_hit->
getID();
633 int trackhit_layer = track_hit->
getLayer();
634 int trackhit_volume = track_hit->
getVolume();
637 double trackhit_time = track_hit->
getTime();
640 if(trackhit_layer > 1)
645 if(trackhit_rawhits.size() < 1)
647 int trackhit_maxstrip = *max_element(trackhit_rawhits.begin(), trackhit_rawhits.end());
648 int trackhit_minstrip = *min_element(trackhit_rawhits.begin(), trackhit_rawhits.end());
652 bool isAxial =
false;
654 if(trackhit_volume == 1){
655 if(trackhit_layer%2 == 1)
658 if(trackhit_volume == 0){
659 if(trackhit_layer%2 == 0)
666 double isohit_dy = 999999.9;
667 double closest_dcharge = 99999.9;
668 double closest_dt = 999999.9;
669 double isohit_y = 999999.9;
671 if ( siClusters ==
nullptr )
673 for(
int j = 0; j < siClusters->size(); j++){
675 int althit_id = althit->
getID();
677 int althit_layer = althit->
getLayer();
680 double althit_time = althit->
getTime();
683 if (althit_layer != trackhit_layer)
687 if(althit_volume != trackhit_volume)
691 if (althit_id == trackhit_id)
695 if ( (trackhit_volume == 0 && althit_y < trackhit_y) ||
696 (trackhit_volume == 1 && althit_y > trackhit_y))
700 if(std::abs(althit_time) > 30.0)
705 int althit_maxstrip = *max_element(althit_rawhits.begin(), althit_rawhits.end());
706 int althit_minstrip = *min_element(althit_rawhits.begin(), althit_rawhits.end());
707 if(trackhit_minstrip - althit_maxstrip <= 1 && althit_minstrip - trackhit_maxstrip <= 1)
711 if (std::abs(trackhit_y - althit_y) < isohit_dy){
712 isohit_dy = std::abs(trackhit_y-althit_y);
713 closest_althit = althit;
714 closest_dcharge = trackhit_charge - althit_charge;
715 closest_dt = trackhit_time - althit_time;
721 L1_axial_iso = isohit_dy;
723 L1_stereo_iso = isohit_dy;
727 if(L1_axial_iso < L1_stereo_iso){
731 return L1_stereo_iso;
736 std::map<int, int> nHits4part_ele;
737 for(
int i =0; i < ele_trk->
getMcpHits().size(); i++)
739 int partID = ele_trk->
getMcpHits().at(i).second;
740 if ( nHits4part_ele.find(partID) == nHits4part_ele.end() )
743 nHits4part_ele[partID] = 1;
748 nHits4part_ele[partID]++;
753 int maxNHits_ele = 0;
755 for (std::map<int,int>::iterator it=nHits4part_ele.begin(); it!=nHits4part_ele.end(); ++it)
757 if(it->second > maxNHits_ele)
759 maxNHits_ele = it->second;
760 maxID_ele = it->first;
765 std::map<int, int> nHits4part_pos;
766 for(
int i =0; i < pos_trk->
getMcpHits().size(); i++)
768 int partID = pos_trk->
getMcpHits().at(i).second;
769 if ( nHits4part_pos.find(partID) == nHits4part_pos.end() )
772 nHits4part_pos[partID] = 1;
777 nHits4part_pos[partID]++;
782 int maxNHits_pos = 0;
784 for (std::map<int,int>::iterator it=nHits4part_pos.begin(); it!=nHits4part_pos.end(); ++it)
786 if(it->second > maxNHits_pos)
788 maxNHits_pos = it->second;
789 maxID_pos = it->first;
794 bool ele_trueAxialL1 =
false;
795 bool ele_trueStereoL1 =
false;
796 bool ele_trueAxialL2 =
false;
797 bool ele_trueStereoL2 =
false;
798 bool pos_trueAxialL1 =
false;
799 bool pos_trueStereoL1 =
false;
800 bool pos_trueAxialL2 =
false;
801 bool pos_trueStereoL2 =
false;
804 for(
int i = 0; i < ele_trk->
getMcpHits().size(); i++){
805 int mcpid = ele_trk->
getMcpHits().at(i).second;
806 int layer = ele_trk->
getMcpHits().at(i).first;
813 bool isAxial =
false;
814 bool isStereo =
false;
822 else if(layer > 1 && layer < 4)
840 if(mcpid == maxID_ele)
846 ele_trueAxialL1 =
true;
848 ele_trueAxialL2 =
true;
852 ele_trueStereoL1 =
true;
854 ele_trueStereoL2 =
true;
861 for(
int i = 0; i < pos_trk->
getMcpHits().size(); i++){
862 int mcpid = pos_trk->
getMcpHits().at(i).second;
863 int layer = pos_trk->
getMcpHits().at(i).first;
870 bool isAxial =
false;
871 bool isStereo =
false;
879 else if(layer > 1 && layer < 4)
897 if(mcpid == maxID_pos)
903 pos_trueAxialL1 =
true;
905 pos_trueAxialL2 =
true;
909 pos_trueStereoL1 =
true;
911 pos_trueStereoL2 =
true;
919 if(ele_trueAxialL1 && ele_trueStereoL1) L1L2hitCode = L1L2hitCode | (0x1 << 3);
920 if(pos_trueAxialL1 && pos_trueStereoL1) L1L2hitCode = L1L2hitCode | (0x1 << 2);
921 if(ele_trueAxialL2 && ele_trueStereoL2) L1L2hitCode = L1L2hitCode | (0x1 << 1);
922 if(pos_trueAxialL2 && pos_trueStereoL2) L1L2hitCode = L1L2hitCode | (0x1 << 0);
926 if(ele_trueAxialL1) L1hitCode = L1hitCode | (0x1 << 3);
927 if(ele_trueStereoL1) L1hitCode = L1hitCode | (0x1 << 2);
928 if(pos_trueAxialL1) L1hitCode = L1hitCode | (0x1 << 1);
929 if(pos_trueStereoL1) L1hitCode = L1hitCode | (0x1 << 0);
932 if(ele_trueAxialL2) L2hitCode = L2hitCode | (0x1 << 3);
933 if(ele_trueStereoL2) L2hitCode = L2hitCode | (0x1 << 2);
934 if(pos_trueAxialL2) L2hitCode = L2hitCode | (0x1 << 1);
935 if(pos_trueStereoL2) L2hitCode = L2hitCode | (0x1 << 0);
939 double &vtx_proj_x_signif,
double &vtx_proj_y_signif,
double vtx_x,
double vtx_y,
double vtx_z,
940 double vtx_px,
double vtx_py,
double vtx_pz){
949 for(
auto entry : v0proj_fits.items()){
950 int check_run = std::stoi(entry.key());
954 closest_run = check_run;
957 double target_pos = v0proj_fits[std::to_string(closest_run)][
"target_position"];
958 double rot_mean_x = v0proj_fits[std::to_string(closest_run)][
"rotated_mean_x"];
959 double rot_mean_y = v0proj_fits[std::to_string(closest_run)][
"rotated_mean_y"];
960 double rot_sigma_x = v0proj_fits[std::to_string(closest_run)][
"rotated_sigma_x"];
961 double rot_sigma_y = v0proj_fits[std::to_string(closest_run)][
"rotated_sigma_y"];
962 double rotation_angle = (double)v0proj_fits[std::to_string(closest_run)][
"rotation_angle_mrad"]/1000.0;
965 vtx_proj_x = vtx_x - ((vtx_z - target_pos)*(vtx_px/vtx_pz));
966 vtx_proj_y = vtx_y - ((vtx_z - target_pos)*(vtx_py/vtx_pz));
969 double rot_vtx_proj_x = vtx_proj_x*std::cos(rotation_angle) - vtx_proj_y*std::sin(rotation_angle);
970 double rot_vtx_proj_y = vtx_proj_x*std::sin(rotation_angle) + vtx_proj_y*std::cos(rotation_angle);
973 vtx_proj_x_signif = (rot_vtx_proj_x - rot_mean_x)/rot_sigma_x;
974 vtx_proj_y_signif = (rot_vtx_proj_y - rot_mean_y)/rot_sigma_y;
977 double significance = std::sqrt( vtx_proj_x_signif*vtx_proj_x_signif + vtx_proj_y_signif*vtx_proj_y_signif );