001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025 #include "TrackingUserMods/SiHitDropModule.hh"
026 #include "AbsEnv/AbsEnv.hh"
027 #include "GeometryBase/CdfDetector.hh"
028 #include "SiliconGeometry/AbsSiDetectorNode.hh"
029 #include "TrackingSI/ClusterFinding/SiClusterFinder.hh"
030
031 #include "TrackingSI/ClusterFinding/SiClusterCorrector.hh"
032 #include "TrackingObjects/SiData/SiClusterSet.hh"
033 #include "TrackingObjects/SiData/SiHitSet.hh"
034 #include "TrackingObjects/Storable/StorableRun2SiStripSet.hh"
035 #include "Edm/ConstHandle.hh"
036 #include "TrackingObjects/Tracks/CdfTrack.hh"
037 #include "TrackingObjects/Storable/CdfTrackColl.hh"
038 #include "TrackingUtils/Integrator/MaterialIntegrator.hh"
039 #include "TrackingSI/TrackFitting/SiTrackFitter.hh"
040 #include "TrackingSI/Integrator/SimpleSiliconIntegrator.hh"
041 #include "HepTuple/HepHBookFileManager.h"
042 #include "HepTuple/HepHBookNtuple.h"
043
044 #include "Extrapolator/G3XIntegrator.hh"
045
046 #include "TrackingUtils/Trybos/TRYGenPrimaryVertexSet.hh"
047 #include "TrackingUtils/GeneratorLevel/GenPrimaryVertex.hh"
048
049 #include "TrackingUserHL/Matching/HitContentTPAssociator.hh"
050
051
052
053
054
055
056
057
058
059
060
061 SiHitDropModule::SiHitDropModule(const char* const theName,
062 const char* const theDescription )
063 : HepHistModule( theName, theDescription ),_drop("drop",this,true),
064 _layer("layer",this,2),_side("side",this,2),_barrel("barrel",this,9),
065 _debug("debug",this,true),_scaleP("scaleP",this,1.0),_matInt("matInt",this,1)
066 {
067 _drop.addDescription("\tThis will let you choose to drop SiHits or not,if not, just do a refit");
068 commands()->append(&_drop);
069 _layer.addDescription("\tThis will let you choose to drop SiHits for which layer if you choose to drop");
070 commands()->append(&_layer);
071 _side.addDescription("\tThis will let you choose to drop SiHits on which side");
072 commands()->append(&_side);
073 _barrel.addDescription("\tThis will let you choose to drop which barrel.9--any barrel");
074 commands()->append(&_barrel);
075 _debug.addDescription("\tThis will let you make debug NTuples, Default: True");
076 commands()->append(&_debug);
077 _scaleP.addDescription("\tThis is the error scaling factor for precursor, Default: 1.0");
078 commands()->append(&_scaleP);
079 _matInt.addDescription("\tMaterial Integrator: 1: Simple, Else: GEANT, Default: 1");
080 commands()->append(&_matInt);
081
082
083 }
084
085
086
087 SiHitDropModule::~SiHitDropModule( )
088 {
089
090 }
091
092
093
094
095
096 AppResult SiHitDropModule:: beginJob(AbsEvent* aJob )
097 {
098
099 HepFileManager* manager = fileManager( );
100 assert( 0 != manager );
101
102 _ptDiffNtuple=&manager->ntuple("ptDiffNtuple");
103 _residNtuple=&manager->ntuple("residNtuple");
104
105
106 return AppResult::OK;
107 }
108
109 AppResult SiHitDropModule::beginRun( AbsEvent* aRun )
110 {
111
112 return AppResult::OK;
113 }
114
115 AppResult SiHitDropModule::endRun( AbsEvent* aRun )
116 {
117
118 return AppResult::OK;
119 }
120
121 AppResult SiHitDropModule::endJob( AbsEvent* aJob )
122 {
123
124 return AppResult::OK;
125 }
126
127 AppResult SiHitDropModule::abortJob( AbsEvent* aJob )
128 {
129
130 return AppResult::OK;
131 }
132
133
134 AppResult SiHitDropModule::event( AbsEvent* anEvent )
135 {
136
137
138 int nEvent = AbsEnv::instance()->trigNumber();
139 int nRun = AbsEnv::instance()->runNumber();
140
141 if (_debug.value()) {
142 std::cout <<std::endl;
143 std::cout << "SiHitDropModule::trigger # "
144 << std::setw(4) << nRun << "/" << std::setw(5) << nEvent
145 << std::endl;
146 }
147
148
149 Handle<CdfTrackColl> refittedTrackSet(new CdfTrackColl() );
150 refittedTrackSet->set_description("AbrigeTracks" );
151
152
153 CdfTrackView_h view_hndl;
154 CdfTrackView::Error trackStatus=CdfTrackView::defTracks(view_hndl);
155 const CdfTrackView::CollType & tracks=view_hndl->contents();
156
157 TRYGenPrimaryVertexSet gpvSet(*anEvent);
158 gpvSet.initializeFromObs();
159 if ( ! gpvSet.size()) gpvSet.initializeFromHepevt();
160 TPAssociator *anAssoc = new HitContentTPAssociator(&gpvSet,&*view_hndl);
161
162 for(CdfTrackView::const_iterator itrack=tracks.begin();
163 itrack!=tracks.end();++itrack)
164 {
165
166
167 if((*itrack)->numSIHits()==0 || (*itrack)->pt()<1.0 || (*itrack)->numSIHits()<6) continue;
168
169
170 const ParentedParticle *p = NULL;
171 if (anAssoc) p = anAssoc->match(**itrack);
172 int pid = (p) ? p->type() : 211;
173
174 std::vector<const SiHit *> dropedSIHit;
175
176 CdfTrack * myCopy=new CdfTrack(**itrack);
177
178
179
180
181
182
183
184
185
186
187
188 CdfTrack_clnk parent=myCopy->parent();
189 if(parent) {
190 while(parent->parent())
191 {
192 parent=parent->parent();
193
194 }
195 if(parent->numSIHits()!=0 || parent->numCTHits()==0)
196 std::cout<<"Something strange!"<<std::endl;
197 }
198
199
200
201 MaterialIntegrator* theMaterialIntegrator;
202 if (_matInt.value()==1) {
203 const AbsSiDetectorNode *siDetector =
204 CdfDetector::instance()->getSiDetector();
205 theMaterialIntegrator=new SimpleSiliconIntegrator(siDetector);
206 } else {
207 G3XIntegrator* theG3XIntegrator=new G3XIntegrator();
208 theG3XIntegrator->setParticle(pid);
209 theMaterialIntegrator=theG3XIntegrator;
210 }
211 SiTrackFitter siFitter(theMaterialIntegrator);
212 siFitter.setPrecursor(parent.operator->());
213 siFitter.setPrecursorErrorScale(_scaleP.value());
214
215
216
217 if (siFitter.fit(*myCopy)==TrackFitter::FAILED) {
218 std::cout<<"Track refit Failed!"<<std::endl;
219 continue;
220 }
221 if (_debug.value()) {
222 _ptDiffNtuple->column("nRun",nRun);
223 _ptDiffNtuple->column("nEvent",nEvent);
224 _ptDiffNtuple->column("algorithm",(*itrack)->algorithm().value());
225 _ptDiffNtuple->column("pt",(*itrack)->pt());
226 _ptDiffNtuple->column("ptFit",myCopy->pt());
227 _ptDiffNtuple->column("ptDiff",(*itrack)->pt()-myCopy->pt());
228 _ptDiffNtuple->column("ptDiffPercent",100.0*((*itrack)->pt()-myCopy->pt())/(*itrack)->pt());
229 _ptDiffNtuple->captureThenStore();
230
231 }
232
233
234 if(_drop.value()) {
235 for (CdfTrack::SiHitIterator h1=(*myCopy).beginSIHits();h1!=(*myCopy).endSIHits();++h1) {
236 if ((*h1)->getHalfLad()->getDetectorCode().getLayer()==_layer.value()
237 && (_side.value()==2 || _side.value()==(*h1)->nSideHit())
238 && (_barrel.value()==9 || _barrel.value()==(*h1)->getHalfLad()->getDetectorCode().getBarrel()) )
239 {
240
241
242
243
244
245
246
247 dropedSIHit.push_back(*h1);
248 myCopy->dropHit(*h1);
249 }
250 }
251 }
252
253
254
255 if (siFitter.fit(*myCopy)==TrackFitter::FAILED) {
256 std::cout<<"Track refit Failed!"<<std::endl;
257 continue;
258 }
259
260
261
262
263
264
265
266
267
268 myCopy->setAlgorithm( CdfTrack::NoSpecifiedAlg );
269
270
271 for(int i=0;i<dropedSIHit.size();i++)
272 {
273
274 myCopy->addHit(dropedSIHit[i]);
275
276
277
278
279 double resid;
280 SiDigiCode key;
281 const SiHit* hit=dropedSIHit[i];
282 key = hit->getHalfLad()->getDetectorCode();
283
284 if (hit->pSideHit()==1) key.setPnSide(0);
285 if (hit->pSideHit()==0) key.setPnSide(1);
286
287 HepVector3D PerpDir;
288 if (key.getPnSide()==0)
289 {
290 PerpDir = hit->getHalfLad()->getShortDirection();
291 }
292 if (key.getPnSide()==1)
293 {
294 if ((key.getLayer()==1)||(key.getLayer()==2)||
295 (key.getLayer()==4))
296 {
297 PerpDir = hit->getHalfLad()->getLongDirection();
298 }
299 else
300 {
301 PerpDir = hit->getHalfLad()->getPerpStereoDirection();
302 }
303 }
304 Helix helix=myCopy->getTrajectory();
305 Trajectory::Location *loc = helix.newIntersectionWith(hit->getHalfLad()->getPlaneOfWafer());
306 if ( loc )
307 {
308 HepPoint3D intersectionPoint = loc->position();
309 HepPoint3D hitPoint = hit->getGlobalPosition();
310 resid = intersectionPoint.dot(PerpDir) - hitPoint.dot(PerpDir);
311 delete loc;
312 }
313 else
314 {
315 resid = -999.0;
316 errlog( ELerror, "Helix intersection failed" )
317 << "@testModule::calcResid"
318 << "Track helix has no intersection with half-ladder that "
319 << "has a hit on the track"
320 << endmsg;
321 }
322
323 if (_debug.value()) {
324 _residNtuple->column("nRun",nRun);
325 _residNtuple->column("nEvent",nEvent);
326 _residNtuple->column("residual",resid*10000.0);
327 _residNtuple->captureThenStore();
328 }
329
330 }
331
332 refittedTrackSet->contents().push_back( myCopy );
333
334 }
335
336 if(refittedTrackSet->contents().size()) anEvent->append(refittedTrackSet);
337 return AppResult::OK;
338 }
Send problems or questions to cdfcode@fnal.gov