AliTRDCalibTask.cxx .h (running on a test task over all triggers)
authorcblume <cblume@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 5 Aug 2011 20:37:29 +0000 (20:37 +0000)
committercblume <cblume@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 5 Aug 2011 20:37:29 +0000 (20:37 +0000)
AliTRDCalibraFit.cxx .h (one constant per run in case of too few stats for vdrift and gain only)
AliTRDPreprocessorOffline.cxx .h  (status implementation and case for one constant per run)

TRD/AliTRDCalibTask.cxx
TRD/AliTRDCalibTask.h
TRD/AliTRDCalibraFit.cxx
TRD/AliTRDCalibraFit.h
TRD/AliTRDPreprocessorOffline.cxx
TRD/AliTRDPreprocessorOffline.h

index 7215e99..0aac7e6 100644 (file)
@@ -35,6 +35,7 @@ using namespace std;
 #include "TH2I.h"
 #include "TH1F.h"
 #include "TH2F.h"
+#include "TH2S.h"
 #include "TList.h"
 #include "TMath.h"
 #include "TObject.h"
@@ -45,6 +46,8 @@ using namespace std;
 #include "TStyle.h"
 #include "TLine.h"
 #include "TIterator.h"
+#include "TLinearFitter.h"
+#include "TVectorD.h"
 
 #include "AliAnalysisTask.h"
 #include "AliAnalysisManager.h"
@@ -111,6 +114,10 @@ ClassImp(AliTRDCalibTask)
       fPH2dSum(0),
       fCH2dSM(0),
       fPH2dSM(0),
+      fCH2dTest(0),
+      fPH2dTest(0),
+      fLinearVdriftTest(0),
+      fOnInstance(kTRUE),
       fHisto2d(kTRUE),
       fVector2d(kFALSE),
       fVdriftLinear(kTRUE),
@@ -198,6 +205,9 @@ AliTRDCalibTask::~AliTRDCalibTask()
   if(fPH2dSum) delete fPH2dSum;
   if(fCH2dSM) delete fCH2dSM;
   if(fPH2dSM) delete fPH2dSM;
+  if(fCH2dTest) delete fCH2dTest;
+  if(fPH2dTest) delete fPH2dTest;
+  if(fLinearVdriftTest) delete fLinearVdriftTest;
   if(fCalDetGain) delete fCalDetGain;
   
   if(fSelectedTrigger) {
@@ -228,59 +238,63 @@ void AliTRDCalibTask::UserCreateOutputObjects()
     }
   }
 
+  // output list
+  fListHist = new TList();
+  fListHist->SetOwner();
+
   // instance calibration 
   fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
-  fTRDCalibraFillHisto->SetHisto2d(fHisto2d); // choose to use histograms
-  fTRDCalibraFillHisto->SetVector2d(fVector2d); // choose to use vectors
-  fTRDCalibraFillHisto->SetCH2dOn();  // choose to calibrate the gain
-  fTRDCalibraFillHisto->SetPH2dOn();  // choose to calibrate the drift velocity
-  fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
-  fTRDCalibraFillHisto->SetLinearFitterOn(fVdriftLinear); // Other possibility vdrift VDRIFT
-  fTRDCalibraFillHisto->SetLinearFitterDebugOn(fVdriftLinear); // Other possibility vdrift
-  for(Int_t k = 0; k < 3; k++){
-    if(((fNz[k] != 10) && (fNrphi[k] != 10)) && ((fNz[k] != 100) && (fNrphi[k] != 100))) {
-      fTRDCalibraFillHisto->SetNz(k,fNz[k]);                                    // Mode calibration
-      fTRDCalibraFillHisto->SetNrphi(k,fNrphi[k]);                             // Mode calibration
-    }
-    else {
-      if((fNz[k] == 100) && (fNrphi[k] == 100))  {
-       if(fVector2d) AliInfo("The mode all together is not supported by the vector method");
-       fTRDCalibraFillHisto->SetAllTogether(k);
+  if(fOnInstance) {
+    fTRDCalibraFillHisto->SetHisto2d(fHisto2d); // choose to use histograms
+    fTRDCalibraFillHisto->SetVector2d(fVector2d); // choose to use vectors
+    fTRDCalibraFillHisto->SetCH2dOn();  // choose to calibrate the gain
+    fTRDCalibraFillHisto->SetPH2dOn();  // choose to calibrate the drift velocity
+    fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
+    fTRDCalibraFillHisto->SetLinearFitterOn(fVdriftLinear); // Other possibility vdrift VDRIFT
+    fTRDCalibraFillHisto->SetLinearFitterDebugOn(fVdriftLinear); // Other possibility vdrift
+    for(Int_t k = 0; k < 3; k++){
+      if(((fNz[k] != 10) && (fNrphi[k] != 10)) && ((fNz[k] != 100) && (fNrphi[k] != 100))) {
+       fTRDCalibraFillHisto->SetNz(k,fNz[k]);                                    // Mode calibration
+       fTRDCalibraFillHisto->SetNrphi(k,fNrphi[k]);                             // Mode calibration
       }
-      if((fNz[k] == 10) && (fNrphi[k] == 10))  {
-       if(fVector2d) AliInfo("The mode per supermodule is not supported by the vector method");
-       fTRDCalibraFillHisto->SetPerSuperModule(k);
+      else {
+       if((fNz[k] == 100) && (fNrphi[k] == 100))  {
+         if(fVector2d) AliInfo("The mode all together is not supported by the vector method");
+         fTRDCalibraFillHisto->SetAllTogether(k);
+       }
+       if((fNz[k] == 10) && (fNrphi[k] == 10))  {
+         if(fVector2d) AliInfo("The mode per supermodule is not supported by the vector method");
+         fTRDCalibraFillHisto->SetPerSuperModule(k);
+       }
       }
     }
-  }
-  // Variables for how to fill
-  fTRDCalibraFillHisto->SetFillWithZero(fFillZero);
-  fTRDCalibraFillHisto->SetNormalizeNbOfCluster(fNormalizeNbOfCluster); 
-  fTRDCalibraFillHisto->SetMaxCluster(fMaxCluster);
-  fTRDCalibraFillHisto->SetNbMaxCluster(fNbMaxCluster);
+    // Variables for how to fill
+    fTRDCalibraFillHisto->SetFillWithZero(fFillZero);
+    fTRDCalibraFillHisto->SetNormalizeNbOfCluster(fNormalizeNbOfCluster); 
+    fTRDCalibraFillHisto->SetMaxCluster(fMaxCluster);
+    fTRDCalibraFillHisto->SetNbMaxCluster(fNbMaxCluster);
   
-  // Init with 30 timebins
-  fTRDCalibraFillHisto->Init2Dhistos(fNbTimeBins); // initialise the histos
-  fTRDCalibraFillHisto->SetNumberClusters(fLow); // At least 11 clusters
-  fTRDCalibraFillHisto->SetNumberClustersf(fHigh); // At least 11 clusters
+    // Init with 30 timebins
+    fTRDCalibraFillHisto->Init2Dhistos(fNbTimeBins); // initialise the histos
+    fTRDCalibraFillHisto->SetNumberClusters(fLow); // At least 11 clusters
+    fTRDCalibraFillHisto->SetNumberClustersf(fHigh); // At least 11 clusters
+    
+    // For testing only
+    if(fDebug > 2) fTRDCalibraFillHisto->SetDebugLevel(1); //debug stuff
+    
+    if(fHisto2d) {  
+      fListHist->Add(fTRDCalibraFillHisto->GetCH2d());
+      fListHist->Add(fTRDCalibraFillHisto->GetPH2d()); 
+      fListHist->Add(fTRDCalibraFillHisto->GetPRF2d());
+    } 
+    if(fVdriftLinear) fListHist->Add((TObject *)fTRDCalibraFillHisto->GetVdriftLinearFit());
+    if(fVector2d) fListHist->Add((TObject *) fTRDCalibraFillHisto->GetCalibraVector()); //calibra vector  
+  }
   fRelativeScale = fTRDCalibraFillHisto->GetRelativeScale(); // Get the relative scale for the gain
   
-  // For testing only
-  if(fDebug > 2) fTRDCalibraFillHisto->SetDebugLevel(1); //debug stuff
-  
-  // output list
-  fListHist = new TList();
-  fListHist->SetOwner();
-  if(fHisto2d) {  
-    fListHist->Add(fTRDCalibraFillHisto->GetCH2d());
-    fListHist->Add(fTRDCalibraFillHisto->GetPH2d()); 
-    fListHist->Add(fTRDCalibraFillHisto->GetPRF2d());
-  } 
-  if(fVdriftLinear) fListHist->Add((TObject *) fTRDCalibraFillHisto->GetVdriftLinearFit());
-  if(fVector2d) fListHist->Add((TObject *) fTRDCalibraFillHisto->GetCalibraVector()); //calibra vector  
-  fNEvents = new TH1I("NEvents","NEvents", 2, 0, 2);
+  fNEvents = new TH1I(Form("NEvents_%s",(const char*)fName),"NEvents", 2, 0, 2);
   fListHist->Add(fNEvents);
-  fNEventsInput = new TH1I("NEventsInput","NEventsInput", 2, 0, 2);
+  fNEventsInput = new TH1I(Form("NEventsInput_%s",(const char*)fName),"NEventsInput", 2, 0, 2);
   fListHist->Add(fNEventsInput);
   
   // absolute gain calibration even without AliESDfriend
@@ -293,7 +307,7 @@ void AliTRDCalibTask::UserCreateOutputObjects()
   for(Int_t i=0; i<=nBinsPt; i++) binLimLogPt[i]=(Double_t)TMath::Log10(minPt) + (TMath::Log10(maxPt)-TMath::Log10(minPt))/nBinsPt*(Double_t)i ;
   for(Int_t i=0; i<=nBinsPt; i++) binLimPt[i]=(Double_t)TMath::Power(10,binLimLogPt[i]);
   
-  fAbsoluteGain = new TH2F("AbsoluteGain","AbsoluteGain", 200, 0.0, 700.0, nBinsPt, binLimPt);
+  fAbsoluteGain = new TH2F(Form("AbsoluteGain_%s",(const char*)fName),"AbsoluteGain", 200, 0.0, 700.0, nBinsPt, binLimPt);
   fAbsoluteGain->SetYTitle("Momentum at TRD");
   fAbsoluteGain->SetXTitle("charge deposit [a.u]");
   fAbsoluteGain->SetZTitle("counts");
@@ -301,15 +315,36 @@ void AliTRDCalibTask::UserCreateOutputObjects()
   fAbsoluteGain->Sumw2();
   fListHist->Add(fAbsoluteGain);
   
-
-  
   /////////////////////////////////////////
   // First debug level
   ///////////////////////////////////////
   if(fDebug > 0) {
+
+    fLinearVdriftTest = new TH2S(Form("LFDV0testversion_%s",(const char*)fName),"LFDV0testversion",36,-0.9,0.9,48,-1.2,1.2);
+    fLinearVdriftTest->SetXTitle("tan(phi_{track})");
+    fLinearVdriftTest->SetYTitle("dy/dt");
+    fLinearVdriftTest->SetZTitle("Number of tracklets");
+    fLinearVdriftTest->SetStats(0);
+    fLinearVdriftTest->SetDirectory(0);
     
     // Standart with AliESDfriend
-    fPH2dSM = new TProfile2D("PH2dSM","Nz10Nrphi10"
+    fPH2dTest = new TProfile2D(Form("PH2dTest_%s",(const char*)fName),"Nz0Nrphi0"
+                           ,fNbTimeBins,-0.05,(Double_t)((fNbTimeBins-0.5)/10.0)
+                          ,540,0,540);
+    fPH2dTest->SetYTitle("Det/pad groups");
+    fPH2dTest->SetXTitle("time [#mus]");
+    fPH2dTest->SetZTitle("<PH> [a.u.]");
+    fPH2dTest->SetStats(0);
+    //
+    fCH2dTest = new TH2I(Form("CH2dTest_%s",(const char*)fName),"Nz0Nrphi0",50,0,300,540,0,540);
+    fCH2dTest->SetYTitle("Det/pad groups");
+    fCH2dTest->SetXTitle("charge deposit [a.u]");
+    fCH2dTest->SetZTitle("counts");
+    fCH2dTest->SetStats(0);
+    fCH2dTest->Sumw2();
+
+    //
+    fPH2dSM = new TProfile2D(Form("PH2dSM_%s",(const char*)fName),"Nz10Nrphi10"
                            ,fNbTimeBins,-0.05,(Double_t)((fNbTimeBins-0.5)/10.0)
                           ,18,0,18);
     fPH2dSM->SetYTitle("Det/pad groups");
@@ -317,14 +352,14 @@ void AliTRDCalibTask::UserCreateOutputObjects()
     fPH2dSM->SetZTitle("<PH> [a.u.]");
     fPH2dSM->SetStats(0);
     //
-    fCH2dSM = new TH2I("CH2dSM","Nz10Nrphi10",50,0,300,18,0,18);
+    fCH2dSM = new TH2I(Form("CH2dSM_%s",(const char*)fName),"Nz10Nrphi10",50,0,300,18,0,18);
     fCH2dSM->SetYTitle("Det/pad groups");
     fCH2dSM->SetXTitle("charge deposit [a.u]");
     fCH2dSM->SetZTitle("counts");
     fCH2dSM->SetStats(0);
     fCH2dSM->Sumw2();
     //
-    fPH2dSum = new TProfile2D("PH2dSum","Nz100Nrphi100"
+    fPH2dSum = new TProfile2D(Form("PH2dSum_%s",(const char*)fName),"Nz100Nrphi100"
                            ,fNbTimeBins,-0.05,(Double_t)((fNbTimeBins-0.5)/10.0)
                            ,1,0,1);
     fPH2dSum->SetYTitle("Det/pad groups");
@@ -332,25 +367,23 @@ void AliTRDCalibTask::UserCreateOutputObjects()
     fPH2dSum->SetZTitle("<PH> [a.u.]");
     fPH2dSum->SetStats(0);
     //
-    fCH2dSum = new TH2I("CH2dSum","Nz100Nrphi100",50,0,300,1,0,1);
+    fCH2dSum = new TH2I(Form("CH2dSum_%s",(const char*)fName),"Nz100Nrphi100",50,0,300,1,0,1);
     fCH2dSum->SetYTitle("Det/pad groups");
     fCH2dSum->SetXTitle("charge deposit [a.u]");
     fCH2dSum->SetZTitle("counts");
     fCH2dSum->SetStats(0);
     fCH2dSum->Sumw2();
-    //
-    fNbGoodTracks = new TH2F("NbGoodTracks","NbGoodTracks",500,0.0,2500.0,200,0.0,100.0);
-    fNbGoodTracks->SetXTitle("Nb of good tracks");
-    fNbGoodTracks->SetYTitle("Centrality");
-    fNbGoodTracks->SetStats(0);
-
+    
     
     // Add them
+    fListHist->Add(fLinearVdriftTest);
+    fListHist->Add(fPH2dTest);
+    fListHist->Add(fCH2dTest);
     fListHist->Add(fPH2dSM);
     fListHist->Add(fCH2dSM);
     fListHist->Add(fPH2dSum);
     fListHist->Add(fCH2dSum);
-    fListHist->Add(fNbGoodTracks);
+
   }
 
   /////////////////////////////////////////
@@ -358,36 +391,43 @@ void AliTRDCalibTask::UserCreateOutputObjects()
   ///////////////////////////////////////
   if(fDebug > 1) {
 
-    fNbTRDTrack = new TH1F("TRDTrack","TRDTrack",50,0,50);
+    fNbGoodTracks = new TH2F(Form("NbGoodTracks_%s",(const char*)fName),"NbGoodTracks",500,0.0,2500.0,200,0.0,100.0);
+    fNbGoodTracks->SetXTitle("Nb of good tracks");
+    fNbGoodTracks->SetYTitle("Centrality");
+    fNbGoodTracks->SetStats(0);
+
+    fNbTRDTrack = new TH1F(Form("TRDTrack_%s",(const char*)fName),"TRDTrack",50,0,50);
     fNbTRDTrack->Sumw2();
-    fNbTRDTrackOffline = new TH1F("TRDTrackOffline","TRDTrackOffline",50,0,50);
+    fNbTRDTrackOffline = new TH1F(Form("TRDTrackOffline_%s",(const char*)fName),"TRDTrackOffline",50,0,50);
     fNbTRDTrackOffline->Sumw2();
-    fNbTRDTrackStandalone = new TH1F("TRDTrackStandalone","TRDTrackStandalone",50,0,50);
+    fNbTRDTrackStandalone = new TH1F(Form("TRDTrackStandalone_%s",(const char*)fName),"TRDTrackStandalone",50,0,50);
     fNbTRDTrackStandalone->Sumw2();
-    fNbTPCTRDtrack = new TH2F("NbTPCTRDtrack","NbTPCTRDtrack",100,0,100,100,0,100);
+    fNbTPCTRDtrack = new TH2F(Form("NbTPCTRDtrack_%s",(const char*)fName),"NbTPCTRDtrack",100,0,100,100,0,100);
     fNbTPCTRDtrack->Sumw2();
     //
-    fNbTimeBin = new TH1F("NbTimeBin","NbTimeBin",35,0,35);
+    fNbTimeBin = new TH1F(Form("NbTimeBin_%s",(const char*)fName),"NbTimeBin",35,0,35);
     fNbTimeBin->Sumw2();
-    fNbTimeBinOffline = new TH1F("NbTimeBinOffline","NbTimeBinOffline",35,0,35);
+    fNbTimeBinOffline = new TH1F(Form("NbTimeBinOffline_%s",(const char*)fName),"NbTimeBinOffline",35,0,35);
     fNbTimeBinOffline->Sumw2();
-    fNbTimeBinStandalone = new TH1F("NbTimeBinStandalone","NbTimeBinStandalone",35,0,35);
+    fNbTimeBinStandalone = new TH1F(Form("NbTimeBinStandalone_%s",(const char*)fName),"NbTimeBinStandalone",35,0,35);
     fNbTimeBinStandalone->Sumw2();
     //
-    fNbClusters = new TH1F("NbClusters","",35,0,35);
+    fNbClusters = new TH1F(Form("NbClusters_%s",(const char*)fName),"",35,0,35);
     fNbClusters->Sumw2();
-    fNbClustersOffline = new TH1F("NbClustersOffline","",35,0,35);
+    fNbClustersOffline = new TH1F(Form("NbClustersOffline_%s",(const char*)fName),"",35,0,35);
     fNbClustersOffline->Sumw2();
-    fNbClustersStandalone = new TH1F("NbClustersStandalone","",35,0,35);
+    fNbClustersStandalone = new TH1F(Form("NbClustersStandalone_%s",(const char*)fName),"",35,0,35);
     fNbClustersStandalone->Sumw2();
     //
-    fNbTracklets = new TH1F("NbTracklets","NbTracklets",540,0.,540.);
+    fNbTracklets = new TH1F(Form("NbTracklets_%s",(const char*)fName),"NbTracklets",540,0.,540.);
     fNbTracklets->Sumw2();
-    fNbTrackletsOffline = new TH1F("NbTrackletsOffline","NbTrackletsOffline",540,0.,540.);
+    fNbTrackletsOffline = new TH1F(Form("NbTrackletsOffline_%s",(const char*)fName),"NbTrackletsOffline",540,0.,540.);
     fNbTrackletsOffline->Sumw2();
-    fNbTrackletsStandalone = new TH1F("NbTrackletsStandalone","NbTrackletsStandalone",540,0.,540.);
+    fNbTrackletsStandalone = new TH1F(Form("NbTrackletsStandalone_%s",(const char*)fName),"NbTrackletsStandalone",540,0.,540.);
     fNbTrackletsStandalone->Sumw2();
    
+    fListHist->Add(fNbGoodTracks);
+   
     fListHist->Add(fNbTRDTrack);
     fListHist->Add(fNbTRDTrackOffline);
     fListHist->Add(fNbTRDTrackStandalone);
@@ -430,16 +470,38 @@ void AliTRDCalibTask::UserExec(Option_t *)
     }
   }
   if(fCounter==0) {
-    fTRDCalibraFillHisto->SetFirstRunGain(fFirstRunGain); // Gain Used
-    fTRDCalibraFillHisto->SetVersionGainUsed(fVersionGainUsed); // Gain Used
-    fTRDCalibraFillHisto->SetSubVersionGainUsed(fSubVersionGainUsed); // Gain Used
-    fTRDCalibraFillHisto->SetFirstRunGainLocal(fFirstRunGainLocal); // Gain Used
-    fTRDCalibraFillHisto->SetVersionGainLocalUsed(fVersionGainLocalUsed); // Gain Used
-    fTRDCalibraFillHisto->SetSubVersionGainLocalUsed(fSubVersionGainLocalUsed); // Gain Used
-    fTRDCalibraFillHisto->SetFirstRunVdrift(fFirstRunVdrift); // Vdrift Used
-    fTRDCalibraFillHisto->SetVersionVdriftUsed(fVersionVdriftUsed); // Vdrift Used
-    fTRDCalibraFillHisto->SetSubVersionVdriftUsed(fSubVersionVdriftUsed); // Vdrift Used
-    fTRDCalibraFillHisto->InitCalDet();
+    if(fOnInstance) {
+      fTRDCalibraFillHisto->SetFirstRunGain(fFirstRunGain); // Gain Used
+      fTRDCalibraFillHisto->SetVersionGainUsed(fVersionGainUsed); // Gain Used
+      fTRDCalibraFillHisto->SetSubVersionGainUsed(fSubVersionGainUsed); // Gain Used
+      fTRDCalibraFillHisto->SetFirstRunGainLocal(fFirstRunGainLocal); // Gain Used
+      fTRDCalibraFillHisto->SetVersionGainLocalUsed(fVersionGainLocalUsed); // Gain Used
+      fTRDCalibraFillHisto->SetSubVersionGainLocalUsed(fSubVersionGainLocalUsed); // Gain Used
+      fTRDCalibraFillHisto->SetFirstRunVdrift(fFirstRunVdrift); // Vdrift Used
+      fTRDCalibraFillHisto->SetVersionVdriftUsed(fVersionVdriftUsed); // Vdrift Used
+      fTRDCalibraFillHisto->SetSubVersionVdriftUsed(fSubVersionVdriftUsed); // Vdrift Used
+      fTRDCalibraFillHisto->InitCalDet();
+    }
+    if(fDebug > 1){
+      // title CH2dTest
+      TString name("Ver");
+      name += fVersionGainUsed;
+      name += "Subver";
+      name += fSubVersionGainUsed;
+      name += "FirstRun";
+      name += fFirstRunGain;
+      name += "Nz0Nrphi0";
+      fCH2dTest->SetTitle(name);  
+      // title PH2dTest
+      TString namee("Ver");
+      namee += fVersionVdriftUsed;
+      namee += "Subver";
+      namee += fSubVersionVdriftUsed;
+      namee += "FirstRun";
+      namee += fFirstRunVdrift;
+      namee += "Nz0Nrphi0";
+      fPH2dTest->SetTitle(namee); 
+    }
   }
   
   //  AliLog::SetGlobalLogLevel(AliLog::kError);
@@ -546,7 +608,7 @@ void AliTRDCalibTask::UserExec(Option_t *)
   for(Int_t itrack = 0; itrack < nbTracks; itrack++) {
     if(ParticleGood(itrack)) nGoodParticles++;  
   }
-  if(fDebug > 0)  {
+  if(fDebug > 1)  {
     // Centrality
     AliCentrality *esdCentrality = fESD->GetCentrality();
     Float_t centrality = esdCentrality->GetCentralityPercentile("V0M");
@@ -602,43 +664,6 @@ void AliTRDCalibTask::UserExec(Option_t *)
   
   //printf("has friends\n");
 
-  /*
-  ////////////////////////////////////
-   // Check the number of TPC tracks
-   ///////////////////////////////////
-   //printf("Nb of tracks %f\n",nbTracks);
-   for(Int_t itrk = 0; itrk < nbTracks; itrk++){
-     // Get ESD track
-     fkEsdTrack = fESD->GetTrack(itrk);
-     ULong_t status = fkEsdTrack->GetStatus(); 
-     if(status&(AliESDtrack::kTPCout)) nbtrackTPC++;
-     if((status&(AliESDtrack::kTRDout)) && (!(status&(AliESDtrack::kTRDin)))) {
-       nbTrdTracks++;    
-       nbTrdTracksStandalone++;
-     }
-     if((status&(AliESDtrack::kTRDin))) {
-       nbTrdTracks++;    
-       nbTrdTracksOffline++;
-     }
-   }
-   
-   if((nbtrackTPC>0) && (nbTrdTracks > (3.0*nbtrackTPC))) pass = kFALSE;
-   
-   if(fDebug > 1) {
-     
-     fNbTRDTrack->Fill(nbTrdTracks);
-     fNbTRDTrackStandalone->Fill(nbTrdTracksStandalone);
-     fNbTRDTrackOffline->Fill(nbTrdTracksOffline);
-     fNbTPCTRDtrack->Fill(nbTrdTracks,nbtrackTPC);
-   
-   }
-
-   if(!pass) {
-     PostData(1, fListHist);
-     return;
-   }
-  */
-  
   /////////////////////////////////////
   // Loop on AliESDtrack
   ////////////////////////////////////
@@ -660,6 +685,7 @@ void AliTRDCalibTask::UserExec(Option_t *)
     // First Absolute gain calibration
     Int_t trdNTracklets = (Int_t) fkEsdTrack->GetTRDntracklets();
     Int_t trdNTrackletsPID = (Int_t) fkEsdTrack->GetTRDntrackletsPID(); 
+    //printf("Number of trd tracklets %d and PID trd tracklets %d\n",trdNTracklets,trdNTrackletsPID);
     if((trdNTracklets > 0) && (trdNTrackletsPID > 0)) {
       for(Int_t iPlane = 0; iPlane < 6; ++iPlane){
        //Double_t slide = fkEsdTrack->GetTRDslice(iPlane);
@@ -712,7 +738,7 @@ void AliTRDCalibTask::UserExec(Option_t *)
       }
       
       fTrdTrack = (AliTRDtrackV1 *)fCalibObject;
-      if(good) {
+      if(good && fOnInstance) {
        //cout << "good" << endl;
        fTRDCalibraFillHisto->UpdateHistogramsV1(fTrdTrack);
        //printf("Fill fTRDCalibraFillHisto\n");
@@ -802,37 +828,41 @@ void AliTRDCalibTask::UserExec(Option_t *)
            else  fNbClustersOffline->Fill(nbclusters);
          }        
          
-         if(fDebug > 0) {
-           if((nbclusters > fLow) && (nbclusters < fHigh)){
-             if(fRelativeScale > 0.0) sum = sum/fRelativeScale;               
-             fCH2dSM->Fill(sum,sector+0.5);
-             fCH2dSum->Fill(sum,0.5);
-             Bool_t checknoise = kTRUE;
-             if(fMaxCluster > 0) {
-               if(phtb[0] > fMaxCluster) checknoise = kFALSE;
-               if(fNbTimeBins > fNbMaxCluster) {
-                 for(Int_t k = (fNbTimeBins-fNbMaxCluster); k < fNbTimeBins; k++){
-                   if(phtb[k] > fMaxCluster) checknoise = kFALSE;
-                 }
+         if((nbclusters > fLow) && (nbclusters < fHigh)){
+           if(fRelativeScale > 0.0) sum = sum/fRelativeScale;
+           fCH2dTest->Fill(sum,detector+0.5);         
+           fCH2dSM->Fill(sum,sector+0.5);
+           fCH2dSum->Fill(sum,0.5);
+           Bool_t checknoise = kTRUE;
+           if(fMaxCluster > 0) {
+             if(phtb[0] > fMaxCluster) checknoise = kFALSE;
+             if(fNbTimeBins > fNbMaxCluster) {
+               for(Int_t k = (fNbTimeBins-fNbMaxCluster); k < fNbTimeBins; k++){
+                 if(phtb[k] > fMaxCluster) checknoise = kFALSE;
                }
              }
-             if(checknoise) {         
-               for(int ic=0; ic<fNbTimeBins; ic++){
-                 if(fFillZero) {
-                   fPH2dSum->Fill((Double_t)(ic/10.0),0.5,(Double_t)phtb[ic]);
+           }
+           if(checknoise) {           
+             for(int ic=0; ic<fNbTimeBins; ic++){
+               if(fFillZero) {
+                 fPH2dTest->Fill((Double_t)(ic/10.0),detector+0.5,(Double_t)phtb[ic]);
+                 fPH2dSum->Fill((Double_t)(ic/10.0),0.5,(Double_t)phtb[ic]);
+                 fPH2dSM->Fill((Double_t)(ic/10.0),sector+0.5,(Double_t)phtb[ic]);
+               }
+               else {
+                 if(phtb[ic] > 0.0) {
+                   fPH2dTest->Fill((Double_t)(ic/10.0),detector+0.5,(Double_t)phtb[ic]);
+                   fPH2dSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);
                    fPH2dSM->Fill((Double_t)(ic/10.0),sector+0.5,(Double_t)phtb[ic]);
                  }
-                 else {
-                   if(phtb[ic] > 0.0) {
-                     fPH2dSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);
-                     fPH2dSM->Fill((Double_t)(ic/10.0),sector+0.5,(Double_t)phtb[ic]);
-                   }
-                 }
                }
              }
            }
          }
+         if(detector == 0) FindP1TrackPHtrackletV1Test(tracklet,nbclusters);
+
        } // loop on tracklets
+
        
       } // debug
       
@@ -1506,6 +1536,127 @@ Bool_t AliTRDCalibTask::ParticleGood(int i) const {
 
 
 }
+//______________________________________________________________________________________________________________________
+Bool_t AliTRDCalibTask::FindP1TrackPHtrackletV1Test(const AliTRDseedV1 *tracklet, Int_t nbclusters)
+{
+  //
+  // Drift velocity calibration:
+  // Fit the clusters with a straight line
+  // From the slope find the drift velocity
+  //
+
+  ////////////////////////////////////////////////
+  //Number of points: if less than 3 return kFALSE
+  /////////////////////////////////////////////////
+  if(nbclusters <= 2) return kFALSE;
+
+  ////////////
+  //Variables
+  ////////////
+  // results of the linear fit
+  Double_t dydt                       = 0.0;                                // dydt tracklet after straight line fit
+  Double_t errorpar                   = 0.0;                                // error after straight line fit on dy/dt
+  Double_t pointError                 = 0.0;                                // error after straight line fit 
+  // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
+  Int_t    crossrow                   = 0;                                  // if it crosses a pad row
+  Int_t    rowp                       = -1;                                 // if it crosses a pad row
+  Float_t  tnt                        = tracklet->GetTilt();                // tan tiltingangle
+  TLinearFitter linearFitterTracklet(2,"pol1");
+  linearFitterTracklet.StoreData(kTRUE);  
+  
+  ///////////////////////////////////////////
+  // Take the parameters of the track
+  //////////////////////////////////////////
+  // take now the snp, tnp and tgl from the track
+  Double_t snp = tracklet->GetSnp();             // sin dy/dx at the end of the chamber
+  Double_t tnp = 0.0;                            // dy/dx at the end of the chamber 
+  if( TMath::Abs(snp) <  1.){
+    tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
+  } 
+  Double_t tgl  = tracklet->GetTgl();           // dz/dl
+  Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp);   // dz/dx calculated from dz/dl
+  // at the entrance
+  //Double_t tnp = tracklet->GetYref(1);      // dy/dx at the entrance of the chamber
+  //Double_t tgl = tracklet->GetZref(1);      // dz/dl at the entrance of the chamber
+  //Double_t dzdx = tgl;                      //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
+  // at the end with correction due to linear fit
+  //Double_t tnp = tracklet->GetYfit(1);      // dy/dx at the end of the chamber after fit correction
+  //Double_t tgl = tracklet->GetZfit(1);      // dz/dl at the end of the chamber after fit correction 
+
+
+  ////////////////////////////
+  // loop over the clusters
+  ////////////////////////////
+  Int_t  nbli = 0;
+  AliTRDcluster *cl                   = 0x0;
+  //////////////////////////////
+  // Check no shared clusters
+  //////////////////////////////
+  for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
+    cl = tracklet->GetClusters(icc);
+    if(cl)  crossrow = 1;
+  }
+  //////////////////////////////////
+  // Loop clusters
+  //////////////////////////////////
+  for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
+    if(!(cl = tracklet->GetClusters(ic))) continue;
+    //if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
+    
+    Double_t ycluster                 = cl->GetY();
+    Int_t time                        = cl->GetPadTime();
+    Double_t timeis                   = time/10.0;
+    //See if cross two pad rows
+    Int_t    row                      = cl->GetPadRow();
+    if(rowp==-1) rowp                 = row;
+    if(row != rowp) crossrow          = 1;
 
+    linearFitterTracklet.AddPoint(&timeis,ycluster,1);
+    nbli++;  
 
+    
+  }
+  
+  ////////////////////////////////////
+  // Do the straight line fit now
+  ///////////////////////////////////
+  if(nbli <= 2){ 
+    linearFitterTracklet.ClearPoints();  
+    return kFALSE; 
+  }
+  TVectorD pars;
+  linearFitterTracklet.Eval();
+  linearFitterTracklet.GetParameters(pars);
+  pointError  =  TMath::Sqrt(linearFitterTracklet.GetChisquare()/(nbli-2));
+  errorpar    =  linearFitterTracklet.GetParError(1)*pointError;
+  dydt        = pars[1]; 
+  //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",linearFitterTracklet->GetChisquare(),nbli,pointError,linearFitterTracklet->GetParError(1),errorpar);
+  linearFitterTracklet.ClearPoints();  
+  /////////////////////////
+  // Cuts quality
+  ////////////////////////
+  
+  if(nbclusters < fLow) return kFALSE;
+  if(nbclusters > fHigh) return kFALSE;
+  if(pointError >= 0.3) return kFALSE;
+  if(crossrow == 1) return kTRUE;
+  
+  ///////////////////////
+  // Fill
+  //////////////////////
+
+  if(fDebug > 0){
+    //Add to the linear fitter of the detector
+    if( TMath::Abs(snp) <  1.){
+      Double_t x = tnp-dzdx*tnt; 
+      //if(!fLinearVdriftTest) printf("Not there\n");
+      Double_t nbentries = fLinearVdriftTest->GetEntries();
+      if(nbentries < (5.0*32767)) fLinearVdriftTest->Fill(x,dydt);
+    }
+  }
+  
+  return kTRUE;
+}
 
index 5c56ed2..9cbb28f 100644 (file)
@@ -14,6 +14,7 @@ class TObjArray;
 class TH2F;
 class TH1F;
 class TH1I;
+class TH2S;
 class TProfile2D;
 class TH2I;
 class TTree;
@@ -22,6 +23,7 @@ class AliESDfriend;
 class AliESDtrack;
 class AliESDfriendTrack;
 class AliTRDtrackV1;
+class AliTRDseedV1;
 class AliTRDCalibraFillHisto;
 class AliTRDcluster;
 class AliESDtrackCuts;
@@ -45,8 +47,10 @@ class AliTRDCalibTask : public AliAnalysisTaskSE {
   void           Plot();
   virtual Long64_t  Merge(TCollection *li);
   void           AddTask(const AliTRDCalibTask * calibTask);
+  Bool_t         FindP1TrackPHtrackletV1Test(const AliTRDseedV1 *tracklet, Int_t nbclusters);
   TList          *GetList() const {return fListHist;};
 
+  void SetOnInstance(Bool_t onInstance)                             {fOnInstance=onInstance;};
   void SetHisto2d(Bool_t histo2d)                                   {fHisto2d=histo2d;};
   void SetVector2d(Bool_t vector2d)                                 {fVector2d=vector2d;};
   void SetVdriftLinear(Bool_t vdriftLinear)                         {fVdriftLinear = vdriftLinear;};
@@ -128,7 +132,11 @@ class AliTRDCalibTask : public AliAnalysisTaskSE {
   TProfile2D  *fPH2dSum;                         //! PH2d PH all
   TH2I        *fCH2dSM;                          //! CH2d per SM
   TProfile2D  *fPH2dSM;                          //! PH2d per SM
+  TH2I        *fCH2dTest;                        //! CH2d for test
+  TProfile2D  *fPH2dTest;                        //! PH2d for test
+  TH2S *fLinearVdriftTest;                       //! VdriftLinear for test
 
+  Bool_t      fOnInstance;                       // On Instance
   Bool_t      fHisto2d;                          // histo
   Bool_t      fVector2d;                         // vector
   Bool_t      fVdriftLinear;                     // vdrift Linear
index eb9c4de..448d20b 100644 (file)
@@ -136,6 +136,7 @@ AliTRDCalibraFit::AliTRDCalibraFit()
   ,fAccCDB(kFALSE)
   ,fMinEntries(800)
   ,fRebin(1)
+  ,fScaleGain(0.02431)
   ,fNumberFit(0)
   ,fNumberFitSuccess(0)
   ,fNumberEnt(0)
@@ -195,6 +196,7 @@ AliTRDCalibraFit::AliTRDCalibraFit(const AliTRDCalibraFit &c)
 ,fAccCDB(c.fAccCDB)
 ,fMinEntries(c.fMinEntries)
 ,fRebin(c.fRebin)
+,fScaleGain(c.fScaleGain)
 ,fNumberFit(c.fNumberFit)
 ,fNumberFitSuccess(c.fNumberFitSuccess)
 ,fNumberEnt(c.fNumberEnt)
@@ -544,6 +546,54 @@ Bool_t AliTRDCalibraFit::AnalyseCH(AliTRDCalibraVector *calvect)
   fDebugStreamer = 0x0;
   return kTRUE;
 }
+//____________Functions fit Online CH2d________________________________________
+Double_t AliTRDCalibraFit::AnalyseCHAllTogether(const TH2I *ch)
+{
+  //
+  // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each
+  // calibration group normalized the resulted coefficients (to 1 normally)
+  //
+  Int_t    nbins   = ch->GetNbinsX();// charge
+  Int_t    nybins  = ch->GetNbinsY();// groups number
+  // Take the histo
+  TH1I *projch = (TH1I *) ch->ProjectionX("projch",1,nybins+1,(Option_t *)"e");
+  projch->SetDirectory(0);
+  // Number of entries for this calibration group
+  Double_t nentries = 0.0;
+  Double_t mean = 0.0;
+  for (Int_t k = 0; k < nbins; k++) {
+    nentries += projch->GetBinContent(k+1);
+    mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
+    projch->SetBinError(k+1,TMath::Sqrt(projch->GetBinContent(k+1)));
+  }
+  projch->SetEntries(nentries);
+  //printf("The number of entries for the group %d is %f\n",idect,nentries);
+  if (nentries > 0) {
+    fNumberEnt++;
+    mean /= nentries;
+  }
+  // This detector has not enough statistics or was off
+  if (nentries <= fMinEntries) {
+    delete projch;
+    AliInfo(Form("There are %d entries for all together, it is not enough (%d)",(Int_t) nentries, fMinEntries));
+    return -100.0;
+  }
+  //Method choosen
+  switch(fMethod)
+    {
+    case 0: FitMeanW((TH1 *) projch, nentries); break;
+    case 1: FitMean((TH1 *) projch, nentries, mean); break;
+    case 2: FitCH((TH1 *) projch, mean); break;
+    case 3: FitBisCH((TH1 *) projch, mean); break;
+    default: return kFALSE;
+    }
+  delete fDebugStreamer;
+  fDebugStreamer = 0x0;
+  
+  if(fCurrentCoef[0] > 0.0) return fCurrentCoef[0];
+  else return -100.0;
+  
+}
 //________________functions fit Online PH2d____________________________________
 Bool_t AliTRDCalibraFit::AnalysePH(const TProfile2D *ph)
 {
@@ -1172,6 +1222,91 @@ Bool_t AliTRDCalibraFit::AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *cali
   fDebugStreamer = 0x0;
   return kTRUE;
   
+}
+//____________Functions fit Online CH2d________________________________________
+Double_t AliTRDCalibraFit::AnalyseLinearFittersAllTogether(AliTRDCalibraVdriftLinearFit *calivdli)
+{
+  //
+  // The linear method
+  //
+
+  // Add histos
+
+  TH2S *linearfitterhisto = 0x0;
+  
+  for(Int_t idet = 0; idet < 540; idet++){
+    
+    TH2S * u = calivdli->GetLinearFitterHistoForce(idet);
+    if(idet == 0) linearfitterhisto = u;
+    else linearfitterhisto->Add(u);
+
+  }
+
+  // Fit
+
+  Int_t entries = 0;
+  TAxis *xaxis = linearfitterhisto->GetXaxis();
+  TAxis *yaxis = linearfitterhisto->GetYaxis();
+  TLinearFitter linearfitter = TLinearFitter(2,"pol1");
+  //printf("test\n");
+  Double_t integral = linearfitterhisto->Integral();
+  //printf("Integral is %f\n",integral);
+  Bool_t securitybreaking = kFALSE;
+  if(TMath::Abs(integral-1199) < 0.00001) securitybreaking = kTRUE;
+  for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){
+    for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){
+      if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
+       Double_t x = xaxis->GetBinCenter(ibinx+1);
+       Double_t y = yaxis->GetBinCenter(ibiny+1);
+       
+       for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
+         if(!securitybreaking){
+           linearfitter.AddPoint(&x,y);
+           entries++;
+         }
+         else {
+           if(entries< 1198){
+             linearfitter.AddPoint(&x,y);
+             entries++; 
+           }
+         }
+       }
+       
+      }
+    }
+  }
+      
+      //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
+
+      // Eval the linear fitter
+  if(entries > fMinEntries){
+    TVectorD  par  = TVectorD(2);
+    //printf("Fit\n");
+    if((linearfitter.EvalRobust(0.8)==0)) {
+      //printf("Take the param\n");
+      linearfitter.GetParameters(par);
+      //printf("Done\n");
+      //par.Print();
+      //printf("Finish\n");
+      // Put the fCurrentCoef
+      fCurrentCoef[0]  = -par[1];
+      // here the database must be the one of the reconstruction for the lorentz angle....
+      fCurrentCoef2[0] = (par[0]+fCurrentCoef[1]*fCurrentCoef2[1])/fCurrentCoef[0];
+      
+      return fCurrentCoef[0];
+    }
+    else return -100.0;
+    
+    
+  }
+  else {
+    return -100.0;
+  }
+  
+  delete linearfitterhisto;
+  delete fDebugStreamer;
+  fDebugStreamer = 0x0;
+  
 }
 //____________Functions for seeing if the pad is really okey___________________
 //_____________________________________________________________________________
@@ -1910,6 +2045,7 @@ AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectGain(const TObjArray *vectorFit,
   // Create the DetObject
   AliTRDCalDet *object = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
   
+  fScaleGain = scaleFitFactor;
  
   Int_t loop = (Int_t) vectorFit->GetEntriesFast();
   if(loop != 540) AliInfo("The Vector Fit is not complete!");
index 8869445..177a29b 100644 (file)
@@ -60,6 +60,7 @@ class AliTRDCalibraFit : public TObject {
   // Functions fit for CH
   Bool_t   AnalyseCH(const TH2I *ch);
   Bool_t   AnalyseCH(AliTRDCalibraVector *calvect);
+  Double_t AnalyseCHAllTogether(const TH2I *ch);
   
   // Functions fit for PH       
   Bool_t   AnalysePH(const TProfile2D *ph);
@@ -74,6 +75,7 @@ class AliTRDCalibraFit : public TObject {
   
   // Functions fit for vdrift/lorentzangle
   Bool_t   AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
+  Double_t AnalyseLinearFittersAllTogether(AliTRDCalibraVdriftLinearFit *calivdli);
   
   // Pad Calibration
   Bool_t   SetModeCalibration(TString name, Int_t i);
@@ -129,6 +131,7 @@ class AliTRDCalibraFit : public TObject {
   Bool_t   GetAccCDB() const                                         { return fAccCDB;                 }
   Int_t    GetMinEntries() const                                     { return fMinEntries;             }
   Short_t  GetRebin() const                                          { return fRebin;                  }
+  Float_t  GetScaleFactorGain() const                                { return fScaleGain;              }
   
   // Statistics
   Int_t    GetNumberFit() const                                      { return fNumberFit;              }
@@ -206,6 +209,7 @@ class AliTRDCalibraFit : public TObject {
        Bool_t       fAccCDB;                // If there is a calibration database to be compared with....
        Int_t        fMinEntries;            // Min Entries to fit the histo
        Short_t      fRebin;                 // If you want to rebin the histo for the gain calibration 
+       Float_t      fScaleGain;            // Scale Factor used to scale the gain
        
        // Statistics      
        Int_t        fNumberFit;             // To know how many pad groups have been fitted
@@ -350,7 +354,7 @@ class AliTRDCalibraFit : public TObject {
        virtual ~AliTRDCalibraFit();
        
        
-  ClassDef(AliTRDCalibraFit,2)                 // TRD Calibration class
+  ClassDef(AliTRDCalibraFit,3)                 // TRD Calibration class
         
 };
   
index 6dc7d73..6e30234 100644 (file)
@@ -62,7 +62,7 @@
 
 ClassImp(AliTRDPreprocessorOffline)
 
-AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
+  AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
   TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
   fMethodSecond(kTRUE),
   fNameList("TRDCalib"),
@@ -87,7 +87,12 @@ AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
   fMinStatsVdriftT0PH(800*20),
   fMinStatsVdriftLinear(800),
   fMinStatsGain(800),
-  fMinStatsPRF(600)
+  fMinStatsPRF(600),
+  fBackCorrectGain(kFALSE),  
+  fBackCorrectVdrift(kTRUE),
+  fNotEnoughStatisticsForTheGain(kFALSE),
+  fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
+  fStatus(0)
 {
   //
   // default constructor
@@ -127,12 +132,12 @@ void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRun
   //
   fVdriftValidated = kTRUE;
   fT0Validated = kTRUE;
+  fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
   //
   // 2. extraction of the information
   //
-  if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
-  //printf("Finish PH\n");
   if(ReadVdriftLinearFitGlobal(file)) AnalyzeVdriftLinearFit();
+  if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
   //
   // 3. Append QA plots
   //
@@ -169,6 +174,8 @@ void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumb
   //                                       - if empty - local storage 'pwd' uesed
   if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
   //
+  fNotEnoughStatisticsForTheGain = kFALSE;
+  //
   // 1. Initialization 
   if(!ReadGainGlobal(file)) return;
   //
@@ -176,8 +183,8 @@ void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumb
   // 2. extraction of the information
   //
   AnalyzeGain();
-  if(fCalDetGainUsed) CorrectFromDetGainUsed();
-  if(fCalDetVdriftUsed) CorrectFromDetVdriftUsed();
+  if(fBackCorrectGain) CorrectFromDetGainUsed();
+  if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
   //
   // 3. Append QA plots
   //
@@ -269,7 +276,7 @@ void AliTRDPreprocessorOffline::CalibChamberStatus(Int_t startRunNumber, Int_t e
   // 5. update of OCDB
   //
   //
-  UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
+  if((!fNotEnoughStatisticsForTheGain) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
   
 }
 //______________________________________________________________________________________________________
@@ -299,6 +306,8 @@ Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
 
   }
    
+  if((fVersionVdriftUsed == 0) && (fVersionGainUsed == 0)) fStatus = -1;
+
   return kTRUE;
   
 }
@@ -428,7 +437,7 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
   if ((nbtg >                  0) && 
       (nbfit        >= 0.5*nbE) && (nbE > 30)) {
     // create the cal objects
-    if(!fCalDetGainUsed) {
+    if(!fBackCorrectGain) {
       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
       meanother = kTRUE;
     }
@@ -441,6 +450,33 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
     //
     ok = kTRUE;
   }
+  else {
+    fNotEnoughStatisticsForTheGain = kTRUE;
+    Double_t gainoverallnotnormalized =  calibra->AnalyseCHAllTogether(fCH2d);
+    if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
+      AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
+      Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
+      //printf("oldmean %f\n",oldmean);
+      if(oldmean > 0.0)  {
+       Double_t scalefactor = calibra->GetScaleFactorGain();
+       //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
+       calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
+       //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
+       TH1F *coefGain  = calDetGain->MakeHisto1DAsFunctionOfDet();
+       fCalibObjects->AddAt(calDetGain,kGain);
+       fPlots->AddAt(coefGain,kGain);
+       // 
+       ok = kTRUE;
+       if(fStatus == 0) fStatus =5;
+      }
+      else {
+       if(fStatus == 0) fStatus =3;
+      }      
+    }
+    else {
+      if(fStatus == 0) fStatus = 3;
+    }
+  }
   
   calibra->ResetVectorFit();
   
@@ -497,6 +533,9 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
     //
     ok = kTRUE;
   }
+  else {
+    if(fStatus == 0) fStatus = 2;
+  }
   calibra->ResetVectorFit();
  
   return ok;
@@ -547,6 +586,29 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
     //
     ok = kTRUE;
   }
+  else {
+    fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
+    Double_t vdriftoverall =  calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit);
+    if(fCalDetVdriftUsed && (vdriftoverall > 0.0)) {
+      AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
+      Double_t oldmean = fCalDetVdriftUsed->CalcMean(kFALSE);
+      //printf("oldmean %f\n",oldmean);
+      if(oldmean > 0.0)  {
+       //printf("Correction factor %f\n",vdriftoverall);
+       calDetVdrift->Multiply(vdriftoverall/oldmean);
+       //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
+       TH1F *coefDriftLinear  = calDetVdrift->MakeHisto1DAsFunctionOfDet();
+       // Put them in the array
+       fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
+       fPlots->AddAt(coefDriftLinear,kVdriftLinear);
+       // 
+       ok = kTRUE;
+       fStatus = 4; 
+      }
+      else fStatus = 1;      
+    }
+    else fStatus = 1;
+  }
   
   calibra->ResetVectorFit();
   
@@ -745,23 +807,37 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
    if(!calDetVdrift) return;
 
    // Calculate mean
-
-   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);
-
-
+   if(!fNotEnoughStatisticsForTheGain) {
+     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, const Char_t *storagePath){
    //
    // Update OCDB entry
@@ -882,7 +958,7 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
 
  }
  //__________________________________________________________________________________________________________________________
- Bool_t AliTRDPreprocessorOffline::ValidateGain() const {
+ Bool_t AliTRDPreprocessorOffline::ValidateGain() {
    //
    // Validate OCDB entry
    //
@@ -893,9 +969,13 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
      Double_t rms = calDet->GetRMSRobust();
      if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
      //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
-     else return kFALSE;
+     else {
+       fStatus = 6;
+       return kFALSE;
+     }
    }
    else return kFALSE;
+   
 
 
  }
@@ -915,7 +995,10 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
      Double_t mean = calDet->GetMean();
      Double_t rms = calDet->GetRMSRobust();
      //printf("Vdrift::mean %f, rms %f\n",mean,rms);
-     if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) ok = kFALSE;
+     if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
+       fStatus = 6;
+       ok = kFALSE;
+     }
    }
    else return kFALSE; 
 
@@ -925,7 +1008,10 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
        Double_t mean = calPad->GetMean();
        Double_t rms = calPad->GetRMS();
        //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
-       if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) ok = kFALSE;
+       if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
+        fStatus = 6;
+        ok = kFALSE;
+       }
      }
      else return kFALSE;
    }
@@ -948,7 +1034,10 @@ Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
      //Double_t rmspad = calPad->GetRMS();
      //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
      if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
-     else return kFALSE;
+     else {
+       fStatus = 6;
+       return kFALSE;
+     }
    }
    else return kFALSE;
 
index 83a1151..340fb75 100644 (file)
@@ -76,12 +76,13 @@ public:
   void UpdateOCDBPRF(Int_t  startRunNumber, Int_t endRunNumber, const char* storagePath);
   void UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath);
 
-  Bool_t ValidateGain() const;
+  Bool_t ValidateGain();
   Bool_t ValidateVdrift();
   Bool_t ValidateT0();
   Bool_t ValidatePRF() const;
   Bool_t ValidateChamberStatus() const;
 
+  Int_t    GetStatus() const                                         { return fStatus;                 }
   Int_t    GetVersionGainUsed() const                                { return fVersionGainUsed;        }
   Int_t    GetSubVersionGainUsed() const                             { return fSubVersionGainUsed;     }
   Int_t    GetFirstRunVdriftUsed() const                             { return fFirstRunVdriftUsed;     }
@@ -92,6 +93,8 @@ public:
   void     SetMinStatsVdriftLinear(Int_t minStatsVdriftLinear)       { fMinStatsVdriftLinear = minStatsVdriftLinear; }  
   void     SetMinStatsGain(Int_t minStatsGain)                       { fMinStatsGain = minStatsGain; }  
   void     SetMinStatsPRF(Int_t minStatsPRF)                         { fMinStatsPRF = minStatsPRF; }  
+  void     SetBackCorrectGain(Bool_t backCorrectGain)                { fBackCorrectGain = backCorrectGain; }
+  void     SetBackCorrectVdrift(Bool_t backCorrectVdrift)            { fBackCorrectVdrift = backCorrectVdrift; }
 
  
   
@@ -120,6 +123,11 @@ public:
   Int_t    fMinStatsVdriftLinear;         // MinStats Vdrift Linear
   Int_t    fMinStatsGain;                 // MinStats Gain
   Int_t    fMinStatsPRF;                  // MinStats PRF
+  Bool_t   fBackCorrectGain;              // Back correction afterwards gain  
+  Bool_t   fBackCorrectVdrift;            // Back correction afterwards vdrift
+  Bool_t   fNotEnoughStatisticsForTheGain;// Take the chamber per chamber distribution from the default distribution
+  Bool_t   fNotEnoughStatisticsForTheVdriftLinear;// Take the chamber per chamber distribution from the default distribution
+  Int_t    fStatus;                       // Status of the TRD offline preprocessor: -1 nothing but do not worry; 0 everything ok; 1 not enough stat vdrift, 2 not enough stat to, 3 not enough stat gain and chammber status, 4 not enough stat vdrift but could put a mean, 5 not enough stat gain but could put a mean
 
 
   Int_t GetSubVersion(TString name) const;
@@ -131,7 +139,7 @@ public:
 private:
   AliTRDPreprocessorOffline& operator=(const AliTRDPreprocessorOffline&); // not implemented
   AliTRDPreprocessorOffline(const AliTRDPreprocessorOffline&); // not implemented
-  ClassDef(AliTRDPreprocessorOffline,1)
+  ClassDef(AliTRDPreprocessorOffline,2)
 };
 
 #endif