All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
anaPix.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 #include "anaPix.h"
3 #include "FPCCDPixelHit.h"
4 #include "FPCCDData.h"
5 
6 #include <iostream>
7 
8 #include <EVENT/LCCollection.h>
9 #include <IMPL/LCCollectionVec.h>
10 #include <EVENT/MCParticle.h>
11 #include <IMPL/TrackerHitImpl.h>
12 #include <gear/VXDParameters.h>
13 #include <gear/VXDLayerLayout.h>
14 
15 #include <cmath>
16 #include <algorithm>
17 #include <sstream>
18 #include <map>
19 #include <vector>
20 #include <TFile.h>
21 #include <TTree.h>
22 
23 using namespace lcio ;
24 using namespace marlin ;
25 using namespace std ;
26 
27 static int g_event = 0;
28 static double g_x = 0.;
29 static double g_y = 0.;
30 static double g_z = 0.;
31 static int g_layer = 0;
32 static int g_ladder = 0;
33 static double g_zeta = 0.;
34 static double g_xi = 0.;
35 static double g_zeta2 = 0.;
36 static double g_xi2 = 0.;
37 static double g_dE = 0.;
38 static double g_digi_dE = 0.;
39 static int g_quality = 0;
40 static int g_nparents = 0;
41 
43 
44 // =====================================================================
45 anaPix::anaPix() : Processor("anaPix") {
46 
47  // modify processor description
48  _description = "anaPix icteats TTree from FPCCDPixelHits" ;
49 
50  // register steering parameters: name, description, class-variable, default value
51  FloatVec PixelSizeVec; // This is a temporary variable. Each ladder's PixelSize are different.
52  for(int i=0;i<6;i++){PixelSizeVec.push_back(0.005);}
53 
54  registerProcessorParameter( "Each_FPCCD_pixelSize(mm)",
55  "Each ladder's Pixel size of FPCCD (unit:mm) (default:0.005)",
57  PixelSizeVec );
58 
59  registerProcessorParameter( "FPCCD_PixelSize" ,
60  "Pixel size of FPCCD (unit:mm) (default: 0.005)",
61  _pixelSize,
62  float(0.0050) ) ;
63  /*
64  registerProcessorParameter( "PointResolutionRPhi" ,
65  "R-Phi Resolution in VTX" ,
66  _pointResoRPhi ,
67  float(0.001440)) ; // 5/sqrt(12)
68 
69  registerProcessorParameter( "PointResolutionZ" ,
70  "Z Resolution in VTX" ,
71  _pointResoZ ,
72  float(0.001440)); // 5/sqrt(12)
73 */
74 
75  registerProcessorParameter( "OutputROOTfileName" ,
76  "Name of output ROOT file" ,
78  std::string( "./pixel.root" ));
79 
80 
81 
82  // Input collections
83  registerInputCollection( LCIO::LCGENERICOBJECT,
84  "VTXPixelHitCollection" ,
85  "Name of the VTX PixelHit collection" ,
86  _colNameVTX ,
87  std::string("VTXPixelHits") ) ;
88 }
89 
90 
91 // =====================================================================
92 void anaPix::init() {
93 
94  // usually a good idea to
95  printParameters() ;
96 
97  _nRun = 0 ;
98  _nEvt = 0 ;
99 
100  InitGeometry();
101 
102  outroot = new TFile(_rootFileName.c_str(),"RECREATE");
103 
104  //hTreePix = new TTree("hTreePix","");
105  hTreePix = new TTree("t","");
106  hTreePix->Branch("event", &g_event, "event/I");
107  hTreePix->Branch("x", &g_x, "x/D");
108  hTreePix->Branch("y", &g_y, "y/D");
109  hTreePix->Branch("z", &g_z, "z/D");
110  hTreePix->Branch("layer", &g_layer, "layer/I");
111  hTreePix->Branch("ladder", &g_ladder, "ladder/I");
112  hTreePix->Branch("dE", &g_dE, "dE/D");
113  hTreePix->Branch("digi_dE", &g_digi_dE, "digi_dE/D");
114  hTreePix->Branch("quality", &g_quality, "quality/I");
115  hTreePix->Branch("multiplicity", &g_nparents, "multiplicity/I");
116  hTreePix->Branch("xi", &g_xi, "xi/D");
117  hTreePix->Branch("zeta", &g_zeta,"zeta/D");
118  hTreePix->Branch("xi2", &g_xi2, "xi2/D");
119  hTreePix->Branch("zeta2", &g_zeta2,"zeta2/D");
120  /*
121  hTreeLocalPix = new TTree("hTreeLocalPix","");
122  hTreeLocalPix->Branch("event", &g_event, "event/I");
123  hTreeLocalPix->Branch("zeta", &g_zeta,"zeta/D");
124  hTreeLocalPix->Branch("xi", &g_xi, "xi/D");
125  hTreeLocalPix->Branch("layer", &g_layer, "layer/I");
126  hTreeLocalPix->Branch("ladder", &g_ladder, "ladder/I");
127  hTreeLocalPix->Branch("dE", &g_dE, "dE/D");
128  hTreeLocalPix->Branch("quality", &g_quality, "quality/I");
129  */
130 }
131 
132 // =====================================================================
134 {
135 // Save frequently used parameters.
136 
137  const gear::VXDParameters &gearVXD = Global::GEAR->getVXDParameters();
138  const gear::VXDLayerLayout &layerVXD=gearVXD.getVXDLayerLayout();
139 
140  _nLayer = layerVXD.getNLayers() ;
141  _geodata.resize(_nLayer);
142  _maxLadder = 0;
143 
144  for(int ly=0;ly<_nLayer;ly++){
145  _geodata[ly].nladder=layerVXD.getNLadders(ly); // Number of ladders in this layer
146  if( _maxLadder < _geodata[ly].nladder ) { _maxLadder=_geodata[ly].nladder; }
147  _geodata[ly].rmin=layerVXD.getSensitiveDistance(ly); // Distance of sensitive area from IP
148  _geodata[ly].dphi=(2*M_PI)/(double)_geodata[ly].nladder;
149  _geodata[ly].phi0=layerVXD.getPhi0(ly); // phi offset.
150  _geodata[ly].sthick=layerVXD.getSensitiveThickness(ly);
151  _geodata[ly].sximin=-layerVXD.getSensitiveOffset(ly)
152  -layerVXD.getSensitiveWidth(ly)/2.0;
153  _geodata[ly].sximax=-layerVXD.getSensitiveOffset(ly)
154  +layerVXD.getSensitiveWidth(ly)/2.0;
155  _geodata[ly].hlength=layerVXD.getSensitiveLength(ly);
156  _geodata[ly].cosphi.resize( _geodata[ly].nladder ) ;
157  _geodata[ly].sinphi.resize( _geodata[ly].nladder ) ;
158  for(int ld=0;ld<_geodata[ly].nladder;ld++) {
159  double phi=_geodata[ly].phi0 + _geodata[ly].dphi*ld;
160  _geodata[ly].cosphi[ld]=cos(phi);
161  _geodata[ly].sinphi[ld]=sin(phi);
162  }
163  }
164 }
165 
166 
167 // =====================================================================
168 void anaPix::processRunHeader( LCRunHeader* /*run*/) {
169  _nRun++ ;
170 }
171 
172 // =====================================================================
173 void anaPix::processEvent( LCEvent * evt )
174 {
175  LCCollection* pHitCol=0;
176  try {
177  pHitCol=evt->getCollection( _colNameVTX ) ;
178  }
179  catch(DataNotAvailableException &e){
180  if (_debug == 1) {
181  std::cout << "Collection " << _colNameVTX.c_str() << " is unavailable in event "
182  << _nEvt << std::endl;
183  }
184  }
185  if( _debug == 1 ) {
186  std::cout << " Collection =" << _colNameVTX << " nevt=" << _nEvt << std::endl;
187  std::cout << " number of elements is " << pHitCol->getNumberOfElements() << std::endl;
188  }
189  if( pHitCol != 0 ){
190  FPCCDData theData(_nLayer, _maxLadder); // prepare object to make pixelhits
191  int nhit = theData.unpackPixelHits(*pHitCol);
192  if( _debug == 1 ) { theData.dump(); }
193  if( nhit > 0 ) { // Output Trackhit, if there are pixel hits
194  g_event = _nEvt;
195  fillTTree(theData);
196  }
197  } // End of process when VXD has hits
198  _nEvt ++ ;
199 }
200 
201 // ====================================================================
202 void anaPix::fillTTree(FPCCDData &pHitCol) {
203 
204 // Convert pixel hits to TrackerHits
205 
206  for(int layer=0;layer<_nLayer;layer++){
207  int nladder=_geodata[layer].nladder; // Number of ladders in this layer
208  double rmin=_geodata[layer].rmin; // Distance of sensitive area from IP
209  double sthick=_geodata[layer].sthick;
210  double sximin=_geodata[layer].sximin;
211  for(int ladder=0;ladder<nladder;ladder++){
212  PixelHitMap_t::iterator it=pHitCol.itBegin(layer, ladder);
213  while( it != pHitCol.itEnd(layer, ladder) ) {
214  FPCCDPixelHit *aHit=(*it).second;
215  int xiID=aHit->getXiID();
216  int zetaID=aHit->getZetaID();
217  int quality = aHit->getQuality();
218  int nparents = aHit->getNMCParticles();
219  double Edep = aHit->getEdep();
220  double eta=sthick*0.5;
221  _pixelSize = _pixelSizeVec[layer];
222  double xi=(xiID+0.5)*_pixelSize;
223  double newpos[3];
224  g_zeta = (zetaID+0.5)*_pixelSize;
225  g_xi = xi;
226  g_layer = layer;
227  g_ladder = ladder;
228  g_dE = Edep;
229  //mori added//////(cf. FPCCDClustering)////////////////////
230  double electronsPerKeV = 276.;
231  int electronsPerStep = 25;
232  int nbitsForEdep = 7;
233  int nEle = static_cast<int>(g_dE * 1e+06 * electronsPerKeV) ;
234  int nStep = 1 << nbitsForEdep ;
235  int count = nEle/ electronsPerStep ;
236  if(count > nStep ) count = nStep ;
237  g_digi_dE = (count * electronsPerStep) * 1e-6 / electronsPerKeV ;
238  /////////////////////////////////////////////////////////////
239 
240 
241  g_quality = quality;
242  g_nparents = nparents;
243 
244  newpos[0]= (xi+sximin)*_geodata[layer].sinphi[ladder]
245  + (rmin+eta)*_geodata[layer].cosphi[ladder];
246  newpos[1]=-(xi+sximin)*_geodata[layer].cosphi[ladder]
247  + (rmin+eta)*_geodata[layer].sinphi[ladder];
248  newpos[2]=(zetaID+0.5)*_pixelSize-_geodata[layer].hlength;
249 
250  it++;
251 
252  g_x = newpos[0];
253  g_y = newpos[1];
254  g_z = newpos[2];
255 
256  //mori added (cf. FPCCDClustering)//////////////////////////////
257  double lpos[3];//xi,eta,zeta
258  double gpos[3];
259  gpos[0] =g_x;
260  gpos[1] =g_y;
261  gpos[2] =g_z;
262  int tlayer = layer;
263  int tladder = ladder;
264  double sinphi = _geodata[tlayer].sinphi[tladder];
265  double cosphi = _geodata[tlayer].cosphi[tladder];
266  lpos[0] = gpos[0] * sinphi - gpos[1] * cosphi + gpos[2] * 0;
267  lpos[1] = gpos[0] * cosphi + gpos[1] * sinphi + gpos[2] * 0;
268  lpos[2] = gpos[0] * 0 + gpos[1] * 0 + gpos[2] * 1;
269  g_xi2 = lpos[0];
270  g_zeta2 = lpos[2];
271  ////////////////////////////////////////////////////////////////////
272 
273  hTreePix->Fill();
274  //hTreeLocalPix->Fill();
275  }
276  }
277  }
278 }
279 
280 
281 // =====================================================================
282 void anaPix::check( LCEvent * /*evt*/ ) {
283  // nothing to check here - could be used to fill checkplots in reconstruction processor
284 }
285 
286 // =====================================================================
287 void anaPix::end(){
288  streamlog_out(MESSAGE) << " end() " << name()
289  << " processed " << _nEvt << " events in " << _nRun << " runs "
290  << std::endl ;
291  outroot->Write();
292 }
293 
int _nRun
Definition: anaPix.h:77
Definition: anaPix.h:37
int _nEvt
Definition: anaPix.h:78
std::string _colNameVTX
Definition: anaPix.h:75
static double g_zeta2
Definition: anaPix.cc:35
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
Definition: anaPix.cc:168
static double g_xi
Definition: anaPix.cc:34
void InitGeometry()
Definition: anaPix.cc:133
static double g_xi2
Definition: anaPix.cc:36
float _pixelSize
Definition: anaPix.h:81
static double g_digi_dE
Definition: anaPix.cc:38
FloatVec _pixelSizeVec
Definition: anaPix.h:80
static int g_layer
Definition: anaPix.cc:31
int _debug
Definition: anaPix.h:79
static double g_y
Definition: anaPix.cc:29
anaPix aanaPix
Definition: anaPix.cc:42
static int g_event
Definition: anaPix.cc:27
std::vector< GeoData_t > _geodata
Definition: anaPix.h:104
int _nLayer
Definition: anaPix.h:90
std::string _rootFileName
Definition: anaPix.h:84
static int g_quality
Definition: anaPix.cc:39
static const float e
TFile * outroot
Definition: anaPix.h:86
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Definition: anaPix.cc:173
anaPix()
Definition: anaPix.cc:45
static double g_z
Definition: anaPix.cc:30
virtual void check(LCEvent *evt)
Definition: anaPix.cc:282
virtual void init()
Called at the begin of the job before anything is read.
Definition: anaPix.cc:92
static double g_x
Definition: anaPix.cc:28
static int g_ladder
Definition: anaPix.cc:32
static double g_dE
Definition: anaPix.cc:37
int _maxLadder
Definition: anaPix.h:91
static double g_zeta
Definition: anaPix.cc:33
void fillTTree(FPCCDData &pxHits)
Definition: anaPix.cc:202
TTree * hTreePix
Definition: anaPix.h:87
virtual void end()
Called after data processing for clean up.
Definition: anaPix.cc:287
static int g_nparents
Definition: anaPix.cc:40