Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:21

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   //cout<<"ctor InttHit"<<endl;
0018 }
0019 
0020 void InttHit::copy(InttHit& hit){
0021 //  //cout<<"copy: "<<hit.pid<<" : "<<endl;
0022   pid       = hit.pid;
0023 //  cout<<"copy t1"<<endl;
0024   adc       = hit.adc;
0025   ampl      = hit.ampl;
0026   chip_id   = hit.chip_id;
0027   module    = hit.module;
0028           
0029 //  cout<<"copy1"<<endl;
0030   chan_id   = hit.chan_id;
0031   bco       = hit.bco;
0032   bco_full  = hit.bco_full;
0033 
0034 //  cout<<"copy2"<<endl;
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 //  cout<<"copy3"<<endl;
0044   full_fphx = hit.full_fphx;
0045   full_roc  = hit.full_roc;
0046 //  cout<<"copy end"<<endl;
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 ispid   = (pid    == (objcp->pid));
0068     bool ismodule= (module == (objcp->module));
0069     bool ischip  = (chip_id== (objcp->chip_id));
0070     bool ischan  = (chan_id== (objcp->chan_id));
0071     bool isadc   = (adc    == (objcp->adc));
0072 
0073     return ispid&&ismodule&&ischip&&ischan&&isadc;
0074 }
0075 
0076 Bool_t InttHit::IsSortable() const { return kTRUE;}
0077 
0078 Int_t  InttHit::Compare(const TObject* obj) const {
0079     const InttHit* objcp = dynamic_cast<const InttHit*>(obj);
0080     if(     pid < objcp->pid) return -1;
0081     else if(pid > objcp->pid) return  1;
0082     else {
0083       if(     module < objcp->module) return -1;
0084       else if(module > objcp->module) return  1;
0085       else {
0086         if(     chip_id < objcp->chip_id)  return -1;
0087         else if(chip_id > objcp->chip_id)  return  1;
0088         else {
0089           if(     chan_id < objcp->chan_id)  return -1;
0090           else if(chan_id > objcp->chan_id)  return  1;
0091 
0092           return 0;
0093         }
0094       }
0095     }
0096 }
0097 
0098 /////////////////////
0099 
0100 InttEvent::InttEvent(): evtSeq(0), bco(0), fNhits(0), fhitArray(NULL) {
0101   fhitArray = new TClonesArray("InttHit", NHITS_INIT);
0102   cout<<"ctor InttEvent"<<endl;
0103 }
0104 
0105 InttEvent::~InttEvent(){
0106   if(fhitArray!=NULL) delete fhitArray;
0107   cout<<"dtor InttEvent"<<endl;
0108 }
0109 
0110 InttHit* InttEvent::addHit(){
0111   //cout<<"nhits: "<<fNhits<<endl;
0112   TClonesArray& hitArray = *fhitArray;
0113   InttHit* hitnew = new(hitArray[fNhits++]) InttHit();
0114 
0115   //cout<<"nhits: before return "<<fNhits<<endl;
0116   return hitnew;
0117 }
0118 
0119 int InttEvent::getNHits(){
0120   return fNhits;//m_hitArray->GetEntries();
0121 }
0122 
0123 InttHit* InttEvent::getHit(const int ihit){
0124   return (ihit<getNHits()) ? (InttHit*)fhitArray->UncheckedAt(ihit) : NULL;
0125 }
0126 
0127 void InttEvent::clear() {
0128   fhitArray->Clear(); 
0129   fNhits=0;
0130   evtSeq=0;
0131   bco=0;
0132 };
0133 
0134 void InttEvent::copy(InttEvent* org) {
0135   if(org==NULL) return;
0136 
0137   clear();
0138 
0139   evtSeq = org->evtSeq;
0140   bco    = org->bco;
0141 
0142   for(int ihit=0; ihit<org->getNHits(); ihit++){
0143       InttHit* hitnew = addHit();
0144       InttHit* hit    = org->getHit(ihit);
0145       hitnew->copy(*hit);
0146       //cout<<"debug hit: "<<endl;
0147       //hitnew->show();
0148       //hit->show();
0149   }
0150 };
0151 
0152 void InttEvent::show() {
0153   cout<<"Evt : "<<evtSeq<<" 0x"<<hex<<bco<<dec<<endl;
0154   cout<<"  Nhits : "<<fNhits<<endl;
0155 
0156   for(int ihit=0; ihit<fNhits; ihit++){
0157     InttHit* hit = getHit(ihit);
0158     hit->show((ihit==0));
0159   }
0160 };
0161 
0162 void InttEvent::sort() {
0163   fhitArray->Sort();
0164 };