FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMCMatchCreatorTask.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairMCMatchCreatorTask source file -----
10 // ----- Created 18/07/08 by T.Stockmanns -----
11 // -------------------------------------------------------------------------
12 #include "FairMCMatchCreatorTask.h"
13 
14 #include "FairLink.h" // for FairLink
15 #include "FairMCEntry.h" // for FairMCEntry
16 #include "FairMCMatch.h" // for FairMCMatch
17 #include "FairMCStage.h" // for FairMCStage
18 #include "FairMultiLinkedData.h" // for FairMultiLinkedData
19 #include "FairRootManager.h" // for FairRootManager
20 
21 #include <TClonesArray.h> // for TClonesArray
22 #include <iostream> // for operator<<, basic_ostream, etc
23 
25  : FairTask("Creates FairMCMatch")
26  , fMCMatch(nullptr)
27  , fBranches()
28  , fPersistance(kTRUE)
29  , fMCLink(nullptr)
30  , fEventNr(0)
31 {}
32 
34 
36 {
37  fMCMatch = new FairMCMatch("FairMCMatch", "FairMCMatch");
38 
40 
41  InitStatus status = InitBranches();
42 
44  if (!ioman) {
45  std::cout << "-E- FairMCMatchCreatorTask::Init: "
46  << "RootManager not instantiated!" << std::endl;
47  return kFATAL;
48  }
49 
50  fMCLink = new TClonesArray("FairMCEntry");
51  ioman->Register("MCLink", "MCInfo", fMCLink, kTRUE);
52 
53  ioman->Register("MCMatch", "MCInfo", fMCMatch, kFALSE);
54 
55  std::cout << "-I- FairMCMatchCreatorTask::Init: Initialization successfull" << std::endl;
56 
57  return status;
58 }
59 
60 InitStatus FairMCMatchCreatorTask::InitBranches()
61 {
62 
63  // Get RootManager
65  if (!ioman) {
66  std::cout << "-E- FairMCMatchCreatorTask::Init: "
67  << "RootManager not instantiated!" << std::endl;
68  return kFATAL;
69  }
70 
71  int NStages = fMCMatch->GetNMCStages();
72  for (int i = NStages - 1; i > -1; i--) {
73  TClonesArray* myBranch =
74  static_cast<TClonesArray*>(ioman->GetObject(fMCMatch->GetMCStage(i)->GetBranchName().c_str()));
75  if (!myBranch) {
76  // std::cout << "NMCStages: " << fMCMatch->GetNMCStages() << std::endl;
77  std::cout << "-W- FairMCMatchCreatorTask::Init: "
78  << "No " << fMCMatch->GetMCStage(i)->GetBranchName() << " array!" << std::endl;
79  fMCMatch->GetMCStage(i)->SetFill(kFALSE); // RemoveStage(fMCMatch->GetMCStage(i)->GetStageId());
80 
81  continue;
82  } else {
83  fMCMatch->GetMCStage(i)->SetFill(kTRUE);
84  }
85  fBranches[fMCMatch->GetMCStage(i)->GetBranchName()] = myBranch;
86  }
87  return kSUCCESS;
88 }
89 
91 
92 void FairMCMatchCreatorTask::Exec(Option_t* /*opt*/)
93 {
94  if (!fMCLink) {
95  Fatal("Exec", "No fMCLinkDet");
96  }
97  fMCLink->Delete();
99 
100  fMCMatch->LoadInMCLists(fMCLink);
101 
102  for (int i = 0; i < fMCMatch->GetNMCStages(); i++) {
103  if (fMCMatch->GetMCStage(i)->GetFill() == kTRUE && fMCMatch->GetMCStage(i)->GetLoaded() == kFALSE) {
104  TClonesArray* clArray = fBranches[fMCMatch->GetMCStage(i)->GetBranchName()];
105  for (int j = 0; j < clArray->GetEntries(); j++) {
106  FairMultiLinkedData* myData = static_cast<FairMultiLinkedData*>(clArray->At(j));
107  fMCMatch->SetElements(fMCMatch->GetMCStage(i)->GetStageId(), j, myData);
108  }
109  if (fMCMatch->GetMCStage(i)->GetNEntries() > 0) {
110  fMCMatch->GetMCStage(i)->SetLoaded(kTRUE);
111  }
112  }
113  }
114 
115  int i = 0;
116  if (fPersistance) {
117  for (int index = 0; index < fMCMatch->GetNMCStages(); index++) {
118  FairMCStage myStage(*(fMCMatch->GetMCStage(index)));
119 
120  for (int indStage = 0; indStage < myStage.GetNEntries(); indStage++) {
121 
122  FairMCEntry myLink(myStage.GetMCLink(indStage));
123  new ((*fMCLink)[i]) FairMCEntry(myLink.GetLinks(), myLink.GetSource(), myLink.GetPos());
124  i++;
125  }
126  }
127  }
128 
129  if (fVerbose > 0) {
130  fMCMatch->Print();
131  std::cout << std::endl;
132  }
133 }
134 
136 
int GetNMCStages() const
Definition: FairMCMatch.h:73
InitStatus
Definition: FairTask.h:33
virtual void Exec(Option_t *opt)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
void SetElements(Int_t sourceType, int index, FairMultiLinkedData *links)
Definition: FairMCMatch.cxx:51
void SetFill(Bool_t fill)
Definition: FairMCStage.h:62
virtual void InitDataStages()=0
Int_t fVerbose
Definition: FairTask.h:100
void SetLoaded(Bool_t loaded)
Definition: FairMCStage.h:61
Bool_t GetFill(void) const
Definition: FairMCStage.h:68
Bool_t GetLoaded(void) const
Definition: FairMCStage.h:67
int GetNEntries() const
Definition: FairMCObject.h:80
FairMCEntry GetMCLink(Int_t index)
Definition: FairMCObject.h:78
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void ClearMCList()
Int_t GetStageId(void) const
Definition: FairMCObject.h:76
void LoadInMCLists(TClonesArray *myLinkArray)
std::string GetBranchName(void) const
Definition: FairMCStage.h:64
FairMCStage * GetMCStage(int index) const
Definition: FairMCMatch.h:75