10 #include <calotrigger/CaloTriggerInfo.h>
11 #include <calobase/RawCluster.h>
12 #include <calobase/RawClusterv1.h>
23 #include <trackbase_historic/SvtxVertex.h>
24 #include <trackbase_historic/SvtxVertexMap.h>
33 #include <GenFit/FieldManager.h>
34 #include <GenFit/GFRaveVertex.h>
35 #include <GenFit/GFRaveVertexFactory.h>
36 #include <GenFit/MeasuredStateOnPlane.h>
37 #include <GenFit/RKTrackRep.h>
38 #include <GenFit/StateOnPlane.h>
41 #include <phgenfit/Track.h>
54 int particleEmbed,
int pythiaEmbed,
bool makeTTree=
true,
string TMVAName=
"",
string TMVAPath=
"") :
SubsysReco(
"TruthConversionEval"),
55 _kRunNumber(runnumber),_kParticleEmbed(particleEmbed), _kPythiaEmbed(pythiaEmbed), _kMakeTTree(makeTTree)
62 cout<<
"destruct"<<endl;
75 _observTree =
new TTree(
"observTree",
"per event observables");
76 _observTree->SetAutoSave(300);
84 _vtxingTree =
new TTree(
"vtxingTree",
"data predicting vtx from track pair");
107 _trackBackTree =
new TTree(
"trackBackTree",
"track background all single tracks");
114 _pairBackTree =
new TTree(
"pairBackTree",
"pair background all possible combinations");
131 _vtxBackTree =
new TTree(
"vtxBackTree",
"events that pass track pair cuts");
150 _signalCutTree =
new TTree(
"cutTreeSignal",
"signal data for making track pair cuts");
180 bool goodPointers=
true;
182 _truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
183 _clusterMap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
184 _allTracks = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
188 cerr<<
Name()<<
": critical error-bad nodes \n";
190 cerr<<
"\t RawClusterContainer is bad";
193 cerr<<
"\t TruthInfoContainer is bad";
196 cerr<<
"\t TrkrClusterMap is bad";
199 cerr<<
"\t SvtxTrackMap is bad";
208 SvtxVertexMap *vertexMap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
209 return vertexMap->
get(0);
215 cout<<
"init vertexer event"<<endl;
223 cerr<<
"NULL track eval in " <<
Name()<<
" fatal error"<<endl;
227 std::map<int,Conversion> mapConversions;
229 std::vector<SvtxTrack*> backgroundTracks;
230 std::vector<std::pair<SvtxTrack*,SvtxTrack*>> tightbackgroundTrackPairs;
231 std::vector<PHG4Particle*> truthPhotons;
232 std::list<int> signalTracks;
240 cout<<
"init truth loop"<<endl;
246 truthPhotons.push_back(g4particle);
264 if(parent->
get_pid()==22&&TMath::Abs(g4particle->
get_pid())==11&&truthpT>2.5){
267 std::cout<<
"Conversion with radius [cm]:"<<radius<<
'\n';
270 (mapConversions[vtx->
get_id()]).setElectron(g4particle);
271 (mapConversions[vtx->
get_id()]).setVtx(vtx);
273 (mapConversions[vtx->
get_id()]).setEmbed(embedID);
281 signalTracks.push_back(recoTrack->
get_id());
283 cout<<
"matched truth track"<<endl;
288 cerr<<
"WARNING no matching track for conversion"<<endl;
294 cout<<
"intit track loop"<<endl;
298 auto inCheck = std::find(signalTracks.begin(),signalTracks.end(),iter->first);
300 if (inCheck==signalTracks.end())
302 TLorentzVector track_tlv =
tracktoTLV(iter->second);
305 for (std::vector<PHG4Particle*>::iterator iPhoton = truthPhotons.begin(); iPhoton != truthPhotons.end()&&addTrack; ++iPhoton)
308 if (photon_tlv.DeltaR(track_tlv)<.2)
314 backgroundTracks.push_back(iter->second);
318 iter->second->get_charge()==jter->second->get_charge()*-1){
319 tightbackgroundTrackPairs.push_back(std::pair<SvtxTrack*,SvtxTrack*>(iter->second,jter->second));
331 cout<<
"intit background process"<<endl;
334 cout<<
"finish back"<<endl;
337 cout<<
"finish process"<<endl;
342 std::vector<std::pair<SvtxTrack*,SvtxTrack*>>* backgroundTracks=NULL){
343 cout<<
"start conversion analysis loop"<<endl;
344 for (std::map<int,Conversion>::iterator
i = mymap->begin();
i != mymap->end(); ++
i) {
345 TLorentzVector tlv_photon,tlv_electron,tlv_positron;
349 else cerr<<
"No truth photon for conversion"<<endl;
354 else cerr<<
"No truth electron for conversion"<<endl;
360 unsigned int nRecoTracks =
i->second.setRecoTracks(trackeval);
374 if(!truthe) cerr<<
"critical error"<<endl;
376 for(
auto pair : *backgroundTracks){
377 if(!pair.first||!pair.second) cerr<<
"critical error2"<<endl;
378 if ((pair.first->get_charge()>0&&truthe->
get_pid()<0)||(pair.first->get_charge()<0&&truthe->
get_pid()>0))
381 TVector3 reco_tlv(pair.first->get_px(),pair.first->get_py(),pair.first->get_pz());
382 if (reco_tlv.DeltaR(truth_tlv)<.1)
387 else if ((pair.second->get_charge()>0&&truthe->
get_pid()<0)||(pair.second->get_charge()<0&&truthe->
get_pid()>0))
390 TVector3 reco_tlv(pair.second->get_px(),pair.second->get_py(),pair.second->get_pz());
391 if (reco_tlv.DeltaR(truth_tlv)<.1)
407 cerr<<
Name()<<
" error setting reco tracks"<<endl;
413 cout<<
"map loop"<<endl;
415 cout<<
"done num"<<endl;
422 unsigned nNullTrack=0;
423 cout<<
"The total possible background track count is "<<v_tracks->size()<<
'\n';
424 for (std::vector<SvtxTrack*>::iterator iter = v_tracks->begin(); iter != v_tracks->end(); ++iter) {
425 cout<<
"looping"<<endl;
433 if(TMath::Abs(iTrack->
get_eta())>1.1||iTrack->
get_pt()==lastpT)
continue;
435 cout<<
"\t pT="<<lastpT<<
'\n';
451 for(std::vector<SvtxTrack*>::iterator jter =
std::next(iter,1);jter!=v_tracks->end(); ++jter){
453 if(!jTrack||TMath::Abs(jTrack->
get_eta())>1.1)
continue;
455 cout<<
"calculations"<<endl;
463 if (cluster2&&cluster1)
466 if(cluster2->get_id()!=cluster1->get_id())
470 TVector3 etaCalc(cluster1->get_x(),cluster1->get_y(),cluster1->get_z());
471 float eta1 = etaCalc.PseudoRapidity();
472 etaCalc.SetXYZ(cluster2->get_x(),cluster2->get_y(),cluster2->get_z());
496 cout<<
"here vertex"<<endl;
499 cout<<
"made vertex"<<endl;
504 cout<<
"corrected vertex"<<endl;
505 TVector3 recoVertPos = recoVert->
getPos();
506 cout<<
"deleting"<<endl;
508 cout<<
"deleted"<<endl;
510 _bb_vtx_radius = sqrt(recoVertPos.x()*recoVertPos.x()+recoVertPos.y()*recoVertPos.y());
515 TLorentzVector* recoPhoton= pairMath.
getRecoPhoton(iTrack,jTrack);
532 cout<<
"fill vtx"<<endl;
536 cout<<
"filled pair"<<endl;
538 cout<<
"filling track"<<endl;
540 cout<<
"filled track"<<endl;
542 cout<<
"Null track count ="<<nNullTrack<<endl;
546 cout<<
"recording"<<endl;
547 if(tlv_photon&&tlv_electron&&tlv_positron&&conversion&&conversion->
recoCount()==2){
556 if(tlv_electron->Pt()>tlv_positron->Pt())
_b_ttrack_pT = tlv_positron->Pt();
563 TLorentzVector truth_added_tlv = *tlv_electron+*tlv_positron;
574 cout<<
"second"<<endl;
584 cout<<
"vertexing"<<endl;
588 cout<<
"finding gf_tracks"<<endl;
610 TVector3 recoVertPos = originalVert->
getPos();
611 _b_vtx_radius = sqrt(recoVertPos.x()*recoVertPos.x()+recoVertPos.y()*recoVertPos.y());
619 pair<float,float> pTstemp = conversion->
getTrackpTs();
622 pair<float,float> etasTemp = conversion->
getTrackEtas();
625 pair<float,float> phisTemp = conversion->
getTrackPhis();
631 recoVertPos = recoVert->
getPos();
632 _b_vtx_radius = sqrt(recoVertPos.x()*recoVertPos.x()+recoVertPos.y()*recoVertPos.y());
633 _b_vtx_phi = recoVertPos.Phi();
640 cout<<
"done full vtx values"<<endl;
644 cout<<
"no vtx "<<endl;
655 pair<float,float> pTstemp = conversion->
getTrackpTs();
658 pair<float,float> etasTemp = conversion->
getTrackEtas();
661 pair<float,float> phisTemp = conversion->
getTrackPhis();
664 cout<<
"done no vtx values"<<endl;
685 TVector3 etaCalc(clustemp->
get_x(),clustemp->
get_y(),clustemp->
get_z());
692 float eta1 = etaCalc.PseudoRapidity();
695 if (clusterIds.first!=clusterIds.second)
708 cout<<
"incomplete conversion"<<endl;
718 else if(tlv_electron->Pt()>tlv_positron->Pt())
_b_ttrack_pT = tlv_positron->Pt();
726 if (tlv_positron&&tlv_electron)
728 TLorentzVector truth_added_tlv = *tlv_electron+*tlv_positron;
745 cout<<
"still here"<<endl;
789 TVector3 etaCalc(clustemp->
get_x(),clustemp->
get_y(),clustemp->
get_z());
796 float eta1 = etaCalc.PseudoRapidity();
799 if (clusterIds.first!=clusterIds.second)
810 cout<<
"Filling"<<endl;
826 cout<<
"ending"<<endl;
828 cout<<
"closing"<<endl;