FairRoot/PandaRoot
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PndMcCloner2 Class Reference

#include <PndMcCloner2.h>

Inheritance diagram for PndMcCloner2:

Public Member Functions

 PndMcCloner2 ()
 
 ~PndMcCloner2 ()
 
virtual InitStatus Init ()
 
virtual void Exec (Option_t *)
 
void SetCleanMc (Bool_t opt=kTRUE)
 
void SetOutputBranch (TString branch)
 

Protected Member Functions

void FindUsedMCIndices ()
 
void CloneMCTrack ()
 
void CloneAndCleanMCTrack ()
 
void CorrectMotherIndices ()
 
void CorrectPidIndices ()
 
 ClassDef (PndMcCloner2, 2)
 

Protected Attributes

TClonesArray * fInputArray
 
TClonesArray * fPidChargedArray [5]
 
TClonesArray * fPidNeutralArray [5]
 
TClonesArray * fOutputArray
 
map< Int_t, Int_t > mapMCIndex
 
Bool_t fCleanMC
 
TString fPidHypoStr [5]
 
Bool_t fHypoFlagCharged [5]
 
Bool_t fHypoFlagNeutral [5]
 Flag to check which hypotheses are present. More...
 
TString fTrackBranchNamePidHypo
 Flag to check which hypotheses are present. More...
 

Detailed Description

Definition at line 13 of file PndMcCloner2.h.

Constructor & Destructor Documentation

PndMcCloner2::PndMcCloner2 ( )

Default constructor

Definition at line 24 of file PndMcCloner2.cxx.

24  : FairTask("Cloner of PndMCTrack"),
27 {
28 }
TString fTrackBranchNamePidHypo
Flag to check which hypotheses are present.
Definition: PndMcCloner2.h:65
TClonesArray * fOutputArray
Definition: PndMcCloner2.h:55
TClonesArray * fPidNeutralArray[5]
Definition: PndMcCloner2.h:51
Bool_t fCleanMC
Definition: PndMcCloner2.h:59
TClonesArray * fPidChargedArray[5]
Definition: PndMcCloner2.h:48
map< Int_t, Int_t > mapMCIndex
Definition: PndMcCloner2.h:57
TClonesArray * fInputArray
Definition: PndMcCloner2.h:45
PndMcCloner2::~PndMcCloner2 ( )

Destructor

Definition at line 32 of file PndMcCloner2.cxx.

32 { }

Member Function Documentation

PndMcCloner2::ClassDef ( PndMcCloner2  ,
 
)
protected
void PndMcCloner2::CloneAndCleanMCTrack ( )
protected

Definition at line 233 of file PndMcCloner2.cxx.

References fInputArray, fOutputArray, mapMCIndex, and mctrack.

Referenced by Exec().

234 {
235  // Copy only the MCTracks which were used, and update the mother indices
236 
237  for (std::map<Int_t,Int_t>::iterator it=mapMCIndex.begin(); it!=mapMCIndex.end(); ++it)
238  {
239  PndMCTrack *mctrack = (PndMCTrack*) fInputArray->At(it->first);
240  TClonesArray& clref = *fOutputArray;
241  Int_t size = clref.GetEntriesFast();
242  new(clref[size]) PndMCTrack(*mctrack);
243  mapMCIndex[it->first] = size;
244  }
245 }
PndMCTrack * mctrack
TClonesArray * fOutputArray
Definition: PndMcCloner2.h:55
map< Int_t, Int_t > mapMCIndex
Definition: PndMcCloner2.h:57
TClonesArray * fInputArray
Definition: PndMcCloner2.h:45
void PndMcCloner2::CloneMCTrack ( )
protected

Definition at line 142 of file PndMcCloner2.cxx.

References fInputArray, fOutputArray, and mctrack.

Referenced by Exec().

143 {
144  // Copy 1:1 of the MCTrack TClonesArray
145 
146  Int_t nMCTracks = fInputArray->GetEntriesFast();
147  for (Int_t iMC=0; iMC<nMCTracks; iMC++)
148  {
149  PndMCTrack *mctrack = (PndMCTrack*) fInputArray->At(iMC);
150  TClonesArray& clref = *fOutputArray;
151  Int_t size = clref.GetEntriesFast();
152  new(clref[size]) PndMCTrack(*mctrack);
153  } // Loop over MCTracks
154 }
PndMCTrack * mctrack
TClonesArray * fOutputArray
Definition: PndMcCloner2.h:55
TClonesArray * fInputArray
Definition: PndMcCloner2.h:45
void PndMcCloner2::CorrectMotherIndices ( )
protected

Definition at line 250 of file PndMcCloner2.cxx.

References fOutputArray, PndMCTrack::GetMotherID(), PndMCTrack::GetSecondMotherID(), mapMCIndex, mctrack, PndMCTrack::SetMotherID(), and PndMCTrack::SetSecondMotherID().

Referenced by Exec().

251 {
252  // Loop over the new MCTrack TClonesArray and update the mother indices
253  Int_t nmc = 0;
254  nmc = fOutputArray->GetEntriesFast();
255  for (Int_t imc=0; imc<nmc; imc++)
256  {
258  Int_t motherID = mctrack->GetMotherID();
259  Int_t secondMotherID = mctrack->GetSecondMotherID();
260  if (motherID!=-1) mctrack->SetMotherID(mapMCIndex[motherID]);
261  if (secondMotherID!=-1) mctrack->SetSecondMotherID(mapMCIndex[secondMotherID]);
262  }
263 }
PndMCTrack * mctrack
TClonesArray * fOutputArray
Definition: PndMcCloner2.h:55
Int_t GetSecondMotherID() const
Definition: PndMCTrack.h:75
void SetSecondMotherID(Int_t id)
Definition: PndMCTrack.h:94
void SetMotherID(Int_t id)
Definition: PndMCTrack.h:93
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
map< Int_t, Int_t > mapMCIndex
Definition: PndMcCloner2.h:57
void PndMcCloner2::CorrectPidIndices ( )
protected

Definition at line 265 of file PndMcCloner2.cxx.

References At, fHypoFlagCharged, fHypoFlagNeutral, fPidChargedArray, fPidNeutralArray, PndPidCandidate::GetMcIndex(), i, mapMCIndex, and PndPidCandidate::SetMcIndex().

Referenced by Exec().

266 {
267  // Loop over Pid Candidates and set the mc indices with the new value
268 
269  Int_t nCands = 0;
270 
271  for(int i=0;i<5;i++){
272  if (!fHypoFlagCharged[i]) continue;
273  nCands = fPidChargedArray[i]->GetEntriesFast();
274  for (Int_t iPid=0; iPid<nCands; iPid++)
275  {
276 
277  PndPidCandidate *pidCand = (PndPidCandidate*) fPidChargedArray[i]->At(iPid);
278  Int_t mcIndex = pidCand->GetMcIndex();
279  pidCand->SetMcIndex(mapMCIndex[mcIndex]);
280  }
281  }
282  for(int i=0;i<5;i++){
283  if (!fHypoFlagNeutral[i]) continue;
284  nCands = fPidNeutralArray[i]->GetEntriesFast();
285  for (Int_t iPid=0; iPid<nCands; iPid++)
286  {
287  PndPidCandidate *pidCand = (PndPidCandidate*) fPidNeutralArray[i]->At(iPid);
288  Int_t mcIndex = pidCand->GetMcIndex();
289  pidCand->SetMcIndex(mapMCIndex[mcIndex]);
290  }
291  }
292 
293 
294 }
Int_t i
Definition: run_full.C:25
Bool_t fHypoFlagCharged[5]
Definition: PndMcCloner2.h:62
void SetMcIndex(int idx)
Int_t GetMcIndex() const
TClonesArray * fPidNeutralArray[5]
Definition: PndMcCloner2.h:51
Bool_t fHypoFlagNeutral[5]
Flag to check which hypotheses are present.
Definition: PndMcCloner2.h:63
TClonesArray * fPidChargedArray[5]
Definition: PndMcCloner2.h:48
map< Int_t, Int_t > mapMCIndex
Definition: PndMcCloner2.h:57
cout<<"the Event No is "<< i<< endl;{{if(hit_array->GetEntriesFast()!=mc_array->GetEntriesFast()) continue;PndSdsHit *hit=(PndSdsHit *) hit_array-> At(j)
Definition: anaLmdCluster.C:71
void PndMcCloner2::Exec ( Option_t *  )
virtual

Virtual method Exec

Definition at line 119 of file PndMcCloner2.cxx.

References CloneAndCleanMCTrack(), CloneMCTrack(), CorrectMotherIndices(), CorrectPidIndices(), fCleanMC, FindUsedMCIndices(), fOutputArray, and mapMCIndex.

119  {
120 
121  // Reset output array
122  if ( ! fOutputArray ) Fatal("Exec", "No Output Array");
123 
124  fOutputArray->Clear();
125  mapMCIndex.clear();
126 
127  if (!fCleanMC)
128  {
129  CloneMCTrack();
130  }
131  else
132  {
137  }
138 }
void CloneMCTrack()
TClonesArray * fOutputArray
Definition: PndMcCloner2.h:55
void FindUsedMCIndices()
void CorrectMotherIndices()
Bool_t fCleanMC
Definition: PndMcCloner2.h:59
void CloneAndCleanMCTrack()
void CorrectPidIndices()
map< Int_t, Int_t > mapMCIndex
Definition: PndMcCloner2.h:57
void PndMcCloner2::FindUsedMCIndices ( )
protected

Definition at line 157 of file PndMcCloner2.cxx.

References At, fHypoFlagCharged, fHypoFlagNeutral, fInputArray, fPidChargedArray, fPidNeutralArray, PndPidCandidate::GetMcIndex(), PndMCTrack::GetMotherID(), i, mapMCIndex, and mctrack.

Referenced by Exec().

157  {
158  // Loop over PidChargedCand and PidNeutralCand, find the used MC indices, and fill the map
159  // with this index and all the mother indices
160 
161  Int_t nCands = 0;
162 
163  // First store primary MC tracks
164  nCands = fInputArray->GetEntriesFast();
165  for (Int_t imc=0; imc<nCands; imc++)
166  {
168  if (mctrack->GetMotherID()==-1)
169  {
170  mapMCIndex[imc] = imc;
171  }
172  else break;
173  }
174 
175  //todo:assume all arrays are of same length, use list0 to get ncands for now
176  //todo:assuming also that all entries in the lists have the same ordering
177  for (int ihyp = 0; ihyp < 5;ihyp++){
178  if (fPidChargedArray[ihyp]) nCands = fPidChargedArray[ihyp]->GetEntriesFast();
179  }
180 // nCands = fPidChargedArray[0]->GetEntriesFast();
181  for (Int_t iPid=0; iPid<nCands; iPid++)
182  {
183  Int_t mcIndex = -1;
184  for(int i = 0;i<5;i++){
185  if (!fHypoFlagCharged[i]) continue;
186  PndPidCandidate *pidCand = (PndPidCandidate*) fPidChargedArray[i]->At(iPid);
187  mcIndex = pidCand->GetMcIndex();
188  if (mcIndex !=-1) break; //If any of the pidcandidates are pointing to a track, we exit loop
189  }
190  while (mcIndex!=-1)
191  {
192  PndMCTrack *mctrack = (PndMCTrack*)fInputArray->At(mcIndex);
193  if (mctrack==NULL)
194  {
195  Error("FindUsedMCIndices","PndMCTrack is not existing!");
196  }
197  mapMCIndex[mcIndex] = mcIndex;
198  mcIndex = mctrack->GetMotherID();
199  }
200 
201  } // Loop over PidChargedCand
202 
203  for (int ihyp = 0; ihyp < 5;ihyp++){
204  if (fPidNeutralArray[ihyp]) nCands = fPidNeutralArray[ihyp]->GetEntriesFast();
205  }
206 // nCands = fPidNeutralArray[0]->GetEntriesFast();
207  for (Int_t iPid=0; iPid<nCands; iPid++)
208  {
209 
210  Int_t mcIndex = -1;
211  for(int i=0;i<5;i++){
212  if (!fHypoFlagNeutral[i]) continue;
213  PndPidCandidate *pidCand = (PndPidCandidate*) fPidNeutralArray[i]->At(iPid);
214  mcIndex = pidCand->GetMcIndex();
215  if (mcIndex !=-1) break; //If any of the pidcandidates are pointing to a track, we exit loop
216  }
217  while (mcIndex!=-1)
218  {
219  PndMCTrack *mctrack = (PndMCTrack*)fInputArray->At(mcIndex);
220  if (mctrack==NULL)
221  {
222  Error("FindUsedMCIndices","PndMCTrack is not existing!");
223  }
224  mapMCIndex[mcIndex] = mcIndex;
225  mcIndex = mctrack->GetMotherID();
226  }
227  } // Loop over PidNeutralCand
228 
229 }
PndMCTrack * mctrack
Int_t i
Definition: run_full.C:25
Bool_t fHypoFlagCharged[5]
Definition: PndMcCloner2.h:62
Int_t GetMcIndex() const
TClonesArray * fPidNeutralArray[5]
Definition: PndMcCloner2.h:51
Bool_t fHypoFlagNeutral[5]
Flag to check which hypotheses are present.
Definition: PndMcCloner2.h:63
TClonesArray * fPidChargedArray[5]
Definition: PndMcCloner2.h:48
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
map< Int_t, Int_t > mapMCIndex
Definition: PndMcCloner2.h:57
cout<<"the Event No is "<< i<< endl;{{if(hit_array->GetEntriesFast()!=mc_array->GetEntriesFast()) continue;PndSdsHit *hit=(PndSdsHit *) hit_array-> At(j)
Definition: anaLmdCluster.C:71
TClonesArray * fInputArray
Definition: PndMcCloner2.h:45
InitStatus PndMcCloner2::Init ( )
virtual

Virtual method Init

Definition at line 36 of file PndMcCloner2.cxx.

References fHypoFlagCharged, fHypoFlagNeutral, fInputArray, fOutputArray, fPidChargedArray, fPidHypoStr, fPidNeutralArray, fTrackBranchNamePidHypo, and i.

36  {
37 
38  cout << "-I- PndMcCloner2::Init: "
39  << "INITIALIZATION *********************" << endl;
40 
41  fPidHypoStr[0] = "Electron";
42  fPidHypoStr[1] = "Muon";
43  fPidHypoStr[2] = "Pion";
44  fPidHypoStr[3] = "Kaon";
45  fPidHypoStr[4] = "Proton";
46 
47  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
48  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
49 
50  // Get RootManager
51  FairRootManager* ioman = FairRootManager::Instance();
52  if ( ! ioman ) {
53  cout << "-E- PndMcCloner2::Init: "
54  << "RootManager not instantiated!" << endl;
55  return kFATAL;
56  }
57 
58  // Get input array
59  fInputArray = (TClonesArray*) ioman->GetObject("MCTrack");
60  if ( ! fInputArray ) {
61  cout << "-E- PndMcCloner2::Init: "
62  << "No MCTrack array!" << endl;
63  return kERROR;
64  }
65  bool anychargedtca = false;
66  bool anyneutraltca = false;
67 
68  for(int i=0;i<5;i++){
69  fPidChargedArray[i] = (TClonesArray*) ioman->GetObject("PidChargedCand"+fPidHypoStr[i]);
70  if ( ! fPidChargedArray[i] ) {
71  cout << "-E- PndMcCloner2::Init: "
72  << "No PidChargedCand"+fPidHypoStr[i]+" array. Continue looking." << endl;
73 // return kERROR;
74  }
75  else {
76  fHypoFlagCharged[i] = true;
77  anychargedtca = true;
78  }
79 
80  fPidNeutralArray[i] = (TClonesArray*) ioman->GetObject("PidNeutralCand"+fPidHypoStr[i]);
81  if ( ! fPidNeutralArray[i] ) {
82  cout << "-E- PndMcCloner2::Init: "
83  << "No PidNeutralCand"+fPidHypoStr[i]+" array. Continue looking." << endl;
84 // return kERROR;
85  }
86  else {
87  fHypoFlagNeutral[i] = true;
88  anyneutraltca = true;
89  }
90  }
91 
92  if (!anychargedtca) {
93  cout << "-E- PndMcCloner2::Init: "
94  << "No PidChargedCand array found!" << endl;
95  return kERROR;
96  }
97  if (!anyneutraltca) {
98  cout << "-E- PndMcCloner2::Init: "
99  << "No PidNeutralCand array found!" << endl;
100  return kERROR;
101  }
102 
103 
104  // Create and register output array
105  fOutputArray = new TClonesArray("PndMCTrack");
106 
107  ioman->Register("MCTrack"+fTrackBranchNamePidHypo,"MC",fOutputArray,kTRUE);
108 
109  cout << "-I- PndMcCloner2: Intialization successfull" << endl;
110 
111  return kSUCCESS;
112 
113 }
Int_t i
Definition: run_full.C:25
Bool_t fHypoFlagCharged[5]
Definition: PndMcCloner2.h:62
TString fTrackBranchNamePidHypo
Flag to check which hypotheses are present.
Definition: PndMcCloner2.h:65
TClonesArray * fOutputArray
Definition: PndMcCloner2.h:55
TClonesArray * fPidNeutralArray[5]
Definition: PndMcCloner2.h:51
Bool_t fHypoFlagNeutral[5]
Flag to check which hypotheses are present.
Definition: PndMcCloner2.h:63
TClonesArray * fPidChargedArray[5]
Definition: PndMcCloner2.h:48
TString fPidHypoStr[5]
Definition: PndMcCloner2.h:61
TClonesArray * fInputArray
Definition: PndMcCloner2.h:45
void PndMcCloner2::SetCleanMc ( Bool_t  opt = kTRUE)
inline

Definition at line 33 of file PndMcCloner2.h.

Referenced by PndMasterMultiPidTask::PndMasterMultiPidTask().

33 { fCleanMC = opt; };
Bool_t fCleanMC
Definition: PndMcCloner2.h:59
void PndMcCloner2::SetOutputBranch ( TString  branch)
inline

Definition at line 34 of file PndMcCloner2.h.

34 { fTrackBranchNamePidHypo = branch; };
TString fTrackBranchNamePidHypo
Flag to check which hypotheses are present.
Definition: PndMcCloner2.h:65

Member Data Documentation

Bool_t PndMcCloner2::fCleanMC
protected

Definition at line 59 of file PndMcCloner2.h.

Referenced by Exec().

Bool_t PndMcCloner2::fHypoFlagCharged[5]
protected

Definition at line 62 of file PndMcCloner2.h.

Referenced by CorrectPidIndices(), FindUsedMCIndices(), and Init().

Bool_t PndMcCloner2::fHypoFlagNeutral[5]
protected

Flag to check which hypotheses are present.

Definition at line 63 of file PndMcCloner2.h.

Referenced by CorrectPidIndices(), FindUsedMCIndices(), and Init().

TClonesArray* PndMcCloner2::fInputArray
protected

Input array of PndMCTrack

Definition at line 45 of file PndMcCloner2.h.

Referenced by CloneAndCleanMCTrack(), CloneMCTrack(), FindUsedMCIndices(), and Init().

TClonesArray* PndMcCloner2::fOutputArray
protected

Output array of PndMCTrack

Definition at line 55 of file PndMcCloner2.h.

Referenced by CloneAndCleanMCTrack(), CloneMCTrack(), CorrectMotherIndices(), Exec(), and Init().

TClonesArray* PndMcCloner2::fPidChargedArray[5]
protected

Input array of PidChargedCand

Definition at line 48 of file PndMcCloner2.h.

Referenced by CorrectPidIndices(), FindUsedMCIndices(), and Init().

TString PndMcCloner2::fPidHypoStr[5]
protected

Definition at line 61 of file PndMcCloner2.h.

Referenced by Init().

TClonesArray* PndMcCloner2::fPidNeutralArray[5]
protected

Input array of PidNeutralCand

Definition at line 51 of file PndMcCloner2.h.

Referenced by CorrectPidIndices(), FindUsedMCIndices(), and Init().

TString PndMcCloner2::fTrackBranchNamePidHypo
protected

Flag to check which hypotheses are present.

Definition at line 65 of file PndMcCloner2.h.

Referenced by Init().

map<Int_t, Int_t> PndMcCloner2::mapMCIndex
protected

The documentation for this class was generated from the following files: