EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmMCMatchCreatorTask.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmMCMatchCreatorTask.cxx
1 // -------------------------------------------------------------------------
2 // ----- CbmMCMatchCreatorTask source file -----
3 // ----- Created 18/07/08 by T.Stockmanns -----
4 // -------------------------------------------------------------------------
6 
7 #include "CbmDetectorList.h"
8 #include "CbmMCEntry.h"
9 #include "CbmMCMatch.h"
10 
11 // framework includes
12 #include "FairRootManager.h"
13 #include "FairMultiLinkedData.h"
14 
15 // Root includes
16 #include "TClonesArray.h"
17 
18 // libc includes
19 #include <iostream>
20 using std::cout;
21 using std::endl;
22 
23 // ----- Default constructor -------------------------------------------
25  : FairTask("Creates CbmMCMatch"),
26  fBranches(),
27  fMCLink(NULL),
28  fEventNr(0),
29  fMCMatch(NULL)
30 {
31 }
32 // -------------------------------------------------------------------------
33 
34 
35 // ----- Destructor ----------------------------------------------------
37 {
38 }
39 
40 // ----- Public method Init --------------------------------------------
42 {
43 
44 
45 // fMCMatch->InitStage(kMCTrack, "", "MCTrack");
46 
47  fMCMatch = new CbmMCMatch("CbmMCMatch", "CbmMCMatch");
48 
49  fMCMatch->InitStage(kStsPoint, "", "StsPoint");
50  fMCMatch->InitStage(kStsDigi, "", "StsDigi");
51  fMCMatch->InitStage(kStsCluster, "", "StsCluster");
52  fMCMatch->InitStage(kStsHit, "", "StsHit");
53 
54  InitStatus status = InitBranches();
55 
56 
58  if (!ioman) {
59  cout << "-E- CbmMCMatchCreatorTask::Init: "
60  << "RootManager not instantiated!" << endl;
61  return kFATAL;
62  }
63 
64  fMCLink = new TClonesArray("CbmMCEntry");
65  ioman->Register("MCLink", "MCInfo", fMCLink, kTRUE);
66 
67  ioman->Register("MCMatch", "MCMatch", fMCMatch, kFALSE);
68 
69  cout << "-I- CbmMCMatchCreatorTask::Init: Initialization successfull" << endl;
70 
71 
72  return status;
73 }
74 
76 {
77 
78  // Get RootManager
80  if (!ioman) {
81  cout << "-E- CbmMCMatchCreatorTask::Init: "
82  << "RootManager not instantiated!" << endl;
83  return kFATAL;
84  }
85 
86  int NStages = fMCMatch->GetNMCStages();
87  for (int i = NStages-1; i > -1; i--){
88  TClonesArray* myBranch = (TClonesArray*)ioman->GetObject(fMCMatch->GetMCStage(i)->GetBranchName().c_str());
89  if (!myBranch) {
90  //cout << "NMCStages: " << fMCMatch->GetNMCStages() << endl;
91  cout << "-W- CbmMCMatchCreatorTask::Init: "<< "No "<<fMCMatch->GetMCStage(i)->GetBranchName() << " array!" << endl;
92  fMCMatch->GetMCStage(i)->SetFill(kFALSE); //RemoveStage(fMCMatch->GetMCStage(i)->GetStageId());
93 
94  continue;
95  }
96  else fMCMatch->GetMCStage(i)->SetFill(kTRUE);
97  fBranches[fMCMatch->GetMCStage(i)->GetBranchName()] = myBranch;
98  }
99  return kSUCCESS;
100 }
101 // -------------------------------------------------------------------------
103 {
104  // Get Base Container
105 // FairRun* ana = FairRun::Instance();
106 // FairRuntimeDb* rtdb=ana->GetRuntimeDb();
107 
108 }
109 
110 
111 // ----- Public method Exec --------------------------------------------
112 void CbmMCMatchCreatorTask::Exec(Option_t* opt)
113 {
114 
115  if (!fMCLink) Fatal("Exec", "No fMCLinkDet");
116  fMCLink->Delete();
118 
120 
121  cout << "NMCStages: " << fMCMatch->GetNMCStages() << endl;
122  for (int i = 0; i < fMCMatch->GetNMCStages(); i++){
123  if (fMCMatch->GetMCStage(i)->GetFill() == kTRUE && fMCMatch->GetMCStage(i)->GetLoaded() == kFALSE){
124  cout << i << ": ";
125  cout << "BranchName: " << fMCMatch->GetMCStage(i)->GetBranchName() << endl;
126  TClonesArray* clArray = fBranches[fMCMatch->GetMCStage(i)->GetBranchName()];
127  for (int j = 0; j < clArray->GetEntries(); j++){
128  FairMultiLinkedData* myData = (FairMultiLinkedData*)clArray->At(j);
129  fMCMatch->SetElements(fMCMatch->GetMCStage(i)->GetStageId(), j, myData);
130  }
131  if (fMCMatch->GetMCStage(i)->GetNEntries() > 0)
132  fMCMatch->GetMCStage(i)->SetLoaded(kTRUE);
133  }
134  }
135 
136  int i = 0;
137  for (int index = 0; index < fMCMatch->GetNMCStages(); index++){
138  CbmMCStage myStage(*(fMCMatch->GetMCStage(index)));
139 
140  for (int indStage = 0; indStage < myStage.GetNEntries(); indStage++){
141 
142  CbmMCEntry myLink(myStage.GetMCLink(indStage));
143  //cout << "myLink: " << myStage.GetMCLink(indStage).GetSource() << "/" << myStage.GetMCLink(indStage).GetPos() << endl;
144  new((*fMCLink)[i]) CbmMCEntry(myLink.GetLinks(), myLink.GetSource(), myLink.GetPos());
145  i++;
146  }
147  }
148 
149  if (fVerbose > 0){
150  fMCMatch->Print();
151  cout << endl;
152  }
153 }
154 
156 {
157 }
158 
159