FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMCDataCrawler.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  * FairMCDataCrawler.cpp
10  *
11  * Created on: Jul 5, 2011
12  * Author: stockman
13  */
14 
15 #include "FairMCDataCrawler.h"
16 
17 #include "FairLink.h" // for FairLink, operator<<
18 #include "FairRootManager.h" // for FairRootManager
19 
20 #include <iostream> // for operator<<, ostream, cout, etc
21 
23 
25  : fIoman(FairRootManager::Instance())
26  , fFinalStage()
27  , fUltimateStage(0)
28  , fVerbose(0)
29  , fStoreAllEndpoints(kTRUE)
30  , fStoreIntermediate(kTRUE)
31 {}
32 
34 
36 {
37 
39  /*
40  fIoman->GetObject("MVDPoint");
41  fIoman->GetObject("MVDStripDigis");
42  fIoman->GetObject("MVDPixelDigis");
43  fIoman->GetObject("MVDHitsPixel");
44  fIoman->GetObject("MVDHitsStrip");
45  fIoman->GetObject("MVDPixelClusterCand");
46  fIoman->GetObject("MVDStripClusterCand");
47  fIoman->GetObject("MVDSortedStripDigis");
48  fIoman->GetObject("MVDSortedPixelDigis");
49 
50 
51  fIoman->GetObject("EmcCluster");
52  fIoman->GetObject("EmcBump");
53  fIoman->GetObject("EmcDigi");
54  fIoman->GetObject("EmcHit");
55  fIoman->GetObject("EmcPoint");
56  fIoman->GetObject("EmcRecoHit");
57  fIoman->GetObject("EmcSharedDigi");
58  fIoman->GetObject("EmcWaveform");
59 
60 
61 
62  fIoman->GetObject("STTPoint");
63  fIoman->GetObject("STTHit");
64  fIoman->GetObject("SttHelixHit");
65  fIoman->GetObject("STTTrack");
66  fIoman->GetObject("STTTrackCand");
67 
68  fIoman->GetObject("FairTpcPoint");
69  fIoman->GetObject("FairTpcPrimaryCluster");
70  fIoman->GetObject("FairTpcDriftedElectron");
71  fIoman->GetObject("FairTpcAvalanche");
72  fIoman->GetObject("FairTpcSignal");
73  fIoman->GetObject("FairTpcDigi");
74  fIoman->GetObject("FairTpcCluster");
75 
76 
77  fIoman->GetObject("GEMPoint");
78  fIoman->GetObject("GEMDigi");
79  fIoman->GetObject("GEMHit");
80 
81  fIoman->GetObject("FairDchPoint");
82  fIoman->GetObject("FairDchDigi");
83  fIoman->GetObject("PndDchCylinderHit");
84 
85  fIoman->GetObject("MdtPoint");
86  fIoman->GetObject("MdtHit");
87  fIoman->GetObject("MdtTrk");
88 
89  fIoman->GetObject("LheHit");
90  fIoman->GetObject("LheCandidate");
91  fIoman->GetObject("LheTrack");
92  fIoman->GetObject("MVDIdealTrackCand");
93  fIoman->GetObject("MVDRiemannTrackCand");
94  fIoman->GetObject("PndTrack");
95  fIoman->GetObject("LheGenTrack");
96  fIoman->GetObject("PidChargedCand");
97  fIoman->GetObject("PidNeutralCand");
98  */
99 }
100 
102 {
103  return GetInfo(startLink, fIoman->GetBranchId(stopStage));
104 }
105 
107 {
108  fFinalStage.ResetLinks();
109  if (fVerbose > 1) {
110  std::cout << "-------------------------------------" << std::endl;
111  std::cout << "StartLink: " << startLink;
112  }
113  if (fVerbose > 1) {
114  std::cout << "StopStageLink: " << fIoman->GetBranchName(stopStageId) << std::endl;
115  }
116  GetNextStage(startLink, stopStageId);
117  if (fVerbose > 1) {
118  std::cout << "FinalStage: " << fFinalStage << std::endl;
119  }
120  return fFinalStage;
121 }
122 
124 {
126 }
127 
128 FairMultiLinkedData* FairMCDataCrawler::GetEntry(Int_t fileId, Int_t eventNr, Int_t type, Int_t index)
129 {
130  return GetEntry(FairLink(fileId, eventNr, type, index));
131 }
132 
133 void FairMCDataCrawler::GetNextStage(FairMultiLinkedData& startStage, Int_t stopStage)
134 {
135  FairMultiLinkedData* tempStage;
136  for (int i = 0; i < startStage.GetNLinks(); i++) {
137  FairLink actualLink = startStage.GetLink(i);
138  // if (fVerbose > 0) { std::cout << "Actual Link: " << actualLink << std::endl; }
139  if (actualLink.GetType() < 0) {
140  if (fStoreAllEndpoints) {
141  AddToFinalStage(actualLink, 1);
142  }
143  if (fVerbose > 2) {
144  std::cout << "ActualLink.Type < 0" << std::endl;
145  std::cout << "FinalStage: " << fFinalStage << std::endl;
146  std::cout << "---------------------" << std::endl;
147  }
148  if (fVerbose > 1) {
149  std::cout << std::endl;
150  }
151  } else if (actualLink.GetType() == stopStage) {
152  AddToFinalStage(actualLink, 1);
153  if (fVerbose > 2) {
154  std::cout << "ActualLink.Type == stopStage" << std::endl;
155  std::cout << "FinalStage: " << fFinalStage << std::endl;
156  std::cout << "---------------------" << std::endl;
157  }
158  if (fVerbose > 1) {
159  std::cout << std::endl;
160  }
161  } else if (actualLink.GetType() == fUltimateStage) {
162  if (fStoreAllEndpoints) {
163  AddToFinalStage(actualLink, 1);
164  }
165  if (fVerbose > 2) {
166  std::cout << "ActualLink.Type == UltimateStage" << std::endl;
167  std::cout << "FinalStage: " << fFinalStage << std::endl;
168  std::cout << "---------------------" << std::endl;
169  }
170  if (fVerbose > 1) {
171  std::cout << std::endl;
172  }
173  } else if (actualLink.GetType() == FairRootManager::Instance()->GetBranchId("EventHeader.")) {
174  if (fStoreAllEndpoints) {
175  AddToFinalStage(actualLink, 1);
176  }
177  if (fVerbose > 2) {
178  std::cout << "ActualLink.Type == EventHeader" << std::endl;
179  std::cout << "FinalStage: " << fFinalStage << std::endl;
180  std::cout << "---------------------" << std::endl;
181  }
182  if (fVerbose > 1) {
183  std::cout << std::endl;
184  }
185  } else {
186  tempStage = GetEntry(actualLink);
187  if (tempStage == 0) {
188  if (fStoreAllEndpoints) {
189  AddToFinalStage(actualLink, 1);
190  }
191  if (fVerbose > 2) {
192  std::cout << "TempStage == 0" << std::endl;
193  std::cout << "FinalStage: " << fFinalStage << std::endl;
194  std::cout << "---------------------" << std::endl;
195  }
196  if (fVerbose > 1) {
197  std::cout << std::endl;
198  }
199  continue;
200  }
201  if (fVerbose > 0) {
202  // std::cout << "TempStage Start";
203  std::cout << " // ";
204  std::cout << actualLink;
205  std::cout << " --> " << *tempStage;
206  }
207  if (tempStage->GetNLinks() == 0) {
208  if (fStoreAllEndpoints) {
209  AddToFinalStage(actualLink, 1);
210  }
211  if (fVerbose > 0) {
212  std::cout << "tempStage->GetNLinks == 0" << std::endl;
213  std::cout << "FinalStage: " << fFinalStage << std::endl;
214  std::cout << "---------------------" << std::endl;
215  }
216  } else {
217  if (fStoreIntermediate) {
218  AddToFinalStage(actualLink, 1);
219  }
220  double tempStageWeight = 1;
221  double startLinkWeight = startStage.GetLink(i).GetWeight();
222 
223  if (fVerbose > 2) {
224  // std::cout << "Tempstage " << tempStage.GetSource() << ": weight " << tempStageWeight <<
225  // std::endl;
226  std::cout << "StartLinkWeight " << startLinkWeight << std::endl;
227  }
228  // std::cout << " StageWeight: " << tempStageWeight << " startLinkWeight: " << startLinkWeight;
229  tempStage->MultiplyAllWeights(tempStageWeight);
230 
231  if ((tempStageWeight * startLinkWeight) == 0) {
232  tempStage->MultiplyAllWeights(tempStageWeight);
233  tempStage->AddAllWeights(startLinkWeight / startStage.GetNLinks());
234  if (fVerbose > 2) {
235  std::cout << " NLinks: " << tempStage->GetNLinks() << " ";
236  std::cout << "AddAllWeights: " << startLinkWeight / startStage.GetNLinks() << std::endl;
237  }
238  } else {
239  tempStage->MultiplyAllWeights(startLinkWeight);
240  if (fVerbose > 2) {
241  std::cout << "MultiplyAllWeights: " << startLinkWeight << std::endl;
242  }
243  }
244  }
245  // if (fVerbose > 0)
246  // std::cout<< "TempStage Stop: " << *tempStage << std::endl;
247 
248  GetNextStage(*tempStage, stopStage);
249  }
250  }
251 }
252 
253 void FairMCDataCrawler::AddToFinalStage(FairLink hitPair, Float_t mult) { fFinalStage.AddLink(hitPair, false, mult); }
FairRootManager * fIoman
virtual void InitDataObjects()=0
TObject * GetCloneOfLinkData(const FairLink link)
virtual void AddAllWeights(Double_t weight)
Adds weight to all Links.
static FairRootManager * Instance()
virtual void ResetLinks()
Clears fLinks.
ClassImp(FairEventBuilder)
virtual void MultiplyAllWeights(Double_t weight)
Multiplies all Links with weight.
FairMultiLinkedData * GetEntry(Int_t fileId, Int_t eventNr, Int_t type, Int_t index)
FairMultiLinkedData GetInfo(FairMultiLinkedData startLink, TString stopStage)
TString GetBranchName(Int_t id)
virtual Int_t GetNLinks() const
returns the number of stored links
virtual FairLink GetLink(Int_t pos) const
returns the FairLink at the given position
virtual void AddLink(FairLink link, Bool_t bypass=kFALSE, Float_t mult=1.0)
Int_t GetBranchId(TString const &BrName)