LCOV - code coverage report
Current view: top level - TPC/TPCcalib - AliAnalysisTaskPt.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 139 0.7 %
Date: 2016-06-14 17:26:59 Functions: 1 7 14.3 %

          Line data    Source code
       1             : #include "TChain.h"
       2             : #include "TTree.h"
       3             : #include "TH1F.h"
       4             : #include "TCanvas.h"
       5             : #include "TObjArray.h"
       6             : 
       7             : #include "AliAnalysisTask.h"
       8             : #include "AliAnalysisManager.h"
       9             : 
      10             : #include "AliESDEvent.h"
      11             : #include "AliESDtrackCuts.h"
      12             : #include "AliVEventHandler.h"
      13             : #include "AliTPCseed.h"
      14             : #include "AliTPCclusterMI.h"
      15             : #include "AliVfriendEvent.h"
      16             : #include "AliVfriendTrack.h"
      17             : #include "AliESDInputHandler.h"
      18             : 
      19             : #include "AliAnalysisTaskPt.h"
      20             : 
      21             : // example of an analysis task creating a p_t spectrum
      22             : // Authors: Panos Cristakoglou, Jan Fiete Grosse-Oetringhaus, Christian Klein-Boesing
      23             : 
      24           6 : ClassImp(AliAnalysisTaskPt)
      25             : 
      26             : //________________________________________________________________________
      27             : AliAnalysisTaskPt::AliAnalysisTaskPt(const char *name) 
      28           0 : : AliAnalysisTask(name, ""), fESD(0), fESDfriend(0), fHistPt(0), fCuts(0), fEv(0), fHistQ(0), fListOut(0), fUseFriends(kFALSE), fHistNTPCCl(0), fHistNESDtracks(0),   fHistNESDfriendtracks(0)
      29             : 
      30           0 : {
      31             :   // Constructor
      32             : 
      33             :   // Define input and output slots here
      34             :   // Input slot #0 works with a TChain
      35           0 :   DefineInput(0, TChain::Class());
      36             :   // Output slot #0 writes into a TH1 container
      37           0 :   DefineOutput(0, TList::Class());
      38           0 : }
      39             : 
      40             : //________________________________________________________________________
      41             : void AliAnalysisTaskPt::ConnectInputData(Option_t *) 
      42             : {
      43             :   // Connect ESD or AOD here
      44             :   // Called once
      45             : 
      46           0 :   printf("----> AliAnalysisTaskPt::ConnectInputData\n");
      47           0 :   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
      48           0 :   if (!tree) {
      49           0 :     Printf("ERROR: Could not read chain from input slot 0");
      50           0 :   } 
      51             :   else {
      52             :     // Disable all branches and enable only the needed ones
      53             :     // The next two lines are different when data produced as AliESDEvent is read
      54             :     /*
      55             :     tree->SetBranchStatus("*", kFALSE);
      56             :     tree->SetBranchStatus("fTracks.*", kTRUE);
      57             :     */
      58             : 
      59           0 :     AliVEventHandler *esdH = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
      60           0 :     TString classInputHandler;
      61             : 
      62           0 :     if (!esdH) {
      63           0 :       Printf("ERROR: Could not get ESDInputHandler");
      64             :     } 
      65             :     else {
      66           0 :       classInputHandler = esdH->ClassName();
      67           0 :       Printf("----> AliAnalysisTaskPt: ClassName of handler = %s", classInputHandler.Data());
      68           0 :       Printf("----> AliAnalysisTaskPt::ConnectInputData Getting the event from handler %p", esdH);
      69           0 :       fESD = esdH->GetEvent();
      70           0 :       if (fUseFriends){
      71           0 :         Printf("...We have to use the friends...");
      72           0 :         if (classInputHandler.Contains("HLT")) { // we are running in HLT
      73           0 :           fESDfriend = esdH->GetVfriendEvent();
      74           0 :         }
      75             :         else { /// we are running offline
      76           0 :           if (esdH && esdH->GetTree()) {
      77           0 :             Printf("...We got the tree...");
      78           0 :             if (esdH->GetTree()->GetBranch("ESDfriend.")){
      79           0 :               Printf("Yu-huuuu!!! friend branch found");
      80           0 :               fESDfriend = ((AliESDInputHandler*)esdH)->GetESDfriend();
      81           0 :             }
      82             :             else {
      83           0 :               Printf("No friend branch found");
      84             :             }
      85             :           }
      86             :         }       
      87           0 :         Printf("and the result is: fESDfriend = %p", fESDfriend);
      88             :       }
      89             :       else {
      90           0 :         Printf("The friends are not requested");
      91             :       }
      92             :     }
      93           0 :     if (!fESD) {
      94           0 :       Printf("ERROR, no ESD event");
      95             :     }
      96           0 :     if (fUseFriends && !fESDfriend) {
      97           0 :       Printf("ERROR, no ESD friend");
      98             :     }
      99           0 :   }
     100             : 
     101           0 :   Printf("fESD = %p, fESDfriend = %p", fESD, fESDfriend);
     102           0 :   printf("<---- AliAnalysisTaskPt::ConnectInputData\n");
     103           0 : }
     104             : 
     105             : //________________________________________________________________________
     106             : void AliAnalysisTaskPt::CreateOutputObjects()
     107             : {
     108             :   // Create histograms
     109             :   // Called once
     110             : 
     111           0 :   fListOut = new TList();
     112           0 :   fListOut->SetOwner();
     113           0 :   fListOut->SetName("listHistos");
     114             : 
     115           0 :   fHistPt = new TH1F("fHistPt", "P_{T} distribution", 15, 0.1, 3.1);
     116           0 :   fHistPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
     117           0 :   fHistPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
     118           0 :   fHistPt->SetMarkerStyle(kFullCircle);
     119             : 
     120           0 :   fHistQ = new TH1F("fHistQ", "TPC clusters: Q distribution", 1000, 0, 10000);
     121           0 :   fHistQ->GetXaxis()->SetTitle("Q");
     122           0 :   fHistQ->GetYaxis()->SetTitle("dN/dQ");
     123           0 :   fHistQ->SetMarkerStyle(kFullCircle);
     124             : 
     125           0 :   fHistNTPCCl = new TH1F("fHistNTPCCl", "Number of TPC clusters", 160, -0.5, 159.5);
     126           0 :   fHistNTPCCl->GetXaxis()->SetTitle("n. TPC Cl.");
     127           0 :   fHistNTPCCl->GetYaxis()->SetTitle("dN/d(n. TPC Cl)");
     128           0 :   fHistNTPCCl->SetMarkerStyle(kFullCircle);
     129             : 
     130           0 :   fHistNESDtracks = new TH1F("fHistNESDtracks", "Number of ESD friend tracks", 1000, -0.5, 999.5);
     131           0 :   fHistNESDtracks->GetXaxis()->SetTitle("n. ESD friend tracks");
     132           0 :   fHistNESDtracks->GetYaxis()->SetTitle("dN/d(n. ESD friend tracks)");
     133           0 :   fHistNESDtracks->SetMarkerStyle(kFullCircle);
     134             : 
     135           0 :   fHistNESDfriendtracks = new TH1F("fHistNESDfriendtracks", "Number of ESD tracks", 1000, -0.5, 999.5);
     136           0 :   fHistNESDfriendtracks->GetXaxis()->SetTitle("n. ESD tracks");
     137           0 :   fHistNESDfriendtracks->GetYaxis()->SetTitle("dN/d(n. ESD tracks)");
     138           0 :   fHistNESDfriendtracks->SetMarkerStyle(kFullCircle);
     139             : 
     140           0 :   fListOut->Add(fHistPt);
     141           0 :   fListOut->Add(fHistQ);
     142           0 :   fListOut->Add(fHistNTPCCl);
     143           0 :   fListOut->Add(fHistNESDtracks);
     144           0 :   fListOut->Add(fHistNESDfriendtracks);
     145             : 
     146           0 :   PostData(0, fListOut);
     147             : 
     148           0 :   fCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(1);
     149           0 : }
     150             : 
     151             : //________________________________________________________________________
     152             : void AliAnalysisTaskPt::Exec(Option_t *) 
     153             : {
     154             :   // Main loop
     155             :   // Called for each event
     156             : 
     157           0 :   if (!fESD) {
     158           0 :     Printf("ERROR: fESD not available");
     159           0 :     return;
     160             :   }
     161             : 
     162             :   /*
     163             :   if (fUseFriends){
     164             :     Printf("In Exec: ...We have to use the friends...");
     165             :     fESDfriend = fESD->FindFriend();
     166             :     Printf("...and we got friends = %p", fESDfriend);
     167             :     if (!fESDfriend) {
     168             :       Printf("ERROR: fESDfriend not available");
     169             :         return;
     170             :     }
     171             :   }
     172             :   */
     173             : 
     174           0 :   if (fUseFriends){
     175           0 :     Printf("In Exec: ...We have to use the friends...");
     176           0 :     Printf("...and we got friends = %p", fESDfriend);
     177           0 :     if (!fESDfriend) {
     178           0 :       Printf("ERROR: fESDfriend not available");
     179           0 :         return;
     180             :     }
     181             :   }
     182             : 
     183           0 :   Int_t nESDtracks = fESD->GetNumberOfTracks();
     184             :   Int_t nESDfriendtracks = 0;
     185           0 :   if (fUseFriends) nESDfriendtracks = fESDfriend->GetNumberOfTracks();
     186           0 :   Printf("There are %d tracks in this event", nESDtracks);
     187           0 :   Printf("... and there are %d friends in this event", nESDfriendtracks);
     188             : 
     189           0 :   fHistNESDtracks->Fill(nESDtracks);
     190           0 :   fHistNESDfriendtracks->Fill(nESDfriendtracks);
     191             : 
     192             :   // Track loop to fill a pT spectrum
     193           0 :   for (Int_t iTracks = 0; iTracks < nESDtracks; iTracks++) {
     194           0 :     Printf("Checking track %d", iTracks);
     195           0 :     const AliVTrack* track = dynamic_cast<AliVTrack*>(fESD->GetTrack(iTracks));
     196           0 :     if (!track) {
     197           0 :       Printf("ERROR: Could not receive track %d", iTracks);
     198           0 :       continue;
     199             :     }
     200           0 :     Printf("track %d has pt = %f", iTracks, track->Pt());
     201           0 :     fHistPt->Fill(track->Pt());
     202           0 :     fHistNTPCCl->Fill(track->GetTPCNcls());
     203           0 :   } //track loop 
     204             : 
     205             : 
     206           0 :   if (fUseFriends){
     207           0 :     Printf("In the loop over the friends");
     208             :     // Friend Track loop
     209           0 :     for (Int_t iFriend = 0; iFriend < nESDfriendtracks; iFriend++) {
     210           0 :       Printf("Getting friend %d", iFriend);
     211           0 :       const AliVfriendTrack* friendTrack = fESDfriend->GetTrack(iFriend);
     212           0 :       if (!friendTrack) {
     213           0 :         Printf("ERROR: Could not receive track %d", iFriend);
     214           0 :         continue;
     215             :       }
     216             :       else {
     217           0 :         Printf("friend track = %p", friendTrack);
     218             :       }
     219             :       
     220           0 :       AliTPCseed seed;
     221           0 :       Int_t err = friendTrack->GetTPCseed( seed );
     222           0 :       Printf("err = %d", err);
     223           0 :       if( err==0 ){
     224           0 :         Printf("Found TPC seed" );
     225           0 :         for (Int_t irow = 0; irow < kMaxRow; irow++){
     226           0 :           AliTPCclusterMI* cluMI = seed.GetClusterPointer(irow);
     227           0 :           if (cluMI){
     228           0 :             Printf("Found cluster at row %d", irow);
     229           0 :             Float_t q = cluMI->GetQ();
     230           0 :             Printf("Q = %f", q);
     231           0 :             fHistQ->Fill(q);
     232           0 :           }
     233             :           else {
     234           0 :             Printf("Row %d does not contain clusters", irow);
     235             :           }              
     236             :         }
     237           0 :       }     
     238             :       else {
     239             :         //Printf("Schade... seed is %p", seed);
     240             :       }
     241           0 :     }
     242           0 :   }
     243             : 
     244             :   // Post output data.
     245           0 :   PostData(0, fListOut);
     246           0 :   fEv++;
     247           0 : }      
     248             : 
     249             : //________________________________________________________________________
     250             : void AliAnalysisTaskPt::Terminate(Option_t *) 
     251             : {
     252             :   // Draw result to the screen
     253             :   // Called once at the end of the query
     254             : 
     255           0 :   Printf("Terminate called: fESD = %p", fESD);
     256             : 
     257           0 :   fListOut = dynamic_cast<TList*> (GetOutputData(0)); 
     258             : 
     259           0 :   if (fListOut) {
     260           0 :     fHistPt = dynamic_cast<TH1F*>(fListOut->FindObject("fHistPt")); 
     261           0 :     if (!fHistPt) {
     262           0 :       Printf("ERROR: fHistPt not available");
     263           0 :       return;
     264             :     }
     265             :    
     266           0 :     TCanvas *c1 = new TCanvas("AliAnalysisTaskPt","Pt",10,10,510,510);
     267           0 :     c1->cd(1)->SetLogy();
     268           0 :     fHistPt->DrawCopy("E");
     269           0 :   }
     270             :   else {
     271           0 :     Printf("In Terminate: no TList found");
     272             :   }
     273             : 
     274           0 : }

Generated by: LCOV version 1.11