Changeset 258 in svn for trunk/Resolutions.cpp
- Timestamp:
- Feb 9, 2009, 11:31:56 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Resolutions.cpp
r227 r258 60 60 if(abs(gen1->PID)==15) 61 61 { 62 cout<<"au moins on a un tau "<<endl; 62 63 int d1=gen1->D1; 63 64 int d2=gen1->D2; 64 65 cout<<"il a des filles? "<<endl; 65 66 if((d1 < array.GetEntries()) && (d1 > 0) && (d2 < array.GetEntries()) && (d2 > 0)) 66 67 { 67 68 tauhad=true; 68 69 for(int d=d1; d < d2+1; d++) 69 { 70 {cout<<abs(array[d]->PID)<<" "<<endl; 70 71 if(abs(array[d]->PID)== pE || abs(array[d]->PID)== pMU)tauhad=false; 71 72 } … … 77 78 } 78 79 79 80 81 void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, vector<fastjet::PseudoJet> sorted_jetsS) 80 double EnergySmallCone(const vector<TLorentzVector> &towers, const float eta, const float phi,float energy_scone,float JET_seed) { 81 double Energie=0; 82 for(unsigned int i=0; i < towers.size(); i++) { 83 if(towers[i].Pt() < JET_seed) continue; 84 if((DeltaR(phi,eta,towers[i].Phi(),towers[i].Eta()) < energy_scone)) { 85 Energie += towers[i].E(); 86 } 87 } 88 return Energie; 89 } 90 91 92 void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, const TClonesArray *branchJet) 82 93 { 83 94 JETSm.SetPxPyPzE(0,0,0,0); 84 95 float deltaRtest=5000; 85 for (unsigned int i = 0; i < sorted_jetsS.size(); i++) { 96 TIter itJet((TCollection*)branchJet); 97 TRootJet *jet; 98 itJet.Reset(); 99 while( (jet = (TRootJet*) itJet.Next()) ) 100 { 86 101 TLorentzVector Att; 87 Att.SetPxPyPzE( sorted_jetsS[i].px(),sorted_jetsS[i].py(),sorted_jetsS[i].pz(),sorted_jetsS[i].E());102 Att.SetPxPyPzE(jet->Px,jet->Py,jet->Pz,jet->E); 88 103 if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest) 89 104 { … … 97 112 } 98 113 114 void PairingElec(TLorentzVector &ELECSm, const TLorentzVector &ELEC, const TClonesArray *branchElec) 115 { 116 ELECSm.SetPxPyPzE(0,0,0,0); 117 float deltaRtest=5000; 118 TIter itElec((TCollection*)branchElec); 119 TRootElectron *elec; 120 itElec.Reset(); 121 while( (elec = (TRootElectron*) itElec.Next()) ) 122 { 123 TLorentzVector Att; 124 Att.SetPxPyPzE(elec->Px,elec->Py,elec->Pz,elec->E); 125 if(DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta()) < deltaRtest) 126 { 127 deltaRtest = DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta()); 128 if(deltaRtest < 0.025) 129 { 130 ELECSm = Att; 131 } 132 } 133 } 134 } 135 136 void PairingMuon(TLorentzVector &MUONSm, const TLorentzVector &MUON, const TClonesArray *branchMuon) 137 { 138 MUONSm.SetPxPyPzE(0,0,0,0); 139 float deltaRtest=5000; 140 TIter itMuon((TCollection*)branchMuon); 141 TRootMuon *muon; 142 itMuon.Reset(); 143 while( (muon = (TRootMuon*) itMuon.Next()) ) 144 { 145 TLorentzVector Att; 146 Att.SetPxPyPzE(muon->Px,muon->Py,muon->Pz,muon->E); 147 if(DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta()) < deltaRtest) 148 { 149 deltaRtest = DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta()); 150 if(deltaRtest < 0.025) 151 { 152 MUONSm = Att; 153 } 154 } 155 } 156 } 157 158 unsigned int NumTracks(const TClonesArray *branchTracks, const float pt_track, const float eta, const float phi,float track_scone) { 159 unsigned int numtrack=0; 160 TIter itTrack((TCollection*)branchTracks); 161 TRootTracks *track; 162 itTrack.Reset(); 163 while( (track = (TRootTracks*) itTrack.Next()) ) 164 { 165 if((track->PT < pt_track )|| 166 (DeltaR(phi,eta,track->Phi,track->Eta) > track_scone) 167 )continue; 168 numtrack++; 169 } 170 return numtrack; 171 } 172 173 174 99 175 int main(int argc, char *argv[]) 100 176 { 101 177 int appargc = 2; 102 char *appName = " Smearing";178 char *appName = "Resolution"; 103 179 char *appargv[] = {appName, "-b"}; 104 180 TApplication app(appName, &appargc, appargv); 105 181 106 if(argc != 4 && argc !=3) {107 cout << " Usage: " << argv[0] << " input_file" << " output_file" << " data_card " <<endl;108 cout << " input_list - list of files in Ntpl, StdHep of LHEFformat," << endl;182 if(argc != 3) { 183 cout << " Usage: " << argv[0] << " input_file" << " output_file" << endl; 184 cout << " input_list - list of files in root format," << endl; 109 185 cout << " output_file - output file." << endl; 110 cout << " data_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;111 186 exit(1); 112 187 } … … 115 190 116 191 //read the input TROOT file 117 string inputFileList(argv[1]), outputfilename(argv[2]); 192 string inputfilename(argv[1]), outputfilename(argv[2]); 193 118 194 if(outputfilename.find(".root") > outputfilename.length() ) { 119 195 cout << "output_file should be a .root file!\n"; … … 121 197 } 122 198 199 200 123 201 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after 124 202 outputFile->Close(); 125 203 126 string line; 127 ifstream infile(inputFileList.c_str()); 128 infile >> line; // the first line determines the type of input files 129 130 DataConverter *converter=0; 131 132 if(strstr(line.c_str(),".hep")) 133 { 134 cout<<"*************************************************************************"<<endl; 135 cout<<"************ StdHEP file format detected **************"<<endl; 136 cout<<"************ Starting convertion to TRoot format **************"<<endl; 137 cout<<"*************************************************************************"<<endl; 138 converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list 139 } 140 else if(strstr(line.c_str(),".lhe")) 141 { 142 cout<<"*************************************************************************"<<endl; 143 cout<<"************ LHEF file format detected **************"<<endl; 144 cout<<"************ Starting convertion to TRoot format **************"<<endl; 145 cout<<"*************************************************************************"<<endl; 146 converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list 147 } 148 else if(strstr(line.c_str(),".root")) 149 { 150 cout<<"*************************************************************************"<<endl; 151 cout<<"************ h2root file format detected **************"<<endl; 152 cout<<"************ Starting convertion to TRoot format **************"<<endl; 153 cout<<"*************************************************************************"<<endl; 154 converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list 155 } 156 else { cout << "*** " << line.c_str() << "\n*** file format not identified\n*** Exiting\n"; return -1;}; 157 158 TChain chain("GEN"); 159 chain.Add(outputfilename.c_str()); 204 TChain chainGEN("GEN"); 205 chainGEN.Add(inputfilename.c_str()); 206 ExRootTreeReader *treeReaderGEN = new ExRootTreeReader(&chainGEN); 207 TChain chain("Analysis"); 208 chain.Add(inputfilename.c_str()); 160 209 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain); 161 const TClonesArray *branchGen = treeReader->UseBranch("Particle"); 210 const TClonesArray *branchJet = treeReader->UseBranch("Jet"); 211 const TClonesArray *branchElec = treeReader->UseBranch("Electron"); 212 const TClonesArray *branchMuon = treeReader->UseBranch("Muon"); 213 const TClonesArray *branchTracks = treeReader->UseBranch("Tracks"); 214 const TClonesArray *branchTowers = treeReader->UseBranch("CaloTower"); 215 const TClonesArray *branchGen = treeReaderGEN->UseBranch("Particle"); 162 216 TIter itGen((TCollection*)branchGen); 163 217 … … 178 232 ETMIS *elementEtmis; 179 233 180 int numTau=0; 181 int numTauRec=0; 182 183 //read the datacard input file 184 string DetDatacard("data/DataCardDet.dat"); 185 if(argc==4) DetDatacard =argv[3]; 186 RESOLution *DET = new RESOLution(); 187 DET->ReadDataCard(DetDatacard); 234 int numTau=0; 235 int numTauRec=0; 236 237 RESOLution *DET = new RESOLution(); 238 DET->ReadDataCard("data/Datacard_CMS.dat"); 239 188 240 189 241 //Jet information 190 JetsUtil *JETRUN = new JetsUtil(DetDatacard); 191 192 //Propagation of tracks in the B field 193 //TrackPropagation *TRACP = new TrackPropagation(DetDatacard); 194 242 JetsUtil *JETRUN = new JetsUtil("data/Datacard_CMS.dat"); 243 195 244 TLorentzVector genMomentum(0,0,0,0);//TLorentzVector containing generator level information 196 TLorentzVector recoMomentumCalo(0,0,0,0); 197 TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing Reco level information 245 TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing generator level information 198 246 LorentzVector jetMomentum; 199 vector<TLorentzVector> TrackCentral;200 247 201 248 vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm 202 249 vector<fastjet::PseudoJet> sorted_jetsGEN; 203 250 204 vector<fastjet::PseudoJet> input_particlesReco;//for FastJet algorithm 205 vector<fastjet::PseudoJet> sorted_jetsReco; 206 207 vector<PhysicsTower> towers; 208 209 float iPhi=0,iEta=0; 251 vector<TLorentzVector> towers; 210 252 211 253 // Loop over all events … … 217 259 TLorentzVector PTmisGEN(0,0,0,0); 218 260 treeReader->ReadEntry(entry); 261 treeReaderGEN->ReadEntry(entry); 219 262 treeWriter->Clear(); 220 263 if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl; … … 222 265 TSimpleArray<TRootGenParticle> bGen; 223 266 itGen.Reset(); 224 TrackCentral.clear();225 267 TSimpleArray<TRootGenParticle> NFCentralQ; 226 268 227 input_particlesReco.clear();228 269 input_particlesGEN.clear(); 229 270 towers.clear(); … … 245 286 //Calculate ETMIS from generated particles 246 287 if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum; 247 248 249 250 251 288 289 if( (particle->Status == 1) && 290 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) && 291 (fabs(particle->Eta) < DET->CEN_max_calo_fwd) 292 ) 252 293 { 253 recoMomentum = genMomentum; 254 //use of the magnetic field propagation 255 //TRACP->Propagation(particle,recoMomentum); 256 // cout<<"eta "<<eta<<endl; 257 eta=fabs(recoMomentum.Eta()); 258 // cout<<"eta apres"<<eta<<endl; 259 260 switch(pid) { 261 262 case pE: // all electrons with eta < DET->MAX_CALO_FWD 263 DET->SmearElectron(recoMomentum); 264 if(recoMomentum.E() !=0 && eta < DET->CEN_max_tracker){ 265 elementElec=(RESOLELEC*) branchelec->NewEntry(); 266 elementElec->E = genMomentum.E(); 267 elementElec->SmearedE = recoMomentum.E();} 268 break; // case pE 269 case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD 270 DET->SmearElectron(recoMomentum); 271 break; // case pGAMMA 272 case pMU: // all muons with eta < DET->MAX_MU 273 DET->SmearMu(recoMomentum); 274 if(recoMomentum.E() !=0){ 275 elementMuon = (RESOLMUON*) branchmuon->NewEntry(); 276 elementMuon->OverPT = (1/genMomentum.Pt()); 277 elementMuon->OverSmearedPT = (1/recoMomentum.Pt());} 278 break; // case pMU 279 case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD 280 case pK0S: // all K0s with eta < DET->MAX_CALO_FWD 281 DET->SmearHadron(recoMomentum, 0.7); 282 break; // case hadron 283 default: // all other final particles with eta < DET->MAX_CALO_FWD 284 DET->SmearHadron(recoMomentum, 1.0); 285 break; 286 } // switch (pid) 287 288 //information to reconstruct jets from reconstructed towers 289 int charge=Charge(pid); 290 if(recoMomentum.E() !=0 && pid != pMU) { 291 // in case the Bfield is not simulated, checks that charged particles have enough pt to reach the calos 292 if ( !DET->FLAG_bfield && charge!=0 && genMomentum.Pt() <= DET->TRACK_ptmin ) { /* particules do not reach calos */ } 293 else { // particles reach calos 294 DET->BinEtaPhi(recoMomentum.Phi(), recoMomentum.Eta(), iPhi, iEta); 295 if(iEta != -100 && iPhi != -100) 296 { 297 recoMomentumCalo.SetPtEtaPhiE(recoMomentum.Pt(),iEta,iPhi,recoMomentum.E()); 298 299 PhysicsTower Tower(LorentzVector(recoMomentumCalo.Px(),recoMomentumCalo.Py(),recoMomentumCalo.Pz(), recoMomentumCalo.E())); 300 towers.push_back(Tower); 301 } 302 } 303 } 304 305 // all final charged particles 306 if( 307 (recoMomentum.E()!=0) && 308 (fabs(recoMomentum.Eta()) < DET->CEN_max_tracker) && 309 (DET->FLAG_bfield || ( !DET->FLAG_bfield && genMomentum.Pt() > DET->TRACK_ptmin )) && 310 // if bfield not simulated, pt should be high enough to be taken into account 311 ((rand()%100) < DET->TRACK_eff) && 312 (charge!=0) 313 ) 314 {TrackCentral.push_back(recoMomentum);} 315 316 } // switch 294 eta=fabs(genMomentum.Eta()); 295 296 switch(pid) { 297 298 case pE: // all electrons with eta < DET->MAX_CALO_FWD 299 PairingElec(recoMomentum,genMomentum,branchElec); 300 if(recoMomentum.Pt()>1){ 301 elementElec=(RESOLELEC*) branchelec->NewEntry(); 302 elementElec->E = genMomentum.E(); 303 elementElec->SmearedE = recoMomentum.E();} 304 break; // case pE 305 case pMU: // all muons with eta < DET->MAX_MU 306 PairingMuon(recoMomentum,genMomentum,branchMuon); 307 if(recoMomentum.E() !=0){ 308 elementMuon = (RESOLMUON*) branchmuon->NewEntry(); 309 elementMuon->OverPT = (1/genMomentum.Pt()); 310 elementMuon->OverSmearedPT = (1/recoMomentum.Pt());} 311 break; // case pMU 312 default: 313 break; 314 } // switch (pid) 315 } 316 317 317 } // while 318 318 319 319 //compute missing transverse energy from calo towers 320 TIter itCalo((TCollection*)branchTowers); 321 TRootCalo *calo; 322 itCalo.Reset(); 320 323 TLorentzVector Att(0.,0.,0.,0.); 321 324 float ScalarEt=0; 322 for(unsigned int i=0; i < towers.size(); i++) 323 { 324 Att.SetPxPyPzE(towers[i].fourVector.px, towers[i].fourVector.py, towers[i].fourVector.pz, towers[i].fourVector.E); 325 while( (calo = (TRootCalo*) itCalo.Next()) ) 326 { 327 //Att.SetPxPyPzE(towers[i].fourVector.px, towers[i].fourVector.py, towers[i].fourVector.pz, towers[i].fourVector.E); 328 Att.SetPtEtaPhiE(calo->PT,calo->Eta,calo->Phi,calo->E); 329 towers.push_back(Att); 325 330 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd) 326 331 { 327 332 ScalarEt = ScalarEt + Att.Et(); 328 333 PTmisReco = PTmisReco + Att; 329 // create a fastjet::PseudoJet with these components and put it onto330 // back of the input_particles vector331 input_particlesReco.push_back(fastjet::PseudoJet(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E));332 334 } 333 335 } … … 344 346 345 347 sorted_jetsGEN=JETRUN->RunJets(input_particlesGEN); 346 sorted_jetsReco=JETRUN->RunJets(input_particlesReco);347 348 348 349 TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen); 350 cout<<"nombre de tau-jets "<<TausHadr.GetEntries()<<endl; 349 351 350 352 TLorentzVector JETreco(0,0,0,0); … … 352 354 TLorentzVector JETgen(0,0,0,0); 353 355 JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E()); 354 PairingJet(JETreco,JETgen, sorted_jetsReco);356 PairingJet(JETreco,JETgen,branchJet); 355 357 if(JETreco.Pt()>1) 356 358 { … … 361 363 } 362 364 numTau = numTau+TausHadr.GetEntries(); 363 for (unsigned int i = 0; i < sorted_jetsReco.size(); i++) { 364 TLorentzVector JETT(0,0,0,0); 365 JETT.SetPxPyPzE(sorted_jetsReco[i].px(),sorted_jetsReco[i].py(),sorted_jetsReco[i].pz(),sorted_jetsReco[i].E()); 366 if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone)) 365 366 TIter itJet((TCollection*)branchJet); 367 TRootJet *jet; 368 itJet.Reset(); 369 //cout<<"a"<<endl; 370 while( (jet = (TRootJet*) itJet.Next()) ) 371 { 372 //cout<<"b"<<endl; 373 TLorentzVector JETT(0,0,0,0); 374 JETT.SetPxPyPzE(jet->Px,jet->Py,jet->Pz,jet->E); 375 if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone)) 367 376 { 377 //cout<<"c"<<endl; 368 378 for(Int_t i=0; i<TausHadr.GetEntries();i++) 369 379 { 380 //cout<<"d"<<endl; 370 381 if(DeltaR(TausHadr[i]->Phi,TausHadr[i]->Eta,JETT.Phi(),JETT.Eta())<0.1) 371 382 { 383 //cout<<"e"<<endl; 372 384 elementTaujet= (TAUHAD*) branchtaujet->NewEntry(); 373 elementTaujet->EnergieCen = (DET->EnergySmallCone(towers,JETT.Eta(),JETT.Phi())/JETT.E()); 374 elementTaujet->NumTrack = DET->NumTracks(TrackCentral,DET->TAU_track_pt,JETT.Eta(),JETT.Phi()); 375 if( (DET->EnergySmallCone(towers,JETT.Eta(),JETT.Phi())/JETT.E()) > 0.95 376 && (DET->NumTracks(TrackCentral,DET->TAU_track_pt,JETT.Eta(),JETT.Phi()))==1)numTauRec++; 385 elementTaujet->EnergieCen = (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E()); 386 elementTaujet->NumTrack = NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone); 387 if( (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E()) > 0.95 388 && (NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone))==1)numTauRec++; 389 //cout<<"f"<<endl; 377 390 378 391 } 392 //cout<<"g"<<endl; 379 393 } 380 394 } 395 //cout<<"h"<<endl; 381 396 382 397 383 398 } // for itJet : loop on all jets 399 //cout<<"i"<<endl; 384 400 385 401 treeWriter->Fill(); … … 397 413 delete treeReader; 398 414 delete DET; 399 if(converter) delete converter; 400 } 401 415 } 416
Note:
See TracChangeset
for help on using the changeset viewer.