New TRD calibration task by Raphaelle
authorcblume <cblume@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 10 Dec 2009 15:29:46 +0000 (15:29 +0000)
committercblume <cblume@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 10 Dec 2009 15:29:46 +0000 (15:29 +0000)
TRD/AliTRDCalibTask.cxx [new file with mode: 0644]
TRD/AliTRDCalibTask.h [new file with mode: 0644]
TRD/Macros/AliTRDrunCalib.C [new file with mode: 0644]
TRD/TRDcalibLinkDef.h [new file with mode: 0644]
TRD/libTRDcalib.pkg [new file with mode: 0644]

diff --git a/TRD/AliTRDCalibTask.cxx b/TRD/AliTRDCalibTask.cxx
new file mode 100644 (file)
index 0000000..25b43a4
--- /dev/null
@@ -0,0 +1,875 @@
+\r
+/**************************************************************************\r
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+ *                                                                        *\r
+ * Author: The ALICE Off-line Project.                                    *\r
+ * Contributors are mentioned in the code where appropriate.              *\r
+ *                                                                        *\r
+ * Permission to use, copy, modify and distribute this software and its   *\r
+ * documentation strictly for non-commercial purposes is hereby granted   *\r
+ * without fee, provided that the above copyright notice appears in all   *\r
+ * copies and that both the copyright notice and this permission notice   *\r
+ * appear in the supporting documentation. The authors make no claims     *\r
+ * about the suitability of this software for any purpose. It is          *\r
+ * provided "as is" without express or implied warranty.                  *\r
+ **************************************************************************/\r
+\r
+// macro for very simple analysis\r
+\r
+\r
+\r
+#include "Riostream.h"\r
+#include "TChain.h"\r
+#include "TTree.h"\r
+#include "TFile.h"\r
+#include "TProfile2D.h"\r
+#include "TH2I.h"\r
+#include "TH1F.h"\r
+#include "TH2F.h"\r
+#include "TList.h"\r
+#include "TMath.h"\r
+#include "TObject.h"\r
+#include "TObjArray.h"\r
+#include "TString.h"\r
+#include "TCanvas.h"\r
+#include "TLegend.h"\r
+#include "TStyle.h"\r
+#include "TLine.h"\r
+\r
+#include "AliAnalysisTask.h"\r
+#include "AliAnalysisManager.h"\r
+\r
+#include "AliESDVertex.h"\r
+#include "AliESDEvent.h"\r
+#include "AliESDfriend.h"\r
+#include "AliESDInputHandler.h"\r
+#include "AliESDtrack.h"\r
+#include "AliESDfriendTrack.h"\r
+#include "AliTRDtrackV1.h"\r
+#include "AliTRDseedV1.h"\r
+#include "AliTRDcluster.h"\r
+#include "AliTRDgeometry.h"\r
+#include "AliESDtrackCuts.h"\r
+#include "AliESDVertex.h"\r
+#include "AliTRDCalDet.h"\r
+\r
+#include "AliTRDCalibraFillHisto.h"\r
+#include "AliTRDCalibraVdriftLinearFit.h" \r
+\r
+#include "AliCDBManager.h"\r
+#include "AliTRDcalibDB.h"\r
+\r
+\r
+#include "AliTRDCalibTask.h"\r
+\r
+\r
+ClassImp(AliTRDCalibTask)\r
+\r
+//________________________________________________________________________\r
+  AliTRDCalibTask::AliTRDCalibTask(const char *name) \r
+    : AliAnalysisTask(name, ""), fESD(0), fESDfriend(0),\r
+      fEsdTrack(0),\r
+      fFriendTrack(0),\r
+      fCalibObject(0),\r
+      fTrdTrack(0),\r
+      fCl(0),\r
+      fListHist(0),\r
+      fTRDCalibraFillHisto(0),\r
+      fNEvents(0),\r
+      fNbTRDTrack(0),\r
+      fNbTRDTrackOffline(0),\r
+      fNbTRDTrackStandalone(0),\r
+      fNbTPCTRDtrack(0),\r
+      fNbTimeBin(0),\r
+      fNbTimeBinOffline(0),\r
+      fNbTimeBinStandalone(0),\r
+      fNbClusters(0),\r
+      fNbClustersOffline(0),\r
+      fNbClustersStandalone(0),\r
+      fNbTracklets(0),\r
+      fNbTrackletsOffline(0),\r
+      fNbTrackletsStandalone(0),\r
+      fCH2dSum(0),\r
+      fPH2dSum(0),\r
+      fCH2dSM(0),\r
+      fPH2dSM(0),\r
+      fHisto2d(kTRUE),\r
+      fVector2d(kFALSE),\r
+      fVdriftLinear(kTRUE),\r
+      fNbTimeBins(0),\r
+      fSelectedTrigger(new TObjArray()),\r
+      fRejected(kTRUE),\r
+      fEsdTrackCuts(0),\r
+      fRequirePrimaryVertex(kFALSE),\r
+      fMinNbContributors(0),\r
+      fLow(0),\r
+      fHigh(30),\r
+      fFillZero(kFALSE),\r
+      fNormalizeNbOfCluster(kFALSE),\r
+      fRelativeScale(0.0),\r
+      fMaxCluster(100.0),\r
+      fNbMaxCluster(2),\r
+      fOfflineTracks(kFALSE),\r
+      fStandaloneTracks(kFALSE),\r
+      fCalDetGain(0x0),\r
+      fMaxEvent(0),\r
+      fCounter(0),\r
+      fDebug(0)\r
+{\r
+  //\r
+  // Default constructor\r
+  //\r
+\r
+  fNz[0] = 0;\r
+  fNz[1] = 0;\r
+  fNz[2] = 0;\r
+  \r
+  fNrphi[0] = 0;\r
+  fNrphi[1] = 0;\r
+  fNrphi[2] = 0;\r
+\r
+  // Define input and output slots here\r
+  // Input slot #0 works with a TChain\r
+  DefineInput(0, TChain::Class());\r
+    \r
+  // Output slot #0 writes into a TList container\r
+  DefineOutput(0, TList::Class());\r
+  \r
+   \r
+}\r
+//____________________________________________________________________________________\r
+AliTRDCalibTask::~AliTRDCalibTask()\r
+{\r
+  //\r
+  // AliTRDCalibTask destructor\r
+  //\r
+\r
+  // Pointeur\r
+  if(fNEvents) delete fNEvents;\r
+  if(fNbTRDTrack) delete fNbTRDTrack;\r
+  if(fNbTRDTrackOffline) delete fNbTRDTrackOffline;\r
+  if(fNbTRDTrackStandalone) delete fNbTRDTrackStandalone;\r
+  if(fNbTPCTRDtrack) delete fNbTPCTRDtrack;\r
+  if(fNbTimeBin) delete fNbTimeBin;\r
+  if(fNbTimeBinOffline) delete fNbTimeBinOffline;\r
+  if(fNbTimeBinStandalone) delete fNbTimeBinStandalone;\r
+  if(fNbClusters) delete fNbClusters;\r
+  if(fNbClustersOffline) delete fNbClustersOffline;\r
+  if(fNbClustersStandalone) delete fNbClustersStandalone;\r
+  if(fNbTracklets) delete fNbTracklets;\r
+  if(fNbTrackletsOffline) delete fNbTrackletsOffline;\r
+  if(fNbTrackletsStandalone) delete fNbTrackletsStandalone;\r
+  if(fCH2dSum) delete fCH2dSum;\r
+  if(fPH2dSum) delete fPH2dSum;\r
+  if(fCH2dSM) delete fCH2dSM;\r
+  if(fPH2dSM) delete fPH2dSM;\r
+  if(fCalDetGain) delete fCalDetGain;\r
+  \r
+  if(fSelectedTrigger) {\r
+    fSelectedTrigger->Delete();\r
+    delete fSelectedTrigger;\r
+  }\r
+  if(fEsdTrackCuts) {\r
+    delete fEsdTrackCuts;\r
+  }\r
+  \r
+}\r
+//________________________________________________________________________\r
+void AliTRDCalibTask::ConnectInputData(Option_t *) \r
+{\r
+  // Connect ESD or AOD here\r
+  // Called once\r
+  \r
+  TTree* tree = dynamic_cast<TTree*> (GetInputData(0)); //pointer wird "umgecastet" auf anderen Variablentyp\r
+  if (!tree) {\r
+    Printf("ERROR: Could not read chain from input slot 0");\r
+  } else {\r
+    \r
+    AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());\r
+    \r
+    if (!esdH) {\r
+      Printf("ERROR: Could not get ESDInputHandler");\r
+    } else {\r
+      fESD = esdH->GetEvent();\r
+      esdH->SetActiveBranches("ESDfriend*");\r
+      Printf("*** CONNECTED NEW EVENT ****");\r
+    }\r
+    \r
+  }\r
+}\r
+//________________________________________________________________________\r
+void AliTRDCalibTask::CreateOutputObjects() \r
+{\r
+  \r
+\r
+  // Number of time bins\r
+  if(fNbTimeBins==0) {\r
+    AliTRDcalibDB *cal = AliTRDcalibDB::Instance();\r
+    fNbTimeBins = cal->GetNumberOfTimeBinsDCS();\r
+    if(fNbTimeBins <= 0){ \r
+      AliWarning(Form("No of TimeBins from DB [%d] use default [30]", fNbTimeBins));\r
+      fNbTimeBins = 30;\r
+    }\r
+  }\r
+  \r
+  // instance calibration \r
+  fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();\r
+  fTRDCalibraFillHisto->SetHisto2d(fHisto2d); // choose to use histograms\r
+  fTRDCalibraFillHisto->SetVector2d(fVector2d); // choose to use vectors\r
+  fTRDCalibraFillHisto->SetCH2dOn();  // choose to calibrate the gain\r
+  fTRDCalibraFillHisto->SetPH2dOn();  // choose to calibrate the drift velocity\r
+  fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF\r
+  fTRDCalibraFillHisto->SetLinearFitterOn(fVdriftLinear); // Other possibility vdrift VDRIFT\r
+  fTRDCalibraFillHisto->SetLinearFitterDebugOn(fVdriftLinear); // Other possibility vdrift\r
+  for(Int_t k = 0; k < 3; k++){\r
+    if(((fNz[k] != 10) && (fNrphi[k] != 10)) && ((fNz[k] != 100) && (fNrphi[k] != 100))) {\r
+      fTRDCalibraFillHisto->SetNz(k,fNz[k]);                                    // Mode calibration\r
+      fTRDCalibraFillHisto->SetNrphi(k,fNrphi[k]);                             // Mode calibration\r
+    }\r
+    else {\r
+      if((fNz[k] == 100) && (fNrphi[k] == 100))  {\r
+       if(fVector2d) AliInfo("The mode all together is not supported by the vector method");\r
+       fTRDCalibraFillHisto->SetAllTogether(k);\r
+      }\r
+      if((fNz[k] == 10) && (fNrphi[k] == 10))  {\r
+       if(fVector2d) AliInfo("The mode per supermodule is not supported by the vector method");\r
+       fTRDCalibraFillHisto->SetPerSuperModule(k);\r
+      }\r
+    }\r
+  }\r
+  // Variables for how to fill\r
+  fTRDCalibraFillHisto->SetFillWithZero(fFillZero);\r
+  fTRDCalibraFillHisto->SetNormalizeNbOfCluster(fNormalizeNbOfCluster); \r
+  fTRDCalibraFillHisto->SetMaxCluster(fMaxCluster);\r
+  fTRDCalibraFillHisto->SetNbMaxCluster(fNbMaxCluster);\r
+  \r
+  // Init with 30 timebins\r
+  fTRDCalibraFillHisto->Init2Dhistos(fNbTimeBins); // initialise the histos\r
+  fTRDCalibraFillHisto->SetNumberClusters(fLow); // At least 11 clusters\r
+  fTRDCalibraFillHisto->SetNumberClustersf(fHigh); // At least 11 clusters\r
+  fRelativeScale = fTRDCalibraFillHisto->GetRelativeScale(); // Get the relative scale for the gain\r
+  \r
+  // For testing only\r
+  if(fDebug > 2) fTRDCalibraFillHisto->SetDebugLevel(1); //debug stuff\r
+  \r
+  // output list\r
+  fListHist = new TList();\r
+  if(fHisto2d) {  \r
+    fListHist->Add(fTRDCalibraFillHisto->GetCH2d());\r
+    fListHist->Add(fTRDCalibraFillHisto->GetPH2d()); \r
+    fListHist->Add(fTRDCalibraFillHisto->GetPRF2d());\r
+  } \r
+  if(fVdriftLinear) fListHist->Add((TObject *) fTRDCalibraFillHisto->GetVdriftLinearFit());\r
+  if(fVector2d) fListHist->Add((TObject *) fTRDCalibraFillHisto->GetCalibraVector()); //calibra vector  \r
+  fNEvents = new TH1I("NEvents","NEvents", 2, 0, 2);\r
+  fListHist->Add(fNEvents);\r
+  \r
+  /////////////////////////////////////////\r
+  // First debug level\r
+  ///////////////////////////////////////\r
+  if(fDebug > 0) {\r
+    \r
+    fPH2dSM = new TProfile2D("PH2dSM","Nz10Nrphi10"\r
+                           ,fNbTimeBins,-0.05,(Double_t)((fNbTimeBins-0.5)/10.0)\r
+                          ,18,0,18);\r
+    fPH2dSM->SetYTitle("Det/pad groups");\r
+    fPH2dSM->SetXTitle("time [#mus]");\r
+    fPH2dSM->SetZTitle("<PH> [a.u.]");\r
+    fPH2dSM->SetStats(0);\r
+    //\r
+    fCH2dSM = new TH2I("CH2dSM","Nz10Nrphi10",50,0,300,18,0,18);\r
+    fCH2dSM->SetYTitle("Det/pad groups");\r
+    fCH2dSM->SetXTitle("charge deposit [a.u]");\r
+    fCH2dSM->SetZTitle("counts");\r
+    fCH2dSM->SetStats(0);\r
+    fCH2dSM->Sumw2();\r
+    //\r
+    fPH2dSum = new TProfile2D("PH2dSum","Nz100Nrphi100"\r
+                           ,fNbTimeBins,-0.05,(Double_t)((fNbTimeBins-0.5)/10.0)\r
+                           ,1,0,1);\r
+    fPH2dSum->SetYTitle("Det/pad groups");\r
+    fPH2dSum->SetXTitle("time [#mus]");\r
+    fPH2dSum->SetZTitle("<PH> [a.u.]");\r
+    fPH2dSum->SetStats(0);\r
+    //\r
+    fCH2dSum = new TH2I("CH2dSum","Nz100Nrphi100",50,0,300,1,0,1);\r
+    fCH2dSum->SetYTitle("Det/pad groups");\r
+    fCH2dSum->SetXTitle("charge deposit [a.u]");\r
+    fCH2dSum->SetZTitle("counts");\r
+    fCH2dSum->SetStats(0);\r
+    fCH2dSum->Sumw2();\r
+    \r
+    // Add them\r
+    fListHist->Add(fPH2dSM);\r
+    fListHist->Add(fCH2dSM);\r
+    fListHist->Add(fPH2dSum);\r
+    fListHist->Add(fCH2dSum);\r
+  }\r
+\r
+  /////////////////////////////////////////\r
+  // Second debug level\r
+  ///////////////////////////////////////\r
+  if(fDebug > 1) {\r
+\r
+    fNbTRDTrack = new TH1F("TRDTrack","TRDTrack",50,0,50);\r
+    fNbTRDTrack->Sumw2();\r
+    fNbTRDTrackOffline = new TH1F("TRDTrackOffline","TRDTrackOffline",50,0,50);\r
+    fNbTRDTrackOffline->Sumw2();\r
+    fNbTRDTrackStandalone = new TH1F("TRDTrackStandalone","TRDTrackStandalone",50,0,50);\r
+    fNbTRDTrackStandalone->Sumw2();\r
+    fNbTPCTRDtrack = new TH2F("NbTPCTRDtrack","NbTPCTRDtrack",100,0,100,100,0,100);\r
+    fNbTPCTRDtrack->Sumw2();\r
+    //\r
+    fNbTimeBin = new TH1F("NbTimeBin","NbTimeBin",35,0,35);\r
+    fNbTimeBin->Sumw2();\r
+    fNbTimeBinOffline = new TH1F("NbTimeBinOffline","NbTimeBinOffline",35,0,35);\r
+    fNbTimeBinOffline->Sumw2();\r
+    fNbTimeBinStandalone = new TH1F("NbTimeBinStandalone","NbTimeBinStandalone",35,0,35);\r
+    fNbTimeBinStandalone->Sumw2();\r
+    //\r
+    fNbClusters = new TH1F("NbClusters","",35,0,35);\r
+    fNbClusters->Sumw2();\r
+    fNbClustersOffline = new TH1F("NbClustersOffline","",35,0,35);\r
+    fNbClustersOffline->Sumw2();\r
+    fNbClustersStandalone = new TH1F("NbClustersStandalone","",35,0,35);\r
+    fNbClustersStandalone->Sumw2();\r
+    //\r
+    fNbTracklets = new TH1F("NbTracklets","NbTracklets",540,0.,540.);\r
+    fNbTracklets->Sumw2();\r
+    fNbTrackletsOffline = new TH1F("NbTrackletsOffline","NbTrackletsOffline",540,0.,540.);\r
+    fNbTrackletsOffline->Sumw2();\r
+    fNbTrackletsStandalone = new TH1F("NbTrackletsStandalone","NbTrackletsStandalone",540,0.,540.);\r
+    fNbTrackletsStandalone->Sumw2();\r
+   \r
+    fListHist->Add(fNbTRDTrack);\r
+    fListHist->Add(fNbTRDTrackOffline);\r
+    fListHist->Add(fNbTRDTrackStandalone);\r
+    fListHist->Add(fNbTPCTRDtrack);\r
+    \r
+    fListHist->Add(fNbTimeBin);\r
+    fListHist->Add(fNbTimeBinOffline);\r
+    fListHist->Add(fNbTimeBinStandalone);\r
+    fListHist->Add(fNbClusters);\r
+    fListHist->Add(fNbClustersOffline);\r
+    fListHist->Add(fNbClustersStandalone);\r
+    fListHist->Add(fNbTracklets);\r
+    fListHist->Add(fNbTrackletsOffline);\r
+    fListHist->Add(fNbTrackletsStandalone);\r
+    \r
+  }\r
+  \r
+ }\r
+ //________________________________________________________________________\r
+ void AliTRDCalibTask::Exec(Option_t *) \r
+ {\r
+   AliLog::SetGlobalLogLevel(AliLog::kError);\r
+\r
+   if (!fESD) {\r
+     Printf("ERROR: fESD not available");\r
+     return;\r
+   }\r
+\r
+   fCounter++;\r
+   if((fMaxEvent != 0) && (fMaxEvent < fCounter)) return;\r
+\r
+   ///////////////////////////////\r
+   // Require a primary vertex\r
+   //////////////////////////////\r
+   if(fRequirePrimaryVertex) {\r
+     //printf("test\n");\r
+     const AliESDVertex* vtxESD = 0x0;\r
+     vtxESD = fESD->GetPrimaryVertexTPC() ;\r
+     if(!vtxESD){\r
+       //printf("No primary at all vertex\n");\r
+       return;\r
+     }\r
+     Int_t nCtrb = vtxESD->GetNContributors();\r
+     //printf("Number of contributors %d\n",nCtrb);\r
+     if(nCtrb < fMinNbContributors) return;\r
+   }\r
+\r
+   //printf("Primary vertex passed\n");\r
+\r
+   ///////////////////\r
+   // Check trigger\r
+   ///////////////////\r
+   //printf("Class Fired %s\n",(const char*)fESD->GetFiredTriggerClasses());\r
+   Bool_t pass = kTRUE;\r
+   Int_t numberOfTriggerSelected = fSelectedTrigger->GetEntriesFast();\r
+   //printf("numberofTriggerSelected %d\n",numberOfTriggerSelected);\r
+   if(fRejected) {\r
+     pass = kTRUE;\r
+     for(Int_t k = 0; k < numberOfTriggerSelected; k++){\r
+       const TObjString *const obString=(TObjString*)fSelectedTrigger->At(k);\r
+       const TString tString=obString->GetString();\r
+       if(fESD->IsTriggerClassFired((const char*)tString)) {\r
+        pass = kFALSE;\r
+       }\r
+     }\r
+   }\r
+   else {\r
+     pass = kFALSE;\r
+     for(Int_t k = 0; k < numberOfTriggerSelected; k++){\r
+       const TObjString *const obString=(TObjString*)fSelectedTrigger->At(k);\r
+       const TString tString=obString->GetString();\r
+       if(fESD->IsTriggerClassFired((const char*)tString)) {\r
+        pass = kTRUE;\r
+       }\r
+     }\r
+   }\r
+   if(!pass) return;   \r
+\r
+   //printf("Trigger passed\n");\r
+  \r
+   fNEvents->Fill(1);\r
+\r
+   // In total\r
+   Int_t nbTrdTracks = 0;\r
+   // standalone\r
+   Int_t nbTrdTracksStandalone = 0;\r
+   // offline\r
+   Int_t nbTrdTracksOffline = 0;\r
+   // TPC\r
+   Int_t nbtrackTPC = 0;\r
+\r
+   Double_t nbTracks = fESD->GetNumberOfTracks();\r
+   //printf("Number of tracks %f\n",nbTracks);  \r
+\r
+   if (nbTracks <= 0.0) {\r
+     \r
+     if(fDebug > 1) {\r
+       fNbTRDTrack->Fill(nbTrdTracks);\r
+       fNbTRDTrackStandalone->Fill(nbTrdTracksStandalone);\r
+       fNbTRDTrackOffline->Fill(nbTrdTracksOffline);\r
+     }\r
+     PostData(0, fListHist);\r
+     return;\r
+   }\r
+\r
+   fESDfriend = (AliESDfriend *)fESD->FindListObject("AliESDfriend");\r
+   fESD->SetESDfriend(fESDfriend);\r
+   if(!fESDfriend) return;   \r
+   \r
+   //printf("has friends\n");\r
+\r
+   ////////////////////////////////////\r
+   // Check the number of TPC tracks\r
+   ///////////////////////////////////\r
+   for(Int_t itrk = 0; itrk < nbTracks; itrk++){\r
+     // Get ESD track\r
+     fEsdTrack = fESD->GetTrack(itrk);\r
+     ULong_t status = fEsdTrack->GetStatus(); \r
+     if(status&(AliESDtrack::kTPCout)) nbtrackTPC++;\r
+     // Check that the calibration object is here\r
+     if(fESDfriend && (fESDfriend->GetTrack(itrk))) {\r
+       fFriendTrack = new AliESDfriendTrack(*(fESDfriend->GetTrack(itrk)));\r
+       Int_t counteer = 0;\r
+       Int_t icalib=0;\r
+       while((fCalibObject = (TObject *)(fFriendTrack->GetCalibObject(icalib++)))){\r
+        if(strcmp(fCalibObject->IsA()->GetName(), "AliTRDtrackV1") != 0) continue;\r
+        counteer++;\r
+       }\r
+       if(counteer > 0) {\r
+        nbTrdTracks++;\r
+        if((status&(AliESDtrack::kTRDout)) && (!(status&(AliESDtrack::kTRDin)))) {\r
+          nbTrdTracksStandalone++;\r
+        }\r
+        if((status&(AliESDtrack::kTRDin))) {\r
+          nbTrdTracksOffline++;\r
+        }\r
+       }\r
+       if(fFriendTrack) delete fFriendTrack;\r
+     }\r
+   }\r
+   //printf("Number of TPC tracks %d, TRD %d\n",nbtrackTPC,nbTrdTracks);\r
+   if((nbtrackTPC>0) && (nbTrdTracks > (3.0*nbtrackTPC))) pass = kFALSE;\r
+   \r
+   if(fDebug > 1) {\r
+     \r
+     fNbTRDTrack->Fill(nbTrdTracks);\r
+     fNbTRDTrackStandalone->Fill(nbTrdTracksStandalone);\r
+     fNbTRDTrackOffline->Fill(nbTrdTracksOffline);\r
+     fNbTPCTRDtrack->Fill(nbTrdTracks,nbtrackTPC);\r
+   \r
+   }\r
+\r
+   if(!pass) {\r
+     PostData(0, fListHist);\r
+     return;\r
+   }\r
+  \r
+   /////////////////////////////////////\r
+   // Loop on AliESDtrack\r
+   ////////////////////////////////////\r
+      \r
+   for(int itrk=0; itrk < nbTracks; itrk++){\r
+\r
+     // Get ESD track\r
+     fEsdTrack = fESD->GetTrack(itrk);\r
+     if(!fEsdTrack) continue;\r
+\r
+     // Quality cuts on the AliESDtrack\r
+     if((fEsdTrackCuts) && (!fEsdTrackCuts->IsSelected((AliVParticle *)fEsdTrack))) {\r
+       //printf("Not a good track\n");\r
+       continue;\r
+     }\r
+     \r
+     // Other cuts\r
+     Bool_t good = kTRUE;\r
+     Bool_t standalonetrack = kFALSE;\r
+     Bool_t offlinetrack = kFALSE;\r
+     ULong_t status = fEsdTrack->GetStatus();\r
+     \r
+     if(!(fESDfriend->GetTrack(itrk)))  continue;   \r
+     \r
+     fFriendTrack = new AliESDfriendTrack(*(fESDfriend->GetTrack(itrk)));\r
+     \r
+     //////////////////////////////////////\r
+     // Loop on calibration objects\r
+     //////////////////////////////////////\r
+     Int_t icalib=0;\r
+     while((fCalibObject = (TObject *)(fFriendTrack->GetCalibObject(icalib++)))){\r
+       if(strcmp(fCalibObject->IsA()->GetName(), "AliTRDtrackV1") != 0) continue;\r
+\r
+       if((status&(AliESDtrack::kTRDout)) && (!(status&(AliESDtrack::kTRDin)))) {\r
+        standalonetrack = kTRUE;\r
+       }\r
+       if((status&(AliESDtrack::kTRDin))) {\r
+        offlinetrack = kTRUE;\r
+       }\r
+       if(fOfflineTracks){\r
+        if(!offlinetrack){\r
+          good = kFALSE;\r
+        }\r
+       }\r
+       else if(fStandaloneTracks){\r
+        if(!standalonetrack){\r
+          good = kFALSE;\r
+        }\r
+       }\r
+       \r
+       fTrdTrack = (AliTRDtrackV1 *)fCalibObject;\r
+       if(good) fTRDCalibraFillHisto->UpdateHistogramsV1(fTrdTrack);\r
+       \r
+       //////////////////////////////////\r
+       // Debug \r
+       ////////////////////////////////\r
+\r
+       if(fDebug > 0) {\r
+        \r
+        \r
+        Int_t nbtracklets = 0;\r
+        \r
+        // Check some stuff\r
+        Bool_t standalonetracklet = kFALSE;  \r
+        const AliTRDseedV1 *tracklet = 0x0;\r
+        //////////////////////////////////////\r
+        // Loop tracklets\r
+        ///////////////////////////////////// \r
+        for(Int_t itr = 0; itr < 6; itr++){\r
+          \r
+          if(!(tracklet = fTrdTrack->GetTracklet(itr))) continue;\r
+          if(!tracklet->IsOK()) continue;\r
+          nbtracklets++;\r
+          standalonetracklet = kFALSE; \r
+          if(tracklet->IsStandAlone()) standalonetracklet = kTRUE;\r
+\r
+          Int_t nbclusters = 0;\r
+          Double_t phtb[AliTRDseedV1::kNtb];\r
+          memset(phtb, 0, AliTRDseedV1::kNtb*sizeof(Double_t));\r
+          Double_t sum = 0.0;\r
+          Float_t normalisation = 6.67;\r
+          Int_t detector = 0;\r
+          Int_t sector = 0;\r
+          //Int_t crossrow = 0;\r
+          \r
+          // Check no shared clusters\r
+          //for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){\r
+          //  if((fcl = tracklet->GetClusters(icc)))  crossrow = 1;\r
+          // }\r
+          \r
+          // Loop on clusters\r
+          for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){\r
+            \r
+            if(!(fCl = tracklet->GetClusters(ic))) continue;\r
+            nbclusters++;\r
+            Int_t time = fCl->GetPadTime();\r
+            Float_t ch =  tracklet->GetdQdl(ic);\r
+            Float_t qcl = TMath::Abs(fCl->GetQ());\r
+            detector = fCl->GetDetector();       \r
+            if((time>-1) && (time<fNbTimeBins)) phtb[time]=qcl;\r
+            if((fCalDetGain) && (fCalDetGain->GetValue(detector) > 0.0)) sum += ch*fCalDetGain->GetValue(detector)/normalisation;      \r
+            else sum += ch/normalisation;\r
+            \r
+            if(fDebug > 1) {\r
+              fNbTimeBin->Fill(time);\r
+              if(tracklet->IsStandAlone()) fNbTimeBinStandalone->Fill(time);\r
+              else fNbTimeBinOffline->Fill(time);\r
+            }\r
+          }\r
+          sector = AliTRDgeometry::GetSector(detector);\r
+          \r
+          if(fDebug > 1) {\r
+            fNbTracklets->Fill(detector);\r
+            if(tracklet->IsStandAlone()) fNbTrackletsStandalone->Fill(detector);\r
+            else fNbTrackletsOffline->Fill(detector);\r
+          \r
+            fNbClusters->Fill(nbclusters);\r
+            if(tracklet->IsStandAlone())  fNbClustersStandalone->Fill(nbclusters);\r
+            else  fNbClustersOffline->Fill(nbclusters);\r
+          }       \r
+\r
+          if(fDebug > 0) {\r
+            if((nbclusters > fLow) && (nbclusters < fHigh)){\r
+              if(fRelativeScale > 0.0) sum = sum/fRelativeScale;              \r
+              fCH2dSM->Fill(sum,sector+0.5);\r
+              fCH2dSum->Fill(sum,0.5);\r
+              Bool_t checknoise = kTRUE;\r
+              if(fMaxCluster > 0) {\r
+                if(phtb[0] > fMaxCluster) checknoise = kFALSE;\r
+                if(fNbTimeBins > fNbMaxCluster) {\r
+                  for(Int_t k = (fNbTimeBins-fNbMaxCluster); k < fNbTimeBins; k++){\r
+                    if(phtb[k] > fMaxCluster) checknoise = kFALSE;\r
+                  }\r
+                }\r
+              }\r
+              if(checknoise) {        \r
+                for(int ic=0; ic<fNbTimeBins; ic++){\r
+                  if(fFillZero) {\r
+                    fPH2dSum->Fill((Double_t)(ic/10.0),0.5,(Double_t)phtb[ic]);\r
+                    fPH2dSM->Fill((Double_t)(ic/10.0),sector+0.5,(Double_t)phtb[ic]);\r
+                  }\r
+                  else {\r
+                    if(phtb[ic] > 0.0) {\r
+                      fPH2dSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);\r
+                      fPH2dSM->Fill((Double_t)(ic/10.0),sector+0.5,(Double_t)phtb[ic]);\r
+                    }\r
+                  }\r
+                }\r
+              }\r
+            }\r
+          }\r
+        } // loop on tracklets\r
+    \r
+       } // debug\r
+       \r
+     }// while calibration objects\r
+     \r
+     delete fFriendTrack;\r
+     \r
+   } // loop ESD track\r
+   \r
+   // Post output data\r
+   PostData(0, fListHist);\r
+ }     \r
+//________________________________________________________________________\r
+void AliTRDCalibTask::Terminate(Option_t *) \r
+{\r
+  \r
+  if(fTRDCalibraFillHisto) fTRDCalibraFillHisto->DestroyDebugStreamer();\r
+\r
\r
+}\r
+//_______________________________________________________\r
+Bool_t AliTRDCalibTask::Load(const Char_t *filename)\r
+{\r
+  //\r
+  // Generic container loader\r
+  //\r
+\r
+  if(!TFile::Open(filename)){\r
+    //AliWarning(Form("Couldn't open file %s.", filename));\r
+    return kFALSE;\r
+  }\r
+  TList *o = 0x0;\r
+  if(!(o = (TList*)gFile->Get(GetName()))){\r
+    //AliWarning("Missing histogram container.");\r
+    return kFALSE;\r
+  }\r
+  fListHist = (TList*)o->Clone(GetName());\r
+  gFile->Close();\r
+  return kTRUE;\r
+}\r
+//________________________________________________________________________\r
+void AliTRDCalibTask::Plot() \r
+{\r
+  //\r
+  // Plot the histos stored in the TList\r
+  //\r
\r
+  if(!fListHist) return;\r
+\r
+  /////////////////////////////////////\r
+  // Take the debug stuff\r
+  /////////////////////////////////////\r
+\r
+  TH1I *nEvents  = (TH1I *) fListHist->FindObject("NEvents");\r
+\r
+  TH1F *trdTrack = (TH1F *) fListHist->FindObject("TRDTrack");\r
+  TH1F *trdTrackOffline = (TH1F *) fListHist->FindObject("TRDTrackOffline");\r
+  TH1F *trdTrackStandalone = (TH1F *) fListHist->FindObject("TRDTrackStandalone");\r
+\r
+  TH2F *tpctrdTrack = (TH2F *) fListHist->FindObject("NbTPCTRDtrack");\r
+\r
+  TH1F *nbTimeBin = (TH1F *) fListHist->FindObject("NbTimeBin");\r
+  TH1F *nbTimeBinOffline = (TH1F *) fListHist->FindObject("NbTimeBinOffline");\r
+  TH1F *nbTimeBinStandalone = (TH1F *) fListHist->FindObject("NbTimeBinStandalone");\r
+\r
+  TH1F *nbClusters = (TH1F *) fListHist->FindObject("NbClusters");\r
+  TH1F *nbClustersOffline = (TH1F *) fListHist->FindObject("NbClustersOffline");\r
+  TH1F *nbClustersStandalone = (TH1F *) fListHist->FindObject("NbClustersStandalone");\r
+\r
+  TH1F *nbTracklets = (TH1F *) fListHist->FindObject("NbTracklets");\r
+  TH1F *nbTrackletsOffline = (TH1F *) fListHist->FindObject("NbTrackletsOffline");\r
+  TH1F *nbTrackletsStandalone = (TH1F *) fListHist->FindObject("NbTrackletsStandalone");\r
+  \r
+  /////////////////////////////////////\r
+  // Take the calibration objects\r
+  /////////////////////////////////////\r
+\r
+  TH2I *ch2d = (TH2I *) fListHist->FindObject("CH2d");\r
+  TProfile2D *ph2d = (TProfile2D *) fListHist->FindObject("PH2d");\r
+\r
+  TH2I *ch2dSum = (TH2I *) fListHist->FindObject("CH2dSum");\r
+  TProfile2D *ph2dSum = (TProfile2D *) fListHist->FindObject("PH2dSum");\r
+\r
+  TH2I *ch2dSM = (TH2I *) fListHist->FindObject("CH2dSM");\r
+  TProfile2D *ph2dSM = (TProfile2D *) fListHist->FindObject("PH2dSM");\r
+  \r
+  AliTRDCalibraVdriftLinearFit *linearfit = (AliTRDCalibraVdriftLinearFit *) fListHist->FindObject("AliTRDCalibraVdriftLinearFit");\r
+  \r
+  ////////////////////////////////////////////////\r
+  // Add the AliTRDCalibraVdriftLinearFit\r
+  ///////////////////////////////////////////////\r
+  \r
+  Int_t first = 0;\r
+  TH2S *histolinearfitsum = 0x0;\r
+  \r
+  if(linearfit) {\r
+    for(Int_t det = 0; det < 540; det++) {\r
+      if(linearfit->GetLinearFitterHisto(det)){\r
+       if(TMath::Abs(first)<0.0001){\r
+         histolinearfitsum = linearfit->GetLinearFitterHisto(det);\r
+         first += 1;\r
+       }\r
+       else {\r
+         histolinearfitsum ->Add(linearfit->GetLinearFitterHisto(det));\r
+       }\r
+      }\r
+    }\r
+  }\r
+\r
+  ///////////////////////////\r
+  // Style\r
+  //////////////////////////\r
+\r
+  gStyle->SetPalette(1);\r
+  gStyle->SetOptStat(1111);\r
+  gStyle->SetOptFit(1111);\r
+  gStyle->SetPadBorderMode(0);\r
+  gStyle->SetCanvasColor(10);\r
+  gStyle->SetPadLeftMargin(0.13);\r
+  gStyle->SetPadRightMargin(0.13);\r
+\r
+  /////////////////////////\r
+  // Plot\r
+  ////////////////////////\r
+\r
+ if(nEvents) {\r
+   \r
+    TCanvas *debugEvents = new TCanvas("cNEvents","cNEvents",10,10,510,510);\r
+    debugEvents->cd(1);\r
+    if(nEvents) nEvents->Draw();\r
+      \r
+  }\r
+\r
+  if(trdTrack || tpctrdTrack) {\r
+    \r
+    TCanvas *debugtrdtpcTrack = new TCanvas("TRDtracktpctrdtrack","TRDtracktpctrdtrack",10,10,510,510);\r
+    debugtrdtpcTrack->Divide(2,1);\r
+    debugtrdtpcTrack->cd(1);\r
+    if(trdTrack) trdTrack->Draw();\r
+    if(trdTrackOffline) trdTrackOffline->Draw("same");\r
+    if(trdTrackStandalone) trdTrackStandalone->Draw("same");\r
+    TLegend *leg = new TLegend(0.4,0.6,0.89,0.89);\r
+    if(trdTrack) leg->AddEntry(trdTrack,"All","p");\r
+    if(trdTrackOffline) leg->AddEntry(trdTrackOffline,"Offline","p");\r
+    if(trdTrackStandalone) leg->AddEntry(trdTrackStandalone,"Standalone","p");\r
+    leg->Draw("same");\r
+    debugtrdtpcTrack->cd(2);\r
+    if(tpctrdTrack) tpctrdTrack->Draw();\r
+    TLine *line = new TLine(0.0,0.0,100.0,100.0);\r
+    line->Draw("same");\r
+    \r
+  }\r
\r
+  if(nbTimeBin || nbTracklets || nbClusters) {\r
+    \r
+    TCanvas *debugTracklets = new TCanvas("TRDtimebintrackletcluster","TRDtimebintrackletcluster",10,10,510,510);\r
+    debugTracklets->Divide(3,1);\r
+    debugTracklets->cd(1);\r
+    if(nbTimeBin) nbTimeBin->Draw();\r
+    if(nbTimeBinOffline) nbTimeBinOffline->Draw("same");\r
+    if(nbTimeBinStandalone) nbTimeBinStandalone->Draw("same");\r
+    TLegend *lega = new TLegend(0.4,0.6,0.89,0.89);\r
+    if(nbTimeBin) lega->AddEntry(nbTimeBin,"All","p");\r
+    if(nbTimeBinOffline) lega->AddEntry(nbTimeBinOffline,"Offline","p");\r
+    if(nbTimeBinStandalone) lega->AddEntry(nbTimeBinStandalone,"Standalone","p");\r
+    lega->Draw("same");\r
+    debugTracklets->cd(2);\r
+    if(nbTracklets) nbTracklets->Draw();\r
+    if(nbTrackletsOffline) nbTrackletsOffline->Draw("same");\r
+    if(nbTrackletsStandalone) nbTrackletsStandalone->Draw("same");\r
+    TLegend *legb = new TLegend(0.4,0.6,0.89,0.89);\r
+    if(nbTracklets) legb->AddEntry(nbTracklets,"All","p");\r
+    if(nbTrackletsOffline) legb->AddEntry(nbTrackletsOffline,"Offline","p");\r
+    if(nbTrackletsStandalone) legb->AddEntry(nbTrackletsStandalone,"Standalone","p");\r
+    legb->Draw("same");\r
+    debugTracklets->cd(3);\r
+    if(nbClusters) nbClusters->Draw();\r
+    if(nbClustersOffline) nbClustersOffline->Draw("same");\r
+    if(nbClustersStandalone) nbClustersStandalone->Draw("same");\r
+    TLegend *legc = new TLegend(0.4,0.6,0.89,0.89);\r
+    if(nbClusters) legc->AddEntry(nbClusters,"All","p");\r
+    if(nbClustersOffline) legc->AddEntry(nbClustersOffline,"Offline","p");\r
+    if(nbClustersStandalone) legc->AddEntry(nbClustersStandalone,"Standalone","p");\r
+    legc->Draw("same");\r
+  \r
+  }\r
+\r
+  if(ch2dSum || ph2dSum || histolinearfitsum) {\r
+    \r
+    TCanvas *debugSum = new TCanvas("SumCalibrationObjects","SumCalibrationObjects",10,10,510,510);\r
+    debugSum->Divide(3,1);\r
+    debugSum->cd(1);\r
+    if(ch2dSum) ch2dSum->Draw("lego");\r
+    debugSum->cd(2);\r
+    if(ph2dSum) ph2dSum->Draw("lego");\r
+    debugSum->cd(3);\r
+    if(histolinearfitsum) histolinearfitsum->Draw();\r
+  \r
+  }\r
+\r
+  if(ch2dSM || ph2dSM) {\r
+    \r
+    TCanvas *debugSM = new TCanvas("SMCalibrationObjects","SMCalibrationObjects",10,10,510,510);\r
+    debugSM->Divide(2,1);\r
+    debugSM->cd(1);\r
+    if(ch2dSM) ch2dSM->Draw("lego");\r
+    debugSM->cd(2);\r
+    if(ph2dSM) ph2dSM->Draw("lego");\r
+     \r
+  }\r
+\r
+  if(ch2d || ph2d) {\r
+    \r
+    TCanvas *debug = new TCanvas("CalibrationObjects","CalibrationObjects",10,10,510,510);\r
+    debug->Divide(2,1);\r
+    debug->cd(1);\r
+    if(ch2d) ch2d->Draw("lego");\r
+    debug->cd(2);\r
+    if(ph2d) ph2d->Draw("lego");\r
+     \r
+  }\r
\r
+}\r
diff --git a/TRD/AliTRDCalibTask.h b/TRD/AliTRDCalibTask.h
new file mode 100644 (file)
index 0000000..2ad5394
--- /dev/null
@@ -0,0 +1,142 @@
+#ifndef AliTRDCalibTask_cxx\r
+#define AliTRDCalibTask_cxx\r
+\r
+// macro for extremely simple analysis\r
+\r
+class TList;\r
+class TObject;\r
+class TObjArray;\r
+class TH2F;\r
+class TH1F;\r
+class TH1I;\r
+class TProfile2D;\r
+class TH2I;\r
+class TTree;\r
+class AliESDEvent;\r
+class AliESDfriend;\r
+class AliESDtrack;\r
+class AliESDfriendTrack;\r
+class AliTRDtrackV1;\r
+class AliTRDCalibraFillHisto;\r
+class AliTRDcluster;\r
+class AliESDtrackCuts;\r
+class AliTRDCalDet;\r
+\r
+#include "TObjString.h"\r
+#include "AliAnalysisTask.h" \r
+\r
+class AliTRDCalibTask : public AliAnalysisTask {\r
+ public:\r
+  AliTRDCalibTask(const char *name = "AliTRDCalibTask");\r
+  virtual ~AliTRDCalibTask();\r
+  \r
+  virtual void   ConnectInputData(Option_t *);\r
+  virtual void   CreateOutputObjects();\r
+  virtual void   Exec(Option_t *option);\r
+  virtual void   Terminate(Option_t *);\r
+  virtual Bool_t Load(const Char_t *filename);\r
+  void           Plot();\r
+\r
+  void SetHisto2d(Bool_t histo2d)                                   {fHisto2d=histo2d;};\r
+  void SetVector2d(Bool_t vector2d)                                 {fVector2d=vector2d;};\r
+  void SetVdriftLinear(Bool_t vdriftLinear)                         {fVdriftLinear = vdriftLinear;};\r
+  void SetNbTimeBins(Int_t nbTimeBins)                              {fNbTimeBins=nbTimeBins;};  \r
+  \r
+  void SetNz(Short_t nz, Int_t i)                                      {fNz[i]=nz;};\r
+  void SetNrphi(Short_t nrphi, Int_t i)                                {fNrphi[i]=nrphi;};\r
+  \r
+  void AddSelectedTriggerClass(const char*name)                        {fSelectedTrigger->Add(new TObjString(name));};\r
+  void SetReject(Bool_t rejected)                                      {fRejected = rejected;};\r
+  \r
+  void SetESDtrackCuts(AliESDtrackCuts *esdtrackCuts)                  {fEsdTrackCuts = esdtrackCuts;};\r
+  void SetRequirePrimaryVertex(Bool_t requirePrimaryVertex)            {fRequirePrimaryVertex = requirePrimaryVertex;};\r
+  void SetMinNbOfContributors(Int_t minNbOfContributors)               {fMinNbContributors = minNbOfContributors;};  \r
+  \r
+  void SetLow(Int_t low)                                               {fLow=low;};\r
+  void SetHigh(Int_t high)                                             {fHigh=high;};\r
+  void SetFillZero(Bool_t fillZero)                                    {fFillZero =  fillZero;};\r
+  void SetNormalizeNbOfCluster(Bool_t normalizeNbOfCluster =  kTRUE)   {fNormalizeNbOfCluster = normalizeNbOfCluster;};\r
+  void SetMaxCluster(Float_t maxCluster)                               {fMaxCluster =  maxCluster; }; \r
+  void SetNbMaxCluster(Short_t nbMaxCluster)                           {fNbMaxCluster =  nbMaxCluster; }; \r
+  void SetOfflineTracks()                                              {fOfflineTracks=kTRUE; fStandaloneTracks=kFALSE; };\r
+  void SetStandaloneTracks()                                           {fStandaloneTracks=kTRUE; fOfflineTracks=kFALSE; };\r
+\r
+  void SetCalDetGain(AliTRDCalDet *calDetGain)                         {fCalDetGain = calDetGain;};  \r
+\r
+  void SetMaxEvent(Int_t nbevents)                                     { fMaxEvent = nbevents; };\r
+  void SetDebug(Int_t debug)                                           { fDebug = debug; };\r
+\r
+ private:\r
+  AliESDEvent  *fESD;                            //! ESD object\r
+  AliESDfriend *fESDfriend;                      //! ESD friend\r
+  const AliESDtrack *fEsdTrack;                  //! ESD track\r
+  AliESDfriendTrack *fFriendTrack;               //! ESD friend track\r
+  TObject *fCalibObject;                         //! calibration objects attached to the ESD friend\r
+  AliTRDtrackV1 *fTrdTrack;                      //! trdtrack\r
+  AliTRDcluster *fCl;                            //! cluster\r
+  \r
+  TList       *fListHist;                        //! list of histograms\r
+\r
+  AliTRDCalibraFillHisto *fTRDCalibraFillHisto;  //! calibration analyse object\r
+\r
+  TH1I        *fNEvents;                         //! counter  \r
+  \r
+  TH1F        *fNbTRDTrack;                      //! nb ESD tracks with TRD clusters\r
+  TH1F        *fNbTRDTrackOffline;               //! nb ESD tracks with TRD clusters\r
+  TH1F        *fNbTRDTrackStandalone;            //! nb ESD tracks with TRD clusters\r
+  TH2F        *fNbTPCTRDtrack;                   //! nb TPC and TRD tracks when problems\r
+   \r
+  TH1F        *fNbTimeBin;                       //! nb Time Bin\r
+  TH1F        *fNbTimeBinOffline;                //! nb Time Bin offline\r
+  TH1F        *fNbTimeBinStandalone;             //! nb Time Bin standalone\r
+  TH1F        *fNbClusters;                      //! nb Clusters\r
+  TH1F        *fNbClustersOffline;               //! nb Clusters offline\r
+  TH1F        *fNbClustersStandalone;            //! nb Clusters standalone\r
+  TH1F        *fNbTracklets;                     //! nb Tracklets\r
+  TH1F        *fNbTrackletsOffline;              //! nb Tracklets offline\r
+  TH1F        *fNbTrackletsStandalone;           //! nb Tracklets standalone\r
+  \r
+  TH2I        *fCH2dSum;                         //! CH2d charge all\r
+  TProfile2D  *fPH2dSum;                         //! PH2d PH all\r
+  TH2I        *fCH2dSM;                          //! CH2d per SM\r
+  TProfile2D  *fPH2dSM;                          //! PH2d per SM\r
+\r
+  Bool_t      fHisto2d;                          //! histo\r
+  Bool_t      fVector2d;                         //! vector\r
+  Bool_t      fVdriftLinear;                     //! vdrift Linear\r
+\r
+  Int_t       fNbTimeBins;                       //! number of timebins \r
+\r
+  Short_t     fNz[3];                            // Nz mode \r
+  Short_t     fNrphi[3];                         // Nrphi mode\r
+   \r
+  TObjArray   *fSelectedTrigger;                 // Trigger class names accepted/rejected\r
+  Bool_t      fRejected;                         // Reject the selected trigger class\r
+  \r
+  AliESDtrackCuts *fEsdTrackCuts;                // Quality cut on the AliESDtrack\r
+  Bool_t      fRequirePrimaryVertex;             // Primary Vertex\r
+  Int_t       fMinNbContributors;                // Min number of contributors\r
+  \r
+  Int_t       fLow;                              // lower limit of nb of TRD clusters per tracklet\r
+  Int_t       fHigh;                             // higher limit of nb of TRD clusters per tracklet\r
+  Bool_t      fFillZero;                         // fill zero\r
+  Bool_t      fNormalizeNbOfCluster;             // normalize with number of clusters (per default not) \r
+  Float_t     fRelativeScale;                    // relative scale for gas gain\r
+  Float_t     fMaxCluster;                       // Maxcluster \r
+  Short_t     fNbMaxCluster;                     // Number of tb at the end\r
+  Bool_t      fOfflineTracks;                    // Only Offline refitted tracks\r
+  Bool_t      fStandaloneTracks;                 // Take only standalone tracks\r
+\r
+  AliTRDCalDet *fCalDetGain;                     // Calib object gain\r
+\r
+  Int_t       fMaxEvent;                         // max events\r
+  Int_t       fCounter;                          // max events\r
+  Int_t       fDebug;                            //! fDebug\r
+\r
+  AliTRDCalibTask(const AliTRDCalibTask&); \r
+  AliTRDCalibTask& operator=(const AliTRDCalibTask&); \r
+\r
+  ClassDef(AliTRDCalibTask, 1); \r
+};\r
+\r
+#endif\r
diff --git a/TRD/Macros/AliTRDrunCalib.C b/TRD/Macros/AliTRDrunCalib.C
new file mode 100644 (file)
index 0000000..70a3a11
--- /dev/null
@@ -0,0 +1,110 @@
+void Plot(Int_t run);
+void AliTRDrunCalib(const char*filename,Int_t runnr)
+{
+  gSystem->Load("libANALYSIS");
+  gSystem->Load("libANALYSISalice");
+  gSystem->Load("libTRDcalib");
+  
+  AliLog::SetGlobalLogLevel(AliLog::kError);
+  gROOT->LoadMacro(Form("%s/PWG0/CreateESDChain.C", gSystem->ExpandPathName("$ALICE_ROOT")));
+  TChain *chain = CreateESDChain((const char*)filename, -1);
+  chain->SetBranchStatus("*FMD*",0);
+  chain->SetBranchStatus("*Calo*",0);
+  chain->SetBranchStatus("Tracks", 1);
+  chain->SetBranchStatus("ESDfriend*",1);
+  chain->Lookup();
+  chain->GetListOfFiles()->Print();
+  printf("\n ----> CHAIN HAS %d ENTRIES <----\n\n", (Int_t)chain->GetEntries());
+    
+
+  TGrid::Connect("alien://");
+  AliCDBManager * man = AliCDBManager::Instance();
+  man->SetDefaultStorage("alien://folder=/alice/data/2009/OCDB?cacheFold=/lustre/alice/local/alice/data/2009/OCDB");
+  man->SetCacheFlag(kTRUE);
+  man->SetRun(runnr);
+
+  AliTRDcalibDB *calib = AliTRDcalibDB::Instance();
+  const AliTRDCalDet* caldet = calib->GetGainFactorDet();
+
+  AliAnalysisManager *TRDqa = new AliAnalysisManager("TRD QA/Calibration");
+  TRDqa->SetInputEventHandler(new AliESDInputHandler);
+  
+  AliTRDCalibTask *calibTask = new AliTRDCalibTask();
+  calibTask->SetHisto2d(kTRUE);
+  calibTask->SetVector2d(kTRUE);
+  calibTask->SetVdriftLinear(kTRUE);
+  calibTask->SetNz(0,0);
+  calibTask->SetNrphi(0,0);
+  calibTask->SetNz(0,1);
+  calibTask->SetNrphi(0,1);
+  calibTask->SetNz(0,2);
+  calibTask->SetNrphi(0,2);
+  calibTask->SetLow(0);
+  calibTask->SetHigh(30);
+  calibTask->SetFillZero(kFALSE);
+  calibTask->SetDebug(3);
+  calibTask->SetNbTimeBins(30);
+  //calibTask->SetMaxEvent(20);
+  calibTask->SetRequirePrimaryVertex(kTRUE);
+  calibTask->SetMinNbOfContributors(1);
+  calibTask->SetMaxCluster(100.0);
+  calibTask->SetNbMaxCluster(2);
+  calibTask->SetCalDetGain(caldet);
+
+  /////////////////////////////
+  // Track cuts
+  /////////////////////////////
+  AliESDtrackCuts *trackCuts = new AliESDtrackCuts("trackcuts","trackcuts");
+  trackCuts->SetMinNClustersTPC(70);
+  trackCuts->SetMaxChi2PerClusterTPC(3.5);
+  //trackCuts->SetMaxCovDiagonalElements(2,2,0.5,0.5,2);
+  trackCuts->SetRequireTPCRefit(kTRUE);
+  //trackCuts->SetRequireITSRefit(kTRUE);
+  //trackCuts->SetMinNsigmaToVertex(10);
+  //trackCuts->SetRequireSigmaToVertex(kFALSE);
+  trackCuts->SetAcceptKinkDaughters(kFALSE);
+  trackCuts->SetMaxDCAToVertexZ(10.0);
+  //trackCuts->SetMaxDCAToVertexXY(4.0);
+
+
+  calibTask->SetESDtrackCuts(trackCuts);
+
+  TRDqa->AddTask(calibTask);
+  
+  TRDqa->ConnectInput( calibTask, 0, TRDqa->GetCommonInputContainer());
+  TRDqa->ConnectOutput(calibTask, 0, TRDqa->CreateContainer(calibTask->GetName(), TList::Class(), AliAnalysisManager::kOutputContainer, Form("TRDcalibration%d.root", runnr)));
+
+  if(TRDqa->InitAnalysis()){
+    TRDqa->Print();
+    TRDqa->StartAnalysis("local", chain);
+  }
+  
+  delete calibTask;
+
+  Plot(runnr);
+}
+
+void Plot(Int_t run){
+  TFile *calibration=new TFile(Form("TRDcalibration%d.root",run));
+  TList *lister = (TList *) calibration->Get("AliTRDCalibTask");
+  TH2I *hCH2d = (TH2I*)lister->FindObject("CH2d");
+  TProfile2D *hPH2d = (TProfile2D*)lister->FindObject("PH2d"); // tracks/event
+  TProfile2D *hPRF2d = (TProfile2D*)lister->FindObject("PRF2d");
+  
+  calibration->Close();
+
+  TCanvas *tcalib = new TCanvas ("CalibrationMonitor", "CalibrationMonitor",50,50,600,900);
+  tcalib->Divide(3,1);
+  tcalib->cd(1);
+  if(hCH2d) hCH2d->Draw("lego2"); 
+  tcalib->cd(2);
+  if(hPH2d) hPH2d->Draw("lego2"); 
+  tcalib->cd(3);
+  if(hPRF2d) hPRF2d->Draw("lego2"); 
+
+  tcalib->SaveAs(Form("CalibrationMon_run%d.gif",run));
+
+}
diff --git a/TRD/TRDcalibLinkDef.h b/TRD/TRDcalibLinkDef.h
new file mode 100644 (file)
index 0000000..6d32464
--- /dev/null
@@ -0,0 +1,20 @@
+#ifdef __CINT__
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id: TPCcalibLinkDef.h 34646 2009-09-05 13:12:53Z marian $ */
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class  AliTRDCalibTask+;
+
+
+#endif
+
+
+
+
+
diff --git a/TRD/libTRDcalib.pkg b/TRD/libTRDcalib.pkg
new file mode 100644 (file)
index 0000000..c0e7d22
--- /dev/null
@@ -0,0 +1,20 @@
+#-*- Mode: Makefile -*-
+
+SRCS = AliTRDCalibTask.cxx 
+
+HDRS:= $(SRCS:.cxx=.h) 
+
+EINCLUDE:=STEER ANALYSIS TRD TRD/Cal 
+
+DHDR= TRDcalibLinkDef.h
+
+#EXPORT:=$(SRCS:.cxx=.h)
+
+ifeq (win32gcc,$(ALICE_TARGET))
+PACKSOFLAGS:= $(SOFLAGS) -L$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET) -lSTEERBase \
+                         -lCDB -lESD -lTRDbase -lTRDrec -lSTEER -lANALYSIS  \
+                         -lSTAT \
+                         -L$(ROOTLIBDIR) -lMinuit -lProof -lEG
+endif
+
+