CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

hcaltb::HcalTBTDCUnpacker Class Reference

#include <HcalTBTDCUnpacker.h>

List of all members.

Classes

struct  Hit
struct  WireChamberRecoData

Public Member Functions

 HcalTBTDCUnpacker (bool)
void setCalib (const std::vector< std::vector< std::string > > &calibLines_)
void unpack (const FEDRawData &raw, HcalTBEventPosition &pos, HcalTBTiming &timing) const

Private Member Functions

void reconstructTiming (const std::vector< Hit > &hits, HcalTBTiming &timing) const
void reconstructWC (const std::vector< Hit > &hits, HcalTBEventPosition &pos) const
void unpackHits (const FEDRawData &raw, std::vector< Hit > &hits, HcalTBTiming &timing) const

Private Attributes

bool includeUnmatchedHits_
double tdc_convers [161]
double tdc_ped [161]
struct
hcaltb::HcalTBTDCUnpacker::WireChamberRecoData 
wc_ [PLANECOUNT]

Static Private Attributes

static const int PLANECOUNT = 16
static const int WC_CHANNELIDS [PLANECOUNT *3]

Detailed Description

Date:
2010/10/19 18:29:26
Revision:
1.7
Author:
J. Mans, P. Dudero - Minnesota

Definition at line 14 of file HcalTBTDCUnpacker.h.


Constructor & Destructor Documentation

hcaltb::HcalTBTDCUnpacker::HcalTBTDCUnpacker ( bool  include_unmatched_hits)

Definition at line 30 of file HcalTBTDCUnpacker.cc.

                                                                :
  includeUnmatchedHits_(include_unmatched_hits) {
//  setupWC(); reads it from configuration file
}

Member Function Documentation

void hcaltb::HcalTBTDCUnpacker::reconstructTiming ( const std::vector< Hit > &  hits,
HcalTBTiming timing 
) const [private]

Definition at line 168 of file HcalTBTDCUnpacker.cc.

References j, lcBeamCoincidence, lcBeamHalo1, lcBeamHalo2, lcBeamHalo3, lcBeamHalo4, lcLaserFlash, lcMuon1, lcMuon2, lcMuon3, lcQIEPhase, lcScint1, lcScint2, lcScint3, lcScint4, lcTOF1J, lcTOF1S, lcTOF2J, lcTOF2S, lcTriggerTime, lcTTCL1ATime, HcalTBTiming::setHits(), HcalTBTiming::setTimes(), and tdc_ped.

Referenced by unpack().

                                                                      {
  std::vector<Hit>::const_iterator j;
  double trigger_time=0;
  double ttc_l1a_time=0;
  double laser_flash=0;
  double qie_phase=0;
  double TOF1S_time=0;
  double TOF1J_time=0;
  double TOF2S_time=0;
  double TOF2J_time=0;
  
  std::vector<double> m1hits, m2hits, m3hits, s1hits, s2hits, s3hits, s4hits,
                      bh1hits, bh2hits, bh3hits, bh4hits,beam_coinc;

  for (j=hits.begin(); j!=hits.end(); j++) {
    switch (j->channel) {
    case lcTriggerTime:     trigger_time   = j->time-tdc_ped[lcTriggerTime];  break;
    case lcTTCL1ATime:      ttc_l1a_time   = j->time-tdc_ped[lcTTCL1ATime];  break;
    case lcBeamCoincidence: beam_coinc.push_back(j->time-tdc_ped[lcBeamCoincidence]);  break;
    case lcLaserFlash:      laser_flash    = j->time-tdc_ped[lcLaserFlash];  break;
    case lcQIEPhase:        qie_phase      = j->time-tdc_ped[lcQIEPhase];  break;
    case lcMuon1:           m1hits.push_back(j->time-tdc_ped[lcMuon1]); break;
    case lcMuon2:           m2hits.push_back(j->time-tdc_ped[lcMuon2]); break;
    case lcMuon3:           m3hits.push_back(j->time-tdc_ped[lcMuon3]); break;
    case lcScint1:          s1hits.push_back(j->time-tdc_ped[lcScint1]); break;
    case lcScint2:          s2hits.push_back(j->time-tdc_ped[lcScint2]); break;
    case lcScint3:          s3hits.push_back(j->time-tdc_ped[lcScint3]); break;
    case lcScint4:          s4hits.push_back(j->time-tdc_ped[lcScint4]); break;
    case lcTOF1S:           TOF1S_time   = j->time-tdc_ped[lcTOF1S];  break;
    case lcTOF1J:           TOF1J_time   = j->time-tdc_ped[lcTOF1J];  break;
    case lcTOF2S:           TOF2S_time   = j->time-tdc_ped[lcTOF2S];  break;
    case lcTOF2J:           TOF2J_time   = j->time-tdc_ped[lcTOF2J];  break;
    case lcBeamHalo1:       bh1hits.push_back(j->time-tdc_ped[lcBeamHalo1]); break;
    case lcBeamHalo2:       bh2hits.push_back(j->time-tdc_ped[lcBeamHalo2]); break;
    case lcBeamHalo3:       bh3hits.push_back(j->time-tdc_ped[lcBeamHalo3]); break;
    case lcBeamHalo4:       bh4hits.push_back(j->time-tdc_ped[lcBeamHalo4]); break;
    default: break;
    }
  }

  timing.setTimes(trigger_time,ttc_l1a_time,laser_flash,qie_phase,TOF1S_time,TOF1J_time,TOF2S_time,TOF2J_time);
  timing.setHits (m1hits,m2hits,m3hits,s1hits,s2hits,s3hits,s4hits,bh1hits,bh2hits,bh3hits,bh4hits,beam_coinc);

}
void hcaltb::HcalTBTDCUnpacker::reconstructWC ( const std::vector< Hit > &  hits,
HcalTBEventPosition pos 
) const [private]

Definition at line 268 of file HcalTBTDCUnpacker.cc.

References hcaltb::HcalTBTDCUnpacker::WireChamberRecoData::b0, hcaltb::HcalTBTDCUnpacker::WireChamberRecoData::b1, includeUnmatchedHits_, j, plotscripts::mean(), hcaltb::N_SIGMA, PLANECOUNT, HcalTBEventPosition::setChamberHits(), hcaltb::TDC_OFFSET_CONSTANT, wc_, WC_CHANNELIDS, and x.

Referenced by unpack().

                                                                                               {
  // process all planes, looping over all hits...
  const int MAX_HITS=100;
  float hits1[MAX_HITS], hits2[MAX_HITS], hitsA[MAX_HITS];
  int n1,n2,nA,chan1,chan2,chanA;
  
  std::vector<double> x;

  for (int plane=0; plane<PLANECOUNT; plane++) {
    n1=0; n2=0; nA=0;

    std::vector<double> plane_hits;
    double hit_time;

    chan1=WC_CHANNELIDS[plane*3];
    chan2=WC_CHANNELIDS[plane*3+1];
    chanA=WC_CHANNELIDS[plane*3+2];

    for (std::vector<Hit>::const_iterator j=hits.begin(); j!=hits.end(); j++) {
      if (j->channel==chan1 && n1<MAX_HITS) {
        hits1[n1]=j->time-TDC_OFFSET_CONSTANT; n1++;
      }
      if (j->channel==chan2 && n2<MAX_HITS) {
        hits2[n2]=j->time-TDC_OFFSET_CONSTANT; n2++;
      }
      if (j->channel==chanA && nA<MAX_HITS) {
        hitsA[nA]=j->time-TDC_OFFSET_CONSTANT; nA++;
      }
    }
    
    // anode-matched hits
    for (int ii=0; ii<n1; ii++) {
      int jmin=-1, lmin=-1;
      float dsumMin=99999;
      for (int jj=0; jj<n2; jj++) {
        for (int ll=0; ll<nA; ll++) {
          float dsum=fabs(wc_[plane].mean - hits1[ii] - hits2[jj] + 2.0*hitsA[ll]);
          if(dsum<(N_SIGMA*wc_[plane].sigma) && dsum<dsumMin){
            jmin=jj;
            lmin=ll;
            dsumMin=dsum;
           }
        }             
      }
      if (jmin>=0) {
        hit_time = wc_[plane].b0 +
                             wc_[plane].b1 * (hits1[ii]-hits2[jmin]);
        if((plane%2)==0)
                {
                plane_hits.push_back(-hit_time);
                }else{
                plane_hits.push_back(hit_time);
                }
        hits1[ii]=-99999;
        hits2[jmin]=-99999;
        hitsA[lmin]=99999;
      }
    }

    if (includeUnmatchedHits_||plane>9)   // unmatched hits (all pairs get in here)
      for (int ii=0; ii<n1; ii++) {
        if (hits1[ii]<-99990) continue;
        for (int jj=0; jj<n2; jj++) {
          if (hits2[jj]<-99990) continue;
          hit_time = wc_[plane].b0 +
                             wc_[plane].b1 * (hits1[ii]-hits2[jj]);
          if((plane%2)==0)
                {
                plane_hits.push_back(-hit_time);
                }else{
                plane_hits.push_back(hit_time);
                }
        }
      }

    if ((plane%2)==0) x=plane_hits;
    else {
      char chamber='A'+plane/2;
      ep.setChamberHits(chamber,x,plane_hits);
    }
  }
  
}
void hcaltb::HcalTBTDCUnpacker::setCalib ( const std::vector< std::vector< std::string > > &  calibLines_)

Definition at line 34 of file HcalTBTDCUnpacker.cc.

References hcaltb::HcalTBTDCUnpacker::WireChamberRecoData::b0, hcaltb::HcalTBTDCUnpacker::WireChamberRecoData::b1, Exception, i, hcaltb::HcalTBTDCUnpacker::WireChamberRecoData::mean, hcaltb::HcalTBTDCUnpacker::WireChamberRecoData::sigma, findQualityFiles::size, tdc_convers, tdc_ped, and wc_.

Referenced by HcalTBObjectUnpacker::HcalTBObjectUnpacker().

                                                                                    {
        for(int i=0;i<161;i++)
         {
          tdc_ped[i]=0.;tdc_convers[i]=1.;
         }
        for(unsigned int ii=0;ii<calibLines_.size();ii++)
         {
//   TDC configuration
          if(calibLines_[ii][0]=="TDC")
                {
                if(calibLines_[ii].size()==4)
                  {
                  int channel=atoi(calibLines_[ii][1].c_str());
                  tdc_ped[channel]=atof(calibLines_[ii][2].c_str());
                  tdc_convers[channel]=atof(calibLines_[ii][3].c_str());
        //        printf("Got TDC %i ped %f , conversion %f\n",channel, tdc_ped[channel],tdc_convers[channel]);
                  }
                 else
                  {
               throw cms::Exception("Incomplete configuration") << 
                "Wrong TDC configuration format : expected 3 parameters, got "<<calibLines_[ii].size()-1;
                  }
                } // End of the TDCs

//   Wire chambers calibration
          if(calibLines_[ii][0]=="WC")
                {
                if(calibLines_[ii].size()==6)
                  {
                  int plane=atoi(calibLines_[ii][1].c_str());
                  wc_[plane].b0=atof(calibLines_[ii][2].c_str());
                  wc_[plane].b1=atof(calibLines_[ii][3].c_str());
                  wc_[plane].mean=atof(calibLines_[ii][4].c_str());
                  wc_[plane].sigma=atof(calibLines_[ii][5].c_str());
       //         printf("Got WC plane %i b0 %f, b1 %f, mean %f, sigma %f\n",plane, 
       //                wc_[plane].b0,wc_[plane].b1,wc_[plane].mean,wc_[plane].sigma);
                  }
                 else
                  {
               throw cms::Exception("Incomplete configuration") << 
                "Wrong Wire Chamber configuration format : expected 5 parameters, got "<<calibLines_[ii].size()-1;
                  }
                } // End of the Wire Chambers

         } // End of the CalibLines
        }
void hcaltb::HcalTBTDCUnpacker::unpack ( const FEDRawData raw,
HcalTBEventPosition pos,
HcalTBTiming timing 
) const

Definition at line 81 of file HcalTBTDCUnpacker.cc.

References reconstructTiming(), reconstructWC(), and unpackHits().

Referenced by HcalTBObjectUnpacker::produce().

                                                           {
    std::vector<Hit> hits;

    unpackHits(raw, hits, timing);
    
    reconstructWC(hits, pos);
    reconstructTiming(hits, timing);
    
  }
void hcaltb::HcalTBTDCUnpacker::unpackHits ( const FEDRawData raw,
std::vector< Hit > &  hits,
HcalTBTiming timing 
) const [private]

Definition at line 109 of file HcalTBTDCUnpacker.cc.

References hcaltb::HcalTBTDCUnpacker::Hit::channel, FEDRawData::data(), Exception, h, hcaltb::ClassicTDCDataFormat::hits, i, hcaltb::ClassicTDCDataFormat::n_hits, hcaltb::ClassicTDCDataFormat::n_max_hits, hcaltb::CombinedTDCQDCDataFormat::n_qdc_hits, hcaltb::CombinedTDCQDCDataFormat::n_tdc_hits, HcalTBTiming::setV775(), FEDRawData::size(), tdc_convers, and hcaltb::HcalTBTDCUnpacker::Hit::time.

Referenced by unpack().

                                                                                    {
  const ClassicTDCDataFormat* tdc=(const ClassicTDCDataFormat*)raw.data();

  if (raw.size()<3*8) {
    throw cms::Exception("Missing Data") << "No data in the TDC block";
  }

  const unsigned int* hitbase=0;
  unsigned int totalhits=0;

  // old TDC (767)
  if (tdc->n_max_hits!=192) {
    const CombinedTDCQDCDataFormat* qdctdc=(const CombinedTDCQDCDataFormat*)raw.data();
    hitbase=(unsigned int*)(qdctdc);
    hitbase+=6; // header
    hitbase+=qdctdc->n_qdc_hits/2; // two unsigned short per unsigned long
    totalhits=qdctdc->n_tdc_hits&0xFFFF; // mask off high bits

    //    for (unsigned int i=0; i<qdctdc->n_qdc_hits; i++)
    //      printf("QADC: %02d %d\n",i,qdctdc->qdc_values[i]&0xFFF);

  } else {
    hitbase=&(tdc->hits[0]);
    totalhits=tdc->n_hits;
  }

  for (unsigned int i=0; i<totalhits; i++) {
    Hit h;    
    h.channel=(hitbase[i]&0x7FC00000)>>22; // hardcode channel assignment
    h.time=(hitbase[i]&0xFFFFF)*tdc_convers[h.channel]; 
    hits.push_back(h);
    //        printf("V767: %d %f\n",h.channel,h.time);
  }

  // new TDC (V775)
  int v775[32];
  for (int i=0;i<32;i++) v775[i]=-1;
  if (tdc->n_max_hits!=192) {
    const CombinedTDCQDCDataFormat* qdctdc=(const CombinedTDCQDCDataFormat*)raw.data();
    hitbase=(unsigned int*)(qdctdc);
    hitbase+=6; // header
    hitbase+=qdctdc->n_qdc_hits/2; // two unsigned short per unsigned long
    hitbase+=(qdctdc->n_tdc_hits&0xFFFF); // same length
    totalhits=(qdctdc->n_tdc_hits&0xFFFF0000)>>16; // mask off high bits    
    for (unsigned int i=0; i<totalhits; i++) {
      Hit h;    
//      h.channel=129+i;
      h.channel=129+((hitbase[i]&0x3F0000)>>16);
      h.time=(hitbase[i]&0xFFF)*tdc_convers[h.channel] ;
      hits.push_back(h);
      if ( (h.channel-129)<32 ) 
         v775[(h.channel-129)] = (hitbase[i]&0xFFF);
      //      printf("V775: %d %f\n",h.channel,h.time);
    }
  }
  timing.setV775(v775);
}

Member Data Documentation

Definition at line 40 of file HcalTBTDCUnpacker.h.

Referenced by reconstructWC().

const int hcaltb::HcalTBTDCUnpacker::PLANECOUNT = 16 [static, private]

Definition at line 34 of file HcalTBTDCUnpacker.h.

Referenced by reconstructWC().

Definition at line 42 of file HcalTBTDCUnpacker.h.

Referenced by setCalib(), and unpackHits().

double hcaltb::HcalTBTDCUnpacker::tdc_ped[161] [private]

Definition at line 41 of file HcalTBTDCUnpacker.h.

Referenced by reconstructTiming(), and setCalib().

Referenced by reconstructWC(), and setCalib().

const int hcaltb::HcalTBTDCUnpacker::WC_CHANNELIDS [static, private]
Initial value:
 { 
                                                     12, 13, 14, 
                                                     10, 11, 15, 
                                                     22, 23, 24, 
                                                     20, 21, 25, 
                                                     32, 33, 34, 
                                                     30, 31, 35, 
                                                     101, 102, 104, 
                                                     107, 108, 110, 
                                                     113, 114, 116, 
                                                     97, 98, 99, 
                                                    42, 43, -1, 
                                                    44, 60, -1, 
                                                    40, 41, -1, 
                                                    45, 61, -1, 
                                                    52, 53, -1, 
                                                    54, 62, -1  
}

Definition at line 35 of file HcalTBTDCUnpacker.h.

Referenced by reconstructWC().