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 | |
---|
56 | using namespace sou; |
---|
57 | ClassImp(CCB_LTTTrigger) |
---|
58 | |
---|
59 | //_____________________________________________________________________________ |
---|
60 | CCB_LTTTrigger::CCB_LTTTrigger() : LTTTrigger(string ("CCB_LTTTrigger"), kCCB_LTTTrigger){ |
---|
61 | // |
---|
62 | // Constructor |
---|
63 | // |
---|
64 | |
---|
65 | fYellowThreshold = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fYellowThreshold"); |
---|
66 | fIntegrateSum = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fIntegrateSum"); |
---|
67 | flag_EC = (Int_t) Conf()->GetNum("CCB_LTTTrigger.EC_PDM"); |
---|
68 | |
---|
69 | //read and calculate path of the box on the chip |
---|
70 | // starting from the directions given as input |
---|
71 | fDataDirectory = Conf()->GetStr("CCB_LTTTrigger.fDataDirectory"); |
---|
72 | fDirectionFileName = Conf()->GetStr("CCB_LTTTrigger.fDirectionFileName"); |
---|
73 | fDirectionFileName = fDataDirectory + "/" + fDirectionFileName; |
---|
74 | fDirectionFileName = Conf()->GetCfgDir() + "/" + Conf()->GetType() + "/" |
---|
75 | + fDirectionFileName; |
---|
76 | Flag_debug_table = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fDebug"); |
---|
77 | |
---|
78 | fPixel_size = (Float_t) Conf()->GetNum("CCB_LTTTrigger.fPixel_size"); |
---|
79 | fGtuLight = (Float_t) Conf()->GetNum("CCB_LTTTrigger.fGtu_light"); |
---|
80 | |
---|
81 | fNum_Dir = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fNum_Dir"); |
---|
82 | |
---|
83 | fNum_Steps = (Int_t) Conf()->GetNum("CCB_LTTTrigger.fNum_Steps"); |
---|
84 | |
---|
85 | fInputTrigger = (Float_t) Conf()->GetNum("CCB_LTTTrigger.fInputTrigger"); |
---|
86 | |
---|
87 | ConfigFileParser* pConf = Config::Get()->GetCF("Electronics", "MacroCell"); |
---|
88 | fGTU = pConf->GetNum("MacroCell.fGtuTimeLength"); |
---|
89 | // fGTU/=1000.; |
---|
90 | fGTU /= microsecond; |
---|
91 | |
---|
92 | pConf = Config::Get()->GetCF("Electronics", "EusoElectronics"); |
---|
93 | fBack = pConf->GetNum("EusoElectronics.fNightGlowRateOnAxis"); |
---|
94 | |
---|
95 | NumbersFileParser *dummy2 = new NumbersFileParser(fDirectionFileName, 2); |
---|
96 | |
---|
97 | for (Int_t j(0); j < fNum_Dir; j++) { |
---|
98 | vector<Double_t> dummy2_line = dummy2->GetRow(j); |
---|
99 | |
---|
100 | for (size_t k(0); k < dummy2_line.size(); k++) { |
---|
101 | angle.push_back(dummy2_line[k]); |
---|
102 | } |
---|
103 | dummy2_line.clear(); |
---|
104 | } |
---|
105 | Calculate_Directions(); |
---|
106 | |
---|
107 | angle.clear(); |
---|
108 | } |
---|
109 | |
---|
110 | //_____________________________________________________________________________ |
---|
111 | CCB_LTTTrigger::~CCB_LTTTrigger() { |
---|
112 | // |
---|
113 | // Destructor |
---|
114 | // |
---|
115 | |
---|
116 | cout << "Destroy " << endl; |
---|
117 | Clear(); |
---|
118 | } |
---|
119 | |
---|
120 | //______________________________________________________________________________ |
---|
121 | void CCB_LTTTrigger::Simulate(MacroCellData* pData) { |
---|
122 | // |
---|
123 | // Simulate CCB_LTT algorithm |
---|
124 | |
---|
125 | if(fInputTrigger != 1 && fInputTrigger != 2) |
---|
126 | Msg(EsafMsg::Panic) << "Wrong input for CCB trigger. Choose 1 (PTT) or 2 (LTT) as first level trigger!!! " << MsgDispatch; |
---|
127 | |
---|
128 | if ((pData->GetLTTTrigger() > -100 && fInputTrigger == 2) |
---|
129 | || (pData->GetPTTTrigger() > -100 && fInputTrigger == 1)) { |
---|
130 | Msg(EsafMsg::Info) << "CCB LTT algorithm (Third level) starting..." |
---|
131 | << MsgDispatch; |
---|
132 | Int_t posit_row, posit_col, flag_inside, chip_id_local, row_second, |
---|
133 | col_second, chip_ID, max_gtu, max_counts, PdmID; |
---|
134 | Int_t matsize = pData->Cell()->GetEC(0)->FrontEnd()->Channels(); |
---|
135 | Int_t side_EC = sqrt(matsize); |
---|
136 | Int_t side_PMT = side_EC / 2; |
---|
137 | if (fInputTrigger == 2) { |
---|
138 | Msg(EsafMsg::Info) << "Output from LTT trigger is used" << MsgDispatch; |
---|
139 | row_second = pData->GetLTTTriggerMaxRow(); |
---|
140 | col_second = pData->GetLTTTriggerMaxCol(); |
---|
141 | chip_ID = pData->GetLTTTriggerChipID(); |
---|
142 | max_gtu = pData->GetLTTTriggerMaxGtu(); |
---|
143 | max_counts = pData->GetLTTTriggerMaxCounts(); |
---|
144 | PdmID = pData->GetLTTTriggerPdmID(); |
---|
145 | } |
---|
146 | if (fInputTrigger == 1) { |
---|
147 | Msg(EsafMsg::Info) << "Output from PTT trigger is used" << MsgDispatch; |
---|
148 | row_second = pData->GetPTTTriggerMaxRow(); |
---|
149 | col_second = pData->GetPTTTriggerMaxCol(); |
---|
150 | chip_ID = pData->GetPTTTriggerChipID(); |
---|
151 | max_gtu = pData->GetPTTTriggerMaxGtu(); |
---|
152 | max_counts = pData->GetPTTTriggerMaxCounts(); |
---|
153 | PdmID = pData->GetPTTTriggerPdmID(); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | // get map of ChipGtuData elements |
---|
158 | map<Int_t, map<Int_t, ChipGtuData*>*> &m1 = pData->fChipData2; |
---|
159 | map<Int_t, ChipGtuData*> &m2 = *m1[chip_ID]; |
---|
160 | map<Int_t, ChipGtuData*> &m3 = *m1[chip_ID + 3]; |
---|
161 | map<Int_t, ChipGtuData*> &m4 = *m1[chip_ID - 3]; |
---|
162 | map<Int_t, ChipGtuData*> &m5 = *m1[chip_ID - 1]; |
---|
163 | map<Int_t, ChipGtuData*> &m6 = *m1[chip_ID + 1]; |
---|
164 | map<Int_t, ChipGtuData*> m_aux; |
---|
165 | |
---|
166 | Double_t divide = (chip_ID - 1) / 9.; |
---|
167 | Double_t num_PDM_DOUB; |
---|
168 | Double_t rest = modf(divide, &num_PDM_DOUB); |
---|
169 | rest *= 9; |
---|
170 | Double_t integ; |
---|
171 | |
---|
172 | Double_t funz = round(1.e10 * rest / 3.) * 1.e-10; |
---|
173 | //round at the 10th digit. Otherwise rounding problems arise |
---|
174 | // for example: modf (1.9999999999999998,&int) is different from |
---|
175 | // modf (1.9999999999999999,&int) |
---|
176 | // why? |
---|
177 | |
---|
178 | rest = funz; |
---|
179 | Double_t rest2 = modf(rest, &integ); |
---|
180 | |
---|
181 | Int_t row_PDM = integ; |
---|
182 | Int_t col_PDM = rest2 * 3.; |
---|
183 | // Int_t ec_num=num_PDM_DOUB; |
---|
184 | |
---|
185 | //function for initial table |
---|
186 | for (Int_t off_row = -1; off_row < 2; off_row++) { |
---|
187 | for (Int_t off_col = -1; off_col < 2; off_col++) { |
---|
188 | for (Int_t off_gtu = -7; off_gtu < 8; off_gtu++) { |
---|
189 | flag_inside = 0; |
---|
190 | CorrectTransformation(row_second, col_second, off_row, off_col, |
---|
191 | &posit_row, &posit_col, &flag_inside, side_PMT, side_EC); |
---|
192 | |
---|
193 | if (flag_inside == 1) { |
---|
194 | chip_id_local = chip_ID; |
---|
195 | m_aux = m2; |
---|
196 | } else if (flag_inside == 2 && row_PDM < 2) { |
---|
197 | chip_id_local = chip_ID + 3; |
---|
198 | m_aux = m3; |
---|
199 | } else if (flag_inside == 3 && row_PDM > 0) { |
---|
200 | chip_id_local = chip_ID - 3; |
---|
201 | m_aux = m4; |
---|
202 | } else if (flag_inside == 4 && col_PDM > 0) { |
---|
203 | chip_id_local = chip_ID - 1; |
---|
204 | m_aux = m5; |
---|
205 | } else if (flag_inside == 5 && row_PDM < 2) { |
---|
206 | chip_id_local = chip_ID + 1; |
---|
207 | m_aux = m6; |
---|
208 | } |
---|
209 | |
---|
210 | if (flag_inside > 0 && flag_inside < 6) { |
---|
211 | if (m_aux.begin()->first < off_gtu + max_gtu |
---|
212 | && m_aux.rbegin()->first > off_gtu + max_gtu) { |
---|
213 | pos_PDM_map.push_back(PDM_Map.size()); |
---|
214 | PDM_Map.push_back(chip_ID); |
---|
215 | PDM_Map.push_back(posit_row); |
---|
216 | PDM_Map.push_back(posit_col); |
---|
217 | PDM_Map.push_back(off_gtu + max_gtu); // In which gtu this event is |
---|
218 | PDM_Map.push_back(PdmID); |
---|
219 | } |
---|
220 | } |
---|
221 | } |
---|
222 | } |
---|
223 | } |
---|
224 | // call integration method////////////////////////////////////////////////////////////////////////// |
---|
225 | |
---|
226 | integrate(PDM_Map,pos_PDM_map,pData,side_PMT,side_EC); |
---|
227 | vector <Float_t> return_val;//save data for reconstruction |
---|
228 | return_val=GetVariabile(); |
---|
229 | if(return_val[0]==1){ |
---|
230 | SetTrigger(CCB_LTTTrigger::GetTriggerWord()); |
---|
231 | SetGtuTriggerCCB(return_val[2]); |
---|
232 | 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); |
---|
233 | } |
---|
234 | |
---|
235 | m_aux.clear(); |
---|
236 | //Clear vectors. |
---|
237 | Clear(); |
---|
238 | } else { |
---|
239 | if (fInputTrigger == 1) |
---|
240 | Msg(EsafMsg::Info) |
---|
241 | << "PTT trigger at the previous stage was not triggering" |
---|
242 | << MsgDispatch; |
---|
243 | if (fInputTrigger == 2) |
---|
244 | Msg(EsafMsg::Info) |
---|
245 | << "LTT trigger at the previous stage was not triggering" |
---|
246 | << MsgDispatch; |
---|
247 | } |
---|
248 | |
---|
249 | } |
---|
250 | |
---|
251 | //______________________________________________________________________________ |
---|
252 | void CCB_LTTTrigger::Clear() { |
---|
253 | //clear///////////////////////////////////////////////////////////////////////////////////// |
---|
254 | PDM_Map.clear(); |
---|
255 | pos_PDM_map.clear(); |
---|
256 | |
---|
257 | } |
---|
258 | |
---|
259 | void CCB_LTTTrigger::FillInfoVector(Int_t up_counts, Int_t GTU_up, Int_t row_up, |
---|
260 | Int_t col_up, Int_t chip_ID_up, Int_t dir_up, Int_t PdmID, |
---|
261 | Int_t Triggering) { |
---|
262 | |
---|
263 | fTracks.push_back(CCB_LTTTriggerSegment()); |
---|
264 | CCB_LTTTriggerSegment &trkseg = fTracks.back(); |
---|
265 | trkseg.SetNumEvt(EEvent::GetCurrent()->GetHeader()->GetNum()); |
---|
266 | trkseg.SetMaxCount(up_counts); |
---|
267 | trkseg.SetMaxGtu(GTU_up); |
---|
268 | trkseg.SetMaxRow(row_up); |
---|
269 | trkseg.SetMaxCol(col_up); |
---|
270 | trkseg.SetMaxChipID(chip_ID_up); |
---|
271 | trkseg.SetMaxDir(dir_up); |
---|
272 | trkseg.SetPdmID(PdmID); |
---|
273 | |
---|
274 | vector<CCB_LTTTriggerSegment>::iterator it; |
---|
275 | |
---|
276 | for (it = fTracks.begin(); it != fTracks.end(); it++) { |
---|
277 | |
---|
278 | if (EEvent::GetCurrent()) { |
---|
279 | |
---|
280 | ECCB_LTTTriggerDataAdder a(&(*it), Triggering, 1); |
---|
281 | EEvent::GetCurrent()->Fill(a); |
---|
282 | } |
---|
283 | |
---|
284 | } |
---|
285 | fTracks.clear(); |
---|
286 | |
---|
287 | } |
---|
288 | |
---|
289 | void CCB_LTTTrigger::FillChipData(Int_t evtNum, Int_t up_counts, Int_t GTU_up, |
---|
290 | Int_t row_up, Int_t col_up, Int_t chip_ID_up, Int_t dir_up, Int_t PdmID, |
---|
291 | MacroCellData* pData) { |
---|
292 | pData->SetCCB_LTTTrigger(evtNum); |
---|
293 | pData->SetCCB_LTTTriggerMaxCounts(up_counts); |
---|
294 | pData->SetCCB_LTTTriggerMaxGtu(GTU_up); |
---|
295 | pData->SetCCB_LTTTriggerMaxRow(row_up); |
---|
296 | pData->SetCCB_LTTTriggerMaxCol(col_up); |
---|
297 | pData->SetCCB_LTTTriggerChipID(chip_ID_up); |
---|
298 | pData->SetCCB_LTTTriggerMaxDir(dir_up); |
---|
299 | pData->SetCCB_LTTTriggerPdmID(PdmID); |
---|
300 | } |
---|
301 | |
---|