X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=VZERO%2FAliVZERODigitizer.cxx;h=f73ebca0faed044f508c817c565205e0dd1ca3a0;hb=729ec9828c82c2b964b17723142852e423d7fcd2;hp=148850517b429b4eb2bb0130bc2ec23b8d2e4748;hpb=2d7933c7f97416fa0d50619854d2f62969b25c43;p=u%2Fmrichter%2FAliRoot.git diff --git a/VZERO/AliVZERODigitizer.cxx b/VZERO/AliVZERODigitizer.cxx index 148850517b4..f73ebca0fae 100644 --- a/VZERO/AliVZERODigitizer.cxx +++ b/VZERO/AliVZERODigitizer.cxx @@ -13,74 +13,86 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -//_________________________________________________________________________ -// -// This constructs Digits out of Hits -// +/* $Id$ */ + +///_________________________________________________________________________ +/// +/// This class constructs Digits out of Hits +/// +/// // --- Standard library --- -#include -#include // --- ROOT system --- -#include -#include -#include -#include +#include #include -#include +#include +#include +#include +#include // --- AliRoot header files --- #include "AliVZEROConst.h" #include "AliRun.h" #include "AliVZERO.h" #include "AliVZEROhit.h" -#include "AliHit.h" -#include "AliDetector.h" #include "AliRunLoader.h" #include "AliLoader.h" -#include "AliConfig.h" #include "AliRunDigitizer.h" -#include "AliDigitizer.h" -#include "AliHeader.h" -#include "AliStack.h" -#include "AliVZERODigitizer.h" +#include "AliCDBManager.h" +#include "AliCDBStorage.h" +#include "AliCDBEntry.h" +#include "AliVZEROCalibData.h" + #include "AliVZEROdigit.h" -#include "AliMC.h" +#include "AliVZERODigitizer.h" ClassImp(AliVZERODigitizer) AliVZERODigitizer::AliVZERODigitizer() + :AliDigitizer(), + fCalibData(GetCalibData()), + fPhotoCathodeEfficiency(0.18), + fPMVoltage(768.0), + fPMGain(TMath::Power((fPMVoltage / 112.5) ,7.04277)), + fNdigits(0), + fDigits(0) + { - if (!fDigits) fDigits = new TClonesArray("AliVZEROdigit", 1000); + // default constructor + +// fNdigits = 0; +// fDigits = 0; +// +// fPhotoCathodeEfficiency = 0.18; +// fPMVoltage = 768.0; +// fPMGain = TMath::Power((fPMVoltage / 112.5) ,7.04277); - fNevents = 0 ; - fDigits = 0 ; - fNdigits = 0; - fHits = 0 ; - fRunLoader = 0; - - fPhotoCathodeEfficiency = 0.18; - fPMVoltage = 768.0; - fPMGain = TMath::Power((fPMVoltage / 112.5) ,7.04277); +// fCalibData = GetCalibData(); } //____________________________________________________________________________ AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager) - :AliDigitizer(manager) - + :AliDigitizer(manager), + fCalibData(GetCalibData()), + fPhotoCathodeEfficiency(0.18), + fPMVoltage(768.0), + fPMGain(TMath::Power((fPMVoltage / 112.5) ,7.04277)), + fNdigits(0), + fDigits(0) + { // constructor - fNevents = 0; - fDigits = 0; - fNdigits = 0; - fHits = 0; - fRunLoader = 0; +// fNdigits = 0; +// fDigits = 0; +// +// fPhotoCathodeEfficiency = 0.18; +// fPMVoltage = 768.0; +// fPMGain = TMath::Power( (fPMVoltage / 112.5) ,7.04277 ); + +// fCalibData = GetCalibData(); - fPhotoCathodeEfficiency = 0.18; - fPMVoltage = 768.0; - fPMGain = TMath::Power( (fPMVoltage / 112.5) ,7.04277 ); } //____________________________________________________________________________ @@ -91,148 +103,235 @@ ClassImp(AliVZERODigitizer) if (fDigits) { fDigits->Delete(); delete fDigits; - fDigits=0; } + fDigits=0; + } } -//____________________________________________________________________________ -void AliVZERODigitizer::OpengAliceFile(const char *file) +//_____________________________________________________________________________ +Bool_t AliVZERODigitizer::Init() { - // Loads galice.root file and corresponding header, kinematics - // hits and digits - - fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(), - "UPDATE"); - - if (!fRunLoader) - { - Error("Open","Can not open session for file %s.",file); - } - - fRunLoader->LoadgAlice(); - fRunLoader->LoadHeader(); - fRunLoader->LoadKinematics(); + // Initialises the digitizer - gAlice = fRunLoader->GetAliRun(); - - if (gAlice) - { printf(" "); - printf("AliRun object found on file.\n");} - else - { printf(" "); - printf("Could not find AliRun object.\n");} - - // Initialise Hit and Digit arrays - fHits = new TClonesArray ("AliVZEROhit", 1000); + // Initialises the Digit array fDigits = new TClonesArray ("AliVZEROdigit", 1000); - - fVZERO = (AliVZERO*) gAlice->GetDetector("VZERO"); - fVZEROLoader = fRunLoader->GetLoader("VZEROLoader"); - if (fVZEROLoader == 0x0){ - cerr<<"Hits2Digits : Can not find VZERO or VZEROLoader\n";} - - Int_t retval = fVZEROLoader->LoadHits("read"); - if (retval){ - Error("Open","Error occured while loading hits... Exiting."); - return;} - - fVZEROLoader->LoadDigits("recreate"); + // TGeoHMatrix *im = AliGeomManager::GetMatrix("VZERO/V0C"); + // im->Print(); + + return kTRUE; } //____________________________________________________________________________ -void AliVZERODigitizer::Exec() - { +void AliVZERODigitizer::Exec(Option_t* /*option*/) +{ + // Creates digits from hits + + Int_t map[80]; // 48 values on V0C + 32 on V0A + Int_t adc[64]; // 32 PMs on V0C + 32 PMs on V0A + Float_t time[80], time_ref[80], time2[64]; + Float_t adc_gain[80]; + Float_t adc_pedestal[64],adc_sigma[64]; + fNdigits = 0; + Float_t PMGain_smeared[64]; + Float_t cPM[80]; + + // Smearing of the PM tubes intrinsic characteristics + + for(Int_t ii=0; ii<64; ii++) { + PMGain_smeared[ii] = gRandom->Gaus(fPMGain, fPMGain/5); } + + // Retrieval of ADC gain values and pedestal information from local CDB + // I use only the first 64th values of the calibration array in CDB + // as I have no beam burst structure - odd or even beam burst number + + // Reminder : We have 16 scintillating cells mounted on 8 PMs + // on Ring 3 and Ring 4 in V0C - added to produce ADC outputs + // on these rings... + + for(Int_t i=0; i<16; i++) { + adc_gain[i] = fCalibData->GetGain(i); + cPM[i] = fPhotoCathodeEfficiency * PMGain_smeared[i];} + + for(Int_t j=16; j<48; j=j+2) { + Int_t i=(j+17)/2; + adc_gain[j] = fCalibData->GetGain(i); + adc_gain[j+1] = fCalibData->GetGain(i); + cPM[j] = fPhotoCathodeEfficiency * PMGain_smeared[i]; + cPM[j+1] = fPhotoCathodeEfficiency * PMGain_smeared[i]; } + + for(Int_t i=48; i<80; i++){ + adc_gain[i] = fCalibData->GetGain(i-16); + cPM[i] = fPhotoCathodeEfficiency * PMGain_smeared[i-16];}; + + for(Int_t i=0; i<64; i++){ adc_pedestal[i] = fCalibData->GetPedestal(i); + adc_sigma[i] = fCalibData->GetSigma(i); }; + +// for(Int_t i=0; i<64; i++) { printf(" i = %d pedestal = %f sigma = %f \n\n", +// i, adc_pedestal[i], adc_sigma[i] );} + + AliRunLoader* outRunLoader = + AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); + if (!outRunLoader) { + Error("Exec", "Can not get output Run Loader"); + return;} + + AliLoader* outLoader = outRunLoader->GetLoader("VZEROLoader"); + if (!outLoader) { + Error("Exec", "Can not get output VZERO Loader"); + return;} - fNdigits = 0; - Int_t N; - Int_t map[96]; - Int_t cell = 0; - Float_t cPM = fPhotoCathodeEfficiency * fPMGain; - - for(Int_t i=0; i<96; i++) map[i] = 0; - - fNevents = (Int_t) fRunLoader->TreeE()->GetEntries (); - printf(" Number of events in file = %d \n", fNevents); + outLoader->LoadDigits("update"); + if (!outLoader->TreeD()) outLoader->MakeTree("D"); + outLoader->MakeDigitsContainer(); + TTree* treeD = outLoader->TreeD(); + Int_t bufsize = 16000; + treeD->Branch("VZERODigit", &fDigits, bufsize); - for (Int_t ievent = 0; ievent < fNevents; ievent++){ + for (Int_t iInput = 0; iInput < fManager->GetNinputs(); iInput++) { + AliRunLoader* runLoader = + AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput)); + AliLoader* loader = runLoader->GetLoader("VZEROLoader"); + if (!loader) { + Error("Exec", "Can not get VZERO Loader for input %d", iInput); + continue;} - for(Int_t i=0; i<96; i++) map[i] = 0; - - fRunLoader->GetEvent(ievent); + if (!runLoader->GetAliRun()) runLoader->LoadgAlice(); + + AliVZERO* vzero = (AliVZERO*) runLoader->GetAliRun()->GetDetector("VZERO"); + if (!vzero) { + Error("Exec", "No VZERO detector for input %d", iInput); + continue;} - fTreeH = fVZEROLoader->TreeH(); - if (fTreeH == 0x0) - { Error("Exec","Cannot get TreeH"); - return; } + loader->LoadHits(); + TTree* treeH = loader->TreeH(); + if (!treeH) { + Error("Exec", "Cannot get TreeH for input %d", iInput); + continue; } + + for(Int_t i=0; i<80; i++) {map[i] = 0; time[i] = 0.0;} + + TClonesArray* hits = vzero->Hits(); - fTreeD = fVZEROLoader->TreeD(); - if (fTreeD == 0x0) - { fVZEROLoader->MakeTree("D"); - fVZEROLoader->MakeDigitsContainer(); - fTreeD = fVZEROLoader->TreeD(); } - - Int_t bufsize = 16000; - fTreeD->Branch("VZERODigit", &fDigits, bufsize); - -// Now make Digits from hits +// Now makes Digits from hits + + Int_t nTracks = (Int_t) treeH->GetEntries(); + for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) { + for (Int_t i=0; i<80; i++) {time_ref[i] = 999999.0;} + vzero->ResetHits(); + treeH->GetEvent(iTrack); + Int_t nHits = hits->GetEntriesFast(); + for (Int_t iHit = 0; iHit < nHits; iHit++) { + AliVZEROhit* hit = (AliVZEROhit *)hits->UncheckedAt(iHit); + Int_t nPhot = hit->Nphot(); + Int_t cell = hit->Cell(); + map[cell] += nPhot; + Float_t dt_scintillator = gRandom->Gaus(0,0.7); + Float_t t = dt_scintillator + 1e9*hit->Tof(); + if (t > 0.0) { + if(t < time_ref[cell]) time_ref[cell] = t; + time[cell] = TMath::Min(t,time_ref[cell]); } + } // hit loop + } // track loop + + loader->UnloadHits(); - if (fVZERO) - { - fHits = fVZERO->Hits(); + } // input loop + +// Now builds the scintillator cell response (80 cells i.e. 80 responses) - Int_t ntracks = (Int_t) fTreeH->GetEntries (); -// printf(" Number of Tracks in the TreeH = %d \n", ntracks); - for (Int_t track = 0; track < ntracks; track++) - { - gAlice->ResetHits (); - fTreeH->GetEvent(track); - fParticle = fRunLoader->Stack()->Particle(track); - Int_t nhits = fHits->GetEntriesFast(); - for (Int_t hit = 0; hit < nhits; hit++) - { - fVZEROHit = (AliVZEROhit *)fHits->UncheckedAt(hit); - N = fVZEROHit->Nphot(); - cell = fVZEROHit->Cell(); - map[cell] = map[cell] + N; - } // hit loop - } // track loop - - Int_t icount = 0; - - for(Int_t i=0; i<96; i++) { - Float_t q1 = Float_t ( map[i] )* cPM * kQe; - Float_t noise = gRandom->Gaus(10.5,3.22); - Float_t PMresponse = q1/kC*TMath::Power(ktheta/kthau,1/(1-ktheta/kthau)) - + noise*1e-3; - map[i] = Int_t( PMresponse * 200.0); - if(map[i] > 3) { - icount++; -// printf(" Event, cell, adc = %d %d %d\n", ievent, i, map[i]); - AddDigit(ievent, i, map[i]);} - } - - fTreeD->Reset(); - fTreeD->Fill(); - ResetDigit(); - fVZEROLoader->WriteDigits("OVERWRITE"); - fVZEROLoader->UnloadDigits(); - } // VZERO loop - } //event loop + for (Int_t i=0; i<80; i++) { + Float_t q1 = Float_t ( map[i] )* cPM[i] * kQe; + Float_t noise = gRandom->Gaus(10.5,3.22); + Float_t pmResponse = q1/kC*TMath::Power(ktheta/kthau,1/(1-ktheta/kthau)) + + noise*1e-3; + map[i] = Int_t( pmResponse * adc_gain[i]); + if(map[i] > (110/2)) {map[i] = Int_t(gRandom->Gaus(map[i], 110/6));} + } + +// Now transforms 80 cell responses into 64 photomultiplier responses +// Also adds the ADC pedestals taken out of the calibration data base + + for (Int_t j=0; j<16; j++){ + adc[j] = static_cast(map [j] + gRandom->Gaus(adc_pedestal[j], adc_sigma[j])); + time2[j]= time[j];} + + for (Int_t j=48; j<80; j++){ + adc[j-16] = static_cast(map [j] + + gRandom->Gaus(adc_pedestal[j-16],adc_sigma[j-16])); + time2[j-16]= time[j]; } + + for (Int_t j=0; j<16; j++){ + adc[16+j] = static_cast(map [16+2*j]+ map [16+2*j+1] + + gRandom->Gaus(adc_pedestal[16+j], adc_sigma[16+j])); + Float_t min_time = TMath::Min(time [16+2*j],time [16+2*j+1]); + time2[16+j] = min_time; + if(min_time==0.0){time2[16+j]=TMath::Max(time[16+2*j],time[16+2*j+1]);} + } + + +// Now add digits to the digit Tree + + for (Int_t i=0; i<64; i++) { + if(adc[i] > 0) { +// printf(" Event, cell, adc, tof = %d %d %d %f\n", +// outRunLoader->GetEventNumber(),i, map[i], time2[i]*10.0); +// multiply by 10 to have 100 ps per channel : + AddDigit(i, adc[i], Int_t(time2[i]*10.0)) ;} + } + + treeD->Fill(); + outLoader->WriteDigits("OVERWRITE"); + outLoader->UnloadDigits(); + ResetDigit(); } //____________________________________________________________________________ -void AliVZERODigitizer::AddDigit(Int_t eventnumber, Int_t cellnumber, Int_t adc) +void AliVZERODigitizer::AddDigit(Int_t PMnumber, Int_t adc, Int_t time) { // Adds Digit TClonesArray &ldigits = *fDigits; - new(ldigits[fNdigits++]) AliVZEROdigit(eventnumber,cellnumber,adc); + new(ldigits[fNdigits++]) AliVZEROdigit(PMnumber,adc,time); } //____________________________________________________________________________ void AliVZERODigitizer::ResetDigit() { +// // Clears Digits +// fNdigits = 0; - if (fDigits) fDigits->Clear(); + if (fDigits) fDigits->Delete(); +} + +//____________________________________________________________________________ +AliVZEROCalibData* AliVZERODigitizer::GetCalibData() const + +{ + AliCDBManager *man = AliCDBManager::Instance(); + + AliCDBEntry *entry=0; + + entry = man->Get("VZERO/Calib/Data"); + +// if(!entry){ +// AliWarning("Load of calibration data from default storage failed!"); +// AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)"); +// Int_t runNumber = man->GetRun(); +// entry = man->GetStorage("local://$ALICE_ROOT") +// ->Get("VZERO/Calib/Data",runNumber); +// +// } + + // Retrieval of data in directory VZERO/Calib/Data: + + + AliVZEROCalibData *calibdata = 0; + + if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject(); + if (!calibdata) AliFatal("No calibration data from calibration database !"); + + return calibdata; + } +