er  dev
ERSimtoRaw.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
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 #include "ERSimtoRaw.h"
10 
11 #include "FairRun.h"
12 
13 #include<iostream>
14 
15 using namespace std;
16 
17 // ----------------------------------------------------------------------------
18 ERSimtoRaw::ERSimtoRaw(Int_t NEvents)
19  : FairTask("Convert Sim event to Raw event", NEvents),
20 fNChanels(2),
21 fEvent(0),
22 fNPoints(1000),
23 fPixelSignals(NULL),
24 fRawEvents(NULL)
25 {
26 }
27 // ----------------------------------------------------------------------------
28 
29 // ----------------------------------------------------------------------------
31  : FairTask("Convert Sim event to Raw event"),
32 fNChanels(2),
33 fEvent(0),
34 fNPoints(1000),
35 fPixelSignals(NULL),
36 fRawEvents(NULL)
37 {
38 }
39 // ----------------------------------------------------------------------------
40 
41 // ----------------------------------------------------------------------------
43 {
44 }
45 // ----------------------------------------------------------------------------
46 
47 // ----------------------------------------------------------------------------
48 InitStatus ERSimtoRaw::Init()
49 {
50  // Get input array
51  FairRootManager* ioman = FairRootManager::Instance();
52  if ( ! ioman ) Fatal("Init", "No FairRootManager");
53 
54  //Get input objects
55  // fPixelSignals = (ERNeuRadPixelSignal*) ioman->GetObject("NeuRadPixelSignal");
56  fPixelSignals = (TClonesArray*) ioman->GetObject("NeuRadPixelSignal");
57  if (!fPixelSignals)
58  Fatal("Init", "Can`t find branch in input file!");
59 
60 
61  //Register output objects
62  fRawEvents = new ERNeuRadRawEvent*[fNChanels];
63  for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
64  fRawEvents[iChanel] = new ERNeuRadRawEvent(fNPoints);
65  TString bName;
66  bName.Form("ch%d.",iChanel+1);
67  ioman->Register(bName,"Raw", fRawEvents[iChanel], kTRUE);
68  }
69 
70  return kSUCCESS;
71 }
72 // -------------------------------------------------------------------------
73 
74 // ----- Public method Exec --------------------------------------------
75 void ERSimtoRaw::Exec(Option_t* opt)
76 {
77  fEvent++;
78  if ( !(fEvent%500) ) { std::cout << "####### EVENT " << fEvent << " #####" << std::endl; }
79  Int_t simSize,side,counter,PEnum;
80  Double_t maxAmp, StartTime, FinishTime;
81 
82 
83 
84  FairRun* run = FairRun::Instance();
85  run->MarkFill(kFALSE);
86  for (Int_t iSignal = 0; iSignal < fPixelSignals->GetEntriesFast(); iSignal++){
87  ERNeuRadPixelSignal* signal = (ERNeuRadPixelSignal*)fPixelSignals->At(iSignal);
88  if ( signal->PixelNb() != 136 ) continue; // for obtaining data from single chosen fiber
89  TArrayF* result = signal->ResultSignal();
90  maxAmp = 0;
91  simSize = 0;
92  simSize = result->GetSize();
93 
94  if ( signal->Side() == 0 ){
95  for(Int_t i = 0; i<simSize; i++){
96  if( maxAmp < result->GetAt(i) ) {maxAmp = result->GetAt(i);}
97  } //searching maxAmp
98  // if(maxAmp > 100.) { // trigger in [mV]
99  run->MarkFill(kTRUE);
100  // }
101  }
102  StartTime = signal->GetStartTime();
103  FinishTime = signal->GetFinishTime();
104 
105  for(Int_t nPoint = 0; nPoint< fNPoints; nPoint++) {
106 
107  if( nPoint<=StartTime*10 || nPoint>=(FinishTime*10-1) ) {
108  if(signal->Side() == 0) {fRawEvents[0]->SetAmp(0, nPoint);}
109  if(signal->Side() == 1) {fRawEvents[1]->SetAmp(0, nPoint);}
110  }
111  else {
112  if(signal->Side() == 0) {fRawEvents[0]->SetAmp(-result->GetAt(nPoint - StartTime*10), nPoint);} //fill the RawEvent
113  if(signal->Side() == 1) {fRawEvents[1]->SetAmp(-result->GetAt(nPoint - StartTime*10), nPoint);}
114  }
115 
116  if(signal->Side() == 0) {fRawEvents[0]->SetTime(nPoint*0.1, nPoint);}
117  if(signal->Side() == 1) {fRawEvents[1]->SetTime(nPoint*0.1, nPoint);}
118  }
119 
120  if(signal->Side() == 0) fRawEvents[0]->SetStartTime(StartTime);
121  if(signal->Side() == 1) fRawEvents[1]->SetStartTime(StartTime);
122  if(signal->Side() == 0) fRawEvents[0]->SetFinishTime(FinishTime);
123  if(signal->Side() == 1) fRawEvents[1]->SetFinishTime(FinishTime);
124 
125  if(signal->Side() == 0) {
126  fRawEvents[0]->SetPETimes(signal->GetPETimes());
127  fRawEvents[0]->SetPEAmps(signal->GetPEAmps());
128  fRawEvents[0]->SetEvent(fEvent);
129  }
130  if(signal->Side() == 1) {
131  fRawEvents[1]->SetPETimes(signal->GetPETimes());
132  fRawEvents[1]->SetPEAmps(signal->GetPEAmps());
133  fRawEvents[1]->SetEvent(fEvent);
134  }
135  }
136 }// pixelsignal entries
137 //----------------------------------------------------------------------------
138 
139 
140  // for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
141  // //ERNeuRadPixelSignal* signal = (ERNeuRadPixelSignal*)fPixelSignals->At(iChanel);
142  // TArrayF* result = fPixelSignals->ResultSignal();
143  // for(Int_t nPoint = 0; nPoint< fNPoints; nPoint++){
144  // fRawEvents[iChanel]->SetAmp(result->GetAt(nPoint), nPoint); //fill the RawEvent
145  // fRawEvents[iChanel]->SetTime(nPoint*0.1, nPoint);
146  // }
147  // }
148 
149 //----------------------------------------------------------------------------
virtual void Exec(Option_t *opt)
Definition: ERSimtoRaw.cxx:75
virtual InitStatus Init()
Definition: ERSimtoRaw.cxx:48
class for raw data obtained from measurements or simulations