--- PamVMC/cal/src/PamVMCCaloDig.cxx 2009/02/19 16:00:14 1.1 +++ PamVMC/cal/src/PamVMCCaloDig.cxx 2010/01/20 11:34:14 1.6 @@ -395,7 +395,7 @@ cout<<"Digitizing CALO..."<Gaus((Double_t)pedestal,(Double_t)rms); + pedenoise = frandom->Gaus((Double_t)pedestal,(Double_t)rms); // // Sum all contribution // @@ -613,12 +613,297 @@ void PamVMCCaloDig::DigitizeCaloCompress(){ + // + // CompressMode implemented by C.Pizzolotto october 2009 + // + // some variables + // + Float_t ens = 0.; + UInt_t adcsig = 0; + UInt_t adcbase = 0; + UInt_t adc[16]; + Float_t rms = 0.; + Double_t pedenoise=0.; + Float_t pedestal = 0.; + UInt_t pedround[16]; + Float_t thres[16]; + Float_t goodflag[16]; + UInt_t min_adc = 0x7FFF; + UInt_t min_adc_ch = 0; + UInt_t l = 0; + UInt_t lpl = 0; + Int_t plane = 0; + Int_t pre; + Int_t npre = 0; // number of pre between 0-5 + UInt_t strip = 0; + UInt_t remainder; + Float_t basesum=0.; + Float_t basenof=0.; + UInt_t baseline=0; + UInt_t fSecPointer = 0; + UInt_t fNofTStripsPointer = 0; + UInt_t NofTransmittedStrips = 0 ; + Int_t fCALOlength; + UShort_t DataCALO[9040]; //TOO LONG? 4264ma non e' vero che e' cosi' lungo...... CECI CECI CECI + fData.clear(); + static const Float_t CALOGeV2MIPratio = 0.0001059994; + // + // clean the data structure + // + memset(adc, 0,sizeof(adc)); + memset(pedround, 0,sizeof(pedround)); + memset(thres, 0,sizeof(thres)); + memset(goodflag, 0,sizeof(goodflag)); + // + memset(DataCALO,0,sizeof(UShort_t)*9040); + // + // Header of the four sections + // + fSecCalo[0] = 0xEA00; // XE + fSecCalo[1] = 0xF100; // XO + fSecCalo[2] = 0xF600; // YE + fSecCalo[3] = 0xED00; // YO + // + // here comes raw data + // + fCALOlength = 0; + // + for (Int_t sec=0; sec < 4; sec++){ // + // + // sec = 0 -> XE 1 -> XO 2-> YE 3 -> YO + // + l = 0; // XE and XO are Y planes + if ( sec < 2 ) l = 1; // while YE and YO are X planes + // + fSecPointer = fCALOlength; + // + // First of all we have section header and packet length + // + DataCALO[fCALOlength] = fSecCalo[sec]; + fCALOlength++; + DataCALO[fCALOlength] = 0; // Unknown: length must be calculated on fly + fCALOlength++; + // + // selftrigger coincidences - in the future we should add here some code to simulate timing response of pre-amplifiers + // + for (Int_t autoplane=0; autoplane < 7; autoplane++){ + DataCALO[fCALOlength] = 0x0000; + fCALOlength++; + }; + // + // second level trigger + // + DataCALO[fCALOlength] = 0x0000; + fCALOlength++; + // + // Nof strips transmetted: must be calculated on fly + // + fNofTStripsPointer = fCALOlength; + DataCALO[fCALOlength] = 0x0000; + fCALOlength++; + NofTransmittedStrips=0; + // + // Identifier of calo data + // + DataCALO[fCALOlength] = 0xCA50; + fCALOlength++; + DataCALO[fCALOlength] = 0xCA50; + fCALOlength++; + DataCALO[fCALOlength] = 0xFFFF; // compresso + fCALOlength++; + // + // Pedestal threashold table checksum + // + DataCALO[fCALOlength] = 0x0000; + fCALOlength++; + // + // Calorimeter event counter + // + DataCALO[fCALOlength] = Getevtcalo() ; + fCALOlength++; + cout<<" evtcalo?"<5) npre=0; + } + } else { + if ( (strip % 16) == 0) { + npre++; + if(npre>5) npre=0; + } + } + // + ens = this->GetCaloErel(sec,plane,strip); + // + // convert it into ADC channels + // + adcsig = int(ens*fCalomip[l][lpl][strip]/CALOGeV2MIPratio); + // + // sum baselines + // + adcbase = (UInt_t)fcalbase[sec][plane][npre]; + // + // add noise and pedestals + // + pedestal = fcalped[sec][plane][strip]; + rms = fcalrms[sec][plane][strip]/4.; + // + // Add random gaussian noise of RMS rms and Centered in the pedestal + // + pedenoise = frandom->Gaus((Double_t)pedestal,(Double_t)rms); + // + // Sum all contribution + // + adc[ch] = adcsig + adcbase + (Int_t)round(pedenoise); + // + // Signal saturation + // + if ( adc[ch] > 0x7FFF ) adc[ch] = 0x7FFF; + // + // save infos + // + pedround[ch] = (Int_t)round(pedestal) ; + thres[ch] = ( fcalthr[sec][plane][npre] ); + goodflag[ch] = ( fcalgood[sec][plane][strip] ); // if bad should be 255 + // + // Find minimum adc in this preamp + // + if ( goodflag[ch]==0 && (adc[ch]-pedround[ch])=9 + // + { + if(sec==1) { + DataCALO[fCALOlength] = 0x0800 + ipre ; + } else { + DataCALO[fCALOlength] = 0x0800 + pre; + } + fCALOlength++; + // + // calculate baseline and save it + // + basenof=0; + baseline=0; + basesum=0; + for (Int_t ch=0; ch <16; ch++){ + if( goodflag[ch]==0 && ( (adc[ch]-pedround[ch])<(min_adc+thres[ch]) ) ) + { + basesum = basesum + (adc[ch]-pedround[ch]) ; + basenof++; + } + }; + baseline = (Int_t)round( basesum / basenof ); + DataCALO[fCALOlength] = baseline; + fCALOlength++; + // + // Transmit only channels > (min_adc+thres[ch]) + // + for (Int_t ch=0; ch <16; ch++){ + if ( (adc[ch]-pedround[ch] )>(min_adc+thres[ch]) ) + { + DataCALO[fCALOlength] = ch; + fCALOlength++; + DataCALO[fCALOlength] = adc[ch]; + fCALOlength++; + NofTransmittedStrips++; + } + }; + } // close if nof_chs_below + }; // close preampl loop + // + // Write the length + // + DataCALO[fSecPointer+1] = fCALOlength-fSecPointer+1 ; + DataCALO[fNofTStripsPointer] = NofTransmittedStrips ; + // + // here we calculate and save the CRC + // + Short_t CRC = 0; + for (UInt_t i=0; i<(fCALOlength-fSecPointer); i++){ + CRC=crc(CRC,DataCALO[i+fSecPointer]); + }; + DataCALO[fCALOlength] = (UShort_t)CRC; + fCALOlength++; + // + }; // close sec loop + + Incrementevtcalo(); + + for (Int_t i = 0; iDigitizeCaloRaw(); return; + + + } void PamVMCCaloDig::DigitizeCaloFull(){