FairRoot/PandaRoot
PndTimeOffsetFinderTask.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 version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- PndTimeOffsetFinderTaskT source file -----
10 // -------------------------------------------------------------------------
11 
13 
14 #include "FairLink.h" // for FairLink
15 #include "FairRootManager.h" // for FairRootManager
16 #include "FairTimeStamp.h" // for FairTimeStamp
17 #include "FairRunAna.h"
18 
19 #include "PndSdsHit.h"
20 
21 #include <iosfwd> // for ostream
22 #include "TClass.h" // for TClass
23 #include "TClonesArray.h" // for TClonesArray
24 
25 #include <iostream> // for operator<<, cout, ostream, etc
26 #include <iomanip>
27 #include <vector> // for vector
28 
30 {
31  return kSUCCESS;
32 }
33 
34 // ----- Public method Init --------------------------------------------
36 {
37 
38  FairRootManager* ioman = FairRootManager::Instance();
39  if ( ! ioman ) {
40  std::cout << "-E- PndTimeOffsetFinderTaskT::Init: "
41  << "RootManager not instantiated!" << std::endl;
42  return kFATAL;
43  }
44 
45  // Create and register output array
46  fInputArray = (TClonesArray*)FairRootManager::Instance()->GetObject("MVDHitsPixel");
47 
48  //if(fVerbose>1) { Info("Init","Registering this branch: %s/%s",fFolder.Data(),fOutputBranch.Data()); }
49  //fOutputArray = ioman->Register(fOutputBranch, fInputArray->GetClass()->GetName(), fFolder, fPersistance);
50 
51  fHc0c1 = new TH1D("fHc0c1", "fHc0c1", 2000000, -5000000, 15000000);
52  fHc0c2 = new TH1D("fHc0c2", "fHc0c2", 2000000, -5000000, 15000000);
53  fHc0c3 = new TH1D("fHc0c3", "fHc0c3", 2000000, -5000000, 15000000);
54  fHc1c2 = new TH1D("fHc1c2", "fHc1c2", 2000000, -5000000, 15000000);
55  fHc1c3 = new TH1D("fHc1c3", "fHc1c3", 2000000, -5000000, 15000000);
56  fHc2c3 = new TH1D("fHc2c3", "fHc2c3", 2000000, -5000000, 15000000);
57 
58  FairRootManager::Instance()->InitTSBuffer(fInputBranch, fFunctor);
59  FairTSBufferFunctional* buffer = FairRootManager::Instance()->GetTSBuffer(fInputBranch);
60  if (buffer != 0){
61  buffer->SetBranchIndex(fStartIndex);
62  std::cout << "BranchIndex: " << buffer->GetBranchIndex() << std::endl;
63  }
64 
65 
66  return kSUCCESS;
67 }
68 // -------------------------------------------------------------------------
69 
70 // ----- Public method Exec --------------------------------------------
72 {
73  if (FairRunAna::Instance()->IsTimeStamp() != kTRUE){
74  std::cout << "-E- PndTimeOffsetFinderTask::Exec not running in time based mode." << std::endl;
75  return;
76  }
77 // if (fFirstExecute){
78 // std::cout << "PndTimeOffsetFinderTask::Exec first execute called with time " << fStartTime << std::endl;
79 // fFirstExecute = kFALSE;
80 //
81 // if (fStartIndex > 0){
82 // fInputArray = FairRootManager::Instance()->GetData(fInputBranch, fFunctor, 0);
83 //
84 // FairTSBufferFunctional* buffer = FairRootManager::Instance()->GetTSBuffer(fInputBranch);
85 // if (buffer != 0){
86 // buffer->SetBranchIndex(fStartIndex);
87 // std::cout << "BranchIndex: " << buffer->GetBranchIndex() << std::endl;
88 // }
89 // }
90 // fInputArray = FairRootManager::Instance()->GetData(fInputBranch, fFunctor, fStartTime);
91 //
92 // //std::cout << "fInputArray size: " << fInputArray->GetEntriesFast() << std::endl;
93 // fInputArray->Delete();
94 // fLastTimeStamp = fStartTime;
95 // }
96  fInputArray = FairRootManager::Instance()->GetData(fInputBranch, fFunctor, fLastTimeStamp + fTimeOffset);
97  //std::cout << "Exec called: " << fEntryNr++ << std::endl;
98  for (int i = 0; i < fInputArray->GetEntriesFast(); i++){
99  PndSdsHit* second = (PndSdsHit*)fInputArray->At(i);
100  // std::cout << i << " : " << std::setw(12) << second->GetTimeStamp() << std::endl;
101  }
102  PndSdsHit* first;
103  //std::cout << "NEntries " << fInputArray->GetEntriesFast() << std::endl;
104  if (fInputArray->GetEntriesFast() > 1){
105  first = (PndSdsHit*)fInputArray->At(0);
106 // std::cout << "first: " << *first << std::endl;
107  if (first != 0)
108  fLastTimeStamp = first->GetTimeStamp();
109  }
111 
113  std::cout << "PndTimeOffsetFinderTask::Exec fLastTimeStamp " << fLastTimeStamp << " > TerminateTime " << fTerminateTime << std::endl;
114  FairRootManager::Instance()->TerminateTSBuffer(fInputBranch);
115  return;
116  }
117  if (fEntryNr++ % 1000 == 0)
118  std::cout << "EventProcessed: " << fEntryNr << " fLastTimeStamp: " << fLastTimeStamp << " TeminateTime " << fTerminateTime << std::endl;
119 
120 
121  if (fInputArray->GetEntriesFast() > 1){
122  //PndSdsHit* first = (PndSdsHit*)fInputArray->At(0);
123  for (int i = 1; i < fInputArray->GetEntriesFast(); i++){
124  PndSdsHit* second = (PndSdsHit*)fInputArray->At(i);
125  // std::cout << "first: " << std::setw(12) << first->GetTimeStamp() << " second: " << std::setw(12) << second->GetTimeStamp() <<
126  // " diff " << second->GetTimeStamp() - first->GetTimeStamp() << std::endl;
127  if (first->GetSensorID() == second->GetSensorID())
128  continue;
129 
130  double diff;
131  if (first->GetSensorID() < second->GetSensorID())
132  diff = second->GetTimeStamp() - first->GetTimeStamp();
133  else diff = first->GetTimeStamp() - second->GetTimeStamp();
134 
135  if ((first->GetSensorID() == 0 && second->GetSensorID() == 1)
136  || (first->GetSensorID() == 1 && second->GetSensorID() == 0))
137  fHc0c1->Fill(diff);
138  else if ((first->GetSensorID() == 0 && second->GetSensorID() == 2)
139  || (first->GetSensorID() == 2 && second->GetSensorID() == 0))
140  fHc0c2->Fill(diff);
141  else if ((first->GetSensorID() == 0 && second->GetSensorID() == 3)
142  || (first->GetSensorID() == 3 && second->GetSensorID() == 0))
143  fHc0c3->Fill(diff);
144  else if ((first->GetSensorID() == 1 && second->GetSensorID() == 2)
145  || (first->GetSensorID() == 2 && second->GetSensorID() == 1))
146  fHc1c2->Fill(diff);
147  else if ((first->GetSensorID() == 1 && second->GetSensorID() == 3)
148  || (first->GetSensorID() == 3 && second->GetSensorID() == 1))
149  fHc1c3->Fill(diff);
150  else if ((first->GetSensorID() == 2 && second->GetSensorID() == 3)
151  || (first->GetSensorID() == 3 && second->GetSensorID() == 2))
152  fHc2c3->Fill(diff);
153 
154  }
155  TClonesArray* tempArray = new TClonesArray(fInputArray->GetClass()->GetName());
156  tempArray->AbsorbObjects(fInputArray,1,fInputArray->GetEntriesFast()-1);
157  fInputArray->Delete();
158  fInputArray->AbsorbObjects(tempArray,0,tempArray->GetEntriesFast()-1);
159  delete(tempArray);
160  //std::cout << "RemoveFirst: " << fInputArray->GetEntriesFast() << std::endl;
161  }
162 }
163 
164 // -------------------------------------------------------------------------
165 
167 {
168  // fOutputArray->Delete();
169 }
170 
172 {
173  fHc0c1->Write();
174  fHc0c2->Write();
175  fHc0c3->Write();
176  fHc1c2->Write();
177  fHc1c3->Write();
178  fHc2c3->Write();
179 
180 }
181 
Int_t i
Definition: run_full.C:25
virtual void Exec(Option_t *opt)
ClassImp(PndAnaContFact)
Int_t GetSensorID() const
Definition: PndSdsHit.h:90