CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/IORawData/CaloPatterns/src/HtrXmlPatternSet.cc

Go to the documentation of this file.
00001 #include "HtrXmlPatternSet.h"
00002 #include <math.h>
00003 #include <iostream>
00004 
00005 ChannelPattern::ChannelPattern() {
00006   for (int i=0; i<SAMPLES; i++) {
00007     fCReal[i]=0;
00008     fCCoded[i]=0;
00009     fCQuantized[i]=0;
00010   }
00011   m_sample_pos=0;
00012 }
00013 
00014 void ChannelPattern::Fill_by_hand(const HcalElectronicsMap *emap,int pattern_number) {
00015 
00016   for (int iSample=0;iSample<SAMPLES;iSample++) {
00017     fCCoded    [iSample]=0;
00018     fCQuantized[iSample]=0;
00019   }
00020 
00021   int dcc9[NUM_CRATES];
00022   int dcc19[NUM_CRATES];
00023   for (int jCrate=0;jCrate<NUM_CRATES;jCrate++) {
00024     dcc9[jCrate]=-1;
00025     dcc19[jCrate]=-1;
00026   }
00027 
00028   int iCrate;
00029   iCrate=4 ; dcc9[iCrate]=700; dcc19[iCrate]=701;
00030   iCrate=0 ; dcc9[iCrate]=702; dcc19[iCrate]=703;
00031   iCrate=1 ; dcc9[iCrate]=704; dcc19[iCrate]=705;
00032   iCrate=5 ; dcc9[iCrate]=706; dcc19[iCrate]=707;
00033   iCrate=11; dcc9[iCrate]=708; dcc19[iCrate]=709;
00034   iCrate=15; dcc9[iCrate]=710; dcc19[iCrate]=711;
00035   iCrate=17; dcc9[iCrate]=712; dcc19[iCrate]=713;
00036   iCrate=14; dcc9[iCrate]=714; dcc19[iCrate]=715;
00037   iCrate=10; dcc9[iCrate]=716; dcc19[iCrate]=717;
00038   iCrate=2 ; dcc9[iCrate]=718; dcc19[iCrate]=719;
00039   iCrate=9 ; dcc9[iCrate]=720; dcc19[iCrate]=721;
00040   iCrate=12; dcc9[iCrate]=722; dcc19[iCrate]=723;
00041   iCrate=3 ; dcc9[iCrate]=724; dcc19[iCrate]=725;
00042   iCrate=7 ; dcc9[iCrate]=726; dcc19[iCrate]=727;
00043   iCrate=6 ; dcc9[iCrate]=728; dcc19[iCrate]=729;
00044   iCrate=13; dcc9[iCrate]=730; dcc19[iCrate]=731;
00045 
00046   int *dcc=0;
00047   int spigot=-100;
00048   if (m_slot>=2 && m_slot<=8) {
00049     spigot=2*m_slot-m_tb-3;
00050     dcc=dcc9;
00051   }
00052   else if (m_slot>=13 && m_slot<=18) {
00053     spigot=2*m_slot-m_tb-25;
00054     dcc=dcc19;
00055   }
00056   else return;
00057 
00058   int fiber_channel=(m_chan-1)%3;
00059   int fiber=(m_chan-fiber_channel-1)/3 +1;
00060   int dcc_num=dcc[m_crate]-700;
00061 
00062   HcalElectronicsId heid(fiber_channel,fiber,spigot,dcc_num);
00063   heid.setHTR(m_crate,m_slot,m_tb);
00064 
00065   //if (heid.readoutVMECrateId()!=m_crate) std::cout << "crate: " << heid.readoutVMECrateId() << "; " << m_crate << std::endl;
00066   //if (heid.htrSlot()!=m_slot) std::cout << "slot:  " << heid.htrSlot() << "; " << m_slot << std::endl;
00067   //if (heid.htrTopBottom()!=m_tb) std::cout << "tb:    " << heid.htrTopBottom() << "; " << m_tb << std::endl;
00068   //if (heid.htrChanId()!=m_chan) std::cout << "chan:  " << heid.htrChanId() << "; " << m_chan << std::endl;
00069   //
00070   //if (heid.readoutVMECrateId()==14 && heid.htrTopBottom()==0 && heid.htrChanId()==3) {
00071   //  std::cout << heid.rawId() << " " << heid << std::endl;
00072   //}
00073 
00074   try {
00075     const HcalDetId hdid=emap->lookup(heid);
00076 
00077     int etaabs=hdid.ietaAbs();
00078     int phi=hdid.iphi();
00079     int side=hdid.zside();
00080     int depth=hdid.depth();
00081     int subdet=hdid.subdet();
00082 
00084     if (pattern_number==1) {
00085       if (m_crate==2 || m_crate==9 || m_crate==12) return;
00086       //fill only one channel per half-crate
00087       if (m_slot!=2 && m_slot!=13) return;
00088       if (m_tb!=0) return;
00089       if (m_chan!=5) return;
00090   
00091       //put some data here
00092       fCCoded[31]=17;
00093     }
00095     if (pattern_number==2) {
00096       if (depth>1) return;
00097       if (subdet==4 && etaabs<30) return;
00098       
00099       if ((etaabs+2)%4!=0) return;
00100       int i=(etaabs+2)/4;
00101       if (i<1 || i>7) return;
00102       
00103       if ((phi+3)%4!=0) return;
00104       int j=(phi+3)/4;
00105       if (j<1 || j>18) return;
00106       
00107       //add one to BX?
00108       if (side<0) fCCoded[phi+10]=i;
00109       if (side>0) fCCoded[phi+10]=i+16;
00110     }
00112     if (pattern_number==3) {
00113       if (depth>1 || etaabs!=18 || side!=1 || phi!=32) return;
00114       std::cout << "hello" << std::endl;
00115       //add one to BX?
00116       if (side>0) fCCoded[15]=20;
00117     }
00118     
00119   }
00120   catch (...) {return;}
00121 }
00122 
00123 void ChannelPattern::Fill(HtrXmlPatternToolParameters* params,HBHEDigiCollection::const_iterator data) {
00124   //first fill with pedestal value (currently hard-coded to 0)
00125   for (int samples=0; samples<params->m_samples_per_event; samples++) {
00126     int index = m_sample_pos + samples;
00127     if (index>=SAMPLES) continue;
00128 
00129     fCCoded    [index] = 0;
00130     fCQuantized[index] = 0;
00131   }
00132 
00133   //now fill with actual samples
00134   for (int samples=0; samples<data->size(); samples++) {
00135     int index = m_sample_pos + params->m_presamples_per_event - data->presamples() + samples;
00136     if (index<m_sample_pos || 
00137         index>=(m_sample_pos+params->m_samples_per_event) ||
00138         index>=SAMPLES) continue;
00139 
00140     fCCoded    [index] = data->sample(samples).adc();
00141     fCQuantized[index] = data->sample(samples).nominal_fC();
00142   }
00143   
00144   m_sample_pos+=params->m_samples_per_event;
00145 }
00146 
00147 void ChannelPattern::Fill(HtrXmlPatternToolParameters* params,HFDigiCollection::const_iterator data) {
00148   //first fill with pedestal value (currently hard-coded to 0)
00149   for (int samples=0; samples<params->m_samples_per_event; samples++) {
00150     int index = m_sample_pos + samples;
00151     if (index>=SAMPLES) continue;
00152 
00153     fCCoded    [index] = 0;
00154     fCQuantized[index] = 0;
00155   }
00156 
00157   //now fill with actual samples
00158   for (int samples=0; samples<data->size(); samples++) {
00159     int index = m_sample_pos + params->m_presamples_per_event - data->presamples() + samples;
00160     if (index<m_sample_pos || 
00161         index>=(m_sample_pos+params->m_samples_per_event) ||
00162         index>=SAMPLES) continue;
00163 
00164     fCCoded    [index] = data->sample(samples).adc();
00165     fCQuantized[index] = data->sample(samples).nominal_fC();
00166   }
00167   
00168   m_sample_pos+=params->m_samples_per_event;
00169 }
00170 
00171 void ChannelPattern::Fill(HtrXmlPatternToolParameters* params,HODigiCollection::const_iterator data) {
00172   //first fill with pedestal value (currently hard-coded to 0)
00173   for (int samples=0; samples<params->m_samples_per_event; samples++) {
00174     int index = m_sample_pos + samples;
00175     if (index>=SAMPLES) continue;
00176 
00177     fCCoded    [index] = 0;
00178     fCQuantized[index] = 0;
00179   }
00180 
00181   //now fill with actual samples
00182   for (int samples=0; samples<data->size(); samples++) {
00183     int index = m_sample_pos + params->m_presamples_per_event - data->presamples() + samples;
00184     if (index<m_sample_pos || 
00185         index>=(m_sample_pos+params->m_samples_per_event) ||
00186         index>=SAMPLES) continue;
00187 
00188     fCCoded    [index] = data->sample(samples).adc();
00189     fCQuantized[index] = data->sample(samples).nominal_fC();
00190   }
00191   
00192   m_sample_pos+=params->m_samples_per_event;
00193 }
00194 
00195 HalfHtrData::HalfHtrData(int crate, int slot, int tb) {
00196   for (int i=0; i<24; i++)
00197     m_patterns[i].setLoc(crate,slot,tb,i+1);
00198   m_crate=crate;
00199   m_slot=slot;
00200   m_tb=tb;
00201   //these are set later with map data
00202   m_dcc=0;
00203   m_spigot=0;
00204 }
00205 
00206 CrateData::CrateData(int crate, int slotsActive[ChannelPattern::NUM_SLOTS]) {
00207   for (int slot=0; slot<ChannelPattern::NUM_SLOTS; slot++) {
00208     for (int tb=0;tb<2;tb++) {
00209       if (slotsActive[slot]) m_slotsDoubled[slot][tb] = new HalfHtrData(crate,slot,tb);
00210       else                   m_slotsDoubled[slot][tb] = 0;
00211     }
00212   }
00213 }
00214 
00215 CrateData::~CrateData() {
00216   for (int slot=0; slot<ChannelPattern::NUM_SLOTS; slot++) {
00217     for (int tb=0;tb<2;tb++) {
00218       if (m_slotsDoubled[slot][tb]) delete m_slotsDoubled[slot][tb];
00219     }
00220   }
00221 }
00222 
00223 HalfHtrData* CrateData::getHalfHtrData(int slot, int tb) {
00224   if ( slot>=0 && slot<ChannelPattern::NUM_SLOTS && (tb==0 || tb==1) ) return m_slotsDoubled[slot][tb];
00225   else return 0;
00226 }
00227 
00228 HtrXmlPatternSet::HtrXmlPatternSet(int cratesActive[ChannelPattern::NUM_CRATES], int slotsActive[ChannelPattern::NUM_SLOTS]) {
00229   for (int crate=0; crate<ChannelPattern::NUM_CRATES; crate++) {
00230     if (cratesActive[crate]) m_crates[crate] = new CrateData(crate,slotsActive);
00231     else                     m_crates[crate] = 0;
00232   }
00233 }
00234 
00235 HtrXmlPatternSet::~HtrXmlPatternSet() {
00236   for (int crate=0; crate<ChannelPattern::NUM_CRATES; crate++) {
00237     if (m_crates[crate]) delete m_crates[crate];
00238   }
00239 }
00240 
00241 CrateData* HtrXmlPatternSet::getCrate(int crate) {
00242   if (crate>=0 && crate<ChannelPattern::NUM_CRATES) return m_crates[crate];
00243   else return 0;
00244 }