--- PamelaDigitizer/DigitizeCalo.cxx 2008/10/15 14:03:16 1.2 +++ PamelaDigitizer/DigitizeCalo.cxx 2014/01/17 13:08:40 1.5 @@ -280,13 +280,13 @@ // first of all load the MIP to ADC conversion values // stringstream calfile; - Int_t error = 0; + // Int_t error = 0; GL_PARAM *glparam = new GL_PARAM(); // // determine where I can find calorimeter ADC to MIP conversion file // - error = 0; - error = glparam->Query_GL_PARAM(3,101,fDbc); + // error = 0; + glparam->Query_GL_PARAM(3,101,fDbc); // calfile.str(""); calfile << glparam->PATH.Data() << "/"; @@ -348,8 +348,8 @@ printf("\n Section %i : using file %s calibration at entry %i: \n",s,fcalname.Data(),calibno); // } else { - error = 0; - error = glparam->Query_GL_PARAM(1,104,fDbc); + // error = 0; + glparam->Query_GL_PARAM(1,104,fDbc); // calfile.str(""); calfile << glparam->PATH.Data() << "/"; @@ -377,9 +377,6 @@ void Digitizer::DigitizeCALO() { // - fModCalo = 0; // 0 is RAW, 1 is COMPRESS, 2 is FULL ####@@@@ should be given as input par @@@@#### - // - // // fCALOlength = 0; // reset total dimension of calo data // @@ -601,46 +598,296 @@ // }; + void Digitizer::DigitizeCALOCOMPRESS() { // - printf(" COMPRESS MODE STILL NOT IMPLEMENTED! \n"); + // CompressMode: implemented by C.Pizzolotto october 2009 // - this->DigitizeCALORAW(); - return; + // 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 ; // + // clean the data structure // - fSecCalo[0] = 0xEA00; - fSecCalo[1] = 0xF100; - fSecCalo[2] = 0xF600; - fSecCalo[3] = 0xED00; + memset(adc, 0,sizeof(adc)); + memset(pedround, 0,sizeof(pedround)); + memset(thres, 0,sizeof(thres)); + memset(goodflag, 0,sizeof(goodflag)); // - // length of the data in DSP mode must be calculated on fly during digitization + memset(fDataCALO,0,sizeof(UShort_t)*fCALObuffer); // - memset(fSecCALOLength,0x0,4*sizeof(UShort_t)); + // 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 // - Int_t en = 0; + fCALOlength = 0; // - for (Int_t sec=0; sec < 4; sec++){ - fDataCALO[en] = fSecCalo[sec]; - en++; - fDataCALO[en] = fSecCALOLength[sec]; - en++; - for (Int_t plane=0; plane < 11; plane++){ - for (Int_t strip=0; strip < 11; strip++){ - fDataCALO[en] = 0x0; - en++; + 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 + // + fDataCALO[fCALOlength] = fSecCalo[sec]; + fCALOlength++; + fDataCALO[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++){ + fDataCALO[fCALOlength] = 0x0000; + fCALOlength++; + }; + // + // second level trigger + // + fDataCALO[fCALOlength] = 0x0000; + fCALOlength++; + // + // Nof strips transmetted: must be calculated on fly + // + fNofTStripsPointer = fCALOlength; + fDataCALO[fCALOlength] = 0x0000; + fCALOlength++; + NofTransmittedStrips=0; + // + // Identifier of calo data + // + fDataCALO[fCALOlength] = 0xCA50; + fCALOlength++; + fDataCALO[fCALOlength] = 0xCA50; + fCALOlength++; + fDataCALO[fCALOlength] = 0xFFFF; // compress mode + fCALOlength++; + // + // Pedestal threashold table checksum + // + fDataCALO[fCALOlength] = 0x0000; + fCALOlength++; + // + // Calorimeter event counter + // + fDataCALO[fCALOlength] = fEvent; + fCALOlength++; + // + // Start here with data + // + plane=-1; + npre =-1; + for (Int_t ipre=0; ipre< 66; ipre++){ // (11 planes*6 preampl) + // + // which plane + if ( (ipre % 6) == 0) { + plane++; + } + // + pre=ipre; + // + // Adjust counter for plane X0 + if (sec==1) // conto invertito + { + remainder = pre % 6 ; + pre = ((plane+1)*6) - remainder ; + } + // + if ( sec == 0 || sec == 3 ) lpl = plane * 2; + if ( sec == 1 || sec == 2 ) lpl = (plane * 2) + 1; + // + // initialize min_adc + min_adc = 0x7FFF; + for (Int_t ch=0; ch <16; ch++){ // 16 channels each pre + // + // strip number + // + strip=((pre-(6*plane))*16)+ch; + if(sec==1) strip = ((pre-(6*plane))*16)+(15-ch)-16; + // + // calculate npre: a number between 0-5 + // + if( sec==1) { + if ( ((95-strip) % 16) == 0) { + npre++; + if(npre>5) npre=0; + } + } else { + if ( (strip % 16) == 0) { + npre++; + if(npre>5) npre=0; + } + } + // + // get the energy in GeV from the simulation for that strip + // + ens = this->GetCALOen(sec,plane,strip); + // + // convert it into ADC channels + // + adcsig = int(ens*fCalomip[l][lpl][strip]/fCALOGeV2MIPratio); + // + // 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 = gRandom->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) { + fDataCALO[fCALOlength] = 0x0800 + ipre ; + } else { + fDataCALO[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 ); + fDataCALO[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]) ) + { + fDataCALO[fCALOlength] = ch; + fCALOlength++; + fDataCALO[fCALOlength] = adc[ch]; + fCALOlength++; + NofTransmittedStrips++; + }; + }; + }; // close if nof_chs_below + }; // close preampl loop + // + // Write the correct length + // + fDataCALO[fSecPointer+1] = (fCALOlength-fSecPointer+1)-2 ; + // total length of the packet: -2: because the words with status and length are not included + fDataCALO[fNofTStripsPointer] = NofTransmittedStrips ; + // + // here we calculate and save the CRC + // + Short_t CRC = 0; + fDataCALO[fCALOlength] =0 ; + for (UInt_t i=0; i<(fCALOlength-fSecPointer); i++){ + CRC=crc(CRC,fDataCALO[i+fSecPointer]); }; - }; - // -}; + fDataCALO[fCALOlength] = (UShort_t)CRC; + fCALOlength++; + // + }; // close sec loop + // The End +} + + void Digitizer::DigitizeCALOFULL() { // - printf(" FULL MODE STILL NOT IMPLEMENTED! \n"); + printf(" FULL MODE STILL NOT IMPLEMENTED! %d\n",fEvent); // this->DigitizeCALORAW(); return; @@ -671,4 +918,4 @@ }; }; // -}; +}