er  dev
simtorawold.cxx
1 #include "ERSimtoRaw.h"
2 #include "FairRun.h"
3 
4 #include "TClonesArray.h"
5 
6 #include<iostream>
7 using namespace std;
8 
9 // ----------------------------------------------------------------------------
10 
11 // ----------------------------------------------------------------------------
12 ERSimtoRaw::ERSimtoRaw(Int_t NEvents)
13  : FairTask("Convert Sim event to Raw event", NEvents),
14 fNChanels(2),
15 fEvent(0),
16 fNPoints(1000),
17 fPixelSignals(NULL),
18 fRawEvents(NULL)
19 {
20 }
21 // ----------------------------------------------------------------------------
22 
23 // ----------------------------------------------------------------------------
25  : FairTask("Convert Sim event to Raw event"),
26 fNChanels(2),
27 fEvent(0),
28 fNPoints(1000),
29 fPixelSignals(NULL),
30 fRawEvents(NULL)
31 {
32 }
33 // ----------------------------------------------------------------------------
34 
35 // ----------------------------------------------------------------------------
37 {
38 }
39 // ----------------------------------------------------------------------------
40 
41 // ----------------------------------------------------------------------------
42 InitStatus ERSimtoRaw::Init()
43 {
44  // Get input array
45  FairRootManager* ioman = FairRootManager::Instance();
46  if ( ! ioman ) Fatal("Init", "No FairRootManager");
47 
48  //Get input objects
49  // fPixelSignals = (ERNeuRadPixelSignal*) ioman->GetObject("NeuRadPixelSignal");
50  fPixelSignals = (TClonesArray*) ioman->GetObject("NeuRadPixelSignal");
51  if (!fPixelSignals)
52  Fatal("Init", "Can`t find branch in input file!");
53 
54  //Register output objects
55  fRawEvents = new RawEvent*[fNChanels];
56  for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
57  fRawEvents[iChanel] = new RawEvent(fNPoints);
58  TString bName;
59  bName.Form("ch%d.",iChanel+1);
60  ioman->Register(bName,"Raw", fRawEvents[iChanel], kTRUE);
61  }
62 
63  return kSUCCESS;
64 }
65 // -------------------------------------------------------------------------
66 
67 // ----- Public method Exec --------------------------------------------
68 void ERSimtoRaw::Exec(Option_t* opt)
69 {
70  fEvent++;
71  if ( !(fEvent%100000) ) { std::cout << "####### EVENT " << fEvent << " #####" << std::endl; }
72  Int_t simSize,side,counter;
73  Double_t maxAmp;
74 
75  FairRun* run = FairRun::Instance();
76  run->MarkFill(kFALSE);
77  for (Int_t iSignal = 0; iSignal < fPixelSignals->GetEntriesFast(); iSignal++){
78  ERNeuRadPixelSignal* signal = (ERNeuRadPixelSignal*)fPixelSignals->At(iSignal);
79  // if (signal->Side() !=1 || signal->PixelNb() != 25) continue;
80  if ( signal->PixelNb() != 136 ) continue;
81  TArrayF* result = signal->ResultSignal();
82  maxAmp = 0;
83  simSize = 0;
84  simSize = result->GetSize();
85 
86  if ( signal->Side() == 0 ){
87  for(Int_t i = 0; i<simSize; i++){
88  if( maxAmp < result->GetAt(i) ) {maxAmp = result->GetAt(i);}
89  } //searching maxAmp
90  //cout << maxAmp << endl;
91  if(maxAmp > 30) {
92  cout << " not NULL event found " << endl;
93  run->MarkFill(kTRUE);
94  }
95  }
96  // std::cout << "####### AMP " << maxAmp << " #####" << std::endl;
97  // Int_t PixelNb() const {return fPixelNb;}
98  // Int_t Side() const {return fSide;}
99 
100 
101 
102  for(Int_t nPoint = 0; nPoint< fNPoints; nPoint++){
103 
104  if( nPoint<=(fNPoints - simSize)/2 || nPoint>=(fNPoints + simSize)/2 ) {
105  if(signal->Side() == 0) {fRawEvents[0]->SetAmp(0, nPoint);}
106  if(signal->Side() == 1) {fRawEvents[1]->SetAmp(0, nPoint);}
107  }
108  else{
109  if(signal->Side() == 0) {fRawEvents[0]->SetAmp(-result->GetAt(nPoint - (fNPoints - simSize)/2), nPoint);} //fill the RawEvent
110  if(signal->Side() == 1) {fRawEvents[1]->SetAmp(-result->GetAt(nPoint - (fNPoints - simSize)/2), nPoint);}
111  // fRawEvents[0]->SetAmp(0, nPoint); //fill the RawEvent
112  }
113 
114  if(signal->Side() == 0) {fRawEvents[0]->SetTime(nPoint*0.1, nPoint);}
115  if(signal->Side() == 1) {fRawEvents[1]->SetTime(nPoint*0.1, nPoint);}
116  }
117  }
118  //----------------------------------------------------------------------------
119  //cout << signal->Side() << "\t" << signal->PixelNb() << endl;
120  // Int_t count = (Int_t)(signal->FinishTime()-signal->StartTime())/signal->dT();
121  // Float_t* times = new Float_t[count];
122  // for (Int_t i = 0; i < count; i++){
123  // times[i] = signal->StartTime() + signal->dT()*i;
124  // }
125  // TGraph* gr = new TGraph(count,times,result->GetArray());
126  // TString title;
127  // title.Form("Pixel Signal, side %d,%d fiber, %d module, %d pe, %d", signal->Side(),
128  // signal->PixelNb(), signal->ModuleNb(), signal->PECount(),
129  // FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber());
130  // gr->SetTitle(title);
131  // if (signal->Side() == 0)
132  // front->cd();
133  // else
134  // back->cd();
135  // gr->Write();
136  // delete gr;
137  // delete [] times;
138 
139 
140 
141  // for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
142  // //ERNeuRadPixelSignal* signal = (ERNeuRadPixelSignal*)fPixelSignals->At(iChanel);
143  // TArrayF* result = fPixelSignals->ResultSignal();
144  // for(Int_t nPoint = 0; nPoint< fNPoints; nPoint++){
145  // fRawEvents[iChanel]->SetAmp(result->GetAt(nPoint), nPoint); //fill the RawEvent
146  // fRawEvents[iChanel]->SetTime(nPoint*0.1, nPoint);
147  // }
148  // }
149 
150 }
151 //----------------------------------------------------------------------------
virtual void Exec(Option_t *opt)
Definition: ERSimtoRaw.cxx:75
virtual InitStatus Init()
Definition: ERSimtoRaw.cxx:48