adaptation for HLT transition from standalone code to aliroot module, selection of...
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorHLT.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  This class creates and fills the monitor histograms for the HLT          //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25 #include "AliMonitorHLT.h"
26 #include "AliMonitorTrend.h"
27 #include "AliTPCParam.h"
28 #include <TFolder.h>
29 #include <stdlib.h>
30 #include "AliL3MemHandler.h"
31 #include "AliL3SpacePointData.h"
32 #include "AliL3TrackArray.h"
33 #include "AliL3Track.h"
34 #include "AliL3Transform.h"
35 #include "AliL3Vertex.h"
36
37 //_____________________________________________________________________________
38 AliMonitorHLT::AliMonitorHLT(AliTPCParam* param)
39 {
40 // create a HLT monitor object with the given parameters
41
42   fParam = param;
43 }
44
45 //_____________________________________________________________________________
46 AliMonitorHLT::AliMonitorHLT(const AliMonitorHLT& monitor) :
47   AliMonitor(monitor)
48 {
49   Fatal("AliMonitorHLT", "copy constructor not implemented");
50 }
51
52 //_____________________________________________________________________________
53 AliMonitorHLT& AliMonitorHLT::operator = (const AliMonitorHLT& /*monitor*/)
54 {
55   Fatal("operator =", "assignment operator not implemented");
56   return *this;
57 }
58
59
60 //_____________________________________________________________________________
61 void AliMonitorHLT::CreateHistos(TFolder* folder)
62 {
63 // create the HLT monitor histograms
64
65   fFolder = folder->AddFolder("HLT", "HLT");
66
67   fClustersCharge = CreateHisto1("ClustersCharge", 
68                                  "charge distribution of clusters", 
69                                  100, 0, 1000, "charge", "#Delta N/N",
70                                  AliMonitorHisto::kNormEvents);
71
72   Int_t nRows = fParam->GetNRowLow() + fParam->GetNRowUp();
73   fNClustersVsRow = CreateHisto1("NClustersVsRow", 
74                                  "mean number of clusters per pad row", 
75                                  nRows, -0.5, nRows-0.5,
76                                  "pad row", "<N_{clusters}>",
77                                  AliMonitorHisto::kNormEvents);
78
79   Int_t nSector = fParam->GetNInnerSector();
80   fNClustersVsSector = CreateHisto1("NClustersVsSector", 
81                                     "mean number of clusters per sector", 
82                                     nSector, -0.5, nSector-0.5, 
83                                     "sector", "<N_{clusters}>",
84                                     AliMonitorHisto::kNormEvents);
85
86   fNTracks = CreateTrend("NTracks", "number of tracks per event", 
87                          "N_{tracks}");
88
89   fTrackPt = CreateHisto1("TrackPt", "pt distribution of tracks", 
90                           90, 0, 3, "p_{t} [GeV/c]", "#Delta N/N",
91                           AliMonitorHisto::kNormNone);
92
93   fTrackEta = CreateHisto1("TrackEta", "eta distribution of tracks", 
94                            100, -2, 2, "#eta", "#Delta N/N",
95                            AliMonitorHisto::kNormEntries);
96
97   fTrackPhi = CreateHisto1("TrackPhi", "phi distribution of tracks", 
98                            120, 0, 360, "#phi [#circ]", "#Delta N/N",
99                            AliMonitorHisto::kNormEntries);
100
101   fTrackNHits = CreateHisto1("TrackNHits", "Number of hits per track", 
102                            200, 0, 200, "N_{hits}", "#Delta N/N",
103                            AliMonitorHisto::kNormNone);
104
105   fTrackXYvsNHits = CreateHisto2("TrackXYvsNHits", "XY vs Number of hits per track", 
106                                  50, 0, 200,50,0,10,
107                                  "N_{hits}","Radius [cm]","#Delta N/N",
108                                  AliMonitorHisto::kNormNone);
109
110   fTrackZvsNHits = CreateHisto2("TrackZvsNHits", "Z vs Number of hits per track", 
111                                  50, 0, 200,50,-20,20,
112                                  "N_{hits}","Z [cm]","#Delta N/N",
113                                  AliMonitorHisto::kNormNone);
114
115   fTrackDEdxVsP = CreateHisto2("TrackDEdxVsP", "dE/dx of tracks", 
116                                100, 0, 3, 100, 0, 1000, 
117                                "p [GeV/c]", "dE/dx", "#Delta N/N",
118                                AliMonitorHisto::kNormEntries);
119
120   fTrackDEdx = CreateHisto1("TrackDEdx", "dE/dx for tracks with 0.4<p<1.0 GeV/c", 
121                                50, 0, 300, 
122                                "dE/dx", "#Delta N/N",
123                                AliMonitorHisto::kNormEntries);
124
125   fTrackDz0 = CreateHisto1("TrackDz0", "Dz0 of tracks", 
126                            100, -100, 100, "#Delta z0 [cm]", "#Delta N/N",
127                            AliMonitorHisto::kNormEntries);
128
129   fTrackDr0 = CreateHisto1("TrackDr0", "Dr0 of tracks", 
130                            130, 80, 250, "#Delta r0 [cm]", "#Delta N/N",
131                            AliMonitorHisto::kNormEntries);
132
133   fTrackEtaVsPhi = CreateHisto2("TrackEtaVsPhi", "#phi vs #eta", 
134                                20, -1, 1, 25, 0, 360, 
135                                "#eta", "#phi", "#Delta N/N",
136                                AliMonitorHisto::kNormNone);
137
138   fPtEtaVsPhi = CreateHisto2("PtEtaVsPhi", "#phi vs #eta", 
139                                20, -1, 1, 25, 0, 360, 
140                                "#eta", "#phi", "#Delta N/N",
141                                AliMonitorHisto::kNormNone);
142
143 }
144
145
146 //_____________________________________________________________________________
147 void AliMonitorHLT::FillHistos(AliRunLoader* /*runLoader*/, 
148                                AliRawReader* /*rawReader*/, AliESD* /*esd*/)
149 {
150 // fill the HLT monitor histogrms
151
152   AliL3MemHandler clusterHandler[36];
153   AliL3SpacePointData *clusters[36];
154   for (Int_t iSector = 0; iSector < fParam->GetNInnerSector(); iSector++) {
155     char fileName[256];
156     sprintf(fileName, "hlt/points_%d_-1.raw", iSector);
157     if (!clusterHandler[iSector].SetBinaryInput(fileName)) {
158       Warning("FillHistos", "could not open file %s", fileName);
159       continue;
160     }
161     clusters[iSector] = (AliL3SpacePointData*) clusterHandler[iSector].Allocate();
162     UInt_t nClusters = 0;
163     clusterHandler[iSector].Binary2Memory(nClusters, clusters[iSector]);
164
165     for (UInt_t iCluster = 0; iCluster < nClusters; iCluster++) {
166       AliL3SpacePointData& cluster = clusters[iSector][iCluster];
167       fClustersCharge->Fill(cluster.fCharge);
168       fNClustersVsRow->Fill(cluster.fPadRow);
169       fNClustersVsSector->Fill(iSector);
170     }
171
172     clusterHandler[iSector].CloseBinaryInput();
173   }
174
175   fNClustersVsSector->ScaleErrorBy(10.);
176
177   AliL3MemHandler memHandler;
178   if (!memHandler.SetBinaryInput("hlt/tracks.raw")) {
179     Warning("FillHistos", "could not open file hlt/tracks.raw");
180     return;
181   }
182   AliL3TrackArray* tracks = new AliL3TrackArray;
183   memHandler.Binary2TrackArray(tracks);
184   Double_t xc,yc,zc;
185   AliL3Vertex vertex;
186
187   fNTracks->Fill(tracks->GetNTracks());
188   for (Int_t iTrack = 0; iTrack < tracks->GetNTracks(); iTrack++) {
189     AliL3Track* track = tracks->GetCheckedTrack(iTrack);
190     if(!track) continue;
191     track->CalculateHelix();
192     track->GetClosestPoint(&vertex,xc,yc,zc);
193     if(fabs(zc)>10.) continue;
194     fTrackPt->Fill(track->GetPt());
195     fTrackEta->Fill(track->GetPseudoRapidity());
196     fTrackPhi->Fill(track->GetPsi() * TMath::RadToDeg());
197     if(track->GetPt()>3.) {
198       fTrackEtaVsPhi->Fill(track->GetPseudoRapidity(),track->GetPsi() * TMath::RadToDeg());
199       fPtEtaVsPhi->Fill(track->GetPseudoRapidity(),track->GetPsi() * TMath::RadToDeg(),track->GetPt());
200     }
201     fTrackDz0->Fill(track->GetZ0());
202     fTrackDr0->Fill(track->GetR0());
203     fTrackNHits->Fill(track->GetNHits());
204     fTrackXYvsNHits->Fill(track->GetNHits(),TMath::Sqrt(xc*xc+yc*yc));
205     fTrackZvsNHits->Fill(track->GetNHits(),zc);
206
207     // Track dEdx
208     Int_t nc=track->GetNHits();
209     UInt_t *hits = track->GetHitNumbers();
210     Float_t sampleDEdx[159];
211     for (Int_t iHit = 0; iHit < nc; iHit++) {
212       UInt_t hitID = hits[iHit];
213       Int_t iSector = (hitID>>25) & 0x7f;
214       UInt_t position = hitID&0x3fffff;
215       UChar_t padrow = clusters[iSector][position].fPadRow;
216       Float_t pWidth = AliL3Transform::GetPadPitchWidthLow();
217       if (padrow>63)
218         pWidth = AliL3Transform::GetPadPitchWidthUp(); 
219       Float_t corr=1.; if (padrow>63) corr=0.67;
220       sampleDEdx[iHit] = clusters[iSector][position].fCharge/pWidth*corr;
221       Double_t crossingangle = track->GetCrossingAngle(padrow,iSector);
222       Double_t s = sin(crossingangle);
223       Double_t t = track->GetTgl();
224       sampleDEdx[iHit] *= TMath::Sqrt((1-s*s)/(1+t*t));
225     }
226
227     /* Cook dEdx */
228     Int_t i;
229     Int_t swap;//stupid sorting
230     do {
231       swap=0;
232       for (i=0; i<nc-1; i++) {
233         if (sampleDEdx[i]<=sampleDEdx[i+1]) continue;
234         Float_t tmp=sampleDEdx[i];
235         sampleDEdx[i]=sampleDEdx[i+1]; sampleDEdx[i+1]=tmp;
236         swap++;
237       }
238     } while (swap);
239
240     Double_t low=0.05; Double_t up=0.7;
241     Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
242     Float_t trackDEdx=0;
243     for (i=nl; i<=nu; i++) trackDEdx += sampleDEdx[i];
244     trackDEdx /= (nu-nl+1);
245
246     fTrackDEdxVsP->Fill(track->GetP(),trackDEdx);
247     if(track->GetP()>0.4 && track->GetP()<1.0)
248       fTrackDEdx->Fill(trackDEdx);
249   }
250
251   delete tracks;
252   memHandler.CloseBinaryInput();
253 }