Improved algorithm for the extrapolation of the tracks in AliCheckMuonDetEltResponse...
authormartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 5 Nov 2009 14:28:00 +0000 (14:28 +0000)
committermartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 5 Nov 2009 14:28:00 +0000 (14:28 +0000)
PWG3/muondep/AliAnalysisTaskMuonTrackingEff.cxx
PWG3/muondep/AliAnalysisTaskMuonTrackingEff.h
PWG3/muondep/AliCheckMuonDetEltResponse.cxx
PWG3/muondep/AliCheckMuonDetEltResponse.h
PWG3/muondep/MuonTrackingEffAnalysis.C

index 7e810be..5319bac 100644 (file)
@@ -26,6 +26,8 @@
 #include <TList.h>
 #include <TClonesArray.h>
 #include <TH2F.h>
+#include <TH1F.h>
+#include <TMath.h>
 
 //ANALYSIS includes
 #include "AliAnalysisManager.h"
 ClassImp(AliAnalysisTaskMuonTrackingEff)
 
 const Int_t AliAnalysisTaskMuonTrackingEff::fTotNbrOfDetectionElt  = 156;
+const Int_t AliAnalysisTaskMuonTrackingEff::fTotNbrOfChamber  = 10;
 
 //________________________________________________________________________
 AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff()
-    :
-    AliAnalysisTask(),
-    fTransformer(0x0),
-    fESD(0x0),
-    fDetEltEffHistList(0x0),
-    fDetEltTDHistList(0x0),
-    fDetEltTTHistList(0x0)
+  :
+  fIsCosmicData(kFALSE),
+  AliAnalysisTask(),
+  fTransformer(0x0),
+  fESD(0x0),
+  fDetEltEffHistList(0x0),
+  fDetEltTDHistList(0x0),
+  fDetEltTTHistList(0x0),
+  fChamberEffHistList(0x0),
+  fChamberTDHistList(0x0),
+  fChamberTTHistList(0x0)
 {
 /// Default constructor
 }
 //________________________________________________________________________
 AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff(const AliAnalysisTaskMuonTrackingEff& src)
-    :
-    AliAnalysisTask(src),
-    fTransformer(0x0),
-    fESD(0x0),
-    fDetEltEffHistList(0x0),
-    fDetEltTDHistList(0x0),
-    fDetEltTTHistList(0x0)
+  :
+  fIsCosmicData(kFALSE),
+  AliAnalysisTask(src),
+  fTransformer(0x0),
+  fESD(0x0),
+  fDetEltEffHistList(0x0),
+  fDetEltTDHistList(0x0),
+  fDetEltTTHistList(0x0),
+  fChamberEffHistList(0x0),
+  fChamberTDHistList(0x0),
+  fChamberTTHistList(0x0)
 {
   /// copy ctor
   src.Copy(*this);
@@ -89,18 +100,25 @@ AliAnalysisTaskMuonTrackingEff& AliAnalysisTaskMuonTrackingEff::operator=(const
 
 //________________________________________________________________________
 AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff(const char* name,
-                                      const AliMUONGeometryTransformer* transformer)
-    :
-    AliAnalysisTask(name, "AnalysisTaskESD"),
-    fTransformer(transformer),
-    fESD(0x0),
-    fDetEltEffHistList(0x0),
-    fDetEltTDHistList(0x0),
-    fDetEltTTHistList(0x0)
+                                                              const AliMUONGeometryTransformer* transformer,
+                                                              Bool_t isCosmic)
+  :
+  fIsCosmicData(kFALSE),
+  AliAnalysisTask(name, "AnalysisTaskESD"),
+  fTransformer(transformer),
+  fESD(0x0),
+  fDetEltEffHistList(0x0),
+  fDetEltTDHistList(0x0),
+  fDetEltTTHistList(0x0),
+  fChamberEffHistList(0x0),
+  fChamberTDHistList(0x0),
+  fChamberTTHistList(0x0)
 {
 //Constructor
 //-----------
     
+  fIsCosmicData = isCosmic;
+
 //Define detection element efficiency histograms
 //----------------------------------------------
 
@@ -110,6 +128,13 @@ AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff(const char* name,
     fDetEltTDHistList  = new TClonesArray("TH2F",fTotNbrOfDetectionElt + 1);
     fDetEltTTHistList  = new TClonesArray("TH2F",fTotNbrOfDetectionElt + 1);
 
+
+    fChamberEffHistList = new TClonesArray("TH1F", fTotNbrOfChamber + 3);
+    fChamberTDHistList = new TClonesArray("TH1F", fTotNbrOfChamber + 1);
+    fChamberTTHistList = new TClonesArray("TH1F", fTotNbrOfChamber + 1);
+
+
+
     for (Int_t i = 0; i<fTotNbrOfDetectionElt; ++i)
     {
       Int_t iDetElt = 0;
@@ -142,6 +167,36 @@ AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff(const char* name,
       ((TH2F*) fDetEltEffHistList->UncheckedAt(i)) -> SetOption("LEGO");
     }
 
+    for (Int_t j = 0; j < fTotNbrOfChamber; j++)
+      {
+       Char_t histName[255]; 
+       Char_t histTitle[255];
+
+
+       sprintf(histName,"Eff_ChamberNbr%d",j+1);
+       sprintf(histTitle,"ChamberNbr %d",j+1);
+       if (j<4) new ((*fChamberEffHistList)[j]) TH1F(histName, histTitle, 4, 0.0, 4.0);
+       else if (j<6) new ((*fChamberEffHistList)[j]) TH1F(histName, histTitle, 18, 0.0, 18.0);
+       if (j>=6) new ((*fChamberEffHistList)[j]) TH1F(histName, histTitle, 26, 0.0, 26.0);
+
+       sprintf(histName,"TD_ChamberNbr%d",j+1);
+       if (j<4) new ((*fChamberTDHistList)[j]) TH1F(histName, histTitle, 4, 0.0, 4.0);
+       else if (j<6) new ((*fChamberTDHistList)[j]) TH1F(histName, histTitle, 18, 0.0, 18.0);
+       if (j>=6) new ((*fChamberTDHistList)[j]) TH1F(histName, histTitle, 26, 0.0, 26.0);
+
+       sprintf(histName,"TT_ChamberNbr%d",j+1);
+       if (j<4) new ((*fChamberTTHistList)[j]) TH1F(histName, histTitle, 4, 0.0, 4.0);
+       else if (j<6) new ((*fChamberTTHistList)[j]) TH1F(histName, histTitle, 18, 0.0, 18.0);
+       if (j>=6) new ((*fChamberTTHistList)[j]) TH1F(histName, histTitle, 26, 0.0, 26.0);
+
+       ((TH1F*) fChamberEffHistList->UncheckedAt(j)) -> GetXaxis() -> SetTitle("DetElement");
+       ((TH1F*) fChamberEffHistList->UncheckedAt(j)) -> GetYaxis() -> SetTitle("Efficiency (%)");
+       ((TH1F*) fChamberEffHistList->UncheckedAt(j)) -> GetXaxis() -> SetTitleOffset(1.8);
+       ((TH1F*) fChamberEffHistList->UncheckedAt(j)) -> GetYaxis() -> SetTitleOffset(1.8); 
+       ((TH1F*) fChamberEffHistList->UncheckedAt(j)) -> Sumw2();       
+      }
+
+
     new((*fDetEltTDHistList )[fTotNbrOfDetectionElt]) TH2F("TD_Chamber" ,"TD_Chamber" ,10,0,10,1,0,1); //!<Detected tracks.
     new((*fDetEltTTHistList )[fTotNbrOfDetectionElt]) TH2F("TT_Chamber" ,"TT_Chamber" ,10,0,10,1,0,1); //!<Tracks total number.
     new((*fDetEltEffHistList)[fTotNbrOfDetectionElt]) TH2F("fChamberEff","fChamberEff",10,0,10,1,0,1); //!<Chamber efficiency.
@@ -174,6 +229,39 @@ AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff(const char* name,
     ((TH2F*) fDetEltEffHistList->UncheckedAt(fTotNbrOfDetectionElt + 2)) -> GetZaxis() -> SetTitleOffset(1.2); 
     ((TH2F*) fDetEltEffHistList->UncheckedAt(fTotNbrOfDetectionElt + 2)) -> SetOption("LEGO");    
 
+
+    new((*fChamberTDHistList )[fTotNbrOfChamber]) TH1F("TD_Chamber_2" ,"TD_Chamber_2" ,10,0,10); //!<Detected tracks.
+    new((*fChamberTTHistList )[fTotNbrOfChamber]) TH1F("TT_Chamber_2" ,"TT_Chamber_2" ,10,0,10); //!<Tracks total number.
+    new((*fChamberEffHistList)[fTotNbrOfChamber]) TH1F("fChamberEff_2","fChamberEff_2",10,0,10); //!<Chamber efficiency.
+
+    ((TH1F*) fChamberTDHistList->UncheckedAt(fTotNbrOfChamber)) -> Sumw2();
+    ((TH1F*) fChamberTTHistList->UncheckedAt(fTotNbrOfChamber)) -> Sumw2();
+
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber)) -> GetXaxis() -> SetTitle("Chamber number");
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber)) -> GetYaxis() -> SetTitle("");
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber)) -> GetXaxis() -> SetTitleOffset(1.8);
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber)) -> GetYaxis() -> SetTitleOffset(1.8); 
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber)) -> Sumw2();
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber)) -> SetOption("");
+  
+    new((*fChamberEffHistList)[11]) TH1F("TT_Chamber_2" ,"TT_Chamber_2" ,10,0,10); //!<Tracks total number by chamber.
+
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 1)) -> GetXaxis() -> SetTitle("Chamber number");
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 1)) -> GetYaxis() -> SetTitle("");
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 1)) -> GetXaxis() -> SetTitleOffset(1.8);
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 1)) -> GetYaxis() -> SetTitleOffset(1.8); 
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 1)) -> Sumw2();
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 1)) -> SetOption("");
+
+    new((*fChamberEffHistList)[12]) TH1F("Total_Number_of_Tracks_2" ,"Total_Number_of_Tracks_2" ,1,0,1); //!<Tracks total number.
+
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 2)) -> GetXaxis() -> SetTitle("");
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 2)) -> GetYaxis() -> SetTitle("");
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 2)) -> GetXaxis() -> SetTitleOffset(1.8);
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 2)) -> GetYaxis() -> SetTitleOffset(1.8); 
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 2)) -> Sumw2();    
+    ((TH1F*) fChamberEffHistList->UncheckedAt(fTotNbrOfChamber + 2)) -> SetOption("");    
+
 //Define input & output
 //---------------------
 
@@ -182,6 +270,9 @@ AliAnalysisTaskMuonTrackingEff::AliAnalysisTaskMuonTrackingEff(const char* name,
 
 // -Output slot 0 writes into a TClonesArray:
     DefineOutput(0, TClonesArray::Class());
+    DefineOutput(1, TClonesArray::Class());
+    DefineOutput(2, TClonesArray::Class());
+    DefineOutput(3, TClonesArray::Class());
 }
 
 
@@ -193,6 +284,9 @@ AliAnalysisTaskMuonTrackingEff::~AliAnalysisTaskMuonTrackingEff()
     delete fDetEltEffHistList;
     delete fDetEltTDHistList;
     delete fDetEltTTHistList;
+    delete fChamberEffHistList;
+    delete fChamberTDHistList;
+    delete fChamberTTHistList;
 }
 
 
@@ -229,7 +323,7 @@ void AliAnalysisTaskMuonTrackingEff::Exec(Option_t */*option*/)
     
    
     AliCheckMuonDetEltResponse* chamberEff;
-    chamberEff = new AliCheckMuonDetEltResponse(fTransformer, fESD, fDetEltTDHistList, fDetEltTTHistList);
+    chamberEff = new AliCheckMuonDetEltResponse(fTransformer, fESD, fDetEltTDHistList, fDetEltTTHistList, fChamberTDHistList, fChamberTTHistList);
     chamberEff->CheckDetEltResponse();
 
 
@@ -239,6 +333,13 @@ void AliAnalysisTaskMuonTrackingEff::Exec(Option_t */*option*/)
                                                             (TH2F*) fDetEltTTHistList->UncheckedAt(i), 100., 1.); 
     }
 
+    for (Int_t j = 0; j < 10; j++)
+      {
+       ((TH1F*) fChamberEffHistList->UncheckedAt(j))-> Divide( (TH1F*) fChamberTDHistList->UncheckedAt(j),
+                                                               (TH1F*) fChamberTTHistList->UncheckedAt(j), 100., 1.);  
+      }
+
+
     ((TH2F*) fDetEltEffHistList->UncheckedAt(156))-> Divide( (TH2F*) fDetEltTDHistList->UncheckedAt(156),
                                                             (TH2F*) fDetEltTTHistList->UncheckedAt(156), 100., 1.); 
 
@@ -250,8 +351,26 @@ void AliAnalysisTaskMuonTrackingEff::Exec(Option_t */*option*/)
     ((TH2F*) fDetEltEffHistList->UncheckedAt(158))-> Fill(0., 0., ((Double_t)fESD -> GetNumberOfMuonTracks()));
 
 
+    ((TH1F*) fChamberEffHistList->UncheckedAt(10))-> Divide( (TH1F*) fChamberTDHistList->UncheckedAt(10),
+                                                            (TH1F*) fChamberTTHistList->UncheckedAt(10), 100., 1.); 
+
+
+    ((TH1F*) fChamberEffHistList->UncheckedAt(11))-> Add   ( (TH1F*) fChamberTTHistList ->UncheckedAt(10),
+                                                            (TH1F*) fChamberEffHistList->UncheckedAt(11), 1., 0.); 
+
+
+    ((TH1F*) fChamberEffHistList->UncheckedAt(12))-> Fill(0., ((Double_t)fESD -> GetNumberOfMuonTracks()));
+
+    ComputeErrors();
+
+
 //Post the output data:
-    PostData(0, fDetEltEffHistList);  
+    PostData(0, fDetEltTDHistList);  
+    PostData(1, fDetEltTTHistList);  
+    PostData(2, fDetEltEffHistList);  
+    PostData(3, fChamberTDHistList);
+    PostData(4, fChamberTTHistList);
+    PostData(5, fChamberEffHistList);
 }
 
 
@@ -262,3 +381,32 @@ void AliAnalysisTaskMuonTrackingEff::Terminate(Option_t */*option*/)
 //Terminate analysis
 
 }
+
+
+//________________________________________________________________________
+void AliAnalysisTaskMuonTrackingEff::ComputeErrors()
+{
+  // Compute error on the efficiency
+  // eff = Ntd/Ntt
+  // error = max {1/Ntt, sqrt(eff*(1-eff)/Ntt)}
+
+  for (Int_t ii = 0; ii < 10; ii++)
+    {
+      Int_t NumberOfBins = ((TH1F*) fChamberEffHistList->UncheckedAt(ii))->GetNbinsX();
+      for (Int_t jj = 0; jj < NumberOfBins; jj++)
+       {
+         Double_t Ntd = ((TH1F*) fChamberTDHistList->UncheckedAt(ii))->GetBinContent(jj);
+         Double_t Ntt = ((TH1F*) fChamberTTHistList->UncheckedAt(ii))->GetBinContent(jj);
+
+         if (Ntt > 0.0 && Ntd > 0.0)
+           {
+             Double_t eff = ((TH1F*) fChamberEffHistList->UncheckedAt(ii))->GetBinContent(jj)/100.0;
+             Double_t err1 = 1.0/Ntt;
+             Double_t err2 = TMath::Sqrt(eff*(1.0 - eff)/Ntt);
+             Double_t error = TMath::Max(err1, err2);
+
+             ((TH1F*) fChamberEffHistList->UncheckedAt(ii))->SetBinError(jj, error*100.0);
+           }
+       }
+    }
+}
index 4616f42..e83d536 100644 (file)
@@ -23,7 +23,8 @@ class AliAnalysisTaskMuonTrackingEff : public AliAnalysisTask
   AliAnalysisTaskMuonTrackingEff(const AliAnalysisTaskMuonTrackingEff& rhs);
   AliAnalysisTaskMuonTrackingEff& operator=(const AliAnalysisTaskMuonTrackingEff&);
   AliAnalysisTaskMuonTrackingEff(const char* name,
-                    const AliMUONGeometryTransformer* transformer);
+                                const AliMUONGeometryTransformer* transformer,
+                                Bool_t isCosmic = kFALSE);
   virtual ~AliAnalysisTaskMuonTrackingEff();
 
   // Implementation of interface methods
@@ -33,6 +34,12 @@ class AliAnalysisTaskMuonTrackingEff : public AliAnalysisTask
   virtual void Terminate(Option_t *option);
 
   static const Int_t fTotNbrOfDetectionElt;    ///< The total number of detection element in the tracking system.
+  static const Int_t fTotNbrOfChamber;
+
+  void ComputeErrors();                        ///< Compute the error on the efficiency (see .ccx for the formula)
+  
+  void SetCosmic(Bool_t isCosmic) {fIsCosmicData = isCosmic;};
+  Bool_t IsCosmic() {return fIsCosmicData;};
 
  private:
   const AliMUONGeometryTransformer* fTransformer;
@@ -41,6 +48,11 @@ class AliAnalysisTaskMuonTrackingEff : public AliAnalysisTask
   TClonesArray* fDetEltEffHistList; //!<Detetcion efficiencies histograms list. 
   TClonesArray* fDetEltTDHistList;  //!<List of histograms of the tracks detected in the detection elements. 
   TClonesArray* fDetEltTTHistList;  //!<List of histograms of the tracks which have passed through the detection elements. 
+  TClonesArray* fChamberEffHistList;
+  TClonesArray* fChamberTDHistList;
+  TClonesArray* fChamberTTHistList;
+
+  Bool_t fIsCosmicData;
 
   ClassDef(AliAnalysisTaskMuonTrackingEff, 1)
 };
index a9c8de4..d78f992 100644 (file)
 
 //include MUON/mapping:
 #include "mapping/AliMpDEManager.h"
+#include "mapping/AliMpSegmentation.h"
+#include "mapping/AliMpSlat.h"
+#include "mapping/AliMpSlatSegmentation.h"
+#include "mapping/AliMpSector.h"
+#include "mapping/AliMpSectorSegmentation.h"
+#include "mapping/AliMpPad.h"
 
 //include ROOT:
 #include <Riostream.h>
@@ -45,6 +51,7 @@
 #include <TROOT.h>
 #include <TSystem.h>
 #include <TH2F.h>
+#include <TH1F.h>
 #include <TClonesArray.h>
 #include <TPaveLabel.h>
 #include <TList.h>
@@ -59,7 +66,7 @@ const Int_t AliCheckMuonDetEltResponse::fNbrOfDetectionElt[10] = {4, 4, 4, 4, 18
 const Int_t AliCheckMuonDetEltResponse::fFirstDetectionElt[10] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
 const Int_t AliCheckMuonDetEltResponse::fOffset                = 100;
 const Int_t AliCheckMuonDetEltResponse::fOverlapSize           = 15;
-const Int_t AliCheckMuonDetEltResponse::fYSlatSize             = 40;
+const Int_t AliCheckMuonDetEltResponse::fYSlatSize             = 20;
 
 //_____________________________________________________________________________
 AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse() 
@@ -67,6 +74,7 @@ AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse()
   fNCh(0),
   fNSt(0),
   fNDE(0),
+  fIsCosmicData(kFALSE),
   fTransformer(0x0),
   fESD(0x0),
   fTracksTotalNbr(0x0),
@@ -74,7 +82,9 @@ AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse()
   fTrackParam(0x0),
   fCluster(0x0),
   fDetEltTDHistList(0x0),
-  fDetEltTTHistList(0x0)
+  fDetEltTTHistList(0x0),
+  fChamberTDHistList(0x0),
+  fChamberTTHistList(0x0)
 {
 /// Default constructor
 
@@ -83,18 +93,10 @@ AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse()
     fNDE = AliAnalysisTaskMuonTrackingEff::fTotNbrOfDetectionElt;
 
     for (Int_t iCluster = 0; iCluster<fNCh; ++iCluster)
-    {
       fNbrClustersCh[iCluster] = 0;
-    }  
 
-    for (Int_t i=0; i<2; ++i)
-    {
-      fGetDetElt[i] = 0;
-    }
     for (Int_t i=0; i<fNCh; ++i)
-    {
       fTrackFilter[i] = 0;
-    } 
 }
 
 //_____________________________________________________________________________
@@ -103,6 +105,7 @@ AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse(const AliCheckMuonDetEltR
   fNCh(0),
   fNSt(0),
   fNDE(0),
+  fIsCosmicData(kFALSE),
   fTransformer(0x0),
   fESD(0x0),
   fTracksTotalNbr(0x0),
@@ -110,7 +113,9 @@ AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse(const AliCheckMuonDetEltR
   fTrackParam(0x0),
   fCluster(0x0),
   fDetEltTDHistList(0x0),
-  fDetEltTTHistList(0x0)
+  fDetEltTTHistList(0x0),
+  fChamberTDHistList(0x0),
+  fChamberTTHistList(0x0)
 {
  src.Copy(*this);
 }
@@ -129,39 +134,39 @@ AliCheckMuonDetEltResponse& AliCheckMuonDetEltResponse::operator=(const AliCheck
 AliCheckMuonDetEltResponse::AliCheckMuonDetEltResponse(const AliMUONGeometryTransformer* transformer,
                                                       AliESDEvent* esd,
                                                       TClonesArray* detEltTDHistList,
-                                                      TClonesArray* detEltTTHistList) 
+                                                      TClonesArray* detEltTTHistList,
+                                                      TClonesArray* chamberTDHistList,
+                                                      TClonesArray* chamberTTHistList,
+                                                      Bool_t isCosmic) 
 : TObject(),
   fNCh(0),
   fNSt(0),
   fNDE(0),
+  fIsCosmicData(kFALSE),
   fTransformer(transformer),
   fESD(esd),
   fTracksTotalNbr(0),
   fTrackParams(0x0),
   fTrackParam(0),
-  fCluster(0), 
+  fCluster(0),
   fDetEltTDHistList(detEltTDHistList),
-  fDetEltTTHistList(detEltTTHistList)
+  fDetEltTTHistList(detEltTTHistList),
+  fChamberTDHistList(chamberTDHistList),
+  fChamberTTHistList(chamberTTHistList)
 {
 /// Constructor
 
     fNCh = AliCheckMuonDetEltResponse::fNbrOfChamber;
     fNSt = AliCheckMuonDetEltResponse::fNbrOfStation;
     fNDE = AliAnalysisTaskMuonTrackingEff::fTotNbrOfDetectionElt;
+    fIsCosmicData = isCosmic;
 
     for (Int_t iCluster = 0; iCluster<fNCh; ++iCluster)
-    {
       fNbrClustersCh[iCluster] = 0;
-    }
-
-    for (Int_t i = 0; i <2 ; ++i)
-    {
-      fGetDetElt[i] = 0;
-    }
+    
     for (Int_t i=0; i<fNCh; ++i)
-    {
       fTrackFilter[i] = 0;
-    } 
+    
 }
 
 
@@ -205,12 +210,61 @@ void AliCheckMuonDetEltResponse::TrackLoop()
     {
       esdTrack   = fESD -> GetMuonTrack(iTrack);
   
-      if( esdTrack->ContainTrackerData() )
-      {
-       AliMUONESDInterface::ESDToMUON(*esdTrack, track);
-        fTrackParams = track.GetTrackParamAtCluster();
-       TrackParamLoop(); //!<Loop on trackParam.
-      }
+      if( esdTrack->ContainTrackerData() && esdTrack->GetMatchTrigger() > 0)
+       {
+         if (fIsCosmicData)
+           {
+             // Beginnig of long stuff to check the number of trigger hit (to only keep muon trigger and cut cosmic showers)
+             Int_t nTriggerHit = 0;
+             Int_t nTriggerHitStrip[8] = {0, 0, 0, 0, 
+                                          0, 0, 0, 0};
+             UShort_t triggerPattern[8] = {esdTrack->GetTriggerX1Pattern(), esdTrack->GetTriggerX2Pattern(), esdTrack->GetTriggerX3Pattern(), esdTrack->GetTriggerX4Pattern(), 
+                                           esdTrack->GetTriggerY1Pattern(), esdTrack->GetTriggerY2Pattern(), esdTrack->GetTriggerY3Pattern(), esdTrack->GetTriggerY4Pattern()};
+             
+             for (Int_t ii = 0; ii < 8; ii++)
+               {
+                 UShort_t pattern = triggerPattern[ii];
+                 Int_t binaryValue[16] = {0, 0, 0, 0,
+                                          0, 0, 0, 0,
+                                          0, 0, 0, 0,
+                                          0, 0, 0, 0};
+                 
+                 for (Int_t jj = 15; jj >= 0; jj--)
+                   {
+                     Int_t base = 1;
+                     for (Int_t bb = 0; bb < jj; bb++)
+                       base *= 2;
+                     
+                     if (pattern/base == 1)
+                       {
+                         binaryValue[jj] = 1;
+                         pattern = pattern - base;
+                       }
+                   }
+               }
+             
+             for (Int_t ii = 0; ii < 8; ii++)
+               nTriggerHit += nTriggerHitStrip[ii];
+             // End of long stuff
+             
+             
+             // Important part   
+             if (nTriggerHit < 10)
+               {
+                 AliMUONESDInterface::ESDToMUON(*esdTrack, track);
+                 fTrackParams = track.GetTrackParamAtCluster();
+                 TrackParamLoop(); //!<Loop on trackParam.
+               }
+           }
+
+         // No trigger cut is required for non-cosmic data
+         else
+           {
+             AliMUONESDInterface::ESDToMUON(*esdTrack, track);
+             fTrackParams = track.GetTrackParamAtCluster();
+             TrackParamLoop(); //!<Loop on trackParam.
+           }
+       }
     }
 }
 
@@ -219,29 +273,29 @@ void AliCheckMuonDetEltResponse::TrackLoop()
 //_____________________________________________________________________________
 void AliCheckMuonDetEltResponse::TrackParamLoop()
 {
-    Int_t nTrackParams = (Int_t) fTrackParams->GetEntriesFast();  //!<Number of trackParams in the track.
-    Int_t iTrackParam = 0;                                        //!<Number of the trackParam of the track.
-    Int_t oldChamber = -1, newChamber = 0; //!<To check if there is 0, 1 or 2 (overlap cases) clusters in the same chamber for a track.                                      
-    Int_t detElt;                          //!<Detection element Id.
+  Int_t nTrackParams = (Int_t) fTrackParams->GetEntriesFast();  //!<Number of trackParams in the track.
+  Int_t iTrackParam = 0;                                        //!<Number of the trackParam of the track.
+  Int_t oldChamber = -1, newChamber = 0; //!<To check if there is 0, 1 or 2 (overlap cases) clusters in the same chamber for a track.                                      
+  Int_t detElt;                          //!<Detection element Id.
   
-    for (Int_t ch = 0; ch < fNCh; ++ch)
+  for (Int_t ch = 0; ch < fNCh; ++ch)
     {
       fTrackFilter[ch] = 0;
     }
 
-    Double_t posXL, posYL, posZL;          //!<Local positions.
-    Double_t posXG, posYG, posZG;          //!<Global. positions.
-    Int_t chamberResponse [10] = {0};      //!<1 if the chamber has responded; 0 if not
-
-    for (iTrackParam = 0; iTrackParam < nTrackParams; ++iTrackParam)
+  Double_t posXL, posYL, posZL;          //!<Local positions.
+  Double_t posXG, posYG, posZG;          //!<Global. positions.
+  Int_t chamberResponse [10] = {0};      //!<1 if the chamber has responded; 0 if not
+  
+  for (iTrackParam = 0; iTrackParam < nTrackParams; ++iTrackParam)
     { 
       fTrackParam = (AliMUONTrackParam*) fTrackParams->At(iTrackParam);
       fCluster    = (AliMUONVCluster*  ) fTrackParam ->GetClusterPtr();    
       fTrackFilter   [fCluster->GetChamberId()] = 1;
       chamberResponse[fCluster->GetChamberId()] = 1;
     }
-
-    for (Int_t station = 0; station < fNSt-1; ++station)
+  
+  for (Int_t station = 0; station < fNSt-1; ++station)
     {
       Int_t filter;                                                  //<!
       Int_t ch1, ch2, ch3, ch4;                                      //<!
@@ -251,51 +305,58 @@ void AliCheckMuonDetEltResponse::TrackParamLoop()
       ch4 = 2*station + 3;                                           //<!
                                                                      //<!For the efficiency calculation the tracks
       if (station < 3 )                                              //<!reconstructed must have responded to the
-      {                                                              //<!criteria of the tracking. 
-       filter            = fTrackFilter[ch1];                       //<!And that's why the tracks usable for the 
-       fTrackFilter[ch1] = fTrackFilter[ch2];                       //<!intrinsic efficiency calculation are
-       fTrackFilter[ch2] = filter;                                  //<!the tracks which have one or two clusters
-      }                                                              //<!in each station. So the case where a track
-                                                                     //<!hasn't a cluster in a station is not
-      else                                                           //<!taking into account.
-      {                                                              //<!This part solves the problem. See the ALICE 
-       if (chamberResponse[ch3]*chamberResponse[ch4] != 0)          //<!note of Diego STOCCO on the trigger efficiency
-       {                                                            //<!
-       filter            = fTrackFilter[ch1];                       //<!
-       fTrackFilter[ch1] = fTrackFilter[ch2];                       //<!
-       fTrackFilter[ch2] = filter;                                  //<!
-       }                                                            //<!
-       else                                                         //<!
-       {                                                            //<!
-       fTrackFilter[ch1] = 0;                                       //<!
-       fTrackFilter[ch2] = 0;                                       //<!
-       }                                                            //<!
-                                                                     //<!
-       if (chamberResponse[ch1]*chamberResponse[ch2] != 0)          //<!
-       {                                                            //<!
-       filter            = fTrackFilter[ch3];                       //<!
-       fTrackFilter[ch3] = fTrackFilter[ch4];                       //<!
-       fTrackFilter[ch4] = filter;                                  //<!
-       }                                                            //<!
-       else                                                         //<!
-       {                                                            //<!
-       fTrackFilter[ch3] = 0;                                       //<!
-       fTrackFilter[ch4] = 0;                                       //<!
-       }                                                            //<!
-      }                                                              //<!
+       {                                                              //<!criteria of the tracking. 
+         filter            = fTrackFilter[ch1];                       //<!And that's why the tracks usable for the 
+         fTrackFilter[ch1] = fTrackFilter[ch2];                       //<!intrinsic efficiency calculation are
+         fTrackFilter[ch2] = filter;                                  //<!the tracks which have one or two clusters
+       }                                                              //<!in each station. So the case where a track
+                                                                       //<!hasn't a cluster in a station is not
+      else                                                             //<!taking into account.
+       {                                                              //<!This part solves the problem. See the ALICE 
+         if (chamberResponse[ch3]*chamberResponse[ch4] != 0)          //<!note of Diego STOCCO on the trigger efficiency
+           {                                                            //<!
+             filter            = fTrackFilter[ch1];                       //<!
+             fTrackFilter[ch1] = fTrackFilter[ch2];                       //<!
+             fTrackFilter[ch2] = filter;                                  //<!
+           }                                                            //<!
+         else                                                         //<!
+           {                                                            //<!
+             fTrackFilter[ch1] = 0;                                       //<!
+             fTrackFilter[ch2] = 0;                                       //<!
+           }                                                            //<!
+         //<!
+         if (chamberResponse[ch1]*chamberResponse[ch2] != 0)          //<!
+           {                                                            //<!
+             filter            = fTrackFilter[ch3];                       //<!
+             fTrackFilter[ch3] = fTrackFilter[ch4];                       //<!
+             fTrackFilter[ch4] = filter;                                  //<!
+           }                                                            //<!
+         else                                                         //<!
+           {                                                            //<!
+             fTrackFilter[ch3] = 0;                                       //<!
+             fTrackFilter[ch4] = 0;                                       //<!
+           }                                                            //<!
+       }                                                              //<!
     }                                                                //<!
+  
 
-    for (Int_t ch = 0; ch < fNCh; ++ch)
+  for (Int_t ch = 0; ch < fNCh; ++ch)
     {
       if (fTrackFilter[ch] == 1)
-      {
-       if ( chamberResponse[ch] != 0) ((TH2F*) fDetEltTDHistList->UncheckedAt(fNDE))->Fill(ch, 0);
-       if (!fDetEltTTHistList) ((TH2F*) fDetEltTTHistList->UncheckedAt(fNDE))->Fill(ch, 0);
-      }
+       {
+         if ( chamberResponse[ch] != 0) 
+           {
+             ((TH2F*) fDetEltTDHistList->UncheckedAt(fNDE))->Fill(ch, 0);
+             ((TH1F*) fChamberTDHistList->UncheckedAt(fNCh))->Fill(ch);          
+           }
+         
+         ((TH2F*) fDetEltTTHistList->UncheckedAt(fNDE))->Fill(ch, 0);
+         ((TH1F*) fChamberTTHistList->UncheckedAt(fNCh))->Fill(ch);
+       }
     } 
-
- ///Begining of the loop:
-    for (iTrackParam = 0; iTrackParam < nTrackParams; ++iTrackParam)
+  
+  ///Begining of the loop:
+  for (iTrackParam = 0; iTrackParam < nTrackParams; ++iTrackParam)
     {
       fTrackParam = (AliMUONTrackParam*) fTrackParams->At(iTrackParam);
       fCluster    = (AliMUONVCluster*  ) fTrackParam ->GetClusterPtr(); 
@@ -303,124 +364,79 @@ void AliCheckMuonDetEltResponse::TrackParamLoop()
       newChamber  = fCluster->GetChamberId();
       detElt      = fCluster->GetDetElemId();
 
-   ///Global and local positions calculation:
+      ///Global and local positions calculation:
       posXG = fTrackParam->GetNonBendingCoor(); 
       posYG = fTrackParam->GetBendingCoor(); 
       posZG = fTrackParam->GetZ(); 
-
+      
       fTransformer->Global2Local(detElt, posXG, posYG, posZG, posXL, posYL, posZL);  //!<Transfomation from global to local positions.
-   
-   ///Filling histograms of the cluster positions on the detection element of the TRACKS DETECTED (TD):
-      FillDetEltTDHisto(newChamber, detElt, posXL, posYL);
-
-   ///Filling histograms of the cluster positions on the detection element of ALL THE TRACKS (TT):
-      FillDetEltTTHisto(newChamber, detElt, posXG, posYG, posZG, posXL, posYL, posZL);
+      
+      ///Filling histograms of the cluster positions on the detection element of the TRACKS DETECTED (TD):
+      FillTDHistos(newChamber, detElt, posXL, posYL);
+    
+      ///Filling histograms of the cluster positions on the detection element of ALL THE TRACKS (TT):
+      FillTTHistos(newChamber, detElt, posXL, posYL);
 
       if (newChamber != oldChamber) 
-      {
-       if (newChamber > oldChamber + 1)                                 //!<Check if it doesn't miss a chamber.
-       {
-         Int_t nbrOfMissCh = newChamber - (oldChamber+1);                //!<Number of missing chambers.
-         CalculMissClusterParam(fTrackParam, oldChamber+1, nbrOfMissCh); //!<Calculation of the parameters of the missing cluster(s).
-       }
-       if ( iTrackParam == nTrackParams - 1 && newChamber != fNCh-1)           //!<Check if the last chamber, chamber 9 (from 0 to 9) has responded.
        {
-         CalculMissClusterParam(fTrackParam, fNCh-1, 1);                      //!<Calculation of the parameters of the missing cluster(s) in the last chamber.
+         if (newChamber > oldChamber + 1)                                 //!<Check if it doesn't miss a chamber.
+           {
+             Int_t nbrMissChamber = newChamber - (oldChamber + 1);
+             FindAndFillMissedDetElt(fTrackParam, oldChamber+1, nbrMissChamber); //!<Calculation of the parameters of the missing cluster(s).
+           }
+           
+         if ( iTrackParam == nTrackParams - 1 && newChamber != fNCh-1)           //!<Check if the last chamber, chamber 9 (from 0 to 9) has responded.
+           {     
+             FindAndFillMissedDetElt(fTrackParam, fNCh-1, 1);                      //!<Calculation of the parameters of the missing cluster(s) in the last chamber.
+           }
        }
-      }
       oldChamber = newChamber; 
-    }
+    } 
 }
 
 
 
 //_____________________________________________________________________________
-void AliCheckMuonDetEltResponse::FillDetEltTDHisto(Int_t chamber,
-                                                  Int_t detElt,
-                                                  Double_t posXL,
-                                                  Double_t posYL)
+void AliCheckMuonDetEltResponse::FillTDHistos(Int_t chamber,
+                                             Int_t detElt,
+                                             Double_t posXL,
+                                             Double_t posYL)
 {
-    if(fTrackFilter[chamber]== 1)
+  if(fTrackFilter[chamber]== 1)
     {
       Int_t iDet = 0; //!<Position of the detection element in the histograms' list.
       iDet = FromDetElt2iDet(chamber, detElt);
       ((TH2F*) fDetEltTDHistList->UncheckedAt(iDet))->Fill(posXL, posYL);
+      
+      Int_t detEltLocalId = 0;  //!<Id of the detection element in the station
+      detEltLocalId =  FromDetElt2LocalId(chamber, detElt);
+      ((TH1F*) fChamberTDHistList->UncheckedAt(chamber))->Fill(detEltLocalId);
     }
 }
 
 
 
+
 //_____________________________________________________________________________
-void AliCheckMuonDetEltResponse::FillDetEltTTHisto(Int_t chamber,
-                                                  Int_t detElt,
-                                                  Double_t posXG,
-                                                  Double_t posYG,
-                                                  Double_t posZG,
-                                                  Double_t posXL,
-                                                  Double_t posYL,
-                                                  Double_t posZL)
+void AliCheckMuonDetEltResponse::FillTTHistos(Int_t chamber,
+                                             Int_t detElt,
+                                             Double_t posXL,
+                                             Double_t posYL)
 {
-    if(fTrackFilter[chamber] == 1)
+  if(fTrackFilter[chamber] == 1)
     {
       Int_t iDet = 0; //!<Position of the detection element in the histograms' list.
       iDet = FromDetElt2iDet(chamber, detElt);
-      if (!fDetEltTTHistList)  ((TH2F*) fDetEltTTHistList->UncheckedAt(iDet)) -> Fill(posXL, posYL);
+      ((TH2F*) fDetEltTTHistList->UncheckedAt(iDet)) -> Fill(posXL, posYL);
       
-      if(TMath::Abs(posYL) > fOverlapSize) //!<It is an overlap area. It can have two clusters for this track in this chamber.
-      {
-       GetDetEltFromPosition(chamber, posXG, posYG, posZG);
-       if(fGetDetElt[1] != 0) //<!There is a second detection element for the same (X,Y) in this chamber (overlap).
-       {
-         if(fGetDetElt[1] != detElt)
-         {
-           fTransformer->Global2Local(fGetDetElt[1], posXG, posYG, posZG, posXL, posYL, posZL);  //!<Transfomation from global to local positions.
-           iDet = FromDetElt2iDet(chamber, fGetDetElt[1]);
-           if (!fDetEltTTHistList) ((TH2F*) fDetEltTTHistList->UncheckedAt(iDet)) -> Fill(posXL, posYL);
-         }
-         else
-         {
-           fTransformer->Global2Local(fGetDetElt[0], posXG, posYG, posZG, posXL, posYL, posZL);  //!<Transfomation from global to local positions.
-           iDet = FromDetElt2iDet(chamber, fGetDetElt[0]);
-           if (!fDetEltTTHistList) ((TH2F*) fDetEltTTHistList->UncheckedAt(iDet)) -> Fill(posXL, posYL);
-         }
-       }
-      }
+      Int_t detEltLocalId = 0;  //!<Id of the detection element in the station
+      detEltLocalId =  FromDetElt2LocalId(chamber, detElt);
+      ((TH1F*) fChamberTTHistList->UncheckedAt(chamber))->Fill(detEltLocalId);
     }
 }
 
 
 
-//_____________________________________________________________________________
-void AliCheckMuonDetEltResponse::CalculMissClusterParam(AliMUONTrackParam* extrapTrackParam,
-                                                       Int_t firstMissCh,
-                                                       Int_t nbrOfMissCh)
-{
-//Calculation of the cluster parameter which was not detect by
-//the chamber.
-
-    for (Int_t iCh = 0; iCh<nbrOfMissCh; ++iCh)
-    {
-      Double_t exTraXL, exTraYL, exTraZL;   //!<Extrapolated local positions.
-      Double_t exTraXG, exTraYG, exTraZG;   //!<Extrapolated global positions.
-      Int_t missChamber= firstMissCh + iCh; //!<The missing chamber.
-      Int_t missDetElt = 0;
-
-      exTraZG = AliMUONConstants::DefaultChamberZ(missChamber);
-      AliMUONTrackExtrap::ExtrapToZ(extrapTrackParam, exTraZG);      //!<Extrapolation to the missing chamber.
-      exTraXG = extrapTrackParam->GetNonBendingCoor();               //!<Global X position extrapolated to the missing chamber.
-      exTraYG = extrapTrackParam->GetBendingCoor();                  //!<Global Y position extrapolated to the missing chamber.
-
-      GetDetEltFromPosition(missChamber, exTraXG, exTraYG, exTraZG); //!<Gives the detection element (fGetDetElt) with the position.
-      missDetElt = fGetDetElt[0];
-
-      if( missDetElt != 0 ) //!<Check if the track has passed trough a detection area
-      {
-       fTransformer->Global2Local(missDetElt, exTraXG, exTraYG, exTraZG, exTraXL, exTraYL, exTraZL);  //!<Transfomation from global to local positions.
-       FillDetEltTTHisto(missChamber, missDetElt, exTraXG, exTraYG, exTraZG, exTraXL, exTraYL, exTraZL);
-      }
-    }
-}
-
 
 
 //_____________________________________________________________________________
@@ -443,53 +459,133 @@ Int_t AliCheckMuonDetEltResponse::FromDetElt2iDet(Int_t chamber,
 
 
 //_____________________________________________________________________________
-void AliCheckMuonDetEltResponse::GetDetEltFromPosition(Int_t chamber,
-                                                      Double_t posX,
-                                                      Double_t posY,
-                                                      Double_t posZ)
+Int_t AliCheckMuonDetEltResponse::FromDetElt2LocalId(Int_t chamber, 
+                                                    Int_t detElt)
 {
 ///
-///Gives the detetection element fGetDetElt[0] corresponding to the position. In the case 
-///of an overlap (two detection element with the same (X,Y)) fGetDetElt[1] is calculated.
+///Connexion between the detection element X and its number in the station.
 ///
 
-    Int_t nbrOfDetElt =  AliMpDEManager::GetNofDEInChamber(chamber, kTRUE); //!<Number of detection elements in the chamber.
-    Int_t detElt = 0, lastDetElt = 0;
+    Int_t localId = 0; //!<Position of the detection element (detElt) in the histograms' list.
+    localId = detElt - (chamber+1) * 100;
 
-    Double_t posXL, posYL, posZL; //!<Local positions.
-    posXL = posYL = posZL = 1000.;
-    fGetDetElt[0] = fGetDetElt[1] = 0;
+    return localId;    
+}
 
-    if(chamber>3)
-    {
-      Int_t shift  = 0;                                                    //!<|
-      if(posX<0) shift =    nbrOfDetElt /4 + 1;                            //!<|Method to avoid the loop on all elements of
-      if(posX>0) shift = (3*nbrOfDetElt)/4 + 1;                            //!<|detection, and just loop through fourth chamber.
-                                                                           //!<|
-      detElt = fOffset*(chamber+1) + shift;                                //!<|
-      lastDetElt = fOffset*(chamber+1) +(shift+nbrOfDetElt/2)%nbrOfDetElt; //!<|
-      
-      Int_t nbr = 0;
-      while(detElt != lastDetElt) //!<Loop on fourth chamber.
-      {
 
-       fTransformer->Global2Local(detElt, posX, posY, posZ, posXL, posYL, posZL);  //!<Transfomation from global to local positions.
 
-       if(TMath::Abs(posYL)< fYSlatSize) //!<If |posYL|<20 => the cluster is in the detection element (-20<Ylocal<20 for each slat).   
-       {
-         fGetDetElt[nbr] = detElt;  
-         ++nbr;
-       }       
-       shift  = (shift + 1)%nbrOfDetElt;
-       detElt = fOffset*(chamber+1) + shift;
-      }
-    }
-    
-    else //!<For the station 1 & 2 (4 detection elements in each chamber). 
+//_____________________________________________________________________________
+void AliCheckMuonDetEltResponse::FindAndFillMissedDetElt(AliMUONTrackParam* extrapTrackParam, 
+                                                        Int_t firstMissCh,
+                                                        Int_t nbrMissCh)
+{
+///
+///Find which detection elements should have been hit but were missed, 
+///and fill the TT histos appropriately
+///
+  for (Int_t iCh = 0; iCh < nbrMissCh; ++iCh)
     {
-      if(posX>0 && posY>0) fGetDetElt[0] = fOffset*(chamber+1)    ;
-      if(posX<0 && posY>0) fGetDetElt[0] = fOffset*(chamber+1) + 1;
-      if(posX<0 && posY<0) fGetDetElt[0] = fOffset*(chamber+1) + 2;
-      if(posX>0 && posY<0) fGetDetElt[0] = fOffset*(chamber+1) + 3; 
+      Int_t chamber = firstMissCh + iCh;
+      Int_t nbrOfDetElt =  AliMpDEManager::GetNofDEInChamber(chamber, kTRUE); //!<Number of detection elements in the chamber.
+      
+      Double_t pos1[6] = {0, 0, 0, 0, 0, 0};        //!<First point used to compute the extrapolated point (first 3 for global coordinates, last 3 for local).
+      Double_t pos2[6] = {0, 0, 0, 0, 0, 0};        //!<Second point used to compute the extrapolated point (first 3 for global coordinates, last 3 for local).
+      Double_t posMiss[2] = {0, 0};                 //!<(X, Y) local coordinates of the missing cluster.
+            
+      pos1[2] = AliMUONConstants::DefaultChamberZ(chamber);           //!<Z of point 1, defined by being the Z of the chamber in "perfect" position.
+      AliMUONTrackExtrap::ExtrapToZ(extrapTrackParam, pos1[2]);
+      pos1[0] = extrapTrackParam->GetNonBendingCoor();                //!<X of point 1, extrapolated by following the Track.
+      pos1[1] = extrapTrackParam->GetBendingCoor();                   //!<Y of point 1, extrapolated by following the Track.
+      
+      pos2[2] = AliMUONConstants::DefaultChamberZ(chamber) + AliMUONConstants::DzCh();   //!<Z of point 2, defined by being the Z of the chamber in "perfect" position 
+      AliMUONTrackExtrap::ExtrapToZ(extrapTrackParam, pos2[2]);                           //!< + plus a small shift (the distance between two stations in a same chamber).
+      pos2[0] = extrapTrackParam->GetNonBendingCoor();                                   //!<X of point 2, extrapolated by following the Track.                        
+      pos2[1] = extrapTrackParam->GetBendingCoor();                                      //!<Y of point 2, extrapolated by following the Track.                          
+      
+      
+      
+       for (Int_t iDE = 0; iDE < nbrOfDetElt; iDE++)                    //!<Loop on all the detection element of the chamber
+         {
+           Int_t deId = (chamber + 1)*fOffset + iDE;                        //!<detection element Id 
+           
+           fTransformer->Global2Local(deId, pos1[0], pos1[1], pos1[2], pos1[3], pos1[4], pos1[5]);      //!<convesrion of point 1 and 2 in the local coordinates
+           fTransformer->Global2Local(deId, pos2[0], pos2[1], pos2[2], pos2[3], pos2[4], pos2[5]);
+           
+           CoordinatesOfMissingCluster(pos1[3], pos1[4], pos1[5], pos2[3], pos2[4], pos2[5], posMiss[0], posMiss[1]);
+
+           Bool_t IsMissed = kFALSE;
+           if (chamber < 4)
+             IsMissed = CoordinatesInDetEltSt12(deId, posMiss[0], posMiss[1]);
+           else
+             IsMissed = CoordinatesInDetEltSt345(deId, posMiss[0], posMiss[1]);
+
+           if (IsMissed)
+             FillTTHistos(chamber, deId, posMiss[0], posMiss[1]);
+           
+         }
     }
 }
+
+
+
+//_____________________________________________________________________________
+void AliCheckMuonDetEltResponse::CoordinatesOfMissingCluster(Double_t x1, Double_t y1, Double_t z1,
+                                                            Double_t x2, Double_t y2, Double_t z2,
+                                                            Double_t& x, Double_t& y)
+{
+  //
+  //Compute the coordinates of the missing cluster.
+  //There are defined by the intersection between the straigth line joining two extrapolated points (1 and 2) and the detection element plane.
+  //In the local coordinates, this means Z=0 in the parametric equation of the line.
+  //
+
+  Double_t t = 0;
+  t = - z1 / (z2 - z1);
+  
+  x = t * (x2 - x1) + x1;
+  y = t * (y2 - y1) + y1;
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliCheckMuonDetEltResponse::CoordinatesInDetEltSt345(Int_t DeId, Double_t x, Double_t y)
+{
+  //
+  //Return kTRUE if the coordinates are in the Detection Element, for station 3, 4 and 5.
+  //This is done by checking if a pad correspond to the (x, y) position.
+  //  
+
+  AliMpPad pad1;
+  AliMpPad pad2;
+
+  AliMpSlatSegmentation *segm1 = new AliMpSlatSegmentation(AliMpSegmentation::Instance(kFALSE)->GetSlat(DeId, AliMp::kCath0));
+  AliMpSlatSegmentation *segm2 = new AliMpSlatSegmentation(AliMpSegmentation::Instance(kFALSE)->GetSlat(DeId, AliMp::kCath1));
+  pad1 = segm1->PadByPosition(x, y, kFALSE);
+  pad2 = segm2->PadByPosition(x, y, kFALSE);
+  if (pad1.IsValid() || pad2.IsValid())
+    return kTRUE;
+  else
+    return kFALSE;
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliCheckMuonDetEltResponse::CoordinatesInDetEltSt12(Int_t DeId, Double_t x, Double_t y)
+{
+  //Return kTRUE if the coordinates are in the Detection Element, for station 1 and 2.
+  //This is done by checking if a pad correspond to the (x, y) position.
+  
+  AliMpPad pad1;
+  AliMpPad pad2;
+
+  AliMpSectorSegmentation *segm1 = new AliMpSectorSegmentation(AliMpSegmentation::Instance(kFALSE)->GetSector(DeId, AliMp::kCath0));
+  AliMpSectorSegmentation *segm2 = new AliMpSectorSegmentation(AliMpSegmentation::Instance(kFALSE)->GetSector(DeId, AliMp::kCath1));
+  pad1 = segm1->PadByPosition(x, y, kFALSE);
+  pad2 = segm2->PadByPosition(x, y, kFALSE);
+  if (pad1.IsValid() || pad2.IsValid())
+    return kTRUE;
+  else
+    return kFALSE;
+}
index ac592be..c2bd16e 100644 (file)
@@ -28,7 +28,10 @@ public:
   AliCheckMuonDetEltResponse(const AliMUONGeometryTransformer* transformer,
                             AliESDEvent* esd,
                             TClonesArray* detEltTDHistList,
-                            TClonesArray* detEltTTHistList);
+                            TClonesArray* detEltTTHistList,
+                            TClonesArray* chamberTDHistList,
+                            TClonesArray* chamberTTHistList,
+                            Bool_t isCosmic = kFALSE);
 
 //Destructor:
   virtual ~AliCheckMuonDetEltResponse();
@@ -37,21 +40,27 @@ public:
   void CheckDetEltResponse ();
   void TrackLoop ();
   void TrackParamLoop ();
+
+  void SetCosmic(Bool_t isCosmic) {fIsCosmicData = isCosmic;};
+  Bool_t IsCosmic() {return fIsCosmicData;};
  
 private:
   
-  void FillDetEltTDHisto (Int_t chamber, Int_t detElt,
-                         Double_t posXL, Double_t posYL);
+  void FillTDHistos (Int_t chamber, Int_t detElt,
+                    Double_t posXL, Double_t posYL);
+
+  void FillTTHistos (Int_t chamber, Int_t detElt,
+                    Double_t posXL, Double_t posYL);
 
-  void FillDetEltTTHisto (Int_t chamber, Int_t detElt,
-                         Double_t posXG, Double_t posYG, Double_t posZG,
-                         Double_t posXL, Double_t posYL, Double_t posZL);
+  void FindAndFillMissedDetElt (AliMUONTrackParam* extrapTrackParam,
+                               Int_t firstMissCh, Int_t lastChamber);
 
-  void CalculMissClusterParam (AliMUONTrackParam* extrapTrackParam,
-                              Int_t firstMissCh, Int_t nbrOfMissCh);
+  void CoordinatesOfMissingCluster(Double_t x1, Double_t y1, Double_t z1,
+                                  Double_t x2, Double_t y2, Double_t z2,
+                                  Double_t& x, Double_t& y);
 
-  void GetDetEltFromPosition (Int_t chamber,
-                             Double_t posX, Double_t posY, Double_t posZ);
+  Bool_t CoordinatesInDetEltSt12(Int_t DeId, Double_t x, Double_t y);
+  Bool_t CoordinatesInDetEltSt345(Int_t DeId, Double_t x, Double_t y);
 
 
   Int_t fNCh; //!<Number of tracking chamber.
@@ -59,6 +68,7 @@ private:
   Int_t fNDE; //!<Number of detection element in the tracking system.
 
   Int_t FromDetElt2iDet (Int_t chamber, Int_t detElt);
+  Int_t FromDetElt2LocalId (Int_t chamber, Int_t detElt);
 
   const AliMUONGeometryTransformer* fTransformer; //!<Geometry transformer
 
@@ -66,8 +76,8 @@ private:
 
   Int_t fNbrClustersCh[10];      //!<Number of clusters in the chamber [fChamberNbr].
   Int_t fTracksTotalNbr;         //!<Total number of tracks in the event.
-  Int_t fGetDetElt[2];           //!<Detection elemtents obtained from position(X,Y,Z). fGetDetElt[1] is for the case where there is an overlap.
   Int_t fTrackFilter[10];        //!<To select track for the efficiency calculation.
+  Bool_t fIsCosmicData;          ///< Check if the data are cosmic rays (used only to cut cosmic shower at hte trigger level if true)
 
   TClonesArray     * fTrackParams;
   AliMUONTrackParam* fTrackParam;
@@ -75,6 +85,8 @@ private:
 
   TClonesArray* fDetEltTDHistList; //!<List of histograms of the tracks detected in the detection elements 
   TClonesArray* fDetEltTTHistList; //!<List of histograms of the tracks which have passed through the detection elements
+  TClonesArray* fChamberTDHistList; //!<List of histograms of the tracks detected in the chambers 
+  TClonesArray* fChamberTTHistList; //!<List of histograms of the tracks which have passed through the chambers
 
   static const Int_t fNbrOfChamber;            ///< The total number of chamber in the tracking system.
   static const Int_t fNbrOfStation;            ///< The total number of station in the tracking system.
index 83a2cdf..c2f0469 100644 (file)
@@ -25,7 +25,7 @@
 
 
 
-void MuonTrackingEffAnalysis(const Bool_t alien = false, const Int_t run = 100, const char * fileName = "AliESDs.root", const char * geometryFileName = "geometry.root")
+void MuonTrackingEffAnalysis(const Bool_t alien = false, const Int_t run = 100, const char * fileName = "AliESDs.root", const char * geometryFileName = "geometry.root", Bool_t isCosmicData = kFALSE)
 {
 //Chain construction
     TChain *chain = new TChain("esdTree");
@@ -54,7 +54,7 @@ void MuonTrackingEffAnalysis(const Bool_t alien = false, const Int_t run = 100,
 
 //Make analysis manager:
     AliAnalysisManager* mgr = new AliAnalysisManager("Manager", "Manager");  
-    AliAnalysisTaskMuonTrackingEff* ESDTask = new AliAnalysisTaskMuonTrackingEff("ESDTask", transformer);
+    AliAnalysisTaskMuonTrackingEff* ESDTask = new AliAnalysisTaskMuonTrackingEff("ESDTask", transformer, isCosmicData);
     AliESDInputHandler* inHandler = new AliESDInputHandler();
 
     mgr->SetInputEventHandler  (inHandler );
@@ -62,14 +62,29 @@ void MuonTrackingEffAnalysis(const Bool_t alien = false, const Int_t run = 100,
     mgr->AddTask(ESDTask);
 
 //Create containers for input/output
-    AliAnalysisDataContainer* cinput1  =       mgr->GetCommonInputContainer();
+    AliAnalysisDataContainer* cinput0  =       mgr->GetCommonInputContainer();
+    AliAnalysisDataContainer *coutput0 =
+       mgr->CreateContainer("TracksDetectedPerDE", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root");
     AliAnalysisDataContainer *coutput1 =
-       mgr->CreateContainer("chistlist1", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root"); 
+       mgr->CreateContainer("TotalTracksPerDE", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root");
+    AliAnalysisDataContainer *coutput2 =
+       mgr->CreateContainer("EfficiencyPerDE", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root");
+    AliAnalysisDataContainer *coutput3 =
+       mgr->CreateContainer("TracksDetectedPerChamber", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root");
+    AliAnalysisDataContainer *coutput4 =
+       mgr->CreateContainer("TotalTracksPerChamber", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root");
+    AliAnalysisDataContainer *coutput5 =
+       mgr->CreateContainer("EfficiencyPerChamber", TClonesArray::Class(),AliAnalysisManager::kOutputContainer, "MuonTrackingChamberEffHistos.root");
 
 //Connection
-    mgr->ConnectInput (ESDTask, 0, cinput1 );
-    mgr->ConnectOutput(ESDTask, 0, coutput1);
-   
+    mgr->ConnectInput (ESDTask, 0, cinput0 );
+    mgr->ConnectOutput(ESDTask, 0, coutput0);
+    mgr->ConnectOutput(ESDTask, 1, coutput1);
+    mgr->ConnectOutput(ESDTask, 2, coutput2);
+    mgr->ConnectOutput(ESDTask, 3, coutput3);
+    mgr->ConnectOutput(ESDTask, 4, coutput4);
+    mgr->ConnectOutput(ESDTask, 5, coutput5);
+  
 //Run analysis
     if(mgr->InitAnalysis())
     {