55 std::string trackstate_location,
56 EVENT::LCCollection* gbl_kink_data,
57 EVENT::LCCollection* track_data)
66 part->
setCharge(lc_particle->getCharge());
69 part->
setType(lc_particle->getType());
72 part->
setEnergy(lc_particle->getEnergy());
78 part->
setMass(lc_particle->getMass());
84 part->
setPDG(lc_particle->getParticleIDUsed()->getPDG());
87 if (lc_particle->getTracks().size()>0)
89 Track * trkPtr =
utils::buildTrack(lc_particle->getTracks()[0],trackstate_location, gbl_kink_data, track_data);
95 if (lc_particle->getClusters().size() > 0)
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);
242 track->setTrackParameters(ts->getD0(),
248 double position[3] = {
249 ts->getReferencePoint()[1],
250 ts->getReferencePoint()[2],
251 ts->getReferencePoint()[0]
254 track->setCov(
static_cast<std::vector<float>
> (ts->getCovMatrix()));
255 track->setPosition(position);
257 double bLocal = lc_track->getTrackState(loc)->getBLocal();
259 track->setMomentum(bLocal);
262 track->setID(lc_track->id());
265 track->setType(lc_track->getType());
268 track->setChi2(lc_track->getChi2());
271 track->setNdf(lc_track->getNdf());
275 const EVENT::TrackState* track_state
276 = lc_track->getTrackState(trackstateLocationMap_[
"AtCalorimeter"]);
279 double position_at_ecal[3] = {
280 track_state->getReferencePoint()[1],
281 track_state->getReferencePoint()[2],
282 track_state->getReferencePoint()[0]
284 track->setPositionAtEcal(position_at_ecal);
290 std::shared_ptr<UTIL::LCRelationNavigator> gbl_kink_data_nav = std::make_shared<UTIL::LCRelationNavigator>(gbl_kink_data);
293 EVENT::LCObjectVec gbl_kink_data_list
294 = gbl_kink_data_nav->getRelatedFromObjects(lc_track);
298 if (gbl_kink_data_list.size() == 1) {
307 IMPL::LCGenericObjectImpl* gbl_kink_datum
308 =
static_cast<IMPL::LCGenericObjectImpl*
>(gbl_kink_data_list.at(0));
311 for (
int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) {
312 track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink));
313 track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink));
324 std::shared_ptr<UTIL::LCRelationNavigator> track_data_nav = std::make_shared<UTIL::LCRelationNavigator>(track_data);
327 EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track);
331 if (track_data_list.size() == 1) {
334 IMPL::LCGenericObjectImpl* track_datum =
static_cast<IMPL::LCGenericObjectImpl*
>(track_data_list.at(0));
338 if (track_datum->getNDouble() > 14 || track_datum->getNFloat() > 8 || track_datum->getNInt() != 1) {
339 throw std::runtime_error(
"[ TrackingProcessor ]: The collection "
341 +
" has the wrong structure.");
345 for (
int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) {
346 track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index));
350 track->setTrackTime(track_datum->getFloatVal(0));
356 if (track_datum->getNFloat()>3 && abs(bLocal)>10.0)
357 track->setMomentum(track_datum->getFloatVal(1),track_datum->getFloatVal(2),track_datum->getFloatVal(3));
360 track->setTrackVolume(track_datum->getIntVal(0));
364 if( abs(bLocal)>10.0){
365 double bfieldY = -999.9;
366 if(track_datum->getNFloat() > 4){
367 if (loc == trackstateLocationMap_[
""])
368 bfieldY = track_datum->getFloatVal(4);
369 if (loc == trackstateLocationMap_[
"AtTarget"]){
370 bfieldY = track_datum->getFloatVal(5);
372 if (loc == trackstateLocationMap_[
"AtCalorimeter"])
373 bfieldY = track_datum->getFloatVal(6);
374 track->setMomentum(-bfieldY);
385 EVENT::LCCollection* raw_svt_hit_fits) {
387 EVENT::long64 value =
388 EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) |
389 ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 );
390 decoder.setValue(value);
398 rawHit->
setSide(decoder[
"side"]);
403 (int)rawTracker_hit->getADCValues().at(0),
404 (int)rawTracker_hit->getADCValues().at(1),
405 (int)rawTracker_hit->getADCValues().at(2),
406 (int)rawTracker_hit->getADCValues().at(3),
407 (int)rawTracker_hit->getADCValues().at(4),
408 (int)rawTracker_hit->getADCValues().at(5)};
411 if (raw_svt_hit_fits) {
412 std::shared_ptr<UTIL::LCRelationNavigator> rawTracker_hit_fits_nav = std::make_shared<UTIL::LCRelationNavigator>(raw_svt_hit_fits);
416 EVENT::LCObjectVec rawTracker_hit_fits_list
417 = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit);
420 IMPL::LCGenericObjectImpl* hit_fit_param
421 =
static_cast<IMPL::LCGenericObjectImpl*
>(rawTracker_hit_fits_list.at(0));
423 double fit_params[5] = {
424 (double)hit_fit_param->getDoubleVal(0),
425 (double)hit_fit_param->getDoubleVal(1),
426 (double)hit_fit_param->getDoubleVal(2),
427 (double)hit_fit_param->getDoubleVal(3),
428 (double)hit_fit_param->getDoubleVal(4)
430 rawHit->
setFit(fit_params, 0);
431 if(rawTracker_hit_fits_list.size()>1)
433 hit_fit_param =
static_cast<IMPL::LCGenericObjectImpl*
>(rawTracker_hit_fits_list.at(1));
434 fit_params[0] = (double)hit_fit_param->getDoubleVal(0);
435 fit_params[1] = (double)hit_fit_param->getDoubleVal(1);
436 fit_params[2] = (double)hit_fit_param->getDoubleVal(2);
437 fit_params[3] = (double)hit_fit_param->getDoubleVal(3);
438 fit_params[4] = (double)hit_fit_param->getDoubleVal(4);
440 rawHit->
setFit(fit_params, 1);
442 rawHit->
setFitN(rawTracker_hit_fits_list.size());
485 IMPL::TrackerHitImpl* lc_tracker_hit,
486 EVENT::LCCollection* raw_svt_fits, std::vector<RawSvtHit*>* rawHits,
int type,
bool storeRawHit) {
488 if (!tracker_hit || !lc_tracker_hit)
498 UTIL::BitField64 decoder(
"system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12");
501 EVENT::LCObjectVec lc_rawHits = lc_tracker_hit->getRawHits();
503 std::vector<int> rawhit_strips;
504 for (
unsigned int irh = 0 ; irh < lc_rawHits.size(); ++irh) {
506 EVENT::TrackerRawData* rawTracker_hit
507 =
static_cast<EVENT::TrackerRawData*
>(lc_rawHits.at(irh));
510 EVENT::long64 value = EVENT::long64( rawTracker_hit->getCellID0() & 0xffffffff ) |
511 ( EVENT::long64( rawTracker_hit->getCellID1() ) << 32 ) ;
512 decoder.setValue(value);
515 int stripnumber = decoder[
"strip"];
516 rawhit_strips.push_back(stripnumber);
520 rawcharge += rawHit->
getAmp(0);
521 int currentHitVolume = rawHit->
getModule() % 2 ? 1 : 0;
522 int currentHitLayer = (rawHit->
getLayer() - 1 ) / 2;
524 currentHitLayer = rawHit->
getLayer() - 1;
526 volume = currentHitVolume;
528 if ( currentHitVolume != volume)
529 std::cout<<
"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent volume found" <<std::endl;
533 layer = currentHitLayer;
535 if (currentHitLayer != layer)
536 std::cout<<
"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent layer found" <<std::endl;
542 rawHits->push_back(rawHit);
611 double L1_axial_iso = 999999.9;
612 double L1_stereo_iso = 999999.9;
614 for(
int i = 0; i < track->getSvtHits().GetEntries(); i++){
617 int trackhit_id = track_hit->
getID();
618 int trackhit_layer = track_hit->
getLayer();
619 int trackhit_volume = track_hit->
getVolume();
622 double trackhit_time = track_hit->
getTime();
625 if(trackhit_layer > 1)
630 if(trackhit_rawhits.size() < 1)
632 int trackhit_maxstrip = *max_element(trackhit_rawhits.begin(), trackhit_rawhits.end());
633 int trackhit_minstrip = *min_element(trackhit_rawhits.begin(), trackhit_rawhits.end());
637 bool isAxial =
false;
639 if(trackhit_volume == 1){
640 if(trackhit_layer%2 == 1)
643 if(trackhit_volume == 0){
644 if(trackhit_layer%2 == 0)
651 double isohit_dy = 999999.9;
652 double closest_dcharge = 99999.9;
653 double closest_dt = 999999.9;
654 double isohit_y = 999999.9;
656 if ( siClusters ==
nullptr )
658 for(
int j = 0; j < siClusters->size(); j++){
660 int althit_id = althit->
getID();
662 int althit_layer = althit->
getLayer();
665 double althit_time = althit->
getTime();
668 if (althit_layer != trackhit_layer)
672 if(althit_volume != trackhit_volume)
676 if (althit_id == trackhit_id)
680 if ( (trackhit_volume == 0 && althit_y < trackhit_y) ||
681 (trackhit_volume == 1 && althit_y > trackhit_y))
685 if(std::abs(althit_time) > 30.0)
690 int althit_maxstrip = *max_element(althit_rawhits.begin(), althit_rawhits.end());
691 int althit_minstrip = *min_element(althit_rawhits.begin(), althit_rawhits.end());
692 if(trackhit_minstrip - althit_maxstrip <= 1 && althit_minstrip - trackhit_maxstrip <= 1)
696 if (std::abs(trackhit_y - althit_y) < isohit_dy){
697 isohit_dy = std::abs(trackhit_y-althit_y);
698 closest_althit = althit;
699 closest_dcharge = trackhit_charge - althit_charge;
700 closest_dt = trackhit_time - althit_time;
706 L1_axial_iso = isohit_dy;
708 L1_stereo_iso = isohit_dy;
712 if(L1_axial_iso < L1_stereo_iso){
716 return L1_stereo_iso;
721 std::map<int, int> nHits4part_ele;
722 for(
int i =0; i < ele_trk->
getMcpHits().size(); i++)
724 int partID = ele_trk->
getMcpHits().at(i).second;
725 if ( nHits4part_ele.find(partID) == nHits4part_ele.end() )
728 nHits4part_ele[partID] = 1;
733 nHits4part_ele[partID]++;
738 int maxNHits_ele = 0;
740 for (std::map<int,int>::iterator it=nHits4part_ele.begin(); it!=nHits4part_ele.end(); ++it)
742 if(it->second > maxNHits_ele)
744 maxNHits_ele = it->second;
745 maxID_ele = it->first;
750 std::map<int, int> nHits4part_pos;
751 for(
int i =0; i < pos_trk->
getMcpHits().size(); i++)
753 int partID = pos_trk->
getMcpHits().at(i).second;
754 if ( nHits4part_pos.find(partID) == nHits4part_pos.end() )
757 nHits4part_pos[partID] = 1;
762 nHits4part_pos[partID]++;
767 int maxNHits_pos = 0;
769 for (std::map<int,int>::iterator it=nHits4part_pos.begin(); it!=nHits4part_pos.end(); ++it)
771 if(it->second > maxNHits_pos)
773 maxNHits_pos = it->second;
774 maxID_pos = it->first;
779 bool ele_trueAxialL1 =
false;
780 bool ele_trueStereoL1 =
false;
781 bool ele_trueAxialL2 =
false;
782 bool ele_trueStereoL2 =
false;
783 bool pos_trueAxialL1 =
false;
784 bool pos_trueStereoL1 =
false;
785 bool pos_trueAxialL2 =
false;
786 bool pos_trueStereoL2 =
false;
789 for(
int i = 0; i < ele_trk->
getMcpHits().size(); i++){
790 int mcpid = ele_trk->
getMcpHits().at(i).second;
791 int layer = ele_trk->
getMcpHits().at(i).first;
798 bool isAxial =
false;
799 bool isStereo =
false;
807 else if(layer > 1 && layer < 4)
825 if(mcpid == maxID_ele)
831 ele_trueAxialL1 =
true;
833 ele_trueAxialL2 =
true;
837 ele_trueStereoL1 =
true;
839 ele_trueStereoL2 =
true;
846 for(
int i = 0; i < pos_trk->
getMcpHits().size(); i++){
847 int mcpid = pos_trk->
getMcpHits().at(i).second;
848 int layer = pos_trk->
getMcpHits().at(i).first;
855 bool isAxial =
false;
856 bool isStereo =
false;
864 else if(layer > 1 && layer < 4)
882 if(mcpid == maxID_pos)
888 pos_trueAxialL1 =
true;
890 pos_trueAxialL2 =
true;
894 pos_trueStereoL1 =
true;
896 pos_trueStereoL2 =
true;
904 if(ele_trueAxialL1 && ele_trueStereoL1) L1L2hitCode = L1L2hitCode | (0x1 << 3);
905 if(pos_trueAxialL1 && pos_trueStereoL1) L1L2hitCode = L1L2hitCode | (0x1 << 2);
906 if(ele_trueAxialL2 && ele_trueStereoL2) L1L2hitCode = L1L2hitCode | (0x1 << 1);
907 if(pos_trueAxialL2 && pos_trueStereoL2) L1L2hitCode = L1L2hitCode | (0x1 << 0);
911 if(ele_trueAxialL1) L1hitCode = L1hitCode | (0x1 << 3);
912 if(ele_trueStereoL1) L1hitCode = L1hitCode | (0x1 << 2);
913 if(pos_trueAxialL1) L1hitCode = L1hitCode | (0x1 << 1);
914 if(pos_trueStereoL1) L1hitCode = L1hitCode | (0x1 << 0);
917 if(ele_trueAxialL2) L2hitCode = L2hitCode | (0x1 << 3);
918 if(ele_trueStereoL2) L2hitCode = L2hitCode | (0x1 << 2);
919 if(pos_trueAxialL2) L2hitCode = L2hitCode | (0x1 << 1);
920 if(pos_trueStereoL2) L2hitCode = L2hitCode | (0x1 << 0);
924 double &vtx_proj_x_signif,
double &vtx_proj_y_signif,
double vtx_x,
double vtx_y,
double vtx_z,
925 double vtx_px,
double vtx_py,
double vtx_pz){
934 for(
auto entry : v0proj_fits.items()){
935 int check_run = std::stoi(entry.key());
939 closest_run = check_run;
942 double target_pos = v0proj_fits[std::to_string(closest_run)][
"target_position"];
943 double rot_mean_x = v0proj_fits[std::to_string(closest_run)][
"rotated_mean_x"];
944 double rot_mean_y = v0proj_fits[std::to_string(closest_run)][
"rotated_mean_y"];
945 double rot_sigma_x = v0proj_fits[std::to_string(closest_run)][
"rotated_sigma_x"];
946 double rot_sigma_y = v0proj_fits[std::to_string(closest_run)][
"rotated_sigma_y"];
947 double rotation_angle = (double)v0proj_fits[std::to_string(closest_run)][
"rotation_angle_mrad"]/1000.0;
950 vtx_proj_x = vtx_x - ((vtx_z - target_pos)*(vtx_px/vtx_pz));
951 vtx_proj_y = vtx_y - ((vtx_z - target_pos)*(vtx_py/vtx_pz));
954 double rot_vtx_proj_x = vtx_proj_x*std::cos(rotation_angle) - vtx_proj_y*std::sin(rotation_angle);
955 double rot_vtx_proj_y = vtx_proj_x*std::sin(rotation_angle) + vtx_proj_y*std::cos(rotation_angle);
958 vtx_proj_x_signif = (rot_vtx_proj_x - rot_mean_x)/rot_sigma_x;
959 vtx_proj_y_signif = (rot_vtx_proj_y - rot_mean_y)/rot_sigma_y;
962 double significance = std::sqrt( vtx_proj_x_signif*vtx_proj_x_signif + vtx_proj_y_signif*vtx_proj_y_signif );