FairRoot/PandaRoot
PndEventBuilderManager.cxx
Go to the documentation of this file.
1 /* $Id: */
2 
3 // -------------------------------------------------------------------------
4 // ----- PndEventBuilderManager source file -----
5 // ----- Created 23/09/2013 by R. Karabowicz -----
6 // -------------------------------------------------------------------------
7 
24 #include "PndEventBuilderManager.h"
25 
26 #include "FairRecoEventHeader.h"
27 #include "FairRootManager.h"
28 #include "FairRunAna.h"
29 #include "FairRuntimeDb.h"
30 
31 #include "TClonesArray.h"
32 #include "TMath.h"
33 #include "TRandom2.h"
34 
35 #include <iomanip>
36 
37 using std::cout;
38 using std::cerr;
39 using std::endl;
40 using std::flush;
41 using std::fixed;
42 using std::right;
43 using std::left;
44 using std::setw;
45 using std::setprecision;
46 using std::set;
47 using std::map;
48 
49 using std::sort;
50 using std::iterator;
51 using std::vector;
52 
53 // ----- Default constructor ------------------------------------------
55  : FairEventBuilderManager(),
56  fOutEvent (NULL)
57 {
58 }
59 // -------------------------------------------------------------------------
60 
61 // ----- Constructor with name -----------------------------------------
63  : FairEventBuilderManager(name, iVerbose),
64  fOutEvent (NULL)
65 {
66 }
67 // -------------------------------------------------------------------------
68 
69 
70 
71 // ----- Destructor ----------------------------------------------------
73 }
74 // -------------------------------------------------------------------------
75 
76 // ----- Private method AnalyzeAndExtractEvents ------------------------
78  if ( fVerbose )
79  cout << "PndEventBuilderManager::AnalyzeAndExtractEvents(" << maxEventTimeAllowed << ")" << endl;
80 
81  Double_t minEventTime = 10.e6;
82  Double_t minEventTErr = 0.;
83  FairRecoEventHeader* tempREH = NULL;
84  while ( 1==1 ) {
85  minEventTime = 10.e6;
86  // find smallest event time
87  for ( Int_t ieb = 0 ; ieb < fEventBuilders.size() ; ieb++ ) {
88  for ( Int_t iev = 0 ; iev < fPossibleEvents[ieb].size() ; iev++ ) {
89  tempREH = (FairRecoEventHeader*)fPossibleEvents[ieb][iev].second;
90  if ( fVerbose )
91  cout << " fPossibleEvents[" << fEventBuilders[ieb]->GetName()
92  << "][" << iev << "] . " << fPossibleEvents[ieb][iev].first << endl;
93  if ( fPossibleEvents[ieb][iev].second->GetEventTime() < minEventTime ) {// i think it is enough to take .first instead of .second->GetEventTime()
94  minEventTime = fPossibleEvents[ieb][iev].second->GetEventTime();
95  minEventTErr = fPossibleEvents[ieb][iev].second->GetEventTimeError();
96  }
97  }
98  }
99  if ( fVerbose )
100  cout << " minEventTime is now " << minEventTime << " with error " << minEventTErr << endl;
101 
102  // check if can be saved
103  if ( maxEventTimeAllowed > -0.5 && minEventTime > maxEventTimeAllowed-5 ) {
104  // cout << "sorry, larger than " << maxEventTimeAllowed-5 << endl;
105  break;
106  }
107  if ( minEventTime > 9.9e6 ) break;
108  // calculate mean event time and remove close events from the event times' TCAs
109  // in fact it should be a mean event with all event characteristics
110  Double_t meanEventTime = 0.;
111  Double_t nofOfEvents = 0.;
112  Double_t sumTW = 0.;
113  Double_t sumW = 0.;
114  Int_t ident = 0;
115  for ( Int_t ieb = 0 ; ieb < fEventBuilders.size() ; ieb++ ) {
116  for ( Int_t iev = 0 ; iev < fPossibleEvents[ieb].size() ; iev++ ) {
117  tempREH = (FairRecoEventHeader*)fPossibleEvents[ieb][iev].second;
118  if ( TMath::Abs(tempREH->GetEventTime()-minEventTime) < minEventTErr+tempREH->GetEventTimeError() ) {
119  if ( tempREH->GetEventTimeError() < 1.e-6 ) {
120  cout << "ERROR ALMOST 0!!!! " << tempREH->GetEventTimeError() << endl;
121  continue;
122  }
123  // meanEventTime += tempREH->GetEventTime();
124  sumTW += tempREH->GetEventTime()/tempREH->GetEventTimeError()/tempREH->GetEventTimeError();
125  sumW += 1./tempREH->GetEventTimeError()/tempREH->GetEventTimeError();
126  ident |= tempREH->GetIdentifier();
127  minEventTime = sumTW/sumW;
128  minEventTErr = TMath::Sqrt(1./sumW);
129  if ( fVerbose )
130  cout << " added event at " << tempREH->GetEventTime() << " +- " << tempREH->GetEventTimeError() << endl;
131  nofOfEvents += 1.;
132  fPossibleEvents[ieb][iev] = fPossibleEvents[ieb][fPossibleEvents[ieb].size()-1];
133  fPossibleEvents[ieb].pop_back();
134  }
135  }
136  }
137  if ( nofOfEvents == 0 ) continue;
138 
139  if ( fVerbose ) {
140  cout << " CREATED EVENT AT " << meanEventTime/nofOfEvents << " OUT OF " << nofOfEvents << " EVENTS" << endl;
141  cout << " WEIGHTED MEAN AT " << sumTW/sumW << " WITH ERROR OF " << TMath::Sqrt(1./sumW) << endl;
142  }
143 
144  fOutEvent->SetEventTime(sumTW/sumW,TMath::Sqrt(1./sumW));//meanEventTime/nofOfEvents,2.);
145  fOutEvent->SetIdentifier(ident);
146 
147  CreateAndFillEvent(fOutEvent);
148  }
149 }
150 // -------------------------------------------------------------------------
151 
152 
153 // ----- Private method SetParContainers -------------------------------
155 
156  // Get run and runtime database
157  FairRunAna* run = FairRunAna::Instance();
158  if ( ! run ) Fatal("SetParContainers", "No analysis run");
159 
160  FairRuntimeDb* db = run->GetRuntimeDb();
161  if ( ! db ) Fatal("SetParContainers", "No runtime database");
162 }
163 // -------------------------------------------------------------------------
164 
165 // ----- Private method Init -------------------------------------------
167  // Get input array
168  FairRootManager* ioman = FairRootManager::Instance();
169  if ( ! ioman ) Fatal("Init", "No FairRootManager");
170 
171  cout << "*** PndEventBuilderManager. " << fEventBuilders.size() << " event builders registered." << endl;
172 
173  fOutEvent = new FairRecoEventHeader();
174  FairRootManager::Instance()->Register("RecoEventHeader.", "RecoEvent", fOutEvent, kTRUE);
175 
176  for ( Int_t ieb = 0 ; ieb < fEventBuilders.size() ; ieb++ ) {
177  fEventBuilders[ieb]->SetIdentifier(TMath::Power(2,ieb));
178  fEventBuilders[ieb]->Init();
179  }
180 
181  return kSUCCESS;
182 }
183 // -------------------------------------------------------------------------
184 
185 // ----- Private method ReInit -------------------------------------------
187 
188  return kSUCCESS;
189 }
190 // -------------------------------------------------------------------------
191 
192 
193 
194 
196 
int fVerbose
Definition: poormantracks.C:24
Int_t run
Definition: autocutx.C:47
PndTransMap * map
Definition: sim_emc_apd.C:99
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
static T Abs(const T &x)
Definition: PndCAMath.h:39
FairRecoEventHeader * fOutEvent
Double_t
TString name
virtual void AnalyzeAndExtractEvents(Double_t maxEventTimeAllowed)
ClassImp(PndAnaContFact)
Int_t iVerbose