File indexing completed on 2025-08-06 08:12:31
0001 #include "InttEvent.h"
0002 #include "TClonesArray.h"
0003
0004 #include <iostream>
0005 #include <iomanip>
0006
0007 ClassImp(InttHit)
0008 ClassImp(InttEvent)
0009
0010
0011 using namespace std;
0012
0013 static const int NHITS_INIT = 500;
0014
0015
0016 InttHit::InttHit() {
0017
0018 }
0019
0020 void InttHit::copy(InttHit& hit){
0021
0022 pid = hit.pid;
0023
0024 adc = hit.adc;
0025 ampl = hit.ampl;
0026 chip_id = hit.chip_id;
0027 module = hit.module;
0028
0029
0030 chan_id = hit.chan_id;
0031 bco = hit.bco;
0032 bco_full = hit.bco_full;
0033
0034
0035 evt = hit.evt;
0036
0037 roc = hit.roc;
0038 barrel = hit.barrel;
0039 layer = hit.layer;
0040 ladder = hit.ladder;
0041 arm = hit.arm;
0042
0043
0044 full_fphx = hit.full_fphx;
0045 full_roc = hit.full_roc;
0046
0047 }
0048
0049 void InttHit::show(bool explanation_flag){
0050 if(explanation_flag){
0051 cout<<" module chip_id chan_id adc ampl";
0052 cout<<endl;
0053 }
0054 cout<<" ";
0055 cout<<setw(6)<<module<<" ";
0056 cout<<setw(6)<<chip_id<<" ";
0057 cout<<setw(6)<<chan_id<<" ";
0058 cout<<setw(3)<<adc<<" ";
0059 cout<<setw(4)<<ampl<<" ";
0060 cout<<endl;
0061 }
0062
0063
0064 Bool_t InttHit::IsEqual(const TObject *obj) const
0065 {
0066 const InttHit* objcp = dynamic_cast<const InttHit*>(obj);
0067 bool ismodule= (module == (objcp->module));
0068 bool ischip = (chip_id== (objcp->chip_id));
0069 bool ischan = (chan_id== (objcp->chan_id));
0070 bool isadc = (adc == (objcp->adc));
0071
0072 return ismodule&&ischip&&ischan&&isadc;
0073 }
0074
0075 Bool_t InttHit::IsSortable() const { return kTRUE;}
0076
0077 Int_t InttHit::Compare(const TObject* obj) const {
0078 const InttHit* objcp = dynamic_cast<const InttHit*>(obj);
0079 if( module < objcp->module) return -1;
0080 else if(module > objcp->module) return 1;
0081 else {
0082 if( chip_id < objcp->chip_id) return -1;
0083 else if(chip_id > objcp->chip_id) return 1;
0084 else {
0085 if( chan_id < objcp->chan_id) return -1;
0086 else if(chan_id > objcp->chan_id) return 1;
0087
0088 return 0;
0089 }
0090 }
0091 }
0092
0093
0094
0095 InttEvent::InttEvent(): evtSeq(0), bco(0), fNhits(0), fhitArray(NULL) {
0096 fhitArray = new TClonesArray("InttHit", NHITS_INIT);
0097 cout<<"ctor InttEvent"<<endl;
0098 }
0099
0100 InttEvent::~InttEvent(){
0101 if(fhitArray!=NULL) delete fhitArray;
0102 cout<<"dtor InttEvent"<<endl;
0103 }
0104
0105 InttHit* InttEvent::addHit(){
0106
0107 TClonesArray& hitArray = *fhitArray;
0108 InttHit* hitnew = new(hitArray[fNhits++]) InttHit();
0109
0110
0111 return hitnew;
0112 }
0113
0114 int InttEvent::getNHits(){
0115 return fNhits;
0116 }
0117
0118 InttHit* InttEvent::getHit(const int ihit){
0119 return (ihit<getNHits()) ? (InttHit*)fhitArray->UncheckedAt(ihit) : NULL;
0120 }
0121
0122 void InttEvent::clear() {
0123 fhitArray->Clear();
0124 fNhits=0;
0125 evtSeq=0;
0126 bco=0;
0127 };
0128
0129 void InttEvent::copy(InttEvent* org) {
0130 if(org==NULL) return;
0131
0132 clear();
0133
0134 evtSeq = org->evtSeq;
0135 bco = org->bco;
0136
0137 for(int ihit=0; ihit<org->getNHits(); ihit++){
0138 InttHit* hitnew = addHit();
0139 InttHit* hit = org->getHit(ihit);
0140 hitnew->copy(*hit);
0141
0142
0143
0144 }
0145 };
0146
0147 void InttEvent::show() {
0148 cout<<"Evt : "<<evtSeq<<" 0x"<<hex<<bco<<dec<<endl;
0149 cout<<" Nhits : "<<fNhits<<endl;
0150
0151 for(int ihit=0; ihit<fNhits; ihit++){
0152 InttHit* hit = getHit(ihit);
0153 hit->show((ihit==0));
0154 }
0155 };
0156
0157 void InttEvent::sort() {
0158 fhitArray->Sort();
0159 };