+ // delete
+ delete []gainmeanSM;
+ delete []vdriftmeanSM;
+ delete []exbmeanSM;
+
+ // Security
+ // for(Int_t sm=0; sm < 18; sm++) {
+ // Int_t counter = 0;
+ // for(Int_t det = 0; det < 30; det++){
+ // Int_t detector = sm*30+det;
+ // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
+ // }
+ // if(counter >= 20) {
+ // for(Int_t det = 0; det < 30; det++){
+ // Int_t detector = sm*30+det;
+ // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
+ // }
+ // }
+ // }
+
+ fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
+ return kTRUE;
+
+ }
+
+
+ //________________________________________________________________________________________________
+ void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
+ //
+ // Correct from the gas gain used afterwards
+ //
+ AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
+ if(!calDetGain) return;
+
+ // Calculate mean
+ Double_t mean = 0.0;
+ Int_t nbdet = 0;
+
+ for(Int_t det = 0; det < 540; det++) {
+
+ Float_t gaininit = fCalDetGainUsed->GetValue(det);
+ Float_t gainout = calDetGain->GetValue(det);
+
+
+ if(TMath::Abs(gainout-1.0) > 0.000001) {
+ mean += (gaininit*gainout);
+ nbdet++;
+ }
+ }
+ if(nbdet > 0) mean = mean/nbdet;
+
+ for(Int_t det = 0; det < 540; det++) {
+
+ Float_t gaininit = fCalDetGainUsed->GetValue(det);
+ Float_t gainout = calDetGain->GetValue(det);
+
+ if(TMath::Abs(gainout-1.0) > 0.000001) {
+ Double_t newgain = gaininit*gainout;
+ if(newgain < 0.1) newgain = 0.1;
+ if(newgain > 1.9) newgain = 1.9;
+ calDetGain->SetValue(det,newgain);
+ }
+ else {
+ Double_t newgain = mean;
+ if(newgain < 0.1) newgain = 0.1;
+ if(newgain > 1.9) newgain = 1.9;
+ calDetGain->SetValue(det,newgain);
+ }
+ }
+
+
+ }
+ //________________________________________________________________________________________________
+ void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
+ //
+ // Correct from the drift velocity
+ //
+
+ //printf("Correct for vdrift\n");
+
+ AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
+ if(!calDetGain) return;
+
+ Int_t detVdrift = kVdriftPHDet;
+ if(fMethodSecond) detVdrift = kVdriftLinear;
+ AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
+ if(!calDetVdrift) return;
+
+ // Calculate mean
+ if(!fNotEnoughStatisticsForTheVdriftLinear) {
+ for(Int_t det = 0; det < 540; det++) {
+
+ Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
+ Float_t vdriftout = calDetVdrift->GetValue(det);
+
+ Float_t gain = calDetGain->GetValue(det);
+ if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
+ if(gain < 0.1) gain = 0.1;
+ if(gain > 1.9) gain = 1.9;
+ calDetGain->SetValue(det,gain);
+ }
+ }
+ else {
+
+ Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
+ Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
+ Float_t factorcorrectif = 1.0;
+ if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
+ for(Int_t det = 0; det < 540; det++) {
+ Float_t gain = calDetGain->GetValue(det);
+ gain = gain*factorcorrectif;
+ if(gain < 0.1) gain = 0.1;
+ if(gain > 1.9) gain = 1.9;
+ calDetGain->SetValue(det,gain);
+ }
+
+ }
+
+ }
+//_________________________________________________________________________________________________________________
+ void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
+ //
+ // Update OCDB entry
+ //
+
+ AliCDBMetaData *metaData= new AliCDBMetaData();
+ metaData->SetObjectClassName("AliTRDCalDet");
+ metaData->SetResponsible("Raphaelle Bailhache");
+ metaData->AddDateToComment();
+ metaData->SetBeamPeriod(1);
+
+ AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
+ AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
+ if(calDet) storage->Put(calDet, id1, metaData);
+
+
+ }
+ //___________________________________________________________________________________________________________________
+ void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
+ //
+ // Update OCDB entry
+ //
+
+ Int_t detExB = kLorentzLinear;
+ if(!fMethodSecond) return;
+
+ //printf("Pass\n");
+
+ AliCDBMetaData *metaData= new AliCDBMetaData();
+ metaData->SetObjectClassName("AliTRDCalDet");
+ metaData->SetResponsible("Raphaelle Bailhache");
+ metaData->AddDateToComment();
+ metaData->SetBeamPeriod(1);
+
+ AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
+ AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
+ if(calDet) storage->Put(calDet, id1, metaData);
+ //if(!calDet) printf("No caldet\n");
+
+ }