29#include "GaudiKernel/AlgFactory.h"
30#include "GaudiKernel/DataObject.h"
31#include "GaudiKernel/IEventProcessor.h"
33#include "GaudiKernel/Incident.h"
34#include "GaudiKernel/IIncidentSvc.h"
35#include "GaudiKernel/Memory.h"
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"
46#include "CgemRawEvent/CgemDigi.h"
47#include "CgemRecEvent/RecCgemCluster.h"
49#include "Identifier/CgemID.h"
51#include "RawEvent/RawDataUtil.h"
52#include "RawEvent/DigiEvent.h"
53#include "ReconEvent/ReconEvent.h"
54#include "EventModel/EventHeader.h"
55#include "GaudiKernel/SmartDataPtr.h"
57#include "ReadCosmicRayData/ReadCosmicRayData.h"
61 Algorithm(name,pSvcLocator){
63 declareProperty(
"Dir_file", Dir_file =
"Cosmic_data_01.root");
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");
90 MsgStream log(
msgSvc(), name());
91 log << MSG::INFO <<
"ReadCosmicRayData initialize()" << endreq;
93 TString TDir_file(Dir_file);
94 f =
new TFile(TDir_file);
97 TString TTreeDigi(TreeDigi);
98 Tdigi = (TTree*)f->Get(TTreeDigi);
101 Tdigi->SetBranchAddress(
"Event", &m_Event_D);
102 Tdigi->SetBranchAddress(
"nGemHit", &m_nGemHit);
106 Tdigi->SetBranchAddress(
"GemHit_channel", m_channel);
107 Tdigi->SetBranchAddress(
"GemHit_ROC", m_ROC);
108 Tdigi->SetBranchAddress(
"GemHit_chip", m_chip);
109 Tdigi->SetBranchAddress(
"GemHit_FEB", m_FEB);
110 Tdigi->SetBranchAddress(
"GemHit_plane", m_plane);
111 Tdigi->SetBranchAddress(
"GemHit_view", m_view);
112 Tdigi->SetBranchAddress(
"GemHit_strip", m_strip);
115 Tdigi->SetBranchAddress(
"GemHit_saturated", m_saturated);
116 Tdigi->SetBranchAddress(
"GemHit_q", m_charge);
117 Tdigi->SetBranchAddress(
"GemHit_time", m_time);
120 No_Entries_D = Tdigi->GetEntries();
155 return StatusCode::SUCCESS;
159int ReadCosmicRayData::TranslateDigitLayerID(
int Input_LayerID)
161 int ShiftValue = Shift_DigitLayerID;
162 return Input_LayerID+ShiftValue;
165int ReadCosmicRayData::TranslateDigitSheetID(
int Input_SheetID)
167 int ShiftValue = Shift_DigitSheetID;
168 return Input_SheetID+ShiftValue;
171int ReadCosmicRayData::TranslateDigitXStripID(
int Input_StripID)
173 int ShiftValue = Shift_DigitXStripID;
174 return Input_StripID+ShiftValue;
177int ReadCosmicRayData::TranslateDigitVStripID(
int Input_StripID)
179 int ShiftValue = Shift_DigitVStripID;
180 return Input_StripID+ShiftValue;
183int ReadCosmicRayData::TranslateDigitStripID(
int Input_StripID,
int StripType)
185 int Output_StripID = -1;
186 if(StripType==0) Output_StripID = TranslateDigitXStripID(Input_StripID);
187 if(StripType==1) Output_StripID = TranslateDigitVStripID(Input_StripID);
188 return Output_StripID;
191int ReadCosmicRayData::TranslateDigitStripType(
int Input_StripType)
193 return Input_StripType;
196int ReadCosmicRayData::TranslateClusterLayerID(
int Input_LayerID)
198 int ShiftValue = Shift_ClusterLayerID;
199 return Input_LayerID+ShiftValue;
202int ReadCosmicRayData::TranslateClusterSheetID(
int Input_SheetID)
204 int ShiftValue = Shift_ClusterSheetID;
205 return Input_SheetID+ShiftValue;
208int ReadCosmicRayData::TranslateClusterFlag(
int Input_Flag)
213double ReadCosmicRayData::TranslateRecPhi(
double Input_RecPhi)
215 double ShiftValue = Shift_RecPhi;
216 return Input_RecPhi+ShiftValue;
219double ReadCosmicRayData::TranslateRecV(
double Input_RecV)
221 double ShiftValue = Shift_RecV;
222 return Input_RecV+ShiftValue;
225double ReadCosmicRayData::TranslateRecZ(
double Input_RecZ)
227 double ShiftValue = Shift_RecZ;
228 return Input_RecZ+ShiftValue;
231void ReadCosmicRayData::ReadCgemDigits()
234 Tdigi->GetEntry(Ind_Entry_D);
238void ReadCosmicRayData::ReadCgemClusters()
241 Tcluster->GetEntry(Ind_Entry_C);
245bool ReadCosmicRayData::ConvertHitToDigi(
int ihit,
unsigned int &charge_channel,
unsigned int &time_channel)
248 if(CosmicRayDataSetID ==
"CR201909") {
256 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0;
257 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1;
258 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1;
262 if(m_view[ihit] == 2) m_StripType[ihit] = 0;
263 else if(m_view[ihit] == 3) m_StripType[ihit] = 1;
268 m_StripID[ihit] = m_strip[ihit];
269 if(m_LayerID[ihit] == 1) {
287 cout <<
"ERROR : ReadCosmicRayData::ConvertGRAALToCgemBoss(), the data set " << CosmicRayDataSetID <<
" is unknown! " << endl;
292void ReadCosmicRayData::SaveCgemDigits()
295 bool printFlag=
false;
304 for(
int i=0;i<m_nGemHit;i++)
306 unsigned int charge_channel;
307 unsigned int time_channel;
308 bool is_converted = ConvertHitToDigi(i, charge_channel, time_channel);
309 if(!is_converted)
continue;
311 TranslateDigitLayerID(m_LayerID[i]),
312 TranslateDigitSheetID(m_SheetID[i]),
313 TranslateDigitStripType(m_StripType[i]),
314 TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i])));
341 <<
" time channel=" << time_channel
342 <<
" charge channel=" << charge_channel << endl;
348 aCgemDigiCol->push_back(aCgemDigi);
354 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Digi/CgemDigiCol", aCgemDigiCol);
355 if(scCgem!=StatusCode::SUCCESS)
357 cout <<
"ERROR : ReadCosmicRayData::SaveCgemDigits(), Could not register CGEM digi collection! " << endl;
382void ReadCosmicRayData::SaveCgemClusters()
385 bool printFlag=
false;
391 int nCluster = m_nGemCluster;
395 for(
int i=0;i<nCluster;i++)
400 aRecCgemCluster->
setlayerid(TranslateClusterLayerID(m_ClusterLayerID[i]));
402 aRecCgemCluster->
setflag(TranslateClusterFlag(m_Flag[i]));
404 if(TranslateClusterFlag(m_Flag[i])==0)
406 aRecCgemCluster->
setrecphi(m_Cluster_x[i]);
410 if(TranslateClusterFlag(m_Flag[i])==1)
412 aRecCgemCluster->
setrecv(m_Cluster_x[i]);
413 aRecCgemCluster->
setrecv_CC(m_Cluster_x_cc[i]);
416 aRecCgemCluster->
setRecZ(ClusterRecZ);
422 aRecCgemCluster->
setclusterflag(m_ClusterHitIndex[i][0],m_ClusterHitIndex[i][m_ClusternHit[i]-1]);
428 <<
" clusterlayerID=" << aRecCgemCluster->
getlayerid()
429 <<
" clustersheetID=" << aRecCgemCluster->
getsheetid()
430 <<
" flag=" << aRecCgemCluster->
getflag()
432 <<
" recphi=" << aRecCgemCluster->
getrecphi()
433 <<
" recv=" << aRecCgemCluster->
getrecv()
434 <<
" recZ=" << aRecCgemCluster->
getRecZ()
439 aRecCgemClusterCol->push_back(aRecCgemCluster);
446 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Recon/RecCgemClusterCol", aRecCgemClusterCol);
447 if(scCgem!=StatusCode::SUCCESS)
449 cout <<
"ERROR : ReadCosmicRayData:::SaveCgemClusters(), Could not register CGEM cluster collection! " << endl;
457 MsgStream log(
msgSvc(), name());
458 if(ReadDigi&&!ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_D+1<<
"/"<<No_Entries_D<<
" events are finished !" << endreq;
459 if(!ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
460 if(ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
463 ISvcLocator* svcLocator = Gaudi::svcLocator();
464 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
466 cout<<
"Could not accesss EventDataSvc!"<<endl;
471 sc = m_evtSvc->registerObject(
"/Event/Digi",aDigiEvent);
472 if(sc!=StatusCode::SUCCESS) {
473 cout<<
"Could not register DigiEvent" <<endl;
480 if(Ind_Entry_D==No_Entries_D)
482 log << MSG::INFO <<
"scheduling a event processing stop...." << endreq;
483 SmartIF<IEventProcessor> ep(serviceLocator());
484 if (ep) ep->stopRun();
491 sc = m_evtSvc->registerObject(
"/Event/Recon",aReconEvent);
492 if(sc!=StatusCode::SUCCESS) {
493 cout<<
"Could not register ReconEvent" <<endl;
499 if(Ind_Entry_C==No_Entries_C)
501 log << MSG::INFO <<
"scheduling a event processing stop...." << endreq;
502 SmartIF<IEventProcessor> ep(serviceLocator());
503 if (ep) ep->stopRun();
506 return StatusCode::SUCCESS;
510 MsgStream log(
msgSvc(),name());
511 log << MSG::INFO <<
"ReadCosmicRayData finalize()" << endreq;
513 return StatusCode::SUCCESS;
ObjectVector< CgemDigi > CgemDigiCol
ObjectVector< RecCgemCluster > RecCgemClusterCol
void setCharge_fc(double q)
void setTime_ns(double t)
static int strip(const Identifier &id)
static int sheet(const Identifier &id)
static value_type getXSTRIP_MAX(unsigned int f_layer)
static int layer(const Identifier &id)
static value_type getVSTRIP_MAX(unsigned int f_layer)
static bool is_xstrip(const Identifier &id)
static Identifier strip_id(int f_layer, int f_sheet, int f_strip_type, int f_strip)
value_type get_value() const
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 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 setclusterflag(int begin, int end)
void setrecv_mTPC(double recv)
void setrecphi(double recphi)
int getclusterflage(void) const