source: JEM-EUSO/esaf_lal/tags/v1_r0/esaf/packages/simulation/detector/electronics/src/CCB_LTTTrigger.cc @ 117

Last change on this file since 117 was 117, checked in by moretto, 11 years ago

ESAF version compilable on mac OS

File size: 10.4 KB
Line 
1// $Id$
2// Author: fenu   2007/12/05
3
4/*****************************************************************************
5 * ESAF: Euso Simulation and Analysis Framework                              *
6 *                                                                           *
7 *  Id: CCB_LTTTrigger                                                           *
8 *  Package: <packagename>                                                   *
9 *  Coordinator: <coordinator>                                               *
10 *                                                                           *
11 *****************************************************************************/
12
13//_____________________________________________________________________________
14//
15// CCB_LTTTrigger
16//
17// <extensive class description>
18//
19//   Config file parameters
20//   ======================
21//
22//   <parameter name>: <parameter description>
23//   -Valid options: <available options>
24// WORKS JUST IF THE ENTIRE MC IS SIMULATED FOR INCOMING SIGNAL
25// WORKS JUST IF PLUGGED TO A PREVIOUS TRIGGER (LTT or PTT)
26/*
27 Works exactly like the LTT but:
28 *on much longer tracks
29 *on more directions
30 *ALWAYS starting from the previous triggers
31
32 How the initial condition is chosen:
33 *select the pixel triggering in the previous trigger
34 *select the box 3X3 around this pixel
35 *select all the GTUs from -7 to +7
36 *start the integration from every pixel inside the box for every GTU which we consider.
37 (we have  3X3X15=135 starting conditions)
38
39
40 CCB_LTT inherits all the methods and attributes from LTT trigger except Simulate function.
41 Look to LTTTrigger.cc to see how all the other methods are.
42
43 */
44
45//
46#include "CCB_LTTTrigger.hh"
47#include "MacroCellData.hh"
48#include "MacroCell.hh"
49#include "ERunParameters.hh"
50#include "NumbersFileParser.hh"
51#include "ECCB_LTTTriggerDataAdder.hh"
52#include "CCB_LTTTriggerSegment.hh"
53#include "EEvent.hh"
54#include "EHeader.hh"
55#include <cmath>
56
57using namespace sou;
58ClassImp(CCB_LTTTrigger)
59
60//_____________________________________________________________________________
61CCB_LTTTrigger::CCB_LTTTrigger() : LTTTrigger(string ("CCB_LTTTrigger"), kCCB_LTTTrigger){
62  //
63  // Constructor
64  //
65
66  fYellowThreshold = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fYellowThreshold");
67  fIntegrateSum = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fIntegrateSum");
68  flag_EC = (Int_t) Conf()->GetNum("CCB_LTTTrigger.EC_PDM");
69
70  //read and calculate path of the box on the chip
71  // starting from the directions given as input
72  fDataDirectory = Conf()->GetStr("CCB_LTTTrigger.fDataDirectory");
73  fDirectionFileName = Conf()->GetStr("CCB_LTTTrigger.fDirectionFileName");
74  fDirectionFileName = fDataDirectory + "/" + fDirectionFileName;
75  fDirectionFileName = Conf()->GetCfgDir() + "/" + Conf()->GetType() + "/"
76      + fDirectionFileName;
77  Flag_debug_table = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fDebug");
78
79  fPixel_size = (Float_t) Conf()->GetNum("CCB_LTTTrigger.fPixel_size");
80  fGtuLight = (Float_t) Conf()->GetNum("CCB_LTTTrigger.fGtu_light");
81
82  fNum_Dir = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fNum_Dir");
83
84  fNum_Steps = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fNum_Steps");
85
86  fInputTrigger = (Float_t) Conf()->GetNum("CCB_LTTTrigger.fInputTrigger");
87
88  ConfigFileParser* pConf = Config::Get()->GetCF("Electronics", "MacroCell");
89  fGTU = pConf->GetNum("MacroCell.fGtuTimeLength");
90//   fGTU/=1000.;
91  fGTU /= microsecond;
92
93  pConf = Config::Get()->GetCF("Electronics", "EusoElectronics");
94  fBack = pConf->GetNum("EusoElectronics.fNightGlowRateOnAxis");
95
96  NumbersFileParser *dummy2 = new NumbersFileParser(fDirectionFileName, 2);
97
98  for (Int_t j(0); j < fNum_Dir; j++) {
99    vector<Double_t> dummy2_line = dummy2->GetRow(j);
100
101    for (size_t k(0); k < dummy2_line.size(); k++) {
102      angle.push_back(dummy2_line[k]);
103    }
104    dummy2_line.clear();
105  }
106  Calculate_Directions();
107
108  angle.clear();
109}
110
111//_____________________________________________________________________________
112CCB_LTTTrigger::~CCB_LTTTrigger() {
113  //
114  // Destructor
115  //
116
117  cout << "Destroy " << endl;
118  Clear();
119}
120
121//______________________________________________________________________________
122void CCB_LTTTrigger::Simulate(MacroCellData* pData) {
123  //
124  // Simulate CCB_LTT algorithm
125
126  if(fInputTrigger != 1 && fInputTrigger != 2)
127    Msg(EsafMsg::Panic) << "Wrong input for CCB trigger. Choose 1 (PTT) or 2 (LTT) as first level trigger!!! " << MsgDispatch;
128 
129  if ((pData->GetLTTTrigger() > -100 && fInputTrigger == 2)
130      || (pData->GetPTTTrigger() > -100 && fInputTrigger == 1)) {
131    Msg(EsafMsg::Info) << "CCB LTT algorithm (Third level) starting..."
132        << MsgDispatch;
133    Int_t posit_row, posit_col, flag_inside, chip_id_local, row_second,
134        col_second, chip_ID, max_gtu, max_counts, PdmID;
135    Int_t matsize = pData->Cell()->GetEC(0)->FrontEnd()->Channels();
136    Int_t side_EC = sqrt(matsize);
137    Int_t side_PMT = side_EC / 2;
138    if (fInputTrigger == 2) {
139      Msg(EsafMsg::Info) << "Output from LTT trigger is used" << MsgDispatch;
140      row_second = pData->GetLTTTriggerMaxRow();
141      col_second = pData->GetLTTTriggerMaxCol();
142      chip_ID = pData->GetLTTTriggerChipID();
143      max_gtu = pData->GetLTTTriggerMaxGtu();
144      max_counts = pData->GetLTTTriggerMaxCounts();
145      PdmID = pData->GetLTTTriggerPdmID();
146    }
147    if (fInputTrigger == 1) {
148      Msg(EsafMsg::Info) << "Output from PTT trigger is used" << MsgDispatch;
149      row_second = pData->GetPTTTriggerMaxRow();
150      col_second = pData->GetPTTTriggerMaxCol();
151      chip_ID = pData->GetPTTTriggerChipID();
152      max_gtu = pData->GetPTTTriggerMaxGtu();
153      max_counts = pData->GetPTTTriggerMaxCounts();
154      PdmID = pData->GetPTTTriggerPdmID();
155    }
156
157
158    // get map of ChipGtuData elements
159    map<Int_t, map<Int_t, ChipGtuData*>*> &m1 = pData->fChipData2;
160    map<Int_t, ChipGtuData*> &m2 = *m1[chip_ID];
161    map<Int_t, ChipGtuData*> &m3 = *m1[chip_ID + 3];
162    map<Int_t, ChipGtuData*> &m4 = *m1[chip_ID - 3];
163    map<Int_t, ChipGtuData*> &m5 = *m1[chip_ID - 1];
164    map<Int_t, ChipGtuData*> &m6 = *m1[chip_ID + 1];
165    map<Int_t, ChipGtuData*> m_aux;
166
167    Double_t divide = (chip_ID - 1) / 9.;
168    Double_t num_PDM_DOUB;
169    Double_t rest = modf(divide, &num_PDM_DOUB);
170    rest *= 9;
171    Double_t integ;
172
173    Double_t funz = round(1.e10 * rest / 3.) * 1.e-10;
174    //round at the 10th digit. Otherwise rounding problems arise
175    // for example: modf (1.9999999999999998,&int) is different from
176    //  modf (1.9999999999999999,&int)
177    // why?
178
179    rest = funz;
180    Double_t rest2 = modf(rest, &integ);
181
182    Int_t row_PDM = integ;
183    Int_t col_PDM = rest2 * 3.;
184//    Int_t ec_num=num_PDM_DOUB;
185
186    //function for initial table
187    for (Int_t off_row = -1; off_row < 2; off_row++) {
188      for (Int_t off_col = -1; off_col < 2; off_col++) {
189        for (Int_t off_gtu = -7; off_gtu < 8; off_gtu++) {
190          flag_inside = 0;
191          CorrectTransformation(row_second, col_second, off_row, off_col,
192              &posit_row, &posit_col, &flag_inside, side_PMT, side_EC);
193
194          if (flag_inside == 1) {
195            chip_id_local = chip_ID;
196            m_aux = m2;
197          } else if (flag_inside == 2 && row_PDM < 2) {
198            chip_id_local = chip_ID + 3;
199            m_aux = m3;
200          } else if (flag_inside == 3 && row_PDM > 0) {
201            chip_id_local = chip_ID - 3;
202            m_aux = m4;
203          } else if (flag_inside == 4 && col_PDM > 0) {
204            chip_id_local = chip_ID - 1;
205            m_aux = m5;
206          } else if (flag_inside == 5 && row_PDM < 2) {
207            chip_id_local = chip_ID + 1;
208            m_aux = m6;
209          }
210
211          if (flag_inside > 0 && flag_inside < 6) {
212            if (m_aux.begin()->first < off_gtu + max_gtu
213               && m_aux.rbegin()->first  > off_gtu + max_gtu) {
214              pos_PDM_map.push_back(PDM_Map.size());
215              PDM_Map.push_back(chip_ID);
216              PDM_Map.push_back(posit_row);
217              PDM_Map.push_back(posit_col);
218              PDM_Map.push_back(off_gtu + max_gtu); // In which gtu this event is
219              PDM_Map.push_back(PdmID);
220            } 
221          }
222        }
223      }
224    }
225    // call integration method//////////////////////////////////////////////////////////////////////////
226
227    integrate(PDM_Map,pos_PDM_map,pData,side_PMT,side_EC);
228    vector <Float_t> return_val;//save data for reconstruction
229    return_val=GetVariabile();
230    if(return_val[0]==1){
231      SetTrigger(CCB_LTTTrigger::GetTriggerWord());
232      SetGtuTriggerCCB(return_val[2]);
233      FillChipData(EEvent::GetCurrent()->GetHeader()->GetNum(),return_val[1],return_val[2],return_val[3],return_val[4],return_val[5],return_val[6],return_val[7],pData);
234    }
235
236    m_aux.clear();
237    //Clear vectors.
238    Clear();
239  } else {
240    if (fInputTrigger == 1)
241      Msg(EsafMsg::Info)
242          << "PTT trigger at the previous stage was not triggering"
243          << MsgDispatch;
244    if (fInputTrigger == 2)
245      Msg(EsafMsg::Info)
246          << "LTT trigger at the previous stage  was not triggering"
247          << MsgDispatch;
248  }
249
250}
251
252//______________________________________________________________________________
253void CCB_LTTTrigger::Clear() {
254//clear/////////////////////////////////////////////////////////////////////////////////////
255  PDM_Map.clear();
256  pos_PDM_map.clear();
257
258}
259
260void CCB_LTTTrigger::FillInfoVector(Int_t up_counts, Int_t GTU_up, Int_t row_up,
261    Int_t col_up, Int_t chip_ID_up, Int_t dir_up, Int_t PdmID,
262    Int_t Triggering) {
263
264  fTracks.push_back(CCB_LTTTriggerSegment());
265  CCB_LTTTriggerSegment &trkseg = fTracks.back();
266  trkseg.SetNumEvt(EEvent::GetCurrent()->GetHeader()->GetNum());
267  trkseg.SetMaxCount(up_counts);
268  trkseg.SetMaxGtu(GTU_up);
269  trkseg.SetMaxRow(row_up);
270  trkseg.SetMaxCol(col_up);
271  trkseg.SetMaxChipID(chip_ID_up);
272  trkseg.SetMaxDir(dir_up);
273  trkseg.SetPdmID(PdmID);
274
275  vector<CCB_LTTTriggerSegment>::iterator it;
276
277  for (it = fTracks.begin(); it != fTracks.end(); it++) {
278
279    if (EEvent::GetCurrent()) {
280
281      ECCB_LTTTriggerDataAdder a(&(*it), Triggering, 1);
282      EEvent::GetCurrent()->Fill(a);
283    }
284
285  }
286  fTracks.clear();
287
288}
289
290void CCB_LTTTrigger::FillChipData(Int_t evtNum, Int_t up_counts, Int_t GTU_up,
291    Int_t row_up, Int_t col_up, Int_t chip_ID_up, Int_t dir_up, Int_t PdmID,
292    MacroCellData* pData) {
293  pData->SetCCB_LTTTrigger(evtNum);
294  pData->SetCCB_LTTTriggerMaxCounts(up_counts);
295  pData->SetCCB_LTTTriggerMaxGtu(GTU_up);
296  pData->SetCCB_LTTTriggerMaxRow(row_up);
297  pData->SetCCB_LTTTriggerMaxCol(col_up);
298  pData->SetCCB_LTTTriggerChipID(chip_ID_up);
299  pData->SetCCB_LTTTriggerMaxDir(dir_up);
300  pData->SetCCB_LTTTriggerPdmID(PdmID);
301}
302
Note: See TracBrowser for help on using the repository browser.