57 std::string trackstate_location,
58 EVENT::LCCollection* gbl_kink_data,
59 EVENT::LCCollection* track_data)
68 part->
setCharge(lc_particle->getCharge());
71 part->
setType(lc_particle->getType());
74 part->
setEnergy(lc_particle->getEnergy());
80 part->
setMass(lc_particle->getMass());
86 part->
setPDG(lc_particle->getParticleIDUsed()->getPDG());
89 if (lc_particle->getTracks().size()>0)
91 Track * trkPtr =
utils::buildTrack(lc_particle->getTracks()[0],trackstate_location, gbl_kink_data, track_data);
97 if (lc_particle->getClusters().size() > 0)
159 std::string trackstate_location,
160 EVENT::LCCollection* gbl_kink_data,
161 EVENT::LCCollection* track_data) {
167 std::map<std::string, int> trackstateLocationMap_ = {
168 {
"", EVENT::TrackState::AtIP},
169 {
"AtTarget", EVENT::TrackState::LastLocation}
173 auto it = trackstateLocationMap_.find(trackstate_location);
174 if (it != trackstateLocationMap_.end()){
178 std::cout <<
"[utilities]::ERROR Track State Location " << trackstate_location <<
" Doesn't Exist!" << std::endl;
179 std::cout <<
"Check map in utilities::buildTrack for defined locations" << std::endl;
185 if (loc == trackstateLocationMap_[
""]){
187 track->setTrackParameters(lc_track->getD0(),
189 lc_track->getOmega(),
190 lc_track->getTanLambda(),
194 track->setCov(
static_cast<std::vector<float>
> (lc_track->getCovMatrix()));
200 const EVENT::TrackState* ts = lc_track->getTrackState(loc);
205 track->setTrackParameters(ts->getD0(),
211 double position[3] = {
212 ts->getReferencePoint()[1],
213 ts->getReferencePoint()[2],
214 ts->getReferencePoint()[0]
217 track->setCov(
static_cast<std::vector<float>
> (ts->getCovMatrix()));
219 track->setPosition(position);
223 track->setID(lc_track->id());
226 track->setType(lc_track->getType());
229 track->setChi2(lc_track->getChi2());
232 track->setNdf(lc_track->getNdf());
236 const EVENT::TrackState* track_state
237 = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter);
240 double position_at_ecal[3] = {
241 track_state->getReferencePoint()[1],
242 track_state->getReferencePoint()[2],
243 track_state->getReferencePoint()[0]
245 track->setPositionAtEcal(position_at_ecal);
251 std::shared_ptr<UTIL::LCRelationNavigator> gbl_kink_data_nav = std::make_shared<UTIL::LCRelationNavigator>(gbl_kink_data);
254 EVENT::LCObjectVec gbl_kink_data_list
255 = gbl_kink_data_nav->getRelatedFromObjects(lc_track);
259 if (gbl_kink_data_list.size() == 1) {
268 IMPL::LCGenericObjectImpl* gbl_kink_datum
269 =
static_cast<IMPL::LCGenericObjectImpl*
>(gbl_kink_data_list.at(0));
272 for (
int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) {
273 track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink));
274 track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink));
285 std::shared_ptr<UTIL::LCRelationNavigator> track_data_nav = std::make_shared<UTIL::LCRelationNavigator>(track_data);
288 EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track);
292 if (track_data_list.size() == 1) {
295 IMPL::LCGenericObjectImpl* track_datum =
static_cast<IMPL::LCGenericObjectImpl*
>(track_data_list.at(0));
299 if (track_datum->getNDouble() > 14 || track_datum->getNFloat() > 8 || track_datum->getNInt() != 1) {
300 throw std::runtime_error(
"[ TrackingProcessor ]: The collection "
302 +
" has the wrong structure.");
306 for (
int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) {
307 track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index));
311 track->setTrackTime(track_datum->getFloatVal(0));
314 if (track_datum->getNFloat()>3)
315 track->setMomentum(track_datum->getFloatVal(1),track_datum->getFloatVal(2),track_datum->getFloatVal(3));
318 track->setTrackVolume(track_datum->getIntVal(0));
321 double bfieldY = -999.9;
322 if(track_datum->getNFloat() > 4){
323 if (loc == trackstateLocationMap_[
""])
324 bfieldY = track_datum->getFloatVal(4);
325 if (loc == trackstateLocationMap_[
"AtTarget"]){
326 bfieldY = track_datum->getFloatVal(5);
328 if (loc == trackstateLocationMap_[
"AtCalorimeter"])
329 bfieldY = track_datum->getFloatVal(6);
331 track->setMomentum(-bfieldY);
341 EVENT::LCCollection* raw_svt_hit_fits) {
343 EVENT::long64 value =
344 EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) |
345 ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 );
346 decoder.setValue(value);
354 rawHit->
setSide(decoder[
"side"]);
359 (int)rawTracker_hit->getADCValues().at(0),
360 (int)rawTracker_hit->getADCValues().at(1),
361 (int)rawTracker_hit->getADCValues().at(2),
362 (int)rawTracker_hit->getADCValues().at(3),
363 (int)rawTracker_hit->getADCValues().at(4),
364 (int)rawTracker_hit->getADCValues().at(5)};
367 if (raw_svt_hit_fits) {
368 std::shared_ptr<UTIL::LCRelationNavigator> rawTracker_hit_fits_nav = std::make_shared<UTIL::LCRelationNavigator>(raw_svt_hit_fits);
372 EVENT::LCObjectVec rawTracker_hit_fits_list
373 = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit);
376 IMPL::LCGenericObjectImpl* hit_fit_param
377 =
static_cast<IMPL::LCGenericObjectImpl*
>(rawTracker_hit_fits_list.at(0));
379 double fit_params[5] = {
380 (double)hit_fit_param->getDoubleVal(0),
381 (double)hit_fit_param->getDoubleVal(1),
382 (double)hit_fit_param->getDoubleVal(2),
383 (double)hit_fit_param->getDoubleVal(3),
384 (double)hit_fit_param->getDoubleVal(4)
386 rawHit->
setFit(fit_params, 0);
387 if(rawTracker_hit_fits_list.size()>1)
389 hit_fit_param =
static_cast<IMPL::LCGenericObjectImpl*
>(rawTracker_hit_fits_list.at(1));
390 fit_params[0] = (double)hit_fit_param->getDoubleVal(0);
391 fit_params[1] = (double)hit_fit_param->getDoubleVal(1);
392 fit_params[2] = (double)hit_fit_param->getDoubleVal(2);
393 fit_params[3] = (double)hit_fit_param->getDoubleVal(3);
394 fit_params[4] = (double)hit_fit_param->getDoubleVal(4);
396 rawHit->
setFit(fit_params, 1);
398 rawHit->
setFitN(rawTracker_hit_fits_list.size());
441 IMPL::TrackerHitImpl* lc_tracker_hit,
442 EVENT::LCCollection* raw_svt_fits, std::vector<RawSvtHit*>* rawHits,
int type,
bool storeRawHit) {
444 if (!tracker_hit || !lc_tracker_hit)
454 UTIL::BitField64 decoder(
"system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12");
457 EVENT::LCObjectVec lc_rawHits = lc_tracker_hit->getRawHits();
459 std::vector<int> rawhit_strips;
460 for (
unsigned int irh = 0 ; irh < lc_rawHits.size(); ++irh) {
462 EVENT::TrackerRawData* rawTracker_hit
463 =
static_cast<EVENT::TrackerRawData*
>(lc_rawHits.at(irh));
466 EVENT::long64 value = EVENT::long64( rawTracker_hit->getCellID0() & 0xffffffff ) |
467 ( EVENT::long64( rawTracker_hit->getCellID1() ) << 32 ) ;
468 decoder.setValue(value);
471 int stripnumber = decoder[
"strip"];
472 rawhit_strips.push_back(stripnumber);
476 rawcharge += rawHit->
getAmp(0);
477 int currentHitVolume = rawHit->
getModule() % 2 ? 1 : 0;
478 int currentHitLayer = (rawHit->
getLayer() - 1 ) / 2;
480 currentHitLayer = rawHit->
getLayer() - 1;
482 volume = currentHitVolume;
484 if ( currentHitVolume != volume)
485 std::cout<<
"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent volume found" <<std::endl;
489 layer = currentHitLayer;
491 if (currentHitLayer != layer)
492 std::cout<<
"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent layer found" <<std::endl;
498 rawHits->push_back(rawHit);
567 double L1_axial_iso = 999999.9;
568 double L1_stereo_iso = 999999.9;
570 for(
int i = 0; i < track->getSvtHits().GetEntries(); i++){
573 int trackhit_id = track_hit->
getID();
574 int trackhit_layer = track_hit->
getLayer();
575 int trackhit_volume = track_hit->
getVolume();
578 double trackhit_time = track_hit->
getTime();
581 if(trackhit_layer > 1)
586 if(trackhit_rawhits.size() < 1)
588 int trackhit_maxstrip = *max_element(trackhit_rawhits.begin(), trackhit_rawhits.end());
589 int trackhit_minstrip = *min_element(trackhit_rawhits.begin(), trackhit_rawhits.end());
593 bool isAxial =
false;
595 if(trackhit_volume == 1){
596 if(trackhit_layer%2 == 1)
599 if(trackhit_volume == 0){
600 if(trackhit_layer%2 == 0)
607 double isohit_dy = 999999.9;
608 double closest_dcharge = 99999.9;
609 double closest_dt = 999999.9;
610 double isohit_y = 999999.9;
612 if ( siClusters ==
nullptr )
614 for(
int j = 0; j < siClusters->size(); j++){
616 int althit_id = althit->
getID();
618 int althit_layer = althit->
getLayer();
621 double althit_time = althit->
getTime();
624 if (althit_layer != trackhit_layer)
628 if(althit_volume != trackhit_volume)
632 if (althit_id == trackhit_id)
636 if ( (trackhit_volume == 0 && althit_y < trackhit_y) ||
637 (trackhit_volume == 1 && althit_y > trackhit_y))
641 if(std::abs(althit_time) > 30.0)
646 int althit_maxstrip = *max_element(althit_rawhits.begin(), althit_rawhits.end());
647 int althit_minstrip = *min_element(althit_rawhits.begin(), althit_rawhits.end());
648 if(trackhit_minstrip - althit_maxstrip <= 1 && althit_minstrip - trackhit_maxstrip <= 1)
652 if (std::abs(trackhit_y - althit_y) < isohit_dy){
653 isohit_dy = std::abs(trackhit_y-althit_y);
654 closest_althit = althit;
655 closest_dcharge = trackhit_charge - althit_charge;
656 closest_dt = trackhit_time - althit_time;
662 L1_axial_iso = isohit_dy;
664 L1_stereo_iso = isohit_dy;
668 if(L1_axial_iso < L1_stereo_iso){
672 return L1_stereo_iso;
677 std::map<int, int> nHits4part_ele;
678 for(
int i =0; i < ele_trk->
getMcpHits().size(); i++)
680 int partID = ele_trk->
getMcpHits().at(i).second;
681 if ( nHits4part_ele.find(partID) == nHits4part_ele.end() )
684 nHits4part_ele[partID] = 1;
689 nHits4part_ele[partID]++;
694 int maxNHits_ele = 0;
696 for (std::map<int,int>::iterator it=nHits4part_ele.begin(); it!=nHits4part_ele.end(); ++it)
698 if(it->second > maxNHits_ele)
700 maxNHits_ele = it->second;
701 maxID_ele = it->first;
706 std::map<int, int> nHits4part_pos;
707 for(
int i =0; i < pos_trk->
getMcpHits().size(); i++)
709 int partID = pos_trk->
getMcpHits().at(i).second;
710 if ( nHits4part_pos.find(partID) == nHits4part_pos.end() )
713 nHits4part_pos[partID] = 1;
718 nHits4part_pos[partID]++;
723 int maxNHits_pos = 0;
725 for (std::map<int,int>::iterator it=nHits4part_pos.begin(); it!=nHits4part_pos.end(); ++it)
727 if(it->second > maxNHits_pos)
729 maxNHits_pos = it->second;
730 maxID_pos = it->first;
735 bool ele_trueAxialL1 =
false;
736 bool ele_trueStereoL1 =
false;
737 bool ele_trueAxialL2 =
false;
738 bool ele_trueStereoL2 =
false;
739 bool pos_trueAxialL1 =
false;
740 bool pos_trueStereoL1 =
false;
741 bool pos_trueAxialL2 =
false;
742 bool pos_trueStereoL2 =
false;
745 for(
int i = 0; i < ele_trk->
getMcpHits().size(); i++){
746 int mcpid = ele_trk->
getMcpHits().at(i).second;
747 int layer = ele_trk->
getMcpHits().at(i).first;
754 bool isAxial =
false;
755 bool isStereo =
false;
763 else if(layer > 1 && layer < 4)
781 if(mcpid == maxID_ele)
787 ele_trueAxialL1 =
true;
789 ele_trueAxialL2 =
true;
793 ele_trueStereoL1 =
true;
795 ele_trueStereoL2 =
true;
802 for(
int i = 0; i < pos_trk->
getMcpHits().size(); i++){
803 int mcpid = pos_trk->
getMcpHits().at(i).second;
804 int layer = pos_trk->
getMcpHits().at(i).first;
811 bool isAxial =
false;
812 bool isStereo =
false;
820 else if(layer > 1 && layer < 4)
838 if(mcpid == maxID_pos)
844 pos_trueAxialL1 =
true;
846 pos_trueAxialL2 =
true;
850 pos_trueStereoL1 =
true;
852 pos_trueStereoL2 =
true;
860 if(ele_trueAxialL1 && ele_trueStereoL1) L1L2hitCode = L1L2hitCode | (0x1 << 3);
861 if(pos_trueAxialL1 && pos_trueStereoL1) L1L2hitCode = L1L2hitCode | (0x1 << 2);
862 if(ele_trueAxialL2 && ele_trueStereoL2) L1L2hitCode = L1L2hitCode | (0x1 << 1);
863 if(pos_trueAxialL2 && pos_trueStereoL2) L1L2hitCode = L1L2hitCode | (0x1 << 0);
867 if(ele_trueAxialL1) L1hitCode = L1hitCode | (0x1 << 3);
868 if(ele_trueStereoL1) L1hitCode = L1hitCode | (0x1 << 2);
869 if(pos_trueAxialL1) L1hitCode = L1hitCode | (0x1 << 1);
870 if(pos_trueStereoL1) L1hitCode = L1hitCode | (0x1 << 0);
873 if(ele_trueAxialL2) L2hitCode = L2hitCode | (0x1 << 3);
874 if(ele_trueStereoL2) L2hitCode = L2hitCode | (0x1 << 2);
875 if(pos_trueAxialL2) L2hitCode = L2hitCode | (0x1 << 1);
876 if(pos_trueStereoL2) L2hitCode = L2hitCode | (0x1 << 0);
880 double &vtx_proj_x_signif,
double &vtx_proj_y_signif,
double vtx_x,
double vtx_y,
double vtx_z,
881 double vtx_px,
double vtx_py,
double vtx_pz){
890 for(
auto entry : v0proj_fits.items()){
891 int check_run = std::stoi(entry.key());
895 closest_run = check_run;
898 double target_pos = v0proj_fits[std::to_string(closest_run)][
"target_position"];
899 double rot_mean_x = v0proj_fits[std::to_string(closest_run)][
"rotated_mean_x"];
900 double rot_mean_y = v0proj_fits[std::to_string(closest_run)][
"rotated_mean_y"];
901 double rot_sigma_x = v0proj_fits[std::to_string(closest_run)][
"rotated_sigma_x"];
902 double rot_sigma_y = v0proj_fits[std::to_string(closest_run)][
"rotated_sigma_y"];
903 double rotation_angle = (double)v0proj_fits[std::to_string(closest_run)][
"rotation_angle_mrad"]/1000.0;
906 vtx_proj_x = vtx_x - ((vtx_z - target_pos)*(vtx_px/vtx_pz));
907 vtx_proj_y = vtx_y - ((vtx_z - target_pos)*(vtx_py/vtx_pz));
910 double rot_vtx_proj_x = vtx_proj_x*std::cos(rotation_angle) - vtx_proj_y*std::sin(rotation_angle);
911 double rot_vtx_proj_y = vtx_proj_x*std::sin(rotation_angle) + vtx_proj_y*std::cos(rotation_angle);
914 vtx_proj_x_signif = (rot_vtx_proj_x - rot_mean_x)/rot_sigma_x;
915 vtx_proj_y_signif = (rot_vtx_proj_y - rot_mean_y)/rot_sigma_y;
918 double significance = std::sqrt( vtx_proj_x_signif*vtx_proj_x_signif + vtx_proj_y_signif*vtx_proj_y_signif );
void setGoodnessOfPID(const double goodness_pid)
void setPDG(const int pdg)
void setMass(const double mass)
void setCharge(const int charge)
void setType(const int type)
void setMomentum(const double *momentum)
void setTrack(Track *track)
void setEnergy(const double energy)
void setCluster(CalCluster *cluster)