LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTSpacePointContainer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 218 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 31 3.2 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the ALICE HLT Project        * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       8             : //*                  for The ALICE HLT Project.                            *
       9             : //*                                                                        *
      10             : //* Permission to use, copy, modify and distribute this software and its   *
      11             : //* documentation strictly for non-commercial purposes is hereby granted   *
      12             : //* without fee, provided that the above copyright notice appears in all   *
      13             : //* copies and that both the copyright notice and this permission notice   *
      14             : //* appear in the supporting documentation. The authors make no claims     *
      15             : //* about the suitability of this software for any purpose. It is          *
      16             : //* provided "as is" without express or implied warranty.                  *
      17             : //**************************************************************************
      18             : 
      19             : /// @file   AliHLTSpacePointContainer.cxx
      20             : /// @author Matthias Richter
      21             : /// @date   2011-04-29
      22             : /// @brief  Base helper class for handling of HLT space point data blocks
      23             : ///
      24             : 
      25             : #include "AliHLTSpacePointContainer.h"
      26             : #include "AliHLTComponent.h"
      27             : #include "TFile.h"
      28             : #include "TString.h"
      29             : #include "TArrayC.h"
      30             : #include "TObjArray.h"
      31             : #include "TH2F.h"
      32             : #include "TMath.h"
      33             : #include "TMarker.h"
      34             : #include "TTree.h"
      35             : #include <memory>
      36             : #include <algorithm>
      37             : #include <iostream>
      38             : #include <iomanip>
      39             : 
      40             : /** ROOT macro for the implementation of ROOT specific class methods */
      41         126 : ClassImp(AliHLTSpacePointContainer)
      42             : 
      43             : AliHLTSpacePointContainer::AliHLTSpacePointContainer()
      44           0 :   : TObject(), AliHLTLogging()
      45           0 :   , fBuffers()
      46           0 : {
      47             :   // see header file for class documentation
      48             :   // or
      49             :   // refer to README to build package
      50             :   // or
      51             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      52           0 : }
      53             : 
      54             : AliHLTSpacePointContainer::AliHLTSpacePointContainer(const AliHLTSpacePointContainer& c)
      55           0 :   : TObject(c), AliHLTLogging()
      56           0 :   , fBuffers()
      57           0 : {
      58             :   /// copy constructor
      59             : 
      60             :   // currently no need to copy or allocate, the fBuffers of the source object are expected
      61             :   // to be persistent throughout the lifetime of the new object. Only pointers are copied.
      62           0 : }
      63             : 
      64             : AliHLTSpacePointContainer& AliHLTSpacePointContainer::operator=(const AliHLTSpacePointContainer& c)
      65             : {
      66             :   /// assignment operator
      67             :   if (&c==this) return *this;
      68             : 
      69             :   // currently no need to copy or allocate
      70             :   return *this;
      71           0 : }
      72             : 
      73           0 : AliHLTSpacePointContainer::~AliHLTSpacePointContainer()
      74           0 : {
      75             :   // destructor
      76           0 :   Clear();
      77           0 : }
      78             : 
      79             : void AliHLTSpacePointContainer::Clear(Option_t * /*option*/)
      80             : {
      81             :   // internal cleanup
      82           0 :   vector<TArrayC*>::iterator element=fBuffers.begin();
      83           0 :   while (element!=fBuffers.end()) {
      84           0 :     TArrayC* pBuffer=*element;
      85           0 :     element=fBuffers.erase(element);
      86           0 :     delete pBuffer;
      87             :   }
      88           0 : }
      89             : 
      90             : void AliHLTSpacePointContainer::Print(Option_t *option) const
      91             : {
      92             :   // print info
      93           0 :   Print(cout, option);
      94           0 : }
      95             : 
      96             : void AliHLTSpacePointContainer::Print(ostream& out, Option_t */*option*/) const
      97             : {
      98             :   // print to stream
      99           0 :   out << "AliHLTSpacePointContainer::Print" << endl;
     100           0 : }
     101             : 
     102             : int AliHLTSpacePointContainer::AddInputBlock(const char* filename, AliHLTComponentDataType dt, unsigned specification)
     103             : {
     104             :   // open block from file and add to collection
     105           0 :   if (!filename) return -EINVAL;
     106             :   
     107           0 :   TString input=filename;
     108           0 :   input+="?filetype=raw";
     109           0 :   std::auto_ptr<TFile> pFile(new TFile(input));
     110           0 :   if (!pFile.get()) return -ENOMEM;
     111           0 :   if (pFile->IsZombie()) return -ENOENT;
     112             : 
     113             :   int iResult=0;
     114           0 :   pFile->Seek(0);
     115           0 :   std::auto_ptr<TArrayC> buffer(new TArrayC);
     116           0 :   if (!buffer.get()) return -ENOMEM;
     117             : 
     118           0 :   buffer->Set(pFile->GetSize());
     119           0 :   if (pFile->ReadBuffer(buffer->GetArray(), buffer->GetSize())==0) {
     120           0 :     AliHLTComponentBlockData bd;
     121           0 :     AliHLTComponent::FillBlockData(bd);
     122           0 :     bd.fPtr=buffer->GetArray();
     123           0 :     bd.fSize=buffer->GetSize();
     124           0 :     bd.fDataType=dt;
     125           0 :     bd.fSpecification=specification;
     126             :     HLTDebug("adding data block %d byte(s) from file %s", pFile->GetSize(), filename);
     127           0 :     iResult=AddInputBlock(&bd);
     128           0 :   } else {
     129           0 :     HLTError("failed reading %d byte(s) from file %s", pFile->GetSize(), filename);
     130             :     iResult=-ENODATA;
     131             :   }
     132             : 
     133           0 :   fBuffers.push_back(buffer.release());
     134           0 :   return iResult;
     135           0 : }
     136             : 
     137             : int AliHLTSpacePointContainer::AddInputBlocks(const char* listfile, AliHLTComponentDataType dt)
     138             : {
     139             :   // open blank separated list of files and add data
     140           0 :   ifstream list(listfile);
     141           0 :   if (!list.good()) return -ENOENT;
     142             : 
     143             :   int count=0;
     144           0 :   TString file;
     145           0 :   while (file.ReadLine(list)) {
     146           0 :     HLTInfo("adding data from file %s", file.Data());
     147           0 :     int iResult=AddInputBlock(file.Data(), dt, kAliHLTVoidDataSpec);
     148           0 :     if (iResult<0) {
     149           0 :       HLTInfo("failed to add data from file %s: error %d", file.Data(), iResult);
     150           0 :       return iResult;
     151             :     }
     152           0 :     count+=iResult;
     153           0 :   }
     154             : 
     155             :   // std::auto_ptr<TObjArray> tokens(files.Tokenize(" "));
     156             :   // if (!tokens.get()) return 0;
     157             :   // for (int i=0; i<tokens->GetEntriesFast(); i++) {
     158             :   //   if (!tokens->At(i)) continue;
     159             :   //   cout << "adding data from file " << tokens->At(i)->GetName() << endl;
     160             :   //   AddInputBlock(tokens->At(i)->GetName(), dt, kAliHLTVoidDataSpec);
     161             :   // }
     162             : 
     163           0 :   return count;
     164           0 : }
     165             : 
     166             : AliHLTUInt8_t* AliHLTSpacePointContainer::Alloc(int size)
     167             : {
     168             :   /// alloc memory for a space point data block
     169           0 :   TArrayC* buffer=new TArrayC;
     170           0 :   if (!buffer) return NULL;
     171             : 
     172           0 :   buffer->Set(size);
     173           0 :   fBuffers.push_back(buffer);
     174           0 :   return reinterpret_cast<AliHLTUInt8_t*>(buffer->GetArray());
     175           0 : }
     176             : 
     177             : AliHLTSpacePointContainer* AliHLTSpacePointContainer::SelectByMask(AliHLTUInt32_t /*mask*/, bool /*bAlloc*/) const
     178             : {
     179             :   /// create a collection of clusters for a space point mask
     180             :   /// default implementation, nothing to do
     181           0 :   return NULL;
     182             : }
     183             : 
     184             : AliHLTSpacePointContainer* AliHLTSpacePointContainer::SelectByTrack(int /*trackId*/, bool /*bAlloc*/) const
     185             : {
     186             :   /// create a collection of clusters for a specific track
     187             :   /// default implementation, nothing to do
     188           0 :   return NULL;
     189             : }
     190             : 
     191             : AliHLTSpacePointContainer* AliHLTSpacePointContainer::SelectByMC(int /*mcId*/, bool /*bAlloc*/) const
     192             : {
     193             :   /// create a collection of clusters for a specific MC track
     194             :   /// default implementation, nothing to do
     195           0 :   return NULL;
     196             : }
     197             : 
     198             : AliHLTSpacePointContainer* AliHLTSpacePointContainer::UsedClusters(bool /*bAlloc*/) const
     199             : {
     200             :   /// create a collection of all used clusters
     201             :   /// default implementation, nothing to do
     202           0 :   return NULL;
     203             : }
     204             : 
     205             : AliHLTSpacePointContainer* AliHLTSpacePointContainer::UnusedClusters(bool /*bAlloc*/) const
     206             : {
     207             :   /// create a collection of all unused clusters
     208             :   /// default implementation, nothing to do
     209           0 :   return NULL;
     210             : }
     211             : 
     212             : int AliHLTSpacePointContainer::MarkUsed(const AliHLTUInt32_t* /*clusterIDs*/, int /*arraySize*/)
     213             : {
     214             :   /// default implementation, nothing to do
     215           0 :   return -ENOSYS;
     216             : }
     217             : 
     218             : int AliHLTSpacePointContainer::SetTrackID(int /*trackID*/, const AliHLTUInt32_t* /*clusterIDs*/, int /*arraySize*/)
     219             : {
     220             :   /// default implementation, nothing to do
     221           0 :   return -ENOSYS;
     222             : }
     223             : 
     224             : int AliHLTSpacePointContainer::SetMCID(int /*mcID*/, const AliHLTUInt32_t* /*clusterIDs*/, int /*arraySize*/)
     225             : {
     226             :   /// default implementation, nothing to do
     227           0 :   return -ENOSYS;
     228             : }
     229             : 
     230             : int AliHLTSpacePointContainer::GetNumberOfSpacePoints() const
     231             : {
     232             :   // get number of space points
     233           0 :   vector<AliHLTUInt32_t> clusterIDs;
     234           0 :   if (GetClusterIDs(clusterIDs)<0) return 0;
     235           0 :   return clusterIDs.size();
     236           0 : }
     237             : 
     238             : bool AliHLTSpacePointContainer::Check(AliHLTUInt32_t id) const
     239             : {
     240             :   // check if space point exists
     241           0 :   vector<AliHLTUInt32_t> clusterIDs;
     242           0 :   if (GetClusterIDs(clusterIDs)<0) return false;
     243           0 :   return find(clusterIDs.begin(), clusterIDs.end(), id)!=clusterIDs.end();
     244           0 : }
     245             : 
     246             : TH1* AliHLTSpacePointContainer::DrawProjection(const char* plane, const vector<AliHLTUInt32_t>& selection) const
     247             : {
     248             :   // draw the projection of space points in a specified plane
     249             :   // "xy", "xz", "yz"
     250             :   
     251             :   int mode=0;
     252           0 :   if (strcmp(plane, "xy")==0) mode=0;
     253           0 :   else if (strcmp(plane, "xz")==0) mode=1;
     254           0 :   else if (strcmp(plane, "yz")==0) mode=2;
     255             :   else {
     256           0 :     HLTError("invalid plane specification %s, allowed 'xy', 'xz', 'yz'", plane);
     257           0 :     return NULL;
     258             :   }
     259             :   
     260             :   float maxXAxis=100.0;
     261             :   float maxYAxis=100.0;
     262           0 :   vector<AliHLTUInt32_t> clusterIDs;
     263           0 :   GetClusterIDs(clusterIDs);
     264           0 :   vector<AliHLTUInt32_t>::iterator clusterID=clusterIDs.begin();
     265           0 :   while (clusterID!=clusterIDs.end()) {
     266           0 :     vector<AliHLTUInt32_t>::const_iterator element=selection.begin();
     267           0 :     for (; element!=selection.end(); element++) {
     268           0 :       if (((*element)&0xffff0000)==((*clusterID)&0xffff0000)) break;
     269             :     }
     270           0 :     if (element==selection.end() && selection.size()>0) {
     271           0 :       clusterID=clusterIDs.erase(clusterID);
     272           0 :       continue;
     273             :     }
     274             :     float XValue=0.0;
     275             :     float YValue=0.0;
     276           0 :     if (mode==0) {
     277           0 :       XValue=GetX(*clusterID);
     278           0 :       YValue=GetY(*clusterID);
     279           0 :     } else if (mode==1) {
     280           0 :       XValue=GetX(*clusterID);
     281           0 :       YValue=GetZ(*clusterID);
     282           0 :     } else if (mode==2) {
     283           0 :       XValue=GetY(*clusterID);
     284           0 :       YValue=GetZ(*clusterID);
     285           0 :     }
     286           0 :     if (maxXAxis<XValue) maxXAxis=XValue;
     287           0 :     if (maxYAxis<YValue) maxYAxis=YValue;
     288           0 :     clusterID++;
     289           0 :   }
     290           0 :   if (maxXAxis<maxYAxis) maxXAxis=maxYAxis;
     291             :   else maxYAxis=maxXAxis;
     292             : 
     293           0 :   TH2F* histogram=new TH2F(plane, plane, 1000, -maxXAxis, maxXAxis, 1000, -maxYAxis, maxYAxis);
     294           0 :   if (!histogram) return NULL;
     295           0 :     if (mode==0) {
     296           0 :       histogram->GetXaxis()->SetTitle("X [cm]");
     297           0 :       histogram->GetYaxis()->SetTitle("Y [cm]");
     298           0 :     } else if (mode==1) {
     299           0 :       histogram->GetXaxis()->SetTitle("Z [cm]");
     300           0 :       histogram->GetYaxis()->SetTitle("X [cm]");
     301           0 :     } else if (mode==2) {
     302           0 :       histogram->GetXaxis()->SetTitle("Z [cm]");
     303           0 :       histogram->GetYaxis()->SetTitle("Y [cm]");
     304             :     }
     305             : 
     306           0 :   for (clusterID=clusterIDs.begin(); clusterID!=clusterIDs.end(); clusterID++) {
     307           0 :     float XValue=GetX(*clusterID);
     308           0 :     float YValue=GetY(*clusterID);
     309           0 :     float ZValue=GetZ(*clusterID);
     310           0 :     Float_t phi     = GetPhi(*clusterID);
     311           0 :     Float_t cos     = TMath::Cos( phi );
     312           0 :     Float_t sin     = TMath::Sin( phi );
     313           0 :     if (mode==0) {
     314           0 :       histogram->SetTitle("XY projection");
     315           0 :       histogram->Fill(cos*XValue - sin*YValue, sin*XValue + cos*YValue);
     316           0 :     } else if (mode==1) {
     317             :       // should be maybe 'ZX' but somehow 'XZ' is more 'lingual convenient'
     318           0 :       histogram->SetTitle("XZ projection");
     319           0 :       histogram->Fill(ZValue, cos*XValue - sin*YValue);
     320           0 :     } else if (mode==2) {
     321             :       // same comment
     322           0 :       histogram->SetTitle("YZ projection");
     323           0 :       histogram->Fill(ZValue, sin*XValue + cos*YValue);
     324             :     }
     325             :   }
     326             : 
     327           0 :   return histogram;
     328           0 : }
     329             : 
     330             : void AliHLTSpacePointContainer::Draw(Option_t *option)
     331             : {
     332             :   /// Inherited from TObject, draw clusters
     333             :   float scale=250;
     334             :   float center[2]={0.5,0.5};
     335             :   int markersize=1;
     336             :   int markercolor=5;
     337             : 
     338           0 :   TString strOption(option);
     339           0 :   std::auto_ptr<TObjArray> tokens(strOption.Tokenize(" "));
     340           0 :   if (!tokens.get()) return;
     341           0 :   for (int i=0; i<tokens->GetEntriesFast(); i++) {
     342           0 :     if (!tokens->At(i)) continue;
     343             :     const char* key="";
     344           0 :     TString arg=tokens->At(i)->GetName();
     345             : 
     346             :     key="scale=";
     347           0 :     if (arg.BeginsWith(key)) {
     348           0 :       arg.ReplaceAll(key, "");
     349           0 :       scale=arg.Atof();
     350           0 :     }
     351             :     key="centerx=";
     352           0 :     if (arg.BeginsWith(key)) {
     353           0 :       arg.ReplaceAll(key, "");
     354           0 :       center[0]=arg.Atof();
     355           0 :     }
     356             :     key="centery=";
     357           0 :     if (arg.BeginsWith(key)) {
     358           0 :       arg.ReplaceAll(key, "");
     359           0 :       center[1]=arg.Atof();
     360           0 :     }
     361             :     key="markersize=";
     362           0 :     if (arg.BeginsWith(key)) {
     363           0 :       arg.ReplaceAll(key, "");
     364           0 :       markersize=arg.Atoi();
     365           0 :     }
     366             :     key="markercolor=";
     367           0 :     if (arg.BeginsWith(key)) {
     368           0 :       arg.ReplaceAll(key, "");
     369           0 :       markercolor=arg.Atoi();
     370           0 :     }
     371           0 :   }
     372             : 
     373           0 :   vector<AliHLTUInt32_t> clusterIDs;
     374           0 :   GetClusterIDs(clusterIDs);
     375           0 :   for (vector<AliHLTUInt32_t>::iterator clusterID=clusterIDs.begin();
     376           0 :        clusterID!=clusterIDs.end();
     377           0 :        clusterID++) {
     378           0 :     float clusterphi=GetPhi(*clusterID);
     379           0 :     float cosphi=TMath::Cos(clusterphi);
     380           0 :     float sinphi=TMath::Sin(clusterphi);
     381           0 :     float clusterx=GetX(*clusterID);
     382           0 :     float clustery=GetY(*clusterID);
     383             :     //cout << " " << *clusterID << " " << clusterx << " " << clustery << " " << clusterphi << endl;
     384             :     // rotate
     385           0 :     float pointx= clusterx*sinphi + clustery*cosphi;
     386           0 :     float pointy=-clusterx*cosphi + clustery*sinphi;
     387             : 
     388           0 :     TMarker* m=new TMarker(pointx/(2*scale)+center[0], pointy/(2*scale)+center[1], 3);
     389           0 :     m->SetMarkerSize(markersize);
     390           0 :     m->SetMarkerColor(markercolor);
     391           0 :     m->Draw("same");    
     392             :   }  
     393           0 : }
     394             : 
     395             : TTree* AliHLTSpacePointContainer::FillTree(const char* name, const char* title)
     396             : {
     397             :   // create tree and fill the space point coordinates
     398           0 :   TString treename=name;
     399           0 :   TString treetitle=title;
     400           0 :   if (treename.IsNull()) treename="spacepoints";
     401           0 :   if (treetitle.IsNull()) treetitle="HLT space point coordinates";
     402           0 :   std::auto_ptr<TTree> tree(new TTree(treename, treetitle));
     403           0 :   if (!tree.get()) return NULL;
     404             : 
     405             :   const unsigned dimension=8;
     406           0 :   float values[dimension];
     407           0 :   memset(values, 0, sizeof(values));
     408           0 :   const char* names[dimension]={
     409             :     "x", "y", "z", "sigmaY2", "sigmaZ2", "charge", "qmax", "alpha"
     410             :   };
     411             : 
     412           0 :   for (unsigned i=0; i<dimension; i++) {
     413           0 :     TString type=names[i]; type+="/F";
     414           0 :     tree->Branch(names[i], &values[i], type);
     415           0 :   }
     416             : 
     417           0 :   const vector<AliHLTUInt32_t>* clusterIDs=GetClusterIDs(0xffffffff);
     418           0 :   for (vector<AliHLTUInt32_t>::const_iterator clusterID=clusterIDs->begin();
     419           0 :        clusterID!=clusterIDs->end();
     420           0 :        clusterID++) {
     421             :     unsigned pos=0;
     422           0 :     values[pos++]=GetX(*clusterID);
     423           0 :     values[pos++]=GetY(*clusterID);
     424           0 :     values[pos++]=GetZ(*clusterID);
     425           0 :     values[pos++]=GetYWidth(*clusterID);
     426           0 :     values[pos++]=GetZWidth(*clusterID);
     427           0 :     values[pos++]=GetCharge(*clusterID);
     428           0 :     values[pos++]=GetMaxSignal(*clusterID);
     429           0 :     values[pos++]=GetPhi(*clusterID);
     430             : 
     431           0 :     tree->Fill();
     432             :   }
     433             : 
     434           0 :   return tree.release();
     435           0 : }
     436             : 
     437             : ostream& operator<<(ostream &out, const AliHLTSpacePointContainer& c)
     438             : {
     439           0 :   c.Print(out);
     440           0 :   return out;
     441             : }
     442             : 
     443             : ostream& operator<<(ostream &out, const AliHLTSpacePointContainer::AliHLTSpacePointProperties& p)
     444             : {
     445             :   // print
     446           0 :   cout << p.fId;
     447           0 :   return out;
     448             : }
     449             : 
     450             : bool operator==(const AliHLTSpacePointContainer::AliHLTSpacePointProperties& a,
     451             :                 const AliHLTSpacePointContainer::AliHLTSpacePointProperties& b) {
     452           0 :   return a.fId==b.fId;
     453             : }

Generated by: LCOV version 1.11