CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
ReadCosmicRayData.cxx
Go to the documentation of this file.
1/**************************************************************************
2 * CgemBOSS (BESIII Offline Software System) *
3 * *
4 * Author: The BESII Collaboration *
5 * Contributors: Aiqiang Guo, Liangliang Wang, Lia Lavezzi *
6 * Date: Dec 10 2018 *
7 * *
8 **************************************************************************/
9/**************************************************************************
10 * Note for 01
11 * Change the reading method for vectorized data
12 * By: Aiqiang Guo
13 * Date: Dec 17 2018
14 **************************************************************************/
15/**************************************************************************
16 * Note for 02
17 * Add CC and mTPC for cluster object
18 * By: Aiqiang Guo
19 * Date: Dec 27 2018
20 **************************************************************************/
21
22// include system lib
23#include <iostream>
24#include <iomanip>
25#include <string>
26#include <cmath>
27
28// Include files
29#include "GaudiKernel/AlgFactory.h"
30#include "GaudiKernel/DataObject.h"
31#include "GaudiKernel/IEventProcessor.h"
32
33#include "GaudiKernel/Incident.h"
34#include "GaudiKernel/IIncidentSvc.h"
35#include "GaudiKernel/Memory.h"
36
37#include <csignal>
38
39// for save digit & cluster
40#include "GaudiKernel/ISvcLocator.h"
41#include "GaudiKernel/IDataProviderSvc.h"
42#include "GaudiKernel/Bootstrap.h"
43#include "GaudiKernel/RegistryEntry.h"
44#include "GaudiKernel/MsgStream.h"
45
48
49#include "Identifier/CgemID.h"
50
52#include "RawEvent/DigiEvent.h"
55#include "GaudiKernel/SmartDataPtr.h"
56
58
59//using namespace std;
60ReadCosmicRayData::ReadCosmicRayData(const std::string& name, ISvcLocator* pSvcLocator):
61 Algorithm(name,pSvcLocator){
62
63 declareProperty("Dir_file", Dir_file = "input_file.txt");
64 declareProperty("TreeDigi", TreeDigi = "t1");
65 declareProperty("TreeCluster", TreeCluster = "t1");
66 declareProperty("ReadDigi", ReadDigi = true);
67 declareProperty("ReadCluster", ReadCluster = true);
68 declareProperty("DigiSheetID", DigiSheetID = 0);
69 declareProperty("Cut_on_tpc", Cut_on_tpc = false);
70 declareProperty("ClusterSheetID", ClusterSheetID = 0);
71 declareProperty("ClusterRecZ", ClusterRecZ = 0);
72 declareProperty("R_Cluster", R_Cluster = 1.0);
73 declareProperty("Shift_DigitLayerID", Shift_DigitLayerID = 0);
74 declareProperty("Shift_DigitSheetID", Shift_DigitSheetID = 0);
75 declareProperty("Shift_DigitXStripID", Shift_DigitXStripID = 0);
76 declareProperty("Shift_DigitVStripID", Shift_DigitVStripID = 0);
77 declareProperty("Shift_ClusterLayerID", Shift_ClusterLayerID = 0);
78 declareProperty("Shift_ClusterSheetID", Shift_ClusterSheetID = 0);
79 declareProperty("Shift_RecPhi", Shift_RecPhi = 0);
80 declareProperty("Shift_RecV", Shift_RecV = 0);
81 declareProperty("Shift_RecZ", Shift_RecZ = 0);
82 declareProperty("CosmicRayDataSetID", CosmicRayDataSetID = "CR201909");
83 declareProperty("runNo", m_runNo = 1);
84
85 // mapper = new StripMapper(CosmicRayDataSetID);
86}
87
90
92 MsgStream log(msgSvc(), name());
93 log << MSG::INFO << "ReadCosmicRayData initialize()" << endreq;
94
95 // bool ismap = mapper->FillMap();
96
97 TString TDir_file(Dir_file);
98 if(ReadDigi)
99 {
100 TString TTreeDigi(TreeDigi);
101 Tdigi = new TChain(TTreeDigi);
102 TFileCollection* fc = new TFileCollection("mylist", "mylist",TDir_file);
103 Tdigi->AddFileInfoList((TCollection*)fc->GetList());
104
105 // Get Cgem digi tree
106 Tdigi->SetBranchAddress("Event", &m_Event_D); // event ID
107 Tdigi->SetBranchAddress("nGemHit", &m_nGemHit); // nof GEM hits
108 // Tdigi->SetBranchAddress("GemHit_nHit", &m_nGemHit); // nof GEM hits it is the same thing as before
109
110 // information on the IDs
111 Tdigi->SetBranchAddress("GemHit_channel", m_channel); // channel no. [0, 63]
112 Tdigi->SetBranchAddress("GemHit_ROC", m_ROC); // ROC no.
113 Tdigi->SetBranchAddress("GemHit_chip", m_chip); // chip no.
114 Tdigi->SetBranchAddress("GemHit_FEB", m_FEB); // FEB no.
115 Tdigi->SetBranchAddress("GemHit_plane", m_plane); // plane
116 Tdigi->SetBranchAddress("GemHit_sheet", m_sheet); // sheet
117 Tdigi->SetBranchAddress("GemHit_view", m_view); // view (axial or stereo strips)
118 Tdigi->SetBranchAddress("GemHit_strip", m_strip); // strip no.
119
120 // physical information
121 Tdigi->SetBranchAddress("GemHit_saturated", m_saturated); // is the ASIC channel saturated
122 Tdigi->SetBranchAddress("GemHit_q", m_charge); // charge (fC)
123 Tdigi->SetBranchAddress("GemHit_time", m_time); // time (ns)
124 // Tdigi->SetBranchAddress("GemHit_is_tpc", m_GemHit_is_tpc);
125
126 No_Entries_D = Tdigi->GetEntries();
127 cout<<"total Entry is "<<No_Entries_D<<endl;
128 Ind_Entry_D = 0;
129 //Ind_Entry_D = 23790; //Ind_Entry_D = 30200;
130 }
131
132 /**
133 if(ReadCluster)
134 {
135 //Get Cgem cluster tree
136 TString TTreeCluster(TreeCluster);
137 Tcluster = (TTree*)f->Get(TTreeCluster);
138
139 Tcluster->SetBranchAddress("Event", &m_Event_C);
140 Tcluster->SetBranchAddress("GemCluster1d_nCluster", &m_nGemCluster);
141 Tcluster->SetBranchAddress("GemCluster1d_nHit", m_ClusternHit);
142 Tcluster->SetBranchAddress("GemCluster1d_HitIndex", m_ClusterHitIndex);
143 Tcluster->SetBranchAddress("GemCluster1d_plane", m_ClusterLayerID);
144 Tcluster->SetBranchAddress("GemCluster1d_view", m_Flag);
145 Tcluster->SetBranchAddress("GemCluster1d_q", m_EnergyDeposit);
146 Tcluster->SetBranchAddress("GemCluster1d_x", m_Cluster_x);
147 Tcluster->SetBranchAddress("GemCluster1d_z", m_Cluster_z);
148 Tcluster->SetBranchAddress("GemCluster1d_x_cc", m_Cluster_x_cc);
149 Tcluster->SetBranchAddress("GemCluster1d_x_tpc", m_Cluster_x_tpc);
150 Tcluster->SetBranchAddress("GemCluster1d_z_cc", m_Cluster_z_cc);
151 Tcluster->SetBranchAddress("GemCluster1d_z_tpc", m_Cluster_z_tpc);
152 //Tcluster->SetBranchAddress("ClusterSheetID", m_ClusterSheetID);
153 //Tcluster->SetBranchAddress("ClusterFlagB", m_ClusterFlagB);
154 //Tcluster->SetBranchAddress("ClusterFlagE", m_ClusterFlagE);
155 //Tcluster->SetBranchAddress("RecV", m_RecV);
156 //Tcluster->SetBranchAddress("RecZ", m_RecZ);
157
158 No_Entries_C = Tcluster->GetEntries();
159 Ind_Entry_C = 0;
160 }
161 **/
162 return StatusCode::SUCCESS;
163}
164
165
166int ReadCosmicRayData::TranslateDigitLayerID(int Input_LayerID)
167{
168 int ShiftValue = Shift_DigitLayerID;
169 return Input_LayerID+ShiftValue;
170}
171
172int ReadCosmicRayData::TranslateDigitSheetID(int Input_SheetID)
173{
174 int ShiftValue = Shift_DigitSheetID;
175 return Input_SheetID+ShiftValue;
176}
177
178int ReadCosmicRayData::TranslateDigitXStripID(int Input_StripID)
179{
180 int ShiftValue = Shift_DigitXStripID;
181 return Input_StripID+ShiftValue;
182}
183
184int ReadCosmicRayData::TranslateDigitVStripID(int Input_StripID)
185{
186 int ShiftValue = Shift_DigitVStripID;
187 return Input_StripID+ShiftValue;
188}
189
190int ReadCosmicRayData::TranslateDigitStripID(int Input_StripID, int StripType)
191{
192 int Output_StripID = -1;
193 if(StripType==0) Output_StripID = TranslateDigitXStripID(Input_StripID);
194 if(StripType==1) Output_StripID = TranslateDigitVStripID(Input_StripID);
195 return Output_StripID;
196}
197
198int ReadCosmicRayData::TranslateDigitStripType(int Input_StripType)
199{
200 return Input_StripType;
201}
202
203int ReadCosmicRayData::TranslateClusterLayerID(int Input_LayerID)
204{
205 int ShiftValue = Shift_ClusterLayerID;
206 return Input_LayerID+ShiftValue;
207}
208
209int ReadCosmicRayData::TranslateClusterSheetID(int Input_SheetID)
210{
211 int ShiftValue = Shift_ClusterSheetID;
212 return Input_SheetID+ShiftValue;
213}
214
215int ReadCosmicRayData::TranslateClusterFlag(int Input_Flag)
216{
217 return Input_Flag-2;
218}
219
220double ReadCosmicRayData::TranslateRecPhi(double Input_RecPhi)
221{
222 double ShiftValue = Shift_RecPhi;
223 return Input_RecPhi+ShiftValue;
224}
225
226double ReadCosmicRayData::TranslateRecV(double Input_RecV)
227{
228 double ShiftValue = Shift_RecV;
229 return Input_RecV+ShiftValue;
230}
231
232double ReadCosmicRayData::TranslateRecZ(double Input_RecZ)
233{
234 double ShiftValue = Shift_RecZ;
235 return Input_RecZ+ShiftValue;
236}
237
238void ReadCosmicRayData::ReadCgemDigits()
239{
240 //cout<<"Start to read the CgemDigits"<<endl;
241 //if(Ind_Entry_D>23790) cout<<"Evt "<<Ind_Entry_D<<": Start to read the CgemDigits"<<endl;
242 Tdigi->GetEntry(Ind_Entry_D);
243 //if(m_nGemHit>MAXNOFHITS) cout<<"m_nGemHit="<<m_nGemHit<<" > MAXNOFHITS = "<<MAXNOFHITS<<endl;
244 Ind_Entry_D++;
245}
246
247void ReadCosmicRayData::ReadCgemClusters()
248{
249 //cout<<"Start to read the CgemClusters"<<endl;
250 Tcluster->GetEntry(Ind_Entry_C);
251 Ind_Entry_C++;
252}
253
254bool ReadCosmicRayData::ConvertHitToDigi(int ihit, unsigned int &charge_channel, unsigned int &time_channel)
255{
256
257 if(CosmicRayDataSetID == "CR201909") {
258 // cout << "ReadCosmicRayData::ConvertGRAALToCgemBoss(), converting set " << CosmicRayDataSetID << endl;
259
260 // if(!m_GemHit_is_tpc[i]&&Cut_on_tpc) return false; // ??
261 charge_channel = 1;
262 time_channel = 1;
263
264 // from plane to LayerID
265 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0; // LAYER1
266 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1; // LAYER2
267 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1; // LAYER2
268 else {
269 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
270 return false;
271 }
272
273 // from view to StripType
274 if(m_view[ihit] == 2) m_StripType[ihit] = 0; // x strip (phi)
275 else if(m_view[ihit] == 3) m_StripType[ihit] = 1; // v strip (stereo)
276 else {
277 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
278 return false;
279 }
280
281 //cout<<"layer "<<m_LayerID[ihit]<<", StripType "<<m_StripType[ihit]<<", original strip id: "<< m_strip[ihit]<<endl;
282 // sheet ID/strip ID
283 if(m_LayerID[ihit] == 0) { // LAYER 1
284 m_SheetID[ihit] = 0; // LAYER 1
285 m_StripID[ihit] = m_strip[ihit]-1;// strip ID starts from 0
286 if(m_StripType[ihit] == 0 && (m_StripID[ihit]<0||m_StripID[ihit]>=CgemID::getXSTRIP_MAX(m_LayerID[ihit]))) cout<<"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer1, sheet "<<m_SheetID[ihit]<<" : "<<m_StripID[ihit]<<endl;
287 if(m_StripType[ihit] == 1 && (m_StripID[ihit]<0||m_StripID[ihit]>=CgemID::getVSTRIP_MAX(m_LayerID[ihit]))) cout<<"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer1, sheet "<<m_SheetID[ihit]<<" : "<<m_StripID[ihit]<<endl;
288 }
289 if(m_LayerID[ihit] == 1) { // LAYER 2
290 m_SheetID[ihit] = 0;
291 if(m_StripType[ihit] == 0) // X strip
292 {
293
294 // sheet down --> sheet 1
295 if(m_strip[ihit] > CgemID::getXSTRIP_MAX(m_LayerID[ihit]))
296 {
297 m_SheetID[ihit] = 0;
298 m_StripID[ihit] = 2*CgemID::getXSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];// strip ID starts from 0
299 }
300 else {
301 // sheet up --> sheet 2
302 m_StripID[ihit] = CgemID::getXSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];
303 m_SheetID[ihit] = 1;
304 }
305 if(m_StripID[ihit]<0||m_StripID[ihit]>=CgemID::getXSTRIP_MAX(m_LayerID[ihit])) cout<<"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<" : "<<m_StripID[ihit]<<endl;
306 }
307 else if(m_StripType[ihit] == 1)// V strip with correction for the wrong mapping at strip 538 and 1617 in integration
308 {
309 if(m_strip[ihit] == 539 || m_strip[ihit] == 1617) {
310 cout<<"ReadCosmicRayData::ConvertHitToDigi: unexpated firing strip"<<m_strip[ihit]<<endl;
311 return false;
312 }
313 else if(m_strip[ihit] < 539) {
314 // sheet up --> sheet 2
315 m_StripID[ihit] = CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];
316 m_SheetID[ihit] = 1;
317 }
318 else if(m_strip[ihit] < CgemID::getVSTRIP_MAX(m_LayerID[ihit]) + 2) {
319 // sheet up --> sheet 2
320 m_StripID[ihit] = CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit] + 1;
321 m_SheetID[ihit] = 1;
322 }
323 else if(m_strip[ihit] < 1617) {
324 // sheet down --> sheet 1
325 m_StripID[ihit] = 2*CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit] + 1;
326 m_SheetID[ihit] = 0;
327 }
328 else {
329 // sheet down --> sheet 1
330 m_StripID[ihit] = 2*CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit] + 2;
331 m_SheetID[ihit] = 0;
332 }
333 if(m_StripID[ihit]<0||m_StripID[ihit]>=CgemID::getVSTRIP_MAX(m_LayerID[ihit])) cout<<"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<" : "<<m_StripID[ihit]<<endl;
334 }
335 }
336 return true;
337 }
338 else if(CosmicRayDataSetID == "CR202001") {
339 // cout << "ReadCosmicRayData::ConvertGRAALToCgemBoss(), converting set " << CosmicRayDataSetID << endl;
340
341 // if(!m_GemHit_is_tpc[i]&&Cut_on_tpc) return false; // ??
342 charge_channel = 1;
343 time_channel = 1;
344
345 // from plane to LayerID
346 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0; // LAYER1
347 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1; // LAYER2
348 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1; // LAYER2
349 else {
350 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
351 return false;
352 }
353
354 // from view to StripType
355 if(m_view[ihit] == 2) m_StripType[ihit] = 0; // x strip (phi)
356 else if(m_view[ihit] == 3) m_StripType[ihit] = 1; // v strip (stereo)
357 else {
358 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
359 return false;
360 }
361
362 if(m_strip[ihit] < 0) return false;
363
364 // sheet ID/strip ID
365 m_SheetID[ihit] = 0;
366
367 if(m_StripType[ihit] == 0) // X strip
368 {
369 if(m_LayerID[ihit] == 0) { // LAYER 1
370 m_StripID[ihit] = CgemID::getXSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];
371 m_SheetID[ihit] = 0;
372 }
373 else if(m_LayerID[ihit] == 1) { // LAYER 2
374 // sheet down --> sheet 1
375 if(m_strip[ihit] > CgemID::getXSTRIP_MAX(m_LayerID[ihit]))
376 {
377 m_SheetID[ihit] = 0;
378 m_StripID[ihit] = 2*CgemID::getXSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];// strip ID starts from 0
379 }
380 else {
381 // sheet up --> sheet 2
382 m_StripID[ihit] = CgemID::getXSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];
383 m_SheetID[ihit] = 1;
384 }
385 }
386 if(m_StripID[ihit]<0||m_StripID[ihit]>=CgemID::getXSTRIP_MAX(m_LayerID[ihit])) cout<<"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<" : "<<m_StripID[ihit]<<endl;
387 }
388 else if(m_StripType[ihit] == 1)// V strip with correction for the wrong mapping at strip 538 and 1617 in integration
389 {
390 if(m_LayerID[ihit] == 0) { // LAYER 1
391 m_StripID[ihit] = CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];
392 m_SheetID[ihit] = 0;
393 }
394 else if(m_LayerID[ihit] == 1) { // LAYER 2
395 // sheet down --> sheet 1
396 if(m_strip[ihit] > CgemID::getVSTRIP_MAX(m_LayerID[ihit]))
397 {
398 m_SheetID[ihit] = 0;
399 m_StripID[ihit] = 2*CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];// strip ID starts from 0
400 }
401 else {
402 // sheet up --> sheet 2
403 m_StripID[ihit] = CgemID::getVSTRIP_MAX(m_LayerID[ihit]) - m_strip[ihit];
404 m_SheetID[ihit] = 1;
405 }
406 }
407 if(m_StripID[ihit]<0||m_StripID[ihit]>=CgemID::getVSTRIP_MAX(m_LayerID[ihit])) cout<<"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<" : "<<m_StripID[ihit]<<endl;
408 }
409
410 // cout << "GRAAL " << m_strip[ihit] << " view " << m_view[ihit] << " plane " << m_plane[ihit] << endl;
411 // cout << "CGEMB " << m_StripID[ihit] << " view " << m_StripType[ihit] << " plane " << m_LayerID[ihit] << " sheet " << m_SheetID[ihit] << endl;
412
413
414 return true;
415 }
416 else if(CosmicRayDataSetID == "NEW202001") {
417
418 charge_channel = 1;
419 time_channel = 1;
420
421 // from plane to LayerID
422 if(m_plane[ihit] != 0 && m_plane[ihit] != 1) {
423 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
424 return false;
425 }
426 else m_LayerID[ihit] = m_plane[ihit] ;
427
428 // from view to StripType
429 if(m_view[ihit] == 2) m_StripType[ihit] = 0; // x strip (phi)
430 else if(m_view[ihit] == 3) m_StripType[ihit] = 1; // v strip (stereo)
431 else {
432 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
433 return false;
434 }
435
436 if(m_strip[ihit] < 0) return false;
437
438 // sheet
439 m_SheetID[ihit] = m_sheet[ihit] ;
440
441 // strip
442 m_StripID[ihit] = m_strip[ihit];
443
444 // some checks
445 if(m_StripType[ihit] == 0 && m_StripID[ihit] > CgemID::getXSTRIP_MAX(m_LayerID[ihit])) {
446 cout<<"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer " << m_LayerID[ihit] << ", sheet " << m_SheetID[ihit] << ": " << m_StripID[ihit] << endl;
447 }
448 else if(m_StripType[ihit] == 1 && m_StripID[ihit] > CgemID::getVSTRIP_MAX(m_LayerID[ihit])) {
449 cout<<"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer " << m_LayerID[ihit] << ", sheet " << m_SheetID[ihit] << ": " << m_StripID[ihit] << endl;
450 }
451
452 return true;
453 }
454
455 else if(CosmicRayDataSetID == "CR202312") {
456
457 charge_channel = 1;
458 time_channel = 1;
459
460 // from plane to LayerID
461 if(m_plane[ihit] != 0 && m_plane[ihit] != 1 && m_plane[ihit] != 2) {
462 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
463 return false;
464 }
465 else m_LayerID[ihit] = m_plane[ihit] ;
466
467 // from view to StripType
468 if(m_view[ihit] == 2) m_StripType[ihit] = 0; // x strip (phi)
469 else if(m_view[ihit] == 3) m_StripType[ihit] = 1; // v strip (stereo)
470 else {
471 cout<<"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
472 return false;
473 }
474
475 if(m_strip[ihit] < 0) {
476 cout<<"ReadCosmicRayData::ConvertHitToDigi: negative strip ID "<<m_strip[ihit]<<endl;
477 return false;
478 }
479
480 // sheet
481 m_SheetID[ihit] = m_sheet[ihit] ;
482
483 // strip
484 m_StripID[ihit] = m_strip[ihit];
485
486 // some checks
487 if(m_StripType[ihit] == 0 && m_StripID[ihit] > CgemID::getXSTRIP_MAX(m_LayerID[ihit])) {
488 cout<<"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer " << m_LayerID[ihit] << ", sheet " << m_SheetID[ihit] << ": " << m_StripID[ihit] << endl;
489 }
490 else if(m_StripType[ihit] == 1 && m_StripID[ihit] > CgemID::getVSTRIP_MAX(m_LayerID[ihit])) {
491 cout<<"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer " << m_LayerID[ihit] << ", sheet " << m_SheetID[ihit] << ": " << m_StripID[ihit] << endl;
492 }
493
494 return true;
495 }
496
497 cout << "ERROR : ReadCosmicRayData::ConvertGRAALToCgemBoss(), the data set " << CosmicRayDataSetID << " is unknown! " << endl;
498 return false;
499
500}
501
502void ReadCosmicRayData::SaveCgemDigits()
503{
504
505 bool printFlag=false;
506 //cout<<"Start to save CgemDigi"<<endl;
507 // cgem digis collection defined in BOSS
508 CgemDigiCol* aCgemDigiCol = new CgemDigiCol;
509
510 //cout<<"nDigi : "<<m_nGemHit<<endl;
511 if (m_nGemHit > 0)
512 {
513 // push back cgem digits to CgemDigiCol in BOSS
514 for(int i=0;i<m_nGemHit;i++)
515 {
516 unsigned int charge_channel;
517 unsigned int time_channel;
518 bool is_converted = ConvertHitToDigi(i, charge_channel, time_channel);
519 if(!is_converted) {
520 cout<<"ReadCosmicRayData::SaveCgemDigits failed to convert hit "<<i<<" to digi in event "<<m_Event_D<<endl;
521 continue;
522 }
523 const Identifier ident = CgemID::strip_id(
524 TranslateDigitLayerID(m_LayerID[i]),
525 TranslateDigitSheetID(m_SheetID[i]),
526 TranslateDigitStripType(m_StripType[i]),
527 TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i])));
528
529 /**
530 cout << "graal strip " << m_strip[i]
531 << " graal view " << m_view[i]
532 << " stripid " << m_StripID[i]
533 << " striptype " << m_StripType[i]
534 << " strip " << TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i]))
535 << " identifier " << CgemID::getIntID(TranslateDigitLayerID(m_LayerID[i]),
536 TranslateDigitSheetID(m_SheetID[i]),
537 TranslateDigitStripType(m_StripType[i]),
538 TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i]))) << endl;;
539 **/
540
541 int layerid = CgemID::layer(ident);
542 int stripid = CgemID::strip(ident);
543 int sheetid = CgemID::sheet(ident);
544 bool is_xstrip = CgemID::is_xstrip(ident);
545
546 if(printFlag)
547 {
548 cout
549 << " digiID=" << ident.get_value()
550 << " layerID=" << CgemID::layer(ident)
551 << " sheetID=" << CgemID::sheet(ident)
552 << " isXstrip="<< CgemID::is_xstrip(ident)
553 << " stripID=" << CgemID::strip(ident)
554 << " time channel=" << time_channel
555 << " charge channel=" << charge_channel << endl;
556 }
557
558 CgemDigi* aCgemDigi = new CgemDigi(ident, time_channel, charge_channel);
559 aCgemDigi->setTime_ns(m_time[i]);
560 aCgemDigi->setCharge_fc(m_charge[i]);
561 aCgemDigiCol->push_back(aCgemDigi);
562
563 } // End of 'for(int i=0;i<nDigi;i++)'
564 } // End of 'if (nDigi > 0)'
565
566 // register CGEM digits collection to TDS
567 //if(Ind_Entry_D>23790) { cout<<"aCgemDigiCol size="<<aCgemDigiCol->size()<<" to be registered"<<endl; }
568 StatusCode scCgem = m_evtSvc->registerObject("/Event/Digi/CgemDigiCol", aCgemDigiCol);
569 //if(Ind_Entry_D>23790) cout<<"registered"<<endl;
570 if(scCgem!=StatusCode::SUCCESS)
571 {
572 cout << "ERROR : ReadCosmicRayData::SaveCgemDigits(), Could not register CGEM digi collection! " << endl;
573 }
574
575 //retrieve CGEM digits from TDS
576 /**
577 SmartDataPtr<CgemDigiCol> aDigiCol(m_evtSvc,"/Event/Digi/CgemDigiCol");
578 if(!aDigiCol)
579 cout<<"Could not retrieve CGEM digi collection"<<endl;
580
581 CgemDigiCol::iterator iDigiCol;
582 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
583 {
584 const Identifier ident = (*iDigiCol)->identify();
585 cout<<" layer: "<<CgemID::layer(ident)
586 <<" sheet: "<<CgemID::sheet(ident)
587 <<" strip: "<<CgemID::strip(ident)
588 <<" charge: "<<(*iDigiCol)->getCharge_fc()
589 <<" time: "<<(*iDigiCol)->getTime_ns()<<endl;
590 }
591 cout<<"end of retrieve CGEM digi collection"<<endl;
592 **/
593}
594
595
596
597void ReadCosmicRayData::SaveCgemClusters()
598{
599
600 bool printFlag=false;
601 //cout<<"Start to save CgemCluster"<<endl;
602
603 // cgem digis collection defined in BOSS
604 RecCgemClusterCol* aRecCgemClusterCol = new RecCgemClusterCol;
605
606 int nCluster = m_nGemCluster; // the number of Clusters in one event
607 if (nCluster > 0)
608 {
609 // push back cgem clusters to RecCgemClusterCol in BOSS
610 for(int i=0;i<nCluster;i++)
611 {
612 RecCgemCluster* aRecCgemCluster = new RecCgemCluster();
613
614 aRecCgemCluster->setclusterid(i);
615 aRecCgemCluster->setlayerid(TranslateClusterLayerID(m_ClusterLayerID[i]));
616 aRecCgemCluster->setsheetid(ClusterSheetID);
617 aRecCgemCluster->setflag(TranslateClusterFlag(m_Flag[i]));
618 aRecCgemCluster->setenergydeposit(m_EnergyDeposit[i]);
619 if(TranslateClusterFlag(m_Flag[i])==0)
620 {
621 aRecCgemCluster->setrecphi(m_Cluster_x[i]);
622 aRecCgemCluster->setrecphi_CC(m_Cluster_x_cc[i]);
623 aRecCgemCluster->setrecphi_mTPC(m_Cluster_x_tpc[i]);
624 }
625 if(TranslateClusterFlag(m_Flag[i])==1)
626 {
627 aRecCgemCluster->setrecv(m_Cluster_x[i]);
628 aRecCgemCluster->setrecv_CC(m_Cluster_x_cc[i]);
629 aRecCgemCluster->setrecv_mTPC(m_Cluster_x_tpc[i]);
630 }
631 aRecCgemCluster->setRecZ(ClusterRecZ); //currently, no Z information is available
632 aRecCgemCluster->setRecZ_CC(ClusterRecZ);
633 aRecCgemCluster->setRecZ_mTPC(ClusterRecZ);
634 //aRecCgemCluster->setRecZ(m_Cluster_z[i]);
635 //aRecCgemCluster->setRecZ_CC(m_Cluster_z_cc[i]);
636 //aRecCgemCluster->setRecZ_mTPC(m_Cluster_z_tpc[i]);
637 aRecCgemCluster->setclusterflag(m_ClusterHitIndex[i][0],m_ClusterHitIndex[i][m_ClusternHit[i]-1]);
638
639 if(printFlag)
640 {
641 cout
642 << " clusterID=" << aRecCgemCluster->getclusterid()
643 << " clusterlayerID=" << aRecCgemCluster->getlayerid()
644 << " clustersheetID=" << aRecCgemCluster->getsheetid()
645 << " flag=" << aRecCgemCluster->getflag()
646 << " energydeposit=" << aRecCgemCluster->getenergydeposit()
647 << " recphi=" << aRecCgemCluster->getrecphi()
648 << " recv=" << aRecCgemCluster->getrecv()
649 << " recZ=" << aRecCgemCluster->getRecZ()
650 << " clusterflagb=" << aRecCgemCluster->getclusterflagb()
651 << " clusterflage=" << aRecCgemCluster->getclusterflage()<< endl;
652 }
653
654 aRecCgemClusterCol->push_back(aRecCgemCluster);
655
656 }
657 }
658
659
660 // register CGEM clusters collection to TDS
661 StatusCode scCgem = m_evtSvc->registerObject("/Event/Recon/RecCgemClusterCol", aRecCgemClusterCol); //Where should I put the vector?
662 if(scCgem!=StatusCode::SUCCESS)
663 {
664 cout << "ERROR : ReadCosmicRayData:::SaveCgemClusters(), Could not register CGEM cluster collection! " << endl;
665 }
666
667}
668
669
671 MsgStream log(msgSvc(), name());
672 if(ReadDigi&&!ReadCluster) log << MSG::INFO << "ReadCosmicRayData execute(): "<<Ind_Entry_D+1<<"/"<<No_Entries_D<<" events are finished !" << endreq;
673 if(!ReadDigi&&ReadCluster) log << MSG::INFO << "ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<"/"<<No_Entries_C<<" events are finished !" << endreq;
674 if(ReadDigi&&ReadCluster) log << MSG::INFO << "ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<"/"<<No_Entries_C<<" events are finished !" << endreq;
675
676
677 //interface to event data service
678 ISvcLocator* svcLocator = Gaudi::svcLocator();
679 StatusCode sc=svcLocator->service("EventDataSvc", m_evtSvc);
680 if (sc.isFailure())
681 cout<<"Could not accesss EventDataSvc!"<<endl;
682
683 // set /Event/EventHeader
684 SmartDataPtr<Event::EventHeader> eventHeader(m_evtSvc,"/Event/EventHeader");
685 if (!eventHeader) {
686 Event::EventHeader *eventHeader = new Event::EventHeader;
687 StatusCode sc = m_evtSvc->registerObject("/Event/EventHeader",eventHeader);
688 }
689 eventHeader->setEventNumber(Ind_Entry_D);
690 eventHeader->setRunNumber( m_runNo);
691
692
693 if(ReadDigi)
694 {
695 DigiEvent* aDigiEvent = new DigiEvent;
696 sc = m_evtSvc->registerObject("/Event/Digi",aDigiEvent);
697 if(sc!=StatusCode::SUCCESS) {
698 cout<< "Could not register DigiEvent" <<endl;
699 }
700
701 ReadCgemDigits();
702 SaveCgemDigits();
703 //cout<<"Ind_Entry_D "<<Ind_Entry_D<<", Max_Ind_Entry_D "<<No_Entries_D<<endl;
704
705 if(Ind_Entry_D==No_Entries_D)
706 {
707 log << MSG::INFO << "scheduling a event processing stop...." << endreq;
708 SmartIF<IEventProcessor> ep(serviceLocator());
709 if (ep) ep->stopRun();
710 }
711
712 }
713 if(ReadCluster)
714 {
715 ReconEvent* aReconEvent = new ReconEvent;
716 sc = m_evtSvc->registerObject("/Event/Recon",aReconEvent);
717 if(sc!=StatusCode::SUCCESS) {
718 cout<< "Could not register ReconEvent" <<endl;
719 }
720
721 ReadCgemClusters();
722 SaveCgemClusters();
723 //cout<<"Ind_Entry_C "<<Ind_Entry_C<<", Max_Ind_Entry_C "<<No_Entries_C<<endl;
724 if(Ind_Entry_C==No_Entries_C)
725 {
726 // log << MSG::INFO << "scheduling a event processing stop...." << endreq;
727 SmartIF<IEventProcessor> ep(serviceLocator());
728 if (ep) ep->stopRun();
729 }
730 }
731 return StatusCode::SUCCESS;
732}
733
735 MsgStream log(msgSvc(),name());
736 log << MSG::INFO << "ReadCosmicRayData finalize()" << endreq;
737
738 // DEBUG
739 /**
740 const int nlayer = 3; // CHECK hardcoded
741 const int nsheet[nlayer] = {1, 2, 2}; // CHECK hardcoded
742 const int nview = 2; // CHECK hardcoded
743 int nstrip[nlayer][nview] = {{856, 1173}, {630, 1077}, {832, 1395}}; // CHECK hardcoded
744
745 int layer=1;
746 int sheet=0;
747 int type=0;
748 for(int strip=0; strip<nstrip[layer][type]; strip++) {
749 cout << strip << " "
750 << mapper->GetGEMROC(strip, type, layer, sheet) << " "
751 << mapper->GetFEB(strip, type, layer, sheet) << " "
752 << mapper->GetTIGER(strip, type, layer, sheet)
753 << endl;
754 }
755 **/
756 // --------
757
758 return StatusCode::SUCCESS;
759}
760
761
762
ObjectVector< CgemDigi > CgemDigiCol
Definition CgemDigi.h:43
ObjectVector< RecCgemCluster > RecCgemClusterCol
IMessageSvc * msgSvc()
void setCharge_fc(double q)
Definition CgemDigi.h:33
void setTime_ns(double t)
Definition CgemDigi.h:32
static int strip(const Identifier &id)
Definition CgemID.cxx:83
static int sheet(const Identifier &id)
Definition CgemID.cxx:77
static value_type getXSTRIP_MAX(unsigned int f_layer)
Definition CgemID.cxx:130
static int layer(const Identifier &id)
Definition CgemID.cxx:71
static value_type getVSTRIP_MAX(unsigned int f_layer)
Definition CgemID.cxx:136
static bool is_xstrip(const Identifier &id)
Definition CgemID.cxx:64
static Identifier strip_id(int f_layer, int f_sheet, int f_strip_type, int f_strip)
Definition CgemID.cxx:89
value_type get_value() const
Definition Identifier.h:163
ReadCosmicRayData(const std::string &name, ISvcLocator *pSvcLocator)
void setsheetid(int sheetid)
void setlayerid(int layerid)
void setRecZ_mTPC(double recZ)
void setrecv_CC(double recv)
double getenergydeposit(void) const
void setrecphi_CC(double recphi)
void setclusterid(int clusterid)
void setenergydeposit(double energydeposit)
double getRecZ(void) const
int getclusterid(void) const
void setrecv(double recv)
void setRecZ(double recZ)
int getlayerid(void) const
int getflag(void) const
int getclusterflagb(void) const
void setrecphi_mTPC(double recphi)
void setRecZ_CC(double recZ)
double getrecphi(void) const
double getrecv(void) const
int getsheetid(void) const
void setflag(int flag)
void setclusterflag(int begin, int end)
void setrecv_mTPC(double recv)
void setrecphi(double recphi)
int getclusterflage(void) const