CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/RecoParticleFlow/PFTracking/src/PFTrackTransformer.cc

Go to the documentation of this file.
00001 //
00002 // -*- C++ -*-
00003 // Package:    PFTracking
00004 // Class:      PFTrackTransformer
00005 // 
00006 // Original Author:  Michele Pioppi
00007 // Other Author: Daniele Benedetti
00008 
00009 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00010 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 
00014 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
00015 #include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
00016 #include "DataFormats/TrackReco/interface/Track.h"
00017 
00018 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00019 #include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h"
00020 
00021 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00022 // Add by Daniele
00023 #include "TrackingTools/GsfTools/interface/MultiGaussianStateTransform.h"
00024 #include "TrackingTools/GsfTools/interface/MultiGaussianState1D.h"
00025 #include "TrackingTools/GsfTools/interface/GaussianSumUtilities1D.h"
00026 #include "RecoParticleFlow/PFTracking/interface/PFGsfHelper.h"
00027 
00028 using namespace std;
00029 using namespace reco;
00030 using namespace edm;
00031 
00032 
00033 
00034 PFTrackTransformer::PFTrackTransformer(math::XYZVector B):B_(B){
00035   LogInfo("PFTrackTransformer")<<"PFTrackTransformer built";
00036 
00037   PFGeometry pfGeometry;
00038   onlyprop_=false;
00039 }
00040 
00041 PFTrackTransformer::~PFTrackTransformer(){
00042   
00043 }
00044 
00045 
00046 bool 
00047 PFTrackTransformer::addPoints( reco::PFRecTrack& pftrack, 
00048                                const reco::Track& track,
00049                                const Trajectory& traj,
00050                                bool msgwarning) const {
00051   
00052   LogDebug("PFTrackTransformer")<<"Trajectory propagation started";
00053   using namespace reco;
00054   using namespace std;
00055   
00056   float PT= track.pt();
00057   float pfmass= (pftrack.algoType()==reco::PFRecTrack::KF_ELCAND) ? 0.0005 : 0.139; 
00058   float pfenergy=sqrt((pfmass*pfmass)+(track.p()*track.p()));
00059    // closest approach
00060   BaseParticlePropagator theParticle = 
00061     BaseParticlePropagator( 
00062                            RawParticle(XYZTLorentzVector(track.px(),
00063                                                          track.py(),
00064                                                          track.pz(),
00065                                                          pfenergy),
00066                                        XYZTLorentzVector(track.vertex().x(),
00067                                                          track.vertex().y(),
00068                                                          track.vertex().z(),
00069                                                          0.)),
00070                            0.,0.,B_.z());
00071 
00072   theParticle.setCharge(track.charge());
00073   float pfoutenergy=sqrt((pfmass*pfmass)+track.outerMomentum().Mag2());
00074   BaseParticlePropagator theOutParticle = 
00075     BaseParticlePropagator( 
00076                            RawParticle(XYZTLorentzVector(track.outerMomentum().x(),
00077                                                          track.outerMomentum().y(),
00078                                                          track.outerMomentum().z(),
00079                                                          pfoutenergy),
00080                                        XYZTLorentzVector(track.outerPosition().x(),
00081                                                          track.outerPosition().y(),
00082                                                          track.outerPosition().z(),
00083                                                          0.)),
00084                            0.,0.,B_.z());
00085   theOutParticle.setCharge(track.charge());
00086   
00087   
00088   math::XYZTLorentzVector momClosest 
00089     = math::XYZTLorentzVector(track.px(), track.py(), 
00090                               track.pz(), track.p());
00091   math::XYZPoint posClosest = track.vertex();
00092   
00093   pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ClosestApproach,
00094                                      posClosest,momClosest));
00095   
00096   
00097   //BEAMPIPE
00098   theParticle.setPropagationConditions(PFGeometry::outerRadius(PFGeometry::BeamPipe), 
00099                                        PFGeometry::outerZ(PFGeometry::BeamPipe), false);
00100   theParticle.propagate();
00101   if(theParticle.getSuccess()!=0)
00102     pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::BeamPipeOrEndVertex,
00103                                        math::XYZPoint(theParticle.vertex()),
00104                                        math::XYZTLorentzVector(theParticle.momentum())));
00105   else {
00106     PFTrajectoryPoint dummyMaxSh;
00107     pftrack.addPoint(dummyMaxSh); 
00108   }
00109   
00110 
00111 
00112   //trajectory points
00113 
00114   if (!onlyprop_){
00115     bool direction =(traj.direction() == alongMomentum);
00116     vector<TrajectoryMeasurement> measurements =traj.measurements();
00117     int iTrajFirst = (direction) ? 0 :  measurements.size() - 1;
00118     int increment = (direction) ? +1 : -1;
00119     int iTrajLast  =  (direction) ? int(measurements.size()) : -1;
00120     
00121 
00122     for (int iTraj = iTrajFirst; iTraj != iTrajLast; iTraj += increment) {
00123       GlobalPoint v=measurements[iTraj].updatedState().globalPosition();
00124       GlobalVector p=measurements[iTraj].updatedState().globalMomentum();
00125       unsigned int iid=measurements[iTraj].recHit()->det()->geographicalId().rawId();
00126       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00127                                          math::XYZPoint(v.x(), v.y(), v.z()),
00128                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00129     }
00130   }
00131 
00132   bool isBelowPS=false; 
00133    theOutParticle.propagateToPreshowerLayer1(false);
00134    if(theOutParticle.getSuccess()!=0)
00135      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00136                                         math::XYZPoint(theOutParticle.vertex()),
00137                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00138    else {
00139      PFTrajectoryPoint dummyPS1;
00140      pftrack.addPoint(dummyPS1); 
00141    }
00142    
00143 
00144    theOutParticle.propagateToPreshowerLayer2(false);
00145    if(theOutParticle.getSuccess()!=0){
00146      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00147                                         math::XYZPoint(theOutParticle.vertex()),
00148                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00149      isBelowPS=true;
00150    }   else {
00151      PFTrajectoryPoint dummyPS2;
00152      pftrack.addPoint(dummyPS2); 
00153    }
00154 
00155    theOutParticle.propagateToEcalEntrance(false);
00156 
00157    if(theOutParticle.getSuccess()!=0){
00158      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00159                                         math::XYZPoint(theOutParticle.vertex()),
00160                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00161    double ecalShowerDepth     
00162      = PFCluster::getDepthCorrection(theOutParticle.momentum().E(),
00163                                      isBelowPS, 
00164                                      false);
00165 
00166    math::XYZPoint meanShower=math::XYZPoint(theOutParticle.vertex())+
00167      math::XYZTLorentzVector(theOutParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00168  
00169    pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00170                                       meanShower,
00171                                       math::XYZTLorentzVector(theOutParticle.momentum())));}
00172    else {
00173      if (PT>5. && msgwarning)
00174        LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE ECAL HAS FAILED";
00175      PFTrajectoryPoint dummyECAL;
00176      pftrack.addPoint(dummyECAL); 
00177      PFTrajectoryPoint dummyMaxSh;
00178      pftrack.addPoint(dummyMaxSh); 
00179    }
00180 
00181 
00182  
00183    //HCAL entrance
00184    theOutParticle.propagateToHcalEntrance(false);
00185    if(theOutParticle.getSuccess()!=0)
00186      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00187                                         math::XYZPoint(theOutParticle.vertex()),
00188                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00189    else{
00190      if (PT>5.&& msgwarning)
00191        LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00192      PFTrajectoryPoint dummyHCALentrance;
00193      pftrack.addPoint(dummyHCALentrance); 
00194    }
00195 
00196    //HCAL exit
00197    // theOutParticle.setMagneticField(0); //Show we propagate as straight line inside HCAL ?
00198    theOutParticle.propagateToHcalExit(false);
00199    if(theOutParticle.getSuccess()!=0)
00200      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00201                                         math::XYZPoint(theOutParticle.vertex()),
00202                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00203    else{
00204      if (PT>5.&& msgwarning)
00205        LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL EXIT HAS FAILED";
00206      PFTrajectoryPoint dummyHCALexit;
00207      pftrack.addPoint(dummyHCALexit); 
00208    }
00209    
00210    
00211    //HO layer0
00212    //   if (abs(theOutParticle.vertex().z())<550) {
00213    if ( PT>3.0) { //Same value is used in PFBlockAlgo::link( case PFBlockLink::TRACKandHO:
00214      theOutParticle.setMagneticField(0);
00215      theOutParticle.setCharge(0);
00216      theOutParticle.propagateToHOLayer(false);
00217      if(theOutParticle.getSuccess()!=0) {
00218        pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
00219                                           math::XYZPoint(theOutParticle.vertex()),
00220                                           math::XYZTLorentzVector(theOutParticle.momentum())));
00221      } else {
00222        if (PT>5. && abs(theOutParticle.Z()) < 700.25 && msgwarning)
00223          LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE HO HAS FAILED";
00224        PFTrajectoryPoint dummyHOLayer;
00225        pftrack.addPoint(dummyHOLayer); 
00226      }
00227    }
00228 
00229    return true;
00230 }
00231 bool 
00232 PFTrackTransformer::addPointsAndBrems( reco::GsfPFRecTrack& pftrack, 
00233                                        const reco::Track& track,
00234                                        const Trajectory& traj,
00235                                        const bool& GetMode) const {
00236 
00237   float PT= track.pt();
00238   // Trajectory for each trajectory point
00239 
00240   bool direction =(traj.direction() == alongMomentum);
00241   vector<TrajectoryMeasurement> measurements =traj.measurements();
00242   int iTrajFirst = (direction) ? 0 :  measurements.size() - 1;
00243   int increment = (direction) ? +1 : -1;
00244   int iTrajLast  =  (direction) ? int(measurements.size()) : -1;
00245   
00246   
00247   unsigned int iTrajPos = 0;
00248   for (int iTraj = iTrajFirst; iTraj != iTrajLast; iTraj += increment) {
00249     
00250     GlobalPoint v=measurements[iTraj].updatedState().globalPosition();
00251     PFGsfHelper* PFGsf = new PFGsfHelper(measurements[iTraj]);
00252     //if (PFGsf->isValid()){ 
00253     bool ComputeMODE = GetMode;
00254     GlobalVector p = PFGsf->computeP(ComputeMODE);
00255     double DP = PFGsf->fittedDP();
00256     double SigmaDP =  PFGsf->sigmafittedDP();   
00257     unsigned int iid=measurements[iTraj].recHit()->det()->geographicalId().rawId();
00258     delete PFGsf;
00259 
00260     // --------------------------   Fill GSF Track ------------------------------------- 
00261     
00262 
00263     //    float pfmass= (pftrack.algoType()==reco::PFRecTrack::KF_ELCAND) ? 0.0005 : 0.139; 
00264     float ptot =  sqrt((p.x()*p.x())+(p.y()*p.y())+(p.z()*p.z()));
00265     float pfenergy= ptot;
00266 
00267     if (iTraj == iTrajFirst) {
00268 
00269       math::XYZTLorentzVector momClosest 
00270         = math::XYZTLorentzVector(p.x(), p.y(), 
00271                                   p.z(), ptot);
00272       math::XYZPoint posClosest = track.vertex();
00273       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ClosestApproach,
00274                                          posClosest,momClosest));
00275       
00276       BaseParticlePropagator theInnerParticle = 
00277         BaseParticlePropagator( 
00278                                RawParticle(XYZTLorentzVector(p.x(),
00279                                                              p.y(),
00280                                                              p.z(),
00281                                                              pfenergy),
00282                                            XYZTLorentzVector(track.vertex().x(),
00283                                                              track.vertex().y(),
00284                                                              track.vertex().z(),
00285                                                              0.)),  //DANIELE Same thing v.x(),v.y(),v.()? 
00286                                0.,0.,B_.z());
00287       theInnerParticle.setCharge(track.charge());  
00288 
00289       //BEAMPIPE
00290       theInnerParticle.setPropagationConditions(PFGeometry::outerRadius(PFGeometry::BeamPipe), 
00291                                            PFGeometry::outerZ(PFGeometry::BeamPipe), false);
00292       theInnerParticle.propagate();
00293       if(theInnerParticle.getSuccess()!=0)
00294         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::BeamPipeOrEndVertex,
00295                                            math::XYZPoint(theInnerParticle.vertex()),
00296                                            math::XYZTLorentzVector(theInnerParticle.momentum())));
00297       else {
00298         PFTrajectoryPoint dummyMaxSh;
00299         pftrack.addPoint(dummyMaxSh); 
00300       }
00301       
00302       // First Point for the trajectory == Vertex ?? 
00303       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00304                                          math::XYZPoint(v.x(), v.y(), v.z()),
00305                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00306       
00307      
00308     }
00309     if (iTraj != iTrajFirst && iTraj != (abs(iTrajLast)-1)) {
00310       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00311                                          math::XYZPoint(v.x(), v.y(), v.z()),
00312                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00313       
00314  
00315     }
00316     if (iTraj == (abs(iTrajLast)-1)) {
00317       
00318       // Last Trajectory Meas
00319       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00320                                          math::XYZPoint(v.x(), v.y(), v.z()),
00321                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00322 
00323 
00324 
00325 
00326       BaseParticlePropagator theOutParticle = 
00327         BaseParticlePropagator( 
00328                                RawParticle(XYZTLorentzVector(p.x(),
00329                                                              p.y(),
00330                                                              p.z(),
00331                                                              pfenergy),
00332                                            XYZTLorentzVector(v.x(),
00333                                                              v.y(),
00334                                                              v.z(),
00335                                                              0.)), 
00336                                0.,0.,B_.z());
00337       theOutParticle.setCharge(track.charge());  
00338       bool isBelowPS=false; 
00339       theOutParticle.propagateToPreshowerLayer1(false);
00340       if(theOutParticle.getSuccess()!=0)
00341         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00342                                            math::XYZPoint(theOutParticle.vertex()),
00343                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00344       else {
00345         PFTrajectoryPoint dummyPS1;
00346         pftrack.addPoint(dummyPS1); 
00347       }
00348       
00349       
00350       theOutParticle.propagateToPreshowerLayer2(false);
00351       if(theOutParticle.getSuccess()!=0){
00352         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00353                                            math::XYZPoint(theOutParticle.vertex()),
00354                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00355         isBelowPS=true;
00356       }   else {
00357         PFTrajectoryPoint dummyPS2;
00358         pftrack.addPoint(dummyPS2); 
00359       }
00360       
00361       theOutParticle.propagateToEcalEntrance(false);
00362       
00363       if(theOutParticle.getSuccess()!=0){
00364         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00365                                            math::XYZPoint(theOutParticle.vertex()),
00366                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00367         double ecalShowerDepth     
00368           = PFCluster::getDepthCorrection(theOutParticle.momentum().E(),
00369                                           isBelowPS, 
00370                                           false);
00371         
00372         math::XYZPoint meanShower=math::XYZPoint(theOutParticle.vertex())+
00373           math::XYZTLorentzVector(theOutParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00374         
00375         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00376                                            meanShower,
00377                                            math::XYZTLorentzVector(theOutParticle.momentum())));}
00378       else {
00379         if (PT>5.)
00380           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE ECAL HAS FAILED";
00381         PFTrajectoryPoint dummyECAL;
00382         pftrack.addPoint(dummyECAL); 
00383         PFTrajectoryPoint dummyMaxSh;
00384         pftrack.addPoint(dummyMaxSh); 
00385       }
00386       
00387       
00388       
00389       //HCAL entrance
00390       theOutParticle.propagateToHcalEntrance(false);
00391       if(theOutParticle.getSuccess()!=0)
00392         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00393                                            math::XYZPoint(theOutParticle.vertex()),
00394                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00395       else{
00396         if (PT>5.)
00397           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00398         PFTrajectoryPoint dummyHCALentrance;
00399         pftrack.addPoint(dummyHCALentrance); 
00400       }  
00401       //HCAL exit
00402       theOutParticle.propagateToHcalExit(false);
00403       if(theOutParticle.getSuccess()!=0)
00404         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00405                                            math::XYZPoint(theOutParticle.vertex()),
00406                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00407       else{
00408         if (PT>5.)
00409           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL EXIT HAS FAILED";
00410         PFTrajectoryPoint dummyHCALexit;
00411         pftrack.addPoint(dummyHCALexit); 
00412       } 
00413       
00414       //HO Layer0
00415       if ( abs(theOutParticle.vertex().z())<550) {
00416         theOutParticle.setMagneticField(0);
00417         theOutParticle.propagateToHOLayer(false);
00418         if(theOutParticle.getSuccess()!=0)
00419           pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
00420                                              math::XYZPoint(theOutParticle.vertex()),
00421                                              math::XYZTLorentzVector(theOutParticle.momentum())));
00422         else{
00423           if (PT>5. && abs(theOutParticle.Z()) < 700.25 )
00424             LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HO HAS FAILED";
00425           PFTrajectoryPoint dummyHOLayer;
00426           pftrack.addPoint(dummyHOLayer); 
00427         }
00428       } 
00429     }
00430 
00431     // --------------------------   END GSF Track ------------------------------------- 
00432   
00433     // --------------------------   Fill Brem "Track" --------------------------------- 
00434     // Fill the brem for each traj point
00435 
00436     //check that the vertex of the brem is in the tracker volume
00437     if ((v.perp()>110) ||(fabs(v.z())>280)) continue;    
00438     unsigned int iTrajPoint =  iTrajPos + 2;
00439     if(iid%2 == 1) iTrajPoint = 99;
00440 
00441     PFBrem brem(DP,SigmaDP,iTrajPoint);
00442 
00443 
00444     GlobalVector p_gamma= p*(fabs(DP)/p.mag());   // Direction from the electron (tangent), DP without any sign!;
00445     float e_gamma = fabs(DP); // DP = pout-pin so could be negative
00446     BaseParticlePropagator theBremParticle = 
00447       BaseParticlePropagator( 
00448                              RawParticle(XYZTLorentzVector(p_gamma.x(),
00449                                                            p_gamma.y(),
00450                                                            p_gamma.z(),
00451                                                            e_gamma),
00452                                          XYZTLorentzVector(v.x(),
00453                                                            v.y(),
00454                                                            v.z(),
00455                                                            0.)),
00456                              0.,0.,B_.z());
00457     int gamma_charge = 0;
00458     theBremParticle.setCharge(gamma_charge);  
00459 
00460 
00461     // add TrajectoryPoint for Brem, PS, ECAL, ECALShowMax, HCAL
00462     // Brem Entrance PS Layer1
00463 
00464     PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
00465     brem.addPoint(dummyClosest); 
00466 
00467     
00468     PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
00469     brem.addPoint(dummyBeamPipe); 
00470 
00471 
00472     
00473     bool isBelowPS=false; 
00474     theBremParticle.propagateToPreshowerLayer1(false);
00475     if(theBremParticle.getSuccess()!=0)
00476       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00477                                          math::XYZPoint(theBremParticle.vertex()),
00478                                          math::XYZTLorentzVector(theBremParticle.momentum())));
00479     else {
00480       PFTrajectoryPoint dummyPS1;
00481       brem.addPoint(dummyPS1); 
00482     }
00483     
00484     // Brem Entrance PS Layer 2
00485 
00486     theBremParticle.propagateToPreshowerLayer2(false);
00487     if(theBremParticle.getSuccess()!=0){
00488       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00489                                          math::XYZPoint(theBremParticle.vertex()),
00490                                          math::XYZTLorentzVector(theBremParticle.momentum())));
00491       isBelowPS=true;
00492     }   else {
00493       PFTrajectoryPoint dummyPS2;
00494       brem.addPoint(dummyPS2); 
00495     }
00496 
00497    theBremParticle.propagateToEcalEntrance(false);
00498 
00499    if(theBremParticle.getSuccess()!=0){
00500      brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00501                                         math::XYZPoint(theBremParticle.vertex()),
00502                                         math::XYZTLorentzVector(theBremParticle.momentum())));
00503    double ecalShowerDepth     
00504      = PFCluster::getDepthCorrection(theBremParticle.momentum().E(),
00505                                      isBelowPS, 
00506                                      false);
00507 
00508    math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
00509      math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00510  
00511    brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00512                                       meanShower,
00513                                       math::XYZTLorentzVector(theBremParticle.momentum())));}
00514    else {
00515      if ((DP>5.) && ((DP/SigmaDP)>3))
00516        LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
00517      PFTrajectoryPoint dummyECAL;
00518      brem.addPoint(dummyECAL); 
00519      PFTrajectoryPoint dummyMaxSh;
00520      brem.addPoint(dummyMaxSh); 
00521    }
00522 
00523 
00524  
00525    //HCAL entrance
00526    theBremParticle.propagateToHcalEntrance(false);
00527    if(theBremParticle.getSuccess()!=0)
00528      brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00529                                         math::XYZPoint(theBremParticle.vertex()),
00530                                         math::XYZTLorentzVector(theBremParticle.momentum())));
00531    else{
00532      if ((DP>5.) && ((DP/SigmaDP)>3))
00533        LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00534      PFTrajectoryPoint dummyHCALentrance;
00535      brem.addPoint(dummyHCALentrance); 
00536    }  
00537    
00538    //HCAL exit
00539    theBremParticle.propagateToHcalExit(false);
00540    if(theBremParticle.getSuccess()!=0)
00541      brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00542                                      math::XYZPoint(theBremParticle.vertex()),
00543                                      math::XYZTLorentzVector(theBremParticle.momentum())));
00544    else{  
00545      if ((DP>5.) && ((DP/SigmaDP)>3))
00546        LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
00547      PFTrajectoryPoint dummyHCALexit;
00548      brem.addPoint(dummyHCALexit); 
00549    }
00550    
00551    //HO Layer0
00552    if ( abs(theBremParticle.vertex().z())<550.0) {
00553      theBremParticle.setMagneticField(0);
00554      theBremParticle.propagateToHOLayer(false);
00555      if(theBremParticle.getSuccess()!=0)
00556        brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
00557                                        math::XYZPoint(theBremParticle.vertex()),
00558                                        math::XYZTLorentzVector(theBremParticle.momentum())));
00559      else {  
00560        if ((DP>5.) && ((DP/SigmaDP)>3) && abs(theBremParticle.Z()) < 700.25 )
00561          LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE H0 HAS FAILED";
00562        PFTrajectoryPoint dummyHOLayer;
00563        brem.addPoint(dummyHOLayer); 
00564      }
00565    }
00566    brem.calculatePositionREP();
00567    pftrack.addBrem(brem);
00568    iTrajPos++;
00569   }
00570   return true;
00571 }
00572 
00573 
00574 
00575 bool 
00576 PFTrackTransformer::addPointsAndBrems( reco::GsfPFRecTrack& pftrack, 
00577                                        const reco::GsfTrack& track,
00578                                        const MultiTrajectoryStateTransform& mtjstate) const {
00579 
00580   //  float PT= track.pt();
00581   unsigned int iTrajPos = 0;
00582   unsigned int iid = 0; // not anymore saved
00583 
00584 
00585   // *****************************   INNER State *************************************
00586   TrajectoryStateOnSurface inTSOS = mtjstate.innerStateOnSurface((track));
00587   TrajectoryStateOnSurface outTSOS = mtjstate.outerStateOnSurface((track));
00588 
00589   if(!inTSOS.isValid() || !outTSOS.isValid()) {
00590     if(!inTSOS.isValid())
00591       LogWarning("PFTrackTransformer")<<" INNER TSOS NOT VALID ";
00592     if(!outTSOS.isValid())
00593       LogWarning("PFTrackTransformer")<<" OUTER TSOS NOT VALID ";
00594     return false;
00595   }
00596 
00597   GlobalVector InMom;
00598   GlobalPoint InPos;
00599   if(inTSOS.isValid()) {
00600     mtsMode_->momentumFromModeCartesian(inTSOS,InMom);
00601     mtsMode_->positionFromModeCartesian(inTSOS,InPos);
00602   }
00603   else {
00604     InMom = GlobalVector(track.pxMode(),track.pyMode(),track.pzMode());
00605     InPos = GlobalPoint(0.,0.,0.);
00606   }
00607 
00608   //  float pfmass= (pftrack.algoType()==reco::PFRecTrack::KF_ELCAND) ? 0.0005 : 0.139; 
00609   float ptot =  sqrt((InMom.x()*InMom.x())+(InMom.y()*InMom.y())+(InMom.z()*InMom.z()));
00610   float pfenergy= ptot;
00611   
00612   math::XYZTLorentzVector momClosest 
00613     = math::XYZTLorentzVector(InMom.x(), InMom.y(), 
00614                               InMom.z(), ptot);
00615   math::XYZPoint posClosest = track.vertex();
00616   pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ClosestApproach,
00617                                      posClosest,momClosest));
00618   
00619   BaseParticlePropagator theInnerParticle = 
00620     BaseParticlePropagator( RawParticle(XYZTLorentzVector(InMom.x(),
00621                                                           InMom.y(),
00622                                                           InMom.z(),
00623                                                           pfenergy),
00624                                         XYZTLorentzVector(track.vertex().x(),
00625                                                           track.vertex().y(),
00626                                                           track.vertex().z(),
00627                                                           0.)),  //DANIELE Same thing v.x(),v.y(),v.()? 
00628                             0.,0.,B_.z());
00629   theInnerParticle.setCharge(track.charge());   // Use the chargeMode ??   
00630   //BEAMPIPE
00631   theInnerParticle.setPropagationConditions(PFGeometry::outerRadius(PFGeometry::BeamPipe), 
00632                                             PFGeometry::outerZ(PFGeometry::BeamPipe), false);
00633   theInnerParticle.propagate();
00634   if(theInnerParticle.getSuccess()!=0)
00635     pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::BeamPipeOrEndVertex,
00636                                        math::XYZPoint(theInnerParticle.vertex()),
00637                                        math::XYZTLorentzVector(theInnerParticle.momentum())));
00638   else {
00639     PFTrajectoryPoint dummyBeam;
00640     pftrack.addPoint(dummyBeam); 
00641   }
00642   
00643 
00644   // first tjpoint 
00645   pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00646                                      math::XYZPoint(InPos.x(),InPos.y(), InPos.z()),
00647                                      math::XYZTLorentzVector(InMom.x(),InMom.y(),InMom.z(),InMom.mag())));
00648   
00649   
00650   //######### Photon at INNER State ##########
00651 
00652 
00653   unsigned int iTrajPoint =  iTrajPos + 2;  
00654   double dp_tang = ptot;
00655   double sdp_tang = track.ptModeError()*(track.pMode()/track.ptMode());
00656   PFBrem brem(dp_tang,sdp_tang,iTrajPoint);
00657   BaseParticlePropagator theBremParticle = 
00658     BaseParticlePropagator( 
00659                            RawParticle(XYZTLorentzVector(InMom.x(),
00660                                                          InMom.y(),
00661                                                          InMom.z(),
00662                                                          dp_tang),
00663                                        XYZTLorentzVector(InPos.x(),
00664                                                          InPos.y(),
00665                                                          InPos.z(),
00666                                                          0.)),
00667                            0.,0.,B_.z());
00668   int gamma_charge = 0;
00669   theBremParticle.setCharge(gamma_charge);  
00670   // add TrajectoryPoint for Brem, PS, ECAL, ECALShowMax, HCAL
00671   // Brem Entrance PS Layer1
00672   PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
00673   brem.addPoint(dummyClosest); 
00674   
00675   
00676   PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
00677   brem.addPoint(dummyBeamPipe); 
00678   
00679   
00680   
00681   bool isBelowPS=false; 
00682   theBremParticle.propagateToPreshowerLayer1(false);
00683   if(theBremParticle.getSuccess()!=0)
00684     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00685                                     math::XYZPoint(theBremParticle.vertex()),
00686                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00687   else {
00688     PFTrajectoryPoint dummyPS1;
00689     brem.addPoint(dummyPS1); 
00690   }
00691   
00692   // Brem Entrance PS Layer 2
00693   
00694   theBremParticle.propagateToPreshowerLayer2(false);
00695   if(theBremParticle.getSuccess()!=0){
00696     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00697                                     math::XYZPoint(theBremParticle.vertex()),
00698                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00699     isBelowPS=true;
00700   }   else {
00701     PFTrajectoryPoint dummyPS2;
00702     brem.addPoint(dummyPS2); 
00703   }
00704   
00705   theBremParticle.propagateToEcalEntrance(false);
00706   
00707   if(theBremParticle.getSuccess()!=0){
00708     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00709                                     math::XYZPoint(theBremParticle.vertex()),
00710                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00711 
00712     //  for the first brem give a low default DP of 100 MeV.  
00713     double EDepthCorr = 0.01;
00714     double ecalShowerDepth     
00715       = PFCluster::getDepthCorrection(EDepthCorr,
00716                                       isBelowPS, 
00717                                       false);
00718     
00719     math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
00720       math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00721     
00722     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00723                                     meanShower,
00724                                     math::XYZTLorentzVector(theBremParticle.momentum())));}
00725   else {
00726     if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00727       LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
00728     PFTrajectoryPoint dummyECAL;
00729     brem.addPoint(dummyECAL); 
00730     PFTrajectoryPoint dummyMaxSh;
00731     brem.addPoint(dummyMaxSh); 
00732   }
00733   
00734   
00735   
00736   //HCAL entrance
00737   theBremParticle.propagateToHcalEntrance(false);
00738   if(theBremParticle.getSuccess()!=0)
00739     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00740                                     math::XYZPoint(theBremParticle.vertex()),
00741                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00742   else{
00743     if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00744       LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00745     PFTrajectoryPoint dummyHCALentrance;
00746     brem.addPoint(dummyHCALentrance); 
00747   }  
00748 
00749   //HCAL exit
00750   theBremParticle.propagateToHcalExit(false);
00751   if(theBremParticle.getSuccess()!=0)
00752     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00753                                     math::XYZPoint(theBremParticle.vertex()),
00754                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00755   else{  
00756     if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00757       LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
00758     PFTrajectoryPoint dummyHCALexit;
00759     brem.addPoint(dummyHCALexit); 
00760   }
00761   
00762   //HO Layer0
00763   if ( abs(theBremParticle.vertex().z())<550) {
00764     theBremParticle.setMagneticField(0);
00765     theBremParticle.propagateToHOLayer(false);
00766     if(theBremParticle.getSuccess()!=0)
00767       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
00768                                       math::XYZPoint(theBremParticle.vertex()),
00769                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00770     else{  
00771       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3) && abs(theBremParticle.Z()) < 700.25 )
00772         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE H0 HAS FAILED";
00773       PFTrajectoryPoint dummyHOLayer;
00774       brem.addPoint(dummyHOLayer); 
00775     }
00776   }
00777   
00778   brem.calculatePositionREP();
00779   pftrack.addBrem(brem);
00780   iTrajPos++;
00781 
00782   
00783 
00784 
00785   // *****************************   INTERMIDIATE State *************************************
00786   //From the new Wolfgang code
00787 
00788   // To think if the cout should be removed. 
00789   if(track.gsfExtra()->tangentsSize() == 0)
00790     LogError("PFTrackTransformer")
00791       <<"BE CAREFUL: Gsf Tangents not stored in the event. You need to re-reco the particle-flow with RecoToDisplay_cfg.py and not RecoToDisplay_NoTracking_cfg.py ";
00792   
00793 
00794   vector<GsfTangent> gsftang = track.gsfExtra()->tangents();
00795   for(unsigned int iTang = 0; iTang < track.gsfExtra()->tangentsSize(); iTang++) {
00796     
00797     dp_tang = gsftang[iTang].deltaP().value();
00798     sdp_tang = gsftang[iTang].deltaP().error();
00799     
00800     //check that the vertex of the brem is in the tracker volume
00801     if ((sqrt(gsftang[iTang].position().x()*gsftang[iTang].position().x() 
00802               + gsftang[iTang].position().y()*gsftang[iTang].position().y())>110) 
00803         ||(fabs(gsftang[iTang].position().z())>280)) continue;    
00804 
00805     iTrajPoint = iTrajPos + 2;
00806     PFBrem brem(dp_tang,sdp_tang,iTrajPoint);
00807 
00808  
00809 
00810     GlobalVector p_tang=  GlobalVector(gsftang[iTang].momentum().x(),
00811                                        gsftang[iTang].momentum().y(),
00812                                        gsftang[iTang].momentum().z());
00813     
00814     
00815     // ###### track tj points
00816     pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00817                                        math::XYZPoint(gsftang[iTang].position().x(),gsftang[iTang].position().y(),gsftang[iTang].position().z()),
00818                                        math::XYZTLorentzVector(p_tang.x(),p_tang.y(),p_tang.z(),p_tang.mag())));
00819     
00820 
00821     //rescale
00822     GlobalVector p_gamma = p_tang *(fabs(dp_tang)/p_tang.mag()); 
00823     
00824     // GlobalVector 
00825 
00826  
00827     double e_gamma = fabs(dp_tang); // DP = pout-pin so could be negative
00828     theBremParticle = BaseParticlePropagator( 
00829                                              RawParticle(XYZTLorentzVector(p_gamma.x(),
00830                                                                            p_gamma.y(),
00831                                                                            p_gamma.z(),
00832                                                                            e_gamma),
00833                                                          XYZTLorentzVector(gsftang[iTang].position().x(),
00834                                                                            gsftang[iTang].position().y(),
00835                                                                            gsftang[iTang].position().z(),
00836                                                                            0.)),
00837                                              0.,0.,B_.z());
00838    
00839     theBremParticle.setCharge(gamma_charge);  
00840     
00841     
00842     PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
00843     brem.addPoint(dummyClosest); 
00844     
00845     
00846     PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
00847     brem.addPoint(dummyBeamPipe); 
00848     
00849     
00850     
00851     isBelowPS=false; 
00852     theBremParticle.propagateToPreshowerLayer1(false);
00853     if(theBremParticle.getSuccess()!=0)
00854       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00855                                       math::XYZPoint(theBremParticle.vertex()),
00856                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00857     else {
00858       PFTrajectoryPoint dummyPS1;
00859       brem.addPoint(dummyPS1); 
00860     }
00861     
00862     // Brem Entrance PS Layer 2
00863     
00864     theBremParticle.propagateToPreshowerLayer2(false);
00865     if(theBremParticle.getSuccess()!=0){
00866       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00867                                       math::XYZPoint(theBremParticle.vertex()),
00868                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00869       isBelowPS=true;
00870     }   else {
00871       PFTrajectoryPoint dummyPS2;
00872       brem.addPoint(dummyPS2); 
00873     }
00874     
00875     theBremParticle.propagateToEcalEntrance(false);
00876     
00877     if(theBremParticle.getSuccess()!=0){
00878       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00879                                       math::XYZPoint(theBremParticle.vertex()),
00880                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00881 
00882       double ecalShowerDepth     
00883         = PFCluster::getDepthCorrection(theBremParticle.momentum().E(),
00884                                         isBelowPS, 
00885                                         false);
00886       
00887       math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
00888         math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00889       
00890       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00891                                       meanShower,
00892                                       math::XYZTLorentzVector(theBremParticle.momentum())));}
00893     else {
00894       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00895         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
00896       PFTrajectoryPoint dummyECAL;
00897       brem.addPoint(dummyECAL); 
00898       PFTrajectoryPoint dummyMaxSh;
00899       brem.addPoint(dummyMaxSh); 
00900     }
00901 
00902 
00903  
00904     //HCAL entrance
00905     theBremParticle.propagateToHcalEntrance(false);
00906     if(theBremParticle.getSuccess()!=0)
00907       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00908                                       math::XYZPoint(theBremParticle.vertex()),
00909                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00910     else{
00911       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00912         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00913       PFTrajectoryPoint dummyHCALentrance;
00914       brem.addPoint(dummyHCALentrance); 
00915     }  
00916     
00917     //HCAL exit
00918     theBremParticle.propagateToHcalExit(false);
00919     if(theBremParticle.getSuccess()!=0)
00920       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00921                                       math::XYZPoint(theBremParticle.vertex()),
00922                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00923     else{  
00924       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00925         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
00926       PFTrajectoryPoint dummyHCALexit;
00927       brem.addPoint(dummyHCALexit); 
00928     }
00929     
00930     //HO Layer0
00931     if ( abs(theBremParticle.vertex().z())<550) {
00932       theBremParticle.setMagneticField(0);
00933       theBremParticle.propagateToHOLayer(false);
00934       if(theBremParticle.getSuccess()!=0)
00935         brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
00936                                         math::XYZPoint(theBremParticle.vertex()),
00937                                         math::XYZTLorentzVector(theBremParticle.momentum())));
00938       else{  
00939         if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3) && abs(theBremParticle.Z()) < 700.25 )
00940           LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE H0 HAS FAILED";
00941         PFTrajectoryPoint dummyHOLayer;
00942         brem.addPoint(dummyHOLayer); 
00943       }
00944     }
00945 
00946     brem.calculatePositionREP();
00947     pftrack.addBrem(brem);
00948     iTrajPos++;
00949   }
00950 
00951 
00952 
00953 
00954   // *****************************   OUTER State *************************************
00955  
00956   if(outTSOS.isValid()) {
00957     GlobalVector OutMom;
00958     GlobalPoint OutPos;
00959     
00960     // DANIELE ?????  if the out is not valid maybe take the last tangent?
00961     // From Wolfgang. It should be always valid 
00962 
00963     mtsMode_->momentumFromModeCartesian(outTSOS,OutMom);
00964     mtsMode_->positionFromModeCartesian(outTSOS,OutPos);
00965 
00966 
00967 
00968     // last tjpoint 
00969     pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00970                                        math::XYZPoint(OutPos.x(),OutPos.y(), OutPos.z()),
00971                                        math::XYZTLorentzVector(OutMom.x(),OutMom.y(),OutMom.z(),OutMom.mag())));
00972 
00973     
00974     float ptot_out =  sqrt((OutMom.x()*OutMom.x())+(OutMom.y()*OutMom.y())+(OutMom.z()*OutMom.z()));
00975     float pTtot_out = sqrt((OutMom.x()*OutMom.x())+(OutMom.y()*OutMom.y()));
00976     float pfenergy_out = ptot_out;
00977     BaseParticlePropagator theOutParticle = 
00978       BaseParticlePropagator( RawParticle(XYZTLorentzVector(OutMom.x(),
00979                                                             OutMom.y(),
00980                                                             OutMom.z(),
00981                                                             pfenergy_out),
00982                                           XYZTLorentzVector(OutPos.x(),
00983                                                             OutPos.y(),
00984                                                             OutPos.z(),
00985                                                             0.)), 
00986                               0.,0.,B_.z());
00987     theOutParticle.setCharge(track.charge());  
00988     isBelowPS=false; 
00989     theOutParticle.propagateToPreshowerLayer1(false);
00990     if(theOutParticle.getSuccess()!=0)
00991       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00992                                          math::XYZPoint(theOutParticle.vertex()),
00993                                          math::XYZTLorentzVector(theOutParticle.momentum())));
00994     else {
00995       PFTrajectoryPoint dummyPS1;
00996       pftrack.addPoint(dummyPS1); 
00997     }
00998     
00999     
01000     theOutParticle.propagateToPreshowerLayer2(false);
01001     if(theOutParticle.getSuccess()!=0){
01002       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
01003                                          math::XYZPoint(theOutParticle.vertex()),
01004                                          math::XYZTLorentzVector(theOutParticle.momentum())));
01005       isBelowPS=true;
01006     }   else {
01007       PFTrajectoryPoint dummyPS2;
01008       pftrack.addPoint(dummyPS2); 
01009     }
01010     
01011     theOutParticle.propagateToEcalEntrance(false);
01012     
01013     if(theOutParticle.getSuccess()!=0){
01014       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
01015                                          math::XYZPoint(theOutParticle.vertex()),
01016                                          math::XYZTLorentzVector(theOutParticle.momentum())));
01017       double EDepthCorr = 0.01;
01018       double ecalShowerDepth     
01019         = PFCluster::getDepthCorrection(EDepthCorr,
01020                                         isBelowPS, 
01021                                         false);
01022       
01023       math::XYZPoint meanShower=math::XYZPoint(theOutParticle.vertex())+
01024         math::XYZTLorentzVector(theOutParticle.momentum()).Vect().Unit()*ecalShowerDepth;
01025       
01026       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
01027                                          meanShower,
01028                                          math::XYZTLorentzVector(theOutParticle.momentum())));}
01029     else {
01030       if (pTtot_out>5.)
01031         LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE ECAL HAS FAILED";
01032       PFTrajectoryPoint dummyECAL;
01033       pftrack.addPoint(dummyECAL); 
01034       PFTrajectoryPoint dummyMaxSh;
01035       pftrack.addPoint(dummyMaxSh); 
01036     }
01037     
01038     
01039     
01040     //HCAL entrance
01041     theOutParticle.propagateToHcalEntrance(false);
01042     if(theOutParticle.getSuccess()!=0)
01043       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
01044                                          math::XYZPoint(theOutParticle.vertex()),
01045                                          math::XYZTLorentzVector(theOutParticle.momentum())));
01046     else{
01047       if (pTtot_out>5.)
01048         LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
01049       PFTrajectoryPoint dummyHCALentrance;
01050       pftrack.addPoint(dummyHCALentrance); 
01051     }  
01052     //HCAL exit
01053     theOutParticle.propagateToHcalExit(false);
01054     if(theOutParticle.getSuccess()!=0)
01055       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
01056                                          math::XYZPoint(theOutParticle.vertex()),
01057                                          math::XYZTLorentzVector(theOutParticle.momentum())));
01058     else{
01059       if (pTtot_out>5.)
01060         LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL EXIT HAS FAILED";
01061       PFTrajectoryPoint dummyHCALexit;
01062       pftrack.addPoint(dummyHCALexit); 
01063     }
01064     
01065     //HO Layer0
01066     if ( abs(theOutParticle.vertex().z())<550) {
01067       theOutParticle.setMagneticField(0);
01068       theOutParticle.propagateToHOLayer(false);
01069       if(theOutParticle.getSuccess()!=0)
01070         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
01071                                            math::XYZPoint(theOutParticle.vertex()),
01072                                            math::XYZTLorentzVector(theOutParticle.momentum())));
01073       else{  
01074         if ( pTtot_out > 5. && abs(theOutParticle.Z()) < 700.25 )
01075           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<<" PROPAGATION TO THE HO HAS FAILED";
01076         PFTrajectoryPoint dummyHOLayer;
01077         pftrack.addPoint(dummyHOLayer); 
01078       }
01079     }
01080     //######## Photon at the OUTER State ##########
01081 
01082     dp_tang = OutMom.mag();
01083     // for the moment same inner error just for semplicity
01084     sdp_tang = track.ptModeError()*(track.pMode()/track.ptMode());
01085     iTrajPoint = iTrajPos + 2;
01086     PFBrem brem(dp_tang,sdp_tang,iTrajPoint);
01087 
01088     theBremParticle =   
01089       BaseParticlePropagator( RawParticle(XYZTLorentzVector(OutMom.x(),
01090                                                             OutMom.y(),
01091                                                             OutMom.z(),
01092                                                             dp_tang),
01093                                           XYZTLorentzVector(OutPos.x(),
01094                                                             OutPos.y(),
01095                                                             OutPos.z(),
01096                                                             0.)), 
01097                               0.,0.,B_.z());
01098     theBremParticle.setCharge(gamma_charge);  
01099     
01100     
01101     PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
01102     brem.addPoint(dummyClosest); 
01103     
01104     
01105     PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
01106     brem.addPoint(dummyBeamPipe); 
01107     
01108     
01109     
01110     isBelowPS=false; 
01111     theBremParticle.propagateToPreshowerLayer1(false);
01112     if(theBremParticle.getSuccess()!=0)
01113       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
01114                                       math::XYZPoint(theBremParticle.vertex()),
01115                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01116     else {
01117       PFTrajectoryPoint dummyPS1;
01118       brem.addPoint(dummyPS1); 
01119     }
01120     
01121     // Brem Entrance PS Layer 2
01122     
01123     theBremParticle.propagateToPreshowerLayer2(false);
01124     if(theBremParticle.getSuccess()!=0){
01125       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
01126                                       math::XYZPoint(theBremParticle.vertex()),
01127                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01128       isBelowPS=true;
01129     }   else {
01130       PFTrajectoryPoint dummyPS2;
01131       brem.addPoint(dummyPS2); 
01132     }
01133     
01134     theBremParticle.propagateToEcalEntrance(false);
01135     
01136     if(theBremParticle.getSuccess()!=0){
01137       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
01138                                       math::XYZPoint(theBremParticle.vertex()),
01139                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01140       double ecalShowerDepth     
01141         = PFCluster::getDepthCorrection(theBremParticle.momentum().E(),
01142                                         isBelowPS, 
01143                                         false);
01144       
01145       math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
01146         math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
01147       
01148       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
01149                                       meanShower,
01150                                       math::XYZTLorentzVector(theBremParticle.momentum())));}
01151     else {
01152       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
01153         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
01154       PFTrajectoryPoint dummyECAL;
01155       brem.addPoint(dummyECAL); 
01156       PFTrajectoryPoint dummyMaxSh;
01157       brem.addPoint(dummyMaxSh); 
01158     }
01159 
01160 
01161  
01162     //HCAL entrance
01163     theBremParticle.propagateToHcalEntrance(false);
01164     if(theBremParticle.getSuccess()!=0)
01165       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
01166                                       math::XYZPoint(theBremParticle.vertex()),
01167                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01168     else{
01169       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
01170         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
01171       PFTrajectoryPoint dummyHCALentrance;
01172       brem.addPoint(dummyHCALentrance); 
01173     } 
01174     //HCAL exit
01175     theBremParticle.propagateToHcalExit(false);
01176     if(theBremParticle.getSuccess()!=0)
01177       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
01178                                       math::XYZPoint(theBremParticle.vertex()),
01179                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01180     else{  
01181       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
01182         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
01183       PFTrajectoryPoint dummyHCALexit;
01184       brem.addPoint(dummyHCALexit); 
01185     }
01186     
01187     //HO Layer0
01188     if ( abs(theBremParticle.vertex().z())<550) {
01189       theBremParticle.setMagneticField(0);
01190       theBremParticle.propagateToHOLayer(false);
01191       if(theBremParticle.getSuccess()!=0)
01192         brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HOLayer,
01193                                         math::XYZPoint(theBremParticle.vertex()),
01194                                         math::XYZTLorentzVector(theBremParticle.momentum())));
01195       else{  
01196         if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3) && abs(theBremParticle.Z()) < 700.25 )
01197           LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE H0 HAS FAILED";
01198         PFTrajectoryPoint dummyHOLayer;
01199         brem.addPoint(dummyHOLayer); 
01200       }
01201     }
01202     brem.calculatePositionREP();
01203     pftrack.addBrem(brem);
01204     iTrajPos++;
01205   }
01206 
01207   return true;
01208 }