16 #include "TClonesArray.h"
17 #include "TParticle.h"
18 #include "TDatabasePDG.h"
19 #include "TParticlePDG.h"
30 #include "FairTrackParP.h"
31 #include "FairTrackParH.h"
32 #include "FairGeanePro.h"
34 #include "FairField.h"
49 fRootManager ( FairRootManager::Instance() ),
54 fBuildMcCands ( false ),
56 fPhotosMax(0), fPhotosThresh(0.05),
57 fChargedPidName ( algnamec ),
58 fNeutralPidName ( algnamen ),
59 fTracksName ( tname1 ),
60 fTracksName2 ( tname2 ),
64 std::cout <<
"-E- PndAnalysis: RootManager not instantiated!" << std::endl;
80 TClonesArray* tca = ( TClonesArray* )
fRootManager->GetObject ( tcaname.Data() );
82 std::cout <<
"-I- PndAnalysis::ReadTCA(): No "<<tcaname.Data() <<
" array found." << std::endl;
109 TString branchnames1[4]= {
fTracksName,
"SttMvdGemGenTrack",
"BarrelGenTrack",
"SttMvdGenTrack"};
111 for (
int i = 0;
i < 6 ;
i++)
121 std::cout<<
" #################### read PidChargedCand with special tracking hypothesis: "<<(
"PidChargedCand"+
fPidHypoStr[
i]).Data()<<
" pointer "<<
fChargedCands[
i] <<std::endl;
125 std::cout<<
" #################### No PidChargedCand with "<<
fPidHypoStr[
i].Data()<<
" tracking hypothesis" <<std::endl;
135 for(
int k=0; k<4; k++) {
137 if(
fVerbose>4) std::cout <<
"-I- PndAnalysis::Init(): br:"<<k<<
" hyp:"<<i<<
" Trying \""<<(branchnames1[k]+
fPidHypoStr[
i]).Data() <<
"\" now.";
141 if(
fVerbose>4) std::cout <<
" Succes reading tracking array \""<<(branchnames1[k]+
fPidHypoStr[
i]).Data() <<
"\" with pointer "<<
fTracks[
i];
146 std::cout <<
"-W- PndAnalysis::Init(): No barrel track inpt array." << std::endl;
148 std::cout<<
" printing track array:";
154 for(
int k=0; k<4; k++) {
157 if(
fVerbose>4) std::cout <<
"-I- PndAnalysis::Init(): Trying \""<<(branchnames2[k]+
fPidHypoStr[
i]).Data() <<
"\" now.";
163 std::cout <<
"-W- PndAnalysis::Init(): No forward track inpt array." << std::endl;
175 std::cout<<
"PndAnalysis::Init(): Default hypothesis is muons."<<std::endl;
179 std::cout<<
"PndAnalysis::Init(): Default hypothesis is electrons."<<std::endl;
183 std::cout<<
"PndAnalysis::Init(): Default hypothesis is Kaons."<<std::endl;
187 std::cout<<
"PndAnalysis::Init(): Default hypothesis is protons."<<std::endl;
190 std::cout<<
"PndAnalysis::Init(): No Multikalman input branches exist, do fallback."<<std::endl;
194 std::cout<<
"PndAnalysis::Init(): Default hypothesis is pions."<<std::endl;
202 if(
fVerbose>4) std::cout <<
"-I- PndAnalysis::Init(): Trying mc stack now." << std::endl;
206 std::cout <<
"-W- PndAnalysis::Init(): No \"MCTrack\" array found. No MC info available." << std::endl;
209 fMcCands =
new TClonesArray (
"RhoCandidate" );
232 for (
int i = 0;
i<6;
i++) {
269 Info(
"PndAnalysis::GetEvent()",
"Maximum number of entries in the file chain reached: %i.",
fEvtCount);
278 <<
"-------->8-------->8-------->8-------->8-------->8-------->8-------->8-------->8"
280 <<
" No. - Name - Flag - PidArr - Trk Arr -Trk Arr2 - PID - Brem"
282 for (
int i = 0;
i < 6 ;
i++)
296 <<
"-------->8-------->8-------->8-------->8-------->8-------->8-------->8-------->8"
303 if(
fVerbose) Info(
"PndAnalysis::GetEvent()",
"Finished loading event fEvtCount=%i.",
fEvtCount);
314 FairMCEventHeader* evthead = ( FairMCEventHeader* ) FairRootManager::Instance()->GetObject (
"MCEventHeader." );
329 TString trkPostfix[6]= {
"Electron",
"Muon",
"Pion",
"Kaon",
"Proton",
""};
330 if(0>trackHypothesis || 6<trackHypothesis) {
331 for(
int i=0;
i<6; ++
i) {
338 if(
fVerbose>4) cout<<
"PndAnalysis::FillList() listkey=\""<<listkey<<
"\" trackhypo="<<trackHypothesis<<
" pidTcaNames=\""<<pidTcaNames.Data()<<
"\" trkPostfix=\""<<trkPostfix[trackHypothesis]<<
"\""<<endl;
341 if ( pidTcaNames!=
"" ) {
349 if ( listkey==
"McTruth" ) {
353 if(
fVerbose>4)Info(
"PndAnalysis::FillList",
"key=%s",listkey.Data());
357 if ( listkey.Contains (
"Neutral" ) ) {
369 if ( listkey==
"Charged" ) {
372 if(
fVerbose>4)cout<<
"trackhyp="<<trackHypothesis<<
" list size after selection="<<resultList.
GetLength()<<endl;
376 const bool doBremCorr = listkey.Contains(
"Brem");
377 if (doBremCorr) listkey.ReplaceAll(
"Brem",
"");
382 if (!checkcrit)
return kFALSE;
384 if ( listkey.Contains (
"Electron" ) ||listkey.Contains (
"Muon" ) ||listkey.Contains (
"Pion" )
385 || listkey.Contains (
"Kaon" ) ||listkey.Contains (
"Proton" )
386 || listkey.Contains (
"Plus" ) ||listkey.Contains (
"Minus" ) ||listkey.Contains (
"Charged" ) ) {
390 if(
fVerbose>4)cout<<
"trackhyp="<<trackHypothesis<<
" list size="<<resultList.
GetLength()<<endl;
395 if(
fVerbose) Warning(
"PndAnalysis::FillList",
"Brem requested but no PndPidBremCorrected4Mom found on input file. Brem Correction can't be done.");
397 for (
int j=0; j<resultList.
GetLength(); ++j)
399 int trk_id = resultList[j]->GetTrackNumber();
400 int nBremCorr =
fBremCorr[trackHypothesis]->GetEntriesFast();
403 Warning(
"PndAnalysis::FillList",
"Warning: BermCorr list size diff. from chargeCandList");
410 if(
fVerbose>4)cout<<
"trackhyp="<<trackHypothesis<<
" list size after pid ="<<resultList.
GetLength()<<endl;
412 if(
fVerbose>4)cout<<
"trackhyp="<<trackHypothesis<<
" list size after selection="<<resultList.
GetLength()<<endl;
416 Error (
"FillList",
"Unknown list key: %s",listkey.Data() );
431 if(
fVerbose>4) std::cout<<
"PndAnalysis::GetMcCandList: mccand "<<
i<<
" :"<<truth<<
" \t "<<*truth<<std::endl;
445 if (mcMotherID<0)
continue;
450 l[k]->SetMotherLink(truthmother,
false);
455 TParticlePDG* ppdg = TDatabasePDG::Instance()->GetParticle(l[k]->PdgCode());
458 charge=ppdg->Charge();
460 cout <<
"-W- CreateMcCandidate: strange PDG code:"<<l[k]->PdgCode() <<endl;
462 if (
fabs(charge) >2 ) {
465 l[k]->SetCharge(charge);
488 for(
int h=0;
h<6;
h++) {
494 if(0==nEntries&&
fVerbose) Warning(
"PndAnalysis::ReadRecoCandidates()",
"No filled charged reco array found.");
496 for ( Int_t i2=0; i2<nEntries; i2++ )
499 for(
int i=0;
i<6;
i++)
507 if(
fVerbose>4) cout<<
"Added Candidate to list i="<<i<<
" with i2="<<i2<<
" making the list to size "<<
fChargedCandList[
i].GetLength()<<endl;
526 if(
fVerbose) Warning(
"PndAnalysis::ReadRecoCandidates()",
"No neutral reco array found.");
537 if(
fVerbose) Info(
"PndAnalysis::BuildMcCands",
"No mc to build...");
541 Warning(
"PndAnalysis::BuildMcCands",
"No array to store candidates...");
544 if (
fMcCands->GetEntriesFast() != 0 ) {
548 Error (
"BuildMcCands",
"MC track Array does not exist." );
553 for (i=0; i<
fMcTracks->GetEntriesFast(); i++)
559 TParticlePDG* ppdg = TDatabasePDG::Instance()->GetParticle(part->
GetPdgCode());
562 charge=ppdg->Charge();
564 cout <<
"-W- CreateMcCandidate: strange PDG code:"<<part->
GetPdgCode() <<endl;
566 if (
fabs(charge) >2 ) {
575 pmc->SetLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), FairRootManager::Instance()->GetBranchId(
"MCTrack"), i));
590 if (
fVerbose) Info(
"BuildMcCands",
"reco object to candidate %i (%p) missing.",icand,currentcand);
598 if(
fVerbose)Info(
"PndAnalysis::BuildMcCands()",
"Now setting truth index %i (%p) to candidate (uid=%i)", mcidx,truth,currentcand->
Uid());
600 for(
int ihyp=0; ihyp<6; ihyp++) {
610 if (
fVerbose) Info(
"BuildMcCands",
"reco object to candidate %i (%p) missing.",icand,currentcand);
618 if(
fVerbose)Info(
"PndAnalysis::BuildMcCands()",
"Now setting truth index %i (%p) to candidate (uid=%i)", mcidx,truth,currentcand->
Uid());
627 TVector3 ip( 0.,0.,0. );
654 return Propagator ( 3,tStart,cand,origin,kFALSE,kFALSE,dj,dk );
660 Error (
"GetTrack",
"Candidate not found: %p",cand );
667 Error (
"GetTrack",
"PID Candidate not found: %p",pidCand );
673 for(
int a=0;
a<5;
a++) {
683 Warning (
"GetTrack",
"Could not find track object of index %d",pidCand->
GetTrackIndex() );
693 Error (
"GetFirstPar",
"Candidate not found: %p",cand );
700 Warning (
"GetFirstPar",
"Could not find track object " );
714 for ( Int_t daug =0; daug<cand->
NDaughters(); daug++ ) {
726 firstpar.GetMARSCov ( globalCov );
729 for ( Int_t ii=0; ii<6; ii++ )
for ( Int_t
jj=0;
jj<6;
jj++ ) {
730 err[ii][
jj]=globalCov[ii][
jj];
733 if(
fVerbose>3){ std::cout<<
"MARS cov (px,py,pz,E,x,y,z): ";err.Print();}
734 TLorentzVector lv = cand->
P4();
738 if(
fVerbose>3){ std::cout<<
"covPosMom (x,y,z,px,py,pz,E): ";covPosMom.Print();}
742 cand->
SetP3 ( firstpar.GetMomentum() );
758 FairGeanePro* geaneProp =
new FairGeanePro();
759 Int_t pdgcode = cand->
PdgCode();
762 cout<<
"Try mode "<<mode<<
" with pdgCode "<<pdgcode<<endl;
766 std::cout<<
"Start Params are:"<<std::endl;
772 tStart.GetMARSCov ( startCov );
775 for ( Int_t ii=0; ii<6; ii++ )
for ( Int_t
jj=0;
jj<6;
jj++ ) {
776 errst[ii][
jj]=startCov[ii][
jj];
780 std::cout<<
"Start MARS cov: ";
785 geaneProp->BackTrackToVertex();
786 geaneProp->SetPoint ( mypoint );
787 }
else if ( 2==mode ) {
788 geaneProp->PropagateToPCA ( 2, -1 );
789 TVector3 ex1 ( 0.,0.,-50. );
790 TVector3 ex2 ( 0.,0.,100. );
791 geaneProp->SetWire ( ex1,ex2 );
792 }
else if ( 3==mode ) {
793 geaneProp->PropagateToPlane(mypoint,planej,planek);
795 Error (
"Propagator()",
"Use mode 1 (to a TVector3) or mode 2 (to z axis) or mode 3 (to plane). (Mode=%i)",mode );
799 if(skipcov) geaneProp->PropagateOnlyParameters();
801 FairTrackParH* myResult=0;
804 FairTrackParP* tResult =
new FairTrackParP();
805 rc = geaneProp->Propagate ( &tStart, tResult,pdgcode );
806 myResult =
new FairTrackParH(*tResult);
808 myResult =
new FairTrackParH();
809 FairTrackParH* myStart =
new FairTrackParH ( tStart );
810 rc = geaneProp->Propagate ( myStart, myResult,pdgcode );
815 Warning (
"Propagator()",
"Geane propagation failed" );
821 TVector3 di = myResult->GetMomentum();
823 TVector3 dj = di.Orthogonal();
824 TVector3 dk = di.Cross ( dj );
825 FairTrackParP* myParab =
new FairTrackParP ( myResult, dj, dk, ierr );
827 TVector3
pos( myResult->GetX(),myResult->GetY(),myResult->GetZ() );
829 cand->
SetP3( myResult->GetMomentum() );
833 TVector3
vecdiff=tStart.GetPosition() - myResult->GetPosition();
834 std::cout<<
"position start :";
835 tStart.GetPosition().Print();
836 std::cout<<
"position ip :";
837 myResult->GetPosition().Print();
838 std::cout<<
"position difference:";
840 vecdiff=tStart.GetMomentum()-myResult->GetMomentum();
841 std::cout<<
"momentum start :";
842 tStart.GetMomentum().Print();
843 std::cout<<
"momentum ip :";
844 myResult->GetMomentum().Print();
845 std::cout<<
"momentum difference:";
849 if(kFALSE==skipcov) {
851 myParab->GetMARSCov ( globalCov );
854 for ( Int_t ii=0; ii<6; ii++ )
for ( Int_t
jj=0;
jj<6;
jj++ ) {
855 err[ii][
jj]=globalCov[ii][
jj];
859 std::cout<<
"MARS cov (px,py,pz,E,x,y,z): ";
863 TLorentzVector lv = cand->
P4();
868 std::cout<<
"covPosMom (x,y,z,px,py,pz,E): ";
878 std::cout<<
" ::::::::::: Printout in PndAnalysis::Propagator() ::::::::::: "<<std::endl;
883 std::cout<<
"SC system params:"
884 <<
"\nq/p = "<<myResult->GetQp()
885 <<
"\nLambda = "<<myResult->GetLambda()
886 <<
"\nPhi = "<<myResult->GetPhi()
887 <<
"\nX_sc = "<<myResult->GetX_sc()
888 <<
"\nY_sc = "<<myResult->GetY_sc()
889 <<
"\nZ_sc = "<<myResult->GetZ_sc()
892 std::cout<<
"some values:"
893 <<
"\n Z0 ?= z_sc / cos(lambda) = "<< myResult->GetZ_sc() /
cos ( myResult->GetLambda() )
894 <<
"\n Z0 ?= sqrt(x_sc^2+z_sc^2) = "<<
sqrt ( myResult->GetX_sc() *myResult->GetX_sc() +myResult->GetZ_sc() *myResult->GetZ_sc() )
904 Info (
"Propagator ",
"overwriting start parameter state with result");
906 tStart.SetTrackPar(myParab->GetV(), myParab->GetW(),
907 myParab->GetTV(), myParab->GetTW(),
908 myParab->GetQp(), myParab->GetCov(),
909 myParab->GetOrigin(),
918 Info (
"Propagator ",
"Succsess=%i",rc );
940 for(
int icand=0; icand<list.
GetLength(); icand++) {
957 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected final state by nonexistent mc truth pointer");
960 if ( mccnd->
PdgCode() == pdg ) {
961 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"accepted final state by PDG code (pdg=%i)",pdg);
965 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected final state by PDG Code (pdg=%i|mcpdg=%i)",pdg, mccnd->
PdgCode());
971 for ( Int_t
i=0;
i<nd;
i++ ) {
973 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected composite (pdg=%i) by non-matching daughter: idau=%i",pdg,
i);
988 if(verbose) Warning(
"PndMcTruthMatch::MctMatch",
"Existing MC truth found. Will reset it now.");
996 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by not existing daughter zero");
1001 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by not existing MC truth of daughter zero");
1005 if (!mcdauzeromother) {
1007 Info(
"PndMcTruthMatch::MctMatch",
"rejected by not existing mother of MC truth of daughter zero");
1008 cout <<*mcdauzero<<endl;
1016 int ndaudiff = mcdauzeromother->
NDaughters() - nd;
1022 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by differing daughter count: cand:%i mc:%i",c->
NDaughters(),mcdauzeromother->
NDaughters());
1028 for (
int idau=0; idau<mcdauzeromother->
NDaughters(); ++idau)
1034 for(
int idau=1; idau<nd; idau++) {
1038 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by not existing daughter %i",idau);
1043 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by not existing MC truth of daughter %i",idau);
1049 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by not existing mother of MC truth of daughter %i",idau);
1052 if(mcdaumother!=mcdauzeromother) {
1053 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by mc mother of daughter %i(%p) is different to mc mother of daughter zero(%p) -> Tree does not match"
1054 ,idau,mcdaumother,mcdauzeromother);
1062 if ( (nphall-nphreco)>fPhotosMax || (nphall-nphreco)!=ndaudiff )
1064 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by differing daughter count not being photos photons: cand:%i mc:%i",c->
NDaughters(),mcdauzeromother->
NDaughters());
1072 if (verbose) Info(
"PndMcTruthMatch::MctMatch",
"accepted composite(pdg=%i) on match-level 1",pdg);
1079 if ( pdg != mcdauzeromother->
PdgCode() ) {
1080 if(verbose) Info(
"PndMcTruthMatch::MctMatch",
"rejected by nonmatching pdg code in tree (pdgcode|mcpdgcode) (%i|%i)",pdg,mcdauzeromother->
PdgCode());
1086 if (verbose) Info(
"PndMcTruthMatch::MctMatch",
"accepted composite(pdg=%i) on match-level 2", pdg);
std::array< TClonesArray *, 6 > fChargedProbability
Int_t GetTrackIndex() const
void Add(const RhoCandidate *c)
Bool_t ResetCandidate(RhoCandidate *cand)
friend F32vec4 cos(const F32vec4 &a)
TClonesArray * ReadTCA(TString tcaname)
Bool_t PropagateToPoint(RhoCandidate *cand, TVector3 mypoint)
PndTrack * GetTrack(RhoCandidate *cand)
void SetTcaNames(TString &names, TString postfix="")
FairTrackParP GetFirstPar(RhoCandidate *cand)
std::array< RhoCandList, 6 > fChargedCandList
void SetPos(const TVector3 &pos)
Bool_t Apply(RhoCandidate *tc)
friend F32vec4 sqrt(const F32vec4 &a)
FairMCEventHeader * GetEventHeader()
static const UInt_t success
Bool_t PropagateToZAxis(RhoCandidate *cand)
PndAnaPidSelector * fPidSelector
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
PndPidCandidate * GetRecoCandidate() const
TVector3 GetMomentum() const
Bool_t MctMatch(RhoCandidate &c, RhoCandList &mct, Int_t level=2, bool verbose=false)
RhoCandidate * Daughter(Int_t n)
Bool_t GetMcCandList(RhoCandList &l)
void SetPosition(const TVector3 &pos)
Bool_t PropagateToPlane(RhoCandidate *cand, TVector3 origin, TVector3 dj, TVector3 dk)
Bool_t SetCriterion(TString &crit)
TLorentzVector Get4Momentum() const
Int_t fDefaultHypo
Flag to check which hypo lists exists //0-4 for trk hypothesis, 5 for fallback.
void SetType(const TParticlePDG *pdt)
void SetP4(Double_t mass, const TVector3 &p3)
PndAnaPidCombiner * fPidCombiner
std::array< TClonesArray *, 6 > fBremCorr
void SetP3(const TVector3 &p3)
PndAnalysis(TString tname1="", TString tname2="", TString algnamec="PidAlgoIdealCharged", TString algnamen="PidAlgoIdealNeutral")
void ReadRecoCandidates()
void Select(RhoParticleSelectorBase *pidmgr)
TLorentzVector P4() const
friend F32vec4 fabs(const F32vec4 &a)
static RhoFactory * Instance()
Bool_t Propagator(int mode, FairTrackParP &tStart, RhoCandidate *cand, TVector3 point=TVector3(0, 0, 0), Bool_t skipcov=kFALSE, Bool_t overwrite=kFALSE, TVector3 planej=TVector3(1, 0, 0), TVector3 planek=TVector3(0, 1, 0))
RhoCandidate * GetMcTruth() const
std::array< TClonesArray *, 6 > fTracks
FairRootManager * fRootManager
void SetMcTruth(RhoCandidate *mct)
void SetTrackNumber(Int_t trnum=-1)
Int_t GetSecondMotherID() const
Bool_t PropagateToIp(RhoCandidate *cand)
RhoCandList fNeutralCandList
void Put(const RhoCandidate *, Int_t i=-1)
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
Bool_t fHypoFlagCharged[6]
Int_t GetEvent(Int_t n=-1)
TVector3 GetStartVertex() const
Int_t GetMotherID() const
std::array< TClonesArray *, 6 > fTracks2
cout<<"the Event No is "<< i<< endl;{{if(hit_array->GetEntriesFast()!=mc_array->GetEntriesFast()) continue;PndSdsHit *hit=(PndSdsHit *) hit_array-> At(j)
void SetCov7(const TMatrixD &cov7)
TClonesArray * fNeutralCands
const RhoCandidate * TheMother() const
std::array< TClonesArray *, 6 > fChargedCands
Bool_t ResetDaughters(RhoCandidate *cand)
FairTrackParP GetParamFirst()
TMatrixT< double > TMatrixD
RhoCandidate * Get(Int_t)