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");
83 declareProperty(
"runNo", m_runNo = 1);
91 MsgStream log(
msgSvc(), name());
92 log << MSG::INFO <<
"ReadCosmicRayData initialize()" << endreq;
94 TString TDir_file(Dir_file);
95 f =
new TFile(TDir_file);
98 TString TTreeDigi(TreeDigi);
99 Tdigi = (TTree*)f->Get(TTreeDigi);
102 Tdigi->SetBranchAddress(
"Event", &m_Event_D);
103 Tdigi->SetBranchAddress(
"nGemHit", &m_nGemHit);
107 Tdigi->SetBranchAddress(
"GemHit_channel", m_channel);
108 Tdigi->SetBranchAddress(
"GemHit_ROC", m_ROC);
109 Tdigi->SetBranchAddress(
"GemHit_chip", m_chip);
110 Tdigi->SetBranchAddress(
"GemHit_FEB", m_FEB);
111 Tdigi->SetBranchAddress(
"GemHit_plane", m_plane);
112 Tdigi->SetBranchAddress(
"GemHit_view", m_view);
113 Tdigi->SetBranchAddress(
"GemHit_strip", m_strip);
116 Tdigi->SetBranchAddress(
"GemHit_saturated", m_saturated);
117 Tdigi->SetBranchAddress(
"GemHit_q", m_charge);
118 Tdigi->SetBranchAddress(
"GemHit_time", m_time);
121 No_Entries_D = Tdigi->GetEntries();
156 return StatusCode::SUCCESS;
160int ReadCosmicRayData::TranslateDigitLayerID(
int Input_LayerID)
162 int ShiftValue = Shift_DigitLayerID;
163 return Input_LayerID+ShiftValue;
166int ReadCosmicRayData::TranslateDigitSheetID(
int Input_SheetID)
168 int ShiftValue = Shift_DigitSheetID;
169 return Input_SheetID+ShiftValue;
172int ReadCosmicRayData::TranslateDigitXStripID(
int Input_StripID)
174 int ShiftValue = Shift_DigitXStripID;
175 return Input_StripID+ShiftValue;
178int ReadCosmicRayData::TranslateDigitVStripID(
int Input_StripID)
180 int ShiftValue = Shift_DigitVStripID;
181 return Input_StripID+ShiftValue;
184int ReadCosmicRayData::TranslateDigitStripID(
int Input_StripID,
int StripType)
186 int Output_StripID = -1;
187 if(StripType==0) Output_StripID = TranslateDigitXStripID(Input_StripID);
188 if(StripType==1) Output_StripID = TranslateDigitVStripID(Input_StripID);
189 return Output_StripID;
192int ReadCosmicRayData::TranslateDigitStripType(
int Input_StripType)
194 return Input_StripType;
197int ReadCosmicRayData::TranslateClusterLayerID(
int Input_LayerID)
199 int ShiftValue = Shift_ClusterLayerID;
200 return Input_LayerID+ShiftValue;
203int ReadCosmicRayData::TranslateClusterSheetID(
int Input_SheetID)
205 int ShiftValue = Shift_ClusterSheetID;
206 return Input_SheetID+ShiftValue;
209int ReadCosmicRayData::TranslateClusterFlag(
int Input_Flag)
214double ReadCosmicRayData::TranslateRecPhi(
double Input_RecPhi)
216 double ShiftValue = Shift_RecPhi;
217 return Input_RecPhi+ShiftValue;
220double ReadCosmicRayData::TranslateRecV(
double Input_RecV)
222 double ShiftValue = Shift_RecV;
223 return Input_RecV+ShiftValue;
226double ReadCosmicRayData::TranslateRecZ(
double Input_RecZ)
228 double ShiftValue = Shift_RecZ;
229 return Input_RecZ+ShiftValue;
232void ReadCosmicRayData::ReadCgemDigits()
235 Tdigi->GetEntry(Ind_Entry_D);
239void ReadCosmicRayData::ReadCgemClusters()
242 Tcluster->GetEntry(Ind_Entry_C);
246bool ReadCosmicRayData::ConvertHitToDigi(
int ihit,
unsigned int &charge_channel,
unsigned int &time_channel)
249 if(CosmicRayDataSetID ==
"CR201909") {
257 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0;
258 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1;
259 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1;
261 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
266 if(m_view[ihit] == 2) m_StripType[ihit] = 0;
267 else if(m_view[ihit] == 3) m_StripType[ihit] = 1;
269 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
275 m_StripID[ihit] = m_strip[ihit]-1;
276 if(m_LayerID[ihit] == 1) {
277 if(m_StripType[ihit] == 0)
285 else if(m_StripType[ihit] == 1)
289 m_StripID[ihit] = m_strip[ihit] - 2;
295 if(m_strip[ihit] >= 1617) m_StripID[ihit] = m_strip[ihit] - 3 -
CgemID::getVSTRIP_MAX(m_LayerID[ihit]);
307 cout <<
"ERROR : ReadCosmicRayData::ConvertGRAALToCgemBoss(), the data set " << CosmicRayDataSetID <<
" is unknown! " << endl;
312void ReadCosmicRayData::SaveCgemDigits()
315 bool printFlag=
false;
324 for(
int i=0;i<m_nGemHit;i++)
326 unsigned int charge_channel;
327 unsigned int time_channel;
328 bool is_converted = ConvertHitToDigi(i, charge_channel, time_channel);
330 cout<<
"ReadCosmicRayData::SaveCgemDigits failed to convert hit "<<i<<
" to digi in event "<<m_Event_D<<endl;
334 TranslateDigitLayerID(m_LayerID[i]),
335 TranslateDigitSheetID(m_SheetID[i]),
336 TranslateDigitStripType(m_StripType[i]),
337 TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i])));
364 <<
" time channel=" << time_channel
365 <<
" charge channel=" << charge_channel << endl;
371 aCgemDigiCol->push_back(aCgemDigi);
377 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Digi/CgemDigiCol", aCgemDigiCol);
378 if(scCgem!=StatusCode::SUCCESS)
380 cout <<
"ERROR : ReadCosmicRayData::SaveCgemDigits(), Could not register CGEM digi collection! " << endl;
405void ReadCosmicRayData::SaveCgemClusters()
408 bool printFlag=
false;
414 int nCluster = m_nGemCluster;
418 for(
int i=0;i<nCluster;i++)
423 aRecCgemCluster->
setlayerid(TranslateClusterLayerID(m_ClusterLayerID[i]));
425 aRecCgemCluster->
setflag(TranslateClusterFlag(m_Flag[i]));
427 if(TranslateClusterFlag(m_Flag[i])==0)
429 aRecCgemCluster->
setrecphi(m_Cluster_x[i]);
433 if(TranslateClusterFlag(m_Flag[i])==1)
435 aRecCgemCluster->
setrecv(m_Cluster_x[i]);
436 aRecCgemCluster->
setrecv_CC(m_Cluster_x_cc[i]);
439 aRecCgemCluster->
setRecZ(ClusterRecZ);
445 aRecCgemCluster->
setclusterflag(m_ClusterHitIndex[i][0],m_ClusterHitIndex[i][m_ClusternHit[i]-1]);
451 <<
" clusterlayerID=" << aRecCgemCluster->
getlayerid()
452 <<
" clustersheetID=" << aRecCgemCluster->
getsheetid()
453 <<
" flag=" << aRecCgemCluster->
getflag()
455 <<
" recphi=" << aRecCgemCluster->
getrecphi()
456 <<
" recv=" << aRecCgemCluster->
getrecv()
457 <<
" recZ=" << aRecCgemCluster->
getRecZ()
462 aRecCgemClusterCol->push_back(aRecCgemCluster);
469 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Recon/RecCgemClusterCol", aRecCgemClusterCol);
470 if(scCgem!=StatusCode::SUCCESS)
472 cout <<
"ERROR : ReadCosmicRayData:::SaveCgemClusters(), Could not register CGEM cluster collection! " << endl;
480 MsgStream log(
msgSvc(), name());
481 if(ReadDigi&&!ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_D+1<<
"/"<<No_Entries_D<<
" events are finished !" << endreq;
482 if(!ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
483 if(ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
486 ISvcLocator* svcLocator = Gaudi::svcLocator();
487 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
489 cout<<
"Could not accesss EventDataSvc!"<<endl;
492 SmartDataPtr<Event::EventHeader> eventHeader(m_evtSvc,
"/Event/EventHeader");
495 StatusCode sc = m_evtSvc->registerObject(
"/Event/EventHeader",eventHeader);
504 sc = m_evtSvc->registerObject(
"/Event/Digi",aDigiEvent);
505 if(sc!=StatusCode::SUCCESS) {
506 cout<<
"Could not register DigiEvent" <<endl;
513 if(Ind_Entry_D==No_Entries_D)
515 log << MSG::INFO <<
"scheduling a event processing stop...." << endreq;
516 SmartIF<IEventProcessor> ep(serviceLocator());
517 if (ep) ep->stopRun();
524 sc = m_evtSvc->registerObject(
"/Event/Recon",aReconEvent);
525 if(sc!=StatusCode::SUCCESS) {
526 cout<<
"Could not register ReconEvent" <<endl;
532 if(Ind_Entry_C==No_Entries_C)
534 log << MSG::INFO <<
"scheduling a event processing stop...." << endreq;
535 SmartIF<IEventProcessor> ep(serviceLocator());
536 if (ep) ep->stopRun();
539 return StatusCode::SUCCESS;
543 MsgStream log(
msgSvc(),name());
544 log << MSG::INFO <<
"ReadCosmicRayData finalize()" << endreq;
546 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